Commit 8b9a4963 authored by Phil Hughes's avatar Phil Hughes

Updated dropdowns to use field instead

Allows a bit more flexibilty and keeps the current functionality
parent c160aae6
class @CompareAutocomplete
constructor: ->
@initDropdown()
initDropdown: ->
$('.js-compare-dropdown').each ->
$dropdown = $(@)
selected = $dropdown.data('selected')
$dropdown.glDropdown(
data: (term, callback) ->
$.ajax(
url: $dropdown.data('refs-url')
data:
ref: $dropdown.data('ref')
).done (refs) ->
callback(refs)
selectable: true
filterable: true
filterByText: true
fieldName: $dropdown.attr('name')
filterInput: 'input[type="text"]'
renderRow: (ref) ->
if ref.header?
$('<li />')
.addClass('dropdown-header')
.text(ref.header)
else
link = $('<a />')
.attr('href', '#')
.addClass(if ref is selected then 'is-active' else '')
.text(ref)
.attr('data-ref', escape(ref))
$('<li />')
.append(link)
id: (obj, $el) ->
$el.attr('data-ref')
toggleLabel: (obj, $el) ->
$el.text().trim()
)
...@@ -138,6 +138,8 @@ class Dispatcher ...@@ -138,6 +138,8 @@ class Dispatcher
new Project() new Project()
new ProjectAvatar() new ProjectAvatar()
switch path[1] switch path[1]
when 'compare'
new CompareAutocomplete()
when 'edit' when 'edit'
shortcut_handler = new ShortcutsNavigation() shortcut_handler = new ShortcutsNavigation()
new ProjectNew() new ProjectNew()
......
...@@ -456,6 +456,8 @@ class GitLabDropdown ...@@ -456,6 +456,8 @@ class GitLabDropdown
rowClicked: (el) -> rowClicked: (el) ->
fieldName = @options.fieldName fieldName = @options.fieldName
isInput = $(@el).is('input')
if @renderedData if @renderedData
groupName = el.data('group') groupName = el.data('group')
if groupName if groupName
...@@ -466,10 +468,19 @@ class GitLabDropdown ...@@ -466,10 +468,19 @@ class GitLabDropdown
selectedObject = @renderedData[selectedIndex] selectedObject = @renderedData[selectedIndex]
value = if @options.id then @options.id(selectedObject, el) else selectedObject.id value = if @options.id then @options.id(selectedObject, el) else selectedObject.id
field = @dropdown.parent().find("input[name='#{fieldName}'][value='#{value}']")
if isInput
field = $(@el)
else
field = @dropdown.parent().find("input[name='#{fieldName}'][value='#{value}']")
if el.hasClass(ACTIVE_CLASS) if el.hasClass(ACTIVE_CLASS)
el.removeClass(ACTIVE_CLASS) el.removeClass(ACTIVE_CLASS)
field.remove()
if isInput
field.val('')
else
field.remove()
# Toggle the dropdown label # Toggle the dropdown label
if @options.toggleLabel if @options.toggleLabel
...@@ -490,7 +501,9 @@ class GitLabDropdown ...@@ -490,7 +501,9 @@ class GitLabDropdown
else else
if not @options.multiSelect or el.hasClass('dropdown-clear-active') if not @options.multiSelect or el.hasClass('dropdown-clear-active')
@dropdown.find(".#{ACTIVE_CLASS}").removeClass ACTIVE_CLASS @dropdown.find(".#{ACTIVE_CLASS}").removeClass ACTIVE_CLASS
@dropdown.parent().find("input[name='#{fieldName}']").remove()
unless isInput
@dropdown.parent().find("input[name='#{fieldName}']").remove()
if !value? if !value?
field.remove() field.remove()
......
...@@ -67,7 +67,7 @@ class @Project ...@@ -67,7 +67,7 @@ class @Project
selectable: true selectable: true
filterable: true filterable: true
filterByText: true filterByText: true
fieldName: $dropdown.data('field-name') fieldName: 'ref'
renderRow: (ref) -> renderRow: (ref) ->
if ref.header? if ref.header?
$('<li />') $('<li />')
...@@ -87,6 +87,5 @@ class @Project ...@@ -87,6 +87,5 @@ class @Project
toggleLabel: (obj, $el) -> toggleLabel: (obj, $el) ->
$el.text().trim() $el.text().trim()
clicked: (e) -> clicked: (e) ->
unless $dropdown.hasClass('js-compare-dropdown') $dropdown.closest('form').submit()
$dropdown.closest('form').submit()
) )
...@@ -48,6 +48,9 @@ ...@@ -48,6 +48,9 @@
border: 1px solid $dropdown-toggle-border-color; border: 1px solid $dropdown-toggle-border-color;
border-radius: $border-radius-base; border-radius: $border-radius-base;
outline: 0; outline: 0;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
.fa { .fa {
position: absolute; position: absolute;
...@@ -58,14 +61,6 @@ ...@@ -58,14 +61,6 @@
font-size: 10px; font-size: 10px;
} }
.dropdown-toggle-text {
display: block;
min-height: 19px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
&:hover, { &:hover, {
border-color: $dropdown-toggle-hover-border-color; border-color: $dropdown-toggle-hover-border-color;
......
...@@ -633,19 +633,7 @@ pre.light-well { ...@@ -633,19 +633,7 @@ pre.light-well {
} }
} }
.compare-input-group { .compare-form-group {
&.input-group .input-group-addon {
@media (min-width: $screen-sm-min) {
width: 1%;
}
}
.dropdown-menu-toggle {
width: 100%;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
.dropdown-menu { .dropdown-menu {
width: 300px; width: 300px;
} }
......
...@@ -2,19 +2,17 @@ ...@@ -2,19 +2,17 @@
.clearfix .clearfix
- if params[:to] && params[:from] - if params[:to] && params[:from]
= link_to 'switch', {from: params[:to], to: params[:from]}, {class: 'commits-compare-switch has-tooltip', title: 'Switch base of comparison'} = link_to 'switch', {from: params[:to], to: params[:from]}, {class: 'commits-compare-switch has-tooltip', title: 'Switch base of comparison'}
.form-group .form-group.dropdown.compare-form-group.js-compare-from-dropdown
= hidden_field_tag :from, params[:from] .input-group.inline-input-group
.input-group.inline-input-group.compare-input-group.dropdown
%span.input-group-addon from %span.input-group-addon from
= dropdown_toggle h(params[:from].presence || ''), { toggle: "dropdown", refs_url: refs_namespace_project_path(@project.namespace, @project), field_name: 'from', selected: params[:from] }, { toggle_class: "js-project-refs-dropdown js-compare-dropdown" } = text_field_tag :from, params[:from], class: "form-control js-compare-dropdown", required: true, data: { refs_url: refs_namespace_project_path(@project.namespace, @project), toggle: "dropdown", target: ".js-compare-from-dropdown", selected: params[:from].presence }
= render "ref_dropdown" = render "ref_dropdown"
= "..." = "..."
.form-group .form-group.dropdown.compare-form-group.js-compare-to-dropdown
= hidden_field_tag :to, params[:to] .input-group.inline-input-group
.input-group.inline-input-group.compare-input-group.dropdown
%span.input-group-addon to %span.input-group-addon to
= dropdown_toggle h(params[:from].presence || ''), { toggle: "dropdown", refs_url: refs_namespace_project_path(@project.namespace, @project), field_name: 'to', selected: params[:to] }, { toggle_class: "js-project-refs-dropdown js-compare-dropdown" } = text_field_tag :to, params[:to], class: "form-control js-compare-dropdown", required: true, data: { refs_url: refs_namespace_project_path(@project.namespace, @project), toggle: "dropdown", target: ".js-compare-to-dropdown", selected: params[:to].presence }
= render "ref_dropdown" = render "ref_dropdown"
&nbsp; &nbsp;
= button_tag "Compare", class: "btn btn-create commits-compare-btn" = button_tag "Compare", class: "btn btn-create commits-compare-btn"
- if @merge_request.present? - if @merge_request.present?
......
.dropdown-menu.dropdown-menu-selectable .dropdown-menu.dropdown-menu-selectable
= dropdown_title "Switch branch/tag" = dropdown_title "Select branch/tag"
= dropdown_filter "Search branches and tags"
= dropdown_content = dropdown_content
= dropdown_loading = dropdown_loading
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
- @options && @options.each do |key, value| - @options && @options.each do |key, value|
= hidden_field_tag key, value, id: nil = hidden_field_tag key, value, id: nil
.dropdown .dropdown
= dropdown_toggle dropdown_toggle_text, { toggle: "dropdown", selected: dropdown_toggle_text, field_name: 'ref', ref: @ref, refs_url: refs_namespace_project_path(@project.namespace, @project) }, { toggle_class: "js-project-refs-dropdown" } = dropdown_toggle dropdown_toggle_text, { toggle: "dropdown", selected: dropdown_toggle_text, ref: @ref, refs_url: refs_namespace_project_path(@project.namespace, @project) }, { toggle_class: "js-project-refs-dropdown" }
.dropdown-menu.dropdown-menu-selectable{ class: ("dropdown-menu-align-right" if local_assigns[:align_right]) } .dropdown-menu.dropdown-menu-selectable{ class: ("dropdown-menu-align-right" if local_assigns[:align_right]) }
= dropdown_title "Switch branch/tag" = dropdown_title "Switch branch/tag"
= dropdown_filter "Search branches and tags" = dropdown_filter "Search branches and tags"
......
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