Commit 5843a43c authored by Phil Hughes's avatar Phil Hughes

Merge branch 'es-module-broadcast_message' into 'master'

Refactor broadcast_message.js

See merge request gitlab-org/gitlab-ce!14853
parents 273b116c 6ad466a3
/* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, no-var, quotes, no-else-return, object-shorthand, comma-dangle, max-len */ export default function initBroadcastMessagesForm() {
$('input#broadcast_message_color').on('input', function onMessageColorInput() {
$(function() { const previewColor = $(this).val();
var previewPath; $('div.broadcast-message-preview').css('background-color', previewColor);
$('input#broadcast_message_color').on('input', function() {
var previewColor;
previewColor = $(this).val();
return $('div.broadcast-message-preview').css('background-color', previewColor);
}); });
$('input#broadcast_message_font').on('input', function() {
var previewColor; $('input#broadcast_message_font').on('input', function onMessageFontInput() {
previewColor = $(this).val(); const previewColor = $(this).val();
return $('div.broadcast-message-preview').css('color', previewColor); $('div.broadcast-message-preview').css('color', previewColor);
}); });
previewPath = $('textarea#broadcast_message_message').data('preview-path');
return $('textarea#broadcast_message_message').on('input', function() { const previewPath = $('textarea#broadcast_message_message').data('preview-path');
var message;
message = $(this).val(); $('textarea#broadcast_message_message').on('input', _.debounce(function onMessageInput() {
const message = $(this).val();
if (message === '') { if (message === '') {
return $('.js-broadcast-message-preview').text("Your message here"); $('.js-broadcast-message-preview').text('Your message here');
} else { } else {
return $.ajax({ $.ajax({
url: previewPath, url: previewPath,
type: "POST", type: 'POST',
data: { data: {
broadcast_message: { broadcast_message: { message },
message: message },
}
}
}); });
} }
}); }, 250));
}); }
...@@ -70,6 +70,7 @@ import initSettingsPanels from './settings_panels'; ...@@ -70,6 +70,7 @@ import initSettingsPanels from './settings_panels';
import initExperimentalFlags from './experimental_flags'; import initExperimentalFlags from './experimental_flags';
import OAuthRememberMe from './oauth_remember_me'; import OAuthRememberMe from './oauth_remember_me';
import PerformanceBar from './performance_bar'; import PerformanceBar from './performance_bar';
import initBroadcastMessagesForm from './broadcast_message';
import initNotes from './init_notes'; import initNotes from './init_notes';
import initLegacyFilters from './init_legacy_filters'; import initLegacyFilters from './init_legacy_filters';
import initIssuableSidebar from './init_issuable_sidebar'; import initIssuableSidebar from './init_issuable_sidebar';
...@@ -555,6 +556,9 @@ import memberExpirationDate from './member_expiration_date'; ...@@ -555,6 +556,9 @@ import memberExpirationDate from './member_expiration_date';
case 'admin': case 'admin':
new Admin(); new Admin();
switch (path[1]) { switch (path[1]) {
case 'broadcast_messages':
initBroadcastMessagesForm();
break;
case 'cohorts': case 'cohorts':
new UsagePing(); new UsagePing();
break; break;
......
...@@ -53,7 +53,6 @@ import './aside'; ...@@ -53,7 +53,6 @@ import './aside';
import './autosave'; import './autosave';
import loadAwardsHandler from './awards_handler'; import loadAwardsHandler from './awards_handler';
import bp from './breakpoints'; import bp from './breakpoints';
import './broadcast_message';
import './commits'; import './commits';
import './compare'; import './compare';
import './compare_autocomplete'; import './compare_autocomplete';
......
---
title: Fix unnecessary ajax requests in admin broadcast message form
merge_request: 14853
author:
type: fixed
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