Example #1
0
function removeSubscription( blogId ) {
	if ( ! blogId ) {
		return;
	}

	// Sanity check - is the user actually subscribed to the blog?
	if ( ! CommentEmailSubscriptionStore.getSubscription( blogId ) ) {
		return false;
	}

	subscriptions[ blogId ] = null;
	return true;
}

Emitter( CommentEmailSubscriptionStore ); // eslint-disable-line

// Increase the max number of listeners from 10 to 100
CommentEmailSubscriptionStore.setMaxListeners( 200 );

CommentEmailSubscriptionStore.dispatchToken = Dispatcher.register( function( payload ) {
	const action = payload.action;

	if ( ! action ) {
		return;
	}

	switch ( action.type ) {
		case ActionTypes.SUBSCRIBE_TO_COMMENT_EMAILS:
			CommentEmailSubscriptionStore.receiveSubscribe( action );
			break;
Example #2
0
	},

	isUpdated( listId ) {
		return !! updatedLists[ listId ];
	},

	isFetching() {
		return isFetching;
	},

	setIsFetching( val ) {
		isFetching = val;
	}
};

emitter( ListStore );

function receiveList( newList ) {
	const existing = ListStore.get( newList.owner, newList.slug );

	newList.URL = getListURL( newList );
	newList.title = decodeEntities( newList.title );

	if ( ! isEqual( existing, newList ) ) {
		lists[ keyForList( newList.owner, newList.slug ) ] = newList;
		ListStore.emit( 'change' );
	}
}

function markUpdatedList( newList ) {
	updatedLists[ newList.ID ] = true;
 * constant error types.
 *
 * {
 *     [ siteId ]: {
 *         [ itemId ]: [
 *             MediaValidationErrors.FILE_TYPE_UNSUPPORTED,
 *             MediaValidationErrors.EXCEEDS_MAX_UPLOAD_SIZE
 *         ]
 *     }
 * }
 *
 * @type {Object}
 * @private
 */

emitter( MediaValidationStore );

function ensureErrorsObjectForSite( siteId ) {
	if ( siteId in MediaValidationStore._errors ) {
		return;
	}

	MediaValidationStore._errors[ siteId ] = {};
}

const isExternalError = message => message.error && message.error === 'servicefail';
const isMediaError = action => action.error && ( action.id || isExternalError( action.error ) );

MediaValidationStore.validateItem = function( site, item ) {
	const itemErrors = [];
Example #4
0
	if ( ! ( this instanceof User ) ) {
		return new User();
	}

	this.initialize();
}

/**
 * Constants
 */
const VERIFICATION_POLL_INTERVAL = 15000;

/**
 * Mixins
 */
Emitter( User.prototype );

/**
 * Initialize the user data depending on the configuration
 **/
User.prototype.initialize = function() {
	debug( 'Initializing User' );
	this.fetching = false;
	this.initialized = false;

	this.on( 'change', this.checkVerification.bind( this ) );

	if ( isSupportUserSession() ) {
		this.data = false;

		supportUserBoot();
Example #5
0
/**
 * Internal dependencies
 */
var Dispatcher = require( 'dispatcher' ),
	emitter = require( 'lib/mixins/emitter' ),
	MediaValidationStore = require( './validation-store' );

/**
 * Module variables
 */
const MediaStore = {
	_media: {},
	_pointers: {}
};

emitter( MediaStore );

function receiveSingle( siteId, item, itemId ) {
	if ( ! ( siteId in MediaStore._media ) ) {
		MediaStore._media[ siteId ] = {};
	}

	if ( itemId ) {
		if ( ! ( siteId in MediaStore._pointers ) ) {
			MediaStore._pointers[ siteId ] = {};
		}

		MediaStore._pointers[ siteId ][ itemId ] = item.ID;
		delete MediaStore._media[ siteId ][ itemId ];
	}
Example #6
0
 * PlansList component
 *
 * @return { PlansList } PlansList instance
 */
function PlansList() {
	if ( ! ( this instanceof PlansList ) ) {
		return new PlansList();
	}

	this.initialized = false;
}

/**
 * Mixins
 */
Emitter( PlansList.prototype );

/**
 * Set up a mapping from product_slug to a pretty path
 */
const pathToSlugMapping = {
	beginner: PLAN_FREE,
	personal: PLAN_PERSONAL,
	premium: PLAN_PREMIUM,
	business: PLAN_BUSINESS
};

/**
 * Get list of plans from current object or store,
 * trigger fetch on first request to update stale data
 *
Example #7
0
 *
 * @api public
 */
export default function MenuData() {
	this.data = {};
	this.idCounter = 1;
	this.hasContentsChanged = false;
	this.hasAssociationChanged = false;
	sites.on( 'change', this.updateInstance.bind( this ) );
	this.updateInstance();
}

/**
 * Mixins
 */
Emitter( MenuData.prototype );

/**
 * Generates a home page menu item
 * This is used to inject home page item into pages list
 *
 * @param {String} pageNameSuffix - page name suffix
 * @return {Object} object menu builder
 */
MenuData.prototype.generateHomePageMenuItem = function( pageNameSuffix ) {
	return {
		ID: HOMEPAGE_MENU_ITEM_ID,
		content_id: HOMEPAGE_MENU_ITEM_ID,
		url: trailingslashit( this.site.URL ),
		name: i18n.translate( 'Home' ) + ( pageNameSuffix ? ': ' + pageNameSuffix : '' ),
		type: 'page',
Example #8
0
/**
 * SharingButtonsList component
 *
 * @api public
 */
function SharingButtonsList() {
	if ( ! ( this instanceof SharingButtonsList ) ) {
		return new SharingButtonsList();
	}
}

/**
 * Mixins
 */
Emitter( SharingButtonsList.prototype );

/**
 * Get list of sharing buttons from current object or, if this is the first
 * request for the specified site, fetch sharing buttons from REST API
 *
 * @param {int} siteId The site from which to retrieve sharing buttons
 */
SharingButtonsList.prototype.get = function( siteId ) {
	if ( ! this.data || this.siteId !== siteId ) {
		this.fetch( siteId );
		return [];
	}

	return this.data;
};
Example #9
0
var UpgradesActionTypes = require( 'lib/upgrades/constants' ).action,
	cartItems = require( 'lib/cart-values' ).cartItems,
	CartStore = require( 'lib/cart/store' ),
	Emitter = require( 'lib/mixins/emitter' ),
	Dispatcher = require( 'dispatcher' ),
	hasDomainDetails = require( 'lib/store-transactions' ).hasDomainDetails;

var _transaction = createInitialTransaction();

var TransactionStore = {
	get: function() {
		return _transaction;
	}
};

Emitter( TransactionStore );

function replaceData( newData ) {
	_transaction = cloneDeep( newData );
	TransactionStore.emit( 'change' );
}

function createInitialTransaction() {
	return {
		errors: {},
		newCardFormFields: {},
		step: { name: 'before-submit' },
		domainDetails: null
	};
}
Example #10
0
	teams = action.data.teams;
	TeamStore.emit( 'change' );
}

if ( config( 'env' ) === 'development' ) {
	assign( TeamStore, {
		// These bedlumps are for testing.
		_reset: function() {
			teams = null;
			errors = [];
		}
	} );
}

emitter( TeamStore );

TeamStore.dispatchToken = Dispatcher.register( function( payload ) {
	var action = payload.action;

	if ( ! action ) {
		return;
	}

	switch ( action.type ) {
		case ActionTypes.RECEIVE_TEAMS:
			receiveTeamsResponse( action );
			break;
	}
} );
/** @format */

/**
 * External dependencies
 */

import emitter from 'lib/mixins/emitter';

const countriesList = {
	get: function() {
		return [
			{
				code: 'US',
				name: 'United States (+1)',
				numeric_code: '+1',
				country_name: 'United States',
			},
			{
				code: 'AR',
				name: 'Argentina (+54)',
				numeric_code: '+54',
				country_name: 'Argentina',
			},
		];
	},
};

emitter( countriesList );

export default countriesList;
			resetEmail();
			emitChange();
			break;

		case actions.RECEIVE_DELETED_ACCOUNT_RECOVERY_EMAIL:
			if ( action.error ) {
				handleEmailError( action.error );
				break;
			}

			resetEmail();
			setEmailNotice( messages.EMAIL_DELETED );
			emitChange();
			break;

		case actions.DISMISS_ACCOUNT_RECOVERY_EMAIL_NOTICE:
			resetEmailNotice();
			emitChange();
			break;

		case actions.DISMISS_ACCOUNT_RECOVERY_PHONE_NOTICE:
			resetPhoneNotice();
			emitChange();
			break;
	}
} );

emitter( AccountRecoveryStore );

module.exports = AccountRecoveryStore;
Example #13
0
 *
 * @return {FeaturesList} FeaturesList instance
 * @api public
 */
function FeaturesList() {
	if ( ! ( this instanceof FeaturesList ) ) {
		return new FeaturesList();
	}

	this.initialized = false;
}

/**
 * Mixins
 */
Emitter( FeaturesList.prototype );

/**
 * Get list of features from current object or store,
 * trigger fetch on first request to update stale data.
 *
 * @return {Array} array of list of features
 */
FeaturesList.prototype.get = function() {
	var data;
	if ( ! this.data ) {
		debug( 'First time loading FeaturesList, check store' );
		data = store.get( 'FeaturesList' );
		if ( data ) {
			this.initialize( data );
		} else {
Example #14
0
			break;
		case 'RECEIVE_VIEWERS':
			_fetchingViewers[ action.siteId ] = false;
			// Only update users if there was not an error
			if ( ! action.error ) {
				updateViewers( action.siteId, action.data.viewers, action.page, action.data.found );
			}
			ViewersStore.emitChange();
			break;
		case 'REMOVE_VIEWER':
			_removingFromSite[ action.siteId ] = true;
			removeViewerFromSite( action.siteId, action.viewer.ID );
			ViewersStore.emitChange();
			break;
		case 'RECEIVE_REMOVE_VIEWER_SUCCESS':
			_removingFromSite[ action.siteId ] = false;
			ViewersStore.emitChange();
			break;
		case 'RECEIVE_REMOVE_VIEWER_ERROR':
			_removingFromSite[ action.siteId ] = false;
			updateViewer( action.siteId, action.viewer.ID, action.viewer );
			incrementPaginationData( action.siteId );
			ViewersStore.emitChange();
			break;
	}
} );

emitter( ViewersStore );

module.exports = ViewersStore;
Example #15
0
 * Initialize a new list of products.
 *
 * @api public
 */
function ProductsList() {
	if ( ! ( this instanceof ProductsList ) ) {
		return new ProductsList();
	}

	this.initialized = false;
}

/**
 * Mixins
 */
Emitter( ProductsList.prototype );

/**
 * Gets the list of products from current object or store, triggers fetch on first request to update stale data.
 *
 * @return {array}
 * @api public
 */
ProductsList.prototype.get = function() {
	var data;

	if ( ! this.data ) {
		debug( 'First time loading ProductsList, check store' );

		data = store.get( 'ProductsList' );
Example #16
0
var localeSuggestions = null;

var LocaleSuggestionStore = {
	get: function() {
		if ( ! localeSuggestions ) {
			LocaleSuggestionActions.fetch();
		}
		return localeSuggestions;
	},

	receiveLocaleSuggestions: function( newLocaleSuggestions ) {
		localeSuggestions = newLocaleSuggestions;
		LocaleSuggestionStore.emit( 'change' );
	}
};

Emitter( LocaleSuggestionStore );

LocaleSuggestionStore.dispatchToken = Dispatcher.register( function( payload ) {
	var action = payload.action;

	switch ( action.type ) {
		case 'RECEIVE_LOCALE_SUGGESTIONS':
			LocaleSuggestionStore.receiveLocaleSuggestions( action.data );
			break;
	}
} );

module.exports = LocaleSuggestionStore;
Example #17
0
/**
 * Internal dependencies
 */
var Dispatcher = require( 'dispatcher' ),
	emitter = require( 'lib/mixins/emitter' );

/**
 * Module variables
 */
var PostFormatsStore = {},
	_formats = {};

emitter( PostFormatsStore );

function receivePostFormats( siteId, data ) {
	_formats[ siteId ] = Object.keys( data ).map( function( slug ) {
		return {
			slug: slug,
			label: data[ slug ]
		};
	} );
}

PostFormatsStore.get = function( siteId ) {
	return _formats[ siteId ];
};

PostFormatsStore.dispatchToken = Dispatcher.register( function( payload ) {
	var action = payload.action;

	switch ( action.type ) {
Example #18
0
		} );
	}

	return tags;
};

TagStore.getQueryParams = function( siteId ) {
	ensureSiteHasStatus( siteId );
	return assign(
		{},
		TagStore._queryDefaults,
		{ page: _siteStatus[ siteId ].page }
	);
};

Emitter( TagStore );

TagStore.dispatchToken = Dispatcher.register( function( payload ) {
	var action = payload.action;

	Dispatcher.waitFor( [ TermStore.dispatchToken ] );

	switch ( action.type ) {
		case ActionTypes.FETCH_TAGS:
			if ( ! action.siteId ) {
				break;
			}

			updateSiteStatus( action.siteId, { isFetchingPage: true } );
			TagStore.emit( 'change' );
			break;
Example #19
0
		return;
	}

	// Sanity check - is the user actually subscribed to the blog?
	if ( ! PostEmailSubscriptionStore.getSubscription( blogId ) ) {
		return true;
	}

	const newSubscriptionInfo = { state: States.UNSUBSCRIBED };

	updateSubscription( blogId, newSubscriptionInfo );

	return true;
}

Emitter( PostEmailSubscriptionStore ); // eslint-disable-line

// Increase the max number of listeners from 10 to 100
PostEmailSubscriptionStore.setMaxListeners( 200 );

PostEmailSubscriptionStore.dispatchToken = Dispatcher.register( function( payload ) {
	var action = payload.action;

	if ( ! action ) {
		return;
	}

	switch ( action.type ) {
		case ActionTypes.SUBSCRIBE_TO_POST_EMAILS:
			PostEmailSubscriptionStore.receiveSubscribe( action );
			break;
Example #20
0
var SignupProgressStore = {
	get: function() {
		return clone( signupProgress );
	},
	reset: function() {
		signupProgress = [];
		store.remove( STORAGE_KEY );
	},
	getFromCache: function() {
		loadProgressFromCache();
		return this.get();
	},
};

emitter( SignupProgressStore );

function updateStep( newStep ) {
	signupProgress = map( signupProgress, function( step ) {
		if ( step.stepName === newStep.stepName ) {
			const { status } = newStep;
			if ( status === 'pending' || status === 'completed' ) {
				// Steps that are resubmitted may decide to omit the
				// `processingMessage` or `wasSkipped` status of a step if e.g.
				// the user goes back and chooses to not skip a step. If a step
				// is submitted without these, we explicitly remove them from
				// the step data.
				return assign( {}, omit( step, [ 'processingMessage', 'wasSkipped' ] ), newStep );
			}

			return assign( {}, step, newStep );
Example #21
0
		case 'RECEIVE_EMAIL_FOLLOWERS':
			namespace = getNamespace( action.fetchOptions );
			_fetchingFollowersByNamespace[ namespace ] = false;
			if ( ! action.error ) {
				updateFollowers( action.fetchOptions, action.data.subscribers, action.data.total_email );
				EmailFollowersStore.emitChange();
			}
			break;
		case 'REMOVE_EMAIL_FOLLOWER':
			_removingFromSite[ action.siteId ] = true;
			removeFollowerFromSite( action.siteId, action.follower.ID );
			EmailFollowersStore.emitChange();
			break;
		case 'RECEIVE_REMOVE_EMAIL_FOLLOWER_SUCCESS':
			_removingFromSite[ action.siteId ] = false;
			removeFollowerFromNamespaces( action.siteId, action.follower.ID );
			EmailFollowersStore.emitChange();
			break;
		case 'RECEIVE_REMOVE_EMAIL_FOLLOWER_ERROR':
			_removingFromSite[ action.siteId ] = false;
			updateFollower( action.siteId, action.follower.ID, action.follower );
			incrementPaginationData( action.siteId, action.follower.ID );
			EmailFollowersStore.emitChange();
			break;
	}
} );

emitter( EmailFollowersStore );

module.exports = EmailFollowersStore;
Example #22
0
			deleteUserFromNamespaces( action.siteId, action.user.ID );
			UsersStore.emitChange();
			break;
		case 'RECEIVE_DELETE_SITE_USER_FAILURE':
			updateUser( action.siteId, action.user.ID, action.user );
			incrementPaginationData( action.siteId, action.user.ID );
			UsersStore.emitChange();
			break;
		case 'FETCHING_USERS':
			namespace = getNamespace( action.fetchOptions );
			_fetchingUsersByNamespace[ namespace ] = true;
			UsersStore.emitChange();
			break;
		case 'RECEIVE_SINGLE_USER':
			namespace = getNamespace( action.fetchOptions );
			_fetchingUsersByNamespace[ namespace ] = false;
			addSingleUser( action.fetchOptions, action.user, namespace );
			UsersStore.emitChange();
			break;
		case 'RECEIVE_USER_FAILED':
			namespace = getNamespace( action.fetchOptions );
			_fetchingUsersByNamespace[ namespace ] = false;
			UsersStore.emitChange();
			break;
	}
} );

emitter( UsersStore );

module.exports = UsersStore;
Example #23
0
	var key;
	if ( !! event.key ) {
		return event.key;
	}
	key = event.keyIdentifier; //U+00XX
	key = key.substring( 2, key.length );
	return String.fromCharCode( parseInt( key, 16 ) );
};

KeyboardShortcuts.prototype.emitEvent = function() {
	this.emit.apply( this, arguments );
};

KeyboardShortcuts.prototype.handleKeyPress = function( event ) {
	// make sure this key press is not targeted at an input/select/textarea with keymaster's filter
	if ( keymaster.filter( event ) ) {
		this.lastKey = String.fromCharCode( event.keyCode ).toLowerCase();
		this.lastKeyTime = Date.now();
	}
};

KeyboardShortcuts.prototype.setNotificationsOpen = function( isOpen ) {
	this.isNotificationsOpen = isOpen;
};

// add EventEmitter methods to prototype
Emitter( KeyboardShortcuts.prototype );

// Return a single instance of KeyboardShortcuts, which will be cached by webpack
export default new KeyboardShortcuts( flatKeyBindings );
Example #24
0
/**
 * Internal dependencies
 */
var Dispatcher = require( 'dispatcher' ),
	emitter = require( 'lib/mixins/emitter' ),
	PreferencesConstants = require( './constants' );

/**
 * Module variables
 */
var PreferencesStore = {
	_preferences: undefined
};

emitter( PreferencesStore );

function ensurePreferencesObject() {
	if ( ! PreferencesStore._preferences ) {
		PreferencesStore._preferences = {};
	}
}

function receiveSingle( key, value ) {
	ensurePreferencesObject();

	if ( null === value ) {
		delete PreferencesStore._preferences[ key ];
	} else {
		PreferencesStore._preferences[ key ] = value;
	}
Example #25
0
	if ( ! ( this instanceof CartSynchronizer ) ) {
		return new CartSynchronizer( cartKey, wpcom );
	}

	this._cartKey = cartKey;
	this._wpcom = wpcom;
	this._latestValue = null;
	this._hasLoadedFromServer = false;
	this._activeRequest = null;
	this._queuedChanges = null;
	this._paused = false;

	this.dispatchToken = Dispatcher.register( this.handleDispatch.bind( this ) );
}

Emitter( CartSynchronizer.prototype );

CartSynchronizer.prototype.handleDispatch = function( payload ) {
	const { action } = payload;

	if ( action.type !== upgradesActionTypes.TRANSACTION_STEP_SET ) {
		return;
	}

	const { step } = action;

	if ( step.first && step.last ) {
		return;
	}

	if ( step.first ) {
Example #26
0
TwoStepAuthorization.prototype.codeValidationFailed = function() {
	return this.invalidCode;
};

TwoStepAuthorization.prototype.isSMSResendThrottled = function() {
	return this.smsResendThrottled;
};

TwoStepAuthorization.prototype.isReauthRequired = function() {
	return this.data ? this.data.two_step_reauthorization_required : false;
};

TwoStepAuthorization.prototype.authExpiresSoon = function() {
	return this.data ? this.data.two_step_authorization_expires_soon : false;
};

TwoStepAuthorization.prototype.isTwoStepSMSEnabled = function() {
	return this.data ? this.data.two_step_sms_enabled : false;
};

TwoStepAuthorization.prototype.getSMSLastFour = function() {
	return this.data ? this.data.two_step_sms_last_four : null;
};

emitter( TwoStepAuthorization.prototype );

/**
 * Expose TwoStepAuthorization
 */
module.exports = new TwoStepAuthorization();
Example #27
0
	if ( ! ( siteId in _terms ) ) {
		return;
	}

	return values( _terms[ siteId ] );
};

TermStore.get = function( siteId, termId ) {
	if ( ! ( siteId in _terms ) ) {
		return;
	}

	return clone( _terms[ siteId ][ termId ] );
};

emitter( TermStore );

TermStore.dispatchToken = Dispatcher.register( function( payload ) {
	var action = payload.action;

	switch ( action.type ) {
		case ActionTypes.RECEIVE_TERMS:
		case ActionTypes.CREATE_TERM:
		case ActionTypes.RECEIVE_ADD_TERM:

			if ( action.error || ! action.siteId || ! action.data ) {
				break;
			}

			receiveItems( action.siteId, action.data.terms );
			TermStore.emit( 'change' );
Example #28
0
	summary: function( context, next ) {
		let siteId = context.params.site_id;
		const siteFragment = route.getSiteFragment( context.path );
		const queryOptions = context.query;
		const StatsList = require( 'lib/stats/stats-list' );
		const StatsSummaryComponent = require( 'my-sites/stats/summary' );
		const filters = function( contextModule, _siteId ) {
			return [
				{ title: i18n.translate( 'Days' ), path: '/stats/' + contextModule + '/' + _siteId,
					altPaths: [ '/stats/day/' + contextModule + '/' + _siteId ], id: 'stats-day',
						period: 'day', back: '/stats/' + _siteId },
				{ title: i18n.translate( 'Weeks' ), path: '/stats/week/' + contextModule + '/' + _siteId,
					id: 'stats-week', period: 'week', back: '/stats/week/' + _siteId },
				{ title: i18n.translate( 'Months' ), path: '/stats/month/' + contextModule + '/' + _siteId,
					id: 'stats-month', period: 'month', back: '/stats/month/' + _siteId },
				{ title: i18n.translate( 'Years' ), path: '/stats/year/' + contextModule + '/' + _siteId,
					id: 'stats-year', period: 'year', back: '/stats/year/' + _siteId }
			];
		}.bind( null, context.params.module, siteId );
		let date;
		let endDate;
		let period;
		let summaryList;
		let visitsList;

		const validModules = [ 'posts', 'referrers', 'clicks', 'countryviews', 'authors', 'videoplays', 'videodetails', 'podcastdownloads', 'searchterms' ];
		let momentSiteZone = i18n.moment();
		const basePath = route.sectionify( context.path );

		let site = sites.getSite( siteId );
		if ( ! site ) {
			site = sites.getSite( parseInt( siteId, 10 ) );
		}
		siteId = site ? ( site.ID || 0 ) : 0;

		const activeFilter = find( filters(), ( filter ) => {
			return context.pathname === filter.path || ( filter.altPaths && -1 !== filter.altPaths.indexOf( context.pathname ) );
		} );

		// if we have a siteFragment, but no siteId, wait for the sites list
		if ( siteFragment && 0 === siteId ) {
			if ( 0 === sites.data.length ) {
				sites.once( 'change', function() {
					page( context.path );
				} );
			} else {
				// site is not in the user's site list
				window.location = '/stats';
			}
		} else if ( ! activeFilter || -1 === validModules.indexOf( context.params.module ) ) {
			next();
		} else {
			if ( 'object' === typeof( site.options ) && 'undefined' !== typeof( site.options.gmt_offset ) ) {
				momentSiteZone = i18n.moment().utcOffset( site.options.gmt_offset );
			}
			if ( queryOptions.startDate && i18n.moment( queryOptions.startDate ).isValid ) {
				date = i18n.moment( queryOptions.startDate );
			} else {
				date = momentSiteZone.endOf( activeFilter.period );
			}
			period = rangeOfPeriod( activeFilter.period, date );
			endDate = period.endOf.format( 'YYYY-MM-DD' );

			const siteDomain = ( site && ( typeof site.slug !== 'undefined' ) )
				? site.slug : siteFragment;
			let extraProps = {};

			// When old list summaries are transitioned to redux, we need a "fake" emitter
			// TODO when all lists are moved to redux, remove this logic
			const fakeStatsList = Emitter( {} );

			let statsQueryOptions = {};

			// All Time Summary Support
			if ( queryOptions.summarize && queryOptions.num ) {
				statsQueryOptions = pick( queryOptions, [ 'num', 'summarize' ] );
				statsQueryOptions.period = 'day';
			}

			switch ( context.params.module ) {

				case 'posts':
					summaryList = fakeStatsList;
					break;

				case 'referrers':
					summaryList = fakeStatsList;
					break;

				case 'clicks':
					summaryList = fakeStatsList;
					break;

				case 'countryviews':
					summaryList = fakeStatsList;
					break;

				case 'authors':
					summaryList = fakeStatsList;
					break;

				case 'videoplays':
					summaryList = fakeStatsList;
					break;

				case 'videodetails':
					summaryList = new StatsList( { statType: 'statsVideo', post: queryOptions.post,
						siteID: siteId, period: activeFilter.period, date: endDate, max: 0, domain: siteDomain } );
					extraProps = { postId: queryOptions.post };
					break;

				case 'searchterms':
					summaryList = fakeStatsList;
					break;

				case 'podcastdownloads':
					summaryList = new StatsList( { statType: 'statsPodcastDownloads', siteID: siteId,
						period: activeFilter.period, date: endDate, max: 0, domain: siteDomain } );
					break;
			}

			analytics.pageView.record(
				basePath,
				analyticsPageTitle + ' > ' + titlecase( activeFilter.period ) + ' > ' + titlecase( context.params.module )
			);

			renderWithReduxStore(
				React.createElement( StatsSummaryComponent, {
					date: date,
					context: context,
					path: context.pathname,
					sites: sites,
					filters: filters,
					summaryList: summaryList,
					visitsList: visitsList,
					siteId: siteId,
					period: period,
					statsQueryOptions,
					...extraProps
				} ),
				document.getElementById( 'primary' ),
				context.store
			);
		}
	},
Example #29
0
			translator.toggle();
			permanentlyDisableInvitation();
		}, { enable_translator: true }
		);
	},
	recordDocsEvent: function() {
		debug( 'docs' );
		analytics.tracks.recordEvent( 'calypso_community_translator_invitation_docsLink', analyticsProperties() );
	},
	recordInvitationDisplayed: once( function() {
		debug( 'displayed' );
		analytics.tracks.recordEvent( 'calypso_community_translator_invitation_displayed', analyticsProperties() );
	} )
};

emitter( invitationUtils );

function permanentlyDisableInvitation() {
	debug( 'disabling' );
	preferencesActions.set( 'translatorInvited', true );
	invitationPending = false;
	invitationUtils.emitChange();
	store.remove( 'calypsoTranslatorInvitationIsPending' );
}

function analyticsProperties() {
	return {
		locale: user.data.localeSlug,
	};
}
Example #30
0
var _selectedSiteID = null,
	_synchronizer = null,
	_poller = null;

var CartStore = {
	get: function() {
		var value = hasLoadedFromServer() ? _synchronizer.getLatestValue() : {};

		return assign( {}, value, {
			hasLoadedFromServer: hasLoadedFromServer(),
			hasPendingServerUpdates: hasPendingServerUpdates()
		} );
	}
};

emitter( CartStore );

function hasLoadedFromServer() {
	return ( _synchronizer && _synchronizer.hasLoadedFromServer() );
}

function hasPendingServerUpdates() {
	return ( _synchronizer && _synchronizer.hasPendingServerUpdates() );
}

function setSelectedSite() {
	var selectedSite = sites.getSelectedSite();

	if ( ! selectedSite ) {
		_selectedSiteID = null;
		return;