define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function deleteTempPage(currentPageIndex, tileDiv) {
if (this.pdfViewer.pageOrganizerSettings.canDelete &&
(this.tempOrganizePagesCollection.filter(function (item) { return item.isDeleted === false; }).length > 0)) {
var index = this.tempOrganizePagesCollection.findIndex(function (item) { return item.currentPageIndex === currentPageIndex; });
var delCurrentIndex_1 = this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].currentPageIndex;
if (index !== -1 && !this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].isInserted &&
!this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].isCopied &&
!this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].isImportedDoc) {
this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].isDeleted = true;
this.tempOrganizePagesCollection[parseInt(index.toString(), 10)].currentPageIndex = null;
}
else {
this.tempOrganizePagesCollection.splice(index, 1);
}
this.tempOrganizePagesCollection = this.tempOrganizePagesCollection.map(function (item) {
if (delCurrentIndex_1 < item.currentPageIndex && !item.isDeleted) {
item.currentPageIndex = item.currentPageIndex - 1;
}
return item;
});
while (!ej2_base_1.isNullOrUndefined(tileDiv.nextElementSibling)) {
var nextTileDiv = tileDiv.nextElementSibling;
var nextTileIndex = parseInt(nextTileDiv.getAttribute('data-page-order'), 10);
nextTileIndex = nextTileIndex - 1;
nextTileDiv.setAttribute('data-page-order', nextTileIndex.toString());
tileDiv = nextTileDiv;
}
}
}
exports.deleteTempPage = deleteTempPage;
function undoDeletedPage(deletedPageIndex, pageIndex, rotateAngle, tileDiv) {
if (this.tempOrganizePagesCollection.some(function (item) { return item.isDeleted; })) {
var deletedItem = this.tempOrganizePagesCollection.find(function (item) {
return item.currentPageIndex === null && item.isDeleted && item.pageIndex !== -1 && item.pageIndex === pageIndex &&
item.copiedPageIndex === null;
});
if (deletedItem) {
deletedItem.currentPageIndex = deletedPageIndex;
deletedItem.rotateAngle = rotateAngle;
}
}
this.tempOrganizePagesCollection = this.tempOrganizePagesCollection.map(function (item) {
if (item.currentPageIndex >= deletedPageIndex && !item.isDeleted) {
item.currentPageIndex += 1;
}
else if (item.currentPageIndex === deletedPageIndex && item.isDeleted) {
item.isDeleted = false;
}
return item;
});
this.tempOrganizePagesCollection.sort(function (a, b) {
return a.currentPageIndex - b.currentPageIndex;
});
if (tileDiv) {
tileDiv.setAttribute('data-page-order', (deletedPageIndex + 1).toString());
}
while (tileDiv && !ej2_base_1.isNullOrUndefined(tileDiv.nextElementSibling)) {
var nextTileDiv = tileDiv.nextElementSibling;
var nextTileIndex = parseInt(nextTileDiv.getAttribute('data-page-order'), 10);
nextTileIndex += 1;
nextTileDiv.setAttribute('data-page-order', nextTileIndex.toString());
tileDiv = nextTileDiv;
}
}
exports.undoDeletedPage = undoDeletedPage;
function insertRemovedPages(toolbarActions, currentPageIndex, tileDiv) {
var deleteCount = 0;
var index = this.tempOrganizePagesCollection.findIndex(function (item) {
return item.currentPageIndex === currentPageIndex;
});
if (index !== -1) {
for (var i = 0; i < index; i++) {
if (this.tempOrganizePagesCollection[parseInt(i.toString(), 10)].isDeleted) {
deleteCount++;
}
}
}
else {
for (var i = 0; i < currentPageIndex; i++) {
if (this.tempOrganizePagesCollection[parseInt(i.toString(), 10)].isDeleted) {
deleteCount++;
}
}
}
this.tempOrganizePagesCollection = this.tempOrganizePagesCollection.slice(0, currentPageIndex + deleteCount).
concat(toolbarActions, this.tempOrganizePagesCollection.slice(currentPageIndex + deleteCount));
this.tempOrganizePagesCollection = this.tempOrganizePagesCollection.map(function (item, mapIndex) {
if (mapIndex > currentPageIndex + deleteCount && !item.isDeleted) {
item.currentPageIndex += 1;
}
return item;
});
if (tileDiv) {
tileDiv.setAttribute('data-page-order', (currentPageIndex + 1).toString());
}
while (tileDiv && !ej2_base_1.isNullOrUndefined(tileDiv.nextElementSibling)) {
var nextTileDiv = tileDiv.nextElementSibling;
var nextTileIndex = parseInt(nextTileDiv.getAttribute('data-page-order'), 10);
nextTileIndex = nextTileIndex + 1;
nextTileDiv.setAttribute('data-page-order', nextTileIndex.toString());
tileDiv = nextTileDiv;
}
}
exports.insertRemovedPages = insertRemovedPages;
function clonedCollection(tempCollecion) {
var clonedCollection = JSON.parse(JSON.stringify(tempCollecion));
return clonedCollection;
}
exports.clonedCollection = clonedCollection;
});
|