Created
July 12, 2012 17:40
-
-
Save egomez99/3099564 to your computer and use it in GitHub Desktop.
Core App module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ti.UI.setBackgroundColor("#eee"); | |
// Boot the app | |
require('core').init(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Main app control / singleton | |
*/ | |
// Module dependencies if any here | |
/** | |
* Main app singleton | |
* @type {Object} | |
*/ | |
var APP = { | |
/** | |
* Sets up the app singleton and all it's child dependencies | |
* NOTE: This should only be fired in app.js file and only once. | |
*/ | |
init: function() { | |
// Setup constants | |
APP.DEBUG_MODE = true; | |
APP.VERSION = "0.0.1"; | |
// Setup lib dependancies (so we only have to require just this module, not all these in every file) | |
APP.HTTP = require('modules/lib/http'); | |
APP.Platform = require('modules/lib/platform'); | |
// Global system Events | |
Ti.Gesture.addEventListener('orientationchange', APP.orientationObserverUpdate); | |
Ti.Network.addEventListener('change', APP.networkObserverUpdate); | |
Ti.App.addEventListener("pause", APP.exit); | |
Ti.App.addEventListener("close", APP.exit); | |
Ti.App.addEventListener("resumed", APP.resume); | |
/** | |
* Entry point logic for app here | |
*/ | |
APP.masterWindow.open(); | |
// We'll just open the user screen for now | |
var UsersController = require('app/controllers/users'); | |
APP.currentScreen = new UsersController(); | |
APP.masterWindow.add( APP.currentScreen.UI.wrapper ); | |
}, | |
/** | |
* The main app window | |
* @type {Object} | |
*/ | |
masterWindow: Ti.UI.createWindow(), | |
/** | |
* Keeps track of the current screen | |
* @type {Object} | |
*/ | |
currentScreen: null, | |
/** | |
* Sets the current orientation of the device constant | |
* @type {String} | |
*/ | |
currentOrientation: (Ti.Gesture.orientation == Ti.UI.LANDSCAPE_LEFT || Ti.Gesture.orientation == Ti.UI.LANDSCAPE_RIGHT) ? 'landscape' : 'portrait', | |
/** | |
* Global orientation event handler | |
* @param {Object} e Standard Ti callback | |
*/ | |
orientationObserverUpdate: function(e) { | |
// Shortcut for current orientation | |
var type = (e.orientation == Ti.UI.LANDSCAPE_LEFT || e.orientation == Ti.UI.LANDSCAPE_RIGHT) ? 'landscape' : 'portrait'; | |
// Make sure it's a different orientation before proceeding | |
if (APP.currentOrientation != type){ | |
// If it's an undesired orientation, just ignore | |
if (e.orientation == Ti.UI.FACE_UP || e.orientation == Ti.UI.FACE_DOWN || e.orientation == Ti.UI.UNKNOWN ) return; | |
//Saves the current orientation | |
APP.currentOrientation = type; | |
// First check if controller has an orientation update (will always take precedence) | |
if(APP.currentScreen && APP.currentScreen.orientationUpdate){ | |
APP.currentScreen.orientationUpdate(type); | |
// Otherwise check if the UI of this controller has an orientation update | |
} else if(APP.currentScreen && APP.currentScreen.UI.orientationUpdate) { | |
APP.currentScreen.UI.orientationUpdate(type); | |
} | |
} | |
}, | |
/** | |
* Global network event handler | |
* @param {Object} _event Standard Ti callback | |
*/ | |
networkObserverUpdate: function(_event) {}, | |
/** | |
* Exit event observer | |
*/ | |
exit: function() {}, | |
/** | |
* Resume event observer | |
*/ | |
resume: function() {} | |
}; | |
module.exports = APP; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Module dependencies | |
var APP = require('core'); | |
/** | |
* Users UI Module | |
* @constructor | |
*/ | |
function UsersUI() { | |
var self = this; | |
/** | |
* Add users to screen | |
* @param {Array} _data | |
* @example | |
* [{ | |
* name: , | |
* id: | |
* }] | |
*/ | |
this.addUsers = function(_data) { | |
var rows = []; | |
for (var i = 0, lgt = _data.length; i < lgt; i++) { | |
rows.push({ title: _data[i].name, id: _data[i].id }); | |
}; | |
self.wrapper.setData( rows ); | |
}; | |
/** | |
* The main view for this screen | |
* @type {Object} | |
*/ | |
this.wrapper = Ti.UI.createTableView({ | |
data: [{ title: 'Loading rows...' }] | |
}); | |
} | |
module.exports = UsersUI; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment