Skip to content

Commit

Permalink
Added user type selection, and ParentHome panel
Browse files Browse the repository at this point in the history
  • Loading branch information
ups-tla committed Jan 11, 2012
1 parent 32c339a commit 5cc03d7
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 431 deletions.
19 changes: 19 additions & 0 deletions UPSUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function UPSUser()
{
this.storage = window.localStorage;
}

UPSUser.prototype.GetUserType = function()
{
if(!this.storage.getItem("usertype"))
{
this.storage.setItem("usertype","none");
}

return this.storage.getItem("usertype");
}

UPSUser.prototype.SetUserType = function(type)
{
this.storage.setItem("usertype",type);
}
10 changes: 10 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Ext.regApplication('UPSApp', {
defaultTarget:'viewport',
name:'UPSApp',
launch: function() {

// The Ext.regApplication call automatically creates our 'views' namespace
this.views.viewport = new this.views.Viewport();
}
});
27 changes: 27 additions & 0 deletions app/views/SelectUserType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
UPSApp.views.SelectUserType = Ext.extend(Ext.Panel, {
cardSwitchAnimation:'slide',
dockedItems:[],
items:[
{
xtype:'button',
text:"I'm a Parent",
handler:function() {
User.SetUserType('parent');
UPSApp.views.viewport.setActiveItem('parenthome');
}
},
{
xtype:'button',
text:"I'm a Student"
},
{
xtype:'button',
text:"I'm an Alumnus"
}
],
initComponent: function() {


UPSApp.views.Viewport.superclass.initComponent.apply(this, arguments);
}
});
49 changes: 49 additions & 0 deletions app/views/Viewport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var User;

UPSApp.views.Viewport = Ext.extend(Ext.Panel, {
fullscreen:true,
layout: 'card',
cardSwitchAnimation:'pop',
dockedItems:[
new Ext.Toolbar({
dock:'bottom',
title:"Debug",
items:[
{
xtype:'button',
text:'Reset Usertype',
handler:function(){User.SetUserType("none");}
}
]
})
],
items:[],
activeItem:0,
initComponent: function() {

User = new UPSUser();

UPSApp.views.toolbar = new Ext.Toolbar({
title:'University of Puget Sound'
});

this.dockedItems[1] = UPSApp.views.toolbar;

UPSApp.views.selectUserType = new UPSApp.views.SelectUserType();
UPSApp.views.parentHome = new UPSApp.views.ParentHome();

this.items[0] = UPSApp.views.selectUserType;
this.items[1] = UPSApp.views.parentHome;

if(User.GetUserType() == "none")
Ext.apply(this, {
activeItem:0
})
else if(User.GetUserType() == "parent")
Ext.apply(this, {
activeItem:1
})

UPSApp.views.Viewport.superclass.initComponent.apply(this, arguments);
}
});
10 changes: 10 additions & 0 deletions app/views/parent/ParentHome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
UPSApp.views.ParentHome = Ext.extend(Ext.Panel, {
id:'parenthome',
dockedItems:[],
items:[],
html:"<p>I'm a <b>Parent</b></p>",
initComponent: function() {

UPSApp.views.Viewport.superclass.initComponent.apply(this, arguments);
}
});
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
<link rel="stylesheet" href="sencha/resources/css/sencha-touch.css" type="text/css">
<script type="text/javascript" src="sencha/sencha-touch.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>
<script type="text/javascript" charset="utf-8" src="UPSUser.js"></script>
<script type="text/javascript" charset="utf-8" src="main.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegapdemo-w-sencha.js"></script>
<script type="text/javascript" charset="utf-8" src="app/app.js"></script>
<script type="text/javascript" charset="utf-8" src="app/views/Viewport.js"></script>
<script type="text/javascript" charset="utf-8" src="app/views/SelectUserType.js"></script>
<script type="text/javascript" charset="utf-8" src="app/views/parent/ParentHome.js"></script>
</head>
<body></body>
</html>
185 changes: 3 additions & 182 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,184 +1,5 @@
var getLocation = function() {
var suc = function(p) {

document.getElementById("loclat").innerHTML = 'Latitude: '
+ p.coords.latitude;
document.getElementById("loclong").innerHTML = 'Longitude: '
+ p.coords.longitude;
document.getElementById("locaccur").innerHTML = 'Accuracy: '
+ p.coords.accuracy + 'm';
document.addEventListener("deviceready", onDeviceReady, false);

var mapview = document.getElementById('mapview');

var image_url = "http://maps.google.com/maps/api/staticmap?sensor=false&center="
+ p.coords.latitude
+ ","
+ p.coords.longitude
+ "&zoom=13&size=220x180&markers=color:blue|"
+ p.coords.latitude + ',' + p.coords.longitude;

mapview.style.display = "";
mapview.style.position = "absolute";
mapview.style.bottom = "7px";
mapview.style.left = "14px";
document.getElementById("mapcanvas").src = image_url;
};
var fail = function(error) {
document.getElementById("loclong").innerHTML = '<span style="color:red;">Failed to get location</span>';
switch (error.code) {
case error.PERMISSION_DENIED:
alert("User did not share geolocation data.");
break;

case error.POSITION_UNAVAILABLE:
alert("Could not detect current position.");
break;

case error.TIMEOUT:
alert("Retrieving position timed out.");
break;

default:
alert("Unknown error.");
break;
}
};

if (navigator.geolocation) {
document.getElementById("loclong").innerHTML = "Getting geolocation . . .";
navigator.geolocation.getCurrentPosition(suc, fail);
} else {
document.getElementById("loclong").innerHTML = '<span style="color:red;">Device or browser can not get location</span>';
}
};

