app/controllers/observations_controller.rb
def new
    @observation = Observation.new(:user => current_user)
    @observation.id_please = params[:id_please]
    @observation.time_zone = current_user.time_zone

    if params[:copy] && (copy_obs = Observation.find_by_id(params[:copy])) && copy_obs.user_id == current_user.id
      %w(observed_on_string time_zone place_guess geoprivacy map_scale positional_accuracy).each do |a|
        @observation.send("#{a}=", copy_obs.send(a))
      end
      @observation.latitude = copy_obs.private_latitude || copy_obs.latitude
      @observation.longitude = copy_obs.private_longitude || copy_obs.longitude
      copy_obs.observation_photos.each do |op|
        @observation.observation_photos.build(:photo => op.photo)
      end
      copy_obs.observation_field_values.each do |ofv|
        @observation.observation_field_values.build(:observation_field => ofv.observation_field, :value => ofv.value)
      end
    end
    
    @taxon = Taxon.find_by_id(params[:taxon_id].to_i) unless params[:taxon_id].blank?
    unless params[:taxon_name].blank?
      @taxon ||= TaxonName.first(:conditions => [
        "lower(name) = ?", params[:taxon_name].to_s.strip.gsub(/[\s_]+/, ' ').downcase]
      ).try(:taxon)
    end
    
    if !params[:project_id].blank?
      @project = if params[:project_id].to_i == 0
        Project.includes(:project_observation_fields => :observation_field).find(params[:project_id])
      else
        Project.includes(:project_observation_fields => :observation_field).find_by_id(params[:project_id].to_i)
      end
      if @project
        @place = @project.place
        @project_curators = @project.project_users.where("role IN (?)", [ProjectUser::MANAGER, ProjectUser::CURATOR])
        @tracking_code = params[:tracking_code] if @project.tracking_code_allowed?(params[:tracking_code])
        @kml_assets = @project.project_assets.select{|pa| pa.asset_file_name =~ /\.km[lz]$/}
      end
    end

    @place ||= Place.find(params[:place_id]) unless params[:place_id].blank? rescue nil

    if @place
      @place_geometry = PlaceGeometry.without_geom.first(:conditions => {:place_id => @place})
    end
    
    if params[:facebook_photo_id]
      begin
        sync_facebook_photo
      rescue Koala::Facebook::APIError => e
        raise e unless e.message =~ /OAuthException/
        redirect_to ProviderAuthorization::AUTH_URLS['facebook']
        return
      end
    end
    sync_flickr_photo if params[:flickr_photo_id] && current_user.flickr_identity
    sync_picasa_photo if params[:picasa_photo_id] && current_user.picasa_identity
    sync_local_photo if params[:local_photo_id]
      
    @welcome = params[:welcome]
    
    # this should happen AFTER photo syncing so params can override attrs 
    # from the photo
    [:latitude, :longitude, :place_guess, :location_is_exact, :map_scale,
        :positional_accuracy, :positioning_device, :positioning_method,
        :observed_on_string].each do |obs_attr|
      next if params[obs_attr].blank?
      # sync_photo indicates that the user clicked sync photo, so presumably they'd 
      # like the photo attrs to override the URL
      # invite links are the other case, in which URL params *should* override the 
      # photo attrs b/c the person who made the invite link chose a taxon or something
      if params[:sync_photo]
        @observation.send("#{obs_attr}=", params[obs_attr]) if @observation.send(obs_attr).blank?
      else
        @observation.send("#{obs_attr}=", params[obs_attr])
      end
    end
    if @taxon
      @observation.taxon = @taxon
      @observation.species_guess = if @taxon.common_name
        @taxon.common_name.name
      else 
        @taxon.name
      end
    elsif !params[:taxon_name].blank?
      @observation.species_guess =  params[:taxon_name]
    end
    
    @observation_fields = ObservationField.recently_used_by(current_user).limit(10)
    
    respond_to do |format|
      format.html do
        @observations = [@observation]
        @sharing_authorizations = current_user.provider_authorizations.select do |pa|
          pa.provider_name == "facebook" || (pa.provider_name == "twitter" && !pa.secret.blank?)
        end
      end
      format.json  { render :json => @observation }
    end
  end
