Updated activity viewlet
authorThierry Florac <thierry.florac@onf.fr>
Thu, 02 Jun 2016 16:27:44 +0200
changeset 138 4ce6e8538a8d
parent 137 2dec7379f935
child 139 c0a07350ec46
Updated activity viewlet
src/pyams_skin/interfaces/viewlet.py
src/pyams_skin/templates/layout.pt
src/pyams_skin/viewlet/activity/__init__.py
src/pyams_skin/viewlet/activity/manager.pt
--- 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=_("&lt;i class=&#39;fa fa-refresh fa-spin&#39;&gt;&lt;/i&gt; Loading..."))
+                            default=_("&lt;i class=&#39;fa fa-refresh fa-spin&#39;&gt;&lt;/i&gt;"))
+
+    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>