Commit ff8fa162 authored by Roque's avatar Roque

erp5_officejs: refactoring on handle action gadget

parent d97ff654
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<script src="rsvp.js"></script> <script src="rsvp.js"></script>
<script src="renderjs.js"></script> <script src="renderjs.js"></script>
<script src="gadget_erp5_page_ojs_add_any_document.js"></script> <script src="gadget_officejs_create_document.js"></script>
</head> </head>
......
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
</item> </item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_ojs_add_any_document.html</string> </value> <value> <string>gadget_officejs_create_document.html</string> </value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>gadget_officejs_erp5_page_ojs_add_any_document_html</string> </value> <value> <string>gadget_officejs_create_document_html</string> </value>
</item> </item>
<item> <item>
<key> <string>language</string> </key> <key> <string>language</string> </key>
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>OfficeJS Add Any Document</string> </value> <value> <string>OfficeJS Create Document</string> </value>
</item> </item>
<item> <item>
<key> <string>url_string</string> </key> <key> <string>url_string</string> </key>
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.60340.37429.26555</string> </value> <value> <string>974.61745.63686.35191</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -291,7 +291,7 @@ ...@@ -291,7 +291,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1554833972.6</float> <float>1554915049.41</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_post", "jio_post")
/////////////////////////////////////////////////////////////////
// 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, doc_id;
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("render", function (options) { });
}(window, rJS));
...@@ -10,8 +10,11 @@ ...@@ -10,8 +10,11 @@
<key> <string>_Access_contents_information_Permission</string> </key> <key> <string>_Access_contents_information_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Anonymous</string>
<string>Assignee</string> <string>Assignee</string>
<string>Assignor</string> <string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string> <string>Manager</string>
</tuple> </tuple>
</value> </value>
...@@ -49,8 +52,11 @@ ...@@ -49,8 +52,11 @@
<key> <string>_View_Permission</string> </key> <key> <string>_View_Permission</string> </key>
<value> <value>
<tuple> <tuple>
<string>Anonymous</string>
<string>Assignee</string> <string>Assignee</string>
<string>Assignor</string> <string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string> <string>Manager</string>
</tuple> </tuple>
</value> </value>
...@@ -77,7 +83,7 @@ ...@@ -77,7 +83,7 @@
</item> </item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_ojs_add_any_document.js</string> </value> <value> <string>gadget_officejs_create_document.js</string> </value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -87,7 +93,7 @@ ...@@ -87,7 +93,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>gadget_officejs_erp5_page_ojs_add_any_document_js</string> </value> <value> <string>gadget_officejs_create_document_js</string> </value>
</item> </item>
<item> <item>
<key> <string>language</string> </key> <key> <string>language</string> </key>
...@@ -126,7 +132,7 @@ ...@@ -126,7 +132,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>OfficeJS Add Any Document JS</string> </value> <value> <string>OfficeJS Create Document JS</string> </value>
</item> </item>
<item> <item>
<key> <string>url_string</string> </key> <key> <string>url_string</string> </key>
...@@ -192,7 +198,7 @@ ...@@ -192,7 +198,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>action</string> </key> <key> <string>action</string> </key>
<value> <string>hide</string> </value> <value> <string>publish_alive</string> </value>
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
...@@ -218,7 +224,7 @@ ...@@ -218,7 +224,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1554903150.06</float> <float>1554912716.44</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -227,7 +233,7 @@ ...@@ -227,7 +233,7 @@
</item> </item>
<item> <item>
<key> <string>validation_state</string> </key> <key> <string>validation_state</string> </key>
<value> <string>hidden</string> </value> <value> <string>published_alive</string> </value>
</item> </item>
</dictionary> </dictionary>
</list> </list>
...@@ -263,7 +269,7 @@ ...@@ -263,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.60340.48045.57105</string> </value> <value> <string>974.61769.15176.41096</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -281,7 +287,7 @@ ...@@ -281,7 +287,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1554836734.22</float> <float>1554916400.71</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -232,8 +232,8 @@ gadget_erp5_page_ojs_controller.html\n ...@@ -232,8 +232,8 @@ gadget_erp5_page_ojs_controller.html\n
gadget_erp5_page_ojs_controller.js\n gadget_erp5_page_ojs_controller.js\n
gadget_erp5_page_ojs_post_list.html\n gadget_erp5_page_ojs_post_list.html\n
gadget_erp5_page_ojs_post_list.js\n gadget_erp5_page_ojs_post_list.js\n
#gadget_erp5_page_ojs_add_any_document.html\n gadget_officejs_create_document.html\n
#gadget_erp5_page_ojs_add_any_document.js\n gadget_officejs_create_document.js\n
\n \n
#needed for appcachestorage sync\n #needed for appcachestorage sync\n
/\n /\n
...@@ -740,7 +740,7 @@ NETWORK:\n ...@@ -740,7 +740,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.60462.54910.65109</string> </value> <value> <string>974.61748.30410.53299</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -758,7 +758,7 @@ NETWORK:\n ...@@ -758,7 +758,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1554905710.65</float> <float>1554916428.12</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this, doc_id;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting('portal_type'),
gadget.getSetting('parent_relative_url')
]);
})
.push(function (result) {
var doc = {
title: "Untitled Document",
portal_type: result[0],
parent_relative_url: result[1]
}, 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);
})
.push(function (id) {
return gadget.redirect({
command: 'display',
options: {
jio_key: id,
editable: true
}
});
});
});
}(window, rJS, RSVP));
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.58750.16325.27204</string> </value> <value> <string>974.61695.23911.16588</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -291,7 +291,7 @@ ...@@ -291,7 +291,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1554736092.72</float> <float>1554912040.86</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -21,36 +21,28 @@ ...@@ -21,36 +21,28 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
action_reference; action_reference,
gadget_script;
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getUrlParameter("action"), gadget.getUrlParameter("action"),
gadget.getSetting('portal_type'), gadget.getSetting('portal_type'),
gadget.getSetting('parent_relative_url') gadget.getSetting('parent_relative_url'),
gadget.declareGadget("gadget_officejs_create_document.html")
]); ]);
}) })
.push(function (result) { .push(function (result) {
action_reference = result[0]; var portal_type = result[1],
// This is the custom code to handle each specific action parent_relative_url = result[2];
// TODO: move to specific gadgets by name? e.g. page: "action_" + portal_type + action_ref action_reference = result[0];
if (action_reference === "new_post") { gadget_script = result[3];
//TODO refactor doc creation to be reused by other actions (e.g. reply action) // This is the custom code to handle each specific action
// move to a js script? // TODO: move to specific gadgets by name? e.g. page: "action_" + portal_type + action_ref
var doc = { if (action_reference === "new_post") {
title: "Untitled Document", options.portal_type = portal_type;
portal_type: result[1], options.parent_relative_url = parent_relative_url;
parent_relative_url: result[2] return gadget_script.createDocument(options)
}, 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)
.push(function (id) { .push(function (id) {
return gadget.redirect({ return gadget.redirect({
command: 'display', command: 'display',
...@@ -60,36 +52,32 @@ ...@@ -60,36 +52,32 @@
} }
}); });
}); });
} }
if (action_reference == "reply") { if (action_reference === "reply") {
return gadget.jio_get(options.jio_key) return gadget.jio_get(options.jio_key)
.push(function (document) { .push(function (document) {
var doc, title = document.title; var title = document.title;
if (!title.startsWith("Re: ")) { if (!title.startsWith("Re: ")) {
title = "Re: " + document.title; title = "Re: " + document.title;
} }
doc = { options.portal_type = document.portal_type;
title: title, options.parent_relative_url = document.parent_relative_url;
//thread parent: same as base post options.my_title = title;
source_reference: document.source_reference, options.my_source_reference = document.source_reference;
portal_type: document.portal_type, return gadget_script.createDocument(options);
parent_relative_url: document.parent_relative_url })
}; .push(function (id) {
return gadget.jio_post(doc) return gadget.redirect({
.push(function (id) { command: "change",
return gadget.redirect({ options: {
command: "change", page: undefined,
options: { jio_key: id,
page: undefined, view: action_reference
jio_key: id, }
view: action_reference });
}
});
});
}); });
} else { }
throw "Action " + action_reference + " not implemented yet"; throw "Action " + action_reference + " not implemented yet";
} });
});
}); });
}(window, rJS, RSVP)); }(window, rJS, RSVP));
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.61589.61140.4744</string> </value> <value> <string>974.61766.59384.31590</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1554905840.94</float> <float>1554916263.24</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