|
2 | 2 | /** |
3 | 3 | * WP_Framework_Custom_Post Views Admin Script Import Custom Post |
4 | 4 | * |
5 | | - * @version 0.0.21 |
| 5 | + * @version 0.0.33 |
6 | 6 | * @author Technote |
7 | 7 | * @copyright Technote All Rights Reserved |
8 | 8 | * @license http://www.opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 |
|
18 | 18 | ?> |
19 | 19 |
|
20 | 20 | <script> |
21 | | - ( function ( $ ) { |
22 | | - const $button = $( '.page-title-action' ); |
23 | | - if ( $button.length ) { |
24 | | - $button.before( '<div class="import-button-wrapper"><input type="file"/><input type="button" value="<?php $instance->h( 'Import from JSON', true );?>" class="import-button button-primary large"/></div>' ); |
| 21 | + ( function( $ ) { |
| 22 | + const $button = $( '.page-title-action' ); |
| 23 | + if ( $button.length ) { |
| 24 | + $button.before( '<div class="import-button-wrapper"><input type="file"/><input type="button" value="<?php $instance->h( 'Import from JSON', true );?>" class="import-button button-primary large"/></div>' ); |
25 | 25 |
|
26 | | - const $wrapper = $('.import-button-wrapper'); |
27 | | - let importing = false; |
28 | | - const importing_message = '<?php $instance->h( 'importing', true );?>...'; |
29 | | - const result_message = '<div class="result-wrap"><div class="result-message"></div><div><input type="button" class="button-primary large close" value="<?php $instance->h('Close', true);?>"/></div></div>'; |
30 | | - $wrapper.find( 'input[type="file"]' ).on( 'change', function () { |
31 | | - if ( this.files.length > 0 ) { |
32 | | - if ( importing ) { |
33 | | - return false; |
34 | | - } |
35 | | - importing = true; |
| 26 | + const $wrapper = $( '.import-button-wrapper' ); |
| 27 | + let importing = false; |
| 28 | + const importing_message = '<?php $instance->h( 'importing', true );?>...'; |
| 29 | + const result_message = '<div class="result-wrap"><div class="result-message"></div><div><input type="button" class="button-primary large close" value="<?php $instance->h( 'Close', true );?>"/></div></div>'; |
| 30 | + const api_class = window[ '<?php $instance->h( $api_class );?>' ]; |
| 31 | + const modal_class = window[ '<?php $instance->modal_class();?>' ]; |
| 32 | + $wrapper.find( 'input[type="file"]' ).on( 'change', function() { |
| 33 | + if ( this.files.length > 0 ) { |
| 34 | + if ( importing ) { |
| 35 | + return false; |
| 36 | + } |
| 37 | + importing = true; |
36 | 38 |
|
37 | | - const formData = new FormData(); |
38 | | - formData.append( 'import', this.files[0] ); |
39 | | - formData.append( 'post_type', '<?php $instance->h( $post_type );?>' ); |
40 | | - window.<?php $instance->h( $api_class );?>.ajax('import_custom_post', formData).done(function (json) { |
41 | | - const close_modal = function() { |
42 | | - if (json.success) { |
43 | | - location.reload(); |
44 | | - } else { |
45 | | - window.<?php $instance->modal_class();?>.hide(); |
46 | | - } |
47 | | - }; |
48 | | - window.<?php $instance->modal_class();?>.show(false, close_modal); |
| 39 | + const formData = new FormData(); |
| 40 | + formData.append( 'import', this.files[ 0 ] ); |
| 41 | + formData.append( 'post_type', '<?php $instance->h( $post_type );?>' ); |
| 42 | + api_class.ajax( 'import_custom_post', formData ).done( function( json ) { |
| 43 | + const close_modal = function() { |
| 44 | + if ( json.success ) { |
| 45 | + location.reload(); |
| 46 | + } else { |
| 47 | + modal_class.hide(); |
| 48 | + } |
| 49 | + }; |
| 50 | + modal_class.show( false, close_modal ); |
49 | 51 |
|
50 | | - window.<?php $instance->modal_class();?>.show_message(result_message); |
51 | | - window.<?php $instance->modal_class();?>._message().find('.result-message').html(json.message); |
52 | | - window.<?php $instance->modal_class();?>._message().find('.close').on('click', close_modal); |
53 | | - if (json.result) { |
54 | | - window.<?php $instance->modal_class();?>._message().find('.result-message').addClass('updated'); |
55 | | - } else { |
56 | | - window.<?php $instance->modal_class();?>._message().find('.result-message').addClass('error'); |
57 | | - } |
58 | | - window.<?php $instance->modal_class();?>._set_message_size(); |
59 | | - }).fail(function (err) { |
60 | | - window.<?php $instance->modal_class();?>.hide(); |
61 | | - console.log(err); |
62 | | - }).always(function () { |
63 | | - importing = false; |
64 | | - }); |
| 52 | + modal_class.show_message( result_message ); |
| 53 | + modal_class._message().find( '.result-message' ).html( json.message ); |
| 54 | + modal_class._message().find( '.close' ).on( 'click', close_modal ); |
| 55 | + if ( json.result ) { |
| 56 | + modal_class._message().find( '.result-message' ).addClass( 'updated' ); |
| 57 | + } else { |
| 58 | + modal_class._message().find( '.result-message' ).addClass( 'error' ); |
| 59 | + } |
| 60 | + modal_class._set_message_size(); |
| 61 | + } ).fail( function( err ) { |
| 62 | + modal_class.hide(); |
| 63 | + console.log( err ); |
| 64 | + } ).always( function() { |
| 65 | + importing = false; |
| 66 | + } ); |
65 | 67 |
|
66 | | - window.<?php $instance->modal_class();?>.show(true, null, importing_message); |
67 | | - } |
68 | | - } ); |
69 | | - $wrapper.find( '.import-button' ).on( 'click', function () { |
70 | | - $wrapper.find( 'input[type="file"]' ).click(); |
71 | | - } ); |
72 | | - } |
73 | | - } )( jQuery ); |
| 68 | + modal_class.show( true, null, importing_message ); |
| 69 | + } |
| 70 | + } ); |
| 71 | + $wrapper.find( '.import-button' ).on( 'click', function() { |
| 72 | + $wrapper.find( 'input[type="file"]' ).click(); |
| 73 | + } ); |
| 74 | + } |
| 75 | + } )( jQuery ); |
74 | 76 | </script> |
0 commit comments