Skip to content

Commit

Permalink
added js files
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Carrafa committed Jul 27, 2011
1 parent 9fcdff9 commit 8169832
Show file tree
Hide file tree
Showing 12 changed files with 996 additions and 0 deletions.
22 changes: 22 additions & 0 deletions assets/www/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;" />-->
<link rel="stylesheet" href="lib/css/sencha-touch.css" type="text/css">

<title>List</title>
<script type="text/javascript" src="lib/sencha-touch.js"></script>
<script type="text/javascript" src="phonegap.0.9.5.js"></script>
<script type="text/javascript" src="src/index.js"></script>
<script type="text/javascript" src="src/util.js"></script>
<script type="text/javascript" src="src/setup.js"></script>
<script type="text/javascript" src="src/selector.js"></script>
<script type="text/javascript" src="src/shuffle.js"></script>
<script type="text/javascript" src="src/teams.js"></script>
<script type="text/javascript" src="src/tournament.js"></script>
<script type="text/javascript" src="src/bracket.js"></script>
<script type="text/javascript" src="src/tournamentui.js"></script>
</head>
<body></body>
</html>
70 changes: 70 additions & 0 deletions assets/www/src/bracket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Hlm.Bracket = Ext.extend(Ext.BoxComponent, {
title: 'Bracket',
autoEl: {
tag : 'canvas'
},
constructor: function(config) {
this.tournament = config.tournament;
this.teams = config.teams;
Hlm.Bracket.superclass.constructor.apply(this, arguments);
},

onRender : function() {
this.el = Ext.get(document.createElement('canvas'));
Hlm.Bracket.superclass.onRender.apply(this, arguments);
},
onShow: function() {
Hlm.Bracket.superclass.onShow.apply(this, arguments);
this.draw(this.getWidth(), this.getHeight());
},
draw: function(width, height) {
this.el.dom.width = this.getWidth();
this.el.dom.height = this.getHeight();

var ctx = this.el.dom.getContext("2d");
var bracketWidth = (this.tournament.xspan[1]-this.tournament.xspan[0]);
var bracketHeight = (this.tournament.yspan[1]-this.tournament.yspan[0]);
var xscale = this.getWidth()/bracketWidth;
var yscale = this.getHeight()/bracketHeight;

ctx.beginPath();
ctx.strokeStyle="#000";
ctx.lineWidth = 1;

// put 0,0 in the middle
ctx.setTransform(1,0,0,1,0,0);
ctx.translate(-this.tournament.xspan[0]*xscale,
-this.tournament.yspan[0]*yscale);

ctx.rect(this.tournament.xspan[0]*xscale,
this.tournament.yspan[0]*yscale,
bracketWidth*xscale,
bracketHeight*yscale);
ctx.stroke();


var matches = this.tournament.getMatches();
for(var i=0; i < matches.length; i ++) {
console.log(matches[i].x, matches[i].y);
var x = matches[i].x,
y1 = matches[i].y1,
y2 = matches[i].y2;
if(matches[i].teams[0] != undefined) {
var team1 = this.teams.getAt(matches[i].teams[0]).data;
ctx.fillText(Hlm.renderTeam(team1), (x-.5)*xscale, y1*yscale-1);
}

ctx.moveTo((x-.5)*xscale, y1*yscale);
ctx.lineTo((x+.5)*xscale, y1*yscale);

if(matches[i].teams[1] != undefined) {
var team2 = this.teams.getAt(matches[i].teams[1]).data;
ctx.fillText(Hlm.renderTeam(team2), (x-.5)*xscale, y2*yscale-1);
}

ctx.moveTo((x-.5)*xscale, y2*yscale);
ctx.lineTo((x+.5)*xscale, y2*yscale);
ctx.stroke();
};
}
});
66 changes: 66 additions & 0 deletions assets/www/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Ext.ns("Hlm");
Ext.ns("Hlm.util");

Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,

onReady : function() {
var selected = Hlm.selected();
var picker = Hlm.picker();

var teamlist = new Hlm.TeamList({
pickedStore: Hlm.pickedStore
});

var teamPanel = new Ext.Panel({
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [{
xtype: 'button',
text: 'Redraw',
handler: function() {
teamlist.redrawTeams();
}
}]
}],
items: [teamlist]
});

