|
@@ -124,6 +124,67 @@ var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressError
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+var doAjaxFormData = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply) {
|
|
|
+ console.log(data);
|
|
|
+ if (ajaxGoing) {
|
|
|
+ console.log('ajax stopped!');
|
|
|
+ //return; TODO: fix and re-enable return
|
|
|
+ }
|
|
|
+ ajaxGoing = true;
|
|
|
+ if (!shouldHideMask) {
|
|
|
+ showMask();
|
|
|
+ }
|
|
|
+ jQuery.ajax(url, {
|
|
|
+ dataType: 'json',
|
|
|
+ data: data,
|
|
|
+ processData: false,
|
|
|
+ contentType: false,
|
|
|
+ type: 'POST',
|
|
|
+ beforeSend: function () {
|
|
|
+ if (pre) {
|
|
|
+ pre();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .done(function (response, b) {
|
|
|
+ console.log(response);
|
|
|
+ var success = response.success;
|
|
|
+ if (success) {
|
|
|
+ if (onSuccess) {
|
|
|
+ onSuccess(response.data);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (onFailure) {
|
|
|
+ onFailure(response.message);
|
|
|
+ }
|
|
|
+ if (!suppressErrorMessage) {
|
|
|
+ //toast the error message
|
|
|
+ //alert(response.message);
|
|
|
+ toastr.error(response.message); // , toastr.success("message") ... .warning(), .error()
|
|
|
+ }
|
|
|
+ hideMask();
|
|
|
+ }
|
|
|
+ if (immediatelyHideMaskOnReply) {
|
|
|
+ hideMask();
|
|
|
+ }
|
|
|
+ ajaxGoing = false;
|
|
|
+ })
|
|
|
+ .fail(function (jqXHR, textStatus) {
|
|
|
+ hideMask();
|
|
|
+ toastr.error('Unable to process');
|
|
|
+ if (onHttpFailure) {
|
|
|
+ onHttpFailure(textStatus);
|
|
|
+ }
|
|
|
+ ajaxGoing = false;
|
|
|
+ })
|
|
|
+ .always(function () {
|
|
|
+ if (post) {
|
|
|
+ post();
|
|
|
+ }
|
|
|
+ ajaxGoing = false;
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
var justLog = false; //THIS IS FOR TEST MODE, FORMS WILL NOT TRIGGER REFRESH/REDIR
|
|
|
|
|
|
var pageReload = function () {
|
|
@@ -420,36 +481,91 @@ var initMoes = function() {
|
|
|
});
|
|
|
console.log(data);
|
|
|
//var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply)
|
|
|
- doAjax(url, data, null, function () {
|
|
|
- moe.isProcessing = false;
|
|
|
- }, function (data) {
|
|
|
- if (justLog) { // this is to test!
|
|
|
- console.log('RETURNED', data);
|
|
|
- } else if (redir) {
|
|
|
- if (redir == "back") {
|
|
|
- window.top.history.back();
|
|
|
+
|
|
|
+ // override with FormData if the form has any files
|
|
|
+ let useFormData = false;
|
|
|
+ if($(form).find('input[type="file"]').length) {
|
|
|
+ let formData = new FormData();
|
|
|
+ for(let x in data) {
|
|
|
+ if(data.hasOwnProperty(x)) {
|
|
|
+ formData.set(x, data[x]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $(form).find('input[type="file"]').each(function() {
|
|
|
+ let fieldName = this.name;
|
|
|
+ if(this.files && this.files.length) {
|
|
|
+ formData.append(fieldName, this.files[0]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ data = formData;
|
|
|
+ useFormData = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!useFormData) {
|
|
|
+ doAjax(url, data, null, function () {
|
|
|
+ moe.isProcessing = false;
|
|
|
+ }, function (data) {
|
|
|
+ if (justLog) { // this is to test!
|
|
|
+ console.log('RETURNED', data);
|
|
|
+ } else if (redir) {
|
|
|
+ if (redir == "back") {
|
|
|
+ window.top.history.back();
|
|
|
+ } else {
|
|
|
+ if (redir.indexOf('[data]') > -1) {
|
|
|
+ redir = redir.replace('[data]', data);
|
|
|
+ }
|
|
|
+ fastLoad(redir, true, false);
|
|
|
+ }
|
|
|
+ } else if (moeParent.length) {
|
|
|
+ showMask();
|
|
|
+ $.get(moeParent.attr('url'), function (_data) {
|
|
|
+ moeParent.html(_data);
|
|
|
+ hideMask();
|
|
|
+ hideMoeFormMask();
|
|
|
+ initMoes();
|
|
|
+ initFastLoad(moeParent);
|
|
|
+ initAutoRxAndICDComplete();
|
|
|
+ });
|
|
|
} else {
|
|
|
- if (redir.indexOf('[data]') > -1) {
|
|
|
- redir = redir.replace('[data]', data);
|
|
|
+ pageReload();
|
|
|
+ }
|
|
|
+ }, function (errorMessage) {
|
|
|
+
|
|
|
+ }, false);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ doAjaxFormData(url, data, null, function () {
|
|
|
+ moe.isProcessing = false;
|
|
|
+ }, function (data) {
|
|
|
+ if (justLog) { // this is to test!
|
|
|
+ console.log('RETURNED', data);
|
|
|
+ } else if (redir) {
|
|
|
+ if (redir == "back") {
|
|
|
+ window.top.history.back();
|
|
|
+ } else {
|
|
|
+ if (redir.indexOf('[data]') > -1) {
|
|
|
+ redir = redir.replace('[data]', data);
|
|
|
+ }
|
|
|
+ fastLoad(redir, true, false);
|
|
|
}
|
|
|
- fastLoad(redir, true, false);
|
|
|
+ } else if (moeParent.length) {
|
|
|
+ showMask();
|
|
|
+ $.get(moeParent.attr('url'), function (_data) {
|
|
|
+ moeParent.html(_data);
|
|
|
+ hideMask();
|
|
|
+ hideMoeFormMask();
|
|
|
+ initMoes();
|
|
|
+ initFastLoad(moeParent);
|
|
|
+ initAutoRxAndICDComplete();
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ pageReload();
|
|
|
}
|
|
|
- } else if (moeParent.length) {
|
|
|
- showMask();
|
|
|
- $.get(moeParent.attr('url'), function (_data) {
|
|
|
- moeParent.html(_data);
|
|
|
- hideMask();
|
|
|
- hideMoeFormMask();
|
|
|
- initMoes();
|
|
|
- initFastLoad(moeParent);
|
|
|
- initAutoRxAndICDComplete();
|
|
|
- });
|
|
|
- } else {
|
|
|
- pageReload();
|
|
|
- }
|
|
|
- }, function (errorMessage) {
|
|
|
+ }, function (errorMessage) {
|
|
|
+
|
|
|
+ }, false);
|
|
|
+ }
|
|
|
|
|
|
- }, false);
|
|
|
}
|
|
|
});
|
|
|
|