-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from alphagov/save-and-transition-in-one-go
Save and transition editions in one go
- Loading branch information
Showing
34 changed files
with
300 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,5 +53,5 @@ def friendly_date(date) | |
end | ||
|
||
include PathsHelper | ||
include ProgressFormsHelper | ||
include EditionActivityHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module EditionActivityButtonsHelper | ||
|
||
def build_review_button(edition, activity, title) | ||
check_method = "can_#{activity}?".to_sym | ||
enabled = edition.send(check_method) | ||
|
||
link_to title, "##{activity}_form", data: { toggle: 'modal'}, | ||
class: "btn btn-info #{"disabled" if !enabled} add-top-margin" | ||
end | ||
|
||
def review_buttons(edition) | ||
[ | ||
["Needs more work", "request_amendments"], | ||
["OK for publication", "approve_review"] | ||
].map{ |title, activity| | ||
build_review_button(edition, activity, title) | ||
}.join("\n").html_safe | ||
end | ||
|
||
def fact_check_buttons(edition) | ||
[ | ||
["Needs major changes", "request_amendments"], | ||
["Minor or no changes required", "approve_fact_check"] | ||
].map{ |title, activity| | ||
build_review_button(edition, activity, title) | ||
}.join("\n").html_safe | ||
end | ||
|
||
def progress_buttons(edition, options = {}) | ||
[ | ||
["Fact check", "send_fact_check"], | ||
["2nd pair of eyes", "request_review"], | ||
*scheduled_publishing_buttons(edition), | ||
["Publish", "publish"], | ||
].map { |title, activity, button_color = 'primary'| | ||
enabled = edition.send("can_#{activity}?") | ||
show_disabled = options.fetch(:show_disabled, true) | ||
next unless show_disabled || enabled | ||
|
||
link_to title, "##{activity}_form", data: { toggle: 'modal'}, | ||
class: "btn btn-large btn-#{button_color} #{"disabled" if !enabled}" | ||
}.join("\n").html_safe | ||
end | ||
|
||
def scheduled_publishing_buttons(edition) | ||
buttons = [] | ||
buttons << ["Schedule", "schedule_for_publishing", 'warning'] if edition.can_schedule_for_publishing? | ||
buttons << ["Cancel scheduled publishing", "cancel_scheduled_publishing", 'danger'] if edition.can_cancel_scheduled_publishing? | ||
buttons | ||
end | ||
|
||
def preview_button(edition) | ||
link_to('Preview', preview_edition_path(edition), class: 'btn btn-primary btn-large') | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module EditionActivityHelper | ||
def edition_activities_fields(f, edition) | ||
activities_fields = Edition::BASIC_EVENTS.map do |activity, title| | ||
content_tag(:div, modal_attributes.merge(id: "#{activity}_form")) do | ||
edition_activity_fields(edition, title, activity, f, inline: true) | ||
end | ||
end | ||
|
||
activities_fields.join("\n").html_safe | ||
end | ||
|
||
def edition_activities_forms(edition, activities) | ||
activities_forms = activities.map do |activity, title| | ||
semantic_form_for(:edition, url: progress_edition_path(edition), | ||
html: modal_attributes.merge(id: "#{activity}_form")) do |f| | ||
edition_activity_fields(edition, title, activity, f, inline: false) | ||
end | ||
end | ||
|
||
activities_forms.join("\n").html_safe | ||
end | ||
|
||
def edition_activity_fields(edition, title, activity, form_builder, options) | ||
render( | ||
:partial => 'shared/edition_activity_fields', | ||
:locals => { | ||
:form_builder => form_builder, :title => title, :activity => activity, | ||
:inline => options[:inline], :disabled => !edition.send("can_#{activity}?".to_sym) | ||
} | ||
) | ||
end | ||
|
||
def review_forms(edition) | ||
edition_activities_forms(edition, Edition::REVIEW_EVENTS) | ||
end | ||
|
||
def fact_check_forms(edition) | ||
edition_activities_forms(edition, Edition::FACT_CHECK_EVENTS) | ||
end | ||
|
||
def modal_attributes | ||
{ :role => 'dialog', :class => 'modal', :tabindex => -1, 'aria-hidden' => true } | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<%= semantic_form_for @resource, :url => edition_path(@resource), :as => :edition, :html => { :id => 'edition-form' } do |f| %> | ||
<%= f.inputs do %> | ||
<%= render :partial => 'shared/title_etc', :locals => {:f => f} %> | ||
<%= render :partial => 'shared/common_edition_attributes', :locals => {:f => f} %> | ||
<div class="row"> | ||
<div class="col-md-10"> | ||
<%= f.input :body, :as => :text, :input_html => { :disabled => @resource.locked_for_edits? } %> | ||
</div> | ||
</div> | ||
<% end %> | ||
|
||
<%= render partial: 'shared/workflow_buttons', locals: { f: f } %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.