Browse Source

Debug variable in JavaScript side, log all ajax requests to console

Vova Tkach 5 years ago
parent
commit
0d68eff6be
3 changed files with 15 additions and 2 deletions
  1. 12 2
      assets/cp.scripts.js
  2. 0 0
      assets/cp.scripts.js.go
  3. 3 0
      main.go

+ 12 - 2
assets/cp.scripts.js

@@ -3348,6 +3348,10 @@
 		// Private
 		var FormDataWasChanged = false;
 
+		function IsDebugMode() {
+			return window.fave_debug && window.fave_debug === true;
+		};
+
 		function GetModalAlertTmpl(title, message, error) {
 			return '<div class="alert alert-' + (!error?'success':'danger') + ' alert-dismissible fade show" role="alert"><strong>' + title + '</strong> ' + message + '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
 		};
@@ -3408,8 +3412,10 @@
 					data: form.serialize()
 				}).done(function(data) {
 					FormDataWasChanged = false;
+					if(IsDebugMode()) console.log('done', data);
 					AjaxDone(data)
 				}).fail(function(xhr, status, error) {
+					if(IsDebugMode()) console.log('fail', xhr, status, error);
 					AjaxFail(xhr.responseText, status, error);
 				}).always(function() {
 					// Add delay for one second
@@ -3676,8 +3682,10 @@
 							action: 'index-user-logout',
 						}
 					}).done(function(data) {
-						AjaxDone(data)
+						if(IsDebugMode()) console.log('done', data);
+						AjaxDone(data);
 					}).fail(function(xhr, status, error) {
+						if(IsDebugMode()) console.log('fail', xhr, status, error);
 						AjaxFail(xhr.responseText, status, error);
 					});
 				}
@@ -3693,8 +3701,10 @@
 							id: id,
 						}
 					}).done(function(data) {
-						AjaxDone(data)
+						if(IsDebugMode()) console.log('done', data);
+						AjaxDone(data);
 					}).fail(function(xhr, status, error) {
+						if(IsDebugMode()) console.log('fail', xhr, status, error);
 						AjaxFail(xhr.responseText, status, error);
 					});
 				}

File diff suppressed because it is too large
+ 0 - 0
assets/cp.scripts.js.go


+ 3 - 0
main.go

@@ -101,6 +101,9 @@ func main() {
 		// Mounted assets
 		if res.Response(w, r, func(w http.ResponseWriter, r *http.Request, i *resource.OneResource) {
 			w.Header().Set("Cache-Control", "public, max-age=31536000")
+			if consts.ParamDebug && i.Path == "assets/cp/scripts.js" {
+				w.Write([]byte("window.fave_debug=true;"))
+			}
 		}, nil) {
 			return
 		}

Some files were not shown because too many files changed in this diff