function DashboardController(userID, b){ var main = document.getElementById('main'), events = new EventManager, core = null, container = null, footer = null, loggedInAs = null, isAdmin = false, isManager = false, brand = b || new Brand({}); // TODO: set the defaults and discuss with Josh function initialize(error, d){ var v = getData(d), isLoggedIn = (!error || error != getAPIErrorMessage('notLoggedIn')); if(isLoggedIn && isDefined(v)){ var m = main; container = new Container(m, v); footer = new Footer(m, v); } else if(!isLoggedIn) window.location.href = '/login'; } function DashboardObject(){ this.dashboard = null; this.balances = null; this.profiles = null; this.users = null; } function getData(d){ var o = {}, dash = d.dashboard; for(var k in dash){ o[k] = dash[k]; } o.balances = d.balances; o.profiles = d.profiles; o.user = d.users; return o; } function getAPIData(id, fn){ new ApiManager(new DashboardObject, id, fn); } function switchUser(id, cb){ getAPIData(id, function(e, d) { update(e, d); core.setSwitchCallback(cb); }); if(isDefined(id) && id !== '' && id !== userID){ setLIA(id); } else { unsetLIA(); } } function resetUser(){ switchUser(userID); } function setLIA(id){ if(!isDefined(loggedInAs)){ loggedInAs = new LoggedInAsNotification(id, core.isAdmin, resetUser); } else { loggedInAs.update(id); } } function unsetLIA(){ if(loggedInAs) loggedInAs.exit(); loggedInAs = null; } function update(error, d, cb){ var data = getData(d); container.update(data); pop('Pop!', 'Dashboard - Index', '/dashboard'); if(core.userType === 'advertiser') core.shoppingCart.changeUid(core.userID); } var Container = function(main, data){ var element = main.querySelector('container'), events = new EventManager, containerObj = null, switchCallback = null; this.update = update; function init(d){ core = new Core(d); containerObj = new ContainerObj(data); core.search = new Search(); } function Core(d){ this.route = null; this.db = null; this.alerts = null; this.cookies = new CookieManager({ 'domain' : '.' + getCurrentHost() }); this.agencyID = (!!d.user && !!d.user.agencyID) ? d.user.agencyID : ''; this.userID = userID; this.userEmail = isDefined(d.profiles.email) ? d.profiles.email : ''; this.brand = new Brand(brand); this.userType = isDefined(d.user) ? d.user.type : null; if(this.userType === 'admin' || this.userType === 'manager') { isAdmin = true; } if(this.userType === 'manager') { isManager = true } this.isAdmin = isAdmin; this.isManager = isManager; this.targetAccount = d.user.targetAccount; this.notifications = new NoficationManager(main); this.refreshSideNavigation = null; this.refreshRouter = null; this.switchUser = switchUser.bind(this); if (isAdmin) { window.switchUser = this.switchUser; } this.resetUser = resetUser; this.search = null; this.db = psStore(); this.shoppingCart = shoppingCart(this.db, main, this.userType === 'advertiser' ? userID : null, this.notifications); this.setSwitchCallback = function(cb) { switchCallback = cb; }; this.switchUserCallback = function() { if(!!switchCallback) setTimeout(switchCallback, 50); switchCallback = null; }; window.core = this; } function ContainerObj(d){ var t = d.content; t.sideNavigation.brand = brand; this.content = new Content(element, d); this.sideNavigation = new SideNavigation(element, t.sideNavigation); } function update(d){ core.agencyID = d.user.agencyID; core.userID = d.user.id; core.userEmail = isDefined(d.profiles.email) ? d.profiles.email : ''; core.userType = d.user.type; core.targetAccount = d.user.targetAccount; core.refreshSideNavigation(d.content.sideNavigation); containerObj.content.update(d); core.search.update(); } var Content = function(target, data){ var element = getElement(), name = data.profiles.company === 'Meteora' && core.brand.name != 'Meteora' ? core.brand.name : data.profiles.company, breadcrumbs = new Breadcrumbs(element, data, name), router = new Router(core, element, data, breadcrumbs), alerts = new AlertsManager(target); this.update = update; core.alerts = alerts; router.refresh(); target.appendChild(element); function update(d){ router.setRoutes(d.routing); breadcrumbs.setName(d.profiles.company); } function getElement(){ return document.createElement('content'); } }; var SideNavigation = function(target, data){ target = target.querySelector('content'); var template = null, branding = getBranding(data), sections = null, element = null; refresh(data); core.refreshSideNavigation = refresh; this.sections = sections; this.element = element; function Section(d){ this.title = d.title; this.rows = getRows(d.rows); } function Row(d){ this.label = d.label; this.create = d.create; this.href = d.href; } function getTemplate(){ var logo = '', topSection = '', searchSection = ''; rowLabel = '{{ label }}', rowCreate = '{{# create }}Create{{/ create }}', rows = '{{# rows }}' + rowLabel + rowCreate + '{{/ rows }}', footer = ''; return '' + topSection + searchSection + '{{# sections }}

{{ title }}

' + rows + '
{{/ sections }}' + footer + '
'; } function getSections(d){ var a = []; for(var i=0, l=d.length; i' + bc + ''; return bc; }); } function buildHandlers() { forEach(element.querySelectorAll('a'), function(a) { a.addEventListener('click', popAnchor); }); } }; var Router = function(core, target, data, breadcrumbs){ var o = data.routing, template = getLoadingTemplate(), pending = null, pendingLoc = null, pendingT = null, current = null, currentLoc = null, notifications = core.notifications; this.refresh = refresh; this.setRoutes = setRoutes; window.onpopstate = history.onpushstate = function(){ setTimeout(refresh, 1); }; function refresh(s){ var loc = s || document.location.pathname.replace('/dashboard', ''); if(loc != currentLoc) initController(loc, o[loc]); } function getLoadingTemplate(){ return '

Scotty is currently beaming up... Please wait while we gather your data.

'; } function initController(loc, t, o){ if(t) setPending(t, loc, null); else if(!isWildcard(loc)) refresh('/404'); core.switchUserCallback(); } function setRoutes(d){ o = d; } function setPending(t, s, wcv){ if(isDefined(pending) && isDefined(pending.exit)) pending.exit(); notifications.setLoading(); pendingLoc = s; pendingT = t; pending = window[t.controller](core, target, data, delayedUpdate, wcv); } function isWildcard(s){ var lio = s.lastIndexOf('/') + 1, k = s.substring(0, lio) + '*', wcv = s.substring(lio), t = o[k]; if(!isDefined(t)) return false; else { setPending(t, s, wcv); return true; } } function delayedUpdate(){ setTimeout(update, 1); } function update(loc, t){ exitCheck(); updateCurrent(t); notifications.setSuccess('Load success!'); } function updateCurrent(t){ if(isDefined(pendingT)){ var t = pendingT; currentLoc = pendingLoc; current = pending; pendingLoc = null; pending = null; pendingT = null; breadcrumbs.update(t.breadcrumbs); if(isDefined(current)){ core.search.setTarget(current.search); } if(!current || current.hasCart !== true){ core.shoppingCart.hide(); } } } function exitCheck(){ if(isDefined(current) && current.exit) current.exit(); } }; var Search = function(){ var events = new EventManager(), ns = document.getElementById('navSearch'), t = getSearch(), state = true, targetFn = null; this.setTarget = setTarget; this.update = update; refresh(); bindSearch(); function setTarget(fn){ targetFn = fn; refresh(); } function refresh(){ if(isFunction(targetFn)){ show(); } else { hide(); } } function update(){ events.reset(); t = getSearch(); bindSearch(); } function bindSearch(){ events.add(t, 'keyup', cb); } function show(){ if(state){ return; } ns.classList.remove('noDisplay'); state = true; } function hide(){ if(!state){ return; } ns.classList.add('noDisplay'); state = false; } function getSearch(){ ns = document.getElementById('navSearch'); if(ns === null){ return null; } return ns.querySelector('input'); } function cb(e){ if(!state){ return; } targetFn(e); } }; if(element) init(data); }; var Footer = function(main, data){ this.update = update; var element = main.querySelector('footer'); function update(){} }; var NoficationManager = function(target){ var notification = new Notification(target, '
', { 'data' : {}, 'id' : 'loading', 'cssTransition' : 'linearShort' }, unset), loadingStd = 'Scotty is currently beaming up... Please wait while we gather your data.', element = notification.getElement(), content = element.querySelector('div'), templates = new Templates, state = false, closeDuration = 6000, freshDuration = 1200, closeTimeout = null, freshTimeout = null, isFresh = false, queue = null; this.setLoading = setLoading; this.setSuccess = setSuccess; this.setMissingFields = setMissingFields/*Cookies*/; this.setError = setError; this.setErrors = setErrors; this.unset = unset; function loading(message){ standardUpdate('loading', message || loadingStd); } function success(message){ standardUpdate('success', message); setCloseTimer(); setFresh(); } function missingFields(array){ standardUpdate('missingFields', array); setCloseTimer(); setFresh(); } function error(message){ standardUpdate('error', message); setCloseTimer(); setFresh(); } function errors(array){ standardUpdate('errors', array); setCloseTimer(); setFresh(); } function standardUpdate(templateKey, data){ clearCloseTimer(); content.innerHTML = render(templates[templateKey], data); open(); setFresh(); } function getQueueClosure(fn, m){ return function(fn, m){ return function(){ fn(m); }; }(fn, m); } function setLoading(message){ if(isFresh === false) loading(message); else queue = loading; } function setSuccess(message){ if(isFresh === false) success(message); else queue = getQueueClosure(success, message); } function setError(message){ if(isFresh === false) error(message); else queue = getQueueClosure(error, message); } function setErrors(array){ if(isFresh === false){ // Do stuff errors(array); return; } queue = getQueueClosure(errors, array); } function setMissingFields(array){ if(isFresh === false) missingFields(array); else queue = getQueueClosure(missingFields, array); } function setFresh(){ isFresh = true; setFreshTimer(); } function setCloseTimer(){ clearCloseTimer(); closeTimeout = setTimeout(close, closeDuration); } function setFreshTimer(){ clearFreshTimer(); freshTimeout = setTimeout(unsetFresh, freshDuration); } function unset(){ close(); } function unsetFresh(){ isFresh = false; if(isDefined(queue)) queue(); queue = null; } function clearCloseTimer(){ if(closeTimeout != null){ clearTimeout(closeTimeout); closeTimeout = null; } } function clearFreshTimer(){ if(freshTimeout != null){ clearTimeout(freshTimeout); freshTimeout = null; } } function open(){ if(state === false){ clearCloseTimer(); state = true; element.className = 'active'; } } function close(){ if(state === true){ state = false; element.className = ''; } } function Templates(){ this.loading = '

{{ . }}

'; this.success = '

{{ . }}

'; this.missingFields = '

Please complete the required fields

'; this.error = '

{{ . }}

'; this.errors = '

The following errors occurred

'; } }; var AlertsManager = function(target){ var themes = { 'standard' : { 'spanColor' : 'mist', 'buttonColor' : 'royal' }, 'danger' : { 'spanColor' : 'hot', 'buttonColor' : 'hot' }, 'cool' : { 'spanColor' : 'mist', 'buttonColor' : 'mist' }, 'bright' : { 'spanColor' : 'fresh', 'buttonColor' : 'fresh' } }; this.alert = alert; function loading(){ return new loadingController(); } function setActive(t){ t.classList.add('active'); } function unsetActive(t){ t.classList.remove('active'); } function alert(target, template, theme, data){ var th = themes[theme], o = { 'data' : data || {} }; o.data.spanColor = th.spanColor; o.data.buttonColor = th.buttonColor; var a = new Alert(target, template, o); if(isDefined(data) && isDefined(data.highlight)){ var hL = data.highlight, l = hL.length, p = target.querySelector('p'), h = p.innerHTML, s = h.indexOf(hL), e = l + s, n = h.substring(0, s) + '' + h.substring(s, e) + '' + h.substring(e); p.innerHTML = n; } } }; function closeShop(){ main = null; header = null; container = null; footer = null; } if(main) getAPIData(userID, initialize); } var cntrl = new Controllers; function index(core, e, data, returnCB){ return new Index(core, e, data, returnCB); } function logout(core, e, data, returnCB){ return new Logout(core, e, data, returnCB); } function gettingStarted(core, e, data, returnCB){ return cntrl.gettingStarted(core, e, data, returnCB); } function ads(core, e, data, returnCB){ return new Ads(core, e, data, returnCB); } function advertisers(core, e, data, returnCB){ return new Advertisers(core, e, data, returnCB); } function agencies(core, e, data, returnCB){ return new Agencies(core, e, data, returnCB); } function campaigns(core, e, data, returnCB){ return cntrl.campaigns(core, e, data, returnCB); } function segments(core, e, data, returnCB){ return new Segments(core, e, data, returnCB); } function adGroups(core, e, data, returnCB){ return new AdGroups(core, e, data, returnCB); } function domainLists(core, e, data, returnCB){ return new DomainLists(core, e, data, returnCB); } function managers(core, e, data, returnCB, wcv){ return new Managers(core, e, data, returnCB, wcv); } function developers(core, e, data, returnCB, wcv){ return new Developers(core, e, data, returnCB, wcv); } function apps(core, e, data, returnCB, wcv){ return new Apps(core, e, data, returnCB, wcv); } function manageCampaign(core, e, data, returnCB, wcv){ return cntrl.manageCampaign(core, e, data, returnCB, false, wcv); } function manageTemplateCampaign(core, e, data, returnCB, wcv){ return cntrl.manageCampaign(core, e, data, returnCB, true, wcv); } function manageCampaignDraft(core, e, data, returnCB, wcv){ return cntrl.manageCampaign(core, e, data, returnCB, false, null, wcv); } function manageSegment(core, e, data, returnCB, wcv){ return new ManageSegment(core, e, data, returnCB, wcv); } function manageProximitySegment(core, e, data, returnCB, wcv){ return cntrl.manageProximitySegment(core, e, data, returnCB, wcv); } function manageStoreSegment(core, e, data, returnCB, wcv){ return cntrl.manageStoreSegment(core, e, data, returnCB, wcv); } function manageStores(core, e, data, returnCB, wcv){ return new cntrl.manageStores(core, e, data, returnCB, wcv); } function manageEvegment(core, e, data, returnCB, wcv){ return new ManageEvegment(core, e, data, returnCB, wcv); } function manageIFASegment(core, e, data, returnCB, wcv){ return new cntrl.manageIFASegment(core, e, data, returnCB, wcv); } function manageAdvertiser(core, e, data, returnCB, wcv){ return new ManageAdvertiser(core, e, data, returnCB, wcv); } function manageAgency(core, e, data, returnCB, wcv){ return new ManageAgency(core, e, data, returnCB, wcv); } function manageManager(core, e, data, returnCB, wcv){ return new ManageManager(core, e, data, returnCB, wcv); } function manageDeveloper(core, e, data, returnCB, wcv){ return new ManageDeveloper(core, e, data, returnCB, wcv); } function manageApps(core, e, data, returnCB, wcv){ return new ManageApps(core, e, data, returnCB, wcv); } function viewProximitySegment(core, e, data, returnCB, wcv){ return cntrl.viewProximitySegment(core, e, data, returnCB, wcv); } function proximityForecast(core, e, data, returnCB, wcv){ return new cntrl.proximityForecast(core, e, data, returnCB, wcv); } function createTemplate(core, e, data, returnCB, wcv){ return new ManageTemplate(core, e, data, returnCB, null, wcv); } function editTemplate(core, e, data, returnCB, wcv){ return new ManageTemplate(core, e, data, returnCB, wcv, null); } function editProfile(core, e, data, returnCB){ return new EditProfile(core, e, data, returnCB); } function editMedia(core, e, data, returnCB){ return new EditMedia(core, e, data, returnCB); } function editAppMedia(core, e, data, returnCB, wcv){ return new EditMedia(core, e, data, returnCB, wcv); } function dailyStats(core, e, data, returnCB){ return cntrl.dailyStats(core, e, returnCB); } function billingHistory(core, e, data, returnCB){ return cntrl.billingHistory(core, e, returnCB); } function editBilling(core, e, data, returnCB){ return cntrl.editBilling(core, e, returnCB); } function pixels(core, e, data, returnCB){ return new Pixels(core, e, data, returnCB); } function uploadBannerAds(core, e, data, returnCB){ return new UploadBannerAds(core, e, data, returnCB); } function uploadNativeAds(core, e, data, returnCB){ return new UploadNativeAds(core, e, data, returnCB); } function uploadThirdPartyAds(core, e, data, returnCB){ return new UploadThirdPartyAds(core, e, data, returnCB); } function createProductAds(core, e, data, returnCB){ return new CreateProductAds(core, e, data, returnCB); } function createTextAds(core, e, data, returnCB){ return new CreateTextAds(core, e, data, returnCB); } function createDynamicAds(core, e, data, returnCB){ return new CreateDynamicAds(core, e, data, returnCB); } function reporting(core, e, data, returnCB){ return new Reporting(core, e, data, returnCB); } function adminReporting(core, e, data, returnCB){ return new AdminReporting(core, e, data, returnCB); } function agencyReporting(core, e, data, returnCB){ return cntrl.agencyReporting(core, e, data, returnCB, null); } function selectAdType(core, e, data, returnCB){ return new SelectAdType(core, e, data, returnCB); } function pagesAgency(core, e, data, returnCB, wcv){ return new Pages(core, e, data, returnCB, 'agency', wcv); } function pagesTemplate(core, e, data, returnCB, wcv){ return new Pages(core, e, data, returnCB, 'template', wcv); } function pagesApplication(core, e, data, returnCB, wcv){ return new Pages(core, e, data, returnCB, 'application', wcv); } function appsList(core, e, data, returnCB){ return new MissionControlList(core, e, data, returnCB, 'apps'); } function campaignTmplsList(core, e, data, returnCB){ return new MissionControlList(core, e, data, returnCB, 'tmpls'); } function agenciesList(core, e, data, returnCB){ return new MissionControlList(core, e, data, returnCB, 'agencies'); } function heatmapsController(core, e, data, returnCB){ return cntrl.heatmaps(core, e, returnCB); } function downloads(core, e, data, returnCB){ return cntrl.downloads(core, e, data, returnCB); } function fourOhFour(core, e, data, returnCB){ returnCB(); } $aa.ready.push(DashboardController); /* _,add8ba, ,d888888888b, d8888888888888b _,ad8ba,_ d888888888888888) ,d888888888b, I8888888888888888 _________ ,8888888888888b __________`Y88888888888888P"""""""""""baaa,__ ,888888888888888, ,adP"""""""""""9888888888P""^ ^""Y8888888888888888I ,a8"^ ,d888P"888P^ ^"Y8888888888P' ,a8^ ,d8888' ^Y8888888P' a88' ,d8888P' I88P"^ ,d88' d88888P' "b, ,d88' d888888' `b, ,d88' d888888I `b, d88I ,8888888' ___ `b, ,888' d8888888 ,d88888b, ____ `b, d888 ,8888888I d88888888b, ,d8888b, `b ,8888 I8888888I d8888888888I ,88888888b 8, I8888 88888888b d88888888888' 8888888888b 8I d8886 888888888 Y888888888P' Y8888888888, ,8b 88888b I88888888b `Y8888888^ `Y888888888I d88, Y88888b `888888888b, `""""^ `Y8888888P' d888I `888888b 88888888888b, `Y8888P^ d88888 Y888888b ,8888888888888ba,_ _______ `""^ ,d888888 I8888888b, ,888888888888888888ba,_ d88888888b ,ad8888888I `888888888b, I8888888888888888888888b, ^"Y888P"^ ____.,ad88888888888I 88888888888b,`888888888888888888888888b, "" ad888888888888888888888' 8888888888888698888888888888888888888888b_,ad88ba,_,d88888888888888888888888 88888888888888888888888888888888888888888b,`"""^ d8888888888888888888888888I 8888888888888888888888888888888888888888888baaad888888888888888888888888888' Y8888888888888888888888888888888888888888888888888888888888888888888888888P I888888888888888888888888888888888888888888888P^ ^Y8888888888888888888888' `Y88888888888888888P88888888888888888888888888' ^88888888888888888888I `Y8888888888888888 `8888888888888888888888888 8888888888888888888P' `Y888888888888888 `888888888888888888888888, ,888888888888888888P' `Y88888888888888b `88888888888888888888888I I888888888888888888' "Y8888888888888b `8888888888888888888888I I88888888888888888' "Y88888888888P `888888888888888888888b d8888888888888888' ^""""""""^ `Y88888888888888888888, 888888888888888P' "8888888888888888888b, Y888888888888P^ `Y888888888888888888b `Y8888888P"^ "Y8888888888888888P `""""^ `"YY88888888888P' ^""""""""' */