2025-02-09 04:09:19
define('home/views/ChannelProfileView',[
    'underscore',
 
    'core/utils/auth',
 
    'home/utils/backboneUtils',
    'home/utils/confirmModal',
    'home/utils/navigationUtils',
 
    'home/views/common/TabbedView',
    'home/views/ChannelCoverView',
    'home/views/ChannelMetadataView',
    'home/views/ChannelCardCollectionView',
    'home/views/ChannelCreateFormView',
    'home/views/common/FetchableCollectionLayout',
    'home/views/ChannelFeedFooterView',
    'home/views/UserCollectionView',
    'home/views/ChannelDiscussionFeedView',
    'home/views/ChannelTopicTabView',
    'home/views/ChannelModeratorsView',
 
    'home/templates/channelProfile',
    'home/templates/guidelines',
    'home/templates/spinnerTall',
 
    'core/UniqueModel',
    'home/models/Session',
    'home/models/Topic',
 
    'home/mixins/withClickLinkTracking',
    'home/mixins/withEmailVerificationAlert',
 
    'core/strings',
], function (
    _,
 
    auth,
 
    backboneUtils,
    confirmModal,
    navigationUtils,
 
    TabbedView,
    ChannelCoverView,
    ChannelMetadataView,
    ChannelCardCollectionView,
    ChannelCreateFormView,
    FetchableCollectionLayout,
    ChannelFeedFooterView,
    UserCollectionView,
    ChannelDiscussionFeedView,
    ChannelTopicTabView,
    ChannelModeratorsView,
 
    channelProfileTemplate,
    guidelinesTemplate,
    spinnerTallTemplate,
 
    UniqueModel,
    Session,
    Topic,
 
    withClickLinkTracking,
    withEmailVerificationAlert,
 
    strings
) {
    'use strict';
 
    var gettext = strings.get;
 
    var ChannelProfileView = TabbedView.extend({
        className: 'channel-profile',
 
        defaultTab: function () {
            return 'top';
        },
 
        // If the channel model is not yet fetched, show a spinner.
        // This is so that model-dependent parts of the page don't require the whole
        // page to re-render on model fetch, which would cause all the subviews to
        // re-render as well.
        template: function (data) {
            return data.channel.name ?
                channelProfileTemplate(data) :
                spinnerTallTemplate(data);
        },
 
        templateHelpers: function () {
            var isDisqusAdmin = auth.getFromCookie().staff;
            var isChannelModerator = isDisqusAdmin || this.model.moderators.items.contains(this.session.user);
 
            return {
                isDisqusAdmin: isDisqusAdmin,
                isChannelModerator: isChannelModerator,
                isSessionUserChannelOwner: this.isSessionUserChannelOwner(),
            };
        },
 
        regions: _.defaults({
            coverRegion: '[data-role=cover]',
            metadataRegion: '[data-role=metadata]',
        }, TabbedView.prototype.regions),
 
        initialize: function (options) {
            if (options && options.activeTab === 'guidelines') {
                // guidelines are shown in a modal, not a tab
                options.activeTab = _.result(this, 'defaultTab');
                this.listenToOnce(this, 'show', this.showGuidelines);
            }
 
            this.session = Session.get();
 
            TabbedView.prototype.initialize.apply(this, arguments);
 
            this.listenTo(this.model.channel, 'sync', this.render);
            this.listenTo(this.model.moderators, 'items:sync', this.render);
 
            if (this.model.trendingTopics)
                this.listenTo(this.model.trendingTopics, 'items:sync', this.render);
 
            // When the tab changes, update any sidebar modules that should be shown or hidden
            // depending on which tab is active.
            this.listenTo(this, 'change:activeTab', this.updateTabSpecificModules);
        },
 
        events: _.defaults({
            'click a[data-link-name]': 'trackClickLink',
            'click [data-action=show-guidelines]': 'showGuidelines',
            'click [data-action=hide-metadata]': 'hideMetadata',
        }, TabbedView.prototype.events),
 
        hideMetadata: function () {
            this.trigger('showMetadata', false);
        },
 
        showGuidelines: function () {
            var self = this;
            backboneUtils.getPromiseFor(this.model.channel, 'name').then(function () {
                var modalHtml = guidelinesTemplate(self.model.channel.toJSON());
 
                confirmModal.confirmationPromise(confirmModal.TYPES.CLOSE, modalHtml).always(function () {
                    navigationUtils.navigate('/channel/' + self.model.id + '/', { replace: true, silent: true });
                });
            });
        },
 
        onDomRefresh: function () {
            if (!this.$(this.coverRegion.el).length)
                // Page has not yet rendered regions, still fetching models
                return;
 
            var coverView = new ChannelCoverView({
                model: this.model.channel,
            });
            this.listenTo(coverView, 'showMetadata', this.showMetadata);
            this.coverRegion.show(coverView);
 
            this.metadataRegion.show(new ChannelMetadataView({
                model: this.model,
            }));
 
            TabbedView.prototype.onDomRefresh.apply(this, arguments);
        },
 
        updateTabSpecificModules: function (activeTab) {
            var isTopicTab = /^topic-.+/.test(activeTab);
            this.$('[data-role=default-nav]').toggleClass('hidden', isTopicTab);
        },
 
        showMetadata: function (shouldShowMetadata) {
            this.$el.toggleClass('metadata-view', shouldShowMetadata);
        },
 
        getTrackingSection: function (activeTab) {
            // Return the tab name for tracking
            return activeTab;
        },
 
        getTabView: function (activeTab) {
            var view;
 
            switch (activeTab) {
            case 'recent':
                return new ChannelDiscussionFeedView({
                    model: this.model.recentActivities,
                    collection: this.model.recentActivities.items,
                    fetchableCollectionView: ChannelCardCollectionView,
                    fetchableCollectionFooterView: ChannelFeedFooterView,
                    channel: this.model.channel,
                    isChannelFeed: true,
                    infiniteScroll: true,
                    filterVerbs: ['trending'],
                });
            case 'top':
                return new ChannelDiscussionFeedView({
                    model: this.model.topActivities,
                    collection: this.model.topActivities.items,
                    fetchableCollectionView: ChannelCardCollectionView,
                    fetchableCollectionFooterView: ChannelFeedFooterView,
                    channel: this.model.channel,
                    isChannelFeed: true,
                    infiniteScroll: true,
                });
            case 'followers':
                view = new FetchableCollectionLayout({
                    model: this.model.followers,
                    collection: this.model.followers.items,
                    fetchableCollectionView: UserCollectionView,
                    fetchableCollectionFooterView: ChannelFeedFooterView,
                    infiniteScroll: true,
                });
                view.$el.attr({
                    'class': 'card-wrap',
                });
 
                return view;
            case 'basics':
                if (!this.isSessionUserChannelOwner()) {
                    this.trigger('badTab');
                    return;
                }
 
                view = new ChannelCreateFormView({
                    model: this.model.channel,
                    session: this.session,
                });
 
                this.listenTo(view, 'updated', function (model) {
                    navigationUtils.navigate('/channel/' + model.id + '/', { trigger: true });
                });
 
                return view;
            case 'moderators':
                if (!this.isSessionUserChannelOwner()) {
                    this.trigger('badTab');
                    return;
                }
 
                return new ChannelModeratorsView({
                    model: this.model,
                });
            }
 
            // Tabs that show a feed filtered to a topic have a naming format
            // of topic-<topicname>. If this is a topic tab, parse out the
            // name of the to topic on which to filter and show the feed
            // filtered to that topic.
            var topicTab = activeTab.match(/^topic-(.+)/);
            if (topicTab) {
                // TODO remove when releasing globally
                if (!this.model.trendingTopics)
                    return;
 
                var topicName = topicTab[1];
                var feed = this.model.getFetchedTopicFilteredFeed(topicName);
 
                return new ChannelTopicTabView({
                    model: feed,
                    collection: feed.items,
                    fetchableCollectionView: ChannelCardCollectionView,
                    fetchableCollectionFooterView: ChannelFeedFooterView,
                    filteredTopic: new UniqueModel(Topic, { identifier: topicName }),
                    channel: this.model.channel,
                    isChannelFeed: true,
                    infiniteScroll: true,
                });
            }
        },
 
        isSessionUserChannelOwner: function () {
            return this.model.channel.get('owner_id') === this.session.user.get('id');
        },
 
        getPageTitle: function () {
            var channel = this.model.channel;
            return backboneUtils.getPromiseFor(channel, 'name')
                .then(function (channelName) {
                    return strings.interpolate(gettext('%(name)s Channel'), { name: channelName });
                });
        },
 
        getMetaAttrs: function () {
            var channel = this.model.channel;
            return this.getPageTitle()
                .then(function (pageTitle) {
                    var options = channel.get('options') || {};
                    return {
                        title: pageTitle,
                        image: options.coverImage ? options.coverImage.cache : options.tile,
                        description: options.description,
                        type: 'article',
                    };
                });
        },
 
        getPageTrackingParams: function () {
            var channel = this.model.channel;
            return this.getPageTitle().then(function (pageTitle) {
                return {
                    channel_slug: channel.get('slug'),
                    title: pageTitle,
                };
            });
        },
    });
 
    withClickLinkTracking.call(ChannelProfileView.prototype);
    withEmailVerificationAlert.call(ChannelProfileView.prototype);
 
    return ChannelProfileView;
});
 
// https://c.disquscdn.com/next/current/home/js/views/ChannelProfileView.js
Invalid Email or Password