all files / pdfviewer/organize-pdf/organize-core/ organize-saveaction.js

12.9% Statements 8/62
0% Branches 0/20
12.5% Functions 1/8
12.9% Lines 8/62
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85                                                                                                                                                          
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function onSaveClicked() {
        var _this = this;
        this.isSkipRevert = true;
        this.showOrganizeLoadingIndicator(true);
        if ((JSON.stringify(this.tempOrganizePagesCollection) !== JSON.stringify(this.organizePagesCollection)) ||
            this.isDocumentModified) {
            this.updateOrganizePageCollection();
            this.totalCheckedCount = 0;
            this.isDocumentModified = true;
            var pdfBlob_1;
            this.pdfViewer.saveAsBlob().then(function (blob) {
                pdfBlob_1 = blob;
                _this.pdfViewerBase.blobToBase64(pdfBlob_1).then(function (base64) {
                    if (!ej2_base_1.isNullOrUndefined(base64) && base64 !== '') {
                        var fileName = _this.pdfViewer.fileName;
                        var downloadFileName = _this.pdfViewer.downloadFileName;
                        var jsonDocumentId = _this.pdfViewerBase.jsonDocumentId;
                        _this.showOrganizeLoadingIndicator(false);
                        _this.organizeDialog.hide();
                        _this.undoOrganizeCollection = [];
                        _this.redoOrganizeCollection = [];
                        _this.pdfViewer.loadDocInternally(base64, null, false);
                        _this.pdfViewerBase.updateDocumentEditedProperty(true);
                        _this.pdfViewer.fileName = fileName;
                        if (!ej2_base_1.isNullOrUndefined(downloadFileName)) {
                            _this.pdfViewer.downloadFileName = downloadFileName;
                        }
                        else {
                            _this.pdfViewer.downloadFileName = fileName;
                        }
                        _this.pdfViewerBase.jsonDocumentId = jsonDocumentId;
                        _this.isOrganizeWindowOpen = false;
                        _this.pdfViewer.isPageOrganizerOpen = false;
                    }
                });
            });
        }
        else {
            this.showOrganizeLoadingIndicator(false);
            this.organizeDialog.hide();
            this.undoOrganizeCollection = [];
            this.redoOrganizeCollection = [];
            this.isOrganizeWindowOpen = false;
            this.pdfViewer.isPageOrganizerOpen = false;
        }
    }
    exports.onSaveClicked = onSaveClicked;
    function onSaveasClicked() {
        var _this = this;
        if (JSON.stringify(this.tempOrganizePagesCollection) !== JSON.stringify(this.organizePagesCollection)) {
            this.updateOrganizePageActions();
        }
        var fileName = this.pdfViewer.fileName;
        var pdfBlob;
        var canDownload = false;
        var temp = JSON.parse(JSON.stringify(this.organizePagesCollection));
        this.pdfViewer.saveAsBlob().then(function (blob) {
            pdfBlob = blob;
            var conversionPromise = _this.pdfViewerBase.clientSideRendering
                ? _this.pdfViewerBase.blobToByteArray(pdfBlob)
                : _this.pdfViewerBase.blobToBase64(pdfBlob);
            conversionPromise.then(function (result) {
                if (!ej2_base_1.isNullOrUndefined(result) && result !== '') {
                    canDownload = _this.pdfViewer.firePageOrganizerSaveAsEventArgs(fileName, result);
                    if (canDownload) {
                        _this.pdfViewerBase.fileDownload(result, _this.pdfViewerBase, true);
                        _this.organizePagesCollection = JSON.parse(JSON.stringify(temp));
                    }
                }
            });
        });
    }
    exports.onSaveasClicked = onSaveasClicked;
    function updateOrganizePageActions() {
        this.updateOrganizePageCollection();
        this.totalCheckedCount = 0;
        this.isDocumentModified = true;
        this.pdfViewerBase.updateDocumentEditedProperty(true);
    }
    exports.updateOrganizePageActions = updateOrganizePageActions;
});