ajax-scaffold-generator 2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,327 @@
1
+
2
+ var Abstract = new Object();
3
+ Abstract.Table = function() {};
4
+ Abstract.Table.prototype = {
5
+ tagTest: function(element, tagName) {
6
+ return $(element).tagName.toLowerCase() == tagName.toLowerCase();
7
+ }
8
+ };
9
+
10
+ Abstract.TableEffect = function() {};
11
+ Abstract.TableEffect.prototype = Object.extend(new Abstract.Table(), {
12
+ callEffect: function(target, command) {
13
+ var target = $(target);
14
+ if (this.tagTest(target,'tr')) {
15
+ var length = target.cells.length;
16
+ for (var i = 0; i < length; i++) {
17
+ eval("new " + command + "(target.cells[i]);");
18
+ }
19
+ } else {
20
+ eval("new " + command + "(targetElement);");
21
+ }
22
+ }
23
+ });
24
+
25
+ Abstract.TableRow = function() {};
26
+ Abstract.TableRow.prototype = Object.extend(new Abstract.Table(), {
27
+ initialize: function(target, source) {
28
+ try {
29
+ var target = $(target);
30
+ var source = $(source);
31
+ if (this.tagTest(target,'tr') && this.tagTest(source,'tr')) {
32
+ var newRow = this.findParentTable(target).insertRow(this.getNewRowIndex(target));
33
+ newRow.parentNode.replaceChild(source, newRow);
34
+ }
35
+ } catch (e) {
36
+ alert(e);
37
+ }
38
+ },
39
+ findParentTable: function(element) {
40
+ var element = $(element);
41
+ var maxSearchDepth = 3;
42
+ var currentSearchDepth = 1;
43
+ var current = element;
44
+ while (currentSearchDepth <= maxSearchDepth) {
45
+ current = current.parentNode;
46
+ if (this.tagTest(current, 'table')) {
47
+ return current;
48
+ }
49
+ currentSearchDepth++;
50
+ }
51
+ }
52
+ });
53
+
54
+ var TableRow = new Object();
55
+
56
+ TableRow.MoveBefore = Class.create();
57
+ TableRow.MoveBefore.prototype = Object.extend(new Abstract.TableRow(), {
58
+ getNewRowIndex: function(target) {
59
+ return target.rowIndex;
60
+ }
61
+ });
62
+
63
+ TableRow.MoveAfter = Class.create();
64
+ TableRow.MoveAfter.prototype = Object.extend(new Abstract.TableRow(), {
65
+ getNewRowIndex: function(target) {
66
+ return target.rowIndex+1;
67
+ }
68
+ });
69
+
70
+ //Since scriptaculous doesn't support tables and causes and error applying effects to rows in IE 6.0 and Safari we need this wrapper
71
+ var TableEffect = new Object();
72
+
73
+ TableEffect.Fade = Class.create();
74
+ TableEffect.Fade.prototype = Object.extend(new Abstract.TableEffect(), {
75
+ initialize: function(target) {
76
+ this.callEffect(target, 'Effect.Fade');
77
+ }
78
+ });
79
+
80
+ TableEffect.SlideDown = Class.create();
81
+ TableEffect.SlideDown.prototype = Object.extend(new Abstract.TableEffect(), {
82
+ initialize: function(target) {
83
+ this.callEffect(target, 'Effect.SlideDown');
84
+ }
85
+ });
86
+
87
+ TableEffect.Highlight = Class.create();
88
+ TableEffect.Highlight.prototype = Object.extend(new Abstract.TableEffect(), {
89
+ initialize: function(target) {
90
+ this.callEffect(target, 'Effect.Highlight');
91
+ }
92
+ });
93
+
94
+ var AjaxScaffold = new Object();
95
+
96
+ Object.extend(AjaxScaffold, {
97
+
98
+ newOnLoading: function(request, type) {
99
+ Element.show(this.getNewIndicator(type));
100
+ },
101
+ newOnFailure: function(request, type) {
102
+ this.showError(type, request.responseText);
103
+ Element.hide(this.getNewIndicator(type));
104
+ },
105
+ newOnSuccess: function(request, type) {
106
+ var createForm = request.responseText;
107
+ new Insertion.Top(this.getTableBodyElement(type), createForm);
108
+
109
+ Element.hide(this.getEmptyMessageElement(type));
110
+ Element.hide(this.getNewIndicator(type));
111
+
112
+ var createElement = this.getCreateElement(type, this.getId(request,type));
113
+ Element.show(createElement);
114
+ new TableEffect.Highlight(createElement);
115
+ Form.focusFirstElement(createElement.getElementsByTagName('form')[0]);
116
+ },
117
+ newOnComplete: function(request, type) {
118
+
119
+ },
120
+ getNewIndicator: function(type) {
121
+ return $(type + "-new-loading-indicator");
122
+ },
123
+
124
+
125
+
126
+
127
+ createOnLoading: function(request,type,id) {
128
+ Element.show(this.getIndicator('create',type,id));
129
+ },
130
+ createOnFailure: function(request,type,id) {
131
+ var errorElement = this.getFormErrorElement('create',type,id)
132
+ var errorMessages = request.responseText;
133
+ errorElement.innerHTML = errorMessages;
134
+ Element.show(errorElement);
135
+ Element.hide(this.getIndicator('create',type,id));
136
+ },
137
+ createOnSuccess: function(request,type,id) {
138
+ var view = request.responseText;
139
+ new Insertion.Top(this.getTableBodyElement(type), view);
140
+ var createElement = this.getCreateElement(type,id);
141
+
142
+ Element.remove(createElement);
143
+
144
+
145
+ var viewElement = this.getViewElement(type, this.getId(request,type));
146
+ new TableEffect.Highlight(viewElement);
147
+
148
+ this.stripeTable(type);
149
+ },
150
+ createOnCancel: function(type,id) {
151
+ var createElement = this.getCreateElement(type,id);
152
+ Element.remove(createElement);
153
+ if (this.countRows(type) == 0) {
154
+ Element.show(this.getEmptyMessageElement(type));
155
+ }
156
+ },
157
+
158
+
159
+ deleteOnLoading: function(type,id) {
160
+
161
+ },
162
+ deleteOnFailure: function(type,id) {
163
+ this.showError(type, request.responseText);
164
+ },
165
+ deleteOnComplete: function(type,id) {
166
+ var viewElement = this.getViewElement(type,id);
167
+
168
+ new TableEffect.Fade(viewElement);
169
+ //We cannot set a timeout to remove this element from the DOM b/c once fade is complete
170
+ // 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
171
+ Element.addClassName(viewElement, 'deleted');
172
+
173
+ if (this.countRows(type) == 0) {
174
+ Element.show(this.getEmptyMessageElement(type));
175
+ } else {
176
+ this.stripeTable(type);
177
+ }
178
+ },
179
+
180
+
181
+ editOnLoading: function(request,type,id) {
182
+ Element.show(this.getIndicator('edit',type,id));
183
+ },
184
+ editOnFailure: function(request,type,id) {
185
+ this.showError(type, request.responseText);
186
+ Element.hide(this.getIndicator('edit',type,id));
187
+ },
188
+ editOnSuccess: function(request,type,id) {
189
+ var viewElement = this.getViewElement(type,id);
190
+
191
+ //Ajax.Update with Insertion.top does not work when being used as a component with other scaffolds on the screen
192
+ // the only safe way it seems it to always insert new elements at the bottom and then move them into the appropriate location
193
+ var editForm = request.responseText;
194
+ new Insertion.Bottom(this.getTableBodyElement(type), editForm);
195
+ var editElement = this.getEditElement(type,id);
196
+ new TableRow.MoveAfter(viewElement, editElement);
197
+
198
+ var formElement = this.getFormElement(type,id);
199
+
200
+ Element.hide(viewElement);
201
+ Element.hide(this.getIndicator('edit',type,id));
202
+ Element.show(editElement);
203
+ new Effect.Highlight(editElement);
204
+ Form.focusFirstElement(formElement);
205
+ },
206
+
207
+
208
+ updateOnLoading: function(request,type,id) {
209
+ Element.show(this.getIndicator('update',type,id));
210
+ },
211
+ updateOnFailure: function(request,type,id) {
212
+ var errorElement = this.getFormErrorElement('update',type,id)
213
+ var errorMessages = request.responseText;
214
+ errorElement.innerHTML = errorMessages;
215
+ Element.show(errorElement);
216
+ Element.hide(this.getIndicator('update',type,id));
217
+ },
218
+ updateOnSuccess: function(request,type,id) {
219
+ var editElement = this.getEditElement(type,id);
220
+ var formElement = this.getFormElement(type,id);
221
+ var viewElement = this.getViewElement(type,id);
222
+
223
+ Element.remove(viewElement);
224
+
225
+ var view = request.responseText;
226
+ new Insertion.Bottom(this.getTableBodyElement(type), view);
227
+ var viewElement = this.getViewElement(type,id);
228
+ new TableRow.MoveBefore(editElement, viewElement);
229
+
230
+ Element.remove(editElement);
231
+ this.stripeTable(type);
232
+ new TableEffect.Highlight(viewElement);
233
+ },
234
+ updateOnCancel: function(type,id) {
235
+ var viewElement = this.getViewElement(type,id);
236
+ var editElement = this.getEditElement(type,id);
237
+
238
+ Element.show(viewElement);
239
+ Element.remove(editElement);
240
+ },
241
+
242
+
243
+ showError: function(type,html) {
244
+ var errorElement = this.getErrorMessageElement(type);
245
+ var errorMessageElement = errorElement.getElementsByTagName("p")[0];
246
+ errorMessageElement.innerHTML = html;
247
+ Element.show(errorElement);
248
+ new TableEffect.Highlight(errorElement);
249
+ },
250
+ hideError: function(type) {
251
+ var errorElement = this.getErrorMessageElement(type);
252
+ Element.hide(errorElement);
253
+ },
254
+
255
+
256
+
257
+
258
+ getIndicator: function(scope, type,id) {
259
+ return $(type + '-' + scope + '-' + id + "-loading-indicator");
260
+ },
261
+ getFormErrorElement: function(scope,type,id) {
262
+ return $(scope + '-' + type + '-' + id + '-errors')
263
+ },
264
+ getId: function(request, type) {
265
+ return request.getResponseHeader(type + '-id');
266
+ },
267
+ getCreateElement: function(type,id) {
268
+ return $('create-' + type + '-' + id);
269
+ },
270
+ getViewElement: function(type,id) {
271
+ return $('view-' + type + '-' + id);
272
+ },
273
+ getEditElement: function(type,id) {
274
+ return $('edit-' + type + '-' + id);
275
+ },
276
+ getFormElement: function(type,id) {
277
+ return $(type + '-' + id + '-form');
278
+ },
279
+ getEmptyMessageElement: function(type) {
280
+ return $(type + '-empty-message');
281
+ },
282
+ getErrorMessageElement: function(type) {
283
+ return $(type + '-error-message');
284
+ },
285
+ getTableBodyElement: function(type) {
286
+ return $(type + '-list-body');
287
+ },
288
+ stripeTable: function(type) {
289
+ var even = false;
290
+ var tableBody = this.getTableBodyElement(type);
291
+ var tableRows = tableBody.getElementsByTagName("tr");
292
+ var length = tableRows.length;
293
+
294
+ for (var i = 0; i < length; i++) {
295
+ var tableRow = tableRows[i];
296
+ //Make sure to skip rows that are create or edit rows or messages
297
+ if (!Element.hasClassName(tableRow, "edit")
298
+ && !Element.hasClassName(tableRow, "create")
299
+ && !Element.hasClassName(tableRow, "deleted")
300
+ && !Element.hasClassName(tableRow, "message")) {
301
+ if (even) {
302
+ Element.addClassName(tableRow, "even");
303
+ } else {
304
+ Element.removeClassName(tableRow, "even");
305
+ }
306
+ even = !even;
307
+ }
308
+ }
309
+ },
310
+ countRows: function(type) {
311
+ var tableBody = this.getTableBodyElement(type);
312
+ var tableRows = tableBody.getElementsByTagName("tr");
313
+ var length = tableRows.length;
314
+
315
+ var validRows = 0;
316
+
317
+ for (var i = 0; i < length; i++) {
318
+ var tableRow = tableRows[i];
319
+ //Make sure to skip rows that are deleted or message
320
+ if (!Element.hasClassName(tableRow, "deleted")
321
+ && !Element.hasClassName(tableRow, "message")) {
322
+ validRows++;
323
+ }
324
+ }
325
+ return validRows;
326
+ }
327
+ });
@@ -0,0 +1,324 @@
1
+ .list-wrapper form,
2
+ .list-wrapper table,
3
+ .list-wrapper p,
4
+ .list-wrapper div,
5
+ .list-wrapper fieldset {
6
+ margin: 0;
7
+ padding: 0;
8
+ }
9
+
10
+ .list-wrapper {
11
+ margin: 5px 0;
12
+ }
13
+
14
+
15
+ table.list {
16
+ width: 100%;
17
+ }
18
+
19
+ .list-header {
20
+ position: relative;
21
+ background: #005CB8;
22
+ clear: both;
23
+ }
24
+
25
+ * html .list-header {
26
+ height: 1%;
27
+ }
28
+
29
+ .list-header div.actions a {
30
+ color: #fff;
31
+ background: url(/images/add.gif) 1px 50% no-repeat;
32
+ font-size: 13px;
33
+ font-family: Trebuchet MS;
34
+ font-weight: bold;
35
+ text-decoration: none;
36
+ padding: 1px 2px 1px 19px;
37
+ }
38
+
39
+ .list-header div.actions a:hover {
40
+ background: #378CDF url(/images/add.gif) 1px 50% no-repeat;
41
+ }
42
+
43
+ .list-header h2 {
44
+ color: #fff;
45
+ padding: 3px 5px;
46
+ margin: 0;
47
+ font-size: 18px;
48
+ font-weight: normal;
49
+ font-family: Verdana, sans-serif;
50
+ }
51
+
52
+ .list-header .actions {
53
+ position: absolute;
54
+ right: 5px;
55
+ bottom: 2px;
56
+ }
57
+
58
+ table.list a {
59
+ color: #0066CC;
60
+ }
61
+
62
+ table.list tr.header {
63
+ background: #C5DBF7;
64
+ }
65
+
66
+ table.list th {
67
+ font-size: 11px;
68
+ padding: 2px;
69
+ color: #fff;
70
+ background: #555;
71
+ letter-spacing: 0;
72
+ font-family: Arial, sans-serif;
73
+ text-align: left;
74
+ padding-left: 5px;
75
+ }
76
+
77
+ table.list td {
78
+ padding: 5px 4px;
79
+ border-bottom: solid 1px #C5DBF7;
80
+ color: #333;
81
+ font-family: Verdana, sans-serif;
82
+ font-size: 11px;
83
+ background-color: #E6F2FF;
84
+ }
85
+
86
+ table.list tr.even td {
87
+ background-color: #fff;
88
+ }
89
+
90
+
91
+ table.list .edit td,
92
+ table.list .create td {
93
+ padding: 0;
94
+ padding: 4px;
95
+ }
96
+
97
+ table.list td.action {
98
+ padding: 0;
99
+ padding-right: 2px;
100
+ }
101
+
102
+ table.list td a {
103
+ font-family: Verdana, sans-serif;
104
+ font-size: 11px;
105
+ font-weight: bold;
106
+ letter-spacing: -1px;
107
+ padding: 2px;
108
+ line-height: 18px;
109
+ }
110
+
111
+ table.list td a:hover {
112
+ background: #ff8;
113
+ }
114
+
115
+ .list-wrapper .list-footer {
116
+ text-align: right;
117
+ background: #005CB8;
118
+ padding: 2px 0;
119
+ border-bottom: none;
120
+ }
121
+
122
+ table.list tfoot a {
123
+ color: #fff;
124
+ font-size: 12px;
125
+ font-weight: bold;
126
+ letter-spacing: 0;
127
+ font-family: Arial, sans-serif;
128
+ }
129
+
130
+ table.list tfoot a:hover {
131
+ color: #0066CC;
132
+ }
133
+
134
+ table.list .edit td,
135
+ table.list .create td {
136
+ background: #DAFFCD;
137
+ }
138
+
139
+ table.list .edit td,
140
+ table.list .create td {
141
+ border-top: solid 2px #fff;
142
+ border-bottom: solid 2px #fff;
143
+ }
144
+
145
+ table.list .actions div {
146
+ width: 95px;
147
+ right: 0;
148
+ text-align: right;
149
+ float: right;
150
+ padding-right: 2px;
151
+ }
152
+
153
+ /* Messages */
154
+
155
+ table.list .empty-message td {
156
+ background: #e8e8e8;
157
+ text-align: center;
158
+ color: #666;
159
+ }
160
+
161
+ table.list .error-message td {
162
+ border-bottom: solid 1px #fff;
163
+ background: #f66;
164
+ color: #333;
165
+ font-size: 11px;
166
+ font-weight: bold;
167
+ }
168
+
169
+ table.list .error-message p {
170
+ padding-left: 19px;
171
+ background: url(/images/error.gif) 0 0 no-repeat;
172
+ }
173
+
174
+ table.list .error-message td.actions {
175
+ background: #f66;
176
+ text-align: right;
177
+ }
178
+
179
+ table.list .error-message td.actions a {
180
+ color: #333;
181
+ }
182
+
183
+ /* Error Styling */
184
+
185
+ table.list #errorExplanation {
186
+ background: #fcc;
187
+ margin: 2px 7px;
188
+ border: solid 1px #f66;
189
+ }
190
+
191
+ table.list #errorExplanation h2 {
192
+ padding: 2px 5px 3px 20px;
193
+ color: #333;
194
+ font-size: 11px;
195
+ margin: 0;
196
+ letter-spacing: 0;
197
+ font-family: Verdana;
198
+ background: #f66 url(/images/error.gif) 2px 1px no-repeat;
199
+ }
200
+
201
+ table.list #errorExplanation ul {
202
+ margin: 0;
203
+ padding: 2px 2px 4px 25px;
204
+ }
205
+
206
+ table.list #errorExplanation p {
207
+ font-size: 11px;
208
+ padding: 2px 5px;
209
+ font-family: Verdana;
210
+ margin: 0;
211
+ }
212
+
213
+ table.list #errorExplanation ul li {
214
+ font-size: 11px;
215
+ margin: 0;
216
+ font-family: Verdana;
217
+ padding: 0;
218
+ }
219
+
220
+ table.list .fieldWithErrors input {
221
+ border: solid 1px #f00;
222
+ }
223
+
224
+ /* Loading Indicator */
225
+
226
+ .list-wrapper .loading-indicator {
227
+ vertical-align: bottom;
228
+ margin: 0;
229
+ }
230
+
231
+ .list-wrapper .list-header .loading-indicator,
232
+ .list-wrapper .edit .loading-indicator,
233
+ .list-wrapper .create .loading-indicator {
234
+ vertical-align: bottom;
235
+ margin-bottom: 3px;
236
+ }
237
+
238
+ /* Form Styling */
239
+
240
+ .list-wrapper fieldset {
241
+ border: none;
242
+ }
243
+
244
+ table.list label.required{
245
+ font-weight: bold;
246
+ }
247
+
248
+ table.list label.example {
249
+ font-size: 11px;
250
+ font-family: arial;
251
+ color: #888;
252
+ }
253
+
254
+ table.list h4 {
255
+ padding: 2px;
256
+ margin: 0;
257
+ color: #1F7F00;
258
+ font-size: 16px;
259
+ letter-spacing: -1px;
260
+ font-family: Georgia, Arial, sans-serif;
261
+ }
262
+
263
+ .list-wrapper .submit {
264
+ font-weight: bold;
265
+ font-size: 14px;
266
+ font-family: Arial, sans-serif;
267
+ letter-spacing: 0;
268
+ margin: 0;
269
+ margin-top: 5px;
270
+ }
271
+
272
+ table.list .edit a,
273
+ table.list .create a {
274
+ font-size: 14px;
275
+ font-weight: bold;
276
+ font-family: Arial, sans-serif;
277
+ letter-spacing: 0;
278
+ }
279
+
280
+ table.list p {
281
+ clear: both;
282
+ }
283
+
284
+ table.list div.row {
285
+ clear: both;
286
+ float: none;
287
+ padding: 2px;
288
+ margin-left: 5px;
289
+ }
290
+
291
+ table.list div.form-element {
292
+ float: left;
293
+ margin-right: 10px;
294
+ margin-bottom: 2px;
295
+ }
296
+
297
+ table.list label {
298
+ display: block;
299
+ font-family: Verdana, sans-serif;
300
+ color: #555;
301
+ font-size: 11px;
302
+ padding-bottom: 1px;
303
+ }
304
+
305
+ table.list input,
306
+ table.list select {
307
+ font-size: 16px;
308
+ font-weight: bold;
309
+ font-family: Arial, sans-serif;
310
+ letter-spacing: -1px;
311
+ }
312
+
313
+ table.list .form-element input {
314
+ padding: 1px;
315
+ border: solid 1px #1F7F00;
316
+ }
317
+
318
+ table.list textarea {
319
+ height: 65px;
320
+ font-family: Arial, sans-serif;
321
+ font-size: 12px;
322
+ padding: 1px;
323
+ border: solid 1px #1F7F00;
324
+ }