From a30aefadd6a31f3f6e7f928a51ddf30528c73e5b Mon Sep 17 00:00:00 2001 From: Igor V Belousov Date: Wed, 10 Jun 2015 12:51:19 +0300 Subject: [PATCH] progress_message complete --- batch.php | 27 +++++++++++++++++++++------ batch_test.php | 14 +++++++++++++- js/batch.js | 14 +++++++------- js/batch.min.js | 2 +- languages/batch-operations-ru_RU.mo | Bin 562 -> 670 bytes languages/batch-operations-ru_RU.po | 14 +++++++++----- languages/batch-operations.pot | 10 +++++++--- 7 files changed, 58 insertions(+), 23 deletions(-) diff --git a/batch.php b/batch.php index 14d080e..62ef345 100644 --- a/batch.php +++ b/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() {
-
-
+
+
*
  • 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: - *
  • title: A safe, translated string to use as the title for the progress page. Defaults to t('Processing'). - *
  • init_message: Message displayed while the processing is initialized. Defaults to t('Initializing.'). + *
  • title: A safe, translated string to use as the title for the progress page. Defaults to __('Processing'). + *
  • init_message: Message displayed while the processing is initialized. Defaults to __('Initializing.'). *
  • progress_message: Message displayed while processing the batch. Available placeholders are %current% and %total%. - *
  • error_message: Message displayed if an error occurred while processing the batch. Defaults to t('An error has occurred.'). + *
  • error_message: Message displayed if an error occurred while processing the batch. Defaults to __('An error has occurred.'). *
  • 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( diff --git a/batch_test.php b/batch_test.php index 1ba4b14..c7a4f23 100644 --- a/batch_test.php +++ b/batch_test.php @@ -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() {
  • $current_array is empty
  • Default title & init_message
  • Set custom title & custom init_message -
  • 5 operations +
  • 5 operations default progress_message +
  • 5 operations custom progress_message 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() } } diff --git a/js/batch.min.js b/js/batch.min.js index dc83f10..5d64cea 100644 --- a/js/batch.min.js +++ b/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()}); \ No newline at end of file +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()}); \ No newline at end of file diff --git a/languages/batch-operations-ru_RU.mo b/languages/batch-operations-ru_RU.mo index 0060b47937454e8eef52fe4a52ee9afc783bb983..2918d318c5e8bfaff2e73a845c6432477272d04e 100644 GIT binary patch delta 270 zcmdnQGLN)k2ZM8dZb43JNotCMYI13jU{PvbiK;?= znu2Oceo11Es@}weP}9ux{33^>)SUd%;{38Qy`oaC0RIqO=c3falFa-(U6;g?R4WA| z14C0?12bJi0|i4PD`WGCHx)P_Y!k!HjEu~Tnv*VeU)X5_FmWu#QVTjLTtRS NGK+XUF delta 163 zcmbQox``#>o)F7a1|VPtVi_Pd0b*7l_5orLNC0A9AWj5gE+Eba;toazhAJQ}4aCe$ z3=Bd*S{_IPg~8?kDFz@H3?@zpRpAQo57BilN=+=u%+J$xNi0dVQZO1VE bFf_F?Fr6&LsK5c`m~VDsWM-UPz@!HNrXLnD diff --git a/languages/batch-operations-ru_RU.po b/languages/batch-operations-ru_RU.po index 4e80dac..b77c192 100644 --- a/languages/batch-operations-ru_RU.po +++ b/languages/batch-operations-ru_RU.po @@ -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 \n" "Language-Team: \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%." diff --git a/languages/batch-operations.pot b/languages/batch-operations.pot index 68febfb..6345963 100644 --- a/languages/batch-operations.pot +++ b/languages/batch-operations.pot @@ -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 \n" "Language-Team: LANGUAGE \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 ""