PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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 4.2.0 All 139 releases
← All changes | assets/src/js/admin/learnpress.js +44 -68 4.2.04.4.8 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
@@ -482,9 +483,9 @@
482 483 } ).trigger( 'lp-metabox-course-tab-panels' );
483 484 };
484 485
485 486 // use to show and hide field condition logic metabox.
486 -const lpMetaboxCondition = () => {
487 +/*const lpMetaboxCondition = () => {
487 488 const fields = document.querySelectorAll( '.lp-meta-box .form-field' );
488 489
489 490 fields.forEach( ( field ) => {
490 491 if ( field.hasAttribute( 'data-show' ) && field.dataset.show ) {
@@ -492,11 +493,11 @@
492 493 } else if ( field.hasAttribute( 'data-hide' ) && field.dataset.hide ) {
493 494 lpMetaboxConditionType( field, field.dataset.hide, 'hide' );
494 495 }
495 496 } );
496 -};
497 +};*/
497 498
498 -const lpMetaboxConditionType = ( field, conditions, typeCondition = 'show' ) => {
499 +/*const lpMetaboxConditionType = ( field, conditions, typeCondition = 'show' ) => {
499 500 const condition = JSON.parse( conditions ),
500 501 eles = document.querySelectorAll( `input[id^="${ condition[ 0 ] }"]` ),
501 502 logic = condition[ 1 ] === '=' ? '=' : '!=',
502 503 dataLogic = condition[ 2 ];
@@ -533,9 +534,9 @@
533 534
534 535 switchCase( type, ele, target );
535 536 } );
536 537 } );
537 -};
538 +};*/
538 539
539 540 /** End Nhamdv code */
540 541
541 542 const initTooltips = function initTooltips() {
@@ -641,11 +642,12 @@
641 642 data: {
642 643 'lp-ajax': 'update-payment-status',
643 644 status,
644 645 id: $row.data( 'payment' ),
646 + nonce: $( 'input[name=lp-settings-nonce]' ).val(),
645 647 },
646 648 success( response ) {
647 - response = LP.parseJSON( response );
649 + response = lpAjaxParseJsonOld( response );
648 650 for ( const i in response ) {
649 651 $( '#payment-' + i + ' .status' ).toggleClass( 'enabled', response[ i ] );
650 652 }
651 653 },
@@ -659,12 +661,13 @@
659 661 data: {
660 662 'lp-ajax': 'update_email_status',
661 663 status: $( this ).parent().hasClass( 'enabled' ) ? 'no' : 'yes',
662 664 id: $( this ).data( 'id' ),
665 + nonce: $( 'input[name=lp-settings-nonce]' ).val(),
663 666 },
664 667 dataType: 'text',
665 668 success: $.proxy( function( res ) {
666 - res = LP.parseJSON( res );
669 + res = lpAjaxParseJsonOld( res );
667 670 for ( const i in res ) {
668 671 $( '#email-' + i + ' .status' ).toggleClass( 'enabled', res[ i ] );
669 672 }
670 673 }, this ),
@@ -678,13 +681,12 @@
678 681 return;
679 682 }
680 683
681 684 $( '.lp_sale_dates_fields' ).each( function() {
682 - const $this = $( this );
683 - const $wrap = $this.closest( 'div.lp-meta-box-course-panels' );
685 + const wrap = $( this ).closest( '#price_course_data' );
684 686 let saleScheduleSet = false;
685 687
686 - $this.find( 'input' ).each( function() {
688 + $( this ).find( 'input' ).each( function() {
687 689 if ( '' !== $( this ).val() ) {
688 690 saleScheduleSet = true;
689 691 }
690 692 } );
@@ -689,18 +691,18 @@
689 691 }
690 692 } );
691 693
692 694 if ( saleScheduleSet ) {
693 - $wrap.find( '.lp_sale_price_schedule' ).hide();
694 - $wrap.find( '.lp_sale_dates_fields' ).show();
695 + wrap.find( '.lp_sale_price_schedule' ).hide();
696 + wrap.find( '.lp_sale_dates_fields' ).show();
695 697 } else {
696 - $wrap.find( '.lp_sale_price_schedule' ).show();
697 - $wrap.find( '.lp_sale_dates_fields' ).hide();
698 + wrap.find( '.lp_sale_price_schedule' ).show();
699 + wrap.find( '.lp_sale_dates_fields' ).hide();
698 700 }
699 701 } );
700 702
701 703 $( '.lp-meta-box-course-panels' ).on( 'click', '.lp_sale_price_schedule', function() {
702 - const wrap = $( this ).closest( 'div.lp-meta-box-course-panels' );
704 + const wrap = $( this ).closest( '#price_course_data' );
703 705
704 706 $( this ).hide();
705 707
706 708 wrap.find( '.lp_cancel_sale_schedule' ).show();
@@ -737,9 +739,9 @@
737 739 }
738 740 }
739 741 } );
740 742
741 - const datePickerSelect = function( datepicker ) {
743 + /*const datePickerSelect = function( datepicker ) {
742 744 const option = $( datepicker ).is( '#_lp_sale_start' ) ? 'minDate' : 'maxDate',
743 745 otherDateField = 'minDate' === option ? $( '#_lp_sale_end' ) : $( '#_lp_sale_start' ),
744 746 date = $( datepicker ).datetimepicker( 'getDate' );
745 747
@@ -760,9 +762,9 @@
760 762
761 763 $( this ).find( 'input' ).each( function() {
762 764 datePickerSelect( $( this ) );
763 765 } );
764 - } );
766 + } );*/
765 767 };
766 768
767 769 const lpHidePassingGrade = () => {
768 770 const listHides = [ 'evaluate_final_quiz', 'evaluate_final_assignment' ];
@@ -826,12 +828,13 @@
826 828 $.ajax( {
827 829 url: '',
828 830 data: {
829 831 'lp-ajax': 'update_email_status',
832 + nonce: $( 'input[name=lp-settings-nonce]' ).val(),
830 833 status,
831 834 },
832 835 success( response ) {
833 - response = LP.parseJSON( response );
836 + response = lpAjaxParseJsonOld( response );
834 837 for ( const i in response ) {
835 838 $( '#email-' + i + ' .status' ).toggleClass( 'enabled', response[ i ] );
836 839 }
837 840 },
@@ -837,51 +840,8 @@
837 840 },
838 841 } );
839 842 };
840 843
841 -const importCourses = function importCourses() {
842 - const $container = $( '#learn-press-install-sample-data-notice' ),
843 - action = $( this ).attr( 'data-action' );
844 - if ( ! action ) {
845 - return;
846 - }
847 - e.preventDefault();
848 -
849 - if ( action === 'yes' ) {
850 - $container
851 - .find( '.install-sample-data-notice' ).slideUp()
852 - .siblings( '.install-sample-data-loading' ).slideDown();
853 - } else {
854 - $container.fadeOut();
855 - }
856 - $.ajax( {
857 - url: ajaxurl,
858 - dataType: 'html',
859 - type: 'post',
860 - data: {
861 - action: 'learnpress_install_sample_data',
862 - yes: action,
863 - },
864 - success( response ) {
865 - response = LP.parseJSON( response );
866 - if ( response.url ) {
867 - $.ajax( {
868 - url: response.url,
869 - success() {
870 - $container
871 - .find( '.install-sample-data-notice' ).html( response.message ).slideDown()
872 - .siblings( '.install-sample-data-loading' ).slideUp();
873 - },
874 - } );
875 - } else {
876 - $container
877 - .find( '.install-sample-data-notice' ).html( response.message ).slideDown()
878 - .siblings( '.install-sample-data-loading' ).slideUp();
879 - }
880 - },
881 - } );
882 -};
883 -
884 844 const onReady = function onReady() {
885 845 makePaymentsSortable();
886 846 initSelect2();
887 847 initTooltips();
@@ -896,9 +856,9 @@
896 856 lpMetaboxsalePriceDate();
897 857 lpMetaboxExtraInfo();
898 858 lpHidePassingGrade();
899 859 lpGetFinalQuiz();
900 - lpMetaboxCondition();
860 + //lpMetaboxCondition();
901 861 lpMetaboxRepeaterField();
902 862
903 863 $( document )
904 864 .on( 'click', '.learn-press-payments .status .dashicons', togglePaymentStatus )
@@ -903,9 +863,25 @@
903 863 $( document )
904 864 .on( 'click', '.learn-press-payments .status .dashicons', togglePaymentStatus )
905 865 .on( 'click', '.change-email-status', updateEmailStatus )
906 866 .on( 'click', '.learn-press-filter-template', callbackFilterTemplates )
907 - .on( 'click', '#learn-press-enable-emails, #learn-press-disable-emails', toggleEmails )
908 - .on( 'click', '#learn-press-install-sample-data-notice a', importCourses );
867 + .on( 'click', '#learn-press-enable-emails, #learn-press-disable-emails', toggleEmails );
909 868 };
910 869
911 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 +} );