feature(rest) add config

This commit is contained in:
coderaiser 2013-11-04 14:57:01 +00:00
parent ba147191b9
commit edc8b36d42
3 changed files with 43 additions and 2 deletions

View file

@ -109,7 +109,20 @@ var CloudCmd, Util, DOM;
}
function change(event) {
Util.log(event);
var data,
obj = {},
el = event.target,
name = el.id,
type = el.type;
if (el.type === 'checkbox')
data = el.checked;
else
data = el.value;
obj[name] = data;
DOM.RESTful.config(obj);
}
function key(event) {

View file

@ -181,6 +181,15 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
callback : pCallBack
});
};
this.config = function(pData, pCallBack) {
sendRequest({
method : 'PUT',
url : '/config',
data : pData,
callback : pCallBack
});
};
function sendRequest(pParams) {
var lRet = Util.checkObjTrue(pParams, ['method']);

View file

@ -20,6 +20,7 @@
pipe = main.pipe,
CloudFunc = main.cloudfunc,
dir = main.dir,
JSONDIR = main.JSONDIR,
OK = 200,
Header = main.generateHeaders({
name:'api.json'
@ -274,7 +275,8 @@
* @param pParams {command, method, body, requrest, response}
*/
function onPUT(pParams) {
var lRet = main.checkParams(pParams, ['body']);
var name, data, json, config,
lRet = main.checkParams(pParams, ['body']);
if (lRet) {
var p = pParams,
@ -350,6 +352,23 @@
main.sendError(pParams, p.data);
break;
case 'config':
config = main.config;
for (name in lFiles)
config[name] = lFiles[name];
json = Util.stringifyJSON(config) + '\n';
fs.writeFile(JSONDIR + 'config.json', json, function(error) {
if (error)
sendError(pParams, error);
else
sendMsg(pParams, 'config', name);
});
break;
default:
send(pParams);
break;