Commit 47ee7f53 authored by Vincent Bechu's avatar Vincent Bechu Committed by Vincent Bechu

erp5_officejs: fix add document in codeeditor

parent 8509511d
...@@ -24,12 +24,12 @@ ...@@ -24,12 +24,12 @@
<div class="ui-field-contain"> <div class="ui-field-contain">
<label data-i18n="Url String:">Url String</label> <label data-i18n="Url String:">Url String</label>
<input type="text" name="url_string" value="{{url_string}}"> <input type="text" name="url_string" value="{{url_string}}" required>
</div> </div>
<div class="ui-field-contain"> <div class="ui-field-contain">
<label data-i18n="Version:">Version:</label> <label data-i18n="Portal Type:">Portal Type:</label>
<input type="text" name="version" value="{{version}}"></label> <input type="text" name="portal_type" value="{{portal_type}}" required></label>
</div> </div>
<div class="ui-field-contain"> <div class="ui-field-contain">
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.55534.43957.17220</string> </value> <value> <string>955.59479.11249.61201</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1481330026.08</float> <float>1481540323.2</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*globals window, rJS, Handlebars, RSVP, loopEventListener, console*/ /*globals window, rJS, Handlebars, RSVP, loopEventListener, console*/
/*jslint indent: 2, nomen: true, maxlen: 80*/ /*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS, Handlebars, loopEventListener) { (function (window, RSVP, rJS, Handlebars, loopEventListener) {
"use strict"; "use strict";
function saveContent(gadget, submit_event) { function saveContent(gadget, submit_event) {
var i, var i,
doc = gadget.options.doc, doc = gadget.options.doc,
now = new Date(); now = new Date();
doc.modification_date = now.toISOString(); doc.modification_date = now.toISOString();
for (i = 0; i < submit_event.target.length; i += 1) { for (i = 0; i < submit_event.target.length; i += 1) {
// XXX Should check input type instead // XXX Should check input type instead
if (submit_event.target[i].name) { if (submit_event.target[i].name) {
doc[submit_event.target[i].name] = submit_event.target[i].value; doc[submit_event.target[i].name] = submit_event.target[i].value;
} }
} }
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.getDeclaredGadget("my_text_content"); return gadget.getDeclaredGadget("my_text_content");
}) })
.push(function (text_content_gadget) { .push(function (text_content_gadget) {
return text_content_gadget.getContent(); return text_content_gadget.getContent();
}) })
.push(function (data) { .push(function (data) {
doc.text_content = data.text_content; doc.text_content = data.text_content;
doc.parent_relative_url = data.parent_relative_url || "web_page_module"; doc.parent_relative_url = data.parent_relative_url || "web_page_module";
doc.portal_type = data.portal_type || "Web Page"; doc.portal_type = data.portal_type || "Web Page";
return gadget.put(gadget.options.jio_key, doc); if (gadget.options.jio_key !== doc.url_string) {
}); return gadget.remove(gadget.options.jio_key);
} }
})
function maximize(gadget) { .push(function () {
var iframe = gadget.props.element.querySelector('iframe'), return gadget.put(doc.url_string, doc);
iframe_class_string = iframe.getAttribute('class') || "", });
class_name = "ui-content-maximize", }
class_index = iframe_class_string.indexOf(class_name);
if (class_index === -1) { function maximize(gadget) {
iframe_class_string += ' ' + class_name; var iframe = gadget.props.element.querySelector('iframe'),
iframe.setAttribute('style', ''); iframe_class_string = iframe.getAttribute('class') || "",
iframe.setAttribute('class', iframe_class_string); class_name = "ui-content-maximize",
return true; class_index = iframe_class_string.indexOf(class_name);
} if (class_index === -1) {
iframe_class_string = iframe_class_string.substring(0, class_index) iframe_class_string += ' ' + class_name;
+ iframe_class_string.substring(class_index + class_name.length); iframe.setAttribute('style', '');
iframe.setAttribute('style', 'width:100%; border: 0 none; height: 600px'); iframe.setAttribute('class', iframe_class_string);
iframe.setAttribute('class', iframe_class_string); return true;
return false; }
} iframe_class_string = iframe_class_string.substring(0, class_index)
+ iframe_class_string.substring(class_index + class_name.length);
var gadget_klass = rJS(window), iframe.setAttribute('style', 'width:100%; border: 0 none; height: 600px');
source = gadget_klass.__template_element iframe.setAttribute('class', iframe_class_string);
.querySelector(".view-web-page-template") return false;
.innerHTML, }
template = Handlebars.compile(source);
var gadget_klass = rJS(window),
source = gadget_klass.__template_element
gadget_klass .querySelector(".view-web-page-template")
.ready(function (g) { .innerHTML,
g.props = {}; template = Handlebars.compile(source);
g.options = null;
return g.getElement()
.push(function (element) { gadget_klass
g.props.element = element; .ready(function (g) {
g.props.deferred = RSVP.defer(); g.props = {};
}); g.options = null;
}) return g.getElement()
.push(function (element) {
.declareAcquiredMethod("updateHeader", "updateHeader") g.props.element = element;
.declareAcquiredMethod("get", "jio_get") g.props.deferred = RSVP.defer();
.declareAcquiredMethod("translateHtml", "translateHtml") });
.declareAcquiredMethod("put", "jio_put") })
.declareAcquiredMethod('allDocs', 'jio_allDocs')
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("get", "jio_get")
.allowPublicAcquisition('triggerSubmit', function (option) { .declareAcquiredMethod("translateHtml", "translateHtml")
if (option[0] === "maximize" || option === "maximize") { .declareAcquiredMethod("put", "jio_put")
var gadget = this; .declareAcquiredMethod("remove","jio_remove")
return RSVP.Queue() .declareAcquiredMethod('allDocs', 'jio_allDocs')
.push(function () { .declareAcquiredMethod("redirect", "redirect")
return maximize(gadget);
}); .allowPublicAcquisition('triggerSubmit', function (option) {
} if (option[0] === "maximize" || option === "maximize") {
return this.props.element.querySelector('button').click(); var gadget = this;
}) return RSVP.Queue()
.push(function () {
.declareMethod('triggerSubmit', function (option) { return maximize(gadget);
if (option[0] === "maximize" || option === "maximize") { });
var gadget = this; }
return RSVP.Queue() return this.props.element.querySelector('button').click();
.push(function () { })
return maximize(gadget);
}); .declareMethod('triggerSubmit', function (option) {
} if (option[0] === "maximize" || option === "maximize") {
return this.props.element.querySelector('button').click(); var gadget = this;
}) return RSVP.Queue()
.push(function () {
.declareMethod("render", function (options) { return maximize(gadget);
var gadget = this; });
gadget.options = options; }
gadget.options.doc.title = gadget.options.doc.title || ""; return this.props.element.querySelector('button').click();
return new RSVP.Queue() })
.push(function () {
return gadget.translateHtml(template(options.doc)); .declareMethod("render", function (options) {
}) var gadget = this;
.push(function (html) { gadget.options = options;
gadget.props.element.innerHTML = html; gadget.options.doc.title = gadget.options.doc.title || "";
return gadget.updateHeader({ gadget.options.doc.url_string = gadget.options.jio_key;
title: options.doc.title + '|' + return new RSVP.Queue()
options.doc.portal_type || "| Web Page", .push(function () {
save_action: true, return gadget.translateHtml(template(options.doc));
maximize_action: true, })
maximized: gadget.options.doc.title !== "" .push(function (html) {
}); gadget.props.element.innerHTML = html;
}) return gadget.updateHeader({
.push(function () { title: options.doc.title + '|' +
return gadget.props.deferred.resolve(); options.doc.portal_type || "| Web Page",
}); save_action: true,
}) maximize_action: true,
maximized: gadget.options.doc.title !== ""
///////////////////////////////////////// });
// Render text content gadget })
///////////////////////////////////////// .push(function () {
.declareService(function () { return gadget.props.deferred.resolve();
var gadget = this; });
})
return new RSVP.Queue()
.push(function () { /////////////////////////////////////////
return gadget.props.deferred.promise; // Render text content gadget
}) /////////////////////////////////////////
.push(function () { .declareService(function () {
return gadget.declareGadget( var gadget = this;
"../../officejs_gadget_codemirror/codemirror/",
{ return new RSVP.Queue()
scope: "my_text_content", .push(function () {
sandbox: "iframe", return gadget.props.deferred.promise;
element: gadget.props.element.querySelector(".document-content") })
} .push(function () {
); return gadget.declareGadget(
}) "../../officejs_gadget_codemirror/codemirror/",
.push(function (text_content_gadget) { {
var iframe = gadget.props.element.querySelector('iframe'); scope: "my_text_content",
iframe.setAttribute( sandbox: "iframe",
'style', element: gadget.props.element.querySelector(".document-content")
'width:100%; border: 0 none; height: 600px' }
); );
return text_content_gadget.render({ })
"key": 'text_content', .push(function (text_content_gadget) {
"value": gadget.options.doc.text_content, var iframe = gadget.props.element.querySelector('iframe');
"mode": gadget.options.doc.content_type iframe.setAttribute(
}); 'style',
}) 'width:100%; border: 0 none; height: 600px'
.push(function () { );
if (gadget.options.doc.title !== "") { return text_content_gadget.render({
return gadget.triggerSubmit("maximize"); "key": 'text_content',
} "value": gadget.options.doc.text_content,
}) "mode": gadget.options.doc.content_type
.push(undefined, function (error) { });
var display_error_element; })
if (error === "Timed out after 5000 ms") { .push(function () {
display_error_element = if (gadget.options.doc.title !== "") {
gadget.props.element.querySelector( return gadget.triggerSubmit("maximize");
"form div.ui-field-contain fieldset" }
); })
display_error_element.innerHTML = .push(undefined, function (error) {
'<br/><p style="color: red"></p><br/><br/>'; var display_error_element;
display_error_element.querySelector('p').textContent = if (error === "Timed out after 5000 ms") {
"TIMEOUT: The editor gadget is taking too long to load but is" + display_error_element =
" currently being cached, please wait for the page to load" + gadget.props.element.querySelector(
" (check your browser loading icon) and then refresh."; "form div.ui-field-contain fieldset"
} else { );
throw error; display_error_element.innerHTML =
} '<br/><p style="color: red"></p><br/><br/>';
}); display_error_element.querySelector('p').textContent =
}) "TIMEOUT: The editor gadget is taking too long to load but is" +
" currently being cached, please wait for the page to load" +
///////////////////////////////////////// " (check your browser loading icon) and then refresh.";
// Form submit } else {
///////////////////////////////////////// throw error;
.declareService(function () { }
var gadget = this; });
})
return new RSVP.Queue()
.push(function () { /////////////////////////////////////////
return gadget.props.deferred.promise; // Form submit
}) /////////////////////////////////////////
.push(function () { .declareService(function () {
return loopEventListener( var gadget = this;
gadget.props.element.querySelector('form'),
'submit', return new RSVP.Queue()
true, .push(function () {
function (event) { return gadget.props.deferred.promise;
return saveContent(gadget, event); })
} .push(function () {
); return loopEventListener(
}); gadget.props.element.querySelector('form'),
}); 'submit',
true,
function (event) {
return saveContent(gadget, event);
}
);
});
});
}(window, RSVP, rJS, Handlebars, loopEventListener)); }(window, RSVP, rJS, Handlebars, loopEventListener));
\ No newline at end of file
...@@ -97,6 +97,10 @@ ...@@ -97,6 +97,10 @@
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value> <value> <string>Web Script</string> </value>
</item> </item>
<item>
<key> <string>revision</string> </key>
<value> <string>13</string> </value>
</item>
<item> <item>
<key> <string>short_title</string> </key> <key> <string>short_title</string> </key>
<value> <value>
...@@ -240,7 +244,7 @@ ...@@ -240,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.56020.64919.42120</string> </value> <value> <string>955.59464.8628.44953</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -258,7 +262,7 @@ ...@@ -258,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1481331946.97</float> <float>1481541034.32</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.55463.25205.4966</string> </value> <value> <string>955.56066.6312.29166</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1481295803.59</float> <float>1481541101.2</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.55463.28674.13312</string> </value> <value> <string>955.56066.6312.29166</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1481295806.77</float> <float>1481541119.53</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
type: "replicate", type: "replicate",
// XXX This drop the signature lists... // XXX This drop the signature lists...
query: { query: {
query: '(portal_type: ("Web Page","Web Script","Web Manifest","Web Style")) ' + query: 'portal_type: ("Web Page","Web Script","Web Manifest","Web Style")',
' AND (version: "' + version + '")',
limit: [0, 30], limit: [0, 30],
sort_on: [["modification_date", "descending"]] sort_on: [["modification_date", "descending"]]
}, },
...@@ -27,37 +26,38 @@ ...@@ -27,37 +26,38 @@
database: version + "_hash" database: version + "_hash"
} }
}, },
use_remote_post: true, use_remote_post: false,
conflict_handling: 1, conflict_handling: 1,
check_local_modification: true, check_local_modification: true,
check_local_creation: true, check_local_creation: true,
check_local_deletion: false, check_local_deletion: false,
check_remote_modification: true, check_remote_modification: true,
check_remote_creation: true, check_remote_creation: true,
check_remote_deletion: true, check_remote_deletion: false,
local_sub_storage: { local_sub_storage: {
type: "mapping", type: "query",
mapping_dict: {
"id": {"equal": "relative_url"},
"url_string": {"equal": "id"}
},
sub_storage: { sub_storage: {
type: "query", type: "uuid",
sub_storage: { sub_storage: {
type: "uuid", type: "indexeddb",
sub_storage: { database: version
type: "indexeddb",
database: version
}
} }
} }
}, },
remote_sub_storage: { remote_sub_storage: {
type: "erp5", type: "mapping",
url: (new URI("hateoas")) mapping_dict: {
.absoluteTo(erp5_url) "id": {"equal": "url_string"},
.toString(), "relative_url": "ignore",
default_view_reference: "jio_view" "version": {"default_value": version}
},
sub_storage: {
type: "erp5",
url: (new URI("hateoas"))
.absoluteTo(erp5_url)
.toString(),
default_view_reference: "jio_view"
}
} }
} }
); );
......
...@@ -97,6 +97,16 @@ ...@@ -97,6 +97,16 @@
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value> <value> <string>Web Script</string> </value>
</item> </item>
<item>
<key> <string>revision</string> </key>
<value> <string>7</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>OfficeJS jIO ERP5 Configurator Page JS</string> </value> <value> <string>OfficeJS jIO ERP5 Configurator Page JS</string> </value>
...@@ -234,7 +244,7 @@ ...@@ -234,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.55534.6594.50944</string> </value> <value> <string>955.59548.4928.4881</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +262,7 @@ ...@@ -252,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1481327828.02</float> <float>1481541022.38</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, Handlebars, loopEventListener */ /*global window, rJS, RSVP, Handlebars, loopEventListener */
/*jslint nomen: true, indent: 2 */ /*jslint nomen: true, indent: 2 */
(function (window, rJS, RSVP, Handlebars, loopEventListener) { (function (window, rJS, RSVP, Handlebars, loopEventListener) {
"use strict"; "use strict";
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// templates // templates
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
var gadget_klass = rJS(window), var gadget_klass = rJS(window),
templater = gadget_klass.__template_element, templater = gadget_klass.__template_element,
listbox_widget_table = Handlebars.compile( listbox_widget_table = Handlebars.compile(
templater.getElementById("listbox-widget-table").innerHTML templater.getElementById("listbox-widget-table").innerHTML
); );
Handlebars.registerPartial( Handlebars.registerPartial(
"listbox-widget-table-partial", "listbox-widget-table-partial",
templater.getElementById("listbox-widget-table-partial").innerHTML templater.getElementById("listbox-widget-table-partial").innerHTML
); );
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// some methods // some methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
gadget_klass gadget_klass
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// ready // ready
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.ready(function (gadget) { .ready(function (gadget) {
gadget.property_dict = { gadget.property_dict = {
render_deferred: RSVP.defer() render_deferred: RSVP.defer()
}; };
}) })
.ready(function (gadget) { .ready(function (gadget) {
return gadget.getElement() return gadget.getElement()
.push(function (element) { .push(function (element) {
gadget.property_dict.element = element; gadget.property_dict.element = element;
}); });
}) })
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// published methods // published methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// acquired methods // acquired methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_allDocs", "jio_allDocs") .declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("translate", "translate") .declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod('render', function (option_dict) { .declareMethod('render', function (option_dict) {
var gadget = this, var gadget = this,
content = '', content = '',
k, k,
k_len, k_len,
search_list = [], search_list = [],
translated_column_list = [], translated_column_list = [],
all_docs_result; all_docs_result;
// store initial configuration // store initial configuration
gadget.property_dict.option_dict = option_dict; gadget.property_dict.option_dict = option_dict;
// Create the search query // Create the search query
if (option_dict.search) { if (option_dict.search) {
for (k = 0, k_len = option_dict.column_list.length; k < k_len; k += 1) { for (k = 0, k_len = option_dict.column_list.length; k < k_len; k += 1) {
search_list.push(option_dict.column_list[k].select + ':"%' + option_dict.search + '%"'); search_list.push(option_dict.column_list[k].select + ':"%' + option_dict.search + '%"');
} }
option_dict.query.query = '(' + search_list.join(' OR ') + ') AND ' + option_dict.query.query; option_dict.query.query = '(' + search_list.join(' OR ') + ') AND ' + option_dict.query.query;
} }
return gadget.jio_allDocs(option_dict.query) return gadget.jio_allDocs(option_dict.query)
.push(function (result) { .push(function (result) {
var promise_list = [], var promise_list = [],
i_len, i_len,
i; i;
all_docs_result = result; all_docs_result = result;
for (i = 0, i_len = result.data.total_rows; i < i_len; i += 1) { for (i = 0, i_len = result.data.total_rows; i < i_len; i += 1) {
promise_list.push(gadget.getUrlFor({jio_key: result.data.rows[i].id, page: 'view'})); promise_list.push(gadget.getUrlFor({jio_key: result.data.rows[i].id, page: 'view'}));
} }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function (link_list) { .push(function (link_list) {
var row_list = [], var row_list = [],
cell_list, cell_list,
i_len, i_len,
i, i,
j_len, j_len,
j; j,
value;
// build handlebars object
// build handlebars object
for (j = 0, j_len = all_docs_result.data.total_rows; j < j_len; j += 1) {
cell_list = []; for (j = 0, j_len = all_docs_result.data.total_rows; j < j_len; j += 1) {
for (i = 0, i_len = option_dict.column_list.length; i < i_len; i += 1) { cell_list = [];
cell_list.push({ for (i = 0, i_len = option_dict.column_list.length; i < i_len; i += 1) {
"href": link_list[j], value = option_dict.column_list[i].select === "url_string" ?
"value": all_docs_result.data.rows[j].value[option_dict.column_list[i].select] all_docs_result.data.rows[j].id :
}); all_docs_result.data.rows[j].value[option_dict.column_list[i].select];
} cell_list.push({
row_list.push({"cell_list": cell_list}); "href": link_list[j],
} "value": value
});
for (i = 0; i < option_dict.column_list.length; i += 1) { }
translated_column_list.push(gadget.translate(option_dict.column_list[i].title)); row_list.push({"cell_list": cell_list});
} }
return RSVP.all([
row_list, for (i = 0; i < option_dict.column_list.length; i += 1) {
RSVP.all(translated_column_list) translated_column_list.push(gadget.translate(option_dict.column_list[i].title));
]); }
}) return RSVP.all([
.push(function (result_list) { row_list,
content += listbox_widget_table({ RSVP.all(translated_column_list)
widget_theme : option_dict.widget_theme, ]);
search: option_dict.search, })
column_list: result_list[1], .push(function (result_list) {
row_list: result_list[0] content += listbox_widget_table({
}); widget_theme : option_dict.widget_theme,
search: option_dict.search,
gadget.property_dict.element.querySelector(".custom-grid .ui-body-c") column_list: result_list[1],
.innerHTML = content; row_list: result_list[0]
gadget.property_dict.render_deferred.resolve(); });
});
}) gadget.property_dict.element.querySelector(".custom-grid .ui-body-c")
.innerHTML = content;
///////////////////////////////////////////////////////////////// gadget.property_dict.render_deferred.resolve();
// declared service });
///////////////////////////////////////////////////////////////// })
.declareService(function () {
var gadget = this; /////////////////////////////////////////////////////////////////
return new RSVP.Queue() // declared service
.push(function () { /////////////////////////////////////////////////////////////////
return gadget.property_dict.render_deferred.promise; .declareService(function () {
}) var gadget = this;
.push(function () { return new RSVP.Queue()
return loopEventListener( .push(function () {
gadget.property_dict.element.querySelector('form'), return gadget.property_dict.render_deferred.promise;
'submit', })
false, .push(function () {
function (evt) { return loopEventListener(
return gadget.redirect({ gadget.property_dict.element.querySelector('form'),
jio_key: gadget.property_dict.option_dict.jio_key || '', 'submit',
page: gadget.property_dict.option_dict.search_page || '', false,
search: evt.target[0].value function (evt) {
}); return gadget.redirect({
} jio_key: gadget.property_dict.option_dict.jio_key || '',
); page: gadget.property_dict.option_dict.search_page || '',
}); search: evt.target[0].value
}); });
}
);
});
});
}(window, rJS, RSVP, Handlebars, loopEventListener)); }(window, rJS, RSVP, Handlebars, loopEventListener));
\ No newline at end of file
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.55462.40798.5324</string> </value> <value> <string>955.56066.6312.29166</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1481295757.83</float> <float>1481502794.84</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -8883,10 +8883,10 @@ return new Parser; ...@@ -8883,10 +8883,10 @@ return new Parser;
use_bulk_get: use_bulk_get, use_bulk_get: use_bulk_get,
conflict_force: (context._conflict_handling === conflict_force: (context._conflict_handling ===
CONFLICT_KEEP_REMOTE), CONFLICT_KEEP_REMOTE),
conflict_ignore: ((context._conflict_handling === conflict_ignore: (context._conflict_handling ===
CONFLICT_CONTINUE) || CONFLICT_CONTINUE) ||
(context._conflict_handling === (context._conflict_handling ===
CONFLICT_KEEP_LOCAL)), CONFLICT_KEEP_LOCAL),
check_modification: context._check_remote_modification, check_modification: context._check_remote_modification,
check_creation: context._check_remote_creation, check_creation: context._check_remote_creation,
check_deletion: context._check_remote_deletion check_deletion: context._check_remote_deletion
...@@ -12077,7 +12077,8 @@ return new Parser; ...@@ -12077,7 +12077,8 @@ return new Parser;
}; };
IndexedDBStorage.prototype.getAttachment = function (id, name, options) { IndexedDBStorage.prototype.getAttachment = function (id, name, options) {
var type, var transaction,
type,
start, start,
end; end;
if (options === undefined) { if (options === undefined) {
...@@ -12085,63 +12086,48 @@ return new Parser; ...@@ -12085,63 +12086,48 @@ return new Parser;
} }
return openIndexedDB(this) return openIndexedDB(this)
.push(function (db) { .push(function (db) {
return new RSVP.Promise(function (resolve, reject) { transaction = openTransaction(db, ["attachment", "blob"], "readonly");
var transaction = openTransaction(db, ["attachment", "blob"], // XXX Should raise if key is not good
"readonly"), return handleGet(transaction.objectStore("attachment")
// XXX Should raise if key is not good .get(buildKeyPath([id, name])));
request = transaction.objectStore("attachment") })
.get(buildKeyPath([id, name])); .push(function (attachment) {
request.onerror = function (error) { var total_length = attachment.info.length,
transaction.abort(); i,
reject(error); promise_list = [],
}; store = transaction.objectStore("blob"),
request.onsuccess = function () { start_index,
var attachment = request.result, end_index;
total_length,
i,
promise_list = [],
store = transaction.objectStore("blob"),
start_index,
end_index;
if (!attachment) {
return reject(
new jIO.util.jIOError("Cannot find attachment", 404)
);
}
total_length = attachment.info.length; type = attachment.info.content_type;
type = attachment.info.content_type; start = options.start || 0;
start = options.start || 0; end = options.end || total_length;
end = options.end || total_length; if (end > total_length) {
if (end > total_length) { end = total_length;
end = total_length; }
}
if (start < 0 || end < 0) { if (start < 0 || end < 0) {
throw new jIO.util.jIOError("_start and _end must be positive", throw new jIO.util.jIOError("_start and _end must be positive",
400); 400);
} }
if (start > end) { if (start > end) {
throw new jIO.util.jIOError("_start is greater than _end", throw new jIO.util.jIOError("_start is greater than _end",
400); 400);
} }
start_index = Math.floor(start / UNITE); start_index = Math.floor(start / UNITE);
end_index = Math.floor(end / UNITE); end_index = Math.floor(end / UNITE);
if (end % UNITE === 0) { if (end % UNITE === 0) {
end_index -= 1; end_index -= 1;
} }
for (i = start_index; i <= end_index; i += 1) { for (i = start_index; i <= end_index; i += 1) {
promise_list.push( promise_list.push(
handleGet(store.get(buildKeyPath([id, handleGet(store.get(buildKeyPath([id,
name, i]))) name, i])))
); );
} }
resolve(RSVP.all(promise_list)); return RSVP.all(promise_list);
};
});
}) })
.push(function (result_list) { .push(function (result_list) {
var array_buffer_list = [], var array_buffer_list = [],
...@@ -12201,12 +12187,10 @@ return new Parser; ...@@ -12201,12 +12187,10 @@ return new Parser;
} }
// Remove previous attachment // Remove previous attachment
transaction = openTransaction(db, ["attachment", "blob"], transaction = openTransaction(db, ["attachment", "blob"], "readwrite");
"readwrite", false);
return removeAttachment(transaction, id, name); return removeAttachment(transaction, id, name);
}) })
.push(function () { .push(function () {
transaction = openTransaction(db, ["attachment", "blob"], "readwrite");
var promise_list = [ var promise_list = [
handleRequest(transaction.objectStore("attachment").put({ handleRequest(transaction.objectStore("attachment").put({
...@@ -12882,10 +12866,6 @@ return new Parser; ...@@ -12882,10 +12866,6 @@ return new Parser;
if (sub_doc.id !== undefined) { if (sub_doc.id !== undefined) {
return sub_doc.id; return sub_doc.id;
} }
throw new jIO.util.jIOError(
"Cannot find id field related",
400
);
} }
query = new SimpleQuery({ query = new SimpleQuery({
key: storage._mapping_dict.id.equal, key: storage._mapping_dict.id.equal,
...@@ -12938,6 +12918,10 @@ return new Parser; ...@@ -12938,6 +12918,10 @@ return new Parser;
return property; return property;
} }
} }
if (!storage._map_all_property ||
storage._mapping_dict[property] === "ignore") {
return false;
}
if (storage._map_all_property) { if (storage._map_all_property) {
sub_doc[property] = doc[property]; sub_doc[property] = doc[property];
return property; return property;
...@@ -12960,6 +12944,10 @@ return new Parser; ...@@ -12960,6 +12944,10 @@ return new Parser;
return property; return property;
} }
} }
if (!storage._map_all_property ||
storage._mapping_dict[property] === "ignore") {
return property;
}
if (storage._map_all_property) { if (storage._map_all_property) {
if (sub_doc.hasOwnProperty(property)) { if (sub_doc.hasOwnProperty(property)) {
doc[property] = sub_doc[property]; doc[property] = sub_doc[property];
...@@ -13262,7 +13250,6 @@ return new Parser; ...@@ -13262,7 +13250,6 @@ return new Parser;
) )
.push(function (result) { .push(function (result) {
for (i = 0; i < result.data.total_rows; i += 1) { for (i = 0; i < result.data.total_rows; i += 1) {
result.data.rows[i].value.id = result.data.rows[i].id;
result.data.rows[i].value = result.data.rows[i].value =
mapToMainDocument( mapToMainDocument(
context, context,
......
...@@ -97,6 +97,16 @@ ...@@ -97,6 +97,16 @@
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value> <value> <string>Web Script</string> </value>
</item> </item>
<item>
<key> <string>revision</string> </key>
<value> <string>10</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>jio.js</string> </value> <value> <string>jio.js</string> </value>
...@@ -234,7 +244,7 @@ ...@@ -234,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.55534.6594.50944</string> </value> <value> <string>955.59479.27056.28433</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +262,7 @@ ...@@ -252,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1481328691.34</float> <float>1481540344.93</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*globals window, document, RSVP, rJS, navigator, jIO, MessageChannel, ProgressEvent*/ /*globals window, document, RSVP, rJS, navigator, jIO, MessageChannel, ProgressEvent*/
/*jslint indent: 2, maxlen: 80, nomen: true*/ /*jslint indent: 2, maxlen: 80, nomen: true*/
var repair = false; var repair = false;
(function (window, document, RSVP, rJS, jIO, navigator, MessageChannel, (function (window, document, RSVP, rJS, jIO, navigator, MessageChannel,
ProgressEvent) { ProgressEvent) {
"use strict"; "use strict";
var serviceWorker_setting_storage = jIO.createJIO({ var serviceWorker_setting_storage = jIO.createJIO({
type: "uuid", type: "uuid",
sub_storage: { sub_storage: {
type: "indexeddb", type: "indexeddb",
database: "serviceWorker_settings" database: "serviceWorker_settings"
} }
}); });
function createStorage(version) { function createStorage(version) {
return jIO.createJIO({ return jIO.createJIO({
type: "replicate", type: "replicate",
conflict_handling: 2, conflict_handling: 2,
check_remote_modification: false, check_remote_modification: false,
check_remote_deletion: false, check_remote_deletion: false,
check_local_creation: false, check_local_creation: false,
check_local_deletion: false, check_local_deletion: false,
check_local_modification: false, check_local_modification: false,
query: { query: {
query: 'portal_type: ("Web Illustration",' + query: 'portal_type: ("Web Illustration",' +
'"Web Manifest","Web Script","Web Style","Web Page")' + '"Web Manifest","Web Script","Web Style","Web Page")' +
'AND version:"' + version + '"', 'AND version:"' + version + '"',
"limit": [0, 27131], "limit": [0, 27131],
"select_list": ["url_string"] "select_list": ["url_string"]
}, },
signature_storage: { signature_storage: {
type: "uuid", type: "uuid",
sub_storage: { sub_storage: {
type: "indexeddb", type: "indexeddb",
database: version + "_hash" database: version + "_hash"
} }
}, },
local_sub_storage: { local_sub_storage: {
type: "mapping", type: "mapping",
map_all_property: true, map_all_property: true,
mapping_dict: { mapping_dict: {
"id": {"equal": "relative_url"}, "id": {"equal": "relative_url"},
"url_string": {"equal": "id"} "url_string": {"equal": "id"}
}, },
sub_storage: { sub_storage: {
type: "query", type: "query",
sub_storage: { sub_storage: {
type: "uuid", type: "uuid",
sub_storage: { sub_storage: {
type: "indexeddb", type: "indexeddb",
database: version database: version
} }
} }
} }
}, },
remote_sub_storage: { remote_sub_storage: {
type: "erp5", type: "erp5",
url: window.location.href + "/hateoasnoauth", url: window.location.href + "/hateoasnoauth",
default_view_reference: "jio_view" default_view_reference: "jio_view"
} }
}); });
} }
function postMessage(gadget, message) { function postMessage(gadget, message) {
return new RSVP.Promise(function (resolve, reject) { return new RSVP.Promise(function (resolve, reject) {
var messageChannel = new MessageChannel(); var messageChannel = new MessageChannel();
messageChannel.port1.onmessage = function (event) { messageChannel.port1.onmessage = function (event) {
if (event.data.error) { if (event.data.error) {
reject(event.data.error); reject(event.data.error);
} else { } else {
return resolve(event.data); return resolve(event.data);
} }
}; };
gadget.props.serviceWorker.postMessage( gadget.props.serviceWorker.postMessage(
JSON.stringify(message), JSON.stringify(message),
[messageChannel.port2] [messageChannel.port2]
); );
}); });
} }
rJS(window) rJS(window)
.ready(function (gadget) { .ready(function (gadget) {
var element_list = var element_list =
gadget.element.querySelectorAll("[data-install-configuration]"), gadget.element.querySelectorAll("[data-install-configuration]"),
i, i,
key, key,
value, value,
gadget_list = []; gadget_list = [];
gadget.props = {}; gadget.props = {};
gadget.props.cached_url = []; gadget.props.cached_url = [];
gadget.gadget_list = []; gadget.gadget_list = [];
function pushGadget(url, i) { function pushGadget(url, i) {
var element = document.createElement("div"); var element = document.createElement("div");
element.setAttribute("style", "display: none"); element.setAttribute("style", "display: none");
gadget.element.appendChild(element); gadget.element.appendChild(element);
return gadget.declareGadget(url, return gadget.declareGadget(url,
{ {
"scope": "sub_app_installer_" + i, "scope": "sub_app_installer_" + i,
"element": element, "element": element,
"sandbox": "iframe" "sandbox": "iframe"
}) })
.push(function (sub_gadget) { .push(function (sub_gadget) {
gadget.gadget_list.push(sub_gadget); gadget.gadget_list.push(sub_gadget);
return sub_gadget.setSubInstall(); return sub_gadget.setSubInstall();
}); });
} }
for (i = 0; i < element_list.length; i += 1) { for (i = 0; i < element_list.length; i += 1) {
key = element_list[i].getAttribute('data-install-configuration'); key = element_list[i].getAttribute('data-install-configuration');
value = element_list[i].textContent; value = element_list[i].textContent;
if (key === "sub_app_installer") { if (key === "sub_app_installer") {
if (value !== "") { if (value !== "") {
gadget_list = value.split('\n'); gadget_list = value.split('\n');
} }
} else { } else {
gadget.props[key] = value; gadget.props[key] = value;
} }
} }
return gadget.render() return gadget.render()
.push(function () { .push(function () {
var promise_list = []; var promise_list = [];
for (i = 0; i < gadget_list.length; i += 1) { for (i = 0; i < gadget_list.length; i += 1) {
promise_list.push(pushGadget(gadget_list[i], i + 1)); promise_list.push(pushGadget(gadget_list[i], i + 1));
} }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}); });
}) })
.declareMethod("render", function () { .declareMethod("render", function () {
var gadget = this, var gadget = this,
element = document.createElement("div"); element = document.createElement("div");
element.className = "presentation"; element.className = "presentation";
gadget.element.insertBefore(element, gadget.element.firstChild); gadget.element.insertBefore(element, gadget.element.firstChild);
return gadget.declareGadget( return gadget.declareGadget(
"gadget_officejs_install_presentation.html", "gadget_officejs_install_presentation.html",
{"scope": "presentation", "element": element} {"scope": "presentation", "element": element}
) )
.push(function (presentation_gadget) { .push(function (presentation_gadget) {
return presentation_gadget.render( return presentation_gadget.render(
{"app_name": gadget.props.app_name} {"app_name": gadget.props.app_name}
); );
}); });
}) })
.declareMethod("setSubInstall", function () { .declareMethod("setSubInstall", function () {
this.props.sub = true; this.props.sub = true;
}) })
.declareMethod("mainInstall", function () { .declareMethod("mainInstall", function () {
var gadget = this; var gadget = this;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
if (gadget.props.document_version) { if (gadget.props.document_version) {
return gadget.install(); return gadget.install();
} }
}) })
.push(function () { .push(function () {
var promise_list = [], i; var promise_list = [], i;
for (i = 0; i < gadget.gadget_list.length; i += 1) { for (i = 0; i < gadget.gadget_list.length; i += 1) {
promise_list.push(gadget.gadget_list[i].waitInstall()); promise_list.push(gadget.gadget_list[i].waitInstall());
} }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function () { .push(function () {
gadget.props.is_installed = true; gadget.props.is_installed = true;
if (gadget.installing !== undefined) { if (gadget.installing !== undefined) {
gadget.installing.resolve(); gadget.installing.resolve();
} }
if (!gadget.props.sub) { if (!gadget.props.sub) {
window.location.href = gadget.props.version_url; window.location.href = gadget.props.version_url;
} }
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
if (error instanceof ProgressEvent) { if (error instanceof ProgressEvent) {
if (gadget.props.sub === undefined) { if (gadget.props.sub === undefined) {
window.location.href = gadget.props.version_url; window.location.href = gadget.props.version_url;
} }
return; return;
} }
throw error; throw error;
}); });
}) })
.declareMethod("waitInstall", function () { .declareMethod("waitInstall", function () {
if (this.props.is_installed) { if (this.props.is_installed) {
return; return;
} }
this.installing = RSVP.defer(); this.installing = RSVP.defer();
return this.installing.promise; return this.installing.promise;
}) })
.declareMethod("install", function () { .declareMethod("install", function () {
var gadget = this; var gadget = this;
return serviceWorker_setting_storage.put( return serviceWorker_setting_storage.put(
window.location.href + gadget.props.version_url, window.location.href + gadget.props.version_url,
{"version": gadget.props.document_version} {"version": gadget.props.document_version}
) )
.push(function () { .push(function () {
gadget.props.storage = createStorage(gadget.props.document_version); gadget.props.storage = createStorage(gadget.props.document_version);
return gadget.props.storage.repair(); return gadget.props.storage.repair();
}) })
.push(function () { .push(function () {
// transform a cache to url_list // transform a cache to url_list
if (gadget.props.cache_file && gadget.props.cache_file !== "") { if (gadget.props.cache_file && gadget.props.cache_file !== "") {
gadget.props.storage = jIO.createJIO({ gadget.props.storage = jIO.createJIO({
type: "query", type: "query",
sub_storage: { sub_storage: {
type: "uuid", type: "uuid",
sub_storage: { sub_storage: {
type: "indexeddb", type: "indexeddb",
database: gadget.props.document_version database: gadget.props.document_version
} }
} }
}); });
return gadget.props.storage.get(gadget.props.cache_file) return gadget.props.storage.get(gadget.props.cache_file)
.push(function (doc) { .push(function (doc) {
var url_list = doc.text_content.split('\n'), var url_list = doc.text_content.split('\r\n'),
i, i,
start = url_list.indexOf("CACHE:") + 1, take = false;
len = url_list.indexOf("NETWORK:"); if (typeof url_list === "string") {
for (i = start; i < len; i += 1) { url_list = doc.text_content.split('\n');
if (url_list[i] !== "" && }
url_list[i].charAt(0) !== '#' && for (i = 0; i < url_list.length; i += 1) {
url_list[i].charAt(0) !== ' ') { if (url_list[i].indexOf("NETWORK:") >= 0) {
gadget.props.cached_url.push(url_list[i]); take = false;
} }
} if (take &&
}); url_list[i] !== "" &&
} url_list[i].charAt(0) !== '#' &&
}) url_list[i].charAt(0) !== ' ') {
.push(function () { url_list[i].replace("\r","");
// remove base if present gadget.props.cached_url.push(url_list[i]);
if (document.querySelector("base")) { }
document.querySelector("head").removeChild( if (url_list[i].indexOf("CACHE:") >= 0) {
document.querySelector("base") take = true;
); }
} }
return navigator.serviceWorker.register( });
"gadget_officejs_install_serviceworker.js", }
{"scope": gadget.props.version_url } })
); .push(function () {
}) // remove base if present
.push(function (registration) { if (document.querySelector("base")) {
if (registration.installing) { document.querySelector("head").removeChild(
gadget.props.serviceWorker = registration.installing; document.querySelector("base")
} else if (registration.waiting) { );
gadget.props.serviceWorker = registration.waiting; }
} else if (registration.active) { return navigator.serviceWorker.register(
gadget.props.serviceWorker = registration.active; "gadget_officejs_install_serviceworker.js",
} {"scope": gadget.props.version_url }
}) );
.push(function () { })
return postMessage( .push(function (registration) {
gadget, if (registration.installing) {
{ gadget.props.serviceWorker = registration.installing;
"action": "install", } else if (registration.waiting) {
"url_list": gadget.props.cached_url, gadget.props.serviceWorker = registration.waiting;
"version": gadget.props.document_version } else if (registration.active) {
} gadget.props.serviceWorker = registration.active;
); }
}); })
}) .push(function () {
return postMessage(
.declareService(function () { gadget,
var gadget = this; {
"action": "install",
function redirect() { "url_list": gadget.props.cached_url,
window.location.href = gadget.props.redirect_url; "version": gadget.props.document_version
} }
);
if (!("serviceWorker" in navigator)) { });
window.applicationCache.addEventListener("cached", redirect); })
window.applicationCache.addEventListener('noupdate', redirect);
window.setTimeout(redirect, 10000); .declareService(function () {
} else { var gadget = this;
return this.mainInstall();
} function redirect() {
}); window.location.href = gadget.props.redirect_url;
}
if (!("serviceWorker" in navigator)) {
window.applicationCache.addEventListener("cached", redirect);
window.applicationCache.addEventListener('noupdate', redirect);
window.setTimeout(redirect, 10000);
} else {
return this.mainInstall();
}
});
}(window, document, RSVP, rJS, jIO, navigator, MessageChannel, ProgressEvent)); }(window, document, RSVP, rJS, jIO, navigator, MessageChannel, ProgressEvent));
\ No newline at end of file
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.55436.28704.31573</string> </value> <value> <string>955.59498.53728.18602</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1481294187.07</float> <float>1481538523.87</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