diff --git a/Gemfile b/Gemfile index e19fdc4df..509673e4e 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ gem 'acts_as_votable', '~> 0.11.1' gem 'ahoy_matey', '~> 1.6.0' gem 'ancestry', '~> 3.0.1' gem 'autoprefixer-rails', '~> 8.2.0' +gem 'best_in_place', '~> 3.0.1' gem 'browser', '~> 2.5.2' gem 'cancancan', '~> 2.1.2' gem 'ckeditor', '~> 4.2.3' diff --git a/Gemfile.lock b/Gemfile.lock index 98b2615df..1cbd74edf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,9 @@ GEM babel-source (>= 4.0, < 6) execjs (~> 2.0) bcrypt (3.1.11) + best_in_place (3.0.3) + actionpack (>= 3.2) + railties (>= 3.2) browser (2.5.2) builder (3.2.3) bullet (5.7.1) @@ -504,6 +507,7 @@ DEPENDENCIES ahoy_matey (~> 1.6.0) ancestry (~> 3.0.1) autoprefixer-rails (~> 8.2.0) + best_in_place (~> 3.0.1) browser (~> 2.5.2) bullet (~> 5.7.0) byebug (~> 10.0.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index cecb1803b..f9c38b1c6 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,6 +17,7 @@ //= require jquery-ui/widgets/autocomplete //= require jquery-ui/widgets/sortable //= require jquery-fileupload/basic +//= require best_in_place //= require foundation //= require turbolinks //= require ckeditor/loader @@ -81,6 +82,7 @@ //= require globalize //= require clipboard //= require clipboard_button +//= require best_in_place_initialize var initialize_modules = function() { App.Comments.initialize(); @@ -127,6 +129,7 @@ var initialize_modules = function() { App.Managers.initialize(); App.Globalize.initialize(); App.ClipboardButton.initialize(); + App.BestInPlace.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/best_in_place_initialize.js.coffee b/app/assets/javascripts/best_in_place_initialize.js.coffee new file mode 100644 index 000000000..2caaea1f1 --- /dev/null +++ b/app/assets/javascripts/best_in_place_initialize.js.coffee @@ -0,0 +1,3 @@ +App.BestInPlace = + initialize: -> + $('.best_in_place').best_in_place(); diff --git a/app/assets/javascripts/rem.min.js b/app/assets/javascripts/rem.min.js old mode 100755 new mode 100644 diff --git a/app/assets/javascripts/respond.min.js b/app/assets/javascripts/respond.min.js old mode 100755 new mode 100644 diff --git a/app/controllers/dashboard/polls_controller.rb b/app/controllers/dashboard/polls_controller.rb index 11d6612ac..360f99f60 100644 --- a/app/controllers/dashboard/polls_controller.rb +++ b/app/controllers/dashboard/polls_controller.rb @@ -34,10 +34,14 @@ class Dashboard::PollsController < Dashboard::BaseController def update authorize! :manage_polls, proposal - if poll.update(poll_params) - redirect_to proposal_dashboard_poll_path(proposal, poll), notice: t("flash.actions.update.poll") - else - render :edit + respond_to do |format| + if poll.update(poll_params) + format.html { redirect_to proposal_dashboard_poll_path(proposal, poll), notice: t("flash.actions.update.poll") } + format.json { respond_with_bip(poll) } + else + format.html { render :edit } + format.json { respond_with_bip(poll) } + end end end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 1e65978d6..071eab471 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -69,7 +69,7 @@ module Abilities can [:create, :destroy, :manage], ::Poll::BoothAssignment can [:create, :destroy], ::Poll::OfficerAssignment can [:read, :create, :update], Poll::Question - can :destroy, Poll::Question # , comments_count: 0, votes_up: 0 + can :destroy, Poll::Question can :manage, SiteCustomization::Page can :manage, SiteCustomization::Image diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 407615d6a..4acd2e18a 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -26,6 +26,10 @@ module Abilities proposal.author.id == user.id end + can :results, Poll do |poll| + poll.related&.author&.id == user.id + end + can [:retire_form, :retire], Proposal, author_id: user.id can :read, Legislation::Proposal diff --git a/app/views/dashboard/polls/_poll.html.erb b/app/views/dashboard/polls/_poll.html.erb index 40610cc98..3c6ff0b44 100644 --- a/app/views/dashboard/polls/_poll.html.erb +++ b/app/views/dashboard/polls/_poll.html.erb @@ -26,6 +26,20 @@ <% end %> +
+ <%= best_in_place poll, + :results_enabled, + as: :checkbox, + url: proposal_dashboard_poll_url(proposal, poll), + collection: { + false: raw(''), + true: raw('') + } %> + <%= t('.show_results') %> +
+<%= t('.show_results_help') %>
+