com.phloxui
Version:
PhloxUI Ng2+ Framework
1,357 lines (1,356 loc) • 116 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
import * as tslib_1 from "tslib";
import { EventEmitter, ViewChildren, QueryList } from '@angular/core';
import { AbstractI18NApplicable } from '../share/AbstractI18NApplicable';
import { Option } from '../decorator/decorators';
import { LOAD_EVENT } from '../share/CustomEventType';
import { EventUtils } from '../share/utils/EventUtils';
import { Preload } from '../directive/Preload.directive';
var /** @type {?} */ DEFAULT_IGNORE_PARENT_DATA = false;
var /** @type {?} */ DEFAULT_DELEGATE_HISTORY = true;
/**
* <p style="text-indent: 2em;">
* An abstract concrete base class of [[IHasData]] interface. All classes implementing [[IHasData]] interface should extend this class.
* For more information, please see [[IHasData]].
* </p>
*
* @author shiorin, tee4cute
* @see [[IHasData]]
* @abstract
*/
var AbstractHasData = /** @class */ (function (_super) {
tslib_1.__extends(AbstractHasData, _super);
function AbstractHasData(elementRef, kbShortcutService) {
var _this = _super.call(this) || this;
_this.dataChildren = [];
_this.histories = [];
_this.historyCursor = -1;
_this.elementRef = elementRef;
_this._disabled = false;
_this._loaded = false;
_this._loading = false;
_this.kbShortcutService = kbShortcutService;
_this.loadingEnabled = true;
return _this;
}
Object.defineProperty(AbstractHasData.prototype, "disabled", {
get: /**
* @return {?}
*/
function () {
if (this.dataParent !== null && typeof this.dataParent !== 'undefined') {
var /** @type {?} */ parent_1 = this.dataParent;
if (typeof parent_1.isDisabled === 'function' && !this.ignoreParentDisabled) {
return parent_1.isDisabled() || this._disabled;
}
}
return this._disabled;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
// change dom css class
var /** @type {?} */ oldSelfDisabled = this._disabled;
this._disabled = value;
var /** @type {?} */ parentDisabled = false;
if (!this.ignoreParentDisabled && this.dataParent !== null && typeof this.dataParent !== 'undefined') {
// Has parent
var /** @type {?} */ parent_2 = this.dataParent;
if (typeof parent_2.isDisabled === 'function') {
parentDisabled = parent_2.isDisabled();
}
}
var /** @type {?} */ oldDisabled = parentDisabled || oldSelfDisabled;
var /** @type {?} */ currentDisabled = parentDisabled || this._disabled;
if (oldDisabled !== currentDisabled) {
if (currentDisabled) {
this._propagateOnDisabled();
}
else {
this._propagateOnEnabled();
}
}
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
AbstractHasData.prototype.ngOnInit = /**
* @return {?}
*/
function () {
if (this.ignoreParentData === null || typeof this.ignoreParentData === 'undefined') {
this.ignoreParentData = DEFAULT_IGNORE_PARENT_DATA;
}
if (this.delegateHistory === null || typeof this.delegateHistory === 'undefined') {
this.delegateHistory = DEFAULT_DELEGATE_HISTORY;
}
if (this.data !== null && typeof this.data !== 'undefined') {
this.setData(this.data);
}
this.setDataParent(this.dataParent);
if (this.loadingEnabled) {
this.preload();
}
else {
this._loaded = true;
}
// auto regist shortcut key
if (this.kbShortcutService !== null && typeof this.kbShortcutService !== 'undefined') {
if (typeof this["getDefaultShortcutKeyHandlers"] === 'function') {
var /** @type {?} */ defaultKeys = this['getDefaultShortcutKeyHandlers'].call(this);
if (defaultKeys !== null && typeof defaultKeys !== 'undefined') {
try {
for (var defaultKeys_1 = tslib_1.__values(defaultKeys), defaultKeys_1_1 = defaultKeys_1.next(); !defaultKeys_1_1.done; defaultKeys_1_1 = defaultKeys_1.next()) {
var shortcut = defaultKeys_1_1.value;
this.kbShortcutService.addKeyHandler(shortcut);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (defaultKeys_1_1 && !defaultKeys_1_1.done && (_a = defaultKeys_1.return)) _a.call(defaultKeys_1);
}
finally { if (e_1) throw e_1.error; }
}
}
}
if (typeof this["getDefaultShortcutNameHandlers"] === 'function') {
var /** @type {?} */ defaultNames = this["getDefaultShortcutNameHandlers"].call(this);
if (defaultNames !== null && typeof defaultNames !== 'undefined') {
try {
for (var defaultNames_1 = tslib_1.__values(defaultNames), defaultNames_1_1 = defaultNames_1.next(); !defaultNames_1_1.done; defaultNames_1_1 = defaultNames_1.next()) {
var shortcut = defaultNames_1_1.value;
this.kbShortcutService.addNameHandler(shortcut);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (defaultNames_1_1 && !defaultNames_1_1.done && (_b = defaultNames_1.return)) _b.call(defaultNames_1);
}
finally { if (e_2) throw e_2.error; }
}
}
}
}
// Auto call selfSaveData() on inited.
this.selfSaveData(this.data);
var e_1, _a, e_2, _b;
};
/**
* @param {?} changes
* @return {?}
*/
AbstractHasData.prototype.ngOnChanges = /**
* @param {?} changes
* @return {?}
*/
function (changes) {
if (changes['data'] !== null && typeof changes['data'] !== 'undefined') {
var /** @type {?} */ newVal = changes['data'].currentValue;
this.setData(newVal);
}
if (changes['dataParent'] !== null && typeof changes['dataParent'] !== 'undefined') {
var /** @type {?} */ newVal = changes['dataParent'].currentValue;
this.setDataParent(newVal);
}
};
/**
* @return {?}
*/
AbstractHasData.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
// auto unregist shortcut key
if (this.kbShortcutService !== null && typeof this.kbShortcutService !== 'undefined') {
if (typeof this["getDefaultShortcutKeyHandlers"] === 'function') {
var /** @type {?} */ defaultKeys = this['getDefaultShortcutKeyHandlers'].call(this);
try {
for (var defaultKeys_2 = tslib_1.__values(defaultKeys), defaultKeys_2_1 = defaultKeys_2.next(); !defaultKeys_2_1.done; defaultKeys_2_1 = defaultKeys_2.next()) {
var shortcut = defaultKeys_2_1.value;
this.kbShortcutService.removeKeyHandler(shortcut);
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (defaultKeys_2_1 && !defaultKeys_2_1.done && (_a = defaultKeys_2.return)) _a.call(defaultKeys_2);
}
finally { if (e_3) throw e_3.error; }
}
}
if (typeof this["getDefaultShortcutNameHandlers"] === 'function') {
var /** @type {?} */ defaultNames = this["getDefaultShortcutNameHandlers"].call(this);
try {
for (var defaultNames_2 = tslib_1.__values(defaultNames), defaultNames_2_1 = defaultNames_2.next(); !defaultNames_2_1.done; defaultNames_2_1 = defaultNames_2.next()) {
var shortcut = defaultNames_2_1.value;
this.kbShortcutService.removeNameHandler(shortcut);
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (defaultNames_2_1 && !defaultNames_2_1.done && (_b = defaultNames_2.return)) _b.call(defaultNames_2);
}
finally { if (e_4) throw e_4.error; }
}
}
}
var e_3, _a, e_4, _b;
};
/**
* @return {?}
*/
AbstractHasData.prototype._propagateOnDisabled = /**
* @return {?}
*/
function () {
// Firstly, call this.onDisabled(this).
if (this.onDisabled !== null && typeof this.onDisabled === 'function') {
this.onDisabled(this);
}
// Auto add css class "disabled" to this native element.
if (this.elementRef !== null && typeof this.elementRef !== 'undefined') {
var /** @type {?} */ hasClass = $(this.elementRef.nativeElement).hasClass("disabled");
if (!hasClass) {
$(this.elementRef.nativeElement).addClass("disabled");
}
}
// Then, propagate method call to children & descendants.
if (this.dataChildren !== null) {
try {
for (var _a = tslib_1.__values(this.dataChildren), _b = _a.next(); !_b.done; _b = _a.next()) {
var c = _b.value;
var /** @type {?} */ child = /** @type {?} */ (c);
var /** @type {?} */ ignore = false;
if (typeof child.isIgnoreParentDisabled === 'function') {
ignore = child.isIgnoreParentDisabled();
}
if (ignore) {
// If this child ignore parent's disabled, do nothing.
continue;
}
var /** @type {?} */ childSelfDisabled = false;
if (typeof child.isSelfDisabled === 'function') {
childSelfDisabled = child.isSelfDisabled();
}
if (!childSelfDisabled) {
// If the child itself was not disabled before, but, this parent is going to be disabled,
// we'll propagate onDisabled to this child and its descendants.
// So, child._propagateOnDisabled() must be called.
if (typeof child._propagateOnDisabled === 'function') {
child._propagateOnDisabled();
}
}
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_5) throw e_5.error; }
}
}
var e_5, _c;
};
/**
* @return {?}
*/
AbstractHasData.prototype._propagateOnEnabled = /**
* @return {?}
*/
function () {
// Firstly, call this.onEnabled(this).
if (this.onEnabled !== null && typeof this.onEnabled === 'function') {
this.onEnabled(this);
}
// Auto remove css class "disabled" from this native element.
if (this.elementRef !== null && typeof this.elementRef !== 'undefined') {
var /** @type {?} */ hasClass = $(this.elementRef.nativeElement).hasClass("disabled");
if (hasClass) {
$(this.elementRef.nativeElement).removeClass("disabled");
}
}
// Then, propagate method call to children & descendants.
if (this.dataChildren !== null) {
try {
for (var _a = tslib_1.__values(this.dataChildren), _b = _a.next(); !_b.done; _b = _a.next()) {
var c = _b.value;
var /** @type {?} */ child = /** @type {?} */ (c);
var /** @type {?} */ ignore = false;
if (typeof child.isIgnoreParentDisabled === 'function') {
ignore = child.isIgnoreParentDisabled();
}
if (ignore) {
// If this child ignore parent's disabled, do nothing.
continue;
}
var /** @type {?} */ childSelfDisabled = false;
if (typeof child.isSelfDisabled === 'function') {
childSelfDisabled = child.isSelfDisabled();
}
if (!childSelfDisabled) {
// If the child itself was not disabled before, but, this parent is going to be enabled,
// we'll propagate onEnabled to this child and its descendants.
// So, child._propagateOnEnabled() must be called.
if (typeof child._propagateOnEnabled === 'function') {
child._propagateOnEnabled();
}
}
}
}
catch (e_6_1) { e_6 = { error: e_6_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_6) throw e_6.error; }
}
}
var e_6, _c;
};
/**
* @param {?} first
* @param {?=} component
* @param {?=} name
* @return {?}
*/
AbstractHasData.prototype._makeHistory = /**
* @param {?} first
* @param {?=} component
* @param {?=} name
* @return {?}
*/
function (first, component, name) {
if (this.isDelegateHistory() && this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent['makeHistory'] === 'function') {
var /** @type {?} */ comp = component;
if ((comp === null || typeof comp === 'undefined') && typeof this['getCurrentHistoryState'] === 'function') {
comp = this;
}
return (/** @type {?} */ (this.dataParent)).makeHistory(comp, name);
}
}
if (!first) {
if (this.histories.length <= 0) {
throw new Error('The method "makeFirstHistory()" should be called at the first time before calling subsequent "makeHistory()".');
}
}
else {
if (this.histories.length > 0) {
throw new Error('The method "makeFirstHistory()" can be called once.');
}
}
if (component === null || typeof component === 'undefined') {
component = /** @type {?} */ (this);
}
if (typeof component.getCurrentHistoryState !== 'function') {
throw new Error('The "component" is not an instance of IHistoryManaged: ' + component.constructor.name);
}
var /** @type {?} */ state = JSON.parse(JSON.stringify(component.getCurrentHistoryState()));
var /** @type {?} */ history = {
component: component,
name: name,
state: state
};
this.histories.splice(this.historyCursor + 1, this.histories.length - this.historyCursor - 1, history);
this.historyCursor = this.histories.length - 1;
return history;
};
/**
* @return {?}
*/
AbstractHasData.prototype.getData = /**
* @return {?}
*/
function () {
return this.data;
};
/**
* @return {?}
*/
AbstractHasData.prototype.getChainData = /**
* @return {?}
*/
function () {
return this.data;
};
/**
* @return {?}
*/
AbstractHasData.prototype.chainData = /**
* @return {?}
*/
function () {
if (this.dataChildren !== null) {
var /** @type {?} */ cData = this.getChainData();
try {
for (var _a = tslib_1.__values(this.dataChildren), _b = _a.next(); !_b.done; _b = _a.next()) {
var c = _b.value;
if (c.isIgnoreParentData()) {
continue;
}
c.setData(cData);
}
}
catch (e_7_1) { e_7 = { error: e_7_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_7) throw e_7.error; }
}
}
var e_7, _c;
};
/**
* @param {?} data
* @return {?}
*/
AbstractHasData.prototype.setData = /**
* @param {?} data
* @return {?}
*/
function (data) {
this.data = data;
this.chainData();
};
/**
* @param {?} child
* @return {?}
*/
AbstractHasData.prototype.addDataChild = /**
* @param {?} child
* @return {?}
*/
function (child) {
if (this.dataChildren !== null) {
this.dataChildren.push(child);
// Auto set data from parent to child if it has no data.
if (child.getData() === undefined && !child.isIgnoreParentData()) {
var /** @type {?} */ cData = this.getChainData();
child.setData(cData);
}
// Auto propagate disabled flag to child if this parent is disabled.
if (this.isDisabled() && typeof child['setDisabled'] === 'function') {
var /** @type {?} */ ignore = false;
if (typeof child['isIgnoreParentDisabled'] === 'function') {
ignore = (/** @type {?} */ (child)).isIgnoreParentDisabled();
}
if (!ignore) {
(/** @type {?} */ (child)).setDisabled(this.isDisabled());
}
}
var /** @type {?} */ i18nChild = child;
if (typeof this.i18nValue !== 'undefined' && typeof i18nChild.applyI18N === 'function') {
var /** @type {?} */ value = this.i18nValue;
if (value === null) {
i18nChild.applyI18N(null);
}
else if (typeof value.children !== 'undefined') {
var /** @type {?} */ bypass = false;
if (typeof i18nChild.isBypassKey === 'function') {
bypass = i18nChild.isBypassKey();
}
if (bypass) {
i18nChild.applyI18N(value.children);
}
else {
if (value.children === null) {
i18nChild.applyI18N(null);
}
else {
if (typeof i18nChild.getI18NKey === 'function') {
var /** @type {?} */ i18nCVal = value.children[i18nChild.getI18NKey()];
if (i18nCVal !== 'undefined') {
i18nChild.applyI18N(i18nCVal);
}
}
}
}
}
}
}
};
/**
* @param {?} child
* @return {?}
*/
AbstractHasData.prototype.removeDataChild = /**
* @param {?} child
* @return {?}
*/
function (child) {
if (this.dataChildren !== null) {
var /** @type {?} */ cIndex = this.dataChildren.indexOf(child);
if (cIndex > -1) {
this.dataChildren.splice(cIndex, 1);
}
}
};
/**
* @param {?} dataParent
* @return {?}
*/
AbstractHasData.prototype.setDataParent = /**
* @param {?} dataParent
* @return {?}
*/
function (dataParent) {
if (this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent.removeDataChild === 'function') {
this.dataParent.removeDataChild(this);
}
}
this.dataParent = dataParent;
if (this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent.addDataChild === 'function') {
this.dataParent.addDataChild(this);
}
}
};
/**
* @return {?}
*/
AbstractHasData.prototype.getDataParent = /**
* @return {?}
*/
function () {
return this.dataParent;
};
/**
* @return {?}
*/
AbstractHasData.prototype.getDataChildren = /**
* @return {?}
*/
function () {
return this.dataChildren;
};
/**
* @return {?}
*/
AbstractHasData.prototype.isDataDirty = /**
* @return {?}
*/
function () {
if (this.dataChildren !== null) {
try {
for (var _a = tslib_1.__values(this.dataChildren), _b = _a.next(); !_b.done; _b = _a.next()) {
var c = _b.value;
if (c.isDataDirty()) {
return true;
}
}
}
catch (e_8_1) { e_8 = { error: e_8_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_8) throw e_8.error; }
}
}
return this.isSelfDataDirty();
var e_8, _c;
};
/**
* @param {?} ignore
* @return {?}
*/
AbstractHasData.prototype.setIgnoreParentData = /**
* @param {?} ignore
* @return {?}
*/
function (ignore) {
this.ignoreParentData = ignore;
};
/**
* @return {?}
*/
AbstractHasData.prototype.isIgnoreParentData = /**
* @return {?}
*/
function () {
return this.ignoreParentData;
};
/**
* @param {?} ignore
* @return {?}
*/
AbstractHasData.prototype.setIgnoreParentDisabled = /**
* @param {?} ignore
* @return {?}
*/
function (ignore) {
this.ignoreParentDisabled = ignore;
};
/**
* @return {?}
*/
AbstractHasData.prototype.isIgnoreParentDisabled = /**
* @return {?}
*/
function () {
return this.ignoreParentDisabled;
};
/**
* @param {?=} data
* @return {?}
*/
AbstractHasData.prototype.saveData = /**
* @param {?=} data
* @return {?}
*/
function (data) {
if (data === undefined) {
data = this.data;
}
if (this.dataChildren !== null) {
try {
for (var _a = tslib_1.__values(this.dataChildren), _b = _a.next(); !_b.done; _b = _a.next()) {
var c = _b.value;
c.saveData(data);
}
}
catch (e_9_1) { e_9 = { error: e_9_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_9) throw e_9.error; }
}
}
this.selfSaveData(data);
var e_9, _c;
};
/**
* @return {?}
*/
AbstractHasData.prototype.resetData = /**
* @return {?}
*/
function () {
if (this.dataChildren !== null) {
try {
for (var _a = tslib_1.__values(this.dataChildren), _b = _a.next(); !_b.done; _b = _a.next()) {
var c = _b.value;
c.resetData();
}
}
catch (e_10_1) { e_10 = { error: e_10_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_10) throw e_10.error; }
}
}
return this.selfResetData();
var e_10, _c;
};
/**
* @param {?} value
* @return {?}
*/
AbstractHasData.prototype.applyI18N = /**
* @param {?} value
* @return {?}
*/
function (value) {
if (typeof value === 'undefined') {
return;
}
_super.prototype.applyI18N.call(this, value);
if (this.dataChildren !== null) {
try {
for (var _a = tslib_1.__values(this.dataChildren), _b = _a.next(); !_b.done; _b = _a.next()) {
var c = _b.value;
var /** @type {?} */ child = /** @type {?} */ (c);
// check if child is applicable
if (typeof child.applyI18N === 'function') {
if (value === null) {
child.applyI18N(null);
}
else {
if (typeof value.children !== 'undefined') {
var /** @type {?} */ bypass = false;
if (typeof child.isBypassKey === 'function') {
bypass = child.isBypassKey();
}
if (bypass) {
child.applyI18N(value.children);
}
else {
if (value.children === null) {
child.applyI18N(null);
}
else {
if (typeof child.getI18NKey === 'function') {
var /** @type {?} */ i18nCVal = value.children[child.getI18NKey()];
if (i18nCVal !== 'undefined') {
child.applyI18N(i18nCVal);
}
}
}
}
}
}
}
}
}
catch (e_11_1) { e_11 = { error: e_11_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_11) throw e_11.error; }
}
}
var e_11, _c;
};
/**
* @return {?}
*/
AbstractHasData.prototype.isDelegateHistory = /**
* @return {?}
*/
function () {
return this.delegateHistory;
};
/**
* @param {?} delegate
* @return {?}
*/
AbstractHasData.prototype.setDelegateHistory = /**
* @param {?} delegate
* @return {?}
*/
function (delegate) {
this.delegateHistory = delegate;
};
/**
* @return {?}
*/
AbstractHasData.prototype.getOnEnabled = /**
* @return {?}
*/
function () {
return this.onEnabled;
};
/**
* @param {?} handler
* @return {?}
*/
AbstractHasData.prototype.setOnEnabled = /**
* @param {?} handler
* @return {?}
*/
function (handler) {
this.onEnabled = handler;
};
/**
* @return {?}
*/
AbstractHasData.prototype.getOnDisabled = /**
* @return {?}
*/
function () {
return this.onDisabled;
};
/**
* @param {?} handler
* @return {?}
*/
AbstractHasData.prototype.setOnDisabled = /**
* @param {?} handler
* @return {?}
*/
function (handler) {
this.onDisabled = handler;
};
/**
* @return {?}
*/
AbstractHasData.prototype.getLoadEvent = /**
* @return {?}
*/
function () {
return this.loadEvent;
};
/**
* @param {?} event
* @return {?}
*/
AbstractHasData.prototype.setLoadEvent = /**
* @param {?} event
* @return {?}
*/
function (event) {
this.loadEvent = event;
};
/**
* @param {?=} component
* @param {?=} name
* @return {?}
*/
AbstractHasData.prototype.makeFirstHistory = /**
* @param {?=} component
* @param {?=} name
* @return {?}
*/
function (component, name) {
return this._makeHistory(true, component, name);
};
/**
* @param {?=} component
* @param {?=} name
* @return {?}
*/
AbstractHasData.prototype.makeHistory = /**
* @param {?=} component
* @param {?=} name
* @return {?}
*/
function (component, name) {
return this._makeHistory(false, component, name);
};
/**
* @param {?=} steps
* @return {?}
*/
AbstractHasData.prototype.undo = /**
* @param {?=} steps
* @return {?}
*/
function (steps) {
if (steps === void 0) { steps = 1; }
if (this.isDelegateHistory() && this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent['undo'] === 'function') {
return (/** @type {?} */ (this.dataParent)).undo(steps);
}
}
if (steps === null || typeof steps !== 'number') {
steps = 1;
}
if (steps <= 0) {
steps = 1;
}
// We use "steps > this.historyCursor" instead of "this.historyCursor + 1"
// since we want to limit the first history should not be able to be undone.
if (steps > this.historyCursor) {
steps = this.historyCursor;
}
if (steps <= 0) {
// If no more history can be undone, return Promise<null>.
return Promise.resolve(null);
}
var /** @type {?} */ revertTo = this.histories[this.historyCursor - steps];
var /** @type {?} */ clonedState = JSON.parse(JSON.stringify(revertTo.state));
this.historyCursor = this.historyCursor - steps;
return revertTo.component.loadHistoryState(revertTo, clonedState).then(function () {
return revertTo;
});
};
/**
* @param {?=} steps
* @return {?}
*/
AbstractHasData.prototype.redo = /**
* @param {?=} steps
* @return {?}
*/
function (steps) {
if (steps === void 0) { steps = 1; }
if (this.isDelegateHistory() && this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent['redo'] === 'function') {
return (/** @type {?} */ (this.dataParent)).redo(steps);
}
}
if (steps === null || typeof steps !== 'number') {
steps = 1;
}
if (steps <= 0) {
steps = 1;
}
if (steps > this.histories.length - this.historyCursor - 1) {
steps = this.histories.length - this.historyCursor - 1;
}
if (steps <= 0) {
// If no more history can be redone, return Promise<null>.
return Promise.resolve(null);
}
var /** @type {?} */ revertTo = this.histories[this.historyCursor + steps];
var /** @type {?} */ clonedState = JSON.parse(JSON.stringify(revertTo.state));
this.historyCursor = this.historyCursor + steps;
return revertTo.component.loadHistoryState(revertTo, clonedState).then(function () {
return revertTo;
});
};
/**
* @return {?}
*/
AbstractHasData.prototype.canUndo = /**
* @return {?}
*/
function () {
if (this.isDelegateHistory() && this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent['canUndo'] === 'function') {
return (/** @type {?} */ (this.dataParent)).canUndo();
}
}
// We use "this.historyCursor > 0" instead of "this.historyCursor > -1" here
// since we want to limit the first history should not be able to be undone.
return this.historyCursor > 0 && this.histories.length > 0;
};
/**
* @return {?}
*/
AbstractHasData.prototype.canRedo = /**
* @return {?}
*/
function () {
if (this.isDelegateHistory() && this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent['canRedo'] === 'function') {
return (/** @type {?} */ (this.dataParent)).canRedo();
}
}
return this.historyCursor < this.histories.length - 1;
};
/**
* @return {?}
*/
AbstractHasData.prototype.clearForwardHistories = /**
* @return {?}
*/
function () {
if (this.isDelegateHistory() && this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent['clearForwardHistories'] === 'function') {
return (/** @type {?} */ (this.dataParent)).clearForwardHistories();
}
}
var /** @type {?} */ re = this.histories.slice(this.historyCursor + 1, this.histories.length);
this.histories.splice(this.historyCursor + 1, this.histories.length - this.historyCursor - 1);
return re;
};
/**
* @return {?}
*/
AbstractHasData.prototype.clearBackwardHistories = /**
* @return {?}
*/
function () {
if (this.isDelegateHistory() && this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent['clearBackwardHistories'] === 'function') {
return (/** @type {?} */ (this.dataParent)).clearBackwardHistories();
}
}
var /** @type {?} */ re = this.histories.slice(0, this.historyCursor + 1);
this.histories.splice(0, this.historyCursor + 1);
if (this.histories.length > 0) {
this.historyCursor = 0;
}
else {
this.historyCursor = -1;
}
return re;
};
/**
* @return {?}
*/
AbstractHasData.prototype.clearHistories = /**
* @return {?}
*/
function () {
if (this.isDelegateHistory() && this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent['clearHistories'] === 'function') {
return (/** @type {?} */ (this.dataParent)).clearHistories();
}
}
var /** @type {?} */ re = this.histories;
this.histories = [];
this.historyCursor = -1;
return re;
};
/**
* @return {?}
*/
AbstractHasData.prototype.getHistories = /**
* @return {?}
*/
function () {
if (this.isDelegateHistory() && this.dataParent !== null && typeof this.dataParent !== 'undefined') {
if (typeof this.dataParent['getHistories'] === 'function') {
return (/** @type {?} */ (this.dataParent)).getHistories();
}
}
return [].concat(this.histories);
};
/**
* @return {?}
*/
AbstractHasData.prototype.isDisabled = /**
* @return {?}
*/
function () {
return this.disabled;
};
/**
* @param {?} disabled
* @return {?}
*/
AbstractHasData.prototype.setDisabled = /**
* @param {?} disabled
* @return {?}
*/
function (disabled) {
// Auto propagate to children.
this.disabled = disabled;
};
/**
* @return {?}
*/
AbstractHasData.prototype.isSelfDisabled = /**
* @return {?}
*/
function () {
return this._disabled;
};
/**
* @return {?}
*/
AbstractHasData.prototype.isLoadingEnabled = /**
* @return {?}
*/
function () {
return this.loadingEnabled;
};
/**
* @param {?} success
* @param {?} resultOrError
* @return {?}
*/
AbstractHasData.prototype.loaded = /**
* @param {?} success
* @param {?} resultOrError
* @return {?}
*/
function (success, resultOrError) {
if (this._loaded) {
// Prevent calling this method twice.
return;
}
this._loaded = true;
// Let sub class implement its own behavior.
try {
this.doLoaded(success, resultOrError);
}
catch (/** @type {?} */ e) {
console.error(e);
}
this.loadSuccess = success;
// Auto remove css class
// Should declare css class as static const
if (this.elementRef !== undefined && this.elementRef !== null) {
$(this.elementRef.nativeElement).removeClass("loading");
}
// emit event
var /** @type {?} */ data = {
success: success,
resultOrError: resultOrError
};
var /** @type {?} */ ev = EventUtils.newCustomEvent(LOAD_EVENT, this, data, null);
if (this.loadEvent !== null && this.loadEvent !== undefined) {
this.loadEvent.emit(ev);
}
};
/**
* @return {?}
*/
AbstractHasData.prototype.isLoading = /**
* @return {?}
*/
function () {
return this._loading;
};
/**
* @return {?}
*/
AbstractHasData.prototype.isLoaded = /**
* @return {?}
*/
function () {
return this._loaded;
};
/**
* @return {?}
*/
AbstractHasData.prototype.isLoadSuccess = /**
* @return {?}
*/
function () {
return this.loadSuccess;
};
/**
* @return {?}
*/
AbstractHasData.prototype.getElementRef = /**
* @return {?}
*/
function () {
return this.elementRef;
};
/**
* @return {?}
*/
AbstractHasData.prototype.selfValidateData = /**
* @return {?}
*/
function () {
// The default implementation will return empty array.
// Sub class should override this method if necessary.
return [];
};
/**
* @return {?}
*/
AbstractHasData.prototype.validateData = /**
* @return {?}
*/
function () {
var /** @type {?} */ results = this.selfValidateData();
if (results === null || typeof results === 'undefined' || !Array.isArray(results)) {
results = [];
}
// Chain this method to children & descendants.
if (this.dataChildren !== null && typeof this.dataChildren !== 'undefined') {
try {
for (var _a = tslib_1.__values(this.dataChildren), _b = _a.next(); !_b.done; _b = _a.next()) {
var c = _b.value;
var /** @type {?} */ child = c;
if (typeof child.validateData === 'function') {
// Force set autoFocusOnError = false to children since we'll only do auto
// focus once when all results are obtained.
var /** @type {?} */ childResults = child.validateData(false);
if (childResults !== null && Array.isArray(childResults)) {
// Add all child's results into results.
results = results.concat(childResults);
}
}
}
}
catch (e_12_1) { e_12 = { error: e_12_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_12) throw e_12.error; }
}
}
return results;
var e_12, _c;
};
/**
* @return {?}
*/
AbstractHasData.prototype.addPreloadDom = /**
* @return {?}
*/
function () {
if (!this.preloadList) {
return;
}
this.preloadList.forEach(function (item, index, array) {
item.show();
});
};
/**
* @return {?}
*/
AbstractHasData.prototype.removePreloadDom = /**
* @return {?}
*/
function () {
if (!this.preloadList) {
return;
}
this.preloadList.forEach(function (item, index, array) {
item.hide();
});
};
/**
* @return {?}
*/
AbstractHasData.prototype.preload = /**
* @return {?}
*/
function () {
var _this = this;
if (this._loading) {
// Prevent calling method twice
return;
}
// Set flag loading as "true"
this._loading = true;
// Unset the flag
this._loaded = false;
if (this.elementRef !== undefined && this.elementRef !== null) {
$(this.elementRef.nativeElement).addClass("loading");
}
this.addPreloadDom();
var /** @type {?} */ result = null;
try {
result = this.doPreload();
}
catch (/** @type {?} */ e) {
result = Promise.reject(e);
}
if (result === null || result === undefined || !(result instanceof Promise)) {
result = Promise.resolve(result);
}
return result.then(function (result) {
_this.loaded(true, result);
_this.removePreloadDom();
// Unset flag loading as "false"
// Unset flag loading as "false"
_this._loading = false;
return Promise.resolve(result);
}).catch(function (error) {
_this.loaded(false, error);
_this.removePreloadDom();
// Unset flag loading as "false"
// Unset flag loading as "false"
_this._loading = false;
return Promise.reject(error);
});
};
AbstractHasData.DEFAULT_IGNORE_PARENT_DATA = DEFAULT_IGNORE_PARENT_DATA;
AbstractHasData.DEFAULT_DELEGATE_HISTORY = DEFAULT_DELEGATE_HISTORY;
AbstractHasData.propDecorators = {
"preloadList": [{ type: ViewChildren, args: [Preload,] },],
};
tslib_1.__decorate([
Option(),
tslib_1.__metadata("design:type", Object)
], AbstractHasData.prototype, "dataParent", void 0);
tslib_1.__decorate([
Option(),
tslib_1.__metadata("design:type", Boolean)
], AbstractHasData.prototype, "ignoreParentData", void 0);
tslib_1.__decorate([
Option(),
tslib_1.__metadata("design:type", Boolean)
], AbstractHasData.prototype, "ignoreParentDisabled", void 0);
tslib_1.__decorate([
Option(),
tslib_1.__metadata("design:type", Function)
], AbstractHasData.prototype, "onDisabled", void 0);
tslib_1.__decorate([
Option(),
tslib_1.__metadata("design:type", Function)
], AbstractHasData.prototype, "onEnabled", void 0);
tslib_1.__decorate([
Option(),
tslib_1.__metadata("design:type", Boolean)
], AbstractHasData.prototype, "loadingEnabled", void 0);
tslib_1.__decorate([
Option('load'),
tslib_1.__metadata("design:type", EventEmitter)
], AbstractHasData.prototype, "loadEvent", void 0);
tslib_1.__decorate([
Option(),
tslib_1.__metadata("design:type", Boolean)
], AbstractHasData.prototype, "delegateHistory", void 0);
tslib_1.__decorate([
Option('disabled'),
tslib_1.__metadata("design:type", Boolean),
tslib_1.__metadata("design:paramtypes", [Boolean])
], AbstractHasData.prototype, "disabled", null);
return AbstractHasData;
}(AbstractI18NApplicable));
export { AbstractHasData };
function AbstractHasData_tsickle_Closure_declarations() {
/** @type {!Object<string,!Array<{type: !Function, args: (undefined|!Array<?>)}>>} */
AbstractHasData.propDecorators;
/** @type {?} */
AbstractHasData.DEFAULT_IGNORE_PARENT_DATA;
/** @type {?} */
AbstractHasData.DEFAULT_DELEGATE_HISTORY;
/** @type {?} */
AbstractHasData.prototype.dataParent;
/** @type {?} */
AbstractHasData.prototype.ignoreParentData;
/** @type {?} */
AbstractHasData.prototype.ignoreParentDisabled;
/** @type {?} */
AbstractHasData.prototype.onDisabled;
/** @type {?} */
AbstractHasData.prototype.onEnabled;
/** @type {?} */
AbstractHasData.prototype.loadingEnabled;
/** @type {?} */
AbstractHasData.prototype.loadEvent;
/** @type {?} */
AbstractHasData.prototype.delegateHistory;
/** @type {?} */
AbstractHasData.prototype.preloadList;
/** @type {?} */
AbstractHasData.prototype.historyCursor;
/** @type {?} */
AbstractHasData.prototype.histories;
/** @type {?} */
AbstractHasData.prototype.elementRef;
/** @type {?} */
AbstractHasData.prototype.dataChildren;
/** @type {?} */
AbstractHasData.prototype.data;
/** @type {?} */
AbstractHasData.prototype.kbShortcutService;
/** @type {?} */
AbstractHasData.prototype.loadSuccess;
/** @type {?} */
AbstractHasData.prototype._loading;
/** @type {?} */
AbstractHasData.prototype._loaded;
/** @type {?} */
AbstractHasData.prototype._disabled;
/**
* @abstract
* @return {?}
*/
AbstractHasData.prototype.doPreload = function () { };
/**
* @abstract
* @param {?} success
* @param {?} resultOrError
* @return {?}
*/
AbstractHasData.prototype.doLoaded = function (success, resultOrError) { };
/**
* @abstract
* @return {?}
*/
AbstractHasData.prototype.isSelfDataDirty = function () { };
/**
* @abstract
* @param {?} data
* @return {?}
*/
AbstractHasData.prototype.selfSaveData = function (data) { };
/**
* @abstract
* @return {?}
*/
AbstractHasData.prototype.selfResetData = function () { };
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWJzdHJhY3RIYXNEYXRhLmpzIiwic291cmNlUm9vdCI6Im5nOi8vY29tLnBobG94dWkvIiwic291cmNlcyI6WyJsaWIvY29tcG9uZW50L0Fic3RyYWN0SGFzRGF0YS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLE9BQU8sRUFBNEMsWUFBWSxFQUFFLFlBQVksRUFBUyxTQUFTLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFRdkgsT0FBTyxFQUFFLHNCQUFzQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFekUsT0FBTyxFQUFFLE1BQU0sRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBS2pELE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUN0RCxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFHdkQsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXpELHFCQUFNLDBCQUEwQixHQUFZLEtBQUssQ0FBQztBQUNsRCxxQkFBTSx3QkFBd0IsR0FBWSxJQUFJLENBQUM7Ozs7Ozs7Ozs7OztJQVdELDJDQUFzQjtJQStFbEUseUJBQVksVUFBc0IsRUFBRSxpQkFBMkM7UUF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