diff --git a/public/assets/js/common.js b/public/assets/js/common.js
new file mode 100644
index 00000000..9dea7705
--- /dev/null
+++ b/public/assets/js/common.js
@@ -0,0 +1,14 @@
+$(function() {
+ $(document).ajaxError(function(event, response, ajaxSettings, thrownError) {
+ switch (response.status) {
+ case 500:
+ default:
+ swal({
+ title: 'Whoops!',
+ text: 'We encountered a problem. Please contact technical support.',
+ type: 'error'
+ });
+ break;
+ }
+ });
+});
\ No newline at end of file
diff --git a/templates/base.html.twig b/templates/base.html.twig
index 410b42fc..84dbcbb4 100644
--- a/templates/base.html.twig
+++ b/templates/base.html.twig
@@ -694,6 +694,7 @@
+
diff --git a/templates/battery-manufacturer/form.html.twig b/templates/battery-manufacturer/form.html.twig
index 0cbcedd1..1e6cc90d 100644
--- a/templates/battery-manufacturer/form.html.twig
+++ b/templates/battery-manufacturer/form.html.twig
@@ -86,38 +86,40 @@
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/battery-manufacturer/list.html.twig b/templates/battery-manufacturer/list.html.twig
index 8c13c188..7d345225 100644
--- a/templates/battery-manufacturer/list.html.twig
+++ b/templates/battery-manufacturer/list.html.twig
@@ -137,12 +137,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/battery-model/form.html.twig b/templates/battery-model/form.html.twig
index dd14199f..9bdf618f 100644
--- a/templates/battery-model/form.html.twig
+++ b/templates/battery-model/form.html.twig
@@ -86,38 +86,40 @@
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/battery-model/list.html.twig b/templates/battery-model/list.html.twig
index bec1aa6d..4af0226d 100644
--- a/templates/battery-model/list.html.twig
+++ b/templates/battery-model/list.html.twig
@@ -137,12 +137,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/battery-size/form.html.twig b/templates/battery-size/form.html.twig
index 1f309d40..4736a772 100644
--- a/templates/battery-size/form.html.twig
+++ b/templates/battery-size/form.html.twig
@@ -86,38 +86,40 @@
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/battery-size/list.html.twig b/templates/battery-size/list.html.twig
index 7afe2389..ecde061b 100644
--- a/templates/battery-size/list.html.twig
+++ b/templates/battery-size/list.html.twig
@@ -137,12 +137,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/battery/form.html.twig b/templates/battery/form.html.twig
index 51c8cdb8..a1801412 100644
--- a/templates/battery/form.html.twig
+++ b/templates/battery/form.html.twig
@@ -264,38 +264,40 @@
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/battery/list.html.twig b/templates/battery/list.html.twig
index 28fe3a32..e3acf6ec 100644
--- a/templates/battery/list.html.twig
+++ b/templates/battery/list.html.twig
@@ -171,12 +171,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/customer/form.html.twig b/templates/customer/form.html.twig
index c98cc459..21c4784e 100644
--- a/templates/customer/form.html.twig
+++ b/templates/customer/form.html.twig
@@ -369,99 +369,101 @@
}
});
}).fail(function(response) {
- var json = response.responseJSON;
- var errors = json.errors;
- var nerrors = json.nerrors;
- var verrors = json.verrors;
- var firstfield = false;
+ if (response.status == 422) {
+ var json = response.responseJSON;
+ var errors = json.errors;
+ var nerrors = json.nerrors;
+ var verrors = json.verrors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[data-name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
-
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
-
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
-
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
-
- // add error class to this tab
- var tabId = $(formfield).closest('.tab-pane').prop('id');
- $("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
- });
-
- // loop through mobile number errors
- $.each(nerrors, function(rowindex, errorlist) {
- var row = $("#data-mobile-numbers table").find("[name='index'][value='" + rowindex + "']").closest('tr');
-
- $.each(errorlist, function(field, msg) {
- var msgbox = row.find(".form-control-feedback[data-field='" + field + "']");
- var col = msgbox.closest('span');
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[data-name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
// add error classes to bad fields
- col.addClass('has-danger');
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
msgbox.html(msg).addClass('has-danger').removeClass('hide');
// check if this field comes first in DOM
- var domfield = col.get(0);
+ var domfield = formfield.get(0);
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
firstfield = domfield;
}
// add error class to this tab
- var tabId = $(col).closest('.tab-pane').prop('id');
+ var tabId = $(formfield).closest('.tab-pane').prop('id');
$("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
});
- });
- // loop through vehicle errors
- $.each(verrors, function(rowindex, errorlist) {
- var row = $("#data-vehicles table").find("[name='index'][value='" + rowindex + "']").closest('tr');
+ // loop through mobile number errors
+ $.each(nerrors, function(rowindex, errorlist) {
+ var row = $("#data-mobile-numbers table").find("[name='index'][value='" + rowindex + "']").closest('tr');
- $.each(errorlist, function(field, msg) {
- var msgbox = row.find(".form-control-feedback[data-field='" + field + "']");
- var col = msgbox.closest('span');
+ $.each(errorlist, function(field, msg) {
+ var msgbox = row.find(".form-control-feedback[data-field='" + field + "']");
+ var col = msgbox.closest('span');
- // add error classes to bad fields
- col.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ col.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = col.get(0);
+ // check if this field comes first in DOM
+ var domfield = col.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
- // add error class to this tab
- var tabId = $(col).closest('.tab-pane').prop('id');
- $("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
+ // add error class to this tab
+ var tabId = $(col).closest('.tab-pane').prop('id');
+ $("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
+ });
});
- });
- // focus on tab containing first field
- var firstTabId = $(firstfield).closest('.tab-pane').prop('id');
- $("#customer-tabs").find("a[href='#" + firstTabId + "']").tab('show');
+ // loop through vehicle errors
+ $.each(verrors, function(rowindex, errorlist) {
+ var row = $("#data-vehicles table").find("[name='index'][value='" + rowindex + "']").closest('tr');
- // focus on first bad field
- firstfield.focus();
+ $.each(errorlist, function(field, msg) {
+ var msgbox = row.find(".form-control-feedback[data-field='" + field + "']");
+ var col = msgbox.closest('span');
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // add error classes to bad fields
+ col.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
+
+ // check if this field comes first in DOM
+ var domfield = col.get(0);
+
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+
+ // add error class to this tab
+ var tabId = $(col).closest('.tab-pane').prop('id');
+ $("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
+ });
+ });
+
+ // focus on tab containing first field
+ var firstTabId = $(firstfield).closest('.tab-pane').prop('id');
+ $("#customer-tabs").find("a[href='#" + firstTabId + "']").tab('show');
+
+ // focus on first bad field
+ firstfield.focus();
+
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/customer/list.html.twig b/templates/customer/list.html.twig
index 7a5aa28f..0bb7036a 100644
--- a/templates/customer/list.html.twig
+++ b/templates/customer/list.html.twig
@@ -192,12 +192,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/hub/form.html.twig b/templates/hub/form.html.twig
index ea6a6c68..6efb573d 100644
--- a/templates/hub/form.html.twig
+++ b/templates/hub/form.html.twig
@@ -269,38 +269,40 @@ $(function() {
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/hub/list.html.twig b/templates/hub/list.html.twig
index 77102f24..398e9c26 100644
--- a/templates/hub/list.html.twig
+++ b/templates/hub/list.html.twig
@@ -154,12 +154,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig
index 32c94240..5d6950c1 100644
--- a/templates/job-order/form.html.twig
+++ b/templates/job-order/form.html.twig
@@ -698,38 +698,40 @@ $(function() {
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "'], [data-name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "'], [data-name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/outlet/form.html.twig b/templates/outlet/form.html.twig
index 13857f77..73ce5f8c 100644
--- a/templates/outlet/form.html.twig
+++ b/templates/outlet/form.html.twig
@@ -248,38 +248,40 @@ $(function() {
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/outlet/list.html.twig b/templates/outlet/list.html.twig
index 40781c9f..cdda3f33 100644
--- a/templates/outlet/list.html.twig
+++ b/templates/outlet/list.html.twig
@@ -158,12 +158,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/promo/form.html.twig b/templates/promo/form.html.twig
index 72c0dd96..1d59df8d 100644
--- a/templates/promo/form.html.twig
+++ b/templates/promo/form.html.twig
@@ -114,38 +114,40 @@ $(function() {
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/promo/list.html.twig b/templates/promo/list.html.twig
index e36f7a76..c42c6710 100644
--- a/templates/promo/list.html.twig
+++ b/templates/promo/list.html.twig
@@ -146,12 +146,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/rider/form.html.twig b/templates/rider/form.html.twig
index 5654553c..def5e92c 100644
--- a/templates/rider/form.html.twig
+++ b/templates/rider/form.html.twig
@@ -169,38 +169,40 @@
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/rider/list.html.twig b/templates/rider/list.html.twig
index 1d9dedd4..6f11ffe9 100644
--- a/templates/rider/list.html.twig
+++ b/templates/rider/list.html.twig
@@ -161,12 +161,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/role/form.html.twig b/templates/role/form.html.twig
index 554f5862..5b3e6344 100644
--- a/templates/role/form.html.twig
+++ b/templates/role/form.html.twig
@@ -116,38 +116,40 @@
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/role/list.html.twig b/templates/role/list.html.twig
index 4332f3eb..5a1248cd 100644
--- a/templates/role/list.html.twig
+++ b/templates/role/list.html.twig
@@ -133,12 +133,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/ticket/form.html.twig b/templates/ticket/form.html.twig
index 3c4d8e22..93a699e7 100644
--- a/templates/ticket/form.html.twig
+++ b/templates/ticket/form.html.twig
@@ -138,38 +138,40 @@
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/ticket/list.html.twig b/templates/ticket/list.html.twig
index efbd460f..3238942f 100644
--- a/templates/ticket/list.html.twig
+++ b/templates/ticket/list.html.twig
@@ -163,12 +163,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/user/form.html.twig b/templates/user/form.html.twig
index 040dc6b1..234c3c02 100644
--- a/templates/user/form.html.twig
+++ b/templates/user/form.html.twig
@@ -184,38 +184,40 @@
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/user/list.html.twig b/templates/user/list.html.twig
index ad650b76..36f7d5ed 100644
--- a/templates/user/list.html.twig
+++ b/templates/user/list.html.twig
@@ -165,12 +165,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/vehicle-manufacturer/form.html.twig b/templates/vehicle-manufacturer/form.html.twig
index 4bf0ac08..d2cf5920 100644
--- a/templates/vehicle-manufacturer/form.html.twig
+++ b/templates/vehicle-manufacturer/form.html.twig
@@ -86,38 +86,40 @@
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/vehicle-manufacturer/list.html.twig b/templates/vehicle-manufacturer/list.html.twig
index 5a7cae59..dc5a9b1c 100644
--- a/templates/vehicle-manufacturer/list.html.twig
+++ b/templates/vehicle-manufacturer/list.html.twig
@@ -137,12 +137,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});
diff --git a/templates/vehicle/form.html.twig b/templates/vehicle/form.html.twig
index 95523dfa..970065e5 100644
--- a/templates/vehicle/form.html.twig
+++ b/templates/vehicle/form.html.twig
@@ -122,38 +122,40 @@
}
});
}).fail(function(response) {
- var errors = response.responseJSON.errors;
- var firstfield = false;
+ if (response.status == 422) {
+ var errors = response.responseJSON.errors;
+ var firstfield = false;
- // remove all error classes first
- removeErrors();
+ // remove all error classes first
+ removeErrors();
- // display errors contextually
- $.each(errors, function(field, msg) {
- var formfield = $("[name='" + field + "']");
- var label = $("label[data-field='" + field + "']");
- var msgbox = $(".form-control-feedback[data-field='" + field + "']");
+ // display errors contextually
+ $.each(errors, function(field, msg) {
+ var formfield = $("[name='" + field + "']");
+ var label = $("label[data-field='" + field + "']");
+ var msgbox = $(".form-control-feedback[data-field='" + field + "']");
- // add error classes to bad fields
- formfield.addClass('form-control-danger');
- label.addClass('has-danger');
- msgbox.html(msg).addClass('has-danger').removeClass('hide');
+ // add error classes to bad fields
+ formfield.addClass('form-control-danger');
+ label.addClass('has-danger');
+ msgbox.html(msg).addClass('has-danger').removeClass('hide');
- // check if this field comes first in DOM
- var domfield = formfield.get(0);
+ // check if this field comes first in DOM
+ var domfield = formfield.get(0);
- if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
- firstfield = domfield;
- }
- });
+ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
+ firstfield = domfield;
+ }
+ });
- // focus on first bad field
- firstfield.focus();
+ // focus on first bad field
+ firstfield.focus();
- // scroll to above that field to make it visible
- $('html, body').animate({
- scrollTop: $(firstfield).offset().top - 200
- }, 100);
+ // scroll to above that field to make it visible
+ $('html, body').animate({
+ scrollTop: $(firstfield).offset().top - 200
+ }, 100);
+ }
});
});
diff --git a/templates/vehicle/list.html.twig b/templates/vehicle/list.html.twig
index 84ee78cf..cf264655 100644
--- a/templates/vehicle/list.html.twig
+++ b/templates/vehicle/list.html.twig
@@ -145,12 +145,6 @@
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
- }).fail(function() {
- swal({
- title: 'Whoops',
- text: 'An error occurred while deleting this item. Please contact support.',
- type: 'error'
- });
});
}
});