Commit ff8fa162 authored by Roque's avatar Roque

erp5_officejs: refactoring on handle action gadget

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