# GET /observations/new
# GET /observations/new.xml
# An attempt at creating a simple new page for batch add
GET /observations/new
GET /observations/new.xml
An attempt at creating a simple new page for batch add
GET / observations / new GET / observations / new . xml An attempt at creating a simple new page for batch add
def new
    @observation = Observation.new(:user => current_user)
    @observation.id_please = params[:id_please]
    @observation.time_zone = current_user.time_zone
    if params[:copy] && (copy_obs = Observation.find_by_id(params[:copy])) && copy_obs.user_id == current_user.id
      %w(observed_on_string time_zone place_guess geoprivacy map_scale positional_accuracy).each do |a|
        @observation.send("#{a}=", copy_obs.send(a))
      end
      @observation.latitude = copy_obs.private_latitude || copy_obs.latitude
      @observation.longitude = copy_obs.private_longitude || copy_obs.longitude
      copy_obs.observation_photos.each do |op|
        @observation.observation_photos.build(:photo => op.photo)
      end
      copy_obs.observation_field_values.each do |ofv|
        @observation.observation_field_values.build(:observation_field => ofv.observation_field, :value => ofv.value)
      end
    end
    @taxon = Taxon.find_by_id(params[:taxon_id].to_i) unless params[:taxon_id].blank?
    unless params[:taxon_name].blank?
      @taxon ||= TaxonName.first(:conditions => [
        "lower(name) = ?", params[:taxon_name].to_s.strip.gsub(/[\s_]+/, ' ').downcase]
      ).try(:taxon)
    end
    if !params[:project_id].blank?
      @project = if params[:project_id].to_i == 0
        Project.includes(:project_observation_fields => :observation_field).find(params[:project_id])
      else
        Project.includes(:project_observation_fields => :observation_field).find_by_id(params[:project_id].to_i)
      end
      if @project
        @place = @project.place
        @project_curators = @project.project_users.where("role IN (?)", [ProjectUser::MANAGER, ProjectUser::CURATOR])
        @tracking_code = params[:tracking_code] if @project.tracking_code_allowed?(params[:tracking_code])
        @kml_assets = @project.project_assets.select{|pa| pa.asset_file_name =~ /\.km[lz]$/}
      end
    end
    @place ||= Place.find(params[:place_id]) unless params[:place_id].blank? rescue nil
    if @place
      @place_geometry = PlaceGeometry.without_geom.first(:conditions => {:place_id => @place})
    end
    if params[:facebook_photo_id]
      begin
        sync_facebook_photo
      rescue Koala::Facebook::APIError => e
        raise e unless e.message =~ /OAuthException/
        redirect_to ProviderAuthorization::AUTH_URLS['facebook']
        return
      end
    end
    sync_flickr_photo if params[:flickr_photo_id] && current_user.flickr_identity
    sync_picasa_photo if params[:picasa_photo_id] && current_user.picasa_identity
    sync_local_photo if params[:local_photo_id]
    @welcome = params[:welcome]
    [:latitude, :longitude, :place_guess, :location_is_exact, :map_scale,
        :positional_accuracy, :positioning_device, :positioning_method,
        :observed_on_string].each do |obs_attr|
      next if params[obs_attr].blank?
      if params[:sync_photo]
        @observation.send("#{obs_attr}=", params[obs_attr]) if @observation.send(obs_attr).blank?
      else
        @observation.send("#{obs_attr}=", params[obs_attr])
      end
    end
    if @taxon
      @observation.taxon = @taxon
      @observation.species_guess = if @taxon.common_name
        @taxon.common_name.name
      else 
        @taxon.name
      end
    elsif !params[:taxon_name].blank?
      @observation.species_guess =  params[:taxon_name]
    end
    @observation_fields = ObservationField.recently_used_by(current_user).limit(10)
    respond_to do |format|
      format.html do
        @observations = [@observation]
        @sharing_authorizations = current_user.provider_authorizations.select do |pa|
          pa.provider_name == "facebook" || (pa.provider_name == "twitter" && !pa.secret.blank?)
        end
      end
      format.json  { render :json => @observation }
    end
  end
