Anton Shestakov <av6@dwimlabs.net>, Sun, 03 Apr 2016 12:27:31 +0800
tram: new pip colors
coffee/contacts.coffee
Permissions: -rw-r--r--
class Tram.Contact extends Backbone.Model @on 'add change:avatar', -> if avatar?.mime and avatar?.data @set('d/avatar', "data:#{ avatar.mime };base64,#{ avatar.data }") @on 'add change:fullname change:nickname change:bjid', -> @set('d/handle', @get('fullname') or @get('nickname') or @get('bjid')) @on 'add change:type change:presence change:callstate', -> if @get('type') is 'self' then return @unset('d/actions') if @get('presence') is 'subscribe' then return @set('d/actions', ['authorize', 'unauthorize']) if @get('presence') isnt 'unavailable' actions.push('wait', 'hang-up') actions.push('accept', 'decline') @set('d/actions', actions) class Tram.Contacts extends Backbone.Collection if model.get('presence') is 'unavailable' else if model.get('type') is 'self' @on('change:presence change:type', @sort) class Tram.AvatarView extends Backbone.View template: $('#avatar-template').html() colors: Tram.colors.avatar ci = hash % @colors.length "color: white; background: #{ @colors[ci] };" @rivet = rivets.bind(@el, model: @model, view: this) class Tram.ContactView extends Backbone.View template: $('#contact-template').html() 'click [data-authorize]': -> @model.trigger('authorize') 'click [data-unauthorize]': -> @model.trigger('unauthorize') 'click [data-call]': (event) -> @model.trigger('call', event.currentTarget.getAttribute('data-call')) 'click [data-accept]': (event) -> @model.trigger('accept', event.currentTarget.getAttribute('data-accept')) 'click [data-decline]': -> @model.trigger('decline') 'click [data-hang-up]': -> @model.trigger('hangup') 'click [data-remove]': -> @model.trigger('remove') @$el.attr('data-jid', @model.get('jid')) @$avatarColumn = @$('.avatar-column') "background: #{ @colors[show] || @colors['default'] };" @rivet = rivets.bind(@el, model: @model, view: this) av = new Tram.AvatarView(model: @model) @$avatarColumn.prepend(av.render().el) class Tram.ContactsApp extends Backbone.View @listenTo(@collection, 'add', @onAdd) @listenTo(@collection, 'remove', @onRemove) @listenTo(@collection, 'sort', @onSort) onAdd: (model, collection) -> mi = collection.indexOf(model) model.view = new Tram.ContactView(model: model) el = model.view.render().el @$el.children().eq(mi - 1).after(el) onSort: (collection, options) -> collection.each (model) => @$el.append(model.view.el)