diff --git a/app/assets/javascripts/projects.js.coffee b/app/assets/javascripts/projects.js.coffee index 158c95e1..55a66ac3 100644 --- a/app/assets/javascripts/projects.js.coffee +++ b/app/assets/javascripts/projects.js.coffee @@ -21,6 +21,7 @@ mark_as_winner_before_send = (event, data, xhr) -> mark_as_winner_success = (event, data, status, xhr) -> project_container = $('article[data-id="'+data.project_id+'"]') + if data.winner project_container.addClass('winner') project_container.find('a.mark-as-winner').attr('data-method', 'delete') @@ -46,7 +47,7 @@ $(".short-list") .bind("ajax:success", shortlist_success) .bind("ajax:failure", shortlist_failure) -$(".mark-as-winner") +$(".mark-as-winner, .remove-as-winner") .bind("ajax:beforeSend", mark_as_winner_before_send) .bind("ajax:success", mark_as_winner_success) .bind("ajax:failure", mark_as_winner_failure) diff --git a/app/assets/stylesheets/_projects-index.scss b/app/assets/stylesheets/_projects-index.scss index ab0d44bd..0e840131 100644 --- a/app/assets/stylesheets/_projects-index.scss +++ b/app/assets/stylesheets/_projects-index.scss @@ -460,7 +460,10 @@ body.projects-index { } } - &.edit-winner { + &.non-winner-action { + display: block; + } + &.winner-action { display: none; } } @@ -590,9 +593,12 @@ body.projects-index { color: $blue; font-weight: bolder; } - li.edit-winner { + li.winner-action { display: block; } + li.non-winner-action { + display: none; + } } div.title { diff --git a/app/assets/stylesheets/_winners.scss b/app/assets/stylesheets/_winners.scss new file mode 100644 index 00000000..90c72c6e --- /dev/null +++ b/app/assets/stylesheets/_winners.scss @@ -0,0 +1,14 @@ +.center-form__cancel { + text-align: center; +} + +.center-form__cancel-link { + color: $lighter-base-font-color !important; + font-size: .85em; + + text-decoration: none !important; + + &:hover { + text-decoration: underline !important; + } +} diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index e7e7dd64..ce8a2868 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -30,6 +30,7 @@ @import 'shared-flash-messages'; @import 'about'; @import 'faq'; +@import 'winners'; @import 'pagination'; @import 'magnific-popup'; diff --git a/app/controllers/winners_controller.rb b/app/controllers/winners_controller.rb index 552ef974..524238bc 100644 --- a/app/controllers/winners_controller.rb +++ b/app/controllers/winners_controller.rb @@ -1,5 +1,5 @@ class WinnersController < ApplicationController - before_action :must_be_able_to_mark_winner + before_action :must_be_able_to_mark_winner, only: [:create, :update, :destroy] def create @project = Project.find(params[:project_id]) @@ -9,6 +9,27 @@ def create render :json => response_json end + def edit + @project = FundedProject.find(params[:project_id]) + @project.funded_description = @project.about_project if @project.funded_description.blank? + end + + def update + @project = FundedProject.find(params[:project_id]) + @project.attributes = winner_params + + if @project.save + if @project.chapter_id_previously_changed? || params[:return_to].blank? + redirect_to chapter_project_path(@project.chapter, @project) + else + redirect_to params[:return_to] + end + else + flash.now[:notice] = t("flash.projects.error") + render action: "edit" + end + end + def destroy @project = Project.find(params[:project_id]) @project.revoke_winner! @@ -17,9 +38,20 @@ def destroy private + def winner_params + permitted = [:funded_on, :title, :name, :url, :rss_feed_url, :funded_description, photo_ids_to_delete: [], new_photos: [], new_photo_direct_upload_urls: [] ] + permitted << :chapter_id if current_project.in_any_chapter? || current_user.admin? + + params.require(:project).permit(permitted) + end + def winning_chapter if params[:chapter_id].present? @chapter ||= Chapter.find(params[:chapter_id]) + elsif params.dig(:project, :chapter_id).present? + @chapter ||= Chapter.find(params[:project][:chapter_id]) + else + @chapter ||= current_project.chapter end end @@ -28,9 +60,14 @@ def current_project end def must_be_able_to_mark_winner - unless current_user.admin? || (current_user.can_mark_winner?(current_project) && current_user.chapters.include?(winning_chapter)) + unless current_user.can_mark_winner?(current_project) && current_user.chapters.include?(winning_chapter) flash[:notice] = t("flash.permissions.cannot-mark-winner") - render :json => { :location => chapter_projects_path(current_project.chapter) } + redirect_location = chapter_projects_path(current_project.chapter) + + respond_to do |format| + format.js { render json: { :location => redirect_location } } + format.html { redirect_to redirect_location and return } + end end end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index d19fd3b2..3b503da3 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -8,6 +8,14 @@ def selectable_chapters_for(user) end end + def winnable_chapters_for(project) + if current_user.admin? + Chapter.visitable.for_display + else + project.in_any_chapter? ? current_user.dean_chapters : Array(project.chapter) + end + end + def show_winner_buttons_for(project, options = {}) if @chapter.any_chapter? winnable_chapters = current_user.dean_chapters diff --git a/app/models/funded_project.rb b/app/models/funded_project.rb new file mode 100644 index 00000000..a5caa7c5 --- /dev/null +++ b/app/models/funded_project.rb @@ -0,0 +1,3 @@ +class FundedProject < Project + validates :funded_on, presence: true +end diff --git a/app/models/project.rb b/app/models/project.rb index aa949fe6..9aa3210d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,6 +1,8 @@ require "textacular/searchable" class Project < ApplicationRecord + MAX_PHOTOS = 5 + attr_accessor :photo_order attr_accessor :photo_ids_to_delete diff --git a/app/views/projects/_form.html.erb b/app/views/projects/_form.html.erb index 762d66f0..fd1bc809 100644 --- a/app/views/projects/_form.html.erb +++ b/app/views/projects/_form.html.erb @@ -27,29 +27,7 @@ -
- <% if form.object.photos.present? %> -
- - -
- <% end %> - - <% if s3_uploader_available? %> - <%= render :partial => "image_form", :locals => { :form => form, :upload_mechanism => :s3 } %> - <% else %> - <%= render :partial => "image_form", :locals => { :form => form, :upload_mechanism => :classic } %> - <% end %> - -
+<%= render partial: "image_upload", locals: { form: form } %>