<commit_before># Copyright (c) 2008-2013 <NAME> and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class OpportunitiesController < EntitiesController
  before_filter :load_settings
  before_filter :get_data_for_sidebar, :only => :index
  before_filter :set_params, :only => [ :index, :redraw, :filter ]

  # GET /opportunities
  #----------------------------------------------------------------------------
  def index
    @opportunities = get_opportunities(:page => params[:page], :per_page => params[:per_page])

    respond_with @opportunities do |format|
      format.xls { render :layout => 'header' }
      format.csv { render :csv => @opportunities }
    end
  end

  # GET /opportunities/1
  # AJAX /opportunities/1
  #----------------------------------------------------------------------------
  def show
    @comment = Comment.new
    @timeline = timeline(@opportunity)
    respond_with(@opportunity)
  end

  # GET /opportunities/new
  #----------------------------------------------------------------------------
  def new
    @opportunity.attributes = {:user => current_user, :stage => Opportunity.default_stage, :access => Setting.default_access, :assigned_to => nil}
    @account     = Account.new(:user => current_user, :access => Setting.default_access)
    @accounts    = Account.my.order('name')

    if params[:related]
      model, id = params[:related].split('_')
      if related = model.classify.constantize.my.find_by_id(id)
        instance_variable_set("@#{model}", related)
        @account = related.account if related.respond_to?(:account)
      else
        respond_to_related_not_found(model) and return
      end
    end

    respond_with(@opportunity)
  end

  # GET /opportunities/1/edit                                              AJAX
  #----------------------------------------------------------------------------
  def edit
    @account  = @opportunity.account || Account.new(:user => current_user)
    @accounts = Account.my.order('name')

    if params[:previous].to_s =~ /(\d+)\z/
      @previous = Opportunity.my.find_by_id($1) || $1.to_i
    end

    respond_with(@opportunity)
  end<commit_msg>Only pre-select account of related entity, if not nil<commit_after># Copyright (c) 2008-2013 <NAME> and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class OpportunitiesController < EntitiesController
  before_filter :load_settings
  before_filter :get_data_for_sidebar, :only => :index
  before_filter :set_params, :only => [ :index, :redraw, :filter ]

  # GET /opportunities
  #----------------------------------------------------------------------------
  def index
    @opportunities = get_opportunities(:page => params[:page], :per_page => params[:per_page])

    respond_with @opportunities do |format|
      format.xls { render :layout => 'header' }
      format.csv { render :csv => @opportunities }
    end
  end

  # GET /opportunities/1
  # AJAX /opportunities/1
  #----------------------------------------------------------------------------
  def show
    @comment = Comment.new
    @timeline = timeline(@opportunity)
    respond_with(@opportunity)
  end

  # GET /opportunities/new
  #----------------------------------------------------------------------------
  def new
    @opportunity.attributes = {:user => current_user, :stage => Opportunity.default_stage, :access => Setting.default_access, :assigned_to => nil}
    @account     = Account.new(:user => current_user, :access => Setting.default_access)
    @accounts    = Account.my.order('name')

    if params[:related]
      model, id = params[:related].split('_')
      if related = model.classify.constantize.my.find_by_id(id)
        instance_variable_set("@#{model}", related)
        @account = related.account if related.try(:account)
      else
        respond_to_related_not_found(model) and return
      end
    end

    respond_with(@opportunity)
  end

  # GET /opportunities/1/edit                                              AJAX
  #----------------------------------------------------------------------------
  def edit
    @account  = @opportunity.account || Account.new(:user => current_user)
    @accounts = Account.my.order('name')

    if params[:previous].to_s =~ /(\d+)\z/
      @previous = Opportunity.my.find_by_id($1) || $1.to_i
    end

    respond_with(@opportunity)
  end
{'fraction_non_alphanumeric': 0.2652931180968564, 'fraction_numerical': 0.0055225148683092605, 'mean_word_length': 1.7473745624270711, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6883631', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1234, 'n_words': 279}