var StaffView = View.extend({ el: ".page", events: { "click #toggle-staff": "toggleStaff", "click #toggle-featured": "toggleFeatured", }, initialize: function() { this.$toggleStaff = $("#toggle-staff") this.$toggleFeatured = $("#toggle-featured") this.$mediaEmbed = $("#media-embed") if (this.$toggleStaff.length && this.$toggleStaff.data().isstaff) { this.$toggleStaff.html("Is Staff") } if (this.$toggleFeatured.length && this.$toggleFeatured.data().featured) { this.$toggleFeatured.html("Featured Project") } if (this.$mediaEmbed.length) { var media = this.$mediaEmbed.data() this.$mediaEmbed.html( Parser.tag( media ) ) } }, load: function() { $(".json").each(function(){ $(this).JSONView( this.innerText ) }).show() this.projectList = new ProjectList () }, toggleStaff: function(){ var state = ! this.$toggleStaff.data().isstaff var verb = state ? "promote this user to staff?" : "remove this user from staff?" ConfirmModal.confirm("Are you sure you want to " + verb, function(){ $.ajax({ type: "put", dataType: "json", url: window.location.href + "/bless", data: { state: state, _csrf: $("#_csrf").val(), }, success: function(data){ this.$toggleStaff.data("isstaff", data.state) this.$toggleStaff.html(data.state ? "Is Staff" : "Make Staff") $("#is-staff").html(data.state ? "yes" : "no") }.bind(this) }) }.bind(this)) }, toggleFeatured: function(){ var state = ! this.$toggleFeatured.data().featured $.ajax({ type: "put", dataType: "json", url: window.location.href + "/feature", data: { state: state, _csrf: $("#_csrf").val(), }, success: function(data){ this.$toggleFeatured.data("featured", data.state) this.$toggleFeatured.html(data.state ? "Featured Project" : "Feature this project") $("#isFeaturedProject").html(data.state ? "yes" : "no") }.bind(this) }) }, })