summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/editor/Collaborators.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/ui/editor/Collaborators.js')
-rw-r--r--public/assets/javascripts/ui/editor/Collaborators.js54
1 files changed, 42 insertions, 12 deletions
diff --git a/public/assets/javascripts/ui/editor/Collaborators.js b/public/assets/javascripts/ui/editor/Collaborators.js
index bb163f8..c27dbe0 100644
--- a/public/assets/javascripts/ui/editor/Collaborators.js
+++ b/public/assets/javascripts/ui/editor/Collaborators.js
@@ -4,14 +4,18 @@ var Collaborators = ModalFormView.extend({
template: $("#collaborator-template").html(),
- createAction: "/api/collaborator/:slug/create",
- destroyAction: "/api/collaborator/:slug/destroy",
+ indexAction: function(){ return "/api/collaborator/" + this.parent.data.slug + "/index" },
+ createAction: function(){ return "/api/collaborator/" + this.parent.data.slug + "/create" },
+ destroyAction: function(){ return "/api/collaborator/" + this.parent.data.slug + "/destroy" },
events: {
+ "keydown [name=email]": "enterSubmit",
"click [data-role=destroy-collaborator]": "destroy",
},
show: function(){
+ this.action = this.createAction
+
if (! this.loaded) {
this.load()
}
@@ -21,44 +25,70 @@ var Collaborators = ModalFormView.extend({
},
load: function(){
- $.get("/api/collaborator/:slug/index", this.populate.bind(this))
+ $.get(this.indexAction(), this.populate.bind(this))
},
populate: function(collaborators){
- //
collaborators.forEach(function(collab){
var $el = $( this.template )
- $el.data("collaborator-id", collab.id)
-
+ $el.data("collaborator-id", collab._id)
+
if (collab.user) {
$el.find(".email").remove()
$el.find(".user")
- .attr("href", "/profile/" + collab.username)
+ .attr("href", "/profile/" + collab.user.username)
$el.find(".avatar")
- .css("background-image", "url(" + collab.photo + ")")
+ .css("background-image", "url(" + collab.user.photo + ")")
$el.find(".username")
- .html( collab.displayName )
+ .html( collab.user.displayName )
+
+ if (collab.owner) {
+ $el.find("button").remove()
+ }
+ else {
+ $el.find(".role").remove()
+ }
}
else {
- $el.remove(".user")
+ $el.find(".user").remove()
+ $el.find(".role").remove()
$el.find(".email").html( collab.email )
}
- $("#collaborators").append($el)
+ $("#collaborator-list").append($el)
}.bind(this))
this.__super__.show.call(this)
},
+ enterSubmit: function (e) {
+ e.stopPropagation()
+ var base = this
+ if (e.keyCode == 13) {
+ setTimeout(function(){
+ base.save(e)
+ base.reset()
+ }, 100)
+ }
+ },
+
success: function(data){
+ this.reset()
this.populate([data])
},
destroy: function(e){
- var _id = $(e.currentTarget).closest("li").data("collaborator-id")
+ var $el = $(e.currentTarget).closest("li")
+ var _id = $el.data("collaborator-id")
+ $el.remove()
+ $.ajax({
+ type: "DELETE",
+ url: this.destroyAction(),
+ data: { _id: _id, _csrf: $("[name=_csrf]").val() },
+ })
},
})