refactor avatars

This commit is contained in:
Felix Niklas 2015-10-19 16:05:33 +02:00
parent fb8666b0e4
commit 2e51c25b1a
5 changed files with 49 additions and 43 deletions

View file

@ -9,12 +9,7 @@ class App.WidgetAvatar extends App.Controller
App.User.unsubscribe(@subscribeId) App.User.unsubscribe(@subscribeId)
render: (user) => render: (user) =>
@html App.view('avatar')( @html user.avatar @size, @position, undefined, false, false, @type
user: user
size: @size
position: @position
type: @type
)
# start user popups # start user popups
@userPopups(@position) @userPopups(@position)

View file

@ -46,55 +46,57 @@ class App.User extends App.Model
return '??' return '??'
avatar: (size = 40, placement = '', cssClass = '', unique = false, avatar, type = undefined) -> 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 if placement
placement = "data-placement=\"#{placement}\"" placement = " data-placement='#{ placement }'"
# use system avatar for system actions if !avatar
if @id is 1 if type is 'personal'
return "<span class='avatar' style='background: white'>#{App.Utils.icon('logo')}</span>" 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 vip = @vip
if type is 'personal' if type is 'personal'
vip = false vip = false
else else
cssClass += ' user-popover' cssClass += ' user-popover'
if vip # use system avatar for system actions
return "<span class=\"avatar #{cssClass}\" data-id=\"#{@id}\" style=\"background-image: url(#{image})\" #{placement}><svg class='icon icon-crown'><use xlink:href='#icon-crown'></svg></span>" if @id is 1
"<span class=\"avatar #{cssClass}\" data-id=\"#{@id}\" style=\"background-image: url(#{image})\" #{placement}></span>" return App.view('avatar_system')()
else if !@image || @image is 'none' || unique
width = 300
height = 226
uniqueAvatar: (size, placement = '', cssClass = '', avatar, type) -> rng = new Math.seedrandom(@id)
width = 300 x = rng() * (width - size)
height = 226 y = rng() * (height - size)
size = parseInt(size, 10)
vip = @vip
rng = new Math.seedrandom(@id) return App.view('avatar_unique')
x = rng() * (width - size) data: data
y = rng() * (height - size) cssClass: cssClass
placement: placement
if !avatar vip: vip
if type is 'personal' x: x
vip = false y: y
data = "data-id=\"#{@id}\"" initials: @initials()
else
cssClass += ' user-popover'
data = "data-id=\"#{@id}\""
else else
vip = false return App.view('avatar')
data = "data-avatar-id=\"#{avatar.id}\"" data: data
cssClass: cssClass
if vip placement: placement
return "<span class=\"avatar unique #{cssClass}\" #{data} style=\"background-position: -#{ x }px -#{ y }px;\" #{placement}><svg class='icon icon-crown'><use xlink:href='#icon-crown'></svg>#{ @initials() }</span>" vip: vip
"<span class=\"avatar unique #{cssClass}\" #{data} style=\"background-position: -#{ x }px -#{ y }px;\" #{placement}>#{ @initials() }</span>" url: @imageUrl()
imageUrl: -> imageUrl: ->
return if !@image return if !@image

View file

@ -1 +1,3 @@
<%- @user.avatar(@size, @position, @class, false, false, @type) %> <span class="avatar <%- @cssClass %>" style="background-image: url(<%- @url %>)"<%- @placement %><%- @data %>>
<%- @Icon('crown') if @vip %>
</span>

View file

@ -0,0 +1,3 @@
<span class="avatar <%- @cssClass %>" style="background: white">
<%- @Icon('logo') %>
</span>

View file

@ -0,0 +1,4 @@
<span class="avatar <%- @cssClass %> unique" style="background-position: -<%- @x %>px -<%- @y %>px;"<%- @placement %><%- @data %>>
<%- @Icon('crown') if @vip %>
<%= @initials %>
</span>