diff --git a/lms/static/js/learner_dashboard/program_details_factory.js b/lms/static/js/learner_dashboard/program_details_factory.js index af90d4ce6a..6073bfadac 100644 --- a/lms/static/js/learner_dashboard/program_details_factory.js +++ b/lms/static/js/learner_dashboard/program_details_factory.js @@ -6,7 +6,7 @@ ], function(ProgramDetailsView) { return function (options) { - var ProgramDetails = new ProgramDetailsView(options); + var ProgramDetails = new ProgramDetailsView(options.programData); return ProgramDetails; }; }); diff --git a/lms/static/js/learner_dashboard/program_list_factory.js b/lms/static/js/learner_dashboard/program_list_factory.js index 9b5cfcf414..06fd63cbdf 100644 --- a/lms/static/js/learner_dashboard/program_list_factory.js +++ b/lms/static/js/learner_dashboard/program_list_factory.js @@ -21,7 +21,11 @@ el: '.program-cards-container', childView: ProgramCardView, collection: new ProgramCollection(options.programsData), - context: options + context: options, + titleContext: { + el: 'h2', + title: 'Your Programs' + } }).render(); new SidebarView({ diff --git a/lms/static/js/learner_dashboard/views/collection_list_view.js b/lms/static/js/learner_dashboard/views/collection_list_view.js index 42812c1946..6ff7970e6b 100644 --- a/lms/static/js/learner_dashboard/views/collection_list_view.js +++ b/lms/static/js/learner_dashboard/views/collection_list_view.js @@ -5,31 +5,35 @@ 'jquery', 'underscore', 'gettext', + 'edx-ui-toolkit/js/utils/string-utils', + 'edx-ui-toolkit/js/utils/html-utils', 'text!../../../templates/learner_dashboard/empty_programs_list.underscore' ], function (Backbone, $, _, gettext, + StringUtils, + HtmlUtils, emptyProgramsListTpl) { return Backbone.View.extend({ initialize: function(data) { this.childView = data.childView; this.context = data.context; + this.titleContext = data.titleContext; }, render: function() { - var childList, tpl; + var childList; if (!this.collection.length) { if (this.context.xseriesUrl) { //Only show the xseries advertising panel if the link is passed in - tpl = _.template(emptyProgramsListTpl); - this.$el.html(tpl(this.context)); + HtmlUtils.setHtml(this.$el, HtmlUtils.template(emptyProgramsListTpl)(this.context)); } - } else { - childList = []; + } else { + childList = []; this.collection.each(function(model) { var child = new this.childView({ @@ -39,8 +43,23 @@ childList.push(child.el); }, this); + if (this.titleContext){ + this.$el.before(HtmlUtils.ensureHtml(this.getTitleHtml()).toString()); + } this.$el.html(childList); } + }, + + getTitleHtml: function(){ + var titleHtml = HtmlUtils.joinHtml( + HtmlUtils.HTML('<'), + this.titleContext.el, + HtmlUtils.HTML(' class="sr-only collection-title">'), + StringUtils.interpolate(this.titleContext.title), + HtmlUtils.HTML(''), + this.titleContext.el, + HtmlUtils.HTML('>')); + return titleHtml; } }); } diff --git a/lms/static/js/learner_dashboard/views/course_card_view.js b/lms/static/js/learner_dashboard/views/course_card_view.js new file mode 100644 index 0000000000..33ea0b0297 --- /dev/null +++ b/lms/static/js/learner_dashboard/views/course_card_view.js @@ -0,0 +1,35 @@ +;(function (define) { + 'use strict'; + + define(['backbone', + 'jquery', + 'underscore', + 'gettext', + 'edx-ui-toolkit/js/utils/html-utils', + 'text!../../../templates/learner_dashboard/course_card.underscore' + ], + function( + Backbone, + $, + _, + gettext, + HtmlUtils, + pageTpl + ) { + return Backbone.View.extend({ + className: 'course-card card', + + tpl: HtmlUtils.template(pageTpl), + + initialize: function() { + this.render(); + }, + + render: function() { + var filledTemplate = this.tpl(this.model.toJSON()); + HtmlUtils.setHtml(this.$el, filledTemplate); + } + }); + } + ); +}).call(this, define || RequireJS.define); diff --git a/lms/static/js/learner_dashboard/views/program_details_view.js b/lms/static/js/learner_dashboard/views/program_details_view.js index 5211af4853..98dd5cff81 100644 --- a/lms/static/js/learner_dashboard/views/program_details_view.js +++ b/lms/static/js/learner_dashboard/views/program_details_view.js @@ -7,9 +7,21 @@ 'gettext', 'edx-ui-toolkit/js/utils/html-utils', 'js/learner_dashboard/views/program_header_view', + 'js/learner_dashboard/views/collection_list_view', + 'js/learner_dashboard/views/course_card_view', 'text!../../../templates/learner_dashboard/program_details_view.underscore' ], - function(Backbone, $, _, gettext, HtmlUtils, HeaderView, pageTpl) { + function( + Backbone, + $, + _, + gettext, + HtmlUtils, + HeaderView, + CollectionListView, + CourseCardView, + pageTpl + ) { return Backbone.View.extend({ el: '.js-program-details-wrapper', @@ -17,6 +29,9 @@ initialize: function(options) { this.programModel = new Backbone.Model(options); + this.courseCardsCollection = new Backbone.Collection( + this.programModel.get('course_codes') + ); this.render(); }, @@ -29,6 +44,16 @@ this.headerView = new HeaderView({ model: this.programModel }); + new CollectionListView({ + el: '.js-course-list', + childView: CourseCardView, + collection: this.courseCardsCollection, + context: this.programModel.toJSON(), + titleContext: { + el: 'h2', + title: 'Course List' + } + }).render(); } }); } diff --git a/lms/static/js/spec/learner_dashboard/collection_list_view_spec.js b/lms/static/js/spec/learner_dashboard/collection_list_view_spec.js index 0cd6abd256..277b752509 100644 --- a/lms/static/js/spec/learner_dashboard/collection_list_view_spec.js +++ b/lms/static/js/spec/learner_dashboard/collection_list_view_spec.js @@ -124,6 +124,31 @@ define([ $cards = view.$el.find('.program-card'); expect($cards.length).toBe(0); }); + it('should have no title when title not provided', function(){ + var $title; + setFixtures('
<%- key %>
+ <% if(enrollment_status){ %> + <%- course_start %> - <%-course_end %> + <%- gettext('View Course') %> + <% }else{ %> + <%- gettext('Not Yet Enrolled') %> + <%- gettext('Learn More') %> + <% } %> +