Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
0141d365
Commit
0141d365
authored
Mar 23, 2016
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable new label form in dropdown until fields are complete
parent
bb0a4c05
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
23 deletions
+60
-23
app/assets/javascripts/labels_select.js.coffee
app/assets/javascripts/labels_select.js.coffee
+60
-23
No files found.
app/assets/javascripts/labels_select.js.coffee
View file @
0141d365
...
@@ -6,7 +6,7 @@ class @LabelsSelect
...
@@ -6,7 +6,7 @@ class @LabelsSelect
labelUrl
=
$dropdown
.
data
(
'labels'
)
labelUrl
=
$dropdown
.
data
(
'labels'
)
selectedLabel
=
$dropdown
.
data
(
'selected'
)
selectedLabel
=
$dropdown
.
data
(
'selected'
)
if
selectedLabel
if
selectedLabel
selectedLabel
=
selectedLabel
.
split
(
','
)
selectedLabel
=
selectedLabel
.
toString
().
split
(
','
)
newLabelField
=
$
(
'#new_label_name'
)
newLabelField
=
$
(
'#new_label_name'
)
newColorField
=
$
(
'#new_label_color'
)
newColorField
=
$
(
'#new_label_color'
)
showNo
=
$dropdown
.
data
(
'show-no'
)
showNo
=
$dropdown
.
data
(
'show-no'
)
...
@@ -14,44 +14,81 @@ class @LabelsSelect
...
@@ -14,44 +14,81 @@ class @LabelsSelect
defaultLabel
=
$dropdown
.
data
(
'default-label'
)
defaultLabel
=
$dropdown
.
data
(
'default-label'
)
if
newLabelField
.
length
if
newLabelField
.
length
$newLabelCreateButton
=
$
(
'.js-new-label-btn'
)
$colorPreview
=
$
(
'.js-dropdown-label-color-preview'
)
$newLabelError
=
$dropdown
.
parent
().
find
(
'.js-label-error'
)
$newLabelError
=
$dropdown
.
parent
().
find
(
'.js-label-error'
)
$newLabelError
.
hide
()
$newLabelError
.
hide
()
# Suggested colors in the dropdown to chose from pre-chosen colors
$
(
'.suggest-colors-dropdown a'
).
on
'click'
,
(
e
)
->
$
(
'.suggest-colors-dropdown a'
).
on
'click'
,
(
e
)
->
e
.
preventDefault
()
e
.
preventDefault
()
e
.
stopPropagation
()
e
.
stopPropagation
()
newColorField
.
val
$
(
this
).
data
(
'color'
)
newColorField
$
(
'.js-dropdown-label-color-preview'
)
.
val
(
$
(
this
).
data
(
'color'
))
.
trigger
(
'change'
)
$colorPreview
.
css
'background-color'
,
$
(
this
).
data
(
'color'
)
.
css
'background-color'
,
$
(
this
).
data
(
'color'
)
.
parent
()
.
parent
()
.
addClass
'is-active'
.
addClass
'is-active'
# Cancel button takes back to first page
resetForm
=
->
newLabelField
.
val
''
.
trigger
'change'
newColorField
.
val
''
.
trigger
'change'
$colorPreview
.
css
'background-color'
,
''
.
parent
()
.
removeClass
'is-active'
$
(
'.dropdown-menu-back'
).
on
'click'
,
->
resetForm
()
$
(
'.js-cancel-label-btn'
).
on
'click'
,
(
e
)
->
$
(
'.js-cancel-label-btn'
).
on
'click'
,
(
e
)
->
e
.
preventDefault
()
e
.
preventDefault
()
e
.
stopPropagation
()
e
.
stopPropagation
()
resetForm
()
$
(
'.dropdown-menu-back'
,
$dropdown
.
parent
()).
trigger
'click'
$
(
'.dropdown-menu-back'
,
$dropdown
.
parent
()).
trigger
'click'
$
(
'.js-new-label-btn'
).
on
'click'
,
(
e
)
->
# Listen for change and keyup events on label and color field
e
.
preventDefault
()
# This allows us to enable the button when ready
e
.
stopPropagation
()
enableLabelCreateButton
=
->
if
newLabelField
.
val
()
isnt
''
and
newColorField
.
val
()
isnt
''
if
newLabelField
.
val
()
isnt
''
and
newColorField
.
val
()
isnt
''
$newLabelError
.
hide
()
$newLabelCreateButton
.
enable
()
$
(
'.js-new-label-btn'
).
disable
()
else
$newLabelCreateButton
.
disable
()
# Create new label with API
Api
.
newLabel
projectId
,
{
newLabelField
.
on
'keyup change'
,
enableLabelCreateButton
name
:
newLabelField
.
val
()
color
:
newColorField
.
val
()
newColorField
.
on
'keyup change'
,
enableLabelCreateButton
},
(
label
)
->
$
(
'.js-new-label-btn'
).
enable
()
# Send the API call to create the label
$newLabelCreateButton
if
label
.
message
?
.
disable
()
$newLabelError
.
on
'click'
,
(
e
)
->
.
text
label
.
message
e
.
preventDefault
()
.
show
()
e
.
stopPropagation
()
else
$
(
'.dropdown-menu-back'
,
$dropdown
.
parent
()).
trigger
'click'
if
newLabelField
.
val
()
isnt
''
and
newColorField
.
val
()
isnt
''
$newLabelError
.
hide
()
$
(
'.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
()
if
label
.
message
?
$newLabelError
.
text
label
.
message
.
show
()
else
$
(
'.dropdown-menu-back'
,
$dropdown
.
parent
()).
trigger
'click'
$dropdown
.
glDropdown
(
$dropdown
.
glDropdown
(
data
:
(
term
,
callback
)
->
data
:
(
term
,
callback
)
->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment