-
-
Save heavysixer/379886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WizardController < ApplicationController | |
session :cookie_only => false, :only => :create | |
before_filter :determine_site_by_domain, :except=> [:upload_page_photo,:create_agent_logo,:index,:content,:customize,:pricing,:new_site, :next_step, :previous_step,:create_site, :brand_select] | |
before_filter :check_domain_in_admin | |
skip_before_filter :verify_authenticity_token, :only => [:upload_page_photo,:create_agent_logo] | |
#before_filter :verify_upload, :only => [:next_step_remote, :previous_step_remote] | |
#after_filter :set_button_positioning #req'd for IE7 with ajaxy goodness | |
layout 'wizard' | |
def new_site | |
@site = Site.new | |
@site.site_info = SiteInfo.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @site } | |
end | |
end | |
def create_site | |
@site = Site.new(params[:site]) | |
@site.site_info = SiteInfo.new(params[:site_info]) | |
respond_to do |format| | |
if( @site.save && @site.site_info.save) | |
@site.site_info.contact_form_email = @site.user.email | |
@site.site_info.estimate_form_email = @site.user.email | |
@site.site_info.save | |
@site.create_new_revision | |
@current_user.wizard.next_step | |
log_activity("Site #{@site.site_info.name} was created.") | |
flash[:notice] = 'Site was successfully created.' | |
format.html { redirect_to :controller => :display , :action => :home} | |
format.xml { render :xml => @site, :status => :created, :location => @site } | |
else | |
@site.destroy | |
format.html { render :action => "new_site" } | |
format.xml { render :xml => @site.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
## move to AgentCMS | |
##-=-=-=-= | |
def homepage | |
end | |
def request_an_estimate | |
end | |
def marquee | |
@marquee = Marquee.find_or_intialize_by_id(@revision.home_page.marquee_id) | |
end | |
def create_marquee | |
@revision.home_page.marquee = Marquee.find(params[:marquee][:id]) | |
if @revision.home_page.save | |
next_step_remote() | |
else | |
render :update do |page| | |
#page << "alert('ERROR');" | |
end | |
end | |
end | |
def agent_logo | |
@agent_logo = AgentLogo.new | |
end | |
def create_agent_logo | |
if params[:Filedata] | |
@revision = Revision.find(params[:revision]) | |
if @revision.agent_logo.nil? | |
@agent_logo = AgentLogo.new(:swfupload_file => params[:Filedata]) | |
@revision.agent_logo = @agent_logo | |
if @revision.agent_logo.save | |
logger.info "SUCCESS!" | |
render :text => @agent_logo.image.url(:normal), :status => 200 | |
else | |
logger.info "FAIL!" | |
render :text => "No response.", :status => 500 | |
end | |
else | |
if @revision.agent_logo.update_attributes({:swfupload_file => params[:Filedata]}) | |
logger.info "SUCCESS!" | |
render :text => @revision.agent_logo.image.url(:normal), :status => 200 | |
else | |
logger.info "FAIL!" | |
render :text => "No response.", :status => 500 | |
end | |
end | |
end | |
end | |
def upload_page_photo | |
if params[:Filedata] | |
@revision = Revision.find( params[:revision] ) | |
@model = @revision.send(params[:model]) | |
#if @model.photo.nil? | |
@model.photo = Photo.new(:swfupload_file => params[:Filedata], :default_image => false) | |
# else | |
# @model.photo = Photo.update(@model.photo.id, {:swfupload_file => params[:Filedata]}) | |
# end | |
if @model.photo.save and @model.save | |
render :text => @model.photo.image.url(:normal), :status => 200 | |
end | |
end | |
end | |
def add_photo | |
model_name = params[:photo][:model] | |
if (!params[model_name.to_sym].nil? && !params[model_name.to_sym].empty?) && (@model = @revision.send(model_name).update_attributes(params[model_name.to_sym])) | |
next_step_remote | |
else | |
generic_error_message("Please select a photo.") | |
end | |
end | |
def get_photo_gallery_form | |
render :update do |page| | |
page.reload | |
end | |
end | |
def get_page_photo_form | |
page = @revision.send(params[:model]) | |
@photo = Photo.find(page.photo) unless page.photo.nil? | |
render :update do |page| | |
page.replace :photo_form, :partial => "upload_page_photo", :locals => {:upload_path => "wizard/upload_page_photo",:model => params[:model], :photo => @photo} | |
page.insert_html :bottom, "agent-wizard-navigation", "<div id='next-button'>#{link_to_remote "Next", :url => {:controller => :wizard, :action=>:next_step}, :before => "try{removeswfupload();}catch(err){};"}</div>" | |
controller.set_button_positioning(page) | |
end | |
end | |
def save_services | |
@revision.services_page.update_attributes(params[:services_page]) | |
render :text => "" | |
end | |
def create_services | |
@revision.services_page.update_attributes(params[:services_page]) | |
if @revision.services_page.services.empty? | |
generic_error_message("Please select at least one service.") | |
else | |
next_step_remote | |
end | |
end | |
def update_services | |
@revision.services_page.update_attributes(params[:services_page]) | |
if @revision.services_page.services.empty? | |
flash[:error] = "Please select at least one service." | |
end | |
respond_to do |format| | |
format.json render :json => { :flash => flash }, :status => 200 | |
end | |
end | |
def save_moving_tips | |
@revision.moving_tips_page.update_attributes(params[:moving_tips_page]) | |
render :text => "" | |
end | |
def create_moving_tips | |
@revision.moving_tips_page.update_attributes(params[:moving_tips_page]) | |
if @revision.moving_tips_page.moving_tips.empty? | |
generic_error_message("Please select at least one moving tip.") | |
else | |
next_step_remote | |
end | |
end | |
def create_testimonials | |
@tp = @revision.testimonials_page | |
if @tp.update_attributes(params[:testimonials_page]) | |
next_step_remote | |
else | |
render :update do |page| | |
page.visual_effect(:drop, '#spinner') | |
page.replace_html("#wizard_content_errors", error_messages_for('tp') ) | |
controller.set_button_positioning(page) | |
end | |
end | |
end | |
def create_pdf_attachments | |
@page = case params[:page_name] | |
when "about_page" then @revision.about_page | |
when "containers_page" then @revision.containers_page | |
when "services_page" then @revision.services_page | |
when "moving_tips_page" then @revision.moving_tips_page | |
else raise "Invalid page_name: #{params[:page_name].inspect}" | |
end | |
responds_to_parent do | |
if @page.update_pdf_attachments(params[:pdf_attachments] || {}) | |
next_step_remote | |
else | |
all_errors = [] | |
for pa_id, errors in @page.pdf_attachment_errors | |
all_errors << (errors.respond_to?(:full_messages) ? errors.full_messages : errors.to_s) | |
end | |
render :update do |page| | |
page.visual_effect(:drop, '#spinner') | |
page.replace_html("#wizard_content_errors", all_errors.join("<br/>\n")) | |
controller.set_button_positioning(page) | |
end | |
end | |
end | |
end | |
def create_location | |
@site_info = @revision.site.site_info | |
@revision.update_attributes(params[:revision]) | |
@site_info.update_attributes(params[:site_info]) | |
next_step_remote | |
rescue | |
render :update do |page| | |
page.visual_effect(:drop, '#spinner') | |
page.replace_html("#wizard_content_errors", error_messages_for('site_info') + error_messages_for('revision') ) | |
controller.set_button_positioning(page) | |
end | |
end | |
def create_contact_us_page | |
if @revision.contact_us_page.update_attributes(params[:contact_us_page]) | |
next_step_remote | |
else | |
render :update do |page| | |
page.visual_effect(:drop, '#spinner') | |
page.replace_html("#wizard_content_errors", error_messages_for('@revision.contact_us_page') ) | |
controller.set_button_positioning(page) | |
end | |
end | |
end | |
def add_testimonial | |
@testimonial = Testimonial.new | |
@index = (params[:index].to_i + 1) | |
render :update do |page| | |
page.insert_html :bottom , :testimonials, :partial => 'wizard/testimonial_fields', :object => @testimonial | |
if @index >= Testimonial::PAGE_LIMIT | |
page.remove :add_testimonials_link | |
else | |
page.replace :add_testimonials_link, :partial => 'add_testimonials_link', :locals => { :index => @index } | |
end | |
page << "$('#overlay').height($(document.html).height());" | |
controller.set_button_positioning(page) | |
end | |
end | |
def add_pdf_attachment | |
@pdf_attachment = PdfAttachment.new | |
@index = params[:index].to_i + 1 | |
render :update do |page| | |
page.insert_html :bottom, :pdf_attachments, | |
:partial => 'wizard/pdf_attachment_fields', | |
:locals => { :pdf_attachment => @pdf_attachment, :index => @index } | |
if @index >= PdfAttachment::PDFABLE_LIMIT | |
page.remove :add_pdf_attachment_link | |
else | |
page.replace :add_pdf_attachment_link, :partial => 'add_pdf_attachment_link', :locals => { :index => @index } | |
end | |
page << "$('#overlay').height($(document.html).height());" | |
controller.set_button_positioning(page) | |
end | |
end | |
def add_location | |
loc_idx = @revision.locations.size + 1 | |
@location = Location.new | |
render :update do |page| | |
page.insert_html :bottom , :locations, :partial => 'wizard/location', :object => @location, :locals => {:idx => loc_idx} | |
page << "$('#overlay').height($(document.html).height());" | |
controller.set_button_positioning(page) | |
end | |
end | |
def custom_homepage | |
render :update do |page| | |
page.replace :home_page_form, :partial => "custom_homepage" | |
end | |
end | |
def prex_homepage | |
render :update do |page| | |
page.replace :home_page_form, :partial => "homepage_form" | |
end | |
end | |
def prex_services | |
render :update do |page| | |
page.replace :services_form, :partial => "services_form" | |
end | |
end | |
def prex_moving_tips | |
render :update do |page| | |
page.replace :moving_tips_form, :partial => "moving_tips_form" | |
end | |
end | |
def create_homepage | |
if !params[:home_page].nil? && @revision.home_page.update_attributes(params[:home_page]) | |
next_step_remote | |
else | |
generic_error_message("Please select an item for your home page.") | |
end | |
end | |
def photo | |
end | |
def create_custom_homepage | |
if @revision.home_page.update_attributes(params[:home_page]) | |
next_step_remote | |
else | |
generic_error_message("There was an error saving your home page copy.") | |
end | |
end | |
def create_about_copy | |
if @revision.about_page.update_attributes(params[:about_page]) | |
next_step_remote | |
else | |
generic_error_message("Please enter copy for the About Us section.") | |
end | |
end | |
def enable_containers | |
enabled = %w(1 on).include?(params[:enabled].to_s) | |
@revision.containers_page.update_attribute(:enabled, enabled) | |
render :update do |page| | |
page << "close_cms();" | |
page.reload | |
end | |
end | |
def create_containers_copy | |
if @revision.containers_page.update_attributes(params[:containers_page]) | |
next_step_remote | |
else | |
generic_error_message("Please enter copy for the Containers section.") | |
end | |
end | |
def pricing_confirm | |
if params[:pricing_structure][:understand] == "1" | |
next_step_remote | |
else | |
generic_error_message("Please check the box indicating that you have read and understand the pricing structure.") | |
end | |
end | |
def terms_confirm | |
if params[:term][:understand] == "1" | |
next_step_remote | |
else | |
generic_error_message("Please check the box indicating that you have read and understand the terms and conditions.") | |
end | |
end | |
def request_estimate_email | |
@site_info = @site.site_info | |
if @site_info.update_attributes(params[:site_info]) | |
next_step_remote | |
else | |
render :update do |page| | |
page.visual_effect(:drop, '#spinner') | |
page.replace_html("#wizard_content_errors", error_messages_for('site_info') ) | |
controller.set_button_positioning(page) | |
end | |
end | |
end | |
def approve | |
do_approval | |
next_step_remote | |
end | |
def next_step_remote | |
if !is_edit? or is_super? | |
render :update do |page| | |
page << "close_cms();" | |
page.reload | |
end | |
else | |
render :update do |page| | |
page << "if (CKEDITOR.instances.ckeditor_textarea) CKEDITOR.instances.ckeditor_textarea.destroy();" | |
page.replace_html('#agent-wizard-content', :partial => "wizard/#{@current_user.wizard.next_step}") | |
page.replace_html("#progress-bar", :partial => 'wizard/progress_indicator') | |
page.replace_html "#agent-wizard-navigation", :partial => "wizard/wizard_overlay_navigation" | |
page << "$('#overlay').height($(document.html).height());" | |
page << "self.scrollTo(0, 0)" | |
end | |
end | |
end | |
def next_step | |
respond_to do |format| | |
format.html {redirect_to :action => @current_user.wizard.next_step} | |
format.js { next_step_remote } | |
end | |
end | |
def previous_step | |
respond_to do |format| | |
format.html { redirect_to :action => @current_user.wizard.previous_step } | |
format.js { previous_step_remote } | |
end | |
end | |
def previous_step_remote | |
render :update do |page| | |
# @current_user.wizard.previous_step | |
page << "if (CKEDITOR.instances.ckeditor_textarea) CKEDITOR.instances.ckeditor_textarea.destroy();" | |
page.replace_html('#agent-wizard-content', :partial => "wizard/#{@current_user.wizard.previous_step}") | |
page.replace_html "#progress-bar", :partial => 'wizard/progress_indicator' | |
page.replace_html "#agent-wizard-navigation", :partial => "wizard/wizard_overlay_navigation" | |
page << "$('#overlay').height($(document.html).height());" | |
page << "self.scrollTo(0, 0)" | |
end | |
end | |
def current_step | |
end | |
def brand_select | |
if !params[:site][:brand_id].nil? | |
brand = Brand.find(params[:site][:brand_id]) | |
render :update do |page| | |
page.replace_html "brand_domain", :text => brand.domain | |
end | |
else | |
render :update do |page| | |
end | |
end | |
end | |
def write_your_own_service | |
@service = Service.new(:brand_id => @site.brand.id, :site_id => @site.id) | |
render :update do |page| | |
# page.replace :bottom, "agent-wizard-navigation", "<div id='next-button'>#{link_to_remote "Next", :url => {:controller => :wizard, :action=>:next_step}}</div>" | |
page.replace :services_form, :partial => "write_your_own_service", :locals => {:svc => @service} | |
controller.set_button_positioning(page) | |
end | |
end | |
def make_service | |
if @service = Service.create(params[:service]) | |
@revision.services_page.services << @service | |
render :update do |page| | |
page['#spinner'].hide | |
page.replace :services_form , :partial => "services_form" | |
controller.set_button_positioning(page) | |
end | |
else | |
render :update do |page| | |
page['#spinner'].hide | |
page.replace_html("#wizard_content_errors", error_messages_for('site_info') ) | |
controller.set_button_positioning(page) | |
end | |
end | |
end | |
def write_your_own_moving_tip | |
@moving_tip = MovingTip.new(:brand_id => @site.brand.id, :site_id => @site.id) | |
render :update do |page| | |
# page.insert_html :bottom, "agent-wizard-navigation", "<div id='next-button'>#{link_to_remote "Next", :url => {:controller => :wizard, :action=>:next_step}}</div>" | |
page.replace :moving_tips_form, :partial => "write_your_own_moving_tip", :locals => {:moving_tip => @moving_tip} | |
controller.set_button_positioning(page) | |
end | |
end | |
def make_moving_tip | |
if @moving_tip = MovingTip.create(params[:moving_tip]) | |
@revision.moving_tips_page.moving_tips << @moving_tip | |
render :update do |page| | |
page["#spinner"].hide | |
page.replace :moving_tips_form, :partial => "moving_tips_form" | |
controller.set_button_positioning(page) | |
end | |
else | |
render :update do |page| | |
page.visual_effect(:drop, '#spinner') | |
page.replace_html("#wizard_content_errors", error_messages_for('moving_tip') ) | |
controller.set_button_positioning(page) | |
end | |
end | |
end | |
def set_button_positioning(page) | |
logger.info "SET POS" | |
page << "$('#overlay').height($(document.html).height());" | |
page << "$('#next-button > input').css('bottom','14px');" | |
page << "$('#agent-wizard-navigation').css('bottom','14px');" | |
end | |
protected | |
def verify_upload | |
logger.info "VERIFY UPLOAD" | |
if @current_user.wizard.current_step == 6 && @revision.agent_logo.nil? | |
logger.info "OMG. NO UPLOAD!" | |
generic_error_message("Please upload a logo.") | |
return false | |
end | |
true | |
end | |
def generic_error_message(msg) | |
render :update do |page| | |
@item = Tableless.new | |
@item.errors.add_to_base(msg) | |
page.visual_effect(:drop, '#spinner') | |
page.replace_html("#wizard_content_errors", error_messages_for('item')) | |
controller.set_button_positioning(page) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment