From 557e4523de6972406564fa9a02af7a68e845e023 Mon Sep 17 00:00:00 2001 From: Samuel Gordalina Date: Thu, 5 Jul 2012 19:38:22 +0200 Subject: [PATCH] Add content textarea to sandbox Problem: Its not possible to POST content in the sandbox. With this change it becomes possible to, e.g.: POST JSON data to the api. Note: The content will take precedence over parameters if set. --- Resources/public/css/screen.css | 16 ++++++++++++--- Resources/views/layout.html.twig | 35 ++++++++++++++++++++++++++++++-- Resources/views/method.html.twig | 14 ++++++++++++- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/Resources/public/css/screen.css b/Resources/public/css/screen.css index 29857f1..c31877a 100644 --- a/Resources/public/css/screen.css +++ b/Resources/public/css/screen.css @@ -1186,7 +1186,7 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio } .pane.sandbox legend { - margin-bottom: 5px; + padding-bottom: 5px; } .remove { @@ -1197,12 +1197,22 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio display: none; } -.parameters { +form .parameters, +form .headers, +form .content { float: left; - width: 50%; + width: 33%; } .buttons { clear: both; padding-top: 10px; } + +form .content textarea { + width:100%; + min-width:100%; + max-width:100%; + height:5em; + margin-bottom:10px; +} diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index 6afc12b..7354892 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -132,6 +132,7 @@ _format: 'json' // default format if not overriden in the form }, headers = {}, + content = $(this).find('textarea.content').val(); result_container = $('.result', $(this).parent()); // retrieve all the parameters to send @@ -173,13 +174,13 @@ $.ajax({ url: '{{ sandboxTarget }}' + url, type: method, - data: params, + data: content.length ? content : params, headers: headers, complete: function(xhr) { displayResponse(xhr, method, url, result_container); // and enable them back - $('input, button', $(self)).removeAttr('disabled'); + $('input:not(.content-type), button', $(self)).removeAttr('disabled'); } }); @@ -226,6 +227,36 @@ $('.pane.sandbox').on('click', '.remove', function() { $(this).parent().remove(); }); + + $('.pane.sandbox').on('click', '.set-content-type', function(e) { + var html; + var $element; + var $headers = $(this).parents('form').find('.headers'); + var content_type = $(this).prev('input.value').val(); + + e.preventDefault(); + + if (content_type.length === 0) { + return; + } + + $headers.find('input.key').each(function() { + if ($.trim($(this).val().toLowerCase()) === 'content-type') { + $element = $(this).parents('p'); + return false; + } + }); + + if (typeof $element === 'undefined') { + html = $(this).parents('.pane').find('.tuple_template').html(); + + $element = $headers.find('legend').after(html).next('p'); + } + + $element.find('input.key').val('Content-Type'); + $element.find('input.value').val(content_type); + + }); diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig index b813024..4701cc1 100644 --- a/Resources/views/method.html.twig +++ b/Resources/views/method.html.twig @@ -127,8 +127,20 @@ -
+
+ Content + + +

+ + = + + Replaces header if set +

+
+ +