# HG changeset patch # User Nattee Niparnan # Date 2015-01-09 10:36:10 # Node ID 24d67ab56dc2fdb7c6b390dcf7c2a2f77c2b17e5 # Parent 0803f3082e05710b7701d265bd96ef4b70ce50ba add best_in_place tidy up route diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,9 @@ # gem 'debugger' # +#in-place editor +gem 'best_in_place', '~> 3.0.1' + # jquery addition gem 'jquery-rails' gem 'jquery-ui-sass-rails' diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,6 +37,9 @@ i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) arel (3.0.3) + best_in_place (3.0.2) + actionpack (>= 3.2) + railties (>= 3.2) builder (3.0.4) coffee-rails (3.2.2) coffee-script (>= 2.2.0) @@ -149,6 +152,7 @@ ruby DEPENDENCIES + best_in_place (~> 3.0.1) coffee-rails (~> 3.2.1) dynamic_form haml diff --git a/app/assets/javascripts/local_jquery.js b/app/assets/javascripts/local_jquery.js --- a/app/assets/javascripts/local_jquery.js +++ b/app/assets/javascripts/local_jquery.js @@ -5,3 +5,10 @@ //= require jquery.ui.slider //= require jquery-ui-timepicker-addon //= require jquery-tablesorter +//= require best_in_place +//= require best_in_place.jquery-ui + +$(document).ready(function() { + /* Activating Best In Place */ + jQuery(".best_in_place").best_in_place(); +}); diff --git a/app/controllers/configurations_controller.rb b/app/controllers/configurations_controller.rb --- a/app/controllers/configurations_controller.rb +++ b/app/controllers/configurations_controller.rb @@ -3,9 +3,6 @@ before_filter :authenticate before_filter { |controller| controller.authorization_by_roles(['admin'])} - in_place_edit_for :grader_configuration, :key - in_place_edit_for :grader_configuration, :type - in_place_edit_for :grader_configuration, :value def index @configurations = GraderConfiguration.find(:all, @@ -17,4 +14,15 @@ redirect_to :action => 'index' end + def update + @config = GraderConfiguration.find(params[:id]) + respond_to do |format| + if @config.update_attributes(params[:grader_configuration]) + format.json { head :ok } + else + format.json { respond_with_bip(@config) } + end + end + end + end diff --git a/app/views/configurations/index.html.haml b/app/views/configurations/index.html.haml --- a/app/views/configurations/index.html.haml +++ b/app/views/configurations/index.html.haml @@ -1,3 +1,6 @@ +- content_for :header do + = javascript_include_tag 'local_jquery' + %h1 System configuration %table.info @@ -14,7 +17,7 @@ %td = in_place_editor_field :grader_configuration, :value_type, {}, :rows=>1 %td - = in_place_editor_field :grader_configuration, :value, {}, :rows=>1 + = best_in_place @grader_configuration, :value, ok_button: "ok", cancel_button: "cancel" %td= conf.description - if GraderConfiguration.config_cached? diff --git a/app/views/graders/list.html.haml b/app/views/graders/list.html.haml --- a/app/views/graders/list.html.haml +++ b/app/views/graders/list.html.haml @@ -1,5 +1,6 @@ - content_for :head do = stylesheet_link_tag 'graders' + = javascript_include_tag 'local_jquery' %h1 Grader information diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,8 @@ resources :announcements resources :sites + resources :grader_configuration, controller: 'configurations' + # The priority is based upon order of creation: # first created -> highest priority.