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

webrjs break break

parent 5225bf78
......@@ -3,14 +3,13 @@
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>ERP5 Page Jump</title>
<link rel="http://www.renderjs.org/rel/interface" href="interface_page.html">
<title>ERP5 PT Form Python Action</title>
<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 -->
<script src="rsvp.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>
<!-- custom script -->
......@@ -18,23 +17,13 @@
<script src="gadget_erp5_global.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>
<body>
<form>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="erp5_form"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, Handlebars, URI, calculatePageTitle */
/*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";
/////////////////////////////////////////////////////////////////
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window),
source = gadget_klass.__template_element
.getElementById("table-template")
.innerHTML,
table_template = Handlebars.compile(source);
function checkValidity() {
return this.getDeclaredGadget("erp5_form")
.push(function (declared_gadget) {
return declared_gadget.checkValidity();
});
}
gadget_klass
/////////////////////////////////////////////////////////////////
// ready
/////////////////////////////////////////////////////////////////
// Init local properties
.ready(function (g) {
g.props = {};
})
function getContent() {
return this.getDeclaredGadget("erp5_form")
.push(function (sub_gadget) {
return sub_gadget.getContent();
});
}
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
.ready(function (g) {
return g.getElement()
.push(function (element) {
g.props.element = element;
// forced document change thus we update history
return gadget.redirect({
command: command,
options: {
"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("translateHtml", "translateHtml")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("submitContent", "submitContent")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this,
erp5_document,
result_list,
view_list;
.declareMethod('triggerSubmit', function () {
return;
})
.declareMethod('checkValidity', checkValidity, {mutex: 'changestate'})
.declareMethod('getContent', getContent, {mutex: 'changestate'})
return gadget.jio_getAttachment(options.jio_key, "links")
.push(function (result) {
var i,
promise_list = [
gadget.getUrlFor({command: 'cancel_dialog_with_history'})
];
erp5_document = result;
view_list = erp5_document._links.action_object_jump || [];
.declareMethod('render', function render(options) {
return this.changeState({
jio_key: options.jio_key,
view: options.view,
erp5_document: options.erp5_document,
form_definition: options.form_definition,
erp5_form: options.erp5_form || {}
});
})
if (view_list.constructor !== Array) {
view_list = [view_list];
}
.declareJob('submit', function () {
return submitDialog.apply(this);
})
for (i = 0; i < view_list.length; i += 1) {
promise_list.push(gadget.getUrlFor({command: 'push_history', options: {
extended_search: new URI(view_list[i].href).query(true).query,
page: 'search'
}}));
}
return RSVP.all(promise_list);
.onStateChange(function onStateChange() {
var form_gadget = this;
return new RSVP.Queue()
.push(function () {
// Render the erp5_from
return form_gadget.getDeclaredGadget("erp5_form");
})
.push(function (all_result) {
var i,
tab_list = [];
result_list = all_result;
for (i = 1; i < all_result.length; i += 1) {
tab_list.push({
title: view_list[i - 1].title,
link: all_result[i],
i18n: view_list[i - 1].title
});
}
.push(function (erp5_form) {
var form_options = form_gadget.state.erp5_form;
// pass own form options to the embedded form
form_options.erp5_document = form_gadget.state.erp5_document;
form_options.form_definition = form_gadget.state.form_definition;
form_options.view = form_gadget.state.view;
form_options.jio_key = form_gadget.state.jio_key;
form_options.editable = true; // dialog is always editable
return erp5_form.render(form_options);
})
.push(function () {
// Render the headers
return RSVP.all([
gadget.translateHtml(table_template({
definition_title: "Jumps",
documentlist: tab_list,
definition_i18n: "Jumps"
})),
calculatePageTitle(gadget, erp5_document)
form_gadget.getUrlFor({command: 'cancel_dialog_with_history'}),
calculatePageTitle(form_gadget, form_gadget.state.erp5_document)
]);
})
.push(function (last_result_list) {
gadget.props.element.innerHTML = last_result_list[0];
return gadget.updateHeader({
back_url: result_list[0],
page_title: last_result_list[1]
.push(function (all_result) {
return form_gadget.updateHeader({
cancel_url: all_result[0],
page_title: all_result[1]
});
})
.push(function () {
return form_gadget.submit();
});
})
.declareMethod("triggerSubmit", function () {
return;
});
}(window, rJS, RSVP, Handlebars, URI, calculatePageTitle));
\ No newline at end of file
}(window, rJS, RSVP, calculatePageTitle));
......@@ -104,9 +104,12 @@
}}));
}
for (i = 0; i < jump_list.length; i += 1) {
promise_list.push(gadget.getUrlFor({command: 'push_history', options: {
extended_search: new URI(jump_list[i].href).query(true).query,
page: 'search'
promise_list.push(gadget.getUrlFor({command: 'display_dialog_with_history', options: {
jio_key: gadget.state.jio_key,
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(
......
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