Skip to content

Commit 318caa3

Browse files
committed
modules v2
1 parent ecf7b62 commit 318caa3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4686
-1936
lines changed

Form.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,12 @@ public static function radio($form, $model, $field){
226226
* @return $this The field object itself.
227227
*/
228228
public static function checkbox($form, $model, $field){
229-
230-
231229
$items = [];
232230
$checked = [];
233231

234232
foreach ($field['items'] as $key => $value) {
235-
$items[$value['value']] = $value['text'];
233+
234+
$items[$value['value']] = $value['text'];
236235
if (isset($value['checked'])){
237236
$checked[] = $key+1;
238237
}

FormBuilder.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Generate forms and create tables from json object
1717
*
1818
* @author Rafal Marguzewicz <info@pceuropa.net>
19-
* @version 1.4.1
19+
* @version 1.5
2020
* @license MIT
2121
*
2222
* https://github.com/pceuropa/yii2-forms
@@ -47,7 +47,13 @@ class FormBuilder extends Widget {
4747

4848
public $easy_mode = true;
4949

50+
/**
51+
* @var bool If true - form can send email response
52+
* @since 1.4
53+
*/
5054

55+
public $email_response = false;
56+
5157
/**
5258
* @var array Configuration data from widget/user
5359
* @since 1.0
@@ -96,6 +102,7 @@ public function init() {
96102
$this->options = [
97103
'easy_mode' => $this->easy_mode,
98104
'test_mode' => $this->test_mode,
105+
'email_response' => $this->email_response,
99106
'update' => false,
100107
'config' => $this->config
101108
];

FormBuilderAsset.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Asset bundle for formbuilder
55
*
66
* @author Rafal Marguzewicz <info@pceuropa.net>
7-
* @version 1.4.1
7+
* @version 1.5
88
* @license MIT
99
*
1010
* https://github.com/pceuropa/yii2-forum
@@ -26,8 +26,11 @@ class FormBuilderAsset extends \yii\web\AssetBundle {
2626
'js/forms/form.js',
2727
'js/forms/field.js',
2828
'js/forms/controller.js',
29+
30+
'js/forms/form.module.response.js',
2931
'js/forms/examples.js',
3032
'js/forms/test.js',
33+
3134
'js/forms/clipboard.min.js',
3235
'https://cdn.quilljs.com/1.2.0/quill.js',
3336
'js/forms/clipboard.min.js',

assets/form-builder/js/forms/controller.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,26 @@ var quill = new Quill('#textdescription', {
4848
//Actions:
4949
// 1. -------- FORM -----------------
5050
preview_form
51-
.delegate('.edit', 'click', function(e){ edit(e) })
52-
.delegate('.clone', 'click', function(e){ clone(e) })
53-
.delegate('.delete', 'click', function(e){ del(e) });
51+
.on('click', '.edit', function(e){ edit(e) })
52+
.on('click', '.clone', function(e){ clone(e) })
53+
.on('click', '.delete', function(e){ del(e) })
54+
.on('click', 'button', function(e){ e.preventDefault();
55+
56+
var button = $(this), clone = button.clone();
57+
button.text('edit mode');
58+
window.setTimeout(function() {button.replaceWith(clone);}, 1111)
59+
});
5460

5561
// 2-1-a view-mode
56-
$('#tabs')
57-
.on('click', 'li', function(e){ activeTab(e.target);});
5862

5963
$('#view-mode')
6064
.change(function (){
6165
form.setView(this.value);
6266
form.render('off');
6367
})
6468

69+
70+
6571
sidebar_div_options
6672
.on('click', '#add-to-form', function(){ form.add( field.body) })
6773
.on('click', '.add-item', function(){ addItem() } )
@@ -75,8 +81,8 @@ sidebar_div_options
7581
.on('mouseenter','#widget-form-options', function(e){ preventEmptyTitleUrl(e) })
7682

7783
$('#sidebar')
78-
.on('click', '#form-tab', function(){ activeAction('#form') })
79-
.on('click', '#field-tab', function(){ select_field.change() })
84+
.on('click', '#form-tab', function(e){ activeTab(e.target); activeAction('#form') })
85+
.on('click', '#field-tab', function(e){ activeTab(e.target); select_field.change() })
8086
.on('click', '#save-form', function(){ form.save() })
8187

8288

assets/form-builder/js/forms/examples.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var MyFORM = MyFORM || {};
22
//#Copyright (c) 2016-2017 Rafal Marguzewicz pceuropa.net
33

4-
MyFORM.template = function (form){
4+
MyFORM.examples = function (form){
55

66
var version = '1.2.4',
77
id_selector = "#examples-form",
@@ -428,15 +428,15 @@ temp = [
428428

429429
var div1 = document.createElement("div"),
430430

431-
innerHTML = '<label class="col-sm-4 control-label">Examples</label>' +
432-
'<div class="col-sm-8">' +
433-
'<select id="examples-form" class="form-control input-sm"><option>-</option> </select><div id="section-confirm"></div>' +
434-
'</div> ';
431+
innerHTML = '<label class="col-sm-3 control-label">Examples</label>' +
432+
'<div class="col-sm-6">' +
433+
'<select id="examples-form" class="form-control"><option>-</option> </select>'+
434+
'</div><div id="section-confirm"></div>';
435435

436436

437437

438438
(function(){
439-
div1.setAttribute('class', 'form-group');
439+
div1.setAttribute('class', 'row form-group-sm');
440440
div1.innerHTML = innerHTML;
441441

442442
$(div1).find(id_selector).append( function() {
@@ -458,7 +458,7 @@ var div1 = document.createElement("div"),
458458

459459
$("#form #widget-form-options").append( div1.outerHTML ).on( "change", id_selector, function() {
460460
var value = this.value;
461-
$("#section-confirm").empty().html( '<button id="confirm-example" type="button" class="btn btn-warning">Confirm</button>' );
461+
$("#section-confirm").empty().html( '<button id="confirm-example" type="button" class="btn btn-sm btn-warning">Confirm</button>' );
462462
$("#confirm-example").click(function () {
463463
form.body = temp[value].body
464464
form.render()

assets/form-builder/js/forms/field.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ factory.prototype = {
139139
rowsAttr: function () {
140140
return this.body.rows ? ' rows="'+ this.body.rows + '"' : '';
141141
},
142-
checkedAttr: function () {
143-
return this.body.checked ? ' checked' : '';
144-
},
142+
145143
requireAttr: function () {
146144
return this.body.require ? ' required' : '';
147145
},
148-
checkedAttr: function () {
149-
return this.body.require ? ' checked' : '';
146+
147+
checkedAttr: function() {
148+
return this.body.require ? ' checked' : '' ;
150149
},
150+
151151
helpBlockAttr: function () {
152152
return this.body.helpBlock ? '\n\t<span class="help-block">' + this.body.helpBlock + '</span>' : '';
153153
},

assets/form-builder/js/forms/form.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@
77

88
var MyFORM = MyFORM || {};
99
MyFORM = (function(){
10-
console.log('form: 1.3.0');
10+
console.log('form: 1.5.0');
1111
var fields_with_data = [], // array for false autosave
12+
1213
Form = function (){
13-
1414
//this.url = null;
1515
this.title = "FormBuilder";
1616
//this.action = "";
1717
this.method = "post";
1818
this.language = "English";
1919
this.body = [];
20-
21-
2220
};
2321

2422
Form.prototype = {
@@ -49,6 +47,7 @@ var fields_with_data = [], // array for false autosave
4947
this.autosaveButton();
5048
Form.prototype.time_out = 800;
5149
}
50+
5251
return MyFORM.controller(this, new MyFORM.field.factory() );
5352

5453
},
@@ -147,6 +146,7 @@ var fields_with_data = [], // array for false autosave
147146

148147
},
149148

149+
150150
successSave: function() {
151151

152152
var save_form = $( "#save-form" ), clone = save_form.clone();
@@ -209,6 +209,7 @@ var fields_with_data = [], // array for false autosave
209209
fields_with_data.push(name);
210210
return name;
211211
},
212+
212213
post: function (o) {
213214
if (this.c.autosave && o.hasOwnProperty('name')){
214215
$.post( this.c.controller_url, {add: o}, function (r) {
@@ -289,19 +290,35 @@ var fields_with_data = [], // array for false autosave
289290
*/
290291

291292
generate: function(o){
293+
var result = false;
292294
h.inheritAll(this, o);
295+
this.setValueInputOptions();
296+
fields_with_data = h.getAllProperty('name', this.body);
293297
if(this.body.length !== 0) this.render('off')
294298

295-
this.setValueInputOptions();
296-
fields_with_data = h.getAllProperty('name', this.body);
297-
console.log(fields_with_data);
298299

299300
},
301+
302+
modules: {
303+
init: function () {
304+
},
305+
306+
},
307+
308+
executeModules: function () {
309+
for (var prop in this.modules) {
310+
if (this.modules.hasOwnProperty(prop)){
311+
this.modules[prop]();
312+
console.log('execute module ' + prop);
313+
314+
}
315+
}
316+
},
300317

301-
302-
/**
303-
* Render form
304-
*/
318+
servicesAfter: function () {
319+
320+
},
321+
305322
render: function(){
306323
var form = this;
307324

@@ -320,7 +337,8 @@ var fields_with_data = [], // array for false autosave
320337
})
321338
}
322339
this.preventNotValidaData();
323-
340+
this.executeModules();
341+
this.servicesAfter();
324342
},
325343
// default save button if title or url are empty
326344
preventNotValidaData: function () {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var
2+
MyFORM = MyFORM || {};
3+
//#Copyright (c) 2016-2017 Rafal Marguzewicz pceuropa.net
4+
5+
/**
6+
* Add module send respond message if in form is field
7+
*
8+
* @param {Form} form
9+
* @param {String} field Optional name of field which active responde textarea
10+
* @return {String}
11+
*/
12+
13+
MyFORM.response = function (form, field){
14+
15+
var html = '<div class="row form-group-sm"> ' +
16+
'<label class="col-sm-3 control-label">Text respond</label> ' +
17+
'<div class="col-sm-9"> ' +
18+
'<textarea id="response" class="form-control input-sm" rows="5" disabled>Respond work if in form is field with name email</textarea> ' +
19+
'</div> ' +
20+
'</div>';
21+
field = field || 'email';
22+
23+
$("#widget-form-options").append(html);
24+
25+
return function(){
26+
fields_with_data = h.getAllProperty('name', form.body);
27+
28+
for (var i = 0; i < fields_with_data.length; i++) {
29+
30+
if (fields_with_data[i] === field){
31+
$('#response').prop('disabled', false); break;
32+
}
33+
$('#response').prop('disabled', true);
34+
}
35+
}
36+
}

assets/form-builder/js/forms/forms.min.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)