Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5525 - Simplify Program Deletion Process #5583

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const AvailableActions = createReactClass({
}

const enteredTitle = prompt(I18n.t('courses.confirm_course_deletion', { title: this.props.course.title }));
if (enteredTitle.trim() === this.props.course.title.trim()) {
if (enteredTitle !== null && enteredTitle.trim() === this.props.course.title.trim()) {
return this.props.deleteCourse(this.props.course.slug);
} else if (enteredTitle) {
return alert(I18n.t('courses.confirm_course_deletion_failed', { title: enteredTitle }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const MarkAsIncompleteButton = (props) => {
className="button danger small"
onClick={update({ ...props, dispatch })}
>
Mark as Incomplete
{I18n.t('articles.mark_as_complete')}
</button>
</div>
);
Expand Down
18 changes: 18 additions & 0 deletions app/assets/javascripts/utils/course.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ document.onreadystatechange = () => {
});
}

const y = document.getElementsByClassName('delete-course-prerequisite')[0];
if (y) {
y.addEventListener('click', () => alert(I18n.t('campaign.delete_course_instructions_campaign')));
}

const z = document.getElementsByClassName('delete-course-from-campaign')[0];
if (z) {
z.addEventListener('click', (e) => {
const enteredTitle = window.prompt(I18n.t('courses.confirm_course_deletion', { title: e.target.dataset.title }));
if (!enteredTitle) {
e.preventDefault();
} else if (enteredTitle.trim() !== e.target.dataset.title.trim()) {
e.preventDefault();
alert(I18n.t('courses.confirm_course_deletion_failed', { title: enteredTitle }));
}
});
}

return document.querySelectorAll('select.sorts').forEach(item => item?.addEventListener('change', function () {
const list = (() => {
switch (this.getAttribute('rel')) {
Expand Down
5 changes: 4 additions & 1 deletion app/assets/stylesheets/_fonts.styl
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
color zircon

.red
color warning
color warning

.delete-course-prerequisite
margin 0px 24px 12px 24px !important;
18 changes: 15 additions & 3 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,21 @@ def update

def destroy
validate
DeleteCourseWorker.schedule_deletion(course: @course, current_user:)
render json: { success: true }
end
if params.key?(:campaign)
campaigns_course = CampaignsCourses.find_by(course_id: @course.id,
campaign_id: params[:campaign_id])
result = campaigns_course&.destroy
message = result ? 'campaign.course_removed' : 'campaign.course_already_removed'
flash[:notice] = t(message, title: @course.title,
campaign_title: params[:campaign_title])
end
DeleteCourseWorker.schedule_deletion(course: @course, current_user: current_user)
if params.key?(:campaign)
redirect_to programs_campaign_path(params[:slug])
else
render json: { success: true }
end
end

# /courses/school/title_(term)
# /courses/school/title_(term)/subpage
Expand Down
4 changes: 4 additions & 0 deletions app/presenters/courses_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def can_remove_course?
@can_remove ||= current_user&.admin? || campaign_organizer?
end

def can_delete_course?
@can_remove ||= current_user&.admin? || campaign_organizer?
end

def campaign_organizer?
return false unless campaign
return @campaign_organizer if @campaign_organizer_set
Expand Down
12 changes: 11 additions & 1 deletion app/views/campaigns/_course_row.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,15 @@
%a.course-link{:href => "#{course_slug_path(course.slug)}"}
= form_for(@campaign, url: remove_course_campaign_path(@campaign.slug, course_id: course.id), method: :put, id: "remove_course-#{course.id}", html: { class: 'remove-program-form' }) do
= hidden_field_tag('course_title', course.title, id: "course_title-#{course.id}")
%button.button.danger.remove-course{'data-id' => course.id, 'data-title' => course.title, 'data-campaign-title' => @campaign.title}
%button.button.danger.remove-course{ 'data-id' => course.id, 'data-title' => course.title, 'data-campaign-title' => @campaign.title, title: t('campaign.remove_course_tooltip') }
= t('assignments.remove')
- if @presenter&.can_delete_course?
- if course.campaigns.size > 1
%button.button.danger.delete-course-prerequisite{ 'data-id' => course.id, 'data-title' => course.title, 'data-campaign-title' => @campaign.title, title: t('campaign.delete_course_tooltip') }
= t('assignments.delete')
- else
%a.course-link{:href => "#{course_slug_path(course.slug)}", style: "padding-top: 0;"}
= form_for(@campaign, url: "/courses/#{course.slug}.json?campaign=true&campaign_title=#{@campaign.title}&campaign_id=#{@campaign.id}&slug=#{@campaign.slug}", method: :delete, id: "delete_course-#{course.id}", html: { class: 'delete-program-form' }) do
= hidden_field_tag('course_title', course.title, id: "course_title-#{course.id}")
%button.button.danger.delete-course-from-campaign{'data-id' => course.id, 'data-title' => course.title, 'data-campaign-title' => @campaign.title, title: t('campaign.delete_course_tooltip') }
= t('assignments.delete')
7 changes: 6 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ en:
history: (history)
label: Articles
loading: Loading articles...
mark_as_complete: Mark as Complete
new: (new)
none: This course has not edited any articles.
preview: Brief preview of Article
Expand Down Expand Up @@ -293,6 +294,7 @@ en:
confirm_add_available: Are you sure you want to add %{title}?
confirm_addition: Are you sure you want to assign %{title} to %{username}?
confirm_deletion: Are you sure you want to delete this assignment?
delete: Delete
editors: Assigned to
group_members: Group members
label: Assign
Expand Down Expand Up @@ -387,6 +389,8 @@ en:
default_passcode_explanation: "By default, new programs in this campaign should have:"
description: Description
delete_campaign: Delete this campaign
delete_course_tooltip: Delete and remove from the campaign.
delete_course_instructions_campaign: You may delete this course if all other campaigns are removed first.
disable_account_requests: Disable account requests
enable_account_requests: Enable account requests
newest_campaigns: Newest Campaigns
Expand All @@ -401,6 +405,7 @@ en:
When an organizer creates a program in this campaign,
the text in this area will be copied over as a description on the program page
random_passcode: a random passcode
remove_course_tooltip: Remove from campaign.
requested_accounts: Requested accounts
title: Title
too_many_articles: The edited article list for this campaign is too long to be displayed. Please view individual courses/programs/events to see the articles edited.
Expand Down Expand Up @@ -487,7 +492,7 @@ en:
campaign_courses: "%{title} Courses"
campaign_select: "Select a campaign"
campaign_users: "%{title} Editors"
confirm_course_deletion: Are you sure you want to delete the course titled %{title}? If so, type the title of the course to proceed.
confirm_course_deletion: 'Are you sure you want to delete the course titled %{title}? If so, type the title of the course to proceed.'
confirm_course_deletion_failed: '"%{title}" is not the title of this course. The course has not been deleted.'
confirm_manual_update: Are you sure you want to run a manual update? The most recent revisions will be imported and then the page will reload. This process may take some time.
controlled_by_event_center: Enrollment in this event is controlled by Wikimedia Event Center. It cannot be joined from the Dashboard.
Expand Down
Loading