--- a/src/pyams_skin/interfaces/viewlet.py Thu May 12 11:00:58 2016 +0200
+++ b/src/pyams_skin/interfaces/viewlet.py Thu Jun 02 16:27:44 2016 +0200
@@ -253,7 +253,10 @@
message = Text(title="Initial message")
loading_text = TextLine(title="Tab loading text",
- default=_("<i class='fa fa-refresh fa-spin'></i> Loading..."))
+ default=_("<i class='fa fa-refresh fa-spin'></i>"))
+
+ refresh_handler = TextLine(title="Refresh button click handler",
+ default="MyAMS.skin.refreshNotificationsPanel")
def get_last_update(self):
"""Get last update time"""
@@ -262,6 +265,8 @@
class IActivityViewlet(IViewlet):
"""User activity panel viewlet"""
+ name = TextLine(title="Tab input value")
+
label = TextLine(title="Tab label")
click_handler = TextLine(title="Tab click handler",
--- a/src/pyams_skin/templates/layout.pt Thu May 12 11:00:58 2016 +0200
+++ b/src/pyams_skin/templates/layout.pt Thu Jun 02 16:27:44 2016 +0200
@@ -108,9 +108,9 @@
<!-- user notifications button -->
<div id="user-activity" class="btn-header pull-right" tal:condition="static.include_menus">
<span>
- <a href="#" title="Notifications" class="hint" i18n:attributes="title"
+ <a href="#" title="Notifications" class="activity-button hint" i18n:attributes="title"
data-ams-hint-gravity="ne"><i class="fa fa-bell"></i></a>
- <b class="badge bg-color-danger txt-color-white">8</b>
+ <b class="badge bg-color-danger txt-color-white hidden">0</b>
<!-- AJAX-dropdown -->
<div class="ajax-dropdown"
tal:content="structure activity">
--- a/src/pyams_skin/viewlet/activity/__init__.py Thu May 12 11:00:58 2016 +0200
+++ b/src/pyams_skin/viewlet/activity/__init__.py Thu Jun 02 16:27:44 2016 +0200
@@ -14,15 +14,16 @@
# import standard library
-from babel.dates import format_datetime
from datetime import datetime
+from babel.dates import format_datetime
# import interfaces
from pyams_skin.interfaces.viewlet import IActivityViewletManager, IActivityViewlet
from pyams_skin.layer import IPyAMSLayer
# import packages
from pyams_template.template import template_config
+from pyams_utils.date import format_datetime
from pyams_viewlet.manager import TemplateBasedViewletManager, WeightOrderedViewletManager, viewletmanager_config
from pyams_viewlet.viewlet import Viewlet
from zope.interface import implementer
@@ -39,18 +40,21 @@
header = FieldProperty(IActivityViewletManager['header'])
message = FieldProperty(IActivityViewletManager['message'])
loading_text = FieldProperty(IActivityViewletManager['loading_text'])
+ refresh_handler = FieldProperty(IActivityViewletManager['refresh_handler'])
- _update_time = _("Last update: {0}")
+ update_time = _("Last update: {0}")
def get_last_update(self):
- now = datetime.now()
- return self._update_time.format(format_datetime(now, format='medium', locale=self.request.locale_name))
+ translate = self.request.localizer.translate
+ return translate(self.update_time).format(format_datetime(datetime.utcnow(),
+ request=self.request))
@implementer(IActivityViewlet)
class ActivityViewlet(Viewlet):
"""Activity viewlet panel"""
+ name = FieldProperty(IActivityViewlet['name'])
label = FieldProperty(IActivityViewlet['label'])
url = FieldProperty(IActivityViewlet['url'])
click_handler = FieldProperty(IActivityViewlet['click_handler'])
--- a/src/pyams_skin/viewlet/activity/manager.pt Thu May 12 11:00:58 2016 +0200
+++ b/src/pyams_skin/viewlet/activity/manager.pt Thu Jun 02 16:27:44 2016 +0200
@@ -1,32 +1,48 @@
-<!-- the ID links are fetched via AJAX to the ajax container "ajax-notifications" -->
-<div class="btn-group btn-group-justified" data-toggle="buttons">
- <tal:loop repeat="viewlet view.viewlets">
- <label class="btn btn-default">
- <input type="radio" name="activity"
- tal:attributes="data-ams-url viewlet.url;
- data-ams-click-handler viewlet.click_handler;"
- tal:content="viewlet.label">Label
- </label>
- </tal:loop>
-</div>
-<!-- notification content -->
-<div class="ajax-notifications custom-scroll">
- <div class="alert alert-transparent">
- <h4 tal:content="view.header"></h4>
- <tal:var replace="structure view.message" />
+<tal:var define="global notification ''">
+ <!-- the ID links are fetched via AJAX to the ajax container "ajax-notifications" -->
+ <div class="btn-group btn-group-justified" data-toggle="buttons">
+ <tal:loop repeat="viewlet view.viewlets">
+ <tal:if condition="repeat['viewlet'].start()">
+ <tal:var define="global notification viewlet.render()" />
+ </tal:if>
+ <label class="btn btn-default"
+ tal:attributes="class 'btn btn-default {0}'.format('active' if repeat['viewlet'].start() else '')">
+ <input type="radio" name="activity"
+ tal:attributes="value viewlet.name;
+ checked '' if repeat['viewlet'].start() else None;
+ data-ams-url viewlet.url;
+ data-ams-click-handler viewlet.click_handler;"
+ tal:content="viewlet.label" />
+ </label>
+ </tal:loop>
</div>
- <i class="fa fa-lock fa-4x fa-border"></i>
-</div>
-<!-- end notification content -->
+
+ <!-- notification content -->
+ <div class="ajax-notifications custom-scroll">
+ <tal:if condition="notification"
+ replace="structure notification" />
+ <tal:if condition="not notification">
+ <div class="alert alert-transparent">
+ <h4 tal:content="view.header"></h4>
+ <tal:if replace="structure view.message" />
+ </div>
+ <i class="fa fa-lock fa-4x fa-border"></i>
+ </tal:if>
+ </div>
+ <!-- end notification content -->
-<!-- footer: refresh area -->
-<span>
- <span id="activity-update"
- tal:content="view.get_last_update()"></span>
- <button type="button"
- class="btn btn-xs btn-default pull-right"
- tal:attributes="data-loading-text view.loading_text">
- <i class="fa fa-refresh"></i>
- </button>
-</span>
-<!-- end footer -->
+ <!-- footer: refresh area -->
+ <span>
+ <span id="activity-update"
+ tal:attributes="data-ams-base-label view.update_time"
+ tal:content="view.get_last_update()"></span>
+ <button type="button"
+ class="btn btn-xs btn-default pull-right"
+ data-ams-stop-propagation="true"
+ tal:attributes="data-loading-text view.loading_text;
+ data-ams-click-handler view.refresh_handler;">
+ <i class="fa fa-refresh"></i>
+ </button>
+ </span>
+ <!-- end footer -->
+</tal:var>