Skip to content

Commit

Permalink
👍 Frontend js support
Browse files Browse the repository at this point in the history
  • Loading branch information
juzaweb committed May 1, 2024
1 parent 591b44a commit e398c81
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
10 changes: 6 additions & 4 deletions modules/CMS/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,27 @@ function (Throwable $e) {
public function render($request, Throwable $e)
{
if ($this->is404Exception($e)) {
$message = $e->getMessage() ?: 'Page not found';

if ($request->expectsJson()) {
return response()->json(['message' => 'Page not found'], 404);
return response()->json(['message' => $message], 404);
}

if ($request->is(config('juzaweb.admin_prefix').'/*')) {
return response()->view('cms::404', ['message' => 'Page not found'], 404);
return response()->view('cms::404', ['message' => $message], 404);
}

if (view()->exists(theme_viewname('theme::404'))) {
return response()->view(
theme_viewname('theme::404'),
['message' => 'Page not found'],
['message' => $message],
404
);
}

return response()->view(
'cms::404',
['message' => 'Page not found'],
['message' => $message],
404
);
}
Expand Down
8 changes: 4 additions & 4 deletions resources/assets/js/form-ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
*/

$(function () {
function sendMessageByResponse(response, notify = false) {
function sendMessageByResponse(response, notify = false, form = null) {
if (notify) {
if (typeof show_notify !== 'undefined' && typeof show_notify === 'function') {
show_notify(response);
}
} else {
if (typeof show_message !== 'undefined' && typeof show_message === 'function') {
show_message(response);
show_message(response, false, form);
}
}
}
Expand All @@ -38,7 +38,7 @@ $(function () {
contentType: false,
processData: false
}).done(function(response) {
sendMessageByResponse(response, notify);
sendMessageByResponse(response, notify, form);

if (submitSuccess) {
let handler = eval(submitSuccess)(form, response);
Expand Down Expand Up @@ -75,7 +75,7 @@ $(function () {
btnsubmit.html(currentText);
}

sendMessageByResponse(response, notify);
sendMessageByResponse(response, notify, form);
return false;
});
}
Expand Down
11 changes: 8 additions & 3 deletions resources/assets/js/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function get_message_response(response)
}
}

function show_message(response, append = false)
function show_message(response, append = false, form = null)
{
let msg = get_message_response(response);
if (!msg) {
Expand All @@ -91,10 +91,15 @@ function show_message(response, append = false)
${msg.status ? '<i class="fa fa-check"></i>' : '<i class="fa fa-times"></i>' } ${msg.message}
</div>`;

let el = $('#jquery-message');
if (form && form.find('.form-mesage').length > 0) {
el = form.find('.form-mesage');
}

if (append) {
$('#jquery-message').append(msgHTML);
el.append(msgHTML);
} else {
$('#jquery-message').html(msgHTML);
el.html(msgHTML);
}
}

Expand Down
2 changes: 1 addition & 1 deletion resources/assets/public/js/custom.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit e398c81

Please sign in to comment.