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
Boxiang Sun
gitlab-ce
Commits
35238511
Commit
35238511
authored
Jul 26, 2019
by
Ammar Alakkad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add default colors for broadcast messages
parent
29a7c83e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
14 deletions
+62
-14
app/assets/javascripts/pages/admin/broadcast_messages/broadcast_message.js
...ripts/pages/admin/broadcast_messages/broadcast_message.js
+42
-7
app/views/admin/broadcast_messages/_form.html.haml
app/views/admin/broadcast_messages/_form.html.haml
+15
-7
changelogs/unreleased/61787-the-colour-selector-for-broadcast-messages-should-provide-a-few-default-options-with-descriptive-labels-like.yml
...de-a-few-default-options-with-descriptive-labels-like.yml
+5
-0
No files found.
app/assets/javascripts/pages/admin/broadcast_messages/broadcast_message.js
View file @
35238511
...
...
@@ -3,26 +3,31 @@ import _ from 'underscore';
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
flash
from
'
~/flash
'
;
import
{
__
}
from
'
~/locale
'
;
import
{
textColorForBackground
}
from
'
~/lib/utils/color_utils
'
;
export
default
()
=>
{
$
(
'
input#broadcast_message_color
'
).
on
(
'
input
'
,
function
onMessageColorInput
()
{
const
$broadcastMessageColor
=
$
(
'
input#broadcast_message_color
'
);
const
$broadcastMessagePreview
=
$
(
'
div.broadcast-message-preview
'
);
$broadcastMessageColor
.
on
(
'
input
'
,
function
onMessageColorInput
()
{
const
previewColor
=
$
(
this
).
val
();
$
(
'
div.broadcast-message-preview
'
)
.
css
(
'
background-color
'
,
previewColor
);
$
broadcastMessagePreview
.
css
(
'
background-color
'
,
previewColor
);
});
$
(
'
input#broadcast_message_font
'
).
on
(
'
input
'
,
function
onMessageFontInput
()
{
const
previewColor
=
$
(
this
).
val
();
$
(
'
div.broadcast-message-preview
'
)
.
css
(
'
color
'
,
previewColor
);
$
broadcastMessagePreview
.
css
(
'
color
'
,
previewColor
);
});
const
previewPath
=
$
(
'
textarea#broadcast_message_message
'
).
data
(
'
previewPath
'
);
const
$broadcastMessage
=
$
(
'
textarea#broadcast_message_message
'
);
const
previewPath
=
$broadcastMessage
.
data
(
'
previewPath
'
);
const
$jsBroadcastMessagePreview
=
$
(
'
.js-broadcast-message-preview
'
);
$
(
'
textarea#broadcast_message_message
'
)
.
on
(
$
broadcastMessage
.
on
(
'
input
'
,
_
.
debounce
(
function
onMessageInput
()
{
const
message
=
$
(
this
).
val
();
if
(
message
===
''
)
{
$
(
'
.js-broadcast-message-preview
'
)
.
text
(
__
(
'
Your message here
'
));
$
jsBroadcastMessagePreview
.
text
(
__
(
'
Your message here
'
));
}
else
{
axios
.
post
(
previewPath
,
{
...
...
@@ -31,10 +36,40 @@ export default () => {
},
})
.
then
(({
data
})
=>
{
$
(
'
.js-broadcast-message-preview
'
)
.
html
(
data
.
message
);
$
jsBroadcastMessagePreview
.
html
(
data
.
message
);
})
.
catch
(()
=>
flash
(
__
(
'
An error occurred while rendering preview broadcast message
'
)));
}
},
250
),
);
const
updateColorPreview
=
()
=>
{
const
selectedBackgroundColor
=
$broadcastMessageColor
.
val
();
const
contrastTextColor
=
textColorForBackground
(
selectedBackgroundColor
);
// save contrastTextColor to hidden input field
$
(
'
input.text-font-color
'
).
val
(
contrastTextColor
);
// Updates the preview color with the hex-color input
const
selectedColorStyle
=
{
backgroundColor
:
selectedBackgroundColor
,
color
:
contrastTextColor
,
};
$
(
'
.label-color-preview
'
).
css
(
selectedColorStyle
);
return
$broadcastMessagePreview
.
css
(
selectedColorStyle
);
};
const
setSuggestedColor
=
e
=>
{
const
color
=
$
(
e
.
currentTarget
).
data
(
'
color
'
);
$broadcastMessageColor
.
val
(
color
)
// Notify the form, that color has changed
.
trigger
(
'
input
'
);
updateColorPreview
();
return
e
.
preventDefault
();
};
$
(
document
).
on
(
'
click
'
,
'
.suggest-colors a
'
,
setSuggestedColor
);
};
app/views/admin/broadcast_messages/_form.html.haml
View file @
35238511
...
...
@@ -17,19 +17,27 @@
required:
true
,
dir:
'auto'
,
data:
{
preview_path:
preview_admin_broadcast_messages_path
}
.form-group.row.js-toggle-colors-container
.col-sm-10.offset-sm-2
=
link_to
'Customize colors'
,
'#'
,
class:
'js-toggle-colors-link'
.form-group.row.js-toggle-colors-container.toggle-colors.hide
.form-group.row
.col-sm-2.col-form-label
=
f
.
label
:color
,
"Background Color"
=
f
.
label
:color
,
_
(
"Background color"
)
.col-sm-10
=
f
.
color_field
:color
,
class:
"form-control"
.input-group
.input-group-prepend
.input-group-text.label-color-preview
{
:style
=>
'background-color: '
+
@broadcast_message
.
color
+
'; color: '
+
@broadcast_message
.
font
}
=
' '
.
html_safe
=
f
.
text_field
:color
,
class:
"form-control"
.form-text.text-muted
=
_
(
'Choose any color.'
)
%br
=
_
(
"Or you can choose one of the suggested colors below"
)
=
render_suggested_colors
.form-group.row.js-toggle-colors-container.toggle-colors.hide
.col-sm-2.col-form-label
=
f
.
label
:font
,
"Font Color"
.col-sm-10
=
f
.
color_field
:font
,
class:
"form-control"
=
f
.
color_field
:font
,
class:
"form-control
text-font-color
"
.form-group.row
.col-sm-2.col-form-label
=
f
.
label
:starts_at
,
_
(
"Starts at (UTC)"
)
...
...
changelogs/unreleased/61787-the-colour-selector-for-broadcast-messages-should-provide-a-few-default-options-with-descriptive-labels-like.yml
0 → 100644
View file @
35238511
---
title
:
add color selector to broadcast messages form
merge_request
:
30988
author
:
type
:
other
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