Browse files

Inital commit

  • Loading branch information...
0 parents commit 2b84b662f450d65360c591dcc2a92bc2d7127dc3 @wilblack committed Oct 27, 2011
Showing with 247 additions and 0 deletions.
  1. BIN .DS_Store
  2. +1 −0 .gitignore
  3. BIN KS_nav_ui.png
  4. BIN KS_nav_views.png
  5. +113 −0 account.js
  6. +53 −0 app.js
  7. +73 −0 features.js
  8. +7 −0 utils.js
BIN .DS_Store
Binary file not shown.
1 .gitignore
@@ -0,0 +1 @@
+android/*
BIN KS_nav_ui.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN KS_nav_views.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 account.js
@@ -0,0 +1,113 @@
+/**
+ * @author Wil Black
+ */
+
+var Account = {};
+
+// Attributes
+Account.first_name ='';
+Account.last_name = '';
+Account.src = 'http://theopenforest.com/api/v1/author/?format=json&';
+Account.username = '';
+Account.loginWindow = null;
+Account.data = [];
+Account.create_db = function(){
+
+};
+
+// Methods
+Account.get_by_username = function(username) {
+
+ var xhr = Ti.Network.createHTTPClient();
+ var qs = "username="+username+"&";
+ _log(qs);
+ xhr.open("GET",Account.src+qs);
+ xhr.onload = function() {
+ rs = eval('('+this.responseText+')');
+ Account.data = rs.objects[0];
+ _log(Account.data.name);
+
+ var acctLabel = Titanium.UI.createLabel({
+ text:"Welcome "+Account.data.name
+ });
+ scrolly.add(acctLabel);
+ Feature.get_by_pid(Account.data.id);
+ };
+ xhr.send();
+};
+
+//Views
+Account.loginWindow = Titanium.UI.createWindow();
+ // initialize to all modes
+Account.loginWindow.orientationModes = [
+ Titanium.UI.PORTRAIT,
+ Titanium.UI.LANDSCAPE_LEFT,
+ Titanium.UI.LANDSCAPE_RIGHT
+];
+
+var scrolly = Titanium.UI.createScrollView({contentHeight:'auto'});
+Account.loginWindow.add(scrolly);
+
+var tf_username = Titanium.UI.createTextField({
+ color:'#336699',
+ height:35,
+ top:10,
+ left:10,
+ width:250,
+ borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
+});
+
+scrolly.add(tf_username);
+
+var l = Titanium.UI.createLabel({
+ top:50,
+ left:10,
+ width:300,
+ height:'auto',
+ color:'#777',
+ font:{fontSize:13},
+ text:'do something like click a button...'
+});
+scrolly.add(l);
+
+//
+// TEXT FIELD EVENTS (return, focus, blur, change)
+//
+tf_username.addEventListener('return',function(e)
+{
+ l.text = 'return received, val = ' + e.value;
+ tf_username.blur();
+});
+
+scrolly.add(tf_username);
+
+//
+// FOCUS
+//
+var focusLabel = Titanium.UI.createButton({
+ top:100,
+ height:60,
+ width:200,
+ title:'Submit'
+});
+scrolly.add(focusLabel);
+focusLabel.addEventListener('click', function()
+{
+ var username = tf_username.value;
+ Account.username = username;
+
+ // Create a notification
+ var n = Ti.UI.createNotification({message:Account.username});
+ n.duration = Ti.UI.NOTIFICATION_DURATION_LONG;
+ n.show();
+
+ rs = Account.get_by_username(username);
+});
+
+
+
+
+
+
+
+
53 app.js
@@ -0,0 +1,53 @@
+// this sets the background color of the master UIView (when there are no windows/tab groups on it)
+Ti.include('utils.js');
+Ti.include('features.js');
+Ti.include('account.js');
+Titanium.UI.setBackgroundColor('#000');
+
+
+// create tab group
+var tabGroup = Titanium.UI.createTabGroup();
+//
+// create base UI tab and root window
+//
+var win1 = Titanium.UI.createWindow({
+ title:'Tab 1',
+ backgroundColor:'#fff'
+});
+var tab1 = Titanium.UI.createTab({
+ icon:'KS_nav_views.png',
+ title:'Tab 1',
+ window:win1
+});
+
+Feature.get();
+featureList = Feature.tableView;
+win1.add(featureList);
+
+//
+// create controls tab and root window
+//
+//var win2 = Titanium.UI.createWindow({
+// title:'Tab 2',
+// backgroundColor:'#fff'
+//});
+var win2 = Account.loginWindow;
+
+var tab2 = Titanium.UI.createTab({
+ icon:'KS_nav_ui.png',
+ title:'Account',
+ window:win2
+});
+
+//win2.add(label2);
+
+//
+// add tabs
+//
+tabGroup.addTab(tab1);
+tabGroup.addTab(tab2);
+
+// open tab group
+tabGroup.open();
+
+
73 features.js
@@ -0,0 +1,73 @@
+var Feature = {};
+Feature.tableView = null;
+Feature.src = "http://theopenforest.com/api/v1/feature/?format=json&";
+Feature.features=[]
+
+Feature.get = function() {
+
+ var xhr = Ti.Network.createHTTPClient();
+ xhr.open("GET",Feature.src);
+ xhr.onload = function() {
+ rs = eval('('+this.responseText+')');
+ Feature.features = rs.objects
+ Feature.updateTable();
+
+ };
+ xhr.send();
+
+ // This needs to be here to create the tableView before the GET request returns
+ Feature.updateTable();
+
+};
+
+Feature.get_by_pid = function(pid){
+ var xhr = Ti.Network.createHTTPClient();
+ var qs = Feature.src+"author="+pid+"&";
+ _log(qs);
+ xhr.open("GET",qs);
+ xhr.onload = function() {
+ rs = eval('('+this.responseText+')');
+ Feature.features = rs.objects;
+ Feature.updateTable();
+ };
+ xhr.send();
+}
+
+Feature.updateTable = function(){
+ var data = [];
+
+ if (Feature.tableView == null){
+ Feature.tableView = Ti.UI.createTableView();
+ }
+
+ for (var i=(Feature.features.length-1);i>=0;i--){
+ var row = Ti.UI.createTableViewRow({height:60});
+ var title = Feature.features[i]['title'];
+ var subtitle = "Created by " + Feature.features[i]['author'];
+
+ var titleLabel = Ti.UI.createLabel({
+ color:'#000',
+ font:{fontSize:20, fontWeight:'bold', fontFamily:'Helvetica Neue'},
+ text:title,
+ height:25,
+ width:300,
+ top:5,
+ left:5
+ });
+ row.add(titleLabel);
+
+ var subtitleLabel = Ti.UI.createLabel({
+ color:'#999',
+ font:{fontSize:16, fontWeight:'bold', fontFamily:'Helvetica Neue'},
+ text:subtitle,
+ height:25,
+ width:300,
+ top:30,
+ left:5
+ });
+ row.add(subtitleLabel);
+ data.push(row);
+ }
+
+ Feature.tableView.setData(data);
+};
7 utils.js
@@ -0,0 +1,7 @@
+// Utils
+function _log(msg){
+ // Create a notification
+ var n = Ti.UI.createNotification({message:msg});
+ n.duration = Ti.UI.NOTIFICATION_DURATION_LONG;
+ n.show();
+}

0 comments on commit 2b84b66

Please sign in to comment.