diff --git a/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/gadget_officejs_monitoring_opml_edit_js.js b/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/gadget_officejs_monitoring_opml_edit_js.js index 2cf97764009c2da3f19c2615c1cc61636daa28cf..e579cea2fcdb1140c2f5878e730ca28acc081fc9 100644 --- a/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/gadget_officejs_monitoring_opml_edit_js.js +++ b/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/gadget_officejs_monitoring_opml_edit_js.js @@ -1,6 +1,6 @@ -/*global window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars */ +/*global window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars, jIO */ /*jslint nomen: true, indent: 2, maxerr: 3*/ -(function (window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars) { +(function (window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars, jIO) { "use strict"; var gadget_klass = rJS(window), @@ -108,7 +108,7 @@ }); } - function checkCredential(url, title, hash) { + function checkCredential(url, title, hash, new_hash) { // Verify if login and password are correct for this URL if (url === undefined) { return {status: 'OK'}; @@ -122,6 +122,17 @@ msg: error.msg + ' (' + url + ')', title: title }; + if (new_hash !== undefined) { + // saved password is not valid + // check if inputted password is valid + return testUrl(url, new_hash) + .then(function () { + ko_msg.hash = new_hash; + return ko_msg; + }, function () { + return ko_msg; + }); + } return ko_msg; }); } @@ -152,7 +163,8 @@ attachment_id: 'enclosure', parser: 'opml', sub_storage: { - type: "http" + type: "http", + timeout: 25000 // timeout after 25 seconds } } }) @@ -162,25 +174,40 @@ }); }) .push(undefined, function (error) { + var message_text, + code; + if (error instanceof jIO.util.jIOError) { + message_text = error.message; + code = error.status_code; + } else { + code = error.target.status; + message_text = error.target.responseType === "text" ? + error.target.statusText : ""; + } gadget.state.message .innerHTML = notify_msg_template({ status: 'error', - message: error.target.status + - ": Failed to access OPML URL. " + error.message + message: code + ": Failed to access OPML URL. " + + message_text }); return {data: {total_rows: 0}}; }) .push(function (opml_result) { var i, - check_list = [true]; + check_list = [true], + new_login; if (opml_result.data.total_rows > 0) { opml_dict.title = opml_result.data.rows[0].value.title; + if (doc.new_password) { + new_login = btoa(doc.username + ':' + doc.new_password); + } 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 + opml_dict.basic_login, + new_login )); update_password_list.push({ base_url: opml_result.data.rows[i].value.url, @@ -195,14 +222,28 @@ }) .push(function (status_list) { var i, - error_msg = ''; + error_msg = '', + used_new_passwd_count = 0; + // in case the current password in opml is wrong and new + // password provided is OK, we set it as the current password in opml. for (i = 1; i < status_list.length; i += 1) { if (status_list[i].status !== 'OK') { + if (status_list[i].hash !== undefined) { + used_new_passwd_count += 1; + } error_msg += 'Login/password invalid for instance: ' + status_list[i].title + '. ' + status_list[i].msg + '\n'; } } + if (used_new_passwd_count > 0 && + used_new_passwd_count === (status_list.length - 1)) { + // all backends password are OK, we only update our password + opml_dict.password = doc.new_password; + doc.new_password = ''; + opml_dict.basic_login = status_list[1].hash; + return true; + } if (error_msg !== '') { gadget.state.message .innerHTML = notify_msg_template({ @@ -352,4 +393,4 @@ return saveOPML(this, form_doc, verify_password); }); -}(window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars)); +}(window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars, jIO)); diff --git a/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/gadget_officejs_monitoring_opml_edit_js.xml b/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/gadget_officejs_monitoring_opml_edit_js.xml index 03e5584f7a6867062f3e06c0923faf1741367baf..486024cb76faac43cfea63f494e7465a4ca25989 100644 --- a/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/gadget_officejs_monitoring_opml_edit_js.xml +++ b/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/gadget_officejs_monitoring_opml_edit_js.xml @@ -242,7 +242,7 @@ </item> <item> <key> <string>serial</string> </key> - <value> <string>963.29541.62889.7577</string> </value> + <value> <string>964.28658.19106.46779</string> </value> </item> <item> <key> <string>state</string> </key> @@ -260,7 +260,7 @@ </tuple> <state> <tuple> - <float>1510680916.21</float> + <float>1514476756.65</float> <string>UTC</string> </tuple> </state> diff --git a/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/monitoring_jio_storage_js.js b/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/monitoring_jio_storage_js.js index b77e62c1f38fcf6f4723102ab0728a4592a6de54..d26077e8f8dff4b5f96c6a935075f63fb4f65a54 100644 --- a/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/monitoring_jio_storage_js.js +++ b/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/monitoring_jio_storage_js.js @@ -38,10 +38,16 @@ } function createStorage(context, storage_spec, key) { - if (!context._remote_storage_dict.hasOwnProperty(key)) { - context._remote_storage_dict[key] = jIO.createJIO(storage_spec); + var signature; + signature = generateHash(JSON.stringify(storage_spec)); + if (!context._remote_storage_dict.hasOwnProperty(key) || + signature !== context._remote_storage_dict[key].signature) { + context._remote_storage_dict[key] = { + storage: jIO.createJIO(storage_spec), + signature: signature + }; } - return context._remote_storage_dict[key]; + return context._remote_storage_dict[key].storage; } /** diff --git a/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/monitoring_jio_storage_js.xml b/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/monitoring_jio_storage_js.xml index be8259e69a168c8bafcd138b24c9c548021ca325..65af5cbc12d710e5600ab2be322c01a4b35b92ee 100644 --- a/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/monitoring_jio_storage_js.xml +++ b/bt5/erp5_web_monitoring/PathTemplateItem/web_page_module/monitoring_jio_storage_js.xml @@ -239,7 +239,7 @@ </item> <item> <key> <string>serial</string> </key> - <value> <string>964.6864.64042.34201</string> </value> + <value> <string>964.7018.29631.50551</string> </value> </item> <item> <key> <string>state</string> </key> @@ -257,7 +257,7 @@ </tuple> <state> <tuple> - <float>1513173747.08</float> + <float>1514476144.01</float> <string>UTC</string> </tuple> </state>