molten-trunk/molten5_withgrid/app/controllers/cases_controller_new.rb
# Provides suggested solutions and cases via AJAX when creating a new support case. 
Provides suggested solutions and cases via AJAX when creating a new support case.
Provides suggested solutions and cases via AJAX when creating a new support case .
def suggested_solutions_and_cases
    search_term = params[:subject].to_s.strip
    case_id = params[:case_id]
    @suggested_cases_all = Sfcase.full_text_search(search_term,current_contact).last
    if case_id
      @suggested_cases_all.delete_if {|c| c.id == case_id}
    end
    @suggested_solutions_all = Sfsolution.full_text_search(search_term,current_contact,
                                             {
                                             },
                                             {
                                               :account_specific => :combine
                                             }
                                            ).last
    @suggested_cases = @suggested_cases_all.slice(0..4)
    @suggested_solutions = @suggested_solutions_all.slice(0..4)
    render :update do |page|
      if @suggested_solutions.any?
        logger.info "Found #{@suggested_solutions_all.size} solutions"
        page.replace_html "suggested_solutions_container", :partial => 'suggested_solutions'
        if @suggested_solutions_all.size > 5
           page.insert_html :bottom, "suggested_solutions_container",
                 link_to("More matching solutions...", "/solutions/search?term=" + search_term)
        end
      else
        page.replace_html "suggested_solutions_container", ''
      end
      if @suggested_cases.any?
        logger.info "Found #{@suggested_cases_all.size} solutions"
        page.replace_html "suggested_cases_container", :partial => 'suggested_cases'
        if @suggested_cases_all.size > 5
           page.insert_html :bottom, "suggested_cases_container",
                 link_to("More similar cases...", "/cases/search?term=" + search_term)
        end
      else
        page.replace_html "suggested_cases_container", ''
      end
      suggestions_text = ''
      suggestions_text = if @suggested_solutions.any? and @suggested_cases.any?
                            "Found #{@suggested_solutions_all.size} matching solutions and #{@suggested_cases_all.size} similar cases."
                         elsif @suggested_solutions.any?
                            "Found #{@suggested_solutions_all.size} matching solutions."
                         elsif @suggested_cases.any?
                            "Found #{@suggested_cases_all.size} similar cases."
                         else 
                           ""
                         end
      suggestions_text = "<span class=\"suggestions_results\">" + suggestions_text + "</span>"
      page.replace_html "suggestions_box", suggestions_text
    end
  end
def suggested_solutions_and_cases search_term = params [ :subject ] . to_s . strip case_id = params [ :case_id ] @suggested_cases_all = Sfcase . full_text_search ( search_term , current_contact ) . last if case_id @suggested_cases_all . delete_if { | c | c . id == case_id } end @suggested_solutions_all = Sfsolution . full_text_search ( search_term , current_contact , { } , { :account_specific => :combine } ) . last @suggested_cases = @suggested_cases_all . slice ( 0 .. 4 ) @suggested_solutions = @suggested_solutions_all . slice ( 0 .. 4 ) render :update do | page | if @suggested_solutions . any? logger . info "Found #{@suggested_solutions_all.size} solutions" page . replace_html "suggested_solutions_container" , :partial => 'suggested_solutions' if @suggested_solutions_all . size > 5 page . insert_html :bottom , "suggested_solutions_container" , link_to ( "More matching solutions..." , "/solutions/search?term=" + search_term ) end else page . replace_html "suggested_solutions_container" , '' end if @suggested_cases . any? logger . info "Found #{@suggested_cases_all.size} solutions" page . replace_html "suggested_cases_container" , :partial => 'suggested_cases' if @suggested_cases_all . size > 5 page . insert_html :bottom , "suggested_cases_container" , link_to ( "More similar cases..." , "/cases/search?term=" + search_term ) end else page . replace_html "suggested_cases_container" , '' end suggestions_text = '' suggestions_text = if @suggested_solutions . any? and @suggested_cases . any? "Found #{@suggested_solutions_all.size} matching solutions and #{@suggested_cases_all.size} similar cases." elsif @suggested_solutions . any? "Found #{@suggested_solutions_all.size} matching solutions." elsif @suggested_cases . any? "Found #{@suggested_cases_all.size} similar cases." else "" end suggestions_text = "<span class=\"suggestions_results\">" + suggestions_text + "</span>" page . replace_html "suggestions_box" , suggestions_text end end
Provides suggested solutions and cases via AJAX when creating a new support case.
Provides suggested solutions and cases via AJAX when creating a new support case .
#@suggested_cases_all.delete_if {|c| c.subject == search_term} #      page.delay(5) do  #          page.hide "suggestions_box" #          page.replace_html "suggestions_box", "Searching..." #      end