LSP: make input type int return numbers instead of strings for .getval()

This commit is contained in:
Cat 2020-05-08 13:32:45 +02:00 committed by Thulinma
parent 000d7afc73
commit fcc61a4b21
2 changed files with 5 additions and 2 deletions

View file

@ -233,8 +233,8 @@ e.validate.indexOf("required")>=0&&e.select.unshift(["","placeholder"in e?"Defau
return e}var d=[],f=["required","optional"];"desc"in a&&d.push({type:"help",help:a.desc});if("sort"in a){var l=[],m;for(m in f)if(a[f[m]])for(var e in a[f[m]]){var q=a[f[m]][e];if(Array.isArray(q))for(var n in q){if(!("validate"in q[n]))q[n].validate=[];q[n].validate=f[m];q[n].id=e;l.push(q[n])}else{if(!("validate"in q))q.validate=[];q.validate.push(f[m]);q.id=e;l.push(q)}}l.sort(function(b,c){return(""+b[a.sort]).localeCompare(c[a.sort])});for(e in l){q=l[e];d.push(c(q.validate,q.id,q))}}else for(m in f)if(a[f[m]]){d.push($("<h4>").text(UI.format.capital(f[m])+ return e}var d=[],f=["required","optional"];"desc"in a&&d.push({type:"help",help:a.desc});if("sort"in a){var l=[],m;for(m in f)if(a[f[m]])for(var e in a[f[m]]){var q=a[f[m]][e];if(Array.isArray(q))for(var n in q){if(!("validate"in q[n]))q[n].validate=[];q[n].validate=f[m];q[n].id=e;l.push(q[n])}else{if(!("validate"in q))q.validate=[];q.validate.push(f[m]);q.id=e;l.push(q)}}l.sort(function(b,c){return(""+b[a.sort]).localeCompare(c[a.sort])});for(e in l){q=l[e];d.push(c(q.validate,q.id,q))}}else for(m in f)if(a[f[m]]){d.push($("<h4>").text(UI.format.capital(f[m])+
" parameters"));for(e in a[f[m]]){q=a[f[m]][e];if(Array.isArray(q))for(n in q)d.push(c(m,e,q[n]));else d.push(c(m,e,q))}}return d},stored:{get:function(){return mist.data.ui_settings||{}},set:function(a,b){var c=this.get();c[a]=b;mist.send(function(){},{ui_settings:c})},del:function(a){delete mist.data.ui_settings[a];mist.send(function(){},{ui_settings:mist.data.ui_settings})}}}; " parameters"));for(e in a[f[m]]){q=a[f[m]][e];if(Array.isArray(q))for(n in q)d.push(c(m,e,q[n]));else d.push(c(m,e,q))}}return d},stored:{get:function(){return mist.data.ui_settings||{}},set:function(a,b){var c=this.get();c[a]=b;mist.send(function(){},{ui_settings:c})},del:function(a){delete mist.data.ui_settings[a];mist.send(function(){},{ui_settings:mist.data.ui_settings})}}};
function log(){try{UI.debug&&[].push.call(arguments,Error().stack);[].unshift.call(arguments,"["+UI.format.time((new Date).getTime()/1E3)+"]");console.log.apply(console,arguments)}catch(a){}} function log(){try{UI.debug&&[].push.call(arguments,Error().stack);[].unshift.call(arguments,"["+UI.format.time((new Date).getTime()/1E3)+"]");console.log.apply(console,arguments)}catch(a){}}
$.fn.getval=function(){var a=$(this).data("opts"),b=$(this).val();if(a&&"type"in a)switch(a.type){case "span":b=$(this).html();break;case "debug":b=$(this).val()==""?null:Number($(this).val());break;case "checkbox":b=$(this).prop("checked");break;case "radioselect":a=$(this).find("label > input[type=radio]:checked").parent();if(a.length){b=[];b.push(a.children("input[type=radio]").val());a=a.children("select");a.length&&b.push(a.val())}else b="";break;case "checklist":b=[];$(this).find(".checklist input[type=checkbox]:checked").each(function(){b.push($(this).attr("name"))}); $.fn.getval=function(){var a=$(this).data("opts"),b=$(this).val();if(a&&"type"in a)switch(a.type){case "int":b!=""&&(b=Number(b));break;case "span":b=$(this).html();break;case "debug":b=$(this).val()==""?null:Number($(this).val());break;case "checkbox":b=$(this).prop("checked");break;case "radioselect":a=$(this).find("label > input[type=radio]:checked").parent();if(a.length){b=[];b.push(a.children("input[type=radio]").val());a=a.children("select");a.length&&b.push(a.val())}else b="";break;case "checklist":b=
break;case "unix":b!=""&&(b=Math.round(new Date($(this).val())/1E3));break;case "selectinput":b=$(this).children("select").first().val();b=="CUSTOM"&&(b=$(this).children("label").first().find(".field_container").children().first().getval());break;case "inputlist":b=[];$(this).children().each(function(){$(this).val()!=""&&b.push($(this).val())});break;case "sublist":b=$(this).data("savelist")}return b}; [];$(this).find(".checklist input[type=checkbox]:checked").each(function(){b.push($(this).attr("name"))});break;case "unix":b!=""&&(b=Math.round(new Date($(this).val())/1E3));break;case "selectinput":b=$(this).children("select").first().val();b=="CUSTOM"&&(b=$(this).children("label").first().find(".field_container").children().first().getval());break;case "inputlist":b=[];$(this).children().each(function(){$(this).val()!=""&&b.push($(this).val())});break;case "sublist":b=$(this).data("savelist")}return b};
$.fn.setval=function(a){var b=$(this).data("opts");$(this).val(a);if(b&&"type"in b)switch(b.type){case "span":$(this).html(a);break;case "checkbox":$(this).prop("checked",a);break;case "geolimited":case "hostlimited":b=$(this).closest(".field_container").data("subUI");if(typeof a=="undefined"||a.length==0)a="-";b.blackwhite.val(a.charAt(0));var a=a.substr(1).split(" "),c;for(c in a)b.values.append(b.prototype.clone(true).val(a[c]));b.blackwhite.trigger("change");break;case "radioselect":if(typeof a== $.fn.setval=function(a){var b=$(this).data("opts");$(this).val(a);if(b&&"type"in b)switch(b.type){case "span":$(this).html(a);break;case "checkbox":$(this).prop("checked",a);break;case "geolimited":case "hostlimited":b=$(this).closest(".field_container").data("subUI");if(typeof a=="undefined"||a.length==0)a="-";b.blackwhite.val(a.charAt(0));var a=a.substr(1).split(" "),c;for(c in a)b.values.append(b.prototype.clone(true).val(a[c]));b.blackwhite.trigger("change");break;case "radioselect":if(typeof a==
"undefined")return $(this);c=$(this).find('label > input[type=radio][value="'+a[0]+'"]').prop("checked",true).parent();a.length>1&&c.children("select").val(a[1]);break;case "checklist":b=$(this).find(".checklist input[type=checkbox]").prop("checked",false);for(c in a)b.filter('[name="'+a[c]+'"]').prop("checked",true);break;case "unix":if(typeof a!="undefined"){a=new Date(Math.round(a)*1E3);a.setMinutes(a.getMinutes()-a.getTimezoneOffset());a=a.toISOString();$(this).val(a.split("Z")[0])}break;case "selectinput":a=== "undefined")return $(this);c=$(this).find('label > input[type=radio][value="'+a[0]+'"]').prop("checked",true).parent();a.length>1&&c.children("select").val(a[1]);break;case "checklist":b=$(this).find(".checklist input[type=checkbox]").prop("checked",false);for(c in a)b.filter('[name="'+a[c]+'"]').prop("checked",true);break;case "unix":if(typeof a!="undefined"){a=new Date(Math.round(a)*1E3);a.setMinutes(a.getMinutes()-a.getTimezoneOffset());a=a.toISOString();$(this).val(a.split("Z")[0])}break;case "selectinput":a===
null&&(a="");var d=false;for(c in b.selectinput){var f;typeof b.selectinput[c]=="string"?f=b.selectinput[c]:typeof b.selectinput[c][0]=="string"&&(f=b.selectinput[c][0]);if(f==a){$(this).children("select").first().val(a);d=true;break}}if(!d){$(this).children("label").first().find(".field_container").children().first().setval(a);$(this).children("select").first().val("CUSTOM").trigger("change")}break;case "inputlist":typeof a=="string"&&(a=[a]);for(c in a)$(this).append($(this).data("newitem")().val(a[c])); null&&(a="");var d=false;for(c in b.selectinput){var f;typeof b.selectinput[c]=="string"?f=b.selectinput[c]:typeof b.selectinput[c][0]=="string"&&(f=b.selectinput[c][0]);if(f==a){$(this).children("select").first().val(a);d=true;break}}if(!d){$(this).children("label").first().find(".field_container").children().first().setval(a);$(this).children("select").first().val("CUSTOM").trigger("change")}break;case "inputlist":typeof a=="string"&&(a=[a]);for(c in a)$(this).append($(this).data("newitem")().val(a[c]));

View file

@ -6953,6 +6953,9 @@ $.fn.getval = function(){
if ((opts) && ('type' in opts)) { if ((opts) && ('type' in opts)) {
var type = opts.type; var type = opts.type;
switch (type) { //exceptions only switch (type) { //exceptions only
case 'int':
if (val != "") { val = Number(val); }
break;
case 'span': case 'span':
val = $(this).html(); val = $(this).html();
break; break;