Add AdminNotification management at admin panel
In the same fashion Newsletters is managed, with the only difference that the preview is using the notification partial in the same way the index of notifications.
This commit is contained in:
@@ -79,6 +79,7 @@
|
|||||||
//= require send_newsletter_alert
|
//= require send_newsletter_alert
|
||||||
//= require managers
|
//= require managers
|
||||||
//= require globalize
|
//= require globalize
|
||||||
|
//= require send_admin_notification_alert
|
||||||
|
|
||||||
var initialize_modules = function() {
|
var initialize_modules = function() {
|
||||||
App.Comments.initialize();
|
App.Comments.initialize();
|
||||||
@@ -124,6 +125,7 @@ var initialize_modules = function() {
|
|||||||
App.SendNewsletterAlert.initialize();
|
App.SendNewsletterAlert.initialize();
|
||||||
App.Managers.initialize();
|
App.Managers.initialize();
|
||||||
App.Globalize.initialize();
|
App.Globalize.initialize();
|
||||||
|
App.SendAdminNotificationAlert.initialize();
|
||||||
};
|
};
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
App.SendAdminNotificationAlert =
|
||||||
|
initialize: ->
|
||||||
|
$('#js-send-admin_notification-alert').on 'click', ->
|
||||||
|
confirm(this.dataset.alert);
|
||||||
67
app/controllers/admin/admin_notifications_controller.rb
Normal file
67
app/controllers/admin/admin_notifications_controller.rb
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
class Admin::AdminNotificationsController < Admin::BaseController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@admin_notifications = AdminNotification.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@admin_notification = AdminNotification.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@admin_notification = AdminNotification.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@admin_notification = AdminNotification.new(admin_notification_params)
|
||||||
|
|
||||||
|
if @admin_notification.save
|
||||||
|
notice = t("admin.admin_notifications.create_success")
|
||||||
|
redirect_to [:admin, @admin_notification], notice: notice
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@admin_notification = AdminNotification.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@admin_notification = AdminNotification.find(params[:id])
|
||||||
|
|
||||||
|
if @admin_notification.update(admin_notification_params)
|
||||||
|
notice = t("admin.admin_notifications.update_success")
|
||||||
|
redirect_to [:admin, @admin_notification], notice: notice
|
||||||
|
else
|
||||||
|
render :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@admin_notification = AdminNotification.find(params[:id])
|
||||||
|
@admin_notification.destroy
|
||||||
|
|
||||||
|
notice = t("admin.admin_notifications.delete_success")
|
||||||
|
redirect_to admin_admin_notifications_path, notice: notice
|
||||||
|
end
|
||||||
|
|
||||||
|
def deliver
|
||||||
|
@admin_notification = AdminNotification.find(params[:id])
|
||||||
|
|
||||||
|
if @admin_notification.valid?
|
||||||
|
@admin_notification.deliver
|
||||||
|
flash[:notice] = t("admin.admin_notifications.send_success")
|
||||||
|
else
|
||||||
|
flash[:error] = t("admin.segment_recipient.invalid_recipients_segment")
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to [:admin, @admin_notification]
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def admin_notification_params
|
||||||
|
params.require(:admin_notification).permit(:title, :body, :link, :segment_recipient)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -79,18 +79,21 @@
|
|||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% messages_sections = %w(newsletters emails_download) %>
|
<% newsletters_notifications_sections = %w(newsletters emails_download admin_notifications) %>
|
||||||
<% messages_menu_active = messages_sections.include?(controller_name) %>
|
<% newsletters_menu_active = newsletters_notifications_sections.include?(controller_name) %>
|
||||||
<li class="section-title" <%= "class=is-active" if messages_menu_active %>>
|
<li class="section-title" <%= "class=active" if newsletters_menu_active %>>
|
||||||
<a href="#">
|
<a href="#">
|
||||||
<span class="icon-zip"></span>
|
<span class="icon-zip"></span>
|
||||||
<strong><%= t("admin.menu.emails") %></strong>
|
<strong><%= t("admin.menu.newsletters_and_notifications") %></strong>
|
||||||
</a>
|
</a>
|
||||||
<ul <%= "class=is-active" if messages_menu_active %>>
|
<ul id="newsletters_and_notifications_menu" <%= "class=is-active" if newsletters_menu_active %>>
|
||||||
<li <%= "class=is-active" if controller_name == "newsletters" %>>
|
<li <%= "class=active" if controller_name == "newsletters" %>>
|
||||||
<%= link_to t("admin.menu.newsletters"), admin_newsletters_path %>
|
<%= link_to t("admin.menu.newsletters"), admin_newsletters_path %>
|
||||||
</li>
|
</li>
|
||||||
<li <%= "class=is-active" if controller_name == "emails_download" %>>
|
<li <%= "class=active" if controller_name == "admin_notifications" %>>
|
||||||
|
<%= link_to t("admin.menu.admin_notifications"), admin_admin_notifications_path %>
|
||||||
|
</li>
|
||||||
|
<li <%= "class=active" if controller_name == "emails_download" %>>
|
||||||
<%= link_to t("admin.menu.emails_download"), admin_emails_download_index_path %>
|
<%= link_to t("admin.menu.emails_download"), admin_emails_download_index_path %>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -231,7 +234,6 @@
|
|||||||
<li <%= "class=is-active" if controller_name == "content_blocks" %>>
|
<li <%= "class=is-active" if controller_name == "content_blocks" %>>
|
||||||
<%= link_to t("admin.menu.site_customization.content_blocks"), admin_site_customization_content_blocks_path%>
|
<%= link_to t("admin.menu.site_customization.content_blocks"), admin_site_customization_content_blocks_path%>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
13
app/views/admin/admin_notifications/_form.html.erb
Normal file
13
app/views/admin/admin_notifications/_form.html.erb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<%= form_for [:admin, @admin_notification] do |f| %>
|
||||||
|
<%= render 'shared/errors', resource: @admin_notification %>
|
||||||
|
|
||||||
|
<%= f.select :segment_recipient, options_for_select(user_segments_options,
|
||||||
|
@admin_notification[:segment_recipient]) %>
|
||||||
|
<%= f.text_field :title %>
|
||||||
|
<%= f.text_field :link %>
|
||||||
|
<%= f.text_area :body %>
|
||||||
|
|
||||||
|
<div class="margin-top">
|
||||||
|
<%= f.submit class: "button success" %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
4
app/views/admin/admin_notifications/edit.html.erb
Normal file
4
app/views/admin/admin_notifications/edit.html.erb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<%= back_link_to %>
|
||||||
|
<h2><%= t("admin.admin_notifications.edit.section_title") %></h2>
|
||||||
|
|
||||||
|
<%= render "form" %>
|
||||||
56
app/views/admin/admin_notifications/index.html.erb
Normal file
56
app/views/admin/admin_notifications/index.html.erb
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<h2 class="inline-block"><%= t("admin.admin_notifications.index.section_title") %></h2>
|
||||||
|
<%= link_to t("admin.admin_notifications.index.new_notification"), new_admin_admin_notification_path,
|
||||||
|
class: "button float-right" %>
|
||||||
|
|
||||||
|
<% if @admin_notifications.any? %>
|
||||||
|
<table id="admin_notifications">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.admin_notifications.index.title") %></th>
|
||||||
|
<th><%= t("admin.admin_notifications.index.segment_recipient") %></th>
|
||||||
|
<th><%= t("admin.admin_notifications.index.sent") %></th>
|
||||||
|
<th class="small-5 text-right"><%= t("admin.admin_notifications.index.actions") %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @admin_notifications.order(created_at: :desc).each do |admin_notification| %>
|
||||||
|
<tr id="<%= dom_id(admin_notification) %>" class="admin_notification">
|
||||||
|
<td>
|
||||||
|
<%= admin_notification.title %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= segment_name(admin_notification.segment_recipient) %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<% if admin_notification.draft? %>
|
||||||
|
<%= t("admin.admin_notifications.index.draft") %>
|
||||||
|
<% else %>
|
||||||
|
<%= l admin_notification.sent_at.to_date %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td class="text-right">
|
||||||
|
<% if admin_notification.draft? %>
|
||||||
|
<%= link_to t("admin.admin_notifications.index.edit"),
|
||||||
|
edit_admin_admin_notification_path(admin_notification),
|
||||||
|
method: :get, class: "button hollow" %>
|
||||||
|
<%= link_to t("admin.admin_notifications.index.delete"),
|
||||||
|
admin_admin_notification_path(admin_notification),
|
||||||
|
method: :delete, class: "button hollow alert" %>
|
||||||
|
<%= link_to t("admin.admin_notifications.index.preview"),
|
||||||
|
admin_admin_notification_path(admin_notification),
|
||||||
|
class: "button" %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to t("admin.admin_notifications.index.view"),
|
||||||
|
admin_admin_notification_path(admin_notification),
|
||||||
|
class: "button" %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% else %>
|
||||||
|
<div data-alert class="callout primary margin-top clear">
|
||||||
|
<%= t("admin.admin_notifications.index.empty_notifications") %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
4
app/views/admin/admin_notifications/new.html.erb
Normal file
4
app/views/admin/admin_notifications/new.html.erb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<%= back_link_to %>
|
||||||
|
<h2><%= t("admin.admin_notifications.new.section_title") %></h2>
|
||||||
|
|
||||||
|
<%= render "form" %>
|
||||||
77
app/views/admin/admin_notifications/show.html.erb
Normal file
77
app/views/admin/admin_notifications/show.html.erb
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<%= back_link_to admin_admin_notifications_path %>
|
||||||
|
|
||||||
|
<h2><%= t("admin.admin_notifications.show.section_title") %></h2>
|
||||||
|
|
||||||
|
<div class="small-12 column">
|
||||||
|
<div class="callout highlight">
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<strong><%= t("admin.admin_notifications.show.sent_at") %></strong><br>
|
||||||
|
<% if @admin_notification.draft? %>
|
||||||
|
<%= t("admin.admin_notifications.index.draft") %>
|
||||||
|
<% else %>
|
||||||
|
<%= l(@admin_notification.sent_at.to_date) %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<strong><%= t("admin.admin_notifications.show.title") %></strong><br>
|
||||||
|
<%= @admin_notification.title %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<strong><%= t("admin.admin_notifications.show.body") %></strong><br>
|
||||||
|
<%= @admin_notification.body %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<strong><%= t("admin.admin_notifications.show.link") %></strong><br>
|
||||||
|
<%= @admin_notification.link %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<strong><%= t("admin.admin_notifications.show.segment_recipient") %></strong><br>
|
||||||
|
<%= segment_name(@admin_notification.segment_recipient) %>
|
||||||
|
<% if @admin_notification.draft? %>
|
||||||
|
<%= t("admin.admin_notifications.show.will_get_notified",
|
||||||
|
n: @admin_notification.list_of_recipients_count) %>
|
||||||
|
<% else %>
|
||||||
|
<%= t("admin.admin_notifications.show.got_notified",
|
||||||
|
n: @admin_notification.recipients_count) %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="help-text" id="phase-description-help-text">
|
||||||
|
<% if @admin_notification.draft? %>
|
||||||
|
<%= t("admin.admin_notifications.show.preview_guide") %>
|
||||||
|
<% else %>
|
||||||
|
<%= t("admin.admin_notifications.show.sent_guide") %>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
<hr>
|
||||||
|
<div class="admin_notification-body-content">
|
||||||
|
<ul class="no-bullet clear notifications-list">
|
||||||
|
<li class="notification unread">
|
||||||
|
<% locals = { notification: nil,
|
||||||
|
title: @admin_notification.title,
|
||||||
|
body: @admin_notification.body,
|
||||||
|
timestamp: Time.current } %>
|
||||||
|
<% link_text = render partial: '/notifications/notification_body', locals: locals %>
|
||||||
|
<%= link_to_if @admin_notification.link.present?, link_text, @admin_notification.link %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
<% if @admin_notification.draft? && @admin_notification.valid_segment_recipient? %>
|
||||||
|
<%= link_to t("admin.admin_notifications.show.send"),
|
||||||
|
deliver_admin_admin_notification_path(@admin_notification),
|
||||||
|
"data-alert": t("admin.admin_notifications.show.send_alert",
|
||||||
|
n: @admin_notification.list_of_recipients_count),
|
||||||
|
method: :post,
|
||||||
|
id: "js-send-admin_notification-alert",
|
||||||
|
class: "button success" %>
|
||||||
|
<% end %>
|
||||||
@@ -159,6 +159,12 @@ namespace :admin do
|
|||||||
get :users, on: :collection
|
get :users, on: :collection
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :admin_notifications do
|
||||||
|
member do
|
||||||
|
post :deliver
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
resources :emails_download, only: :index do
|
resources :emails_download, only: :index do
|
||||||
get :generate_csv, on: :collection
|
get :generate_csv, on: :collection
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user