Преглед на файлове

[fix] callback for ajax (#3802)

* [fix] callback for ajax

* [fix] ajaxSend instead of ajaxStart
version-14
Rushabh Mehta преди 8 години
committed by Makarand Bauskar
родител
ревизия
a0aa9a2079
променени са 1 файла, в които са добавени 18 реда и са изтрити 12 реда
  1. +18
    -12
      frappe/public/js/frappe/request.js

+ 18
- 12
frappe/public/js/frappe/request.js Целия файл

@@ -8,6 +8,8 @@ frappe.request.url = '/';
frappe.request.ajax_count = 0; frappe.request.ajax_count = 0;
frappe.request.waiting_for_ajax = []; frappe.request.waiting_for_ajax = [];




// generic server call (call page, object) // generic server call (call page, object)
frappe.call = function(opts) { frappe.call = function(opts) {
if(opts.quiet) { if(opts.quiet) {
@@ -180,7 +182,7 @@ frappe.request.call = function(opts) {
console.log("Unable to handle success response"); // eslint-disable-line console.log("Unable to handle success response"); // eslint-disable-line
console.trace(e); // eslint-disable-line console.trace(e); // eslint-disable-line
} }
}) })
.always(function(data, textStatus, xhr) { .always(function(data, textStatus, xhr) {
try { try {
@@ -218,8 +220,6 @@ frappe.request.call = function(opts) {


// call execute serverside request // call execute serverside request
frappe.request.prepare = function(opts) { frappe.request.prepare = function(opts) {
frappe.request.ajax_count++;
$("body").attr("data-ajax-state", "triggered"); $("body").attr("data-ajax-state", "triggered");


// btn indicator // btn indicator
@@ -258,7 +258,7 @@ frappe.request.cleanup = function(opts, r) {


// un-freeze page // un-freeze page
if(opts.freeze) frappe.dom.unfreeze(); if(opts.freeze) frappe.dom.unfreeze();
if(r) { if(r) {


// session expired? - Guest has no business here! // session expired? - Guest has no business here!
@@ -304,14 +304,6 @@ frappe.request.cleanup = function(opts, r) {
} }


frappe.last_response = r; frappe.last_response = r;

frappe.request.ajax_count--;
if(!frappe.request.ajax_count) {
$.each(frappe.request.waiting_for_ajax || [], function(i, fn) {
fn();
});
frappe.request.waiting_for_ajax = [];
}
} }


frappe.after_server_call = () => { frappe.after_server_call = () => {
@@ -413,3 +405,17 @@ frappe.request.cleanup_request_opts = function(request_opts) {
} }
return request_opts; return request_opts;
}; };

$(document).ajaxSend(function() {
frappe.request.ajax_count++;
});

$(document).ajaxComplete(function() {
frappe.request.ajax_count--;
if(!frappe.request.ajax_count) {
$.each(frappe.request.waiting_for_ajax || [], function(i, fn) {
fn();
});
frappe.request.waiting_for_ajax = [];
}
});

Зареждане…
Отказ
Запис