Skip to content

Instantly share code, notes, and snippets.

@denpamusic
Last active January 18, 2023 00:54
Show Gist options
  • Save denpamusic/6cbe2af44ee02eb22a001b7543438928 to your computer and use it in GitHub Desktop.
Save denpamusic/6cbe2af44ee02eb22a001b7543438928 to your computer and use it in GitHub Desktop.
from eco-mr3020-v3-3.2.3678-em-fda69db834b649919bfeeecd8d955327
function logError(jqXHR, textStatus, errorThrown) {
console.log('Error! ' + textStatus);
console.log(errorThrown);
console.log(jqXHR);
}
var ECOMAX_850P_TYPE = 0;
var ECOMAX_850i_TYPE = 1;
function Controller(destination, ecosrv_address) {
this.destination_ = destination;
this.ecosrvAddress_ = ecosrv_address;
this.protocol_type = '';
this.type_ = 0;
this.setProtocolType = function(t) {
if (typeof t === "string") {
this.protocol_type = t.toLowerCase();
}
};
this.setType = function(t) {
if (typeof t === "number") {
this.type_ = t;
} else {
console.log("Warning: wrong type for Controller.setType()");
}
};
this.getRegParams = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + "regParams",
success: responseMethod,
error: logError
});
return false;
};
this.getRegDataParams = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + "regParamsData",
success: responseMethod,
error: logError
});
return false;
};
this.getEditParams = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + "editParams",
success: responseMethod,
error: logError
});
return false;
};
this.getSysParams = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + "sysParams",
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuLangs = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmLangs?uid=" + encodeURIComponent(updater.currentDevice_) : "rmLangs"),
success: responseMethod,
error: logError
});
return false;
};
this.getCurrentParamsEdits = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmCurrentDataParamsEdits?uid=" + encodeURIComponent(updater.currentDevice_) : "rmCurrentDataParamsEdits"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuParamsNames = function(responseMethod, lang) {
if (lang == null && updater.currentDevice_) {
lang = getRmLang();
}
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmParamsNames?uid=" + encodeURIComponent(updater.currentDevice_) + "&lang=" + encodeURIComponent(lang) : "rmParamsNames"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuCatsNames = function(responseMethod, lang) {
if (lang == null && updater.currentDevice_) {
lang = getRmLang();
}
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmCatsNames?uid=" + encodeURIComponent(updater.currentDevice_) + "&lang=" + encodeURIComponent(lang) : "rmCatsNames"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuParamsUnitsNames = function(responseMethod, lang) {
if (lang == null && updater.currentDevice_) {
lang = getRmLang();
}
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmParamsUnitsNames?uid=" + encodeURIComponent(updater.currentDevice_) + "&lang=" + encodeURIComponent(lang) : "rmParamsUnitsNames"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuParamsEnums = function(responseMethod, lang) {
if (lang == null && updater.currentDevice_) {
lang = getRmLang();
}
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmParamsEnums?uid=" + encodeURIComponent(updater.currentDevice_) + "&lang=" + encodeURIComponent(lang) : "rmParamsEnums"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuLocksNames = function(responseMethod, lang) {
if (lang == null && updater.currentDevice_) {
lang = getRmLang();
}
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmLocksNames?uid=" + encodeURIComponent(updater.currentDevice_) + "&lang=" + encodeURIComponent(lang) : "rmLocksNames"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuStructure = function(responseMethod, lang) {
if (lang == null && updater.currentDevice_) {
lang = getRmLang();
}
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmStructure?uid=" + encodeURIComponent(updater.currentDevice_) + "&lang=" + encodeURIComponent(lang) : "rmStructure"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuCurrDataDisp = function(responseMethod, lang) {
if (lang == null && updater.currentDevice_) {
lang = getRmLang();
}
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmCurrentDataParams?uid=" + encodeURIComponent(updater.currentDevice_) + "&lang=" + encodeURIComponent(lang) : "rmCurrentDataParams"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuParamsData = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmParamsData?uid=" + encodeURIComponent(updater.currentDevice_) : "rmParamsData"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuExistingLangsList = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmExistingLangs?uid=" + encodeURIComponent(updater.currentDevice_) : "rmExistingLangs"),
success: responseMethod,
error: logError
});
return false;
};
this.getWirelessList = function(responseMethod, errorMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + "iwlist",
success: responseMethod,
error: errorMethod
});
return false;
};
this.getRemoteMenuAlarmsNames = function(responseMethod, lang) {
if (lang == null && updater.currentDevice_) {
lang = getRmLang();
}
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmAlarmsNames?uid=" + encodeURIComponent(updater.currentDevice_) + "&lang=" + encodeURIComponent(lang) : "rmAlarmsNames"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuParamsDescs = function(responseMethod, lang) {
if (lang == null && updater.currentDevice_) {
lang = getRmLang();
}
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmParamsDescs?uid=" + encodeURIComponent(updater.currentDevice_) + "&lang=" + encodeURIComponent(lang) : "rmParamsDescs"),
success: responseMethod,
error: logError
});
return false;
};
this.getRemoteMenuCatsDescs = function(responseMethod, lang) {
if (lang == null && updater.currentDevice_) {
lang = getRmLang();
}
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmCatsDescs?uid=" + encodeURIComponent(updater.currentDevice_) + "&lang=" + encodeURIComponent(lang) : "rmCatsDescs"),
success: responseMethod,
error: logError
});
return false;
};
this.getPassword = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "call/run/getServicePassword?uid=" + encodeURIComponent(updater.currentDevice_) : "password"),
success: responseMethod,
error: logError
});
};
this.getETPassword = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "getETservicePasswords?uid=" + encodeURIComponent(updater.currentDevice_) : "etpassword"),
success: responseMethod,
error: logError
});
};
this.updateSoftware = function(responseMethod, errorMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "updateEconet?uid=" + updater.currentDevice_ : "updateSoftware"),
success: responseMethod,
error: errorMethod
});
};
this.checkMainSrvConn = function(responseMethod, errorMethod) {
$.ajax({
type: "GET",
dataType: 'jsonp',
cache: false,
url: "https://" + this.ecosrvAddress_ + "/ecosrv/default/call/run/connEcho?param=" + encodeURIComponent("echo"),
success: responseMethod,
error: errorMethod
});
return false;
};
this.setSysParams = function(network, password, security, regRefresh, responseMethod, errorMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + "setSysParams?" +
(network.length > 0 ? "ssid=" + encodeURIComponent(network) + "&" : "") +
(password.length > 0 ? "password=" + encodeURIComponent(password) + "&" : "") +
"security=" + encodeURIComponent(security) + "&" + "regRefresh=" + encodeURIComponent(regRefresh),
success: responseMethod,
error: errorMethod
});
return false;
};
this.saveParam = function(name, value, responseMethod, errorMethod, bit) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "newParam?uid=" + encodeURIComponent(updater.currentDevice_) + "&" : "newParam?") +
"newParamName=" + encodeURIComponent(name) + "&newParamValue=" + encodeURIComponent(value),
success: responseMethod,
error: errorMethod
});
return false;
};
this.rmSaveParam = function(index, value, responseMethod, errorMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmNewParam?uid=" + encodeURIComponent(updater.currentDevice_) + "&" : "rmNewParam?") +
"newParamIndex=" + encodeURIComponent(index) + "&newParamValue=" + encodeURIComponent(value),
success: responseMethod,
error: errorMethod
});
return false;
};
this.rmSaveCurrParam = function(key, value, responseMethod, errorMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmCurrNewParam?uid=" + encodeURIComponent(updater.currentDevice_) + "&" : "rmCurrNewParam?") +
"newParamKey=" + encodeURIComponent(key) + "&newParamValue=" + encodeURIComponent(value),
success: responseMethod,
error: errorMethod
});
return false;
};
this.rmCheckAccess = function(password, responseMethod, errorMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmAccess?uid=" + encodeURIComponent(updater.currentDevice_) + "&" : "rmAccess?") +
"password=" + encodeURIComponent(password),
success: responseMethod,
error: errorMethod
});
return false;
};
this.rmSaveLang = function(value, responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "rmSaveLang?uid=" + encodeURIComponent(updater.currentDevice_) + "&" : "rmSaveLang?") +
"lang=" + encodeURIComponent(value),
success: responseMethod,
error: logError
});
return false;
};
this.changePassword = function(oldUserName, oldPassword, newUserName, newPassword) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + "changePassword?oldUserName=" + encodeURIComponent(oldUserName) + "&oldPassword=" + encodeURIComponent(oldPassword) +
"&newUserName=" + encodeURIComponent(newUserName) + "&newPassword=" + encodeURIComponent(newPassword),
success: changePasswordResponse,
error: logError
});
};
this.downloadImg = function() {
window.open(this.destination_ + "downloadImg?protocolType=" + this.protocol_type);
};
this.saveSchedules = function(param, mode, value, responseMethod, scheduleDev) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "saveSchedules?uid=" + encodeURIComponent(updater.currentDevice_) + "&" : "setSchedule?") +
"scheduleType=" + encodeURIComponent(param) + "&timeOfWeek=" + encodeURIComponent(mode) + "&values=" + encodeURIComponent(value) + "&scheduleDev=" + encodeURIComponent(scheduleDev),
success: responseMethod,
error: logError
});
return false;
};
this.getSchedules = function(responseMethod) {
$.ajax({
type: "GET",
dataType: 'json',
cache: false,
url: this.destination_ + (updater.currentDevice_ ? "getSchedule?uid=" + encodeURIComponent(updater.currentDevice_) + "&" : "getSchedule?"),
success: responseMethod,
error: logError
});
return false;
};
this.getSchemaFromServer = function(name, responseMethod) {
$.ajax({
type: "GET",
contentType: "text/plain",
dataType: "text",
cache: true,
url: this.destination_ + "getSchemaFromServer?name=" + encodeURIComponent(name),
error: logError,
success: responseMethod,
});
return false;
};
this.checkSoftUpdate = function(protocol, responseMethod) {
$.ajax({
type: "GET",
contentType: "json",
cache: false,
url: this.destination_ + "checkSoftwareUpdate",
error: logError,
success: responseMethod,
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", Cookies.get('csrftoken'));
}
});
return false;
};
this.getEmSchemaFromServer = function(name, responseMethod) {
$.ajax({
type: "GET",
contentType: "text/plain",
dataType: "text",
cache: true,
url: this.destination_ + "getEmSchemaFromServer?name=" + encodeURIComponent(name),
error: logError,
success: responseMethod,
});
return false;
};
this.getEmLogoFromServer = function(name, responseMethod) {
$.ajax({
type: "GET",
contentType: "text/plain",
dataType: "text",
cache: true,
url: this.destination_ + "getProdLogoFromServer?name=" + encodeURIComponent(name),
error: logError,
success: responseMethod,
});
return false;
};
this.runSchemaDownload = function(name, responseMethod) {
$.ajax({
type: "GET",
contentType: "text/plain",
dataType: "text",
cache: true,
url: this.destination_ + "runSchemaDownload?name=" + encodeURIComponent(name),
error: logError,
success: responseMethod,
});
return false;
};
this.getSchemaDirectFromServer = function(name, responseMethod) {
$.ajax({
type: "POST",
contentType: "text/plain",
dataType: "text",
data: {
"name": name,
},
headers: {
Accept: "text/plain",
"Content-Type": "application/x-www-form-urlencoded"
},
cache: true,
url: this.ecosrvAddress_ + "/service/getSchema/",
error: logError,
success: responseMethod,
});
return false;
};
this.getProdLogoDirectFromServer = function(prod_id, responseMethod) {
$.ajax({
type: "POST",
contentType: "text/plain",
dataType: "text",
data: {
"prod_id": prod_id,
},
headers: {
Accept: "text/plain",
"Content-Type": "application/x-www-form-urlencoded"
},
cache: true,
url: this.ecosrvAddress_ + "/service/getProdLogo/",
error: logError,
success: responseMethod,
});
return false;
};
this.getETtranslations = function(ver, client, lang, responseMethod, errorMethod) {
if (client == null || schema.controllerID == null || schema.controllerID == "") {
return false;
errorMethod();
}
$.ajax({
type: "POST",
contentType: "json",
data: {
"ver": ver,
"client": client,
"lang": lang,
"regName": schema.controllerID,
},
headers: {
Accept: "json",
"Content-Type": "application/x-www-form-urlencoded"
},
cache: true,
url: this.ecosrvAddress_ + "/service/getETtranslations/",
error: errorMethod,
success: responseMethod,
});
return false;
};
this.downloadConfig = function() {
$.ajax({
type: "GET",
contentType: "text/plain",
dataType: "text",
cache: true,
url: this.destination_ + "downloadConfig",
error: logError,
});
return false;
};
this.reloadConfigFileCache = function(ver, logo, regname, lang, responseMethod) {
$.ajax({
type: "POST",
contentType: "text/plain",
dataType: "text",
data: {
"ver": ver,
"logo": logo,
"regName": regname,
"lang": lang
},
headers: {
Accept: "text/plain",
"Content-Type": "application/x-www-form-urlencoded"
},
cache: true,
url: this.ecosrvAddress_ + "/service/reloadConfigFileCache/",
error: logError,
success: responseMethod,
});
return false;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment