From 58d4bb70db18d19f9e86628b958404c0160ff1e8 Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Wed, 13 Oct 2021 22:08:47 +0300 Subject: [PATCH] [DE] Add navigation in viewer for pdf --- .../main/app/controller/Main.js | 2 +- .../main/app/controller/Navigation.js | 67 ++++++++++++++++--- .../main/app/controller/PageThumbnails.js | 6 -- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index a508cb55f..743610f5d 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1434,7 +1434,7 @@ define([ var type = /^(?:(pdf|djvu|xps))$/.exec(this.document.fileType); this.appOptions.canDownloadOrigin = this.permissions.download !== false && (type && typeof type[1] === 'string'); this.appOptions.canDownload = this.permissions.download !== false && (!type || typeof type[1] !== 'string'); - this.appOptions.canUseThumbnails = /^pdf$/.test(this.document.fileType); + this.appOptions.canUseThumbnails = this.appOptions.canUseViwerNavigation = /^(?:(pdf|djvu|xps))$/.test(this.document.fileType); this.appOptions.fileKey = this.document.key; diff --git a/apps/documenteditor/main/app/controller/Navigation.js b/apps/documenteditor/main/app/controller/Navigation.js index 3ebd05091..d80f24d10 100644 --- a/apps/documenteditor/main/app/controller/Navigation.js +++ b/apps/documenteditor/main/app/controller/Navigation.js @@ -56,13 +56,17 @@ define([ this.addListeners({ 'Navigation': { 'show': function() { - var obj = me.api.asc_ShowDocumentOutline(); - if (!me._navigationObject) - me._navigationObject = obj; - me.updateNavigation(); + if (!this.canUseViwerNavigation) { + var obj = me.api.asc_ShowDocumentOutline(); + if (!me._navigationObject) + me._navigationObject = obj; + me.updateNavigation(); + } }, 'hide': function() { - me.api && me.api.asc_HideDocumentOutline(); + if (!this.canUseViwerNavigation) { + me.api && me.api.asc_HideDocumentOutline(); + } } } }); @@ -77,6 +81,7 @@ define([ }); this.panelNavigation.on('render:after', _.bind(this.onAfterRender, this)); this._navigationObject = null; + this._viewerNavigationObject = null; this._isDisabled = false; }, @@ -87,11 +92,14 @@ define([ this.api.asc_registerCallback('asc_onDocumentOutlineUpdateAdd', _.bind(this.updateNavigation, this)); this.api.asc_registerCallback('asc_onDocumentOutlineUpdateChange', _.bind(this.updateChangeNavigation, this)); this.api.asc_registerCallback('asc_onDocumentOutlineUpdateRemove', _.bind(this.updateNavigation, this)); + + this.api.asc_registerCallback('asc_onViewerBookmarksUpdate', _.bind(this.updateViewerNavigation, this)); return this; }, setMode: function(mode) { this.mode = mode; + this.canUseViwerNavigation = this.mode.canUseViwerNavigation; return this; }, @@ -171,6 +179,9 @@ define([ menu.items[i].setVisible(this.mode.isEdit); } + menu.items[7].setVisible(!this.canUseViwerNavigation); + menu.items[8].setVisible(!this.canUseViwerNavigation); + var isNotHeader = record.get('isNotHeader'); menu.items[0].setDisabled(isNotHeader || this._isDisabled); menu.items[1].setDisabled(isNotHeader || this._isDisabled); @@ -203,13 +214,16 @@ define([ }, onSelectItem: function(picker, item, record, e){ - if (!this._navigationObject) return; - this._navigationObject.goto(record.get('index')); + if (this._navigationObject) { + this._navigationObject.goto(record.get('index')); + } else if (this._viewerNavigationObject) { + this.api.asc_viewerNavigateTo(record.get('index')); + } Common.NotificationCenter.trigger('edit:complete', this.panelNavigation); }, onMenuItemClick: function (menu, item) { - if (!this._navigationObject) return; + if (!this._navigationObject && !this._viewerNavigationObject) return; var index = parseInt(menu.cmpEl.attr('data-value')); if (item.value == 'promote') { @@ -239,6 +253,43 @@ define([ this._isDisabled = state; }, + updateViewerNavigation: function (bookmarks) { + this._viewerNavigationObject = bookmarks.length > 0 ? bookmarks : null; + if (this._viewerNavigationObject) { + var count = this._viewerNavigationObject.length, + prev_level = -1, + header_level = -1, + first_header = true,//!this._navigationObject.isFirstItemNotHeader(), + arr = []; + for (var i = 0; i < count; i++) { + var level = this._viewerNavigationObject[i].level - 1, + hasParent = true; + if (level > prev_level && i > 0) + arr[i - 1].set('hasSubItems', true); + if (header_level < 0 || level <= header_level) { + if (i > 0 || first_header) + header_level = level; + hasParent = false; + } + arr.push(new Common.UI.TreeViewModel({ + name: this._viewerNavigationObject[i].description, + level: level, + index: i, + hasParent: hasParent, + isEmptyItem: !this._viewerNavigationObject[i].description + })); + prev_level = level; + } + if (count > 0 && !first_header) { + arr[0].set('hasSubItems', false); + arr[0].set('isNotHeader', true); + arr[0].set('name', this.txtBeginning); + arr[0].set('tip', this.txtGotoBeginning); + } + this.getApplication().getCollection('Navigation').reset(arr); + } + }, + txtBeginning: 'Beginning of document', txtGotoBeginning: 'Go to the beginning of the document' diff --git a/apps/documenteditor/main/app/controller/PageThumbnails.js b/apps/documenteditor/main/app/controller/PageThumbnails.js index 0bcec238e..f5fb7e765 100644 --- a/apps/documenteditor/main/app/controller/PageThumbnails.js +++ b/apps/documenteditor/main/app/controller/PageThumbnails.js @@ -74,7 +74,6 @@ define([ setApi: function(api) { this.api = api; this.api.asc_registerCallback('asc_onViewerThumbnailsZoomUpdate', _.bind(this.updateSize, this)); - this.api.asc_registerCallback('asc_onViewerBookmarksUpdate', _.bind(this.updateBookmarks, this)); return this; }, @@ -114,10 +113,5 @@ define([ } }, - updateBookmarks: function (t) { - var r = t; - console.log(t); - } - }, DE.Controllers.PageThumbnails || {})); }); \ No newline at end of file