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 -72 4.1.7.24.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
@@ -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 ];
@@ -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() {
@@ -645,11 +642,12 @@
645 642 data: {
646 643 'lp-ajax': 'update-payment-status',
647 644 status,
648 645 id: $row.data( 'payment' ),
646 + nonce: $( 'input[name=lp-settings-nonce]' ).val(),
649 647 },
650 648 success( response ) {
651 - response = LP.parseJSON( response );
649 + response = lpAjaxParseJsonOld( response );
652 650 for ( const i in response ) {
653 651 $( '#payment-' + i + ' .status' ).toggleClass( 'enabled', response[ i ] );
654 652 }
655 653 },
@@ -663,12 +661,13 @@
663 661 data: {
664 662 'lp-ajax': 'update_email_status',
665 663 status: $( this ).parent().hasClass( 'enabled' ) ? 'no' : 'yes',
666 664 id: $( this ).data( 'id' ),
665 + nonce: $( 'input[name=lp-settings-nonce]' ).val(),
667 666 },
668 667 dataType: 'text',
669 668 success: $.proxy( function( res ) {
670 - res = LP.parseJSON( res );
669 + res = lpAjaxParseJsonOld( res );
671 670 for ( const i in res ) {
672 671 $( '#email-' + i + ' .status' ).toggleClass( 'enabled', res[ i ] );
673 672 }
674 673 }, this ),
@@ -682,13 +681,12 @@
682 681 return;
683 682 }
684 683
685 684 $( '.lp_sale_dates_fields' ).each( function() {
686 - const $this = $( this );
687 - const $wrap = $this.closest( 'div.lp-meta-box-course-panels' );
685 + const wrap = $( this ).closest( '#price_course_data' );
688 686 let saleScheduleSet = false;
689 687
690 - $this.find( 'input' ).each( function() {
688 + $( this ).find( 'input' ).each( function() {
691 689 if ( '' !== $( this ).val() ) {
692 690 saleScheduleSet = true;
693 691 }
694 692 } );
@@ -693,18 +691,18 @@
693 691 }
694 692 } );
695 693
696 694 if ( saleScheduleSet ) {
697 - $wrap.find( '.lp_sale_price_schedule' ).hide();
698 - $wrap.find( '.lp_sale_dates_fields' ).show();
695 + wrap.find( '.lp_sale_price_schedule' ).hide();
696 + wrap.find( '.lp_sale_dates_fields' ).show();
699 697 } else {
700 - $wrap.find( '.lp_sale_price_schedule' ).show();
701 - $wrap.find( '.lp_sale_dates_fields' ).hide();
698 + wrap.find( '.lp_sale_price_schedule' ).show();
699 + wrap.find( '.lp_sale_dates_fields' ).hide();
702 700 }
703 701 } );
704 702
705 703 $( '.lp-meta-box-course-panels' ).on( 'click', '.lp_sale_price_schedule', function() {
706 - const wrap = $( this ).closest( 'div.lp-meta-box-course-panels' );
704 + const wrap = $( this ).closest( '#price_course_data' );
707 705
708 706 $( this ).hide();
709 707
710 708 wrap.find( '.lp_cancel_sale_schedule' ).show();
@@ -741,9 +739,9 @@
741 739 }
742 740 }
743 741 } );
744 742
745 - const datePickerSelect = function( datepicker ) {
743 + /*const datePickerSelect = function( datepicker ) {
746 744 const option = $( datepicker ).is( '#_lp_sale_start' ) ? 'minDate' : 'maxDate',
747 745 otherDateField = 'minDate' === option ? $( '#_lp_sale_end' ) : $( '#_lp_sale_start' ),
748 746 date = $( datepicker ).datetimepicker( 'getDate' );
749 747
@@ -764,9 +762,9 @@
764 762
765 763 $( this ).find( 'input' ).each( function() {
766 764 datePickerSelect( $( this ) );
767 765 } );
768 - } );
766 + } );*/
769 767 };
770 768
771 769 const lpHidePassingGrade = () => {
772 770 const listHides = [ 'evaluate_final_quiz', 'evaluate_final_assignment' ];
@@ -830,12 +828,13 @@
830 828 $.ajax( {
831 829 url: '',
832 830 data: {
833 831 'lp-ajax': 'update_email_status',
832 + nonce: $( 'input[name=lp-settings-nonce]' ).val(),
834 833 status,
835 834 },
836 835 success( response ) {
837 - response = LP.parseJSON( response );
836 + response = lpAjaxParseJsonOld( response );
838 837 for ( const i in response ) {
839 838 $( '#email-' + i + ' .status' ).toggleClass( 'enabled', response[ i ] );
840 839 }
841 840 },
@@ -841,51 +840,8 @@
841 840 },
842 841 } );
843 842 };
844 843
845 -const importCourses = function importCourses() {
846 - const $container = $( '#learn-press-install-sample-data-notice' ),
847 - action = $( this ).attr( 'data-action' );
848 - if ( ! action ) {
849 - return;
850 - }
851 - e.preventDefault();
852 -
853 - if ( action === 'yes' ) {
854 - $container
855 - .find( '.install-sample-data-notice' ).slideUp()
856 - .siblings( '.install-sample-data-loading' ).slideDown();
857 - } else {
858 - $container.fadeOut();
859 - }
860 - $.ajax( {
861 - url: ajaxurl,
862 - dataType: 'html',
863 - type: 'post',
864 - data: {
865 - action: 'learnpress_install_sample_data',
866 - yes: action,
867 - },
868 - success( response ) {
869 - response = LP.parseJSON( response );
870 - if ( response.url ) {
871 - $.ajax( {
872 - url: response.url,
873 - success() {
874 - $container
875 - .find( '.install-sample-data-notice' ).html( response.message ).slideDown()
876 - .siblings( '.install-sample-data-loading' ).slideUp();
877 - },
878 - } );
879 - } else {
880 - $container
881 - .find( '.install-sample-data-notice' ).html( response.message ).slideDown()
882 - .siblings( '.install-sample-data-loading' ).slideUp();
883 - }
884 - },
885 - } );
886 -};
887 -
888 844 const onReady = function onReady() {
889 845 makePaymentsSortable();
890 846 initSelect2();
891 847 initTooltips();
@@ -900,9 +856,9 @@
900 856 lpMetaboxsalePriceDate();
901 857 lpMetaboxExtraInfo();
902 858 lpHidePassingGrade();
903 859 lpGetFinalQuiz();
904 - lpMetaboxCondition();
860 + //lpMetaboxCondition();
905 861 lpMetaboxRepeaterField();
906 862
907 863 $( document )
908 864 .on( 'click', '.learn-press-payments .status .dashicons', togglePaymentStatus )
@@ -907,9 +863,25 @@
907 863 $( document )
908 864 .on( 'click', '.learn-press-payments .status .dashicons', togglePaymentStatus )
909 865 .on( 'click', '.change-email-status', updateEmailStatus )
910 866 .on( 'click', '.learn-press-filter-template', callbackFilterTemplates )
911 - .on( 'click', '#learn-press-enable-emails, #learn-press-disable-emails', toggleEmails )
912 - .on( 'click', '#learn-press-install-sample-data-notice a', importCourses );
867 + .on( 'click', '#learn-press-enable-emails, #learn-press-disable-emails', toggleEmails );
913 868 };
914 869
915 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 +} );