def new @observation = Observation . new ( :user => current_user ) @observation . id_please = params [ :id_please ] @observation . time_zone = current_user . time_zone if params [ :copy ] && ( copy_obs = Observation . find_by_id ( params [ :copy ] ) ) && copy_obs . user_id == current_user . id %w( observed_on_string time_zone place_guess geoprivacy map_scale positional_accuracy ) . each do | a | @observation . send ( "#{a}=" , copy_obs . send ( a ) ) end @observation . latitude = copy_obs . private_latitude || copy_obs . latitude @observation . longitude = copy_obs . private_longitude || copy_obs . longitude copy_obs . observation_photos . each do | op | @observation . observation_photos . build ( :photo => op . photo ) end copy_obs . observation_field_values . each do | ofv | @observation . observation_field_values . build ( :observation_field => ofv . observation_field , :value => ofv . value ) end end @taxon = Taxon . find_by_id ( params [ :taxon_id ] . to_i ) unless params [ :taxon_id ] . blank? unless params [ :taxon_name ] . blank? @taxon ||= TaxonName . first ( :conditions => [ "lower(name) = ?" , params [ :taxon_name ] . to_s . strip . gsub ( / [ \s _]+ / , ' ' ) . downcase ] ) . try ( :taxon ) end if ! params [ :project_id ] . blank? @project = if params [ :project_id ] . to_i == 0 Project . includes ( :project_observation_fields => :observation_field ) . find ( params [ :project_id ] ) else Project . includes ( :project_observation_fields => :observation_field ) . find_by_id ( params [ :project_id ] . to_i ) end if @project @place = @project . place @project_curators = @project . project_users . where ( "role IN (?)" , [ ProjectUser :: MANAGER , ProjectUser :: CURATOR ] ) @tracking_code = params [ :tracking_code ] if @project . tracking_code_allowed? ( params [ :tracking_code ] ) @kml_assets = @project . project_assets . select { | pa | pa . asset_file_name =~ / \. km[lz]$ / } end end @place ||= Place . find ( params [ :place_id ] ) unless params [ :place_id ] . blank? rescue nil if @place @place_geometry = PlaceGeometry . without_geom . first ( :conditions => { :place_id => @place } ) end if params [ :facebook_photo_id ] begin sync_facebook_photo rescue Koala :: Facebook :: APIError => e raise e unless e . message =~ / OAuthException / redirect_to ProviderAuthorization :: AUTH_URLS [ 'facebook' ] return end end sync_flickr_photo if params [ :flickr_photo_id ] && current_user . flickr_identity sync_picasa_photo if params [ :picasa_photo_id ] && current_user . picasa_identity sync_local_photo if params [ :local_photo_id ] @welcome = params [ :welcome ] [ :latitude , :longitude , :place_guess , :location_is_exact , :map_scale , :positional_accuracy , :positioning_device , :positioning_method , :observed_on_string ] . each do | obs_attr | next if params [ obs_attr ] . blank? if params [ :sync_photo ] @observation . send ( "#{obs_attr}=" , params [ obs_attr ] ) if @observation . send ( obs_attr ) . blank? else @observation . send ( "#{obs_attr}=" , params [ obs_attr ] ) end end if @taxon @observation . taxon = @taxon @observation . species_guess = if @taxon . common_name @taxon . common_name . name else @taxon . name end elsif ! params [ :taxon_name ] . blank? @observation . species_guess = params [ :taxon_name ] end @observation_fields = ObservationField . recently_used_by ( current_user ) . limit ( 10 ) respond_to do | format | format . html do @observations = [ @observation ] @sharing_authorizations = current_user . provider_authorizations . select do | pa | pa . provider_name == "facebook" || ( pa . provider_name == "twitter" && ! pa . secret . blank? ) end end format . json { render :json => @observation } end end
GET /observations/new
GET /observations/new.xml
An attempt at creating a simple new page for batch add
GET / observations / new GET / observations / new . xml An attempt at creating a simple new page for batch add
# this should happen AFTER photo syncing so params can override attrs  # from the photo # sync_photo indicates that the user clicked sync photo, so presumably they'd  # like the photo attrs to override the URL # invite links are the other case, in which URL params *should* override the  # photo attrs b/c the person who made the invite link chose a taxon or something