mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-20 21:54:25 -04:00
108 lines
3.7 KiB
JavaScript
108 lines
3.7 KiB
JavaScript
define(
|
|
[
|
|
'jquery'
|
|
], function ($) {
|
|
'use strict';
|
|
|
|
$.fn.processServerError = function (error) {
|
|
|
|
var validationName = error.propertyName.toLowerCase();
|
|
|
|
var errorMessage = this.formatErrorMessage(error);
|
|
|
|
this.find('.validation-errors')
|
|
.addClass('alert alert-danger')
|
|
.append('<div><i class="icon-exclamation-sign"></i>' + errorMessage + '</div>');
|
|
|
|
if (!validationName || validationName === "") {
|
|
this.addFormError(error);
|
|
return;
|
|
}
|
|
|
|
var input = this.find('[name]').filter(function () {
|
|
return this.name.toLowerCase() === validationName;
|
|
});
|
|
|
|
if (input.length === 0) {
|
|
input = this.find('[validation-name]').filter(function () {
|
|
return $(this).attr('validation-name').toLowerCase() === validationName;
|
|
});
|
|
|
|
//still not found?
|
|
if (input.length === 0) {
|
|
this.addFormError(error);
|
|
console.error('couldn\'t find input for ' + error.propertyName);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
var controlGroup = input.parents('.form-group');
|
|
|
|
if(controlGroup.length === 0) {
|
|
controlGroup = input.parent();
|
|
}
|
|
else{
|
|
var inputGroup = controlGroup.find('.input-group');
|
|
|
|
if (inputGroup.length === 0) {
|
|
controlGroup.append('<span class="help-inline validation-error">' + errorMessage + '</span>');
|
|
}
|
|
|
|
else {
|
|
inputGroup.parent().append('<span class="help-block validation-error">' + errorMessage + '</span>');
|
|
}
|
|
}
|
|
|
|
controlGroup.addClass('has-error');
|
|
|
|
return controlGroup.find('.help-inline').text();
|
|
};
|
|
|
|
|
|
$.fn.processClientError = function (error) {
|
|
|
|
};
|
|
|
|
$.fn.addFormError = function (error) {
|
|
|
|
var errorMessage = this.formatErrorMessage(error);
|
|
|
|
if (this.find('.modal-body')) {
|
|
this.find('.modal-body').prepend('<div class="alert alert-danger validation-error">' + errorMessage + '</div>');
|
|
}
|
|
|
|
else {
|
|
this.prepend('<div class="alert alert-danger validation-error">' + errorMessage + '</div>');
|
|
}
|
|
};
|
|
|
|
$.fn.removeAllErrors = function () {
|
|
this.find('.has-error').removeClass('has-error');
|
|
this.find('.error').removeClass('error');
|
|
this.find('.validation-errors').removeClass('alert').removeClass('alert-danger').html('');
|
|
this.find('.validation-error').remove();
|
|
return this.find('.help-inline.error-message').remove();
|
|
};
|
|
|
|
$.fn.formatErrorMessage = function (error) {
|
|
|
|
var errorMessage = error.errorMessage;
|
|
var infoLink = "";
|
|
|
|
if (error.infoLink) {
|
|
if (error.detailedDescription) {
|
|
errorMessage += " <a class=\"no-router\" target=\"_blank\" href=\"" + error.infoLink + "\"><i class=\"icon-external-link\" title=\"" + error.detailedDescription + "\"></i></a>";
|
|
}
|
|
else {
|
|
errorMessage += " <a class=\"no-router\" target=\"_blank\" href=\"" + error.infoLink + "\"><i class=\"icon-external-link\"></i></a>";
|
|
}
|
|
}
|
|
else if (error.detailedDescription) {
|
|
errorMessage += " <i class=\"icon-nd-form-info\" title=\"" + error.detailedDescription + "\"></i>";
|
|
}
|
|
|
|
return errorMessage;
|
|
}
|
|
|
|
});
|