PluginProbe
Smart Forms – when you need more than just a contact form / 0.5
Smart Forms – when you need more than just a contact form v0.5
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.5, at js/formBuilder/formbuilder.js

325 lines 12.8 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
186
187 }
188
189
190 /************************************************************************************* Initialization ***************************************************************************************************/
191
192
193
194
195 RedNaoFormBuilder.prototype.InitializeTabs = function () {
196 rnJQuery(".rednaoformbuilder .formtab").click(function (e) {
197
198 var thisJQuery = rnJQuery(this);
199 var tabName = thisJQuery.attr("id");
200 tabName = tabName.substr(1);
201
202 rnJQuery('#navtab').find(".selectedTab").removeClass("selectedTab");
203 thisJQuery.addClass("selectedTab");
204
205 rnJQuery(".rednaoformbuilder .rednaotablist").css("display", "none");
206 rnJQuery(".rednaoformbuilder #" + tabName).css("display", "block");
207
208 });
209 }
210
211 RedNaoFormBuilder.prototype.InitializeComponents = function () {
212 RedNaoCreateFormElementByName('rednaotitle', null).GenerateHtml(rnJQuery("#components .rednaotitle"));
213 RedNaoCreateFormElementByName('rednaotextinput', null).GenerateHtml(rnJQuery("#components .rednaotextinput"));
214 RedNaoCreateFormElementByName('rednaoprependedtext', null).GenerateHtml(rnJQuery("#components .rednaoprependedtext"));
215 RedNaoCreateFormElementByName('rednaoappendedtext', null).GenerateHtml(rnJQuery("#components .rednaoappendedtext"));
216 RedNaoCreateFormElementByName('rednaoprependedcheckbox', null).GenerateHtml(rnJQuery("#components .rednaoprependedcheckbox"));
217 RedNaoCreateFormElementByName('rednaoappendedcheckbox', null).GenerateHtml(rnJQuery("#components .rednaoappendedcheckbox"));
218 RedNaoCreateFormElementByName('rednaotextarea', null).GenerateHtml(rnJQuery("#components .rednaotextarea"));
219 RedNaoCreateFormElementByName('rednaomultipleradios', null).GenerateHtml(rnJQuery("#components .rednaomultipleradios"));
220 RedNaoCreateFormElementByName('rednaomultiplecheckboxes', null).GenerateHtml(rnJQuery("#components .rednaomultiplecheckboxes"));
221 RedNaoCreateFormElementByName('rednaoselectbasic', null).GenerateHtml(rnJQuery("#components .rednaoselectbasic"));
222 RedNaoCreateFormElementByName('rednaodonationamount', null).GenerateHtml(rnJQuery("#components .rednaodonationamount"));
223 RedNaoCreateFormElementByName('rednaodonationbutton', null).GenerateHtml(rnJQuery("#components .rednaodonationbutton"));
224 RedNaoCreateFormElementByName('rednaodonationrecurrence', null).GenerateHtml(rnJQuery("#components .rednaodonationrecurrence"));
225 RedNaoCreateFormElementByName('rednaosubmissionbutton', null).GenerateHtml(rnJQuery("#components .rednaosubmissionbutton"));
226 RedNaoCreateFormElementByName('rednaodatepicker', null).GenerateHtml(rnJQuery("#components .rednaodatepicker"));
227
228
229 var self=this;
230 SmartFormsFieldIsAvailable=function(fieldName)
231 {
232 for(var i=0;i<self.RedNaoFormElements.length;i++)
233 if(self.RedNaoFormElements[i].Id==fieldName)
234 return false;
235
236 return true;
237 }
238
239
240 }
241
242
243 /************************************************************************************* Move Windows On Scroll ***************************************************************************************************/
244
245 RedNaoFormBuilder.prototype.GetFormInformation=function()
246 {
247 var arrayOfOptions=[];
248
249 for(var i=0;i<this.RedNaoFormElements.length;i++)
250 {
251 arrayOfOptions.push(this.RedNaoFormElements[i].Options);
252 }
253 return arrayOfOptions;
254 }
255
256
257 RedNaoFormBuilder.prototype.ScrollSettings = function () {
258 var documentScroll = this.redNaoWindow.scrollTop();
259 var newPosition = Math.max(0, documentScroll - this.formSettingsOriginalTop);
260
261 this.formSettings.animate({
262 top:newPosition
263 }, 500);
264 };
265
266
267 RedNaoFormBuilder.prototype.CloneFormElement=function(jQueryElement){
268 if(this.RedNaoFormElements.length>=7&&!RedNaoLicensingManagerVar.LicenseIsValid('Sorry, this version only support up to 8 fields'))
269 {
270 return;
271 }
272 var formObject=this.RedNaoFormElements[jQueryElement.index()];
273 var newElement= formObject.Clone();
274
275 this.RedNaoFormElements.splice(jQueryElement.index()+1,0,newElement);
276
277 var container=rnJQuery("<div></div>");
278 container.insertAfter(jQueryElement);
279 container=newElement.GenerateHtml(container);
280
281
282 this.DragManager.MakeItemDraggable(container);
283 this.ElementClicked(container);
284 this.OpenProperties(container);
285
286 }
287
288 RedNaoFormBuilder.prototype.ElementClicked=function(jQueryElement)
289 {
290 rnJQuery('#redNaoElementlist').find('.SmartFormsElementSelected').removeClass('SmartFormsElementSelected');
291 rnJQuery('.smartFormsActionMenu').remove();
292
293 jQueryElement.addClass('SmartFormsElementSelected');
294 this.OpenProperties(jQueryElement);
295
296 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>');
297 var self=this;
298
299
300 jQueryElement.prepend(actionElement);
301
302 actionElement.find('#cloneFormElement').mousedown(function(e){e.preventDefault();e.stopPropagation(); self.CloneFormElement(jQueryElement);});
303 actionElement.find('#deleteFormElement').mousedown(function(e){e.preventDefault();e.stopPropagation(); self.DeleteFormElement(jQueryElement);});
304 }
305
306 RedNaoFormBuilder.prototype.DeleteFormElement=function(jQueryElement){
307 var index=jQueryElement.index();
308 this.RedNaoFormElements.splice(index,1);
309 jQueryElement.remove();
310 }
311
312
313 /*
314 RedNaoFormBuilder.prototype.RefreshForm = function () {
315 var form = rnJQuery("#redNaoElementlist");
316 form.empty();
317 for (var i = 0; i < this.RedNaoFormElements.length; i++) {
318 this.RedNaoFormElements[i].AppendElementToContainer(form);
319 }
320
321 form.append('<div class="rednaoformbuilder formelement last" style="height:77px;width:100%;"></div>');
322 SmartDonationsPrepareDraggableItems();
323 }*/
324
325