app/controllers/survey_respondents_controller.rb
#
# TODO - if no survey has been specified then we want to go to a participant home page....  
#
if no survey has been specified then we want to go to a participant home page
if no survey has been specified then we want to go to a participant home page
def create
    key       = params[:key]
    last_name = params[:last_name]
    @site_config = SiteConfig.first
    @survey_respondent = findRespondent(key, last_name) if (key && key != '')
    page = get_stored_page
    @survey = Survey.find_by(alias: page)
    if @survey_respondent
      @survey_respondent.attending = params[:cancel] 
      if @survey_respondent.save
        if params[:cancel]
          @survey = Survey.find_by(alias: "partsurvey") if !@survey
          if (@survey.decline_status && @survey_respondent.person) 
            @survey_respondent.person.acceptance_status = @survey.decline_status
            @survey_respondent.person.save!
          end
          begin
            MailService.sendEmail(@survey_respondent.person, MailUse[:DeclinedSurvey], @survey, (@survey_respondent ? @survey_respondent.survey_respondent_detail : nil))
          rescue => ex
            logger.error "No email template. We were not able to send the email to " + @survey_respondent.person.getFullName
          end
          render 'no_survey'
        else 
          @survey_respondent.single_access_token = (0...25).map { ('a'..'z').to_a[rand(26)] }.join 
          @survey_respondent.save
          survey_redirect_back '/form/partsurvey', @survey_respondent.single_access_token
        end
      else
        flash[:error] = "Unable to save the information. Please try again."
        render :action => :new
      end
    else
      @survey_respondent = SurveyRespondent.new
      flash[:error] = "Unable to find a potential participant that matches the inputs."
      render :action => :new
    end
  end
def create key = params [ :key ] last_name = params [ :last_name ] @site_config = SiteConfig . first @survey_respondent = findRespondent ( key , last_name ) if ( key && key != '' ) page = get_stored_page @survey = Survey . find_by ( alias : page ) if @survey_respondent @survey_respondent . attending = params [ :cancel ] if @survey_respondent . save if params [ :cancel ] @survey = Survey . find_by ( alias : "partsurvey" ) if ! @survey if ( @survey . decline_status && @survey_respondent . person ) @survey_respondent . person . acceptance_status = @survey . decline_status @survey_respondent . person . save! end begin MailService . sendEmail ( @survey_respondent . person , MailUse [ :DeclinedSurvey ] , @survey , ( @survey_respondent ? @survey_respondent . survey_respondent_detail : nil ) ) rescue => ex logger . error "No email template. We were not able to send the email to " + @survey_respondent . person . getFullName end render 'no_survey' else @survey_respondent . single_access_token = ( 0 ... 25 ) . map { ( 'a' .. 'z' ) . to_a [ rand ( 26 ) ] } . join @survey_respondent . save survey_redirect_back '/form/partsurvey' , @survey_respondent . single_access_token end else flash [ :error ] = "Unable to save the information. Please try again." render :action => :new end else @survey_respondent = SurveyRespondent . new flash [ :error ] = "Unable to find a potential participant that matches the inputs." render :action => :new end end
TODO - if no survey has been specified then we want to go to a participant home page....
TODO - if no survey has been specified then we want to go to a participant home page ....
# find a respondent with the key and last name # We need to get the survey that is to be filled in, if we do not have page then we can get if back # Indicate whether or not the person said that they are attending # Redirect the person to the survey # TODO hanle case of no surevy selected????? # Otherwise we continue to the form # TODO - change the '/' to the participant page (for past surveys and managing availabilities etc.) # generate random key for access # there was a problem so return to the new page # there was a problem so return to the 'login' page