diff options
Diffstat (limited to 'public/assets/javascripts')
| -rw-r--r-- | public/assets/javascripts/ui/AlertModal.js | 25 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/ConfirmModal.js | 25 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/DocumentModal.js | 13 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/Router.js | 19 | ||||
| -rw-r--r-- | public/assets/javascripts/vendor/ModalFormView.js | 6 |
5 files changed, 84 insertions, 4 deletions
diff --git a/public/assets/javascripts/ui/AlertModal.js b/public/assets/javascripts/ui/AlertModal.js new file mode 100644 index 0000000..c5693ad --- /dev/null +++ b/public/assets/javascripts/ui/AlertModal.js @@ -0,0 +1,25 @@ + + +var AlertModal = ModalFormView.extend({ + el: ".mediaDrawer.alert", + + events: { + "click .ok": "advance", + "click .close": "advance", + }, + + alert: function(message, callback){ + this.$(".message").html(message) + this.callback = callback + this.show() + }, + + advance: function(e){ + e && e.preventDefault() + this.hide() + this.callback && this.callback() + this.callback = null + } + +}) + diff --git a/public/assets/javascripts/ui/ConfirmModal.js b/public/assets/javascripts/ui/ConfirmModal.js new file mode 100644 index 0000000..868ce8e --- /dev/null +++ b/public/assets/javascripts/ui/ConfirmModal.js @@ -0,0 +1,25 @@ + + +var ConfirmModal = ModalFormView.extend({ + el: ".mediaDrawer.confirm", + + events: { + "click .yes": "advance", + "click .no": "hide", + }, + + confirm: function(question, callback){ + this.$(".question").html(question) + this.callback = callback + this.show() + }, + + advance: function(e){ + e && e.preventDefault() + this.hide() + this.callback && this.callback() + this.callback = null + } + +}) + diff --git a/public/assets/javascripts/ui/DocumentModal.js b/public/assets/javascripts/ui/DocumentModal.js index d9901bd..6f16169 100644 --- a/public/assets/javascripts/ui/DocumentModal.js +++ b/public/assets/javascripts/ui/DocumentModal.js @@ -3,6 +3,7 @@ var DocumentModal = ModalFormView.extend({ el: ".mediaDrawer.editDocument", createAction: "/api/docs/new", updateAction: "/api/docs/edit", + destroyAction: "/api/docs/destroy", load: function(name, isNew){ this.reset() @@ -32,9 +33,17 @@ var DocumentModal = ModalFormView.extend({ this.show() }, this)) }, - + success: function(res){ window.location.pathname = "/about/" + res.name - } + }, + + destroy: function(name, cb){ + $.ajax({ + type: "delete", + url: this.destroyAction, + data: { name: name, _csrf: $("[name=_csrf]").val() } + }).complete(cb || function(){}) + }, }) diff --git a/public/assets/javascripts/ui/Router.js b/public/assets/javascripts/ui/Router.js index a7aa566..85ed1aa 100644 --- a/public/assets/javascripts/ui/Router.js +++ b/public/assets/javascripts/ui/Router.js @@ -10,6 +10,7 @@ var Router = View.extend({ "click [data-role='edit-profile-modal']": 'editProfile', "click [data-role='new-document-modal']": 'newDocument', "click [data-role='edit-document-modal']": 'editDocument', + "click [data-role='delete-document-modal']": 'destroyDocument', }, routes: { @@ -30,6 +31,8 @@ var Router = View.extend({ this.editProjectModal = new EditProjectModal() this.editProfileModal = new EditProfileModal() this.documentModal = new DocumentModal() + this.confirmModal = new ConfirmModal() + this.alertModal = new AlertModal() this.originalPath = window.location.pathname @@ -115,5 +118,21 @@ var Router = View.extend({ this.documentModal.load(name, false) }, + destroyDocument: function(e, name){ + e && e.preventDefault() + + var name = e ? $(e.currentTarget).data("name") : name + + this.confirmModal.confirm("Are you sure you want to delete " + name + "?", $.proxy(function(){ + this.documentModal.destroy(name, $.proxy(function(){ + this.alertModal.alert("Document deleted!", $.proxy(function(){ + window.location.href = "/about" + }, this)) + }, this)) + }, this)) + + // this.documentModal.destroy(name) + }, + }) diff --git a/public/assets/javascripts/vendor/ModalFormView.js b/public/assets/javascripts/vendor/ModalFormView.js index f99317b..d084031 100644 --- a/public/assets/javascripts/vendor/ModalFormView.js +++ b/public/assets/javascripts/vendor/ModalFormView.js @@ -50,9 +50,11 @@ var ModalFormView = ModalView.extend({ } } else { - fd.append(this.name, $(this).val()); + fd.append(this.name, this.value); } }); + + return fd }, submit: function(e){ @@ -67,7 +69,7 @@ var ModalFormView = ModalView.extend({ return } } - + var request = $.ajax({ url: this.action, type: this.method, |
