Commit eff80bae by Diana Huang Committed by cahrens

Convert cohort JS to use RequireJS.

parent 1ceb8a0d
var edx = edx || {}; ;(function (define) {
(function(Backbone, CohortModel) {
'use strict'; 'use strict';
define(['backbone', 'js/groups/models/cohort'], function(Backbone, CohortModel) {
edx.groups = edx.groups || {}; var CohortCollection = Backbone.Collection.extend({
edx.groups.CohortCollection = Backbone.Collection.extend({
model : CohortModel, model : CohortModel,
comparator: "name", comparator: "name",
...@@ -13,4 +10,6 @@ var edx = edx || {}; ...@@ -13,4 +10,6 @@ var edx = edx || {};
return response.cohorts; return response.cohorts;
} }
}); });
}).call(this, Backbone, edx.groups.CohortModel); return CohortCollection;
});
}).call(this, define || RequireJS.define);
var edx = edx || {}; ;(function (define) {
(function(Backbone) {
'use strict'; 'use strict';
define(['backbone'], function(Backbone) {
edx.groups = edx.groups || {}; var CohortModel = Backbone.Model.extend({
edx.groups.CohortModel = Backbone.Model.extend({
idAttribute: 'id', idAttribute: 'id',
defaults: { defaults: {
name: '', name: '',
...@@ -26,4 +23,6 @@ var edx = edx || {}; ...@@ -26,4 +23,6 @@ var edx = edx || {};
group_id: null group_id: null
} }
}); });
}).call(this, Backbone); return CohortModel;
});
}).call(this, define || RequireJS.define);
var edx = edx || {}; ;(function (define) {
(function(Backbone) {
'use strict'; 'use strict';
define(['backbone'], function(Backbone) {
edx.groups = edx.groups || {}; var DiscussionTopicsSettingsModel = Backbone.Model.extend({
edx.groups.DiscussionTopicsSettingsModel = Backbone.Model.extend({
defaults: { defaults: {
course_wide_discussions: {}, course_wide_discussions: {},
inline_discussions: {} inline_discussions: {}
} }
}); });
}).call(this, Backbone); return DiscussionTopicsSettingsModel;
});
}).call(this, define || RequireJS.define);
var edx = edx || {}; ;(function (define) {
(function(Backbone) {
'use strict'; 'use strict';
define(['backbone'], function(Backbone) {
edx.groups = edx.groups || {}; var ContentGroupModel = Backbone.Model.extend({
edx.groups.ContentGroupModel = Backbone.Model.extend({
idAttribute: 'id', idAttribute: 'id',
defaults: { defaults: {
name: '', name: '',
user_partition_id: null user_partition_id: null
} }
}); });
}).call(this, Backbone); return ContentGroupModel;
});
}).call(this, define || RequireJS.define);
var edx = edx || {}; ;(function (define) {
(function(Backbone) {
'use strict'; 'use strict';
define(['backbone'], function(Backbone) {
edx.groups = edx.groups || {}; var CourseCohortSettingsModel = Backbone.Model.extend({
edx.groups.CourseCohortSettingsModel = Backbone.Model.extend({
idAttribute: 'id', idAttribute: 'id',
defaults: { defaults: {
is_cohorted: false, is_cohorted: false,
...@@ -14,4 +11,6 @@ var edx = edx || {}; ...@@ -14,4 +11,6 @@ var edx = edx || {};
always_cohort_inline_discussions: true always_cohort_inline_discussions: true
} }
}); });
}).call(this, Backbone); return CourseCohortSettingsModel;
});
}).call(this, define || RequireJS.define);
var edx = edx || {}; ;(function (define) {
(function ($, _, Backbone, gettext, interpolate_text, NotificationModel, NotificationView) {
'use strict'; 'use strict';
define(['jquery', 'underscore', 'backbone', 'gettext', 'js/models/notification', 'js/views/notification'],
function ($, _, Backbone) {
edx.groups = edx.groups || {}; var CohortDiscussionConfigurationView = Backbone.View.extend({
edx.groups.CohortDiscussionConfigurationView = Backbone.View.extend({
/** /**
* Add/Remove the disabled attribute on given element. * Add/Remove the disabled attribute on given element.
...@@ -95,5 +93,6 @@ var edx = edx || {}; ...@@ -95,5 +93,6 @@ var edx = edx || {};
} }
}); });
}).call(this, $, _, Backbone, gettext, interpolate_text, NotificationModel, NotificationView return CohortDiscussionConfigurationView;
); });
}).call(this, define || RequireJS.define);
var edx = edx || {}; ;(function (define) {
(function ($, _, Backbone, gettext, interpolate_text, CohortDiscussionConfigurationView) {
'use strict'; 'use strict';
define(['jquery', 'underscore', 'backbone', 'gettext', 'js/groups/views/cohort_discussions'],
edx.groups = edx.groups || {}; function ($, _, Backbone, gettext, CohortDiscussionConfigurationView) {
var CourseWideDiscussionsView = CohortDiscussionConfigurationView.extend({
edx.groups.CourseWideDiscussionsView = CohortDiscussionConfigurationView.extend({
events: { events: {
'change .check-discussion-subcategory-course-wide': 'discussionCategoryStateChanged', 'change .check-discussion-subcategory-course-wide': 'discussionCategoryStateChanged',
'click .cohort-course-wide-discussions-form .action-save': 'saveCourseWideDiscussionsForm' 'click .cohort-course-wide-discussions-form .action-save': 'saveCourseWideDiscussionsForm'
...@@ -80,4 +77,6 @@ var edx = edx || {}; ...@@ -80,4 +77,6 @@ var edx = edx || {};
} }
}); });
}).call(this, $, _, Backbone, gettext, interpolate_text, edx.groups.CohortDiscussionConfigurationView); return CourseWideDiscussionsView;
});
}).call(this, define || RequireJS.define);
var edx = edx || {}; ;(function (define) {
(function ($, _, Backbone, gettext, interpolate_text, CohortDiscussionConfigurationView) {
'use strict'; 'use strict';
define(['jquery', 'underscore', 'backbone', 'gettext', 'js/groups/views/cohort_discussions', 'js/vendor/jquery.qubit'],
edx.groups = edx.groups || {}; function ($, _, Backbone, gettext, CohortDiscussionConfigurationView) {
var InlineDiscussionsView = CohortDiscussionConfigurationView.extend({
edx.groups.InlineDiscussionsView = CohortDiscussionConfigurationView.extend({
events: { events: {
'change .check-discussion-category': 'setSaveButton', 'change .check-discussion-category': 'setSaveButton',
'change .check-discussion-subcategory-inline': 'setSaveButton', 'change .check-discussion-subcategory-inline': 'setSaveButton',
...@@ -142,4 +139,6 @@ var edx = edx || {}; ...@@ -142,4 +139,6 @@ var edx = edx || {};
} }
}); });
}).call(this, $, _, Backbone, gettext, interpolate_text, edx.groups.CohortDiscussionConfigurationView); return InlineDiscussionsView;
});
}).call(this, define || RequireJS.define);
var edx = edx || {}; ;(function (define) {
(function(Backbone, _, $, gettext, ngettext, interpolate_text, CohortFormView, NotificationModel, NotificationView) {
'use strict'; 'use strict';
define(['backbone', 'underscore', 'jquery', 'gettext', 'js/groups/views/cohort_form', 'string_utils',
edx.groups = edx.groups || {}; 'js/models/notification', 'js/views/notification'],
function(Backbone, _, $, gettext, CohortFormView) {
edx.groups.CohortEditorView = Backbone.View.extend({ var CohortEditorView = Backbone.View.extend({
events : { events : {
'click .wrapper-tabs .tab': 'selectTab', 'click .wrapper-tabs .tab': 'selectTab',
...@@ -255,5 +253,6 @@ var edx = edx || {}; ...@@ -255,5 +253,6 @@ var edx = edx || {};
} }
} }
}); });
}).call(this, Backbone, _, $, gettext, ngettext, interpolate_text, edx.groups.CohortFormView, return CohortEditorView;
NotificationModel, NotificationView); });
}).call(this, define || RequireJS.define);
var edx = edx || {}; ;(function (define) {
(function($, _, Backbone, gettext, interpolate_text, CohortModel, NotificationModel, NotificationView) {
'use strict'; 'use strict';
define(['jquery', 'underscore', 'backbone', 'gettext', 'js/groups/models/cohort',
'js/models/notification', 'js/views/notification'],
function($, _, Backbone, gettext, CohortModel) {
edx.groups = edx.groups || {}; var CohortFormView = Backbone.View.extend({
edx.groups.CohortFormView = Backbone.View.extend({
events : { events : {
'change .cohort-management-details-association-course input': 'onRadioButtonChange' 'change .cohort-management-details-association-course input': 'onRadioButtonChange'
}, },
...@@ -169,4 +168,6 @@ var edx = edx || {}; ...@@ -169,4 +168,6 @@ var edx = edx || {};
return saveOperation.promise(); return saveOperation.promise();
} }
}); });
}).call(this, $, _, Backbone, gettext, interpolate_text, edx.groups.CohortModel, NotificationModel, NotificationView); return CohortFormView;
});
}).call(this, define || RequireJS.define);
var edx = edx || {}; ;(function (define) {
(function($, _, Backbone, gettext, interpolate_text, CohortModel, CohortEditorView, CohortFormView,
CourseCohortSettingsNotificationView, NotificationModel, NotificationView, FileUploaderView,
InlineDiscussionsView, CourseWideDiscussionsView) {
'use strict'; 'use strict';
define(['jquery', 'underscore', 'backbone', 'gettext', 'js/groups/models/cohort',
'js/groups/views/cohort_editor', 'js/groups/views/cohort_form',
'js/groups/views/course_cohort_settings_notification',
'js/groups/views/cohort_discussions_inline', 'js/groups/views/cohort_discussions_course_wide',
'js/views/file_uploader', 'js/models/notification', 'js/views/notification', 'string_utils'],
function($, _, Backbone, gettext, CohortModel, CohortEditorView, CohortFormView,
CourseCohortSettingsNotificationView, InlineDiscussionsView, CourseWideDiscussionsView) {
var hiddenClass = 'is-hidden', var hiddenClass = 'is-hidden',
disabledClass = 'is-disabled'; disabledClass = 'is-disabled';
edx.groups = edx.groups || {};
edx.groups.CohortsView = Backbone.View.extend({ var CohortsView = Backbone.View.extend({
events : { events : {
'change .cohort-select': 'onCohortSelected', 'change .cohort-select': 'onCohortSelected',
'change .cohorts-state': 'onCohortsEnabledChanged', 'change .cohorts-state': 'onCohortsEnabledChanged',
...@@ -305,6 +307,6 @@ var edx = edx || {}; ...@@ -305,6 +307,6 @@ var edx = edx || {};
return ".instructor-nav .nav-item a[data-section='" + section + "']"; return ".instructor-nav .nav-item a[data-section='" + section + "']";
} }
}); });
}).call(this, $, _, Backbone, gettext, interpolate_text, edx.groups.CohortModel, edx.groups.CohortEditorView, return CohortsView;
edx.groups.CohortFormView, edx.groups.CourseCohortSettingsNotificationView, NotificationModel, NotificationView, });
FileUploaderView, edx.groups.InlineDiscussionsView, edx.groups.CourseWideDiscussionsView); }).call(this, define || RequireJS.define);
;(function (define, undefined) { ;(function (define, undefined) {
'use strict'; 'use strict';
define(['jquery', 'js/groups/views/cohorts', 'js/groups/collections/cohort', 'js/groups/models/course_cohort_settings', define(['jquery', 'js/groups/views/cohorts', 'js/groups/collections/cohort', 'js/groups/models/course_cohort_settings',
'js/groups/models/cohort_discussions'], 'js/groups/models/cohort_discussions', 'js/groups/models/content_group'],
function($) { function($, CohortsView, CohortCollection, CourseCohortSettingsModel, DiscussionTopicsSettingsModel, ContentGroupModel) {
return function(contentGroups, studioGroupConfigurationsUrl) { return function(contentGroups, studioGroupConfigurationsUrl) {
var contentGroupModels = $.map(contentGroups, function(group) {
return new ContentGroupModel({
id: group.id,
name: group.name,
user_partition_id: group.user_partition_id
});
});
var cohorts = new edx.groups.CohortCollection(), var cohorts = new CohortCollection(),
courseCohortSettings = new edx.groups.CourseCohortSettingsModel(), courseCohortSettings = new CourseCohortSettingsModel(),
discussionTopicsSettings = new edx.groups.DiscussionTopicsSettingsModel(); discussionTopicsSettings = new DiscussionTopicsSettingsModel();
var cohortManagementElement = $('.cohort-management'); var cohortManagementElement = $('.cohort-management');
...@@ -16,10 +23,10 @@ ...@@ -16,10 +23,10 @@
courseCohortSettings.url = cohortManagementElement.data('course_cohort_settings_url'); courseCohortSettings.url = cohortManagementElement.data('course_cohort_settings_url');
discussionTopicsSettings.url = cohortManagementElement.data('discussion-topics-url'); discussionTopicsSettings.url = cohortManagementElement.data('discussion-topics-url');
var cohortsView = new edx.groups.CohortsView({ var cohortsView = new CohortsView({
el: cohortManagementElement, el: cohortManagementElement,
model: cohorts, model: cohorts,
contentGroups: contentGroups, contentGroups: contentGroupModels,
cohortSettings: courseCohortSettings, cohortSettings: courseCohortSettings,
context: { context: {
discussionTopicsSettingsModel: discussionTopicsSettings, discussionTopicsSettingsModel: discussionTopicsSettings,
......
var edx = edx || {}; ;(function (define) {
(function($, _, Backbone, gettext) {
'use strict'; 'use strict';
define(['jquery', 'underscore', 'backbone', 'gettext'], function($, _, Backbone, gettext) {
edx.groups = edx.groups || {}; var CourseCohortSettingsNotificationView = Backbone.View.extend({
edx.groups.CourseCohortSettingsNotificationView = Backbone.View.extend({
initialize: function(options) { initialize: function(options) {
this.template = _.template($('#cohort-state-tpl').text()); this.template = _.template($('#cohort-state-tpl').text());
this.cohortEnabled = options.cohortEnabled; this.cohortEnabled = options.cohortEnabled;
...@@ -28,4 +25,6 @@ var edx = edx || {}; ...@@ -28,4 +25,6 @@ var edx = edx || {};
} }
} }
}); });
}).call(this, $, _, Backbone, gettext); return CourseCohortSettingsNotificationView;
});
}).call(this, define || RequireJS.define);
...@@ -67,18 +67,6 @@ ...@@ -67,18 +67,6 @@
'js/models/notification': 'js/models/notification', 'js/models/notification': 'js/models/notification',
'js/views/file_uploader': 'js/views/file_uploader', 'js/views/file_uploader': 'js/views/file_uploader',
'js/views/notification': 'js/views/notification', 'js/views/notification': 'js/views/notification',
'js/groups/models/cohort': 'js/groups/models/cohort',
'js/groups/models/content_group': 'js/groups/models/content_group',
'js/groups/models/course_cohort_settings': 'js/groups/models/course_cohort_settings',
'js/groups/models/cohort_discussions': 'js/groups/models/cohort_discussions',
'js/groups/views/cohort_discussions': 'js/groups/views/cohort_discussions',
'js/groups/views/cohort_discussions_course_wide': 'js/groups/views/cohort_discussions_course_wide',
'js/groups/views/cohort_discussions_inline': 'js/groups/views/cohort_discussions_inline',
'js/groups/views/course_cohort_settings_notification': 'js/groups/views/course_cohort_settings_notification',
'js/groups/collections/cohort': 'js/groups/collections/cohort',
'js/groups/views/cohort_editor': 'js/groups/views/cohort_editor',
'js/groups/views/cohort_form': 'js/groups/views/cohort_form',
'js/groups/views/cohorts': 'js/groups/views/cohorts',
'js/student_account/account': 'js/student_account/account', 'js/student_account/account': 'js/student_account/account',
'js/student_account/views/FormView': 'js/student_account/views/FormView', 'js/student_account/views/FormView': 'js/student_account/views/FormView',
'js/student_account/models/LoginModel': 'js/student_account/models/LoginModel', 'js/student_account/models/LoginModel': 'js/student_account/models/LoginModel',
...@@ -301,63 +289,6 @@ ...@@ -301,63 +289,6 @@
exports: 'edx.instructor_dashboard.ecommerce.ExpiryCouponView', exports: 'edx.instructor_dashboard.ecommerce.ExpiryCouponView',
deps: ['backbone', 'jquery', 'underscore'] deps: ['backbone', 'jquery', 'underscore']
}, },
'js/groups/models/cohort': {
exports: 'edx.groups.CohortModel',
deps: ['backbone']
},
'js/groups/models/content_group': {
exports: 'edx.groups.ContentGroupModel',
deps: ['backbone']
},
'js/groups/models/course_cohort_settings': {
exports: 'edx.groups.CourseCohortSettingsModel',
deps: ['backbone']
},
'js/groups/models/cohort_discussions': {
exports: 'edx.groups.DiscussionTopicsSettingsModel',
deps: ['backbone']
},
'js/groups/views/cohort_discussions': {
exports: 'edx.groups.CohortDiscussionConfigurationView',
deps: ['backbone']
},
'js/groups/views/cohort_discussions_course_wide': {
exports: 'edx.groups.CourseWideDiscussionsView',
deps: ['backbone', 'js/groups/views/cohort_discussions']
},
'js/groups/views/cohort_discussions_inline': {
exports: 'edx.groups.InlineDiscussionsView',
deps: ['backbone', 'js/groups/views/cohort_discussions', 'js/vendor/jquery.qubit']
},
'js/groups/views/course_cohort_settings_notification': {
exports: 'edx.groups.CourseCohortSettingsNotificationView',
deps: ['backbone']
},
'js/groups/collections/cohort': {
exports: 'edx.groups.CohortCollection',
deps: ['backbone', 'js/groups/models/cohort']
},
'js/groups/views/cohort_form': {
exports: 'edx.groups.CohortFormView',
deps: [
'backbone', 'jquery', 'underscore', 'js/views/notification', 'js/models/notification',
'string_utils'
]
},
'js/groups/views/cohort_editor': {
exports: 'edx.groups.CohortEditorView',
deps: [
'backbone', 'jquery', 'underscore', 'js/views/notification', 'js/models/notification',
'string_utils', 'js/groups/views/cohort_form'
]
},
'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'
]
},
'js/models/notification': { 'js/models/notification': {
exports: 'NotificationModel', exports: 'NotificationModel',
deps: ['backbone'] deps: ['backbone']
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* done. * done.
*/ */
modules: getModulesList([ modules: getModulesList([
'js/groups/views/cohorts_dashboard_factory',
'js/student_account/views/account_settings_factory', 'js/student_account/views/account_settings_factory',
'js/student_account/views/finish_auth_factory', 'js/student_account/views/finish_auth_factory',
'js/student_profile/views/learner_profile_factory', 'js/student_profile/views/learner_profile_factory',
......
<%page args="section_data"/> <%page args="section_data"/>
<%namespace name='static' file='../../static_content.html'/>
<%! <%!
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from courseware.courses import get_studio_url from courseware.courses import get_studio_url
...@@ -16,32 +17,23 @@ from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_ ...@@ -16,32 +17,23 @@ from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_
</div> </div>
<%block name="headextra"> <%block name="js_extra">
<%static:require_module module_name="js/groups/views/cohorts_dashboard_factory" class_name="CohortsFactory">
<% <%
cohorted_user_partition = get_cohorted_user_partition(course.id) cohorted_user_partition = get_cohorted_user_partition(course.id)
content_groups = cohorted_user_partition.groups if cohorted_user_partition else [] content_groups = cohorted_user_partition.groups if cohorted_user_partition else []
%> %>
<script type="text/javascript">
$(document).ready(function() {
var cohortUserPartitionId = ${cohorted_user_partition.id if cohorted_user_partition else 'null'}, var cohortUserPartitionId = ${cohorted_user_partition.id if cohorted_user_partition else 'null'},
contentGroups = [ contentGroups = [
% for content_group in content_groups: % for content_group in content_groups:
new edx.groups.ContentGroupModel({ {
id: ${content_group.id}, id: ${content_group.id},
name: "${content_group.name | h}", name: "${content_group.name | h}",
user_partition_id: cohortUserPartitionId user_partition_id: cohortUserPartitionId
}), },
% endfor % endfor
]; ];
(function (require) {
require(['js/groups/views/cohorts_dashboard_factory'], function (CohortsFactory) {
CohortsFactory(contentGroups, '${get_studio_url(course, 'group_configurations') | h}'); CohortsFactory(contentGroups, '${get_studio_url(course, 'group_configurations') | h}');
}); </%static:require_module>
}).call(this, require || RequireJS.require);
});
</script>
</%block> </%block>
<div class="cohort-state-message"></div> <div class="cohort-state-message"></div>
...@@ -56,22 +56,9 @@ from django.core.urlresolvers import reverse ...@@ -56,22 +56,9 @@ from django.core.urlresolvers import reverse
<%static:js group='application'/> <%static:js group='application'/>
## Backbone classes declared explicitly until RequireJS is supported ## Backbone classes declared explicitly until RequireJS is supported
<script type="text/javascript" src="${static.url('js/instructor_dashboard/cohort_management.js')}"></script>
<script type="text/javascript" src="${static.url('js/models/notification.js')}"></script> <script type="text/javascript" src="${static.url('js/models/notification.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/notification.js')}"></script> <script type="text/javascript" src="${static.url('js/views/notification.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/file_uploader.js')}"></script> <script type="text/javascript" src="${static.url('js/views/file_uploader.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/models/cohort.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/models/content_group.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/models/course_cohort_settings.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/collections/cohort.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/views/course_cohort_settings_notification.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/models/cohort_discussions.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/views/cohort_discussions.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/views/cohort_discussions_course_wide.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/views/cohort_discussions_inline.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/views/cohort_form.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/views/cohort_editor.js')}"></script>
<script type="text/javascript" src="${static.url('js/groups/views/cohorts.js')}"></script>
<script type="text/javascript" src="${static.url('js/utils/animation.js')}"></script> <script type="text/javascript" src="${static.url('js/utils/animation.js')}"></script>
</%block> </%block>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment