Commit 087b0523 authored by Romain Courteaud's avatar Romain Courteaud

webrjs break break

parent 5225bf78
...@@ -3,14 +3,13 @@ ...@@ -3,14 +3,13 @@
<head> <head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<title>ERP5 Page Jump</title> <title>ERP5 PT Form Python Action</title>
<link rel="http://www.renderjs.org/rel/interface" href="interface_page.html"> <link rel="http://www.renderjs.org/rel/interface" href="interface_erp5_page_template.html">
<link rel="http://www.renderjs.org/rel/interface" href="interface_erp5_form_content_provider.html">
<!-- renderjs --> <!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script> <script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script> <script src="renderjs.js" type="text/javascript"></script>
<script src="handlebars.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script> <script src="jiodev.js" type="text/javascript"></script>
<!-- custom script --> <!-- custom script -->
...@@ -18,23 +17,13 @@ ...@@ -18,23 +17,13 @@
<script src="gadget_erp5_global.js" type="text/javascript"></script> <script src="gadget_erp5_global.js" type="text/javascript"></script>
<script src="gadget_erp5_page_jump.js" type="text/javascript"></script> <script src="gadget_erp5_page_jump.js" type="text/javascript"></script>
<!-- XXX need theme here currently -->
<script id="table-template" type="text/x-handlebars-template">
<section class="ui-content-header-plain">
<h3 data-i18n="[last]{{definition_i18n}}">
<span class="ui-icon ui-icon-plane">&nbsp;</span>
{{definition_title}}
</h3>
</section>
<ul class="document-listview">
{{#each documentlist}}
<li><a data-i18n="{{i18n}}" href="{{link}}">{{title}}</a></li>
{{/each}}
</ul>
</script>
</head> </head>
<body> <body>
<form>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="erp5_form"
data-gadget-sandbox="public">
</div>
</form>
</body> </body>
</html> </html>
\ No newline at end of file
/*global window, rJS, RSVP, Handlebars, URI, calculatePageTitle */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, URI, calculatePageTitle) { /*global window, rJS, RSVP, calculatePageTitle */
(function (window, rJS, RSVP, calculatePageTitle) {
"use strict"; "use strict";
///////////////////////////////////////////////////////////////// function checkValidity() {
// Handlebars return this.getDeclaredGadget("erp5_form")
///////////////////////////////////////////////////////////////// .push(function (declared_gadget) {
// Precompile the templates while loading the first gadget instance return declared_gadget.checkValidity();
var gadget_klass = rJS(window), });
source = gadget_klass.__template_element }
.getElementById("table-template")
.innerHTML,
table_template = Handlebars.compile(source);
gadget_klass function getContent() {
///////////////////////////////////////////////////////////////// return this.getDeclaredGadget("erp5_form")
// ready .push(function (sub_gadget) {
///////////////////////////////////////////////////////////////// return sub_gadget.getContent();
// Init local properties });
.ready(function (g) { }
g.props = {};
}) function submitDialog() {
var gadget = this;
return gadget.getDeclaredGadget("erp5_form")
.push(function (sub_gadget) {
return sub_gadget.getContent();
})
.push(function (data) {
return gadget.submitContent(
gadget.state.jio_key,
gadget.state.erp5_document._embedded._view._actions.put.href, // most likely points to Base_callDialogMethod
data
);
})
.push(function (result) { // success redirect handler
console.log(result);
throw new Error("couscous");
var splitted_jio_key_list,
splitted_current_jio_key_list,
command,
i;
if (!result.jio_key) {
return;
}
if (gadget.state.jio_key === result.jio_key) {
// don't update navigation history when not really redirecting
return gadget.redirect({command: 'cancel_dialog_with_history'});
}
// Check if the redirection goes to a same parent's subdocument.
// In this case, do not add current document to the history
// example: when cloning, do not keep the original document in history
splitted_jio_key_list = result.jio_key.split('/');
splitted_current_jio_key_list = gadget.state.jio_key.split('/');
command = 'display_with_history';
if (splitted_jio_key_list.length === splitted_current_jio_key_list.length) {
for (i = 0; i < splitted_jio_key_list.length - 1; i += 1) {
if (splitted_jio_key_list[i] !== splitted_current_jio_key_list[i]) {
command = 'push_history';
}
}
} else {
command = 'push_history';
}
// Assign the element to a variable // forced document change thus we update history
.ready(function (g) { return gadget.redirect({
return g.getElement() command: command,
.push(function (element) { options: {
g.props.element = element; "jio_key": result.jio_key,
"view": result.view
// do not mingle with editable because it isn't necessary
}
}); });
}) });
}
var gadget_klass = rJS(window);
gadget_klass
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // acquisition
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment") .declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader") .declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("submitContent", "submitContent")
///////////////////////////////////////////////////////////////// .declareMethod('triggerSubmit', function () {
// declared methods return;
///////////////////////////////////////////////////////////////// })
.declareMethod("render", function (options) { .declareMethod('checkValidity', checkValidity, {mutex: 'changestate'})
var gadget = this, .declareMethod('getContent', getContent, {mutex: 'changestate'})
erp5_document,
result_list,
view_list;
return gadget.jio_getAttachment(options.jio_key, "links") .declareMethod('render', function render(options) {
.push(function (result) { return this.changeState({
var i, jio_key: options.jio_key,
promise_list = [ view: options.view,
gadget.getUrlFor({command: 'cancel_dialog_with_history'}) erp5_document: options.erp5_document,
]; form_definition: options.form_definition,
erp5_document = result; erp5_form: options.erp5_form || {}
view_list = erp5_document._links.action_object_jump || []; });
})
if (view_list.constructor !== Array) { .declareJob('submit', function () {
view_list = [view_list]; return submitDialog.apply(this);
} })
for (i = 0; i < view_list.length; i += 1) { .onStateChange(function onStateChange() {
promise_list.push(gadget.getUrlFor({command: 'push_history', options: { var form_gadget = this;
extended_search: new URI(view_list[i].href).query(true).query, return new RSVP.Queue()
page: 'search' .push(function () {
}})); // Render the erp5_from
} return form_gadget.getDeclaredGadget("erp5_form");
return RSVP.all(promise_list);
}) })
.push(function (all_result) { .push(function (erp5_form) {
var i, var form_options = form_gadget.state.erp5_form;
tab_list = []; // pass own form options to the embedded form
form_options.erp5_document = form_gadget.state.erp5_document;
result_list = all_result; form_options.form_definition = form_gadget.state.form_definition;
form_options.view = form_gadget.state.view;
for (i = 1; i < all_result.length; i += 1) { form_options.jio_key = form_gadget.state.jio_key;
tab_list.push({ form_options.editable = true; // dialog is always editable
title: view_list[i - 1].title, return erp5_form.render(form_options);
link: all_result[i], })
i18n: view_list[i - 1].title .push(function () {
}); // Render the headers
}
return RSVP.all([ return RSVP.all([
gadget.translateHtml(table_template({ form_gadget.getUrlFor({command: 'cancel_dialog_with_history'}),
definition_title: "Jumps", calculatePageTitle(form_gadget, form_gadget.state.erp5_document)
documentlist: tab_list,
definition_i18n: "Jumps"
})),
calculatePageTitle(gadget, erp5_document)
]); ]);
}) })
.push(function (last_result_list) { .push(function (all_result) {
gadget.props.element.innerHTML = last_result_list[0]; return form_gadget.updateHeader({
cancel_url: all_result[0],
return gadget.updateHeader({ page_title: all_result[1]
back_url: result_list[0],
page_title: last_result_list[1]
}); });
})
.push(function () {
return form_gadget.submit();
}); });
})
.declareMethod("triggerSubmit", function () {
return;
}); });
}(window, rJS, RSVP, Handlebars, URI, calculatePageTitle)); }(window, rJS, RSVP, calculatePageTitle));
\ No newline at end of file
...@@ -104,9 +104,12 @@ ...@@ -104,9 +104,12 @@
}})); }}));
} }
for (i = 0; i < jump_list.length; i += 1) { for (i = 0; i < jump_list.length; i += 1) {
promise_list.push(gadget.getUrlFor({command: 'push_history', options: { promise_list.push(gadget.getUrlFor({command: 'display_dialog_with_history', options: {
extended_search: new URI(jump_list[i].href).query(true).query, jio_key: gadget.state.jio_key,
page: 'search' view: jump_list[i].href,
page: 'jump' // Views in ERP5 must be forms but because of
// extended_search: new URI(jump_list[i].href).query(true).query,
// page: 'search'
}})); }}));
} }
promise_list.push( promise_list.push(
......
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