Added ability to purge popover content
authorAlexander Ebert <ebert@woltlab.com>
Mon, 9 Jun 2014 11:54:30 +0000 (13:54 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 9 Jun 2014 11:54:30 +0000 (13:54 +0200)
wcfsetup/install/files/js/WCF.User.js
wcfsetup/install/files/js/WCF.js

index b7ff6393d07071846c891531a4176538456cd10f..82fe2297641dbebfa4cbaafeb94edff7dd506f11 100644 (file)
@@ -1803,6 +1803,9 @@ WCF.User.ProfilePreview = WCF.Popover.extend({
                this._proxy = new WCF.Action.Proxy({
                        showLoadingOverlay: false
                });
+               
+               // register instance
+               WCF.System.ObjectStore.add('WCF.User.ProfilePreview', this);
        },
        
        /**
@@ -1843,6 +1846,18 @@ WCF.User.ProfilePreview = WCF.Popover.extend({
                        });
                        this._proxy.sendRequest();
                }
+       },
+       
+       /**
+        * Purages a cached user profile.
+        * 
+        * @param       integer         userID
+        */
+       purge: function(userID) {
+               delete this._userProfiles[userID];
+               
+               // purge content cache
+               this._data = { };
        }
 });
 
@@ -1954,6 +1969,12 @@ WCF.User.Action.Follow = Class.extend({
                
                var $notification = new WCF.System.Notification();
                $notification.show();
+               
+               // force rebuilding of popover cache
+               var self = this;
+               WCF.System.ObjectStore.invoke('WCF.User.ProfilePreview', function(profilePreview) {
+                       profilePreview.purge(self._userID);
+               });
        }
 });
 
@@ -2060,6 +2081,12 @@ WCF.User.Action.Ignore = Class.extend({
                
                var $notification = new WCF.System.Notification();
                $notification.show();
+               
+               // force rebuilding of popover cache
+               var self = this;
+               WCF.System.ObjectStore.invoke('WCF.User.ProfilePreview', function(profilePreview) {
+                       profilePreview.purge(self._userID);
+               });
        }
 });
 
index 02c4cfebc5993f5730c6c1cb32fe7e4cb6d3f7a0..c0122c4b73343ecad083db432f545f4e4ecf8384 100755 (executable)
@@ -6740,6 +6740,45 @@ WCF.System.Mobile.UX = {
        }
 };
 
+/**
+ * Stores object references for global access.
+ */
+WCF.System.ObjectStore = {
+       /**
+        * list of objects grouped by identifier
+        * @var object<array>
+        */
+       _objects: { },
+       
+       /**
+        * Adds a new object to the collection.
+        * 
+        * @param       string          identifier
+        * @param       object          object
+        */
+       add: function(identifier, obj) {
+               if (this._objects[identifier] === undefined) {
+                       this._objects[identifier] = [ ];
+               }
+               
+               this._objects[identifier].push(obj);
+       },
+       
+       /**
+        * Invokes a callback passing the matching objects as a parameter.
+        * 
+        * @param       string          identifier
+        * @param       object          callback
+        */
+       invoke: function(identifier, callback) {
+               if (this._objects[identifier]) {
+                       for (var $i = 0; $i < this._objects[identifier].length; $i++) {
+                               callback(this._objects[identifier][$i]);
+                       }
+               }
+       }
+};
+
 WCF.System.Page = { };
 
 WCF.System.Page.Multiple = Class.extend({