Commit 879fcb77 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_web_renderjs_ui: x

parent 5e2cf409
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>ERP5 Home Page</title>
<link rel="http://www.renderjs.org/rel/interface" href="interface_page.html">
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="domsugar.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_erp5_page_homepage.js" type="text/javascript"></script>
</head>
<body>
<section class="homepage"></section>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, domsugar, URI */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, domsugar, SimpleQuery, ComplexQuery, Query) {
"use strict";
// copy from wiki
function SearchError(message, status_code) {
if ((message !== undefined) && (typeof message !== "string")) {
throw new TypeError('You must pass a string.');
}
this.message = message || "Default Message";
this.status_code = status_code || 500;
}
SearchError.prototype = new Error();
SearchError.prototype.constructor = SearchError;
function createMultipleSimpleOrQuery(key, value_list) {
var i,
query_list = [];
if (!Array.isArray(value_list)) {
value_list = [value_list];
}
for (i = 0; i < value_list.length; i += 1) {
query_list.push(new SimpleQuery({
key: key,
operator: "=",
type: "simple",
value: value_list[i]
}));
}
if (value_list.len === 1) {
return query_list[0];
}
return new ComplexQuery({
operator: "OR",
query_list: query_list,
type: "complex"
});
}
function getFirstDocumentValue(gadget, select_list, search_dict) {
var query_list = Object.entries(search_dict).map(function (tuple) {
return createMultipleSimpleOrQuery(tuple[0], tuple[1]);
});
return gadget.jio_allDocs({
select_list: select_list,
query: Query.objectToSearchText(
new ComplexQuery({
operator: "AND",
type: "complex",
query_list: query_list
})
),
limit: 1
})
.push(function (result) {
if (result.data.rows.length === 0) {
throw new SearchError(
'Can find document matching ' + JSON.stringify(search_dict),
404
);
}
return result.data.rows[0].value;
});
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("updatePanel", "updatePanel")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this,
extra_action_dict = {},
parameter_list = [];
parameter_list.push({
command: 'display_with_history',
options: {
page: "osoe_new"
}
});
parameter_list.push({
command: 'display_with_history',
options: {
page: 'osoe_report'
}
});
parameter_list.push({
command: 'display_erp5_action_with_history',
options: {
jio_key: 'document_module',
page: 'contribute_file',
keep_history: true
}
});
return gadget.getUrlForList(parameter_list)
.push(function (href_list) {
return gadget.changeState({
extra_menu_dict: {
'Link' : {
'icon': 'link',
'action_list': [
{
"title" : "New",
"class_name" : "ui-btn-icon-top ui-icon-plus"
},
{
'title' : 'Report',
'class_name' : 'ui-icon ui-icon-bar-chart-o'
},
{
'title' : 'Contribute',
'class_name' : 'ui-btn-icon-top ui-icon-file'
}
],
'href_list': href_list
}
},
homepage: 'my_homepage'
});
});
})
.onStateChange(function onStateChange(modification_dict) {
var gadget = this,
doc,
queue = new RSVP.Queue();
if (modification_dict.homepage) {
queue
.push(function () {
return RSVP.all([
gadget.declareGadget('gadget_html_viewer.html', {element: gadget.element.querySelector('.homepage')}),
getFirstDocumentValue(
gadget,
['relative_url', 'title', 'text_content'],
{
reference: modification_dict.homepage,
portal_type: 'Web Page',
validation_state: ['shared', 'shared_alive',
'released', 'released_alive',
'published', 'published_alive']
})
]);
})
.push(function (result_list) {
doc = result_list[1];
return result_list[0].render({value: result_list[1].text_content});
});
}
queue.push(function () {
return gadget.updatePanel({
extra_menu_dict: modification_dict.extra_menu_dict
});
}).push(function () {
return gadget.updateHeader({
page_title: 'Homepage',
page_icon: 'home'
});
});
return queue;
});
}(window, rJS, RSVP, domsugar, SimpleQuery, ComplexQuery, Query));
\ No newline at end of file
......@@ -62,6 +62,7 @@
view = options.view,
jump_view = options.jump_view,
visible = options.visible,
extra_menu_dict = options.extra_menu_dict,
display_workflow_list,
context = this,
workflow_list,
......@@ -119,6 +120,9 @@
clone_list = JSON.stringify(clone_list);
jump_list = JSON.stringify(jump_list);
}
if (extra_menu_dict !== undefined) {
extra_menu_dict = JSON.stringify(extra_menu_dict);
}
return context.getUrlParameter('editable')
.push(function (editable) {
return context.changeState({
......@@ -133,7 +137,8 @@
jio_key: jio_key,
view: view,
jump_view: jump_view,
editable: asBoolean(options.editable) || asBoolean(editable) || false
editable: asBoolean(options.editable) || asBoolean(editable) || false,
extra_menu_dict: extra_menu_dict
});
});
})
......@@ -258,7 +263,7 @@
modification_dict.hasOwnProperty("jio_key") ||
modification_dict.hasOwnProperty("view_list"))) {
if (this.state.view_list === undefined) {
gadget.element.querySelector("dl").textContent = '';
gadget.element.querySelector("dl.document_menu").textContent = '';
} else {
queue
.push(function () {
......@@ -345,7 +350,7 @@
view_list.length + workflow_list.length +
action_list.length + clone_list.length);
dl_element = gadget.element.querySelector("dl");
dl_element = gadget.element.querySelector("dl.document_menu");
while (dl_element.firstChild) {
dl_element.removeChild(dl_element.firstChild);
}
......@@ -353,7 +358,27 @@
});
}
}
if ((this.state.global === true) &&
(modification_dict.hasOwnProperty("extra_menu_dict"))) {
queue.push(function () {
var key,
item,
dl_element = gadget.element.querySelector("dl.global_menu"),
dl_fragment,
extra_menu_dict;
if (gadget.state.extra_menu_dict === undefined) {
dl_element.textContent = "";
} else {
dl_fragment = document.createDocumentFragment();
extra_menu_dict = JSON.parse(gadget.state.extra_menu_dict);
for (key in extra_menu_dict) {
appendDt(dl_fragment, key, extra_menu_dict[key].icon,
extra_menu_dict[key].action_list, extra_menu_dict[key].href_list, 0);
}
dl_element.appendChild(dl_fragment);
}
});
}
return queue;
})
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>988.65434.35774.5563</string> </value>
<value> <string>989.43428.10979.16264</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1609322633.89</float>
<float>1611934613.05</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