Anton Shestakov <av6@dwimlabs.net>, Mon, 21 Mar 2016 21:13:17 +0800
contacts: new ui element, contact list
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:jid', -> @set('d/handle', @get('fullname') or @get('nickname') or @get('jid')) @on 'add change:show change:presence', -> @set('d/pip', if @has('show') then @get('show') else @get('presence')) 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.ContactView extends Backbone.View template: $('#contact-template').html() colors: Tram.colors.presence @$el.attr('data-jid', @model.get('jid')) "background: #{ @colors[@model.get 'd/pip'] || @colors['default'] };" @rivet = rivets.bind(@el, model: @model, view: this) class Tram.ContactsApp extends Backbone.View @listenTo(@collection, 'add', @onAdd) @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)