Skip to content

Commit

Permalink
Added chosen library, and implemented ajax-chosen.proto in separate repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbroadbent committed Dec 21, 2011
1 parent 73e82ed commit a125da5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gem 'simple_form', '~> 1.5.2'
gem 'prototype-rails', '>= 3.1.0'
gem 'ffaker', '>= 1.5.0' # For demo data
gem 'uglifier'
gem 'chosen-rails'

# Gems used only for assets and not required
# in production environments by default.
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ GEM
activerecord (>= 3.0.7)
awesome_print (1.0.1)
builder (3.0.0)
chosen-rails (0.9.5)
railties (~> 3.0)
thor (~> 0.14)
cocaine (0.2.1)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -196,6 +199,7 @@ DEPENDENCIES
annotate (~> 2.4.1.beta)
authlogic (~> 3.1.0)
awesome_print (>= 0.3.1)
chosen-rails
coffee-rails (>= 3.1.1)
factory_girl (>= 1.3.3)
factory_girl_rails (~> 1.4.0)
Expand Down
22 changes: 16 additions & 6 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
//= require modalbox
//= require facebooklist
//= require facebooklist.simulate
//= require chosen-prototype
//= require ajax-chosen.proto

var fbtaglist = null;

Expand Down Expand Up @@ -141,13 +143,22 @@ var crm = {
}
},

ensure_chosen_account: function() {
if (! $("account_id_chzn")) {
new ajaxChosen($("account_id"),
{url: "/accounts/auto_complete.json",
query_key: "auto_complete_query"})
}
},

// Hide accounts dropdown and show create new account edit field instead.
//----------------------------------------------------------------------------
create_account: function(and_focus) {
crm.ensure_chosen_account();
$("account_disabled_title").hide();
$("account_select_title").hide();
$("account_create_title").show();
$("account_id").hide();
$("account_id_chzn").hide();
$("account_id").disable();
$("account_name").enable();
$("account_name").clear();
Expand All @@ -160,28 +171,27 @@ var crm = {
// Hide create account edit field and show accounts dropdown instead.
//----------------------------------------------------------------------------
select_account: function(and_focus) {
crm.ensure_chosen_account();
$("account_disabled_title").hide();
$("account_create_title").hide();
$("account_select_title").show();
$("account_name").hide();
$("account_name").disable();
$("account_id").enable();
$("account_id").show();
if (and_focus) {
$("account_id").focus();
}
$("account_id_chzn").show();
},

// Show accounts dropdown and disable it to prevent changing the account.
//----------------------------------------------------------------------------
select_existing_account: function() {
crm.ensure_chosen_account();
$("account_create_title").hide();
$("account_select_title").hide();
$("account_disabled_title").show();
$("account_name").hide();
$("account_name").disable();
$("account_id").disable();
$("account_id").show();
$("account_id_chzn").show();
},

//----------------------------------------------------------------------------
Expand Down
Empty file modified app/assets/javascripts/application_tabbed.js
100755 → 100644
Empty file.
3 changes: 2 additions & 1 deletion app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*------------------------------------------------------------------------------
*/

/*
*= require base
*= require header
Expand All @@ -25,4 +25,5 @@
*= require safari
*= require modalbox
*= require facebooklist
*= require chosen
*/
5 changes: 4 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def auto_complete
@auto_complete = @auto_complete.last
end
session[:auto_complete] = controller_name.to_sym
render "shared/auto_complete", :layout => nil
respond_to do |format|
format.js { render "shared/auto_complete", :layout => nil }
format.json { render :json => @auto_complete.inject({}){|h,a| h[a.id] = a.name; h } }
end
end

# Common attach handler for all core controllers.
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def new
@contact = Contact.new(:user => @current_user, :access => Setting.default_access)
@account = Account.new(:user => @current_user)
@users = User.except(@current_user)
@accounts = Account.my.order("name")
@accounts = Account.order("name").my.limit(10)
if params[:related]
model, id = params[:related].split("_")
instance_variable_set("@#{model}", model.classify.constantize.my.find(id))
Expand All @@ -91,7 +91,7 @@ def edit
@contact = Contact.my.find(params[:id])
@users = User.except(@current_user)
@account = @contact.account || Account.new(:user => @current_user)
@accounts = Account.my.order("name")
@accounts = Account.order("name").my.limit(10)
if params[:previous].to_s =~ /(\d+)\z/
@previous = Contact.my.find($1)
end
Expand All @@ -116,7 +116,7 @@ def create
format.xml { render :xml => @contact, :status => :created, :location => @contact }
else
@users = User.except(@current_user)
@accounts = Account.my.order("name")
@accounts = Account.order("name").my.limit(10)
unless params[:account][:id].blank?
@account = Account.find(params[:account][:id])
else
Expand Down Expand Up @@ -148,7 +148,7 @@ def update
format.xml { head :ok }
else
@users = User.except(@current_user)
@accounts = Account.my.order("name")
@accounts = Account.order("name").my.limit(10)
if @contact.account
@account = Account.find(@contact.account.id)
else
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
get :options
get :search
get :field_group
post :auto_complete
match :auto_complete
post :redraw
end
member do
Expand Down

0 comments on commit a125da5

Please sign in to comment.