Etemplate: Check dirty before closing, ask if there are changes

This commit is contained in:
nathangray
2020-06-19 13:27:41 -06:00
parent 73515cd412
commit 52714f0a63
14 changed files with 149 additions and 23 deletions

View File

@ -58,6 +58,14 @@ var et2_inputWidget = /** @class */ (function (_super) {
_super.prototype.destroy.call(this);
this._labelContainer = null;
};
/**
* Make sure dirty flag is properly set
*/
et2_inputWidget.prototype.doLoadingFinished = function () {
var result = _super.prototype.doLoadingFinished.call(this);
this.resetDirty();
return result;
};
/**
* Load the validation errors from the server
*
@ -212,7 +220,25 @@ var et2_inputWidget = /** @class */ (function (_super) {
return this._oldValue;
};
et2_inputWidget.prototype.isDirty = function () {
return this._oldValue != this.getValue();
var value = this.getValue();
if (typeof value !== typeof this._oldValue) {
return true;
}
if (this._oldValue === value) {
return false;
}
switch (typeof this._oldValue) {
case "object":
if (this._oldValue.length !== value.length)
return true;
for (var key in this._oldValue) {
if (this._oldValue[key] !== value[key])
return true;
}
return false;
default:
return this._oldValue != value;
}
};
et2_inputWidget.prototype.resetDirty = function () {
this._oldValue = this.getValue();