1
|
/*global
|
2
|
dojo:false
|
3
|
*/
|
4
|
var ed = {};
|
5
|
|
6
|
ed.form = function(args) {
|
7
|
|
8
|
var button = dojo.byId("formButton");
|
9
|
var id = args.domId;
|
10
|
var clearOnSuccess = args.clearOnSuccess;
|
11
|
|
12
|
dojo.connect(button, "onclick", function(event) {
|
13
|
event.preventDefault();
|
14
|
event.stopPropagation();
|
15
|
|
16
|
var xhrArgs = {
|
17
|
form: dojo.byId(id),
|
18
|
handleAs: "json",
|
19
|
load: function(data) {
|
20
|
IRIGO.toaster([{
|
21
|
message: data.message,
|
22
|
type: "message",
|
23
|
duration: 2000
|
24
|
}]);
|
25
|
if(data.action){
|
26
|
// the action reflects the category and title
|
27
|
dojo.byId(id).action = data.action;
|
28
|
}
|
29
|
if(clearOnSuccess){
|
30
|
var nodes = dojo.query('#' + id + ' input, #' + id + ' textarea');
|
31
|
var clear = function(node){
|
32
|
node.value = "";
|
33
|
};
|
34
|
dojo.forEach(nodes, clear);
|
35
|
}
|
36
|
},
|
37
|
error: function(error) {
|
38
|
IRIGO.toaster([
|
39
|
{
|
40
|
message: error.responseText,
|
41
|
type: "error",
|
42
|
duration: 5000
|
43
|
}]);
|
44
|
}
|
45
|
};
|
46
|
|
47
|
IRIGO.toaster([{
|
48
|
message: "Processing ...",
|
49
|
type: "message",
|
50
|
duration: 500
|
51
|
}]);
|
52
|
|
53
|
var deferred = dojo.xhrPost(xhrArgs);
|
54
|
|
55
|
});
|
56
|
};
|