Permalink
Browse files

Merge branch 'feature/593-delete-by-blocks'

  • Loading branch information...
2 parents c2b456b + 743bbb6 commit bf5b50c979a4d12d9673ef96bd7091922c6e44cb @plegall plegall committed Jan 10, 2017
@@ -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,108 @@ 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 = Math.min(
+ Number((elements.length/2).toFixed()),
+ 1000
+ );
+ 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: jQuery("input[name=pwg_token").val(),
+ return_details: true,
+ image_id: image_ids.join(',')
+ },
+ dataType: 'json',
+ success: ( function(data) {
+ todo += data.result.nb_processed;
+ progressDelete(todo, progressBar_max, true)
+ }),
+ error: ( function(data) {
+ todo += deleteBlockSize; // TODO: might be not exact, if last query
+ 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'
+ });
+
+ 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,13 @@ 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(
+ 'nb_processed' => count($image_ids),
+ );
+ }
}
/**
@@ -1760,4 +1767,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 bf5b50c

Please sign in to comment.