diff --git a/app/assets/javascripts/venue_management_file_link.js b/app/assets/javascripts/venue_management_file_link.js new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/admin/venue_management_contracts_controller.rb b/app/controllers/admin/venue_management_contracts_controller.rb index 8a57e0d..18d19f6 100644 --- a/app/controllers/admin/venue_management_contracts_controller.rb +++ b/app/controllers/admin/venue_management_contracts_controller.rb @@ -29,8 +29,6 @@ class Admin::VenueManagementContractsController < OrbitAdminController def create @venue_management_contract = VenueManagementContract.new(venue_management_contract_params) - inviting = VenueManagementInviting.find_by(id: venue_management_contract_params[:venue_management_inviting_id]) - assign_inviting_attrs(@venue_management_contract, inviting) @venue_management_contract.save redirect_to params['referer_url'] @@ -41,10 +39,7 @@ class Admin::VenueManagementContractsController < OrbitAdminController end def update - inviting = VenueManagementInviting.find_by(id: venue_management_contract_params[:venue_management_inviting_id]) - assign_inviting_attrs(@venue_management_contract, inviting) - @venue_management_contract.update_attributes(venue_management_contract_params) - + @venue_management_contract.update_attributes!(venue_management_contract_params) redirect_to venue_management_contracts_admin_venue_management_path(@venue_management_contract.venue_management_main_id) end @@ -57,12 +52,6 @@ class Admin::VenueManagementContractsController < OrbitAdminController private - def assign_inviting_attrs(contract, inviting) - %i(case_no publish_times start_date end_date close_date bid_date evaluation_date early_rent operation_rent royalty contractor_manager house_tax_payer land_tax_payer bid_result details).each do |attr| - contract[attr] = inviting.send(attr) - end - end - def set_venue_management_contract @venue_management_contract = VenueManagementContract.find(params[:id]) end diff --git a/app/controllers/admin/venue_management_memorabilias_controller.rb b/app/controllers/admin/venue_management_memorabilias_controller.rb index 36f48b3..3592cc2 100644 --- a/app/controllers/admin/venue_management_memorabilias_controller.rb +++ b/app/controllers/admin/venue_management_memorabilias_controller.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - class Admin::VenueManagementMemorabiliasController < OrbitAdminController include Admin::VenueManagementsHelper before_action ->(module_app = @app_title) { set_variables module_app } @@ -22,7 +20,7 @@ class Admin::VenueManagementMemorabiliasController < OrbitAdminController def new @venue_management = VenueManagementMain.find(params[:id]) - @venue_management_memorabilia = @venue_management.venue_management_memorabilias.build + @venue_management_memorabilia = VenueManagementMemorabilia.new(venue_management_main_id: params[:id]) end def create diff --git a/app/controllers/admin/venue_managements_controller.rb b/app/controllers/admin/venue_managements_controller.rb index 081596a..7980fe0 100644 --- a/app/controllers/admin/venue_managements_controller.rb +++ b/app/controllers/admin/venue_managements_controller.rb @@ -81,12 +81,12 @@ class Admin::VenueManagementsController < OrbitAdminController def create - if !venue_management_params['venue_management_links_attributes'].nil? - venue_management_params['venue_management_links_attributes'].each do |idx,link| - venue_management_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank? + venue_management_main_params = venue_management_params + if !venue_management_main_params['venue_management_links_attributes'].nil? + venue_management_main_params['venue_management_links_attributes'].each do |idx,link| + venue_management_main_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank? end end - venue_management_main_params = venue_management_params venue_management_signup_set_params = venue_management_main_params['venue_management_signup_field_sets'] venue_management_submission_set_params = venue_management_main_params['venue_management_submission_field_sets'] venue_management_email_sets_params = venue_management_main_params['venue_management_email_sets'] @@ -173,20 +173,21 @@ class Admin::VenueManagementsController < OrbitAdminController @venue_management.venue_management_submission_fields.each{|t| t.destroy if t["to_delete"] == true} redirect_to admin_venue_managements_path else - - if !venue_management_params['venue_management_links_attributes'].nil? - venue_management_params['venue_management_links_attributes'].each do |idx,link| - venue_management_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank? + venue_management_main_params = venue_management_params + if !venue_management_main_params['venue_management_links_attributes'].nil? + venue_management_main_params['venue_management_links_attributes'].each do |idx,link| + venue_management_main_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank? end end @venue_management.update_user_id = current_user.id - if @venue_management.update_attributes(venue_management_params) + if @venue_management.update_attributes(venue_management_main_params) @venue_management.venue_management_signup_fields.each{|t| t.destroy if t["to_delete"] == true} redirect_to params['referer_url'] else flash.now[:error] = t('update.error.category') - render action: :edit + flash.keep + redirect_to action: :edit, :id =>@venue_management.id.to_s end end diff --git a/app/models/concerns/venue_link_file.rb b/app/models/concerns/venue_link_file.rb new file mode 100644 index 0000000..e8771c3 --- /dev/null +++ b/app/models/concerns/venue_link_file.rb @@ -0,0 +1,12 @@ +module VenueLinkFile + extend ActiveSupport::Concern + included do + tmp = self.to_s.underscore.to_sym + VenueManagementFile.send(:belongs_to,tmp, :class_name => self.to_s, :foreign_key => "#{tmp}_id") + VenueManagementLink.send(:belongs_to,tmp, :class_name => self.to_s, :foreign_key => "#{tmp}_id") + self.has_many :venue_management_files, :autosave => true, :dependent => :destroy + self.accepts_nested_attributes_for :venue_management_files, :allow_destroy => true + self.has_many :venue_management_links, :autosave => true, :dependent => :destroy + self.accepts_nested_attributes_for :venue_management_links, :allow_destroy => true + end +end \ No newline at end of file diff --git a/app/models/venue_management_contract.rb b/app/models/venue_management_contract.rb index 3613f6e..af1fdac 100644 --- a/app/models/venue_management_contract.rb +++ b/app/models/venue_management_contract.rb @@ -7,10 +7,12 @@ class VenueManagementContract include Mongoid::Timestamps include Mongoid::Enum - PAYERS = [ :school, :vendor ].freeze - BID_RESULTS = [ :failure, :abandoned, :qualified ].freeze + PAYERS = [ :school, :vendor].freeze + BID_RESULTS = [ :failure, :abandoned, :qualified].freeze # Copy from Inviting + field :renewal_permission, type: Boolean,default: false + field :renewal_deadline, type: Date field :case_no, type: String field :publish_times, type: Integer field :start_date, type: Date, default: Time.now @@ -49,10 +51,31 @@ class VenueManagementContract field :other_commitment, localize: true field :note, localize: true - belongs_to :venue_management_main belongs_to :venue_management_inviting - has_many :venue_management_links, :as => :venue_object, :autosave => true, :dependent => :destroy - accepts_nested_attributes_for :venue_management_links, :allow_destroy => true - + include VenueLinkFile + before_save do + org_contract = VenueManagementContract.find(self.id) + inviting = VenueManagementInviting.find(self.venue_management_inviting_id) rescue nil + if !inviting.nil? + %i(case_no publish_times start_date end_date close_date bid_date evaluation_date contractor_manager bid_result details).each do |attr_| + self[attr_] = inviting.send(attr_) rescue nil + end + else + self[:case_no] = nil + end + update_flag = true + if org_contract.venue_management_inviting_id == self.venue_management_inviting_id + %i(early_rent operation_rent royalty house_tax_payer land_tax_payer).each do |attr_| + if self[attr_] != (inviting.send(attr_) rescue nil) + update_flag = false + end + end + end + if update_flag && !inviting.nil? + %i(early_rent operation_rent royalty house_tax_payer land_tax_payer).each do |attr_| + self[attr_] = (inviting.send(attr_) rescue nil) + end + end + end end diff --git a/app/models/venue_management_file.rb b/app/models/venue_management_file.rb index 43a0d5e..44f2a47 100644 --- a/app/models/venue_management_file.rb +++ b/app/models/venue_management_file.rb @@ -8,7 +8,6 @@ class VenueManagementFile field :description, localize: true field :title, localize: true - - belongs_to :venue_management_main - + #belongs_to :venue_management_main + #belongs_to :venue_management_contract end diff --git a/app/models/venue_management_inviting.rb b/app/models/venue_management_inviting.rb index 58336ef..0afe740 100644 --- a/app/models/venue_management_inviting.rb +++ b/app/models/venue_management_inviting.rb @@ -6,9 +6,9 @@ class VenueManagementInviting include Mongoid::Document include Mongoid::Timestamps include Mongoid::Enum - - PAYERS = [ :school, :vendor ].freeze - BID_RESULTS = [ :failure, :abandoned, :qualified ].freeze + include OrbitTag::Taggable + PAYERS = [ :school, :vendor].freeze + BID_RESULTS = [ :failure, :abandoned, :qualified].freeze field :case_no, type: String field :publish_times, type: Integer @@ -26,8 +26,14 @@ class VenueManagementInviting enum :bid_result, BID_RESULTS field :details, localize: true + has_many :venue_management_contracts + has_many :venue_management_memorabilias, :class_name => 'VenueManagementMemorabilia', :foreign_key => "venue_management_memorabilia_ids" belongs_to :venue_management_main - has_many :venue_management_links, :as => :venue_object, :autosave => true, :dependent => :destroy - accepts_nested_attributes_for :venue_management_links, :allow_destroy => true - + include VenueLinkFile + before_save do + contracts = self.venue_management_contracts + contracts.each do |contract| + contract.save + end + end end diff --git a/app/models/venue_management_link.rb b/app/models/venue_management_link.rb index 5cdca42..46da24b 100644 --- a/app/models/venue_management_link.rb +++ b/app/models/venue_management_link.rb @@ -7,12 +7,11 @@ class VenueManagementLink field :url field :title, localize: true - - belongs_to :venue_management_main before_validation :add_http - - validates :url, :presence => true, :format => /\A(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?\Z/i + #belongs_to :venue_management_main + #belongs_to :venue_management_contract + #validates :url, :presence => true, :format => /\A(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?\Z/i protected diff --git a/app/models/venue_management_main.rb b/app/models/venue_management_main.rb index 4537bbc..cb8d22b 100644 --- a/app/models/venue_management_main.rb +++ b/app/models/venue_management_main.rb @@ -1,7 +1,6 @@ class VenueManagementMain include Mongoid::Document include Mongoid::Timestamps - include OrbitModel::Impression # encoding: utf-8 include OrbitCategory::Categorizable @@ -35,11 +34,9 @@ class VenueManagementMain belongs_to :venue_management_item - has_many :venue_management_links, :autosave => true, :dependent => :destroy has_many :venue_management_invitings, :autosave => true, :dependent => :destroy has_many :venue_management_memorabilias, :autosave => true, :dependent => :destroy has_many :venue_management_contracts, :autosave => true, :dependent => :destroy - has_many :venue_management_files, :autosave => true, :dependent => :destroy has_many :venue_management_item_contents, :autosave => true, :dependent => :destroy has_many :venue_management_signups, :autosave => true, :dependent => :destroy has_many :venue_management_submission_fields, :autosave => true, :dependent => :destroy @@ -49,8 +46,7 @@ class VenueManagementMain has_many :venue_management_submission_field_sets, autosave: true, dependent: :destroy has_many :venue_management_email_sets, autosave: true, dependent: :destroy has_many :venue_management_signup_field_customs, :autosave => true, :dependent => :destroy - accepts_nested_attributes_for :venue_management_links, :allow_destroy => true - accepts_nested_attributes_for :venue_management_files, :allow_destroy => true + accepts_nested_attributes_for :venue_management_memorabilias, :allow_destroy => true accepts_nested_attributes_for :venue_management_item_contents, :allow_destroy => true accepts_nested_attributes_for :venue_management_signups, :allow_destroy => true accepts_nested_attributes_for :venue_management_submission_fields, :allow_destroy => true @@ -60,6 +56,7 @@ class VenueManagementMain accepts_nested_attributes_for :venue_management_submission_field_sets, :allow_destroy => true accepts_nested_attributes_for :venue_management_email_sets, :allow_destroy => true accepts_nested_attributes_for :venue_management_signup_field_customs, :allow_destroy => true + include VenueLinkFile def self.time_range(date1 = null, date2 = null) if !date1.blank? diff --git a/app/models/venue_management_memorabilia.rb b/app/models/venue_management_memorabilia.rb index 1066089..901adc1 100644 --- a/app/models/venue_management_memorabilia.rb +++ b/app/models/venue_management_memorabilia.rb @@ -1,18 +1,19 @@ -# frozen_string_literal: true - -require 'orbit_form_helper' - class VenueManagementMemorabilia include Mongoid::Document include Mongoid::Timestamps include Mongoid::Enum field :event_date, type: Date, default: Time.now - field :case_no, type: String field :details, localize: true - + def case_no + inviting = self.venue_management_inviting + if !inviting.nil? + inviting.case_no + else + nil + end + end + belongs_to :venue_management_inviting belongs_to :venue_management_main - has_many :venue_management_links, :as => :venue_object, :autosave => true, :dependent => :destroy - accepts_nested_attributes_for :venue_management_links, :allow_destroy => true - + include VenueLinkFile end diff --git a/app/views/admin/venue_management_contracts/_form.html.erb b/app/views/admin/venue_management_contracts/_form.html.erb index 145fc63..a5ca4d7 100644 --- a/app/views/admin/venue_management_contracts/_form.html.erb +++ b/app/views/admin/venue_management_contracts/_form.html.erb @@ -24,6 +24,48 @@ <%= f.select :venue_management_inviting_id, @venue_management.venue_management_invitings.map { |i| [ i.case_no, i.id ] }, :include_blank => true %> +
- <%= hidden_field_tag 'venue_management_link_field_count', @venue_management_contract.venue_management_links.count %> - <%= t(:add) %> -
-- <%= hidden_field_tag 'venue_management_link_field_count', @venue_management_inviting.venue_management_links.count %> - <%= t(:add) %> -
-- <%= hidden_field_tag 'venue_management_link_field_count', @venue_management_memorabilia.venue_management_links.count %> - <%= t(:add) %> -
-- <%= hidden_field_tag 'venue_management_link_field_count', @venue_management.venue_management_links.count %> - <%= t(:add) %> -
- -- <%= hidden_field_tag 'venue_management_file_field_count', @venue_management.venue_management_files.count %> - <%= t(:add) %> -
- -+ <%= hidden_field_tag 'venue_management_link_field_count', venue.venue_management_links.count %> + <%= t(:add) %> +
++ <%= hidden_field_tag 'venue_management_file_field_count', venue.venue_management_files.count %> + <%= t(:add) %> +
+ +