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

	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');
}());