Added initial mail template editor #2369

This commit is contained in:
Priit Tark 2015-08-25 21:11:36 +03:00
parent 5ba39fb406
commit 032cff3cf3
16 changed files with 298 additions and 1 deletions

View file

@ -0,0 +1,61 @@
class Admin::MailTemplatesController < AdminController
load_and_authorize_resource
def index
@q = MailTemplate.search(params[:q])
@mail_templates = @q.result.page(params[:page])
end
def new
@mail_tempalte = MailTemplate.new
end
def show
@mail_template = MailTemplate.find(params[:id])
@subject = Liquid::Template.parse(@mail_template.subject).render.html_safe
@html_body = Liquid::Template.parse(@mail_template.body).render.html_safe
@text_body = Liquid::Template.parse(@mail_template.text_body).render.html_safe
end
def edit
@mail_template = MailTemplate.find(params[:id])
end
def create
@mail_template = MailTemplate.new(mail_template_params)
if @mail_template.save
redirect_to [:admin, @mail_template]
else
flash.now[:alert] = I18n.t(:failure)
render 'new'
end
end
def update
@mail_template = MailTemplate.find(params[:id])
if @mail_template.update_attributes(mail_template_params)
redirect_to [:admin, @mail_template]
else
flash.now[:alert] = I18n.t(:failure)
render 'edit'
end
end
def destroy
@mail_template = MailTemplate.find(params[:id])
if @mail_template.destroy
redirect_to admin_mail_templates_path, notise: t(:deleted)
else
flash.now[:alert] = I18n.t(:failure)
render 'show'
end
end
private
def mail_template_params
params.require(:mail_template).permit(:name, :subject, :from, :bcc, :cc, :body, :text_body)
end
end

View file

@ -96,6 +96,7 @@ class Ability
can :manage, LegalDocument
can :manage, BankStatement
can :manage, BankTransaction
can :manage, MailTemplate
can :manage, Invoice
can :manage, WhiteIp
can :read, ApiLog::EppLog

View file

@ -0,0 +1,10 @@
class MailTemplate < ActiveRecord::Base
validates :name, :subject, :from, :body, :text_body, presence: true
def to_html(body)
template = Erubis::Eruby.new(content, escape: true)
template_result = template.result(context)
Sanitize.clean(RDiscount.new(template_result).to_html.encode('UTF-8', undef: :replace), Sanitize::Config::RELAXED)
end
end

View file

@ -0,0 +1,54 @@
= form_for([:admin, mail_template], html: {class: 'form-horizontal'}) do |f|
= render 'shared/full_errors', object: mail_template
- liquid_help = link_to 'Liquid info', 'https://github.com/Shopify/liquid/wiki/Liquid-for-Designers'
.row
.col-md-12
.panel.panel-default
.panel-body
.form-group
.col-md-4.control-label
= f.label :name
.col-md-7
= f.text_field(:name, class: 'form-control')
.form-group
.col-md-4.control-label
= f.label :subject
%br
= liquid_help
.col-md-7
= f.text_field(:subject, class: 'form-control')
.form-group
.col-md-4.control-label
= f.label :from
.col-md-7
= f.text_field(:from, class: 'form-control', lax_email: true)
.form-group
.col-md-4.control-label
= f.label :cc
.col-md-7
= f.text_field(:cc, class: 'form-control', lax_email: true)
.form-group
.col-md-4.control-label
= f.label :bcc
.col-md-7
= f.text_field(:bcc, class: 'form-control', lax_email: true)
.form-group
.col-md-12
= f.label :body, t(:html_body)
= liquid_help
.col-md-12
= f.text_area(:body, class: 'form-control', size: '15x15')
.form-group
.col-md-12
= f.label :text_body
= liquid_help
.col-md-12
= f.text_area(:text_body, class: 'form-control', size: '15x15')
%hr
.row
.col-md-12.text-right
= button_tag(t(:save), class: 'btn btn-primary')

View file

@ -0,0 +1,3 @@
= render 'shared/title', name: "#{t(:edit)}: #{@mail_template.name}"
= render 'form', mail_template: @mail_template

View file

@ -0,0 +1,26 @@
- content_for :actions do
= link_to(t(:new), new_admin_mail_template_path, class: 'btn btn-primary')
= render 'shared/title', name: t(:mail_templates)
.row
.col-md-12
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-3'}= sort_link(@q, 'name', t(:name))
%th{class: 'col-xs-3'}= sort_link(@q, 'subject')
%th{class: 'col-xs-3'}= sort_link(@q, 'updated_at')
%th{class: 'col-xs-3'}= t(:actions)
%tbody
- @mail_templates.each do |mt|
%tr
%td= link_to(truncate(mt.name), admin_mail_template_path(mt))
%td= truncate(mt.subject)
%td= l(mt.updated_at)
%td
= link_to(t(:edit), edit_admin_mail_template_path(mt), class: 'btn btn-primary btn-xs')
.row
.col-md-12
= paginate @mail_templates

View file

@ -0,0 +1,3 @@
= render 'shared/title', name: t(:new_mail_template)
= render 'form', mail_template: @mail_template

View file

@ -0,0 +1,41 @@
- content_for :actions do
= link_to(t(:edit), edit_admin_mail_template_path(@mail_template.id), class: 'btn btn-primary')
= link_to(t(:delete), admin_mail_template_path(@mail_template.id),
method: :delete, data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger')
= link_to(t(:email_templates), admin_mail_templates_path, class: 'btn btn-default')
= render 'shared/title', name: @mail_template.name
.row
.col-md-12
.panel.panel-default
.panel-heading
%h3.panel-title= t(:general)
.panel-body
%dl.dl-horizontal
%dt= t(:subject)
%dd= @mail_template.subject
%dt= t(:from)
%dd= @mail_template.from
- if @mail_template.cc.present?
%dt= t(:cc)
%dd= @mail_template.cc
- if @mail_template.bcc.present?
%dt= t(:bcc)
%dd= @mail_template.bcc
.col-md-12
.panel.panel-default
.panel-heading
%h3.panel-title= t(:html_body)
.panel-body
= @html_body
.col-md-12
.panel.panel-default
.panel-heading
%h3.panel-title= t(:text_body)
.panel-body
= @text_body

View file

@ -61,6 +61,7 @@
%li= link_to t(:zonefile), admin_zonefile_settings_path
%li= link_to t(:blocked_domains), admin_blocked_domains_path
%li= link_to t(:reserved_domains), admin_reserved_domains_path
%li= link_to t(:mail_templates), admin_mail_templates_path
-# %li= link_to t(:domains_history), admin_domain_versions_path
%li= link_to t(:epp_logs), admin_epp_logs_path
%li= link_to t(:repp_logs), admin_repp_logs_path