diff --git a/app/assets/javascripts/app/controllers/tag.coffee b/app/assets/javascripts/app/controllers/tag.coffee index 3dc9545af..7e7696841 100644 --- a/app/assets/javascripts/app/controllers/tag.coffee +++ b/app/assets/javascripts/app/controllers/tag.coffee @@ -54,6 +54,7 @@ class Table extends App.Controller events: 'click .js-delete': 'destroy' 'click .js-edit': 'edit' + 'click .js-search': 'search' constructor: -> super @@ -95,6 +96,12 @@ class Table extends App.Controller row: row ) + search: (e) -> + e.preventDefault() + e.stopPropagation() + item = $(e.target).closest('tr').find('.js-name').text() + App.GlobalSearchWidget.search(item, 'tag') + class Edit extends App.ControllerModal buttonClose: true buttonCancel: true diff --git a/app/assets/javascripts/app/controllers/widget/global_search.coffee b/app/assets/javascripts/app/controllers/widget/global_search.coffee new file mode 100644 index 000000000..b551b7d0b --- /dev/null +++ b/app/assets/javascripts/app/controllers/widget/global_search.coffee @@ -0,0 +1,38 @@ +class App.GlobalSearchWidget extends Spine.Module + shiftHeld = false + + constructor: -> + $('body').on('mousedown', (e) => + @shiftHeldToogle(e) + ) + App.Event.bind('global:search:set', (data) => + item = data[0] + attribute = data[1] + item = item.replace('"', '') + if item.match(/\W/) + item = "\"#{item}\"" + if !attribute + searchAttribute = "#{item}" + else + searchAttribute = "#{attribute}:#{item}" + currentValue = $('#global-search').val() + + if @shiftHeld && currentValue + currentValue += ' AND ' + currentValue += searchAttribute + else + currentValue = searchAttribute + + $('#global-search').val(currentValue) + delay = -> + $('#global-search').focus() + App.Delay.set(delay, 20, 'global-search-delay') + ) + + shiftHeldToogle: (e) -> + @shiftHeld = e.shiftKey + + @search: (item, attribute) -> + App.Event.trigger('global:search:set', [item, attribute]) + +App.Config.set('global_navigation', App.GlobalSearchWidget, 'Widgets') diff --git a/app/assets/javascripts/app/controllers/widget/tag.coffee b/app/assets/javascripts/app/controllers/widget/tag.coffee index bbe4f535b..ceecabb57 100644 --- a/app/assets/javascripts/app/controllers/widget/tag.coffee +++ b/app/assets/javascripts/app/controllers/widget/tag.coffee @@ -1,6 +1,5 @@ class App.WidgetTag extends App.Controller possibleTags: {} - shiftHeld: false elements: '.js-newTagLabel': 'newTagLabel' '.js-newTagInput': 'newTagInput' @@ -11,7 +10,6 @@ class App.WidgetTag extends App.Controller 'click .js-newTagInput': 'onAddTag' 'submit form': 'onAddTag' 'click .js-delete': 'onRemoveTag' - 'mousedown .js-tag': 'shiftHeldToogle' 'click .js-tag': 'searchTag' constructor: -> @@ -126,23 +124,7 @@ class App.WidgetTag extends App.Controller @fetch() ) - searchTag: (e) => + searchTag: (e) -> e.preventDefault() item = $(e.target).text() - item = item.replace('"', '') - if item.match(/\W/) - item = "\"#{item}\"" - searchAttribute = "tag:#{item}" - currentValue = $('#global-search').val() - if @shiftHeld && currentValue - currentValue += ' AND ' - currentValue += searchAttribute - else - currentValue = searchAttribute - $('#global-search').val(currentValue) - delay = -> - $('#global-search').focus() - @delay(delay, 20) - - shiftHeldToogle: (e) => - @shiftHeld = e.shiftKey + App.GlobalSearchWidget.search(item, 'tag') diff --git a/app/assets/javascripts/app/views/tag/table.jst.eco b/app/assets/javascripts/app/views/tag/table.jst.eco index 7b57c8078..355535465 100644 --- a/app/assets/javascripts/app/views/tag/table.jst.eco +++ b/app/assets/javascripts/app/views/tag/table.jst.eco @@ -10,8 +10,8 @@ <% for item in @list: %>