1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

F #4926 Added boolean type in user inputs (#243)

* F #4926 Added boolean type in user inputs

* F #4926 Added mandatory field

* F #4926 Done order option in user inputs
This commit is contained in:
Abel Coronado 2017-04-07 11:09:19 +02:00 committed by Tino Vázquez
parent b10dc84a2b
commit 63d0b91777
7 changed files with 75 additions and 14 deletions

View File

@ -16,6 +16,8 @@
define(function(require) {
require('jquery');
require('jquery-ui');
require('foundation');
Foundation.Dropdown.defaults.positionClass = 'left';

View File

@ -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',

View File

@ -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));

View File

@ -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 type="password" value="'+value+'" '+wizard_field+' '+required+'/>';
input = '<br><input type="password" value="'+value+'" '+wizard_field+' '+required+'/>';
break;
case "boolean":
input = '<br>' + Locale.tr("YES ") + '<input type="radio" name="bool_' + attr.name + '" value="YES"' + wizard_field + ' ' + required + '/>';
input += Locale.tr("NO ") + '<input type="radio" name="bool_' + attr.name + '" value="NO"' + wizard_field + ' ' + required + '/>';
break;
case "number":
case "number-float":

View File

@ -1,4 +1,4 @@
<tr>
<tr style="border-style: groove; border-width: 0.5px 0">
<td>
<label>{{tr "Name"}}
<input class="user_input_name" type="text" pattern="^\w+$"/>
@ -16,6 +16,7 @@
<option value="range"> {{tr "range"}} </option>
<option value="range-float"> {{tr "range (float)"}} </option>
<option value="list"> {{tr "list"}} </option>
<option value="boolean"> {{tr "boolean"}} </option>
</select>
</label>
</td>
@ -33,6 +34,11 @@
<input type="number" step="any" class="user_input_initial" placeholder="42.5"/>
</label>
</div>
<div class="user_input_type_right boolean">
<label>{{tr "Default value"}}</label>
<input type="radio" step="any" name="bool_{{idInput}}" class="user_input_initial" id="radio_yes" value="YES"> {{tr "YES"}}
<input type="radio" step="any" name="bool_{{idInput}}" class="user_input_initial" id="radio_no" value="NO"> {{tr "NO"}}
</div>
<div class="user_input_type_right range">
<div class="row collapse">
<div class="small-6 columns">
@ -78,6 +84,11 @@
</label>
</div>
</td>
<td>
<label>{{tr "Mandatory"}}</label>
<input checked type="checkbox" name="user_input_mandatory_{{idInput}}" class="switch input user_input_mandatory slaac" id="user_input_mandatory_{{idInput}}" hidden/>
<label class="switch-paddle" for="user_input_mandatory_{{idInput}}"></label>
</td>
<td>
<br/>
<a href="#"><i class="fa fa-times-circle remove-tab"></i></a>

View File

@ -1,4 +1,4 @@
<table class="user_input_attrs policies_table dataTable">
<table class="user_input_attrs policies_table dataTable" style="cursor: pointer;">
<thead>
<tr>
<th style="width:30%"></th>

View File

@ -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 <dmolina@opennebula.org>",