diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -54,6 +54,7 @@ #add bootstrap gem 'bootstrap-sass', '~> 3.2.0' gem 'bootstrap-switch-rails' +gem 'bootstrap-toggle-rails' gem 'autoprefixer-rails' diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,7 @@ bootstrap-sass (3.2.0.2) sass (~> 3.2) bootstrap-switch-rails (3.3.3) + bootstrap-toggle-rails (2.2.1.0) builder (3.0.4) coffee-rails (3.2.2) coffee-script (>= 2.2.0) @@ -164,6 +165,7 @@ best_in_place (~> 3.0.1) bootstrap-sass (~> 3.2.0) bootstrap-switch-rails + bootstrap-toggle-rails coffee-rails (~> 3.2.2) dynamic_form haml diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,7 +14,8 @@ //= require jquery_ujs //= require jquery.ui.all //= require bootstrap-sprockets -//= require bootstrap-switch +//x= require bootstrap-switch +//= require bootstrap-toggle //= require select2 //= require custom diff --git a/app/assets/javascripts/custom.js.coffee b/app/assets/javascripts/custom.js.coffee --- a/app/assets/javascripts/custom.js.coffee +++ b/app/assets/javascripts/custom.js.coffee @@ -13,7 +13,8 @@ $ -> $(".select2").select2() - $(".bootstrap-switch").bootstrapSwitch() + #$(".bootstrap-switch").bootstrapSwitch() + $(".bootstrap-toggle").bootstrapToggle() $('.btn-file :file').on 'fileselect', (event, numFiles, label) -> input = $(this).parents('.input-group').find(':text') log = if numFiles > 1 then numFiles + ' files selected' else label diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -30,7 +30,8 @@ @import bootstrap @import select2 @import select2-bootstrap -@import bootstrap3-switch +//@import bootstrap3-switch +@import bootstrap-toggle .secondnavbar top: 50px diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -69,14 +69,24 @@ if @announcement.update_attributes(params[:announcement]) flash[:notice] = 'Announcement was successfully updated.' format.html { redirect_to(@announcement) } + format.js {} format.xml { head :ok } else format.html { render :action => "edit" } + format.js {} format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } end end end + def toggle + @announcement = Announcement.find(params[:id]) + @announcement.update_attributes( published: params[:published] == 1) + respond_to do |format| + format.js {} + end + end + # DELETE /announcements/1 # DELETE /announcements/1.xml def destroy diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,6 +8,7 @@ # Returns the current logged-in user (if any). def current_user + return nil unless session[:user_id] @current_user ||= User.find(session[:user_id]) end diff --git a/app/views/announcements/index.html.erb b/app/views/announcements/index.html.erb --- a/app/views/announcements/index.html.erb +++ b/app/views/announcements/index.html.erb @@ -27,7 +27,7 @@ <%=h announcement.body %> <%=h announcement.author %> - <%= check_box_tag :published, 1, announcement.published, class: 'bootstrap-switch', data: {size: 'small'} %> + <%= check_box_tag :published, 1, announcement.published, { class: 'bootstrap-toggle', id: "published-#{announcement.id}", data: {remote: true, method: 'PUT', url: url_for(controller: :announcements, action: :toggle, id: announcement), size: 'small', toggle: 'toggle' } } %> <%= link_to 'Show', announcement %> <%= link_to 'Edit', edit_announcement_path(announcement) %> diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,8 @@ resources :contests resources :announcements + match 'announcements/toggle/:id' => 'announcements#toggle', via: :put + resources :sites resources :grader_configuration, controller: 'configurations'