Browse Source

Popovers refactoring

Mantas 6 years ago
parent
commit
9d5b83169d

+ 0 - 226
app/assets/javascripts/app/controllers/_application_controller.coffee

@@ -77,10 +77,6 @@ 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
@@ -295,228 +291,6 @@ class App.Controller extends Spine.Controller
     item.attr('title', App.i18n.translateTimestamp(timestamp))
     item.html(time)
 
-  ticketPopups: (position = 'right') ->
-
-    # open ticket in new task if curent user agent
-    if @permissionCheck('ticket.agent')
-      @$('div.ticket-popover, span.ticket-popover').bind('click', (e) =>
-        id = $(e.target).data('id')
-        return if !id
-        ticket = App.Ticket.findNative(id)
-        @navigate ticket.uiUrl()
-      )
-
-    @ticketPopupsDestroy()
-
-    # show ticket popup
-    ui = @
-    @ticketPopupsList = @el.find('.ticket-popover').popover(
-      trigger:    'hover'
-      container:  'body'
-      html:       true
-      animation:  false
-      delay:      100
-      placement:  position
-      title: ->
-        ticketId = $(@).data('id')
-        ticket   = App.Ticket.find(ticketId)
-        App.Utils.htmlEscape(ticket.title)
-      content: ->
-        ticketId = $(@).data('id')
-        ticket   = App.Ticket.fullLocal(ticketId)
-        html = $(App.view('popover/ticket')(
-          ticket: ticket
-        ))
-        html.find('.humanTimeFromNow').each(->
-          ui.frontendTimeUpdateItem($(@))
-        )
-        html
-    )
-
-  ticketPopupsDestroy: =>
-    if @ticketPopupsList
-      @ticketPopupsList.popover('destroy')
-
-  userPopups: (position = 'right') ->
-
-    # open user in new task if current user is agent
-    return if !@permissionCheck('ticket.agent')
-    @$('div.user-popover, span.user-popover').bind('click', (e) =>
-      id = $(e.target).data('id')
-      return if !id
-      user = App.User.findNative(id)
-      @navigate user.uiUrl()
-    )
-
-    @userPopupsDestroy()
-
-    # show user popup
-    @userPopupsList = @el.find('.user-popover').popover(
-      trigger:    'hover'
-      container:  'body'
-      html:       true
-      animation:  false
-      delay:      100
-      placement:  "auto #{position}"
-      title: ->
-        userId = $(@).data('id')
-        user   = App.User.find(userId)
-        headline = App.Utils.htmlEscape(user.displayName())
-        if user.isOutOfOffice()
-          headline += " (#{App.Utils.htmlEscape(user.outOfOfficeText())})"
-        headline
-      content: ->
-        userId = $(@).data('id')
-        user   = App.User.fullLocal(userId)
-
-        # get display data
-        userData = []
-        for attributeName, attributeConfig of App.User.attributesGet('view')
-
-          # check if value for _id exists
-          name    = attributeName
-          nameNew = name.substr(0, name.length - 3)
-          if nameNew of user
-            name = nameNew
-
-          # add to show if value exists
-          if user[name] && attributeConfig.shown
-
-            # do not show firstname and lastname / already show via diplayName()
-            if name isnt 'firstname' && name isnt 'lastname' && name isnt 'organization'
-              userData.push attributeConfig
-
-        # insert data
-        App.view('popover/user')(
-          user:     user
-          userData: userData
-        )
-    )
-
-  userPopupsDestroy: =>
-    if @userPopupsList
-      @userPopupsList.popover('destroy')
-
-  organizationPopups: (position = 'right') ->
-
-    # open org in new task if current user agent
-    return if !@permissionCheck('ticket.agent')
-
-    @$('div.organization-popover, span.organization-popover').bind('click', (e) =>
-      id = $(e.target).data('id')
-      return if !id
-      organization = App.Organization.find(id)
-      @navigate organization.uiUrl()
-    )
-
-    @organizationPopupsDestroy()
-
-    # show organization popup
-    @organizationPopupsList = @el.find('.organization-popover').popover(
-      trigger:    'hover'
-      container:  'body'
-      html:       true
-      animation:  false
-      delay:      100
-      placement:  "auto #{position}"
-      title: ->
-        organization_id = $(@).data('id')
-        organization    = App.Organization.find(organization_id)
-        App.Utils.htmlEscape(organization.name)
-      content: ->
-        organization_id = $(@).data('id')
-        organization    = App.Organization.fullLocal(organization_id)
-
-        # get display data
-        organizationData = []
-        for attributeName, attributeConfig of App.Organization.attributesGet('view')
-
-          # check if value for _id exists
-          name    = attributeName
-          nameNew = name.substr(0, name.length - 3)
-          if nameNew of organization
-            name = nameNew
-
-          # add to show if value exists
-          if organization[name] && attributeConfig.shown
-
-            # do not show firstname and lastname / already show via diplayName()
-            if name isnt 'name'
-              organizationData.push attributeConfig
-
-        # insert data
-        App.view('popover/organization')(
-          organization:     organization,
-          organizationData: organizationData,
-        )
-    )
-
-  organizationPopupsDestroy: =>
-    if @organizationPopupsList
-      @organizationPopupsList.popover('destroy')
-
-  userTicketPopups: (params) ->
-
-    show = (data, ticket_list) =>
-
-      if !data.position
-        data.position = 'left'
-
-      @userTicketPopupsDestroy()
-
-      # show user popup
-      ui = @
-      @userTicketPopupsList = @el.find(data.selector).popover(
-        trigger:    'hover'
-        container:  'body'
-        html:       true
-        animation:  false
-        delay:      100
-        placement:  "auto #{data.position}"
-        title: ->
-          $(@).find('[title="*"]').val()
-
-        content: ->
-          type = $(@).filter('[data-type]').data('type')
-          tickets = []
-          if ticket_list[type]
-            for ticketId in ticket_list[type]
-              tickets.push App.Ticket.fullLocal(ticketId)
-
-          # insert data
-          html = $(App.view('popover/user_ticket_list')(
-            tickets: tickets
-          ))
-          html.find('.humanTimeFromNow').each( ->
-            ui.frontendTimeUpdateItem($(@))
-          )
-          html
-      )
-
-    fetch = (params) =>
-      @ajax(
-        type:  'GET'
-        url:   "#{@Config.get('api_path')}/ticket_customer"
-        data:
-          customer_id: params.user_id
-        processData: true
-        success: (data, status, xhr) ->
-          App.Collection.loadAssets(data.assets)
-          show(params, { open: data.ticket_ids_open, closed: data.ticket_ids_closed })
-      )
-
-    # get data
-    fetch(params)
-
-  userTicketPopupsDestroy: =>
-    if @userTicketPopupsList
-      @userTicketPopupsList.popover('destroy')
-
-  anyPopoversDestroy: ->
-
-    # do not remove permanent .popover--notifications widget
-    $('.popover:not(.popover--notifications)').remove()
-
   recentView: (object, o_id) =>
     params =
       object: object

