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 */
(function (window, rJS, RSVP, Handlebars) {
(function (window, rJS, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
......@@ -32,7 +32,6 @@
page_title: "Jump to Object"
});
});
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
}(window, rJS, Handlebars));
\ No newline at end of file
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.3579.43071.5205</string> </value>
<value> <string>963.29379.61141.36334</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1509121711.67</float>
<float>1510669689.61</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -104,7 +104,8 @@
var gadget = this;
return getHostingData(gadget, param_list[0])
.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) {
if (result.data.rows[i].value.hasOwnProperty("date")) {
result.data.rows[i].value.date = {
......@@ -171,7 +172,7 @@
lines_limit;
return new RSVP.Queue()
.push(function () {
return gadget.getSetting("listbox_lines_limit", 100);
return gadget.getSetting("listbox_lines_limit", 20);
})
.push(function (listbox_lines_limit) {
lines_limit = listbox_lines_limit;
......@@ -224,7 +225,7 @@
}
});
})
.push(function (result) {
.push(function () {
return gadget.updateHeader({
page_title: "Hosting Subscriptions Status",
filter_action: true
......
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.19077.52757.17169</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1510052055.87</float>
<float>1510766156.1</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, document, Handlebars, Rusha */
/*global window, rJS, document, RSVP, Rusha, escape */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, document, Handlebars, Rusha) {
(function (window, rJS, document, RSVP, Rusha, escape) {
"use strict";
var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
rusha = new Rusha();
function generateHash(str) {
......@@ -41,7 +40,9 @@
})
.push(function () {
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) {
if (result.data.rows[i].value.hasOwnProperty("date")) {
value = new Date(result.data.rows[i].value.date);
......@@ -122,28 +123,28 @@
return RSVP.all(promise_list);
})
.push(function (result_list) {
var i,
var j,
ok_to_save = true,
promise_list = [];
for (i = 0; i < result_list.length; i += 1) {
if (result_list[i].status !== 'OK') {
return_list = [];
for (j = 0; j < result_list.length; j += 1) {
if (result_list[j].status !== 'OK') {
ok_to_save = false;
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) {
return RSVP.all(promise_list);
return RSVP.all(return_list);
}
// One of storage failed, cancel save to be consistent
return result_list;
})
.push(function (result_list) {
var msg_list = [],
i;
for (i = 0; i < result_list.length; i += 1) {
if (result_list[i].status !== "OK") {
msg_list.push(result_list[i].stage + " from " + result_list[i].url);
j;
for (j = 0; j < result_list.length; j += 1) {
if (result_list[j].status !== "OK") {
msg_list.push(result_list[j].stage + " from " + result_list[j].url);
}
}
if (msg_list.length > 0) {
......@@ -172,7 +173,6 @@
}
if (modification_dict.hasOwnProperty('instance_dict')) {
// render parameter form
return new RSVP.Queue()
.push(function () {
var promise_list = [],
......@@ -190,11 +190,9 @@
element.appendChild(gadget_element);
promise_list.push(
gadget.declareGadget("gadget_officejs_monitoring_parameter_view.html",
{
element: gadget_element,
{element: gadget_element,
scope: 'p_' + gadget.state.instance_dict.data.rows[i].id,
sandbox: "public"
}
sandbox: "public"}
)
);
}
......@@ -309,4 +307,4 @@
});
});
}(window, rJS, document, Handlebars, Rusha));
\ No newline at end of file
}(window, rJS, document, RSVP, Rusha, escape));
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.20929.61143.52155</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510216762.18</float>
<float>1510586789.54</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser,
/*global window, rJS, RSVP, jsen, Handlebars, atob, btoa, DOMParser,
URLSearchParams */
/*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) {
"use strict";
......@@ -139,7 +139,7 @@
var is_old_schema = false;
gadget.state.message.textContent = "";
return new RSVP.Queue()
.push(function (form_doc) {
.push(function () {
var configuration_dict;
if (typeof config === 'string') {
try {
......@@ -231,14 +231,13 @@
}
return true;
});
} else {
}
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: 'Error: Content is not a valid Monitoring Json configuration!'
});
return false;
}
})
.push(function (status) {
if (status) {
......@@ -530,9 +529,7 @@
});
})
.push(function () {
var hosting_subscription_list = [],
has_failed = false,
uid_dict = {};
var has_failed = false;
if (gadget.state.sync === "erp5" && gadget.state.storage_url) {
// start import from erp5 now
return gadget.notifySubmitting()
......@@ -548,8 +545,7 @@
.push(function (select_limit) {
return getInstanceOPMLListFromMaster(gadget, select_limit);
})
.push(undefined, function (error) {
console.log(error);
.push(undefined, function () {
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
......@@ -593,12 +589,11 @@
message: "Failed to import Configurations",
status: "error"
});
} else {
}
return gadget.notifySubmitted({
message: "Configuration Saved!",
status: "success"
});
}
})
.push(function () {
if (!has_failed) {
......@@ -611,5 +606,4 @@
}
});
});
}(window, rJS, RSVP, jsen, Rusha, Handlebars, atob, btoa, DOMParser,
URLSearchParams));
}(window, rJS, RSVP, jsen, Handlebars, atob, btoa, DOMParser, URLSearchParams));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.21850.42337.9796</string> </value>
<value> <string>963.27920.40078.20411</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1510219191.94</float>
<float>1510582176.99</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -40,8 +40,7 @@
return RSVP.all(promise_list);
})
.push(function (result_list) {
var i,
tab_list = [];
var tab_list = [];
tab_list.push({
title: options.view_title || options.jio_key,
......
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.1691.38549.3618</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1509095381.18</float>
<float>1510581537.14</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -9,20 +9,15 @@
<script src="rsvp.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 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>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
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"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
......
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.1898.2167.63078</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1509020790.01</float>
<float>1510675648.98</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, Handlebars, OPMLManage */
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, OPMLManage) {
(function (window, rJS, RSVP) {
"use strict";
var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
notify_msg_template = Handlebars.compile(
templater.getElementById("template-message-error").innerHTML
),
opml_global = OPMLManage;
rJS(window)
gadget_klass
/////////////////////////////
// state
/////////////////////////////
.setState({
message: "",
redirect: true
})
/////////////////////////////
// ready
/////////////////////////////
.ready(function (gadget) {
return opml_global.init(gadget, notify_msg_template);
})
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
......@@ -31,7 +12,6 @@
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
......@@ -40,9 +20,14 @@
/////////////////////////////////////////////////////////////////
.onEvent('submit', function () {
var gadget = this,
opml_gadget,
doc;
return new RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget('opml_gadget');
})
.push(function (g) {
opml_gadget = g;
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
......@@ -50,39 +35,14 @@
})
.push(function (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 (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;
return opml_gadget.checkOPMLForm(doc);
})
.push(function (state) {
if (state) {
return gadget.notifySubmitting()
.push(function () {
doc.title = "";
return opml_global.saveOPML(doc, true);
return opml_gadget.saveOPML(doc, true);
})
.push(function (status) {
var msg = {message: 'OPML document added', status: 'success'};
......@@ -95,10 +55,10 @@
]);
})
.push(function (result_list) {
if (result_list[1] && gadget.state.redirect) {
if (result_list[1]) {
return gadget.redirect({
"command": "change",
"options": {"page": "ojsm_status_list"}
"command": "display",
"options": {"page": "settings_configurator"}
});
}
});
......@@ -169,13 +129,13 @@
},
"my_active": {
"description": "Sync this opml or not",
"title": "Active (Auto Sync)",
"title": "Active (Enable Sync)",
"default": 1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "active",
"hidden": 1,
"hidden": 0,
"type": "CheckBoxField"
},
"my_new_password": {
......@@ -199,7 +159,7 @@
"key": "confirm_new_password",
"hidden": (options.chg_passwd || '' === true) ? 0 : 1,
"type": "PasswordField"
},
}
}},
"_links": {
"type": {
......@@ -236,4 +196,4 @@
});
});
});
}(window, rJS, RSVP, Handlebars, OPMLManage));
}(window, rJS, RSVP));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.21318.32760.12475</string> </value>
<value> <string>963.29486.6222.37785</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1510217057.28</float>
<float>1510676454.74</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, Handlebars */
/*global window, rJS */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars) {
(function (window, rJS) {
"use strict";
rJS(window)
......@@ -29,4 +29,4 @@
}});
});
});
}(window, rJS, RSVP, Handlebars));
}(window, rJS));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.20929.61143.52155</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1510231849.59</float>
<float>1510581396.39</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -10,6 +10,7 @@
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script id="infobox-widget-template" type="text/x-handlebars-template">
{{#each resource_list}}
......
......@@ -243,7 +243,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.22427.36654.49664</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -261,7 +261,7 @@
</tuple>
<state>
<tuple>
<float>1510327379.3</float>
<float>1510669287.69</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -56,9 +56,7 @@
});
})
.push(function () {
var key,
promise_list = [];
gadget.property_dict.jio_gadget.createJio({
return gadget.property_dict.jio_gadget.createJio({
type: "webhttp",
// XXX fix URL
url: (gadget.state.opml_outline.url
......@@ -66,10 +64,12 @@
'documents/'),
basic_login: gadget.state.opml.basic_login
});
})
.push(function () {
return gadget.property_dict.jio_gadget
.get(gadget.property_dict.monitor_process_state);
})
.push(undefined, function (error) {
.push(undefined, function () {
return gadget.notifySubmitted({
message: "Error: Failed to download data files!",
status: "error"
......@@ -91,7 +91,7 @@
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.allowPublicAcquisition("jio_allDocs", function (param_list) {
.allowPublicAcquisition("jio_allDocs", function () {
var gadget = this,
result = {data: {total_rows: 0, rows: []}};
return gadget.property_dict.jio_gadget.get(gadget.property_dict.process_state)
......@@ -223,7 +223,13 @@
return gadget.property_dict.jio_gadget
.get(gadget.property_dict.monitor_process_state)
.push(undefined, function () {
return gadget.notifySubmitted({
message: "Error: Failed to download data files!",
status: "error"
})
.push(function () {
return undefined;
});
})
.push(function (average_result) {
if (average_result !== undefined) {
......
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.22187.48632.58282</string> </value>
<value> <string>963.29300.23681.7082</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1510239168.21</float>
<float>1510669789.68</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, console */
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, console) {
(function (window, rJS, RSVP) {
"use strict";
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) {
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)
.push(undefined, function () {
return gadget.notifySubmitted({
......@@ -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) {
return new RSVP.Queue()
.push(function () {
var key,
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));
}
}
return RSVP.all(promise_list);
})
.push(function () {
......@@ -136,8 +137,7 @@
var data_list = [],
axis_dict = {},
line_list,
i,
j;
i;
axis_dict = {
"0": {
......@@ -259,8 +259,7 @@
})
.ready(function (gadget) {
gadget.property_dict = {};
gadget.property_dict.render_deferred = RSVP.defer();
gadget.property_dict.ressource_dict = {
gadget.property_dict.resource_dict = {
memory_resource: "monitor_resource_memory.data",
cpu_resource: "monitor_resource_process.data",
io_resource: "monitor_resource_io.data"
......@@ -276,7 +275,6 @@
return gadget.getDeclaredGadget("graph_cpu")
.push(function (graph_cpu) {
gadget.property_dict.graph_cpu = graph_cpu;
gadget.property_dict.graph_cpu_label_list = [];
});
})
.ready(function (gadget) {
......@@ -333,7 +331,7 @@
gadget.property_dict.mem_data = {data: []};
gadget.property_dict.process_data = {data: []};
gadget.property_dict.io_data = {data: []};
return gadget.property_dict.render_deferred.resolve();
return gadget.deferUpdateGraph();
});
})
......@@ -349,9 +347,9 @@
/////////////////////////////////////////////////////////////////
// declared service
/////////////////////////////////////////////////////////////////
.declareService(function () {
var gadget = this,
date_window = [];
.declareJob("deferUpdateGraph", function () {
return updateGraph(this);
/*function toggleSerieVisibility(evt) {
var checkbox = evt.target.nextSibling,
......@@ -367,10 +365,6 @@
});
}*/
return new RSVP.Queue()
.push(function () {
return gadget.property_dict.render_deferred.promise;
})
/**.push(function () {
return gadget.property_dict.graph_cpu.render(
gadget.property_dict.process_data.data.join('\n'),
......@@ -434,9 +428,6 @@
RSVP.all(promise_list);
return updateGraphTimer();
})**/
.push(function () {
return updateGraph(gadget);
});
});
}(window, rJS, RSVP, console));
\ No newline at end of file
}(window, rJS, RSVP));
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.22199.29933.17390</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510239154.52</float>
<float>1510651329.34</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -86,7 +86,7 @@
return new RSVP.Queue()
.push(function () {
return gadget.getSetting("listbox_lines_limit", 100);
return gadget.getSetting("listbox_lines_limit", 20);
})
.push(function (listbox_lines_limit) {
lines_limit = listbox_lines_limit;
......@@ -136,7 +136,7 @@
}
});
})
.push(function (result) {
.push(function () {
return gadget.updateHeader({
page_title: "Software Instances Status",
filter_action: true
......@@ -147,7 +147,6 @@
.onLoop(function () {
var gadget = this;
console.log("ONloop...");
return gadget.getSetting('latest_sync_time')
.push(function (latest_sync_time) {
if (latest_sync_time > gadget.state.latest_reload_time) {
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.19079.34809.6058</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510051687.96</float>
<float>1510766173.29</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -108,7 +108,7 @@
}
})
.push(function () {
return gadget.getSetting("listbox_lines_limit", 50);
return gadget.getSetting("listbox_lines_limit", 20);
})
.push(function (listbox_lines_limit) {
lines_limit = listbox_lines_limit;
......@@ -160,7 +160,7 @@
}
});
})
.push(function (result) {
.push(function () {
return gadget.updateHeader({
page_title: "Monitoring Promises Status",
filter_action: true
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.16563.15280.46899</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510052474.13</float>
<float>1510766112.11</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -19,11 +19,14 @@
return gadget.getDeclaredGadget('sync_gadget')
.push(function (sync_gadget) {
// start synchronization now if possible (not running already)
return sync_gadget.registerSync({now: true});
return sync_gadget.register({now: true});
});
})
.push(function () {
gadget.redirect({command: "change", options: {page: "ojsm_status_list"}});
return gadget.redirect({
command: "change",
options: {page: "ojsm_status_list"}
});
});
});
}(window, rJS));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.53085.48571.55790</string> </value>
<value> <string>963.29336.22296.43468</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1508159965.22</float>
<float>1510668189.54</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -9,22 +9,17 @@
<script src="rsvp.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 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="template-view"></div>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
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"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
......
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.1858.13217.15684</string> </value>
<value> <string>963.29465.32349.33501</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1509018559.06</float>
<float>1510675412.13</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, Handlebars, OPMLManage */
/*global window, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, OPMLManage) {
(function (window, rJS, RSVP) {
"use strict";
var gadget_klass = 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);
})
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
......@@ -40,9 +18,14 @@
/////////////////////////////////////////////////////////////////
.onEvent('submit', function () {
var gadget = this,
doc;
doc,
opml_gadget;
return new RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget('opml_gadget');
})
.push(function (g) {
opml_gadget = g;
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
......@@ -50,37 +33,24 @@
})
.push(function (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) {
// password was modified, update on backend
doc.new_password = doc.password;
doc.confirm_new_password = doc.new_password;
doc.password = gadget.state.password;
doc.verify_password = 1;
}
return true;
return opml_gadget.checkOPMLForm(doc);
})
.push(function (state) {
if (state) {
return gadget.notifySubmitting()
.push(function () {
doc.title = gadget.state.opml_title;
return opml_global.saveOPML(doc,
doc.title === "" || doc.title === undefined || doc.verify_password === 1);
return opml_gadget.saveOPML(
doc,
doc.title === "" || doc.title === undefined || doc.verify_password === 1
);
})
.push(function (status) {
var msg = {message: 'Document Updated', status: 'success'};
......@@ -92,11 +62,10 @@
status
]);
})
.push(function (result_list) {
if (result_list[1] && gadget.state.redirect) {
return gadget.redirect({
"command": "change",
"options": {"page": "ojsm_status_list"}
.push(function (result) {
if (result[1]) {
return gadget.changeState({
"password": doc.password
});
}
});
......@@ -224,7 +193,7 @@
});
})
.push(function () {
return gadget.changeState({redirect: false})
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'history_previous'}),
......@@ -258,4 +227,4 @@
});
});
});
}(window, rJS, RSVP, Handlebars, OPMLManage));
}(window, rJS, RSVP));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.21293.17700.853</string> </value>
<value> <string>963.29546.42896.22118</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1510185606.72</float>
<float>1510680193.17</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, Handlebars, RegExp */
/*global window, rJS, RSVP, Handlebars, RegExp, document, atob */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, RegExp) {
(function (window, rJS, RSVP, Handlebars, RegExp, document, atob) {
"use strict";
var gadget_klass = rJS(window),
......@@ -10,20 +10,22 @@
link_template = Handlebars.compile(source);
function getPromiseTextContent(content, private_url) {
/*jslint regexp: true*/
var regex = /(https?:\/\/[^\s]+)/g,
i,
parser,
private_parser = document.createElement('a'),
result_list = content.match(regex),
url_list = [];
/*jslint regexp: false*/
function makeUnique(array_list) {
var temp = {},
i,
l,
r = [],
k;
for (i = 0; i < array_list.length; i += 1) {
temp[array_list[i]] = true;
for (l = 0; l < array_list.length; l += 1) {
temp[array_list[l]] = true;
}
for (k in temp) {
if (temp.hasOwnProperty(k)) {
......@@ -57,14 +59,15 @@
for (i = 0; i < url_list.length; i += 1) {
content = content.replace(
new RegExp(url_list[i].url, 'g'),
url_list[i].next);
url_list[i].next
);
}
return content;
}
gadget_klass
.setState({
jio_gadget: "",
jio_gadget: ""
})
.ready(function (gadget) {
return gadget.getDeclaredGadget("jio_gadget")
......@@ -80,7 +83,6 @@
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("redirect", "redirect")
......@@ -90,9 +92,7 @@
.declareMethod("render", function (options) {
var gadget = this,
hosting_subscription,
software_instance,
opml_outline,
opml_doc;
return new RSVP.Queue()
......@@ -117,9 +117,6 @@
],
query: '(portal_type:"global") AND (parent_id:"' +
options.doc.parent_id + '")'
}, function (error) {
console.log(error);
return {};
});
})
.push(function (result) {
......@@ -131,7 +128,6 @@
return gadget.jio_get(options.doc.parent_id);
})
.push(function (outline_doc) {
opml_outline = outline_doc;
// get opml
return gadget.jio_get(outline_doc.parent_url);
})
......@@ -153,10 +149,10 @@
_embedded: {instance: {}}};
}
// fix URLs
software_instance._links.private_url.href = software_instance.
_links.private_url.href.replace("jio_private", "private");
software_instance._links.public_url.href = software_instance.
_links.public_url.href.replace("jio_public", "public");
software_instance._links.private_url.href = software_instance
._links.private_url.href.replace("jio_private", "private");
software_instance._links.public_url.href = software_instance
._links.public_url.href.replace("jio_public", "public");
pass_url = "https://" + atob(opml_doc.basic_login) +
"@" + software_instance._links.private_url.href.split("//")[1];
......@@ -202,8 +198,14 @@
gadget.state.promise.source + ".history"
)
.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;
});
})
.push(function (status_history) {
var i,
......@@ -223,7 +225,7 @@
//if (lines > len) {
// 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);
if (message.length >= 60) {
message += "...";
......@@ -266,7 +268,8 @@
editable: 0,
hidden: 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",
required: 0,
timezone_style: 0,
......@@ -506,14 +509,21 @@
}
},
form_definition: {
group_list: [[
group_list: [
[
"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",
[["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",
......@@ -522,7 +532,8 @@
[
"bottom",
[["your_promise_history"]]
]]
]
]
}
});
})
......@@ -543,4 +554,4 @@
});
});
});
}(window, rJS, RSVP, Handlebars, RegExp));
}(window, rJS, RSVP, Handlebars, RegExp, document, atob));
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.706.49244.32460</string> </value>
<value> <string>963.29333.34848.27204</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1508949544.51</float>
<float>1510666984.34</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -108,7 +108,7 @@
<item>
<key> <string>text_content</string> </key>
<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
# images/ajax-loader.gif\n
CACHE:\n
......@@ -133,8 +133,6 @@ dygraph.js\n
handlebars.js\n
jiodev.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_web_storage.js\n
jsen.min.js\n
......@@ -197,6 +195,8 @@ gadget_erp5_jio.html\n
gadget_erp5_jio.js\n
gadget_erp5_search_editor.html\n
gadget_erp5_search_editor.js\n
gadget_erp5_sort_editor.html\n
gadget_erp5_sort_editor.js\n
\n
# monitoring\n
gadget_officejs_monitoring.appcache\n
......@@ -222,6 +222,7 @@ gadget_erp5_page_ojsm_status_list.html\n
gadget_erp5_page_ojsm_synchronize.html\n
gadget_erp5_page_ojsm_erp5_configurator.html\n
gadget_erp5_page_ojsm_jump.html\n
gadget_officejs_monitoring_opml_edit.html\n
\n
# monitoring js\n
gadget_officejs_monitoring_jio.js\n
......@@ -248,7 +249,7 @@ gadget_officejs_jio_opml_view.js\n
gadget_erp5_page_ojsm_synchronize.js\n
gadget_erp5_page_ojsm_jump.js\n
gadget_erp5_page_ojsm_erp5_configurator.js\n
gadget_officejs_monitoring_global.js\n
gadget_officejs_monitoring_opml_edit.js\n
\n
# erp5_web_renderjs_ui\n
gadget_erp5_editor_panel.html\n
......@@ -383,7 +384,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.22437.57747.1757</string> </value>
<value> <string>963.30985.26464.16281</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -401,7 +402,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1510327329.0</float>
<float>1510766013.21</float>
<string>UTC</string>
</tuple>
</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 @@
</item>
<item>
<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>
<key> <string>description</string> </key>
......@@ -93,7 +93,7 @@
</item>
<item>
<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>
<key> <string>language</string> </key>
......@@ -111,7 +111,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Monitoring Global Js</string> </value>
<value> <string>Monitoring OPML edit widget Js</string> </value>
</item>
<item>
<key> <string>version</string> </key>
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.1892.25677.55654</string> </value>
<value> <string>963.29541.62889.7577</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1509020867.3</float>
<float>1510680916.21</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -273,7 +273,7 @@
.declareService(function () {
return this.getDeclaredGadget("sync_gadget")
.push(function (sync_gadget) {
return sync_gadget.registerSync();
return sync_gadget.register();
});
})
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.52822.35420.57019</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1509093907.79</float>
<float>1510668451.66</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS */
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS) {
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
rJS(window)
.ready(function (gadget) {
gadget.props = {};
return gadget.getDeclaredGadget("jio_gadget")
......@@ -17,7 +17,7 @@ rJS(window)
var gadget = this;
return new RSVP.Queue()
.push(function () {
gadget.props.jio_gadget.createJio({
return gadget.props.jio_gadget.createJio({
type: "query",
sub_storage: {
type: "drivetojiomapping",
......@@ -28,6 +28,8 @@ rJS(window)
}
}
});
})
.push(function () {
return gadget.changeState({
parameter_list: options.parameters,
save_to: 'config.tmp',
......@@ -51,14 +53,10 @@ rJS(window)
.push(function (form_gadget) {
var i,
parameter_dict = {},
group_list = [[
"left",
[]
],
[
"right",
[]
]];
group_list = [
["left", []],
["right", []]
];
for (i = 0; i < gadget.state.parameter_list.length; i += 1) {
parameter_dict[gadget.state.parameter_list[i].title] = {
"description": "",
......@@ -73,7 +71,7 @@ rJS(window)
"hidden": 0,
"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({
erp5_document: {
......@@ -117,9 +115,8 @@ rJS(window)
return form_gadget.getContent();
})
.push(function (doc) {
var parameter_dict = {},
var key,
parameter_list = JSON.parse(JSON.stringify(gadget.state.parameter_list)),
key,
i;
for (i = 0; i < parameter_list.length; i += 1) {
key = gadget.state.key + '_' + parameter_list[i].title;
......@@ -132,10 +129,10 @@ rJS(window)
.push(function () {
return {status: 'OK'};
}, function (error) {
console.log(error);
//console.log(error);
return {status: 'ERROR', code: error.target.status,
url: gadget.state.url, stage: "Saving file"};
});
});
}(window, rJS));
\ No newline at end of file
}(window, rJS, RSVP));
\ No newline at end of file
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.48797.18350.58214</string> </value>
<value> <string>963.27984.14453.52343</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1507902562.82</float>
<float>1510664009.77</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, clearTimeout, setTimeout, console, XMLHttpRequest, document */
/*global window, rJS, RSVP, console, XMLHttpRequest, document */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, console, clearTimeout, setTimeout,
XMLHttpRequest, document) {
(function (window, rJS, RSVP, console, XMLHttpRequest, document) {
"use strict";
var gadget_klass = rJS(window);
......@@ -17,7 +16,7 @@
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareMethod("registerSync", function (options) {
.declareMethod("register", function (options) {
var gadget = this;
function testOnline(url) {
......@@ -35,7 +34,7 @@
}
};
xhr.onerror = function (e) {
xhr.onerror = function () {
reject({
status: 'ERROR'
});
......@@ -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() {
var has_error = false,
last_sync_time;
......@@ -104,8 +67,10 @@
return gadget.jio_repair();
})
.push(undefined, function (error) {
// should include error message in error
has_error = true;
console.error(error);
// return false so it will trigger the next run
return false;
})
.push(function () {
......@@ -116,18 +81,13 @@
]);
})
.push(function () {
var time = 3000,
classname = "success",
message = "Synchronisation finished.",
//log_message = '',
log_title = "OK: " + message;
var classname = "success",
message = "Synchronisation finished.";
if (has_error) {
classname = "error";
time = 5000;
//log_message = getErrorLog(gadget.props.error_list);
log_title = "Synchronisation finished with error(s).";
message = log_title + "\nYou can retry with manual sync.";
message = "Synchronisation finished with error(s).";
message += " \nYou can retry with manual sync.";
}
return gadget.notifySubmitted({
message: message,
......@@ -148,12 +108,37 @@
});
}
function syncDataTimer() {
if (gadget.props.timer) {
clearTimeout(gadget.props.timer);
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;
});
}
gadget.props.timer = setTimeout(function () {
return syncAllStorage();
});
}
function syncDataTimer() {
return new RSVP.Queue()
.push(function () {
return RSVP.delay(gadget.props.timer_interval);
})
.push(function () {
return gadget.getSetting('sync_start_time');
})
......@@ -162,15 +147,11 @@
if (start_timestamp !== undefined &&
(current_time - gadget.props.timer_interval) <=
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 syncAllStorageWithCheck();
})
.push(undefined, function (error) {
console.error(error);
return;
})
.push(function () {
return gadget.getSetting('sync_data_interval');
})
......@@ -184,8 +165,6 @@
gadget.props.timer_interval = timer_interval;
return syncDataTimer();
});
}, gadget.props.timer_interval);
return gadget.props.timer;
}
......@@ -244,5 +223,4 @@
});
});
}(window, rJS, RSVP, console, clearTimeout, setTimeout, XMLHttpRequest,
document));
\ No newline at end of file
}(window, rJS, RSVP, console, XMLHttpRequest, document));
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.21916.52285.31846</string> </value>
<value> <string>963.29129.42634.5819</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510233154.98</float>
<float>1510655414.57</float>
<string>UTC</string>
</tuple>
</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