Commit 1a64a95e authored by Roque's avatar Roque

erp5_officejs: refactor on form view gadget and new common utils gadget

parent bdc37f33
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Common Utils</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_officejs_common_utils.js"></script>
</head>
<body>
</body>
</html>
/*global window, rJS */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (document, window, rJS, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("isDesktopMedia", "isDesktopMedia")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("createDocument", function (options) {
var gadget = this,
doc = {
title: "Untitled Document",
portal_type: options.portal_type,
parent_relative_url: options.parent_relative_url
},
key,
doc_key;
for (key in options) {
if (options.hasOwnProperty(key)) {
if (key.startsWith("my_")) {
doc_key = key.replace("my_", "");
doc[doc_key] = options[key];
}
}
}
return gadget.jio_post(doc);
})
.declareMethod("getFormDefinition", function (portal_type, action_reference) {
var gadget = this,
parent = "portal_types/" + portal_type,
query = 'portal_type: "Action Information" AND reference: "' + action_reference + '" AND parent_relative_url: "' + parent + '"';
return gadget.jio_allDocs({query: query})
.push(function (data) {
if (data.data.rows.length === 0) {
throw "Can not find action '" + action_reference + "' for portal type '" + portal_type + "'";
}
return gadget.jio_get(data.data.rows[0].id);
})
.push(function (action_result) {
return gadget.jio_get(action_result.action);
})
.push(function (form_result) {
return form_result.form_definition;
});
});
}(document, window, rJS, RSVP));
......@@ -4,7 +4,9 @@
"use strict";
var default_view = "jio_view",
gadget_utils;
common_utils_gadget_url = "gadget_officejs_common_utils.html",
form_view_gadget_url = "gadget_officejs_form_view.html",
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html';
rJS(window)
......@@ -30,9 +32,8 @@
.declareMethod("render", function (options) {
var gadget = this,
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html',
jio_document;
return gadget.declareGadget("gadget_officejs_form_view.html")
gadget_utils, jio_document;
return gadget.declareGadget(common_utils_gadget_url)
.push(function (result) {
gadget_utils = result;
return gadget.jio_get(options.jio_key);
......@@ -61,7 +62,11 @@
})
.onStateChange(function () {
return gadget_utils.renderGadget(this);
var gadget = this;
return gadget.declareGadget(form_view_gadget_url)
.push(function (form_view_gadget) {
return form_view_gadget.renderGadget(gadget);
});
});
}(window, rJS));
\ No newline at end of file
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.9054.53655.8977</string> </value>
<value> <string>975.16183.49695.48503</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -243,7 +243,7 @@
</tuple>
<state>
<tuple>
<float>1555685699.99</float>
<float>1556115863.74</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -233,6 +233,8 @@ gadget_field_new_action_js_script.html\n
gadget_field_new_action_js_script.js\n
gadget_field_reply_action_js_script.html\n
gadget_field_reply_action_js_script.js\n
gadget_officejs_common_utils.html\n
gadget_officejs_common_utils.js\n
\n
#needed for appcachestorage sync\n
/\n
......@@ -742,7 +744,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.15178.25005.32409</string> </value>
<value> <string>975.16181.55679.14097</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -760,7 +762,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1556053135.7</float>
<float>1556114650.11</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Common Utils</title>
<title>OfficeJS Form View</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
......
......@@ -273,7 +273,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.7931.7412.49851</string> </value>
<value> <string>975.7931.26448.43366</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -291,7 +291,7 @@
</tuple>
<state>
<tuple>
<float>1555618284.2</float>
<float>1556112021.33</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -61,44 +61,6 @@
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("createDocument", function (options) {
var gadget = this,
doc = {
title: "Untitled Document",
portal_type: options.portal_type,
parent_relative_url: options.parent_relative_url
},
key,
doc_key;
for (key in options) {
if (options.hasOwnProperty(key)) {
if (key.startsWith("my_")) {
doc_key = key.replace("my_", "");
doc[doc_key] = options[key];
}
}
}
return gadget.jio_post(doc);
})
.declareMethod("getFormDefinition", function (portal_type, action_reference) {
var gadget = this,
parent = "portal_types/" + portal_type,
query = 'portal_type: "Action Information" AND reference: "' + action_reference + '" AND parent_relative_url: "' + parent + '"';
return gadget.jio_allDocs({query: query})
.push(function (data) {
if (data.data.rows.length === 0) {
throw "Can not find action '" + action_reference + "' for portal type '" + portal_type + "'";
}
return gadget.jio_get(data.data.rows[0].id);
})
.push(function (action_result) {
return gadget.jio_get(action_result.action);
})
.push(function (form_result) {
return form_result.form_definition;
});
})
.declareMethod("renderForm", function (form_definition, document) {
var i, j, fields, field_info, my_element, element_id, rendered_field,
......
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.9052.17383.43895</string> </value>
<value> <string>975.16184.31473.12014</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1555685570.38</float>
<float>1556114597.52</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -5,7 +5,8 @@
(function (window, document, rJS, RSVP) {
"use strict";
var gadget_utils, action_reference, action_type, action_gadget;
var common_utils_gadget_url = "gadget_officejs_common_utils.html",
gadget_utils, action_reference, action_type, action_gadget;
rJS(window)
/////////////////////////////////////////////////////////////////
......@@ -32,7 +33,7 @@
gadget.getUrlParameter("action_type"),
gadget.getUrlParameter("parent_portal_type"),
gadget.getSetting('parent_portal_type'),
gadget.declareGadget("gadget_officejs_form_view.html")
gadget.declareGadget(common_utils_gadget_url)
]);
})
.push(function (result) {
......
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.16139.11100.7901</string> </value>
<value> <string>975.16180.59466.25548</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1556111042.18</float>
<float>1556113276.28</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