summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/DocumentModal.js
blob: d9901bd4977b33371307a19e32d6d285dc3fcfb9 (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
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
	}

})