Commit 585b38b1 authored by Roque Porchetto's avatar Roque Porchetto

erp5_wendelin_telecom_UI: fixing several UI redirection bugs

- TODO: use the new custom dialog gadget
parent 5e53a1ab
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.9075.35285.62173</string> </value>
<value> <string>969.16321.4013.58965</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1532526555.8</float>
<float>1532962084.26</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.611.21138.12390</string> </value>
<value> <string>969.16316.40169.55057</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1508943588.17</float>
<float>1532962171.47</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.15125.3949.58658</string> </value>
<value> <string>969.16324.59873.53640</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1532889234.5</float>
<float>1532962227.81</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -32,7 +32,7 @@
action_list,
// XXX harcoded...
return_page = "data_set";
if (options.jio_key.indexOf("data_array") !== -1) {
if (options.jio_key.indexOf("data_stream") !== -1) {
return_page = "file_fif";
}
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.25389.60346.26402</string> </value>
<value> <string>969.16436.60878.46762</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1529660655.72</float>
<float>1532968976.36</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<!--
data-i18n=Input data has errors
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 PT Form Dialog</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_global.js" type="text/javascript"></script>
<script src="gadget_erp5_pt_form_dialog.js" type="text/javascript"></script>
</head>
<body>
<section class="ui-content-header-plain">
<h3 class="ui-content-title ui-body-c"></h3>
</section>
<!-- XXX action, method, fieldset -->
<form class="dialog_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-action ui-btn-icon-right ui-screen-hidden">Submit</button>
<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
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Page" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_pt_form_dialog.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>fif_gadget_erp5_pt_form_dialog_html</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Page</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>FIF Gadget ERP5 Form Dialog</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1532964825.29</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>draft</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.16391.48876.8550</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1532966455.44</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1532964825.28</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, RSVP, URI, calculatePageTitle */
(function (window, rJS, RSVP, URI, calculatePageTitle) {
"use strict";
rJS(window)
.setState({
title: ""
})
/////////////////////////////////////////////////////////////////
// acquisition
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareAcquiredMethod("displayFormulatorValidationError",
"displayFormulatorValidationError")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod('triggerSubmit', function () {
this.element.querySelector('button').click();
})
.declareMethod('render', function (options) {
var isFifDataSite = options.erp5_document._links.self.href.indexOf("fif_data_runner") !== -1,
return_page;
// XXX hardcoded...
if (isFifDataSite) {
if (options.jio_key.indexOf("data_array") !== -1) {
return_page = "file_fif";
} else { return_page = "data_set"; }
}
if (options.form_definition.title === "Validate Workflow Action") {
options.form_definition.title = "Validate deletion";
}
var state_dict = {
id: options.jio_key,
view: options.view,
editable: options.editable,
erp5_document: options.erp5_document,
form_definition: options.form_definition,
erp5_form: options.erp5_form || {},
isFifDataSite: isFifDataSite,
return_page: return_page
};
return this.changeState(state_dict);
})
.onStateChange(function () {
var form_gadget = this,
icon,
selector = form_gadget.element.querySelector("h3"),
title,
i,
return_page = this.state.return_page,
view_list = this.state.erp5_document._links.action_workflow || [];
title = this.state.form_definition.title;
for (i = 0; i < view_list.length; i += 1) {
if (view_list[i].name === this.state.view) {
title = view_list[i].title;
}
}
// XXX hardcoded...
switch (form_gadget.state.title) {
case "Create User":
icon = " ui-icon-user";
break;
case "Create Document":
icon = " ui-icon-file-o";
break;
case "Change State":
icon = " ui-icon-share-alt";
break;
case "Submit":
icon = " ui-icon-check";
break;
default:
icon = " ui-icon-random";
break;
}
// Calculate the h3 properties
return form_gadget.translate(title)
.push(function (translated_title) {
selector.textContent = "\u00A0" + translated_title;
selector.className = "ui-content-title ui-body-c ui-icon ui-icon-custom" + icon;
// Render the erp5_from
return form_gadget.getDeclaredGadget("erp5_form");
})
.push(function (erp5_form) {
var form_options = form_gadget.state.erp5_form;
// <span class="ui-icon ui-icon-custom ui-icon-random">&nbsp;</span>
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;
return erp5_form.render(form_options);
})
.push(function () {
// Render the headers
return RSVP.all([
form_gadget.getUrlFor({command: 'change', options: {page: return_page, view: undefined}}),
calculatePageTitle(form_gadget, form_gadget.state.erp5_document)
]);
})
.push(function (all_result) {
return form_gadget.updateHeader({
cancel_url: all_result[0],
page_title: all_result[1],
submit_action: true
});
});
})
.onEvent('submit', function () {
var form_gadget = this,
action = this.state.erp5_document._embedded._view._actions.put,
form_id = this.state.erp5_document._embedded._view.form_id,
isFifDataSite = this.state.isFifDataSite,
redirect_to_parent;
return form_gadget.notifySubmitting()
.push(function () {
return form_gadget.getDeclaredGadget("erp5_form");
})
.push(function (erp5_form) {
return erp5_form.getContent();
})
.push(function (content_dict) {
var data = {},
key;
data[form_id.key] = form_id['default'];
// XXX Hardcoded
data.dialog_id = form_id['default'];
data.dialog_method = action.action;
//XXX hack for redirect, difined in form
redirect_to_parent = content_dict.field_your_redirect_to_parent;
for (key in content_dict) {
if (content_dict.hasOwnProperty(key)) {
data[key] = content_dict[key];
}
}
return form_gadget.jio_putAttachment(
form_gadget.state.id,
action.href,
data
);
})
.push(function (evt) {
var location = evt.target.getResponseHeader("X-Location"),
jio_key,
list = [],
message;
try {
message = JSON.parse(evt.target.response).portal_status_message;
} catch (ignore) {
}
list.push(form_gadget.notifySubmitted(message));
if (isFifDataSite) {
list.push(form_gadget.redirect({command: 'change', options: {page: "fifdata"}}));
}
else {
if (redirect_to_parent) {
list.push(form_gadget.redirect({command: 'history_previous'}));
} else {
if (location === undefined || location === null) {
// No redirection, stay on the same document
list.push(form_gadget.redirect({command: 'change', options: {view: "view", page: undefined, editable: form_gadget.state.editable}}));
} else {
jio_key = new URI(location).segment(2);
if (form_gadget.state.id === jio_key) {
// Do not update navigation history if dialog redirect to the same document
list.push(form_gadget.redirect({command: 'change', options: {jio_key: jio_key, view: "view", page: undefined, editable: form_gadget.state.editable}}));
} else {
list.push(form_gadget.redirect({command: 'push_history', options: {jio_key: jio_key, editable: form_gadget.state.editable}}));
}
}
}
}
return RSVP.all(list);
})
.push(undefined, function (error) {
if ((error.target !== undefined) && (error.target.status === 400)) {
return form_gadget.notifySubmitted()
.push(function () {
return form_gadget.translate('Input data has errors');
})
.push(function (message) {
return form_gadget.notifyChange(message + '.');
})
.push(function () {
return form_gadget.displayFormulatorValidationError(JSON.parse(error.target.responseText));
});
}
throw error;
});
}, false, true);
}(window, rJS, RSVP, URI, calculatePageTitle));
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_pt_form_dialog.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>fif_gadget_erp5_pt_form_dialog_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>FIF Gadget ERP5 Form Dialog JS</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1532964830.1</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>draft</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.16391.15144.9659</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1532966440.99</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1532964830.1</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
......@@ -24,7 +24,7 @@
for (i = 0; i < options_list.length; i += 1) {
if (options_list[i].command === 'index') {
result_list.push({
command: 'display_stored_state',
command: 'index',
options: {jio_key: options_list[i].options.jio_key, page: "data_set"}
});
} else {
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.9069.22873.24849</string> </value>
<value> <string>969.16308.20198.46865</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1532525611.57</float>
<float>1532960456.21</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -23,7 +23,7 @@
for (i = 0; i < options_list.length; i += 1) {
if (options_list[i].command === 'index') {
result_list.push({
command: 'display_stored_state',
command: 'index',
options: {jio_key: options_list[i].options.jio_key, page: "file_fif"}
});
} else {
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.10372.38821.30208</string> </value>
<value> <string>969.16306.54351.50995</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1532802432.68</float>
<float>1532960466.35</float>
<string>UTC</string>
</tuple>
</state>
......
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, RSVP, URI, calculatePageTitle */
(function (window, rJS, RSVP, URI, calculatePageTitle) {
/*global window, rJS, RSVP, calculatePageTitle, Handlebars, ensureArray */
(function (window, rJS, RSVP, calculatePageTitle, Handlebars, ensureArray) {
"use strict";
rJS(window)
function checkValidity() {
return this.getDeclaredGadget("erp5_form")
.push(function (declared_gadget) {
return declared_gadget.checkValidity();
});
}
function getContent() {
return this.getDeclaredGadget("erp5_form")
.push(function (sub_gadget) {
return sub_gadget.getContent();
});
}
function submitDialog(is_updating) {
var gadget = this,
button_container =
gadget.element.querySelector('.dialog_button_container'),
update_button = button_container.querySelector('button'),
submit_input = button_container.querySelector('input');
submit_input.disabled = true;
if (update_button !== null) {
update_button.disabled = true;
}
function enableButton() {
submit_input.disabled = false;
if (update_button !== null) {
update_button.disabled = false;
}
}
return getContent.apply(this)
.push(function (content_dict) {
var data = {},
key;
// create a copy of sub_data so we do not modify them in-place
for (key in content_dict) {
if (content_dict.hasOwnProperty(key)) {
data[key] = content_dict[key];
}
}
// ERP5 expects target Script name in dialog_method field
data.dialog_method = gadget.state.form_definition.action;
// For Update Action - override the default value from "action"
if (is_updating) {
data.dialog_method = gadget.state.form_definition.update_action;
data.update_method = gadget.state.form_definition.update_action;
}
return data;
})
.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 (jio_key) { // success redirect handler
var splitted_jio_key_list,
splitted_current_jio_key_list,
command,
i;
if (is_updating || !jio_key) {
return;
}
if (gadget.state.redirect_to_parent) {
return gadget.redirect({command: 'history_previous'});
}
if (gadget.state.jio_key === jio_key) {
// don't update navigation history when not really redirecting
var return_page = gadget.state.return_page_confirm;
return gadget.redirect({
command: 'change',
options: {
"jio_key": jio_key,
"view": "view",
"page": return_page
// do not mingle with editable because it isn't necessary
}
});
}
// 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 = 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';
}
// forced document change thus we update history
return gadget.redirect({
command: command,
options: {
"jio_key": jio_key
// do not mingle with editable because it isn't necessary
}
});
})
.push(function (result) {
enableButton();
return result;
}, function (error) {
enableButton();
throw error;
});
// We do not handle submit failures because Page Form handles them well
// If any error bubbles here we do not know what to do with it anyway
}
var gadget_klass = rJS(window),
dialog_button_source = gadget_klass.__template_element
.getElementById("dialog-button-template")
.innerHTML,
dialog_button_template = Handlebars.compile(dialog_button_source);
gadget_klass
.setState({
title: ""
'redirect_to_parent': false, // set by a presence of special field
'has_update_action': undefined // default "submit" issue update in case of its presence
})
/////////////////////////////////////////////////////////////////
// acquisition
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareAcquiredMethod("displayFormulatorValidationError",
"displayFormulatorValidationError")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("submitContent", "submitContent")
/////////////////////////////////////////////////////////////////
// Proxy methods to the child gadget
/////////////////////////////////////////////////////////////////
.declareMethod('checkValidity', checkValidity, {mutex: 'changestate'})
.declareMethod('getContent', getContent, {mutex: 'changestate'})
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod('triggerSubmit', function () {
this.element.querySelector('button').click();
})
.declareMethod('triggerSubmit', function triggerSubmit() {
this.element.querySelector('input[type="submit"]').click();
}, {mutex: 'changestate'})
.declareMethod('render', function (options) {
var isFifDataSite = options.erp5_document._links.self.href.indexOf("fif_data_runner") !== -1,
return_page;
.declareMethod('render', function render(options) {
var gadget = this,
isFifDataSite = options.erp5_document._links.self.href.indexOf("fif_data_runner") !== -1,
return_page_cancel, return_page_confirm;
// XXX hardcoded...
if (isFifDataSite) {
if (options.jio_key.indexOf("data_array") !== -1) {
return_page = "file_fif";
} else { return_page = "data_set"; }
return_page_cancel = "data_set";
return_page_confirm = "fifdata";
if (options.jio_key.indexOf("data_stream") !== -1) {
return_page_cancel = "file_fif";
}
}
if (options.form_definition.title === "Validate Workflow Action") {
options.form_definition.title = "Validate deletion";
}
var state_dict = {
id: options.jio_key,
view: options.view,
editable: options.editable,
erp5_document: options.erp5_document,
form_definition: options.form_definition,
erp5_form: options.erp5_form || {},
isFifDataSite: isFifDataSite,
return_page: return_page
};
return this.changeState(state_dict);
var gadget = this;
// copy out wanted items from options and pass it to `changeState`
return gadget.getUrlParameter('extended_search')
.push(function (extended_search) {
return gadget.changeState({
jio_key: options.jio_key,
view: options.view,
// ignore options.editable because dialog is always editable
erp5_document: options.erp5_document,
form_definition: options.form_definition,
erp5_form: options.erp5_form || {},
// editable: true, // ignore global editable state (be always editable)
has_update_action: Boolean(options.form_definition.update_action),
// pass extended_search from previous view in case any gadget is curious
extended_search: extended_search,
isFifDataSite: isFifDataSite,
return_page_cancel: return_page_cancel,
return_page_confirm: return_page_confirm,
// XXX Hack of ERP5 how to express redirect to parent after success
redirect_to_parent: options.erp5_document._embedded._view.field_your_redirect_to_parent !== undefined
});
});
})
.onStateChange(function () {
// .declareMethod('submitDialog', submitDialog, {mutex: 'changestate'})
.onStateChange(function onStateChange(modification_dict) {
var form_gadget = this,
icon,
selector = form_gadget.element.querySelector("h3"),
view_list = ensureArray(this.state.erp5_document._links.action_workflow),
icon,
title,
i,
return_page = this.state.return_page,
view_list = this.state.erp5_document._links.action_workflow || [];
return_page_confirm = this.state.return_page_confirm,
return_page_cancel = this.state.return_page_cancel,
i;
title = this.state.form_definition.title;
for (i = 0; i < view_list.length; i += 1) {
if (view_list[i].name === this.state.view) {
title = view_list[i].title;
}
}
// XXX hardcoded...
switch (form_gadget.state.title) {
switch (title) {
case "Create User":
icon = " ui-icon-user";
break;
case "Create Document":
icon = " ui-icon-file-o";
break;
case "Change State":
case "Validate Workflow Action":
icon = " ui-icon-share-alt";
break;
case "Submit":
......@@ -90,10 +233,37 @@
break;
}
// Calculate the h3 properties
return form_gadget.translate(title)
.push(function (translated_title) {
selector.textContent = "\u00A0" + translated_title;
// By default we display dialog form title
for (i = 0; i < view_list.length; i += 1) {
if (this.state.view === view_list[i].href) {
title = view_list[i].title;
}
}
return new RSVP.Queue()
.push(function () {
// Set the dialog button
if (modification_dict.hasOwnProperty('has_update_action')) {
return form_gadget.translateHtml(dialog_button_template({
show_update_button: form_gadget.state.has_update_action
}))
.push(function (html) {
form_gadget.element.querySelector('.dialog_button_container')
.innerHTML = html;
});
}
})
.push(function () {
// Calculate the h3 properties
return RSVP.all([
form_gadget.translate(form_gadget.state.form_definition.title),
form_gadget.translate(title)
]);
})
.push(function (translated_title_list) {
form_gadget.element.querySelector('input.dialogconfirm').value = translated_title_list[1];
selector.textContent = "\u00A0" + translated_title_list[0];
selector.className = "ui-content-title ui-body-c ui-icon ui-icon-custom" + icon;
// Render the erp5_from
......@@ -102,116 +272,66 @@
.push(function (erp5_form) {
var form_options = form_gadget.state.erp5_form;
// <span class="ui-icon ui-icon-custom ui-icon-random">&nbsp;</span>
// 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
// this might cause problems if the listbox in the dialog is not curious
// about the previous search
if (form_gadget.state.extended_search) {
form_options.form_definition.extended_search = form_gadget.state.extended_search;
}
return erp5_form.render(form_options);
})
.push(function () {
// Render the headers
return RSVP.all([
form_gadget.getUrlFor({command: 'change', options: {page: return_page, view: undefined}}),
form_gadget.getUrlFor({command: 'change', options: {page: return_page_cancel, view: undefined}}),
calculatePageTitle(form_gadget, form_gadget.state.erp5_document)
]);
})
.push(function (all_result) {
form_gadget.element.querySelector('a.dialogcancel').href = all_result[0];
return form_gadget.updateHeader({
cancel_url: all_result[0],
page_title: all_result[1],
submit_action: true
page_title: all_result[1]
});
});
})
.onEvent('submit', function submit() {
if (this.state.has_update_action === true) {
// default action on submit is update in case of its existence
return submitDialog.apply(this, [true]);
}
return submitDialog.apply(this, [false]);
}, false, true)
.onEvent('submit', function () {
var form_gadget = this,
action = this.state.erp5_document._embedded._view._actions.put,
form_id = this.state.erp5_document._embedded._view.form_id,
isFifDataSite = this.state.isFifDataSite,
redirect_to_parent;
return form_gadget.notifySubmitting()
.push(function () {
return form_gadget.getDeclaredGadget("erp5_form");
})
.push(function (erp5_form) {
return erp5_form.getContent();
})
.push(function (content_dict) {
var data = {},
key;
data[form_id.key] = form_id['default'];
// XXX Hardcoded
data.dialog_id = form_id['default'];
data.dialog_method = action.action;
//XXX hack for redirect, difined in form
redirect_to_parent = content_dict.field_your_redirect_to_parent;
for (key in content_dict) {
if (content_dict.hasOwnProperty(key)) {
data[key] = content_dict[key];
}
}
return form_gadget.jio_putAttachment(
form_gadget.state.id,
action.href,
data
);
})
.push(function (evt) {
var location = evt.target.getResponseHeader("X-Location"),
jio_key,
list = [],
message;
try {
message = JSON.parse(evt.target.response).portal_status_message;
} catch (ignore) {
}
list.push(form_gadget.notifySubmitted(message));
if (isFifDataSite) {
list.push(form_gadget.redirect({command: 'change', options: {page: "fifdata"}}));
}
else {
if (redirect_to_parent) {
list.push(form_gadget.redirect({command: 'history_previous'}));
} else {
if (location === undefined || location === null) {
// No redirection, stay on the same document
list.push(form_gadget.redirect({command: 'change', options: {view: "view", page: undefined, editable: form_gadget.state.editable}}));
} else {
jio_key = new URI(location).segment(2);
if (form_gadget.state.id === jio_key) {
// Do not update navigation history if dialog redirect to the same document
list.push(form_gadget.redirect({command: 'change', options: {jio_key: jio_key, view: "view", page: undefined, editable: form_gadget.state.editable}}));
} else {
list.push(form_gadget.redirect({command: 'push_history', options: {jio_key: jio_key, editable: form_gadget.state.editable}}));
}
}
}
}
return RSVP.all(list);
})
.push(undefined, function (error) {
if ((error.target !== undefined) && (error.target.status === 400)) {
return form_gadget.notifySubmitted()
.push(function () {
return form_gadget.translate('Input data has errors');
})
.push(function (message) {
return form_gadget.notifyChange(message + '.');
})
.push(function () {
return form_gadget.displayFormulatorValidationError(JSON.parse(error.target.responseText));
});
}
throw error;
});
}, false, true);
.onEvent('click', function click(evt) {
if (evt.target.name === "action_confirm") {
evt.preventDefault();
return submitDialog.apply(this, [false]);
}
if (evt.target.name === "action_update") {
evt.preventDefault();
return submitDialog.apply(this, [true]);
}
}, false, false)
.declareService(function enableButton() {
// click event listener is now activated
// Change the state of the gadget
var gadget = this,
button_container =
gadget.element.querySelector('.dialog_button_container'),
update_button = button_container.querySelector('button'),
submit_input = button_container.querySelector('input');
submit_input.disabled = false;
if (update_button !== null) {
update_button.disabled = false;
}
});
}(window, rJS, RSVP, URI, calculatePageTitle));
\ No newline at end of file
}(window, rJS, RSVP, calculatePageTitle, Handlebars, ensureArray));
\ No newline at end of file
......@@ -224,7 +224,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.1736.17088.5205</string> </value>
<value> <string>969.16457.56234.60791</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -242,7 +242,7 @@
</tuple>
<state>
<tuple>
<float>1509011695.92</float>
<float>1532968990.23</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