| @@ -2,79 +2,11 @@ | ||
| 2 | 2 | import createIndexes from './tools/database/create_indexs'; |
| 3 | 3 | import reUpgradeDB from './tools/database/re-upgrade-db'; |
| 4 | 4 | import cleanDatabases from './tools/database/clean_database'; |
| 5 | 5 | |
| 6 | -import resetData from './tools/reset-data'; | |
| 7 | - | |
| 8 | 6 | ( function( $ ) { |
| 9 | 7 | const $doc = $( document ); |
| 10 | - let isRunning = false; | |
| 11 | 8 | |
| 12 | - const installSampleCourse = function installSampleCourse( e ) { | |
| 13 | - e.preventDefault(); | |
| 14 | - | |
| 15 | - const $button = $( this ); | |
| 16 | - | |
| 17 | - if ( isRunning ) { | |
| 18 | - return; | |
| 19 | - } | |
| 20 | - | |
| 21 | - if ( ! confirm( lpGlobalSettings.i18n.confirm_install_sample_data ) ) { | |
| 22 | - return; | |
| 23 | - } | |
| 24 | - | |
| 25 | - $button.addClass( 'disabled' ).html( $button.data( 'installing-text' ) ); | |
| 26 | - $( '.lp-install-sample__response' ).remove(); | |
| 27 | - isRunning = true; | |
| 28 | - | |
| 29 | - $.ajax( { | |
| 30 | - method: 'POST', | |
| 31 | - url: $button.attr( 'href' ), | |
| 32 | - data: $( '.lp-install-sample__options' ).serializeJSON(), | |
| 33 | - success( response ) { | |
| 34 | - $button.removeClass( 'disabled' ).html( $button.data( 'text' ) ); | |
| 35 | - isRunning = false; | |
| 36 | - $( response ).insertBefore( $button.parent() ); | |
| 37 | - }, | |
| 38 | - error() { | |
| 39 | - $button.removeClass( 'disabled' ).html( $button.data( 'text' ) ); | |
| 40 | - isRunning = false; | |
| 41 | - $( response ).insertBefore( $button.parent() ); | |
| 42 | - }, | |
| 43 | - } ); | |
| 44 | - }; | |
| 45 | - | |
| 46 | - const uninstallSampleCourse = function uninstallSampleCourse( e ) { | |
| 47 | - e.preventDefault(); | |
| 48 | - | |
| 49 | - const $button = $( this ); | |
| 50 | - | |
| 51 | - if ( isRunning ) { | |
| 52 | - return; | |
| 53 | - } | |
| 54 | - | |
| 55 | - if ( ! confirm( lpGlobalSettings.i18n.confirm_uninstall_sample_data ) ) { | |
| 56 | - return; | |
| 57 | - } | |
| 58 | - | |
| 59 | - $button.addClass( 'disabled' ).html( $button.data( 'uninstalling-text' ) ); | |
| 60 | - isRunning = true; | |
| 61 | - | |
| 62 | - $.ajax( { | |
| 63 | - url: $button.attr( 'href' ), | |
| 64 | - success( response ) { | |
| 65 | - $button.removeClass( 'disabled' ).html( $button.data( 'text' ) ); | |
| 66 | - isRunning = false; | |
| 67 | - $( response ).insertBefore( $button.parent() ); | |
| 68 | - }, | |
| 69 | - error() { | |
| 70 | - $button.removeClass( 'disabled' ).html( $button.data( 'text' ) ); | |
| 71 | - isRunning = false; | |
| 72 | - $( response ).insertBefore( $button.parent() ); | |
| 73 | - }, | |
| 74 | - } ); | |
| 75 | - }; | |
| 76 | - | |
| 77 | 9 | const clearHardCache = function clearHardCache( e ) { |
| 78 | 10 | e.preventDefault(); |
| 79 | 11 | const $button = $( this ); |
| 80 | 12 | |
| @@ -105,43 +37,13 @@ | ||
| 105 | 37 | }, |
| 106 | 38 | } ); |
| 107 | 39 | }; |
| 108 | 40 | |
| 109 | - const toggleOptions = function toggleOptions( e ) { | |
| 110 | - e.preventDefault(); | |
| 111 | - $( '.lp-install-sample__options' ).toggleClass( 'hide-if-js' ); | |
| 112 | - }; | |
| 113 | - | |
| 114 | - const formatValueInput = ( e ) => { | |
| 115 | - const input = $( e.target ); | |
| 116 | - let value = input.val(); | |
| 117 | - value = value.replace( /[^0-9]/g, '' ); | |
| 118 | - | |
| 119 | - input.val( value ); | |
| 120 | - | |
| 121 | - if ( parseInt( value, 10 ) < input.attr( 'min' ) ) { | |
| 122 | - input.val( input.attr( 'min' ) ); | |
| 123 | - } | |
| 124 | - | |
| 125 | - if ( parseInt( value, 10 ) > input.attr( 'max' ) ) { | |
| 126 | - input.val( input.attr( 'max' ) ); | |
| 127 | - } | |
| 128 | - }; | |
| 129 | - | |
| 130 | 41 | $( function() { |
| 131 | 42 | getStepsUpgradeStatus(); |
| 132 | 43 | createIndexes(); |
| 133 | 44 | reUpgradeDB(); |
| 134 | - resetData(); | |
| 135 | 45 | cleanDatabases(); |
| 136 | - $doc.on( 'click', '.lp-install-sample__install', installSampleCourse ) | |
| 137 | - .on( 'click', '.lp-install-sample__uninstall', uninstallSampleCourse ) | |
| 138 | - .on( 'click', '#learn-press-clear-cache', clearHardCache ) | |
| 139 | - .on( 'click', 'input[name="enable_hard_cache"]', toggleHardCache ) | |
| 140 | - .on( 'click', '.lp-install-sample__toggle-options', toggleOptions ) | |
| 141 | - .on( 'change', 'input[name="section-range[]"]', formatValueInput ) | |
| 142 | - .on( 'change', 'input[name="item-range[]"]', formatValueInput ) | |
| 143 | - .on( 'change', 'input[name="question-range[]"]', formatValueInput ) | |
| 144 | - .on( 'change', 'input[name="answer-range[]"]', formatValueInput ) | |
| 145 | - .on( 'change', 'input[name="course-price"]', formatValueInput ); | |
| 46 | + $doc.on( 'click', '#learn-press-clear-cache', clearHardCache ) | |
| 47 | + .on( 'click', 'input[name="enable_hard_cache"]', toggleHardCache ); | |
| 146 | 48 | } ); |
| 147 | 49 | }( jQuery ) ); |