+ 5 - 2
app/assets/javascripts/app/controllers/_application_controller_generic.coffee

@@ -545,6 +545,9 @@ class App.ControllerNavSidbar extends App.Controller
       sidebar: @$('.sidebar').scrollTop()
 
 class App.GenericHistory extends App.ControllerModal
+  @extend App.PopoverProvidable
+  @registerPopovers 'User'
+
   buttonClose: true
   buttonCancel: false
   buttonSubmit: false
@@ -568,7 +571,7 @@ class App.GenericHistory extends App.ControllerModal
     content
 
   onShown: =>
-    @userPopups()
+    @renderPopovers()
 
   sortorder: =>
     @items = @items.reverse()
@@ -1403,4 +1406,4 @@ class App.ImportResult extends App.ControllerModal
     content
 
   onSubmit: (e) =>
-    @close()
+    @close()

+ 6 - 2
app/assets/javascripts/app/controllers/cti.coffee

@@ -1,4 +1,7 @@
 class App.CTI extends App.Controller
+  @extend App.PopoverProvidable
+  @registerPopovers 'User'
+
   elements:
     '.js-callerLog': 'callerLog'
   events:
@@ -160,9 +163,10 @@ class App.CTI extends App.Controller
       if diff_in_min > 1
         item.disabled = false
 
-    @userPopupsDestroy()
+    @removePopovers()
     @callerLog.html( App.view('cti/caller_log')(list: @list))
-    @userPopups()
+    @renderPopovers()
+
     @updateNavMenu()
 
   done: (e) =>

+ 9 - 12
app/assets/javascripts/app/controllers/navigation.coffee

@@ -1,4 +1,7 @@
 class App.Navigation extends App.ControllerWidgetPermanent
+  @extend App.PopoverProvidable
+  @registerAllPopovers()
+
   className: 'navigation vertical'
 
   elements:
@@ -157,6 +160,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
       )
 
   renderResult: (result = []) =>
+    @removePopovers()
 
     # remove result if not result exists
     if _.isEmpty(result)
@@ -174,14 +178,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
     # show result list
     @searchContainer.addClass('open')
 
-    # start ticket popups
-    @ticketPopups()
-
-    # start user popups
-    @userPopups()
-
-    # start oorganization popups
-    @organizationPopups()
+    @renderPopovers()
 
   render: ->
 
@@ -206,7 +203,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
   searchFocus: (e) =>
     @query = '' # reset query cache
     @searchContainer.addClass('focused')
