require 'deprecation' class Hydra::ContributorsController < ApplicationController extend Deprecation self.deprecation_horizon = 'hydra-head 5.x' include Hydra::Controller::RepositoryControllerBehavior include Hydra::AssetsControllerHelper include Hydra::SubmissionWorkflow include Hydra::AccessControlsEnforcement before_filter :load_document, :only => :update before_filter :enforce_access_controls def initialize *args Deprecation.warn(Hydra::ContributorsController, "Hydra::ContributorsController is deprecated and will be removed from #{self.class.deprecation_horizon}") super end # Display form for adding a new Contributor # If contributor_type is provided, renders the appropriate "new" form # If contributor_type is not provided, renders a form for selecting which type of contributor to add # If format is .inline, this renders without layout so you can embed it in a page def new # Only load the document if you need to if params.has_key?(:contributor_type) @document_fedora = load_document_from_id(params[:asset_id]) @next_contributor_index = @document_fedora end respond_to do |format| format.html { render :file=>"contributors/new" , :layout=>true} format.inline { render :partial=>"contributors/new", :layout=>false } end end deprecation_deprecate :new def create @document_fedora = load_document_from_id(params[:asset_id]) ct = params[:contributor_type] inserted_node, new_node_index = @document_fedora.insert_contributor(ct) @document_fedora.save partial_name = "contributors/edit_#{ct}" respond_to do |format| format.html { redirect_to edit_catalog_path(params[:asset_id], :anchor=>"#{params[:contributor_type]}_#{new_node_index}") } format.inline { render :partial=>partial_name, :formats=>[:html], :locals=>{"edit_#{ct}".to_sym =>inserted_node, "edit_#{ct}_counter".to_sym =>new_node_index}, :layout=>false } end end deprecation_deprecate :create # Not sure how the #create method was intended to work, but this seems like it works and takes a hybrid approach to how the contributors were handled between this and the AssetsController work. def update if params[:id].nil? params[:id] = params[:asset_id] end # generates sanatized params from params hash to update the doc with sanitize_update_params @response = update_document(@document,@sanitized_params) @document.save flash[:notice] = "Your changes have been saved." if params.has_key? :add_another_author redirect_to edit_catalog_path(params[:asset_id], :wf_step => :contributor, :add_contributor => true) else redirect_to next_step(params[:asset_id]) end end deprecation_deprecate :update def destroy af_model = retrieve_af_model(params[:content_type], :default=>ModsAsset) @document_fedora = af_model.find(params[:asset_id]) authorize! :edit, @document_fedora @document_fedora.remove_contributor(params[:contributor_type], params[:index]) result = @document_fedora.save if request.xhr? render :text=>result.inspect else redirect_to edit_catalog_path(params[:asset_id], :wf_step => :contributor) end end deprecation_deprecate :destroy protected # validate the mods assets when they are sumbitted # The first author requires an ID field. # All authors require a First & Last name. def mods_assets_update_validation i = 0 desc_metadata = params[:asset][:descMetadata] unless desc_metadata.nil? while desc_metadata.has_key? "person_#{i}_computing_id".to_sym if desc_metadata["person_#{i}_first_name".to_sym]["0"].blank? or desc_metadata["person_#{i}_last_name".to_sym]["0"].blank? flash[:error] = "The First and Last names are required for all authors." return false end i += 1 end end return true end deprecation_deprecate :mods_assets_update_validation private def load_document_from_id(asset_id) af_model = retrieve_af_model(params[:content_type], :default=>ModsAsset) af_model.find(asset_id) end end