Commit fb28aca8 authored by Roque's avatar Roque

erp5_officejs: code cleanup and refactoring

parent d1b278bb
/*global window, rJS, RSVP, Query, SimpleQuery, ComplexQuery, console */ /*global window, rJS, RSVP, Query, SimpleQuery, ComplexQuery, console */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (window, rJS, RSVP, Query, SimpleQuery, ComplexQuery, console) { (function (window, rJS, RSVP, Query, SimpleQuery, ComplexQuery, console) {
"use strict"; "use strict";
// TODO: check if there are other categories that are 'views' and find a less hardcoded way to get this // TODO: check if there are other categories that are 'views'
var view_categorie_list = ["object_view", "object_jio_view", "object_web_view", "object_list"]; // and find a less hardcoded way to get this
var view_categorie_list = ["object_view", "object_jio_view",
"object_web_view", "object_list"];
function filterViewList(views_dict, app_view, default_view) { function filterViewList(views_dict, app_view, default_view) {
// there must be only one "View" action (title = "View") // there must be only one "View" action (title = "View")
// this is for scenarios were the portal type has several "View" (like view, jio_view, custom_view) // this is for scenarios were the portal type has several "View"
// (like view, jio_view, custom_view)
// priority: app_view ; default_view ; other // priority: app_view ; default_view ; other
var only_view, key, var only_view, key,
view_list = Object.keys(views_dict).map(function (key) { view_list = Object.keys(views_dict).map(function (key) {
...@@ -48,7 +51,7 @@ ...@@ -48,7 +51,7 @@
} }
} catch (e) { } catch (e) {
if (e instanceof SyntaxError) { if (e instanceof SyntaxError) {
console.log("Error while parsing configuration settings. Format error maybe?"); console.log("Error parsing configuration settings. Format error?");
console.log("Please check site configuration 'app_allowed_sub_types'"); console.log("Please check site configuration 'app_allowed_sub_types'");
console.log(e); console.log(e);
formatted_list = []; formatted_list = [];
...@@ -129,7 +132,9 @@ ...@@ -129,7 +132,9 @@
var path_for_jio_get_list = [], row; var path_for_jio_get_list = [], row;
for (row in action_list.data.rows) { for (row in action_list.data.rows) {
if (action_list.data.rows.hasOwnProperty(row)) { if (action_list.data.rows.hasOwnProperty(row)) {
path_for_jio_get_list.push(gadget.jio_get(action_list.data.rows[row].id)); path_for_jio_get_list.push(gadget.jio_get(action_list
.data.rows[row]
.id));
} }
} }
return RSVP.all(path_for_jio_get_list); return RSVP.all(path_for_jio_get_list);
...@@ -149,17 +154,22 @@ ...@@ -149,17 +154,22 @@
action_type: action_doc.action_type, action_type: action_doc.action_type,
parent_portal_type: portal_type parent_portal_type: portal_type
}; };
if (view_categorie_list.includes(action_settings.action_type)) { if (view_categorie_list.includes(action_settings
.action_type)) {
action_settings.page = "ojs_local_controller"; action_settings.page = "ojs_local_controller";
action_info_dict.view_list[action_settings.action] = action_settings; action_info_dict.view_list[action_settings.action] =
action_settings;
} else { } else {
action_settings.page = "handle_action"; action_settings.page = "handle_action";
action_info_dict.action_list[action_settings.action] = action_settings; action_info_dict.action_list[action_settings.action] =
action_settings;
} }
} }
} }
} }
action_info_dict.view_list = filterViewList(action_info_dict.view_list, app_view, default_view); action_info_dict.view_list =
filterViewList(action_info_dict.view_list,
app_view, default_view);
return action_info_dict; return action_info_dict;
}); });
}); });
...@@ -189,7 +199,8 @@ ...@@ -189,7 +199,8 @@
return [form_type, child_gadget_url]; return [form_type, child_gadget_url];
}) })
.declareMethod("getFormDefinition", function (portal_type, action_reference) { .declareMethod("getFormDefinition", function (portal_type,
action_reference) {
var gadget = this, var gadget = this,
query = buildSearchQuery(portal_type, action_reference), query = buildSearchQuery(portal_type, action_reference),
action_type, action_type,
...@@ -208,7 +219,8 @@ ...@@ -208,7 +219,8 @@
}) })
.push(function (data) { .push(function (data) {
if (data.data.rows.length === 0) { if (data.data.rows.length === 0) {
error = new Error("Can not find action '" + action_reference + "' for portal type '" + portal_type + "'"); error = new Error("Can not find action '" + action_reference +
"' for portal type '" + portal_type + "'");
error.status_code = 400; error.status_code = 400;
throw error; throw error;
} }
...@@ -218,18 +230,25 @@ ...@@ -218,18 +230,25 @@
action_title = action_result.title; action_title = action_result.title;
action_type = action_result.action_type; action_type = action_result.action_type;
if (action_result.action.includes("string:${object_url}")) { if (action_result.action.includes("string:${object_url}")) {
action_result.action = action_result.action.replace("string:${object_url}", portal_skin_folder); action_result.action = action_result.action
.replace("string:${object_url}", portal_skin_folder);
} }
return gadget.jio_get(action_result.action); return gadget.jio_get(action_result.action);
}) })
.push(function (form_result) { .push(function (form_result) {
form_definition = form_result.raw_dict._embedded._view._embedded.form_definition; form_definition = form_result.raw_dict._embedded._view
form_definition.fields_raw_properties = form_result.raw_dict._embedded._view.my_fields_raw_properties["default"]; ._embedded.form_definition;
form_definition._actions = form_result.raw_dict._embedded._view._actions; form_definition.fields_raw_properties = form_result.raw_dict
//[PATCH] if custom action and anonymous, get _actions field from fields_raw_properties ._embedded._view.my_fields_raw_properties["default"];
form_definition._actions = form_result.raw_dict._embedded
._view._actions;
//[PATCH] if custom action and anonymous
// get _actions field from fields_raw_properties
if ("_actions" in form_definition.fields_raw_properties) { if ("_actions" in form_definition.fields_raw_properties) {
if (!form_definition._actions && action_type === "object_jio_js_script") { if (!form_definition._actions &&
form_definition._actions = form_definition.fields_raw_properties._actions; action_type === "object_jio_js_script") {
form_definition._actions = form_definition
.fields_raw_properties._actions;
} }
delete form_definition.fields_raw_properties._actions; delete form_definition.fields_raw_properties._actions;
} }
...@@ -249,8 +268,10 @@ ...@@ -249,8 +268,10 @@
return gadget.getViewAndActionDict(portal_type); return gadget.getViewAndActionDict(portal_type);
}) })
.push(function (action_view_dict) { .push(function (action_view_dict) {
form_definition.has_more_views = Object.keys(action_view_dict.view_list).length > 1; form_definition.has_more_views =
form_definition.has_more_actions = Object.keys(action_view_dict.action_list).length > 0; Object.keys(action_view_dict.view_list).length > 1;
form_definition.has_more_actions =
Object.keys(action_view_dict.action_list).length > 0;
return gadget.getSetting('hide_header_add_button'); return gadget.getSetting('hide_header_add_button');
}) })
.push(function (hide_add_button_setting) { .push(function (hide_add_button_setting) {
......
/*global document, window, rJS, RSVP */ /*global document, window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (document, window, rJS, RSVP) { (function (document, window, rJS, RSVP) {
"use strict"; "use strict";
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
default_view, default_view,
app_view, app_view,
form_definition, form_definition,
gadget_utils, gadget_util,
jio_document, jio_document,
portal_type, portal_type,
front_page; front_page;
...@@ -37,10 +37,11 @@ ...@@ -37,10 +37,11 @@
]); ]);
}) })
.push(function (result_list) { .push(function (result_list) {
gadget_utils = result_list[0]; gadget_util = result_list[0];
app_view = options.action || result_list[1]; app_view = options.action || result_list[1];
default_view = result_list[2]; default_view = result_list[2];
options.editable = ((result_list[3] == "1") ? true : options.editable); options.editable = ((result_list[3] == "1") ?
true : options.editable);
return gadget.jio_get(options.jio_key); return gadget.jio_get(options.jio_key);
}) })
.push(function (result) { .push(function (result) {
...@@ -64,19 +65,19 @@ ...@@ -64,19 +65,19 @@
portal_type = parent_portal_type; portal_type = parent_portal_type;
} }
front_page = portal_type === parent_portal_type; front_page = portal_type === parent_portal_type;
return gadget_utils.getFormDefinition(portal_type, app_view); return gadget_util.getFormDefinition(portal_type, app_view);
}) })
.push(function (result) { .push(function (result) {
return result; return result;
}, function (error) { }, function (error) {
if (error.status_code === 400) { if (error.status_code === 400) {
return gadget_utils.getFormDefinition(portal_type, default_view); return gadget_util.getFormDefinition(portal_type, default_view);
} }
throw error; throw error;
}) })
.push(function (result) { .push(function (result) {
form_definition = result; form_definition = result;
return gadget_utils.getFormInfo(form_definition); return gadget_util.getFormInfo(form_definition);
}) })
.push(function (form_info) { .push(function (form_info) {
var form_type = form_info[0], var form_type = form_info[0],
...@@ -102,8 +103,8 @@ ...@@ -102,8 +103,8 @@
this.element.removeChild(this.element.firstChild); this.element.removeChild(this.element.firstChild);
} }
this.element.appendChild(fragment); this.element.appendChild(fragment);
return gadget.declareGadget("gadget_officejs_form_view.html", {element: fragment, return gadget.declareGadget("gadget_officejs_form_view.html",
scope: 'form_view'}) {element: fragment, scope: 'form_view'})
.push(function (form_view_gadget) { .push(function (form_view_gadget) {
return form_view_gadget.render(gadget.state); return form_view_gadget.render(gadget.state);
}); });
...@@ -130,7 +131,8 @@ ...@@ -130,7 +131,8 @@
return gadget.notifySubmitting(); return gadget.notifySubmitting();
}) })
.push(function () { .push(function () {
return gadget.notifySubmitted({message: 'Data Updated', status: 'success'}); return gadget.notifySubmitted({message: 'Data Updated',
status: 'success'});
}); });
}) })
......
...@@ -45,6 +45,42 @@ ...@@ -45,6 +45,42 @@
return result; return result;
} }
function renderForm(form_definition, context_document) {
var i, j, field_list, field_info, my_element, element_id, rendered_field,
raw_properties = form_definition.fields_raw_properties,
form_json = {
erp5_document: {
"_embedded": {"_view": {}},
"_links": {}
},
form_definition: form_definition
};
for (i = 0; i < form_definition.group_list.length; i += 1) {
field_list = form_definition.group_list[i][1];
for (j = 0; j < field_list.length; j += 1) {
my_element = field_list[j][0];
if (my_element.startsWith("my_")) {
element_id = my_element.replace("my_", "");
} else if (my_element.startsWith("your_")) {
element_id = my_element.replace("your_", "");
} else {
element_id = my_element;
}
if (element_id && raw_properties.hasOwnProperty(my_element)) {
field_info = raw_properties[my_element];
rendered_field = renderField(element_id, field_info,
context_document);
form_json.erp5_document._embedded._view[my_element] =
rendered_field;
}
}
}
form_json.erp5_document._embedded._view._actions =
form_definition._actions;
form_json.erp5_document._links = form_definition._links;
return form_json;
}
rJS(window) rJS(window)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
...@@ -96,42 +132,6 @@ ...@@ -96,42 +132,6 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("renderForm", function (form_definition, context_document) {
var i, j, fields, field_info, my_element, element_id, rendered_field,
raw_properties = form_definition.fields_raw_properties,
form_json = {
erp5_document: {
"_embedded": {"_view": {}},
"_links": {}
},
form_definition: form_definition
};
for (i = 0; i < form_definition.group_list.length; i += 1) {
fields = form_definition.group_list[i][1];
for (j = 0; j < fields.length; j += 1) {
my_element = fields[j][0];
if (my_element.startsWith("my_")) {
element_id = my_element.replace("my_", "");
} else if (my_element.startsWith("your_")) {
element_id = my_element.replace("your_", "");
} else {
element_id = my_element;
}
if (element_id && raw_properties.hasOwnProperty(my_element)) {
field_info = raw_properties[my_element];
rendered_field = renderField(element_id, field_info,
context_document);
form_json.erp5_document._embedded._view[my_element] =
rendered_field;
}
}
}
form_json.erp5_document._embedded._view._actions =
form_definition._actions;
form_json.erp5_document._links = form_definition._links;
return form_json;
})
.declareMethod("triggerSubmit", function (argument_list) { .declareMethod("triggerSubmit", function (argument_list) {
return this.getDeclaredGadget('fg') return this.getDeclaredGadget('fg')
.push(function (gadget) { .push(function (gadget) {
...@@ -152,17 +152,13 @@ ...@@ -152,17 +152,13 @@
.onStateChange(function onStateChange() { .onStateChange(function onStateChange() {
var fragment = document.createElement('div'), var fragment = document.createElement('div'),
gadget = this, gadget = this,
form_json; form_json = renderForm(gadget.state.form_definition, gadget.state.doc);
return gadget.renderForm(gadget.state.form_definition, gadget.state.doc)
.push(function (json) {
form_json = json;
while (gadget.element.firstChild) { while (gadget.element.firstChild) {
gadget.element.removeChild(gadget.element.firstChild); gadget.element.removeChild(gadget.element.firstChild);
} }
gadget.element.appendChild(fragment); gadget.element.appendChild(fragment);
return gadget.declareGadget(gadget.state.child_gadget_url, return gadget.declareGadget(gadget.state.child_gadget_url,
{element: fragment, scope: 'fg'}); {element: fragment, scope: 'fg'})
})
.push(function (form_gadget) { .push(function (form_gadget) {
return gadget.renderSubGadget(gadget.state.options, form_gadget, return gadget.renderSubGadget(gadget.state.options, form_gadget,
form_json); form_json);
......
/*global window, window, rJS, jIO, RSVP, document, URLSearchParams, UriTemplate, console */ /*global window, window, rJS, jIO, RSVP, document, URLSearchParams, UriTemplate, console */
/*jslint indent: 2, maxerr: 3 */ /*jslint indent: 2, maxerr: 10, maxlen: 80 */
(function (window, rJS, jIO, RSVP, document, URLSearchParams, UriTemplate, console) { (function (window, rJS, jIO, RSVP, document, URLSearchParams, UriTemplate,
console) {
"use strict"; "use strict";
// jIO call wrapper for redirection to authentication page if needed // jIO call wrapper for redirection to authentication page if needed
function wrapJioCall(gadget, method_name, argument_list) { function wrapJioCall(gadget, method_name, argument_list) {
var storage = gadget.state_parameter_dict.jio_storage; var storage = gadget.state_parameter_dict.jio_storage;
if (storage === undefined) { if (storage === undefined) {
return gadget.redirect({command: 'display', options: {page: 'ojs_configurator'}}); return gadget.redirect({command: 'display',
options: {page: 'ojs_configurator'}});
} }
return storage[method_name].apply(storage, argument_list) return storage[method_name].apply(storage, argument_list)
.push(undefined, function (error) { .push(undefined, function (error) {
...@@ -27,7 +29,8 @@ ...@@ -27,7 +29,8 @@
return gadget.redirect({ return gadget.redirect({
command: 'raw', command: 'raw',
options: { options: {
url: UriTemplate.parse(regexp.exec(login_page)[1]).expand({came_from: came_from}) url: UriTemplate.parse(regexp.exec(login_page)[1])
.expand({came_from: came_from})
} }
}); });
}); });
...@@ -50,7 +53,8 @@ ...@@ -50,7 +53,8 @@
} }
// User entered wrong password ? // User entered wrong password ?
// Notify // Notify
return gadget.notifySubmitted({message: 'Unauthorized storage access', status: 'error'}) return gadget.notifySubmitted({message: 'Unauthorized storage access',
status: 'error'})
.push(function () { .push(function () {
return gadget.redirect({command: 'display', return gadget.redirect({command: 'display',
options: {page: 'ojs_configurator'}}); options: {page: 'ojs_configurator'}});
...@@ -61,19 +65,21 @@ ...@@ -61,19 +65,21 @@
} }
function processHateoasDict(raw_dict) { function processHateoasDict(raw_dict) {
var raw_fields, type, parent, field_key, field_id, return_dict = {}; var raw_field_list, type, parent, field_key, field_id, return_dict = {};
return_dict.raw_dict = raw_dict; return_dict.raw_dict = raw_dict;
/*jslint nomen: true*/ /*jslint nomen: true*/
if (raw_dict.hasOwnProperty("_embedded") && raw_dict._embedded.hasOwnProperty("_view")) { if (raw_dict.hasOwnProperty("_embedded") &&
raw_fields = raw_dict._embedded._view; raw_dict._embedded.hasOwnProperty("_view")) {
raw_field_list = raw_dict._embedded._view;
type = raw_dict._links.type.name; type = raw_dict._links.type.name;
parent = raw_dict._links.parent.name; parent = raw_dict._links.parent.name;
return_dict.parent_relative_url = "portal_types/" + parent; return_dict.parent_relative_url = "portal_types/" + parent;
return_dict.portal_type = type; return_dict.portal_type = type;
for (field_key in raw_fields) { for (field_key in raw_field_list) {
if (raw_fields.hasOwnProperty(field_key)) { if (raw_field_list.hasOwnProperty(field_key)) {
field_id = ""; field_id = "";
if (raw_fields[field_key]["default"] !== undefined && raw_fields[field_key]["default"] !== "") { if (raw_field_list[field_key]["default"] !== undefined &&
raw_field_list[field_key]["default"] !== "") {
if (field_key.startsWith("my_")) { if (field_key.startsWith("my_")) {
field_id = field_key.replace("my_", ""); field_id = field_key.replace("my_", "");
} else if (field_key.startsWith("your_")) { } else if (field_key.startsWith("your_")) {
...@@ -81,7 +87,7 @@ ...@@ -81,7 +87,7 @@
} else { } else {
field_id = field_key; field_id = field_key;
} }
return_dict[field_id] = raw_fields[field_key]["default"]; return_dict[field_id] = raw_field_list[field_key]["default"];
} }
} }
} }
...@@ -109,7 +115,8 @@ ...@@ -109,7 +115,8 @@
var appcache_storage, var appcache_storage,
origin_url = window.location.href, origin_url = window.location.href,
hateoas_script = "hateoas_appcache/ERP5Document_getHateoas", hateoas_script = "hateoas_appcache/ERP5Document_getHateoas",
// TODO manifest should come from gadget.props.cache_file -add script in html body // TODO manifest should come from gadget.props.cache_file
// add script in html body
manifest = "gadget_officejs_text_editor.configuration", manifest = "gadget_officejs_text_editor.configuration",
jio_appchache_options = { jio_appchache_options = {
type: "replicate", type: "replicate",
...@@ -144,7 +151,8 @@ ...@@ -144,7 +151,8 @@
if (jio_options === undefined) { if (jio_options === undefined) {
return; return;
} }
jio_appchache_options.local_sub_storage = JSON.parse(JSON.stringify(jio_options)); jio_appchache_options.local_sub_storage = JSON.parse(
JSON.stringify(jio_options));
jio_options = { jio_options = {
type: 'dateupdater', type: 'dateupdater',
sub_storage: jio_options, sub_storage: jio_options,
...@@ -173,9 +181,13 @@ ...@@ -173,9 +181,13 @@
for (id in attachment_dict) { for (id in attachment_dict) {
if (attachment_dict.hasOwnProperty(id)) { if (attachment_dict.hasOwnProperty(id)) {
if (id.indexOf(hateoas_script) === -1) { if (id.indexOf(hateoas_script) === -1) {
promise_list.push(appcache_storage.getAttachment(origin_url, id)); promise_list.push(appcache_storage
.getAttachment(origin_url, id));
} else { } else {
promise_list.push(appcache_storage.getAttachment(origin_url, id, {"format": "json"})); promise_list.push(
appcache_storage
.getAttachment(origin_url, id,
{"format": "json"}));
} }
configuration_ids_list[i] = id; configuration_ids_list[i] = id;
i += 1; i += 1;
...@@ -203,9 +215,12 @@ ...@@ -203,9 +215,12 @@
.push(undefined); .push(undefined);
}); });
}, function (error) { }, function (error) {
console.log("Error while appcache-local storage synchronization"); console.log("Error while appcache-local " +
if (error && error.currentTarget && error.currentTarget.status === "401") { "storage synchronization");
console.log("Unauthorized access to storage, sync cancelled"); if (error && error.currentTarget &&
error.currentTarget.status === "401") {
console.log("Unauthorized access to storage," +
"sync cancelled");
return; return;
} }
throw error; throw error;
......
/*global window, rJS, RSVP, Handlebars */ /*global window, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (window, rJS, RSVP, Handlebars) { (function (window, rJS, RSVP, Handlebars) {
"use strict"; "use strict";
...@@ -36,23 +36,8 @@ ...@@ -36,23 +36,8 @@
); );
} }
gadget_klass function getHTMLElementList(gadget, element_list) {
///////////////////////////////////////////////////////////////// var i = 0,
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("updateHeader", "updateHeader")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("getHTMLElementList", function (element_list) {
var gadget = this,
i = 0,
element_info_list = [], element_info_list = [],
url_for_parameter_list = [], url_for_parameter_list = [],
element_info, element_info,
...@@ -60,8 +45,10 @@ ...@@ -60,8 +45,10 @@
for (key in element_list) { for (key in element_list) {
if (element_list.hasOwnProperty(key)) { if (element_list.hasOwnProperty(key)) {
element_info = element_list[key]; element_info = element_list[key];
url_for_parameter_list.push({ command: 'change', options: element_info }); url_for_parameter_list.push({ command: 'change',
element_info_list[i] = { reference: element_info.reference, title: element_info.title}; options: element_info });
element_info_list[i] = { reference: element_info.reference,
title: element_info.title};
i += 1; i += 1;
} }
} }
...@@ -77,7 +64,21 @@ ...@@ -77,7 +64,21 @@
} }
return html_element_list; return html_element_list;
}); });
}) }
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("updateHeader", "updateHeader")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
...@@ -98,15 +99,15 @@ ...@@ -98,15 +99,15 @@
.push(function (gadget_utils) { .push(function (gadget_utils) {
// TODO views are also listed here // TODO views are also listed here
// should views be handled in another gadget like "..tab_office.js" ? // should views be handled in another gadget like "..tab_office.js" ?
return gadget_utils.getViewAndActionDict(portal_type, options.jio_key); return gadget_utils.getViewAndActionDict(portal_type,
options.jio_key);
}) })
.push(function (action_info_dict) { .push(function (action_info_dict) {
return RSVP.all([ return RSVP.all([
gadget.getHTMLElementList(action_info_dict.view_list), getHTMLElementList(gadget, action_info_dict.view_list),
gadget.getHTMLElementList(action_info_dict.action_list) getHTMLElementList(gadget, action_info_dict.action_list)
]); ]);
}) })
// check other lists like clone or delete? NO. For now, they will be actions
.push(function (all_html_elements) { .push(function (all_html_elements) {
return RSVP.all([ return RSVP.all([
renderLinkList(gadget, "Views", "eye", all_html_elements[0]), renderLinkList(gadget, "Views", "eye", all_html_elements[0]),
...@@ -115,7 +116,8 @@ ...@@ -115,7 +116,8 @@
}) })
.push(function (translated_html_link_list) { .push(function (translated_html_link_list) {
gadget.element.innerHTML = translated_html_link_list.join("\n"); gadget.element.innerHTML = translated_html_link_list.join("\n");
return gadget.getUrlFor({command: 'change', options: {page: undefined}}); return gadget.getUrlFor({command: 'change',
options: {page: undefined}});
}) })
.push(function (back_url) { .push(function (back_url) {
return gadget.updateHeader({ return gadget.updateHeader({
......
/*global window, document, rJS */ /*global window, document, rJS */
/*jslint nomen: true, indent: 2, maxerr: 13 */ /*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (window, document, rJS) { (function (window, document, rJS) {
"use strict"; "use strict";
...@@ -8,12 +8,6 @@ ...@@ -8,12 +8,6 @@
// Acquired methods // Acquired methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post") .declareAcquiredMethod("jio_post", "jio_post")
...@@ -22,7 +16,8 @@ ...@@ -22,7 +16,8 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("createDocument", function (portal_type, parent_portal_type) { .declareMethod("createDocument", function (portal_type,
parent_portal_type) {
var gadget = this, var gadget = this,
doc = { doc = {
title: "Untitled Document", title: "Untitled Document",
...@@ -67,9 +62,12 @@ ...@@ -67,9 +62,12 @@
return gadget.jio_get(new_content_action); return gadget.jio_get(new_content_action);
}) })
.push(function (form_result) { .push(function (form_result) {
form_definition = form_result.raw_dict._embedded._view._embedded.form_definition; form_definition = form_result.raw_dict._embedded._view
form_definition.fields_raw_properties = form_result.raw_dict._embedded._view.my_fields_raw_properties["default"]; ._embedded.form_definition;
form_definition._actions = form_result.raw_dict._embedded._view._actions; form_definition.fields_raw_properties = form_result.raw_dict._embedded
._view.my_fields_raw_properties["default"];
form_definition._actions = form_result.raw_dict._embedded
._view._actions;
form_definition.group_list = form_result.raw_dict.group_list; form_definition.group_list = form_result.raw_dict.group_list;
form_definition.title = "Create Document"; form_definition.title = "Create Document";
return gadget.changeState({ return gadget.changeState({
...@@ -93,15 +91,17 @@ ...@@ -93,15 +91,17 @@
this.element.removeChild(this.element.firstChild); this.element.removeChild(this.element.firstChild);
} }
this.element.appendChild(fragment); this.element.appendChild(fragment);
return gadget.declareGadget("gadget_officejs_form_view.html", {element: fragment, return gadget.declareGadget("gadget_officejs_form_view.html",
scope: 'fg'}) {element: fragment, scope: 'fg'})
.push(function (form_view_gadget) { .push(function (form_view_gadget) {
return form_view_gadget.render(gadget.state); return form_view_gadget.render(gadget.state);
}); });
} else { } else {
// if there is only one sub portal type, skip create document dialog rendering // if there is only one sub portal type
// skip create document dialog rendering
return gadget.createDocument(gadget.state.doc.portal_type[0], return gadget.createDocument(gadget.state.doc.portal_type[0],
gadget.state.parent_portal_type.replace(/ /g, '_').toLowerCase()); gadget.state.parent_portal_type
.replace(/ /g, '_').toLowerCase());
} }
}) })
...@@ -109,7 +109,8 @@ ...@@ -109,7 +109,8 @@
var gadget = this, var gadget = this,
content_dict = options[2]; content_dict = options[2];
return gadget.createDocument(content_dict.portal_type, return gadget.createDocument(content_dict.portal_type,
gadget.state.parent_portal_type.replace(/ /g, '_').toLowerCase()); gadget.state.parent_portal_type
.replace(/ /g, '_').toLowerCase());
}); });
}(window, document, rJS)); }(window, document, rJS));
\ No newline at end of file
/*global window, document, rJS, RSVP */ /*global window, document, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (window, document, rJS, RSVP) { (function (window, document, rJS, RSVP) {
"use strict"; "use strict";
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
}) })
.push(function (result) { .push(function (result) {
parent_portal_type = result[0]; parent_portal_type = result[0];
return result[1].getFormDefinition(parent_portal_type, action_reference); return result[1].getFormDefinition(parent_portal_type,
action_reference);
}); });
}) })
...@@ -45,7 +46,9 @@ ...@@ -45,7 +46,9 @@
}) })
.push(function (result) { .push(function (result) {
if (result[0] !== undefined) { options.portal_type = result[0]; } if (result[0] !== undefined) { options.portal_type = result[0]; }
if (result[1] !== undefined) { options.parent_relative_url = result[1]; } if (result[1] !== undefined) {
options.parent_relative_url = result[1];
}
action_reference = result[2]; action_reference = result[2];
gadget_util = result[3]; gadget_util = result[3];
return gadget.getActionFormDefinition(action_reference); return gadget.getActionFormDefinition(action_reference);
...@@ -59,10 +62,12 @@ ...@@ -59,10 +62,12 @@
action_gadget_url, action_gadget_url,
form_type = form_info[0], form_type = form_info[0],
child_gadget_url = form_info[1], child_gadget_url = form_info[1],
//an action form must have a GadgetField called "gadget_field_new_action_js_script" //an action form must have a GadgetField called
//"gadget_field_new_action_js_script"
//this gadget will point the custom action gadget //this gadget will point the custom action gadget
valid_action = form_definition.action_type === "object_jio_js_script" && valid_action = form_definition.action_type ===
form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script"), "object_jio_js_script" && form_definition.fields_raw_properties
.hasOwnProperty("gadget_field_action_js_script"),
state_options = { state_options = {
doc: {}, doc: {},
action_options: options, action_options: options,
...@@ -73,9 +78,12 @@ ...@@ -73,9 +78,12 @@
valid_action: valid_action valid_action: valid_action
}; };
if (valid_action) { if (valid_action) {
action_gadget_url = form_definition.fields_raw_properties.gadget_field_action_js_script.values.gadget_url; action_gadget_url = form_definition.fields_raw_properties
// as custom gadget render is being done here, avoid to child gadget to render it .gadget_field_action_js_script.values.gadget_url;
delete form_definition.fields_raw_properties.gadget_field_action_js_script; // as custom gadget render is being done here
// avoid to child gadget to render it
delete form_definition.fields_raw_properties
.gadget_field_action_js_script;
gadget.element.appendChild(fragment); gadget.element.appendChild(fragment);
return gadget.declareGadget(action_gadget_url, { return gadget.declareGadget(action_gadget_url, {
scope: "action_field", scope: "action_field",
...@@ -102,8 +110,8 @@ ...@@ -102,8 +110,8 @@
this.element.removeChild(this.element.firstChild); this.element.removeChild(this.element.firstChild);
} }
this.element.appendChild(fragment); this.element.appendChild(fragment);
return gadget.declareGadget("gadget_officejs_form_view.html", {element: fragment, return gadget.declareGadget("gadget_officejs_form_view.html",
scope: 'fg'}) {element: fragment, scope: 'fg'})
.push(function (form_view_gadget) { .push(function (form_view_gadget) {
return form_view_gadget.render(gadget.state); return form_view_gadget.render(gadget.state);
}); });
...@@ -136,7 +144,8 @@ ...@@ -136,7 +144,8 @@
return gadget.notifySubmitting(); return gadget.notifySubmitting();
}) })
.push(function () { .push(function () {
return gadget.notifySubmitted({message: 'Data Updated', status: 'success'}); return gadget.notifySubmitted({message: 'Data Updated',
status: 'success'});
}) })
.push(function () { .push(function () {
return gadget.redirect({ return gadget.redirect({
...@@ -148,7 +157,9 @@ ...@@ -148,7 +157,9 @@
}); });
}); });
} else { } else {
return gadget.notifySubmitted({message: 'Could not perform this action: configuration error', status: 'fail'}); return gadget.notifySubmitted(
{message: 'Could not perform this action: configuration error',
status: 'fail'});
} }
}); });
......
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