diff --git a/app/controllers/admin/property_hires_controller.rb b/app/controllers/admin/property_hires_controller.rb
index e0ce112..42e013b 100644
--- a/app/controllers/admin/property_hires_controller.rb
+++ b/app/controllers/admin/property_hires_controller.rb
@@ -1,5 +1,5 @@
class Admin::PropertyHiresController < OrbitAdminController
-
+ include Admin::PropertyHiresHelper
def index
@tags = @module_app.tags
@categories = @module_app.categories.enabled
@@ -21,12 +21,14 @@ class Admin::PropertyHiresController < OrbitAdminController
def new
@property = Property.new
+ create_set (false)
@locations = PropertyLocation.all.desc(:created_at).collect{|loc| [loc.title, loc.id.to_s]}
@locations << ["Other", "other_location"]
end
def edit
@property = Property.where(:uid => params[:id].split("-").last).first rescue nil
+ create_set (true)
@locations = PropertyLocation.all.desc(:created_at).collect{|loc| [loc.title, loc.id.to_s]}
@locations << ["Other", "other_location"]
end
@@ -39,6 +41,9 @@ class Admin::PropertyHiresController < OrbitAdminController
def destroy
property = Property.find(params[:id]) rescue nil
+ email = Array(MemberProfile.find(property.owners)).collect{|v| v.email} rescue []
+ email = User.all.select{|v| v.is_admin? && v.user_name != 'rulingcom'}.collect{|v| v.member_profile.email} if email.length == 0
+ HireMethod.send_mail('delete',email,property.id)
property.destroy if !property.nil?
if params[:page]
redirect_to admin_property_hires_path(:page => params[:page])
@@ -51,6 +56,9 @@ class Admin::PropertyHiresController < OrbitAdminController
property = Property.where(:uid => params[:id].split("-").last).first rescue nil
redirect_to admin_property_hires_path and return if property.nil?
property.update_attributes(property_params)
+ email = Array(MemberProfile.find(property.owners)).collect{|v| v.email} rescue []
+ email = User.all.select{|v| v.is_admin? && v.user_name != 'rulingcom'}.collect{|v| v.member_profile.email} if email.length == 0
+ HireMethod.send_mail('edit',email,property.id)
if params[:page]
redirect_to admin_property_hires_path(:page => params[:page])
else
@@ -59,8 +67,7 @@ class Admin::PropertyHiresController < OrbitAdminController
end
def create
- property = Property.new(property_params)
- if property.save
+ if Property.create(property_params)
redirect_to admin_property_hires_path
end
end
@@ -178,5 +185,28 @@ class Admin::PropertyHiresController < OrbitAdminController
prop.delete(:property_location) if prop[:property_location] == "other"
prop
end
-
+ def create_set (save_flag)
+ @email_set = []
+ ['p_hire','edit','delete'].each do |field_name|
+ email_set = @property.hire_email_sets.select{|v| v.field_name==field_name}
+ if email_set.length==0
+ title = Hash.new
+ content = Hash.new
+ I18n.available_locales.each do |locale|
+ I18n.with_locale(locale) do
+ title[locale] = t("property_hire.email_#{field_name}_success")
+ content[locale] = t("property_hire.email_#{field_name}_content")
+ end
+ end
+ if save_flag
+ email_set = @property.hire_email_sets.create(field_name:field_name,title:title,content:content)
+ else
+ email_set = @property.hire_email_sets.new(field_name:field_name,title:title,content:content)
+ end
+ else
+ email_set = email_set[0]
+ end
+ @email_set << email_set
+ end
+ end
end
\ No newline at end of file
diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb
index 457fe92..66562ee 100644
--- a/app/controllers/property_hires_controller.rb
+++ b/app/controllers/property_hires_controller.rb
@@ -165,6 +165,12 @@ class PropertyHiresController < ApplicationController
hire = PHire.new(booking_p)
hire.passed = true if PropertyHireSetting.auto_approve_enabled?
hire.save
+ if !property.nil?
+ email = Array(MemberProfile.find(property.owners)).collect{|v| v.email} rescue []
+ email = User.all.select{|v| v.is_admin? && v.user_name != 'rulingcom'}.collect{|v| v.member_profile.email} if email.length == 0
+ email << hire.hiring_person_email
+ HireMethod.send_mail('p_hire',email,property.id)
+ end
redirect_to params[:url]
else
session["hire-save-msg"] = data["msg"]
diff --git a/app/helpers/admin/property_hires_helper.rb b/app/helpers/admin/property_hires_helper.rb
index 2359a51..56aac5a 100644
--- a/app/helpers/admin/property_hires_helper.rb
+++ b/app/helpers/admin/property_hires_helper.rb
@@ -19,5 +19,78 @@ module Admin::PropertyHiresHelper
end
return data
end
-
+ module HireMethod
+ extend ActionView::Helpers::UrlHelper
+ extend ActionView::Helpers::TagHelper
+ extend ActionView::Context
+ extend ActionView::Helpers::FormTagHelper
+ def self.set_input_name(input_name)
+ @input_name = input_name
+ end
+ def self.get_input_name
+ @input_name
+ end
+ def self.create_lang_panel(field)
+ tmp2 = content_tag(:div,:class => 'btn-group', :data=>{:toggle=>"buttons-radio"}) do
+ I18n.available_locales.collect do |key|
+ link_entry_ary = ["##{field}","_#{key}"]
+ link_entry = link_entry_ary.join
+ link_to(I18n.t(key),link_entry,:data=>{:toggle=>"tab"},:class=>"btn #{(key == I18n.locale ? "active" : nil)}",:for=>key)
+ end.join.html_safe
+ end
+ end
+ def self.multiple_lang_tag(index1,type_of_tag,field,value=nil,custom_options={},combine_element='',exteral_options={},panel_in_first=false)
+ content_tag(:div,{:class => "tab-panel"}.merge(exteral_options)) do
+ all_field = (get_input_name + "[#{index1}][#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
+ tmp = I18n.available_locales.collect do |locale|
+ active_flag = ((locale == I18n.locale) ? ' active' : '')
+ content_tag(:div,:class => "tab-content#{active_flag}",:id=>"#{all_field}_#{locale}") do
+ value_locale = ((value[locale] || value[locale.to_s]) rescue nil)
+ self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{index1}][#{field}][#{locale}]",value_locale,custom_options)
+ end
+ end.join
+ if panel_in_first
+ tmp = create_lang_panel(all_field).html_safe + tmp.html_safe + combine_element
+ else
+ tmp = tmp.html_safe + create_lang_panel(all_field).html_safe + combine_element
+ end
+ tmp
+ end
+ end
+ def self.show_set_field(id,field_sets,key_field,key_index,field,markup='text_field',with_id=true)
+ end_block = with_id ? hidden_field_tag("property[#{key_field}][#{key_index}]"+"[id]",id) : ''
+ custom_options = markup == 'text_area' ? {:class => 'ckeditor'} : {}
+ a = multiple_lang_tag(key_field,markup,"#{key_index}][#{field}",field_sets,custom_options,end_block,{},markup=='text_area')
+ a.html_safe
+ end
+ def self.send_mail(field_name,email,property_id,send_date=nil)
+ property = Property.where(id: property_id).first
+ if !property.nil?
+ email_set = property.hire_email_sets.select{|v| v.field_name == field_name}
+ title = property['title'].collect{|k,v| v}.select{|v| !v.to_s.empty?}.join('/')
+ note = property['note'].collect{|k,v| v}.select{|v| !v.to_s.empty?}.join('/')
+ content = "title:#{title}
note:#{note}"
+ if email_set.length==0
+ mail = Email.create(mail_to: Array(email),
+ module_app_key:"property_hire",
+ template:"email/#{field_name}_email.html.erb",
+ mail_sentdate: send_date || Time.current,
+ mail_subject: t("seminar.email_#{field_name}_success"),
+ template_data:{'property_id'=>property_id,'content'=>content,'locale'=>I18n.locale.to_s})
+ elsif !(email_set[0].disabled)
+ mail = Email.create(mail_to: Array(email),
+ module_app_key:"property_hire",
+ template:"email/#{field_name}_email.html.erb",
+ mail_sentdate: send_date || Time.current,
+ mail_subject: email_set[0].title[I18n.locale],
+ template_data:{'property_id'=>property_id,'email_set_content'=>email_set[0].content.to_yaml,'content'=>content,'locale'=>I18n.locale.to_s})
+ end
+ begin
+ mail.deliver
+ rescue => e
+ puts ["email can't deliver",e]
+ end
+ end
+ end
+ end
end
\ No newline at end of file
diff --git a/app/models/hire_email_set.rb b/app/models/hire_email_set.rb
new file mode 100644
index 0000000..7f3417e
--- /dev/null
+++ b/app/models/hire_email_set.rb
@@ -0,0 +1,10 @@
+class HireEmailSet
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :field_name, type: String
+ field :title
+ field :content
+ field :disabled, type: Boolean, default: false
+ belongs_to :property
+end
diff --git a/app/models/property.rb b/app/models/property.rb
index dca9ecb..6353bba 100644
--- a/app/models/property.rb
+++ b/app/models/property.rb
@@ -33,7 +33,8 @@ class Property
belongs_to :property_location
has_many :p_hires
-
+ has_many :hire_email_sets, :autosave => true, :dependent => :destroy, :inverse_of => :property
+ accepts_nested_attributes_for :hire_email_sets, :allow_destroy => true
WEEKDAYS = [
"Sunday",
"Monday",
diff --git a/app/models/property_hire_setting.rb b/app/models/property_hire_setting.rb
index ae81271..c38ba06 100644
--- a/app/models/property_hire_setting.rb
+++ b/app/models/property_hire_setting.rb
@@ -5,6 +5,6 @@ class PropertyHireSetting
field :auto_approve, type: Boolean, :default => false
def self.auto_approve_enabled?
- self.first.auto_approve
+ self.first.auto_approve rescue false
end
end
\ No newline at end of file
diff --git a/app/views/admin/property_hires/_form.html.erb b/app/views/admin/property_hires/_form.html.erb
index 364bfe4..b70bcbf 100644
--- a/app/views/admin/property_hires/_form.html.erb
+++ b/app/views/admin/property_hires/_form.html.erb
@@ -1,3 +1,19 @@
+<%
+ hire_method = Admin::PropertyHiresHelper::HireMethod
+ hire_method.set_input_name('property')
+%>
+
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
@@ -20,7 +36,8 @@
+ <%= t('disable') %> + | ++ + <%= check_box_tag("property[hire_email_sets][#{index1}][disabled]", true ,@email_set[index1].disabled) %> + | +
+ <%= t('property_hire.email_title') %> + | ++ <%= hire_method.show_set_field(@email_set[index1].id,@email_set[index1]['title'],'hire_email_sets',index1,'title','text_field',action_name != 'new') %> + | +
+ <%= t('property_hire.email_content') %> + | +
+
+ <%= hire_method.show_set_field(@email_set[index1].id,@email_set[index1]['content'],'hire_email_sets',index1,'content','text_area',action_name != 'new') %>
+
+ <%= hidden_field_tag("property[hire_email_sets][#{index1}][field_name]",@email_set[index1]['field_name']) %>
+ <%= hidden_field_tag("property[hire_email_sets][#{index1}][property_id]",@property.id) %>
+ |
+