PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 All 140 releases
← All changes | assets/src/js/admin/learnpress.js +104 -76 4.1.6.9 → 4.4.9 View file →
@@ -1,7 +1,7 @@
1 +import { lpAjaxParseJsonOld } from '../utils';
1 2 const $ = jQuery;
2 3 const $doc = $( document );
3 -const $win = $( window );
4 4
5 5 const makePaymentsSortable = function makePaymentsSortable() {
6 6 // Make payments sortable
7 7 $( '.learn-press-payments.sortable tbody' ).sortable( {
@@ -28,8 +28,9 @@
28 28 url: '',
29 29 data: {
30 30 'lp-ajax': 'update-payment-order',
31 31 order,
32 + nonce: $( 'input[name=lp-settings-nonce]' ).val(),
32 33 },
33 34 success( response ) {
34 35 },
35 36 } );
@@ -139,9 +140,9 @@
139 140
140 141 return false;
141 142 } );
142 143
143 - document.querySelectorAll( '.lp_course_extra_meta_box__fields' ).forEach( ( ele ) => {
144 + /*document.querySelectorAll( '.lp_course_extra_meta_box__fields' ).forEach( ( ele ) => {
144 145 ele.addEventListener( 'keydown', ( e ) => {
145 146 const inputs = ele.querySelectorAll( '.lp_course_extra_meta_box__input' );
146 147
147 148 if ( e.keyCode === 13 ) {
@@ -151,9 +152,9 @@
151 152 } );
152 153 return false;
153 154 }
154 155 } );
155 - } );
156 + } );*/
156 157
157 158 $( '.lp_course_extra_meta_box__fields' ).on( 'click', 'a.delete', function() {
158 159 $( this ).closest( '.lp_course_extra_meta_box__field' ).remove();
159 160
@@ -177,9 +178,9 @@
177 178
178 179 return false;
179 180 } );
180 181
181 - document.querySelectorAll( '.lp_course_faq_meta_box__fields' ).forEach( ( ele ) => {
182 + /*document.querySelectorAll( '.lp_course_faq_meta_box__fields' ).forEach( ( ele ) => {
182 183 ele.addEventListener( 'keydown', ( e ) => {
183 184 const inputs = ele.querySelectorAll( '.lp_course_faq_meta_box__field input' );
184 185 const textareas = ele.querySelectorAll( '.lp_course_faq_meta_box__field textarea' );
185 186
@@ -190,9 +191,9 @@
190 191 } );
191 192 return false;
192 193 }
193 194 } );
194 - } );
195 + } );*/
195 196
196 197 $( '.lp_course_faq_meta_box__fields' ).on( 'click', 'a.delete', function() {
197 198 $( this ).closest( '.lp_course_faq_meta_box__field' ).remove();
198 199
@@ -244,12 +245,8 @@
244 245 } );
245 246 } );
246 247
247 248 const getResponse = async ( btn ) => {
248 - if ( ! lpGlobalSettings.root ) {
249 - return;
250 - }
251 -
252 249 const response = await wp.apiFetch( {
253 250 path: 'lp/v1/admin/course/get_final_quiz',
254 251 method: 'POST',
255 252 data: {
@@ -486,9 +483,9 @@
486 483 } ).trigger( 'lp-metabox-course-tab-panels' );
487 484 };
488 485
489 486 // use to show and hide field condition logic metabox.
490 -const lpMetaboxCondition = () => {
487 +/*const lpMetaboxCondition = () => {
491 488 const fields = document.querySelectorAll( '.lp-meta-box .form-field' );
492 489
493 490 fields.forEach( ( field ) => {
494 491 if ( field.hasAttribute( 'data-show' ) && field.dataset.show ) {
@@ -496,11 +493,11 @@
496 493 } else if ( field.hasAttribute( 'data-hide' ) && field.dataset.hide ) {
497 494 lpMetaboxConditionType( field, field.dataset.hide, 'hide' );
498 495 }
499 496 } );
500 -};
497 +};*/
501 498
502 -const lpMetaboxConditionType = ( field, conditions, typeCondition = 'show' ) => {
499 +/*const lpMetaboxConditionType = ( field, conditions, typeCondition = 'show' ) => {
503 500 const condition = JSON.parse( conditions ),
504 501 eles = document.querySelectorAll( `input[id^="${ condition[ 0 ] }"]` ),
505 502 logic = condition[ 1 ] === '=' ? '=' : '!=',
506 503 dataLogic = condition[ 2 ];
@@ -516,13 +513,13 @@
516 513 val = false;
517 514 }
518 515
519 516 if ( logic == '!=' && val !== Boolean( target ? target.checked : ele.checked ) ) {
520 - field.style.display = typeCondition === 'show' ? 'flex' : 'none';
517 + field.style.display = typeCondition === 'show' ? '' : 'none';
521 518 } else if ( logic == '=' && val == Boolean( target ? target.checked : ele.checked ) ) {
522 - field.style.display = typeCondition === 'show' ? 'flex' : 'none';
519 + field.style.display = typeCondition === 'show' ? '' : 'none';
523 520 } else {
524 - field.style.display = typeCondition === 'show' ? 'none' : 'flex';
521 + field.style.display = typeCondition === 'show' ? 'none' : '';
525 522 }
526 523 break;
527 524 }
528 525 };
@@ -537,9 +534,9 @@
537 534
538 535 switchCase( type, ele, target );
539 536 } );
540 537 } );
541 -};
538 +};*/
542 539
543 540 /** End Nhamdv code */
544 541
545 542 const initTooltips = function initTooltips() {
@@ -551,9 +548,65 @@
551 548 };
552 549
553 550 const initSelect2 = function initSelect2() {
554 551 if ( $.fn.select2 ) {
555 - $( '.lp-select-2 select' ).select2();
552 + const elSelect2 = $( '.lp-select-2 select' );
553 + elSelect2.select2( {
554 + placeholder: 'Select a value',
555 + } );
556 + elSelect2.on( 'change.select2', function( e ) {
557 + const el = $( e.target );
558 + const val = el.val();
559 +
560 + if ( ! val.length ) {
561 + el.val( null );
562 + }
563 + } );
564 +
565 + $( '.lp_autocomplete_metabox_field' ).each( function() {
566 + const dataAtts = $( this ).data( 'atts' );
567 + let action = dataAtts.action;
568 +
569 + if ( ! action ) {
570 + switch ( dataAtts.data ) {
571 + case 'users':
572 + action = dataAtts.rest_url + 'wp/v2/users';
573 + break;
574 + default:
575 + action = dataAtts.rest_url + 'wp/v2/' + dataAtts.data;
576 + break;
577 + }
578 + }
579 +
580 + $( this ).find( 'select' ).select2( {
581 + placeholder: dataAtts.placeholder ? dataAtts.placeholder : 'Select',
582 + ajax: {
583 + url: action,
584 + dataType: 'json',
585 + delay: 250,
586 + beforeSend( xhr ) {
587 + xhr.setRequestHeader( 'X-WP-Nonce', dataAtts.nonce );
588 + },
589 + data( params ) {
590 + return {
591 + search: params.term,
592 + };
593 + },
594 + processResults( data ) {
595 + return {
596 + results: data.map( ( item ) => {
597 + return {
598 + id: item.id,
599 + text: item.title && item.title.rendered ? item.title.rendered : item.name,
600 + };
601 + } ),
602 + };
603 + },
604 + cache: true,
605 + },
606 + minimumInputLength: 2,
607 + } );
608 + } );
556 609 }
557 610 };
558 611
559 612 const initSingleCoursePermalink = function initSingleCoursePermalink() {
@@ -589,11 +642,12 @@
589 642 data: {
590 643 'lp-ajax': 'update-payment-status',
591 644 status,
592 645 id: $row.data( 'payment' ),
646 + nonce: $( 'input[name=lp-settings-nonce]' ).val(),
593 647 },
594 648 success( response ) {
595 - response = LP.parseJSON( response );
649 + response = lpAjaxParseJsonOld( response );
596 650 for ( const i in response ) {
597 651 $( '#payment-' + i + ' .status' ).toggleClass( 'enabled', response[ i ] );
598 652 }
599 653 },
@@ -607,12 +661,13 @@
607 661 data: {
608 662 'lp-ajax': 'update_email_status',
609 663 status: $( this ).parent().hasClass( 'enabled' ) ? 'no' : 'yes',
610 664 id: $( this ).data( 'id' ),
665 + nonce: $( 'input[name=lp-settings-nonce]' ).val(),
611 666 },
612 667 dataType: 'text',
613 668 success: $.proxy( function( res ) {
614 - res = LP.parseJSON( res );
669 + res = lpAjaxParseJsonOld( res );
615 670 for ( const i in res ) {
616 671 $( '#email-' + i + ' .status' ).toggleClass( 'enabled', res[ i ] );
617 672 }
618 673 }, this ),
@@ -626,13 +681,12 @@
626 681 return;
627 682 }
628 683
629 684 $( '.lp_sale_dates_fields' ).each( function() {
630 - const $this = $( this );
631 - const $wrap = $this.closest( 'div.lp-meta-box-course-panels' );
685 + const wrap = $( this ).closest( '#price_course_data' );
632 686 let saleScheduleSet = false;
633 687
634 - $this.find( 'input' ).each( function() {
688 + $( this ).find( 'input' ).each( function() {
635 689 if ( '' !== $( this ).val() ) {
636 690 saleScheduleSet = true;
637 691 }
638 692 } );
@@ -637,18 +691,18 @@
637 691 }
638 692 } );
639 693
640 694 if ( saleScheduleSet ) {
641 - $wrap.find( '.lp_sale_price_schedule' ).hide();
642 - $wrap.find( '.lp_sale_dates_fields' ).show();
695 + wrap.find( '.lp_sale_price_schedule' ).hide();
696 + wrap.find( '.lp_sale_dates_fields' ).show();
643 697 } else {
644 - $wrap.find( '.lp_sale_price_schedule' ).show();
645 - $wrap.find( '.lp_sale_dates_fields' ).hide();
698 + wrap.find( '.lp_sale_price_schedule' ).show();
699 + wrap.find( '.lp_sale_dates_fields' ).hide();
646 700 }
647 701 } );
648 702
649 703 $( '.lp-meta-box-course-panels' ).on( 'click', '.lp_sale_price_schedule', function() {
650 - const wrap = $( this ).closest( 'div.lp-meta-box-course-panels' );
704 + const wrap = $( this ).closest( '#price_course_data' );
651 705
652 706 $( this ).hide();
653 707
654 708 wrap.find( '.lp_cancel_sale_schedule' ).show();
@@ -685,9 +739,9 @@
685 739 }
686 740 }
687 741 } );
688 742
689 - const datePickerSelect = function( datepicker ) {
743 + /*const datePickerSelect = function( datepicker ) {
690 744 const option = $( datepicker ).is( '#_lp_sale_start' ) ? 'minDate' : 'maxDate',
691 745 otherDateField = 'minDate' === option ? $( '#_lp_sale_end' ) : $( '#_lp_sale_start' ),
692 746 date = $( datepicker ).datetimepicker( 'getDate' );
693 747
@@ -708,9 +762,9 @@
708 762
709 763 $( this ).find( 'input' ).each( function() {
710 764 datePickerSelect( $( this ) );
711 765 } );
712 - } );
766 + } );*/
713 767 };
714 768
715 769 const lpHidePassingGrade = () => {
716 770 const listHides = [ 'evaluate_final_quiz', 'evaluate_final_assignment' ];
@@ -774,12 +828,13 @@
774 828 $.ajax( {
775 829 url: '',
776 830 data: {
777 831 'lp-ajax': 'update_email_status',
832 + nonce: $( 'input[name=lp-settings-nonce]' ).val(),
778 833 status,
779 834 },
780 835 success( response ) {
781 - response = LP.parseJSON( response );
836 + response = lpAjaxParseJsonOld( response );
782 837 for ( const i in response ) {
783 838 $( '#email-' + i + ' .status' ).toggleClass( 'enabled', response[ i ] );
784 839 }
785 840 },
@@ -785,51 +840,8 @@
785 840 },
786 841 } );
787 842 };
788 843
789 -const importCourses = function importCourses() {
790 - const $container = $( '#learn-press-install-sample-data-notice' ),
791 - action = $( this ).attr( 'data-action' );
792 - if ( ! action ) {
793 - return;
794 - }
795 - e.preventDefault();
796 -
797 - if ( action === 'yes' ) {
798 - $container
799 - .find( '.install-sample-data-notice' ).slideUp()
800 - .siblings( '.install-sample-data-loading' ).slideDown();
801 - } else {
802 - $container.fadeOut();
803 - }
804 - $.ajax( {
805 - url: ajaxurl,
806 - dataType: 'html',
807 - type: 'post',
808 - data: {
809 - action: 'learnpress_install_sample_data',
810 - yes: action,
811 - },
812 - success( response ) {
813 - response = LP.parseJSON( response );
814 - if ( response.url ) {
815 - $.ajax( {
816 - url: response.url,
817 - success() {
818 - $container
819 - .find( '.install-sample-data-notice' ).html( response.message ).slideDown()
820 - .siblings( '.install-sample-data-loading' ).slideUp();
821 - },
822 - } );
823 - } else {
824 - $container
825 - .find( '.install-sample-data-notice' ).html( response.message ).slideDown()
826 - .siblings( '.install-sample-data-loading' ).slideUp();
827 - }
828 - },
829 - } );
830 -};
831 -
832 844 const onReady = function onReady() {
833 845 makePaymentsSortable();
834 846 initSelect2();
835 847 initTooltips();
@@ -844,9 +856,9 @@
844 856 lpMetaboxsalePriceDate();
845 857 lpMetaboxExtraInfo();
846 858 lpHidePassingGrade();
847 859 lpGetFinalQuiz();
848 - lpMetaboxCondition();
860 + //lpMetaboxCondition();
849 861 lpMetaboxRepeaterField();
850 862
851 863 $( document )
852 864 .on( 'click', '.learn-press-payments .status .dashicons', togglePaymentStatus )
@@ -851,9 +863,25 @@
851 863 $( document )
852 864 .on( 'click', '.learn-press-payments .status .dashicons', togglePaymentStatus )
853 865 .on( 'click', '.change-email-status', updateEmailStatus )
854 866 .on( 'click', '.learn-press-filter-template', callbackFilterTemplates )
855 - .on( 'click', '#learn-press-enable-emails, #learn-press-disable-emails', toggleEmails )
856 - .on( 'click', '#learn-press-install-sample-data-notice a', importCourses );
867 + .on( 'click', '#learn-press-enable-emails, #learn-press-disable-emails', toggleEmails );
857 868 };
858 869
859 870 $( document ).ready( onReady );
871 +
872 +// Events
873 +document.addEventListener( 'keydown', function( e ) {
874 + const target = e.target;
875 + if ( e.key === 'Enter' || e.keyCode === 13 ) {
876 + // When enter on input on Extra information Options, blur it.
877 + if ( target.classList.contains( 'lp_course_extra_meta_box__input' ) ) {
878 + e.preventDefault();
879 + target.blur();
880 + } else if ( target.tagName === 'INPUT' ) {
881 + if ( target.closest( '.lp_course_faq_meta_box__field' ) ) {
882 + e.preventDefault();
883 + target.blur();
884 + }
885 + }
886 + }
887 +} );