diff --git a/common/static/common/js/discussion/views/discussion_thread_list_view.js b/common/static/common/js/discussion/views/discussion_thread_list_view.js index 3129fda11b..c2764e86e1 100644 --- a/common/static/common/js/discussion/views/discussion_thread_list_view.js +++ b/common/static/common/js/discussion/views/discussion_thread_list_view.js @@ -1,4 +1,4 @@ -/* globals Content, Discussion, DiscussionUtil */ +/* globals _, Backbone, Content, Discussion, DiscussionUtil */ (function() { 'use strict'; var __hasProp = {}.hasOwnProperty, @@ -156,16 +156,13 @@ /** * Creates search alert model and adds it to collection * @param message - alert message - * @param css_class - Allows setting custom css class for a message. This can be used to style messages - * of different types differently (i.e. other background, completely hide, etc.) + * @param cssClass - Allows setting custom css class for a message. This can be used to style messages + * of different types differently (i.e. other background, completely hide, etc.) * @returns {Backbone.Model} */ - DiscussionThreadListView.prototype.addSearchAlert = function(message, css_class) { + DiscussionThreadListView.prototype.addSearchAlert = function(message, cssClass) { var m; - if (typeof css_class === 'undefined' || css_class === null) { - css_class = ''; - } - m = new Backbone.Model({'message': message, 'css_class': css_class}); + m = new Backbone.Model({message: message, css_class: cssClass || ''}); this.searchAlertCollection.add(m); return m; }; @@ -179,16 +176,16 @@ }; DiscussionThreadListView.prototype.reloadDisplayedCollection = function(thread) { - var active, $content, current_el, thread_id; + var active, $content, $currentElement, threadId; this.clearSearchAlerts(); - thread_id = thread.get('id'); + threadId = thread.get('id'); $content = this.renderThread(thread); - current_el = this.$('.forum-nav-thread[data-id=' + thread_id + ']'); - active = current_el.has('.forum-nav-thread-link.is-active').length !== 0; - current_el.replaceWith($content); + $currentElement = this.$('.forum-nav-thread[data-id=' + threadId + ']'); + active = $currentElement.has('.forum-nav-thread-link.is-active').length !== 0; + $currentElement.replaceWith($content); this.showMetadataAccordingToSort(); if (active) { - return this.setActiveThread(thread_id); + return this.setActiveThread(threadId); } }; @@ -198,14 +195,14 @@ DiscussionThreadListView.prototype.addAndSelectThread = function(thread) { - var commentable_id, menuItem, + var commentableId, menuItem, self = this; - commentable_id = thread.get('commentable_id'); + commentableId = thread.get('commentable_id'); menuItem = this.$('.forum-nav-browse-menu-item[data-discussion-id]').filter(function() { - return $(this).data('discussion-id') === commentable_id; + return $(this).data('discussion-id') === commentableId; }); this.setCurrentTopicDisplay(this.getPathText(menuItem)); - return this.retrieveDiscussion(commentable_id, function() { + return this.retrieveDiscussion(commentableId, function() { return self.trigger('thread:created', thread.get('id')); }); }; @@ -403,27 +400,28 @@ this.trigger('thread:removed', thread); }; - DiscussionThreadListView.prototype.setActiveThread = function(thread_id) { + DiscussionThreadListView.prototype.setActiveThread = function(threadId) { var $srElem; this.$('.forum-nav-thread-link').find('.sr').remove(); - this.$(".forum-nav-thread[data-id!='" + thread_id + "'] .forum-nav-thread-link") + this.$(".forum-nav-thread[data-id!='" + threadId + "'] .forum-nav-thread-link") .removeClass('is-active'); $srElem = edx.HtmlUtils.joinHtml( edx.HtmlUtils.HTML(''), edx.HtmlUtils.ensureHtml(gettext('Current conversation')), edx.HtmlUtils.HTML('') ).toString(); - this.$(".forum-nav-thread[data-id='" + thread_id + "'] .forum-nav-thread-link") + this.$(".forum-nav-thread[data-id='" + threadId + "'] .forum-nav-thread-link") .addClass('is-active').find('.forum-nav-thread-wrapper-1') .prepend($srElem); }; DiscussionThreadListView.prototype.goHome = function() { - var url, $tpl_content; + var url, $templateContent; this.template = _.template($('#discussion-home-template').html()); - $tpl_content = $(this.template()); - $('.forum-content').empty().append($tpl_content); - $('.forum-nav-thread-list a').removeClass('is-active').find('.sr').remove(); + $templateContent = $(this.template()); + $('.forum-content').empty().append($templateContent); + $('.forum-nav-thread-list a').removeClass('is-active').find('.sr') + .remove(); $('input.email-setting').bind('click', this.updateEmailNotifications); url = DiscussionUtil.urlFor('notifications_status', window.user.get('id')); DiscussionUtil.safeAjax({ @@ -480,12 +478,19 @@ }; DiscussionThreadListView.prototype.getBreadcrumbText = function($item) { - var subTopic = $('.forum-nav-browse-title', $item).first().text().trim(), - $parentSubMenus = $item.parents('.forum-nav-browse-submenu'), - crumbs = []; + var $parentSubMenus = $item.parents('.forum-nav-browse-submenu'), + crumbs = [], + subTopic = $('.forum-nav-browse-title', $item) + .first() + .text() + .trim(); $parentSubMenus.each(function(i, el) { - crumbs.push($(el).siblings('.forum-nav-browse-title').first().text().trim()); + crumbs.push($(el).siblings('.forum-nav-browse-title') + .first() + .text() + .trim() + ); }); if (subTopic !== 'All Discussions') { @@ -505,15 +510,15 @@ } else { items.hide(); return items.each(function(i, item) { - var path, pathText; - item = $(item); - if (!item.is(':visible')) { - pathText = self.getPathText(item).toLowerCase(); + var path, pathText, + $item = $(item); + if (!$item.is(':visible')) { + pathText = self.getPathText($item).toLowerCase(); if (query.split(' ').every(function(term) { return pathText.search(term.toLowerCase()) !== -1; })) { - path = item.parents('.forum-nav-browse-menu-item').andSelf(); - return path.add(item.find('.forum-nav-browse-menu-item')).show(); + path = $item.parents('.forum-nav-browse-menu-item').andSelf(); + return path.add($item.find('.forum-nav-browse-menu-item')).show(); } } }); @@ -559,7 +564,7 @@ _results.push(x.replace(/^\s+|\s+$/g, '')); } return _results; - })(); + }()); prefix = ''; while (path.length > 1) { prefix = gettext('…') + '/'; @@ -619,9 +624,10 @@ return this.retrieveFirstPage(); }; - DiscussionThreadListView.prototype.retrieveDiscussion = function(discussion_id, callback) { - var url, self = this; - url = DiscussionUtil.urlFor('retrieve_discussion', discussion_id); + DiscussionThreadListView.prototype.retrieveDiscussion = function(discussionId, callback) { + var url, + self = this; + url = DiscussionUtil.urlFor('retrieve_discussion', discussionId); return DiscussionUtil.safeAjax({ url: url, type: 'GET', @@ -671,7 +677,7 @@ this.hideBrowseMenu(); this.setCurrentTopicDisplay(gettext('Search Results')); text = this.$('.forum-nav-search-input').val(); - return this.searchFor(text); + this.searchFor(text); } }; @@ -730,10 +736,10 @@ message = edx.HtmlUtils.interpolateHtml( noResponseMsg, { - 'original_query': edx.HtmlUtils.joinHtml( + original_query: edx.HtmlUtils.joinHtml( edx.HtmlUtils.HTML(''), text, edx.HtmlUtils.HTML('') ), - 'suggested_query': edx.HtmlUtils.joinHtml( + suggested_query: edx.HtmlUtils.joinHtml( edx.HtmlUtils.HTML(''), response.corrected_text, edx.HtmlUtils.HTML('') diff --git a/common/static/common/js/spec/discussion/view/discussion_thread_list_view_spec.js b/common/static/common/js/spec/discussion/view/discussion_thread_list_view_spec.js index eeec29949a..d55a902d80 100644 --- a/common/static/common/js/spec/discussion/view/discussion_thread_list_view_spec.js +++ b/common/static/common/js/spec/discussion/view/discussion_thread_list_view_spec.js @@ -1,5 +1,5 @@ /* globals - Discussion, DiscussionCourseSettings, DiscussionViewSpecHelper, DiscussionSpecHelper, + _, Discussion, DiscussionCourseSettings, DiscussionViewSpecHelper, DiscussionSpecHelper, DiscussionThreadListView, DiscussionUtil, Thread */ (function() { @@ -156,22 +156,22 @@ return expect(this.view.$('.forum-nav-filter-main-control').val()).toEqual('all'); }); - checkThreadsOrdering = function(view, sort_order, type) { + checkThreadsOrdering = function(view, sortOrder, type) { expect(view.$el.find('.forum-nav-thread').children().length).toEqual(4); expect(view.$el.find('.forum-nav-thread:nth-child(1) .forum-nav-thread-title').text()) - .toEqual(sort_order[0]); + .toEqual(sortOrder[0]); expect(view.$el.find('.forum-nav-thread:nth-child(2) .forum-nav-thread-title').text()) - .toEqual(sort_order[1]); + .toEqual(sortOrder[1]); expect(view.$el.find('.forum-nav-thread:nth-child(3) .forum-nav-thread-title').text()) - .toEqual(sort_order[2]); + .toEqual(sortOrder[2]); expect(view.$el.find('.forum-nav-thread:nth-child(4) .forum-nav-thread-title').text()) - .toEqual(sort_order[3]); + .toEqual(sortOrder[3]); return expect(view.$el.find('.forum-nav-sort-control').val()).toEqual(type); }; describe('thread rendering should be correct', function() { var checkRender; - checkRender = function(threads, type, sort_order) { + checkRender = function(threads, type, sortOrder) { var discussion, view; discussion = new Discussion(_.map(threads, function(thread) { return new Thread(thread); @@ -181,56 +181,56 @@ }); view = makeView(discussion); view.render(); - checkThreadsOrdering(view, sort_order, type); + checkThreadsOrdering(view, sortOrder, type); expect(view.$el.find('.forum-nav-thread-comments-count:visible').length) .toEqual(type === 'votes' ? 0 : 4); expect(view.$el.find('.forum-nav-thread-votes-count:visible').length) .toEqual(type === 'votes' ? 4 : 0); if (type === 'votes') { - return expect(_.map(view.$el.find('.forum-nav-thread-votes-count'), function(element) { + expect(_.map(view.$el.find('.forum-nav-thread-votes-count'), function(element) { return $(element).text().trim(); })).toEqual(['+25 votes', '+20 votes', '+42 votes', '+12 votes']); } }; it('with sort preference activity', function() { - return checkRender(this.threads, 'activity', ['Thread1', 'Thread2', 'Thread3', 'Thread4']); + checkRender(this.threads, 'activity', ['Thread1', 'Thread2', 'Thread3', 'Thread4']); }); it('with sort preference votes', function() { - return checkRender(this.threads, 'votes', ['Thread4', 'Thread1', 'Thread2', 'Thread3']); + checkRender(this.threads, 'votes', ['Thread4', 'Thread1', 'Thread2', 'Thread3']); }); it('with sort preference comments', function() { - return checkRender(this.threads, 'comments', ['Thread1', 'Thread4', 'Thread3', 'Thread2']); + checkRender(this.threads, 'comments', ['Thread1', 'Thread4', 'Thread3', 'Thread2']); }); }); describe('Sort change should be correct', function() { var changeSorting; - changeSorting = function(threads, selected_type, new_type, sort_order) { - var discussion, sortControl, sorted_threads, view; + changeSorting = function(threads, selectedType, newType, sortOrder) { + var discussion, sortControl, sortedThreads, view; discussion = new Discussion(_.map(threads, function(thread) { return new Thread(thread); }), { pages: 1, - sort: selected_type + sort: selectedType }); view = makeView(discussion); view.render(); sortControl = view.$el.find('.forum-nav-sort-control'); - expect(sortControl.val()).toEqual(selected_type); - sorted_threads = []; - if (new_type === 'activity') { - sorted_threads = [threads[0], threads[3], threads[1], threads[2]]; - } else if (new_type === 'comments') { - sorted_threads = [threads[0], threads[3], threads[2], threads[1]]; - } else if (new_type === 'votes') { - sorted_threads = [threads[3], threads[0], threads[1], threads[2]]; + expect(sortControl.val()).toEqual(selectedType); + sortedThreads = []; + if (newType === 'activity') { + sortedThreads = [threads[0], threads[3], threads[1], threads[2]]; + } else if (newType === 'comments') { + sortedThreads = [threads[0], threads[3], threads[2], threads[1]]; + } else if (newType === 'votes') { + sortedThreads = [threads[3], threads[0], threads[1], threads[2]]; } $.ajax.and.callFake(function(params) { params.success({ - 'discussion_data': sorted_threads, + discussion_data: sortedThreads, page: 1, num_pages: 1 }); @@ -239,9 +239,9 @@ } }; }); - sortControl.val(new_type).change(); + sortControl.val(newType).change(); expect($.ajax).toHaveBeenCalled(); - checkThreadsOrdering(view, sort_order, new_type); + checkThreadsOrdering(view, sortOrder, newType); }; it('with sort preference activity', function() { @@ -290,7 +290,7 @@ }); it('renders search alert with custom class', function() { - var foo, messages; + var messages; testAlertMessages([]); this.view.addSearchAlert('foo', 'custom-class'); @@ -299,7 +299,7 @@ expect(messages[0].text).toEqual('foo'); expect(messages[0].css_class).toEqual('search-alert custom-class'); - foo = this.view.addSearchAlert('bar', 'other-class'); + this.view.addSearchAlert('bar', 'other-class'); messages = getAlertMessagesAndClasses(); expect(messages.length).toEqual(2); @@ -572,11 +572,7 @@ }); describe('when shown', function() { - beforeEach(function() { - return $('.forum-nav-browse').click(); - }); - - it('should hide when header button is clicked', function() { + it('should show again when header button is clicked', function() { $('.forum-nav-browse').click(); return expectBrowseMenuVisible(false); }); diff --git a/common/static/common/js/spec_helpers/discussion_spec_helper.js b/common/static/common/js/spec_helpers/discussion_spec_helper.js index a41368ca17..0fe17ce3b4 100644 --- a/common/static/common/js/spec_helpers/discussion_spec_helper.js +++ b/common/static/common/js/spec_helpers/discussion_spec_helper.js @@ -22,18 +22,18 @@ DiscussionSpecHelper.getTestRoleInfo = function() { return { - 'Moderator': [], - 'Administrator': [], + Moderator: [], + Administrator: [], 'Community TA': [] }; }; DiscussionSpecHelper.makeTA = function() { - return DiscussionUtil.roleIds['Community TA'].push(parseInt(DiscussionUtil.getUser().id)); + return DiscussionUtil.roleIds['Community TA'].push(parseInt(DiscussionUtil.getUser().id, 10)); }; DiscussionSpecHelper.makeModerator = function() { - return DiscussionUtil.roleIds.Moderator.push(parseInt(DiscussionUtil.getUser().id)); + return DiscussionUtil.roleIds.Moderator.push(parseInt(DiscussionUtil.getUser().id, 10)); }; DiscussionSpecHelper.makeAjaxSpy = function(fakeAjax) { @@ -50,25 +50,22 @@ return jasmine.createSpyObj('event', ['preventDefault', 'target']); }; - DiscussionSpecHelper.makeCourseSettings = function(isCohorted) { - if (typeof isCohorted === 'undefined' || isCohorted === null) { - isCohorted = true; - } + DiscussionSpecHelper.makeCourseSettings = function() { return new DiscussionCourseSettings({ category_map: { children: ['Test Topic', 'Other Topic'], entries: { 'Test Topic': { - is_cohorted: isCohorted, + is_cohorted: true, id: 'test_topic' }, 'Other Topic': { - is_cohorted: isCohorted, + is_cohorted: true, id: 'other_topic' } } }, - is_cohorted: isCohorted + is_cohorted: true }); }; @@ -106,7 +103,7 @@ // suppressing Line is too long (4272 characters!) /* jshint -W101 */ appendSetFixtures( - ""); + ""); // eslint-disable-line max-len, no-useless-escape appendSetFixtures( '
\n' + diff --git a/lms/djangoapps/discussion/static/discussion/js/discussion_board_factory.js b/lms/djangoapps/discussion/static/discussion/js/discussion_board_factory.js index d57e906320..103bd130e4 100644 --- a/lms/djangoapps/discussion/static/discussion/js/discussion_board_factory.js +++ b/lms/djangoapps/discussion/static/discussion/js/discussion_board_factory.js @@ -55,7 +55,7 @@ BreadcrumbsModel = Backbone.Model.extend({ defaults: { - contents: [], + contents: [] } }); diff --git a/lms/djangoapps/discussion/static/discussion/js/discussion_profile_page_factory.js b/lms/djangoapps/discussion/static/discussion/js/discussion_profile_page_factory.js index 8af348f2b2..0b59b15a91 100644 --- a/lms/djangoapps/discussion/static/discussion/js/discussion_profile_page_factory.js +++ b/lms/djangoapps/discussion/static/discussion/js/discussion_profile_page_factory.js @@ -11,14 +11,13 @@ numPages = options.numPages; // Roles are not included in user profile page, but they are not used for anything window.DiscussionUtil.loadRoles({ - 'Moderator': [], - 'Administrator': [], + Moderator: [], + Administrator: [], 'Community TA': [] }); window.$$course_id = options.courseId; window.user = new window.DiscussionUser(userInfo); - // jshint nonew:false - new DiscussionUserProfileView({ + new DiscussionUserProfileView({ // eslint-disable-line no-new el: $element, collection: threads, page: page, diff --git a/lms/djangoapps/discussion/static/discussion/js/spec/views/discussion_user_profile_view_spec.js b/lms/djangoapps/discussion/static/discussion/js/spec/views/discussion_user_profile_view_spec.js index 6e231bfc0a..2709da2d94 100644 --- a/lms/djangoapps/discussion/static/discussion/js/spec/views/discussion_user_profile_view_spec.js +++ b/lms/djangoapps/discussion/static/discussion/js/spec/views/discussion_user_profile_view_spec.js @@ -62,15 +62,7 @@ define( }); describe('pagination rendering should be correct', function() { - var baseUri, checkRender, pageInfo; - baseUri = URI(window.location); - pageInfo = function(page) { - return { - url: baseUri.clone().addSearch('page', page).toString(), - number: page - }; - }; - checkRender = function(params) { + var checkRender = function(params) { var getPageNumber, paginator, view; view = makeView([], params.page, params.numPages); paginator = view.$('.discussion-paginator'); diff --git a/lms/djangoapps/discussion/static/discussion/js/views/discussion_fake_breadcrumbs.js b/lms/djangoapps/discussion/static/discussion/js/views/discussion_fake_breadcrumbs.js index f43a74c3ed..7c9b3311db 100644 --- a/lms/djangoapps/discussion/static/discussion/js/views/discussion_fake_breadcrumbs.js +++ b/lms/djangoapps/discussion/static/discussion/js/views/discussion_fake_breadcrumbs.js @@ -12,7 +12,7 @@ define([ 'backbone', 'edx-ui-toolkit/js/utils/html-utils', - 'text!discussion/templates/fake-breadcrumbs.underscore', + 'text!discussion/templates/fake-breadcrumbs.underscore' ], function(Backbone, HtmlUtils, breadcrumbsTemplate) { var DiscussionFakeBreadcrumbs = Backbone.View.extend({ diff --git a/lms/static/js/spec/courseware/link_clicked_events_spec.js b/lms/static/js/spec/courseware/link_clicked_events_spec.js index 9ca1886864..ef9a26815a 100644 --- a/lms/static/js/spec/courseware/link_clicked_events_spec.js +++ b/lms/static/js/spec/courseware/link_clicked_events_spec.js @@ -12,7 +12,7 @@ define(['jquery', 'logger', 'js/courseware/courseware_factory'], function($, Log $('.external-link').click(); expect(Logger.log).toHaveBeenCalledWith('edx.ui.lms.link_clicked', { target_url: 'http://example.com/', - current_url: 'http://' + window.location.host + '/context.html' + current_url: window.location.toString() }); }); diff --git a/lms/static/lms/js/spec/main.js b/lms/static/lms/js/spec/main.js index fb14af08d3..72ed3adb50 100644 --- a/lms/static/lms/js/spec/main.js +++ b/lms/static/lms/js/spec/main.js @@ -8,7 +8,7 @@ paths: { 'gettext': 'xmodule_js/common_static/js/test/i18n', 'codemirror': 'xmodule_js/common_static/js/vendor/CodeMirror/codemirror', - 'jquery': 'common/js/vendor/jquery', + jquery: 'common/js/vendor/jquery', 'jquery-migrate': 'common/js/vendor/jquery-migrate', 'jquery.ui': 'xmodule_js/common_static/js/vendor/jquery-ui.min', 'jquery.eventDrag': 'xmodule_js/common_static/js/vendor/jquery.event.drag-2.2',