progress_message complete
Этот коммит содержится в:
родитель
16636f3a27
Коммит
a30aefadd6
27
batch.php
27
batch.php
@ -70,7 +70,7 @@ function batch_operations_load_translation_file() {
|
||||
* Add backend page without menu item
|
||||
*/
|
||||
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">
|
||||
<span style="width:0%;"></span>
|
||||
</div>
|
||||
<div class="batch-progress-message"></div><div class="batch-percent"></div>
|
||||
<div class="batch-message"><?php echo $init_message; ?></div>
|
||||
<div class="batch-progress-message"><?php echo $init_message; ?></div><div class="batch-percent"></div>
|
||||
<div class="batch-message"></div>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
@ -157,6 +157,17 @@ function batch_operations_process () {
|
||||
}
|
||||
|
||||
$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'];
|
||||
|
||||
if ( '' == $result['do'] ) {
|
||||
@ -193,10 +204,10 @@ function batch_operations_process () {
|
||||
*
|
||||
* <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> title: A safe, translated string to use as the title for the progress page. Defaults to t('Processing').
|
||||
* <li> init_message: Message displayed while the processing is initialized. Defaults to t('Initializing.').
|
||||
* <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 __('Initializing.').
|
||||
* <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.
|
||||
*
|
||||
* Sample callback_batch_operation():
|
||||
@ -239,6 +250,10 @@ function batch_operations_start($batch_arr)
|
||||
$batch_arr['count'] = count( $batch_arr['operations'] );
|
||||
$batch_arr['current'] = 0;
|
||||
|
||||
if ( empty( $batch_arr['progress_message'] ) ) {
|
||||
$batch_arr['progress_message'] = __('Completed %current% of %total%.');
|
||||
}
|
||||
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . 'batch_operations',
|
||||
array(
|
||||
|
@ -38,6 +38,17 @@ function batch_operations_test_page_view() {
|
||||
$batch['operations'][]=array('test_batch_operation',array());
|
||||
batch_operations_start($batch);
|
||||
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:
|
||||
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-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=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>
|
||||
</div>
|
||||
<?php
|
||||
|
14
js/batch.js
14
js/batch.js
@ -1,17 +1,17 @@
|
||||
jQuery(document).ready(function($) {
|
||||
var batch_progress = function (percent){
|
||||
$(".batch-percent").html(percent + "%");
|
||||
return $(".batch-progress > span").animate({ width: percent + "%" }, 600);
|
||||
var batch_progress = function ( data ) {
|
||||
$( '.batch-progress-message' ).html( data['progress_message'] );
|
||||
$( '.batch-percent' ).html( data['percent'] + "%" );
|
||||
$( '.batch-progress > span' ).animate({ width: data['percent'] + "%" }, 500);
|
||||
};
|
||||
|
||||
function batch_process(){
|
||||
function batch_process() {
|
||||
$.post(
|
||||
ajaxurl+'?action=batch_operations&id='+batch_id,
|
||||
function(data){
|
||||
if (data['do']=='finish')
|
||||
{
|
||||
|
||||
batch_progress(data['percent']);
|
||||
batch_progress( data );
|
||||
$('.batch-message').html(data['message']).delay(1500).queue(function () {
|
||||
$(location).attr('href',successful_page);
|
||||
$(this).dequeue();
|
||||
@ -21,7 +21,7 @@ jQuery(document).ready(function($) {
|
||||
else
|
||||
{
|
||||
$('.batch-message').html(data['message']);
|
||||
batch_progress(data['percent']);
|
||||
batch_progress( data );
|
||||
batch_process()
|
||||
}
|
||||
}
|
||||
|
2
js/batch.min.js
поставляемый
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
Двоичные данные
languages/batch-operations-ru_RU.mo
Двоичный файл не отображается.
@ -1,9 +1,9 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Batch operations\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2015-06-09 15:05+0300\n"
|
||||
"PO-Revision-Date: 2015-06-09 15:07+0300\n"
|
||||
"Report-Msgid-Bugs-To: igor@belousovv.ru\n"
|
||||
"POT-Creation-Date: 2015-06-10 12:37+0300\n"
|
||||
"PO-Revision-Date: 2015-06-10 12:41+0300\n"
|
||||
"Last-Translator: Igor V Belousov <igor@belousovv.ru>\n"
|
||||
"Language-Team: <igor@belousovv.ru>\n"
|
||||
"Language: ru_RU\n"
|
||||
@ -13,10 +13,14 @@ msgstr ""
|
||||
"X-Generator: Poedit 1.5.5\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
|
||||
#: batch.php:90
|
||||
#: batch.php:91
|
||||
msgid "Processing"
|
||||
msgstr "Обработка"
|
||||
|
||||
#: batch.php:95
|
||||
#: batch.php:96
|
||||
msgid "Initializing."
|
||||
msgstr "Инициализация."
|
||||
|
||||
#: batch.php:254
|
||||
msgid "Completed %current% of %total%."
|
||||
msgstr "Выполнено %current% из %total%."
|
||||
|
@ -2,7 +2,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Batch operations 0.1.0\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"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -11,10 +11,14 @@ msgstr ""
|
||||
"Content-Type: text/plain; charset=CHARSET\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: batch.php:90
|
||||
#: batch.php:91
|
||||
msgid "Processing"
|
||||
msgstr ""
|
||||
|
||||
#: batch.php:95
|
||||
#: batch.php:96
|
||||
msgid "Initializing."
|
||||
msgstr ""
|
||||
|
||||
#: batch.php:254
|
||||
msgid "Completed %current% of %total%."
|
||||
msgstr ""
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user