Commit 75b21ebd authored by Phil Hughes's avatar Phil Hughes

Can create new label from dropdown

parent 5cdac761
...@@ -75,6 +75,20 @@ ...@@ -75,6 +75,20 @@
).done (labels) -> ).done (labels) ->
callback(labels) callback(labels)
newLabel: (project_id, data, callback) ->
url = Api.buildUrl(Api.labels_path)
url = url.replace(':id', project_id)
data.private_token = gon.api_token
$.ajax(
url: url
type: "POST"
data: data
dataType: "json"
).done (label) ->
callback(label)
milestones: (project_id, callback) -> milestones: (project_id, callback) ->
url = Api.buildUrl(Api.milestones_path) url = Api.buildUrl(Api.milestones_path)
url = url.replace(':id', project_id) url = url.replace(':id', project_id)
......
...@@ -2,7 +2,7 @@ class GitLabDropdownFilter ...@@ -2,7 +2,7 @@ class GitLabDropdownFilter
BLUR_KEYCODES = [27, 40] BLUR_KEYCODES = [27, 40]
constructor: (@dropdown, @remote, @query, @data, @callback) -> constructor: (@dropdown, @remote, @query, @data, @callback) ->
@input = @dropdown.find(".dropdown-input-field") @input = @dropdown.find(".dropdown-input .dropdown-input-field")
# Key events # Key events
timeout = "" timeout = ""
...@@ -108,10 +108,10 @@ class GitLabDropdown ...@@ -108,10 +108,10 @@ class GitLabDropdown
@togglePage() @togglePage()
if @options.selectable if @options.selectable
selector = "a" selector = ".dropdown-content a"
if @dropdown.find(".dropdown-toggle-page").length if @dropdown.find(".dropdown-toggle-page").length
selector = ".dropdown-page-one a" selector = ".dropdown-page-one .dropdown-content a"
@dropdown.on "click", selector, (e) -> @dropdown.on "click", selector, (e) ->
self.rowClicked $(@) self.rowClicked $(@)
......
...@@ -3,6 +3,32 @@ class @LabelsSelect ...@@ -3,6 +3,32 @@ class @LabelsSelect
$('.js-label-select').each (i, dropdown) -> $('.js-label-select').each (i, dropdown) ->
projectId = $(dropdown).data('project-id') projectId = $(dropdown).data('project-id')
selectedLabel = $(dropdown).data('selected') selectedLabel = $(dropdown).data('selected')
newLabelField = $('#new_label_name')
newColorField = $('#new_label_color')
if newLabelField.length
$('.suggest-colors-dropdown a').on "click", (e) ->
e.preventDefault()
e.stopPropagation()
newColorField.val $(this).data("color")
$('.js-dropdown-label-color-preview')
.css 'background-color', $(this).data("color")
.addClass 'is-active'
$('.js-new-label-btn').on "click", (e) ->
e.preventDefault()
e.stopPropagation()
if newLabelField.val() isnt "" && newColorField.val() isnt ""
$('.js-new-label-btn').disable()
# Create new label with API
Api.newLabel projectId, {
name: newLabelField.val()
color: newColorField.val()
}, (label) ->
$('.js-new-label-btn').enable()
$('.dropdown-menu-back', $(dropdown).parent()).trigger "click"
$(dropdown).glDropdown( $(dropdown).glDropdown(
data: (term, callback) -> data: (term, callback) ->
......
...@@ -238,6 +238,7 @@ ...@@ -238,6 +238,7 @@
font-size: 14px; font-size: 14px;
border: 0; border: 0;
background: none; background: none;
outline: 0;
&:hover { &:hover {
color: darken($dropdown-title-btn-color, 15%); color: darken($dropdown-title-btn-color, 15%);
......
...@@ -20,6 +20,17 @@ ...@@ -20,6 +20,17 @@
} }
} }
.dropdown-label-color-preview {
display: none;
margin-top: 5px;
width: 100%;
height: 25px;
&.is-active {
display: block;
}
}
.label-row { .label-row {
.label { .label {
padding: 9px; padding: 9px;
......
...@@ -73,13 +73,17 @@ ...@@ -73,13 +73,17 @@
= icon('arrow-left') = icon('arrow-left')
%span %span
Create new label Create new label
%button.dropdown-title-button.dropdown-menu-close{type: "button", aria: {label: "close"}}
= icon('times')
.dropdown-content .dropdown-content
= text_field_tag :label_name, nil, class: "dropdown-input-field", placeholder: "Name new label" = hidden_field_tag :new_label_color, nil
= text_field_tag :new_label_name, nil, class: "dropdown-input-field", placeholder: "Name new label"
.dropdown-label-color-preview.js-dropdown-label-color-preview
.suggest-colors.suggest-colors-dropdown .suggest-colors.suggest-colors-dropdown
- suggested_colors.each do |color| - suggested_colors.each do |color|
= link_to '#', style: "background-color: #{color}", data: { color: color } do = link_to '#', style: "background-color: #{color}", data: { color: color } do
&nbsp &nbsp
%button.btn.btn-primary{type: "button"} %button.btn.btn-primary.js-new-label-btn{type: "button"}
Create Create
.dropdown-loading .dropdown-loading
= icon('spinner spin') = icon('spinner spin')
......
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