imports/vx/client/code/vxapp.js
/**
     * Perform a variety of functions immediately when the route changes.
     */
Perform a variety of functions immediately when the route changes.
Perform a variety of functions immediately when the route changes .
routeBefore() {
        OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] *fire*`)
        if (VXApp.isExemptRoute()) {
            return
        }
        let userId = Meteor.userId()
        if (!userId) {
            OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] user is not logged in`)
            return
        }
        let email = Util.getUserEmail(userId)
        if (!email) {
            OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] userId=${userId} subscription is not yet ready`)
            return
        }
        UX.unregisterIosButtonDelegates()
        let tenantId = Util.getCurrentTenantId(userId)
        let domainId = Util.getCurrentDomainId(userId)
        let currentDomainId = Store.getState().currentDomainId
        let publishingMode = VXApp.getPublishingMode(tenantId, domainId, "client", userId)
        let currentPublishingMode = Store.getState().currentPublishingMode
        if (domainId !== currentDomainId || publishingMode !== currentPublishingMode) {
            OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] *before* email=${email} detected domain or publishing mode change:` +
                ` domain=${Util.fetchDomainName(domainId)} mode=${publishingMode} *clearing* session variables`)
            Store.dispatch(setPublishCurrentTenant({ criteria: { _id: tenantId } }))
            Store.dispatch(setPublishCurrentDomain({ criteria: { _id: domainId } }))
            Store.dispatch(setPublishAuthoringUser(null))
            Store.dispatch(setPublishAuthoringDomain(null))
            Store.dispatch(setCurrentDomainId(domainId))
            Store.dispatch(setCurrentPublishingMode(publishingMode))
            VXApp.setSessionVariables(userId)
        }
        let currentUserId = Store.getState().currentUserId
        if (userId !== currentUserId) {
            if (email && domainId) {
                OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] *before* email=${email} domain ${Util.fetchDomainName(domainId)}`)
                Store.dispatch(setCurrentUserId(userId))
                let currentLocale = Util.getProfileValue("locale")
                Store.dispatch(setCurrentLocale(currentLocale))
                OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] *before* email=${email} i18n currentLocale=${currentLocale}`)
                if (!Util.getProfileValue("timezone", userId)) {
                    let detectedTimezone = TimezonePicker.detectedZone()
                    OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] *before* email=${email} setting user profile timezone=${detectedTimezone}`)
                    Meteor.users.update(userId, { $set: { "profile.timezone": detectedTimezone } })
                }
                VXApp.setSessionVariables(userId)
            }
            else {
                OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] *before* email=${email} *notready* userId=${userId} waiting for email and domain`)
            }
        }
        else {
            OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] *before* email=${email} *matching* userId=${userId} currentUserId=${currentUserId}`)
        }
        if (Util.routePath() && UXState.previousBefore === Util.routePath()) {
            OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] *before* email=${email} route is unchanged from previous=${UXState.previousBefore} before action will be suppressed`)
            return
        }
        UXState.previousBefore = Util.routePath()
        OLog.debug(`vxapp.js routeBefore [${Util.routePath()}] invoking doRouteBefore`)
        Routes.doRouteBefore()
    }
routeBefore ( ) { OLog . debug ( ` ${ Util . routePath ( ) } ` ) if ( VXApp . isExemptRoute ( ) ) { return } let userId = Meteor . userId ( ) if ( ! userId ) { OLog . debug ( ` ${ Util . routePath ( ) } ` ) return } let email = Util . getUserEmail ( userId ) if ( ! email ) { OLog . debug ( ` ${ Util . routePath ( ) } ${ userId } ` ) return } UX . unregisterIosButtonDelegates ( ) let tenantId = Util . getCurrentTenantId ( userId ) let domainId = Util . getCurrentDomainId ( userId ) let currentDomainId = Store . getState ( ) . currentDomainId let publishingMode = VXApp . getPublishingMode ( tenantId , domainId , "client" , userId ) let currentPublishingMode = Store . getState ( ) . currentPublishingMode if ( domainId !== currentDomainId || publishingMode !== currentPublishingMode ) { OLog . debug ( ` ${ Util . routePath ( ) } ${ email } ` + ` ${ Util . fetchDomainName ( domainId ) } ${ publishingMode } ` ) Store . dispatch ( setPublishCurrentTenant ( { criteria : { _id : tenantId } } ) ) Store . dispatch ( setPublishCurrentDomain ( { criteria : { _id : domainId } } ) ) Store . dispatch ( setPublishAuthoringUser ( null ) ) Store . dispatch ( setPublishAuthoringDomain ( null ) ) Store . dispatch ( setCurrentDomainId ( domainId ) ) Store . dispatch ( setCurrentPublishingMode ( publishingMode ) ) VXApp . setSessionVariables ( userId ) } let currentUserId = Store . getState ( ) . currentUserId if ( userId !== currentUserId ) { if ( email && domainId ) { OLog . debug ( ` ${ Util . routePath ( ) } ${ email } ${ Util . fetchDomainName ( domainId ) } ` ) Store . dispatch ( setCurrentUserId ( userId ) ) let currentLocale = Util . getProfileValue ( "locale" ) Store . dispatch ( setCurrentLocale ( currentLocale ) ) OLog . debug ( ` ${ Util . routePath ( ) } ${ email } ${ currentLocale } ` ) if ( ! Util . getProfileValue ( "timezone" , userId ) ) { let detectedTimezone = TimezonePicker . detectedZone ( ) OLog . debug ( ` ${ Util . routePath ( ) } ${ email } ${ detectedTimezone } ` ) Meteor . users . update ( userId , { $set : { "profile.timezone" : detectedTimezone } } ) } VXApp . setSessionVariables ( userId ) } else { OLog . debug ( ` ${ Util . routePath ( ) } ${ email } ${ userId } ` ) } } else { OLog . debug ( ` ${ Util . routePath ( ) } ${ email } ${ userId } ${ currentUserId } ` ) } if ( Util . routePath ( ) && UXState . previousBefore === Util . routePath ( ) ) { OLog . debug ( ` ${ Util . routePath ( ) } ${ email } ${ UXState . previousBefore } ` ) return } UXState . previousBefore = Util . routePath ( ) OLog . debug ( ` ${ Util . routePath ( ) } ` ) Routes . doRouteBefore ( ) }
Perform a variety of functions immediately when the route changes.
Perform a variety of functions immediately when the route changes .
// Set the user's default timezone if it hasn't already been established: // Set session variables that piggy back on existing subscriptions: