This repository has been archived by the owner on Mar 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
quick-edit.js
executable file
·97 lines (77 loc) · 1.98 KB
/
quick-edit.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(function(){
function QuickEdit( id, row, formTemplate, values ) {
this.id = id;
this.formTemplate = formTemplate;
this.values = values;
this.row = row;
this.formShowing = false;
QuickEdit.objects[id] = this;
};
QuickEdit.objects = {};
QuickEdit.prototype = {
revert : function(){
// reset the values
this.form.hide();
this.row.show();
this.formShowing = false;
this.form.remove();
},
save : function(){
$('img.waiting', this.form).show();
var data = this.form.serialize();
// validate
// AJAX call
// this.revert
// update row, this.row
// update values, this.values
},
edit : function(){
this.createForm();
this.row.hide();
this.form.show();
for( key in QuickEdit.objects ){
if( key != this.id && QuickEdit.objects[key].formShowing ){
QuickEdit.objects[key].revert();
}
}
this.formShowing = true;
},
createForm : function(){
var self = this;
this.form = this.formTemplate.clone();
this.form
.insertAfter(this.row)
.toggleClass('alternate', this.row.hasClass('alternate'))
.find('a.cancel')
.click(function(event){
self.revert();
event.stopPropagation();
return false;
})
.end()
.find('a.save')
.click(function(event){
self.save();
event.stopPropagation();
return false;
});
// set the values
var text = this.form.find( ':text' );
var checkbox = this.form.find( ':checkbox' );
var t, c, name;
for( var i=0; i<text.length; ++i ){
t = text.eq(i);
name = t.attr('name');
t.val(this.values.find('span.'+name).text());
}
for( var i=0; i<checkbox.length; ++i ){
c = checkbox.eq(i);
name = c.attr('name');
c.attr( 'checked', this.values.find('span.'+name).text() == 'true' );
}
}
}
function init_quickedit() {
}
$(document).ready(init_quickedit);
})();