PluginProbe
Smart Forms – when you need more than just a contact form / 0.7
Smart Forms – when you need more than just a contact form v0.7
trunk 0.5 0.5.5 0.6 0.7 0.8 0.8.5 0.9.1
smart-forms / js / formBuilder / formbuilder.js

formbuilder.js in Smart Forms – when you need more than just a contact form 0.7, at js/formBuilder/formbuilder.js

343 lines 14.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2 var smartDonationsIsDesignMode=true;
3 var SmartFormsFieldIsAvailable=function(fieldName){return true;};
4 function RedNaoFormBuilder(smartFormsOptions,formElementsOptions) {
5
6 this.formSettings = rnJQuery('#formSettings');
7 this.redNaoWindow = rnJQuery(document);
8 this.formSettingsOriginalTop = this.formSettings.offset().top - 35;
9 this.RedNaoFormElements = [];
10 this.scrollTimeOut = null;
11 this.propertiesPanel = rnJQuery("#rednaoPropertiesPanel");
12
13 rnJQuery("#formBuilderButtonSet").buttonset();
14
15
16 var self = this;
17 $(window).scroll(function (data) {
18 if (self.scrollTimeOut != null)
19 clearTimeout(self.scrollTimeOut);
20
21 self.scrollTimeOut = setTimeout(function () {
22 self.ScrollSettings();
23 }, 150);
24
25 });
26 rnJQuery('#rednaoPropertySave').click(function () {
27 self.SavePropertyEdition
28 });
29 rnJQuery('#rednaoPropertyCancel').click(function () {
30 self.CloseProperties
31 });
32 rnJQuery('input[name=smartFormsFormEditStyle]').change(function (e) {
33 self.smartFormsFormEditTypeChanged()
34 });
35
36
37 this.RecreateExistingFormIfAny(formElementsOptions);
38
39 this.InitializeTabs();
40 this.InitializeComponents();
41
42 if(smartFormsOptions!=null)
43 FormElementBase.IdCounter=smartFormsOptions.LatestId;
44 else
45 FormElementBase.IdCounter=0;
46 this.DragManager = new RedNaoDragManager(this);
47 };
48
49
50
51 RedNaoFormBuilder.prototype.SmartDonationsPrepareDraggableItems = function () {
52 rnJQuery(".rednaoformbuilder .component,#redNaoElementlist .rednao-control-group").unbind('mousedown');
53 rnJQuery(".rednaoformbuilder .component,#redNaoElementlist .rednao-control-group").mousedown(SmartDonationsFormMouseDownFired);
54
55 rnJQuery(".redNaoDonationButton").unbind('click');
56 rnJQuery(".redNaoDonationButton").click(function () {
57 return false;
58 })
59 }
60
61
62 RedNaoFormBuilder.prototype.RecreateExistingFormIfAny=function(elementOptions)
63 {
64 for(var i=0;i<elementOptions.length;i++)
65 {
66 var element=RedNaoCreateFormElementByName(elementOptions[i].ClassName,elementOptions[i]);
67 this.RedNaoFormElements.push(element);
68 }
69
70
71 var form=rnJQuery("#redNaoElementlist");
72 form.empty();
73 for(var i=0;i<this.RedNaoFormElements.length;i++)
74 {
75 this.RedNaoFormElements[i].AppendElementToContainer(form);
76 }
77
78 form.append('<div class="formelement last" style="height:77px;width:100%"><p>Drop new fields here</p></div>');
79
80 }
81
82
83 /************************************************************************************* Tabs ***************************************************************************************************/
84
85
86
87
88 RedNaoFormBuilder.prototype.smartFormsFormEditTypeChanged = function () {
89 var typeOfEdition = rnJQuery('input[name=smartFormsFormEditStyle]:checked').val();
90
91 if (typeOfEdition == 'Fields') {
92 rnJQuery('#formBuilderComponents').show();
93 rnJQuery('#formPropertiesContainer').hide();
94 }
95
96 if (typeOfEdition == 'Settings') {
97 rnJQuery('#formBuilderComponents').hide();
98 rnJQuery('#formPropertiesContainer').show();
99 }
100
101 }
102
103
104 RedNaoFormBuilder.prototype.OpenProperties = function (element) {
105 rnJQuery('#formRadio2').click();
106
107 this.FillPropertiesPanel(this.RedNaoFormElements[element.index()]);
108 }
109
110 RedNaoFormBuilder.prototype.FillPropertiesPanel = function (element) {
111
112
113 var tableProperties = rnJQuery('#smartFormPropertiesTable');
114 tableProperties.empty();
115
116
117 this.propertiesPanel.find('.popover-title').text(element.Title);
118 element.GeneratePropertiesHtml(tableProperties);
119 }
120
121
122 /************************************************************************************* General Methods ***************************************************************************************************/
123
124
125
126
127 RedNaoFormBuilder.prototype.GetJavascriptObjectOfElement = function (element) {
128 var id = element.attr("id");
129 for (var i = 0; i < RedNaoFormElements.length; i++)
130 if (RedNaoFormElements[i].Id == id) {
131 return RedNaoFormElements[i];
132 }
133 }
134
135 RedNaoFormBuilder.prototype.CreateNewInstanceOfElement = function (element) {
136 var componentType = this.GetComponentType(element);
137 return RedNaoCreateFormElementByName(componentType);
138 }
139
140 RedNaoFormBuilder.prototype.GetComponentType = function (element) {
141 if (rnJQuery(element).children().first().hasClass('rednaotextinput'))
142 return 'rednaotextinput';
143 if (rnJQuery(element).children().first().hasClass('rednaodonationamount'))
144 return 'rednaodonationamount';
145 if (rnJQuery(element).children().first().hasClass('rednaopasswordinput'))
146 return 'rednaopasswordinput';
147 if (rnJQuery(element).children().first().hasClass('rednaosearchinput'))
148 return 'rednaosearchinput';
149 if (rnJQuery(element).children().first().hasClass('rednaoprependedtext'))
150 return 'rednaoprependedtext';
151 if (rnJQuery(element).children().first().hasClass('rednaoappendedtext'))
152 return 'rednaoappendedtext';
153 if (rnJQuery(element).children().first().hasClass('rednaoprependedcheckbox'))
154 return 'rednaoprependedcheckbox';
155 if (rnJQuery(element).children().first().hasClass('rednaoappendedcheckbox'))
156 return 'rednaoappendedcheckbox';
157 if (rnJQuery(element).children().first().hasClass('rednaobuttondropdown'))
158 return 'rednaobuttondropdown';
159 if (rnJQuery(element).children().first().hasClass('tabradioscheckboxes'))
160 return 'tabradioscheckboxes';
161 if (rnJQuery(element).children().first().hasClass('rednaomultiplecheckboxes'))
162 return 'rednaomultiplecheckboxes';
163 if (rnJQuery(element).children().first().hasClass('rednaoselectbasic'))
164 return 'rednaoselectbasic';
165 if (rnJQuery(element).children().first().hasClass('rednaofilebutton'))
166 return 'rednaofilebutton';
167 if (rnJQuery(element).children().first().hasClass('rednaosinglebutton'))
168 return 'rednaosinglebutton';
169 if (rnJQuery(element).children().first().hasClass('rednaodoublebutton'))
170 return 'rednaodoublebutton';
171 if (rnJQuery(element).children().first().hasClass('rednaotitle'))
172 return 'rednaotitle';
173 if (rnJQuery(element).children().first().hasClass('rednaotextarea'))
174 return 'rednaotextarea';
175 if (rnJQuery(element).children().first().hasClass('rednaomultipleradios'))
176 return 'rednaomultipleradios';
177 if (rnJQuery(element).children().first().hasClass('rednaodonationbutton'))
178 return 'rednaodonationbutton';
179 if (rnJQuery(element).children().first().hasClass('rednaodonationrecurrence'))
180 return 'rednaodonationrecurrence';
181 if (rnJQuery(element).children().first().hasClass('rednaosubmissionbutton'))
182 return 'rednaosubmissionbutton';
183 if (rnJQuery(element).children().first().hasClass('rednaodatepicker'))
184 return 'rednaodatepicker';
185 if (rnJQuery(element).children().first().hasClass('rednaoname'))
186 return 'rednaoname';
187 if (rnJQuery(element).children().first().hasClass('rednaoaddress'))
188 return 'rednaoaddress';
189 if (rnJQuery(element).children().first().hasClass('rednaophone'))
190 return 'rednaophone';
191 if (rnJQuery(element).children().first().hasClass('rednaoemail'))
192 return 'rednaoemail';
193 if (rnJQuery(element).children().first().hasClass('rednaonumber'))
194 return 'rednaonumber';
195 if (rnJQuery(element).children().first().hasClass('rednaocaptcha'))
196 return 'rednaocaptcha';
197
198
199 }
200
201
202 /************************************************************************************* Initialization ***************************************************************************************************/
203
204
205
206
207 RedNaoFormBuilder.prototype.InitializeTabs = function () {
208 rnJQuery(".rednaoformbuilder .formtab").click(function (e) {
209
210 var thisJQuery = rnJQuery(this);
211 var tabName = thisJQuery.attr("id");
212 tabName = tabName.substr(1);
213
214 rnJQuery('#navtab').find(".selectedTab").removeClass("selectedTab");
215 thisJQuery.addClass("selectedTab");
216
217 rnJQuery(".rednaoformbuilder .rednaotablist").css("display", "none");
218 rnJQuery(".rednaoformbuilder #" + tabName).css("display", "block");
219
220 });
221 }
222
223 RedNaoFormBuilder.prototype.InitializeComponents = function () {
224 RedNaoCreateFormElementByName('rednaotitle', null).GenerateHtml(rnJQuery("#components .rednaotitle"));
225 RedNaoCreateFormElementByName('rednaotextinput', null).GenerateHtml(rnJQuery("#components .rednaotextinput"));
226 RedNaoCreateFormElementByName('rednaoprependedtext', null).GenerateHtml(rnJQuery("#components .rednaoprependedtext"));
227 RedNaoCreateFormElementByName('rednaoappendedtext', null).GenerateHtml(rnJQuery("#components .rednaoappendedtext"));
228 RedNaoCreateFormElementByName('rednaoprependedcheckbox', null).GenerateHtml(rnJQuery("#components .rednaoprependedcheckbox"));
229 RedNaoCreateFormElementByName('rednaoappendedcheckbox', null).GenerateHtml(rnJQuery("#components .rednaoappendedcheckbox"));
230 RedNaoCreateFormElementByName('rednaotextarea', null).GenerateHtml(rnJQuery("#components .rednaotextarea"));
231 RedNaoCreateFormElementByName('rednaomultipleradios', null).GenerateHtml(rnJQuery("#components .rednaomultipleradios"));
232 RedNaoCreateFormElementByName('rednaomultiplecheckboxes', null).GenerateHtml(rnJQuery("#components .rednaomultiplecheckboxes"));
233 RedNaoCreateFormElementByName('rednaoselectbasic', null).GenerateHtml(rnJQuery("#components .rednaoselectbasic"));
234 RedNaoCreateFormElementByName('rednaodonationamount', null).GenerateHtml(rnJQuery("#components .rednaodonationamount"));
235 RedNaoCreateFormElementByName('rednaodonationbutton', null).GenerateHtml(rnJQuery("#components .rednaodonationbutton"));
236 RedNaoCreateFormElementByName('rednaodonationrecurrence', null).GenerateHtml(rnJQuery("#components .rednaodonationrecurrence"));
237 RedNaoCreateFormElementByName('rednaosubmissionbutton', null).GenerateHtml(rnJQuery("#components .rednaosubmissionbutton"));
238 RedNaoCreateFormElementByName('rednaodatepicker', null).GenerateHtml(rnJQuery("#components .rednaodatepicker"));
239 RedNaoCreateFormElementByName('rednaoname', null).GenerateHtml(rnJQuery("#components .rednaoname"));
240 RedNaoCreateFormElementByName('rednaoaddress', null).GenerateHtml(rnJQuery("#components .rednaoaddress"));
241 RedNaoCreateFormElementByName('rednaophone', null).GenerateHtml(rnJQuery("#components .rednaophone"));
242 RedNaoCreateFormElementByName('rednaoemail', null).GenerateHtml(rnJQuery("#components .rednaoemail"));
243 RedNaoCreateFormElementByName('rednaonumber', null).GenerateHtml(rnJQuery("#components .rednaonumber"));
244 // RedNaoCreateFormElementByName('rednaocaptcha', null).GenerateHtml(rnJQuery("#components .rednaocaptcha"));
245
246
247 var self=this;
248 SmartFormsFieldIsAvailable=function(fieldName)
249 {
250 for(var i=0;i<self.RedNaoFormElements.length;i++)
251 if(self.RedNaoFormElements[i].Id==fieldName)
252 return false;
253
254 return true;
255 }
256
257
258 }
259
260
261 /************************************************************************************* Move Windows On Scroll ***************************************************************************************************/
262
263 RedNaoFormBuilder.prototype.GetFormInformation=function()
264 {
265 var arrayOfOptions=[];
266
267 for(var i=0;i<this.RedNaoFormElements.length;i++)
268 {
269 arrayOfOptions.push(this.RedNaoFormElements[i].Options);
270 }
271 return arrayOfOptions;
272 }
273
274
275 RedNaoFormBuilder.prototype.ScrollSettings = function () {
276 var documentScroll = this.redNaoWindow.scrollTop();
277 var newPosition = Math.max(0, documentScroll - this.formSettingsOriginalTop);
278
279 this.formSettings.animate({
280 top:newPosition
281 }, 500);
282 };
283
284
285 RedNaoFormBuilder.prototype.CloneFormElement=function(jQueryElement){
286 if(this.RedNaoFormElements.length>=7&&!RedNaoLicensingManagerVar.LicenseIsValid('Sorry, this version only support up to 8 fields'))
287 {
288 return;
289 }
290 var formObject=this.RedNaoFormElements[jQueryElement.index()];
291 var newElement= formObject.Clone();
292
293 this.RedNaoFormElements.splice(jQueryElement.index()+1,0,newElement);
294
295 var container=rnJQuery("<div></div>");
296 container.insertAfter(jQueryElement);
297 container=newElement.GenerateHtml(container);
298
299
300 this.DragManager.MakeItemDraggable(container);
301 this.ElementClicked(container);
302 this.OpenProperties(container);
303
304 }
305
306 RedNaoFormBuilder.prototype.ElementClicked=function(jQueryElement)
307 {
308 rnJQuery('#redNaoElementlist').find('.SmartFormsElementSelected').removeClass('SmartFormsElementSelected');
309 rnJQuery('.smartFormsActionMenu').remove();
310
311 jQueryElement.addClass('SmartFormsElementSelected');
312 this.OpenProperties(jQueryElement);
313
314 var actionElement=rnJQuery('<div class="smartFormsActionMenu" ><img id="cloneFormElement" src="'+smartFormsRootPath+'images/clone.png" title="Clone" /><img id="deleteFormElement" src="'+smartFormsRootPath+'images/delete.png" title="Delete"/></div>');
315 var self=this;
316
317
318 jQueryElement.prepend(actionElement);
319
320 actionElement.find('#cloneFormElement').mousedown(function(e){e.preventDefault();e.stopPropagation(); self.CloneFormElement(jQueryElement);});
321 actionElement.find('#deleteFormElement').mousedown(function(e){e.preventDefault();e.stopPropagation(); self.DeleteFormElement(jQueryElement);});
322 }
323
324 RedNaoFormBuilder.prototype.DeleteFormElement=function(jQueryElement){
325 var index=jQueryElement.index();
326 this.RedNaoFormElements.splice(index,1);
327 jQueryElement.remove();
328 }
329
330
331 /*
332 RedNaoFormBuilder.prototype.RefreshForm = function () {
333 var form = rnJQuery("#redNaoElementlist");
334 form.empty();
335 for (var i = 0; i < this.RedNaoFormElements.length; i++) {
336 this.RedNaoFormElements[i].AppendElementToContainer(form);
337 }
338
339 form.append('<div class="rednaoformbuilder formelement last" style="height:77px;width:100%;"></div>');
340 SmartDonationsPrepareDraggableItems();
341 }*/
342
343