Improved notification links to mark items as confirmed
authorAlexander Ebert <ebert@woltlab.com>
Tue, 2 Dec 2014 21:24:05 +0000 (22:24 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 2 Dec 2014 21:24:05 +0000 (22:24 +0100)
com.woltlab.wcf/templates/notificationList.tpl
com.woltlab.wcf/templates/notificationListOustanding.tpl
wcfsetup/install/files/js/WCF.User.js
wcfsetup/install/files/lib/action/NotificationConfirmAction.class.php [new file with mode: 0644]

index da5d1977e15e9be6d8744a376d81b1a8e2c03f22..6522ea6a3381c20d5b9ee557c36f7d1b3f26f3e8 100644 (file)
@@ -63,7 +63,7 @@
                        <div class="container marginTop">
                                <ul class="containerList userNotificationItemList">
                {/if}
-                               <li class="jsNotificationItem notificationItem{if $notification[authors] > 1} groupedNotificationItem{/if}{if !$notification[event]->isConfirmed()} notificationUnconfirmed{/if}" data-notification-id="{@$notification[notificationID]}" data-link="{$notification[event]->getLink()}" data-is-grouped="{if $notification[authors] > 1}true{else}false{/if}" data-is-confirmed="{if $notification[event]->isConfirmed()}true{else}false{/if}">
+                               <li class="jsNotificationItem notificationItem{if $notification[authors] > 1} groupedNotificationItem{/if}{if !$notification[event]->isConfirmed()} notificationUnconfirmed{/if}" data-notification-id="{@$notification[notificationID]}" data-link="{$notification[event]->getLink()}" data-confirm-link="{link controller='NotificationConfirm' id=$notification[notificationID]}{/link}" data-is-grouped="{if $notification[authors] > 1}true{else}false{/if}" data-is-confirmed="{if $notification[event]->isConfirmed()}true{else}false{/if}">
                                        <div class="box24">
                                                {if $notification[authors] < 2}
                                                        <div class="framed">
index ccb5cb282c7befd8837f8b95946dcde5e22467d2..e8bae594eedb4b6e211bb55a29d7959379ee9941 100644 (file)
@@ -1,5 +1,5 @@
 {foreach from=$notifications[notifications] item=notification}
-       <li class="jsNotificationItem notificationItem{if $notification[event]->getAuthors()|count > 1} groupedNotificationItem{/if}{if !$notification[event]->isConfirmed()} notificationUnconfirmed{/if}" data-link="{$notification[event]->getLink()}" data-notification-id="{@$notification[notificationID]}" data-is-confirmed="{if $notification[event]->isConfirmed()}true{else}false{/if}">
+       <li class="jsNotificationItem notificationItem{if $notification[event]->getAuthors()|count > 1} groupedNotificationItem{/if}{if !$notification[event]->isConfirmed()} notificationUnconfirmed{/if}" data-link="{$notification[event]->getLink()}" data-confirm-link="{link controller='NotificationConfirm' id=$notification[notificationID]}{/link}" data-notification-id="{@$notification[notificationID]}" data-is-confirmed="{if $notification[event]->isConfirmed()}true{else}false{/if}">
                <span class="box24">
                        <div class="framed">
                                {if $notification[event]->getAuthors()|count < 2}
index 493dd20db4077c04217082fc8cb07ef8f8e72f1e..718fa274c7e0ad9601fc7b2be609ae68934c1415 100644 (file)
@@ -1295,10 +1295,15 @@ WCF.Notification.List = Class.extend({
        _convertList: function() {
                $('.userNotificationItemList > .notificationItem').each((function(index, item) {
                        var $item = $(item);
+                       var $isConfirmed = $item.data('isConfirmed');
                        
-                       if (!$.browser.mobile && !$item.data('isConfirmed')) {
-                               var $markAsConfirmed = $('<a href="#" class="icon icon24 fa-check green notificationItemMarkAsConfirmed jsTooltip" title="' + WCF.Language.get('wcf.user.notification.markAsConfirmed') + '" />').prependTo($item.find('> div.box24 > .framed'));
-                               $markAsConfirmed.click($.proxy(this._markAsConfirmed, this));
+                       if (!$isConfirmed) {
+                               $item.find('a:not(.userLink)').prop('href', $item.data('confirmLink'));
+                               
+                               if (!$.browser.mobile) {
+                                       var $markAsConfirmed = $('<a href="#" class="icon icon24 fa-check green notificationItemMarkAsConfirmed jsTooltip" title="' + WCF.Language.get('wcf.user.notification.markAsConfirmed') + '" />').prependTo($item.find('> div.box24 > .framed'));
+                                       $markAsConfirmed.click($.proxy(this._markAsConfirmed, this));
+                               }
                        }
                }).bind(this));
                
@@ -1448,15 +1453,20 @@ WCF.Notification.UserPanel = WCF.UserPanel.extend({
                var $insertAfter = null;
                $items.each((function(index, item) {
                        var $item = $(item);
+                       var $isConfirmed = $item.data('isConfirmed');
                        
                        if (!$.browser.msie) {
                                $item.addClass('notificationItemLink');
-                               $('<a href="' + $item.data('link') + '" />').appendTo($item);
+                               $('<a href="' + ($isConfirmed ? $item.data('link') : $item.data('confirmLink')) + '" />').appendTo($item);
                        }
                        
-                       if (!$.browser.mobile && !$item.data('isConfirmed')) {
-                               var $markAsConfirmed = $('<a href="#" class="icon icon24 fa-check green notificationItemMarkAsConfirmed jsTooltip" title="' + WCF.Language.get('wcf.user.notification.markAsConfirmed') + '" />').prependTo($item.find('> span.box24 > .framed'));
-                               $markAsConfirmed.click($.proxy(this._markAsConfirmed, this));
+                       if (!$isConfirmed) {
+                               $item.find('a:not(.userLink)').prop('href', $item.data('confirmLink'));
+                               
+                               if (!$.browser.mobile) {
+                                       var $markAsConfirmed = $('<a href="#" class="icon icon24 fa-check green notificationItemMarkAsConfirmed jsTooltip" title="' + WCF.Language.get('wcf.user.notification.markAsConfirmed') + '" />').prependTo($item.find('> span.box24 > .framed'));
+                                       $markAsConfirmed.click($.proxy(this._markAsConfirmed, this));
+                               }
                        }
                        
                        if (!$item.data('isConfirmed')) {
diff --git a/wcfsetup/install/files/lib/action/NotificationConfirmAction.class.php b/wcfsetup/install/files/lib/action/NotificationConfirmAction.class.php
new file mode 100644 (file)
index 0000000..fa30f9b
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+namespace wcf\action;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\data\user\notification\event\UserNotificationEvent;
+use wcf\data\user\notification\UserNotification;
+use wcf\data\user\User;
+use wcf\data\user\UserProfile;
+use wcf\system\exception\IllegalLinkException;
+use wcf\system\exception\PermissionDeniedException;
+use wcf\system\user\notification\UserNotificationHandler;
+use wcf\system\WCF;
+use wcf\util\HeaderUtil;
+
+/**
+ * Marks target notification as confirmed and forwards to the notification URL.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2014 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage action
+ * @category   Community Framework
+ */
+class NotificationConfirmAction extends AbstractAction {
+       /**
+        * @see \wcf\action\AbstractAction::$loginRequired
+        */
+       public $loginRequired = true;
+       
+       /**
+        * user notification object
+        * @var \wcf\data\user\notification\UserNotification
+        */
+       public $notification = null;
+       
+       /**
+        * user notification id
+        * @var integer
+        */
+       public $notificationID = 0;
+       
+       /**
+        * @see \wcf\action\IAction::readParameters()
+        */
+       public function readParameters() {
+               parent::readParameters();
+               
+               if (isset($_REQUEST['id'])) $this->notificationID = intval($_REQUEST['id']);
+               
+               $this->notification = new UserNotification($this->notificationID);
+               if (!$this->notification->notificationID) {
+                       throw new IllegalLinkException();
+               }
+               
+               if ($this->notification->userID != WCF::getUser()->userID) {
+                       throw new PermissionDeniedException();
+               }
+       }
+       
+       /**
+        * @see \wcf\action\IAction::execute()
+        */
+       public function execute() {
+               parent::execute();
+               
+               if (!$this->notification->confirmTime) {
+                       UserNotificationHandler::getInstance()->markAsConfirmedByID($this->notification->notificationID);
+               }
+               
+               $event = new UserNotificationEvent($this->notification->eventID);
+               $objectType = ObjectTypeCache::getInstance()->getObjectType($event->objectTypeID);
+               $objects = $objectType->getProcessor()->getObjectsByIDs(array($this->notification->objectID));
+               
+               $className = $event->className;
+               $notificationEvent = new $className($event);
+               $notificationEvent->setObject(
+                       $this->notification,
+                       $objects[$this->notification->objectID],
+                       $unknownAuthor = new UserProfile(new User(null, array('userID' => null, 'username' => WCF::getLanguage()->get('wcf.user.guest')))),
+                       $this->notification->additionalData
+               );
+               
+               HeaderUtil::redirect($notificationEvent->getLink());
+               exit;
+       }
+}