From 30560ad5b111b28426128cf7c5243f606f3134fc Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 9 Mar 2015 01:24:02 +0100 Subject: [PATCH] Moved to own controller for showing avatars. --- .../_application_controller.js.coffee | 30 ++++++++++--------- .../_dashboard/activity_stream.js.coffee | 22 +++++++++----- .../app/controllers/navigation.js.coffee | 6 ++++ .../app/controllers/widget/avatar.js.coffee | 20 +++++++++++++ .../javascripts/app/views/avatar.jst.eco | 1 + .../views/dashboard/activity_stream.jst.eco | 20 +------------ .../dashboard/activity_stream_item.jst.eco | 14 +++++++++ .../app/views/navigation/personal.jst.eco | 2 +- .../app/views/ticket_zoom/edit.jst.eco | 2 +- 9 files changed, 74 insertions(+), 43 deletions(-) create mode 100644 app/assets/javascripts/app/controllers/widget/avatar.js.coffee create mode 100644 app/assets/javascripts/app/views/avatar.jst.eco create mode 100644 app/assets/javascripts/app/views/dashboard/activity_stream_item.jst.eco diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 2ba35483d..03c859fb2 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -268,13 +268,14 @@ class App.Controller extends Spine.Controller userPopups: (position = 'right') -> # open user in new task if current user is agent - if @isRole('Agent') - @el.find('div.user-popover, span.user-popover').bind('click', (e) => - id = $(e.target).data('id') - if id - user = App.User.find(id) - @navigate user.uiUrl() - ); + return if !@isRole('Agent') + + @el.find('div.user-popover, span.user-popover').bind('click', (e) => + id = $(e.target).data('id') + if id + user = App.User.find(id) + @navigate user.uiUrl() + ); @userPopupsDestroy() @@ -325,13 +326,14 @@ class App.Controller extends Spine.Controller organizationPopups: (position = 'right') -> # open org in new task if current user agent - if @isRole('Agent') - @el.find('div.organization-popover, span.organization-popover').bind('click', (e) => - id = $(e.target).data('id') - if id - organization = App.Organization.find(id) - @navigate organization.uiUrl() - ); + return if !@isRole('Agent') + + @el.find('div.organization-popover, span.organization-popover').bind('click', (e) => + id = $(e.target).data('id') + if id + organization = App.Organization.find(id) + @navigate organization.uiUrl() + ); @organizationPopupsDestroy() diff --git a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee index 4a3c47903..3af74f5d0 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee @@ -40,16 +40,22 @@ class App.DashboardActivityStream extends App.Controller render: (items) -> items = @prepareForObjectList(items) - html = App.view('dashboard/activity_stream')( + @html App.view('dashboard/activity_stream')( head: 'Activity Stream', - items: items ) - html = $(html) - - @html html - - # start user popups - @userPopups('left') + for item in items + @el.append( @renderItem(item) ) # update time @frontendTimeUpdate() + + renderItem: (item) -> + html = $(App.view('dashboard/activity_stream_item')( + item: item, + )) + new App.WidgetAvatar( + el: html.find('.js-avatar') + user_id: item.created_by_id + size: 40 + ) + html \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index 90e33563d..b47360553 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -86,6 +86,12 @@ class App.Navigation extends App.Controller active_tab: active_tab ) + new App.WidgetAvatar( + el: @$('.js-avatar') + user_id: App.Session.get('id') + noPopups: true + ) + renderResult: (result = []) => el = @$('#global-search-result') diff --git a/app/assets/javascripts/app/controllers/widget/avatar.js.coffee b/app/assets/javascripts/app/controllers/widget/avatar.js.coffee new file mode 100644 index 000000000..ac13989d9 --- /dev/null +++ b/app/assets/javascripts/app/controllers/widget/avatar.js.coffee @@ -0,0 +1,20 @@ +class App.WidgetAvatar extends App.Controller + constructor: -> + super + + # subscribe and reload data / fetch new data if triggered + @subscribeId = App.User.full( @user_id, @render, false, true ) + + release: => + App.User.unsubscribe(@subscribeId) + + render: (user) => + @html App.view('avatar')( + user: user + size: @size + position: @position + ) + + # start user popups + if !@noPopups + @userPopups(@position) diff --git a/app/assets/javascripts/app/views/avatar.jst.eco b/app/assets/javascripts/app/views/avatar.jst.eco new file mode 100644 index 000000000..a8c83f7c0 --- /dev/null +++ b/app/assets/javascripts/app/views/avatar.jst.eco @@ -0,0 +1 @@ +<%- @user.avatar(@size, @position, @class) %> \ No newline at end of file diff --git a/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco b/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco index b9cc85b36..c2148475c 100644 --- a/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco +++ b/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco @@ -1,19 +1 @@ -

<%- @T( @head ) %>

-<% for item in @items: %> -
- - <%- item.created_by.avatar() %> - - - - - <%= item.created_by.displayName() %> <%- @T( item.type ) %> <%- @T( item.object_name ) %><% if item.title: %> (<%= item.title %>)<% end %> - - ? - - - - - -
-<% end %> +

<%- @T( @head ) %>

\ No newline at end of file diff --git a/app/assets/javascripts/app/views/dashboard/activity_stream_item.jst.eco b/app/assets/javascripts/app/views/dashboard/activity_stream_item.jst.eco new file mode 100644 index 000000000..c4577f53e --- /dev/null +++ b/app/assets/javascripts/app/views/dashboard/activity_stream_item.jst.eco @@ -0,0 +1,14 @@ +
+
+ + + + <%= @item.created_by.displayName() %> <%- @T( @item.type ) %> <%- @T( @item.object_name ) %><% if @item.title: %> (<%= @item.title %>)<% end %> + + ? + + + + + +
\ No newline at end of file diff --git a/app/assets/javascripts/app/views/navigation/personal.jst.eco b/app/assets/javascripts/app/views/navigation/personal.jst.eco index b472890ef..2855ca8a7 100644 --- a/app/assets/javascripts/app/views/navigation/personal.jst.eco +++ b/app/assets/javascripts/app/views/navigation/personal.jst.eco @@ -4,7 +4,7 @@ <% if item.class is 'user': %> - <%- item.avatar %> + <% else: %> diff --git a/app/assets/javascripts/app/views/ticket_zoom/edit.jst.eco b/app/assets/javascripts/app/views/ticket_zoom/edit.jst.eco index 30a6d0013..b3ebb2ad4 100644 --- a/app/assets/javascripts/app/views/ticket_zoom/edit.jst.eco +++ b/app/assets/javascripts/app/views/ticket_zoom/edit.jst.eco @@ -3,7 +3,7 @@
- <%- App.User.fullLocal( @S('id') ).avatar("40", 'right', 'zIndex-5') %> +