@@ -46,6 +46,7 @@ module Budgets
|
||||
@investment.author = current_user
|
||||
|
||||
if @investment.save
|
||||
Mailer.budget_investment_created(@investment).deliver_later
|
||||
redirect_to budget_investment_path(@budget, @investment),
|
||||
notice: t('flash.actions.create.budget_investment')
|
||||
else
|
||||
|
||||
@@ -21,6 +21,11 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
|
||||
|
||||
def valuate
|
||||
if valid_price_params? && @investment.update(valuation_params)
|
||||
|
||||
if @investment.unfeasible_email_pending?
|
||||
@investment.send_unfeasible_email
|
||||
end
|
||||
|
||||
redirect_to valuation_budget_budget_investment_path(@budget, @investment), notice: t('valuation.budget_investments.notice.valuate')
|
||||
else
|
||||
render action: :edit
|
||||
|
||||
@@ -74,6 +74,23 @@ class Mailer < ApplicationMailer
|
||||
end
|
||||
end
|
||||
|
||||
def budget_investment_created(investment)
|
||||
@investment = investment
|
||||
|
||||
with_user(@investment.author) do
|
||||
mail(to: @investment.author.email, subject: t('mailers.budget_investment_created.subject'))
|
||||
end
|
||||
end
|
||||
|
||||
def budget_investment_unfeasible(investment)
|
||||
@investment = investment
|
||||
@author = investment.author
|
||||
|
||||
with_user(@author) do
|
||||
mail(to: @author.email, subject: t('mailers.budget_investment_unfeasible.subject', code: @investment.code))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def with_user(user, &block)
|
||||
|
||||
@@ -136,12 +136,21 @@ class Budget
|
||||
unfeasible? && valuation_finished?
|
||||
end
|
||||
|
||||
def unfeasible_email_pending?
|
||||
unfeasible_email_sent_at.blank? && unfeasible? && valuation_finished?
|
||||
end
|
||||
|
||||
def total_votes
|
||||
cached_votes_up + physical_votes
|
||||
end
|
||||
|
||||
def code
|
||||
"B#{budget.id}I#{id}"
|
||||
"#{created_at.strftime('%Y')}-#{id}" + (administrator.present? ? "-A#{administrator.id}" : "")
|
||||
end
|
||||
|
||||
def send_unfeasible_email
|
||||
Mailer.budget_investment_unfeasible(self).deliver_later
|
||||
update(unfeasible_email_sent_at: Time.current)
|
||||
end
|
||||
|
||||
def reason_for_not_being_selectable_by(user)
|
||||
|
||||
@@ -95,7 +95,8 @@
|
||||
<div class="social-share-full">
|
||||
<%= social_share_button_tag("#{investment.title} #{setting['twitter_hashtag']}") %>
|
||||
<% if browser.device.mobile? %>
|
||||
<a href="whatsapp://send?text=<%= investment.title %> <%= budget_investment_url(budget_id: investment.budget_id, id: investment.id) %>" data-action="share/whatsapp/share">
|
||||
<a href="whatsapp://send?text=<%= investment.title %> <%= budget_investment_url(budget_id: investment.budget_id, id: investment.id) %>"
|
||||
data-action="share/whatsapp/share">
|
||||
<span class="icon-whatsapp whatsapp"></span>
|
||||
</a>
|
||||
<% end %>
|
||||
@@ -104,11 +105,23 @@
|
||||
<% else %>
|
||||
<div class="small-12 medium-3 column">
|
||||
<div class="float-right">
|
||||
<span class="label-budget-investment float-left"><%= t("budgets.investments.show.title") %></span>
|
||||
<span class="label-budget-investment float-left">
|
||||
<%= t("budgets.investments.show.title") %>
|
||||
</span>
|
||||
<span class="icon-budget"></span>
|
||||
</div>
|
||||
<br>
|
||||
<% end %>
|
||||
<div id="social-share" class="sidebar-divider"></div>
|
||||
<h2><%= t("budgets.investments.show.share") %></h2>
|
||||
<div class="social-share-full">
|
||||
<%= social_share_button_tag("#{investment.title} #{setting['twitter_hashtag']}") %>
|
||||
<% if browser.device.mobile? %>
|
||||
<a href="whatsapp://send?text=<%= investment.title %> <%= budget_investment_url(budget_id: investment.budget_id, id: investment.id) %>" data-action="share/whatsapp/share">
|
||||
<span class="icon-whatsapp whatsapp"></span>
|
||||
</a>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</aside>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
42
app/views/mailer/budget_investment_created.html.erb
Normal file
42
app/views/mailer/budget_investment_created.html.erb
Normal file
@@ -0,0 +1,42 @@
|
||||
<td style="padding-bottom: 20px; padding-left: 10px;">
|
||||
|
||||
<h1 style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;">
|
||||
<%= t("mailers.budget_investment_created.title") %>
|
||||
</h1>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.budget_investment_created.intro_html",
|
||||
author: @investment.author.name).html_safe %>
|
||||
</p>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.budget_investment_created.text_html",
|
||||
investment: @investment.title,
|
||||
budget: @investment.budget.name).html_safe %>
|
||||
</p>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.budget_investment_created.follow_html",
|
||||
link: link_to(t("mailers.budget_investment_created.follow_link"), budgets_url)).html_safe %>
|
||||
</p>
|
||||
|
||||
<table style="width: 100%;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="padding-bottom: 12px; text-align: center;">
|
||||
<%= link_to budget_investment_url(@investment.budget, @investment, anchor: "social-share"), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block;" do %>
|
||||
<%= image_tag('icon_mailer_share.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px", alt: "") %>
|
||||
<%= t('mailers.budget_investment_created.share') %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.budget_investment_created.sincerely") %>
|
||||
<br>
|
||||
<span style="color: #ccc; font-size: 12px;">
|
||||
<%= t("mailers.budget_investment_created.signatory") %>
|
||||
</span>
|
||||
</p>
|
||||
35
app/views/mailer/budget_investment_unfeasible.html.erb
Normal file
35
app/views/mailer/budget_investment_unfeasible.html.erb
Normal file
@@ -0,0 +1,35 @@
|
||||
<td style="padding-bottom: 20px; padding-left: 10px;">
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.budget_investment_unfeasible.hi") %>
|
||||
</p>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.budget_investment_unfeasible.unfeasible_html",
|
||||
title: @investment.title) %>
|
||||
</p>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px; padding-left: 12px; border-left: 2px solid #ccc;">
|
||||
<%= @investment.unfeasibility_explanation %>
|
||||
</p>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.budget_investment_unfeasible.new_html",
|
||||
url: link_to(t("mailers.budget_investment_unfeasible.new_href"),
|
||||
new_budget_investment_url(@investment.budget), style: "color: #2895F1; text-decoration: underline;")) %>
|
||||
</p>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.budget_investment_unfeasible.reconsider_html", code: @investment.code) %>
|
||||
</p>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.budget_investment_unfeasible.sorry") %>
|
||||
</p>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.budget_investment_unfeasible.sincerely") %><br>
|
||||
<span style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 12px;font-weight: normal;line-height: 24px; color: #ccc;">
|
||||
<%= t("mailers.budget_investment_unfeasible.signatory") %></span>
|
||||
</p>
|
||||
</td>
|
||||
Reference in New Issue
Block a user