summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/DocumentModal.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-06-09 16:14:49 -0400
committerJules Laplace <jules@okfoc.us>2014-06-09 16:14:49 -0400
commit1165ef5440e643252635aeea73a14cba0bb2e461 (patch)
tree6563f5314c774ee3ac9216e8375b38037b2eddcb /public/assets/javascripts/ui/DocumentModal.js
parentb1974b9c2fe6ee1f35b3e34895f134d906299cec (diff)
documentation system
Diffstat (limited to 'public/assets/javascripts/ui/DocumentModal.js')
-rw-r--r--public/assets/javascripts/ui/DocumentModal.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/public/assets/javascripts/ui/DocumentModal.js b/public/assets/javascripts/ui/DocumentModal.js
new file mode 100644
index 0000000..f821d07
--- /dev/null
+++ b/public/assets/javascripts/ui/DocumentModal.js
@@ -0,0 +1,41 @@
+
+
+var DocumentModal = ModalFormView.extend({
+ el: ".mediaDrawer.editDocument",
+ createAction: "/api/docs/new",
+ updateAction: "/api/docs/edit",
+
+ load: function(name, isNew){
+ this.reset()
+
+ if (isNew || name === "new") {
+ name = sanitize(name)
+ if (name !== "new") {
+ this.$("[name='new_name']").val( name.replace(/\s+/g,"-") )
+ this.$("[name='displayName']").val( capitalize(name.replace(/-/g," ")) )
+ }
+ this.action = this.createAction
+ return this.show()
+ }
+
+ this.action = this.updateAction
+
+ $.get("/api/docs", { name: name }, $.proxy(function(data){
+ if (data.isNew) {
+ this.action = this.createAction
+ }
+
+ for (var i in data) {
+ this.$("[name='" + i + "']").val(data[i])
+ }
+ this.$("[name='new_name']").val(name)
+
+ this.show()
+ }, this))
+ },
+
+ success: function(res){
+ window.location.pathname = "/about/" + res.name
+ }
+
+})