diff options
author | Clement Ho <clemmakesapps@gmail.com> | 2018-02-05 17:59:48 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2018-02-05 17:59:48 +0300 |
commit | 95994503c9171caa0177d08a5ae17a7be353da03 (patch) | |
tree | 083645e8ffb75c1adb0da9efdf43e7f2e8f8bfe5 /app | |
parent | 3cb7b472cd834dcd67142bb25599af3872628bbf (diff) |
Replace $.ajax in admin broadcast messages with axios
Diffstat (limited to 'app')
3 files changed, 15 insertions, 8 deletions
diff --git a/app/assets/javascripts/pages/admin/broadcast_messages/broadcast_message.js b/app/assets/javascripts/pages/admin/broadcast_messages/broadcast_message.js index 857a6793fe3..885acfac6d0 100644 --- a/app/assets/javascripts/pages/admin/broadcast_messages/broadcast_message.js +++ b/app/assets/javascripts/pages/admin/broadcast_messages/broadcast_message.js @@ -1,4 +1,7 @@ import _ from 'underscore'; +import axios from '~/lib/utils/axios_utils'; +import flash from '~/flash'; +import { __ } from '~/locale'; export default function initBroadcastMessagesForm() { $('input#broadcast_message_color').on('input', function onMessageColorInput() { @@ -18,13 +21,15 @@ export default function initBroadcastMessagesForm() { if (message === '') { $('.js-broadcast-message-preview').text('Your message here'); } else { - $.ajax({ - url: previewPath, - type: 'POST', - data: { - broadcast_message: { message }, + axios.post(previewPath, { + broadcast_message: { + message, }, - }); + }) + .then(({ data }) => { + $('.js-broadcast-message-preview').html(data.message); + }) + .catch(() => flash(__('An error occurred while rendering preview broadcast message'))); } }, 250)); } diff --git a/app/controllers/admin/broadcast_messages_controller.rb b/app/controllers/admin/broadcast_messages_controller.rb index c49b6459452..a9109a1d4d0 100644 --- a/app/controllers/admin/broadcast_messages_controller.rb +++ b/app/controllers/admin/broadcast_messages_controller.rb @@ -1,4 +1,6 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController + include BroadcastMessagesHelper + before_action :finder, only: [:edit, :update, :destroy] def index @@ -37,7 +39,8 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController end def preview - @broadcast_message = BroadcastMessage.new(broadcast_message_params) + broadcast_message = BroadcastMessage.new(broadcast_message_params) + render json: { message: render_broadcast_message(broadcast_message) } end protected diff --git a/app/views/admin/broadcast_messages/preview.js.haml b/app/views/admin/broadcast_messages/preview.js.haml deleted file mode 100644 index c72e59640d7..00000000000 --- a/app/views/admin/broadcast_messages/preview.js.haml +++ /dev/null @@ -1 +0,0 @@ -$('.js-broadcast-message-preview').html("#{j(render_broadcast_message(@broadcast_message))}"); |