PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.5.4
Secure Custom Fields v6.5.4
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / assets / src / js / pro / _acf-ui-options-page.js
secure-custom-fields / assets / src / js / pro Last commit date
_acf-blocks.js 1 year ago _acf-field-flexible-content.js 1 year ago _acf-field-gallery.js 1 year ago _acf-field-repeater.js 1 year ago _acf-jsx-names.js 1 year ago _acf-setting-clone.js 1 year ago _acf-setting-flexible-content.js 1 year ago _acf-setting-repeater.js 1 year ago _acf-ui-options-page.js 1 year ago acf-pro-blocks.js 1 year ago acf-pro-field-group.js 1 year ago acf-pro-input.js 1 year ago acf-pro-ui-options-page.js 1 year ago
_acf-ui-options-page.js
206 lines
1 ( function ( $, undefined ) {
2
3 const parentPageSelectTemplate = function ( selection ) {
4 if ( 'undefined' === typeof selection.element ) {
5 return selection;
6 }
7
8 // Hides the optgroup for the "No Parent" option.
9 if ( selection.children && 'None' === selection.text ) {
10 return;
11 }
12
13 if ( 'acfOptionsPages' === selection.text ) {
14 selection.text = acf.__( 'Options Pages' );
15 }
16
17 return $( '<span class="acf-selection"></span>' )
18 .data( 'element', selection.element )
19 .html( acf.strEscape( selection.text ) );
20 };
21
22 const defaultPillTemplate = function ( selection ) {
23 if ( 'undefined' === typeof selection.element ) {
24 return selection;
25 }
26
27 const $selection = $( '<span class="acf-selection"></span>' );
28 $selection.html( acf.strEscape( selection.element.innerHTML ) );
29
30 if (
31 selection.id === 'options' ||
32 selection.id === 'edit_posts'
33 ) {
34 $selection.append(
35 '<span class="acf-select2-default-pill">' +
36 acf.__( 'Default' ) +
37 '</span>'
38 );
39 }
40 $selection.data( 'element', selection.element );
41 return $selection;
42 };
43
44 const UIOptionsPageManager = new acf.Model({
45 id: 'UIOptionsPageManager',
46 wait: 'ready',
47 events: {
48 'change .acf-options-page-parent_slug' : 'toggleMenuPositionDesc',
49 },
50 initialize: function() {
51 if ( 'ui_options_page' !== acf.get( 'screen' ) ) {
52 return;
53 }
54 acf.newSelect2( $( 'select.acf-options-page-parent_slug' ), {
55 field: false,
56 templateSelection: parentPageSelectTemplate,
57 templateResult: parentPageSelectTemplate,
58 dropdownCssClass: 'field-type-select-results'
59 } );
60
61 acf.newSelect2( $( 'select.acf-options-page-capability' ), {
62 field: false,
63 templateSelection: defaultPillTemplate,
64 templateResult: defaultPillTemplate,
65 } );
66
67 acf.newSelect2( $( 'select.acf-options-page-data_storage' ), {
68 field: false,
69 templateSelection: defaultPillTemplate,
70 templateResult: defaultPillTemplate,
71 } );
72
73 this.toggleMenuPositionDesc();
74 },
75
76 toggleMenuPositionDesc: function( e, $el ) {
77 const parentPage = $( 'select.acf-options-page-parent_slug' ).val();
78
79 if ( 'none' === parentPage ) {
80 $( '.acf-menu-position-desc-child' ).hide();
81 $( '.acf-menu-position-desc-parent' ).show();
82 } else {
83 $( '.acf-menu-position-desc-parent' ).hide();
84 $( '.acf-menu-position-desc-child' ).show();
85 }
86 },
87 });
88
89 const optionsPageModalManager = new acf.Model( {
90 id: 'optionsPageModalManager',
91 events: {
92 'change .location-rule-value': 'createOptionsPage',
93 },
94 createOptionsPage: function( e ) {
95 const $locationSelect = $( e.target );
96
97 if ( 'add_new_options_page' !== $locationSelect.val() ) {
98 return;
99 }
100
101 let popup = false;
102
103 const getForm = function() {
104 const fieldGroupTitle = $( '.acf-headerbar-title-field' ).val();
105 const ajaxData = {
106 action: 'acf/create_options_page',
107 acf_parent_page_choices: this.acf.data.optionPageParentOptions ? this.acf.data.optionPageParentOptions : []
108 };
109
110 if ( fieldGroupTitle.length ) {
111 ajaxData.field_group_title = fieldGroupTitle;
112 }
113
114 $.ajax( {
115 url: acf.get( 'ajaxurl' ),
116 data: acf.prepareForAjax( ajaxData ),
117 type: 'post',
118 dataType: 'json',
119 success: populateForm,
120 } );
121 };
122
123 const populateForm = function( response ) {
124 popup = acf.newPopup( {
125 title: response.data.title,
126 content: response.data.content,
127 width: '600px',
128 } );
129
130 popup.$el.addClass( 'acf-create-options-page-popup' );
131
132 // Hack to focus with the cursor at the end of the input.
133 const $pageTitle = popup.$el.find( '#acf_ui_options_page-page_title' );
134 const pageTitleVal = $pageTitle.val();
135 $pageTitle.focus().val( '' ).val( pageTitleVal );
136
137 acf.newSelect2( $( '#acf_ui_options_page-parent_slug' ), {
138 field: false,
139 templateSelection: parentPageSelectTemplate,
140 templateResult: parentPageSelectTemplate,
141 dropdownCssClass: 'field-type-select-results'
142 } );
143
144 popup.on( 'submit', 'form', validateForm );
145 };
146
147 const validateForm = function( e ) {
148 e.preventDefault();
149
150 acf.validateForm( {
151 form: $( '#acf-create-options-page-form' ),
152 success: submitForm,
153 failure: onFail
154 } );
155 }
156
157 const submitForm = function() {
158 const formValues = $( '#acf-create-options-page-form' ).serializeArray();
159 const ajaxData = {
160 action: 'acf/create_options_page'
161 };
162
163 formValues.forEach( setting => {
164 ajaxData[ setting.name ] = setting.value;
165 } );
166
167 $.ajax( {
168 url: acf.get( 'ajaxurl' ),
169 data: acf.prepareForAjax( ajaxData ),
170 type: 'post',
171 dataType: 'json',
172 success: populateLocationSelect,
173 } );
174 };
175
176 const onFail = function( e ) {
177 const $form = $( '#acf-create-options-page-form' );
178 const $fieldNotices = $form.find( '.acf-field .acf-error-message' );
179
180 // Hide the general validation failed notice.
181 $form.find( '.acf-notice' ).first().remove();
182
183 // Update class for inline notices and move into field label.
184 $fieldNotices.each( function() {
185 const $label = $( this ).closest( '.acf-field' ).find( '.acf-label:first' );
186 $( this ).attr( 'class', 'acf-options-page-modal-error' ).appendTo( $label );
187 } );
188 };
189
190 const populateLocationSelect = function( response ) {
191 if ( response.success && response.data.menu_slug ) {
192 $locationSelect.prepend(
193 '<option value="' + response.data.menu_slug + '">' + response.data.page_title + '</option>'
194 );
195 $locationSelect.val( response.data.menu_slug );
196 popup.close();
197 } else if ( ! response.success && response.data.error ) {
198 alert(response.data.error);
199 }
200 };
201
202 getForm();
203 },
204 } );
205
206 } )( jQuery );