-    @anyPopoversDestroy()
+    App.PopoverProvidable.anyPopoversDestroy()
     @search()
 
   searchBlur: (e) =>
@@ -288,14 +285,14 @@ class App.Navigation extends App.ControllerWidgetPermanent
     @searchContainer.removeClass('filled').removeClass('open').removeClass('focused')
     @globalSearch.close()
 
-    # remove not needed popovers
-    @delay(@anyPopoversDestroy, 100, 'removePopovers')
+    @delayedRemoveAnyPopover()
 
   andClose: =>
     @searchInput.blur()
     @searchContainer.removeClass('open')
     @globalSearch.close()
-    @delay(@anyPopoversDestroy, 100, 'removePopovers')
+
+    @delayedRemoveAnyPopover()
 
   search: =>
     query = @searchInput.val().trim()

+ 3 - 2
app/assets/javascripts/app/controllers/search.coffee

@@ -1,4 +1,6 @@
 class App.Search extends App.Controller
+  @extend App.PopoverProvidable
+
   elements:
     '.js-search': 'searchInput'
 
@@ -112,8 +114,7 @@ class App.Search extends App.Controller
     @updateFilledClass()
     @updateTask()
 
-    # remove not needed popovers
-    @delay(@anyPopoversDestroy, 100, 'removePopovers')
+    @delayedRemoveAnyPopover()
 
   search: (force = false) =>
     query = @searchInput.val().trim()

+ 4 - 5
app/assets/javascripts/app/controllers/ticket_overview.coffee

@@ -926,6 +926,9 @@ class Navbar extends App.Controller
       @autoFoldTabs()
 
 class Table extends App.Controller
+  @extend App.PopoverProvidable
+  @registerPopovers 'Organization', 'User'
+
   events:
     'click [data-type=settings]': 'settings'
     'click [data-type=viewmode]': 'viewmode'
@@ -1174,11 +1177,7 @@ class Table extends App.Controller
             'click': callbackCheckbox
       )
 
-    # start user popups
-    @userPopups()
-
-    # start organization popups
-    @organizationPopups()
+    @renderPopovers()
 
     @bulkForm = new BulkForm(
       holder: @el

+ 4 - 1
app/assets/javascripts/app/controllers/widget/avatar.coffee

@@ -1,4 +1,7 @@
 class App.WidgetAvatar extends App.ObserverController
+  @extend App.PopoverProvidable
+  @registerPopovers 'User'
+
   model: 'User'
   observe:
     login: true
@@ -17,4 +20,4 @@ class App.WidgetAvatar extends App.ObserverController
 
   render: (user) =>
     @html(user.avatar(@size, @position, @cssClass, false, false, @type))
-    @userPopups(@position)
+    @renderPopovers()

+ 8 - 1
app/assets/javascripts/app/controllers/widget/link.coffee

@@ -1,4 +1,10 @@
 class App.WidgetLink extends App.Controller
+  @extend App.PopoverProvidable
+  @registerPopovers 'Ticket'
+
+  @popoversDefaults:
+    position: 'left'
+
   events:
     'click .js-add': 'add'
     'click .js-delete': 'delete'
@@ -54,7 +60,8 @@ class App.WidgetLink extends App.Controller
     @html App.view('link/info')(
       links: list
     )
-    @ticketPopups('left')
+
+    @renderPopovers()
 
   delete: (e) =>
     e.preventDefault()

+ 4 - 10
app/assets/javascripts/app/controllers/widget/organization.coffee

@@ -1,4 +1,7 @@
 class App.WidgetOrganization extends App.Controller
+  @extend App.PopoverProvidable
+  @registerPopovers 'User'
+
   events:
     'focusout [contenteditable]': 'update'
 
@@ -44,16 +47,7 @@ class App.WidgetOrganization extends App.Controller
       maxlength: 250
     )
 
-    # enable user popups
-    @userPopups()
-
-    ###
-    @userTicketPopups(
-      selector: '.user-tickets'
-      user_id:  user.id
-      position: 'right'
-    )
-    ###
+    @renderPopovers()
 
   update: (e) =>
     name  = $(e.target).attr('data-name')

+ 4 - 5
app/assets/javascripts/app/controllers/widget/ticket_list.coffee

@@ -1,4 +1,7 @@
 class App.TicketList extends App.Controller
+  @extend App.PopoverProvidable
+  @registerPopovers 'Organization', 'User'
+
   constructor: ->
     super
 
@@ -85,8 +88,4 @@ class App.TicketList extends App.Controller
       radio: @radio
     )
 
-    # start user popups
-    @userPopups()
-
-    # start organization popups
-    @organizationPopups()
+    @renderPopovers()

Some files were not shown because too many files changed in this diff