Commit f1f1efee authored by Roque's avatar Roque

erp5_officejs: restoring old controller gadget

- new approach uses a new controller gadget
- old one is kept for backward compatibility (not migrated apps)
parent 0a9563e2
...@@ -10,134 +10,81 @@ ...@@ -10,134 +10,81 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put") .declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("isDesktopMedia", "isDesktopMedia")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod('getUrlParameter', 'getUrlParameter')
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.allowPublicAcquisition('updateDocument', function (param_list) {
var gadget = this, content = param_list[0];
return gadget.jio_get(gadget.state.jio_key)
.push(function (doc) {
var property;
for (property in content) {
if (content.hasOwnProperty(property)) {
doc[property] = content[property];
}
}
return gadget.jio_put(gadget.state.jio_key, doc);
});
})
.declareMethod('triggerSubmit', function () {
return this.getDeclaredGadget('fg')
.push(function (g) {
return g.triggerSubmit();
});
})
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
default_view = "jio_view", child_gadget_url;
common_utils_gadget_url = "gadget_officejs_common_utils.html",
form_definition, return gadget.jio_get(options.jio_key)
gadget_utils,
jio_document,
portal_type,
front_page;
return gadget.declareGadget(common_utils_gadget_url)
.push(function (result) {
gadget_utils = result;
return gadget.jio_get(options.jio_key);
})
.push(function (result) { .push(function (result) {
jio_document = result;
if (jio_document.portal_type === undefined) { if (result.portal_type !== undefined) {
throw new Error('Can not display document: ' + options.jio_key); child_gadget_url = 'gadget_officejs_jio_' +
} result.portal_type.replace(/ /g, '_').toLowerCase() +
}, function (error) {}) '_view.html';
.push(function () {
return gadget.getSetting('parent_portal_type');
})
.push(function (parent_portal_type) {
if (jio_document) {
portal_type = jio_document.portal_type;
} else if (options.portal_type) {
portal_type = options.portal_type;
} else { } else {
portal_type = parent_portal_type; throw new Error('Can not display document: ' + options.jio_key);
} }
front_page = portal_type === parent_portal_type;
return gadget_utils.getFormDefinition(portal_type, default_view);
})
.push(function (result) {
form_definition = result;
//TODO: solve add button (header add button - '+' icon)
//solved: add elements must be done via actions
/*if (form_definition.action_type === "object_list") {
form_definition._links.action_object_new_content_action = {
page: "handle_action",
title: "New Post",
action: "new_html_post",
reference: "new_html_post",
action_type: "object_jio_js_script",
parent_portal_type: "Post Module",
source_reference: "for-future-thread-id"
};
}*/
return gadget_utils.getFormInfo(form_definition);
})
.push(function (form_info) {
var form_type = form_info[0],
child_gadget_url = form_info[1];
return gadget.changeState({ return gadget.changeState({
jio_key: options.jio_key, jio_key: options.jio_key,
doc: jio_document, doc: result,
portal_type: portal_type, child_gadget_url: child_gadget_url
child_gadget_url: child_gadget_url,
form_definition: form_definition,
form_type: form_type,
//TODO editable should come from getFormInfo(form_definition)
editable: true,
view: options.view || default_view,
front_page: front_page
}); });
}); });
}) })
.onStateChange(function (modification_dict) {
.onStateChange(function () {
var fragment = document.createElement('div'), var fragment = document.createElement('div'),
gadget = this; gadget = this;
if (!modification_dict.hasOwnProperty('child_gadget_url')) {
return gadget.getDeclaredGadget('fg')
.push(function (child_gadget) {
return child_gadget.render({
jio_key: gadget.state.jio_key,
doc: gadget.state.doc
});
});
}
// Clear first to DOM, append after to reduce flickering/manip
while (this.element.firstChild) { while (this.element.firstChild) {
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,
scope: 'form_view'})
.push(function (form_view_gadget) {
return form_view_gadget.render(gadget.state);
});
})
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.allowPublicAcquisition('submitContent', function (param_list) {
var gadget = this,
//target_url = options[1],
content_dict = param_list[2];
return gadget.jio_get(gadget.state.jio_key)
.push(function (doc) {
var property;
for (property in content_dict) {
if (content_dict.hasOwnProperty(property)) {
doc[property] = content_dict[property];
}
}
return gadget.jio_put(gadget.state.jio_key, doc);
})
.push(function () {
return gadget.notifySubmitting();
})
.push(function () {
return gadget.notifySubmitted({message: 'Data Updated', status: 'success'});
});
})
.declareMethod("triggerSubmit", function () { return gadget.declareGadget(gadget.state.child_gadget_url, {element: fragment,
var argument_list = arguments; scope: 'fg'})
return this.getDeclaredGadget('form_view') .push(function (form_gadget) {
.push(function (view_gadget) { return form_gadget.render({
return view_gadget.triggerSubmit(argument_list); jio_key: gadget.state.jio_key,
doc: gadget.state.doc
});
}); });
}); });
......
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.61034.6128.3037</string> </value> <value> <string>975.61034.13526.32648</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -243,7 +243,7 @@ ...@@ -243,7 +243,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1558718052.37</float> <float>1558971188.94</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global document, window, rJS */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (document, window, rJS) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("isDesktopMedia", "isDesktopMedia")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod('getUrlParameter', 'getUrlParameter')
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("redirect", "redirect")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this,
default_view = "jio_view",
common_utils_gadget_url = "gadget_officejs_common_utils.html",
form_definition,
gadget_utils,
jio_document,
portal_type,
front_page;
return gadget.declareGadget(common_utils_gadget_url)
.push(function (result) {
gadget_utils = result;
return gadget.jio_get(options.jio_key);
})
.push(function (result) {
jio_document = result;
if (jio_document.portal_type === undefined) {
throw new Error('Can not display document: ' + options.jio_key);
}
}, function (error) {})
.push(function () {
return gadget.getSetting('parent_portal_type');
})
.push(function (parent_portal_type) {
if (jio_document) {
portal_type = jio_document.portal_type;
} else if (options.portal_type) {
portal_type = options.portal_type;
} else {
portal_type = parent_portal_type;
}
front_page = portal_type === parent_portal_type;
return gadget_utils.getFormDefinition(portal_type, default_view);
})
.push(function (result) {
form_definition = result;
//TODO: solve add button (header add button - '+' icon)
//solved: add elements must be done via actions
/*if (form_definition.action_type === "object_list") {
form_definition._links.action_object_new_content_action = {
page: "handle_action",
title: "New Post",
action: "new_html_post",
reference: "new_html_post",
action_type: "object_jio_js_script",
parent_portal_type: "Post Module",
source_reference: "for-future-thread-id"
};
}*/
return gadget_utils.getFormInfo(form_definition);
})
.push(function (form_info) {
var form_type = form_info[0],
child_gadget_url = form_info[1];
return gadget.changeState({
jio_key: options.jio_key,
doc: jio_document,
portal_type: portal_type,
child_gadget_url: child_gadget_url,
form_definition: form_definition,
form_type: form_type,
//TODO editable should come from getFormInfo(form_definition)
editable: true,
view: options.view || default_view,
front_page: front_page
});
});
})
.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: 'form_view'})
.push(function (form_view_gadget) {
return form_view_gadget.render(gadget.state);
});
})
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.allowPublicAcquisition('submitContent', function (param_list) {
var gadget = this,
//target_url = options[1],
content_dict = param_list[2];
return gadget.jio_get(gadget.state.jio_key)
.push(function (doc) {
var property;
for (property in content_dict) {
if (content_dict.hasOwnProperty(property)) {
doc[property] = content_dict[property];
}
}
return gadget.jio_put(gadget.state.jio_key, doc);
})
.push(function () {
return gadget.notifySubmitting();
})
.push(function () {
return gadget.notifySubmitted({message: 'Data Updated', status: 'success'});
});
})
.declareMethod("triggerSubmit", function () {
var argument_list = arguments;
return this.getDeclaredGadget('form_view')
.push(function (view_gadget) {
return view_gadget.triggerSubmit(argument_list);
});
});
}(document, window, rJS));
\ No newline at end of file
...@@ -223,8 +223,8 @@ gadget_erp5_field_listbox.html\n ...@@ -223,8 +223,8 @@ gadget_erp5_field_listbox.html\n
gadget_erp5_field_listbox.js\n gadget_erp5_field_listbox.js\n
gadget_erp5_page_action_officejs.html\n gadget_erp5_page_action_officejs.html\n
gadget_erp5_page_action_officejs.js\n gadget_erp5_page_action_officejs.js\n
gadget_erp5_page_ojs_controller.html\n gadget_erp5_page_ojs_local_controller.html\n
gadget_erp5_page_ojs_controller.js\n gadget_erp5_page_ojs_local_controller.js\n
gadget_officejs_form_view.html\n gadget_officejs_form_view.html\n
gadget_officejs_form_view.js\n gadget_officejs_form_view.js\n
gadget_erp5_page_handle_action.html\n gadget_erp5_page_handle_action.html\n
...@@ -760,7 +760,7 @@ NETWORK:\n ...@@ -760,7 +760,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.58057.27606.16981</string> </value> <value> <string>975.59928.32228.31914</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -778,7 +778,7 @@ NETWORK:\n ...@@ -778,7 +778,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1558539574.95</float> <float>1558971840.81</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -105,7 +105,7 @@ ...@@ -105,7 +105,7 @@
action_doc = action_document_list[action_key]; action_doc = action_document_list[action_key];
page = "handle_action"; page = "handle_action";
if (view_categories.includes(action_doc.action_type)) { if (view_categories.includes(action_doc.action_type)) {
page = "ojs_controller"; page = "ojs_local_controller";
} }
action_settings_list.push({ action_settings_list.push({
page: page, page: page,
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.60908.18646.37734</string> </value> <value> <string>975.60908.26814.32921</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1558710504.54</float> <float>1558970764.45</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>ERP5 Local Controller</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="jio_appcachestorage.js"></script>
<!-- custom script -->
<script src="gadget_erp5_page_ojs_local_controller.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
...@@ -365,7 +365,7 @@ ...@@ -365,7 +365,7 @@
</item> </item>
<item> <item>
<key> <string>configuration_default_jio_document_page_gadget_url</string> </key> <key> <string>configuration_default_jio_document_page_gadget_url</string> </key>
<value> <string>ojs_controller</string> </value> <value> <string>ojs_local_controller</string> </value>
</item> </item>
<item> <item>
<key> <string>configuration_default_view_action_reference</string> </key> <key> <string>configuration_default_view_action_reference</string> </key>
...@@ -373,7 +373,7 @@ ...@@ -373,7 +373,7 @@
</item> </item>
<item> <item>
<key> <string>configuration_frontpage_gadget_url</string> </key> <key> <string>configuration_frontpage_gadget_url</string> </key>
<value> <string>ojs_controller</string> </value> <value> <string>ojs_local_controller</string> </value>
</item> </item>
<item> <item>
<key> <string>configuration_hateoas_url</string> </key> <key> <string>configuration_hateoas_url</string> </key>
...@@ -680,7 +680,7 @@ ...@@ -680,7 +680,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>973.45044.62122.33672</string> </value> <value> <string>975.50798.33418.15411</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -698,7 +698,7 @@ ...@@ -698,7 +698,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1557417902.24</float> <float>1558970711.99</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -365,7 +365,7 @@ ...@@ -365,7 +365,7 @@
</item> </item>
<item> <item>
<key> <string>configuration_default_jio_document_page_gadget_url</string> </key> <key> <string>configuration_default_jio_document_page_gadget_url</string> </key>
<value> <string>ojs_controller</string> </value> <value> <string>ojs_local_controller</string> </value>
</item> </item>
<item> <item>
<key> <string>configuration_default_view_action_reference</string> </key> <key> <string>configuration_default_view_action_reference</string> </key>
...@@ -373,7 +373,7 @@ ...@@ -373,7 +373,7 @@
</item> </item>
<item> <item>
<key> <string>configuration_frontpage_gadget_url</string> </key> <key> <string>configuration_frontpage_gadget_url</string> </key>
<value> <string>ojs_controller</string> </value> <value> <string>ojs_local_controller</string> </value>
</item> </item>
<item> <item>
<key> <string>configuration_hateoas_url</string> </key> <key> <string>configuration_hateoas_url</string> </key>
...@@ -680,7 +680,7 @@ ...@@ -680,7 +680,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.50798.33418.15411</string> </value> <value> <string>975.59928.32228.31914</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -698,7 +698,7 @@ ...@@ -698,7 +698,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1558110397.69</float> <float>1558970713.21</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