Commit 875d44b1 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Add headless listbox on the front page to Unread Acknowledgement messages

This is mostly to display Site Messages for various uses.
parent d0420574
......@@ -13,6 +13,22 @@
padding-top: 17px;
}
.box-gadget-top {
float: left;
width: 100%;
padding-bottom: 30px;
}
.box-gadget-top nav,
.box-gadget-top div.ui-header {
display: none;
}
.box-gadget-top .document_table table thead {
background-color: white;
}
.ui-btn-white-front,
.ui-btn-white-front:active,
.ui-btn-white-front:hover {
......
......@@ -245,7 +245,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>966.40300.60783.54357</string> </value>
<value> <string>975.6713.31372.10752</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -263,7 +263,7 @@
</tuple>
<state>
<tuple>
<float>1522775894.53</float>
<float>1555545224.77</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -29,7 +29,12 @@
</head>
<body>
<form>
<div class="box-gadget-top">
<div data-gadget-url="gadget_erp5_pt_form_view_editable.html"
data-gadget-scope="top"></div>
</div>
<div class="box-gadget-left">
<div class="map-gadget"></div>
</div>
......
......@@ -245,7 +245,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>966.40689.62566.35447</string> </value>
<value> <string>975.8047.34187.33979</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -263,7 +263,7 @@
</tuple>
<state>
<tuple>
<float>1522799337.96</float>
<float>1555625336.18</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -37,7 +37,7 @@
.push(function (result) {
var i, value, value_jio_key, date, len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (1 || (result.data.rows[i].hasOwnProperty("id"))) {
if (result.data.rows[i].value.hasOwnProperty("Organisation_getNewsDict")) {
value_jio_key = result.data.rows[i].id;
value = result.data.rows[i].value.Organisation_getNewsDict;
result.data.rows[i].value.Organisation_getNewsDict = {
......@@ -57,6 +57,27 @@
value: 2713
};
}
if (result.data.rows[i].value.hasOwnProperty("Event_getAcknowledgementDict")) {
value_jio_key = result.data.rows[i].id;
value = result.data.rows[i].value.Event_getAcknowledgementDict;
result.data.rows[i].value.Event_getAcknowledgementDict = {
field_gadget_param : {
editable: 1,
css_class: "",
description: "",
hidden: 0,
"default": value,
key: "acknowledge_message",
url: "gadget_slapos_alert_listbox_field.html",
title: "Acknowledge Message",
type: "GadgetField"
}
};
result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list",
value: 2713
};
}
if (result.data.rows[i].value.hasOwnProperty("modification_date")) {
date = new Date(result.data.rows[i].value.modification_date);
result.data.rows[i].value.modification_date = {
......@@ -158,6 +179,59 @@
});
});
})
.push(function () {
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('top'),
gadget.getSetting("hateoas_url")
]);
})
.push(function (result) {
var column_list = [
['Event_getAcknowledgementDict', ' ']
];
return result[0].render({
erp5_document: {
"_embedded": {"_view": {
"listbox": {
"column_list": column_list,
"show_anchor": 0,
"default_params": {},
editable: 1,
"editable_column_list": column_list,
"key": "slap_acknowledgement_listbox",
"lines": 5,
"list_method": "AcknowledgementTool_getUserUnreadAcknowledgementValueList",
"list_method_template": result[1] + "ERP5Document_getHateoas?mode=search&" +
"list_method=AcknowledgementTool_getUserUnreadAcknowledgementValueList" +
"{&query,select_list*,limit*,sort_on*,local_roles*}",
"query": "urn:jio:allDocs?query=",
"portal_type": [],
"search_column_list": column_list,
"sort_column_list": column_list,
"sort": [["Event_getAcknowledgementDict", "ASC"]],
"title": "Notifications",
"type": "ListBox"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"bottom",
[["listbox"]]
]]
}
});
});
})
.push(function () {
var lines_limit = 15;
return new RSVP.Queue()
......
......@@ -241,7 +241,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.61525.54996.33297</string> </value>
<value> <string>975.8014.50969.47940</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -259,7 +259,7 @@
</tuple>
<state>
<tuple>
<float>1554901947.77</float>
<float>1555624052.83</float>
<string>UTC</string>
</tuple>
</state>
......
.message {
position: fixed;
top: 60pt;
}
.alert {
position: relative;
padding: .75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: .25rem;
}
.alert-pointer {
cursor: pointer;
}
.alert-info {
color: #0c5460;
background-color: #d1ecf1;
border-color: #bee5eb;
}
.alert-warning {
color: #856404;
background-color: #fff3cd;
border-color: #ffeeba;
}
.alert-danger {
color: #721c24;
background-color: #f8d7da;
border-color: #f5c6cb;
}
.alert > h2 {
font-weight: bold;
margin-bottom: 10px;
}
.alert p {
white-space: pre-wrap;
display: block;
word-wrap: break-word;
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Message Alert</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_slapos_alert_listbox_field.js"></script>
<link href="gadget_slapos_alert_listbox_field.css" rel="stylesheet" type="text/css"/>
<script id="alert-message-template" type="text/x-handlebars-template">
{{#if link}}
<a href={{link}}>
{{/if}}
<div class="alert alert-{{type}}">
{{#if title}}
<h2>{{title}}</h2>
{{/if}}
<p>{{message}}</p>
</div>
{{#if link}}
</a>
{{/if}}
</script>
<script id="alert-message-with-link-template" type="text/x-handlebars-template">
<div class="alert alert-{{type}}">
{{#if title}}
<h2>{{title}}</h2>
{{/if}}
<p>{{message}}</p>
</div>
</a>
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*globals console, document, window, rJS, RSVP, Handlebars*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (document, window, rJS, RSVP, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
alert_message_content = gadget_klass.__template_element
.getElementById("alert-message-template")
.innerHTML,
alert_message_template = Handlebars.compile(alert_message_content);
gadget_klass
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareMethod("render", function (options) {
var gadget = this,
html_message,
message_content = document.createElement('div'),
closable = options.can_close || false,
id = "alert" + new Date().getTime();
message_content.id = id;
message_content.setAttribute("data-key", options.key || "");
return new RSVP.Queue()
.push(function () {
if (options.value.link) {
return RSVP.all([
gadget.getElement(),
gadget.getUrlFor({command: "index",
options: {jio_key: options.value.link,
page: "slap_controller"}})
]);
} else {
return RSVP.all([
gadget.getElement()
]);
}
})
.push(function (result) {
var element = result[0],
link = result[1];
element.innerHTML = alert_message_template({
link: link,
message: options.value.text_content,
title: options.value.title || "",
type: options.type || "danger"
});
return element;
});
});
}(document, window, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -108,7 +108,7 @@
<value> <string encoding="cdata"><![CDATA[
CACHE MANIFEST\n
# generated on Tue, 19 Mars 2019 00:00:00 GMT+0200\n
# generated on Fri, 26 Avril 2019 00:00:00 GMT+0200\n
CACHE:\n
favicon.ico\n
font-awesome/font-awesome-webfont.eot?v=4.6.3\n
......@@ -404,6 +404,9 @@ gadget_slapos_invoice_state.html\n
gadget_slapos_invoice_state.js\n
gadget_slapos_label_listbox_field.html\n
gadget_slapos_label_listbox_field.js\n
gadget_slapos_alert_listbox_field.js\n
gadget_slapos_alert_listbox_field.css\n
gadget_slapos_alert_listbox_field.html\n
gadget_slapos_network_status.html\n
gadget_slapos_network_status.js\n
gadget_slapos_panel.html\n
......@@ -558,7 +561,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.29171.1584.24746</string> </value>
<value> <string>975.9238.47958.47360</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -576,7 +579,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1554923957.36</float>
<float>1556264848.5</float>
<string>UTC</string>
</tuple>
</state>
......
"""
Return the list of unread acknowledgements for the user currently
connected. This script will use efficiently caches in order to slow
down as less a possible the user interface
"""
from DateTime import DateTime
portal = context.getPortalObject()
user_name = portal.portal_membership.getAuthenticatedMember().getId()
def getUnreadAcknowledgementListForUser(user_name=None):
# We give the portal type "Mass Notification" for now, we can
# have a getPortalAcknowledgeableTypeList method in the future
portal_acknowledgements = getattr(portal, "portal_acknowledgements", None)
result = []
if portal_acknowledgements is not None:
result = portal_acknowledgements.getUnreadDocumentUrlList(
user_name=user_name, portal_type="Site Message")
return result
from Products.ERP5Type.Cache import CachingMethod
# Cache for every user the list of url of not acknowledge documents
getUnreadAcknowledgementList = CachingMethod(getUnreadAcknowledgementListForUser,
"getUnreadAcknowledgementListForUser")
return_list = []
url_list = getUnreadAcknowledgementList(user_name=user_name)
# For every not acknowledge document, check that documents are still not
# acknowledged and return them for the user interface
if len(url_list) > 0:
return portal.portal_acknowledgements.getUnreadAcknowledgementList(
url_list=url_list, user_name=user_name)
return return_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<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_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<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>_params</string> </key>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AcknowledgementTool_getUserUnreadAcknowledgementValueList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
return {
"title": context.getCausalityTitle(),
"text_content": context.getTextContent(),
"link": context.getCausalityValue(context).getFollowUp(checked_permission='View')
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<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_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<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>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Event_getAcknowledgementDict</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
image_module/gadget_slapos_panel_png
web_page_module/rjs_gadget_translation_data_js
web_page_module/rjs_gadget_slapos_alert_listbox_field_css
web_page_module/rjs_gadget_slapos_alert_listbox_field_html
web_page_module/rjs_gadget_slapos_alert_listbox_field_js
web_page_module/rjs_gadget_erp5_attention_point_css
web_page_module/rjs_gadget_erp5_attention_point_html
web_page_module/rjs_gadget_erp5_attention_point_js
......
......@@ -137,6 +137,9 @@ web_page_module/rjs_gadget_erp5_panel_shortcut_html
web_page_module/rjs_gadget_erp5_panel_shortcut_js
web_page_module/rjs_gadget_erp5_pt_form_slapos_index_html
web_page_module/rjs_gadget_erp5_pt_form_slapos_index_js
web_page_module/rjs_gadget_slapos_alert_listbox_field_css
web_page_module/rjs_gadget_slapos_alert_listbox_field_html
web_page_module/rjs_gadget_slapos_alert_listbox_field_js
web_page_module/rjs_gadget_slapos_appcache
web_page_module/rjs_gadget_slapos_computer_map_html
web_page_module/rjs_gadget_slapos_computer_map_js
......
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