diff --git a/app/assets/javascripts/app/controllers/widget/avatar.coffee b/app/assets/javascripts/app/controllers/widget/avatar.coffee index 331ba8bc7..73991604f 100644 --- a/app/assets/javascripts/app/controllers/widget/avatar.coffee +++ b/app/assets/javascripts/app/controllers/widget/avatar.coffee @@ -9,12 +9,7 @@ class App.WidgetAvatar extends App.Controller App.User.unsubscribe(@subscribeId) render: (user) => - @html App.view('avatar')( - user: user - size: @size - position: @position - type: @type - ) + @html user.avatar @size, @position, undefined, false, false, @type # start user popups @userPopups(@position) diff --git a/app/assets/javascripts/app/models/user.coffee b/app/assets/javascripts/app/models/user.coffee index 61d90a8e1..6edb71b68 100644 --- a/app/assets/javascripts/app/models/user.coffee +++ b/app/assets/javascripts/app/models/user.coffee @@ -46,55 +46,57 @@ class App.User extends App.Model return '??' avatar: (size = 40, placement = '', cssClass = '', unique = false, avatar, type = undefined) -> - cssClass += " size-#{size}" + size = parseInt(size, 10) + + cssClass += " " if cssClass + cssClass += "size-#{ size }" if placement - placement = "data-placement=\"#{placement}\"" + placement = " data-placement='#{ placement }'" - # use system avatar for system actions - if @id is 1 - return "#{App.Utils.icon('logo')}" + if !avatar + if type is 'personal' + vip = false + data = " data-id=\"#{@id}\"" + else + cssClass += ' user-popover' + data = " data-id=\"#{@id}\"" + else + vip = false + data = " data-avatar-id=\"#{avatar.id}\"" - # use generated avatar - if !@image || @image is 'none' || unique - return @uniqueAvatar(size, placement, cssClass, avatar, type) - - # use image as avatar - image = @imageUrl() vip = @vip if type is 'personal' vip = false else cssClass += ' user-popover' - if vip - return "" - "" + # use system avatar for system actions + if @id is 1 + return App.view('avatar_system')() + else if !@image || @image is 'none' || unique + width = 300 + height = 226 - uniqueAvatar: (size, placement = '', cssClass = '', avatar, type) -> - width = 300 - height = 226 - size = parseInt(size, 10) - vip = @vip + rng = new Math.seedrandom(@id) + x = rng() * (width - size) + y = rng() * (height - size) - rng = new Math.seedrandom(@id) - x = rng() * (width - size) - y = rng() * (height - size) - - if !avatar - if type is 'personal' - vip = false - data = "data-id=\"#{@id}\"" - else - cssClass += ' user-popover' - data = "data-id=\"#{@id}\"" + return App.view('avatar_unique') + data: data + cssClass: cssClass + placement: placement + vip: vip + x: x + y: y + initials: @initials() else - vip = false - data = "data-avatar-id=\"#{avatar.id}\"" - - if vip - return "#{ @initials() }" - "#{ @initials() }" + return App.view('avatar') + data: data + cssClass: cssClass + placement: placement + vip: vip + url: @imageUrl() imageUrl: -> return if !@image diff --git a/app/assets/javascripts/app/views/avatar.jst.eco b/app/assets/javascripts/app/views/avatar.jst.eco index 3beb48952..423634fb4 100644 --- a/app/assets/javascripts/app/views/avatar.jst.eco +++ b/app/assets/javascripts/app/views/avatar.jst.eco @@ -1 +1,3 @@ -<%- @user.avatar(@size, @position, @class, false, false, @type) %> \ No newline at end of file +<%- @data %>> + <%- @Icon('crown') if @vip %> + \ No newline at end of file diff --git a/app/assets/javascripts/app/views/avatar_system.jst.eco b/app/assets/javascripts/app/views/avatar_system.jst.eco new file mode 100644 index 000000000..726316e5b --- /dev/null +++ b/app/assets/javascripts/app/views/avatar_system.jst.eco @@ -0,0 +1,3 @@ + + <%- @Icon('logo') %> + \ No newline at end of file diff --git a/app/assets/javascripts/app/views/avatar_unique.jst.eco b/app/assets/javascripts/app/views/avatar_unique.jst.eco new file mode 100644 index 000000000..c384ef7f9 --- /dev/null +++ b/app/assets/javascripts/app/views/avatar_unique.jst.eco @@ -0,0 +1,4 @@ +<%- @data %>> + <%- @Icon('crown') if @vip %> + <%= @initials %> + \ No newline at end of file