Permalink
Browse files

fixes #593, delete by blocks of 100 photos, with a progress bar

  • Loading branch information...
1 parent 3a8b267 commit e6e7465b9d285b42e7ea3c61fe0c0c7b93f57d19 @plegall plegall committed Dec 26, 2016
@@ -361,12 +361,13 @@
{
if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion'])
{
- $deleted_count = delete_elements($collection, true);
- if ($deleted_count > 0)
+ // now done with ajax calls, with blocks
+ // $deleted_count = delete_elements($collection, true);
+ if (count($collection) > 0)
{
$_SESSION['page_infos'][] = l10n_dec(
'%d photo was deleted', '%d photos were deleted',
- $deleted_count
+ count($collection)
);
$redirect_url = get_root_url().'admin.php?page='.$_GET['page'];
@@ -215,3 +215,102 @@ function selectDelDerivAll() {
function selectDelDerivNone() {
$("#action_delete_derivatives input[type=checkbox]").prop("checked", false);
}
+
+/* delete photos by blocks, with progress bar */
+jQuery('#applyAction').click(function(e) {
+ if (typeof(elements) != "undefined") {
+ return true;
+ }
+
+ if (jQuery('[name="selectAction"]').val() == 'delete') {
+ if (!jQuery("#action_delete input[name=confirm_deletion]").is(':checked')) {
+ jQuery("#action_delete span.errors").show();
+ return false;
+ }
+ e.stopPropagation();
+ }
+ else {
+ return true;
+ }
+
+ jQuery('.bulkAction').hide();
+ jQuery('#regenerationText').html(lang.deleteProgressMessage);
+ var maxRequests=1;
+
+ var queuedManager = jQuery.manageAjax.create('queued', {
+ queue: true,
+ cacheResponse: false,
+ maxRequests: maxRequests
+ });
+
+ elements = Array();
+
+ if (jQuery('input[name=setSelected]').is(':checked')) {
+ elements = all_elements;
+ }
+ else {
+ jQuery('input[name="selection[]"]').filter(':checked').each(function() {
+ elements.push(jQuery(this).val());
+ });
+ }
+
+ progressBar_max = elements.length;
+ var todo = 0;
+ var deleteBlockSize = 100;
+ var image_ids = Array();
+
+ jQuery('#applyActionBlock').hide();
+ jQuery('select[name="selectAction"]').hide();
+ jQuery('#regenerationMsg').show();
+ jQuery('#progressBar').progressBar(0, {
+ max: progressBar_max,
+ textFormat: 'fraction',
+ boxImage: 'themes/default/images/progressbar.gif',
+ barImage: 'themes/default/images/progressbg_orange.gif'
+ });
+
+ for (i=0;i<elements.length;i++) {
+ image_ids.push(elements[i]);
+ if (i % deleteBlockSize != deleteBlockSize - 1 && i != elements.length - 1) {
+ continue;
+ }
+
+ queuedManager.add({
+ type: 'POST',
+ url: 'ws.php?format=json',
+ data: {
+ method: "pwg.images.delete",
+ pwg_token: wm_pwg_token,
+ return_details: true,
+ image_id: image_ids
+ },
+ dataType: 'json',
+ success: ( function(data) { todo += data.result.details.nb_processed; progressDelete(todo, progressBar_max, data.result.success) }),
+ error: ( function(data) { todo += data.result.details.nb_processed; progressDelete(todo, progressBar_max, false) })
+ });
+
+ image_ids = Array();
+ }
+ return false;
+});
+
+function progressDelete(val, max, success) {
+ jQuery('#progressBar').progressBar(val, {
+ max: max,
+ textFormat: 'fraction',
+ boxImage: 'themes/default/images/progressbar.gif',
+ barImage: 'themes/default/images/progressbg_orange.gif'
+ });
+ type = success ? 'regenerateSuccess': 'regenerateError'
+ s = jQuery('[name="'+type+'"]').val();
+ jQuery('[name="'+type+'"]').val(++s);
+
+ if (val == max) {
+ jQuery('#applyAction').click();
+ }
+}
+
+
+jQuery("#action_delete input[name=confirm_deletion]").change(function() {
+ jQuery("#action_delete span.errors").hide();
+});
@@ -21,6 +21,7 @@
{footer_script}
var lang = {
Cancel: '{'Cancel'|translate|escape:'javascript'}',
+ deleteProgressMessage: "{'Deletion in progress'|translate|escape:'javascript'}",
AreYouSure: "{'Are you sure?'|translate|escape:'javascript'}"
};
@@ -226,7 +227,6 @@ $(document).ready(function() {
return false;
});
-
jQuery('#applyAction').click(function() {
var action = jQuery('[name="selectAction"]').val();
if (action == 'delete_derivatives') {
@@ -597,7 +597,7 @@ UL.thumbnails SPAN.wrap2 {ldelim}
<!-- delete -->
<div id="action_delete" class="bulkAction">
- <p><label><input type="checkbox" name="confirm_deletion" value="1"> {'Are you sure?'|@translate}</label></p>
+ <p><label><input type="checkbox" name="confirm_deletion" value="1"> {'Are you sure?'|@translate}</label><span class="errors" style="display:none">{"You need to confirm deletion"|translate}</span></p>
</div>
<!-- associate -->{* also used for "move" action *}
@@ -1739,6 +1739,20 @@ function ws_images_delete($params, $service)
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
delete_elements($image_ids, true);
invalidate_user_cache();
+
+ if ($params['return_details'])
+ {
+ return array(
+ 'success' => true,
+ 'details' => array(
+ 'nb_processed' => count($image_ids),
+ ),
+ );
+ }
+ else
+ {
+ return true;
+ }
}
/**
@@ -1760,4 +1774,4 @@ function ws_images_checkUpload($params, $service)
return $ret;
}
-?>
+?>
View
@@ -504,6 +504,7 @@ function ws_addDefaultMethods( $arr )
array(
'image_id' => array('flags'=>WS_PARAM_ACCEPT_ARRAY),
'pwg_token' => array(),
+ 'return_details' => array('default'=>false, 'type'=>WS_TYPE_BOOL),
),
'Deletes image(s).',
$ws_functions_root . 'pwg.images.php',
@@ -1024,4 +1025,4 @@ function ws_addDefaultMethods( $arr )
);
}
-?>
+?>

0 comments on commit e6e7465

Please sign in to comment.