1
0
Fork 0

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
This commit is contained in:
Torsten Dreyer 2015-03-28 21:44:24 +01:00
parent 8872ca7083
commit 778f056fd8

View file

@ -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;
}
},
};