BigW Consortium Gitlab

Commit a477d604 by Alfredo Sumaran

Add ability to clear location badge

parent eff98ffe
...@@ -27,6 +27,7 @@ class @SearchAutocomplete ...@@ -27,6 +27,7 @@ class @SearchAutocomplete
@groupInputEl = @getElement('#group_id') @groupInputEl = @getElement('#group_id')
@searchCodeInputEl = @getElement('#search_code') @searchCodeInputEl = @getElement('#search_code')
@repositoryInputEl = @getElement('#repository_ref') @repositoryInputEl = @getElement('#repository_ref')
@clearInput = @getElement('.js-clear-input')
@saveOriginalState() @saveOriginalState()
...@@ -59,6 +60,7 @@ class @SearchAutocomplete ...@@ -59,6 +60,7 @@ class @SearchAutocomplete
@searchInput.on 'keydown', @onSearchInputKeyDown @searchInput.on 'keydown', @onSearchInputKeyDown
@searchInput.on 'focus', @onSearchInputFocus @searchInput.on 'focus', @onSearchInputFocus
@searchInput.on 'blur', @onSearchInputBlur @searchInput.on 'blur', @onSearchInputBlur
@clearInput.on 'click', @onRemoveLocationClick
enableAutocomplete: -> enableAutocomplete: ->
return if @autocomplete return if @autocomplete
...@@ -150,12 +152,25 @@ class @SearchAutocomplete ...@@ -150,12 +152,25 @@ class @SearchAutocomplete
onSearchInputFocus: => onSearchInputFocus: =>
@wrap.addClass('search-active') @wrap.addClass('search-active')
onSearchInputBlur: => onRemoveLocationClick: (e) =>
@wrap.removeClass('search-active') e.preventDefault()
@removeLocationBadge()
@searchInput.val('').focus()
@skipBlurEvent = true
# If input is blank then restore state onSearchInputBlur: (e) =>
if @searchInput.val() is '' @skipBlurEvent = false
@restoreOriginalState()
# We should wait to make sure we are not clearing the input instead
setTimeout( =>
return if @skipBlurEvent
@wrap.removeClass('search-active')
# If input is blank then restore state
if @searchInput.val() is ''
@restoreOriginalState()
, 100)
addLocationBadge: (item) -> addLocationBadge: (item) ->
category = if item.category? then "#{item.category}: " else '' category = if item.category? then "#{item.category}: " else ''
...@@ -165,6 +180,7 @@ class @SearchAutocomplete ...@@ -165,6 +180,7 @@ class @SearchAutocomplete
<i class='location-text'>#{category}#{value}</i> <i class='location-text'>#{category}#{value}</i>
</span>" </span>"
@locationBadgeEl.html(html) @locationBadgeEl.html(html)
@wrap.addClass('has-location-badge')
restoreOriginalState: -> restoreOriginalState: ->
inputs = Object.keys @originalState inputs = Object.keys @originalState
...@@ -208,6 +224,8 @@ class @SearchAutocomplete ...@@ -208,6 +224,8 @@ class @SearchAutocomplete
# Reset state # Reset state
@resetSearchState() @resetSearchState()
@wrap.removeClass('has-location-badge')
disableAutocomplete: -> disableAutocomplete: ->
if @autocomplete if @autocomplete
@searchInput.addClass('disabled') @searchInput.addClass('disabled')
......
...@@ -199,4 +199,5 @@ $award-emoji-new-btn-icon-color: #dcdcdc; ...@@ -199,4 +199,5 @@ $award-emoji-new-btn-icon-color: #dcdcdc;
$location-badge-color: #aaa; $location-badge-color: #aaa;
$location-badge-bg: $gray-normal; $location-badge-bg: $gray-normal;
$location-icon-color: #e7e9ed; $location-icon-color: #e7e9ed;
$location-active-color: #7f8fa4;
$location-active-bg: $location-active-color;
...@@ -26,24 +26,6 @@ ...@@ -26,24 +26,6 @@
margin-left: 10px; margin-left: 10px;
margin-top: ($header-height - 35) / 2; margin-top: ($header-height - 35) / 2;
&.search-active {
form {
@extend .form-control:focus;
}
.location-badge {
@include transition(all .15s);
background-color: $input-border-focus;
color: $white-light;
}
.search-input-wrap {
i {
color: $input-border-focus;
}
}
}
form { form {
@extend .form-control; @extend .form-control;
margin: 0; margin: 0;
...@@ -92,16 +74,11 @@ ...@@ -92,16 +74,11 @@
width: 100%; width: 100%;
position: relative; position: relative;
.search-icon { .search-icon, .clear-icon {
@extend .fa-search;
@include transition(color .15s);
position: absolute; position: absolute;
right: 5px; right: 5px;
color: $location-icon-color;
top: 0; top: 0;
-webkit-user-select: none; color: $location-icon-color;
-moz-user-select: none;
-ms-user-select: none;
&:before { &:before {
font-family: FontAwesome; font-family: FontAwesome;
...@@ -110,9 +87,53 @@ ...@@ -110,9 +87,53 @@
} }
} }
.search-icon {
@extend .fa-search;
@include transition(color .15s);
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
.clear-icon {
@extend .fa-times;
display: none;
}
.dropdown-header { .dropdown-header {
text-transform: uppercase; text-transform: uppercase;
font-size: 11px; font-size: 11px;
} }
} }
&.search-active {
form {
@extend .form-control:focus;
}
.location-badge {
@include transition(all .15s);
background-color: $location-active-bg;
color: $white-light;
}
.search-input-wrap {
i {
color: $location-active-color;
}
}
&.has-location-badge {
.search-icon {
display: none;
}
.clear-icon {
cursor: pointer;
display: block;
}
}
}
} }
.search.search-form - if controller.controller_path =~ /^groups/
- label = 'This group'
- if controller.controller_path =~ /^projects/
- label = 'This project'
.search.search-form{class: "#{'has-location-badge' if label.present?}"}
= form_tag search_path, method: :get, class: 'navbar-form' do |f| = form_tag search_path, method: :get, class: 'navbar-form' do |f|
.search-input-container .search-input-container
.search-location-badge .search-location-badge
= render 'shared/location_badge' - if label.present?
%span.location-badge
%i.location-text
= label
.search-input-wrap .search-input-wrap
.dropdown{ data: {url: search_autocomplete_path } } .dropdown{ data: {url: search_autocomplete_path } }
= search_field_tag "search", nil, placeholder: 'Search', class: "search-input dropdown-menu-toggle", spellcheck: false, tabindex: "1", autocomplete: 'off', data: { toggle: 'dropdown' } = search_field_tag "search", nil, placeholder: 'Search', class: "search-input dropdown-menu-toggle", spellcheck: false, tabindex: "1", autocomplete: 'off', data: { toggle: 'dropdown' }
...@@ -10,6 +18,7 @@ ...@@ -10,6 +18,7 @@
= dropdown_content = dropdown_content
= dropdown_loading = dropdown_loading
%i.search-icon %i.search-icon
%i.clear-icon.js-clear-input
= hidden_field_tag :group_id, @group.try(:id) = hidden_field_tag :group_id, @group.try(:id)
= hidden_field_tag :project_id, @project && @project.persisted? ? @project.id : '', id: 'search_project_id' = hidden_field_tag :project_id, @project && @project.persisted? ? @project.id : '', id: 'search_project_id'
......
- if controller.controller_path =~ /^groups/
- label = 'This group'
- if controller.controller_path =~ /^projects/
- label = 'This project'
- if label.present?
%span.location-badge
%i.location-text
= label
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment