class @UsersSelect constructor: -> @usersPath = "/autocomplete/users.json" @userPath = "/autocomplete/users/:id.json" $('.js-user-search').each (i, dropdown) => $dropdown = $(dropdown) @projectId = $dropdown.data('project-id') @showCurrentUser = $dropdown.data('current-user') showNullUser = $dropdown.data('null-user') showAnyUser = $dropdown.data('any-user') 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) => @users term, (users) => if term.length is 0 showDivider = 0 if firstUser # Move current user to the front of the list for obj, index in users if obj.username == firstUser users.splice(index, 1) users.unshift(obj) break if showNullUser showDivider += 1 users.unshift( beforeDivider: true name: 'Unassigned', id: 0 ) if showAnyUser showDivider += 1 name = showAnyUser name = 'Any User' if name == true anyUser = { beforeDivider: true name: name, id: null } users.unshift(anyUser) if showDivider users.splice(showDivider, 0, "divider") # Send the data back callback users filterable: true filterRemote: true search: 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' isMRIndex = page is page is 'projects:merge_requests:index' if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex) Issues.filterResults $dropdown.closest('form') else if $dropdown.hasClass 'js-filter-submit' $dropdown.closest('form').submit() 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 selected = if user.id is selectedId then "is-active" else "" img = "" if user.beforeDivider? "