diff --git a/apps/common/main/lib/view/SearchBar.js b/apps/common/main/lib/view/SearchBar.js index c9f695f4c..4e00db634 100644 --- a/apps/common/main/lib/view/SearchBar.js +++ b/apps/common/main/lib/view/SearchBar.js @@ -80,6 +80,9 @@ define([ Common.UI.Window.prototype.render.call(this); this.inputSearch = this.$window.find('#search-bar-text'); + this.inputSearch.on('input', _.bind(function () { + this.disableNavButtons(); + }, this)); this.btnBack = new Common.UI.Button({ parentEl: $('#search-bar-back'), @@ -113,6 +116,8 @@ define([ this.on('animate:before', _.bind(this.focus, this)); + Common.NotificationCenter.on('search:updateresults', _.bind(this.disableNavButtons, this)); + return this; }, @@ -127,6 +132,7 @@ define([ this.inputSearch.val(''); } + this.disableNavButtons(); this.focus(); }, @@ -167,6 +173,12 @@ define([ this.fireEvent('search:show', [true, this.inputSearch.val()]); }, + disableNavButtons: function (resultNumber, allResults) { + var disable = this.inputSearch.val() === ''; + this.btnBack.setDisabled(disable || !allResults || resultNumber === 0); + this.btnNext.setDisabled(disable); + }, + textFind: 'Find' }, Common.UI.SearchBar || {})); diff --git a/apps/common/main/lib/view/SearchPanel.js b/apps/common/main/lib/view/SearchPanel.js index 9715b8cf1..239b9662b 100644 --- a/apps/common/main/lib/view/SearchPanel.js +++ b/apps/common/main/lib/view/SearchPanel.js @@ -72,6 +72,7 @@ define([ validateOnBlur: false, style: 'width: 100%;' }); + this.inputText._input.on('input', _.bind(this.disableNavButtons, this)); this.inputReplace = new Common.UI.InputField({ el: $('#search-adv-replace-text'), @@ -161,6 +162,7 @@ define([ me.$resultsContainer.scroller.update({alwaysVisibleY: true}); }); + Common.NotificationCenter.on('search:updateresults', _.bind(this.disableNavButtons, this)); if (window.SSE) { this.cmbWithin = new Common.UI.ComboBox({ el: $('#search-adv-cmb-within'), @@ -223,6 +225,7 @@ define([ this.$resultsContainer.outerHeight($('#search-box').outerHeight() - $('#search-header').outerHeight() - $('#search-adv-settings').outerHeight()); this.$resultsContainer.scroller.update({alwaysVisibleY: true}); + this.disableNavButtons(); this.fireEvent('show', this ); }, @@ -302,6 +305,12 @@ define([ this.updateResultsNumber('no-results'); }, + disableNavButtons: function (resultNumber, allResults) { + var disable = this.inputText._input.val() === ''; + this.btnBack.setDisabled(disable || !allResults || resultNumber === 0); + this.btnNext.setDisabled(disable); + }, + textFind: 'Find', textFindAndReplace: 'Find and replace', textCloseSearch: 'Close search', diff --git a/apps/documenteditor/main/app/controller/LeftMenu.js b/apps/documenteditor/main/app/controller/LeftMenu.js index 5f30ed3e7..3a6bb4e66 100644 --- a/apps/documenteditor/main/app/controller/LeftMenu.js +++ b/apps/documenteditor/main/app/controller/LeftMenu.js @@ -968,6 +968,7 @@ define([ } else if (text !== undefined) { this.leftMenu.panelSearch.setFindText(''); } + this.leftMenu.panelSearch.disableNavButtons(); this.leftMenu.panelSearch.focus(); }, diff --git a/apps/documenteditor/main/app/controller/Search.js b/apps/documenteditor/main/app/controller/Search.js index c45152321..ee0b601af 100644 --- a/apps/documenteditor/main/app/controller/Search.js +++ b/apps/documenteditor/main/app/controller/Search.js @@ -152,6 +152,7 @@ define([ if (this.view) { this.view.updateResultsNumber(current, all); } + Common.NotificationCenter.trigger('search:updateresults', current, all); }, onStartTextAroundSearch: function () { diff --git a/apps/documenteditor/main/app/view/LeftMenu.js b/apps/documenteditor/main/app/view/LeftMenu.js index f2e08d19f..2206c2590 100644 --- a/apps/documenteditor/main/app/view/LeftMenu.js +++ b/apps/documenteditor/main/app/view/LeftMenu.js @@ -271,7 +271,6 @@ define([ if (this.panelSearch) { if (this.btnSearchBar.pressed) { this.panelSearch.show(); - this.fireEvent('search:aftershow', this); } else { this.panelSearch.hide(); } @@ -418,6 +417,7 @@ define([ this.btnSearchBar.toggle(true); this.onBtnMenuClick(this.btnSearchBar); this.onCoauthOptions(); + this.fireEvent('search:aftershow', this); } } /** coauthoring end **/ diff --git a/apps/presentationeditor/main/app/controller/LeftMenu.js b/apps/presentationeditor/main/app/controller/LeftMenu.js index a2538ec14..bb96924ee 100644 --- a/apps/presentationeditor/main/app/controller/LeftMenu.js +++ b/apps/presentationeditor/main/app/controller/LeftMenu.js @@ -823,6 +823,7 @@ define([ } else if (text !== undefined) { this.leftMenu.panelSearch.setFindText(''); } + this.leftMenu.panelSearch.disableNavButtons(); this.leftMenu.panelSearch.focus(); }, diff --git a/apps/presentationeditor/main/app/controller/Search.js b/apps/presentationeditor/main/app/controller/Search.js index b170b4901..67c9d9734 100644 --- a/apps/presentationeditor/main/app/controller/Search.js +++ b/apps/presentationeditor/main/app/controller/Search.js @@ -139,6 +139,7 @@ define([ if (this.view) { this.view.updateResultsNumber(current, all); } + Common.NotificationCenter.trigger('search:updateresults', current, all); }, textNoTextFound: 'The data you have been searching for could not be found. Please adjust your search options.', diff --git a/apps/presentationeditor/main/app/view/LeftMenu.js b/apps/presentationeditor/main/app/view/LeftMenu.js index f3b8f98aa..912d430a4 100644 --- a/apps/presentationeditor/main/app/view/LeftMenu.js +++ b/apps/presentationeditor/main/app/view/LeftMenu.js @@ -255,7 +255,6 @@ define([ if (this.panelSearch) { if (this.btnSearchBar.pressed) { this.panelSearch.show(); - this.fireEvent('search:aftershow', this); } else { this.panelSearch.hide(); } @@ -375,6 +374,7 @@ define([ this.btnSearchBar.toggle(true); this.onBtnMenuClick(this.btnSearchBar); this.onCoauthOptions(); + this.fireEvent('search:aftershow', this); } } /** coauthoring end **/