mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-12 16:13:58 -07:00
Moved source code under src folder - massive change
This commit is contained in:
parent
2fc8123d6b
commit
5bf0e197ec
1499 changed files with 1054 additions and 1444 deletions
69
src/UI/Mixins/AsValidatedView.js
Normal file
69
src/UI/Mixins/AsValidatedView.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
define(
|
||||
[
|
||||
'backbone.validation',
|
||||
'underscore',
|
||||
'jQuery/jquery.validation'
|
||||
], function (Validation, _) {
|
||||
'use strict';
|
||||
|
||||
return function () {
|
||||
|
||||
var originalOnRender = this.prototype.onRender;
|
||||
var originalBeforeClose = this.prototype.onBeforeClose;
|
||||
|
||||
var errorHandler = function (response) {
|
||||
|
||||
if (response.status === 400) {
|
||||
|
||||
var view = this;
|
||||
var validationErrors = JSON.parse(response.responseText);
|
||||
_.each(validationErrors, function (error) {
|
||||
view.$el.processServerError(error);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var validatedSync = function (method, model,options) {
|
||||
this.$el.removeAllErrors();
|
||||
arguments[2].isValidatedCall = true;
|
||||
return model._originalSync.apply(this, arguments).fail(errorHandler.bind(this));
|
||||
};
|
||||
|
||||
var bindToModel = function (model) {
|
||||
|
||||
if (!model._originalSync) {
|
||||
model._originalSync = model.sync;
|
||||
model.sync = validatedSync.bind(this);
|
||||
}
|
||||
};
|
||||
|
||||
this.prototype.onRender = function () {
|
||||
|
||||
Validation.bind(this);
|
||||
this.bindToModelValidation = bindToModel.bind(this);
|
||||
|
||||
if (this.model) {
|
||||
this.bindToModelValidation(this.model);
|
||||
}
|
||||
|
||||
if (originalOnRender) {
|
||||
originalOnRender.call(this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.prototype.onBeforeClose = function () {
|
||||
|
||||
if (this.model) {
|
||||
Validation.unbind(this);
|
||||
}
|
||||
|
||||
if (originalBeforeClose) {
|
||||
originalBeforeClose.call(this);
|
||||
}
|
||||
};
|
||||
|
||||
return this;
|
||||
};
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue