2014-02-04 11:00:32 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Doodle3D project (http://doodle3d.com).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, Doodle3D
|
|
|
|
* This software is licensed under the terms of the GNU GPL v2 or later.
|
|
|
|
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function ConfigAPI() {
|
|
|
|
|
|
|
|
var _wifiboxURL;
|
|
|
|
var _wifiboxCGIBinURL;
|
|
|
|
var _timeoutTime = 3000;
|
|
|
|
var _saveSettingsTimeoutTime = 8000;
|
|
|
|
|
|
|
|
var _self = this;
|
|
|
|
|
|
|
|
this.init = function(wifiboxURL,wifiboxCGIBinURL) {
|
2014-02-04 22:56:58 +01:00
|
|
|
//console.log("ConfigAPI:init");
|
2014-02-04 11:00:32 +01:00
|
|
|
|
|
|
|
_wifiboxURL = wifiboxURL;
|
|
|
|
_wifiboxCGIBinURL = wifiboxCGIBinURL;
|
|
|
|
}
|
|
|
|
this.loadAll = function(completeHandler,failedHandler) {
|
2014-02-04 22:56:58 +01:00
|
|
|
//console.log("ConfigAPI:loadAll");
|
2014-02-04 11:00:32 +01:00
|
|
|
$.ajax({
|
|
|
|
url: _wifiboxURL + "/config/all",
|
|
|
|
type: "GET",
|
|
|
|
dataType: 'json',
|
|
|
|
timeout: _timeoutTime,
|
|
|
|
success: function(response){
|
|
|
|
if(response.status == "error" || response.status == "fail") {
|
2014-02-10 14:44:17 +01:00
|
|
|
if(failedHandler) failedHandler(response);
|
2014-02-04 11:00:32 +01:00
|
|
|
} else {
|
|
|
|
completeHandler(response.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(function() {
|
2014-02-10 14:44:17 +01:00
|
|
|
if(failedHandler) failedHandler();
|
2014-02-04 11:00:32 +01:00
|
|
|
});
|
|
|
|
};
|
2014-02-04 21:06:25 +01:00
|
|
|
this.load = function(targetSettings,completeHandler,failedHandler) {
|
2014-02-04 22:56:58 +01:00
|
|
|
//console.log("ConfigAPI:load");
|
|
|
|
$.ajax({
|
|
|
|
url: _wifiboxURL + "/config/",
|
|
|
|
type: "GET",
|
|
|
|
dataType: 'json',
|
|
|
|
data: targetSettings,
|
|
|
|
timeout: _timeoutTime,
|
|
|
|
success: function(response){
|
|
|
|
if(response.status == "error" || response.status == "fail") {
|
2014-02-10 14:44:17 +01:00
|
|
|
if(failedHandler) failedHandler(response);
|
2014-02-04 22:56:58 +01:00
|
|
|
} else {
|
|
|
|
completeHandler(response.data);
|
2014-02-04 21:06:25 +01:00
|
|
|
}
|
2014-02-04 22:56:58 +01:00
|
|
|
}
|
|
|
|
}).fail(function() {
|
2014-02-10 14:44:17 +01:00
|
|
|
if(failedHandler) failedHandler();
|
2014-02-04 22:56:58 +01:00
|
|
|
});
|
|
|
|
};
|
2014-02-04 11:00:32 +01:00
|
|
|
this.save = function(newSettings,completeHandler,failedHandler) {
|
2014-02-04 22:56:58 +01:00
|
|
|
//console.log("ConfigAPI:save");
|
2014-02-04 11:00:32 +01:00
|
|
|
$.ajax({
|
2014-02-07 14:37:06 +01:00
|
|
|
url: _wifiboxCGIBinURL + "/config",
|
2014-02-04 11:00:32 +01:00
|
|
|
type: "POST",
|
|
|
|
data: newSettings,
|
|
|
|
dataType: 'json',
|
|
|
|
timeout: _saveSettingsTimeoutTime,
|
|
|
|
success: function(response){
|
|
|
|
//console.log("ConfigAPI:save response: ",response);
|
|
|
|
if(response.status == "error" || response.status == "fail") {
|
2014-02-10 14:44:17 +01:00
|
|
|
if(failedHandler) failedHandler(response);
|
2014-02-04 11:00:32 +01:00
|
|
|
} else {
|
|
|
|
completeHandler(response.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(function() {
|
2014-02-10 14:44:17 +01:00
|
|
|
if(failedHandler) failedHandler();
|
2014-02-04 11:00:32 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
this.resetAll = function(completeHandler,failedHandler) {
|
2014-02-04 22:56:58 +01:00
|
|
|
//console.log("ConfigAPI:resetAll");
|
2014-02-04 11:00:32 +01:00
|
|
|
$.ajax({
|
|
|
|
url: _wifiboxCGIBinURL + "/config/resetall",
|
|
|
|
type: "POST",
|
|
|
|
dataType: 'json',
|
|
|
|
timeout: _timeoutTime,
|
|
|
|
success: function(response){
|
|
|
|
if(response.status == "error" || response.status == "fail") {
|
2014-02-10 14:44:17 +01:00
|
|
|
if(failedHandler) failedHandler(response);
|
2014-02-04 11:00:32 +01:00
|
|
|
} else {
|
|
|
|
completeHandler(response.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(function() {
|
2014-02-10 14:44:17 +01:00
|
|
|
if(failedHandler) failedHandler();
|
2014-02-04 11:00:32 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|