Sha256: 35949c822b1e93b188877498f3776c59ab2d1d1da1250bd665382f4c50343b26

Contents?: true

Size: 1.3 KB

Versions: 16

Compression:

Stored size: 1.3 KB

Contents

module Sufia
  module GenericFile
    module WebForm
      extend ActiveSupport::Concern
      include Sufia::GenericFile::AccessibleAttributes
      included do
        before_save :remove_blank_assertions
      end

      def remove_blank_assertions
        terms_for_editing.each do |key|
          self[key] = nil if self[key] == ['']
        end
      end

      # override this method if you need to initialize more complex RDF assertions (b-nodes)
      def initialize_fields
        terms_for_editing.each do |key|
          # if value is empty, we create an one element array to loop over for output 
          self[key] = [''] if self[key].empty?
        end
      end

      def terms_for_editing
        terms_for_display - [:date_modified, :date_uploaded, :format]
      end

      def terms_for_display
        # 'type' is the RDF.type assertion, which is not present by default, but may be
        # provided in some RDF schemas
        self.descMetadata.class.fields - [:part_of]
      end

      def to_jq_upload
        return {
          "name" => self.title,
          "size" => self.file_size,
          "url" => "/files/#{noid}",
          "thumbnail_url" => self.pid,
          "delete_url" => "deleteme", # generic_file_path(:id => id),
          "delete_type" => "DELETE"
        }
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
sufia-4.0.0.beta2 sufia-models/lib/sufia/models/generic_file/web_form.rb
sufia-models-4.0.0.beta2 lib/sufia/models/generic_file/web_form.rb
sufia-4.0.0.beta1 sufia-models/lib/sufia/models/generic_file/web_form.rb
sufia-models-4.0.0.beta1 lib/sufia/models/generic_file/web_form.rb
sufia-models-3.7.2 lib/sufia/models/generic_file/web_form.rb
sufia-3.7.2 sufia-models/lib/sufia/models/generic_file/web_form.rb
sufia-models-3.7.1 lib/sufia/models/generic_file/web_form.rb
sufia-3.7.1 sufia-models/lib/sufia/models/generic_file/web_form.rb
sufia-models-3.7.0 lib/sufia/models/generic_file/web_form.rb
sufia-3.7.0 sufia-models/lib/sufia/models/generic_file/web_form.rb
sufia-3.6.1 sufia-models/lib/sufia/models/generic_file/web_form.rb
sufia-models-3.6.1 lib/sufia/models/generic_file/web_form.rb
sufia-3.6.0 sufia-models/lib/sufia/models/generic_file/web_form.rb
sufia-models-3.6.0 lib/sufia/models/generic_file/web_form.rb
sufia-3.5.0 sufia-models/lib/sufia/models/generic_file/web_form.rb
sufia-models-3.5.0 lib/sufia/models/generic_file/web_form.rb