Skip to content

Commit e4af7e6

Browse files
authored
Course builder improvements (#3096)
* Show permalink for new lessons and quizzes right after saving * Quiz set to Published by default * Create named quiz url using title if none manually entered * Add lesson description (content) * Hide the "Add Existing Lesson" modal after selecting a lesson * Improved section selection, and highlighting of the current section
1 parent e63cc58 commit e4af7e6

21 files changed

+198
-20
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
significance: minor
2+
type: added
3+
entry: Lesson content can be edited within the Course Builder for new lessons,
4+
or existing lessons with no existing content.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
significance: patch
2+
type: fixed
3+
entry: Close lesson settings panel when lesson has been trashed.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
significance: minor
2+
type: changed
3+
links:
4+
- "#3033"
5+
- "#3056"
6+
- "#3097"
7+
- "#2938"
8+
- "#3030"
9+
entry: Various course builder fixes, with quizzes set to published by default.

assets/js/builder/Controllers/Sync.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,18 @@ define( [], function() {
430430
model.set( 'id', info.id );
431431
delete model._unsavedChanges.id;
432432
}
433+
434+
if ( info.permalink ) {
435+
model.set( 'permalink', info.permalink );
436+
}
437+
if ( info.name ) {
438+
model.set( 'name', info.name );
439+
}
440+
441+
if ( info.content_added_in_builder ) {
442+
model.set( 'content_added_in_builder', info.content_added_in_builder );
443+
}
444+
433445
maybe_restart_tracking( model, info );
434446

435447
// check children
@@ -460,6 +472,20 @@ define( [], function() {
460472
model.set( 'id', info.id );
461473
delete model._unsavedChanges.id;
462474
}
475+
476+
// Update permalink and name if provided by the server.
477+
if ( info.permalink ) {
478+
model.set( 'permalink', info.permalink );
479+
}
480+
if ( info.name ) {
481+
model.set( 'name', info.name );
482+
}
483+
484+
if ( info.content_added_in_builder ) {
485+
model.set( 'content_added_in_builder', info.content_added_in_builder );
486+
}
487+
488+
463489
maybe_restart_tracking( model, info );
464490

465491
// check children

assets/js/builder/Models/Lesson.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ define( [ 'Models/Quiz', 'Models/_Relationships', 'Models/_Utilities', 'Schemas/
7676
quiz: {}, // Quiz model/data.
7777
quiz_enabled: 'no',
7878

79+
content_added_in_builder: '',
80+
7981
_forceSync: false,
8082

8183
};

assets/js/builder/Models/Quiz.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ define( [
6464
type: 'llms_quiz',
6565
lesson_id: '',
6666

67-
status: 'draft',
67+
status: 'publish',
6868

6969
// editable fields.
7070
content: '',

assets/js/builder/Schemas/Lesson.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,34 @@ define( [], function() {
1212
title: LLMS.l10n.translate( 'General Settings' ),
1313
toggleable: true,
1414
fields: [
15-
[
16-
{
17-
attribute: 'permalink',
18-
id: 'permalink',
19-
type: 'permalink',
20-
},
21-
], [
22-
{
23-
attribute: 'video_embed',
15+
[
16+
{
17+
attribute: 'permalink',
18+
id: 'permalink',
19+
type: 'permalink',
20+
},
21+
], [
22+
{
23+
attribute: 'content',
24+
id: 'content',
25+
label: LLMS.l10n.translate( 'Content' ),
26+
type: 'editor',
27+
condition: function() {
28+
return '' === this.get( 'content' ) || 'yes' === this.get( 'content_added_in_builder' );
29+
},
30+
},
31+
], [
32+
{
33+
id: 'content-page-builder-notice',
34+
label: LLMS.l10n.translate( 'Content' ),
35+
type: 'page_builder_notice',
36+
condition: function() {
37+
return '' !== this.get( 'content' ) && 'yes' !== this.get( 'content_added_in_builder' );
38+
},
39+
},
40+
], [
41+
{
42+
attribute: 'video_embed',
2443
id: 'video-embed',
2544
label: LLMS.l10n.translate( 'Video Embed URL' ),
2645
type: 'video_embed',

assets/js/builder/Views/Assignment.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ define( [
114114
*/
115115
this.model.set_parent( this.lesson );
116116

117+
this.listenTo( this.model, 'change:permalink', this.render_settings );
118+
117119
}
118120

119121
this.on( 'model-trashed', this.on_trashed );
@@ -154,6 +156,23 @@ define( [
154156

155157
},
156158

159+
/**
160+
* Re-render the settings subview when permalink updates after saving.
161+
*
162+
* @since [version]
163+
*
164+
* @return {Void}
165+
*/
166+
render_settings: function() {
167+
168+
var view = this.get_subview( 'settings' );
169+
if ( view && view.instance ) {
170+
view.instance.render();
171+
this.init_selects();
172+
}
173+
174+
},
175+
157176
/**
158177
* Adds a new assignment to a lesson which currently has no assignment associated with it.
159178
*
@@ -176,6 +195,7 @@ define( [
176195
this.lesson.set( 'assignment_enabled', 'yes' );
177196
this.lesson.set( 'assignment', this.model );
178197

198+
this.listenTo( this.model, 'change:permalink', this.render_settings );
179199
this.render();
180200

181201
} else {
@@ -221,6 +241,7 @@ define( [
221241
this.lesson.set( 'assignment', assignment );
222242
this.model = assignment;
223243

244+
this.listenTo( this.model, 'change:permalink', this.render_settings );
224245
this.render();
225246

226247
},

assets/js/builder/Views/Course.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ define( [
8989

9090
Backbone.pubSub.on( 'lesson-selected', this.active_lesson_change, this );
9191

92+
// Select the first section by default on load.
93+
var firstSection = this.model.get( 'sections' ).first();
94+
if ( firstSection ) {
95+
this.sectionListView.setSelectedModel( firstSection );
96+
}
97+
9298
},
9399

94100
/**
@@ -167,8 +173,7 @@ define( [
167173
*/
168174
on_section_toggle: function( model ) {
169175

170-
var selected = model.get( '_expanded' ) ? [ model ] : [];
171-
this.sectionListView.setSelectedModels( selected );
176+
this.sectionListView.setSelectedModel( model );
172177

173178
},
174179

assets/js/builder/Views/Elements.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ define( [ 'Models/Section', 'Views/Section', 'Models/Lesson', 'Views/Lesson', 'V
130130

131131
event.preventDefault();
132132

133-
var pop = new Popover( {
133+
var pop, onLessonSelect;
134+
135+
pop = new Popover( {
134136
el: '#llms-existing-lesson',
135137
args: {
136138
backdrop: true,
@@ -144,13 +146,22 @@ define( [ 'Models/Section', 'Views/Section', 'Models/Lesson', 'Views/Lesson', 'V
144146
post_type: 'lesson',
145147
searching_message: LLMS.l10n.translate( 'Search for existing lessons...' ),
146148
} ).render().$el,
149+
onHide: function() {
150+
Backbone.pubSub.off( 'lesson-search-select', onLessonSelect );
151+
},
147152
}
148153
} );
149154

155+
onLessonSelect = function() {
156+
pop.hide();
157+
158+
// Ref #3097 — pop.hide() doesn't always remove the DOM elements.
159+
$( '.webui-popover' ).remove();
160+
$( '.webui-popover-backdrop' ).remove();
161+
};
162+
150163
pop.show();
151-
Backbone.pubSub.on( 'lesson-search-select', function() {
152-
pop.hide()
153-
} );
164+
Backbone.pubSub.once( 'lesson-search-select', onLessonSelect );
154165

155166
},
156167

0 commit comments

Comments
 (0)