summaryrefslogtreecommitdiffstats
path: root/web/js/labitrack.d/46-edit.js
blob: c7039b0c4b8129bca0a273d889b95217d4884107 (plain) (blame)
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
(function(){
	function on_submit(label, o)
	{
		o.save(undef, {success: function() {
			label.set_data(o.toJSON());
			Backbone.history.navigate('/view/'+o.id, true);
		}});
	}

	function success(o)
	{
		var data = o.toJSON();
		λ.setcontent('edit', {
			id: o.id,
			save_text: 'Save',
			data: data,
			tags: λ.tags
		});

		λ.labelform({
			model: o,
		    	submit: on_submit
		});
	}

	var view = λ.routableview.extend({
		render: function (id) {
			var o = λ.o.get(id, {
				success: function(){
					success(o);
				},
				error: function(ev){
					λ.setcontent('notfound', {
						action: 'Edit',
						id: id,
						status: ev.status
					});
				}
			});
		}
	});

	view.route('edit/:id', 'edit');
}());