tmpsets/set/mod007-05_standard/abstract/attachment.rb in card-1.16.9 vs tmpsets/set/mod007-05_standard/abstract/attachment.rb in card-1.16.10

- old
+ new

@@ -1,7 +1,8 @@ # -*- encoding : utf-8 -*- -class Card; module Set; module Abstract; module Attachment; extend Card::Set # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/05_standard/set/abstract/attachment.rb ~~~~~~~~~~~ +class Card; module Set; module Abstract; module Attachment; extend Card::Set +# ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/05_standard/set/abstract/attachment.rb ~~~~~~~~~~~ require 'carrier_wave/cardmount' def self.included host_class host_class.extend CarrierWave::CardMount end @@ -24,19 +25,20 @@ } abort :success end event :assign_attachment_on_create, after: :prepare, on: :create, when: proc { |c| c.save_preliminary_upload? } do - if (action = Card::Action.fetch(Card::Env.params[:cached_upload])) + if (action = Card::Action.fetch(@cached_upload)) upload_cache_card.selected_action_id = action.id upload_cache_card.select_file_revision assign_attachment upload_cache_card.attachment.file, action.comment end end -event :assign_attachment_on_update, after: :prepare, on: :update, when: proc { |c| c.save_preliminary_upload? } do - if (action = Card::Action.fetch(Card::Env.params[:cached_upload])) +event :assign_attachment_on_update, after: :prepare, on: :update, + when: proc { |c| c.save_preliminary_upload? } do + if (action = Card::Action.fetch(@cached_upload)) uploaded_file = with_selected_action_id(action.id) do attachment.file end assign_attachment uploaded_file, action.comment @@ -53,27 +55,27 @@ # we need a card id for the path so we have to update db_content when we got an id event :correct_identifier, after: :store, on: :create do update_column(:db_content,attachment.db_content(mod: load_from_mod)) expire end - event :save_original_filename, after: :validate_name, when: proc {|c| !c.preliminary_upload? && !c.save_preliminary_upload? && c.attachment_changed?} do + if @current_action @current_action.update_attributes! comment: original_filename end end event :delete_cached_upload_file_on_create, after: :extend, on: :create, when: proc { |c| c.save_preliminary_upload? } do - if (action = Card::Action.fetch(Card::Env.params[:cached_upload])) + if (action = Card::Action.fetch(@cached_upload)) upload_cache_card.delete_files_for_action action action.delete end clear_upload_cache_dir_for_new_cards end event :delete_cached_upload_file_on_update, after: :extend, on: :update, when: proc { |c| c.save_preliminary_upload? } do - if (action = Card::Action.fetch(Card::Env.params[:cached_upload])) + if (action = Card::Action.fetch(@cached_upload)) delete_files_for_action action action.delete end end @@ -89,16 +91,20 @@ def original_filename attachment.original_filename end +def unfilled? + !attachment.present? && !save_preliminary_upload? && super +end + def preliminary_upload? Card::Env && Card::Env.params[:attachment_upload] end def save_preliminary_upload? - Card::Env.params[:cached_upload].present? + @cached_upload.present? end def attachment_changed? send "#{attachment_name}_changed?" end @@ -110,11 +116,19 @@ # used for uploads for new cards until the new card is created def upload_cache_card @upload_cache_card ||= Card["new_#{attachment_name}".to_sym ] end +# action id of the cached upload +def cached_upload= value + @cached_upload = value +end +def cached_upload + @cached_upload +end + def load_from_mod= value @mod = value write_identifier if value @store_in_mod = true @@ -163,10 +177,9 @@ if Dir.exist? dir return dir end end end - def mod_file? if @store_in_mod return @mod # when db_content was changed assume that it's no longer a mod file