Этот коммит содержится в:
Igor V Belousov 2015-06-10 12:51:19 +03:00
родитель 16636f3a27
Коммит a30aefadd6
7 изменённых файлов: 58 добавлений и 23 удалений

Просмотреть файл

@ -70,7 +70,7 @@ function batch_operations_load_translation_file() {
* Add backend page without menu item * Add backend page without menu item
*/ */
function batch_operations_add_page() { function batch_operations_add_page() {
add_submenu_page(null,'Batch operations','Batch operations','edit_posts','batch-operations','batch_operations_page_view'); add_submenu_page( null, 'Batch operations', 'Batch operations', 'edit_posts', 'batch-operations', 'batch_operations_page_view' );
} }
/** /**
@ -106,8 +106,8 @@ function batch_operations_page_view() {
<div class="batch-progress"> <div class="batch-progress">
<span style="width:0%;"></span> <span style="width:0%;"></span>
</div> </div>
<div class="batch-progress-message"></div><div class="batch-percent"></div> <div class="batch-progress-message"><?php echo $init_message; ?></div><div class="batch-percent"></div>
<div class="batch-message"><?php echo $init_message; ?></div> <div class="batch-message"></div>
</div> </div>
<?php <?php
@ -157,6 +157,17 @@ function batch_operations_process () {
} }
$result['percent'] = round( $current_array['current'] / ($current_array['count'] / 100 ) ); $result['percent'] = round( $current_array['current'] / ($current_array['count'] / 100 ) );
$result['progress_message'] = str_replace(
array(
'%current%',
'%total%'
),
array(
$current_array['current'],
$current_array['count']
),
__( $current_array['progress_message'], 'batch-operations')
);
$result['message'] = $current_array['context']['message']; $result['message'] = $current_array['context']['message'];
if ( '' == $result['do'] ) { if ( '' == $result['do'] ) {
@ -193,10 +204,10 @@ function batch_operations_process () {
* *
* <ul> * <ul>
* <li> operations: (required) Array of operations to be performed, where each item is an array consisting of the name of an implementation of callback_batch_operation() and an array of parameter. Example: * <li> operations: (required) Array of operations to be performed, where each item is an array consisting of the name of an implementation of callback_batch_operation() and an array of parameter. Example:
* <li> title: A safe, translated string to use as the title for the progress page. Defaults to t('Processing'). * <li> title: A safe, translated string to use as the title for the progress page. Defaults to __('Processing').
* <li> init_message: Message displayed while the processing is initialized. Defaults to t('Initializing.'). * <li> init_message: Message displayed while the processing is initialized. Defaults to __('Initializing.').
* <li> progress_message: Message displayed while processing the batch. Available placeholders are %current% and %total%. * <li> progress_message: Message displayed while processing the batch. Available placeholders are %current% and %total%.
* <li> error_message: Message displayed if an error occurred while processing the batch. Defaults to t('An error has occurred.'). * <li> error_message: Message displayed if an error occurred while processing the batch. Defaults to __('An error has occurred.').
* <li> finished: Name of an implementation of callback_batch_finished(). This is executed after the batch has completed. This should be used to perform any result massaging that may be needed, and possibly save data in $_SESSION for display after final page redirection. * <li> finished: Name of an implementation of callback_batch_finished(). This is executed after the batch has completed. This should be used to perform any result massaging that may be needed, and possibly save data in $_SESSION for display after final page redirection.
* *
* Sample callback_batch_operation(): * Sample callback_batch_operation():
@ -239,6 +250,10 @@ function batch_operations_start($batch_arr)
$batch_arr['count'] = count( $batch_arr['operations'] ); $batch_arr['count'] = count( $batch_arr['operations'] );
$batch_arr['current'] = 0; $batch_arr['current'] = 0;
if ( empty( $batch_arr['progress_message'] ) ) {
$batch_arr['progress_message'] = __('Completed %current% of %total%.');
}
$wpdb->insert( $wpdb->insert(
$wpdb->prefix . 'batch_operations', $wpdb->prefix . 'batch_operations',
array( array(

Просмотреть файл

@ -38,6 +38,17 @@ function batch_operations_test_page_view() {
$batch['operations'][]=array('test_batch_operation',array()); $batch['operations'][]=array('test_batch_operation',array());
batch_operations_start($batch); batch_operations_start($batch);
break; break;
case 5:
$batch['progress_message']='Current=%current%. Total=%total%.';
$batch['operations'][]=array('test_batch_operation',array());
$batch['operations'][]=array('test_batch_operation',array());
$batch['operations'][]=array('test_batch_operation',array());
$batch['operations'][]=array('test_batch_operation',array());
$batch['operations'][]=array('test_batch_operation',array());
batch_operations_start($batch);
break;
default: default:
break; break;
} }
@ -50,7 +61,8 @@ function batch_operations_test_page_view() {
<li><a href="tools.php?page=batch-operations&id=0">$current_array is empty</a> <li><a href="tools.php?page=batch-operations&id=0">$current_array is empty</a>
<li><a href="tools.php?page=batch-operations-test&test=2">Default <strong>title</strong> & <strong>init_message</strong></a> <li><a href="tools.php?page=batch-operations-test&test=2">Default <strong>title</strong> & <strong>init_message</strong></a>
<li><a href="tools.php?page=batch-operations-test&test=3">Set <strong>custom title</strong> & <strong>custom init_message</strong></a> <li><a href="tools.php?page=batch-operations-test&test=3">Set <strong>custom title</strong> & <strong>custom init_message</strong></a>
<li><a href="tools.php?page=batch-operations-test&test=4">5 operations</a> <li><a href="tools.php?page=batch-operations-test&test=4">5 operations default <strong>progress_message</strong></a>
<li><a href="tools.php?page=batch-operations-test&test=5">5 operations custom <strong>progress_message</strong></a>
</ol> </ol>
</div> </div>
<?php <?php

Просмотреть файл

@ -1,17 +1,17 @@
jQuery(document).ready(function($) { jQuery(document).ready(function($) {
var batch_progress = function (percent){ var batch_progress = function ( data ) {
$(".batch-percent").html(percent + "%"); $( '.batch-progress-message' ).html( data['progress_message'] );
return $(".batch-progress > span").animate({ width: percent + "%" }, 600); $( '.batch-percent' ).html( data['percent'] + "%" );
$( '.batch-progress > span' ).animate({ width: data['percent'] + "%" }, 500);
}; };
function batch_process(){ function batch_process() {
$.post( $.post(
ajaxurl+'?action=batch_operations&id='+batch_id, ajaxurl+'?action=batch_operations&id='+batch_id,
function(data){ function(data){
if (data['do']=='finish') if (data['do']=='finish')
{ {
batch_progress( data );
batch_progress(data['percent']);
$('.batch-message').html(data['message']).delay(1500).queue(function () { $('.batch-message').html(data['message']).delay(1500).queue(function () {
$(location).attr('href',successful_page); $(location).attr('href',successful_page);
$(this).dequeue(); $(this).dequeue();
@ -21,7 +21,7 @@ jQuery(document).ready(function($) {
else else
{ {
$('.batch-message').html(data['message']); $('.batch-message').html(data['message']);
batch_progress(data['percent']); batch_progress( data );
batch_process() batch_process()
} }
} }

2
js/batch.min.js поставляемый
Просмотреть файл

@ -1 +1 @@
jQuery(document).ready(function(a){function b(){a.post(ajaxurl+"?action=batch_operations&id="+batch_id,function(d){"finish"==d["do"]?(c(d.percent),a(".batch-message").html(d.message).delay(1500).queue(function(){a(location).attr("href",successful_page),a(this).dequeue()})):(a(".batch-message").html(d.message),c(d.percent),b())})}var c=function(b){return a(".batch-percent").html(b+"%"),a(".batch-progress > span").animate({width:b+"%"},600)};b()}); jQuery(document).ready(function(a){function b(){a.post(ajaxurl+"?action=batch_operations&id="+batch_id,function(d){"finish"==d["do"]?(c(d),a(".batch-message").html(d.message).delay(1500).queue(function(){a(location).attr("href",successful_page),a(this).dequeue()})):(a(".batch-message").html(d.message),c(d),b())})}var c=function(b){a(".batch-progress-message").html(b.progress_message),a(".batch-percent").html(b.percent+"%"),a(".batch-progress > span").animate({width:b.percent+"%"},500)};b()});

Двоичные данные
languages/batch-operations-ru_RU.mo

Двоичный файл не отображается.

Просмотреть файл

@ -1,9 +1,9 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Batch operations\n" "Project-Id-Version: Batch operations\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: igor@belousovv.ru\n"
"POT-Creation-Date: 2015-06-09 15:05+0300\n" "POT-Creation-Date: 2015-06-10 12:37+0300\n"
"PO-Revision-Date: 2015-06-09 15:07+0300\n" "PO-Revision-Date: 2015-06-10 12:41+0300\n"
"Last-Translator: Igor V Belousov <igor@belousovv.ru>\n" "Last-Translator: Igor V Belousov <igor@belousovv.ru>\n"
"Language-Team: <igor@belousovv.ru>\n" "Language-Team: <igor@belousovv.ru>\n"
"Language: ru_RU\n" "Language: ru_RU\n"
@ -13,10 +13,14 @@ msgstr ""
"X-Generator: Poedit 1.5.5\n" "X-Generator: Poedit 1.5.5\n"
"X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-SourceCharset: UTF-8\n"
#: batch.php:90 #: batch.php:91
msgid "Processing" msgid "Processing"
msgstr "Обработка" msgstr "Обработка"
#: batch.php:95 #: batch.php:96
msgid "Initializing." msgid "Initializing."
msgstr "Инициализация." msgstr "Инициализация."
#: batch.php:254
msgid "Completed %current% of %total%."
msgstr "Выполнено %current% из %total%."

Просмотреть файл

@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Batch operations 0.1.0\n" "Project-Id-Version: Batch operations 0.1.0\n"
"Report-Msgid-Bugs-To: igor@belousovv.ru\n" "Report-Msgid-Bugs-To: igor@belousovv.ru\n"
"POT-Creation-Date: 2015-06-09 15:05+0300\n" "POT-Creation-Date: 2015-06-10 12:37+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -11,10 +11,14 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: batch.php:90 #: batch.php:91
msgid "Processing" msgid "Processing"
msgstr "" msgstr ""
#: batch.php:95 #: batch.php:96
msgid "Initializing." msgid "Initializing."
msgstr "" msgstr ""
#: batch.php:254
msgid "Completed %current% of %total%."
msgstr ""