Commit e8d84110 authored by Jacob Schatz's avatar Jacob Schatz

Adds new dropdown ajax to user selection

parent 74c7a537
......@@ -198,14 +198,13 @@ class @LabelsSelect
# need inline-block here instead of show,
# which will default to the element's style in this case inline.
selected = if selected.length then selected else ['']
$loading
.fadeIn()
$loading.fadeIn()
$.ajax(
type: 'PUT'
url: issueURL
data:
issue:
label_ids: selected
assignee_id: selected
).done (data) ->
$loading.fadeOut()
$selectbox.hide()
......
......@@ -12,6 +12,11 @@ class @UsersSelect
firstUser = $dropdown.data('first-user')
selectedId = $dropdown.data('selected')
defaultLabel = $dropdown.data('default-label')
issueURL = $dropdown.data('issueUpdate')
$selectbox = $dropdown.closest('.selectbox')
$block = $selectbox.closest('.block')
$value = $block.find('.value')
$loading = $block.find('.block-loading').fadeOut()
$dropdown.glDropdown(
data: (term, callback) =>
......@@ -57,11 +62,17 @@ class @UsersSelect
fields: ['name', 'username']
selectable: true
fieldName: $dropdown.data('field-name')
toggleLabel: (selected) ->
if selected && 'id' of selected
selected.name
else
defaultLabel
hidden: ->
$selectbox.hide()
$value.show()
clicked: ->
page = $('body').data 'page'
isIssueIndex = page is 'projects:issues:index'
......@@ -72,7 +83,32 @@ class @UsersSelect
else if $dropdown.hasClass 'js-filter-submit'
$dropdown.closest('form').submit()
else
console.log 'else'
selected = $dropdown
.closest('.selectbox')
.find("input[name='#{$dropdown.data('field-name')}']").val()
$loading
.fadeIn()
$.ajax(
type: 'PUT'
url: issueURL
data:
issue:
assignee_id: selected
).done (data) ->
$loading.fadeOut()
$selectbox.hide()
href = $value
.show()
.find('.author')
.text(data.assignee.name)
.end()
.find('a')
.attr('href')
splitHref = href.split('/')
splitHref[splitHref.length - 1] = data.assignee.username
$value
.find('a')
.attr('href',splitHref.join('/'))
renderRow: (user) ->
username = if user.username then "@#{user.username}" else ""
avatar = if user.avatar_url then user.avatar_url else false
......
......@@ -114,7 +114,7 @@ class Projects::IssuesController < Projects::ApplicationController
end
end
format.json do
render json: @issue.to_json(include: [:milestone, :labels])
render json: @issue.to_json(include: [:milestone, :labels, :assignee])
end
end
end
......
......@@ -28,6 +28,7 @@
= icon('user')
.title.hide-collapsed
Assignee
=icon('spinner spin', class: 'block-loading')
- if can?(current_user, :"admin_#{issuable.to_ability_name}", @project)
= link_to 'Edit', '#', class: 'edit-link pull-right'
.value.bold.hide-collapsed
......@@ -42,7 +43,8 @@
.light None
.selectbox.hide-collapsed
= dropdown_tag("Select assignee", options: { toggle_class: "js-user-search js-author-search", title: "Filter by user", filter: true, dropdown_class: "dropdown-menu-user dropdown-menu-selectable dropdown-menu-author", placeholder: "Search users", data: { first_user: (current_user.username if current_user), current_user: true, project_id: (@project.id if @project), selected: params[:author_id], field_name: "author_id" } })
= f.hidden_field 'assignee_id', value: issuable.assignee.id, id: nil
= dropdown_tag("Select assignee", options: { toggle_class: "js-user-search js-author-search", title: "Filter by user", filter: true, dropdown_class: "dropdown-menu-user dropdown-menu-selectable dropdown-menu-author", placeholder: "Search users", data: { first_user: (current_user.username if current_user), current_user: true, project_id: (@project.id if @project), field_name: "issue[assignee_id]", issue_update: namespace_project_issue_path(@project.namespace, @project, issuable.id, :json) } })
.block.milestone
.sidebar-collapsed-icon
......
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