Просмотр исходного кода

Improved re-execute of controller if already active on click.

Martin Edenhofer 9 лет назад
Родитель
Сommit
3b47de0014

+ 16 - 12
app/assets/javascripts/app/controllers/_application_controller.coffee

@@ -550,21 +550,25 @@ class App.Controller extends Spine.Controller
       'meta-task-update'
     )
 
-  locationVerify: (e, callback) =>
+  locationVerify: (e) =>
     newLocation = $(e.currentTarget).attr 'href'
-    @log 'debug', "new location #{newLocation}"
+    @log 'debug', "new location '#{newLocation}'"
     return if !newLocation
+    @locationExecuteOrNavigate(newLocation)
+
+  locationExecuteOrNavigate: (newLocation) =>
     currentLocation = Spine.Route.getPath()
-    @log 'debug', "current location #{currentLocation}"
-    return if newLocation.replace(/#/, '') isnt currentLocation
-    @locationExecute(newLocation, callback)
-
-  locationExecute: (location, callback) =>
-    if callback
-      callback()
-    location = location.replace(/#/, '')
-    @log 'debug', "execute controller again for '#{location}' because of same hash"
-    Spine.Route.matchRoutes(location)
+    @log 'debug', "current location '#{currentLocation}'"
+    if newLocation.replace(/#/, '') isnt currentLocation
+      @log 'debug', "navigate to location '#{newLocation}'"
+      @navigate(newLocation)
+      return
+    @locationExecute(newLocation)
+
+  locationExecute: (newLocation) =>
+    newLocation = newLocation.replace(/#/, '')
+    @log 'debug', "execute controller again for '#{newLocation}' because of same hash"
+    Spine.Route.matchRoutes(newLocation)
 
   logoUrl: ->
     "#{@Config.get('image_path')}/#{@Config.get('product_logo')}"

+ 3 - 1
app/assets/javascripts/app/controllers/widget/notify.coffee

@@ -29,14 +29,16 @@ class App.Notify extends App.ControllerWidgetPermanent
       counter = @desktopNotifyCounter
       notification = new window.Notification(data.title, data)
       @desktopNotify[counter] = notification
+      @log 'debug', 'notifyDesktop', data, counter
 
       notification.onclose = (e) =>
         delete @desktopNotify[counter]
 
       notification.onclick = (e) =>
         window.focus()
+        @log 'debug', 'notifyDesktop.click', data
         if data.url
-          @locationExecute(data.url)
+          @locationExecuteOrNavigate(data.url)
         if data.callback
           data.callback()
 

+ 2 - 1
app/assets/javascripts/app/controllers/widget/online_notification.coffee

@@ -150,7 +150,8 @@ class App.OnlineNotificationWidget extends App.Controller
 
     # execute controller again of already open (because hash hasn't changed, we need to do it manually)
     notificationsContainer.find('.js-locationVerify').on('click', (e) =>
-      @locationVerify(e, @hidePopover)
+      @locationVerify(e)
+      @hidePopover()
     )
 
     # close notification list on click