/
fast_in_place_editor.js
40 lines (34 loc) · 1.02 KB
/
fast_in_place_editor.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
function processEditables(){
var inPlaceEditables = $$('[data-in-place-editable]');
inPlaceEditables.each(function(editable) {
var id = editable.id;
var entity = editable.readAttribute("data-entity");
var field = editable.readAttribute("data-field");
var submitUrl = editable.readAttribute("data-url");
var columnNr = editable.readAttribute("data-cols");
var rowNr = editable.readAttribute("data-rows");
var options = {
callback: function(form, value) {
return entity + "[" + field + "]=" + encodeURIComponent(value) +
"&delta=" + encodeURIComponent(value) +
"&_method=PUT";
}
};
if(columnNr && rowNr){
Object.extend(options, {cols: columnNr, rows: rowNr})
}
new Ajax.InPlaceEditor(
id,
submitUrl,
options
);
});
}
(function() {
document.on("dom:loaded", function() {
processEditables();
});
document.on("ajax:after", function(event, element) {
setTimeout( "processEditables()", 200);
});
})();