From 674bfc4fcba9f5f24c591a23a3f5b5c991172708 Mon Sep 17 00:00:00 2001 From: Andy Armstrong Date: Thu, 18 Dec 2014 22:23:34 -0500 Subject: [PATCH] Use edx namespace for Backbone classes --- lms/static/js/collections/cohort.js | 11 ----- lms/static/js/groups/collections/cohort.js | 16 ++++++++ lms/static/js/{ => groups}/models/cohort.js | 10 +++-- .../js/{ => groups}/views/cohort_editor.js | 10 +++-- lms/static/js/{ => groups}/views/cohorts.js | 15 +++++-- .../spec/{ => groups}/views/cohorts_spec.js | 2 +- lms/static/js/spec/main.js | 41 ++++++++++--------- .../instructor_dashboard_2.html | 8 ++-- .../instructor_dashboard_2/membership.html | 4 +- 9 files changed, 70 insertions(+), 47 deletions(-) delete mode 100644 lms/static/js/collections/cohort.js create mode 100644 lms/static/js/groups/collections/cohort.js rename lms/static/js/{ => groups}/models/cohort.js (86%) rename lms/static/js/{ => groups}/views/cohort_editor.js (98%) rename lms/static/js/{ => groups}/views/cohorts.js (96%) rename lms/static/js/spec/{ => groups}/views/cohorts_spec.js (99%) diff --git a/lms/static/js/collections/cohort.js b/lms/static/js/collections/cohort.js deleted file mode 100644 index c4d83788b3..0000000000 --- a/lms/static/js/collections/cohort.js +++ /dev/null @@ -1,11 +0,0 @@ -(function(Backbone) { - var CohortCollection = Backbone.Collection.extend({ - model : this.CohortModel, - comparator: "name", - - parse: function(response) { - return response.cohorts; - } - }); - this.CohortCollection = CohortCollection; -}).call(this, Backbone); diff --git a/lms/static/js/groups/collections/cohort.js b/lms/static/js/groups/collections/cohort.js new file mode 100644 index 0000000000..12f524ce26 --- /dev/null +++ b/lms/static/js/groups/collections/cohort.js @@ -0,0 +1,16 @@ +var edx = edx || {}; + +(function(Backbone, CohortModel) { + 'use strict'; + + edx.groups = edx.groups || {}; + + edx.groups.CohortCollection = Backbone.Collection.extend({ + model : CohortModel, + comparator: "name", + + parse: function(response) { + return response.cohorts; + } + }); +}).call(this, Backbone, edx.groups.CohortModel); diff --git a/lms/static/js/models/cohort.js b/lms/static/js/groups/models/cohort.js similarity index 86% rename from lms/static/js/models/cohort.js rename to lms/static/js/groups/models/cohort.js index 4696351428..e5d9a19144 100644 --- a/lms/static/js/models/cohort.js +++ b/lms/static/js/groups/models/cohort.js @@ -1,5 +1,11 @@ +var edx = edx || {}; + (function(Backbone) { - var CohortModel = Backbone.Model.extend({ + 'use strict'; + + edx.groups = edx.groups || {}; + + edx.groups.CohortModel = Backbone.Model.extend({ idAttribute: 'id', defaults: { name: '', @@ -20,6 +26,4 @@ group_id: null } }); - - this.CohortModel = CohortModel; }).call(this, Backbone); diff --git a/lms/static/js/views/cohort_editor.js b/lms/static/js/groups/views/cohort_editor.js similarity index 98% rename from lms/static/js/views/cohort_editor.js rename to lms/static/js/groups/views/cohort_editor.js index bb9294689c..c38af29d14 100644 --- a/lms/static/js/views/cohort_editor.js +++ b/lms/static/js/groups/views/cohort_editor.js @@ -1,5 +1,11 @@ +var edx = edx || {}; + (function(Backbone, _, $, gettext, ngettext, interpolate_text, NotificationModel, NotificationView) { - var CohortEditorView = Backbone.View.extend({ + 'use strict'; + + edx.groups = edx.groups || {}; + + edx.groups.CohortEditorView = Backbone.View.extend({ events : { "submit .cohort-management-group-add-form": "addStudents" }, @@ -202,6 +208,4 @@ } } }); - - this.CohortEditorView = CohortEditorView; }).call(this, Backbone, _, $, gettext, ngettext, interpolate_text, NotificationModel, NotificationView); diff --git a/lms/static/js/views/cohorts.js b/lms/static/js/groups/views/cohorts.js similarity index 96% rename from lms/static/js/views/cohorts.js rename to lms/static/js/groups/views/cohorts.js index 85e723e5f2..12cdf91978 100644 --- a/lms/static/js/views/cohorts.js +++ b/lms/static/js/groups/views/cohorts.js @@ -1,8 +1,15 @@ -(function($, _, Backbone, gettext, interpolate_text, CohortEditorView, NotificationModel, NotificationView, FileUploaderView) { +var edx = edx || {}; + +(function($, _, Backbone, gettext, interpolate_text, CohortEditorView, + NotificationModel, NotificationView, FileUploaderView) { + 'use strict'; + var hiddenClass = 'is-hidden', disabledClass = 'is-disabled'; - this.CohortsView = Backbone.View.extend({ + edx.groups = edx.groups || {}; + + edx.groups.CohortsView = Backbone.View.extend({ events : { 'change .cohort-select': 'onCohortSelected', 'click .action-create': 'showAddCohortForm', @@ -226,6 +233,6 @@ getSectionCss: function (section) { return ".instructor-nav .nav-item a[data-section='" + section + "']"; } - }); -}).call(this, $, _, Backbone, gettext, interpolate_text, CohortEditorView, NotificationModel, NotificationView, FileUploaderView); +}).call(this, $, _, Backbone, gettext, interpolate_text, edx.groups.CohortEditorView, + NotificationModel, NotificationView, FileUploaderView); diff --git a/lms/static/js/spec/views/cohorts_spec.js b/lms/static/js/spec/groups/views/cohorts_spec.js similarity index 99% rename from lms/static/js/spec/views/cohorts_spec.js rename to lms/static/js/spec/groups/views/cohorts_spec.js index d3ff4cbfbb..a592e0b5f3 100644 --- a/lms/static/js/spec/views/cohorts_spec.js +++ b/lms/static/js/spec/groups/views/cohorts_spec.js @@ -1,5 +1,5 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpers/template_helpers', - 'js/views/cohorts', 'js/collections/cohort', 'string_utils'], + 'js/groups/views/cohorts', 'js/groups/collections/cohort', 'string_utils'], function (Backbone, $, AjaxHelpers, TemplateHelpers, CohortsView, CohortCollection) { describe("Cohorts View", function () { var catLoversInitialCount = 123, dogLoversInitialCount = 456, unknownUserMessage, diff --git a/lms/static/js/spec/main.js b/lms/static/js/spec/main.js index 856c6289f0..a0bebd885c 100644 --- a/lms/static/js/spec/main.js +++ b/lms/static/js/spec/main.js @@ -61,13 +61,13 @@ 'js/staff_debug_actions': 'js/staff_debug_actions', // Backbone classes loaded explicitly until they are converted to use RequireJS - 'js/views/file_uploader': 'js/views/file_uploader', - 'js/models/cohort': 'js/models/cohort', - 'js/collections/cohort': 'js/collections/cohort', - 'js/views/cohort_editor': 'js/views/cohort_editor', - 'js/views/cohorts': 'js/views/cohorts', - 'js/views/notification': 'js/views/notification', 'js/models/notification': 'js/models/notification', + 'js/views/file_uploader': 'js/views/file_uploader', + 'js/views/notification': 'js/views/notification', + 'js/groups/models/cohort': 'js/groups/models/cohort', + 'js/groups/collections/cohort': 'js/groups/collections/cohort', + 'js/groups/views/cohort_editor': 'js/groups/views/cohort_editor', + 'js/groups/views/cohorts': 'js/groups/views/cohorts', 'js/student_account/account': 'js/student_account/account', 'js/student_account/views/FormView': 'js/student_account/views/FormView', 'js/student_account/models/LoginModel': 'js/student_account/models/LoginModel', @@ -280,23 +280,25 @@ exports: 'edx.instructor_dashboard.ecommerce.ExpiryCouponView', deps: ['backbone', 'jquery', 'underscore'] }, - 'js/models/cohort': { - exports: 'CohortModel', + 'js/groups/models/cohort': { + exports: 'edx.groups.CohortModel', deps: ['backbone'] }, - 'js/collections/cohort': { - exports: 'CohortCollection', - deps: ['backbone', 'js/models/cohort'] + 'js/groups/collections/cohort': { + exports: 'edx.groups.CohortCollection', + deps: ['backbone', 'js/groups/models/cohort'] }, - 'js/views/cohort_editor': { - exports: 'CohortsEditor', - deps: ['backbone', 'jquery', 'underscore', 'js/views/notification', 'js/models/notification', + 'js/groups/views/cohort_editor': { + exports: 'edx.groups.CohortsEditor', + deps: [ + 'backbone', 'jquery', 'underscore', 'js/views/notification', 'js/models/notification', 'string_utils' ] }, - 'js/views/cohorts': { - exports: 'CohortsView', - deps: ['jquery', 'underscore', 'backbone', 'gettext', 'string_utils', 'js/views/cohort_editor', + 'js/groups/views/cohorts': { + exports: 'edx.groups.CohortsView', + deps: [ + 'jquery', 'underscore', 'backbone', 'gettext', 'string_utils', 'js/groups/views/cohort_editor', 'js/views/notification', 'js/models/notification', 'js/views/file_uploader' ] }, @@ -310,7 +312,8 @@ }, 'js/views/file_uploader': { exports: 'FileUploaderView', - deps: ['backbone', 'jquery', 'underscore', 'gettext', 'string_utils', 'js/views/notification', + deps: [ + 'backbone', 'jquery', 'underscore', 'gettext', 'string_utils', 'js/views/notification', 'js/models/notification', 'jquery.fileupload' ] }, @@ -505,12 +508,12 @@ // TODO: why do these need 'lms/include' at the front but the CMS equivalent logic doesn't? define([ // Run the LMS tests - 'lms/include/js/spec/views/cohorts_spec.js', 'lms/include/js/spec/photocapture_spec.js', 'lms/include/js/spec/staff_debug_actions_spec.js', 'lms/include/js/spec/views/notification_spec.js', 'lms/include/js/spec/views/file_uploader_spec.js', 'lms/include/js/spec/dashboard/donation.js', + 'lms/include/js/spec/groups/views/cohorts_spec.js', 'lms/include/js/spec/shoppingcart/shoppingcart_spec.js', 'lms/include/js/spec/instructor_dashboard/ecommerce_spec.js', 'lms/include/js/spec/student_account/account_spec.js', diff --git a/lms/templates/instructor/instructor_dashboard_2/instructor_dashboard_2.html b/lms/templates/instructor/instructor_dashboard_2/instructor_dashboard_2.html index a3e389f271..733b5a90ab 100644 --- a/lms/templates/instructor/instructor_dashboard_2/instructor_dashboard_2.html +++ b/lms/templates/instructor/instructor_dashboard_2/instructor_dashboard_2.html @@ -57,10 +57,10 @@ - - - - + + + + ## Include Underscore templates diff --git a/lms/templates/instructor/instructor_dashboard_2/membership.html b/lms/templates/instructor/instructor_dashboard_2/membership.html index 2d18373c37..3d61a5ada6 100644 --- a/lms/templates/instructor/instructor_dashboard_2/membership.html +++ b/lms/templates/instructor/instructor_dashboard_2/membership.html @@ -258,9 +258,9 @@ $(document).ready(function() { var cohortManagementElement = $('.cohort-management'); if (cohortManagementElement.length > 0) { - var cohorts = new CohortCollection(); + var cohorts = new edx.groups.CohortCollection(); cohorts.url = cohortManagementElement.data('ajax_url'); - var cohortsView = new CohortsView({ + var cohortsView = new edx.groups.CohortsView({ el: cohortManagementElement, model: cohorts, advanced_settings_url: cohortManagementElement.data('advanced-settings-url'),