From c23422465e60b6cf0fe705b3e2eff102ccd96781 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 29 Mar 2018 16:02:54 +0300 Subject: [PATCH] [DE] Hyperlink refactoring --- .../main/app/view/HyperlinkSettingsDialog.js | 152 ++++++++++-------- 1 file changed, 84 insertions(+), 68 deletions(-) diff --git a/apps/documenteditor/main/app/view/HyperlinkSettingsDialog.js b/apps/documenteditor/main/app/view/HyperlinkSettingsDialog.js index 6f3fc2cf7..ef7595db9 100644 --- a/apps/documenteditor/main/app/view/HyperlinkSettingsDialog.js +++ b/apps/documenteditor/main/app/view/HyperlinkSettingsDialog.js @@ -157,7 +157,12 @@ define([ me.internalList = new Common.UI.TreeView({ el: $('#id-dlg-hyperlink-list'), store: new Common.UI.TreeViewStore(), - enableKeyEvents: false + enableKeyEvents: true + }); + me.internalList.on('item:select', _.bind(this.onSelectItem, this)); + + me.btnOk = new Common.UI.Button({ + el: $window.find('.primary') }); $window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); @@ -170,79 +175,86 @@ define([ this.externalPanel.toggleClass('hidden', value !== c_oHyperlinkType.WebLink); this.internalPanel.toggleClass('hidden', value !== c_oHyperlinkType.InternalLink); var store = this.internalList.store; - if (value==c_oHyperlinkType.InternalLink && store.length<1) { - var anchors = this.api.asc_GetHyperlinkAnchors(), - count = anchors.length, - prev_level = 0, - header_level = 0, - arr = []; - arr.push(new Common.UI.TreeViewModel({ - name : this.txtBeginning, - level: 0, - index: 0, - hasParent: false, - isEmptyItem: false, - isNotHeader: true, - hasSubItems: false - })); - arr.push(new Common.UI.TreeViewModel({ - name : this.txtHeadings, - level: 0, - index: 1, - hasParent: false, - isEmptyItem: false, - isNotHeader: false, - hasSubItems: false - })); + if (value==c_oHyperlinkType.InternalLink) { + if (store.length<1) { + var anchors = this.api.asc_GetHyperlinkAnchors(), + count = anchors.length, + prev_level = 0, + header_level = 0, + arr = []; + arr.push(new Common.UI.TreeViewModel({ + name : this.txtBeginning, + level: 0, + index: 0, + hasParent: false, + isEmptyItem: false, + isNotHeader: true, + hasSubItems: false + })); + arr.push(new Common.UI.TreeViewModel({ + name : this.txtHeadings, + level: 0, + index: 1, + hasParent: false, + isEmptyItem: false, + isNotHeader: false, + hasSubItems: false + })); - for (var i=0; iprev_level) - arr[arr.length-1].set('hasSubItems', true); - if (level<=header_level) { - header_level = level; - hasParent = false; + for (var i=0; iprev_level) + arr[arr.length-1].set('hasSubItems', true); + if (level<=header_level) { + header_level = level; + hasParent = false; + } + arr.push(new Common.UI.TreeViewModel({ + name : anchor.asc_GetHeadingText(), + level: level, + index: i+2, + hasParent: hasParent + })); + prev_level = level; } - arr.push(new Common.UI.TreeViewModel({ - name : anchor.asc_GetHeadingText(), - level: level, - index: i+2, - hasParent: hasParent - })); - prev_level = level; } - } - arr.push(new Common.UI.TreeViewModel({ - name : this.txtBookmarks, - level: 0, - index: arr.length, - hasParent: false, - isEmptyItem: false, - isNotHeader: false, - hasSubItems: false - })); + arr.push(new Common.UI.TreeViewModel({ + name : this.txtBookmarks, + level: 0, + index: arr.length, + hasParent: false, + isEmptyItem: false, + isNotHeader: false, + hasSubItems: false + })); - prev_level = 0; - for (var i=0; i0); + + } else + this.btnOk.setDisabled(false); + this.linkType = value; }, @@ -250,6 +262,10 @@ define([ this.ShowHideElem(type); }, + onSelectItem: function(picker, item, record, e){ + this.btnOk.setDisabled(record.get('level')==0 && record.get('index')>0); + }, + show: function() { Common.UI.Window.prototype.show.apply(this, arguments);