var setupPanel = new Hlm.SetupPanel({
items: [
picker, selected, teamPanel
]
});
var panel = new Ext.Panel({
fullscreen: true,
layout: 'card',
items: [setupPanel]
});
picker.on('disclose', setupPanel.next, setupPanel);
var done = function() {
panel.add(new Hlm.TournamentUi({
teamStore: teamlist.teamStore
}));
panel.getLayout().next({type: 'slide'})
};
setupPanel.on('done', done);
setupPanel.on('addAll', function() {
var pickRange = Hlm.contactStore.getRange();
for(var i=0; i < pickRange.length; i++) {
Hlm.pickedStore.add(pickRange[i]);
}
});

Hlm.contactStore.load();
panel.show();

////TEST////
//setupPanel.getLayout().next();
//setupPanel.getLayout().next();
//done();
}
});
154 changes: 154 additions & 0 deletions assets/www/src/selector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
Hlm.selected = function() {
var list = new Ext.List({
itemTpl: '<div class="contact2"><strong>{firstName}</strong> {lastName}</div>',
store: Hlm.pickedStore,
onItemDisclosure: function(record) {
Hlm.pickedStore.remove(record);
}
});
list.addCls('x-list-delete');
return list;
};

Hlm.picker = function() {
var itemDisclosure = {
handler: function(record, btn, index) {
Hlm.pickedStore.add(record);
}
};

var list = new Ext.List({
itemTpl: '<div class="contact2"><strong>{firstName}</strong> {lastName}</div>',
selModel: {
mode: 'SINGLE',
allowDeselect: true
},
grouped: true,
indexBar: true,

onItemDisclosure: itemDisclosure,
store: Hlm.contactStore
});

return list;
};

Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});

Ext.data.ProxyMgr.registerType("gapStorage",
Ext.extend(Ext.data.Proxy, {
create: function(operation, callback, scope) {
},
read: function(operation, callback, scope) {
var thisProxy = this;
console.log('navigator called');

var phonegapfunc = function(deviceContacts) {
//loop over deviceContacts and create Contact model instances
console.log('navigator returned');
var contacts = [];
console.log('length was' + deviceContacts.length);
for (var i = 0; i < deviceContacts.length; i++) {
var deviceContact = deviceContacts[i];
console.log('this name is' + deviceContact.displayName);
var contact = new thisProxy.model({
firstName: deviceContact.displayName,
lastName: ''
});
contact.deviceContact = deviceContact;
contacts.push(contact);
}
//return model instances in a result set
operation.resultSet = new Ext.data.ResultSet({
records: contacts,
total : contacts.length,
loaded : true
});
//announce success
operation.setSuccessful();
operation.setCompleted();
//finish with callback
try{
if (typeof callback == "function") {
callback.call(scope || thisProxy, operation);
}
} catch (e) {
console.log("Error in success callback: "+e);
printStackTrace();
}

console.log('navigator callback end');
}
if (navigator.service) {
navigator.service.contacts.find(
['displayName'],
phonegapfunc,
function(){}
);
} else {
var contact = new thisProxy.model({
firstName: 'Joe C',
lastName: ''
});
operation.resultSet = new Ext.data.ResultSet({
records: [contact],
total : 1,
loaded : true
});
operation.setSuccessful();
operation.setCompleted();
if (typeof callback == "function") {
callback.call(scope || thisProxy, operation);
}
}
},
update: function(operation, callback, scope) {
},
destroy: function(operation, callback, scope) {
}
})
);

Ext.regModel('GapContact', {
fields: [
{name: 'firstName', type: "string"},
{name: 'lastName', type: "string"}
],
proxy: {
type: "gapStorage"
}
});

Hlm.pickedStore = new Ext.data.Store({
model: 'Contact',
sorters: 'firstName',
data: [
/////////////////TEST DATA////////////////////////////////////////
// {firstName: '0', lastName: '0'},
// {firstName: '1', lastName: '1'},
// {firstName: '2', lastName: '2'},
// {firstName: '3', lastName: '3'},
// {firstName: '4', lastName: '4'},
// {firstName: '5', lastName: '5'},
// {firstName: '6', lastName: '6'},
// {firstName: '7', lastName: '7'},
// {firstName: '8', lastName: '8'},
// {firstName: '9', lastName: '9'},
// {firstName: 'a', lastName: 'a'},
// {firstName: 'b', lastName: 'b'},
// {firstName: 'c', lastName: 'c'},
// {firstName: 'd', lastName: 'd'},
// {firstName: 'e', lastName: 'e'},
// {firstName: 'f', lastName: 'f'}
//////////////////////////////////////////////////////////////////
]
});

Hlm.contactStore = new Ext.data.Store({
model: 'GapContact',
getGroupString : function(record) {
return record.get('firstName')[0];
}
});
Loading

0 comments on commit 8169832

Please sign in to comment.