Commit 9d71f234 authored by Vincent Bechu's avatar Vincent Bechu

[erp5_officejs] Add document redirect on edit new document

parent 7f44c447
......@@ -14,13 +14,5 @@
</head>
<body>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
......@@ -260,7 +260,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>vincent</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -274,7 +274,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>961.2051.42133.29593</string> </value>
<value> <string>963.7730.44194.2696</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -292,7 +292,7 @@
</tuple>
<state>
<tuple>
<float>1501502796.71</float>
<float>1509969877.35</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
(function (window, rJS, RSVP, Blob) {
"use strict";
var content_type = {
......@@ -15,167 +15,37 @@
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.onEvent('submit', function () {
var gadget = this;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (doc) {
doc.modification_date = (new Date()).toISOString();
if (content_type.hasOwnProperty(doc.portal_type)) {
doc.content_type = content_type[doc.portal_type];
}
return gadget.jio_post(doc);
})
.push(function () {
// Workaround, find a way to open document without break gadget.
return gadget.redirect({"command": "change", "options": {"page": "ojs_document_list"}});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.declareMethod("render", function () {
var gadget = this;
var gadget = this, doc_id;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.getSetting('portal_type'),
gadget.getSetting('parent_relative_url')
]);
})
.push(function (result) {
return result[0].render({
erp5_document: {
"_embedded": {"_view": {
"my_title": {
"description": "The name of a document in ERP5",
"title": "Title",
"default": "",
"css_class": "",
"required": 0,
"editable": 1,
"key": "title",
"hidden": 0,
"type": "StringField"
},
"my_reference": {
"description": "The name of a document in ERP5",
"title": "Reference",
"default": "",
"css_class": "",
"required": 0,
"editable": 1,
"key": "reference",
"hidden": 0,
"type": "StringField"
},
"my_version": {
"description": "",
"title": "Version",
"default": "",
"css_class": "",
"required": 0,
"editable": 1,
"key": "version",
"hidden": 0,
"type": "StringField"
},
"my_language": {
"description": "",
"title": "Language",
"default": "",
"css_class": "",
"required": 0,
"editable": 1,
"key": "language",
"hidden": 0,
"type": "StringField"
},
"my_description": {
"description": "",
"title": "Description",
"default": "",
"css_class": "",
"required": 0,
"editable": 1,
"key": "description",
"hidden": 0,
"type": "TextAreaField"
},
"my_portal_type": {
"description": "The name of a document in ERP5",
"title": "Portal Type",
"default": result[1],
"css_class": "",
"required": 1,
"editable": 1,
"key": "portal_type",
"hidden": 1,
"type": "StringField"
},
"my_parent_relative_url": {
"description": "",
"title": "Parent Relative Url",
"default": result[2],
"css_class": "",
"required": 1,
"editable": 1,
"key": "parent_relative_url",
"hidden": 1,
"type": "StringField"
},
"my_text_content": {
"description": "",
"title": "Text Content",
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "text_content",
"hidden": 1,
"type": "StringField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_title"], ["my_reference"], ["my_version"], ["my_language"], ["my_description"],
["my_portal_type"], ["my_parent_relative_url"]]
]]
}
return gadget.jio_post({
title: "Untitled Document",
portal_type: result[0],
parent_relative_url: result[1]
});
})
.push(function () {
return gadget.getSetting('document_title');
})
.push(function (document_title) {
return gadget.updateHeader({
page_title: "New " + document_title,
save_action: true
.push(function (id) {
return gadget.redirect({
command: 'display',
options: {
jio_key: id,
editable: true
}
});
});
});
}(window, rJS, RSVP));
\ No newline at end of file
}(window, rJS, RSVP, Blob));
\ No newline at end of file
......@@ -270,7 +270,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.37203.11411.48349</string> </value>
<value> <string>963.17747.60005.26606</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -288,7 +288,7 @@
</tuple>
<state>
<tuple>
<float>1507206916.7</float>
<float>1509971879.7</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