Skip to content

Commit 7014e5d

Browse files
committed
fix: fix issues when displaying error from deleting and renaming
1 parent 423f1ad commit 7014e5d

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

public/js/script.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ function performLfmRequest(url, parameter, type) {
284284
}
285285

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

290294
var refreshFoldersAndItems = function (data) {
@@ -540,7 +544,7 @@ function rename(item) {
540544
}
541545

542546
function trash(items) {
543-
notify(lang['message-delete'], function () {
547+
confirm(lang['message-delete'], function () {
544548
performLfmRequest('delete', {
545549
items: items.map(function (item) { return item.name; })
546550
}).done(refreshFoldersAndItems)
@@ -794,12 +798,16 @@ function notImp() {
794798
notify('Not yet implemented!');
795799
}
796800

797-
function notify(body, callback) {
798-
$('#notify').find('.btn-primary').toggle(callback !== undefined);
799-
$('#notify').find('.btn-primary').unbind().click(callback);
801+
function notify(body) {
800802
$('#notify').modal('show').find('.modal-body').html(body);
801803
}
802804

805+
function confirm(body, callback) {
806+
$('#confirm').find('.btn-primary').toggle(callback !== undefined);
807+
$('#confirm').find('.btn-primary').click(callback);
808+
$('#confirm').modal('show').find('.modal-body').html(body);
809+
}
810+
803811
function dialog(title, value, callback) {
804812
$('#dialog').find('input').val(value);
805813
$('#dialog').on('shown.bs.modal', function () {

src/Controllers/DeleteController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getDelete()
7171
}
7272

7373
if (count($errors) > 0) {
74-
return $errors;
74+
return response()->json($errors, 400);
7575
}
7676

7777
return parent::$success_response;

src/Controllers/LfmController.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function getErrors()
7676
*
7777
* @return null
7878
*/
79-
public function applyIniOverrides()
79+
private function applyIniOverrides()
8080
{
8181
$overrides = config('lfm.php_ini_overrides', []);
8282

@@ -90,4 +90,10 @@ public function applyIniOverrides()
9090
}
9191
}
9292
}
93+
94+
// TODO: remove this after refactoring RenameController and DeleteController
95+
protected function error($error_type, $variables = [])
96+
{
97+
return trans(Lfm::PACKAGE_NAME . '::lfm.error-' . $error_type, $variables);
98+
}
9399
}

src/Controllers/RenameController.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ public function getRename()
2929

3030
if (empty($new_name)) {
3131
if ($is_directory) {
32-
return parent::error('folder-name');
32+
return response()->json(parent::error('folder-name'), 400);
3333
} else {
34-
return parent::error('file-name');
34+
return response()->json(parent::error('file-name'), 400);
3535
}
3636
}
3737

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

4646
if (! $is_directory) {

src/views/index.blade.php

+11
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@
136136
</div>
137137

138138
<div class="modal fade" id="notify" tabindex="-1" role="dialog" aria-hidden="true">
139+
<div class="modal-dialog modal-lg">
140+
<div class="modal-content">
141+
<div class="modal-body"></div>
142+
<div class="modal-footer">
143+
<button type="button" class="btn btn-secondary w-100" data-dismiss="modal">{{ trans('laravel-filemanager::lfm.btn-close') }}</button>
144+
</div>
145+
</div>
146+
</div>
147+
</div>
148+
149+
<div class="modal fade" id="confirm" tabindex="-1" role="dialog" aria-hidden="true">
139150
<div class="modal-dialog modal-lg">
140151
<div class="modal-content">
141152
<div class="modal-body"></div>

0 commit comments

Comments
 (0)