PluginProbe
Hello Plus / 1.2.0
Hello Plus v1.2.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / modules / forms / assets / js / editor / fields-repeater-control.js

fields-repeater-control.js in Hello Plus 1.2.0, at modules/forms/assets/js/editor/fields-repeater-control.js

104 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import RepeaterRowView from './fields-repeater-row';
2
3 export default class extends elementor.modules.controls.Repeater {
4 className() {
5 let classes = super.className();
6
7 classes += ' elementor-control-type-repeater';
8
9 return classes;
10 }
11
12 getChildView() {
13 return RepeaterRowView;
14 }
15
16 initialize( ...args ) {
17 super.initialize( ...args );
18
19 const formFields = this.container.settings.get( 'form_fields' );
20
21 this
22 .listenTo( formFields, 'change', ( model ) => this.onFormFieldChange( model ) )
23 .listenTo( formFields, 'remove', ( model ) => this.onFormFieldRemove( model ) );
24 }
25
26 getFirstChild() {
27 return this.children.findByModel( this.collection.models[ 0 ] );
28 }
29
30 lockFirstStep() {
31 const firstChild = this.getFirstChild();
32
33 if ( 'step' !== firstChild.model.get( 'field_type' ) ) {
34 return;
35 }
36
37 const stepFields = this.collection.where( { field_type: 'step' } );
38
39 if ( 1 < stepFields.length ) {
40 firstChild.toggleFieldTypeControl( false );
41
42 firstChild.toggleTools( false );
43 }
44
45 firstChild.toggleSort( false );
46 }
47
48 onFormFieldChange( model ) {
49 const fieldType = model.changed.field_type;
50
51 if ( ! fieldType || ( 'step' !== fieldType && 'step' !== model._previousAttributes.field_type ) ) {
52 return;
53 }
54
55 const isStep = 'step' === fieldType;
56
57 this.children.findByModel( model ).toggleStepField( isStep );
58
59 this.onStepFieldChanged( isStep );
60 }
61
62 onFormFieldRemove( model ) {
63 if ( 'step' === model.get( 'field_type' ) ) {
64 this.onStepFieldChanged( false );
65 }
66 }
67
68 onStepFieldChanged( isStep ) {
69 if ( isStep ) {
70 this.lockFirstStep();
71
72 return;
73 }
74
75 const stepFields = this.collection.where( { field_type: 'step' } );
76
77 if ( stepFields.length > 1 ) {
78 return;
79 }
80
81 const firstChild = this.getFirstChild();
82
83 if ( 1 === stepFields.length ) {
84 firstChild.toggleTools( true );
85
86 firstChild.toggleFieldTypeControl( true );
87
88 return;
89 }
90
91 firstChild.toggleSort( true );
92 }
93
94 onAddChild( childView ) {
95 super.onAddChild( childView );
96
97 if ( 'step' === childView.model.get( 'field_type' ) ) {
98 this.lockFirstStep();
99
100 childView.toggleStepField( true );
101 }
102 }
103 }
104