Commit d7867c93 authored by Xiaowu Zhang's avatar Xiaowu Zhang

ors_wendelin: front page

parent 2913f03d
<!DOCTYPE html>
<html>
<!--
data-i18n=Others
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>ERP5 PT Frontpage</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>
<!-- custom script -->
<script src="jiodev.js" type="text/javascript"></script>
<script src="gadget_global.js" type="text/javascript"></script>
<script src="domsugar.js" type="text/javascript"></script>
<script src="gadget_erp5_page_ors_wendelin_front.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, domsugar, SimpleQuery, ComplexQuery, Query,
console, URL, Error */
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80, continue:true */
(function () {
"use strict";
var MAIN_SCOPE = 'child_scope',
document_reference_matching = /^[a-zA-Z0-9_.]+-.+/,
document_relative_url_matching = /^[a-z]+[a-z_]*_module\/[a-zA-Z0-9_]+/;
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 loadChildGadget(gadget, gadget_url, must_declare, callback) {
var queue,
child_gadget;
if (must_declare) {
queue = gadget.declareGadget(gadget_url, {scope: MAIN_SCOPE});
} else {
queue = gadget.getDeclaredGadget(MAIN_SCOPE);
}
return queue
.push(function (result) {
child_gadget = result;
if (callback) {
return callback(result);
}
})
.push(function (result) {
if (must_declare) {
domsugar(gadget.element, [
domsugar('div', {'class': 'page'}, [
child_gadget.element
])
]);
}
return result;
});
}
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: [0, 2]
})
.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;
});
}
function rewriteHTMLPageContent(gadget, html) {
var container = domsugar('div', {html: html}),
i,
a_list = container.querySelectorAll('a'),
url_options_list = [],
to_modify_a_list = [],
href;
for (i = 0; i < a_list.length; i += 1) {
href = a_list[i].getAttribute('href');
if (href !== null) {
if (document_reference_matching.test(href) && (!href.includes('/'))) {
// search for a document by reference reference
to_modify_a_list.push(a_list[i]);
url_options_list.push({
command: 'push_history',
options: {
page: gadget.state.page,
jio_key: href
}
});
} else if (document_relative_url_matching.test(href) &&
(!href.includes('view'))) {
// search for a document by reference reference
to_modify_a_list.push(a_list[i]);
url_options_list.push({
command: 'push_history',
options: {
jio_key: href
}
});
} else if ((href.indexOf('#!') === 0) || (href.indexOf('#/') === 0)) {
// ERP5JS anchor links
a_list[i].href = new URL(href, window.location.href);
} else {
// Compatibility layer with previous site
a_list[i].href = new URL(href, 'https://www.erp5.com/group_section/');
}
}
}
return gadget.getUrlForList(url_options_list)
.push(function (result_list) {
for (i = 0; i < to_modify_a_list.length; i += 1) {
to_modify_a_list[i].href = new URL(result_list[i],
window.location.href).href;
}
return container.innerHTML;
});
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("updatePanel", "updatePanel")
.declareMethod('triggerSubmit', function () {
return;
})
////////////////////////////////////////////////////////////////////
// Go
////////////////////////////////////////////////////////////////////
.allowPublicAcquisition('updateHeader', function () {
return;
})
.declareMethod('render', function (options) {
return this.changeState({
first_render: true,
page: options.page,
jio_key: options.jio_key || 'ORS-WENDELIN.Home.Page',
// Force updating the content
render_timestamp: new Date().getTime()
});
})
.onStateChange(function (modification_dict) {
var gadget = this,
doc;
return loadChildGadget(
gadget,
"gadget_editor.html",
modification_dict.hasOwnProperty('first_render'),
function (editor_gadget) {
return getFirstDocumentValue(gadget,
['relative_url', 'title',
'asStrippedHTML'], {
reference: gadget.state.jio_key,
portal_type: 'Web Page',
validation_state: ['shared', 'shared_alive',
'released', 'released_alive',
'published', 'published_alive']
})
.push(function (result_dict) {
doc = result_dict;
return rewriteHTMLPageContent(gadget, result_dict.asStrippedHTML);
})
.push(function (text_content) {
return editor_gadget.render({
"editor": "fck_editor",
"editable": false,
"maximize": "auto",
"value": text_content
});
})
.push(function () {
return gadget.getUrlForList([
{command: 'history_previous'},
{command: 'display_erp5_action_with_history', options: {
jio_key: doc.relative_url,
page: 'view_editor',
editable: true
}}
]);
})
.push(function (url_list) {
return gadget.updateHeader({
page_title: 'Wiki: ' + doc.title,
page_icon: 'puzzle-piece',
front_url: url_list[0],
edit_url: url_list[1]
});
})
/*
.push(function () {
return gadget.updatePanel({
erp5_document: {
'_links': {
'action_object_view': [{
"name": "view",
"title": "View",
"href": "view",
"icon": null
}]
}
},
jio_key: doc.relative_url,
editable: true,
view: null
});
})
*/
.push(undefined, function (error) {
if ((error instanceof SearchError) &&
(error.status_code === 404)) {
// redirect to a search, to allow people understanding
// why the list is broken
return gadget.redirect({
command: "display_with_history",
options: {
page: "search",
extended_search: Query.objectToSearchText(
createMultipleSimpleOrQuery('reference',
gadget.state.jio_key)
)
}
}, false);
}
throw error;
});
}
);
});
}());
\ No newline at end of file
<h1>Welcome to ORS Wendelin</h1>
<li>ORS Device List: <a href="#!push_history?p.editable=true&n.jio_key=data_acquisition_unit_module">Link</a></li>
\ No newline at end of file
...@@ -344,7 +344,7 @@ ...@@ -344,7 +344,7 @@
</item> </item>
<item> <item>
<key> <string>configuration_frontpage_gadget_url</string> </key> <key> <string>configuration_frontpage_gadget_url</string> </key>
<value> <string>worklist</string> </value> <value> <string>ors_wendelin_front</string> </value>
</item> </item>
<item> <item>
<key> <string>configuration_hateoas_url</string> </key> <key> <string>configuration_hateoas_url</string> </key>
...@@ -651,7 +651,7 @@ ...@@ -651,7 +651,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>zope</string> </value> <value> <unicode>zope</unicode> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -665,7 +665,7 @@ ...@@ -665,7 +665,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1007.23969.29369.58589</string> </value> <value> <string>1007.27209.27755.44270</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -685,7 +685,7 @@ ...@@ -685,7 +685,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1680077049.55</float> <float>1680271528.11</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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