Commit 3b3b3dcd by Daniel Friedman

Show current unit in unit outline.

TNL-291
parent a4e1cc48
...@@ -88,6 +88,17 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/common_helpers/template_ ...@@ -88,6 +88,17 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/common_helpers/template_
expect(unitOutlineView.$('.list-units')).toExist(); expect(unitOutlineView.$('.list-units')).toExist();
}); });
it('highlights the current unit', function() {
createUnitOutlineView(this, createMockXBlockInfo('Mock Unit'));
$('.outline-unit').each(function(i) {
if ($(this).data('locator') === model.get('id')) {
expect($(this)).toHaveClass('is-current');
} else {
expect($(this)).not.toHaveClass('is-current');
}
});
});
it('can add a unit', function() { it('can add a unit', function() {
var redirectSpy; var redirectSpy;
createUnitOutlineView(this, createMockXBlockInfo('Mock Unit')); createUnitOutlineView(this, createMockXBlockInfo('Mock Unit'));
......
...@@ -35,15 +35,8 @@ define(["jquery", "underscore", "js/views/xblock_outline", "js/views/utils/view_ ...@@ -35,15 +35,8 @@ define(["jquery", "underscore", "js/views/xblock_outline", "js/views/utils/view_
return !this.model.isVertical(); return !this.model.isVertical();
}, },
createChildView: function(xblockInfo, parentInfo, parentView) { getChildViewClass: function() {
return new CourseOutlineView({ return CourseOutlineView;
model: xblockInfo,
parentInfo: parentInfo,
initialState: this.initialState,
expandedLocators: this.expandedLocators,
template: this.template,
parentView: parentView || this
});
}, },
/** /**
...@@ -112,7 +105,7 @@ define(["jquery", "underscore", "js/views/xblock_outline", "js/views/utils/view_ ...@@ -112,7 +105,7 @@ define(["jquery", "underscore", "js/views/xblock_outline", "js/views/utils/view_
}); });
// Fetch the full xblock info for the section and then create a view for it // Fetch the full xblock info for the section and then create a view for it
sectionInfo.fetch().done(function() { sectionInfo.fetch().done(function() {
sectionView = self.createChildView(sectionInfo, self.model, self); sectionView = self.createChildView(sectionInfo, self.model, {parentView: self});
sectionView.initialState = initialState; sectionView.initialState = initialState;
sectionView.expandedLocators = self.expandedLocators; sectionView.expandedLocators = self.expandedLocators;
sectionView.render(); sectionView.render();
......
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
* the ancestors of the unit along with its direct siblings. It also has a single "New Unit" * the ancestors of the unit along with its direct siblings. It also has a single "New Unit"
* button to allow a new sibling unit to be added. * button to allow a new sibling unit to be added.
*/ */
define(['js/views/xblock_outline'], define(['underscore', 'js/views/xblock_outline', 'js/views/unit_outline_child'],
function(XBlockOutlineView) { function(_, XBlockOutlineView, UnitOutlineChildView) {
var UnitOutlineView = XBlockOutlineView.extend({ var UnitOutlineView = XBlockOutlineView.extend({
// takes XBlockInfo as a model // takes XBlockInfo as a model
...@@ -29,7 +28,11 @@ define(['js/views/xblock_outline'], ...@@ -29,7 +28,11 @@ define(['js/views/xblock_outline'],
// i.e. subsection and then section. // i.e. subsection and then section.
for (i=ancestors.length - 1; i >= 0; i--) { for (i=ancestors.length - 1; i >= 0; i--) {
ancestor = ancestors[i]; ancestor = ancestors[i];
ancestorView = this.createChildView(ancestor, previousAncestor, ancestorView); ancestorView = this.createChildView(
ancestor,
previousAncestor,
{parentView: ancestorView, currentUnitId: this.model.get('id')}
);
ancestorView.render(); ancestorView.render();
listElement.append(ancestorView.$el); listElement.append(ancestorView.$el);
previousAncestor = ancestor; previousAncestor = ancestor;
...@@ -37,6 +40,17 @@ define(['js/views/xblock_outline'], ...@@ -37,6 +40,17 @@ define(['js/views/xblock_outline'],
} }
} }
return ancestorView; return ancestorView;
},
getChildViewClass: function() {
return UnitOutlineChildView;
},
getTemplateContext: function() {
return _.extend(
XBlockOutlineView.prototype.getTemplateContext.call(this),
{currentUnitId: this.model.get('id')}
);
} }
}); });
......
/**
* The UnitOutlineChildView is used to render each Section,
* Subsection, and Unit within the Unit Outline component on the unit
* page.
*/
define(['underscore', 'js/views/xblock_outline'],
function(_, XBlockOutlineView) {
var UnitOutlineChildView = XBlockOutlineView.extend({
initialize: function() {
XBlockOutlineView.prototype.initialize.call(this);
this.currentUnitId = this.options.currentUnitId;
},
getTemplateContext: function() {
return _.extend(
XBlockOutlineView.prototype.getTemplateContext.call(this),
{currentUnitId: this.currentUnitId}
);
},
getChildViewClass: function() {
return UnitOutlineChildView;
},
createChildView: function(childInfo, parentInfo, options) {
options = _.isUndefined(options) ? {} : options;
return XBlockOutlineView.prototype.createChildView.call(
this, childInfo, parentInfo, _.extend(options, {currentUnitId: this.currentUnitId})
);
}
});
return UnitOutlineChildView;
}); // end define()
...@@ -54,6 +54,15 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/ ...@@ -54,6 +54,15 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/
}, },
renderTemplate: function() { renderTemplate: function() {
var html = this.template(this.getTemplateContext());
if (this.parentInfo) {
this.setElement($(html));
} else {
this.$el.html(html);
}
},
getTemplateContext: function() {
var xblockInfo = this.model, var xblockInfo = this.model,
childInfo = xblockInfo.get('child_info'), childInfo = xblockInfo.get('child_info'),
parentInfo = this.parentInfo, parentInfo = this.parentInfo,
...@@ -62,7 +71,6 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/ ...@@ -62,7 +71,6 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/
parentType = parentInfo ? XBlockViewUtils.getXBlockType(parentInfo.get('category')) : null, parentType = parentInfo ? XBlockViewUtils.getXBlockType(parentInfo.get('category')) : null,
addChildName = null, addChildName = null,
defaultNewChildName = null, defaultNewChildName = null,
html,
isCollapsed = this.shouldRenderChildren() && !this.shouldExpandChildren(); isCollapsed = this.shouldRenderChildren() && !this.shouldExpandChildren();
if (childInfo) { if (childInfo) {
addChildName = interpolate(gettext('New %(component_type)s'), { addChildName = interpolate(gettext('New %(component_type)s'), {
...@@ -70,7 +78,7 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/ ...@@ -70,7 +78,7 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/
}, true); }, true);
defaultNewChildName = childInfo.display_name; defaultNewChildName = childInfo.display_name;
} }
html = this.template({ return {
xblockInfo: xblockInfo, xblockInfo: xblockInfo,
visibilityClass: XBlockViewUtils.getXBlockVisibilityClass(xblockInfo.get('visibility_state')), visibilityClass: XBlockViewUtils.getXBlockVisibilityClass(xblockInfo.get('visibility_state')),
typeListClass: XBlockViewUtils.getXBlockListTypeClass(xblockType), typeListClass: XBlockViewUtils.getXBlockListTypeClass(xblockType),
...@@ -86,20 +94,15 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/ ...@@ -86,20 +94,15 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/
includesChildren: this.shouldRenderChildren(), includesChildren: this.shouldRenderChildren(),
hasExplicitStaffLock: this.model.get('has_explicit_staff_lock'), hasExplicitStaffLock: this.model.get('has_explicit_staff_lock'),
staffOnlyMessage: this.model.get('staff_only_message') staffOnlyMessage: this.model.get('staff_only_message')
}); };
if (this.parentInfo) {
this.setElement($(html));
} else {
this.$el.html(html);
}
}, },
renderChildren: function() { renderChildren: function() {
var self = this, var self = this,
xblockInfo = this.model; parentInfo = this.model;
if (xblockInfo.get('child_info')) { if (parentInfo.get('child_info')) {
_.each(this.model.get('child_info').children, function(child) { _.each(this.model.get('child_info').children, function(childInfo) {
var childOutlineView = self.createChildView(child, xblockInfo); var childOutlineView = self.createChildView(childInfo, parentInfo);
childOutlineView.render(); childOutlineView.render();
self.addChildView(childOutlineView); self.addChildView(childOutlineView);
}); });
...@@ -182,15 +185,20 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/ ...@@ -182,15 +185,20 @@ define(["jquery", "underscore", "gettext", "js/views/baseview", "js/views/utils/
return true; return true;
}, },
createChildView: function(xblockInfo, parentInfo, parentView) { getChildViewClass: function() {
return new XBlockOutlineView({ return XBlockOutlineView;
model: xblockInfo, },
createChildView: function(childInfo, parentInfo, options) {
var viewClass = this.getChildViewClass();
return new viewClass(_.extend({
model: childInfo,
parentInfo: parentInfo, parentInfo: parentInfo,
parentView: this,
initialState: this.initialState, initialState: this.initialState,
expandedLocators: this.expandedLocators, expandedLocators: this.expandedLocators,
template: this.template, template: this.template
parentView: parentView || this }, options));
});
}, },
onSync: function(event) { onSync: function(event) {
......
<% if (parentInfo) { %> <% if (parentInfo) { %>
<li class="outline-item outline-<%= xblockType %> <%= visibilityClass %>" <li class="outline-item outline-<%= xblockType %> <%= visibilityClass %> <%= xblockInfo.get('id') === currentUnitId ? 'is-current' : '' %>"
data-parent="<%= parentInfo.get('id') %>" data-locator="<%= xblockInfo.get('id') %>"> data-parent="<%= parentInfo.get('id') %>" data-locator="<%= xblockInfo.get('id') %>">
<div class="<%= xblockType %>-header"> <div class="<%= xblockType %>-header">
<h3 class="<%= xblockType %>-header-details"> <h3 class="<%= xblockType %>-header-details">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment