-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
188 additions
and
57 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
56 changes: 35 additions & 21 deletions
56
app/controllers/publishers/vacancies/extend_deadline_controller.rb
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class Publishers::JobListing::RelistForm < Publishers::JobListing::ExtendDeadlineForm | ||
attr_reader :publish_on | ||
attr_writer :publish_on_day | ||
|
||
validates(:publish_on, date: { on_or_after: :today, on_or_before: :far_future }, unless: lambda do | ||
publish_on_day.blank? || (publish_on.is_a?(Date) && (publish_on.today? || publish_on.tomorrow?)) | ||
end) | ||
validates :publish_on_day, inclusion: { in: %w[today tomorrow another_day] } | ||
|
||
def initialize(params = {}) | ||
@params = params | ||
super | ||
end | ||
|
||
def attributes_to_save | ||
super.merge( | ||
publish_on: publish_on, | ||
) | ||
end | ||
|
||
def publish_on_day | ||
return "today" if @publish_on_day == "today" || publish_on == Date.today | ||
return "tomorrow" if @publish_on_day == "tomorrow" || publish_on == Date.tomorrow | ||
|
||
"another_day" if @publish_on_day == "another_day" || publish_on.is_a?(Date) | ||
end | ||
|
||
def publish_on=(value) | ||
@publish_on = | ||
case @params[:publish_on_day] | ||
when "today" then Date.today | ||
when "tomorrow" then Date.tomorrow | ||
else date_from_multiparameter_hash(value) | ||
end | ||
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
10 changes: 10 additions & 0 deletions
10
app/views/publishers/vacancies/base/_publish_date.html.slim
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,10 @@ | ||
= f.govuk_radio_buttons_fieldset :publish_on_day, legend: { size: "m", tag: nil } do | ||
= f.govuk_radio_button :publish_on_day, :today, link_errors: true, | ||
label: { text: t("helpers.label.publishers_job_listing_important_dates_form.publish_on_day_options.today", date: Time.now.strftime("%d %m %Y")) } | ||
= f.govuk_radio_button :publish_on_day, :tomorrow, | ||
label: { text: t("helpers.label.publishers_job_listing_important_dates_form.publish_on_day_options.tomorrow", date: 1.day.from_now.strftime("%d %m %Y")) } | ||
= f.govuk_radio_button :publish_on_day, :another_day, | ||
label: { text: t("helpers.label.publishers_job_listing_important_dates_form.publish_on_day_options.another_day") } do | ||
= f.govuk_date_field :publish_on, | ||
legend: { tag: nil, text: t("helpers.label.publishers_job_listing_important_dates_form.publish_on") }, | ||
hint: -> { t("helpers.hint.date", date: 1.week.from_now.to_fs(:publish_on_date)) } |
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
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.