Small refactoring. Made empty search field working.

This commit is contained in:
Martin Edenhofer 2014-09-24 23:49:18 +02:00
parent 6e8791340d
commit 92570b2d6f

View file

@ -1,9 +1,6 @@
class App.Navigation extends App.Controller class App.Navigation extends App.Controller
className: 'navigation vertical' className: 'navigation vertical'
events:
'click .empty-search': 'emptySearch'
constructor: -> constructor: ->
super super
@render() @render()
@ -34,32 +31,32 @@ class App.Navigation extends App.Controller
# bell on / bell off # bell on / bell off
@bind 'bell', (data) => @bind 'bell', (data) =>
if data is 'on' if data is 'on'
@el.find('.bell').addClass('show') @$('.bell').addClass('show')
App.Audio.play( 'https://www.sounddogs.com/previews/2193/mp3/219024_SOUNDDOGS__be.mp3' ) App.Audio.play( 'https://www.sounddogs.com/previews/2193/mp3/219024_SOUNDDOGS__be.mp3' )
@delay( @delay(
-> App.Event.trigger('bell', 'off' ) -> App.Event.trigger('bell', 'off' )
3000 3000
) )
else else
@el.find('.bell').removeClass('show') @$('.bell').removeClass('show')
renderMenu: => renderMenu: =>
items = @getItems( navbar: @Config.get( 'NavBar' ) ) items = @getItems( navbar: @Config.get( 'NavBar' ) )
# get open tabs to repopen on rerender # get open tabs to repopen on rerender
open_tab = {} open_tab = {}
@el.find('.open').children('a').each( (i,d) => @$('.open').children('a').each( (i,d) =>
href = $(d).attr('href') href = $(d).attr('href')
open_tab[href] = true open_tab[href] = true
) )
# get active tabs to reactivate on rerender # get active tabs to reactivate on rerender
active_tab = {} active_tab = {}
@el.find('.active').children('a').each( (i,d) => @$('.active').children('a').each( (i,d) =>
href = $(d).attr('href') href = $(d).attr('href')
active_tab[href] = true active_tab[href] = true
) )
@el.find('.main-navigation').html App.view('navigation/menu')( @$('.main-navigation').html App.view('navigation/menu')(
items: items items: items
open_tab: open_tab open_tab: open_tab
active_tab: active_tab active_tab: active_tab
@ -71,26 +68,26 @@ class App.Navigation extends App.Controller
# get open tabs to repopen on rerender # get open tabs to repopen on rerender
open_tab = {} open_tab = {}
@el.find('.open').children('a').each( (i,d) => @$('.open').children('a').each( (i,d) =>
href = $(d).attr('href') href = $(d).attr('href')
open_tab[href] = true open_tab[href] = true
) )
# get active tabs to reactivate on rerender # get active tabs to reactivate on rerender
active_tab = {} active_tab = {}
@el.find('.active').children('a').each( (i,d) => @$('.active').children('a').each( (i,d) =>
href = $(d).attr('href') href = $(d).attr('href')
active_tab[href] = true active_tab[href] = true
) )
@el.find('.navbar-items-personal').html App.view('navigation/personal')( @$('.navbar-items-personal').html App.view('navigation/personal')(
items: items items: items
open_tab: open_tab open_tab: open_tab
active_tab: active_tab active_tab: active_tab
) )
renderResult: (result = []) => renderResult: (result = []) =>
el = @el.find('#global-search-result') el = @$('#global-search-result')
# destroy existing popovers # destroy existing popovers
@ticketPopupsDestroy() @ticketPopupsDestroy()
@ -99,7 +96,7 @@ class App.Navigation extends App.Controller
# remove result if not result exists # remove result if not result exists
if _.isEmpty( result ) if _.isEmpty( result )
@el.find('.search').removeClass('open') @$('.search').removeClass('open')
el.html( '' ) el.html( '' )
return return
@ -110,7 +107,7 @@ class App.Navigation extends App.Controller
el.html( html ) el.html( html )
# show result list # show result list
@el.find('.search').addClass('open') @$('.search').addClass('open')
# start ticket popups # start ticket popups
@ticketPopups() @ticketPopups()
@ -123,13 +120,9 @@ class App.Navigation extends App.Controller
render: () -> render: () ->
# remember old search query user = App.Session.get()
search = @el.find('#global-search').val()
user = App.Session.get()
@html App.view('navigation')( @html App.view('navigation')(
user: user user: user
search: search
) )
# renderMenu # renderMenu
@ -138,14 +131,6 @@ class App.Navigation extends App.Controller
# renderPersonal # renderPersonal
@renderPersonal() @renderPersonal()
# set focus to search box
if @searchFocus
@searchFocusSet = true
App.ClipBoard.setPosition( 'global-search', search.length )
else
@searchFocusSet = false
searchFunction = => searchFunction = =>
App.Ajax.request( App.Ajax.request(
id: 'search' id: 'search'
@ -202,57 +187,56 @@ class App.Navigation extends App.Controller
) )
# observer search box # observer search box
@el.find('#global-search').bind( 'focusin', (e) => @$('#global-search').bind( 'focusin', (e) =>
# remember to set search box @$('.search').addClass('focused')
@searchFocus = true
@el.find('.search').addClass('focused')
# check if search is needed # check if search is needed
@term = @el.find('#global-search').val() term = @$('#global-search').val().trim()
return if @searchFocusSet return if !term
return if !@term @term = term
@delay( searchFunction, 200, 'search' ) @delay( searchFunction, 220, 'search' )
) )
# remove search result # remove search result
@el.find('#global-search').bind( 'focusout', (e) => @$('#global-search').bind( 'focusout', (e) =>
@el.find('.search').removeClass('focused') @$('.search').removeClass('focused')
@delay( @delay(
=> =>
@searchFocus = false
@renderResult() @renderResult()
320 320
) )
) )
# prevent submit of search box # prevent submit of search box
@el.find('form.search').bind( 'submit', (e) => @$('form.search').bind( 'submit', (e) =>
e.preventDefault() e.preventDefault()
) )
# start search # start search
@el.find('#global-search').bind( 'keyup', (e) => @$('#global-search').bind( 'keyup', (e) =>
@term = @el.find('#global-search').val() term = @$('#global-search').val().trim()
return if !term
@el.find('.search').toggleClass('filled', !!@term) return if term is @term
@term = term
return if !@term @$('.search').toggleClass('filled', !!@term)
return if @term is search
@delay( searchFunction, 220, 'search' ) @delay( searchFunction, 220, 'search' )
) )
# bind to empty search
@$('.empty-search').on(
'click'
=>
@$('#global-search').val('')
@$('.search').removeClass('filled')
)
new App.OnlineNotificationWidget( new App.OnlineNotificationWidget(
el: @el el: @el
) )
@taskbar = new App.TaskbarWidget( el: @el.find('.tasks') ) @taskbar = new App.TaskbarWidget( el: @$('.tasks') )
emptySearch: (event) =>
@el.find('#global-search').val("")
@el.find('.search').removeClass('filled')
getItems: (data) -> getItems: (data) ->
navbar = _.values(data.navbar) navbar = _.values(data.navbar)
@ -353,8 +337,8 @@ class App.Navigation extends App.Controller
@addPrioCount newlist, item @addPrioCount newlist, item
update: (url) => update: (url) =>
@el.find('li').removeClass('active') @$('li').removeClass('active')
@el.find("[href=\"#{url}\"]").parents('li').addClass('active') @$("[href=\"#{url}\"]").parents('li').addClass('active')
recentViewNavbarItemsRebuild: => recentViewNavbarItemsRebuild: =>