diff --git a/Gemfile b/Gemfile index b2a23adb..14d7aabb 100644 --- a/Gemfile +++ b/Gemfile @@ -121,6 +121,9 @@ gem 'money-rails' # for lists gem 'acts_as_list' +# for switch checkboxes +gem 'bootstrap-switch-rails', '~> 3.0.0' + # Use guard and spring for testing in development group :development do # rspec Guard rules diff --git a/Gemfile.lock b/Gemfile.lock index c9cce0ee..5025f714 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -70,6 +70,7 @@ GEM bcrypt (3.1.7) bootstrap-sass (3.3.1.0) sass (~> 3.2) + bootstrap-switch-rails (3.0.2) bootstrap3-datetimepicker-rails (3.0.3) momentjs-rails (>= 2.8.1) browser (0.6.0) @@ -438,6 +439,7 @@ DEPENDENCIES awesome_nested_set (~> 3.0.0.rc.5) axlsx_rails bootstrap-sass + bootstrap-switch-rails (~> 3.0.0) bootstrap3-datetimepicker-rails (~> 3.0.2) byebug cancancan diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 0370bfd9..2ec6c867 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -34,6 +34,7 @@ //= require osem-datepickers //= require osem-datatables //= require osem-tickets +//= require bootstrap-switch $(document).ready(function() { $('a[disabled=disabled]').click(function(event){ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 4ff9cf5d..9a771225 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,4 +13,5 @@ *= require bootstrap-markdown.min *= require bootstrap-datetimepicker *= require leaflet + *= require bootstrap3-switch */ diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 0747dfae..298b5cd7 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -106,9 +106,14 @@ module Admin def update if @event.submitter.update_attributes(params[:user]) && - @event.update_attributes(params[:event]) + @event.update_attributes(params[:event]) + + if request.xhr? + render js: 'index' + else flash[:notice] = "Successfully updated event with ID #{@event.id}." redirect_back_or_to(admin_conference_event_path(@conference.short_title, @event)) + end else @url = admin_conference_event_path(@conference.short_title, @event) flash[:notice] = 'Update not successful. ' + @event.errors.full_messages.to_sentence diff --git a/app/views/admin/events/_proposal.html.haml b/app/views/admin/events/_proposal.html.haml index 1d3b6398..d912b1d8 100644 --- a/app/views/admin/events/_proposal.html.haml +++ b/app/views/admin/events/_proposal.html.haml @@ -32,15 +32,9 @@ %td %b Highlight %td - = link_to "#{@event.is_highlight}".capitalize, - admin_conference_event_path(@conference.short_title, - @event, - event: { is_highlight: !@event.is_highlight }), - method: :patch - - if @event.is_highlight - (the event is as a highlight and will appear in the splashpage) - - else - (mark as true to make the event a highlight that appears in the splashpage) + = check_box_tag @conference.short_title, @event.id, @event.is_highlight, class: 'switch-checkbox', + data: { size: "small" } + %tr %td %b State diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index ab300d0e..15d7510d 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -22,6 +22,8 @@ %b Submitter %th %b Speaker + %th + %b Highlight %th %b Type %th @@ -70,6 +72,10 @@ = link_to speaker.name, admin_user_path(speaker) - else Unknown speaker + %td + = check_box_tag @conference.short_title, event.id, event.is_highlight, class: 'switch-checkbox', + data: { size: "small" } + %td .btn-group %button{:type=>"button", :class=>"btn btn-link dropdown-toggle", "data-toggle"=>"dropdown"} diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index a2eb5b4c..6f9e2a1a 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -15,6 +15,23 @@ detectlang: true, autocollect: true }; + + $(document).ready(function() { + $("[class='switch-checkbox']").bootstrapSwitch(); + }); + + $(document).ready(function() { + $('input[class="switch-checkbox"]').on('switchChange.bootstrapSwitch', function(event, state) { + url = "/admin/conference/" + this.name + "/events/" + this.value + + $.ajax({ + url: url, + type: 'PATCH', + data: { event: { is_highlight: state } }, + dataType: "script" + }); + }); + }); = content_for(:script_head) =# javascript_include_tag "//cdn.transifex.com/live.js" diff --git a/app/views/proposal/_proposal_form.html.haml b/app/views/proposal/_proposal_form.html.haml index 6ad68fa2..6fcd0c05 100644 --- a/app/views/proposal/_proposal_form.html.haml +++ b/app/views/proposal/_proposal_form.html.haml @@ -16,8 +16,12 @@ include_blank: false, label: 'Session Type' - else Event type: #{@event.event_type.title} - %br - %br + + %br + = f.label :is_highlight + = f.check_box :is_highlight, class: 'switch-checkbox', data: { size: "small" } + + %br = f.input :difficulty_level, :as => :select, :collection => @conference.difficulty_levels, :include_blank => "(Please select)" if @conference.difficulty_levels.any? = f.input :require_registration = f.input :abstract, :input_html => {:rows => 5, :class => "span11"},