mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-16 18:26:06 +01:00
move grav ajax handler to separate file
This commit is contained in:
@@ -49,30 +49,13 @@ $(function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var ajaxRequest = function (url, settings) {
|
|
||||||
settings = typeof settings === 'undefined' ? typeof url === 'string' ? {} : url : settings;
|
|
||||||
settings.url = typeof settings.url === 'undefined' && typeof url === 'string' ? url : settings.url;
|
|
||||||
|
|
||||||
var successHandler = typeof settings.success !== 'undefined' ? typeof settings.success === 'function' ? [ settings.success ] : settings.success : [];
|
|
||||||
successHandler.unshift(ajaxRequest.logoutHandler);
|
|
||||||
settings.success = successHandler;
|
|
||||||
|
|
||||||
return $.ajax(settings);
|
|
||||||
};
|
|
||||||
ajaxRequest.logoutHandler = function (response, status, xhr) {
|
|
||||||
if (response.status && (response.status === "unauthorized" || response.status === "forbidden")) {
|
|
||||||
document.location.href = GravAdmin.config.base_url_relative;
|
|
||||||
throw "Logged out";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Cache Clear
|
// Cache Clear
|
||||||
$('[data-clear-cache]').on('click', function(e) {
|
$('[data-clear-cache]').on('click', function(e) {
|
||||||
|
|
||||||
$(this).attr('disabled','disabled').find('> .fa').removeClass('fa-trash').addClass('fa-refresh fa-spin');
|
$(this).attr('disabled','disabled').find('> .fa').removeClass('fa-trash').addClass('fa-refresh fa-spin');
|
||||||
var url = $(this).data('clearCache');
|
var url = $(this).data('clearCache');
|
||||||
|
|
||||||
ajaxRequest({
|
GravAjax({
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
url: url,
|
url: url,
|
||||||
success: function(result, status) {
|
success: function(result, status) {
|
||||||
@@ -93,7 +76,7 @@ $(function () {
|
|||||||
$(this).attr('disabled','disabled').find('> .fa').removeClass('fa-cloud-download').addClass('fa-refresh fa-spin');
|
$(this).attr('disabled','disabled').find('> .fa').removeClass('fa-cloud-download').addClass('fa-refresh fa-spin');
|
||||||
var url = $(this).data('maintenanceUpdate');
|
var url = $(this).data('maintenanceUpdate');
|
||||||
|
|
||||||
ajaxRequest({
|
GravAjax({
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
url: url,
|
url: url,
|
||||||
success: function(result, status) {
|
success: function(result, status) {
|
||||||
@@ -110,7 +93,7 @@ $(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var GPMRefresh = function () {
|
var GPMRefresh = function () {
|
||||||
ajaxRequest({
|
GravAjax({
|
||||||
dataType: "JSON",
|
dataType: "JSON",
|
||||||
url: window.location.href,
|
url: window.location.href,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
20
themes/grav/js/ajax.js
Normal file
20
themes/grav/js/ajax.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
$(function(){
|
||||||
|
var root = window || {};
|
||||||
|
|
||||||
|
root.GravAjax = function (url, settings) {
|
||||||
|
settings = typeof settings === 'undefined' ? typeof url === 'string' ? {} : url : settings;
|
||||||
|
settings.url = typeof settings.url === 'undefined' && typeof url === 'string' ? url : settings.url;
|
||||||
|
|
||||||
|
var successHandler = typeof settings.success !== 'undefined' ? typeof settings.success === 'function' ? [ settings.success ] : settings.success : [];
|
||||||
|
successHandler.unshift(root.GravAjax.logoutHandler);
|
||||||
|
settings.success = successHandler;
|
||||||
|
|
||||||
|
return $.ajax(settings);
|
||||||
|
};
|
||||||
|
root.GravAjax.logoutHandler = function (response, status, xhr) {
|
||||||
|
if (response.status && (response.status === "unauthorized" || response.status === "forbidden")) {
|
||||||
|
document.location.href = GravAdmin.config.base_url_relative;
|
||||||
|
throw "Logged out";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
{% do assets.addJs(theme_url~'/js/selectize.min.js') %}
|
{% do assets.addJs(theme_url~'/js/selectize.min.js') %}
|
||||||
{% do assets.addJs(theme_url~'/js/toastr.min.js') %}
|
{% do assets.addJs(theme_url~'/js/toastr.min.js') %}
|
||||||
{% do assets.addJs(theme_url~'/js/jquery.remodal.min.js') %}
|
{% do assets.addJs(theme_url~'/js/jquery.remodal.min.js') %}
|
||||||
|
{% do assets.addJs(theme_url~'/js/ajax.js') %}
|
||||||
{% do assets.addJs(theme_url~'/js/admin-all.js') %}
|
{% do assets.addJs(theme_url~'/js/admin-all.js') %}
|
||||||
{{ assets.js() }}
|
{{ assets.js() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user