Commit b5e79630 authored by Boxiang Sun's avatar Boxiang Sun Committed by Eteri

erp5_officejs_support_request_ui: Add worklist to the homepage and remove child changeState calls

This commit contains two main changes:
- Add worklist gadget to the homepage.
- Remove the child's `changeState` calls in homepage.
  This was done by using customized `form_list_sr`. Which can let the listbox
  has same appearance like `form_view` but use same argument passing mechanism
  as `form_list`.
parent af50db8e
<!DOCTYPE html>
<html>
<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 List</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_global.js" type="text/javascript"></script>
<script src="gadget_erp5_pt_form_list_sr.js" type="text/javascript"></script>
</head>
<body>
<!-- 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
/*global window, rJS, RSVP, calculatePageTitle */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, calculatePageTitle) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("renderEditorPanel", "renderEditorPanel")
/////////////////////////////////////////////////////////////////
// Proxy methods to the child gadget
/////////////////////////////////////////////////////////////////
.declareMethod('checkValidity', function () {
return this.getDeclaredGadget("erp5_form")
.push(function (declared_gadget) {
return declared_gadget.checkValidity();
});
})
.declareMethod('getContent', function () {
return this.getDeclaredGadget("erp5_form")
.push(function (declared_gadget) {
return declared_gadget.getContent();
});
})
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod('render', function (options) {
var gadget = this;
return gadget.getUrlParameter('extended_search')
.push(function (extended_search) {
var state_dict = {
jio_key: options.jio_key,
view: options.view,
editable: options.editable,
erp5_document: options.erp5_document,
form_definition: options.form_definition,
erp5_form: options.erp5_form || {},
extended_search: extended_search
};
return gadget.changeState(state_dict);
});
})
.onStateChange(function () {
var form_gadget = this;
// render the erp5 form
return form_gadget.getDeclaredGadget("erp5_form")
.push(function (erp5_form) {
var form_options = form_gadget.state.erp5_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 = form_gadget.state.editable;
// XXX Hardcoded for listbox's hide functionality
form_options.form_definition.hide_enabled = true;
// XXX not generic, fix later
if (form_gadget.state.extended_search) {
form_options.form_definition.extended_search = form_gadget.state.extended_search;
}
return erp5_form.render(form_options);
})
})
}(window, rJS, RSVP, calculatePageTitle));
\ No newline at end of file
......@@ -52,4 +52,9 @@ button:disabled{
input[type="submit"] {
-webkit-appearance: none;
}
.worklist-title {
color: #777777;
margin-top: 10px;
}
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.1022.173.35635</string> </value>
<value> <string>962.1250.5215.15667</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1505136124.72</float>
<float>1505897718.64</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -44,6 +44,8 @@
</div>
<div data-gadget-url="gadget_erp5_page_form.html" data-gadget-scope="last"></div>
<h1 data-i18n="Support Requests" class="ui-title ui-override-theme worklist-title">Support Requests WorkList</h1>
<div data-gadget-url="gadget_supportrequest_page_worklist.html" data-gadget-scope="worklist"></div>
</form>
</body>
</html>
\ No newline at end of file
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.1011.37939.53486</string> </value>
<value> <string>962.17075.21280.35942</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1505136135.97</float>
<float>1506095040.88</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -65,12 +65,16 @@
})
.allowPublicAcquisition("chartItemClick", function (params) {
var gadget = this;
return gadget.getDeclaredGadget("last")
.push(function () {
return gadget.getSearchCriteria(params[0][0], params[0][1])
.push(function (search_criteria) {
gadget.changeState({extended_search: search_criteria});
});
return gadget.getSearchCriteria(params[0][0], params[0][1])
.push(function (result) {
return gadget.redirect({command: 'change', options: {extended_search: result}});
})
.push(undefined, function (error) {
if (error instanceof RSVP.CancellationError) {
return;
}
throw error;
})
.push(function () {
var restore = document.getElementById("restoreButton");
......@@ -232,63 +236,49 @@
});
});
})
.onStateChange(function (modification_dict) {
.onStateChange(function () {
var gadget = this,
queue = new RSVP.Queue();
if (modification_dict.hasOwnProperty("extended_search")) {
// render the erp5 form
queue
.push(function () {
return gadget.getDeclaredGadget("last");
})
.push(function (result_list) {
var erp5_form = result_list,
tmp;
tmp = JSON.parse(erp5_form.state.erp5_form);
tmp.extended_search = modification_dict.extended_search;
return erp5_form.changeState({erp5_form: JSON.stringify(tmp)});
});
}
if (modification_dict.hasOwnProperty("render")) {
queue
.push(function () {
return RSVP.all([
gadget.jio_getAttachment("support_request_module", "links"),
gadget.getDeclaredGadget("last")
]);
})
.push(function (result_list) {
var i,
erp5_document = result_list[0],
view_list = erp5_document._links.action_object_view || [],
last_href;
queue
.push(function () {
return RSVP.all([
gadget.jio_getAttachment("support_request_module", "links"),
gadget.getDeclaredGadget("worklist"),
gadget.getUrlParameter('field_listbox_begin_from')
]);
})
.push(function (result_list) {
var i,
erp5_document = result_list[0],
view_list = erp5_document._links.action_object_view || [],
last_href;
if (view_list.constructor !== Array) {
view_list = [view_list];
}
if (view_list.constructor !== Array) {
view_list = [view_list];
}
for (i = 0; i < view_list.length; i += 1) {
if (view_list[i].name === 'view_last_support_request') {
last_href = view_list[i].href;
}
for (i = 0; i < view_list.length; i += 1) {
if (view_list[i].name === 'view_last_support_request') {
last_href = view_list[i].href;
}
}
if (last_href === undefined) {
throw new Error('Cant find the list document view');
}
gadget.property_dict.option_dict = {
graph_gadget: "unsafe/gadget_field_graph_echarts.html",
listbox_gadget: last_href,
listbox_jio_key: "support_request_module"
};
if (last_href === undefined) {
throw new Error('Cant find the list document view');
}
gadget.property_dict.option_dict = {
graph_gadget: "unsafe/gadget_field_graph_echarts.html",
listbox_gadget: last_href,
listbox_jio_key: "support_request_module",
field_listbox_begin_from: result_list[2]
};
return RSVP.all([
gadget.renderGraph() //Launched as service, not blocking
]);
});
}
return RSVP.all([
result_list[1].render(),
gadget.renderGraph() //Launched as service, not blocking
]);
});
return queue;
})
.onEvent('change', function (evt) {
......@@ -319,13 +309,19 @@
}, false, false)
.onEvent('click', function (event) {
var gadget = this, rss_link = gadget.element.querySelector("#generate-rss"),
generate_button = gadget.element.querySelector("#generateRSS");
generate_button = gadget.element.querySelector("#generateRSS"),
restore = document.getElementById("restoreButton");
if (event.target.id === "restoreButton") {
return gadget.changeState({extended_search: null})
.push(function () {
var restore = document.getElementById("restoreButton");
restore.setAttribute("disabled", "disabled");
restore.setAttribute("disabled", "disabled");
return gadget.getDeclaredGadget("last")
.push(function (listbox) {
return listbox.render({
jio_key: gadget.property_dict.option_dict.listbox_jio_key,
view: gadget.property_dict.option_dict.listbox_gadget,
extended_search: null
});
});
}
......@@ -383,4 +379,4 @@
});
});
}(window, rJS, RSVP));
\ No newline at end of file
}(window, rJS, RSVP));
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.5582.22272.14165</string> </value>
<value> <string>962.17232.34531.58794</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1505396121.35</float>
<float>1506095076.51</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<!--
data-i18n=Worklist
data-i18n=All work caught up!
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 Page Worklist</title>
<!-- 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 -->
<script src="gadget_global.js" type="text/javascript"></script>
<script src="gadget_supportrequest_page_worklist.js" type="text/javascript"></script>
<!-- XXX must set theme here! -->
<script id="table-template" type="text/x-handlebars-template">
{{#if document_list }}
<ul data-role="listview" data-theme="c" class="document-listview ui-listview-inset ui-corner-all">
{{#each document_list}}
<li class="ui-li-has-count" data-icon="false" ><a class="ui-body-inherit" href="{{link}}">{{title}} <span class="ui-li-count">{{count}}</span></a></li>
{{/each}}
</ul>
{{else}}
<p>All work caught up!</p>
{{/if}}
</script>
</head>
<body>
<section class="document_list"></section>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, Handlebars, URI */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, URI) {
"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);
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function () {
var gadget = this;
return gadget.updateHeader({
page_title: 'Worklist',
page_icon: 'clipboard'
})
.push(function () {
return gadget.jio_getAttachment(
'portal_workflow',
'links'
);
})
.push(function (result) {
return gadget.jio_getAttachment(
// result.data.rows[0].id,
'portal_workflow',
result._links.action_worklist.href
);
})
.push(function (links) {
/*jslint continue:true*/
var action_list = links.worklist,
query_string,
promise_list = [],
display_options,
i;
for (i = 0; i < action_list.length; i += 1) {
query_string = new URI(action_list[i].href).query(true).query;
if (query_string.indexOf('portal_type:"Support Request"') === -1) {
continue;
}
display_options = {extended_search: query_string};
if (action_list[i].hasOwnProperty('module')) {
display_options = {
jio_key: new URI(action_list[i].module).segment(2),
extended_search: query_string,
page: 'form',
view: 'view'
};
} else {
display_options = {
extended_search: query_string,
page: 'search'
};
}
promise_list.push(RSVP.all([
gadget.getUrlFor({command: 'display', options: display_options}),
// Remove the counter from the title
action_list[i].name,
action_list[i].count
]));
}
return RSVP.all(promise_list);
})
.push(function (result_list) {
var line_list = [],
i;
for (i = 0; i < result_list.length; i += 1) {
line_list.push({
link: result_list[i][0],
title: result_list[i][1],
count: result_list[i][2]
});
}
gadget.element.querySelector('.document_list').innerHTML = table_template({
document_list: line_list
});
});
});
}(window, rJS, RSVP, Handlebars, URI));
\ No newline at end of file
......@@ -128,7 +128,7 @@
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_view</string> </value>
<value> <string>form_list_sr</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>form_list_sr</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<tal:block xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<!--
The "form_list_sr.apt" is exactly same as "form_list.apt".
The differences between these two page tempalte is the "form_list_sr"
removed the search field in its html definition. Use the customized
"form_list" because we want the listbox gadget has same appearance like
"form_view" but keep the argument pass mechanism of "form_list".
-->
<tal:block metal:use-macro="here/list_main/macros/master">
<tal:block metal:fill-slot="main">
<tal:block metal:use-macro="here/form_render/macros/master" />
</tal:block>
</tal:block>
</tal:block>
\ No newline at end of file
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