Commit 76584479 authored by Alain Takoudjou's avatar Alain Takoudjou

[erp5_web_monitoring] fix jslint, remove useless code and use more renderjs and RSVP methods

make all javascript code compliant with jslint
use renderjs declarejob instead of rsvp defer
use RSVP.delay in replacement of setTimeout for background sync
factorise opml add/view gadget and remove global OPMLManage
parent 65570efd
/*global window, rJS, RSVP, Handlebars */ /*global window, rJS, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars) { (function (window, rJS, Handlebars) {
"use strict"; "use strict";
var gadget_klass = rJS(window), var gadget_klass = rJS(window),
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
page_title: "Jump to Object" page_title: "Jump to Object"
}); });
}); });
}); });
}(window, rJS, RSVP, Handlebars)); }(window, rJS, Handlebars));
\ No newline at end of file \ No newline at end of file
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.3579.43071.5205</string> </value> <value> <string>963.29379.61141.36334</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -256,7 +256,7 @@ ...@@ -256,7 +256,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1509121711.67</float> <float>1510669689.61</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -104,7 +104,8 @@ ...@@ -104,7 +104,8 @@
var gadget = this; var gadget = this;
return getHostingData(gadget, param_list[0]) return getHostingData(gadget, param_list[0])
.push(function (result) { .push(function (result) {
var i, value, len = result.data.total_rows; var i,
len = result.data.total_rows;
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
if (result.data.rows[i].value.hasOwnProperty("date")) { if (result.data.rows[i].value.hasOwnProperty("date")) {
result.data.rows[i].value.date = { result.data.rows[i].value.date = {
...@@ -171,7 +172,7 @@ ...@@ -171,7 +172,7 @@
lines_limit; lines_limit;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.getSetting("listbox_lines_limit", 100); return gadget.getSetting("listbox_lines_limit", 20);
}) })
.push(function (listbox_lines_limit) { .push(function (listbox_lines_limit) {
lines_limit = listbox_lines_limit; lines_limit = listbox_lines_limit;
...@@ -224,7 +225,7 @@ ...@@ -224,7 +225,7 @@
} }
}); });
}) })
.push(function (result) { .push(function () {
return gadget.updateHeader({ return gadget.updateHeader({
page_title: "Hosting Subscriptions Status", page_title: "Hosting Subscriptions Status",
filter_action: true filter_action: true
......
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.19077.52757.17169</string> </value> <value> <string>963.27984.14453.52343</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510052055.87</float> <float>1510766156.1</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, document, Handlebars, Rusha */ /*global window, rJS, document, RSVP, Rusha, escape */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, document, Handlebars, Rusha) { (function (window, rJS, document, RSVP, Rusha, escape) {
"use strict"; "use strict";
var gadget_klass = rJS(window), var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
rusha = new Rusha(); rusha = new Rusha();
function generateHash(str) { function generateHash(str) {
...@@ -41,7 +40,9 @@ ...@@ -41,7 +40,9 @@
}) })
.push(function () { .push(function () {
var result = gadget.state.instance_dict, var result = gadget.state.instance_dict,
i, value, len = result.data.total_rows; i,
value,
len = result.data.total_rows;
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
if (result.data.rows[i].value.hasOwnProperty("date")) { if (result.data.rows[i].value.hasOwnProperty("date")) {
value = new Date(result.data.rows[i].value.date); value = new Date(result.data.rows[i].value.date);
...@@ -91,8 +92,8 @@ ...@@ -91,8 +92,8 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this; var gadget = this;
return gadget.updateHeader({ return gadget.updateHeader({
title: 'Hosting Subscriptions View' title: 'Hosting Subscriptions View'
}) })
.push(function () { .push(function () {
return gadget.jio_get(options.opml_key); return gadget.jio_get(options.opml_key);
}) })
...@@ -101,8 +102,8 @@ ...@@ -101,8 +102,8 @@
}) })
.push(function () { .push(function () {
return gadget.jio_allDocs({ return gadget.jio_allDocs({
query: '(portal_type:"opml-outline") AND (parent_id:"' + query: '(portal_type:"opml-outline") AND (parent_id:"' +
generateHash(options.opml_key) + '")' generateHash(options.opml_key) + '")'
}); });
}) })
.push(function (ouline_list) { .push(function (ouline_list) {
...@@ -122,28 +123,28 @@ ...@@ -122,28 +123,28 @@
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function (result_list) { .push(function (result_list) {
var i, var j,
ok_to_save = true, ok_to_save = true,
promise_list = []; return_list = [];
for (i = 0; i < result_list.length; i += 1) { for (j = 0; j < result_list.length; j += 1) {
if (result_list[i].status !== 'OK') { if (result_list[j].status !== 'OK') {
ok_to_save = false; ok_to_save = false;
break; break;
} }
promise_list.push(gadget.props.parameter_form_list[i].saveContent()); return_list.push(gadget.props.parameter_form_list[j].saveContent());
} }
if (ok_to_save) { if (ok_to_save) {
return RSVP.all(promise_list); return RSVP.all(return_list);
} }
// One of storage failed, cancel save to be consistent // One of storage failed, cancel save to be consistent
return result_list; return result_list;
}) })
.push(function (result_list) { .push(function (result_list) {
var msg_list = [], var msg_list = [],
i; j;
for (i = 0; i < result_list.length; i += 1) { for (j = 0; j < result_list.length; j += 1) {
if (result_list[i].status !== "OK") { if (result_list[j].status !== "OK") {
msg_list.push(result_list[i].stage + " from " + result_list[i].url); msg_list.push(result_list[j].stage + " from " + result_list[j].url);
} }
} }
if (msg_list.length > 0) { if (msg_list.length > 0) {
...@@ -172,7 +173,6 @@ ...@@ -172,7 +173,6 @@
} }
if (modification_dict.hasOwnProperty('instance_dict')) { if (modification_dict.hasOwnProperty('instance_dict')) {
// render parameter form // render parameter form
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var promise_list = [], var promise_list = [],
...@@ -190,12 +190,10 @@ ...@@ -190,12 +190,10 @@
element.appendChild(gadget_element); element.appendChild(gadget_element);
promise_list.push( promise_list.push(
gadget.declareGadget("gadget_officejs_monitoring_parameter_view.html", gadget.declareGadget("gadget_officejs_monitoring_parameter_view.html",
{ {element: gadget_element,
element: gadget_element,
scope: 'p_' + gadget.state.instance_dict.data.rows[i].id, scope: 'p_' + gadget.state.instance_dict.data.rows[i].id,
sandbox: "public" sandbox: "public"}
} )
)
); );
} }
return RSVP.all(promise_list); return RSVP.all(promise_list);
...@@ -224,13 +222,13 @@ ...@@ -224,13 +222,13 @@
}) })
.push(function (form_list) { .push(function (form_list) {
var column_list = [ var column_list = [
['title', 'Instance Title'], ['title', 'Instance Title'],
['date', 'Status Date'], ['date', 'Status Date'],
['status', 'Status'] ['status', 'Status']
], ],
j, j,
key_list = [], key_list = [],
instance_query = '(portal_type:"global")'; instance_query = '(portal_type:"global")';
if (gadget.state.ouline_list.length === 0) { if (gadget.state.ouline_list.length === 0) {
return; return;
...@@ -309,4 +307,4 @@ ...@@ -309,4 +307,4 @@
}); });
}); });
}(window, rJS, document, Handlebars, Rusha)); }(window, rJS, document, RSVP, Rusha, escape));
\ No newline at end of file \ No newline at end of file
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.20929.61143.52155</string> </value> <value> <string>963.27984.14453.52343</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510216762.18</float> <float>1510586789.54</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser, /*global window, rJS, RSVP, jsen, Handlebars, atob, btoa, DOMParser,
URLSearchParams */ URLSearchParams */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser, (function (window, rJS, RSVP, jsen, Handlebars, atob, btoa, DOMParser,
URLSearchParams) { URLSearchParams) {
"use strict"; "use strict";
...@@ -22,14 +22,14 @@ ...@@ -22,14 +22,14 @@
select_list: ["basic_login", "url", "title", "active"], select_list: ["basic_login", "url", "title", "active"],
query: '(portal_type:"opml")' query: '(portal_type:"opml")'
}) })
.push(function (opml_result) { .push(function (opml_result) {
var i, var i,
opml_dict = {opml_description_list: []}; opml_dict = {opml_description_list: []};
for (i = 0; i < opml_result.data.total_rows; i += 1) { for (i = 0; i < opml_result.data.total_rows; i += 1) {
opml_dict.opml_description_list.push(opml_result.data.rows[i].value); opml_dict.opml_description_list.push(opml_result.data.rows[i].value);
} }
return opml_dict; return opml_dict;
}); });
} }
function validateJsonConfiguration(json_value, uses_old_schema) { function validateJsonConfiguration(json_value, uses_old_schema) {
...@@ -139,7 +139,7 @@ ...@@ -139,7 +139,7 @@
var is_old_schema = false; var is_old_schema = false;
gadget.state.message.textContent = ""; gadget.state.message.textContent = "";
return new RSVP.Queue() return new RSVP.Queue()
.push(function (form_doc) { .push(function () {
var configuration_dict; var configuration_dict;
if (typeof config === 'string') { if (typeof config === 'string') {
try { try {
...@@ -231,14 +231,13 @@ ...@@ -231,14 +231,13 @@
} }
return true; return true;
}); });
} else {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Error: Content is not a valid Monitoring Json configuration!'
});
return false;
} }
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Error: Content is not a valid Monitoring Json configuration!'
});
return false;
}) })
.push(function (status) { .push(function (status) {
if (status) { if (status) {
...@@ -297,13 +296,13 @@ ...@@ -297,13 +296,13 @@
limit = 100; limit = 100;
} }
return gadget.state.erp5_gadget.allDocs({ return gadget.state.erp5_gadget.allDocs({
query: '(portal_type:"Hosting Subscription") AND (validation_state:"validated")', query: '(portal_type:"Hosting Subscription") AND (validation_state:"validated")',
select_list: ['title', 'default_predecessor_uid', 'uid'], select_list: ['title', 'default_predecessor_uid', 'uid'],
limit: [0, limit], limit: [0, limit],
sort_on: [ sort_on: [
["creation_date", "descending"] ["creation_date", "descending"]
] ]
}) })
.push(function (result) { .push(function (result) {
var i, var i,
uid_search_list = []; uid_search_list = [];
...@@ -530,9 +529,7 @@ ...@@ -530,9 +529,7 @@
}); });
}) })
.push(function () { .push(function () {
var hosting_subscription_list = [], var has_failed = false;
has_failed = false,
uid_dict = {};
if (gadget.state.sync === "erp5" && gadget.state.storage_url) { if (gadget.state.sync === "erp5" && gadget.state.storage_url) {
// start import from erp5 now // start import from erp5 now
return gadget.notifySubmitting() return gadget.notifySubmitting()
...@@ -548,8 +545,7 @@ ...@@ -548,8 +545,7 @@
.push(function (select_limit) { .push(function (select_limit) {
return getInstanceOPMLListFromMaster(gadget, select_limit); return getInstanceOPMLListFromMaster(gadget, select_limit);
}) })
.push(undefined, function (error) { .push(undefined, function () {
console.log(error);
gadget.state.message gadget.state.message
.innerHTML = notify_msg_template({ .innerHTML = notify_msg_template({
status: 'error', status: 'error',
...@@ -593,12 +589,11 @@ ...@@ -593,12 +589,11 @@
message: "Failed to import Configurations", message: "Failed to import Configurations",
status: "error" status: "error"
}); });
} else {
return gadget.notifySubmitted({
message: "Configuration Saved!",
status: "success"
});
} }
return gadget.notifySubmitted({
message: "Configuration Saved!",
status: "success"
});
}) })
.push(function () { .push(function () {
if (!has_failed) { if (!has_failed) {
...@@ -611,5 +606,4 @@ ...@@ -611,5 +606,4 @@
} }
}); });
}); });
}(window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser, }(window, rJS, RSVP, jsen, Handlebars, atob, btoa, DOMParser, URLSearchParams));
URLSearchParams));
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.21850.42337.9796</string> </value> <value> <string>963.27920.40078.20411</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510219191.94</float> <float>1510582176.99</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -40,8 +40,7 @@ ...@@ -40,8 +40,7 @@
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function (result_list) { .push(function (result_list) {
var i, var tab_list = [];
tab_list = [];
tab_list.push({ tab_list.push({
title: options.view_title || options.jio_key, title: options.view_title || options.jio_key,
......
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.1691.38549.3618</string> </value> <value> <string>963.27666.8050.30907</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -256,7 +256,7 @@ ...@@ -256,7 +256,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1509095381.18</float> <float>1510581537.14</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -9,20 +9,15 @@ ...@@ -9,20 +9,15 @@
<script src="rsvp.js"></script> <script src="rsvp.js"></script>
<script src="renderjs.js"></script> <script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_officejs_monitoring_global.js"></script>
<script src="gadget_erp5_page_ojsm_opml_add.js"></script> <script src="gadget_erp5_page_ojsm_opml_add.js"></script>
<script id="template-message-error" type="text/x-handlebars-template">
<p><span class='ui-text-{{status}}'>{{message}}</span></p>
</script>
</head> </head>
<body> <body>
<div data-gadget-url="gadget_officejs_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div>
<form class="save_form ui-body-c" novalidate> <form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline <button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button> ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div class="ui-message-alert"></div> <div data-gadget-url="gadget_officejs_monitoring_opml_edit.html"
data-gadget-scope="opml_gadget" data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_erp5_form.html" <div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view" data-gadget-scope="form_view"
data-gadget-sandbox="public"> data-gadget-sandbox="public">
......
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.1898.2167.63078</string> </value> <value> <string>963.27666.8050.30907</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1509020790.01</float> <float>1510675648.98</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, Handlebars, OPMLManage */ /*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, OPMLManage) { (function (window, rJS, RSVP) {
"use strict"; "use strict";
var gadget_klass = rJS(window), rJS(window)
templater = gadget_klass.__template_element,
notify_msg_template = Handlebars.compile(
templater.getElementById("template-message-error").innerHTML
),
opml_global = OPMLManage;
gadget_klass
/////////////////////////////
// state
/////////////////////////////
.setState({
message: "",
redirect: true
})
/////////////////////////////
// ready
/////////////////////////////
.ready(function (gadget) {
return opml_global.init(gadget, notify_msg_template);
})
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -31,7 +12,6 @@ ...@@ -31,7 +12,6 @@
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting") .declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted') .declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
...@@ -40,49 +20,29 @@ ...@@ -40,49 +20,29 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.onEvent('submit', function () { .onEvent('submit', function () {
var gadget = this, var gadget = this,
opml_gadget,
doc; doc;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.getDeclaredGadget('form_view'); return gadget.getDeclaredGadget('opml_gadget');
})
.push(function (g) {
opml_gadget = g;
return gadget.getDeclaredGadget('form_view');
}) })
.push(function (form_gadget) { .push(function (form_gadget) {
return form_gadget.getContent(); return form_gadget.getContent();
}) })
.push(function (form_doc) { .push(function (form_doc) {
doc = form_doc; doc = form_doc;
if (!opml_global.validateHttpUrl(form_doc.url)) { return opml_gadget.checkOPMLForm(doc);
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: "'" + form_doc.url + "' is not a valid OPML URL"
});
return false;
}
if (!form_doc.username || !form_doc.password) {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Username and password fields are required!'
});
return false;
}
if (form_doc.new_password &&
form_doc.new_password !== form_doc.confirm_new_password) {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'The new password and it confirmation are differents!'
});
return false;
}
return true;
}) })
.push(function (state) { .push(function (state) {
if (state) { if (state) {
return gadget.notifySubmitting() return gadget.notifySubmitting()
.push(function () { .push(function () {
doc.title = ""; doc.title = "";
return opml_global.saveOPML(doc, true); return opml_gadget.saveOPML(doc, true);
}) })
.push(function (status) { .push(function (status) {
var msg = {message: 'OPML document added', status: 'success'}; var msg = {message: 'OPML document added', status: 'success'};
...@@ -95,10 +55,10 @@ ...@@ -95,10 +55,10 @@
]); ]);
}) })
.push(function (result_list) { .push(function (result_list) {
if (result_list[1] && gadget.state.redirect) { if (result_list[1]) {
return gadget.redirect({ return gadget.redirect({
"command": "change", "command": "display",
"options": {"page": "ojsm_status_list"} "options": {"page": "settings_configurator"}
}); });
} }
}); });
...@@ -169,13 +129,13 @@ ...@@ -169,13 +129,13 @@
}, },
"my_active": { "my_active": {
"description": "Sync this opml or not", "description": "Sync this opml or not",
"title": "Active (Auto Sync)", "title": "Active (Enable Sync)",
"default": 1, "default": 1,
"css_class": "", "css_class": "",
"required": 1, "required": 1,
"editable": 1, "editable": 1,
"key": "active", "key": "active",
"hidden": 1, "hidden": 0,
"type": "CheckBoxField" "type": "CheckBoxField"
}, },
"my_new_password": { "my_new_password": {
...@@ -199,7 +159,7 @@ ...@@ -199,7 +159,7 @@
"key": "confirm_new_password", "key": "confirm_new_password",
"hidden": (options.chg_passwd || '' === true) ? 0 : 1, "hidden": (options.chg_passwd || '' === true) ? 0 : 1,
"type": "PasswordField" "type": "PasswordField"
}, }
}}, }},
"_links": { "_links": {
"type": { "type": {
...@@ -236,4 +196,4 @@ ...@@ -236,4 +196,4 @@
}); });
}); });
}); });
}(window, rJS, RSVP, Handlebars, OPMLManage)); }(window, rJS, RSVP));
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.21318.32760.12475</string> </value> <value> <string>963.29486.6222.37785</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510217057.28</float> <float>1510676454.74</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, Handlebars */ /*global window, rJS */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars) { (function (window, rJS) {
"use strict"; "use strict";
rJS(window) rJS(window)
...@@ -29,4 +29,4 @@ ...@@ -29,4 +29,4 @@
}}); }});
}); });
}); });
}(window, rJS, RSVP, Handlebars)); }(window, rJS));
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.20929.61143.52155</string> </value> <value> <string>963.27666.8050.30907</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510231849.59</float> <float>1510581396.39</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<script src="rsvp.js"></script> <script src="rsvp.js"></script>
<script src="renderjs.js"></script> <script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script id="infobox-widget-template" type="text/x-handlebars-template"> <script id="infobox-widget-template" type="text/x-handlebars-template">
{{#each resource_list}} {{#each resource_list}}
......
...@@ -243,7 +243,7 @@ ...@@ -243,7 +243,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.22427.36654.49664</string> </value> <value> <string>963.27666.8050.30907</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -261,7 +261,7 @@ ...@@ -261,7 +261,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510327379.3</float> <float>1510669287.69</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -56,9 +56,7 @@ ...@@ -56,9 +56,7 @@
}); });
}) })
.push(function () { .push(function () {
var key, return gadget.property_dict.jio_gadget.createJio({
promise_list = [];
gadget.property_dict.jio_gadget.createJio({
type: "webhttp", type: "webhttp",
// XXX fix URL // XXX fix URL
url: (gadget.state.opml_outline.url url: (gadget.state.opml_outline.url
...@@ -66,14 +64,16 @@ ...@@ -66,14 +64,16 @@
'documents/'), 'documents/'),
basic_login: gadget.state.opml.basic_login basic_login: gadget.state.opml.basic_login
}); });
})
.push(function () {
return gadget.property_dict.jio_gadget return gadget.property_dict.jio_gadget
.get(gadget.property_dict.monitor_process_state); .get(gadget.property_dict.monitor_process_state);
}) })
.push(undefined, function (error) { .push(undefined, function () {
return gadget.notifySubmitted({ return gadget.notifySubmitted({
message: "Error: Failed to download data files!", message: "Error: Failed to download data files!",
status: "error" status: "error"
}) })
.push(function () { .push(function () {
return undefined; return undefined;
}); });
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted') .declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.allowPublicAcquisition("jio_allDocs", function (param_list) { .allowPublicAcquisition("jio_allDocs", function () {
var gadget = this, var gadget = this,
result = {data: {total_rows: 0, rows: []}}; result = {data: {total_rows: 0, rows: []}};
return gadget.property_dict.jio_gadget.get(gadget.property_dict.process_state) return gadget.property_dict.jio_gadget.get(gadget.property_dict.process_state)
...@@ -222,16 +222,22 @@ ...@@ -222,16 +222,22 @@
return gadget.property_dict.jio_gadget return gadget.property_dict.jio_gadget
.get(gadget.property_dict.monitor_process_state) .get(gadget.property_dict.monitor_process_state)
.push(undefined, function () { .push(undefined, function () {
return undefined; return gadget.notifySubmitted({
message: "Error: Failed to download data files!",
status: "error"
}) })
.push(function (average_result) { .push(function () {
if (average_result !== undefined) { return undefined;
return gadget.changeState({ });
average_state: average_result })
}); .push(function (average_result) {
} if (average_result !== undefined) {
}); return gadget.changeState({
average_state: average_result
});
}
});
}, 65000); }, 65000);
}(window, rJS, RSVP, Handlebars)); }(window, rJS, RSVP, Handlebars));
\ No newline at end of file
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.22187.48632.58282</string> </value> <value> <string>963.29300.23681.7082</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510239168.21</float> <float>1510669789.68</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, console */ /*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, console) { (function (window, rJS, RSVP) {
"use strict"; "use strict";
var gadget_klass = rJS(window); var gadget_klass = rJS(window);
function getDateWindow(data) {
var max_date,
begin_date,
end_date,
date_window = [];
if (data.length > 0) {
max_date = data[data.length - 1].split(',')[0];
begin_date = new Date(max_date);
end_date = new Date(max_date);
begin_date.setHours(begin_date.getHours() - 2);
date_window = [Date.parse(begin_date), Date.parse(end_date)];
}
return date_window;
}
function loadGraphData(gadget, key) { function loadGraphData(gadget, key) {
var resource_key = gadget.property_dict.ressource_dict[key]; var resource_key = gadget.property_dict.resource_dict[key];
return gadget.property_dict.jio_gadget.get(resource_key) return gadget.property_dict.jio_gadget.get(resource_key)
.push(undefined, function () { .push(undefined, function () {
return gadget.notifySubmitted({ return gadget.notifySubmitted({
message: "Error: Failed to download resource file '" + resource_key + message: "Error: Failed to download resource file '" + resource_key +
"' from URL: " + gadget.state.opml_outline.url, "' from URL: " + gadget.state.opml_outline.url,
status: "error" status: "error"
}) })
.push(function () { .push(function () {
return {data: []}; return {data: []};
}); });
...@@ -103,28 +117,15 @@ ...@@ -103,28 +117,15 @@
}; };
} }
function getDateWindow(data) {
var max_date,
begin_date,
end_date,
date_window = [];
if (data.length > 0) {
max_date = data[data.length - 1].split(',')[0];
begin_date = new Date(max_date);
end_date = new Date(max_date);
begin_date.setHours(begin_date.getHours() - 2);
date_window = [Date.parse(begin_date), Date.parse(end_date)];
}
return date_window;
}
function updateGraph(gadget) { function updateGraph(gadget) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var key, var key,
promise_list = []; promise_list = [];
for (key in gadget.property_dict.ressource_dict) { for (key in gadget.property_dict.resource_dict) {
promise_list.push(loadGraphData(gadget, key)); if (gadget.property_dict.resource_dict.hasOwnProperty(key)) {
promise_list.push(loadGraphData(gadget, key));
}
} }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
...@@ -136,8 +137,7 @@ ...@@ -136,8 +137,7 @@
var data_list = [], var data_list = [],
axis_dict = {}, axis_dict = {},
line_list, line_list,
i, i;
j;
axis_dict = { axis_dict = {
"0": { "0": {
...@@ -259,8 +259,7 @@ ...@@ -259,8 +259,7 @@
}) })
.ready(function (gadget) { .ready(function (gadget) {
gadget.property_dict = {}; gadget.property_dict = {};
gadget.property_dict.render_deferred = RSVP.defer(); gadget.property_dict.resource_dict = {
gadget.property_dict.ressource_dict = {
memory_resource: "monitor_resource_memory.data", memory_resource: "monitor_resource_memory.data",
cpu_resource: "monitor_resource_process.data", cpu_resource: "monitor_resource_process.data",
io_resource: "monitor_resource_io.data" io_resource: "monitor_resource_io.data"
...@@ -276,7 +275,6 @@ ...@@ -276,7 +275,6 @@
return gadget.getDeclaredGadget("graph_cpu") return gadget.getDeclaredGadget("graph_cpu")
.push(function (graph_cpu) { .push(function (graph_cpu) {
gadget.property_dict.graph_cpu = graph_cpu; gadget.property_dict.graph_cpu = graph_cpu;
gadget.property_dict.graph_cpu_label_list = [];
}); });
}) })
.ready(function (gadget) { .ready(function (gadget) {
...@@ -333,7 +331,7 @@ ...@@ -333,7 +331,7 @@
gadget.property_dict.mem_data = {data: []}; gadget.property_dict.mem_data = {data: []};
gadget.property_dict.process_data = {data: []}; gadget.property_dict.process_data = {data: []};
gadget.property_dict.io_data = {data: []}; gadget.property_dict.io_data = {data: []};
return gadget.property_dict.render_deferred.resolve(); return gadget.deferUpdateGraph();
}); });
}) })
...@@ -349,9 +347,9 @@ ...@@ -349,9 +347,9 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared service // declared service
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareService(function () { .declareJob("deferUpdateGraph", function () {
var gadget = this,
date_window = []; return updateGraph(this);
/*function toggleSerieVisibility(evt) { /*function toggleSerieVisibility(evt) {
var checkbox = evt.target.nextSibling, var checkbox = evt.target.nextSibling,
...@@ -367,10 +365,6 @@ ...@@ -367,10 +365,6 @@
}); });
}*/ }*/
return new RSVP.Queue()
.push(function () {
return gadget.property_dict.render_deferred.promise;
})
/**.push(function () { /**.push(function () {
return gadget.property_dict.graph_cpu.render( return gadget.property_dict.graph_cpu.render(
gadget.property_dict.process_data.data.join('\n'), gadget.property_dict.process_data.data.join('\n'),
...@@ -434,9 +428,6 @@ ...@@ -434,9 +428,6 @@
RSVP.all(promise_list); RSVP.all(promise_list);
return updateGraphTimer(); return updateGraphTimer();
})**/ })**/
.push(function () {
return updateGraph(gadget);
});
}); });
}(window, rJS, RSVP, console)); }(window, rJS, RSVP));
\ No newline at end of file \ No newline at end of file
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.22199.29933.17390</string> </value> <value> <string>963.27984.14453.52343</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510239154.52</float> <float>1510651329.34</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.getSetting("listbox_lines_limit", 100); return gadget.getSetting("listbox_lines_limit", 20);
}) })
.push(function (listbox_lines_limit) { .push(function (listbox_lines_limit) {
lines_limit = listbox_lines_limit; lines_limit = listbox_lines_limit;
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
} }
}); });
}) })
.push(function (result) { .push(function () {
return gadget.updateHeader({ return gadget.updateHeader({
page_title: "Software Instances Status", page_title: "Software Instances Status",
filter_action: true filter_action: true
...@@ -147,7 +147,6 @@ ...@@ -147,7 +147,6 @@
.onLoop(function () { .onLoop(function () {
var gadget = this; var gadget = this;
console.log("ONloop...");
return gadget.getSetting('latest_sync_time') return gadget.getSetting('latest_sync_time')
.push(function (latest_sync_time) { .push(function (latest_sync_time) {
if (latest_sync_time > gadget.state.latest_reload_time) { if (latest_sync_time > gadget.state.latest_reload_time) {
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.19079.34809.6058</string> </value> <value> <string>963.27984.14453.52343</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510051687.96</float> <float>1510766173.29</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
} }
}) })
.push(function () { .push(function () {
return gadget.getSetting("listbox_lines_limit", 50); return gadget.getSetting("listbox_lines_limit", 20);
}) })
.push(function (listbox_lines_limit) { .push(function (listbox_lines_limit) {
lines_limit = listbox_lines_limit; lines_limit = listbox_lines_limit;
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
} }
}); });
}) })
.push(function (result) { .push(function () {
return gadget.updateHeader({ return gadget.updateHeader({
page_title: "Monitoring Promises Status", page_title: "Monitoring Promises Status",
filter_action: true filter_action: true
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.16563.15280.46899</string> </value> <value> <string>963.27984.14453.52343</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510052474.13</float> <float>1510766112.11</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -13,17 +13,20 @@ ...@@ -13,17 +13,20 @@
.declareMethod("render", function () { .declareMethod("render", function () {
var gadget = this; var gadget = this;
return this.updateHeader({ return this.updateHeader({
page_title: "Monitoring Synchronization" page_title: "Monitoring Synchronization"
}) })
.push(function () { .push(function () {
return gadget.getDeclaredGadget('sync_gadget') return gadget.getDeclaredGadget('sync_gadget')
.push(function (sync_gadget) { .push(function (sync_gadget) {
// start synchronization now if possible (not running already) // start synchronization now if possible (not running already)
return sync_gadget.registerSync({now: true}); return sync_gadget.register({now: true});
}); });
}) })
.push(function () { .push(function () {
gadget.redirect({command: "change", options: {page: "ojsm_status_list"}}); return gadget.redirect({
command: "change",
options: {page: "ojsm_status_list"}
});
}); });
}); });
}(window, rJS)); }(window, rJS));
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>962.53085.48571.55790</string> </value> <value> <string>963.29336.22296.43468</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1508159965.22</float> <float>1510668189.54</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -9,22 +9,17 @@ ...@@ -9,22 +9,17 @@
<script src="rsvp.js"></script> <script src="rsvp.js"></script>
<script src="renderjs.js"></script> <script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_officejs_monitoring_global.js"></script>
<script src="gadget_officejs_jio_opml_view.js"></script> <script src="gadget_officejs_jio_opml_view.js"></script>
<script id="template-message-error" type="text/x-handlebars-template">
<p><span class='ui-text-{{status}}'>{{message}}</span></p>
</script>
</head> </head>
<body> <body>
<div data-gadget-url="gadget_officejs_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div>
<div class="template-view"></div> <div class="template-view"></div>
<form class="save_form ui-body-c" novalidate> <form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline <button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button> ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div class="ui-message-alert"></div> <div data-gadget-url="gadget_officejs_monitoring_opml_edit.html"
data-gadget-scope="opml_gadget" data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_erp5_form.html" <div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view" data-gadget-scope="form_view"
data-gadget-sandbox="public"> data-gadget-sandbox="public">
......
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.1858.13217.15684</string> </value> <value> <string>963.29465.32349.33501</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1509018559.06</float> <float>1510675412.13</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, Handlebars, OPMLManage */ /*global window, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, OPMLManage) { (function (window, rJS, RSVP) {
"use strict"; "use strict";
var gadget_klass = rJS(window), rJS(window)
templater = gadget_klass.__template_element,
notify_msg_template = Handlebars.compile(
templater.getElementById("template-message-error").innerHTML
),
opml_global = OPMLManage;
gadget_klass
/////////////////////////////
// state
/////////////////////////////
.setState({
message: "",
redirect: false
})
/////////////////////////////
// ready
/////////////////////////////
.ready(function (gadget) {
return opml_global.init(gadget, notify_msg_template);
})
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader") .declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting") .declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted') .declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
...@@ -40,47 +18,39 @@ ...@@ -40,47 +18,39 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.onEvent('submit', function () { .onEvent('submit', function () {
var gadget = this, var gadget = this,
doc; doc,
opml_gadget;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.getDeclaredGadget('form_view'); return gadget.getDeclaredGadget('opml_gadget');
})
.push(function (g) {
opml_gadget = g;
return gadget.getDeclaredGadget('form_view');
}) })
.push(function (form_gadget) { .push(function (form_gadget) {
return form_gadget.getContent(); return form_gadget.getContent();
}) })
.push(function (form_doc) { .push(function (form_doc) {
doc = form_doc; doc = form_doc;
if (!opml_global.validateHttpUrl(form_doc.url)) {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: "'" + form_doc.url + "' is not a valid OPML URL"
});
return false;
}
if (!form_doc.username || !form_doc.password) {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Username and password fields are required!'
});
return false;
}
if (doc.password !== gadget.state.password) { if (doc.password !== gadget.state.password) {
// password was modified, update on backend // password was modified, update on backend
doc.new_password = doc.password; doc.new_password = doc.password;
doc.confirm_new_password = doc.new_password;
doc.password = gadget.state.password; doc.password = gadget.state.password;
doc.verify_password = 1; doc.verify_password = 1;
} }
return true; return opml_gadget.checkOPMLForm(doc);
}) })
.push(function (state) { .push(function (state) {
if (state) { if (state) {
return gadget.notifySubmitting() return gadget.notifySubmitting()
.push(function () { .push(function () {
doc.title = gadget.state.opml_title; doc.title = gadget.state.opml_title;
return opml_global.saveOPML(doc, return opml_gadget.saveOPML(
doc.title === "" || doc.title === undefined || doc.verify_password === 1); doc,
doc.title === "" || doc.title === undefined || doc.verify_password === 1
);
}) })
.push(function (status) { .push(function (status) {
var msg = {message: 'Document Updated', status: 'success'}; var msg = {message: 'Document Updated', status: 'success'};
...@@ -92,11 +62,10 @@ ...@@ -92,11 +62,10 @@
status status
]); ]);
}) })
.push(function (result_list) { .push(function (result) {
if (result_list[1] && gadget.state.redirect) { if (result[1]) {
return gadget.redirect({ return gadget.changeState({
"command": "change", "password": doc.password
"options": {"page": "ojsm_status_list"}
}); });
} }
}); });
...@@ -224,7 +193,7 @@ ...@@ -224,7 +193,7 @@
}); });
}) })
.push(function () { .push(function () {
return gadget.changeState({redirect: false}) return new RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getUrlFor({command: 'history_previous'}), gadget.getUrlFor({command: 'history_previous'}),
...@@ -258,4 +227,4 @@ ...@@ -258,4 +227,4 @@
}); });
}); });
}); });
}(window, rJS, RSVP, Handlebars, OPMLManage)); }(window, rJS, RSVP));
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.21293.17700.853</string> </value> <value> <string>963.29546.42896.22118</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510185606.72</float> <float>1510680193.17</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, Handlebars, RegExp */ /*global window, rJS, RSVP, Handlebars, RegExp, document, atob */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, RegExp) { (function (window, rJS, RSVP, Handlebars, RegExp, document, atob) {
"use strict"; "use strict";
var gadget_klass = rJS(window), var gadget_klass = rJS(window),
...@@ -10,20 +10,22 @@ ...@@ -10,20 +10,22 @@
link_template = Handlebars.compile(source); link_template = Handlebars.compile(source);
function getPromiseTextContent(content, private_url) { function getPromiseTextContent(content, private_url) {
/*jslint regexp: true*/
var regex = /(https?:\/\/[^\s]+)/g, var regex = /(https?:\/\/[^\s]+)/g,
i, i,
parser, parser,
private_parser = document.createElement('a'), private_parser = document.createElement('a'),
result_list = content.match(regex), result_list = content.match(regex),
url_list = []; url_list = [];
/*jslint regexp: false*/
function makeUnique(array_list) { function makeUnique(array_list) {
var temp = {}, var temp = {},
i, l,
r = [], r = [],
k; k;
for (i = 0; i < array_list.length; i += 1) { for (l = 0; l < array_list.length; l += 1) {
temp[array_list[i]] = true; temp[array_list[l]] = true;
} }
for (k in temp) { for (k in temp) {
if (temp.hasOwnProperty(k)) { if (temp.hasOwnProperty(k)) {
...@@ -57,14 +59,15 @@ ...@@ -57,14 +59,15 @@
for (i = 0; i < url_list.length; i += 1) { for (i = 0; i < url_list.length; i += 1) {
content = content.replace( content = content.replace(
new RegExp(url_list[i].url, 'g'), new RegExp(url_list[i].url, 'g'),
url_list[i].next); url_list[i].next
);
} }
return content; return content;
} }
gadget_klass gadget_klass
.setState({ .setState({
jio_gadget: "", jio_gadget: ""
}) })
.ready(function (gadget) { .ready(function (gadget) {
return gadget.getDeclaredGadget("jio_gadget") return gadget.getDeclaredGadget("jio_gadget")
...@@ -80,7 +83,6 @@ ...@@ -80,7 +83,6 @@
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs") .declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted') .declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("translateHtml", "translateHtml") .declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
...@@ -90,9 +92,7 @@ ...@@ -90,9 +92,7 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
hosting_subscription,
software_instance, software_instance,
opml_outline,
opml_doc; opml_doc;
return new RSVP.Queue() return new RSVP.Queue()
...@@ -105,22 +105,19 @@ ...@@ -105,22 +105,19 @@
}) })
.push(function () { .push(function () {
return gadget.jio_allDocs({ return gadget.jio_allDocs({
select_list: [ select_list: [
"parent_url", "parent_url",
"parent_id", "parent_id",
"title", "title",
"opml_title", "opml_title",
"portal_type", "portal_type",
"_links", "_links",
"_embedded", "_embedded",
"reference" "reference"
], ],
query: '(portal_type:"global") AND (parent_id:"' + query: '(portal_type:"global") AND (parent_id:"' +
options.doc.parent_id + '")' options.doc.parent_id + '")'
}, function (error) { });
console.log(error);
return {};
});
}) })
.push(function (result) { .push(function (result) {
var i; var i;
...@@ -131,7 +128,6 @@ ...@@ -131,7 +128,6 @@
return gadget.jio_get(options.doc.parent_id); return gadget.jio_get(options.doc.parent_id);
}) })
.push(function (outline_doc) { .push(function (outline_doc) {
opml_outline = outline_doc;
// get opml // get opml
return gadget.jio_get(outline_doc.parent_url); return gadget.jio_get(outline_doc.parent_url);
}) })
...@@ -153,10 +149,10 @@ ...@@ -153,10 +149,10 @@
_embedded: {instance: {}}}; _embedded: {instance: {}}};
} }
// fix URLs // fix URLs
software_instance._links.private_url.href = software_instance. software_instance._links.private_url.href = software_instance
_links.private_url.href.replace("jio_private", "private"); ._links.private_url.href.replace("jio_private", "private");
software_instance._links.public_url.href = software_instance. software_instance._links.public_url.href = software_instance
_links.public_url.href.replace("jio_public", "public"); ._links.public_url.href.replace("jio_public", "public");
pass_url = "https://" + atob(opml_doc.basic_login) + pass_url = "https://" + atob(opml_doc.basic_login) +
"@" + software_instance._links.private_url.href.split("//")[1]; "@" + software_instance._links.private_url.href.split("//")[1];
...@@ -202,8 +198,14 @@ ...@@ -202,8 +198,14 @@
gadget.state.promise.source + ".history" gadget.state.promise.source + ".history"
) )
.push(undefined, function (error) { .push(undefined, function (error) {
console.log(error); return gadget.notifySubmitted({
return undefined; status: "error",
message: "Failed to get promise history content! \n" +
error.message || ''
})
.push(function () {
return undefined;
});
}) })
.push(function (status_history) { .push(function (status_history) {
var i, var i,
...@@ -223,7 +225,7 @@ ...@@ -223,7 +225,7 @@
//if (lines > len) { //if (lines > len) {
// lines = len - start; // lines = len - start;
//} //}
for (i = start; i >= 0; i-= 1) { for (i = start; i >= 0; i -= 1) {
message = status_history.data[i].message.slice(0, 60); message = status_history.data[i].message.slice(0, 60);
if (message.length >= 60) { if (message.length >= 60) {
message += "..."; message += "...";
...@@ -266,7 +268,8 @@ ...@@ -266,7 +268,8 @@
editable: 0, editable: 0,
hidden: 0, hidden: 0,
hidden_day_is_last_day: 0, hidden_day_is_last_day: 0,
"default": new Date(status_history.data[i]['change-time']*1000).toUTCString(), "default": new Date(status_history.data[i]['change-time'] * 1000)
.toUTCString(),
key: "change_date", key: "change_date",
required: 0, required: 0,
timezone_style: 0, timezone_style: 0,
...@@ -506,23 +509,31 @@ ...@@ -506,23 +509,31 @@
} }
}, },
form_definition: { form_definition: {
group_list: [[ group_list: [
"left", [
[["your_title"], ["your_status"], ["your_status_date"], ["your_report_date"], ["your_public_url"], ["your_private_url"]] "left",
], [
[ ["your_title"], ["your_status"], ["your_status_date"],
"right", ["your_report_date"], ["your_public_url"], ["your_private_url"]
[["your_hosting_title"], ["your_instance_title"], ["your_computer_reference"], ["your_computer_partition"], ]
["your_partition_ipv6"], ["your_software_release_url"]] ],
], [
[ "right",
"center", [
[["your_promise_output"]] ["your_hosting_title"], ["your_instance_title"],
], ["your_computer_reference"], ["your_computer_partition"],
[ ["your_partition_ipv6"], ["your_software_release_url"]
"bottom", ]
[["your_promise_history"]] ],
]] [
"center",
[["your_promise_output"]]
],
[
"bottom",
[["your_promise_history"]]
]
]
} }
}); });
}) })
...@@ -543,4 +554,4 @@ ...@@ -543,4 +554,4 @@
}); });
}); });
}); });
}(window, rJS, RSVP, Handlebars, RegExp)); }(window, rJS, RSVP, Handlebars, RegExp, document, atob));
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.706.49244.32460</string> </value> <value> <string>963.29333.34848.27204</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1508949544.51</float> <float>1510666984.34</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
<item> <item>
<key> <string>text_content</string> </key> <key> <string>text_content</string> </key>
<value> <string>CACHE MANIFEST\n <value> <string>CACHE MANIFEST\n
# generated on Fri, 06 Nov 2017 15:47:33 +0000\n # generated on Fri, 15 Nov 2017 15:47:33 +0000\n
# XXX + fonts\n # XXX + fonts\n
# images/ajax-loader.gif\n # images/ajax-loader.gif\n
CACHE:\n CACHE:\n
...@@ -133,8 +133,6 @@ dygraph.js\n ...@@ -133,8 +133,6 @@ dygraph.js\n
handlebars.js\n handlebars.js\n
jiodev.js\n jiodev.js\n
erp5_launcher_nojqm.js\n erp5_launcher_nojqm.js\n
monitoring_jio_http_storage.js\n
monitoring_jio_parser_storage.js\n
monitoring_jio_storage.js\n monitoring_jio_storage.js\n
monitoring_jio_web_storage.js\n monitoring_jio_web_storage.js\n
jsen.min.js\n jsen.min.js\n
...@@ -197,6 +195,8 @@ gadget_erp5_jio.html\n ...@@ -197,6 +195,8 @@ gadget_erp5_jio.html\n
gadget_erp5_jio.js\n gadget_erp5_jio.js\n
gadget_erp5_search_editor.html\n gadget_erp5_search_editor.html\n
gadget_erp5_search_editor.js\n gadget_erp5_search_editor.js\n
gadget_erp5_sort_editor.html\n
gadget_erp5_sort_editor.js\n
\n \n
# monitoring\n # monitoring\n
gadget_officejs_monitoring.appcache\n gadget_officejs_monitoring.appcache\n
...@@ -222,6 +222,7 @@ gadget_erp5_page_ojsm_status_list.html\n ...@@ -222,6 +222,7 @@ gadget_erp5_page_ojsm_status_list.html\n
gadget_erp5_page_ojsm_synchronize.html\n gadget_erp5_page_ojsm_synchronize.html\n
gadget_erp5_page_ojsm_erp5_configurator.html\n gadget_erp5_page_ojsm_erp5_configurator.html\n
gadget_erp5_page_ojsm_jump.html\n gadget_erp5_page_ojsm_jump.html\n
gadget_officejs_monitoring_opml_edit.html\n
\n \n
# monitoring js\n # monitoring js\n
gadget_officejs_monitoring_jio.js\n gadget_officejs_monitoring_jio.js\n
...@@ -248,7 +249,7 @@ gadget_officejs_jio_opml_view.js\n ...@@ -248,7 +249,7 @@ gadget_officejs_jio_opml_view.js\n
gadget_erp5_page_ojsm_synchronize.js\n gadget_erp5_page_ojsm_synchronize.js\n
gadget_erp5_page_ojsm_jump.js\n gadget_erp5_page_ojsm_jump.js\n
gadget_erp5_page_ojsm_erp5_configurator.js\n gadget_erp5_page_ojsm_erp5_configurator.js\n
gadget_officejs_monitoring_global.js\n gadget_officejs_monitoring_opml_edit.js\n
\n \n
# erp5_web_renderjs_ui\n # erp5_web_renderjs_ui\n
gadget_erp5_editor_panel.html\n gadget_erp5_editor_panel.html\n
...@@ -383,7 +384,7 @@ NETWORK:\n ...@@ -383,7 +384,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.22437.57747.1757</string> </value> <value> <string>963.30985.26464.16281</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -401,7 +402,7 @@ NETWORK:\n ...@@ -401,7 +402,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510327329.0</float> <float>1510766013.21</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Monitoring OPML edit</title>
<link href="gadget_officejs_monitoring_custom.css" rel="stylesheet" type="text/css"/>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_officejs_monitoring_opml_edit.js"></script>
<script id="template-message-error" type="text/x-handlebars-template">
<p><span class='ui-text-{{status}}'>{{message}}</span></p>
</script>
</head>
<body>
<div data-gadget-url="gadget_officejs_monitoring_jio.html" data-gadget-scope="jio_gadget" data-gadget-sandbox="public"></div>
<div class="ui-message-alert"></div>
</body>
</html>
\ No newline at end of file
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
</item> </item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>gadget_officejs_monitoring_global.js</string> </value> <value> <string>gadget_officejs_monitoring_opml_edit.js</string> </value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>gadget_officejs_monitoring_global_js</string> </value> <value> <string>gadget_officejs_monitoring_opml_edit_js</string> </value>
</item> </item>
<item> <item>
<key> <string>language</string> </key> <key> <string>language</string> </key>
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Monitoring Global Js</string> </value> <value> <string>Monitoring OPML edit widget Js</string> </value>
</item> </item>
<item> <item>
<key> <string>version</string> </key> <key> <string>version</string> </key>
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.1892.25677.55654</string> </value> <value> <string>963.29541.62889.7577</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1509020867.3</float> <float>1510680916.21</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
.declareService(function () { .declareService(function () {
return this.getDeclaredGadget("sync_gadget") return this.getDeclaredGadget("sync_gadget")
.push(function (sync_gadget) { .push(function (sync_gadget) {
return sync_gadget.registerSync(); return sync_gadget.register();
}); });
}) })
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>962.52822.35420.57019</string> </value> <value> <string>963.27666.8050.30907</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1509093907.79</float> <float>1510668451.66</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS */ /*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS) { (function (window, rJS, RSVP) {
"use strict"; "use strict";
rJS(window) rJS(window)
.ready(function (gadget) { .ready(function (gadget) {
gadget.props = {}; gadget.props = {};
return gadget.getDeclaredGadget("jio_gadget") return gadget.getDeclaredGadget("jio_gadget")
...@@ -16,8 +16,8 @@ rJS(window) ...@@ -16,8 +16,8 @@ rJS(window)
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this; var gadget = this;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
gadget.props.jio_gadget.createJio({ return gadget.props.jio_gadget.createJio({
type: "query", type: "query",
sub_storage: { sub_storage: {
type: "drivetojiomapping", type: "drivetojiomapping",
...@@ -28,6 +28,8 @@ rJS(window) ...@@ -28,6 +28,8 @@ rJS(window)
} }
} }
}); });
})
.push(function () {
return gadget.changeState({ return gadget.changeState({
parameter_list: options.parameters, parameter_list: options.parameters,
save_to: 'config.tmp', save_to: 'config.tmp',
...@@ -51,14 +53,10 @@ rJS(window) ...@@ -51,14 +53,10 @@ rJS(window)
.push(function (form_gadget) { .push(function (form_gadget) {
var i, var i,
parameter_dict = {}, parameter_dict = {},
group_list = [[ group_list = [
"left", ["left", []],
[] ["right", []]
], ];
[
"right",
[]
]];
for (i = 0; i < gadget.state.parameter_list.length; i += 1) { for (i = 0; i < gadget.state.parameter_list.length; i += 1) {
parameter_dict[gadget.state.parameter_list[i].title] = { parameter_dict[gadget.state.parameter_list[i].title] = {
"description": "", "description": "",
...@@ -73,7 +71,7 @@ rJS(window) ...@@ -73,7 +71,7 @@ rJS(window)
"hidden": 0, "hidden": 0,
"type": "StringField" // for now everything are stringField "type": "StringField" // for now everything are stringField
}; };
group_list[i%2][1].push([gadget.state.parameter_list[i].title]); group_list[i % 2][1].push([gadget.state.parameter_list[i].title]);
} }
return form_gadget.render({ return form_gadget.render({
erp5_document: { erp5_document: {
...@@ -117,9 +115,8 @@ rJS(window) ...@@ -117,9 +115,8 @@ rJS(window)
return form_gadget.getContent(); return form_gadget.getContent();
}) })
.push(function (doc) { .push(function (doc) {
var parameter_dict = {}, var key,
parameter_list = JSON.parse(JSON.stringify(gadget.state.parameter_list)), parameter_list = JSON.parse(JSON.stringify(gadget.state.parameter_list)),
key,
i; i;
for (i = 0; i < parameter_list.length; i += 1) { for (i = 0; i < parameter_list.length; i += 1) {
key = gadget.state.key + '_' + parameter_list[i].title; key = gadget.state.key + '_' + parameter_list[i].title;
...@@ -132,10 +129,10 @@ rJS(window) ...@@ -132,10 +129,10 @@ rJS(window)
.push(function () { .push(function () {
return {status: 'OK'}; return {status: 'OK'};
}, function (error) { }, function (error) {
console.log(error); //console.log(error);
return {status: 'ERROR', code: error.target.status, return {status: 'ERROR', code: error.target.status,
url: gadget.state.url, stage: "Saving file"}; url: gadget.state.url, stage: "Saving file"};
}); });
}); });
}(window, rJS)); }(window, rJS, RSVP));
\ No newline at end of file \ No newline at end of file
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>962.48797.18350.58214</string> </value> <value> <string>963.27984.14453.52343</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1507902562.82</float> <float>1510664009.77</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, clearTimeout, setTimeout, console, XMLHttpRequest, document */ /*global window, rJS, RSVP, console, XMLHttpRequest, document */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, console, clearTimeout, setTimeout, (function (window, rJS, RSVP, console, XMLHttpRequest, document) {
XMLHttpRequest, document) {
"use strict"; "use strict";
var gadget_klass = rJS(window); var gadget_klass = rJS(window);
...@@ -17,7 +16,7 @@ ...@@ -17,7 +16,7 @@
.declareAcquiredMethod("notifySubmitting", "notifySubmitting") .declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted") .declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareMethod("registerSync", function (options) { .declareMethod("register", function (options) {
var gadget = this; var gadget = this;
function testOnline(url) { function testOnline(url) {
...@@ -35,7 +34,7 @@ ...@@ -35,7 +34,7 @@
} }
}; };
xhr.onerror = function (e) { xhr.onerror = function () {
reject({ reject({
status: 'ERROR' status: 'ERROR'
}); });
...@@ -46,42 +45,6 @@ ...@@ -46,42 +45,6 @@
}); });
} }
function formatDate(d) {
function addZero(n) {
return n < 10 ? "0" + n : n.toString();
}
return d.getFullYear() + "-" + addZero(d.getMonth() + 1) +
"-" + addZero(d.getDate()) + " " + addZero(d.getHours()) +
":" + addZero(d.getMinutes()) + ":" + addZero(d.getSeconds());
}
function syncAllStorageWithCheck() {
gadget.props.offline = false;
return gadget.getSetting('sync_check_offline', 'true')
.push(function (check_offline) {
var parser;
if (check_offline === 'true') {
parser = document.createElement("a");
parser.href = document.URL;
return new RSVP.Queue()
.push(function () {
return testOnline(parser.origin);
})
.push(undefined, function () {
return {status: "ERROR"};
})
.push(function (online_result) {
if (online_result.status === "OK") {
return syncAllStorage();
}
gadget.props.offline = true;
});
}
return syncAllStorage();
});
}
function syncAllStorage() { function syncAllStorage() {
var has_error = false, var has_error = false,
last_sync_time; last_sync_time;
...@@ -104,8 +67,10 @@ ...@@ -104,8 +67,10 @@
return gadget.jio_repair(); return gadget.jio_repair();
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
// should include error message in error
has_error = true; has_error = true;
console.error(error); console.error(error);
// return false so it will trigger the next run
return false; return false;
}) })
.push(function () { .push(function () {
...@@ -116,18 +81,13 @@ ...@@ -116,18 +81,13 @@
]); ]);
}) })
.push(function () { .push(function () {
var time = 3000, var classname = "success",
classname = "success", message = "Synchronisation finished.";
message = "Synchronisation finished.",
//log_message = '',
log_title = "OK: " + message;
if (has_error) { if (has_error) {
classname = "error"; classname = "error";
time = 5000; message = "Synchronisation finished with error(s).";
//log_message = getErrorLog(gadget.props.error_list); message += " \nYou can retry with manual sync.";
log_title = "Synchronisation finished with error(s).";
message = log_title + "\nYou can retry with manual sync.";
} }
return gadget.notifySubmitted({ return gadget.notifySubmitted({
message: message, message: message,
...@@ -148,44 +108,63 @@ ...@@ -148,44 +108,63 @@
}); });
} }
function syncAllStorageWithCheck() {
gadget.props.offline = false;
return gadget.getSetting('sync_check_offline', 'true')
.push(function (check_offline) {
var parser;
if (check_offline === 'true') {
parser = document.createElement("a");
parser.href = document.URL;
return new RSVP.Queue()
.push(function () {
return testOnline(parser.origin);
})
.push(undefined, function () {
return {status: "ERROR"};
})
.push(function (online_result) {
if (online_result.status === "OK") {
return syncAllStorage();
}
gadget.props.offline = true;
});
}
return syncAllStorage();
});
}
function syncDataTimer() { function syncDataTimer() {
if (gadget.props.timer) { return new RSVP.Queue()
clearTimeout(gadget.props.timer); .push(function () {
} return RSVP.delay(gadget.props.timer_interval);
gadget.props.timer = setTimeout(function () { })
return new RSVP.Queue() .push(function () {
.push(function () { return gadget.getSetting('sync_start_time');
return gadget.getSetting('sync_start_time'); })
}) .push(function (start_timestamp) {
.push(function (start_timestamp) { var current_time = new Date().getTime();
var current_time = new Date().getTime(); if (start_timestamp !== undefined &&
if (start_timestamp !== undefined && (current_time - gadget.props.timer_interval) <=
(current_time - gadget.props.timer_interval) <= start_timestamp) {
start_timestamp) { // There was another recent sync don't start a new sync before the time_interval!
// There was a recent sync don't start a new sync before the time_interval!
return;
}
return syncAllStorageWithCheck();
})
.push(undefined, function (error) {
console.error(error);
return; return;
}) }
.push(function () { return syncAllStorageWithCheck();
return gadget.getSetting('sync_data_interval'); })
}) .push(function () {
.push(function (timer_interval) { return gadget.getSetting('sync_data_interval');
if (gadget.props.offline === true) { })
// Offline mode detected, next check will be in 3 minutes .push(function (timer_interval) {
timer_interval = 180000; if (gadget.props.offline === true) {
} else if (timer_interval === undefined) { // Offline mode detected, next check will be in 3 minutes
timer_interval = gadget.props.default_sync_interval; timer_interval = 180000;
} } else if (timer_interval === undefined) {
gadget.props.timer_interval = timer_interval; timer_interval = gadget.props.default_sync_interval;
return syncDataTimer(); }
}); gadget.props.timer_interval = timer_interval;
}, gadget.props.timer_interval); return syncDataTimer();
return gadget.props.timer; });
} }
...@@ -244,5 +223,4 @@ ...@@ -244,5 +223,4 @@
}); });
}); });
}(window, rJS, RSVP, console, clearTimeout, setTimeout, XMLHttpRequest, }(window, rJS, RSVP, console, XMLHttpRequest, document));
document)); \ No newline at end of file
\ No newline at end of file
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.21916.52285.31846</string> </value> <value> <string>963.29129.42634.5819</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510233154.98</float> <float>1510655414.57</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment