Add "Save & Publish" buttons (quizzes)

Fixes CNVS-18433

Test plan:
 - On the Quizzes page, hit "+ Quiz"
 - Enter a title for the quiz
 - Click the "Save & Publish" button and make sure that its text
   changes to "Saving", then to "Saved!"
 - Verify that the quiz has been published
 - Edit the quiz
 - Verify that the "Save & Publish" button no longer shows up
 - Unpublish the quiz, then edit it again
 - Verify that the "Save & Publish" button shows up again

Change-Id: Id19880cd619cd278950857c609bcee46aa0135ac
Reviewed-on: https://gerrit.instructure.com/48432
Tested-by: Jenkins
Reviewed-by: Ryan Taylor <rtaylor@instructure.com>
QA-Review: Amber Taniuchi <amber@instructure.com>
Product-Review: Hilary Scharton <hilary@instructure.com>
This commit is contained in:
Alex Boyd 2015-02-08 17:35:42 -07:00
parent 24bb77eb85
commit 6e370c4a9f
4 changed files with 50 additions and 6 deletions

View File

@ -403,6 +403,8 @@ class Quizzes::QuizzesController < ApplicationController
end
@quiz.reload
@quiz.update_quiz_submission_end_at_times if params[:quiz][:time_limit].present?
@quiz.publish! if params[:publish]
end
flash[:notice] = t('notices.quiz_updated', "Quiz successfully updated")
format.html { redirect_to named_context_url(@context, :context_quiz_url, @quiz) }

View File

@ -448,6 +448,9 @@
<%= link_to context_url(@context, :context_quiz_url, @quiz), :class => 'btn', :id => 'cancel_button' do %>
<%= t('links.cancel', "Cancel") %>
<% end %>
<% unless @quiz.published %>
<button type="submit" class="save_and_publish btn btn-publish"><%= t('buttons.save_and_publish', "Save & Publish") %></button>
<% end %>
<button type="submit" class="save_quiz_button btn btn-primary"><%= t('buttons.save', "Save") %></button>
</div>
</div>

View File

@ -1683,16 +1683,14 @@ define([
},
beforeSubmit: function(data) {
$quiz_edit_wrapper
.find(".btn.save_quiz_button")
.attr('disabled', true)
.text(I18n.t('buttons.saving', "Saving..."));
$quiz_edit_wrapper.find(".btn.save_quiz_button").attr('disabled', true);
$quiz_edit_wrapper.find(".btn.save_and_publish").attr('disabled', true);
},
success: function(data) {
var $form = $(this);
$quiz_edit_wrapper
.find(".btn.save_quiz_button")
.find(".btn.saving")
.text(I18n.t('buttons.saved', "Saved!"));
if (data.quiz.assignment) {
var assignment = data.quiz.assignment;
@ -1717,17 +1715,44 @@ define([
$("#quiz_edit_wrapper")
.find(".btn.save_quiz_button")
.attr('disabled', false)
.removeClass("saving")
.text(I18n.t('buttons.save', "Save"));
$("#quiz_edit_wrapper")
.find(".btn.save_and_publish")
.attr('disabled', false)
.removeClass("saving")
.text(I18n.t('buttons.save_and_publish', "Save & Publish"));
$("#quiz_edit_wrapper")
.find('input[name="publish"]')
.remove();
$(this).trigger('xhrError', data);
$(this).formErrors(data);
$quiz_edit_wrapper.find(".btn.save_quiz_button").attr('disabled', false);
}
});
$quiz_edit_wrapper.find(".save_quiz_button").click(function(event) {
event.preventDefault();
event.stopPropagation();
$quiz_edit_wrapper
.find(".btn.save_quiz_button")
.addClass("saving")
.text(I18n.t('buttons.saving', "Saving..."));
$quiz_options_form.data('submit_type', 'save_only').submit();
}).end();
$quiz_edit_wrapper.find(".save_and_publish").click(function(event) {
event.preventDefault();
event.stopPropagation();
var $publish_input = $(document.createElement('input'));
$publish_input.attr('type', 'hidden').attr('name', 'publish').attr('value', 'true');
$quiz_options_form.append($publish_input);
$quiz_edit_wrapper
.find(".btn.save_and_publish")
.addClass("saving")
.text(I18n.t('buttons.saving', "Saving..."));
$quiz_options_form.data('submit_type', 'save_only').submit();
}).end();

View File

@ -966,6 +966,20 @@ describe Quizzes::QuizzesController do
expect(assigns[:quiz].title).to eql("some quiz")
end
it "should publish if asked to" do
user_session(@teacher)
course_quiz
post 'update', :course_id => @course.id, :id => @quiz.id, :quiz => {:title => "some quiz"}, :publish => 'true'
expect(@quiz.reload.published).to be(true)
end
it "should not publish if not asked to" do
user_session(@teacher)
course_quiz
post 'update', :course_id => @course.id, :id => @quiz.id, :quiz => {:title => "some quiz"}
expect(@quiz.reload.published).to be(false)
end
context 'post_to_sis' do
before { @course.enable_feature!(:post_grades) }