ajax_scaffold_generator 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -20
- data/README +28 -28
- data/ajax_scaffold_generator.rb +123 -123
- data/templates/controller.rb +61 -61
- data/templates/form.rhtml +4 -4
- data/templates/functional_test.rb +88 -88
- data/templates/helper.rb +12 -12
- data/templates/layout.rhtml +15 -15
- data/templates/partial_item.rhtml +24 -24
- data/templates/script.js +425 -327
- data/templates/style.css +345 -324
- data/templates/view_edit.rhtml +1 -1
- data/templates/view_index.rhtml +1 -1
- data/templates/view_list.rhtml +57 -52
- data/templates/view_new.rhtml +2 -1
- metadata +5 -3
data/templates/script.js
CHANGED
@@ -1,327 +1,425 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Abstract
|
4
|
-
Abstract.Table
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
}
|
9
|
-
|
10
|
-
|
11
|
-
Abstract.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
var
|
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
|
-
var
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
TableRow
|
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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
this.
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
return
|
122
|
-
},
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
var
|
146
|
-
|
147
|
-
|
148
|
-
this.
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
},
|
188
|
-
|
189
|
-
var
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
var
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
Element.
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
this.
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
Element.
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
Element.
|
253
|
-
},
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
},
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
},
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
1
|
+
// The following is a cross browser way to move around <tr> elements in a <table> or <tbody>
|
2
|
+
|
3
|
+
var Abstract = new Object();
|
4
|
+
Abstract.Table = function() {};
|
5
|
+
Abstract.Table.prototype = {
|
6
|
+
tagTest: function(element, tagName) {
|
7
|
+
return $(element).tagName.toLowerCase() == tagName.toLowerCase();
|
8
|
+
}
|
9
|
+
};
|
10
|
+
|
11
|
+
Abstract.TableRow = function() {};
|
12
|
+
Abstract.TableRow.prototype = Object.extend(new Abstract.Table(), {
|
13
|
+
initialize: function(targetTableRow, sourceTableRow) {
|
14
|
+
try {
|
15
|
+
var sourceTableRow = $(sourceTableRow);
|
16
|
+
var targetTableRow = $(targetTableRow);
|
17
|
+
|
18
|
+
if (targetTableRow == null || !this.tagTest(targetTableRow,'tr')
|
19
|
+
|| sourceTableRow == null || !this.tagTest(sourceTableRow,'tr')) {
|
20
|
+
throw("TableRow: both parameters must be a <tr> tag.");
|
21
|
+
}
|
22
|
+
|
23
|
+
var tableOrTbody = this.findParentTableOrTbody(targetTableRow);
|
24
|
+
|
25
|
+
var newRow = tableOrTbody.insertRow(this.getNewRowIndex(targetTableRow) - this.getRowOffset(tableOrTbody));
|
26
|
+
newRow.parentNode.replaceChild(sourceTableRow, newRow);
|
27
|
+
|
28
|
+
} catch (e) {
|
29
|
+
alert(e);
|
30
|
+
}
|
31
|
+
},
|
32
|
+
getRowOffset: function(tableOrTbody) {
|
33
|
+
//If we are inserting into a tablebody we would need figure out the rowIndex of the first
|
34
|
+
// row in that tbody and subtract that offset from the new row index
|
35
|
+
var rowOffset = 0;
|
36
|
+
if (this.tagTest(tableOrTbody,'tbody')) {
|
37
|
+
rowOffset = tableOrTbody.rows[0].rowIndex;
|
38
|
+
}
|
39
|
+
return rowOffset;
|
40
|
+
},
|
41
|
+
findParentTableOrTbody: function(element) {
|
42
|
+
var element = $(element);
|
43
|
+
// Completely arbitrary value
|
44
|
+
var maxSearchDepth = 3;
|
45
|
+
var currentSearchDepth = 1;
|
46
|
+
var current = element;
|
47
|
+
while (currentSearchDepth <= maxSearchDepth) {
|
48
|
+
current = current.parentNode;
|
49
|
+
if (this.tagTest(current, 'tbody') || this.tagTest(current, 'table')) {
|
50
|
+
return current;
|
51
|
+
}
|
52
|
+
currentSearchDepth++;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
});
|
56
|
+
|
57
|
+
var TableRow = new Object();
|
58
|
+
|
59
|
+
TableRow.MoveBefore = Class.create();
|
60
|
+
TableRow.MoveBefore.prototype = Object.extend(new Abstract.TableRow(), {
|
61
|
+
getNewRowIndex: function(target) {
|
62
|
+
return target.rowIndex;
|
63
|
+
}
|
64
|
+
});
|
65
|
+
|
66
|
+
TableRow.MoveAfter = Class.create();
|
67
|
+
TableRow.MoveAfter.prototype = Object.extend(new Abstract.TableRow(), {
|
68
|
+
getNewRowIndex: function(target) {
|
69
|
+
return target.rowIndex+1;
|
70
|
+
}
|
71
|
+
});
|
72
|
+
|
73
|
+
//Since scriptaculous doesn't support tables and causes and error applying effects to rows in IE 6.0 and Safari we need this wrapper
|
74
|
+
|
75
|
+
Abstract.TableEffect = function() {};
|
76
|
+
Abstract.TableEffect.prototype = Object.extend(new Abstract.Table(), {
|
77
|
+
callEffect: function(target, command) {
|
78
|
+
var target = $(target);
|
79
|
+
if (this.tagTest(target,'tr')) {
|
80
|
+
var length = target.cells.length;
|
81
|
+
for (var i = 0; i < length; i++) {
|
82
|
+
eval("new " + command + "(target.cells[i]);");
|
83
|
+
}
|
84
|
+
} else {
|
85
|
+
eval("new " + command + "(targetElement);");
|
86
|
+
}
|
87
|
+
}
|
88
|
+
});
|
89
|
+
|
90
|
+
var TableEffect = new Object();
|
91
|
+
|
92
|
+
TableEffect.Fade = Class.create();
|
93
|
+
TableEffect.Fade.prototype = Object.extend(new Abstract.TableEffect(), {
|
94
|
+
initialize: function(target) {
|
95
|
+
this.callEffect(target, 'Effect.Fade');
|
96
|
+
}
|
97
|
+
});
|
98
|
+
|
99
|
+
TableEffect.Highlight = Class.create();
|
100
|
+
TableEffect.Highlight.prototype = Object.extend(new Abstract.TableEffect(), {
|
101
|
+
initialize: function(target) {
|
102
|
+
this.callEffect(target, 'Effect.Highlight');
|
103
|
+
}
|
104
|
+
});
|
105
|
+
|
106
|
+
//The following is a utility to paint beautiful stripes on our table rows, a lot of logic for setting the colors explicitly on each element
|
107
|
+
// if hightlighting is going to overwrite out CSS styles otherwise.
|
108
|
+
|
109
|
+
var TableBodyUtil = {
|
110
|
+
enableHighlighting: function(tableBody) {
|
111
|
+
this.getColorStore(tableBody).highlighting = true;
|
112
|
+
},
|
113
|
+
disableHighlighting: function(tableBody) {
|
114
|
+
this.getColorStore(tableBody).highlighting = false;
|
115
|
+
},
|
116
|
+
highlightingEnabled: function(tableBody) {
|
117
|
+
var returnValue = true;
|
118
|
+
if (this.getColorStore(tableBody).highlighting != null) {
|
119
|
+
returnValue = this.getColorStore(tableBody).highlighting;
|
120
|
+
}
|
121
|
+
return returnValue;
|
122
|
+
},
|
123
|
+
// We are going to proxy all highlighting through this so that we can uniformly allow/block it (and subsequently paintStripes depending on this)
|
124
|
+
highlight: function(target, tableBody) {
|
125
|
+
if (this.highlightingEnabled(tableBody)) {
|
126
|
+
new TableEffect.Highlight(target);
|
127
|
+
}
|
128
|
+
},
|
129
|
+
getColorStore: function(tableBody) {
|
130
|
+
var uniqueId = tableBody.id;
|
131
|
+
|
132
|
+
if (this.tables == null) {
|
133
|
+
this.tables = new Object();
|
134
|
+
}
|
135
|
+
|
136
|
+
if (this.tables[String(uniqueId)] == null) {
|
137
|
+
this.tables[String(uniqueId)] = new Object();
|
138
|
+
}
|
139
|
+
|
140
|
+
return this.tables[String(uniqueId)];
|
141
|
+
},
|
142
|
+
paintStripes: function(tableBody) {
|
143
|
+
var even = false;
|
144
|
+
var tableBody = tableBody;
|
145
|
+
var tableRows = tableBody.getElementsByTagName("tr");
|
146
|
+
var length = tableBody.rows.length;
|
147
|
+
|
148
|
+
var colorStore = this.getColorStore(tableBody);
|
149
|
+
|
150
|
+
for (var i = 0; i < length; i++) {
|
151
|
+
var tableRow = tableBody.rows[i];
|
152
|
+
//Make sure to skip rows that are create or edit rows or messages
|
153
|
+
if (!Element.hasClassName(tableRow, "edit")
|
154
|
+
&& !Element.hasClassName(tableRow, "create")
|
155
|
+
&& !Element.hasClassName(tableRow, "deleted")
|
156
|
+
&& !Element.hasClassName(tableRow, "message")) {
|
157
|
+
|
158
|
+
if (even) {
|
159
|
+
Element.addClassName(tableRow, "even");
|
160
|
+
if (this.highlightingEnabled(tableBody)) {
|
161
|
+
//If we don't already know what the color is supposed to be we'll poll it from the styles and then save that to apply later
|
162
|
+
if (!colorStore.evenColor) {
|
163
|
+
colorStore.evenColor = this.getCellBackgroundColor(tableRow);
|
164
|
+
// Safari won't pick up the style of the color if the row is not displayed so we are going to hide and then show
|
165
|
+
// the dummy row if thats what this is.
|
166
|
+
if (colorStore.evenColor == null) {
|
167
|
+
Element.show(tableRow);
|
168
|
+
colorStore.evenColor = this.getCellBackgroundColor(tableRow);
|
169
|
+
Element.hide(tableRow);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
this.setCellBackgroundColor(tableRow, colorStore.evenColor);
|
173
|
+
}
|
174
|
+
} else {
|
175
|
+
Element.removeClassName(tableRow, "even");
|
176
|
+
|
177
|
+
if (this.highlightingEnabled(tableBody)) {
|
178
|
+
if (!colorStore.oddColor) {
|
179
|
+
colorStore.oddColor = this.getCellBackgroundColor(tableRow);
|
180
|
+
}
|
181
|
+
this.setCellBackgroundColor(tableRow, colorStore.oddColor);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
even = !even;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
},
|
188
|
+
getCellBackgroundColor: function(tableRow) {
|
189
|
+
var tableCell = tableRow.getElementsByTagName("td")[0];
|
190
|
+
return Element.getStyle(tableCell, 'background-color');
|
191
|
+
},
|
192
|
+
setCellBackgroundColor: function(tableRow, color) {
|
193
|
+
var length = tableRow.cells.length;
|
194
|
+
for (var i = 0; i < length; i++) {
|
195
|
+
try {
|
196
|
+
tableRow.cells[i].style.backgroundColor = color;
|
197
|
+
} catch (e) {
|
198
|
+
alert(e);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
},
|
202
|
+
countRows: function(tableBody) {
|
203
|
+
var tableBody = tableBody;
|
204
|
+
var length = tableBody.rows.length;
|
205
|
+
|
206
|
+
var validRows = 0;
|
207
|
+
|
208
|
+
for (var i = 0; i < length; i++) {
|
209
|
+
var tableRow = tableBody.rows[i];
|
210
|
+
//Make sure to skip rows that are deleted or message
|
211
|
+
if (!Element.hasClassName(tableRow, "deleted")
|
212
|
+
&& !Element.hasClassName(tableRow, "message")
|
213
|
+
&& !Element.hasClassName(tableRow, "ignore")) {
|
214
|
+
validRows++;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
return validRows;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
var AjaxScaffold = {
|
222
|
+
newOnLoading: function(request, type) {
|
223
|
+
Element.show(this.getNewIndicator(type));
|
224
|
+
},
|
225
|
+
newOnFailure: function(request, type) {
|
226
|
+
this.showError(type, request.responseText);
|
227
|
+
Element.hide(this.getNewIndicator(type));
|
228
|
+
},
|
229
|
+
newOnSuccess: function(request, type) {
|
230
|
+
var createForm = request.responseText;
|
231
|
+
var id = this.getId(request,type);
|
232
|
+
|
233
|
+
new Insertion.Top(this.getTableBodyElement(type), createForm);
|
234
|
+
|
235
|
+
Element.hide(this.getEmptyMessageElement(type));
|
236
|
+
Element.hide(this.getNewIndicator(type));
|
237
|
+
|
238
|
+
var createElement = this.getCreateElement(type, id);
|
239
|
+
Element.show(createElement);
|
240
|
+
TableBodyUtil.highlight(createElement,this.getTableBodyElement(type));
|
241
|
+
Form.focusFirstElement(this.getFormElement('create',type,id));
|
242
|
+
},
|
243
|
+
newOnComplete: function(request, type) {
|
244
|
+
|
245
|
+
},
|
246
|
+
getNewIndicator: function(type) {
|
247
|
+
return $(type + "-new-loading-indicator");
|
248
|
+
},
|
249
|
+
|
250
|
+
|
251
|
+
createOnLoading: function(request,type,id) {
|
252
|
+
Element.show(this.getIndicator('create',type,id));
|
253
|
+
},
|
254
|
+
createOnFailure: function(request,type,id) {
|
255
|
+
var errorElement = this.getFormErrorElement('create',type,id)
|
256
|
+
var errorMessages = request.responseText;
|
257
|
+
errorElement.innerHTML = errorMessages;
|
258
|
+
Element.show(errorElement);
|
259
|
+
Element.hide(this.getIndicator('create',type,id));
|
260
|
+
},
|
261
|
+
createOnSuccess: function(request,type,id) {
|
262
|
+
var createElement = this.getCreateElement(type,id);
|
263
|
+
|
264
|
+
var view = request.responseText;
|
265
|
+
var viewId = this.getId(request,type);
|
266
|
+
|
267
|
+
// TODO : Convert this into TableRow.InsertAfter
|
268
|
+
new Insertion.Bottom(this.getTableBodyElement(type), view);
|
269
|
+
var viewElement = this.getViewElement(type,viewId);
|
270
|
+
new TableRow.MoveAfter(createElement, viewElement);
|
271
|
+
|
272
|
+
Element.remove(createElement);
|
273
|
+
Element.show(viewElement);
|
274
|
+
|
275
|
+
TableBodyUtil.paintStripes(this.getTableBodyElement(type));
|
276
|
+
TableBodyUtil.highlight(viewElement,this.getTableBodyElement(type));
|
277
|
+
},
|
278
|
+
createOnCancel: function(type,id) {
|
279
|
+
var createElement = this.getCreateElement(type,id);
|
280
|
+
Element.remove(createElement);
|
281
|
+
if (TableBodyUtil.countRows(this.getTableBodyElement(type)) == 0) {
|
282
|
+
Element.show(this.getEmptyMessageElement(type));
|
283
|
+
}
|
284
|
+
},
|
285
|
+
|
286
|
+
|
287
|
+
deleteOnLoading: function(type,id) {
|
288
|
+
|
289
|
+
},
|
290
|
+
deleteOnFailure: function(type,id) {
|
291
|
+
this.showError(type, request.responseText);
|
292
|
+
},
|
293
|
+
deleteOnSuccess: function(type,id) {
|
294
|
+
var viewElement = this.getViewElement(type,id);
|
295
|
+
|
296
|
+
new TableEffect.Fade(viewElement);
|
297
|
+
//We cannot set a timeout to remove this element from the DOM b/c once fade is complete
|
298
|
+
// get by ID no longer works on this element. So we'll set a class so that it isn't picked up in a re striping
|
299
|
+
Element.addClassName(viewElement, 'deleted');
|
300
|
+
|
301
|
+
if (TableBodyUtil.countRows(this.getTableBodyElement(type)) == 0) {
|
302
|
+
Element.show(this.getEmptyMessageElement(type));
|
303
|
+
} else {
|
304
|
+
TableBodyUtil.paintStripes(this.getTableBodyElement(type));
|
305
|
+
}
|
306
|
+
},
|
307
|
+
|
308
|
+
|
309
|
+
editOnLoading: function(request,type,id) {
|
310
|
+
Element.show(this.getIndicator('edit',type,id));
|
311
|
+
},
|
312
|
+
editOnFailure: function(request,type,id) {
|
313
|
+
this.showError(type, request.responseText);
|
314
|
+
Element.hide(this.getIndicator('edit',type,id));
|
315
|
+
},
|
316
|
+
editOnSuccess: function(request,type,id) {
|
317
|
+
var viewElement = this.getViewElement(type,id);
|
318
|
+
|
319
|
+
//Ajax.Update with Insertion.top does not work when being used as a component with other scaffolds on the screen
|
320
|
+
// the only safe way it seems it to always insert new elements at the bottom and then move them into the appropriate location
|
321
|
+
var editForm = request.responseText;
|
322
|
+
|
323
|
+
// TODO : Convert this into TableRow.InsertAfter
|
324
|
+
new Insertion.Bottom(this.getTableBodyElement(type), editForm);
|
325
|
+
var editElement = this.getEditElement(type,id);
|
326
|
+
new TableRow.MoveAfter(viewElement, editElement);
|
327
|
+
|
328
|
+
var formElement = this.getFormElement('edit',type,id);
|
329
|
+
|
330
|
+
Element.hide(viewElement);
|
331
|
+
Element.hide(this.getIndicator('edit',type,id));
|
332
|
+
Element.show(editElement);
|
333
|
+
new Effect.Highlight(editElement);
|
334
|
+
Form.focusFirstElement(formElement);
|
335
|
+
},
|
336
|
+
|
337
|
+
|
338
|
+
updateOnLoading: function(request,type,id) {
|
339
|
+
Element.show(this.getIndicator('update',type,id));
|
340
|
+
},
|
341
|
+
updateOnFailure: function(request,type,id) {
|
342
|
+
var errorElement = this.getFormErrorElement('update',type,id)
|
343
|
+
var errorMessages = request.responseText;
|
344
|
+
errorElement.innerHTML = errorMessages;
|
345
|
+
Element.show(errorElement);
|
346
|
+
Element.hide(this.getIndicator('update',type,id));
|
347
|
+
},
|
348
|
+
updateOnSuccess: function(request,type,id) {
|
349
|
+
var editElement = this.getEditElement(type,id);
|
350
|
+
var formElement = this.getFormElement(type,id);
|
351
|
+
var viewElement = this.getViewElement(type,id);
|
352
|
+
|
353
|
+
Element.remove(viewElement);
|
354
|
+
|
355
|
+
var view = request.responseText;
|
356
|
+
|
357
|
+
// TODO : Convert this into a TableRow.InsertBefore
|
358
|
+
new Insertion.Bottom(this.getTableBodyElement(type), view);
|
359
|
+
var viewElement = this.getViewElement(type,id);
|
360
|
+
new TableRow.MoveBefore(editElement, viewElement);
|
361
|
+
|
362
|
+
Element.remove(editElement);
|
363
|
+
Element.show(viewElement);
|
364
|
+
|
365
|
+
TableBodyUtil.paintStripes(this.getTableBodyElement(type));
|
366
|
+
TableBodyUtil.highlight(viewElement,this.getTableBodyElement(type));
|
367
|
+
},
|
368
|
+
updateOnCancel: function(type,id) {
|
369
|
+
var viewElement = this.getViewElement(type,id);
|
370
|
+
var editElement = this.getEditElement(type,id);
|
371
|
+
|
372
|
+
Element.show(viewElement);
|
373
|
+
Element.remove(editElement);
|
374
|
+
},
|
375
|
+
|
376
|
+
|
377
|
+
showError: function(type,html) {
|
378
|
+
var errorElement = this.getErrorMessageElement(type);
|
379
|
+
var errorMessageElement = errorElement.getElementsByTagName("p")[0];
|
380
|
+
errorMessageElement.innerHTML = html;
|
381
|
+
Element.show(errorElement);
|
382
|
+
TableBodyUtil.highlight(errorElement,this.getTableBodyElement(type));
|
383
|
+
},
|
384
|
+
hideError: function(type) {
|
385
|
+
var errorElement = this.getErrorMessageElement(type);
|
386
|
+
Element.hide(errorElement);
|
387
|
+
},
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
getIndicator: function(scope, type,id) {
|
393
|
+
return $(type + '-' + scope + '-' + id + "-loading-indicator");
|
394
|
+
},
|
395
|
+
getFormErrorElement: function(scope,type,id) {
|
396
|
+
return $(scope + '-' + type + '-' + id + '-errors')
|
397
|
+
},
|
398
|
+
getId: function(request, type) {
|
399
|
+
return request.getResponseHeader(type + '-id');
|
400
|
+
},
|
401
|
+
getCreateElementId: function(type,id) {
|
402
|
+
return 'create-' + type + '-' + id;
|
403
|
+
},
|
404
|
+
getCreateElement: function(type,id) {
|
405
|
+
return $('create-' + type + '-' + id);
|
406
|
+
},
|
407
|
+
getViewElement: function(type,id) {
|
408
|
+
return $('view-' + type + '-' + id);
|
409
|
+
},
|
410
|
+
getEditElement: function(type,id) {
|
411
|
+
return $('edit-' + type + '-' + id);
|
412
|
+
},
|
413
|
+
getFormElement: function(scope,type,id) {
|
414
|
+
return $(scope+'-'+type + '-' + id + '-form');
|
415
|
+
},
|
416
|
+
getEmptyMessageElement: function(type) {
|
417
|
+
return $(type + '-empty-message');
|
418
|
+
},
|
419
|
+
getErrorMessageElement: function(type) {
|
420
|
+
return $(type + '-error-message');
|
421
|
+
},
|
422
|
+
getTableBodyElement: function(type) {
|
423
|
+
return $(type + '-list-body');
|
424
|
+
}
|
425
|
+
}
|