com.phloxui
Version:
PhloxUI Ng2+ Framework
1,350 lines (1,349 loc) • 145 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
import * as tslib_1 from "tslib";
import { Component, ElementRef, Input, ViewChild, Inject } from '@angular/core';
import { AbstractDataEditorView } from '../AbstractDataEditorView';
import { FormViewModel } from '../../model/FormViewModel';
import { TabPane } from '../../../component/dataview/TabPane.component';
import { TabModel } from '../../model/TabModel';
import { DialogService } from '../../../service/DialogService.service';
import { ArrayUtils } from '../../../share/utils/ArrayUtils';
import { EditorSettingServiceFactory } from '../IEditorSettingServiceFactory';
import { Option } from '../../../decorator/Option.decorator';
import { I18N } from '../../../decorator/I18N.decorator';
import { DataUtils } from '../../../share/utils/DataUtils';
const /** @type {?} */ TYPE_NAME = "phx-form-view";
export class FormView extends AbstractDataEditorView {
/**
* @param {?} dialogService
* @param {?} editorSettingFactory
* @param {?} elementRef
*/
constructor(dialogService, editorSettingFactory, elementRef) {
super(editorSettingFactory, elementRef);
this.tabsData = [];
this.originalTabsData = [];
this.dialogService = dialogService;
this.showMoreMenu = true;
}
/**
* @return {?}
*/
ngOnInit() {
super.ngOnInit();
if (this.editor !== null && (typeof this.editor !== 'undefined')) {
this.editor.addViewComponent(this);
let /** @type {?} */ objIdField = this.editor.getObjectIdField();
if (this.showEvent !== null && (typeof this.showEvent !== 'undefined')) {
this.showEvent.subscribe((event) => {
this.reloadAllTab();
});
}
let /** @type {?} */ createdEvent = this.editor.getDataCreateEvent();
if (createdEvent !== null && (typeof createdEvent !== 'undefined')) {
createdEvent.subscribe((event) => {
let /** @type {?} */ original = null;
let /** @type {?} */ data = null;
if (event.detail !== null && typeof event.detail !== 'undefined') {
if (event.detail.data !== null && typeof event.detail.data !== 'undefined') {
if (event.detail.data.data !== null && typeof event.detail.data.data !== 'undefined') {
data = event.detail.data.data;
}
if (event.detail.data.original !== null && typeof event.detail.data.original !== 'undefined') {
original = event.detail.data.original;
}
}
}
// got id ? update in tab with dataID
if (data !== null) {
// get all tabIndex
let /** @type {?} */ indexMap = {};
if (original !== null) {
for (let /** @type {?} */ i = 0; i < original.length; i++) {
let /** @type {?} */ oriItem = original[i];
let /** @type {?} */ item = null;
if (i < data.length) {
item = data[i];
}
if (item === null || typeof item === 'undefined') {
continue;
}
let /** @type {?} */ tBodyData = this.getWrapDataObject([oriItem]);
let /** @type {?} */ indexArray = this.getTabDataIndexesMatched(tBodyData, false);
for (let /** @type {?} */ index of indexArray) {
if (index <= -1) {
continue;
}
let /** @type {?} */ keyString = index + "";
if (indexMap[keyString] !== null && typeof indexMap[keyString] !== 'undefined') {
indexMap[keyString].push(item);
}
else {
indexMap[keyString] = [item];
}
}
}
}
for (let /** @type {?} */ key in indexMap) {
let /** @type {?} */ curTab = parseInt(key);
let /** @type {?} */ objArray = indexMap[key];
if (curTab > -1) {
// update model title
let /** @type {?} */ tModels = this.tabPane.getTabModels();
let /** @type {?} */ firstData = null;
if (objArray.length > 0) {
firstData = objArray[0];
}
if (curTab < tModels.length) {
tModels[curTab].label = this.generateTabLabel(objArray);
}
// update data in tab
let /** @type {?} */ tBodyData = this.getWrapDataObject(objArray);
this.tabPane.setTabData(curTab, tBodyData);
this.tabPane.saveTabData(curTab);
let /** @type {?} */ tabDataObjs = null;
if (curTab < this.tabsData.length) {
this.tabsData[curTab].objects = [];
tabDataObjs = this.tabsData[curTab].objects;
}
let /** @type {?} */ originalObjs = null;
if (curTab < this.originalTabsData.length) {
this.originalTabsData[curTab] = [];
originalObjs = this.originalTabsData[curTab];
}
for (let /** @type {?} */ d of objArray) {
// add to tabBody
if (tabDataObjs !== null) {
let /** @type {?} */ cloneData = JSON.parse(JSON.stringify(d));
tabDataObjs.push(cloneData);
}
// add to original
if (originalObjs !== null) {
originalObjs.push(d);
}
}
}
}
}
});
}
let /** @type {?} */ updateEvent = this.editor.getDataUpdateEvent();
if (updateEvent !== null && (typeof updateEvent !== 'undefined')) {
updateEvent.subscribe((event) => {
let /** @type {?} */ data = null;
if (event.detail !== null && typeof event.detail !== 'undefined') {
if (event.detail.data !== null && typeof event.detail.data !== 'undefined') {
data = event.detail.data.data;
}
}
if (data !== null) {
// update data in tab
let /** @type {?} */ tBodyData = null;
if (Array.isArray(data)) {
tBodyData = this.getWrapDataObject(data);
}
else {
tBodyData = this.getWrapDataObject([data]);
}
let /** @type {?} */ updateTabIndexes = this.getTabDataIndexesMatched(tBodyData, false);
for (let /** @type {?} */ updateTabIndex of updateTabIndexes) {
if (updateTabIndex > -1) {
// reload data & render by tab
this.reloadTabIndex(updateTabIndex);
}
}
}
});
}
// delete by id if exist close tab and more
let /** @type {?} */ deleteEvent = this.editor.getDataDeleteEvent();
if (deleteEvent !== null && (typeof deleteEvent !== 'undefined')) {
deleteEvent.subscribe((event) => {
let /** @type {?} */ data = null;
if (event.detail !== null && typeof event.detail !== 'undefined') {
if (event.detail.data !== null && typeof event.detail.data !== 'undefined') {
data = event.detail.data.data;
}
}
if (data !== null) {
for (let /** @type {?} */ d of data) {
let /** @type {?} */ dIndex = this.getIndexFromOriginalData(d);
if (dIndex > -1) {
// close tab
this.closeTabAtIndex(dIndex);
// remove from original
this.removeFromOriginalData(d);
if (dIndex < this.originalTabsData.length && this.originalTabsData[dIndex].length <= 0) {
// remove
this.originalTabsData.splice(dIndex, 1);
}
}
}
}
});
}
// revert
let /** @type {?} */ revertEvent = this.editor.getDataRevertEvent();
if (revertEvent !== null && (typeof revertEvent !== 'undefined')) {
revertEvent.subscribe((event) => {
let /** @type {?} */ data = null;
if (event.detail !== null && typeof event.detail !== 'undefined') {
if (event.detail.data !== null && typeof event.detail.data !== 'undefined') {
data = event.detail.data.data;
}
}
if (data !== null) {
let /** @type {?} */ tBodyData = null;
if (Array.isArray(data)) {
tBodyData = this.getWrapDataObject(data);
}
else {
tBodyData = this.getWrapDataObject([data]);
}
let /** @type {?} */ updateTabIndexes = this.getTabDataIndexesMatched(tBodyData, false);
for (let /** @type {?} */ updateTabIndex of updateTabIndexes) {
if (updateTabIndex > -1) {
// reload data & render by tab
this.reloadTabIndex(updateTabIndex);
}
}
}
});
}
let /** @type {?} */ dataReloadEvent = this.editor.getDataReloadEvent();
if (dataReloadEvent !== null && (typeof dataReloadEvent !== 'undefined')) {
dataReloadEvent.subscribe((event) => {
//! do reload sthing
});
}
let /** @type {?} */ dataQueryEvent = this.editor.getDataQueryEvent();
if (dataQueryEvent !== null && (typeof dataQueryEvent !== 'undefined')) {
dataQueryEvent.subscribe((event) => {
//! do reload sthing
});
}
}
if (this.model !== null && this.model instanceof FormViewModel) {
this.tabComponentType = this.model.tabComponentType;
this.tabComponentModel = this.model.tabComponentModel;
}
}
/**
* @return {?}
*/
ngOnDestroy() {
if (this.editor !== null && (typeof this.editor !== 'undefined')) {
this.editor.removeViewComponent(this);
}
}
/**
* @param {?} objects
* @return {?}
*/
generateTabLabel(objects) {
if (this.tabLabelGenerator !== null && typeof this.tabLabelGenerator === 'function') {
try {
let /** @type {?} */ value = this.tabLabelGenerator(this, objects);
return value;
}
catch (/** @type {?} */ error) {
}
}
if (objects !== null && typeof objects !== 'undefined') {
if (objects.length == 1) {
let /** @type {?} */ objIdField = (this.editor === null ? "" : this.editor.getObjectIdField());
return DataUtils.getDataValue(objIdField, objects[0]);
}
else {
return "MULTIPLE DATA";
}
}
return (this.tabLabel === "" || this.tabLabel === undefined || this.tabLabel === null) ? 'New tab' : this.tabLabel;
}
/**
* @param {?} data
* @return {?}
*/
removeFromOriginalData(data) {
if (data !== null && typeof data !== 'undefined') {
let /** @type {?} */ tempDatas = [];
for (let /** @type {?} */ dataContainer of this.originalTabsData) {
let /** @type {?} */ tempContainer = [];
for (let /** @type {?} */ d of dataContainer) {
if (!this.editor.getDataComparator().equals(d, data)) {
tempContainer.push(d);
}
}
tempDatas.push(tempContainer);
}
this.originalTabsData = tempDatas;
}
}
/**
* @param {?} data
* @return {?}
*/
getIndexFromOriginalData(data) {
if (data === null || typeof data === 'undefined') {
return -1;
}
let /** @type {?} */ index = 0;
for (let /** @type {?} */ dataContainer of this.originalTabsData) {
if (dataContainer !== null && typeof dataContainer !== 'undefined') {
for (let /** @type {?} */ d of dataContainer) {
if (Array.isArray(data)) {
for (let /** @type {?} */ inner of data) {
if (this.editor.getDataComparator().equals(d, inner)) {
return index;
}
}
}
else {
if (this.editor.getDataComparator().equals(d, data)) {
return index;
}
}
}
}
index += 1;
}
return -1;
}
/**
* @param {?} index
* @return {?}
*/
isTabDirty(index) {
if (index === null || typeof index === 'undefined' || index < 0) {
return false;
}
return this.tabPane.isTabDirty(index);
}
/**
* @return {?}
*/
getAllDirtyData() {
let /** @type {?} */ result = [];
for (let /** @type {?} */ i = 0; i < this.tabsData.length; i++) {
if (this.isTabDirty(i)) {
let /** @type {?} */ tabDataArray = this.getTabData(i);
for (let /** @type {?} */ d of tabDataArray) {
result.push(d);
}
}
}
return result;
}
/**
* @param {?} dataObject
* @return {?}
*/
getWrapDataObject(dataObject) {
let /** @type {?} */ data = {
editor: this.editor,
objects: dataObject
};
return data;
}
/**
* @param {?} sourceArray
* @param {?} value
* @return {?}
*/
isMatchValue(sourceArray, value) {
if (sourceArray === null || typeof sourceArray === 'undefined') {
return false;
}
for (let /** @type {?} */ a of sourceArray) {
try {
return this.editor.getDataComparator().equals(a, value);
}
catch (/** @type {?} */ err) {
}
}
return false;
}
/**
* @param {?} sourceArray
* @param {?} toMatchArray
* @return {?}
*/
isMatchLessOneValue(sourceArray, toMatchArray) {
if (sourceArray === null || typeof sourceArray === 'undefined') {
return false;
}
if (toMatchArray === null || typeof toMatchArray === 'undefined') {
return false;
}
for (let /** @type {?} */ a of toMatchArray) {
if (this.isMatchValue(sourceArray, a)) {
return true;
}
}
return false;
}
/**
* @param {?} sourceArray
* @param {?} toMatchArray
* @return {?}
*/
isMatchAllValue(sourceArray, toMatchArray) {
if (sourceArray === null || typeof sourceArray === 'undefined') {
return false;
}
if (toMatchArray === null || typeof toMatchArray === 'undefined') {
return false;
}
if (sourceArray.length !== toMatchArray.length) {
return false;
}
for (let /** @type {?} */ a of toMatchArray) {
if (!this.isMatchValue(sourceArray, a)) {
return false;
}
}
return true;
}
/**
* @param {?} index
* @return {?}
*/
removeTabDataAtIndex(index) {
if (index < this.tabsData.length) {
this.tabsData.splice(index, 1);
}
if (index < this.originalTabsData.length) {
this.originalTabsData.splice(index, 1);
}
}
/**
* @param {?} index
* @return {?}
*/
removeTabDataOther(index) {
let /** @type {?} */ leftCloseTab = index;
let /** @type {?} */ rightCloseTab = this.tabsData.length - (index + 1);
// close tab to the left
this.tabsData.splice(0, leftCloseTab);
this.originalTabsData.splice(0, leftCloseTab);
// close tab to the right
if (rightCloseTab > 0) {
this.tabsData.splice(1, rightCloseTab);
this.originalTabsData.splice(1, rightCloseTab);
}
}
/**
* @param {?} index
* @return {?}
*/
removeTabDataToTheLeft(index) {
let /** @type {?} */ leftCloseTab = index;
// close tab to the left
if (leftCloseTab > 0) {
this.tabsData.splice(0, leftCloseTab);
this.originalTabsData.splice(0, leftCloseTab);
}
}
/**
* @param {?} index
* @return {?}
*/
removeTabDataToTheRight(index) {
let /** @type {?} */ rightCloseTab = this.tabsData.length - (index + 1);
// close tab to the right
if (rightCloseTab > 0) {
this.tabsData.splice(index + 1, rightCloseTab);
this.originalTabsData.splice(index + 1, rightCloseTab);
}
}
/**
* @param {?} indexDirty
* @return {?}
*/
removeTabDataSaved(indexDirty) {
let /** @type {?} */ currentTabSize = this.tabsData.length;
if (currentTabSize > 0) {
// close tab saved
let /** @type {?} */ indexDirtyClone = JSON.parse(JSON.stringify(indexDirty));
let /** @type {?} */ countDirty = indexDirtyClone.length;
for (let /** @type {?} */ i = 0; i < this.tabsData.length; i++) {
if (indexDirtyClone.length > 0) {
if (indexDirtyClone[0] !== i) {
this.tabsData.splice(i, 1);
this.originalTabsData.splice(i, 1);
for (let /** @type {?} */ d = 0; d < indexDirtyClone.length; d++) {
indexDirtyClone[d] = indexDirtyClone[d] - 1;
}
i--;
}
else if (indexDirtyClone[0] === i) {
indexDirtyClone.splice(0, 1);
}
}
else {
this.tabsData.splice(i, this.tabsData.length - countDirty);
this.originalTabsData.splice(i, this.originalTabsData.length - countDirty);
}
}
}
}
/**
* @return {?}
*/
removeTabDataAll() {
this.tabsData = [];
this.originalTabsData = [];
}
/**
* @param {?} data
* @return {?}
*/
getTabDataIndexes(data) {
return this.getTabDataIndexesMatched(data, true);
}
/**
* @param {?} objects
* @return {?}
*/
getDefaultDataArray(objects) {
let /** @type {?} */ result = [];
if (objects !== null && typeof objects !== 'undefined') {
let /** @type {?} */ langField = null;
let /** @type {?} */ langFieldName = null;
if (this.editor !== null && typeof this.editor !== 'undefined') {
langFieldName = this.editor.getLanguageField();
}
for (let /** @type {?} */ obj of objects) {
if (obj[langFieldName] === null || typeof obj[langFieldName] === 'undefined') {
result.push(obj);
}
}
}
return result;
}
/**
* @param {?} data
* @param {?} isMatchAll
* @return {?}
*/
getTabDataIndexesMatched(data, isMatchAll) {
let /** @type {?} */ result = [];
if (data !== null && typeof data !== 'undefined') {
let /** @type {?} */ index = 0;
for (let /** @type {?} */ wrapperData of this.tabsData) {
let /** @type {?} */ defObjArray = this.getDefaultDataArray(wrapperData.objects);
if (Array.isArray(data)) {
if (isMatchAll) {
if (this.isMatchAllValue(defObjArray, data)) {
result.push(index);
}
}
else {
if (this.isMatchLessOneValue(defObjArray, data)) {
result.push(index);
}
}
}
else {
if (isMatchAll) {
if (this.isMatchAllValue(defObjArray, data.objects)) {
result.push(index);
}
}
else {
if (this.isMatchLessOneValue(defObjArray, data.objects)) {
result.push(index);
}
}
}
index += 1;
}
}
return result;
}
/**
* @return {?}
*/
reloadAllData() {
// reload from editor
let /** @type {?} */ tabSize = this.tabsData.length;
for (let /** @type {?} */ i = 0; i < tabSize; i++) {
this.reloadDataAtIndex(i);
}
}
/**
* @param {?} index
* @return {?}
*/
reloadDataAtIndex(index) {
let /** @type {?} */ dataArray = this.getTabData(index);
let /** @type {?} */ oriDataArray = this.getOriginalTabData(index);
let /** @type {?} */ editorData = [];
if (this.editor != null && this.editor.getData() != null && typeof this.editor.getData() !== 'undefined') {
editorData = this.editor.getData();
}
if (editorData.length <= 0) {
return;
}
let /** @type {?} */ comparator = this.editor.getDataComparator();
let /** @type {?} */ tempData = [];
let /** @type {?} */ cloneTempData = [];
for (let /** @type {?} */ d of oriDataArray) {
let /** @type {?} */ isAdding = false;
for (let /** @type {?} */ editorDT of editorData) {
if (comparator !== null) {
if (comparator.equals(d, editorDT)) {
tempData.push(editorDT);
let /** @type {?} */ cloneData = JSON.parse(JSON.stringify(editorDT));
cloneTempData.push(cloneData);
isAdding = true;
break;
}
}
}
if (!isAdding) {
tempData.push(d);
let /** @type {?} */ cloneData = JSON.parse(JSON.stringify(d));
cloneTempData.push(cloneData);
}
}
if (index < this.originalTabsData.length) {
this.originalTabsData[index] = tempData;
}
if (index < this.tabsData.length) {
this.tabsData[index].objects = cloneTempData;
}
}
/**
* @param {?} index
* @return {?}
*/
reloadTabIndex(index) {
if (index === null || typeof index === 'undefined' || index <= -1) {
return;
}
this.reloadDataAtIndex(index);
if (index < this.tabsData.length) {
let /** @type {?} */ tabData = this.tabsData[index];
// update data in tab
this.tabPane.setTabData(index, tabData);
this.tabPane.saveTabData(index);
}
}
/**
* @return {?}
*/
reloadAllTab() {
this.reloadAllData();
for (let /** @type {?} */ i = 0; i < this.tabsData.length; i++) {
this.tabPane.setTabData(i, this.tabsData[i]);
}
}
/**
* @param {?} index
* @return {?}
*/
getOriginalTabData(index) {
if (index == null) {
return [];
}
if (index < this.originalTabsData.length) {
return this.originalTabsData[index];
}
return [];
}
/**
* @return {?}
*/
onViewSettingLoaded() {
this.reloadAllTab();
}
/**
* @return {?}
*/
isShowMoreMenu() {
return this.showMoreMenu;
}
/**
* @param {?} $event
* @return {?}
*/
onTabMoved($event) {
let /** @type {?} */ evData = null;
if ($event.detail !== null && typeof $event.detail !== 'undefined') {
evData = $event.detail.data;
}
if (evData !== null && typeof evData !== 'undefined') {
let /** @type {?} */ fromIndex = evData.fromIndex;
let /** @type {?} */ toIndex = evData.toIndex;
ArrayUtils.move(this.tabsData, fromIndex, toIndex);
ArrayUtils.move(this.originalTabsData, fromIndex, toIndex);
}
}
/**
* @param {?} $event
* @return {?}
*/
onTabAdded($event) {
let /** @type {?} */ evData = null;
if ($event.detail !== null && typeof $event.detail !== 'undefined') {
evData = $event.detail.data;
}
if (evData !== null && typeof evData !== 'undefined') {
let /** @type {?} */ tBody = evData.tabBody;
let /** @type {?} */ tHeader = evData.tabHeader;
if (tBody !== null && typeof tBody !== 'undefined') {
let /** @type {?} */ hasData = false;
if (typeof tBody.getData === 'function') {
hasData = (tBody.getData() !== null && typeof tBody.getData() !== 'undefined') ? true : false;
}
// if no data set new data
if (!hasData && typeof tBody.setData === 'function') {
// init {}
// let newObj: any = {};
let /** @type {?} */ newObj = this.editor.newDataObject();
let /** @type {?} */ tBodyData = this.getWrapDataObject([newObj]); // new value
this.tabsData.push(tBodyData);
this.originalTabsData.push([newObj]); // add new value
tBody.setData(tBodyData);
if (tHeader !== null && typeof tHeader !== 'undefined') {
if (typeof tHeader.setData === 'function') {
tHeader.setData(tBodyData);
}
}
}
}
}
}
/**
* @return {?}
*/
createDefaultTab() {
this.tabPane.addDefaultTab();
}
/**
* @param {?} data
* @return {?}
*/
createTab(data) {
let /** @type {?} */ newObj = this.editor.newDataObject();
let /** @type {?} */ tBodyData = this.getWrapDataObject([newObj]);
if (data !== null && typeof data !== 'undefined') {
if (Array.isArray(data)) {
let /** @type {?} */ cloneArray = [];
for (let /** @type {?} */ item of data) {
let /** @type {?} */ cloneData = JSON.parse(JSON.stringify(item));
cloneArray.push(cloneData);
}
tBodyData = this.getWrapDataObject(cloneArray);
this.originalTabsData.push(data);
}
else {
let /** @type {?} */ cloneData = JSON.parse(JSON.stringify(data));
tBodyData = this.getWrapDataObject([cloneData]);
this.originalTabsData.push([data]);
}
}
else {
this.originalTabsData.push([newObj]);
}
let /** @type {?} */ tabName = this.generateTabLabel(tBodyData.objects);
let /** @type {?} */ labelField = null;
this.tabsData.push(tBodyData);
let /** @type {?} */ tModel = new TabModel(tabName, null, this.tabComponentType, this.tabComponentModel, tBodyData, labelField, null, null);
this.tabPane.addTab(tModel);
}
/**
* @param {?} data
* @return {?}
*/
closeTab(data) {
// find index from data
let /** @type {?} */ index = this.getTabDataIndex(data);
this.closeTabAtIndex(index);
}
/**
* @param {?} index
* @return {?}
*/
closeTabAtIndex(index) {
// remove dirty
let /** @type {?} */ tModels = this.tabPane.getTabModels();
if (index > -1 && index < tModels.length) {
// is dirty
let /** @type {?} */ isDirty = this.isTabDirty(index);
if (isDirty) {
// dialog
this.dialogService.showConfirmDialog('Confirm Close Tab', 'Data unsaved confirm close ?', true, "300pt", "190pt").then((result) => {
let /** @type {?} */ tempIndex = index;
if (result == 1) {
// ok close
let /** @type {?} */ tempModel = tModels[tempIndex];
this.tabPane.closeTabAtIndex(tempIndex);
this.removeTabDataAtIndex(tempIndex);
}
else if (result == -1) {
// cancel not to change view
return;
}
else {
// no option set tap to index
this.tabPane.showTabAtIndex(tempIndex);
}
});
return;
}
}
// close tab
this.tabPane.closeTabAtIndex(index);
this.removeTabDataAtIndex(index);
}
/**
* @param {?} index
* @return {?}
*/
closeTabOther(index) {
// remove dirty
let /** @type {?} */ tModels = this.tabPane.getTabModels();
if (index > -1 && index < tModels.length) {
let /** @type {?} */ indexDirty = [];
// is dirty
for (let /** @type {?} */ i = 0; i < tModels.length; i++) {
if (index !== i) {
let /** @type {?} */ isDirty = this.isTabDirty(i);
if (isDirty) {
indexDirty.push(i);
}
}
else {
indexDirty.push(i);
}
}
if (indexDirty.length > 1) {
// dialog
this.dialogService.showConfirmDialog('Confirm Close Tab Other', 'Unsaved information Confirm Close Press Yes or Close Tab Saved Press No ?', true, "425pt", "190pt").then((result) => {
if (result == 1) {
// ok close
this.tabPane.closeTabOther(index);
this.removeTabDataOther(index);
}
else if (result == -1) {
// no option set tap to index
this.tabPane.showTabAtIndex(index);
}
else {
// close tab saved
this.tabPane.closeTabSaved(indexDirty);
this.removeTabDataSaved(indexDirty);
}
});
return;
}
}
// close tab
this.tabPane.closeTabOther(index);
this.removeTabDataOther(index);
}
/**
* @param {?} index
* @return {?}
*/
closeTabToTheLeft(index) {
// remove dirty
let /** @type {?} */ tModels = this.tabPane.getTabModels();
if (index > -1 && index < tModels.length) {
let /** @type {?} */ indexDirty = [];
// is dirty
for (let /** @type {?} */ i = 0; i < tModels.length; i++) {
if (i < index) {
let /** @type {?} */ isDirty = this.isTabDirty(i);
if (isDirty) {
indexDirty.push(i);
}
}
else {
indexDirty.push(i);
}
}
if (indexDirty[0] < index) {
// dialog
this.dialogService.showConfirmDialog('Confirm Close Tab To The Left', 'Unsaved information Confirm Close Press Yes or Close Tab Saved Press No ?', true, "425pt", "190pt").then((result) => {
if (result == 1) {
// ok close
this.tabPane.closeTabToTheLeft(index);
this.removeTabDataToTheLeft(index);
}
else if (result == -1) {
// no option set tap to index
this.tabPane.showTabAtIndex(index);
}
else {
// close tab saved
this.tabPane.closeTabSaved(indexDirty);
this.removeTabDataSaved(indexDirty);
}
});
return;
}
}
// close tab to the Left
this.tabPane.closeTabToTheLeft(index);
this.removeTabDataToTheLeft(index);
}
/**
* @param {?} index
* @return {?}
*/
closeTabToTheRight(index) {
// remove dirty
let /** @type {?} */ tModels = this.tabPane.getTabModels();
if (index > -1 && index < tModels.length) {
let /** @type {?} */ indexDirty = [];
// is dirty
for (let /** @type {?} */ i = 0; i < tModels.length; i++) {
if (i > index) {
let /** @type {?} */ isDirty = this.isTabDirty(i);
if (isDirty) {
indexDirty.push(i);
}
}
else {
indexDirty.push(i);
}
}
if (indexDirty[indexDirty.length - 1] > index) {
// dialog
this.dialogService.showConfirmDialog('Confirm Close Tab To The Right', 'Unsaved information Confirm Close Press Yes or Close Tab Saved Press No ?', true, "425pt", "190pt").then((result) => {
if (result == 1) {
// ok close
this.tabPane.closeTabToTheRight(index);
this.removeTabDataToTheRight(index);
}
else if (result == -1) {
// no option set tap to index
this.tabPane.showTabAtIndex(index);
}
else {
// close tab saved
this.tabPane.closeTabSaved(indexDirty);
this.removeTabDataSaved(indexDirty);
}
});
return;
}
}
// close tab to the right
this.tabPane.closeTabToTheRight(index);
this.removeTabDataToTheRight(index);
}
/**
* @return {?}
*/
closeTabSaved() {
// remove dirty
let /** @type {?} */ tModels = this.tabPane.getTabModels();
if (tModels.length > 0) {
let /** @type {?} */ indexDirty = [];
// is dirty
for (let /** @type {?} */ i = 0; i < tModels.length; i++) {
let /** @type {?} */ isDirty = this.isTabDirty(i);
if (isDirty) {
indexDirty.push(i);
}
}
// close tab saved
this.tabPane.closeTabSaved(indexDirty);
this.removeTabDataSaved(indexDirty);
}
}
/**
* @param {?} index
* @return {?}
*/
closeTabAll(index) {
// remove dirty
let /** @type {?} */ tModels = this.tabPane.getTabModels();
if (tModels.length > 0) {
let /** @type {?} */ indexDirty = [];
// is dirty
for (let /** @type {?} */ i = 0; i < tModels.length; i++) {
let /** @type {?} */ isDirty = this.isTabDirty(i);
if (isDirty) {
indexDirty.push(i);
}
}
if (indexDirty.length > 0) {
// dialog
this.dialogService.showConfirmDialog('Confirm Close Tab All', 'Unsaved information Confirm Close Press Yes or Close Tab Saved Press No ?', true, "425pt", "190pt").then((result) => {
if (result == 1) {
// ok close
this.tabPane.closeTabAll();
this.removeTabDataAll();
}
else if (result == -1) {
// no option set tap to index
this.tabPane.showTabAtIndex(index);
}
else {
// close tab saved
this.tabPane.closeTabSaved(indexDirty);
this.removeTabDataSaved(indexDirty);
}
});
return;
}
}
// close tab to the right
this.tabPane.closeTabAll();
this.removeTabDataAll();
}
/**
* @return {?}
*/
getTabsCount() {
return this.tabPane.getTabsCount();
}
/**
* @param {?} model
* @return {?}
*/
getTabModelIndex(model) {
return this.tabPane.getTabModelIndex(model);
}
/**
* @param {?} index
* @return {?}
*/
getTabModelByIndex(index) {
if (index === null || typeof index === 'undefined' || index <= -1) {
return null;
}
let /** @type {?} */ tModels = this.tabPane.getTabModels();
if (tModels !== null && typeof tModels !== 'undefined') {
if (index < tModels.length) {
return tModels[index];
}
}
return null;
}
/**
* @param {?} data
* @return {?}
*/
getTabDataIndex(data) {
let /** @type {?} */ indexArray = this.getTabDataIndexes(data);
if (indexArray.length > 0) {
return indexArray[0];
}
return -1;
}
/**
* @param {?} index
* @return {?}
*/
getTabData(index) {
if (index == null || index <= -1) {
return [];
}
if (index < this.tabsData.length) {
return this.tabsData[index].objects;
}
return [];
}
/**
* @param {?} index
* @return {?}
*/
showTabAtIndex(index) {
if (index == null || index <= -1) {
return null;
}
this.tabPane.showTabAtIndex(index);
}
/**
* @param {?} data
* @return {?}
*/
showTabByData(data) {
// wrapperData before search
let /** @type {?} */ tBodyData = null;
if (Array.isArray(data)) {
tBodyData = this.getWrapDataObject(data);
}
else {
tBodyData = this.getWrapDataObject([data]);
}
let /** @type {?} */ indexes = this.getTabDataIndexes(tBodyData);
let /** @type {?} */ inTab = -1;
if (indexes.length > 0) {
if (indexes.length > 1) {
// close other and open new one
for (let /** @type {?} */ idx of indexes) {
this.closeTabAtIndex(idx);
}
}
else {
inTab = indexes[0];
}
}
else {
inTab = this.getTabDataIndex(data);
}
// close other and open new one
if (inTab === -1 && Array.isArray(data) && data.length > 1) {
for (let /** @type {?} */ d of data) {
let /** @type {?} */ idx = this.getTabDataIndex(d);
this.closeTabAtIndex(idx);
}
}
if (inTab > -1) {
this.showTabAtIndex(inTab);
}
else {
this.createTab(data);
let /** @type {?} */ allTabsCount = this.getTabsCount();
if (allTabsCount > 0) {
this.showTabAtIndex(allTabsCount - 1);
}
}
}
/**
* @return {?}
*/
getCurrentTabIndex() {
return this.tabPane.getCurrentTabIndex();
}
/**
* @return {?}
*/
getEditorDirtyData() {
return new Promise((resolve, reject) => {
let /** @type {?} */ dirtyArray = this.getAllDirtyData();
resolve(dirtyArray);
});
}
/**
* @return {?}
*/
getSelectedData() {
return new Promise((resolve, reject) => {
let /** @type {?} */ selectedArray = [];
let /** @type {?} */ curTab = this.getCurrentTabIndex();
let /** @type {?} */ tabDataArary = this.getTabData(curTab);
if (tabDataArary !== null) {
selectedArray = tabDataArary;
}
resolve(selectedArray);
});
}
/**
* @param {?} data
* @return {?}
*/
selfSaveData(data) {
}
/**
* @return {?}
*/
selfResetData() {
}
/**
* @return {?}
*/
doPreload() { return new Promise((resolve, reject) => { resolve(null); }); }
/**
* @return {?}
*/
doLoaded() {
}
/**
* @return {?}
*/
isSelfDataDirty() {
return false;
}
/**
* @return {?}
*/
getTabLabelGenerator() {
return this.tabLabelGenerator;
}
/**
* @param {?} generator
* @return {?}
*/
setTabLabelGenerator(generator) {
this.tabLabelGenerator = generator;
}
/**
* @return {?}
*/
getTabComponentType() {
return this.tabComponentType;
}
/**
* @param {?} type
* @return {?}
*/
setTabComponentType(type) {
this.tabComponentType = type;
}
/**
* @return {?}
*/
getTabComponentModel() {
return this.tabComponentModel;
}
/**
* @param {?} model
* @return {?}
*/
setTabComponentModel(model) {
this.tabComponentModel = model;
}
/**
* @return {?}
*/
getCurrentHistoryState() {
return this.tabsData;
}
/**
* @param {?} history
* @param {?} state
* @return {?}
*/
loadHistoryState(history, state) {
if (history === null || typeof history === 'undefined') {
return Promise.reject(new Error('The "history" cannot be "null" or "undefined".'));
}
return new Promise((resolve, reject) => {
try {
resolve();
}
catch (/** @type {?} */ e) {
reject(e);
}
});
}
/**
* @return {?}
*/
reloadView() {
this.reloadAllTab();
}
/**
* @return {?}
*/
getTabPane() {
return this.tabPane;
}
}
FormView.TYPE_NAME = TYPE_NAME;
FormView.decorators = [
{ type: Component, args: [{
moduleId: module.id,
selector: TYPE_NAME,
template: `<div class="phx-form-view" [class.hide]="!isActive()">
<phx-tab-pane #tabPane [tabComponentType]="getTabComponentType()" [tabComponentModel]="getTabComponentModel()"
[menuFactory]="getEditor().getMenuModelFactory()"
[showMoreMenu]="isShowMoreMenu()"
[ignoreParentData]="true"
(phxTabAdd)="onTabAdded($event)"
(phxTabMove)="onTabMoved($event)"></phx-tab-pane>
</div>
`
},] },
];
/** @nocollapse */
FormView.ctorParameters = () => [
{ type: DialogService, },
{ type: undefined, decorators: [{ type: Inject, args: [EditorSettingServiceFactory,] },] },
{ type: ElementRef, },
];
FormView.propDecorators = {
"model": [{ type: Input },],
"dataParent": [{ type: Input },],
"ignoreParentData": [{ type: Input },],
"data": [{ type: Input },],
"ignoreParentDisabled": [{ type: Input },],
"delegateHistory": [{ type: Input },],
"onDisabled": [{ type: Input },],
"onEnabled": [{ type: Input },],
"loadingEnabled": [{ type: Input },],
"i18nKey": [{ type: Input },],
"bypass": [{ type: Input, args: ['i18nBypass',] },],
"options": [{ type: Input },],
"tabPane": [{ type: ViewChild, args: ['tabPane',] },],
};
tslib_1.__decorate([
Option('tabLabel'),
I18N('tabLabel'),
tslib_1.__metadata("design:type", String)
], FormView.prototype, "tabLabel", void 0);
tslib_1.__decorate([
Option('tabPane'),
I18N('tabPane'),
tslib_1.__metadata("design:type", TabPane)
], FormView.prototype, "tabPane", void 0);
tslib_1.__decorate([
Option(),
tslib_1.__metadata("design:type", Function)
], FormView.prototype, "tabLabelGenerator", void 0);
function FormView_tsickle_Closure_declarations() {
/** @type {!Array<{type: !Function, args: (undefined|!Array<?>)}>} */
FormView.decorators;
/**
* @nocollapse
* @type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<{type: !Function, args: (undefined|!Array<?>)}>)})>}
*/
FormView.ctorParameters;
/** @type {!Object<string,!Array<{type: !Function, args: (undefined|!Array<?>)}>>} */
FormView.propDecorators;
/** @type {?} */
FormView.TYPE_NAME;
/** @type {?} */
FormView.prototype.model;
/** @type {?} */
FormView.prototype.dataParent;
/** @type {?} */
FormView.prototype.ignoreParentData;
/** @type {?} */
FormView.prototype.data;
/** @type {?} */
FormView.prototype.ignoreParentDisabled;
/** @type {?} */
FormView.prototype.delegateHistory;
/** @type {?} */
FormView.prototype.onDisabled;
/** @type {?} */
FormView.prototype.onEnabled;
/** @type {?} */
FormView.prototype.loadingEnabled;
/** @type {?} */
FormView.prototype.i18nKey;
/** @type {?} */
FormView.prototype.bypass;
/** @type {?} */
FormView.prototype.options;
/** @type {?} */
FormView.prototype.tabLabel;
/** @type {?} */
FormView.prototype.tabPane;
/** @type {?} */
FormView.prototype.tabLabelGenerator;
/** @type {?} */
FormView.prototype.dialogService;
/** @type {?} */
FormView.prototype.tabComponentType;
/** @type {?} */
FormView.prototype.tabComponentModel;
/** @type {?} */
FormView.prototype.tabsData;
/** @type {?} */
FormView.prototype.originalTabsData;
/** @type {?} */
FormView.prototype.showMoreMenu;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRm9ybVZpZXcuY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6Im5nOi8vY29tLnBobG94dWkvIiwic291cmNlcyI6WyJsaWIvY29tcG9uZW50L2VkaXRvci9lZGl0b3IuaW50ZXJuYWwvRm9ybVZpZXcuY29tcG9uZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsT0FBTyxFQUFFLFNBQVMsRUFBVSxVQUFVLEVBQUUsS0FBSyxFQUFRLFNBQVMsRUFBYSxNQUFNLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDekcsT0FBTyxFQUFFLHNCQUFzQixFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFDbkUsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQzFELE9BQU8sRUFBRSxPQUFPLEVBQUUsTUFBTSwrQ0FBK0MsQ0FBQztBQUN4RSxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDaEQsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLHdDQUF3QyxDQUFDO0FBQ3ZFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUM3RCxPQUFPLEVBQUUsMkJBQTJCLEVBQWdDLE1BQU0saUNBQWlDLENBQUM7QUFDNUcsT0FBTyxFQUFFLE1BQU0sRUFBRSxNQUFNLHFDQUFxQyxDQUFDO0FBQzdELE9BQU8sRUFBRSxJQUFJLEVBQUUsTUFBTSxtQ0FBbUMsQ0FBQztBQUN6RCxPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFNM0QsdUJBQU0sU0FBUyxHQUFXLGVBQWUsQ0FBQztBQWUxQyxNQUFNLGVBQWdCLFNBQVEsc0JBQXNCOzs7Ozs7SUE0Q2xELFlBQVksYUFBNEIsRUFBdUMsc0JBQW9ELFVBQXNCO1FBQ3ZKLEtBQUssQ0FBQyxvQkFBb0IsRUFBRSxVQUFVLENBQUMsQ0FBQztRQUN4QyxJQUFJLENBQUMsUUFBUSxHQUFHLEVBQUUsQ0FBQztRQUNuQixJQUFJLENBQUMsZ0JBQWdCLEdBQUcsRUFBRSxDQUFDO1FBQzNCLElBQUksQ0FBQyxhQUFhLEdBQUcsYUFBYSxDQUFDO1FBQ25DLElBQUksQ0FBQyxZQUFZLEdBQUcsSUFBSSxDQ