const CoreView = require('backbone/core-view'); const checkAndBuildOpts = require('builder/helpers/required-opts'); const TrialNotificationView = require('dashboard/components/trial-notification/trial-notification-view'); const AccountContentView = require('./account-content-view'); const UpgradeMessage = require('dashboard/components/upgrade-message-view.js'); const VendorScriptsView = require('dashboard/components/vendor-scripts/vendor-scripts-view'); const FlashMessageModel = require('dashboard/data/flash-message-model'); const FlashMessageView = require('dashboard/components/flash-message/flash-message-view'); var moment = require('moment'); const TRIAL_ACCOUNTS = ['PERSONAL30', 'Individual']; const REQUIRED_OPTS = [ 'userModel', 'configModel', 'client', 'assetsVersion', 'organizationNotifications' ]; module.exports = CoreView.extend({ initialize: function (options) { checkAndBuildOpts(options, REQUIRED_OPTS, this); this._initViews(); }, _initViews: function () { const $app = this.$('#app'); const accountType = this._userModel.get('account_type'); if (TRIAL_ACCOUNTS.indexOf(accountType) > -1) { const trialEndsAt = moment(this._userModel.get('trial_ends_at')); const now = moment(); const trialNotificationView = new TrialNotificationView({ userModel: this._userModel, upgradeUrl: this._configModel.get('upgrade_url'), trialDays: Math.round(trialEndsAt.diff(now, 'days', true)) }); $app.append(trialNotificationView.render().el); this.addView(trialNotificationView); } const flashMessageModel = new FlashMessageModel(); const flashMessageView = new FlashMessageView({ model: flashMessageModel }); $app.prepend(flashMessageView.render().el); this.addView(flashMessageView); const accountContentView = new AccountContentView({ userModel: this._userModel, configModel: this._configModel, flashMessageModel, client: this._client }); $app.append(accountContentView.render().el); this.addView(accountContentView); const upgradeMessage = new UpgradeMessage({ userModel: this._userModel, configModel: this._configModel }); $app.prepend(upgradeMessage.render().el); this.addView(upgradeMessage); const vendorScriptsView = new VendorScriptsView({ configModel: this._configModel, assetsVersion: this._assetsVersion, userModel: this._userModel }); this.$el.append(vendorScriptsView.render().el); this.addView(vendorScriptsView); return this; } });