BLUE-18: implemented a "select all" button on the album admin page, which can also select all items in an album

This commit is contained in:
Andy Heathershaw 2016-10-30 19:10:20 +00:00
parent 5b915f911e
commit 2f65c6085d
4 changed files with 105 additions and 16 deletions

View File

@ -431,25 +431,43 @@ class PhotoController extends Controller
private function applyBulkActions(Request $request, Album $album) private function applyBulkActions(Request $request, Album $album)
{ {
$photoIds = $request->get('select-photo'); $selectAllInAlbum = boolval($request->get('select-all-album'));
if (is_null($photoIds) || !is_array($photoIds) || count($photoIds) == 0) $photosToProcess = [];
if ($selectAllInAlbum)
{ {
$request->session()->flash('warning', trans('admin.no_photo_selected_message')); foreach ($album->photos as $photo)
return 0; {
$photosToProcess[] = $photo;
}
}
else
{
$photoIds = $request->get('select-photo');
if (is_null($photoIds) || !is_array($photoIds) || count($photoIds) == 0)
{
$request->session()->flash('warning', trans('admin.no_photo_selected_message'));
return 0;
}
foreach ($photoIds as $photoId)
{
/** @var Photo $photo */
$photo = $album->photos()->where('id', intval($photoId))->first();
if (is_null($photo))
{
continue;
}
$photosToProcess[] = $photo;
}
} }
$action = $request->get('bulk-action'); $action = $request->get('bulk-action');
$numberChanged = 0; $numberChanged = 0;
foreach ($photoIds as $photoId) foreach ($photosToProcess as $photo)
{ {
/** @var Photo $photo */
$photo = $album->photos()->where('id', intval($photoId))->first();
if (is_null($photo))
{
continue;
}
$photoService = new PhotoService($photo); $photoService = new PhotoService($photo);
$doNotSave = false; $doNotSave = false;
switch (strtolower($action)) switch (strtolower($action))

View File

@ -116,7 +116,9 @@ function EditPhotosViewModel(album_id, language, urls) {
self.albums = ko.observableArray(); self.albums = ko.observableArray();
self.bulkModifyMethod = ko.observable(); self.bulkModifyMethod = ko.observable();
self.photoIDs = ko.observableArray(); self.photoIDs = ko.observableArray();
self.photoIDsAvailable = ko.observableArray();
self.isSubmitting = false; self.isSubmitting = false;
self.selectAllInAlbum = ko.observable(0);
/* Called when the Apply button on the "bulk apply selected actions" form is clicked */ /* Called when the Apply button on the "bulk apply selected actions" form is clicked */
self.bulkModifySelected = function() self.bulkModifySelected = function()
@ -146,8 +148,8 @@ function EditPhotosViewModel(album_id, language, urls) {
{ {
// Prompt for a confirmation - are you sure?! // Prompt for a confirmation - are you sure?!
bootbox.dialog({ bootbox.dialog({
message: language.delete_bulk_confirm_message.replace(':number', self.photoIDs().length), message: language.delete_bulk_confirm_message,
title: language.delete_bulk_confirm_title.replace(':number', self.photoIDs().length), title: language.delete_bulk_confirm_title,
buttons: { buttons: {
cancel: { cancel: {
label: language.action_cancel, label: language.action_cancel,
@ -385,6 +387,48 @@ function EditPhotosViewModel(album_id, language, urls) {
return false; return false;
}; };
self.selectAll = function() {
bootbox.dialog({
title: language.select_all_choice_title,
message: language.select_all_choice_message,
buttons: {
select_all: {
label: language.select_all_choice_all_action,
className: 'btn-default',
callback: function()
{
self.selectAllInAlbum(1);
for (i = 0; i < self.photoIDsAvailable().length; i++)
{
self.photoIDs.push(self.photoIDsAvailable()[i]);
}
}
},
select_visible: {
label: language.select_all_choice_visible_action,
className: 'btn-primary',
callback: function()
{
self.selectAllInAlbum(0);
for (i = 0; i < self.photoIDsAvailable().length; i++)
{
self.photoIDs.push(self.photoIDsAvailable()[i]);
}
}
}
}
});
return false;
};
self.selectNone = function() {
self.photoIDs.removeAll();
self.selectAllInAlbum(0);
return false;
};
self.selectPhotoSingle = function (link_item) { self.selectPhotoSingle = function (link_item) {
// Get the photo ID from the clicked link // Get the photo ID from the clicked link
var parent = $(link_item).parents('.photo'); var parent = $(link_item).parents('.photo');

View File

@ -42,8 +42,8 @@ return [
'delete_album' => 'Delete album :name', 'delete_album' => 'Delete album :name',
'delete_album_confirm' => 'Are you sure you want to permanently delete this album and all its contents?', 'delete_album_confirm' => 'Are you sure you want to permanently delete this album and all its contents?',
'delete_album_warning' => 'This is a permanent action that cannot be undone!', 'delete_album_warning' => 'This is a permanent action that cannot be undone!',
'delete_bulk_photos_message' => 'Are you sure you want to delete the :number selected photos? This action cannot be undone!', 'delete_bulk_photos_message' => 'Are you sure you want to delete the selected photos? This action cannot be undone!',
'delete_bulk_photos_title' => 'Delete :number photos', 'delete_bulk_photos_title' => 'Delete selected photos',
'delete_photo_message' => 'Are you sure you want to delete this photo? This action cannot be undone!', 'delete_photo_message' => 'Are you sure you want to delete this photo? This action cannot be undone!',
'delete_photo_successful_message' => 'The photo ":name" was deleted successfully.', 'delete_photo_successful_message' => 'The photo ":name" was deleted successfully.',
'delete_photo_title' => 'Delete photo', 'delete_photo_title' => 'Delete photo',
@ -90,6 +90,15 @@ return [
], ],
'save_changes_heading' => 'Save changes', 'save_changes_heading' => 'Save changes',
'save_changes_intro' => 'If you have made any changes to the above fields, you\'ll need to hit the Save Changes button below.', 'save_changes_intro' => 'If you have made any changes to the above fields, you\'ll need to hit the Save Changes button below.',
'select_all_action' => 'Select all',
'select_all_album_active' => 'Any action you select in the list below will apply to all photos in this album.',
'select_all_choice' => [
'all_action' => 'All in this album',
'message' => 'Do you want to select all the photos in the album, or just those that are visible on this page?',
'title' => 'Select all in album?',
'visible_action' => 'Only those visible'
],
'select_none_action' => 'Clear selection',
'settings_image_protection' => 'Image Protection', 'settings_image_protection' => 'Image Protection',
'settings_recaptcha' => 'reCAPTCHA settings', 'settings_recaptcha' => 'reCAPTCHA settings',
'settings_save_action' => 'Update Settings', 'settings_save_action' => 'Update Settings',

View File

@ -48,6 +48,16 @@
@endforeach @endforeach
<div class="pull-left" style="margin-bottom: 15px;"> <div class="pull-left" style="margin-bottom: 15px;">
<p style="margin-bottom: 15px;">
<button data-bind="click: selectAll" type="button" class="btn btn-default">@lang('admin.select_all_action')</button>
<button data-bind="click: selectNone" type="button" class="btn btn-default">@lang('admin.select_none_action')</button>
</p>
<input data-bind="value: selectAllInAlbum" type="hidden" name="select-all-album"/>
<div data-bind="visible: selectAllInAlbum" class="alert alert-warning">
<p>@lang('admin.select_all_album_active')</p>
</div>
<p>{!! Form::label('bulk-action', trans('forms.bulk_edit_photos_label'), ['class' => 'control-label']) !!}</p> <p>{!! Form::label('bulk-action', trans('forms.bulk_edit_photos_label'), ['class' => 'control-label']) !!}</p>
{!! Form::hidden('new-album-id', $album->id) !!} {!! Form::hidden('new-album-id', $album->id) !!}
{!! Form::select('bulk-action', $bulk_actions, null, ['placeholder' => trans('forms.bulk_edit_photos_placeholder'), 'id' => 'bulk-action-apply', 'data-bind' => 'value: bulkModifyMethod, enable: photoIDs().length > 0']) !!} {!! Form::select('bulk-action', $bulk_actions, null, ['placeholder' => trans('forms.bulk_edit_photos_placeholder'), 'id' => 'bulk-action-apply', 'data-bind' => 'value: bulkModifyMethod, enable: photoIDs().length > 0']) !!}
@ -247,6 +257,10 @@
language.delete_bulk_confirm_title = '{!! addslashes(trans('admin.delete_bulk_photos_title')) !!}'; language.delete_bulk_confirm_title = '{!! addslashes(trans('admin.delete_bulk_photos_title')) !!}';
language.delete_confirm_message = '{!! addslashes(trans('admin.delete_photo_message')) !!}'; language.delete_confirm_message = '{!! addslashes(trans('admin.delete_photo_message')) !!}';
language.delete_confirm_title = '{!! addslashes(trans('admin.delete_photo_title')) !!}'; language.delete_confirm_title = '{!! addslashes(trans('admin.delete_photo_title')) !!}';
language.select_all_choice_all_action = '{!! addslashes(trans('admin.select_all_choice.all_action')) !!}';
language.select_all_choice_message = '{!! addslashes(trans('admin.select_all_choice.message')) !!}';
language.select_all_choice_title = '{!! addslashes(trans('admin.select_all_choice.title')) !!}';
language.select_all_choice_visible_action = '{!! addslashes(trans('admin.select_all_choice.visible_action')) !!}';
language.image_failed = '{!! addslashes(trans('admin.upload_file_status_failed')) !!}'; language.image_failed = '{!! addslashes(trans('admin.upload_file_status_failed')) !!}';
language.image_uploaded = '{!! addslashes(trans('admin.upload_file_status_success')) !!}'; language.image_uploaded = '{!! addslashes(trans('admin.upload_file_status_success')) !!}';
language.upload_status = '{!! addslashes(trans('admin.upload_file_status_progress')) !!}'; language.upload_status = '{!! addslashes(trans('admin.upload_file_status_progress')) !!}';
@ -262,6 +276,10 @@
var viewModel = new UploadPhotosViewModel('{{ $album->id }}', '{{ $queue_token }}', language, urls); var viewModel = new UploadPhotosViewModel('{{ $album->id }}', '{{ $queue_token }}', language, urls);
var editViewModel = new EditPhotosViewModel('{{ $album->id }}', language, urls); var editViewModel = new EditPhotosViewModel('{{ $album->id }}', language, urls);
@foreach ($photos as $photo)
editViewModel.photoIDsAvailable.push('{{ $photo->id }}');
@endforeach
// Populate the list of albums in the view model // Populate the list of albums in the view model
@foreach ($albums as $album) @foreach ($albums as $album)
editViewModel.albums.push({ editViewModel.albums.push({