From 210596eae94436f05c49077c226dde3e3e12c8e1 Mon Sep 17 00:00:00 2001
From: Jonathan Chan
Date: Tue, 17 Jun 2014 00:10:34 -0400
Subject: [PATCH] adding support for different parameter types
---
Resources/views/layout.html.twig | 59 ++++++++++++++++++++++++++++++--
Resources/views/method.html.twig | 27 +++++++++++++--
2 files changed, 81 insertions(+), 5 deletions(-)
diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig
index 2c964fe..b67a5c5 100644
--- a/Resources/views/layout.html.twig
+++ b/Resources/views/layout.html.twig
@@ -101,6 +101,39 @@
});
{% if enableSandbox %}
+ var setParameterType = function ($context,setType) {
+ // no 2nd argument, use default from parameters
+ if (typeof setType == "undefined") {
+ setType = $context.parent().attr("data-dataType");
+ $context.val(setType);
+ }
+
+ $context.parent().find('.value').remove();
+ var placeholder = "";
+ if ($context.parent().attr("data-dataType") != "" && typeof $context.parent().attr("data-dataType") != "undefined") {
+ placeholder += "[" + $context.parent().attr("data-dataType") + "] ";
+ }
+ if ($context.parent().attr("data-format") != "" && typeof $context.parent().attr("data-format") != "undefined") {
+ placeholder += $context.parent().attr("data-dataType");
+ }
+ if ($context.parent().attr("data-description") != "" && typeof $context.parent().attr("data-description") != "undefined") {
+ placeholder += $context.parent().attr("data-description");
+ } else {
+ placeholder += "Value";
+ }
+
+ switch(setType) {
+ case "boolean":
+ $('').insertAfter($context);
+ break;
+ case "file":
+ $('').insertAfter($context);
+ break;
+ default:
+ $('').insertAfter($context);
+ }
+ };
+
var toggleButtonText = function ($btn) {
if ($btn.text() === 'Default') {
$btn.text('Raw');
@@ -369,8 +402,30 @@
e.preventDefault();
});
- $('.pane.sandbox').on('click', '.add', function() {
- var html = $(this).parents('.pane').find('.tuple_template').html();
+
+ // sets the correct parameter type on load
+ $('.pane.sandbox .tuple_type').each(function() {
+ setParameterType($(this));
+ });
+
+
+ // handles parameter type change
+ $('.pane.sandbox').on('change', '.tuple_type', function() {
+ setParameterType($(this),$(this).val());
+ });
+
+
+
+ $('.pane.sandbox').on('click', '.add_parameter', function() {
+ var html = $(this).parents('.pane').find('.parameters_tuple_template').html();
+
+ $(this).before(html);
+
+ return false;
+ });
+
+ $('.pane.sandbox').on('click', '.add_header', function() {
+ var html = $(this).parents('.pane').find('.headers_tuple_template').html();
$(this).before(html);
diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig
index b4b4ac2..8089805 100644
--- a/Resources/views/method.html.twig
+++ b/Resources/views/method.html.twig
@@ -228,14 +228,20 @@
Parameters
{% for name, infos in data.parameters %}
{% if not infos.readonly %}
-
+
=
+
-
{% endif %}
{% endfor %}
-
+
{% endif %}
@@ -257,7 +263,7 @@
-
-
+