PluginProbe ʕ •ᴥ•ʔ
Slider Ultimate / 2.0.8
Slider Ultimate v2.0.8
trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9
ultimate-slider / lib / simple-admin-pages / js / infinite_table.js
ultimate-slider / lib / simple-admin-pages / js Last commit date
address.js 4 years ago admin-settings.js 4 years ago count.js 4 years ago file_upload.js 4 years ago image.js 4 years ago infinite_table.js 4 years ago opening-hours.js 4 years ago ordering.js 4 years ago scheduler.js 4 years ago spectrum.js 4 years ago
infinite_table.js
102 lines
1 /**
2 * Javascript functions for Infinite Table
3 *
4 * @package Simple Admin Pages
5 */
6
7 jQuery(document).ready(function ($) {
8
9 // disable options where not required initially
10 $('.sap-infinite-table table tbody tr').each((idx_tr, tr) => {
11 let val = $(tr).find('[data-name="cf_type"]').val();
12
13 if(!['dropdown', 'checkbox', 'radio'].includes(val)) {
14 $(tr).find('[data-name="cf_options"]').val('').prop('readonly', true);
15 }
16 });
17
18 // process fields
19 $('.sap-parent-form').on('submit', function (ev) {
20 var _form = $(this), ignore;
21
22 $('.sap-infinite-table').each( function() {
23
24 var main_input = $(this).find('#sap-infinite-table-main-input');
25
26 var main_input_val = [];
27
28 $(this).find('table tbody tr').each((idx_tr, tr) => {
29 let record = {}; ignore = false;
30
31 $(tr).find('td').each((idx_td, td) => {
32 let elm = $(td).find('select, input, textarea, checkbox');
33
34 ignore = 'cf_field_name' == elm.data('name') && elm.val().length < 1 ? true : ignore;
35
36 if(!ignore) {
37
38 if ( elm.prop( 'type' ) == 'checkbox' ) { record[ elm.data('name') ] = elm.is( ':checked' ); }
39 else { record[elm.data('name')] = elm.val(); }
40 }
41 });
42
43 !ignore ? main_input_val.push(record) : null;
44 });
45
46 main_input.val(JSON.stringify(main_input_val));
47
48 });
49 });
50
51 // Add new field
52 $('.sap-infinite-table-add-row .sap-new-admin-add-button').on('click', function (ev) {
53 let rowid = 1;
54 let _list = [];
55 $( this ).parents( 'tfoot' ).siblings( 'tbody' ).find( 'tr td' ).each((i, x) => {
56 let f_type = $(x).data( 'field-type' );
57 if( 'id' == f_type ) {
58 _list.push( parseInt( $(x).find( '.sap-infinite-table-id-html' ).eq(0).html() ) );
59 }
60 });
61
62 _list.sort();
63 if( 0 < _list.length ) {
64 rowid = _list[ _list.length - 1 ] + 1;
65 }
66
67 let _template_tr = $( this ).parents( 'tfoot' ).find( '.sap-infinite-table-row-template' ).clone();
68 _template_tr
69 .hide()
70 .removeClass()
71 .addClass( 'sap-infinite-table-row' );
72
73 $( this ).parents( 'table' ).first().find( 'tbody' ).append( _template_tr );
74 _template_tr.find( '.sap-infinite-table-id-html' ).eq(0).siblings( 'input' ).val( rowid );
75 _template_tr.find( '.sap-infinite-table-id-html' ).eq(0).html( rowid );
76 _template_tr.fadeIn( 'fast' );
77 _template_tr.find( '[data-name="cf_options"]' ).prop( 'readonly' , true );
78 });
79
80 // update options field
81 $(document).on('change', '.sap-infinite-table-row [data-name="cf_type"]', function (ev) {
82 let parent_tr = $(this).parents('tr').eq(0);
83
84 if(!['dropdown', 'checkbox', 'radio'].includes($(this).val())) {
85 parent_tr.find('[data-name="cf_options"]').val('').prop('readonly', true);
86 }
87 else {
88 parent_tr.find('[data-name="cf_options"]').prop('readonly', false);
89 }
90 });
91
92 // Remvoe field
93 $(document).on('click', '.sap-infinite-table-row .sap-infinite-table-row-delete', function (ev) {
94 let parent_tr = $(this).parents('tr').eq(0);
95 parent_tr.fadeOut('fast', () => parent_tr.remove());
96 });
97
98 $('.sap-infinite-table table tbody').sortable({
99 axis: 'y'
100 });
101
102 })