From 00124e9566c5126f36a6df69b36417a90b59f86a Mon Sep 17 00:00:00 2001 From: Brian Whitmer Date: Mon, 7 Feb 2011 09:44:01 -0700 Subject: [PATCH] publish multiple quizzes at the same time When we import quizzes from another system we leave them all unpublished so the teacher can review the import results before publishing. This adds a "Publish Multiple Quizzes" button that will, well, publish multiple quizzes -- at the same time. fixes #3636 Change-Id: I9b762da0e938a0b2e1986e3bdb9a216dd5bc7142 Reviewed-on: https://gerrit.instructure.com/2175 Tested-by: Hudson Reviewed-by: Bracken Mosbacker --- app/controllers/quizzes_controller.rb | 14 ++++++++++++++ app/views/quizzes/_quiz_summary.html.erb | 1 + app/views/quizzes/index.html.erb | 21 ++++++++++++++++++++- config/routes.rb | 1 + public/javascripts/quiz_index.js | 24 ++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/app/controllers/quizzes_controller.rb b/app/controllers/quizzes_controller.rb index fd62f4601a1..a2c9b9d6985 100644 --- a/app/controllers/quizzes_controller.rb +++ b/app/controllers/quizzes_controller.rb @@ -176,6 +176,20 @@ class QuizzesController < ApplicationController end protected :take_quiz + def publish + if authorized_action(@context, @current_user, :manage_assignments) + @quizzes = @context.quizzes.active.find_all_by_id(params[:quizzes]).compact.select{|q| !q.available? } + @quizzes.each do |quiz| + quiz.generate_quiz_data + quiz.published_at = Time.now + quiz.workflow_state = 'available' + quiz.save + end + flash[:notice] = "#{@quizzes.length} quizzes successfully published!" + redirect_to named_context_url(@context, :context_quizzes_url) + end + end + def reorder if authorized_action(@quiz, @current_user, :update) items = [] diff --git a/app/views/quizzes/_quiz_summary.html.erb b/app/views/quizzes/_quiz_summary.html.erb index a18ced2a981..cc27859ce2b 100644 --- a/app/views/quizzes/_quiz_summary.html.erb +++ b/app/views/quizzes/_quiz_summary.html.erb @@ -15,6 +15,7 @@ <% end %> <%= q.quiz_title || q.readable_type %> + <% if q && q.assignment_id %> (<%= pluralize(q.assignment.points_possible, "pt") if q.assignment.points_possible %>) <% end %> diff --git a/app/views/quizzes/index.html.erb b/app/views/quizzes/index.html.erb index ebc3b2564bf..22718b0ae5a 100644 --- a/app/views/quizzes/index.html.erb +++ b/app/views/quizzes/index.html.erb @@ -9,6 +9,9 @@ <% if can_do(@context, @current_user, :manage_assignments) && feature_enabled?(:question_banks) %> <%= image_tag "edit.png" %> Manage Question Banks <% end %> + <% if can_do(@context, @current_user, :manage_assignments) && @unpublished_quizzes.length > 1 %> + Publish Multiple Quizzes + <% end %> <% end %> <% end %> @@ -40,9 +43,25 @@ ul.quiz_list li.quiz div.description { <% end %> <% if can_do(@context, @current_user, :manage_assignments) && @unpublished_quizzes && !@unpublished_quizzes.empty? %>

Unpublished Quizzes

-
    +
      <%= render :partial => "quiz_summary", :collection => @unpublished_quizzes, :locals => {:unpublished => true} %>
    + <% end %> <% if @assignment_quizzes.empty? && @open_quizzes.empty? %>

    Course Quizzes

    diff --git a/config/routes.rb b/config/routes.rb index 2a3425d792f..d003117151f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -165,6 +165,7 @@ ActionController::Routing::Routes.draw do |map| course.resources :assessment_questions do |question| question.move_question 'move', :controller => 'assessment_questions', :action => 'move' end + course.quizzes_publish 'quizzes/publish', :controller => 'quizzes', :action => 'publish' course.resources :quizzes do |quiz| quiz.reorder "reorder", :controller => "quizzes", :action => "reorder" quiz.history "history", :controller => "quizzes", :action => "history" diff --git a/public/javascripts/quiz_index.js b/public/javascripts/quiz_index.js index f675c4b4a10..db84a2e9718 100644 --- a/public/javascripts/quiz_index.js +++ b/public/javascripts/quiz_index.js @@ -27,6 +27,30 @@ $(document).ready(function() { } }); }); + $(".publish_multiple_quizzes_link").click(function(event) { + event.preventDefault(); + var $dialog = $("#publish_multiple_quizzes_dialog"); + var $template = $dialog.find(".quiz_item.blank:first").clone(true); + var $list = $dialog.find(".quiz_list").find(".quiz_item:not(.blank)").remove().end(); + $("#unpublished_quizzes .quiz").each(function() { + var $quiz_item = $template.clone(true); + var data = $(this).getTemplateData({textValues: ['quiz_id', 'quiz_title']}); + $quiz_item.find(".id").val(data.quiz_id).attr('id', 'quiz_checkbox_' + data.quiz_id).end() + .find(".title").text(data.quiz_title || 'Unnamed Quiz').attr('for', 'quiz_checkbox_' + data.quiz_id); + $list.append($quiz_item.show()); + }); + $dialog.find("button").attr('disabled', false); + $dialog.dialog('close').dialog({ + autoOpen: false, + width: 400 + }).dialog('open'); + }); + $("#publish_quizzes_form").submit(function() { + $(this).find("button").attr('disabled', true).filter('.submit_button').text('Publishing Quizzes...'); + }); + $("#publish_multiple_quizzes_dialog .cancel_button").click(function() { + $("#publish_multiple_quizzes_dialog").dialog('close'); + }); if($("#quiz_locks_url").length > 0) { var data = {}; var assets = [];