notes_page.js 2.84 KB
Newer Older
1 2 3 4 5 6 7
(function(define, undefined) {
    'use strict';
    define([
        'backbone', 'js/edxnotes/collections/tabs', 'js/edxnotes/views/tabs_list',
        'js/edxnotes/views/tabs/recent_activity', 'js/edxnotes/views/tabs/course_structure',
        'js/edxnotes/views/tabs/search_results', 'js/edxnotes/views/tabs/tags'
    ], function(
8
    Backbone, TabsCollection, TabsListView, RecentActivityView, CourseStructureView,
9
    SearchResultsView, TagsView
10
) {
11 12 13
        var NotesPageView = Backbone.View.extend({
            initialize: function(options) {
                var scrollToTag, tagsModel;
14

15 16
                this.options = options;
                this.tabsCollection = new TabsCollection();
17

18
                if (!_.contains(this.options.disabledTabs, 'tags')) {
19
                // Must create the Tags view first to get the "scrollToTag" method.
20 21 22 23 24
                    this.tagsView = new TagsView({
                        el: this.el,
                        collection: this.collection,
                        tabsCollection: this.tabsCollection
                    });
25

26
                    scrollToTag = this.tagsView.scrollToTag;
27

28
                // Remove the Tags model from the tabs collection because it should not appear first.
29 30
                    tagsModel = this.tabsCollection.shift();
                }
31

32
                this.recentActivityView = new RecentActivityView({
33 34 35 36 37
                    el: this.el,
                    collection: this.collection,
                    tabsCollection: this.tabsCollection,
                    scrollToTag: scrollToTag
                });
38 39 40 41 42 43 44 45 46 47 48

                if (!_.contains(this.options.disabledTabs, 'course_structure')) {
                    this.courseStructureView = new CourseStructureView({
                        el: this.el,
                        collection: this.collection,
                        tabsCollection: this.tabsCollection,
                        scrollToTag: scrollToTag
                    });
                }

                if (!_.contains(this.options.disabledTabs, 'tags')) {
49
                // Add the Tags model after the Course Structure model.
50 51
                    this.tabsCollection.push(tagsModel);
                }
52

53 54 55 56 57 58 59 60
                this.searchResultsView = new SearchResultsView({
                    el: this.el,
                    tabsCollection: this.tabsCollection,
                    debug: this.options.debug,
                    perPage: this.options.perPage,
                    createTabOnInitialization: false,
                    scrollToTag: scrollToTag
                });
61

62 63
                this.tabsView = new TabsListView({collection: this.tabsCollection});
                this.$('.tab-list')
64 65
                .append(this.tabsView.render().$el)
                .removeClass('is-hidden');
66 67
            }
        });
68

69 70
        return NotesPageView;
    });
71
}).call(this, define || RequireJS.define);