summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/site/EditProjectModal.js
blob: 20baa54de68e5645acba6ace957a01fd75d72a4b (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
41
42
43
44
45
46
47
48
49
var EditProjectModal = ModalView.extend({
	el: ".mediaDrawer.editProject",
	action: "/project/edit",

	events: {
		"submit form": "submit"
	},

	initialize: function(){
		this.$form = this.$("form")
		this.$errors = this.$(".errors")
		this.$errorList = this.$(".errorList")
	},

	reset: function(){
		this.$("input").not("[type='submit']").not("[type='hidden']").val("")
	},
	
	load: function(){
		this.reset()
		this.show()
	},
	
	submit: function(e){
		e.preventDefault()

		this.$errors.hide();
		this.$errorList.empty()

		var fields = this.$form.serializeArray()
		
		var request = $.post(this.action, $.param(fields));
		request.done(function (response) {
			if (response.error) {
				this.$errors.show();
				for (var key in response.error.errors) {
					this.$errorList.append('<div>' + response.error.errors[key].message + '</div>');
				}
				return
			}
			else {
				window.location.href = "/profile"
			}
		}.bind(this));
	}

})