Commit df54ab65 authored by amrani's avatar amrani

Added POPUP gadget

Added POPUP file to appchache
some Modification to support dropbox encryption and cryptostorage
added callback to mapping and date storage as well as all other JIO storage
parent f4e03e05
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 OJS POPUP</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="handlebars.js" type="text/javascript"></script>
<script id="popup_password" type="text/x-handlebars-template">
<div class="overlay">
<h3 class="header">{{message}}</h3>
<span class="ui-icon ui-icon-lock"></span>
<form>
<input placeholder="Password" autocomplete="off" class="ui-password-overlay" type="password" required>
<br>
<button type="submit" >Proceed</button>
</form>
</div>
</script>
<!-- custom script -->
<script src="gadget_erp5_popup.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, Handlebars, RSVP, TextEncoder */
(function (window, rJS, RSVP, Handlebars, TextEncoder) {
"use strict";
var gadget_klass = rJS(window),
popup = gadget_klass.__template_element
.getElementById("popup_password")
.innerHTML,
popup_template = Handlebars.compile(popup);
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
gadget_klass
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("redirect", "redirect")
//////////////////////////////////////////
// Converting from user key to Cryptokey
/////////////////////////////////////////
.declareMethod('convertKey', function (str) {
var buffer = new TextEncoder("utf-8").encode(str);
// We transform the string into an arraybuffer.
return new RSVP.Queue()
.push(function () {
return RSVP.all([window.crypto.subtle.digest("SHA-256", buffer),
window.crypto.subtle.importKey(
"raw",
buffer,
{name: "PBKDF2"
},
false,
["deriveKey"]
)
]);
})
.push(function (my_array) {
return {
CryptoKey: my_array[1],
Salt: my_array[0]
};
})
.push(undefined, function (error) {
throw error;
});
})
//////////////////////////////////////////
// Displaying POPUP function
/////////////////////////////////////////
.declareMethod('display_popup', function (options) {
var gadget = this;
if (options && options.message && options.addkey && options.error) {
return this.changeState({
visible: true,
message: options.message,
addkey: options.addkey,
error: options.error
})
.push(function () {
return gadget.notifySubmitted({message: gadget.state.error.error_message,
status: 'failure'});
});
}
})
.declareMethod('close', function () {
return this.changeState({
visible: false
});
})
.onStateChange(function (modification_dict) {
var gadget = this;
if (modification_dict.hasOwnProperty('visible')) {
if (gadget.state.visible) {
if (!gadget.element.classList.contains('visible')) {
gadget.element.classList.toggle('visible');
}
} else {
if (gadget.element.classList.contains('visible')) {
gadget.element.classList.remove('visible');
}
}
}
if (modification_dict.hasOwnProperty('message') && modification_dict.hasOwnProperty('addkey') &&
modification_dict.hasOwnProperty('error')) {
//window.top.document.body.addEventListener("click", function (evt) {
//evt.stopPropagation();
//evt.preventDefault();
//}, true);
gadget.element.innerHTML = popup_template({
message: gadget.state.message
});
}
})
//////////////////////////////////////////
// Evenet lisener on input
/////////////////////////////////////////
.declareMethod('add_lisener_input', function (input_pass) {
var gadget = this;
input_pass.addEventListener('input', function () {
gadget.notifySubmitted();
}, {once: true});
return;
})
//////////////////////////////////////////
// Form submit
/////////////////////////////////////////
.onEvent('submit', function () {
var gadget = this,
input_pass_value,
input_pass = this.element.querySelector("input.ui-password-overlay");
if (input_pass.value !== undefined && input_pass.value !== null && input_pass.value !== "") {
input_pass_value = input_pass.value;
if (input_pass_value.match(/^(?=[\w\W]*\d)(?=[\w\W]*[a-z])(?=[\w\W]*[A-Z])[0-9a-zA-Z]{8,}$/)) {
return gadget.convertKey(input_pass_value)
.push(function (obj) {
return gadget.state.addkey(obj);
})
.push(function () {
return gadget.notifySubmitted();
})
.push(function () {
return gadget.close();
})
.push(function () {
return gadget.redirect({command: "display", options: {page: 'ojs_sync', auto_repair: 'true'}});
});
}
return gadget.add_lisener_input(input_pass)
.push(function () {
return gadget.notifySubmitted({message: 'Passwords must contain: \n' +
'a lower case letter [a-z] \n' +
'a upper case letter [A-Z] \n' +
'a numeric character [0-9] and \n ' +
'at least 8 characters in length', status: 'failure'});
});
}
return gadget.notifySubmitted({message: 'no field found', status: 'failure'});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
});
//.onEvent('click', function (evt) {
//if ((evt.target.nodeType === Node.ELEMENT_NODE) &&
// (evt.target.tagName === 'BUTTON')) {
//return this.close();
//}
//}, false, false);
}(window, rJS, RSVP, Handlebars, TextEncoder));
\ No newline at end of file
......@@ -181,6 +181,8 @@ gadget_html5_element.html\n
gadget_html5_element.js\n
gadget_erp5_notification.html\n
gadget_erp5_notification.js\n
gadget_erp5_popup.html\n
gadget_erp5_popup.js\n
gadget_erp5_field_string.html\n
gadget_erp5_field_string.js\n
gadget_erp5_field_editor.html\n
......@@ -348,7 +350,7 @@ NETWORK:\n
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -362,7 +364,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.48513.5538.10342</string> </value>
<value> <string>966.44456.34486.30566</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -380,7 +382,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1516115771.45</float>
<float>1532963989.74</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -185,6 +185,8 @@ gadget_html5_element.html\n
gadget_html5_element.js\n
gadget_erp5_notification.html\n
gadget_erp5_notification.js\n
gadget_erp5_popup.html\n
gadget_erp5_popup.js\n
gadget_erp5_field_string.html\n
gadget_erp5_field_string.js\n
gadget_erp5_field_editor.html\n
......@@ -352,7 +354,7 @@ NETWORK:\n
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -366,7 +368,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.45561.47559.9591</string> </value>
<value> <string>966.44456.34486.30566</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -384,7 +386,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1515771172.06</float>
<float>1532963940.17</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -182,6 +182,8 @@ gadget_html5_element.html\n
gadget_html5_element.js\n
gadget_erp5_notification.html\n
gadget_erp5_notification.js\n
gadget_erp5_popup.html\n
gadget_erp5_popup.js\n
gadget_erp5_field_string.html\n
gadget_erp5_field_string.js\n
gadget_erp5_field_editor.html\n
......@@ -603,7 +605,7 @@ NETWORK:\n
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -617,7 +619,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.58581.32438.37376</string> </value>
<value> <string>966.44456.34486.30566</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -635,7 +637,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1518539910.86</float>
<float>1532963922.74</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, jIO, FormData, UriTemplate */
/*global window, rJS, jIO, FormData, UriTemplate */
/*jslint indent: 2, maxerr: 3 */
(function (window, rJS, jIO) {
(function (window, rJS, jIO, RSVP) {
"use strict";
// jIO call wrapper for redirection to authentication page if needed
......@@ -49,6 +51,11 @@
return gadget.redirect({ command: "row", url: site});
}
}
if (error.hasOwnProperty("status_code") && error.status_code === 801) {
if (gadget.state_parameter_dict.jio_storage_name === "DROPBOX") {
throw error.message;
}
}
throw error;
});
}
......@@ -64,9 +71,21 @@
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod('getUrlFor', 'getUrlFor')
.declareAcquiredMethod('popupshow', 'popupshow')
.declareMethod('createJio', function (jio_options) {
var gadget = this;
var gadget = this,
utils = {"crypto_getCryptoKey": function (callback) {
return new RSVP.Queue()
.push(function () {
return gadget.popupshow({message: "Provide your password for dropbox encryption ",
addkey: callback.addkey_crypto,
error: callback.error_crypto });
})
.push(undefined, function (error) {
throw error;
});
}
};
if (jio_options === undefined) {
return;
}
......@@ -76,7 +95,7 @@
property_list: ['modification_date']
};
try {
this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options);
this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options, utils);
} catch (error) {
this.state_parameter_dict.jio_storage = undefined;
}
......@@ -116,4 +135,4 @@
return wrapJioCall(this, 'repair', arguments);
});
}(window, rJS, jIO));
\ No newline at end of file
}(window, rJS, jIO, RSVP));
\ No newline at end of file
......@@ -222,7 +222,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.36985.29761.10359</string> </value>
<value> <string>969.1654.46860.62464</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1507216488.77</float>
<float>1532081552.21</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -4,6 +4,7 @@
"use strict";
function setDropboxConfiguration(gadget, token) {
var keyid = "key" + Math.floor(Math.random() * 7000).toString();
return new RSVP.Queue()
.push(function () {
return RSVP.all([
......@@ -34,8 +35,6 @@
check_remote_modification: true,
check_remote_creation: true,
check_remote_deletion: true,
parallel_operation_attachment_amount: 50,
parallel_operation_amount: 50,
signature_sub_storage: {
type: "query",
sub_storage: {
......@@ -47,21 +46,12 @@
}
},
local_sub_storage: {
type: "mapping",
attachment: {
DOCUMENT_REGEXP : {
get: {uri_template: 'enclosure'},
put: {uri_template: 'enclosure'}
}
},
type: "query",
sub_storage: {
type: "query",
type: "uuid",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "officejs-dropbox"
}
type: "indexeddb",
database: "officejs-dropbox"
}
}
},
......@@ -82,7 +72,7 @@
type: "drivetojiomapping",
sub_storage: {
type: "crypt",
key: 'amrani',
keyid: keyid,
sub_storage: {
type: "dropbox",
access_token: token,
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>967.9063.45697.9454</string> </value>
<value> <string>968.63024.5682.53521</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1525334912.53</float>
<float>1531832487.77</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -182,6 +182,8 @@ gadget_html5_element.html\n
gadget_html5_element.js\n
gadget_erp5_notification.html\n
gadget_erp5_notification.js\n
gadget_erp5_popup.html\n
gadget_erp5_popup.js\n
gadget_erp5_field_string.html\n
gadget_erp5_field_string.js\n
gadget_erp5_field_editor.html\n
......@@ -575,7 +577,7 @@ NETWORK:\n
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -589,7 +591,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.54546.48173.5239</string> </value>
<value> <string>966.44456.34486.30566</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -607,7 +609,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1516026588.79</float>
<float>1532963871.52</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -159,8 +159,8 @@ gadget_erp5_page_ojs_dav_configurator.html\n
gadget_erp5_page_ojs_dav_configurator.js\n
gadget_erp5_page_ojs_erp5_configurator.html\n
gadget_erp5_page_ojs_erp5_configurator.js\n
gadget_erp5_page_ojs_dropbox_configurator.html\n
gadget_erp5_page_ojs_dropbox_configurator.js\n
gadget_erp5_popup.html\n
gadget_erp5_popup.js\n
gadget_erp5_page_ojs_sync.html\n
gadget_erp5_page_ojs_sync.js\n
gadget_erp5_page_ojs_document_list.html\n
......@@ -685,7 +685,7 @@ NETWORK:\n
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -699,7 +699,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.48519.41997.58350</string> </value>
<value> <string>967.34686.32911.56883</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -717,7 +717,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1515675473.77</float>
<float>1532944919.09</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -178,9 +178,10 @@
}
}
function MappingStorage(spec) {
function MappingStorage(spec, utils) {
this.utils = utils;
this._mapping_dict = spec.property || {};
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._sub_storage = jIO.createJIO(spec.sub_storage, utils);
this._map_all_property = spec.map_all_property !== undefined ?
spec.map_all_property : true;
this._no_sub_query_id = spec.no_sub_query_id;
......@@ -648,8 +649,9 @@
return doc;
}
function DateUpdaterStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
function DateUpdaterStorage(spec, utils) {
this.utils = utils;
this._sub_storage = jIO.createJIO(spec.sub_storage, utils);
this._property_list = spec.property_list || [];
}
......@@ -726,8 +728,9 @@
*/
function SafeRepairStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
function SafeRepairStorage(spec, utils) {
this.utils = utils;
this._sub_storage = jIO.createJIO(spec.sub_storage, utils);
this._id_dict = {};
}
......
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.45923.44376.29252</string> </value>
<value> <string>966.44456.34486.30566</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1507730215.96</float>
<float>1530609994.82</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -175,6 +175,8 @@ gadget_html5_element.html\n
gadget_html5_element.js\n
gadget_erp5_notification.html\n
gadget_erp5_notification.js\n
gadget_erp5_popup.html\n
gadget_erp5_popup.js\n
gadget_erp5_field_string.html\n
gadget_erp5_field_string.js\n
gadget_erp5_field_editor.html\n
......@@ -326,7 +328,7 @@ NETWORK:\n
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -340,7 +342,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.45561.47559.9591</string> </value>
<value> <string>966.44456.34486.30566</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -358,7 +360,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1515773947.57</float>
<float>1532963857.09</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