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);
...@@ -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,11 +190,9 @@ ...@@ -190,11 +190,9 @@
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"}
}
) )
); );
} }
...@@ -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";
...@@ -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 gadget.state.message
.innerHTML = notify_msg_template({ .innerHTML = notify_msg_template({
status: 'error', status: 'error',
message: 'Error: Content is not a valid Monitoring Json configuration!' message: 'Error: Content is not a valid Monitoring Json configuration!'
}); });
return false; return false;
}
}) })
.push(function (status) { .push(function (status) {
if (status) { if (status) {
...@@ -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({ return gadget.notifySubmitted({
message: "Configuration Saved!", message: "Configuration Saved!",
status: "success" 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,9 +20,14 @@ ...@@ -40,9 +20,14 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.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('opml_gadget');
})
.push(function (g) {
opml_gadget = g;
return gadget.getDeclaredGadget('form_view'); return gadget.getDeclaredGadget('form_view');
}) })
.push(function (form_gadget) { .push(function (form_gadget) {
...@@ -50,39 +35,14 @@ ...@@ -50,39 +35,14 @@
}) })
.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,10 +64,12 @@ ...@@ -66,10 +64,12 @@
'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"
...@@ -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)
...@@ -223,7 +223,13 @@ ...@@ -223,7 +223,13 @@
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 gadget.notifySubmitted({
message: "Error: Failed to download data files!",
status: "error"
})
.push(function () {
return undefined; return undefined;
});
}) })
.push(function (average_result) { .push(function (average_result) {
if (average_result !== undefined) { if (average_result !== undefined) {
......
...@@ -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({
...@@ -103,29 +117,16 @@ ...@@ -103,29 +117,16 @@
}; };
} }
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) {
if (gadget.property_dict.resource_dict.hasOwnProperty(key)) {
promise_list.push(loadGraphData(gadget, key)); promise_list.push(loadGraphData(gadget, key));
} }
}
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function () { .push(function () {
...@@ -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>
......
...@@ -19,11 +19,14 @@ ...@@ -19,11 +19,14 @@
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,9 +18,14 @@ ...@@ -40,9 +18,14 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.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('opml_gadget');
})
.push(function (g) {
opml_gadget = g;
return gadget.getDeclaredGadget('form_view'); return gadget.getDeclaredGadget('form_view');
}) })
.push(function (form_gadget) { .push(function (form_gadget) {
...@@ -50,37 +33,24 @@ ...@@ -50,37 +33,24 @@
}) })
.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()
...@@ -117,9 +117,6 @@ ...@@ -117,9 +117,6 @@
], ],
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) {
...@@ -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({
status: "error",
message: "Failed to get promise history content! \n" +
error.message || ''
})
.push(function () {
return undefined; 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,14 +509,21 @@ ...@@ -506,14 +509,21 @@
} }
}, },
form_definition: { form_definition: {
group_list: [[ group_list: [
[
"left", "left",
[["your_title"], ["your_status"], ["your_status_date"], ["your_report_date"], ["your_public_url"], ["your_private_url"]] [
["your_title"], ["your_status"], ["your_status_date"],
["your_report_date"], ["your_public_url"], ["your_private_url"]
]
], ],
[ [
"right", "right",
[["your_hosting_title"], ["your_instance_title"], ["your_computer_reference"], ["your_computer_partition"], [
["your_partition_ipv6"], ["your_software_release_url"]] ["your_hosting_title"], ["your_instance_title"],
["your_computer_reference"], ["your_computer_partition"],
["your_partition_ipv6"], ["your_software_release_url"]
]
], ],
[ [
"center", "center",
...@@ -522,7 +532,8 @@ ...@@ -522,7 +532,8 @@
[ [
"bottom", "bottom",
[["your_promise_history"]] [["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>
......
/*global window, RSVP, btoa */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, RSVP, btoa) {
"use strict";
/* Function used to manage/add/update OPML */
window.OPMLManage = (function(){
var gadget,
self = {};
self.init = function (rjs_gadget, template_msg) {
gadget = rjs_gadget;
gadget.props = {gindex: 0};
self.notify_msg_template = template_msg;
return new RSVP.Queue()
.push(function () {
return gadget.changeState({
message: gadget.element.querySelector('.ui-message-alert')
});
})
.push(function () {
return gadget.getDeclaredGadget("jio_gadget")
.push(function (jio_gadget) {
return gadget.changeState({"jio_gadget": jio_gadget});
});
});
};
self.validateHttpUrl = function (value) {
/*jslint regexp: true*/
if (/\(?(?:(http|https):\/\/)(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[[\dabcedf:]+\])(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?/i.test(value)) {
return true;
}
/*jslint regexp: false*/
return false;
};
self.changeMonitorPassword = function (base_url, title, basic_login,
password) {
var url = base_url,
jio_gadget,
jio_options;
url += (url.endsWith('/') ? '' : '/') + 'config/';
gadget.props.gindex += 1;
return gadget.declareGadget("gadget_officejs_monitoring_jio.html",
{
element: gadget.element,
scope: 'jio_' + gadget.props.gindex + "_gadget",
sandbox: "public"
}
).push(function(new_gadget) {
jio_gadget = new_gadget;
jio_gadget.createJio({
type: "query",
sub_storage: {
type: "drivetojiomapping",
sub_storage: {
type: "dav",
url: url,
basic_login: basic_login
}
}
});
return jio_gadget.get('config');
})
.push(function (doc) {
var i;
if (doc) {
for (i = 0; i < doc.length; i += 1) {
if (doc[i].key === 'monitor-password') {
doc[i].value = password;
return jio_gadget.put('config.tmp', doc);
}
}
}
return new Error("Cannot get document 'config.json' at : " % url);
})
.push(function () {
return {status: 'OK'};
}, function (error) {
console.log(error);
return {
status: 'ERROR',
code: error.status || error.target.status,
url: base_url,
title: title
};
});
};
self.checkCredential = function (url, title, hash) {
var ouput;
// Verify if login and password are correct for this URL
if (url === undefined) {
return {status: 'OK'};
}
return self.testUrl(url, hash)
.then(function(result) {
return result;
}, function(error) {
var ko_msg = {
status: 'KO',
msg: error.msg + ' (' + url + ')',
title: title
};
return ko_msg;
});
};
self.testUrl = function (url, credential_hash) {
// test URL availability!!
// check that password is valid for that URL
return new RSVP.Queue()
.push(function () {
return new RSVP.Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onload = function (event) {
var response = event.target;
if (response.status === 200) {
resolve({status: 'OK'});
} else {
reject({
status: 'ERROR',
msg: new Error("XHR: " + response.status + ": " + response.statusText)
});
}
};
xhr.onerror = function (e) {
reject({
status: 'ERROR',
msg: e.target.status + ": " + e.target.statusText
});
};
xhr.open("GET", url, true);
if (credential_hash !== undefined) {
xhr.setRequestHeader('Authorization', 'Basic ' + credential_hash);
}
xhr.send("");
});
});
};
self.saveOPML = function (doc, verify_password) {
var opml_dict = {
type: "opml",
title: doc.title,
portal_type: "opml",
url: doc.url,
basic_login: btoa(doc.username + ':' + doc.password),
username: doc.username,
password: doc.password,
active: (doc.active === 1) ? true : false
},
update_password_list = [];
gadget.state.message.textContent = "";
function validateOPML() {
// read the opml online to get the content and title
// it also help to make sure that the opml content is valid
gadget.state.message.textContent = "Reading OPML content...";
gadget.state.jio_gadget.createJio({
type: "query",
sub_storage: {
type: "parser",
document_id: doc.url,
attachment_id: 'enclosure',
parser: 'opml',
sub_storage: {
type: "http"
}
}
});
return gadget.state.jio_gadget.allDocs({
select_list: ['title', 'opml_title', 'xmlUrl', 'url']
})
.push(undefined, function (error) {
gadget.state.message
.innerHTML = self.notify_msg_template({
status: 'error',
message: error.name +
": Failed to access OPML URL. " + error.message
});
return {data: {total_rows: 0}};
})
.push(function (opml_result) {
var i,
check_list = [true];
if (opml_result.data.total_rows > 0) {
opml_dict.title = opml_result.data.rows[0].value.title;
for (i = 1; i < opml_result.data.total_rows; i += 1) {
if (opml_result.data.rows[i].value.url !== undefined) {
check_list.push(self.checkCredential(
opml_result.data.rows[i].value.url,
opml_result.data.rows[i].value.title,
opml_dict.basic_login
));
update_password_list.push({
base_url: opml_result.data.rows[i].value.url,
title: opml_result.data.rows[i].value.title
});
}
}
gadget.state.message.textContent = "Validating password(s)...";
return RSVP.all(check_list);
}
return [false];
})
.push(function (status_list) {
var i,
error_msg = '';
for (i = 1; i < status_list.length; i += 1) {
if (status_list[i].status !== 'OK') {
error_msg += 'Login/password invalid for instance: ' +
status_list[i].title + '. ' +
status_list[i].msg + '\n';
}
}
if (error_msg !== '') {
gadget.state.message
.innerHTML = self.notify_msg_template({
status: 'error',
message: error_msg
});
return false;
}
return status_list[0];
})
.push(function (previous_status) {
var i,
update_promise_list = [];
if (doc.new_password === "") {
return previous_status;
}
if (!previous_status) {
return false;
}
gadget.state.message.textContent = "Updating password(s)...";
for (i = 0; i < update_password_list.length; i += 1) {
update_promise_list.push(self.changeMonitorPassword(
update_password_list[i].base_url,
update_password_list[i].title,
opml_dict.basic_login,
doc.new_password
));
}
return new RSVP.Queue()
.push(function () {
return RSVP.all(update_promise_list);
})
.push(function(result_list) {
var i,
error_msg = "";
for (i = 0; i < result_list.length; i += 1) {
if (result_list[i].status === 'ERROR') {
error_msg += 'ERROR ' + result_list[i].code +
'. [' + result_list[i].title + '] Failed to ' +
'change password, please try again\n';
}
}
if (error_msg !== "") {
gadget.state.message
.innerHTML = self.notify_msg_template({
status: 'error',
message: error_msg
});
return false;
} else {
opml_dict.basic_login =
btoa(doc.username + ':' + doc.new_password);
opml_dict.password = doc.new_password;
return true;
}
});
});
}
return new RSVP.Queue()
.push(function () {
if (verify_password) {
return validateOPML();
}
return true;
})
.push(function (status) {
if (status) {
gadget.state.message.textContent = "Saving OPML...";
return gadget.jio_put(opml_dict.url, opml_dict)
.push(function () {
gadget.state.message.textContent = "";
return status;
});
}
return status;
});
};
return self;
})();
}(window, RSVP, btoa));
<!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
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Page" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>classification/collaborative/team</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_officejs_monitoring_opml_edit.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>gadget_officejs_monitoring_opml_edit_html</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Page</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Monitoring OPML edit widget</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1510673457.39</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.29438.65222.13568</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1510673297.93</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1510673090.03</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
/*global window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
notify_msg_template = Handlebars.compile(
templater.getElementById("template-message-error").innerHTML
);
function validateHttpUrl(value) {
/*jslint regexp: true*/
if (/\(?(?:(http|https):\/\/)(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[[\dabcedf:]+\])(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?/i.test(value)) {
return true;
}
/*jslint regexp: false*/
return false;
}
function changeMonitorPassword(gadget, base_url, title, basic_login,
password) {
var url = base_url,
jio_gadget;
url += (url.endsWith('/') ? '' : '/') + 'config/';
gadget.props.gindex += 1;
return gadget.declareGadget("gadget_officejs_monitoring_jio.html",
{element: gadget.element,
scope: 'jio_' + gadget.props.gindex + "_gadget",
sandbox: "public"}
)
.push(function (new_gadget) {
jio_gadget = new_gadget;
return jio_gadget.createJio({
type: "query",
sub_storage: {
type: "drivetojiomapping",
sub_storage: {
type: "dav",
url: url,
basic_login: basic_login
}
}
});
})
.push(function () {
return jio_gadget.get('config');
})
.push(function (doc) {
var i;
if (doc) {
for (i = 0; i < doc.length; i += 1) {
if (doc[i].key === 'monitor-password') {
doc[i].value = password;
return jio_gadget.put('config.tmp', doc);
}
}
}
return new Error("Cannot get document 'config.json' at : " + url);
})
.push(function () {
return {status: 'OK'};
}, function (error) {
//console.error(error);
return {
status: 'ERROR',
code: error.status || error.target.status,
url: base_url,
title: title
};
});
}
function testUrl(url, credential_hash) {
// test URL availability!!
// check that password is valid for that URL
return new RSVP.Queue()
.push(function () {
return new RSVP.Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onload = function (event) {
var response = event.target;
if (response.status === 200) {
resolve({status: 'OK'});
} else {
reject({
status: 'ERROR',
msg: new Error("XHR: " + response.status + ": " + response.statusText)
});
}
};
xhr.onerror = function (e) {
reject({
status: 'ERROR',
msg: e.target.status + ": " + e.target.statusText
});
};
xhr.open("GET", url, true);
if (credential_hash !== undefined) {
xhr.setRequestHeader('Authorization', 'Basic ' + credential_hash);
}
xhr.send("");
});
});
}
function checkCredential(url, title, hash) {
// Verify if login and password are correct for this URL
if (url === undefined) {
return {status: 'OK'};
}
return testUrl(url, hash)
.then(function (result) {
return result;
}, function (error) {
var ko_msg = {
status: 'KO',
msg: error.msg + ' (' + url + ')',
title: title
};
return ko_msg;
});
}
function saveOPML(gadget, doc, verify_password) {
var opml_dict = {
type: "opml",
title: doc.title,
portal_type: "opml",
url: doc.url,
basic_login: btoa(doc.username + ':' + doc.password),
username: doc.username,
password: doc.password,
active: (doc.active === 1) ? true : false
},
update_password_list = [];
gadget.state.message.textContent = "";
function validateOPML() {
// read the opml online to get the content and title
// it also help to make sure that the opml content is valid
gadget.state.message.textContent = "Reading OPML content...";
return gadget.state.jio_gadget.createJio({
type: "query",
sub_storage: {
type: "parser",
document_id: doc.url,
attachment_id: 'enclosure',
parser: 'opml',
sub_storage: {
type: "http"
}
}
})
.push(function () {
return gadget.state.jio_gadget.allDocs({
select_list: ['title', 'opml_title', 'xmlUrl', 'url']
});
})
.push(undefined, function (error) {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: error.target.status +
": Failed to access OPML URL. " + error.message
});
return {data: {total_rows: 0}};
})
.push(function (opml_result) {
var i,
check_list = [true];
if (opml_result.data.total_rows > 0) {
opml_dict.title = opml_result.data.rows[0].value.title;
for (i = 1; i < opml_result.data.total_rows; i += 1) {
if (opml_result.data.rows[i].value.url !== undefined) {
check_list.push(checkCredential(
opml_result.data.rows[i].value.url,
opml_result.data.rows[i].value.title,
opml_dict.basic_login
));
update_password_list.push({
base_url: opml_result.data.rows[i].value.url,
title: opml_result.data.rows[i].value.title
});
}
}
gadget.state.message.textContent = "Validating password(s)...";
return RSVP.all(check_list);
}
return [false];
})
.push(function (status_list) {
var i,
error_msg = '';
for (i = 1; i < status_list.length; i += 1) {
if (status_list[i].status !== 'OK') {
error_msg += 'Login/password invalid for instance: ' +
status_list[i].title + '. ' +
status_list[i].msg + '\n';
}
}
if (error_msg !== '') {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: error_msg
});
return false;
}
return status_list[0];
})
.push(function (previous_status) {
var i,
update_promise_list = [];
if (doc.new_password === "") {
return previous_status;
}
if (!previous_status) {
return false;
}
gadget.state.message.textContent = "Updating password(s)...";
for (i = 0; i < update_password_list.length; i += 1) {
update_promise_list.push(changeMonitorPassword(
gadget,
update_password_list[i].base_url,
update_password_list[i].title,
opml_dict.basic_login,
doc.new_password
));
}
return new RSVP.Queue()
.push(function () {
return RSVP.all(update_promise_list);
})
.push(function (result_list) {
var j,
error_msg = "";
for (j = 0; j < result_list.length; j += 1) {
if (result_list[j].status === 'ERROR') {
error_msg += 'ERROR ' + result_list[j].code +
'. [' + result_list[j].title + '] Failed to ' +
'change password, please try again\n';
}
}
if (error_msg !== "") {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: error_msg
});
return false;
}
opml_dict.basic_login =
btoa(doc.username + ':' + doc.new_password);
opml_dict.password = doc.new_password;
return true;
});
});
}
return new RSVP.Queue()
.push(function () {
if (verify_password) {
return validateOPML();
}
return true;
})
.push(function (status) {
if (status) {
gadget.state.message.textContent = "Saving OPML...";
return gadget.jio_put(opml_dict.url, opml_dict)
.push(function () {
gadget.state.message.textContent = "";
return status;
});
}
return status;
});
}
gadget_klass
/////////////////////////////
// state
/////////////////////////////
.setState({
message: "",
redirect: false
})
/////////////////////////////
// ready
/////////////////////////////
.ready(function (gadget) {
gadget.props = {gindex: 0};
return gadget.changeState({
message: gadget.element.querySelector('.ui-message-alert')
})
.push(function () {
return gadget.getDeclaredGadget("jio_gadget")
.push(function (jio_gadget) {
return gadget.changeState({"jio_gadget": jio_gadget});
});
});
})
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_put", "jio_put")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("checkOPMLForm", function (form_doc) {
var gadget = this;
if (!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 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;
})
.declareMethod("saveOPML", function (form_doc, verify_password) {
return saveOPML(this, form_doc, verify_password);
});
}(window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars));
...@@ -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")
...@@ -17,7 +17,7 @@ rJS(window) ...@@ -17,7 +17,7 @@ rJS(window)
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,12 +108,37 @@ ...@@ -148,12 +108,37 @@
}); });
} }
function syncDataTimer() { function syncAllStorageWithCheck() {
if (gadget.props.timer) { gadget.props.offline = false;
clearTimeout(gadget.props.timer); 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;
});
} }
gadget.props.timer = setTimeout(function () { return syncAllStorage();
});
}
function syncDataTimer() {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () {
return RSVP.delay(gadget.props.timer_interval);
})
.push(function () { .push(function () {
return gadget.getSetting('sync_start_time'); return gadget.getSetting('sync_start_time');
}) })
...@@ -162,15 +147,11 @@ ...@@ -162,15 +147,11 @@
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 a recent sync don't start a new sync before the time_interval! // There was another recent sync don't start a new sync before the time_interval!
return; return;
} }
return syncAllStorageWithCheck(); return syncAllStorageWithCheck();
}) })
.push(undefined, function (error) {
console.error(error);
return;
})
.push(function () { .push(function () {
return gadget.getSetting('sync_data_interval'); return gadget.getSetting('sync_data_interval');
}) })
...@@ -184,8 +165,6 @@ ...@@ -184,8 +165,6 @@
gadget.props.timer_interval = timer_interval; gadget.props.timer_interval = timer_interval;
return syncDataTimer(); return syncDataTimer();
}); });
}, gadget.props.timer_interval);
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