From b1af59ad9976972aaf1fa262c4fe22515bdf118e Mon Sep 17 00:00:00 2001 From: Andy Armstrong Date: Thu, 23 Jun 2016 10:32:33 -0400 Subject: [PATCH 1/2] Move discussion .coffee files to .js --- .../discussion/content.coffee => common/js/discussion/content.js} | 0 .../discussion.coffee => common/js/discussion/discussion.js} | 0 .../js/discussion/discussion_module_view.js} | 0 .../js/discussion/discussion_router.js} | 0 .../src/discussion/main.coffee => common/js/discussion/main.js} | 0 .../js/discussion/models/discussion_course_settings.js} | 0 .../js/discussion/models/discussion_user.js} | 0 .../src/discussion/utils.coffee => common/js/discussion/utils.js} | 0 .../js/discussion/views/discussion_content_view.js} | 0 .../js}/discussion/views/discussion_thread_edit_view.js | 0 .../js/discussion/views/discussion_thread_list_view.js} | 0 .../js/discussion/views/discussion_thread_profile_view.js} | 0 .../js/discussion/views/discussion_thread_show_view.js} | 0 .../js/discussion/views/discussion_thread_view.js} | 0 .../js}/discussion/views/discussion_topic_menu_view.js | 0 .../js/discussion/views/discussion_user_profile_view.js} | 0 .../js/discussion/views/new_post_view.js} | 0 .../js/discussion/views/response_comment_edit_view.js} | 0 .../js/discussion/views/response_comment_show_view.js} | 0 .../js/discussion/views/response_comment_view.js} | 0 .../js/discussion/views/thread_response_edit_view.js} | 0 .../js/discussion/views/thread_response_show_view.js} | 0 .../js/discussion/views/thread_response_view.js} | 0 .../js/spec/discussion/content_spec.js} | 0 .../utils_spec.coffee => common/js/spec/discussion/utils_spec.js} | 0 .../js/spec/discussion/view/discussion_content_view_spec.js} | 0 .../js}/spec/discussion/view/discussion_thread_edit_view_spec.js | 0 .../js/spec/discussion/view/discussion_thread_list_view_spec.js} | 0 .../spec/discussion/view/discussion_thread_profile_view_spec.js} | 0 .../js/spec/discussion/view/discussion_thread_show_view_spec.js} | 0 .../js/spec/discussion/view/discussion_thread_view_spec.js} | 0 .../js}/spec/discussion/view/discussion_topic_menu_view_spec.js | 0 .../js/spec/discussion/view/discussion_user_profile_view_spec.js} | 0 .../js/spec/discussion/view/discussion_view_spec_helper.js} | 0 .../js/spec/discussion/view/new_post_view_spec.js} | 0 .../js/spec/discussion/view/response_comment_show_view_spec.js} | 0 .../js/spec/discussion/view/response_comment_view_spec.js} | 0 .../js/spec/discussion/view/thread_response_show_view_spec.js} | 0 .../js/spec/discussion/view/thread_response_view_spec.js} | 0 .../js/spec_helpers/discussion_spec_helper.js} | 0 40 files changed, 0 insertions(+), 0 deletions(-) rename common/static/{coffee/src/discussion/content.coffee => common/js/discussion/content.js} (100%) rename common/static/{coffee/src/discussion/discussion.coffee => common/js/discussion/discussion.js} (100%) rename common/static/{coffee/src/discussion/discussion_module_view.coffee => common/js/discussion/discussion_module_view.js} (100%) rename common/static/{coffee/src/discussion/discussion_router.coffee => common/js/discussion/discussion_router.js} (100%) rename common/static/{coffee/src/discussion/main.coffee => common/js/discussion/main.js} (100%) rename common/static/{coffee/src/discussion/models/discussion_course_settings.coffee => common/js/discussion/models/discussion_course_settings.js} (100%) rename common/static/{coffee/src/discussion/models/discussion_user.coffee => common/js/discussion/models/discussion_user.js} (100%) rename common/static/{coffee/src/discussion/utils.coffee => common/js/discussion/utils.js} (100%) rename common/static/{coffee/src/discussion/views/discussion_content_view.coffee => common/js/discussion/views/discussion_content_view.js} (100%) rename common/static/{coffee/src => common/js}/discussion/views/discussion_thread_edit_view.js (100%) rename common/static/{coffee/src/discussion/views/discussion_thread_list_view.coffee => common/js/discussion/views/discussion_thread_list_view.js} (100%) rename common/static/{coffee/src/discussion/views/discussion_thread_profile_view.coffee => common/js/discussion/views/discussion_thread_profile_view.js} (100%) rename common/static/{coffee/src/discussion/views/discussion_thread_show_view.coffee => common/js/discussion/views/discussion_thread_show_view.js} (100%) rename common/static/{coffee/src/discussion/views/discussion_thread_view.coffee => common/js/discussion/views/discussion_thread_view.js} (100%) rename common/static/{coffee/src => common/js}/discussion/views/discussion_topic_menu_view.js (100%) rename common/static/{coffee/src/discussion/views/discussion_user_profile_view.coffee => common/js/discussion/views/discussion_user_profile_view.js} (100%) rename common/static/{coffee/src/discussion/views/new_post_view.coffee => common/js/discussion/views/new_post_view.js} (100%) rename common/static/{coffee/src/discussion/views/response_comment_edit_view.coffee => common/js/discussion/views/response_comment_edit_view.js} (100%) rename common/static/{coffee/src/discussion/views/response_comment_show_view.coffee => common/js/discussion/views/response_comment_show_view.js} (100%) rename common/static/{coffee/src/discussion/views/response_comment_view.coffee => common/js/discussion/views/response_comment_view.js} (100%) rename common/static/{coffee/src/discussion/views/thread_response_edit_view.coffee => common/js/discussion/views/thread_response_edit_view.js} (100%) rename common/static/{coffee/src/discussion/views/thread_response_show_view.coffee => common/js/discussion/views/thread_response_show_view.js} (100%) rename common/static/{coffee/src/discussion/views/thread_response_view.coffee => common/js/discussion/views/thread_response_view.js} (100%) rename common/static/{coffee/spec/discussion/content_spec.coffee => common/js/spec/discussion/content_spec.js} (100%) rename common/static/{coffee/spec/discussion/utils_spec.coffee => common/js/spec/discussion/utils_spec.js} (100%) rename common/static/{coffee/spec/discussion/view/discussion_content_view_spec.coffee => common/js/spec/discussion/view/discussion_content_view_spec.js} (100%) rename common/static/{coffee => common/js}/spec/discussion/view/discussion_thread_edit_view_spec.js (100%) rename common/static/{coffee/spec/discussion/view/discussion_thread_list_view_spec.coffee => common/js/spec/discussion/view/discussion_thread_list_view_spec.js} (100%) rename common/static/{coffee/spec/discussion/view/discussion_thread_profile_view_spec.coffee => common/js/spec/discussion/view/discussion_thread_profile_view_spec.js} (100%) rename common/static/{coffee/spec/discussion/view/discussion_thread_show_view_spec.coffee => common/js/spec/discussion/view/discussion_thread_show_view_spec.js} (100%) rename common/static/{coffee/spec/discussion/view/discussion_thread_view_spec.coffee => common/js/spec/discussion/view/discussion_thread_view_spec.js} (100%) rename common/static/{coffee => common/js}/spec/discussion/view/discussion_topic_menu_view_spec.js (100%) rename common/static/{coffee/spec/discussion/view/discussion_user_profile_view_spec.coffee => common/js/spec/discussion/view/discussion_user_profile_view_spec.js} (100%) rename common/static/{coffee/spec/discussion/view/discussion_view_spec_helper.coffee => common/js/spec/discussion/view/discussion_view_spec_helper.js} (100%) rename common/static/{coffee/spec/discussion/view/new_post_view_spec.coffee => common/js/spec/discussion/view/new_post_view_spec.js} (100%) rename common/static/{coffee/spec/discussion/view/response_comment_show_view_spec.coffee => common/js/spec/discussion/view/response_comment_show_view_spec.js} (100%) rename common/static/{coffee/spec/discussion/view/response_comment_view_spec.coffee => common/js/spec/discussion/view/response_comment_view_spec.js} (100%) rename common/static/{coffee/spec/discussion/view/thread_response_show_view_spec.coffee => common/js/spec/discussion/view/thread_response_show_view_spec.js} (100%) rename common/static/{coffee/spec/discussion/view/thread_response_view_spec.coffee => common/js/spec/discussion/view/thread_response_view_spec.js} (100%) rename common/static/{coffee/spec/discussion/discussion_spec_helper.coffee => common/js/spec_helpers/discussion_spec_helper.js} (100%) diff --git a/common/static/coffee/src/discussion/content.coffee b/common/static/common/js/discussion/content.js similarity index 100% rename from common/static/coffee/src/discussion/content.coffee rename to common/static/common/js/discussion/content.js diff --git a/common/static/coffee/src/discussion/discussion.coffee b/common/static/common/js/discussion/discussion.js similarity index 100% rename from common/static/coffee/src/discussion/discussion.coffee rename to common/static/common/js/discussion/discussion.js diff --git a/common/static/coffee/src/discussion/discussion_module_view.coffee b/common/static/common/js/discussion/discussion_module_view.js similarity index 100% rename from common/static/coffee/src/discussion/discussion_module_view.coffee rename to common/static/common/js/discussion/discussion_module_view.js diff --git a/common/static/coffee/src/discussion/discussion_router.coffee b/common/static/common/js/discussion/discussion_router.js similarity index 100% rename from common/static/coffee/src/discussion/discussion_router.coffee rename to common/static/common/js/discussion/discussion_router.js diff --git a/common/static/coffee/src/discussion/main.coffee b/common/static/common/js/discussion/main.js similarity index 100% rename from common/static/coffee/src/discussion/main.coffee rename to common/static/common/js/discussion/main.js diff --git a/common/static/coffee/src/discussion/models/discussion_course_settings.coffee b/common/static/common/js/discussion/models/discussion_course_settings.js similarity index 100% rename from common/static/coffee/src/discussion/models/discussion_course_settings.coffee rename to common/static/common/js/discussion/models/discussion_course_settings.js diff --git a/common/static/coffee/src/discussion/models/discussion_user.coffee b/common/static/common/js/discussion/models/discussion_user.js similarity index 100% rename from common/static/coffee/src/discussion/models/discussion_user.coffee rename to common/static/common/js/discussion/models/discussion_user.js diff --git a/common/static/coffee/src/discussion/utils.coffee b/common/static/common/js/discussion/utils.js similarity index 100% rename from common/static/coffee/src/discussion/utils.coffee rename to common/static/common/js/discussion/utils.js diff --git a/common/static/coffee/src/discussion/views/discussion_content_view.coffee b/common/static/common/js/discussion/views/discussion_content_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/discussion_content_view.coffee rename to common/static/common/js/discussion/views/discussion_content_view.js diff --git a/common/static/coffee/src/discussion/views/discussion_thread_edit_view.js b/common/static/common/js/discussion/views/discussion_thread_edit_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/discussion_thread_edit_view.js rename to common/static/common/js/discussion/views/discussion_thread_edit_view.js diff --git a/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee b/common/static/common/js/discussion/views/discussion_thread_list_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee rename to common/static/common/js/discussion/views/discussion_thread_list_view.js diff --git a/common/static/coffee/src/discussion/views/discussion_thread_profile_view.coffee b/common/static/common/js/discussion/views/discussion_thread_profile_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/discussion_thread_profile_view.coffee rename to common/static/common/js/discussion/views/discussion_thread_profile_view.js diff --git a/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee b/common/static/common/js/discussion/views/discussion_thread_show_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee rename to common/static/common/js/discussion/views/discussion_thread_show_view.js diff --git a/common/static/coffee/src/discussion/views/discussion_thread_view.coffee b/common/static/common/js/discussion/views/discussion_thread_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/discussion_thread_view.coffee rename to common/static/common/js/discussion/views/discussion_thread_view.js diff --git a/common/static/coffee/src/discussion/views/discussion_topic_menu_view.js b/common/static/common/js/discussion/views/discussion_topic_menu_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/discussion_topic_menu_view.js rename to common/static/common/js/discussion/views/discussion_topic_menu_view.js diff --git a/common/static/coffee/src/discussion/views/discussion_user_profile_view.coffee b/common/static/common/js/discussion/views/discussion_user_profile_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/discussion_user_profile_view.coffee rename to common/static/common/js/discussion/views/discussion_user_profile_view.js diff --git a/common/static/coffee/src/discussion/views/new_post_view.coffee b/common/static/common/js/discussion/views/new_post_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/new_post_view.coffee rename to common/static/common/js/discussion/views/new_post_view.js diff --git a/common/static/coffee/src/discussion/views/response_comment_edit_view.coffee b/common/static/common/js/discussion/views/response_comment_edit_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/response_comment_edit_view.coffee rename to common/static/common/js/discussion/views/response_comment_edit_view.js diff --git a/common/static/coffee/src/discussion/views/response_comment_show_view.coffee b/common/static/common/js/discussion/views/response_comment_show_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/response_comment_show_view.coffee rename to common/static/common/js/discussion/views/response_comment_show_view.js diff --git a/common/static/coffee/src/discussion/views/response_comment_view.coffee b/common/static/common/js/discussion/views/response_comment_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/response_comment_view.coffee rename to common/static/common/js/discussion/views/response_comment_view.js diff --git a/common/static/coffee/src/discussion/views/thread_response_edit_view.coffee b/common/static/common/js/discussion/views/thread_response_edit_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/thread_response_edit_view.coffee rename to common/static/common/js/discussion/views/thread_response_edit_view.js diff --git a/common/static/coffee/src/discussion/views/thread_response_show_view.coffee b/common/static/common/js/discussion/views/thread_response_show_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/thread_response_show_view.coffee rename to common/static/common/js/discussion/views/thread_response_show_view.js diff --git a/common/static/coffee/src/discussion/views/thread_response_view.coffee b/common/static/common/js/discussion/views/thread_response_view.js similarity index 100% rename from common/static/coffee/src/discussion/views/thread_response_view.coffee rename to common/static/common/js/discussion/views/thread_response_view.js diff --git a/common/static/coffee/spec/discussion/content_spec.coffee b/common/static/common/js/spec/discussion/content_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/content_spec.coffee rename to common/static/common/js/spec/discussion/content_spec.js diff --git a/common/static/coffee/spec/discussion/utils_spec.coffee b/common/static/common/js/spec/discussion/utils_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/utils_spec.coffee rename to common/static/common/js/spec/discussion/utils_spec.js diff --git a/common/static/coffee/spec/discussion/view/discussion_content_view_spec.coffee b/common/static/common/js/spec/discussion/view/discussion_content_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/discussion_content_view_spec.coffee rename to common/static/common/js/spec/discussion/view/discussion_content_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/discussion_thread_edit_view_spec.js b/common/static/common/js/spec/discussion/view/discussion_thread_edit_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/discussion_thread_edit_view_spec.js rename to common/static/common/js/spec/discussion/view/discussion_thread_edit_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/discussion_thread_list_view_spec.coffee b/common/static/common/js/spec/discussion/view/discussion_thread_list_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/discussion_thread_list_view_spec.coffee rename to common/static/common/js/spec/discussion/view/discussion_thread_list_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/discussion_thread_profile_view_spec.coffee b/common/static/common/js/spec/discussion/view/discussion_thread_profile_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/discussion_thread_profile_view_spec.coffee rename to common/static/common/js/spec/discussion/view/discussion_thread_profile_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/discussion_thread_show_view_spec.coffee b/common/static/common/js/spec/discussion/view/discussion_thread_show_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/discussion_thread_show_view_spec.coffee rename to common/static/common/js/spec/discussion/view/discussion_thread_show_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/discussion_thread_view_spec.coffee b/common/static/common/js/spec/discussion/view/discussion_thread_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/discussion_thread_view_spec.coffee rename to common/static/common/js/spec/discussion/view/discussion_thread_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/discussion_topic_menu_view_spec.js b/common/static/common/js/spec/discussion/view/discussion_topic_menu_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/discussion_topic_menu_view_spec.js rename to common/static/common/js/spec/discussion/view/discussion_topic_menu_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/discussion_user_profile_view_spec.coffee b/common/static/common/js/spec/discussion/view/discussion_user_profile_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/discussion_user_profile_view_spec.coffee rename to common/static/common/js/spec/discussion/view/discussion_user_profile_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/discussion_view_spec_helper.coffee b/common/static/common/js/spec/discussion/view/discussion_view_spec_helper.js similarity index 100% rename from common/static/coffee/spec/discussion/view/discussion_view_spec_helper.coffee rename to common/static/common/js/spec/discussion/view/discussion_view_spec_helper.js diff --git a/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee b/common/static/common/js/spec/discussion/view/new_post_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/new_post_view_spec.coffee rename to common/static/common/js/spec/discussion/view/new_post_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/response_comment_show_view_spec.coffee b/common/static/common/js/spec/discussion/view/response_comment_show_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/response_comment_show_view_spec.coffee rename to common/static/common/js/spec/discussion/view/response_comment_show_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/response_comment_view_spec.coffee b/common/static/common/js/spec/discussion/view/response_comment_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/response_comment_view_spec.coffee rename to common/static/common/js/spec/discussion/view/response_comment_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/thread_response_show_view_spec.coffee b/common/static/common/js/spec/discussion/view/thread_response_show_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/thread_response_show_view_spec.coffee rename to common/static/common/js/spec/discussion/view/thread_response_show_view_spec.js diff --git a/common/static/coffee/spec/discussion/view/thread_response_view_spec.coffee b/common/static/common/js/spec/discussion/view/thread_response_view_spec.js similarity index 100% rename from common/static/coffee/spec/discussion/view/thread_response_view_spec.coffee rename to common/static/common/js/spec/discussion/view/thread_response_view_spec.js diff --git a/common/static/coffee/spec/discussion/discussion_spec_helper.coffee b/common/static/common/js/spec_helpers/discussion_spec_helper.js similarity index 100% rename from common/static/coffee/spec/discussion/discussion_spec_helper.coffee rename to common/static/common/js/spec_helpers/discussion_spec_helper.js From 2b8c02a759c04477f1d003a86f383a860b1b85a6 Mon Sep 17 00:00:00 2001 From: "E. Kolpakov" Date: Thu, 16 Jun 2016 10:51:34 -0700 Subject: [PATCH 2/2] Discussion coffee files to JS --- .../static/coffee/spec/discussion/.gitignore | 2 - .../static/coffee/src/discussion/.gitignore | 2 - common/static/common/js/discussion/content.js | 566 ++++--- .../static/common/js/discussion/discussion.js | 327 ++-- .../js/discussion/discussion_module_view.js | 405 +++-- .../common/js/discussion/discussion_router.js | 233 ++- common/static/common/js/discussion/main.js | 114 +- .../models/discussion_course_settings.js | 36 +- .../js/discussion/models/discussion_user.js | 61 +- common/static/common/js/discussion/utils.js | 757 ++++++---- .../views/discussion_content_view.js | 775 ++++++---- .../views/discussion_thread_edit_view.js | 9 +- .../views/discussion_thread_list_view.js | 1319 ++++++++++------- .../views/discussion_thread_profile_view.js | 89 +- .../views/discussion_thread_show_view.js | 126 +- .../views/discussion_thread_view.js | 771 ++++++---- .../views/discussion_topic_menu_view.js | 16 +- .../views/discussion_user_profile_view.js | 144 +- .../js/discussion/views/new_post_view.js | 290 ++-- .../views/response_comment_edit_view.js | 77 +- .../views/response_comment_show_view.js | 118 +- .../discussion/views/response_comment_view.js | 227 ++- .../views/thread_response_edit_view.js | 77 +- .../views/thread_response_show_view.js | 106 +- .../discussion/views/thread_response_view.js | 508 ++++--- common/static/common/js/karma.common.conf.js | 1 + .../common/js/spec/discussion/content_spec.js | 271 ++-- .../common/js/spec/discussion/utils_spec.js | 115 +- .../view/discussion_content_view_spec.js | 90 +- .../view/discussion_thread_edit_view_spec.js | 22 +- .../view/discussion_thread_list_view_spec.js | 1296 ++++++++-------- .../discussion_thread_profile_view_spec.js | 264 ++-- .../view/discussion_thread_show_view_spec.js | 346 +++-- .../view/discussion_thread_view_spec.js | 876 ++++++----- .../view/discussion_topic_menu_view_spec.js | 13 +- .../view/discussion_user_profile_view_spec.js | 474 +++--- .../view/discussion_view_spec_helper.js | 222 +-- .../discussion/view/new_post_view_spec.js | 478 +++--- .../view/response_comment_show_view_spec.js | 209 +-- .../view/response_comment_view_spec.js | 336 +++-- .../view/thread_response_show_view_spec.js | 486 +++--- .../view/thread_response_view_spec.js | 213 +-- .../js/spec_helpers/discussion_spec_helper.js | 171 ++- .../js/spec/views/team_discussion_spec.js | 2 +- .../teams/js/spec/views/team_profile_spec.js | 2 +- lms/envs/common.py | 2 +- lms/static/lms/js/spec/main.js | 112 +- scripts/safelint_thresholds.json | 28 +- 48 files changed, 7858 insertions(+), 5326 deletions(-) delete mode 100644 common/static/coffee/spec/discussion/.gitignore delete mode 100644 common/static/coffee/src/discussion/.gitignore diff --git a/common/static/coffee/spec/discussion/.gitignore b/common/static/coffee/spec/discussion/.gitignore deleted file mode 100644 index ac5223af30..0000000000 --- a/common/static/coffee/spec/discussion/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -!view/discussion_thread_edit_view_spec.js -!view/discussion_topic_menu_view_spec.js diff --git a/common/static/coffee/src/discussion/.gitignore b/common/static/coffee/src/discussion/.gitignore deleted file mode 100644 index 3c396b9365..0000000000 --- a/common/static/coffee/src/discussion/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -!views/discussion_thread_edit_view.js -!views/discussion_topic_menu_view.js diff --git a/common/static/common/js/discussion/content.js b/common/static/common/js/discussion/content.js index 49f199ab1c..111e4fd821 100644 --- a/common/static/common/js/discussion/content.js +++ b/common/static/common/js/discussion/content.js @@ -1,218 +1,436 @@ -if Backbone? - class @Content extends Backbone.Model +/* globals DiscussionUtil */ +(function() { + 'use strict'; - @contents: {} - @contentInfos: {} + var __hasProp = {}.hasOwnProperty; - template: -> DiscussionUtil.getTemplate('_content') + function __extends(child, parent) { + for (var key in parent) { + if (__hasProp.call(parent, key)) { + child[key] = parent[key]; + } + } + function ctor() { + this.constructor = child; + } - actions: - editable: '.admin-edit' - can_reply: '.discussion-reply' - can_delete: '.admin-delete' - can_openclose: '.admin-openclose' - can_report: '.admin-report' - can_vote: '.admin-vote' + ctor.prototype = parent.prototype; + child.prototype = new ctor(); + child.__super__ = parent.prototype; + return child; + } - urlMappers: {} + var __indexOf = [].indexOf || function(item) { + for (var i = 0, l = this.length; i < l; i++) { + if (i in this && this[i] === item) { + return i; + } + } + return -1; + }; - urlFor: (name) -> - @urlMappers[name].apply(@) + if (typeof Backbone !== "undefined" && Backbone !== null) { + this.Content = (function(_super) { - can: (action) -> - (@get('ability') || {})[action] + __extends(Content, _super); - # Default implementation - canBeEndorsed: -> false + function Content() { + return Content.__super__.constructor.apply(this, arguments); + } - updateInfo: (info) -> - if info - @set('ability', info.ability) - @set('voted', info.voted) - @set('subscribed', info.subscribed) + Content.contents = {}; - addComment: (comment, options) -> - options ||= {} - if not options.silent - thread = @get('thread') - comments_count = parseInt(thread.get('comments_count')) - thread.set('comments_count', comments_count + 1) - @get('children').push comment - model = new Comment $.extend {}, comment, { thread: @get('thread') } - @get('comments').add model - @trigger "comment:add" - model + Content.contentInfos = {}; - removeComment: (comment) -> - thread = @get('thread') - comments_count = parseInt(thread.get('comments_count')) - thread.set('comments_count', comments_count - 1 - comment.getCommentsCount()) - @trigger "comment:remove" + Content.prototype.template = function() { + return DiscussionUtil.getTemplate('_content'); + }; - resetComments: (children) -> - @set 'children', [] - @set 'comments', new Comments() - for comment in (children || []) - @addComment comment, { silent: true } + Content.prototype.actions = { + editable: '.admin-edit', + can_reply: '.discussion-reply', + can_delete: '.admin-delete', + can_openclose: '.admin-openclose', + can_report: '.admin-report', + can_vote: '.admin-vote' + }; - initialize: -> - Content.addContent @id, @ - userId = @get('user_id') - if userId? - @set('staff_authored', DiscussionUtil.isStaff(userId)) - @set('community_ta_authored', DiscussionUtil.isTA(userId)) - else - @set('staff_authored', false) - @set('community_ta_authored', false) - if Content.getInfo(@id) - @updateInfo(Content.getInfo(@id)) - @set 'user_url', DiscussionUtil.urlFor('user_profile', userId) - @resetComments(@get('children')) + Content.prototype.urlMappers = {}; - remove: -> + Content.prototype.urlFor = function(name) { + return this.urlMappers[name].apply(this); + }; - if @get('type') == 'comment' - @get('thread').removeComment(@) - @get('thread').trigger "comment:remove", @ - else - @trigger "thread:remove", @ + Content.prototype.can = function(action) { + return (this.get('ability') || {})[action]; + }; - @addContent: (id, content) -> @contents[id] = content + Content.prototype.canBeEndorsed = function() { + return false; + }; - @getContent: (id) -> @contents[id] + Content.prototype.updateInfo = function(info) { + if (info) { + this.set('ability', info.ability); + this.set('voted', info.voted); + return this.set('subscribed', info.subscribed); + } + }; - @getInfo: (id) -> - @contentInfos[id] + Content.prototype.addComment = function(comment, options) { + var comments_count, model, thread; + options = (options) ? options : {}; + if (!options.silent) { + thread = this.get('thread'); + comments_count = parseInt(thread.get('comments_count')); + thread.set('comments_count', comments_count + 1); + } + this.get('children').push(comment); + model = new Comment($.extend({}, comment, { + thread: this.get('thread') + })); + this.get('comments').add(model); + this.trigger("comment:add"); + return model; + }; - @loadContentInfos: (infos) -> - for id, info of infos - if @getContent(id) - @getContent(id).updateInfo(info) - $.extend @contentInfos, infos + Content.prototype.removeComment = function(comment) { + var comments_count, thread; + thread = this.get('thread'); + comments_count = parseInt(thread.get('comments_count')); + thread.set('comments_count', comments_count - 1 - comment.getCommentsCount()); + return this.trigger("comment:remove"); + }; - pinThread: -> - pinned = @get("pinned") - @set("pinned",pinned) - @trigger "change", @ + Content.prototype.resetComments = function(children) { + var comment, _i, _len, _ref, _results; + this.set('children', []); + this.set('comments', new Comments()); // jshint ignore:line + _ref = children || []; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + comment = _ref[_i]; + _results.push(this.addComment(comment, { + silent: true + })); + } + return _results; + }; - unPinThread: -> - pinned = @get("pinned") - @set("pinned",pinned) - @trigger "change", @ + Content.prototype.initialize = function() { + var userId; + Content.addContent(this.id, this); + userId = this.get('user_id'); + if (userId) { + this.set('staff_authored', DiscussionUtil.isStaff(userId)); + this.set('community_ta_authored', DiscussionUtil.isTA(userId)); + } else { + this.set('staff_authored', false); + this.set('community_ta_authored', false); + } + if (Content.getInfo(this.id)) { + this.updateInfo(Content.getInfo(this.id)); + } + this.set('user_url', DiscussionUtil.urlFor('user_profile', userId)); + return this.resetComments(this.get('children')); + }; - flagAbuse: -> - temp_array = @get("abuse_flaggers") - temp_array.push(window.user.get('id')) - @set("abuse_flaggers",temp_array) - @trigger "change", @ + Content.prototype.remove = function() { + if (this.get('type') === 'comment') { + this.get('thread').removeComment(this); + return this.get('thread').trigger("comment:remove", this); + } else { + return this.trigger("thread:remove", this); + } + }; - unflagAbuse: -> - @get("abuse_flaggers").pop(window.user.get('id')) - @trigger "change", @ + Content.addContent = function(id, content) { + this.contents[id] = content; + }; - isFlagged: -> - user = DiscussionUtil.getUser() - flaggers = @get("abuse_flaggers") - user and (user.id in flaggers or (DiscussionUtil.isPrivilegedUser(user.id) and flaggers.length > 0)) + Content.getContent = function(id) { + return this.contents[id]; + }; - incrementVote: (increment) -> - newVotes = _.clone(@get("votes")) - newVotes.up_count = newVotes.up_count + increment - @set("votes", newVotes) + Content.getInfo = function(id) { + return this.contentInfos[id]; + }; - vote: -> - @incrementVote(1) + Content.loadContentInfos = function(infos) { + var id, info; + for (id in infos) { + if (infos.hasOwnProperty(id)) { + info = infos[id]; + if (this.getContent(id)) { + this.getContent(id).updateInfo(info); + } + } + } + return $.extend(this.contentInfos, infos); + }; - unvote: -> - @incrementVote(-1) + Content.prototype.pinThread = function() { + var pinned; + pinned = this.get("pinned"); + this.set("pinned", pinned); + return this.trigger("change", this); + }; - class @Thread extends @Content - urlMappers: - 'retrieve' : -> DiscussionUtil.urlFor('retrieve_single_thread', @.get('commentable_id'), @id) - 'reply' : -> DiscussionUtil.urlFor('create_comment', @id) - 'unvote' : -> DiscussionUtil.urlFor("undo_vote_for_#{@get('type')}", @id) - 'upvote' : -> DiscussionUtil.urlFor("upvote_#{@get('type')}", @id) - 'downvote' : -> DiscussionUtil.urlFor("downvote_#{@get('type')}", @id) - 'close' : -> DiscussionUtil.urlFor('openclose_thread', @id) - 'update' : -> DiscussionUtil.urlFor('update_thread', @id) - '_delete' : -> DiscussionUtil.urlFor('delete_thread', @id) - 'follow' : -> DiscussionUtil.urlFor('follow_thread', @id) - 'unfollow' : -> DiscussionUtil.urlFor('unfollow_thread', @id) - 'flagAbuse' : -> DiscussionUtil.urlFor("flagAbuse_#{@get('type')}", @id) - 'unFlagAbuse' : -> DiscussionUtil.urlFor("unFlagAbuse_#{@get('type')}", @id) - 'pinThread' : -> DiscussionUtil.urlFor("pin_thread", @id) - 'unPinThread' : -> DiscussionUtil.urlFor("un_pin_thread", @id) + Content.prototype.unPinThread = function() { + var pinned; + pinned = this.get("pinned"); + this.set("pinned", pinned); + return this.trigger("change", this); + }; - initialize: -> - @set('thread', @) - super() + Content.prototype.flagAbuse = function() { + var temp_array; + temp_array = this.get("abuse_flaggers"); + temp_array.push(window.user.get('id')); + this.set("abuse_flaggers", temp_array); + return this.trigger("change", this); + }; - comment: -> - @set("comments_count", parseInt(@get("comments_count")) + 1) + Content.prototype.unflagAbuse = function() { + this.get("abuse_flaggers").pop(window.user.get('id')); + return this.trigger("change", this); + }; - follow: -> - @set('subscribed', true) + Content.prototype.isFlagged = function() { + var flaggers, user; + user = DiscussionUtil.getUser(); + flaggers = this.get("abuse_flaggers"); + return user && ( + (__indexOf.call(flaggers, user.id) >= 0) || + (DiscussionUtil.isPrivilegedUser(user.id) && flaggers.length > 0) + ); + }; - unfollow: -> - @set('subscribed', false) + Content.prototype.incrementVote = function(increment) { + var newVotes; + newVotes = _.clone(this.get("votes")); + newVotes.up_count = newVotes.up_count + increment; + return this.set("votes", newVotes); + }; - display_body: -> - if @has("highlighted_body") - String(@get("highlighted_body")).replace(//g, '').replace(/<\/highlight>/g, '') - else - @get("body") + Content.prototype.vote = function() { + return this.incrementVote(1); + }; - display_title: -> - if @has("highlighted_title") - String(@get("highlighted_title")).replace(//g, '').replace(/<\/highlight>/g, '') - else - @get("title") + Content.prototype.unvote = function() { + return this.incrementVote(-1); + }; - toJSON: -> - json_attributes = _.clone(@attributes) - _.extend(json_attributes, { title: @display_title(), body: @display_body() }) + return Content; - created_at_date: -> - new Date(@get("created_at")) + })(Backbone.Model); + this.Thread = (function(_super) { - created_at_time: -> - new Date(@get("created_at")).getTime() + __extends(Thread, _super); - hasResponses: -> - @get('comments_count') > 0 + function Thread() { + return Thread.__super__.constructor.apply(this, arguments); + } - class @Comment extends @Content - urlMappers: - 'reply': -> DiscussionUtil.urlFor('create_sub_comment', @id) - 'unvote': -> DiscussionUtil.urlFor("undo_vote_for_#{@get('type')}", @id) - 'upvote': -> DiscussionUtil.urlFor("upvote_#{@get('type')}", @id) - 'downvote': -> DiscussionUtil.urlFor("downvote_#{@get('type')}", @id) - 'endorse': -> DiscussionUtil.urlFor('endorse_comment', @id) - 'update': -> DiscussionUtil.urlFor('update_comment', @id) - '_delete': -> DiscussionUtil.urlFor('delete_comment', @id) - 'flagAbuse' : -> DiscussionUtil.urlFor("flagAbuse_#{@get('type')}", @id) - 'unFlagAbuse' : -> DiscussionUtil.urlFor("unFlagAbuse_#{@get('type')}", @id) + Thread.prototype.urlMappers = { + 'retrieve': function() { + return DiscussionUtil.urlFor('retrieve_single_thread', this.get('commentable_id'), this.id); + }, + 'reply': function() { + return DiscussionUtil.urlFor('create_comment', this.id); + }, + 'unvote': function() { + return DiscussionUtil.urlFor("undo_vote_for_" + (this.get('type')), this.id); + }, + 'upvote': function() { + return DiscussionUtil.urlFor("upvote_" + (this.get('type')), this.id); + }, + 'downvote': function() { + return DiscussionUtil.urlFor("downvote_" + (this.get('type')), this.id); + }, + 'close': function() { + return DiscussionUtil.urlFor('openclose_thread', this.id); + }, + 'update': function() { + return DiscussionUtil.urlFor('update_thread', this.id); + }, + '_delete': function() { + return DiscussionUtil.urlFor('delete_thread', this.id); + }, + 'follow': function() { + return DiscussionUtil.urlFor('follow_thread', this.id); + }, + 'unfollow': function() { + return DiscussionUtil.urlFor('unfollow_thread', this.id); + }, + 'flagAbuse': function() { + return DiscussionUtil.urlFor("flagAbuse_" + (this.get('type')), this.id); + }, + 'unFlagAbuse': function() { + return DiscussionUtil.urlFor("unFlagAbuse_" + (this.get('type')), this.id); + }, + 'pinThread': function() { + return DiscussionUtil.urlFor("pin_thread", this.id); + }, + 'unPinThread': function() { + return DiscussionUtil.urlFor("un_pin_thread", this.id); + } + }; - getCommentsCount: -> - count = 0 - @get('comments').each (comment) -> - count += comment.getCommentsCount() + 1 - count + Thread.prototype.initialize = function() { + this.set('thread', this); + return Thread.__super__.initialize.call(this); + }; - canBeEndorsed: => - user_id = window.user.get("id") - user_id && ( - DiscussionUtil.isPrivilegedUser(user_id) || - (@get('thread').get('thread_type') == 'question' && @get('thread').get('user_id') == user_id) - ) + Thread.prototype.comment = function() { + return this.set("comments_count", parseInt(this.get("comments_count")) + 1); + }; - class @Comments extends Backbone.Collection + Thread.prototype.follow = function() { + return this.set('subscribed', true); + }; - model: Comment + Thread.prototype.unfollow = function() { + return this.set('subscribed', false); + }; - initialize: -> - @bind "add", (item) => - item.collection = @ + Thread.prototype.display_body = function() { + if (this.has("highlighted_body")) { + return String(this.get("highlighted_body")) + .replace(//g, '') + .replace(/<\/highlight>/g, ''); + } else { + return this.get("body"); + } + }; - find: (id) -> - _.first @where(id: id) + Thread.prototype.display_title = function() { + if (this.has("highlighted_title")) { + return String(this.get("highlighted_title")) + .replace(//g, '') + .replace(/<\/highlight>/g, ''); + } else { + return this.get("title"); + } + }; + + Thread.prototype.toJSON = function() { + var json_attributes; + json_attributes = _.clone(this.attributes); + return _.extend(json_attributes, { + title: this.display_title(), + body: this.display_body() + }); + }; + + Thread.prototype.created_at_date = function() { + return new Date(this.get("created_at")); + }; + + Thread.prototype.created_at_time = function() { + return new Date(this.get("created_at")).getTime(); + }; + + Thread.prototype.hasResponses = function() { + return this.get('comments_count') > 0; + }; + + return Thread; + + })(this.Content); + this.Comment = (function(_super) { + + __extends(Comment, _super); + + function Comment() { + var self = this; + this.canBeEndorsed = function() { + return Comment.prototype.canBeEndorsed.apply(self, arguments); + }; + return Comment.__super__.constructor.apply(this, arguments); + } + + Comment.prototype.urlMappers = { + 'reply': function() { + return DiscussionUtil.urlFor('create_sub_comment', this.id); + }, + 'unvote': function() { + return DiscussionUtil.urlFor("undo_vote_for_" + (this.get('type')), this.id); + }, + 'upvote': function() { + return DiscussionUtil.urlFor("upvote_" + (this.get('type')), this.id); + }, + 'downvote': function() { + return DiscussionUtil.urlFor("downvote_" + (this.get('type')), this.id); + }, + 'endorse': function() { + return DiscussionUtil.urlFor('endorse_comment', this.id); + }, + 'update': function() { + return DiscussionUtil.urlFor('update_comment', this.id); + }, + '_delete': function() { + return DiscussionUtil.urlFor('delete_comment', this.id); + }, + 'flagAbuse': function() { + return DiscussionUtil.urlFor("flagAbuse_" + (this.get('type')), this.id); + }, + 'unFlagAbuse': function() { + return DiscussionUtil.urlFor("unFlagAbuse_" + (this.get('type')), this.id); + } + }; + + Comment.prototype.getCommentsCount = function() { + var count; + count = 0; + this.get('comments').each(function(comment) { + return count += comment.getCommentsCount() + 1; + }); + return count; + }; + + Comment.prototype.canBeEndorsed = function() { + var user_id; + user_id = window.user.get("id"); + return user_id && ( + DiscussionUtil.isPrivilegedUser(user_id) || + ( + this.get('thread').get('thread_type') === 'question' && + this.get('thread').get('user_id') === user_id + ) + ); + }; + + return Comment; + + })(this.Content); + + this.Comments = (function(_super) { + + __extends(Comments, _super); + + function Comments() { + return Comments.__super__.constructor.apply(this, arguments); + } + + Comments.prototype.model = Comment; + + Comments.prototype.initialize = function() { + var self = this; + return this.bind("add", function(item) { + item.collection = self; + }); + }; + + Comments.prototype.find = function(id) { + return _.first(this.where({ + id: id + })); + }; + + return Comments; + + })(Backbone.Collection); + } + +}).call(window); diff --git a/common/static/common/js/discussion/discussion.js b/common/static/common/js/discussion/discussion.js index 3b0c68b1ef..dfa272c04b 100644 --- a/common/static/common/js/discussion/discussion.js +++ b/common/static/common/js/discussion/discussion.js @@ -1,131 +1,222 @@ -if Backbone? - class @Discussion extends Backbone.Collection - model: Thread +/* globals Thread, DiscussionUtil, Content */ +(function() { + 'use strict'; + var __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { + for (var key in parent) { + if (__hasProp.call(parent, key)) { + child[key] = parent[key]; + } + } + function ctor() { + this.constructor = child; + } - initialize: (models, options={})-> - @pages = options['pages'] || 1 - @current_page = 1 - @sort_preference = options['sort'] - @bind "add", (item) => - item.discussion = @ - @setSortComparator(@sort_preference) - @on "thread:remove", (thread) => - @remove(thread) + ctor.prototype = parent.prototype; + child.prototype = new ctor(); + child.__super__ = parent.prototype; + return child; + }; - find: (id) -> - _.first @where(id: id) + if (typeof Backbone !== "undefined" && Backbone !== null) { + this.Discussion = (function(_super) { - hasMorePages: -> - @current_page < @pages + __extends(Discussion, _super); - setSortComparator: (sortBy) -> - switch sortBy - when 'activity' then @comparator = @sortByDateRecentFirst - when 'votes' then @comparator = @sortByVotes - when 'comments' then @comparator = @sortByComments + function Discussion() { + return Discussion.__super__.constructor.apply(this, arguments); + } - addThread: (thread, options) -> - # TODO: Check for existing thread with same ID in a faster way - if not @find(thread.id) - options ||= {} - model = new Thread thread - @add model - model + Discussion.prototype.model = Thread; - retrieveAnotherPage: (mode, options={}, sort_options={}, error=null)-> - data = { page: @current_page + 1 } - if _.contains(["unread", "unanswered", "flagged"], options.filter) - data[options.filter] = true - switch mode - when 'search' - url = DiscussionUtil.urlFor 'search' - data['text'] = options.search_text - when 'commentables' - url = DiscussionUtil.urlFor 'search' - data['commentable_ids'] = options.commentable_ids - when 'all' - url = DiscussionUtil.urlFor 'threads' - when 'followed' - url = DiscussionUtil.urlFor 'followed_threads', options.user_id - if options['group_id'] - data['group_id'] = options['group_id'] - data['sort_key'] = sort_options.sort_key || 'activity' - data['sort_order'] = sort_options.sort_order || 'desc' - DiscussionUtil.safeAjax - $elem: @$el - url: url - data: data - dataType: 'json' - success: (response, textStatus) => - models = @models - new_threads = [new Thread(data) for data in response.discussion_data][0] - new_collection = _.union(models, new_threads) - Content.loadContentInfos(response.annotated_content_info) - @pages = response.num_pages - @current_page = response.page - @reset new_collection - error: error + Discussion.prototype.initialize = function(models, options) { + var self = this; + if (!options) { + options = {}; + } + this.pages = options.pages || 1; + this.current_page = 1; + this.sort_preference = options.sort; + this.bind("add", function(item) { + item.discussion = self; + }); + this.setSortComparator(this.sort_preference); + return this.on("thread:remove", function(thread) { + self.remove(thread); + }); + }; - sortByDate: (thread) -> - # - # The comment client asks each thread for a value by which to sort the collection - # and calls this sort routine regardless of the order returned from the LMS/comments service - # so, this takes advantage of this per-thread value and returns tomorrow's date - # for pinned threads, ensuring that they appear first, (which is the intent of pinned threads) - # - @pinnedThreadsSortComparatorWithDate(thread, true) + Discussion.prototype.find = function(id) { + return _.first(this.where({ + id: id + })); + }; + Discussion.prototype.hasMorePages = function() { + return this.current_page < this.pages; + }; - sortByDateRecentFirst: (thread) -> - # - # Same as above - # but negative to flip the order (newest first) - # - @pinnedThreadsSortComparatorWithDate(thread, false) - #return String.fromCharCode.apply(String, - # _.map(thread.get("created_at").split(""), - # ((c) -> return 0xffff - c.charChodeAt())) - #) + Discussion.prototype.setSortComparator = function(sortBy) { + switch (sortBy) { + case 'activity': + this.comparator = this.sortByDateRecentFirst; + break; + case 'votes': + this.comparator = this.sortByVotes; + break; + case 'comments': + this.comparator = this.sortByComments; + break; + } + }; - sortByVotes: (thread1, thread2) -> - thread1_count = parseInt(thread1.get("votes")['up_count']) - thread2_count = parseInt(thread2.get("votes")['up_count']) - @pinnedThreadsSortComparatorWithCount(thread1, thread2, thread1_count, thread2_count) + Discussion.prototype.addThread = function(thread) { + var model; + if (!this.find(thread.id)) { + model = new Thread(thread); + this.add(model); + return model; + } + }; - sortByComments: (thread1, thread2) -> - thread1_count = parseInt(thread1.get("comments_count")) - thread2_count = parseInt(thread2.get("comments_count")) - @pinnedThreadsSortComparatorWithCount(thread1, thread2, thread1_count, thread2_count) + Discussion.prototype.retrieveAnotherPage = function(mode, options, sort_options, error) { + var data, url, + self = this; + if (options === null) { + options = {}; + } + if (sort_options === null) { + sort_options = {}; + } + data = { + page: this.current_page + 1 + }; + if (_.contains(["unread", "unanswered", "flagged"], options.filter)) { + data[options.filter] = true; + } + switch (mode) { + case 'search': + url = DiscussionUtil.urlFor('search'); + data.text = options.search_text; + break; + case 'commentables': + url = DiscussionUtil.urlFor('search'); + data.commentable_ids = options.commentable_ids; + break; + case 'all': + url = DiscussionUtil.urlFor('threads'); + break; + case 'followed': + url = DiscussionUtil.urlFor('followed_threads', options.user_id); + } + if (options.group_id) { + data.group_id = options.group_id; + } + data.sort_key = sort_options.sort_key || 'activity'; + data.sort_order = sort_options.sort_order || 'desc'; + return DiscussionUtil.safeAjax({ + $elem: this.$el, + url: url, + data: data, + dataType: 'json', + success: function(response) { + var models, new_collection, new_threads; + models = self.models; + new_threads = [ + (function() { + var _i, _len, _ref, _results; + _ref = response.discussion_data; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + data = _ref[_i]; + _results.push(new Thread(data)); + } + return _results; + })() + ][0]; + new_collection = _.union(models, new_threads); + Content.loadContentInfos(response.annotated_content_info); + self.pages = response.num_pages; + self.current_page = response.page; + return self.reset(new_collection); + }, + error: error + }); + }; - pinnedThreadsSortComparatorWithCount: (thread1, thread2, thread1_count, thread2_count) -> - # if threads are pinned they should be displayed on top. - # Unpinned will be sorted by their property count - if thread1.get('pinned') and not thread2.get('pinned') - -1 - else if thread2.get('pinned') and not thread1.get('pinned') - 1 - else - if thread1_count > thread2_count - -1 - else if thread2_count > thread1_count - 1 - else - if thread1.created_at_time() > thread2.created_at_time() - -1 - else - 1 + Discussion.prototype.sortByDate = function(thread) { + /* + The comment client asks each thread for a value by which to sort the collection + and calls this sort routine regardless of the order returned from the LMS/comments service + so, this takes advantage of this per-thread value and returns tomorrow's date + for pinned threads, ensuring that they appear first, (which is the intent of pinned threads) + */ + return this.pinnedThreadsSortComparatorWithDate(thread, true); + }; - pinnedThreadsSortComparatorWithDate: (thread, ascending)-> - # if threads are pinned they should be displayed on top. - # Unpinned will be sorted by their last activity date - threadLastActivityAtTime = new Date(thread.get("last_activity_at")).getTime() - if thread.get('pinned') - #use tomorrow's date - today = new Date(); - preferredDate = new Date(today.getTime() + (24 * 60 * 60 * 1000) + threadLastActivityAtTime); - else - preferredDate = threadLastActivityAtTime - if ascending - preferredDate - else - -(preferredDate) + Discussion.prototype.sortByDateRecentFirst = function(thread) { + /* + Same as above + but negative to flip the order (newest first) + */ + return this.pinnedThreadsSortComparatorWithDate(thread, false); + }; + + Discussion.prototype.sortByVotes = function(thread1, thread2) { + var thread1_count, thread2_count; + thread1_count = parseInt(thread1.get("votes").up_count); + thread2_count = parseInt(thread2.get("votes").up_count); + return this.pinnedThreadsSortComparatorWithCount(thread1, thread2, thread1_count, thread2_count); + }; + + Discussion.prototype.sortByComments = function(thread1, thread2) { + var thread1_count, thread2_count; + thread1_count = parseInt(thread1.get("comments_count")); + thread2_count = parseInt(thread2.get("comments_count")); + return this.pinnedThreadsSortComparatorWithCount(thread1, thread2, thread1_count, thread2_count); + }; + + Discussion.prototype.pinnedThreadsSortComparatorWithCount = function( + thread1, thread2, thread1_count, thread2_count + ) { + if (thread1.get('pinned') && !thread2.get('pinned')) { + return -1; + } else if (thread2.get('pinned') && !thread1.get('pinned')) { + return 1; + } else { + if (thread1_count > thread2_count) { + return -1; + } else if (thread2_count > thread1_count) { + return 1; + } else { + if (thread1.created_at_time() > thread2.created_at_time()) { + return -1; + } else { + return 1; + } + } + } + }; + + Discussion.prototype.pinnedThreadsSortComparatorWithDate = function(thread, ascending) { + var preferredDate, threadLastActivityAtTime, today; + threadLastActivityAtTime = new Date(thread.get("last_activity_at")).getTime(); + if (thread.get('pinned')) { + today = new Date(); + preferredDate = new Date(today.getTime() + (24 * 60 * 60 * 1000) + threadLastActivityAtTime); + } else { + preferredDate = threadLastActivityAtTime; + } + if (ascending) { + return preferredDate; + } else { + return -preferredDate; + } + }; + + return Discussion; + + })(Backbone.Collection); + } + +}).call(window); diff --git a/common/static/common/js/discussion/discussion_module_view.js b/common/static/common/js/discussion/discussion_module_view.js index 198d48d34c..7ee44fa18e 100644 --- a/common/static/common/js/discussion/discussion_module_view.js +++ b/common/static/common/js/discussion/discussion_module_view.js @@ -1,173 +1,266 @@ -if Backbone? - class @DiscussionModuleView extends Backbone.View - events: - "click .discussion-show": "toggleDiscussion" - "keydown .discussion-show": - (event) -> DiscussionUtil.activateOnSpace(event, @toggleDiscussion) - "click .new-post-btn": "toggleNewPost" - "keydown .new-post-btn": - (event) -> DiscussionUtil.activateOnSpace(event, @toggleNewPost) - "click .discussion-paginator a": "navigateToPage" +/* globals Discussion, DiscussionUtil, DiscussionUser, DiscussionCourseSettings, DiscussionThreadView, Content, +NewPostView */ +(function() { + 'use strict'; + var __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { + for (var key in parent) { + if (__hasProp.call(parent, key)) { + child[key] = parent[key]; + } + } + function ctor() { + this.constructor = child; + } - page_re: /\?discussion_page=(\d+)/ - initialize: (options) -> - @toggleDiscussionBtn = @$(".discussion-show") - # Set the page if it was set in the URL. This is used to allow deep linking to pages - match = @page_re.exec(window.location.href) - @context = options.context or "course" # allowed values are "course" or "standalone" - if match - @page = parseInt(match[1]) - else - @page = 1 + ctor.prototype = parent.prototype; + child.prototype = new ctor(); + child.__super__ = parent.prototype; + return child; + }; - toggleNewPost: (event) => - event.preventDefault() - if !@newPostForm - @toggleDiscussion() - @isWaitingOnNewPost = true; - return - if @showed - @newPostForm.slideDown(300) - else - @newPostForm.show().focus() - @toggleDiscussionBtn.addClass('shown') - @toggleDiscussionBtn.find('.button-text').html(gettext("Hide Discussion")) - @$("section.discussion").slideDown() - @showed = true + if (typeof Backbone !== "undefined" && Backbone !== null) { + this.DiscussionModuleView = (function(_super) { - hideNewPost: => - @newPostForm.slideUp(300) + __extends(DiscussionModuleView, _super); - hideDiscussion: => - @$("section.discussion").slideUp() - @toggleDiscussionBtn.removeClass('shown') - @toggleDiscussionBtn.find('.button-text').html(gettext("Show Discussion")) - @showed = false + function DiscussionModuleView() { + var self = this; + this.navigateToPage = function() { + return DiscussionModuleView.prototype.navigateToPage.apply(self, arguments); + }; + this.renderPagination = function() { + return DiscussionModuleView.prototype.renderPagination.apply(self, arguments); + }; + this.addThread = function() { + return DiscussionModuleView.prototype.addThread.apply(self, arguments); + }; + this.renderDiscussion = function() { + return DiscussionModuleView.prototype.renderDiscussion.apply(self, arguments); + }; + this.loadPage = function() { + return DiscussionModuleView.prototype.loadPage.apply(self, arguments); + }; + this.toggleDiscussion = function() { + return DiscussionModuleView.prototype.toggleDiscussion.apply(self, arguments); + }; + this.hideDiscussion = function() { + return DiscussionModuleView.prototype.hideDiscussion.apply(self, arguments); + }; + this.hideNewPost = function() { + return DiscussionModuleView.prototype.hideNewPost.apply(self, arguments); + }; + this.toggleNewPost = function() { + return DiscussionModuleView.prototype.toggleNewPost.apply(self, arguments); + }; + return DiscussionModuleView.__super__.constructor.apply(this, arguments); + } - toggleDiscussion: (event) => - if @showed - @hideDiscussion() - else - @toggleDiscussionBtn.addClass('shown') - @toggleDiscussionBtn.find('.button-text').html(gettext("Hide Discussion")) + DiscussionModuleView.prototype.events = { + "click .discussion-show": "toggleDiscussion", + "keydown .discussion-show": function(event) { + return DiscussionUtil.activateOnSpace(event, this.toggleDiscussion); + }, + "click .new-post-btn": "toggleNewPost", + "keydown .new-post-btn": function(event) { + return DiscussionUtil.activateOnSpace(event, this.toggleNewPost); + }, + "click .discussion-paginator a": "navigateToPage" + }; - if @retrieved - @$("section.discussion").slideDown() - @showed = true - else - $elem = @toggleDiscussionBtn - @loadPage( - $elem, - => - @hideDiscussion() - DiscussionUtil.discussionAlert( - gettext("Sorry"), - gettext("We had some trouble loading the discussion. Please try again.") - ) - ) + DiscussionModuleView.prototype.page_re = /\?discussion_page=(\d+)/; - loadPage: ($elem, error) => - discussionId = @$el.data("discussion-id") - url = DiscussionUtil.urlFor('retrieve_discussion', discussionId) + "?page=#{@page}" - DiscussionUtil.safeAjax - $elem: $elem - $loading: $elem - takeFocus: true - url: url - type: "GET" - dataType: 'json' - success: (response, textStatus, jqXHR) => @renderDiscussion($elem, response, textStatus, discussionId) - error: error + DiscussionModuleView.prototype.initialize = function(options) { + var match; + this.toggleDiscussionBtn = this.$(".discussion-show"); + match = this.page_re.exec(window.location.href); + this.context = options.context || "course"; + if (match) { + this.page = parseInt(match[1]); + } else { + this.page = 1; + } + }; - renderDiscussion: ($elem, response, textStatus, discussionId) => - $elem.focus() - user = new DiscussionUser(response.user_info) - window.user = user - DiscussionUtil.setUser(user) - Content.loadContentInfos(response.annotated_content_info) - DiscussionUtil.loadRoles(response.roles) + DiscussionModuleView.prototype.toggleNewPost = function(event) { + event.preventDefault(); + if (!this.newPostForm) { + this.toggleDiscussion(); + this.isWaitingOnNewPost = true; + return; + } + if (this.showed) { + this.newPostForm.slideDown(300); + } else { + this.newPostForm.show().focus(); + } + this.toggleDiscussionBtn.addClass('shown'); + this.toggleDiscussionBtn.find('.button-text').html(gettext("Hide Discussion")); + this.$("section.discussion").slideDown(); + this.showed = true; + }; - @course_settings = new DiscussionCourseSettings(response.course_settings) - @discussion = new Discussion() - @discussion.reset(response.discussion_data, {silent: false}) + DiscussionModuleView.prototype.hideNewPost = function() { + return this.newPostForm.slideUp(300); + }; - $discussion = _.template($("#inline-discussion-template").html())( - 'threads': response.discussion_data, - 'discussionId': discussionId - ) - if @$('section.discussion').length - @$('section.discussion').replaceWith($discussion) - else - @$el.append($discussion) + DiscussionModuleView.prototype.hideDiscussion = function() { + this.$("section.discussion").slideUp(); + this.toggleDiscussionBtn.removeClass('shown'); + this.toggleDiscussionBtn.find('.button-text').html(gettext("Show Discussion")); + this.showed = false; + }; - @newPostForm = this.$el.find('.new-post-article') - @threadviews = @discussion.map (thread) => - view = new DiscussionThreadView( - el: @$("article#thread_#{thread.id}"), - model: thread, - mode: "inline", - context: @context, - course_settings: @course_settings, - topicId: discussionId - ) - thread.on "thread:thread_type_updated", -> - view.rerender() - view.expand() - return view - _.each @threadviews, (dtv) -> dtv.render() - DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info) - @newPostView = new NewPostView( - el: @newPostForm, - collection: @discussion, - course_settings: @course_settings, - topicId: discussionId, - is_commentable_cohorted: response.is_commentable_cohorted - ) - @newPostView.render() - @listenTo( @newPostView, 'newPost:cancel', @hideNewPost ) - @discussion.on "add", @addThread + DiscussionModuleView.prototype.toggleDiscussion = function() { + var $elem, + self = this; + if (this.showed) { + return this.hideDiscussion(); + } else { + this.toggleDiscussionBtn.addClass('shown'); + this.toggleDiscussionBtn.find('.button-text').html(gettext("Hide Discussion")); + if (this.retrieved) { + this.$("section.discussion").slideDown(); + this.showed = true; + } else { + $elem = this.toggleDiscussionBtn; + return this.loadPage($elem, function() { + self.hideDiscussion(); + return DiscussionUtil.discussionAlert( + gettext("Sorry"), + gettext("We had some trouble loading the discussion. Please try again.") + ); + }); + } + } + }; - @retrieved = true - @showed = true - @renderPagination(response.num_pages) + DiscussionModuleView.prototype.loadPage = function($elem, error) { + var discussionId, url, + self = this; + discussionId = this.$el.data("discussion-id"); + url = DiscussionUtil.urlFor('retrieve_discussion', discussionId) + ("?page=" + this.page); + return DiscussionUtil.safeAjax({ + $elem: $elem, + $loading: $elem, + takeFocus: true, + url: url, + type: "GET", + dataType: 'json', + success: function(response, textStatus) { + return self.renderDiscussion($elem, response, textStatus, discussionId); + }, + error: error + }); + }; - if @isWaitingOnNewPost - @newPostForm.show().focus() + DiscussionModuleView.prototype.renderDiscussion = function($elem, response, textStatus, discussionId) { + var $discussion, user, + self = this; + $elem.focus(); + user = new DiscussionUser(response.user_info); + window.user = user; + DiscussionUtil.setUser(user); + Content.loadContentInfos(response.annotated_content_info); + DiscussionUtil.loadRoles(response.roles); + this.course_settings = new DiscussionCourseSettings(response.course_settings); + this.discussion = new Discussion(); + this.discussion.reset(response.discussion_data, { + silent: false + }); + $discussion = _.template($("#inline-discussion-template").html())({ + 'threads': response.discussion_data, + 'discussionId': discussionId + }); + if (this.$('section.discussion').length) { + this.$('section.discussion').replaceWith($discussion); + } else { + this.$el.append($discussion); + } + this.newPostForm = this.$el.find('.new-post-article'); + this.threadviews = this.discussion.map(function(thread) { + var view; + view = new DiscussionThreadView({ + el: self.$("article#thread_" + thread.id), + model: thread, + mode: "inline", + context: self.context, + course_settings: self.course_settings, + topicId: discussionId + }); + thread.on("thread:thread_type_updated", function() { + view.rerender(); + return view.expand(); + }); + return view; + }); + _.each(this.threadviews, function(dtv) { + return dtv.render(); + }); + DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info); + this.newPostView = new NewPostView({ + el: this.newPostForm, + collection: this.discussion, + course_settings: this.course_settings, + topicId: discussionId, + is_commentable_cohorted: response.is_commentable_cohorted + }); + this.newPostView.render(); + this.listenTo(this.newPostView, 'newPost:cancel', this.hideNewPost); + this.discussion.on("add", this.addThread); + this.retrieved = true; + this.showed = true; + this.renderPagination(response.num_pages); + if (this.isWaitingOnNewPost) { + return this.newPostForm.show().focus(); + } + }; - addThread: (thread, collection, options) => - # TODO: When doing pagination, this will need to repaginate. Perhaps just reload page 1? - article = $("
") - @$('section.discussion > .threads').prepend(article) + DiscussionModuleView.prototype.addThread = function(thread) { + var article, threadView; + article = $("
"); + this.$('section.discussion > .threads').prepend(article); + threadView = new DiscussionThreadView({ + el: article, + model: thread, + mode: "inline", + context: this.context, + course_settings: this.course_settings, + topicId: this.$el.data("discussion-id") + }); + threadView.render(); + return this.threadviews.unshift(threadView); + }; - threadView = new DiscussionThreadView( - el: article, - model: thread, - mode: "inline", - context: @context, - course_settings: @course_settings, - topicId: @$el.data("discussion-id") - ) - threadView.render() - @threadviews.unshift threadView + DiscussionModuleView.prototype.renderPagination = function(numPages) { + var pageUrl, pagination, params; + pageUrl = function(number) { + return "?discussion_page=" + number; + }; + params = DiscussionUtil.getPaginationParams(this.page, numPages, pageUrl); + pagination = _.template($("#pagination-template").html())(params); + return this.$('section.discussion-pagination').html(pagination); + }; - renderPagination: (numPages) => - pageUrl = (number) -> - "?discussion_page=#{number}" - params = DiscussionUtil.getPaginationParams(@page, numPages, pageUrl) - pagination = _.template($("#pagination-template").html())(params) - @$('section.discussion-pagination').html(pagination) + DiscussionModuleView.prototype.navigateToPage = function(event) { + var currPage, + self = this; + event.preventDefault(); + window.history.pushState({}, window.document.title, event.target.href); + currPage = this.page; + this.page = $(event.target).data('page-number'); + return this.loadPage($(event.target), function() { + self.page = currPage; + DiscussionUtil.discussionAlert( + gettext("Sorry"), + gettext("We had some trouble loading the threads you requested. Please try again.") + ); + }); + }; - navigateToPage: (event) => - event.preventDefault() - window.history.pushState({}, window.document.title, event.target.href) - currPage = @page - @page = $(event.target).data('page-number') - @loadPage( - $(event.target), - => - @page = currPage - DiscussionUtil.discussionAlert( - gettext("Sorry"), - gettext("We had some trouble loading the threads you requested. Please try again.") - ) - ) + return DiscussionModuleView; + + })(Backbone.View); + } + +}).call(window); diff --git a/common/static/common/js/discussion/discussion_router.js b/common/static/common/js/discussion/discussion_router.js index 5b90925b67..14ce7a6bf4 100644 --- a/common/static/common/js/discussion/discussion_router.js +++ b/common/static/common/js/discussion/discussion_router.js @@ -1,90 +1,167 @@ -if Backbone? - class @DiscussionRouter extends Backbone.Router - routes: - "": "allThreads" - ":forum_name/threads/:thread_id" : "showThread" +/* globals DiscussionThreadListView, DiscussionThreadView, DiscussionUtil, NewPostView */ +(function() { + 'use strict'; + var __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { + for (var key in parent) { + if (__hasProp.call(parent, key)) { + child[key] = parent[key]; + } + } + function ctor() { + this.constructor = child; + } - initialize: (options) -> - @discussion = options['discussion'] - @course_settings = options['course_settings'] + ctor.prototype = parent.prototype; + child.prototype = new ctor(); + child.__super__ = parent.prototype; + return child; + }; - @nav = new DiscussionThreadListView( - collection: @discussion, - el: $(".forum-nav"), - courseSettings: @course_settings - ) - @nav.on "thread:selected", @navigateToThread - @nav.on "thread:removed", @navigateToAllThreads - @nav.on "threads:rendered", @setActiveThread - @nav.on "thread:created", @navigateToThread - @nav.render() + if (typeof Backbone !== "undefined" && Backbone !== null) { + this.DiscussionRouter = (function(_super) { - @newPost = $('.new-post-article') - @newPostView = new NewPostView( - el: @newPost, - collection: @discussion, - course_settings: @course_settings, - mode: "tab" - ) - @newPostView.render() - @listenTo( @newPostView, 'newPost:cancel', @hideNewPost ) - $('.new-post-btn').bind "click", @showNewPost - $('.new-post-btn').bind "keydown", (event) => DiscussionUtil.activateOnSpace(event, @showNewPost) + __extends(DiscussionRouter, _super); - allThreads: -> - @nav.updateSidebar() - @nav.goHome() + function DiscussionRouter() { + var self = this; + this.hideNewPost = function() { + return DiscussionRouter.prototype.hideNewPost.apply(self, arguments); + }; + this.showNewPost = function() { + return DiscussionRouter.prototype.showNewPost.apply(self, arguments); + }; + this.navigateToAllThreads = function() { + return DiscussionRouter.prototype.navigateToAllThreads.apply(self, arguments); + }; + this.navigateToThread = function() { + return DiscussionRouter.prototype.navigateToThread.apply(self, arguments); + }; + this.showMain = function() { + return DiscussionRouter.prototype.showMain.apply(self, arguments); + }; + this.setActiveThread = function() { + return DiscussionRouter.prototype.setActiveThread.apply(self, arguments); + }; + return DiscussionRouter.__super__.constructor.apply(this, arguments); + } - setActiveThread: => - if @thread - @nav.setActiveThread(@thread.get("id")) - else - @nav.goHome + DiscussionRouter.prototype.routes = { + "": "allThreads", + ":forum_name/threads/:thread_id": "showThread" + }; - showThread: (forum_name, thread_id) -> - @thread = @discussion.get(thread_id) - @thread.set("unread_comments_count", 0) - @thread.set("read", true) - @setActiveThread() - @showMain() + DiscussionRouter.prototype.initialize = function(options) { + var self = this; + this.discussion = options.discussion; + this.course_settings = options.course_settings; + this.nav = new DiscussionThreadListView({ + collection: this.discussion, + el: $(".forum-nav"), + courseSettings: this.course_settings + }); + this.nav.on("thread:selected", this.navigateToThread); + this.nav.on("thread:removed", this.navigateToAllThreads); + this.nav.on("threads:rendered", this.setActiveThread); + this.nav.on("thread:created", this.navigateToThread); + this.nav.render(); + this.newPost = $('.new-post-article'); + this.newPostView = new NewPostView({ + el: this.newPost, + collection: this.discussion, + course_settings: this.course_settings, + mode: "tab" + }); + this.newPostView.render(); + this.listenTo(this.newPostView, 'newPost:cancel', this.hideNewPost); + $('.new-post-btn').bind("click", this.showNewPost); + return $('.new-post-btn').bind("keydown", function(event) { + return DiscussionUtil.activateOnSpace(event, self.showNewPost); + }); + }; - showMain: => - if(@main) - @main.cleanup() - @main.undelegateEvents() - unless($(".forum-content").is(":visible")) - $(".forum-content").fadeIn() - if(@newPost.is(":visible")) - @newPost.fadeOut() + DiscussionRouter.prototype.allThreads = function() { + this.nav.updateSidebar(); + return this.nav.goHome(); + }; - @main = new DiscussionThreadView( - el: $(".forum-content"), - model: @thread, - mode: "tab", - course_settings: @course_settings, - ) - @main.render() - @main.on "thread:responses:rendered", => - @nav.updateSidebar() - @thread.on "thread:thread_type_updated", @showMain + DiscussionRouter.prototype.setActiveThread = function() { + if (this.thread) { + return this.nav.setActiveThread(this.thread.get("id")); + } else { + return this.nav.goHome; + } + }; - navigateToThread: (thread_id) => - thread = @discussion.get(thread_id) - @navigate("#{thread.get("commentable_id")}/threads/#{thread_id}", trigger: true) + DiscussionRouter.prototype.showThread = function(forum_name, thread_id) { + this.thread = this.discussion.get(thread_id); + this.thread.set("unread_comments_count", 0); + this.thread.set("read", true); + this.setActiveThread(); + return this.showMain(); + }; - navigateToAllThreads: => - @navigate("", trigger: true) + DiscussionRouter.prototype.showMain = function() { + var self = this; + if (this.main) { + this.main.cleanup(); + this.main.undelegateEvents(); + } + if (!($(".forum-content").is(":visible"))) { + $(".forum-content").fadeIn(); + } + if (this.newPost.is(":visible")) { + this.newPost.fadeOut(); + } + this.main = new DiscussionThreadView({ + el: $(".forum-content"), + model: this.thread, + mode: "tab", + course_settings: this.course_settings + }); + this.main.render(); + this.main.on("thread:responses:rendered", function() { + return self.nav.updateSidebar(); + }); + return this.thread.on("thread:thread_type_updated", this.showMain); + }; - showNewPost: (event) => - $('.forum-content').fadeOut( - duration: 200 - complete: => - @newPost.fadeIn(200).focus() - ) + DiscussionRouter.prototype.navigateToThread = function(thread_id) { + var thread; + thread = this.discussion.get(thread_id); + return this.navigate("" + (thread.get("commentable_id")) + "/threads/" + thread_id, { + trigger: true + }); + }; - hideNewPost: => - @newPost.fadeOut( - duration: 200 - complete: => - $('.forum-content').fadeIn(200).find('.thread-wrapper').focus() - ) + DiscussionRouter.prototype.navigateToAllThreads = function() { + return this.navigate("", { + trigger: true + }); + }; + + DiscussionRouter.prototype.showNewPost = function() { + var self = this; + return $('.forum-content').fadeOut({ + duration: 200, + complete: function() { + return self.newPost.fadeIn(200).focus(); + } + }); + }; + + DiscussionRouter.prototype.hideNewPost = function() { + return this.newPost.fadeOut({ + duration: 200, + complete: function() { + return $('.forum-content').fadeIn(200).find('.thread-wrapper').focus(); + } + }); + }; + + return DiscussionRouter; + + })(Backbone.Router); + } + +}).call(window); diff --git a/common/static/common/js/discussion/main.js b/common/static/common/js/discussion/main.js index 5c663ffa21..866a3491d1 100644 --- a/common/static/common/js/discussion/main.js +++ b/common/static/common/js/discussion/main.js @@ -1,38 +1,76 @@ -if Backbone? - DiscussionApp = - start: (elem)-> - # TODO: Perhaps eliminate usage of global variables when possible - DiscussionUtil.loadRolesFromContainer() - element = $(elem) - window.$$course_id = element.data("course-id") - window.courseName = element.data("course-name") - user_info = element.data("user-info") - sort_preference = element.data("sort-preference") - threads = element.data("threads") - thread_pages = element.data("thread-pages") - content_info = element.data("content-info") - user = new DiscussionUser(user_info) - DiscussionUtil.setUser(user) - window.user = user - Content.loadContentInfos(content_info) - discussion = new Discussion(threads, {pages: thread_pages, sort: sort_preference}) - course_settings = new DiscussionCourseSettings(element.data("course-settings")) - new DiscussionRouter({discussion: discussion, course_settings: course_settings}) - Backbone.history.start({pushState: true, root: "/courses/#{$$course_id}/discussion/forum/"}) - DiscussionProfileApp = - start: (elem) -> - # Roles are not included in user profile page, but they are not used for anything - DiscussionUtil.loadRoles({"Moderator": [], "Administrator": [], "Community TA": []}) - element = $(elem) - window.$$course_id = element.data("course-id") - threads = element.data("threads") - user_info = element.data("user-info") - window.user = new DiscussionUser(user_info) - page = element.data("page") - numPages = element.data("num-pages") - new DiscussionUserProfileView(el: element, collection: threads, page: page, numPages: numPages) - $ -> - $("section.discussion").each (index, elem) -> - DiscussionApp.start(elem) - $("section.discussion-user-threads").each (index, elem) -> - DiscussionProfileApp.start(elem) +/* global $$course_id, Content, Discussion, DiscussionRouter, DiscussionCourseSettings, + DiscussionUser, DiscussionUserProfileView, DiscussionUtil */ +(function() { + 'use strict'; + var DiscussionApp, DiscussionProfileApp; + + if (typeof Backbone !== "undefined" && Backbone !== null) { + DiscussionApp = { + start: function(elem) { + var content_info, course_settings, discussion, element, sort_preference, thread_pages, threads, + user, user_info; + DiscussionUtil.loadRolesFromContainer(); + element = $(elem); + window.$$course_id = element.data("course-id"); + window.courseName = element.data("course-name"); + user_info = element.data("user-info"); + sort_preference = element.data("sort-preference"); + threads = element.data("threads"); + thread_pages = element.data("thread-pages"); + content_info = element.data("content-info"); + user = new DiscussionUser(user_info); + DiscussionUtil.setUser(user); + window.user = user; + Content.loadContentInfos(content_info); + discussion = new Discussion(threads, { + pages: thread_pages, + sort: sort_preference + }); + course_settings = new DiscussionCourseSettings(element.data("course-settings")); + // suppressing Do not use 'new' for side effects. + /* jshint -W031*/ + new DiscussionRouter({ + discussion: discussion, + course_settings: course_settings + }); + /* jshint +W031*/ + return Backbone.history.start({ + pushState: true, + root: "/courses/" + $$course_id + "/discussion/forum/" + }); + } + }; + DiscussionProfileApp = { + start: function(elem) { + var element, numPages, page, threads, user_info; + DiscussionUtil.loadRoles({ + "Moderator": [], + "Administrator": [], + "Community TA": [] + }); + element = $(elem); + window.$$course_id = element.data("course-id"); + threads = element.data("threads"); + user_info = element.data("user-info"); + window.user = new DiscussionUser(user_info); + page = element.data("page"); + numPages = element.data("num-pages"); + return new DiscussionUserProfileView({ + el: element, + collection: threads, + page: page, + numPages: numPages + }); + } + }; + $(function() { + $("section.discussion").each(function(index, elem) { + return DiscussionApp.start(elem); + }); + return $("section.discussion-user-threads").each(function(index, elem) { + return DiscussionProfileApp.start(elem); + }); + }); + } + +}).call(window); diff --git a/common/static/common/js/discussion/models/discussion_course_settings.js b/common/static/common/js/discussion/models/discussion_course_settings.js index 97275a639b..931fe9832d 100644 --- a/common/static/common/js/discussion/models/discussion_course_settings.js +++ b/common/static/common/js/discussion/models/discussion_course_settings.js @@ -1,2 +1,34 @@ -if Backbone? - class @DiscussionCourseSettings extends Backbone.Model +(function() { + 'use strict'; + var __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { + for (var key in parent) { + if (__hasProp.call(parent, key)) { + child[key] = parent[key]; + } + } + function ctor() { + this.constructor = child; + } + + ctor.prototype = parent.prototype; + child.prototype = new ctor(); + child.__super__ = parent.prototype; + return child; + }; + + if (typeof Backbone !== "undefined" && Backbone !== null) { + this.DiscussionCourseSettings = (function(_super) { + + __extends(DiscussionCourseSettings, _super); + + function DiscussionCourseSettings() { + return DiscussionCourseSettings.__super__.constructor.apply(this, arguments); + } + + return DiscussionCourseSettings; + + })(Backbone.Model); + } + +}).call(this); diff --git a/common/static/common/js/discussion/models/discussion_user.js b/common/static/common/js/discussion/models/discussion_user.js index 892727c523..6f1a849f6b 100644 --- a/common/static/common/js/discussion/models/discussion_user.js +++ b/common/static/common/js/discussion/models/discussion_user.js @@ -1,15 +1,52 @@ -if Backbone? - class @DiscussionUser extends Backbone.Model - following: (thread) -> - _.include(@get('subscribed_thread_ids'), thread.id) +(function() { + 'use strict'; + var __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { + for (var key in parent) { + if (__hasProp.call(parent, key)) { + child[key] = parent[key]; + } + } + function ctor() { + this.constructor = child; + } - voted: (thread) -> - _.include(@get('upvoted_ids'), thread.id) + ctor.prototype = parent.prototype; + child.prototype = new ctor(); + child.__super__ = parent.prototype; + return child; + }; - vote: (thread) -> - @get('upvoted_ids').push(thread.id) - thread.vote() + if (typeof Backbone !== "undefined" && Backbone !== null) { + this.DiscussionUser = (function(_super) { - unvote: (thread) -> - @set('upvoted_ids', _.without(@get('upvoted_ids'), thread.id)) - thread.unvote() + __extends(DiscussionUser, _super); + + function DiscussionUser() { + return DiscussionUser.__super__.constructor.apply(this, arguments); + } + + DiscussionUser.prototype.following = function(thread) { + return _.include(this.get('subscribed_thread_ids'), thread.id); + }; + + DiscussionUser.prototype.voted = function(thread) { + return _.include(this.get('upvoted_ids'), thread.id); + }; + + DiscussionUser.prototype.vote = function(thread) { + this.get('upvoted_ids').push(thread.id); + return thread.vote(); + }; + + DiscussionUser.prototype.unvote = function(thread) { + this.set('upvoted_ids', _.without(this.get('upvoted_ids'), thread.id)); + return thread.unvote(); + }; + + return DiscussionUser; + + })(Backbone.Model); + } + +}).call(this); diff --git a/common/static/common/js/discussion/utils.js b/common/static/common/js/discussion/utils.js index 06f1667e13..280bfa7512 100644 --- a/common/static/common/js/discussion/utils.js +++ b/common/static/common/js/discussion/utils.js @@ -1,346 +1,489 @@ -class @DiscussionUtil +/* globals $$course_id, Content, Markdown, URI */ +(function() { + 'use strict'; + this.DiscussionUtil = (function() { - @wmdEditors: {} + function DiscussionUtil() { + } - @getTemplate: (id) -> - $("script##{id}").html() + DiscussionUtil.wmdEditors = {}; - @setUser: (user) -> - @user = user + DiscussionUtil.getTemplate = function(id) { + return $("script#" + id).html(); + }; - @getUser: () -> - @user + DiscussionUtil.setUser = function(user) { + this.user = user; + }; - @loadRoles: (roles)-> - @roleIds = roles + DiscussionUtil.getUser = function() { + return this.user; + }; - @loadRolesFromContainer: -> - @loadRoles($("#discussion-container").data("roles")) + DiscussionUtil.loadRoles = function(roles) { + this.roleIds = roles; + }; - @isStaff: (user_id) -> - user_id ?= @user?.id - staff = _.union(@roleIds['Moderator'], @roleIds['Administrator']) - _.include(staff, parseInt(user_id)) + DiscussionUtil.loadRolesFromContainer = function() { + return this.loadRoles($("#discussion-container").data("roles")); + }; - @isTA: (user_id) -> - user_id ?= @user?.id - ta = _.union(@roleIds['Community TA']) - _.include(ta, parseInt(user_id)) + DiscussionUtil.isStaff = function(userId) { + var staff; + if (userId === null) { + userId = this.user ? this.user.id : void 0; + } + staff = _.union(this.roleIds.Moderator, this.roleIds.Administrator); + return _.include(staff, parseInt(userId)); + }; - @isPrivilegedUser: (user_id) -> - @isStaff(user_id) || @isTA(user_id) + DiscussionUtil.isTA = function(userId) { + var ta; + if (userId === null) { + userId = this.user ? this.user.id : void 0; + } + ta = _.union(this.roleIds['Community TA']); + return _.include(ta, parseInt(userId)); + }; - @bulkUpdateContentInfo: (infos) -> - for id, info of infos - Content.getContent(id).updateInfo(info) + DiscussionUtil.isPrivilegedUser = function(userId) { + return this.isStaff(userId) || this.isTA(userId); + }; - @generateDiscussionLink: (cls, txt, handler) -> - $("").addClass("discussion-link") - .attr("href", "javascript:void(0)") - .addClass(cls).html(txt) - .click -> handler(this) + DiscussionUtil.bulkUpdateContentInfo = function(infos) { + var id, info, _results; + _results = []; + for (id in infos) { + if (infos.hasOwnProperty(id)) { + info = infos[id]; + _results.push(Content.getContent(id).updateInfo(info)); + } + } + return _results; + }; - @urlFor: (name, param, param1, param2) -> - { - follow_discussion : "/courses/#{$$course_id}/discussion/#{param}/follow" - unfollow_discussion : "/courses/#{$$course_id}/discussion/#{param}/unfollow" - create_thread : "/courses/#{$$course_id}/discussion/#{param}/threads/create" - update_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/update" - create_comment : "/courses/#{$$course_id}/discussion/threads/#{param}/reply" - delete_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/delete" - flagAbuse_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/flagAbuse" - unFlagAbuse_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unFlagAbuse" - flagAbuse_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/flagAbuse" - unFlagAbuse_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/unFlagAbuse" - upvote_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/upvote" - downvote_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/downvote" - pin_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/pin" - un_pin_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unpin" - undo_vote_for_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unvote" - follow_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/follow" - unfollow_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unfollow" - update_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/update" - endorse_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/endorse" - create_sub_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/reply" - delete_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/delete" - upvote_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/upvote" - downvote_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/downvote" - undo_vote_for_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/unvote" - upload : "/courses/#{$$course_id}/discussion/upload" - users : "/courses/#{$$course_id}/discussion/users" - search : "/courses/#{$$course_id}/discussion/forum/search" - retrieve_discussion : "/courses/#{$$course_id}/discussion/forum/#{param}/inline" - retrieve_single_thread : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}" - openclose_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/close" - permanent_link_thread : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}" - permanent_link_comment : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}##{param2}" - user_profile : "/courses/#{$$course_id}/discussion/forum/users/#{param}" - followed_threads : "/courses/#{$$course_id}/discussion/forum/users/#{param}/followed" - threads : "/courses/#{$$course_id}/discussion/forum" - "enable_notifications" : "/notification_prefs/enable/" - "disable_notifications" : "/notification_prefs/disable/" - "notifications_status" : "/notification_prefs/status/" - }[name] + DiscussionUtil.generateDiscussionLink = function(cls, txt, handler) { + return $("") + .addClass("discussion-link").attr("href", "#") + .addClass(cls).html(txt).click(function() {return handler(this);}); + }; - @ignoreEnterKey: (event) => - if event.which == 13 - event.preventDefault() + DiscussionUtil.urlFor = function(name, param, param1, param2) { + return { + follow_discussion: "/courses/" + $$course_id + "/discussion/" + param + "/follow", + unfollow_discussion: "/courses/" + $$course_id + "/discussion/" + param + "/unfollow", + create_thread: "/courses/" + $$course_id + "/discussion/" + param + "/threads/create", + update_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/update", + create_comment: "/courses/" + $$course_id + "/discussion/threads/" + param + "/reply", + delete_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/delete", + flagAbuse_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/flagAbuse", + unFlagAbuse_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/unFlagAbuse", + flagAbuse_comment: "/courses/" + $$course_id + "/discussion/comments/" + param + "/flagAbuse", + unFlagAbuse_comment: "/courses/" + $$course_id + "/discussion/comments/" + param + "/unFlagAbuse", + upvote_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/upvote", + downvote_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/downvote", + pin_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/pin", + un_pin_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/unpin", + undo_vote_for_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/unvote", + follow_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/follow", + unfollow_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/unfollow", + update_comment: "/courses/" + $$course_id + "/discussion/comments/" + param + "/update", + endorse_comment: "/courses/" + $$course_id + "/discussion/comments/" + param + "/endorse", + create_sub_comment: "/courses/" + $$course_id + "/discussion/comments/" + param + "/reply", + delete_comment: "/courses/" + $$course_id + "/discussion/comments/" + param + "/delete", + upvote_comment: "/courses/" + $$course_id + "/discussion/comments/" + param + "/upvote", + downvote_comment: "/courses/" + $$course_id + "/discussion/comments/" + param + "/downvote", + undo_vote_for_comment: "/courses/" + $$course_id + "/discussion/comments/" + param + "/unvote", + upload: "/courses/" + $$course_id + "/discussion/upload", + users: "/courses/" + $$course_id + "/discussion/users", + search: "/courses/" + $$course_id + "/discussion/forum/search", + retrieve_discussion: "/courses/" + $$course_id + "/discussion/forum/" + param + "/inline", + retrieve_single_thread: "/courses/" + $$course_id + "/discussion/forum/" + param + "/threads/" + param1, + openclose_thread: "/courses/" + $$course_id + "/discussion/threads/" + param + "/close", + permanent_link_thread: "/courses/" + $$course_id + "/discussion/forum/" + param + "/threads/" + param1, + permanent_link_comment: "/courses/" + $$course_id + + "/discussion/forum/" + param + "/threads/" + param1 + "#" + param2, + user_profile: "/courses/" + $$course_id + "/discussion/forum/users/" + param, + followed_threads: "/courses/" + $$course_id + "/discussion/forum/users/" + param + "/followed", + threads: "/courses/" + $$course_id + "/discussion/forum", + "enable_notifications": "/notification_prefs/enable/", + "disable_notifications": "/notification_prefs/disable/", + "notifications_status": "/notification_prefs/status/" + }[name]; + }; - @activateOnSpace: (event, func) -> - if event.which == 32 - event.preventDefault() - func(event) + DiscussionUtil.ignoreEnterKey = function(event) { + if (event.which === 13) { + return event.preventDefault(); + } + }; - @makeFocusTrap: (elem) -> - elem.keydown( - (event) -> - if event.which == 9 # Tab - event.preventDefault() - ) + DiscussionUtil.activateOnSpace = function(event, func) { + if (event.which === 32) { + event.preventDefault(); + return func(event); + } + }; - @showLoadingIndicator: (element, takeFocus) -> - @$_loading = $("
" + gettext("Loading content") + "
") - element.after(@$_loading) - if takeFocus - @makeFocusTrap(@$_loading) - @$_loading.focus() + DiscussionUtil.makeFocusTrap = function(elem) { + return elem.keydown(function(event) { + if (event.which === 9) { + return event.preventDefault(); + } + }); + }; - @hideLoadingIndicator: () -> - @$_loading.remove() + DiscussionUtil.showLoadingIndicator = function(element, takeFocus) { + this.$_loading = $( + "
" + + gettext("Loading content") + + "
" + ); + element.after(this.$_loading); + if (takeFocus) { + this.makeFocusTrap(this.$_loading); + return this.$_loading.focus(); + } + }; - @discussionAlert: (header, body) -> - if $("#discussion-alert").length == 0 - alertDiv = $("