Commit f0bbda2f authored by Roque's avatar Roque

erp5_officejs: fill document type list field in create document gadget

parent 8488d7b7
......@@ -262,6 +262,7 @@ officejs_logo.png\n
jio_appcachestorage.js\n
\n
#configuration resources\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_hal_json_style%2FBase_viewNewContentDialog&view=jio_view&appcache=1\n
\n
#discussion tool\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewAsJio&view=jio_view&appcache=1\n
......@@ -770,7 +771,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.2798.32101.13585</string> </value>
<value> <string>976.5449.107.50432</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -788,7 +789,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1559156188.36</float>
<float>1559327609.48</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -115,6 +115,8 @@ CACHE MANIFEST\n
# generated on Thu, 14 Jan 2019 11:55:33 +0000\n
CACHE:\n
\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_hal_json_style%2FBase_viewNewContentDialog&view=jio_view&appcache=1\n
\n
#discussion tool\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewAsJio&view=jio_view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewReplyDialog&view=jio_view&appcache=1\n
......@@ -301,7 +303,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1559155949.19</float>
<float>1559314986.76</float>
<string>UTC</string>
</tuple>
</state>
......
/*global document, window, rJS, RSVP */
/*global document, window, rJS, RSVP, ensureArray */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (document, window, rJS, RSVP) {
(function (document, window, rJS, RSVP, ensureArray) {
"use strict";
function renderField(field_id, field_definition, document) {
......@@ -36,7 +36,15 @@
result.type = field_definition.type;
result.key = field_id;
if (document && document.hasOwnProperty(field_id)) {
result["default"] = document[field_id];
if (field_definition.type === "ListField") {
var item_list = ensureArray(document[field_id]).map(function (item) {
if (Array.isArray(item)) {return item; }
return [item, item];
});
result.items = item_list;
} else {
result["default"] = document[field_id];
}
}
return result;
}
......@@ -148,7 +156,7 @@
page_title = options.doc.title;
}
erp5_document = form_json.erp5_document;
if (form_json.form_definition.allowed_sub_types_list.length > 0) {
if (form_json.form_definition.allowed_sub_types_list && form_json.form_definition.allowed_sub_types_list.length > 0) {
url_for_parameter_list.push({command: 'change', options: {page: "create_document", jio_key: options.jio_key, portal_type: options.portal_type, allowed_sub_types_list: form_json.form_definition.allowed_sub_types_list}});
add_url = true;
}
......@@ -212,4 +220,4 @@
});
});
}(document, window, rJS, RSVP));
}(document, window, rJS, RSVP, ensureArray));
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.2523.47706.38553</string> </value>
<value> <string>976.5655.16835.17186</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1559144299.92</float>
<float>1559327478.46</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, Handlebars */
/*global window, document, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars) {
(function (window, document, rJS, RSVP, Handlebars) {
"use strict";
/////////////////////////////////////////////////////////////////
......@@ -77,6 +77,7 @@
.declareMethod("render", function (options) {
var gadget = this,
allowed_sub_types_list = options.allowed_sub_types_list.split(","),
portal_type,
document_title;
return gadget.jio_get(options.jio_key)
.push(function (document) {
......@@ -86,32 +87,45 @@
document_title = options.portal_type;
return options.portal_type;
})
// TODO: this gadget must load the form dialog to select the type of document
// somehow (a generic action?) get the path string:${object_url}/Base_viewNewContentDialog
// get corresponding form definition (only contains a select field)
// fill select field with allowed_sub_types_list
.push(function (portal_type) {
return gadget.getHTMLElementList(allowed_sub_types_list, options.jio_key, portal_type);
})
.push(function (all_html_elements) {
return RSVP.all([
renderLinkList(gadget, "Create Document", "file", all_html_elements)
]);
.push(function (portal_type_result) {
portal_type = portal_type_result;
// TODO: somehow (a generic action?) get the path string:${object_url}/Base_viewNewContentDialog
// for now hardcoded
// get corresponding form definition (only contains a select field)
return gadget.jio_get("portal_skins/erp5_hal_json_style/Base_viewNewContentDialog");
})
.push(function (translated_html_link_list) {
gadget.element.innerHTML = translated_html_link_list.join("\n");
return gadget.getUrlFor({command: 'change', options: {page: undefined}});
})
.push(function (back_url) {
return gadget.updateHeader({
page_title: document_title,
back_url: back_url
.push(function (form_result) {
form_result.form_definition.title = "Create Document";
return gadget.changeState({
doc: { title: document_title, portal_type: allowed_sub_types_list },
action_options: options,
child_gadget_url: 'gadget_erp5_pt_form_dialog.html',
form_type: 'dialog',
form_definition: form_result.form_definition,
view: "view"
});
});
})
.declareMethod("triggerSubmit", function () {
return;
.onStateChange(function () {
var fragment = document.createElement('div'),
gadget = this;
while (this.element.firstChild) {
this.element.removeChild(this.element.firstChild);
}
this.element.appendChild(fragment);
return gadget.declareGadget("gadget_officejs_form_view.html", {element: fragment,
scope: 'fg'})
.push(function (form_view_gadget) {
return form_view_gadget.render(gadget.state);
});
})
.declareMethod('triggerSubmit', function () {
return this.getDeclaredGadget('fg')
.push(function (gadget) {
return gadget.triggerSubmit();
});
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
}(window, document, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.2629.49630.20326</string> </value>
<value> <string>976.5677.14251.21606</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1559147821.67</float>
<float>1559329004.84</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