dynamite 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CDDL-LICENSE +382 -0
- data/README.rdoc +2 -1
- data/lib/assets/javascripts/dynamite.js +1 -1
- data/lib/assets/javascripts/dynamite/dynamite.jquery.js +201 -0
- data/lib/assets/javascripts/dynamite/email.dynamite.jquery.js +14 -0
- data/lib/assets/javascripts/dynamite/textarea.dynamite.jquery.js +14 -0
- data/lib/assets/javascripts/dynamite/textbox.dynamite.jquery.js +4 -0
- data/lib/assets/javascripts/dynamite/tickbox.dynamite.jquery.js +14 -0
- data/lib/default_partials/_email.html.erb +13 -0
- data/lib/default_partials/_textarea.html.erb +13 -0
- data/lib/default_partials/_textbox.html.erb +13 -0
- data/lib/default_partials/_tickbox.html.erb +13 -0
- data/lib/dynamite.rb +63 -0
- data/lib/dynamite/version.rb +1 -1
- data/lib/generators/install/templates/app/assets/stylesheets/dynamite.css +34 -0
- data/lib/generators/install/templates/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/lib/generators/install/templates/app/controllers/form_submissions_controller.rb +83 -0
- data/lib/generators/install/templates/app/controllers/forms_controller.rb +83 -0
- data/lib/generators/install/templates/app/models/form.rb +37 -0
- data/lib/generators/install/templates/app/models/form_schema.rb +3 -0
- data/lib/generators/install/templates/app/models/form_submission.rb +58 -0
- data/lib/generators/install/templates/app/models/form_var.rb +3 -0
- data/lib/generators/install/templates/app/views/form_submissions/_form.html.erb +21 -0
- data/lib/generators/install/templates/app/views/form_submissions/edit.html.erb +6 -0
- data/lib/generators/install/templates/app/views/form_submissions/index.html.erb +24 -0
- data/lib/generators/install/templates/app/views/form_submissions/new.html.erb +5 -0
- data/lib/generators/install/templates/app/views/form_submissions/show.html.erb +10 -0
- data/lib/generators/install/templates/app/views/forms/_form.html.erb +25 -0
- data/lib/generators/install/templates/app/views/forms/edit.html.erb +6 -0
- data/lib/generators/install/templates/app/views/forms/index.html.erb +23 -0
- data/lib/generators/install/templates/app/views/forms/new.html.erb +5 -0
- data/lib/generators/install/templates/app/views/forms/show.html.erb +15 -0
- data/lib/generators/install/templates/db/migrate/install_dynamite.rb +28 -0
- metadata +43 -8
- data/MIT-LICENSE +0 -20
data/CDDL-LICENSE
ADDED
@@ -0,0 +1,382 @@
|
|
1
|
+
Copyright Leanbid Ltd
|
2
|
+
|
3
|
+
COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
|
4
|
+
|
5
|
+
1. Definitions.
|
6
|
+
|
7
|
+
1.1. "Contributor" means each individual or entity that
|
8
|
+
creates or contributes to the creation of Modifications.
|
9
|
+
|
10
|
+
1.2. "Contributor Version" means the combination of the
|
11
|
+
Original Software, prior Modifications used by a
|
12
|
+
Contributor (if any), and the Modifications made by that
|
13
|
+
particular Contributor.
|
14
|
+
|
15
|
+
1.3. "Covered Software" means (a) the Original Software, or
|
16
|
+
(b) Modifications, or (c) the combination of files
|
17
|
+
containing Original Software with files containing
|
18
|
+
Modifications, in each case including portions thereof.
|
19
|
+
|
20
|
+
1.4. "Executable" means the Covered Software in any form
|
21
|
+
other than Source Code.
|
22
|
+
|
23
|
+
1.5. "Initial Developer" means the individual or entity
|
24
|
+
that first makes Original Software available under this
|
25
|
+
License.
|
26
|
+
|
27
|
+
1.6. "Larger Work" means a work which combines Covered
|
28
|
+
Software or portions thereof with code not governed by the
|
29
|
+
terms of this License.
|
30
|
+
|
31
|
+
1.7. "License" means this document.
|
32
|
+
|
33
|
+
1.8. "Licensable" means having the right to grant, to the
|
34
|
+
maximum extent possible, whether at the time of the initial
|
35
|
+
grant or subsequently acquired, any and all of the rights
|
36
|
+
conveyed herein.
|
37
|
+
|
38
|
+
1.9. "Modifications" means the Source Code and Executable
|
39
|
+
form of any of the following:
|
40
|
+
|
41
|
+
A. Any file that results from an addition to,
|
42
|
+
deletion from or modification of the contents of a
|
43
|
+
file containing Original Software or previous
|
44
|
+
Modifications;
|
45
|
+
|
46
|
+
B. Any new file that contains any part of the
|
47
|
+
Original Software or previous Modification; or
|
48
|
+
|
49
|
+
C. Any new file that is contributed or otherwise made
|
50
|
+
available under the terms of this License.
|
51
|
+
|
52
|
+
1.10. "Original Software" means the Source Code and
|
53
|
+
Executable form of computer software code that is
|
54
|
+
originally released under this License.
|
55
|
+
|
56
|
+
1.11. "Patent Claims" means any patent claim(s), now owned
|
57
|
+
or hereafter acquired, including without limitation,
|
58
|
+
method, process, and apparatus claims, in any patent
|
59
|
+
Licensable by grantor.
|
60
|
+
|
61
|
+
1.12. "Source Code" means (a) the common form of computer
|
62
|
+
software code in which modifications are made and (b)
|
63
|
+
associated documentation included in or with such code.
|
64
|
+
|
65
|
+
1.13. "You" (or "Your") means an individual or a legal
|
66
|
+
entity exercising rights under, and complying with all of
|
67
|
+
the terms of, this License. For legal entities, "You"
|
68
|
+
includes any entity which controls, is controlled by, or is
|
69
|
+
under common control with You. For purposes of this
|
70
|
+
definition, "control" means (a) the power, direct or
|
71
|
+
indirect, to cause the direction or management of such
|
72
|
+
entity, whether by contract or otherwise, or (b) ownership
|
73
|
+
of more than fifty percent (50%) of the outstanding shares
|
74
|
+
or beneficial ownership of such entity.
|
75
|
+
|
76
|
+
2. License Grants.
|
77
|
+
|
78
|
+
2.1. The Initial Developer Grant.
|
79
|
+
|
80
|
+
Conditioned upon Your compliance with Section 3.1 below and
|
81
|
+
subject to third party intellectual property claims, the
|
82
|
+
Initial Developer hereby grants You a world-wide,
|
83
|
+
royalty-free, non-exclusive license:
|
84
|
+
|
85
|
+
(a) under intellectual property rights (other than
|
86
|
+
patent or trademark) Licensable by Initial Developer,
|
87
|
+
to use, reproduce, modify, display, perform,
|
88
|
+
sublicense and distribute the Original Software (or
|
89
|
+
portions thereof), with or without Modifications,
|
90
|
+
and/or as part of a Larger Work; and
|
91
|
+
|
92
|
+
(b) under Patent Claims infringed by the making,
|
93
|
+
using or selling of Original Software, to make, have
|
94
|
+
made, use, practice, sell, and offer for sale, and/or
|
95
|
+
otherwise dispose of the Original Software (or
|
96
|
+
portions thereof).
|
97
|
+
|
98
|
+
(c) The licenses granted in Sections 2.1(a) and (b)
|
99
|
+
are effective on the date Initial Developer first
|
100
|
+
distributes or otherwise makes the Original Software
|
101
|
+
available to a third party under the terms of this
|
102
|
+
License.
|
103
|
+
|
104
|
+
(d) Notwithstanding Section 2.1(b) above, no patent
|
105
|
+
license is granted: (1) for code that You delete from
|
106
|
+
the Original Software, or (2) for infringements
|
107
|
+
caused by: (i) the modification of the Original
|
108
|
+
Software, or (ii) the combination of the Original
|
109
|
+
Software with other software or devices.
|
110
|
+
|
111
|
+
2.2. Contributor Grant.
|
112
|
+
|
113
|
+
Conditioned upon Your compliance with Section 3.1 below and
|
114
|
+
subject to third party intellectual property claims, each
|
115
|
+
Contributor hereby grants You a world-wide, royalty-free,
|
116
|
+
non-exclusive license:
|
117
|
+
|
118
|
+
(a) under intellectual property rights (other than
|
119
|
+
patent or trademark) Licensable by Contributor to
|
120
|
+
use, reproduce, modify, display, perform, sublicense
|
121
|
+
and distribute the Modifications created by such
|
122
|
+
Contributor (or portions thereof), either on an
|
123
|
+
unmodified basis, with other Modifications, as
|
124
|
+
Covered Software and/or as part of a Larger Work; and
|
125
|
+
|
126
|
+
(b) under Patent Claims infringed by the making,
|
127
|
+
using, or selling of Modifications made by that
|
128
|
+
Contributor either alone and/or in combination with
|
129
|
+
its Contributor Version (or portions of such
|
130
|
+
combination), to make, use, sell, offer for sale,
|
131
|
+
have made, and/or otherwise dispose of: (1)
|
132
|
+
Modifications made by that Contributor (or portions
|
133
|
+
thereof); and (2) the combination of Modifications
|
134
|
+
made by that Contributor with its Contributor Version
|
135
|
+
(or portions of such combination).
|
136
|
+
|
137
|
+
(c) The licenses granted in Sections 2.2(a) and
|
138
|
+
2.2(b) are effective on the date Contributor first
|
139
|
+
distributes or otherwise makes the Modifications
|
140
|
+
available to a third party.
|
141
|
+
|
142
|
+
(d) Notwithstanding Section 2.2(b) above, no patent
|
143
|
+
license is granted: (1) for any code that Contributor
|
144
|
+
has deleted from the Contributor Version; (2) for
|
145
|
+
infringements caused by: (i) third party
|
146
|
+
modifications of Contributor Version, or (ii) the
|
147
|
+
combination of Modifications made by that Contributor
|
148
|
+
with other software (except as part of the
|
149
|
+
Contributor Version) or other devices; or (3) under
|
150
|
+
Patent Claims infringed by Covered Software in the
|
151
|
+
absence of Modifications made by that Contributor.
|
152
|
+
|
153
|
+
3. Distribution Obligations.
|
154
|
+
|
155
|
+
3.1. Availability of Source Code.
|
156
|
+
|
157
|
+
Any Covered Software that You distribute or otherwise make
|
158
|
+
available in Executable form must also be made available in
|
159
|
+
Source Code form and that Source Code form must be
|
160
|
+
distributed only under the terms of this License. You must
|
161
|
+
include a copy of this License with every copy of the
|
162
|
+
Source Code form of the Covered Software You distribute or
|
163
|
+
otherwise make available. You must inform recipients of any
|
164
|
+
such Covered Software in Executable form as to how they can
|
165
|
+
obtain such Covered Software in Source Code form in a
|
166
|
+
reasonable manner on or through a medium customarily used
|
167
|
+
for software exchange.
|
168
|
+
|
169
|
+
3.2. Modifications.
|
170
|
+
|
171
|
+
The Modifications that You create or to which You
|
172
|
+
contribute are governed by the terms of this License. You
|
173
|
+
represent that You believe Your Modifications are Your
|
174
|
+
original creation(s) and/or You have sufficient rights to
|
175
|
+
grant the rights conveyed by this License.
|
176
|
+
|
177
|
+
3.3. Required Notices.
|
178
|
+
|
179
|
+
You must include a notice in each of Your Modifications
|
180
|
+
that identifies You as the Contributor of the Modification.
|
181
|
+
You may not remove or alter any copyright, patent or
|
182
|
+
trademark notices contained within the Covered Software, or
|
183
|
+
any notices of licensing or any descriptive text giving
|
184
|
+
attribution to any Contributor or the Initial Developer.
|
185
|
+
|
186
|
+
3.4. Application of Additional Terms.
|
187
|
+
|
188
|
+
You may not offer or impose any terms on any Covered
|
189
|
+
Software in Source Code form that alters or restricts the
|
190
|
+
applicable version of this License or the recipients'
|
191
|
+
rights hereunder. You may choose to offer, and to charge a
|
192
|
+
fee for, warranty, support, indemnity or liability
|
193
|
+
obligations to one or more recipients of Covered Software.
|
194
|
+
However, you may do so only on Your own behalf, and not on
|
195
|
+
behalf of the Initial Developer or any Contributor. You
|
196
|
+
must make it absolutely clear that any such warranty,
|
197
|
+
support, indemnity or liability obligation is offered by
|
198
|
+
You alone, and You hereby agree to indemnify the Initial
|
199
|
+
Developer and every Contributor for any liability incurred
|
200
|
+
by the Initial Developer or such Contributor as a result of
|
201
|
+
warranty, support, indemnity or liability terms You offer.
|
202
|
+
|
203
|
+
3.5. Distribution of Executable Versions.
|
204
|
+
|
205
|
+
You may distribute the Executable form of the Covered
|
206
|
+
Software under the terms of this License or under the terms
|
207
|
+
of a license of Your choice, which may contain terms
|
208
|
+
different from this License, provided that You are in
|
209
|
+
compliance with the terms of this License and that the
|
210
|
+
license for the Executable form does not attempt to limit
|
211
|
+
or alter the recipient's rights in the Source Code form
|
212
|
+
from the rights set forth in this License. If You
|
213
|
+
distribute the Covered Software in Executable form under a
|
214
|
+
different license, You must make it absolutely clear that
|
215
|
+
any terms which differ from this License are offered by You
|
216
|
+
alone, not by the Initial Developer or Contributor. You
|
217
|
+
hereby agree to indemnify the Initial Developer and every
|
218
|
+
Contributor for any liability incurred by the Initial
|
219
|
+
Developer or such Contributor as a result of any such terms
|
220
|
+
You offer.
|
221
|
+
|
222
|
+
3.6. Larger Works.
|
223
|
+
|
224
|
+
You may create a Larger Work by combining Covered Software
|
225
|
+
with other code not governed by the terms of this License
|
226
|
+
and distribute the Larger Work as a single product. In such
|
227
|
+
a case, You must make sure the requirements of this License
|
228
|
+
are fulfilled for the Covered Software.
|
229
|
+
|
230
|
+
4. Versions of the License.
|
231
|
+
|
232
|
+
4.1. New Versions.
|
233
|
+
|
234
|
+
Sun Microsystems, Inc. is the initial license steward and
|
235
|
+
may publish revised and/or new versions of this License
|
236
|
+
from time to time. Each version will be given a
|
237
|
+
distinguishing version number. Except as provided in
|
238
|
+
Section 4.3, no one other than the license steward has the
|
239
|
+
right to modify this License.
|
240
|
+
|
241
|
+
4.2. Effect of New Versions.
|
242
|
+
|
243
|
+
You may always continue to use, distribute or otherwise
|
244
|
+
make the Covered Software available under the terms of the
|
245
|
+
version of the License under which You originally received
|
246
|
+
the Covered Software. If the Initial Developer includes a
|
247
|
+
notice in the Original Software prohibiting it from being
|
248
|
+
distributed or otherwise made available under any
|
249
|
+
subsequent version of the License, You must distribute and
|
250
|
+
make the Covered Software available under the terms of the
|
251
|
+
version of the License under which You originally received
|
252
|
+
the Covered Software. Otherwise, You may also choose to
|
253
|
+
use, distribute or otherwise make the Covered Software
|
254
|
+
available under the terms of any subsequent version of the
|
255
|
+
License published by the license steward.
|
256
|
+
|
257
|
+
4.3. Modified Versions.
|
258
|
+
|
259
|
+
When You are an Initial Developer and You want to create a
|
260
|
+
new license for Your Original Software, You may create and
|
261
|
+
use a modified version of this License if You: (a) rename
|
262
|
+
the license and remove any references to the name of the
|
263
|
+
license steward (except to note that the license differs
|
264
|
+
from this License); and (b) otherwise make it clear that
|
265
|
+
the license contains terms which differ from this License.
|
266
|
+
|
267
|
+
5. DISCLAIMER OF WARRANTY.
|
268
|
+
|
269
|
+
COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS"
|
270
|
+
BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
|
271
|
+
INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED
|
272
|
+
SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
|
273
|
+
PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND
|
274
|
+
PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY
|
275
|
+
COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
|
276
|
+
INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF
|
277
|
+
ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF
|
278
|
+
WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
|
279
|
+
ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
|
280
|
+
DISCLAIMER.
|
281
|
+
|
282
|
+
6. TERMINATION.
|
283
|
+
|
284
|
+
6.1. This License and the rights granted hereunder will
|
285
|
+
terminate automatically if You fail to comply with terms
|
286
|
+
herein and fail to cure such breach within 30 days of
|
287
|
+
becoming aware of the breach. Provisions which, by their
|
288
|
+
nature, must remain in effect beyond the termination of
|
289
|
+
this License shall survive.
|
290
|
+
|
291
|
+
6.2. If You assert a patent infringement claim (excluding
|
292
|
+
declaratory judgment actions) against Initial Developer or
|
293
|
+
a Contributor (the Initial Developer or Contributor against
|
294
|
+
whom You assert such claim is referred to as "Participant")
|
295
|
+
alleging that the Participant Software (meaning the
|
296
|
+
Contributor Version where the Participant is a Contributor
|
297
|
+
or the Original Software where the Participant is the
|
298
|
+
Initial Developer) directly or indirectly infringes any
|
299
|
+
patent, then any and all rights granted directly or
|
300
|
+
indirectly to You by such Participant, the Initial
|
301
|
+
Developer (if the Initial Developer is not the Participant)
|
302
|
+
and all Contributors under Sections 2.1 and/or 2.2 of this
|
303
|
+
License shall, upon 60 days notice from Participant
|
304
|
+
terminate prospectively and automatically at the expiration
|
305
|
+
of such 60 day notice period, unless if within such 60 day
|
306
|
+
period You withdraw Your claim with respect to the
|
307
|
+
Participant Software against such Participant either
|
308
|
+
unilaterally or pursuant to a written agreement with
|
309
|
+
Participant.
|
310
|
+
|
311
|
+
6.3. In the event of termination under Sections 6.1 or 6.2
|
312
|
+
above, all end user licenses that have been validly granted
|
313
|
+
by You or any distributor hereunder prior to termination
|
314
|
+
(excluding licenses granted to You by any distributor)
|
315
|
+
shall survive termination.
|
316
|
+
|
317
|
+
7. LIMITATION OF LIABILITY.
|
318
|
+
|
319
|
+
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
|
320
|
+
(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
|
321
|
+
INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF
|
322
|
+
COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE
|
323
|
+
LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
|
324
|
+
CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT
|
325
|
+
LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK
|
326
|
+
STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
|
327
|
+
COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
|
328
|
+
INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
|
329
|
+
LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
|
330
|
+
INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT
|
331
|
+
APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO
|
332
|
+
NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
|
333
|
+
CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT
|
334
|
+
APPLY TO YOU.
|
335
|
+
|
336
|
+
8. U.S. GOVERNMENT END USERS.
|
337
|
+
|
338
|
+
The Covered Software is a "commercial item," as that term is
|
339
|
+
defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial
|
340
|
+
computer software" (as that term is defined at 48 C.F.R. ¤
|
341
|
+
252.227-7014(a)(1)) and "commercial computer software
|
342
|
+
documentation" as such terms are used in 48 C.F.R. 12.212 (Sept.
|
343
|
+
1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1
|
344
|
+
through 227.7202-4 (June 1995), all U.S. Government End Users
|
345
|
+
acquire Covered Software with only those rights set forth herein.
|
346
|
+
This U.S. Government Rights clause is in lieu of, and supersedes,
|
347
|
+
any other FAR, DFAR, or other clause or provision that addresses
|
348
|
+
Government rights in computer software under this License.
|
349
|
+
|
350
|
+
9. MISCELLANEOUS.
|
351
|
+
|
352
|
+
This License represents the complete agreement concerning subject
|
353
|
+
matter hereof. If any provision of this License is held to be
|
354
|
+
unenforceable, such provision shall be reformed only to the
|
355
|
+
extent necessary to make it enforceable. This License shall be
|
356
|
+
governed by the law of the jurisdiction specified in a notice
|
357
|
+
contained within the Original Software (except to the extent
|
358
|
+
applicable law, if any, provides otherwise), excluding such
|
359
|
+
jurisdiction's conflict-of-law provisions. Any litigation
|
360
|
+
relating to this License shall be subject to the jurisdiction of
|
361
|
+
the courts located in the jurisdiction and venue specified in a
|
362
|
+
notice contained within the Original Software, with the losing
|
363
|
+
party responsible for costs, including, without limitation, court
|
364
|
+
costs and reasonable attorneys' fees and expenses. The
|
365
|
+
application of the United Nations Convention on Contracts for the
|
366
|
+
International Sale of Goods is expressly excluded. Any law or
|
367
|
+
regulation which provides that the language of a contract shall
|
368
|
+
be construed against the drafter shall not apply to this License.
|
369
|
+
You agree that You alone are responsible for compliance with the
|
370
|
+
United States export administration regulations (and the export
|
371
|
+
control laws and regulation of any other countries) when You use,
|
372
|
+
distribute or otherwise make available any Covered Software.
|
373
|
+
|
374
|
+
10. RESPONSIBILITY FOR CLAIMS.
|
375
|
+
|
376
|
+
As between Initial Developer and the Contributors, each party is
|
377
|
+
responsible for claims and damages arising, directly or
|
378
|
+
indirectly, out of its utilization of rights under this License
|
379
|
+
and You agree to work with Initial Developer and Contributors to
|
380
|
+
distribute such responsibility on an equitable basis. Nothing
|
381
|
+
herein is intended or shall be deemed to constitute any admission
|
382
|
+
of liability.
|
data/README.rdoc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
//= require_tree ./
|
1
|
+
//= require_tree ./dynamite
|
@@ -0,0 +1,201 @@
|
|
1
|
+
|
2
|
+
var Dynamite = {};
|
3
|
+
|
4
|
+
function DynamiteType(){
|
5
|
+
|
6
|
+
this.name = function(){
|
7
|
+
return 'textbox';
|
8
|
+
};
|
9
|
+
|
10
|
+
this.previewHtml = function(){
|
11
|
+
return "<input type=\"text\" value=\"(textbox)\" disabled />";
|
12
|
+
};
|
13
|
+
|
14
|
+
this.defaultModel = function(){
|
15
|
+
return {type: this.name(), label: ""};
|
16
|
+
};
|
17
|
+
|
18
|
+
this.edit = function(state){
|
19
|
+
state.label = prompt("Please enter label:", state.label);
|
20
|
+
if(state.label != '' && state.label != null){
|
21
|
+
state.save();
|
22
|
+
}
|
23
|
+
};
|
24
|
+
|
25
|
+
this.add = function(state){
|
26
|
+
this.edit(state);
|
27
|
+
}
|
28
|
+
|
29
|
+
this.confirmDeleteMessage = function(){
|
30
|
+
return "Are you sure you want to delete this " + this.name() + "?";
|
31
|
+
};
|
32
|
+
|
33
|
+
this.confirmDelete = function(){
|
34
|
+
return confirm(this.confirmDeleteMessage());
|
35
|
+
};
|
36
|
+
}
|
37
|
+
|
38
|
+
(function(){
|
39
|
+
var types = [];
|
40
|
+
|
41
|
+
Dynamite.addType = function(type){
|
42
|
+
types[type.name()] = type;
|
43
|
+
};
|
44
|
+
|
45
|
+
Dynamite.type = function(name){
|
46
|
+
return types[name];
|
47
|
+
};
|
48
|
+
|
49
|
+
function InputState(model, fn){
|
50
|
+
for(var i in model){
|
51
|
+
this[i] = model[i];
|
52
|
+
}
|
53
|
+
this.save = function(){
|
54
|
+
out = {};
|
55
|
+
for(var i in model){
|
56
|
+
out[i] = this[i];
|
57
|
+
}
|
58
|
+
fn(out);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
function to_json_string(data){
|
64
|
+
if(typeof data == 'number' || typeof data == 'boolean'){
|
65
|
+
return data;
|
66
|
+
}
|
67
|
+
if(typeof data == 'string'){
|
68
|
+
return "\"" + data.replace(/\"/, "\\\"") + "\"";
|
69
|
+
}
|
70
|
+
if(data instanceof Array){
|
71
|
+
var items = [];
|
72
|
+
for(var i in data){
|
73
|
+
items.push(to_json_string(data[i]));
|
74
|
+
}
|
75
|
+
return "[" + items.join(",") + "]";
|
76
|
+
}
|
77
|
+
var items = [];
|
78
|
+
for(var i in data){
|
79
|
+
items.push(to_json_string(i) + ":" + to_json_string(data[i]));
|
80
|
+
}
|
81
|
+
return "{" + items.join(",") + "}";
|
82
|
+
}
|
83
|
+
|
84
|
+
function html_escape(data){
|
85
|
+
return data.replace(/&/, "&").replace(/</, "<").replace(/>/, ">").replace(/\"/, """);
|
86
|
+
}
|
87
|
+
|
88
|
+
function Editor(form_input){
|
89
|
+
var that = this;
|
90
|
+
var container = $('<div class="dynamite_editor">');
|
91
|
+
$(form_input).hide();
|
92
|
+
container.insertAfter(form_input);
|
93
|
+
|
94
|
+
var model;
|
95
|
+
try {model = jQuery.parseJSON($(form_input).val());} catch(e){};
|
96
|
+
if(!model){
|
97
|
+
model = {inputs: []};
|
98
|
+
}
|
99
|
+
|
100
|
+
function update(){
|
101
|
+
$(container).html("");
|
102
|
+
|
103
|
+
var table = $("<table>");
|
104
|
+
$(container).append(table);
|
105
|
+
|
106
|
+
var inputs = model['inputs'];
|
107
|
+
|
108
|
+
if(inputs.length > 0 ){
|
109
|
+
table.html("<tr><th>Label</th><th>Preview</th></tr>");
|
110
|
+
}
|
111
|
+
|
112
|
+
for(var i in inputs){
|
113
|
+
var input = inputs[i];
|
114
|
+
var row = $("<tr>");
|
115
|
+
$(table).append(row);
|
116
|
+
|
117
|
+
|
118
|
+
(function(i){
|
119
|
+
|
120
|
+
var cell = $("<td valign=\"top\" class=\"label\">"+html_escape(input.label)+"</td><td class=\"preview\">"+types[input.type].previewHtml()+"</td>");
|
121
|
+
$(row).append(cell);
|
122
|
+
|
123
|
+
var cell = $("<td valign=\"top\"><a href=\"javascript:;\" class=\"button edit\">Edit</a></td>");
|
124
|
+
$(row).append(cell);
|
125
|
+
$(cell).find("a").click(function(){
|
126
|
+
types[inputs[i].type].edit(new InputState(inputs[i], function(input_model){
|
127
|
+
inputs[i] = input_model;
|
128
|
+
update();
|
129
|
+
}));
|
130
|
+
});
|
131
|
+
|
132
|
+
var cell = $("<td valign=\"top\"><a href=\"javascript:;\" class=\"button delete\">Delete</a></td>");
|
133
|
+
$(row).append(cell);
|
134
|
+
$(cell).find("a").click(function(){
|
135
|
+
if(types[inputs[i].type].confirmDelete()){
|
136
|
+
var new_inputs = [];
|
137
|
+
for(var j in inputs){
|
138
|
+
if(j != i){
|
139
|
+
new_inputs.push(inputs[j]);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
model['inputs'] = new_inputs;
|
143
|
+
update();
|
144
|
+
}
|
145
|
+
});
|
146
|
+
|
147
|
+
var cell = $("<td valign=\"top\"><a href=\"javascript:;\" class=\"button up\">Up</a></td>");
|
148
|
+
$(row).append(cell);
|
149
|
+
if(i > 0){
|
150
|
+
$(cell).find("a").click(function(){
|
151
|
+
var current = inputs[i];
|
152
|
+
inputs[i] = inputs[i - 1];
|
153
|
+
inputs[i - 1] = current;
|
154
|
+
update();
|
155
|
+
});
|
156
|
+
}
|
157
|
+
var cell = $("<td valign=\"top\"><a href=\"javascript:;\" class=\"button down\">Down</a></td>");
|
158
|
+
$(row).append(cell);
|
159
|
+
if(i < inputs.length - 1){
|
160
|
+
$(cell).find("a").click(function(){
|
161
|
+
var current = inputs[i];
|
162
|
+
inputs[i] = inputs[i + 1];
|
163
|
+
inputs[i + 1] = current;
|
164
|
+
update();
|
165
|
+
});
|
166
|
+
}
|
167
|
+
|
168
|
+
})(parseInt(i));
|
169
|
+
}
|
170
|
+
|
171
|
+
var row = $("<tr>");
|
172
|
+
$(table).append(row);
|
173
|
+
var cell = $("<td colspan=\"6\">");
|
174
|
+
$(row).append(cell);
|
175
|
+
var insert_select = $("<select>");
|
176
|
+
$(cell).append(insert_select);
|
177
|
+
$(insert_select).append($("<option selected> --- Add --- </option>"));
|
178
|
+
for(var i in types){
|
179
|
+
var type = types[i];
|
180
|
+
$(insert_select).append($("<option value=\""+i+"\">"+i+"</option>"));
|
181
|
+
}
|
182
|
+
|
183
|
+
$(insert_select).change(function(){
|
184
|
+
var type = $(this).val();
|
185
|
+
$(this).val("");
|
186
|
+
types[type].add(new InputState(types[type].defaultModel(), function(input_model){
|
187
|
+
model.inputs.push(input_model);
|
188
|
+
update();
|
189
|
+
}));
|
190
|
+
});
|
191
|
+
|
192
|
+
$(form_input).val(to_json_string(model));
|
193
|
+
}
|
194
|
+
update();
|
195
|
+
}
|
196
|
+
|
197
|
+
$(function(){
|
198
|
+
$(".dynamite").each(function(){new Editor(this);});
|
199
|
+
});
|
200
|
+
})();
|
201
|
+
|