refinerycms-multiform-email-action 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ class Admin::EmailActionsController < Admin::BaseController
2
+ def destroy
3
+ @multiform_email_action = MultiformEmailAction.find(params[:id])
4
+ @multiform = @multiform_email_action.multiform
5
+ @multiform_email_action.destroy
6
+ redirect_to admin_multiform_path(@multiform)
7
+ end
8
+
9
+ def new
10
+ @email_action = MultiformEmailAction.new
11
+ end
12
+
13
+ def edit
14
+ @email_action = MultiformEmailAction.find(params[:id])
15
+ end
16
+
17
+ def create
18
+ @multiform = Multiform.find(params[:multiform_id])
19
+ @email_action = MultiformEmailAction.new(params[:multiform_email_action])
20
+ @email_action.multiform = @multiform
21
+ if @email_action.save
22
+ flash[:notice] = "Email Action created."
23
+ render :text => "<script type='text/javascript'>parent.window.location = '#{admin_multiform_url(@multiform)}';</script>"
24
+ else
25
+ render :action => 'new'
26
+ end
27
+ end
28
+
29
+ def update
30
+ @email_action = MultiformEmailAction.find(params[:id])
31
+ if @email_action.update_attributes(params[:multiform_email_action])
32
+ flash[:notice] = "Updated email action."
33
+ render :text => "<script type='text/javascript'>parent.window.location = '#{admin_multiform_url(@email_action.multiform)}';</script>"
34
+ else
35
+ render :action => 'edit'
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,11 @@
1
+ class EmailActionPostOffice < ActionMailer::Base
2
+ # default :from => "system@example.com"
3
+
4
+ def email_action(email_action,submission)
5
+ mail(:to => email_action.recipients,
6
+ :subject => email_action.subject) do |format|
7
+ format.text { render :text => submission.apply_template }
8
+ format.html { render :text => submission.apply_template(true) }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ class MultiformEmailAction < ActiveRecord::Base
2
+ belongs_to :multiform
3
+ validates_presence_of :subject
4
+ validates_presence_of :recipients
5
+
6
+ def self.on_submission(submission)
7
+ self.all(:conditions => {:multiform_id => submission.multiform_id}).each do |email_action|
8
+ EmailActionPostOffice.email_action(email_action,submission).deliver
9
+ end
10
+ end
11
+
12
+ def self.render_add_new_action_link(binding)
13
+ template = ERB.new(NEW_ACTION_LINK)
14
+ return template.result(binding)
15
+ end
16
+
17
+ def self.render_action_rows(binding)
18
+ begin
19
+ template = ERB.new(ACTION_ROWS)
20
+ return template.result(binding)
21
+ rescue Exception => e
22
+ return "<li><pre><code>#{e.message}\n#{e.backtrace.inspect}</pre></code></li>"
23
+ end
24
+ end
25
+
26
+ ACTION_ROWS = <<-EOS
27
+ <% MultiformEmailAction.all(:conditions => {:multiform_id => @multiform.id}).each do |a| %>
28
+ <li class='clearfix record <%= cycle("on","on-hover") %>' id="<%= dom_id(a) %>">
29
+ <span class='title'>
30
+ Send email to <%= a.recipients %>
31
+ </span>
32
+ <span class='actions'>
33
+ <%= link_to refinery_icon_tag("application_edit.png"),
34
+ edit_admin_multiform_email_action_path(@multiform,a,
35
+ :dialog => true,
36
+ :height => 400,
37
+ :width => 600
38
+ ), :title => t('.edit') %>
39
+ <%= link_to refinery_icon_tag("delete.png"), admin_email_action_path(a),
40
+ :class => "cancel confirm-delete",
41
+ :title => t('.delete'),
42
+ :'data-confirm' => t('shared.admin.delete.message',
43
+ :title => a.subject
44
+ ),
45
+ :'data-method' => :delete %>
46
+ </span>
47
+ </li>
48
+ <% end %>
49
+ EOS
50
+
51
+ NEW_ACTION_LINK = <<-EOS
52
+ <%= link_to t('.create_new_email_action'),
53
+ new_admin_multiform_email_action_url(@multiform,
54
+ :dialog => true,
55
+ :width => 600,
56
+ :height => 400
57
+ ), :class => "add_icon" %>
58
+ EOS
59
+
60
+
61
+ end
@@ -0,0 +1,26 @@
1
+ <% form_for [:admin,@email_action],
2
+ :style => 'float:left;width:70%;' do |f| -%>
3
+ <%= render :partial => "/shared/admin/error_messages",
4
+ :locals => {
5
+ :object => @email_action,
6
+ :include_object_name => true } %>
7
+ <%= f.hidden_field :multiform_id %>
8
+ <div class='field'>
9
+ <label>Subject:</label>
10
+ <%= f.text_field :subject %>
11
+ </div>
12
+ <div class='field'>
13
+ <label>Recipients:</label>
14
+ <%= f.text_field :recipients %>
15
+ </div>
16
+ <div>
17
+ <%= render :partial => "/shared/admin/form_actions",
18
+ :locals => {
19
+ :f => f,
20
+ :continue_editing => false,
21
+ :delete_title => t('.delete'),
22
+ :delete_confirmation => t('shared.admin.delete.message', :title => @email_action.subject)
23
+ } %>
24
+ </div>
25
+ <% end -%>
26
+
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,14 @@
1
+ if RAILS_ENV == "development"
2
+ # run this before every request since MultiformSubmission is unloaded
3
+ Rails.configuration.to_prepare do
4
+ MultiformSubmission.register_plugin(MultiformEmailAction)
5
+ Multiform.class_eval <<-EOS
6
+ has_many :multiform_email_actions
7
+ EOS
8
+ end
9
+ else
10
+ MultiformSubmission.register_plugin(MultiformEmailAction)
11
+ Multiform.class_eval <<-EOS
12
+ has_many :multiform_email_actions
13
+ EOS
14
+ end
data/lib/engine.rb ADDED
@@ -0,0 +1,7 @@
1
+ module MultiformEmailActions
2
+ class Engine < Rails::Engine
3
+ initializer "static assets" do |app|
4
+ app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require 'engine'
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-multiform-email-action
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Jonathan Baughn
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-02 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: jonathan@uitek.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/refinerycms_multiform_email_action.rb
31
+ - lib/engine.rb
32
+ - app/models/multiform_email_action.rb
33
+ - app/mailers/email_action_post_office.rb
34
+ - app/views/admin/email_actions/_form.html.erb
35
+ - app/views/admin/email_actions/new.html.erb
36
+ - app/views/admin/email_actions/edit.html.erb
37
+ - app/controllers/admin/email_actions_controller.rb
38
+ - config/initializers/register_action.rb
39
+ has_rdoc: true
40
+ homepage: http://uitek.com
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --main
46
+ - readme.md
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Provides a simple email action to refinerycms-multiform
72
+ test_files: []
73
+