@@ -20,7 +20,7 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview',
2020 StaffLockEditor , UnitAccessEditor , ContentVisibilityEditor , TimedExaminationPreferenceEditor ,
2121 AccessEditor , ShowCorrectnessEditor , HighlightsEditor , HighlightsEnableXBlockModal , HighlightsEnableEditor ,
2222 DiscussionEditor , SummaryConfigurationEditor , SubsectionShareLinkXBlockModal , FullPageShareLinkEditor ,
23- EmbedLinkShareLinkEditor ;
23+ EmbedLinkShareLinkEditor , OptionalCompletionEditor ;
2424
2525 CourseOutlineXBlockModal = BaseModal . extend ( {
2626 events : _ . extend ( { } , BaseModal . prototype . events , {
@@ -1359,6 +1359,50 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview',
13591359 }
13601360 } ) ;
13611361
1362+ OptionalCompletionEditor = AbstractEditor . extend ( {
1363+ templateName : 'optional-completion-editor' ,
1364+ className : 'edit-optional-completion' ,
1365+
1366+ afterRender : function ( ) {
1367+ AbstractEditor . prototype . afterRender . call ( this ) ;
1368+ this . setValue ( this . model . get ( 'optional_completion' ) ) ;
1369+ } ,
1370+
1371+ setValue : function ( value ) {
1372+ this . $ ( 'input[name=optional_completion]' ) . prop ( 'checked' , value ) ;
1373+ } ,
1374+
1375+ currentValue : function ( ) {
1376+ return this . $ ( 'input[name=optional_completion]' ) . is ( ':checked' ) ;
1377+ } ,
1378+
1379+ hasChanges : function ( ) {
1380+ return this . model . get ( 'optional_completion' ) !== this . currentValue ( ) ;
1381+ } ,
1382+
1383+ getRequestData : function ( ) {
1384+ if ( this . hasChanges ( ) ) {
1385+ return {
1386+ publish : 'republish' ,
1387+ metadata : {
1388+ // This variable relies on the inheritance mechanism, so we want to unset it instead of
1389+ // explicitly setting it to `false`.
1390+ optional_completion : this . currentValue ( ) || null
1391+ }
1392+ } ;
1393+ } else {
1394+ return { } ;
1395+ }
1396+ } ,
1397+
1398+ getContext : function ( ) {
1399+ return {
1400+ optional_completion : this . model . get ( 'optional_completion' ) ,
1401+ optional_ancestor : this . model . get ( 'ancestor_has_optional_completion' )
1402+ } ;
1403+ } ,
1404+ } ) ;
1405+
13621406 return {
13631407 getModal : function ( type , xblockInfo , options ) {
13641408 if ( type === 'edit' ) {
@@ -1427,6 +1471,14 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview',
14271471 }
14281472 }
14291473
1474+ if ( course . get ( 'completion_tracking_enabled' ) ) {
1475+ if ( tabs . length > 0 ) {
1476+ tabs [ 0 ] . editors . push ( OptionalCompletionEditor ) ;
1477+ } else {
1478+ editors . push ( OptionalCompletionEditor ) ;
1479+ }
1480+ }
1481+
14301482 /* globals course */
14311483 if ( course . get ( 'self_paced' ) ) {
14321484 editors = _ . without ( editors , ReleaseDateEditor , DueDateEditor ) ;
0 commit comments