var closeLocation = function() {
document.getElementById("loclat").innerHTML = "";
document.getElementById("loclong").innerHTML = "";
document.getElementById("locaccur").innerHTML = "";
document.getElementById("mapcanvas").src = "";
document.getElementById("mapview").style.display = "none";
};

var beep = function() {
navigator.notification.beep(2);
};

var vibrate = function() {
navigator.notification.vibrate(0);
};

function roundNumber(num) {
var dec = 3;
var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
return result;
}

var accelerationWatch = null;

function updateAcceleration(a) {
document.getElementById('x').innerHTML = roundNumber(a.x);
document.getElementById('y').innerHTML = roundNumber(a.y);
document.getElementById('z').innerHTML = roundNumber(a.z);
}

function toggleAccel() {
if (accelerationWatch !== null) {
navigator.accelerometer.clearWatch(accelerationWatch);
updateAcceleration({
x : "",
y : "",
z : ""
});
accelerationWatch = null;
} else {
var options = {};
options.frequency = 1000;
accelerationWatch = navigator.accelerometer.watchAcceleration(
updateAcceleration, function(ex) {
alert("accel fail (" + ex.name + ": " + ex.message + ")");
}, options);
}
}

var preventBehavior = function(e) {
e.preventDefault();
};

function dump_pic(data) {
var viewport = document.getElementById('viewport');
//console.log(data);
viewport.style.display = "";
viewport.style.position = "relative";
viewport.style.top = "10px";
viewport.style.left = "20px";
document.getElementById("test_img").src = "data:image/jpeg;base64," + data;
}

function fail(msg) {
alert(msg);
}

function show_pic() {
navigator.camera.getPicture(dump_pic, fail, {
quality : 30
});
}

function closeviewport() {
var viewport = document.getElementById('viewport');
viewport.style.display = "none";
document.getElementById("test_img").src = "";
}

function contacts_success(contacts) {
alert(contacts.length
+ ' contacts returned.'
+ (contacts[2] && contacts[2].name &&
contacts[2].name.formatted ? (' Third contact is ' + contacts[2].name.formatted)
: ''));
}

function get_contacts() {
var obj = new ContactFindOptions();
obj.filter = "";
obj.multiple = true;
navigator.contacts.find(
[ "displayName", "name" ], contacts_success,
fail, obj);
}

var check_network = function() {
var networkState = navigator.network.connection.type;

var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.NONE] = 'No network connection';

document.getElementById("networktext").innerHTML = "<span>Connection type:<br/>"
+ states[networkState] + "</span>";
};

var compassWatch = null;

function updateHeading(h) {
document.getElementById('h').innerHTML = h.magneticHeading;
}

function toggleCompass() {
if (compassWatch !== null) {
navigator.compass.clearWatch(compassWatch);
compassWatch = null;
updateHeading({ magneticHeading : "Off"});
} else {
var options = { frequency: 1000 };
compassWatch = navigator.compass.watchHeading(updateHeading, function(e) {
alert('Compass Error: ' + e.code);
}, options);
}
function onDeviceReady() {

}
Loading

0 comments on commit 5cc03d7

Please sign in to comment.