2011-02-01 09:57:29 +08:00
/ * *
* Copyright ( C ) 2011 Instructure , Inc .
*
* This file is part of Canvas .
*
* Canvas is free software : you can redistribute it and / or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation , version 3 of the License .
*
* Canvas is distributed in the hope that it will be useful , but WITHOUT ANY
* WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE . See the GNU Affero General Public License for more
* details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
2012-03-06 01:37:09 +08:00
define ( [
2011-11-11 00:31:45 +08:00
'i18n!quizzes.show' ,
'jquery' /* $ */ ,
2013-03-22 04:49:35 +08:00
'compiled/views/MessageStudentsDialog' ,
2012-08-15 03:59:38 +08:00
'quiz_arrows' ,
'quiz_inputs' ,
2013-06-29 07:12:58 +08:00
'compiled/models/Quiz' ,
2013-06-15 01:39:23 +08:00
'compiled/views/PublishButtonView' ,
2014-12-13 05:25:02 +08:00
'compiled/quizzes/dump_events' ,
2016-09-29 14:06:20 +08:00
'jsx/conditional_release_stats/index' ,
2011-11-11 00:31:45 +08:00
'jquery.instructure_date_and_time' /* dateString, time_field, datetime_field */ ,
2012-04-07 01:02:00 +08:00
'jqueryui/dialog' ,
2013-03-22 04:49:35 +08:00
'compiled/jquery/fixDialogButtons' ,
'compiled/jquery.rails_flash_notifications' ,
2011-11-11 00:31:45 +08:00
'jquery.instructure_misc_plugins' /* ifExists, confirmDelete */ ,
2013-02-28 07:07:34 +08:00
'jquery.disableWhileLoading' ,
2011-11-11 00:31:45 +08:00
'message_students' /* messageStudents */
2016-09-29 14:06:20 +08:00
] , function ( I18n , $ , MessageStudentsDialog , QuizArrowApplicator , inputMethods , Quiz , PublishButtonView , QuizLogAuditingEventDumper , CyoeStats ) {
2013-06-08 03:25:57 +08:00
$ ( document ) . ready ( function ( ) {
2015-05-29 10:40:35 +08:00
if ( ENV . QUIZ _SUBMISSION _EVENTS _URL ) {
QuizLogAuditingEventDumper ( true ) ;
}
2013-06-08 03:25:57 +08:00
2015-08-28 06:12:39 +08:00
$ ( '#preview_quiz_button' ) . click ( function ( e ) {
$ ( '#js-sequential-warning-dialogue div a' ) . attr ( 'href' , $ ( '#preview_quiz_button' ) . attr ( 'href' ) ) ;
} ) ;
2013-06-08 03:25:57 +08:00
function ensureStudentsLoaded ( callback ) {
if ( $ ( '#quiz_details' ) . length ) {
return callback ( ) ;
} else {
2014-12-19 17:35:02 +08:00
return $ . get ( $ ( "#quiz_details_wrapper" ) . data ( 'url' ) , function ( html ) {
$ ( "#quiz_details_wrapper" ) . html ( html ) ;
2013-06-08 03:25:57 +08:00
callback ( ) ;
} ) ;
2016-09-29 14:06:20 +08:00
}
2011-06-23 06:26:54 +08:00
}
2013-06-08 03:25:57 +08:00
2016-03-12 05:11:36 +08:00
var arrowApplicator = new QuizArrowApplicator ( ) ;
arrowApplicator . applyArrows ( ) ;
2014-05-06 07:41:51 +08:00
// quiz_show is being pulled into ember show for now. only hide inputs
// when we don't have a .allow-inputs
if ( ! $ ( '.allow-inputs' ) . length ) {
inputMethods . disableInputs ( '[type=radio], [type=checkbox]' ) ;
inputMethods . setWidths ( ) ;
}
2013-06-08 03:25:57 +08:00
2014-03-12 01:44:33 +08:00
$ ( 'form.edit_quizzes_quiz' ) . on ( 'submit' , function ( e ) {
e . preventDefault ( ) ;
e . stopImmediatePropagation ( ) ;
$ ( this ) . find ( '.loading' ) . removeClass ( 'hidden' ) ;
var data = $ ( this ) . serializeArray ( ) ;
var url = $ ( this ) . attr ( 'action' ) ;
$ . ajax ( {
url : url ,
data : data ,
type : 'POST' ,
success : function ( ) {
$ ( '.edit_quizzes_quiz' ) . parents ( '.alert' ) . hide ( ) ;
}
} ) ;
} ) ;
2013-06-08 03:25:57 +08:00
$ ( ".delete_quiz_link" ) . click ( function ( event ) {
event . preventDefault ( ) ;
var deleteConfirmMessage = I18n . t ( 'confirms.delete_quiz' , "Are you sure you want to delete this quiz?" ) ;
submittedCount = parseInt ( $ ( '#quiz_details_wrapper' ) . data ( 'submitted-count' ) ) ;
if ( submittedCount > 0 ) {
deleteConfirmMessage += "\n\n" + I18n . t ( 'confirms.delete_quiz_submissions_warning' ,
{ 'one' : "Warning: 1 student has already taken this quiz. If you delete it, any completed submissions will be deleted and no longer appear in the gradebook." ,
'other' : "Warning: %{count} students have already taken this quiz. If you delete it, any completed submissions will be deleted and no longer appear in the gradebook." } ,
{ 'count' : submittedCount } ) ;
2011-02-01 09:57:29 +08:00
}
2013-06-08 03:25:57 +08:00
$ ( "nothing" ) . confirmDelete ( {
url : $ ( this ) . attr ( 'href' ) ,
message : deleteConfirmMessage ,
success : function ( ) {
window . location . href = ENV . QUIZZES _URL ;
}
} ) ;
2011-02-01 09:57:29 +08:00
} ) ;
2013-06-08 03:25:57 +08:00
var hasOpenedQuizDetails = false ;
$ ( ".quiz_details_link" ) . click ( function ( event ) {
event . preventDefault ( ) ;
$ ( "#quiz_details_wrapper" ) . disableWhileLoading (
ensureStudentsLoaded ( function ( ) {
var $quizResultsText = $ ( '#quiz_details_text' ) ;
$ ( "#quiz_details" ) . slideToggle ( ) ;
if ( hasOpenedQuizDetails ) {
if ( ENV . IS _SURVEY ) {
$quizResultsText . text ( I18n . t ( 'links.show_student_survey_results' ,
'Show Student Survey Results' ) ) ;
} else {
$quizResultsText . text ( I18n . t ( 'links.show_student_quiz_results' ,
'Show Student Quiz Results' ) ) ;
}
2013-03-21 05:22:29 +08:00
} else {
2013-06-08 03:25:57 +08:00
if ( ENV . IS _SURVEY ) {
$quizResultsText . text ( I18n . t ( 'links.hide_student_survey_results' ,
'Hide Student Survey Results' ) ) ;
} else {
$quizResultsText . text ( I18n . t ( 'links.hide_student_quiz_results' ,
'Hide Student Quiz Results' ) ) ;
}
2013-03-21 05:22:29 +08:00
}
2013-06-08 03:25:57 +08:00
hasOpenedQuizDetails = ! hasOpenedQuizDetails ;
} )
) ;
} ) ;
$ ( ".message_students_link" ) . click ( function ( event ) {
event . preventDefault ( ) ;
ensureStudentsLoaded ( function ( ) {
var submissionList = ENV . QUIZ _SUBMISSION _LIST ;
var unsubmittedStudents = submissionList . UNSUBMITTED _STUDENTS ;
var submittedStudents = submissionList . SUBMITTED _STUDENTS ;
var haveTakenQuiz = I18n . t ( 'students_who_have_taken_the_quiz' , "Students who have taken the quiz" ) ;
var haveNotTakenQuiz = I18n . t ( 'students_who_have_not_taken_the_quiz' , "Students who have NOT taken the quiz" ) ;
var dialog = new MessageStudentsDialog ( {
context : ENV . QUIZ . title ,
recipientGroups : [
{ name : haveTakenQuiz , recipients : submittedStudents } ,
{ name : haveNotTakenQuiz , recipients : unsubmittedStudents }
]
} ) ;
dialog . open ( ) ;
} ) ;
} ) ;
$ ( "#let_students_take_this_quiz_button" ) . ifExists ( function ( $link ) {
var $unlock _for _how _long _dialog = $ ( "#unlock_for_how_long_dialog" ) ;
$link . click ( function ( ) {
$unlock _for _how _long _dialog . dialog ( 'open' ) ;
return false ;
} ) ;
don't parse datetime_suggest for getFormData
refs CNVS-19515
getFormData (and things that use its result, e.g. processData on formSubmit)
now returns iso8601 values for datetime_fields instead of the formatted suggest
string. this means they no longer need to be parsed and reformatted before
submission from forms, inclusion in redirect parameters, etc.
to support this, and for general use, a datetime_field now has two additional
data attributes:
iso8601: an iso8601 formatting version of the unfudged date value
invalid: a boolean indicating if the form had an invalid input (distinct from
valid but blank input; both would cause the date data attribute to
be null)
also removed a couple calls to getFormData that weren't even used
also cleans up some nearby code around the "course concludes at midnight"
warning, so that it displays if the conclude_at is set to midnight in the
context timezone (or profile timezone if no context timezone) instead
midnight in the browser timezone.
test-plan:
- regression tests, particularly around browser vs. profile timezone,
for:
* setting term start/end dates
* setting course start/conclude dates
* setting section start/end dates
* setting unlock at on new context module
* "add assignment" form from the assignment list:
- preservation of due date when clicking "more options"
- setting due date on form submission
* editing assignment due date from calendar
* editing assignment overridden due date from calendar
* create a quiz, lock it, then unlock it until a specific date
* changing attachment and folder lock/unlock dates
- set profile timezone to differ from browser timezone. set course
conclude at to midnight in profile timezone; should show "course
ends at midnight" warning
- set course conclude at to midnight in browser timezone; should not
show "course ends at midnight" warning
- set course timezone to differ from profile timezone. set course
conclude at to midnight in course timezone; should show "course ends
at midnight" warning
- set course conclude at to midnight in profile timezone; should not
show "course ends at midnight" warning
Change-Id: I55179d4416eb07cdda0e94abc79d2c9f948a5387
Reviewed-on: https://gerrit.instructure.com/53188
Tested-by: Jenkins
Reviewed-by: Ethan Vizitei <evizitei@instructure.com>
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Product-Review: Jacob Fugal <jacob@instructure.com>
2015-04-10 01:06:47 +08:00
var $lock _at = $ ( this ) . find ( '.datetime_field' ) ;
2013-06-08 03:25:57 +08:00
$unlock _for _how _long _dialog . dialog ( {
autoOpen : false ,
modal : true ,
resizable : false ,
width : 400 ,
buttons : {
'Unlock' : function ( ) {
$ ( '#quiz_unlock_form' )
// append this back to the form since it got moved to be a child of body when we called .dialog('open')
. append ( $ ( this ) . dialog ( 'destroy' ) )
don't parse datetime_suggest for getFormData
refs CNVS-19515
getFormData (and things that use its result, e.g. processData on formSubmit)
now returns iso8601 values for datetime_fields instead of the formatted suggest
string. this means they no longer need to be parsed and reformatted before
submission from forms, inclusion in redirect parameters, etc.
to support this, and for general use, a datetime_field now has two additional
data attributes:
iso8601: an iso8601 formatting version of the unfudged date value
invalid: a boolean indicating if the form had an invalid input (distinct from
valid but blank input; both would cause the date data attribute to
be null)
also removed a couple calls to getFormData that weren't even used
also cleans up some nearby code around the "course concludes at midnight"
warning, so that it displays if the conclude_at is set to midnight in the
context timezone (or profile timezone if no context timezone) instead
midnight in the browser timezone.
test-plan:
- regression tests, particularly around browser vs. profile timezone,
for:
* setting term start/end dates
* setting course start/conclude dates
* setting section start/end dates
* setting unlock at on new context module
* "add assignment" form from the assignment list:
- preservation of due date when clicking "more options"
- setting due date on form submission
* editing assignment due date from calendar
* editing assignment overridden due date from calendar
* create a quiz, lock it, then unlock it until a specific date
* changing attachment and folder lock/unlock dates
- set profile timezone to differ from browser timezone. set course
conclude at to midnight in profile timezone; should show "course
ends at midnight" warning
- set course conclude at to midnight in browser timezone; should not
show "course ends at midnight" warning
- set course timezone to differ from profile timezone. set course
conclude at to midnight in course timezone; should show "course ends
at midnight" warning
- set course conclude at to midnight in profile timezone; should not
show "course ends at midnight" warning
Change-Id: I55179d4416eb07cdda0e94abc79d2c9f948a5387
Reviewed-on: https://gerrit.instructure.com/53188
Tested-by: Jenkins
Reviewed-by: Ethan Vizitei <evizitei@instructure.com>
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Product-Review: Jacob Fugal <jacob@instructure.com>
2015-04-10 01:06:47 +08:00
. find ( '#quiz_lock_at' ) . val ( $lock _at . data ( 'iso8601' ) ) . end ( )
2013-06-08 03:25:57 +08:00
. submit ( ) ;
2013-03-21 05:22:29 +08:00
}
}
don't parse datetime_suggest for getFormData
refs CNVS-19515
getFormData (and things that use its result, e.g. processData on formSubmit)
now returns iso8601 values for datetime_fields instead of the formatted suggest
string. this means they no longer need to be parsed and reformatted before
submission from forms, inclusion in redirect parameters, etc.
to support this, and for general use, a datetime_field now has two additional
data attributes:
iso8601: an iso8601 formatting version of the unfudged date value
invalid: a boolean indicating if the form had an invalid input (distinct from
valid but blank input; both would cause the date data attribute to
be null)
also removed a couple calls to getFormData that weren't even used
also cleans up some nearby code around the "course concludes at midnight"
warning, so that it displays if the conclude_at is set to midnight in the
context timezone (or profile timezone if no context timezone) instead
midnight in the browser timezone.
test-plan:
- regression tests, particularly around browser vs. profile timezone,
for:
* setting term start/end dates
* setting course start/conclude dates
* setting section start/end dates
* setting unlock at on new context module
* "add assignment" form from the assignment list:
- preservation of due date when clicking "more options"
- setting due date on form submission
* editing assignment due date from calendar
* editing assignment overridden due date from calendar
* create a quiz, lock it, then unlock it until a specific date
* changing attachment and folder lock/unlock dates
- set profile timezone to differ from browser timezone. set course
conclude at to midnight in profile timezone; should show "course
ends at midnight" warning
- set course conclude at to midnight in browser timezone; should not
show "course ends at midnight" warning
- set course timezone to differ from profile timezone. set course
conclude at to midnight in course timezone; should show "course ends
at midnight" warning
- set course conclude at to midnight in profile timezone; should not
show "course ends at midnight" warning
Change-Id: I55179d4416eb07cdda0e94abc79d2c9f948a5387
Reviewed-on: https://gerrit.instructure.com/53188
Tested-by: Jenkins
Reviewed-by: Ethan Vizitei <evizitei@instructure.com>
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Product-Review: Jacob Fugal <jacob@instructure.com>
2015-04-10 01:06:47 +08:00
} ) ;
$lock _at . datetime _field ( ) ;
2013-03-22 04:49:35 +08:00
} ) ;
2013-06-08 03:25:57 +08:00
$ ( '#lock_this_quiz_now_link' ) . ifExists ( function ( $link ) {
$link . click ( function ( e ) {
e . preventDefault ( ) ;
$ ( '#quiz_lock_form' ) . submit ( ) ;
} )
2011-02-01 09:57:29 +08:00
} ) ;
2013-06-08 03:25:57 +08:00
if ( $ ( 'ul.page-action-list' ) . find ( 'li' ) . length > 0 ) {
$ ( 'ul.page-action-list' ) . show ( ) ;
}
$ ( '#publish_quiz_form' ) . formSubmit ( {
beforeSubmit : function ( data ) {
$ ( this ) . find ( 'button' ) . attr ( 'disabled' , true ) . text ( I18n . t ( 'buttons.publishing' , "Publishing..." ) ) ;
} ,
success : function ( data ) {
$ ( this ) . find ( 'button' ) . text ( I18n . t ( 'buttons.already_published' , "Published!" ) ) ;
location . reload ( ) ;
2011-02-01 09:57:29 +08:00
}
2013-06-08 03:25:57 +08:00
} ) ;
2013-06-15 01:39:23 +08:00
var $el = $ ( '#quiz-publish-link' ) ;
2013-08-29 07:22:52 +08:00
var model = new Quiz ( $ . extend ( ENV . QUIZ , { unpublishable : ! $el . hasClass ( "disabled" ) } ) ) ;
2013-06-15 01:39:23 +08:00
var view = new PublishButtonView ( { model : model , el : $el } ) ;
2013-06-27 00:28:20 +08:00
2013-06-29 07:12:58 +08:00
var refresh = function ( ) {
location . href = location . href ;
}
view . on ( "publish" , refresh ) ;
view . on ( "unpublish" , refresh ) ;
2013-06-15 01:39:23 +08:00
view . render ( ) ;
2016-09-29 14:06:20 +08:00
var graphsRoot = document . getElementById ( 'crs-graphs' )
var detailsParent = document . getElementById ( 'not_right_side' )
CyoeStats . init ( graphsRoot , detailsParent )
2013-02-14 03:37:17 +08:00
} ) ;
2011-02-01 09:57:29 +08:00
} ) ;