From 778f056fd82c7fad0e06211e49c5a95a46bbeac5 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Sat, 28 Mar 2015 21:44:24 +0100 Subject: [PATCH] fgcommand.js: allow setting of multiple properties extend setPropertyValue(path,value,callback,context) if value is 'just a value': set value of property named by path if value is object, assume JsonProperty(ies) and set the entire tree if callback is set, callback gets called after to POST succeeded if context is set, 'this' is set for the callback --- webgui/lib/fgcommand.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/webgui/lib/fgcommand.js b/webgui/lib/fgcommand.js index 1596cceea..14b638aa9 100644 --- a/webgui/lib/fgcommand.js +++ b/webgui/lib/fgcommand.js @@ -186,11 +186,35 @@ }); }, - setPropertyValue : function(path, value) { + setPropertyValue : function(path, value, callback, context) { + if( value == null ) + return; + var url = "/json/" + path; - jquery.post(url, JSON.stringify({ - 'value' : value - })); + switch( typeof(value) ) { + case 'number': + case 'string': + case 'boolean': + jquery.post(url, JSON.stringify({ + 'value' : value + })).done(function(data){ + if( !callback ) return; + if (context) callback.call(context, data.value); + else callback(data.value); + }); + return; + + case 'object': + jquery.post(url, JSON.stringify(value)).done(function(data){ + if( !callback ) return; + if (context) callback.call(context, data.value); + else callback(data.value); + }); + return; + + default: + return; + } }, };