diff --git a/src/sunstone/public/app/app.js b/src/sunstone/public/app/app.js index 44796ad769..37bc96f5d5 100644 --- a/src/sunstone/public/app/app.js +++ b/src/sunstone/public/app/app.js @@ -16,6 +16,8 @@ define(function(require) { require('jquery'); + require('jquery-ui'); + require('foundation'); Foundation.Dropdown.defaults.positionClass = 'left'; diff --git a/src/sunstone/public/app/main.js b/src/sunstone/public/app/main.js index e95489afa4..b1b8ecbdb5 100644 --- a/src/sunstone/public/app/main.js +++ b/src/sunstone/public/app/main.js @@ -21,6 +21,7 @@ require.config({ /* jQuery */ 'jquery': '../bower_components/jquery/dist/jquery', + 'jquery-ui': '../bower_components/jquery-ui/jquery-ui', /* DataTables */ 'datatables.net': '../bower_components/datatables/media/js/jquery.dataTables', diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js index 5376b7af0e..1c23e66e2d 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js @@ -223,7 +223,7 @@ define(function(require) { $.each(userInputsJSON, function(key,value){ var name = key.toUpperCase(); - contextJSON[name] = "$" + name; + contextJSON[name.split("_")[2]] = "$" + name; }); var start_script = WizardFields.retrieveInput($(".START_SCRIPT", context)); diff --git a/src/sunstone/public/app/utils/user-inputs.js b/src/sunstone/public/app/utils/user-inputs.js index 255cbbae48..ade2231edd 100644 --- a/src/sunstone/public/app/utils/user-inputs.js +++ b/src/sunstone/public/app/utils/user-inputs.js @@ -55,11 +55,13 @@ define(function(require) { function _setup(context){ context.on("click", ".add_user_input_attr", function() { - $(".user_input_attrs tbody", context).append(RowTemplateHTML()); - + $(".user_input_attrs tbody", context).append(RowTemplateHTML({'idInput': UniqueId.id()})); + $('tbody label').css('cursor', 'pointer'); $("select.user_input_type", context).change(); }); + $('tbody').sortable(); + context.on("change", "select.user_input_type", function() { var row = $(this).closest("tr"); @@ -74,12 +76,24 @@ define(function(require) { function _retrieve(context){ var userInputsJSON = {}; - + var ids = []; + var index = 0; + $('.user_input_attrs tbody tr').each(function(key, value){ + ids[index] = "_" + key + "_" + $(".user_input_name", $(this)).val(); + index += 1; + }); + index = 0; $(".user_input_attrs tbody tr", context).each(function() { + if ($(".user_input_name", $(this)).val()) { var attr = {}; attr.name = $(".user_input_name", $(this)).val(); - attr.mandatory = true; + if($('.user_input_mandatory', $(this)).prop('checked')){ + attr.mandatory = true; + } else { + attr.mandatory = false; + } + attr.type = $(".user_input_type", $(this)).val(); attr.description = $(".user_input_description", $(this)).val(); @@ -89,7 +103,6 @@ define(function(require) { case "fixed": attr.initial = $("."+attr.type+" input.user_input_initial", $(this)).val(); break; - case "range": case "range-float": var min = $("."+attr.type+" input.user_input_params_min", $(this)).val(); @@ -101,10 +114,15 @@ define(function(require) { attr.params = $("."+attr.type+" input.user_input_params", $(this)).val(); attr.initial = $("."+attr.type+" input.user_input_initial", $(this)).val(); break; + case "boolean": + attr.initial = $('.user_input_initial:checked', $(this)).val(); + break; } - userInputsJSON[attr.name] = _marshall(attr); + userInputsJSON[ids[index]] = _marshall(attr); + index += 1; } + }); return userInputsJSON; @@ -115,28 +133,51 @@ define(function(require) { if (userInputsJSON) { $.each(userInputsJSON, function(key, value) { + $(".add_user_input_attr", context).trigger("click"); var trcontext = $(".user_input_attrs tbody tr", context).last(); - $(".user_input_name", trcontext).val(key); + var name = ""; + var len = key.split("_"); + + for (i = 2; i < len.length; i++){ + name += (len[i] + "_"); + } + + name = name.slice(0,-1); + $(".user_input_name", trcontext).val(name); var attr = _unmarshall(value); if (templateJSON[key] != undefined){ attr.initial = templateJSON[key]; } - $(".user_input_type", trcontext).val(attr.type).change(); $(".user_input_description", trcontext).val(attr.description); + if (attr.mandatory){ + $('.user_input_mandatory', trcontext).attr("checked", "checked"); + } else { + $('.user_input_mandatory', trcontext).removeAttr("checked"); + } + switch(attr.type){ case "number": case "number-float": case "fixed": $("."+attr.type+" input.user_input_initial", trcontext).val(attr.initial); break; - + case "boolean": + if(attr.initial == "YES"){ + $('input#radio_yes', trcontext).attr("checked", "checked"); + $('input#radio_no', trcontext).removeAttr('checked'); + } + else { + $('input#radio_yes', trcontext).removeAttr("checked"); + $('input#radio_no', trcontext).attr("checked", "checked"); + } + break; case "range": case "range-float": var values = attr.params.split(".."); // "2..8" @@ -343,6 +384,7 @@ define(function(require) { switch (attr.type) { case "number": case "number-float": + case "boolean": case "fixed": st += ("| |" + (attr.initial != undefined ? attr.initial : "") ); @@ -605,7 +647,11 @@ define(function(require) { } break; case "password": - input = ''; + input = '
'; + break; + case "boolean": + input = '
' + Locale.tr("YES ") + ''; + input += Locale.tr("NO ") + ''; break; case "number": case "number-float": diff --git a/src/sunstone/public/app/utils/user-inputs/row.hbs b/src/sunstone/public/app/utils/user-inputs/row.hbs index 8c5d4d037d..9d9b8cfb5c 100644 --- a/src/sunstone/public/app/utils/user-inputs/row.hbs +++ b/src/sunstone/public/app/utils/user-inputs/row.hbs @@ -1,4 +1,4 @@ - + @@ -33,6 +34,11 @@ +
+ + {{tr "YES"}} + {{tr "NO"}} +
@@ -78,6 +84,11 @@
+ + + + +
diff --git a/src/sunstone/public/app/utils/user-inputs/table.hbs b/src/sunstone/public/app/utils/user-inputs/table.hbs index 1ac18f199e..4881c91348 100644 --- a/src/sunstone/public/app/utils/user-inputs/table.hbs +++ b/src/sunstone/public/app/utils/user-inputs/table.hbs @@ -1,4 +1,4 @@ - +
diff --git a/src/sunstone/public/bower.json b/src/sunstone/public/bower.json index 83f78e9567..1336c25aec 100644 --- a/src/sunstone/public/bower.json +++ b/src/sunstone/public/bower.json @@ -16,7 +16,8 @@ "jquery": "2.2.3", "datatables": "1.10.12", "navigo": "2.1.1", - "sprintf": "1.0.3" + "sprintf": "1.0.3", + "jquery-ui": "^1.12.1" }, "authors": [ "Daniel Molina ",