Class: MailEngine::MailTemplatesController
Constant Summary
Constants included
from MailEngine
PLACEHOLDERS_IN_LAYOUT, VERSION
Instance Method Summary
collapse
#close_modal_and_refresh
Instance Method Details
#body ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 26
def body
I18n.with_locale(@mail_template.locale) {
if @mail_template.partial?
render :partial => @mail_template.path,
:layout => false,
:content_type => Mime[@mail_template.format].to_s
else
related_partial_paths = {}
@mail_template.template_partials.each { |tmp| related_partial_paths["#{tmp.placeholder_name}_path".to_sym] = tmp.partial.path }
render :template => @mail_template.path,
:layout => "layouts/mail_engine/mail_template_layouts/#{@mail_template.layout}",
:locals => related_partial_paths
end
}
end
|
#create ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 66
def create
@mail_template = MailTemplate.new(params[:mail_engine_mail_template])
if @mail_template.save
redirect_to mail_template_path(@mail_template), :notice => 'Mail template was successfully created.'
else
render "new"
end
end
|
#create_by_upload ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 88
def create_by_upload
@mail_template = MailTemplate.new(params[:mail_engine_mail_template])
if @mail_template.save
redirect_to mail_template_path(@mail_template), :notice => 'Mail template was successfully created.'
else
render "new_by_upload"
end
end
|
#destroy ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 57
def destroy
if @mail_template.partial_in_use?
flash[:notice] = "Partial##{@mail_template.id} is in use, so can't be destroyed."
else
@mail_template.destroy
end
redirect_to mail_templates_path(:type => params[:type])
end
|
#duplicate ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 43
def duplicate
if request.put?
@duplicated_mail_template = @mail_template.duplicate(params[:mail_engine_mail_template])
if @duplicated_mail_template.errors.blank?
close_modal_and_refresh
return
end
else
@duplicated_mail_template = @mail_template
end
render :layout => "mail_engine/simple"
end
|
#edit ⇒ Object
132
133
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 132
def edit
end
|
#get_existed_subject ⇒ Object
79
80
81
82
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 79
def get_existed_subject
subject = MailTemplate.get_subject_from_bother_template(params[:path], params[:locale], params[:for_marketing] == 'true')
render :text => %Q{#{subject}}
end
|
#import ⇒ Object
135
136
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 135
def import
end
|
#import_from_files ⇒ Object
138
139
140
141
142
143
144
145
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 138
def import_from_files
MailEngine::MailTemplate.import_from_files!(params[:import][:mailer_name])
flash[:notice] = "Import successfully!"
rescue => e
flash[:notice] = "Import failed due to: #{e.to_s}"
ensure
render :import
end
|
#index ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 4
def index
@mail_templates = case params[:type]
when "marketing"
MailEngine::MailTemplate.for_marketing
when "system"
MailEngine::MailTemplate.for_system
when "partial"
MailEngine::MailTemplate.partial
else
redirect_to mail_templates_path(:type => "system")
return
end
@mail_templates = @mail_templates.group("path").page(params[:page]).per(20)
end
|
#new ⇒ Object
75
76
77
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 75
def new
@mail_template = MailTemplate.new :layout => 'none', :partial => params[:type] == 'partial'
end
|
#new_by_upload ⇒ Object
84
85
86
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 84
def new_by_upload
@mail_template = MailTemplate.new :layout => 'none', :format => 'html'
end
|
#partial_options ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 97
def partial_options
@tmp_mail_template = MailTemplate.new
if @mail_template and @mail_template.persisted?
@tmp_mail_template.layout = @mail_template.try(:layout)
@tmp_mail_template.template_partials = @mail_template.try(:template_partials)
end
if params[:layout] != @tmp_mail_template.layout || @tmp_mail_template.template_partials.blank?
@tmp_mail_template.template_partials.delete_if {|tmp| tmp.persisted?}
case params[:layout]
when 'none'
when 'only_footer'
@tmp_mail_template.template_partials.build :placeholder_name => 'footer'
when 'header_and_footer'
@tmp_mail_template.template_partials.build :placeholder_name => 'header'
@tmp_mail_template.template_partials.build :placeholder_name => 'footer'
else
end
end
render :layout => false
end
|
#preview ⇒ Object
20
21
22
23
24
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 20
def preview
@mail_template = MailEngine::MailTemplate.new if @mail_template.blank?
@mail_template.body = params[:new_body] if params[:new_body]
render :layout => false
end
|
#show ⇒ Object
129
130
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 129
def show
end
|
#update ⇒ Object
121
122
123
124
125
126
127
|
# File 'app/controllers/mail_engine/mail_templates_controller.rb', line 121
def update
if @mail_template.update_attributes(params[:mail_engine_mail_template])
redirect_to mail_template_path(@mail_template), :notice => 'Mail template was successfully updated.'
else
render "edit"
end
end
|