|
19 | 19 |
|
20 | 20 | hidden_fields: function hidden_fields() { |
21 | 21 | return this.$store.state.form_fields.filter(function (item) { |
22 | | - return 'custom_hidden_field' === item.template; |
| 22 | + return 'custom_hidden_field' === item.template || 'humanpresence' === item.template; |
23 | 23 | }); |
24 | 24 | }, |
25 | 25 |
|
|
32 | 32 | } |
33 | 33 | }, |
34 | 34 |
|
| 35 | + created: function created() { |
| 36 | + var self = this, |
| 37 | + humanpresence_field_id = 0, |
| 38 | + i = 0; |
| 39 | + for(i = 0; i < self.$store.state.form_fields.length; i++) { |
| 40 | + if (self.$store.state.form_fields[i].template === 'humanpresence') { |
| 41 | + humanpresence_field_id = self.$store.state.form_fields[i].id; |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + wpuf_form_builder.event_hub.$on('humanpresence-changed', this.humanpresence_changed); |
| 46 | + wpuf_form_builder.event_hub.$on('humanpresence-disabled', this.delete_humanpresence_field); |
| 47 | + |
| 48 | + }, |
| 49 | + |
35 | 50 | mounted: function mounted() { |
36 | 51 | var self = this, |
37 | 52 | in_column_field = false; |
|
153 | 168 | }, function () {}); |
154 | 169 | }, |
155 | 170 |
|
| 171 | + delete_field_no_confirm: function delete_field_no_confirm(index) { |
| 172 | + this.$store.commit('delete_form_field_element', index); |
| 173 | + }, |
| 174 | + |
156 | 175 | delete_hidden_field: function delete_hidden_field(field_id) { |
157 | 176 | var i = 0; |
158 | 177 |
|
159 | 178 | for (i = 0; i < this.form_fields.length; i++) { |
160 | 179 | if (parseInt(field_id) === parseInt(this.form_fields[i].id)) { |
161 | | - this.delete_field(i); |
| 180 | + if(this.form_fields[i].template === 'humanpresence'){ |
| 181 | + this.delete_field_no_confirm(i); |
| 182 | + this.disable_humanpresence_setting(); |
| 183 | + } else { |
| 184 | + this.delete_field(i); |
| 185 | + } |
162 | 186 | } |
163 | 187 | } |
164 | 188 | }, |
165 | 189 |
|
| 190 | + delete_humanpresence_field: function delete_humanpresence_field(data) { |
| 191 | + var i = 0; |
| 192 | + if(data.$store.state.form_fields.length) { |
| 193 | + for(i = 0; i < data.$store.state.form_fields.length; i++) { |
| 194 | + if(data.$store.state.form_fields[i].template === 'humanpresence') { |
| 195 | + this.delete_field_no_confirm(i); |
| 196 | + this.disable_humanpresence_setting(); |
| 197 | + } |
| 198 | + } |
| 199 | + } |
| 200 | + }, |
| 201 | + |
| 202 | + disable_humanpresence_setting: function disable_humanpresence_setting() { |
| 203 | + var settings = this.$store.state.settings; |
| 204 | + settings.humanpresence_enabled = false; |
| 205 | + this.$store.commit('set_form_settings', settings); |
| 206 | + }, |
| 207 | + |
| 208 | + humanpresence_changed: function humanpresence_changed(e, data) { |
| 209 | + if(data.$store.state.settings.humanpresence_enabled === 'true'){ |
| 210 | + wpuf_form_builder.event_hub.$emit('humanpresence-enabled', data); |
| 211 | + } else { |
| 212 | + wpuf_form_builder.event_hub.$emit('humanpresence-disabled', data); |
| 213 | + } |
| 214 | + }, |
| 215 | + |
166 | 216 | is_pro_feature: function is_pro_feature(template) { |
167 | 217 | return this.field_settings[template] && this.field_settings[template].pro_feature ? true : false; |
168 | 218 | }, |
|
427 | 477 | return { |
428 | 478 | show_basic_settings: true, |
429 | 479 | show_advanced_settings: false, |
430 | | - show_quiz_settings: false |
| 480 | + show_quiz_settings: false, |
| 481 | + show_humanpresence_settings: false |
431 | 482 | }; |
432 | 483 | }, |
433 | 484 |
|
|
436 | 487 | this.show_basic_settings = true; |
437 | 488 | this.show_advanced_settings = false; |
438 | 489 | this.show_quiz_settings = false; |
| 490 | + this.show_humanpresence_settings = false; |
439 | 491 |
|
440 | 492 | return parseInt(this.$store.state.editing_field_id); |
441 | 493 | }, |
|
503 | 555 | }); |
504 | 556 | }, |
505 | 557 |
|
| 558 | + humanpresence_settings: function humanpresence_settings() { |
| 559 | + return this.settings.filter(function (item) { |
| 560 | + return 'humanpresence' === item.section; |
| 561 | + }); |
| 562 | + }, |
| 563 | + |
506 | 564 | form_field_type_title: function form_field_type_title() { |
507 | 565 | var template = this.editing_form_field.template; |
508 | 566 |
|
|
1195 | 1253 | } |
1196 | 1254 | }, |
1197 | 1255 |
|
| 1256 | + created: function created() { |
| 1257 | + wpuf_form_builder.event_hub.$on('humanpresence-enabled', this.add_humanpresence_field); |
| 1258 | + }, |
| 1259 | + |
1198 | 1260 | mounted: function mounted() { |
1199 | 1261 | // bind jquery ui draggable |
1200 | | - $(this.$el).find('.panel-form-field-buttons .button').draggable({ |
| 1262 | + $(this.$el).find('.panel-form-field-buttons .button').not('[data-form-field="humanpresence"]').draggable({ |
1201 | 1263 | connectToSortable: '#form-preview-stage .wpuf-form, .wpuf-column-inner-fields .wpuf-column-fields-sortable-list', |
1202 | 1264 | helper: 'clone', |
1203 | 1265 | revert: 'invalid', |
|
1240 | 1302 | } |
1241 | 1303 | } |
1242 | 1304 |
|
| 1305 | + if(field_template === 'humanpresence') { |
| 1306 | + var settings = this.$store.state.settings; |
| 1307 | + settings.humanpresence_enabled = true; |
| 1308 | + this.$store.commit('set_form_settings', settings); |
| 1309 | + } |
| 1310 | + |
1243 | 1311 | payload.field = field; |
1244 | 1312 |
|
1245 | 1313 | // add new form element |
1246 | 1314 | this.$store.commit('add_form_field_element', payload); |
1247 | 1315 | }, |
1248 | 1316 |
|
| 1317 | + add_humanpresence_field: function add_humanpresence_field(data) { |
| 1318 | + if(!this.containsField('humanpresence')) { |
| 1319 | + this.add_form_field('humanpresence'); |
| 1320 | + } |
| 1321 | + }, |
| 1322 | + |
1249 | 1323 | is_pro_feature: function is_pro_feature(field) { |
1250 | 1324 | return this.field_settings[field].pro_feature; |
1251 | 1325 | }, |
|
1371 | 1445 | } |
1372 | 1446 | }); |
1373 | 1447 |
|
| 1448 | + /** |
| 1449 | + * Field template: HumanPresence |
| 1450 | + */ |
| 1451 | + Vue.component('form-humanpresence', { |
| 1452 | + template: '#tmpl-wpuf-form-humanpresence', |
| 1453 | + |
| 1454 | + mixins: [wpuf_mixins.form_field_mixin], |
| 1455 | + |
| 1456 | + computed: { |
| 1457 | + has_humanpresence_installed: function has_humanpresence_installed() { |
| 1458 | + return wpuf_form_builder.humanpresence_installed; |
| 1459 | + }, |
| 1460 | + |
| 1461 | + no_humanpresence_installed_msg: function no_humanpresence_installed_msg() { |
| 1462 | + return wpuf_form_builder.field_settings.humanpresence.validator.msg; |
| 1463 | + } |
| 1464 | + } |
| 1465 | + |
| 1466 | + }); |
| 1467 | + |
1374 | 1468 | /** |
1375 | 1469 | * Field template: Section Break |
1376 | 1470 | */ |
|
0 commit comments