Skip to content

Commit

Permalink
fix: fix issues when displaying error from deleting and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
streamtw committed Feb 27, 2024
1 parent 423f1ad commit 7014e5d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
18 changes: 13 additions & 5 deletions public/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ function performLfmRequest(url, parameter, type) {
}

function displayErrorResponse(jqXHR) {
notify('<div style="max-height:50vh;overflow: scroll;">' + jqXHR.responseText + '</div>');
var message = JSON.parse(jqXHR.responseText)
if (Array.isArray(message)) {
message = message.join('<br>')
}
notify('<div style="max-height:50vh;overflow: auto;">' + message + '</div>');
}

var refreshFoldersAndItems = function (data) {
Expand Down Expand Up @@ -540,7 +544,7 @@ function rename(item) {
}

function trash(items) {
notify(lang['message-delete'], function () {
confirm(lang['message-delete'], function () {
performLfmRequest('delete', {
items: items.map(function (item) { return item.name; })
}).done(refreshFoldersAndItems)
Expand Down Expand Up @@ -794,12 +798,16 @@ function notImp() {
notify('Not yet implemented!');
}

function notify(body, callback) {
$('#notify').find('.btn-primary').toggle(callback !== undefined);
$('#notify').find('.btn-primary').unbind().click(callback);
function notify(body) {
$('#notify').modal('show').find('.modal-body').html(body);
}

function confirm(body, callback) {
$('#confirm').find('.btn-primary').toggle(callback !== undefined);
$('#confirm').find('.btn-primary').click(callback);
$('#confirm').modal('show').find('.modal-body').html(body);
}

function dialog(title, value, callback) {
$('#dialog').find('input').val(value);
$('#dialog').on('shown.bs.modal', function () {
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/DeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getDelete()
}

if (count($errors) > 0) {
return $errors;
return response()->json($errors, 400);
}

return parent::$success_response;
Expand Down
8 changes: 7 additions & 1 deletion src/Controllers/LfmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getErrors()
*
* @return null
*/
public function applyIniOverrides()
private function applyIniOverrides()
{
$overrides = config('lfm.php_ini_overrides', []);

Expand All @@ -90,4 +90,10 @@ public function applyIniOverrides()
}
}
}

// TODO: remove this after refactoring RenameController and DeleteController
protected function error($error_type, $variables = [])
{
return trans(Lfm::PACKAGE_NAME . '::lfm.error-' . $error_type, $variables);
}
}
10 changes: 5 additions & 5 deletions src/Controllers/RenameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ public function getRename()

if (empty($new_name)) {
if ($is_directory) {
return parent::error('folder-name');
return response()->json(parent::error('folder-name'), 400);
} else {
return parent::error('file-name');
return response()->json(parent::error('file-name'), 400);
}
}

if ($is_directory && config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $new_name)) {
return parent::error('folder-alnum');
return response()->json(parent::error('folder-alnum'), 400);
} elseif (config('lfm.alphanumeric_filename') && preg_match('/[^.\w-]/i', $new_name)) {
return parent::error('file-alnum');
return response()->json(parent::error('file-alnum'), 400);
} elseif ($this->lfm->setName($new_name)->exists()) {
return parent::error('rename');
return response()->json(parent::error('rename'), 400);
}

if (! $is_directory) {
Expand Down
11 changes: 11 additions & 0 deletions src/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@
</div>

<div class="modal fade" id="notify" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary w-100" data-dismiss="modal">{{ trans('laravel-filemanager::lfm.btn-close') }}</button>
</div>
</div>
</div>
</div>

<div class="modal fade" id="confirm" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-body"></div>
Expand Down

0 comments on commit 7014e5d

Please sign in to comment.