5
5
// Brackets
6
6
Brakkit . BracketsController = SC . ArrayProxy . create ( {
7
7
content : [ ] ,
8
- selected : { } ,
8
+ selected : null ,
9
9
addBracket : function ( _title ) {
10
10
var self = this ;
11
11
var bracket = Brakkit . Bracket . create ( {
@@ -17,7 +17,7 @@ Brakkit.BracketsController = SC.ArrayProxy.create({
17
17
self . selectBracket ( bracket ) ;
18
18
} ) ;
19
19
} ,
20
- getBrackets : function ( ) {
20
+ loadBrackets : function ( ) {
21
21
var self = this ;
22
22
$ . getJSON ( '/brackets' , function ( data , status , xhr ) {
23
23
data . forEach ( function ( value ) {
@@ -34,42 +34,32 @@ Brakkit.BracketsController = SC.ArrayProxy.create({
34
34
selectBracket : function ( bracket ) {
35
35
//set the current bracket
36
36
Brakkit . BracketsController . set ( 'selected' , bracket ) ;
37
- $ . getJSON ( '/brackets/' + bracket . get ( 'id' ) , function ( data ) {
38
- Brakkit . TeamsController . getTeams ( ) ;
39
- } ) ;
40
- } ,
41
- startup : function ( ) {
42
- Brakkit . BracketsController . getBrackets ( ) ;
43
37
}
44
38
} ) ;
45
39
Brakkit . BracketController = SC . Object . create ( {
46
- contentBinding : "Brakkit.BracketsController.selected"
47
- } ) ;
48
-
49
- $ ( function ( ) {
50
- Brakkit . BracketsController . startup ( ) ;
40
+ contentBinding : "Brakkit.BracketsController.selected" ,
41
+ calculate : function ( ) {
42
+ console . log ( 'calculate the bracket' ) ;
43
+ }
51
44
} ) ;
52
45
53
46
//Teams
54
47
Brakkit . TeamsController = SC . ArrayProxy . create ( {
55
48
content : [ ] ,
56
- getTeams : function ( ) {
49
+ loadTeams : function ( ) {
57
50
var self = this ;
58
- console . log ( 'getting teams' ) ;
59
51
var c = [ ] ;
60
- $ . getJSON ( '/teams' , function ( data ) {
61
- console . log ( data ) ;
62
- for ( var i = 0 ; i < data . length ; i ++ ) {
63
- c . pushObject ( Brakkit . Team . create ( data [ i ] ) ) ;
64
- }
65
-
66
- // data.forEach(function(value){
67
- // console.log(value);
68
- // c.push(Brakkit.Team.create(value));
69
- // });
70
- } ) ;
52
+ var bracket = Brakkit . BracketController . get ( 'content' ) ;
53
+ console . log ( bracket ) ;
54
+ if ( bracket ) {
55
+ bracket . get ( 'teams' ) . forEach ( function ( value ) {
56
+ $ . getJSON ( '/teams/' + value , function ( data ) {
57
+ c . pushObject ( Brakkit . Team . create ( data ) ) ;
58
+ } ) ;
59
+ } ) ;
60
+ }
71
61
self . set ( 'content' , c ) ;
72
- } . observes ( ) ,
62
+ } . observes ( "Brakkit.BracketController.content" ) ,
73
63
addTeam : function ( _name , _seed ) {
74
64
var team = Brakkit . Team . create ( {
75
65
name : _name ,
@@ -98,70 +88,20 @@ Brakkit.TeamsController = SC.ArrayProxy.create({
98
88
}
99
89
} ) ;
100
90
101
-
102
- Brakkit . Eliminator = {
103
- eliminate : function ( from ) {
104
- var divisor = from < 4 ? 2 : 4 ;
105
- if ( from % divisor === 0 ) {
106
- return 0 ;
107
- }
108
- var matches = [ ] ;
109
- for ( var i = 0 ; i <= from / 2 ; i ++ ) {
110
- if ( ( from - i ) % divisor === 0 ) {
111
- matches . push ( i ) ;
112
- }
113
- }
114
- return matches [ matches . length - 1 ] ;
115
- }
116
- } ;
117
-
118
91
//Rounds
119
92
Brakkit . RoundsController = SC . ArrayProxy . create ( {
120
- setRounds : function ( ) {
121
- // var bracket = Brakkit.BracketController.get('content');
122
- // var teams = Brakkit.TeamsController.get('content');
123
- // var teamsAllocated = 0;
124
- // if(bracket && teams){
125
- // var rounds = [];
126
- // var numberOfTeams = teams.get('length');
127
- // //the first round of the tournament has to even out the number of remaining teams
128
- // //make sure we're playing the exact number of teams that, after elimination, will yeild a multiple of 4
129
- // //ex: if there are 17 team, eliminate 5 teams in the first round to yeild 12 remaining teams in the second
130
- // var teamsToEliminate = Brakkit.Eliminator.eliminate(numberOfTeams);
131
- // //Make the teams with the highest seed compete in the first round of elimination
132
- // //teams with higher seeds will automatically advance to the next round
133
- // var seedThreshold = numberOfTeams - teamsToEliminate;
134
- // var teamsInFirstRound = teams.filter(function(item){
135
- // return item.get('seed') > seedThreshold;
136
- // });
137
- // //if we already have a nice number of teams
138
- // if(teamsInFirstRound.length == 0){
139
- // //Add all the teams!
140
- // teamsInFirstRound = teams;
141
- // }
142
- // //create the first round
143
- // rounds.push(
144
- // Brakkit.Round.create({
145
- // teams : teamsInFirstRound
146
- // })
147
- // );
148
- // //create the second round
149
- // if(teamsInFirstRound.length < numberOfTeams){
150
- // var teamsInSecondRound = teams.filter(function(item){
151
- // return item.get('seed') <= seedThreshold;
152
- // })
153
- // rounds.push(
154
- // Brakkit.Round.create({
155
- // teams : teamsInSecondRound
156
- // })
157
- // )
158
- // }
159
- // if(rounds[0].get('teams').length + rounds[1].get('teams').length != numberOfTeams){
160
- // alert("Unable to allocate all teams");
161
- // }
162
- // Brakkit.RoundsController.set('content', rounds);
163
- // }
93
+ loadRounds : function ( ) {
94
+ var self = this ;
95
+ var c = [ ] ;
96
+ var bracket = Brakkit . BracketController . get ( 'content' ) ;
97
+ if ( bracket ) {
98
+ bracket . get ( 'rounds' ) . forEach ( function ( value ) {
99
+ $ . getJSON ( '/rounds/' + value , function ( data ) {
100
+ c . pushObject ( Brakkit . Round . create ( data ) ) ;
101
+ } ) ;
102
+ } ) ;
103
+ }
104
+ self . set ( 'content' , c ) ;
164
105
} . observes ( "Brakkit.BracketController.content" ) ,
165
106
content : [ ]
166
107
} ) ;
167
-
0 commit comments