summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/editor/Collaborators.js
blob: bb163f85748ae7c3a79e935915e04c9b635826d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var Collaborators = ModalFormView.extend({
	el: ".mediaDrawer.collaborators",
	
	template: $("#collaborator-template").html(),

	createAction: "/api/collaborator/:slug/create",
	destroyAction: "/api/collaborator/:slug/destroy",
	
	events: {
	  "click [data-role=destroy-collaborator]": "destroy",
	},
	
	show: function(){
		if (! this.loaded) {
			this.load()
		}
		else {
			this.__super__.show.call(this)
		}
	},
	
	load: function(){
		$.get("/api/collaborator/:slug/index", this.populate.bind(this))
	},

  populate: function(collaborators){
    //
    collaborators.forEach(function(collab){
      var $el = $( this.template )
      $el.data("collaborator-id", collab.id)
      
      if (collab.user) {
        $el.find(".email").remove()
        
        $el.find(".user")
           .attr("href", "/profile/" + collab.username)
        
        $el.find(".avatar")
           .css("background-image", "url(" + collab.photo + ")")
        
        $el.find(".username")
           .html( collab.displayName )
      }
      else {
        $el.remove(".user")
        $el.find(".email").html( collab.email )
      }
      
      $("#collaborators").append($el)
    }.bind(this))
    
    this.__super__.show.call(this)
  },
  
  success: function(data){
    this.populate([data])
  },
  
  destroy: function(e){
    var _id = $(e.currentTarget).closest("li").data("collaborator-id")
  },

})