From 807b9e58382bc4efc077e45f9bc4159514743583 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 27 Aug 2014 16:06:31 +0200 Subject: [PATCH] Improved handling of popovers. --- .../_application_controller.js.coffee | 52 ++++++++++++------- .../app/controllers/navigation.js.coffee | 11 ++-- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 215e4c301..536abf021 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -62,6 +62,10 @@ class App.Controller extends Spine.Controller if @ajaxCalls for callId in @ajaxCalls App.Ajax.abort(callId) + @userTicketPopupsDestroy() + @ticketPopupsDestroy() + @userPopupsDestroy() + @organizationPopupsDestroy() release: => # release custom bindings after it got removed from dom @@ -281,16 +285,15 @@ class App.Controller extends Spine.Controller ticketPopups: (position = 'right') -> - # remove old popovers - $('.popover').remove() + @ticketPopupsDestroy() # show ticket popup ui = @ - @el.find('.ticket-popover').popover( + @ticketPopupsList = @el.find('.ticket-popover').popover( trigger: 'hover' container: 'body' html: true - delay: { show: 500, hide: 1200 } + delay: { show: 400, hide: 400 } placement: position title: -> ticket_id = $(@).data('id') @@ -306,25 +309,27 @@ class App.Controller extends Spine.Controller ) ) - userPopups: (position = 'right') -> + ticketPopupsDestroy: => + if @ticketPopupsList + @ticketPopupsList.popover('destroy') - # remove old popovers - $('.popover').remove() + userPopups: (position = 'right') -> # open user in new task if user isn't customer if !@isRole('Customer') @el.find('.user-popover').bind('click', (e) => user_id = $(e.target).data('id') @navigate "#user/zoom/#{user_id}" - $('.popover').remove() ); + @userPopupsDestroy() + # show user popup - @el.find('.user-popover').popover( + @userPopupsList = @el.find('.user-popover').popover( trigger: 'hover' container: 'body' html: true - delay: { show: 500, hide: 1200 } + delay: { show: 400, hide: 400 } placement: position title: -> user_id = $(@).data('id') @@ -360,17 +365,21 @@ class App.Controller extends Spine.Controller ) ) + userPopupsDestroy: => + console.log('userPopupsDestroy', @userPopupsList) + if @userPopupsList + @userPopupsList.popover('destroy') + organizationPopups: (position = 'right') -> - # remove old popovers - $('.popover').remove() + @organizationPopupsDestroy() # show organization popup - @el.find('.organization-popover').popover( + @organizationPopupsList = @el.find('.organization-popover').popover( trigger: 'hover' container: 'body' html: true - delay: { show: 500, hide: 1200 } + delay: { show: 400, hide: 400 } placement: position title: -> organization_id = $(@).data('id') @@ -385,19 +394,22 @@ class App.Controller extends Spine.Controller ) ) - userTicketPopups: (params) -> + organizationPopupsDestroy: => + if @organizationPopupsList + @organizationPopupsList.popover('destroy') - # remove old popovers - $('.popover').remove() + userTicketPopups: (params) -> show = (data, tickets) => if !data.position data.position = 'left' + @userTicketPopupsDestroy() + # show user popup controller = @ - @el.find(data.selector).popover( + @userTicketPopupsList = @el.find(data.selector).popover( trigger: 'hover' container: 'body' html: true @@ -446,6 +458,10 @@ class App.Controller extends Spine.Controller else fetch(params) + userTicketPopupsDestroy: => + if @userTicketPopupsList + @userTicketPopupsList.popover('destroy') + recentView: (object, o_id) => params = object: object diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index 5d67be250..2b2d312b1 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -89,13 +89,15 @@ class App.Navigation extends App.Controller renderResult: (result = []) => el = @el.find('#global-search-result') + # destroy existing popovers + @ticketPopupsDestroy() + @userPopupsDestroy() + @organizationPopupsDestroy() + # remove result if not result exists if _.isEmpty( result ) @el.find('#global-search').parents('li').removeClass('open') el.html( '' ) - - # remove old popovers - $('.popover').remove() return # show result list @@ -118,9 +120,6 @@ class App.Navigation extends App.Controller render: () -> - # remove old popovers - $('.popover').remove() - # remember old search query search = @el.find('#global-search').val()