| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | /******/ (() => { // webpackBootstrap |
| 2 | 2 | /*!***************************************************!*\ |
| 3 | 3 | !*** ./assets/src/apps/js/admin/pages/widgets.js ***! |
| 4 | 4 | \***************************************************/ |
| @@ -13,67 +13,67 @@ | ||
| 13 | 13 | function formatCourseSelection(repo) { |
| 14 | 14 | return repo.title.rendered || repo.text; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | -/*function autocompleteWidget( widget = null ) { | |
| 18 | - const searchs = $( '.lp-widget_select_course' ); | |
| 19 | - const wpRestUrl = searchs.data( 'rest-url' ); | |
| 20 | - const postType = searchs.data( 'post_type' ) || 'lp_course'; | |
| 21 | - | |
| 22 | - if ( postType === 'lp_course' ) { | |
| 23 | - const dataStruct = { | |
| 24 | - urlApi: Api.admin.apiSearchCourses, | |
| 25 | - dataType: 'courses', | |
| 26 | - keyGetValue: { | |
| 27 | - value: 'ID', | |
| 28 | - text: '{{post_title}} (#{{ID}})', | |
| 29 | - key_render: { | |
| 30 | - post_title: 'post_title', | |
| 31 | - ID: 'ID', | |
| 32 | - }, | |
| 33 | - }, | |
| 34 | - }; | |
| 35 | - const dataStructJson = JSON.stringify( dataStruct ); | |
| 36 | - const widgetListEl = document.querySelector( '#widget-list' ); | |
| 37 | - let nonTomSelectWidgetEls = ''; | |
| 38 | - if ( widgetListEl ) { | |
| 39 | - const tomSelectWidgetEls = Array.prototype.slice.call( widgetListEl.querySelectorAll( '.lp-widget_select_course' ) ); | |
| 40 | - nonTomSelectWidgetEls = Array.prototype.slice.call( searchs ).filter( ( el ) => ! tomSelectWidgetEls.includes( el ) ); | |
| 41 | - } | |
| 42 | - | |
| 43 | - nonTomSelectWidgetEls.forEach( ( nonTomSelectWidgetEl ) => { | |
| 44 | - $( nonTomSelectWidgetEl ).attr( 'data-struct', dataStructJson ); | |
| 45 | - initTomSelect( nonTomSelectWidgetEl ); | |
| 46 | - } ); | |
| 47 | - } else { | |
| 48 | - searchs.select2( { | |
| 49 | - ajax: { | |
| 50 | - method: 'GET', | |
| 51 | - url: wpRestUrl + 'wp/v2/' + postType, | |
| 52 | - dataType: 'json', | |
| 53 | - delay: 250, | |
| 54 | - data( params ) { | |
| 55 | - return { | |
| 56 | - search: params.term, | |
| 57 | - }; | |
| 58 | - }, | |
| 59 | - processResults( data, params ) { | |
| 60 | - params.page = params.page || 1; | |
| 61 | - | |
| 62 | - return { | |
| 63 | - results: data, | |
| 64 | - }; | |
| 65 | - }, | |
| 66 | - cache: true, | |
| 67 | - }, | |
| 68 | - escapeMarkup( markup ) { | |
| 69 | - return markup; | |
| 70 | - }, | |
| 71 | - minimumInputLength: 2, | |
| 72 | - templateResult: formatCourse, // omitted for brevity, see the source of this page | |
| 73 | - templateSelection: formatCourseSelection, // omitted for brevity, see the source of this page | |
| 74 | - } ); | |
| 75 | - } | |
| 17 | +/*function autocompleteWidget( widget = null ) { | |
| 18 | + const searchs = $( '.lp-widget_select_course' ); | |
| 19 | + const wpRestUrl = searchs.data( 'rest-url' ); | |
| 20 | + const postType = searchs.data( 'post_type' ) || 'lp_course'; | |
| 21 | + | |
| 22 | + if ( postType === 'lp_course' ) { | |
| 23 | + const dataStruct = { | |
| 24 | + urlApi: Api.admin.apiSearchCourses, | |
| 25 | + dataType: 'courses', | |
| 26 | + keyGetValue: { | |
| 27 | + value: 'ID', | |
| 28 | + text: '{{post_title}} (#{{ID}})', | |
| 29 | + key_render: { | |
| 30 | + post_title: 'post_title', | |
| 31 | + ID: 'ID', | |
| 32 | + }, | |
| 33 | + }, | |
| 34 | + }; | |
| 35 | + const dataStructJson = JSON.stringify( dataStruct ); | |
| 36 | + const widgetListEl = document.querySelector( '#widget-list' ); | |
| 37 | + let nonTomSelectWidgetEls = ''; | |
| 38 | + if ( widgetListEl ) { | |
| 39 | + const tomSelectWidgetEls = Array.prototype.slice.call( widgetListEl.querySelectorAll( '.lp-widget_select_course' ) ); | |
| 40 | + nonTomSelectWidgetEls = Array.prototype.slice.call( searchs ).filter( ( el ) => ! tomSelectWidgetEls.includes( el ) ); | |
| 41 | + } | |
| 42 | + | |
| 43 | + nonTomSelectWidgetEls.forEach( ( nonTomSelectWidgetEl ) => { | |
| 44 | + $( nonTomSelectWidgetEl ).attr( 'data-struct', dataStructJson ); | |
| 45 | + initTomSelect( nonTomSelectWidgetEl ); | |
| 46 | + } ); | |
| 47 | + } else { | |
| 48 | + searchs.select2( { | |
| 49 | + ajax: { | |
| 50 | + method: 'GET', | |
| 51 | + url: wpRestUrl + 'wp/v2/' + postType, | |
| 52 | + dataType: 'json', | |
| 53 | + delay: 250, | |
| 54 | + data( params ) { | |
| 55 | + return { | |
| 56 | + search: params.term, | |
| 57 | + }; | |
| 58 | + }, | |
| 59 | + processResults( data, params ) { | |
| 60 | + params.page = params.page || 1; | |
| 61 | + | |
| 62 | + return { | |
| 63 | + results: data, | |
| 64 | + }; | |
| 65 | + }, | |
| 66 | + cache: true, | |
| 67 | + }, | |
| 68 | + escapeMarkup( markup ) { | |
| 69 | + return markup; | |
| 70 | + }, | |
| 71 | + minimumInputLength: 2, | |
| 72 | + templateResult: formatCourse, // omitted for brevity, see the source of this page | |
| 73 | + templateSelection: formatCourseSelection, // omitted for brevity, see the source of this page | |
| 74 | + } ); | |
| 75 | + } | |
| 76 | 76 | }*/ |
| 77 | 77 | |
| 78 | 78 | document.addEventListener('DOMContentLoaded', function (event) { |
| 79 | 79 | if (document.querySelector('#widgets-editor')) { |