Skip to content

Commit

Permalink
Implemented issue #2395 - Search term is deleted after I opened a obj…
Browse files Browse the repository at this point in the history
…ect/ticket.
  • Loading branch information
martini authored and znuny-robo committed Dec 7, 2018
1 parent ecad97f commit 23059d7
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions app/assets/javascripts/app/controllers/navigation.coffee
Expand Up @@ -16,9 +16,8 @@ class App.Navigation extends App.ControllerWidgetPermanent
'submit form.search-holder': 'preventDefault' 'submit form.search-holder': 'preventDefault'
'dblclick form.search-holder .icon-magnifier': 'openExtendedSearch' 'dblclick form.search-holder .icon-magnifier': 'openExtendedSearch'
'focus #global-search': 'searchFocus' 'focus #global-search': 'searchFocus'
'blur #global-search': 'searchBlur'
'keyup #global-search': 'listNavigate' 'keyup #global-search': 'listNavigate'
'click .js-global-search-result': 'emptyAndClose' 'click .js-global-search-result': 'emptyAndCloseDelayed'
'click .js-details-link': 'openExtendedSearch' 'click .js-details-link': 'openExtendedSearch'
'change .js-menu .js-switch input': 'switch' 'change .js-menu .js-switch input': 'switch'


Expand Down Expand Up @@ -162,7 +161,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
renderResult: (result = [], noChange) => renderResult: (result = [], noChange) =>
if noChange if noChange
return return

@removePopovers() @removePopovers()


# remove result if not result exists # remove result if not result exists
Expand Down Expand Up @@ -202,19 +201,11 @@ class App.Navigation extends App.ControllerWidgetPermanent
$('#app').append @notificationWidget.el $('#app').append @notificationWidget.el


searchFocus: (e) => searchFocus: (e) =>
@query = '' # reset query cache @clearDelay('emptyAndCloseDelayed')
@throttledSearch()
App.PopoverProvidable.anyPopoversDestroy() App.PopoverProvidable.anyPopoversDestroy()
@searchContainer.addClass('focused') @searchContainer.addClass('focused')

@selectAll(e)
searchBlur: (e) =>
# delay to be able to click x
update = =>
query = @searchInput.val().trim()
if !query
@emptyAndClose()
return

@delay(update, 100, 'removeFocused')


listNavigate: (e) => listNavigate: (e) =>
if e.keyCode is 27 # close on esc if e.keyCode is 27 # close on esc
Expand All @@ -231,9 +222,9 @@ class App.Navigation extends App.ControllerWidgetPermanent
href = @$('.global-search-result .nav-tab.is-hover').attr('href') href = @$('.global-search-result .nav-tab.is-hover').attr('href')
if href if href
@navigate(href) @navigate(href)
@emptyAndCloseDelayed()
else else
@openExtendedSearch() @openExtendedSearch()
@emptyAndClose()
return return


# on other keys, show result # on other keys, show result
Expand Down Expand Up @@ -277,18 +268,24 @@ class App.Navigation extends App.ControllerWidgetPermanent
@scrollToIfNeeded(prev, false) @scrollToIfNeeded(prev, false)


emptyAndClose: => emptyAndClose: =>
@andClose()
@andEmpty()

emptyAndCloseDelayed: =>
@andClose()
delay = =>
@andEmpty()
@delay(delay, 60000, 'emptyAndCloseDelayed')

andEmpty: =>
@query = '' @query = ''
@searchInput.val('') @searchInput.val('')
@searchContainer.removeClass('focused filled open no-match loading')
@globalSearch.close()
@delayedRemoveAnyPopover()


andClose: => andClose: =>
@query = '' @searchContainer.removeClass('focused filled open no-match loading')
@searchInput.blur()
@searchContainer.removeClass('open no-match loading')
@globalSearch.close() @globalSearch.close()
@delayedRemoveAnyPopover() @delayedRemoveAnyPopover()
@searchInput.blur()


search: => search: =>
query = @searchInput.val().trim() query = @searchInput.val().trim()
Expand All @@ -301,9 +298,10 @@ class App.Navigation extends App.ControllerWidgetPermanent
@query = query @query = query


if @query == '' if @query == ''
@searchContainer.removeClass('open') @searchContainer.removeClass('open loading')
return return


@searchContainer.addClass('open')
@globalSearch.search(query: @query) @globalSearch.search(query: @query)


filterNavbar: (values, user, parent = null) -> filterNavbar: (values, user, parent = null) ->
Expand Down Expand Up @@ -460,7 +458,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
if e if e
e.preventDefault() e.preventDefault()
query = @searchInput.val() query = @searchInput.val()
@searchInput.val('').blur() @emptyAndClose()
if query if query
@navigate("#search/#{encodeURIComponent(query)}") @navigate("#search/#{encodeURIComponent(query)}")
return return
Expand Down

0 comments on commit 23059d7

Please sign in to comment.