/** * Handle drawer init for both platforms * @method defineNavigation * @return {View} the drawer */ function defineNavigation() { var drawerOpen = function (evt) { dispatcher.trigger('menu:open'); }, drawerClose = function (evt) { dispatcher.trigger('menu:close'); }; if (OS_IOS) { WM.setActiveNavWindow($.navigationWindow); $.drawer.open(); $.drawer.addEventListener('willShowMenuViewController', drawerOpen); $.drawer.addEventListener('willHideMenuViewController', drawerClose); } else { // define menu and main content view var menu = Alloy.createController('menu'); $.drawer.leftView = menu.getView(); $.drawer.centerView = Alloy.createController('surveys').getView(); $.drawer.addEventListener('draweropen', drawerOpen); $.drawer.addEventListener('drawerclose', drawerClose); $.navigationWindow.addEventListener('android:back', function(){ Ti.API.warn(">> menu.activeItem", menu.activeItem); if(menu.getActiveItem() != 'menuItemSurveys') { dispatcher.trigger('menu:activate', 'menuItemSurveys'); navigateTo('surveys'); return false; } $.navigationWindow.close(); }); $.navigationWindow.addEventListener('open',function(){ var activity = $.navigationWindow.getActivity(); if (activity){ var actionBar = activity.getActionBar(); if (actionBar){ actionBar.title = L('surveys.welcomeTitle'); actionBar.displayHomeAsUp = true; actionBar.onHomeIconItemSelected=function(){ $.drawer.toggleLeftWindow(); } } } }) $.navigationWindow.open(); } dispatcher.on("index:navigate", function(name) { if (OS_ANDROID) { var activity = $.navigationWindow.getActivity(), actionBar = activity && activity.getActionBar(); actionBar && actionBar.setTitle(L(name === "surveys" && "surveys.welcomeTitle" || "menu." + name)); } navigateTo(name); }); dispatcher.on("drawer:open", function() { OS_IOS && $.drawer.presentLeftMenuViewController(); OS_ANDROID && $.drawer.openLeftWindow(); }); dispatcher.on("drawer:close", function() { OS_IOS && $.drawer.hideMenuViewController(); OS_ANDROID && $.drawer.closeLeftWindow(); }); }
construct: function(config) { parent = config.parent; if (config.state) { state = config.state || state; } // If flow is survey start as standalone navigation group WM.openModal($.getView(), { title: L('coordinates.title') } ); dispatcher.on('trackingLocation', closeCoordinates); },
export function dispatcherMixin(events, callback) { return { componentDidMount() { dispatcher.on(events, _.isString(callback) ? this[callback] : callback, this); }, componentWillUnmount() { dispatcher.off(null, null, this); } }; }
/** * Application startup code **/ function launchApp() { // Bind some connecting events to 'wire up' our modules proxyEvents({ // PatternGrid note trigger -> SampleBank play sound 'patterngrid:notehit': 'samplebank:playsample', // Transport control changes -> PatternGrid state changes 'transport:requestplay': 'patterngrid:play', 'transport:requeststop': 'patterngrid:stop', 'transport:tempochanged': 'patterngrid:settempo', // FilterFX node creation -> SampleBank node hookup 'filterfx:nodeupdated': 'samplebank:setfxnode' }); // Handle keypress events from KeyControls and trigger // the appropriate module events dispatcher.on('keycontrols:keypressed', function(key) { switch (key) { case 'PAUSE_RESUME': dispatcher.trigger('patterngrid:toggleplay'); break; case 'TOGGLE_FILTER': dispatcher.trigger('filterfx:changeactive'); break; case 'CLEAR': dispatcher.trigger('patterngrid:setpattern', patterns.empty); break; default: break; } }); // Init the rest of our modules, telling them // where in the DOM we want them to render. // Try commenting these out one-by-one and note // that the app will still run. Transport.init({ el: document.getElementById('top') }); PatternGrid.init({ el: document.getElementById('middle') }); FilterFX.init({ el: document.getElementById('bottom') }); KeyControls.init(); // Start with the basic drum pattern on the grid dispatcher.trigger('patterngrid:setpattern', patterns.basic); console.log('Ready'); }
/** * Utility function to proxy the parameters from a triggered * event directly into another. Allows us to easily 'wire up' * modules by creating connections from an outbound event on * one module to an inbound event on another, like a switchboard. * * @param eventsHash: object of event pairs to connect **/ function proxyEvents(eventsHash) { for (var triggerEvent in eventsHash) { var _proxy = (function(proxyEvent) { return function() { var args = Array.prototype.slice.apply(arguments); args.unshift(proxyEvent); dispatcher.trigger.apply(dispatcher, args); } })(eventsHash[triggerEvent]); dispatcher.on(triggerEvent, _proxy); } }
construct: function(config) { dispatcher.on('trackingLocation', hideMessage); checkCoordinates(); _.delay(function () { if (!checkCoordinates()) { if (config.direct) { showMessageDirect(); return; } if (OS_IOS) { showMessage(); } if (OS_ANDROID) { showMessageDirect(); } } }, 1000); },
init: function() { // Stop playback if the tab loses focus. // Our scheduling code desyncs when we're not focused, so the // drums sound ridiculous if they're left to play document.addEventListener('visibilitychange', function(e) { if (document.hidden) dispatcher.trigger('patterngrid:stop'); }, false); // When the SampleBank has loaded all its samples, fire our // main application startup code dispatcher.on('samplebank:ready', launchApp); // Init the SampleBank, passing in the paths to our samples var sampleSrcs = { 'kick': 'assets/samples/kick.wav', 'snare': 'assets/samples/snare.wav', 'openHat': 'assets/samples/openHat.wav', 'closedHat': 'assets/samples/closedHat.wav' }; SampleBank.init(sampleSrcs); }
this.model.on('sync', this.onModelSync, this); // eslint-disable-line no-sync this.defaultModel = this.props.cluster.get('vcenter_defaults'); this.defaultsJson = JSON.stringify(this.defaultModel.toJSON()); this.setState({model: this.model, defaultModel: this.defaultModel}); this.model.setModels({ cluster: this.props.cluster, settings: this.props.cluster.get('settings'), networking_parameters: this.props.cluster.get('networkConfiguration') .get('networking_parameters') }); this.onModelSync(); // eslint-disable-line no-sync dispatcher.on('vcenter_model_update', () => { if (this.isMounted()) { this.forceUpdate(); } }); }, componentWillUnmount() { this.model.off('sync', null, this); dispatcher.off('vcenter_model_update'); }, getInitialState() { return {model: null}; }, readData() { return this.model.fetch(); }, onLoadDefaults() { this.model.loadDefaults = true;