voluntary 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YmQ1ZjZjNDk5MjhjMGExMzNlYmI3NDM0ZGZjOWFkYzJkYWI4YzlkMA==
5
+ data.tar.gz: !binary |-
6
+ ZjNkMDA4MzU1N2RhZDBhNzMyMjc1ODVhN2M5MjFhZDk3NjY1NGNkNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OWJiY2Y1ZGNkODFiMTIxMGJlMjMwY2E3OWNiOGNlOTI0OTI2NTIxODdjNGIw
10
+ ZDg4OTM3YWM0N2ZhZWZlYjQ4YTg5MjVmMDlkYzVlZjE0NWZhNGM0N2QwMDI1
11
+ ZmNlNzM0NTc2NTdkMWZjZTk4YjZkNWMyNmVmMTA4ZjY4M2U3NjE=
12
+ data.tar.gz: !binary |-
13
+ ZWJkYzg0ZmRjYTlmYjFmMWNmZDgxZmRkMzcwOTg2ODEwZmVkM2Q3ZDhjZmQ1
14
+ ZjE1YzE0ODUzZjVlNDYyZWMyOTQ0Mzk3Y2EwNmVlZjA4NWMyOWJlMDFiOWFl
15
+ ZDlhNDY3NTBhMWZlOWI4OTI5NTUyMDdmZDUxNWE5NmJhYWExZDY=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## unreleased ##
2
2
 
3
+ ## 0.2.4 (March 23, 2015) ##
4
+
5
+ * #73 Sticky Footer for Application Layout (Twitter Bootstrap).
6
+ * #72 CORS: Access-Control-(Allow-Origin|Request-Method)=* (API)
7
+
3
8
  ## 0.2.3 (March 15, 2015) ##
4
9
 
5
10
  * #16 Implements scope liked_by for likeables.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2012 YOURNAME
1
+ Copyright (c) 2012 - 2015 Mathias Gawlista
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -59,9 +59,9 @@ Run this in your console:
59
59
 
60
60
  git clone https://github.com/user/voluntary_product_name.git
61
61
  cd voluntary_product_name
62
- rvm --create use --rvmrc 1.9.3@voluntary_product_name
62
+ rvm --create use --rvmrc 1.9.3@voluntary_product_name # if you use RVM
63
63
  gem update bundler
64
- gem install rails --no-ri --no-rdoc -v=3.2.14
64
+ gem install rails -v 4.0.13 --no-ri --no-rdoc
65
65
  cd ..
66
66
  rails plugin new voluntary_product_name --database=postgresql --skip-javascript --skip-test-unit --dummy-path=dummy --full
67
67
  cd voluntary_product_name
@@ -5,5 +5,4 @@
5
5
  //= require bootstrap-datetimepicker
6
6
  //= require jquery.tokeninput
7
7
  //= require selectize
8
- //= require competitive_list
9
8
  //= require_tree .
@@ -0,0 +1,484 @@
1
+ (function() {
2
+ this.CompetitiveList = (function() {
3
+ CompetitiveList.prototype.competitiveListOptions = [];
4
+
5
+ CompetitiveList.prototype.competitors = [];
6
+
7
+ CompetitiveList.prototype.competitorsOfCompetitor = {};
8
+
9
+ CompetitiveList.prototype.defeatedCompetitorsByCompetitor = {};
10
+
11
+ CompetitiveList.prototype.outmatchedCompetitorsByCompetitor = {};
12
+
13
+ CompetitiveList.prototype.matchesLeft = 0;
14
+
15
+ CompetitiveList.prototype.currentMatch = null;
16
+
17
+ CompetitiveList.prototype.currentMatchIndex = 0;
18
+
19
+ CompetitiveList.prototype.currentAutoWinnerMatches = [];
20
+
21
+ CompetitiveList.prototype.movingCompetitorToPosition = false;
22
+
23
+ function CompetitiveList(options) {
24
+ this.competitiveListOptions = options;
25
+ this.competitiveListOptions || (this.competitiveListOptions = {});
26
+ $(document.body).on("click", this.competitiveListOptions['id'] + " .competitive_list_start_link", (function(_this) {
27
+ return function(event) {
28
+ event.preventDefault();
29
+ return _this.start();
30
+ };
31
+ })(this));
32
+ $(document.body).on("click", this.competitiveListOptions['id'] + " .save_match_results_link", (function(_this) {
33
+ return function(event) {
34
+ event.preventDefault();
35
+ _this.sortByMostWins();
36
+ return $(_this.competitiveListOptions['id'] + " .save_match_results_link").hide();
37
+ };
38
+ })(this));
39
+ $(document.body).on("click", this.competitiveListOptions['id'] + "_buttons .cancel_tournament_button", (function(_this) {
40
+ return function(event) {
41
+ event.preventDefault();
42
+ return _this.cancelTournament();
43
+ };
44
+ })(this));
45
+ $(document.body).on("click", this.competitiveListOptions['id'] + "_buttons .select_winner_button", (function(_this) {
46
+ return function(event) {
47
+ event.preventDefault();
48
+ return _this.appointWinnerOfMatchByInput();
49
+ };
50
+ })(this));
51
+ }
52
+
53
+ CompetitiveList.meaningOfLife = function() {
54
+ return 42;
55
+ };
56
+
57
+ CompetitiveList.prototype.start = function() {
58
+ var matchesAlreadyExist, matchesWithoutWinner;
59
+ matchesAlreadyExist = false;
60
+ window.matches || (window.matches = []);
61
+ if (window.matches.length > 0) {
62
+ matchesAlreadyExist = true;
63
+ }
64
+ this.setCompetitors();
65
+ this.competitorsOfCompetitor = {};
66
+ this.defeatedCompetitorsByCompetitor = {};
67
+ this.outmatchedCompetitorsByCompetitor = {};
68
+ if (matchesAlreadyExist) {
69
+ if (confirm('Remove previous results and start over?')) {
70
+ window.matches = [];
71
+ } else {
72
+ this.removeMatchesOfNonExistingCompetitors();
73
+ }
74
+ }
75
+ this.generateMatches();
76
+ matchesWithoutWinner = jQuery.map(window.matches, function(m) {
77
+ if (m['winner'] === void 0) {
78
+ return m;
79
+ }
80
+ });
81
+ this.matchesLeft = matchesWithoutWinner.length;
82
+ if (this.nextMatch(true)) {
83
+ return $('#bootstrap_modal').modal('show');
84
+ }
85
+ };
86
+
87
+ CompetitiveList.prototype.setCompetitors = function() {
88
+ return this.competitors = jQuery.map($('.competitive_list li'), function(c) {
89
+ return $(c).data('id');
90
+ });
91
+ };
92
+
93
+ CompetitiveList.prototype.removeMatchesOfNonExistingCompetitors = function() {
94
+ return $.each(window.matches, (function(_this) {
95
+ return function(index, match) {
96
+ var base, base1, loserId, name, name1, notExistingCompetitors;
97
+ notExistingCompetitors = jQuery.map(match['competitors'], function(c) {
98
+ if ($.inArray(c, _this.competitors) === -1) {
99
+ return c;
100
+ }
101
+ });
102
+ if (notExistingCompetitors.length > 0) {
103
+ return window.matches = _this.removeItemFromArray(window.matches, match);
104
+ } else {
105
+ (base = _this.competitorsOfCompetitor)[name = match['competitors'][0]] || (base[name] = []);
106
+ _this.competitorsOfCompetitor[match['competitors'][0]].push(match['competitors'][1]);
107
+ (base1 = _this.competitorsOfCompetitor)[name1 = match['competitors'][1]] || (base1[name1] = []);
108
+ _this.competitorsOfCompetitor[match['competitors'][1]].push(match['competitors'][0]);
109
+ if (match['winner'] !== void 0) {
110
+ loserId = _this.otherCompetitorOfMatch(match, match['winner']);
111
+ return _this.updateDefeatedAndOutmatchedCompetitorsByCompetitor(match['winner'], loserId);
112
+ }
113
+ }
114
+ };
115
+ })(this));
116
+ };
117
+
118
+ CompetitiveList.prototype.removeItemFromArray = function(array, item) {
119
+ var list;
120
+ list = [];
121
+ jQuery.each(array, function(index, workingItem) {
122
+ if (JSON.stringify(workingItem) !== JSON.stringify(item)) {
123
+ return list.push(workingItem);
124
+ }
125
+ });
126
+ return list;
127
+ };
128
+
129
+ CompetitiveList.prototype.generateMatches = function() {
130
+ return $.each(this.competitors, (function(_this) {
131
+ return function(index, competitorId) {
132
+ var base;
133
+ (base = _this.competitorsOfCompetitor)[competitorId] || (base[competitorId] = []);
134
+ return $.each(_this.competitors, function(index, otherCompetitorId) {
135
+ var base1;
136
+ (base1 = _this.competitorsOfCompetitor)[otherCompetitorId] || (base1[otherCompetitorId] = []);
137
+ if (competitorId !== otherCompetitorId && $.inArray(otherCompetitorId, _this.competitorsOfCompetitor[competitorId]) === -1) {
138
+ window.matches.push({
139
+ competitors: [competitorId, otherCompetitorId]
140
+ });
141
+ _this.competitorsOfCompetitor[competitorId].push(otherCompetitorId);
142
+ return _this.competitorsOfCompetitor[otherCompetitorId].push(competitorId);
143
+ }
144
+ });
145
+ };
146
+ })(this));
147
+ };
148
+
149
+ CompetitiveList.prototype.nextMatch = function(from_start) {
150
+ var autoWinnerMatchesHtml, competitorStrings, html, i, modalBodyHtml, modalFooterHtml, modalTitle, radioButtons, rows;
151
+ autoWinnerMatchesHtml = '';
152
+ if (this.currentAutoWinnerMatches.length > 0) {
153
+ this.currentMatch = window.matches[this.currentMatchIndex];
154
+ rows = "";
155
+ $.each(this.currentAutoWinnerMatches, (function(_this) {
156
+ return function(index, match) {
157
+ var even_or_odd, html, manualWinnerChangedHtml;
158
+ even_or_odd = '';
159
+ if (index % 2 === 0) {
160
+ even_or_odd = 'even';
161
+ } else {
162
+ even_or_odd = 'odd';
163
+ }
164
+ manualWinnerChangedHtml = '';
165
+ if (match['manual_winner_changed'] === true) {
166
+ manualWinnerChangedHtml = "<a class=\"bootstrap_tooltip\" href=\"#\" data-toggle=\"tooltip\" title=\"The winner you once have set has been changed automatically!\">\n <i class='icon-warning-sign'/>\n</a>";
167
+ }
168
+ return rows += html = "<tr class=\"" + even_or_odd + "\">\n <td>\n " + manualWinnerChangedHtml + "\n </td>\n <td style=\"width:200px\">" + (_this.nameOfCompetitor(match['winner'], false)) + "</td>\n <td><input type=\"radio\" checked=\"checked\" disabled=\"disabled\"/></td>\n <td>&nbsp;&nbsp;VS.&nbsp;&nbsp;&nbsp;</td>\n <td><input type=\"radio\" disabled=\"disabled\"/></td>\n <td>&nbsp;&nbsp;&nbsp;</td>\n <td style=\"width:200px\">" + (_this.nameOfCompetitor(_this.otherCompetitorOfMatch(match, match['winner']), false)) + "</td>\n <td style=\"text-align:center\">\n <a class=\"bootstrap_tooltip\" href=\"#\" data-toggle=\"tooltip\" data-html=\"true\" title=\"" + match['auto_winner_reason'] + "\">\n <i class=\"icon-question-sign\"/>\n </a>\n </td>\n <td style=\"width:200px\">" + (_this.nameOfCompetitor(match['foot_note_competitor'], false)) + "</td>\n</tr> ";
169
+ };
170
+ })(this));
171
+ autoWinnerMatchesHtml = "<h4>Auto Winners due to Result of last Match</h4>\n<table>\n <tr>\n <td><strong>Last Match was:&nbsp;&nbsp;</strong></td>\n <td>" + (this.nameOfCompetitor(this.currentMatch['winner'], false)) + "</td>\n <td>&nbsp;&nbsp;<input type=\"radio\" checked=\"checked\" disabled=\"disabled\"/></td>\n <td>&nbsp;&nbsp;VS.&nbsp;&nbsp;&nbsp;</td>\n <td><input type=\"radio\" disabled=\"disabled\"/></td>\n <td>&nbsp;&nbsp;&nbsp;</td>\n <td>" + (this.nameOfCompetitor(this.otherCompetitorOfMatch(this.currentMatch, this.currentMatch['winner']), false)) + "</td>\n </tr>\n</table>\n<table class=\"table table-striped\">\n <thead>\n <tr class=\"odd\">\n <th></th>\n <th>Winner</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th>Loser</th>\n <th>Reason</th>\n <th>[1]</th>\n </tr>\n </thead>\n <tbody>\n " + rows + "\n </tbody>\n</table> ";
172
+ }
173
+ this.currentMatch = null;
174
+ $.each(window.matches, (function(_this) {
175
+ return function(index, match) {
176
+ if (match['winner'] === void 0) {
177
+ _this.currentMatch = match;
178
+ _this.currentMatchIndex = index;
179
+ return false;
180
+ }
181
+ };
182
+ })(this));
183
+ if (from_start === true && this.currentMatch === null) {
184
+ alert('No matches to rate left.');
185
+ return false;
186
+ } else {
187
+ $(this.competitiveListOptions['id'] + " .save_match_results_link").show();
188
+ }
189
+ modalBodyHtml = '';
190
+ modalTitle = '';
191
+ modalFooterHtml = '';
192
+ if (this.currentMatch === null) {
193
+ modalTitle = 'No matches to rate left.';
194
+ modalFooterHtml = "<p id=\"" + (this.competitiveListOptions['id'].replace('#', '')) + "_buttons\">\n <button type=\"button\" class=\"cancel_tournament_button\" class=\"btn\">Save match results and close window</button>\n</p> ";
195
+ } else {
196
+ modalTitle = "Appoint Winner (" + this.matchesLeft + " matches left)";
197
+ radioButtons = [];
198
+ competitorStrings = [];
199
+ i = 0;
200
+ $.each(this.currentMatch['competitors'], (function(_this) {
201
+ return function(index, competitorId) {
202
+ var checked;
203
+ checked = ' checked="checked"';
204
+ if (i === 1) {
205
+ checked = '';
206
+ }
207
+ radioButtons.push('<input type="radio" ' + checked + ' name="winner" value="' + competitorId + '" style="position:relative; top:-5px "/>');
208
+ competitorStrings.push(_this.nameOfCompetitor(competitorId, true));
209
+ return i += 1;
210
+ };
211
+ })(this));
212
+ modalBodyHtml += "<div class=\"controls\" style=\"margin-left:50px\">\n <table>\n <tr> \n <td style=\"width:325px; text-align:right;\">\n " + competitorStrings[0] + "\n </td>\n <td>&nbsp;&nbsp;&nbsp;</td>\n <td>" + radioButtons[0] + "</td>\n <td>&nbsp;&nbsp;VS.&nbsp;&nbsp;&nbsp;</td>\n <td>" + radioButtons[1] + "</td>\n <td>\n &nbsp;&nbsp;&nbsp;\n </td>\n <td style=\"width:325px\">\n " + competitorStrings[1] + "\n </td>\n </tr>\n </table>\n</div> ";
213
+ modalFooterHtml = "<p id=\"" + (this.competitiveListOptions['id'].replace('#', '')) + "_buttons\">\n <button type=\"button\" class=\"cancel_tournament_button\" class=\"btn\">Save match results and close window</button> &nbsp;&nbsp;&nbsp;&nbsp;\n <button type=\"button\" class=\"select_winner_button\" class=\"btn btn-primary\">Submit</button>\n</p>";
214
+ }
215
+ modalBodyHtml += autoWinnerMatchesHtml;
216
+ html = "<form class=\"form-inline\" style=\"margin:0px;\">\n <div class=\"modal-header\">\n <button type=\"button\" id=\"close_bootstrap_modal_button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">&times;</button>\n <h3>" + modalTitle + "</h3>\n </div>\n <div class=\"modal-body scrollable-modal-body\">\n " + modalBodyHtml + "\n </div>\n <div class=\"modal-footer\" style=\"text-align:left;\">\n " + modalFooterHtml + "\n </div>\n</form>";
217
+ $('#bootstrap_modal').html(html);
218
+ $('.bootstrap_tooltip').tooltip();
219
+ this.currentAutoWinnerMatches = [];
220
+ return true;
221
+ };
222
+
223
+ CompetitiveList.prototype.otherCompetitorOfMatch = function(match, competitorId) {
224
+ var otherCompetitors;
225
+ otherCompetitors = jQuery.map(match['competitors'], function(c) {
226
+ if (c !== competitorId) {
227
+ return c;
228
+ }
229
+ });
230
+ return otherCompetitors[0];
231
+ };
232
+
233
+ CompetitiveList.prototype.nameOfCompetitor = function(competitorId, considerProc) {
234
+ var competitorDomElement;
235
+ competitorDomElement = $('#competitor_' + competitorId);
236
+ if (considerProc === false || this.competitiveListOptions['competitor_name_proc'] === void 0 || $(competitorDomElement).find('.competitor_name').data('proc-argument') === void 0) {
237
+ return $(competitorDomElement).find('.competitor_name').html();
238
+ } else {
239
+ return this.competitiveListOptions['competitor_name_proc']($(competitorDomElement).find('.competitor_name').data('proc-argument'));
240
+ }
241
+ };
242
+
243
+ CompetitiveList.prototype.cancelTournament = function() {
244
+ this.sortByMostWins();
245
+ $(this.competitiveListOptions['id'] + " .save_match_results_link").hide();
246
+ return $('#bootstrap_modal').modal('hide');
247
+ };
248
+
249
+ CompetitiveList.prototype.appointWinnerOfMatchByInput = function() {
250
+ var loserId, winnerId;
251
+ winnerId = parseInt($("input[name='winner']:checked").val());
252
+ loserId = this.otherCompetitorOfMatch(this.currentMatch, winnerId);
253
+ this.appointWinnerOfMatch(this.currentMatchIndex, winnerId, loserId, true);
254
+ return this.nextMatch(false);
255
+ };
256
+
257
+ CompetitiveList.prototype.appointWinnerOfMatch = function(matchIndex, winnerId, loserId, decrementMatchesLeft) {
258
+ window.matches[matchIndex]['winner'] = winnerId;
259
+ if (decrementMatchesLeft) {
260
+ this.matchesLeft = this.matchesLeft - 1;
261
+ }
262
+ this.updateDefeatedAndOutmatchedCompetitorsByCompetitor(winnerId, loserId);
263
+ this.letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser(winnerId, loserId);
264
+ return this.letOutMatchedCompetitorsOfWinnerWinAgainstLoser(winnerId, loserId);
265
+ };
266
+
267
+ CompetitiveList.prototype.updateDefeatedAndOutmatchedCompetitorsByCompetitor = function(winnerId, loserId) {
268
+ var base, base1;
269
+ (base = this.defeatedCompetitorsByCompetitor)[winnerId] || (base[winnerId] = []);
270
+ this.defeatedCompetitorsByCompetitor[winnerId].push(loserId);
271
+ (base1 = this.outmatchedCompetitorsByCompetitor)[loserId] || (base1[loserId] = []);
272
+ return this.outmatchedCompetitorsByCompetitor[loserId].push(winnerId);
273
+ };
274
+
275
+ CompetitiveList.prototype.letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser = function(winnerId, loserId) {
276
+ var base;
277
+ (base = this.defeatedCompetitorsByCompetitor)[loserId] || (base[loserId] = []);
278
+ return $.each(window.matches, (function(_this) {
279
+ return function(index, match) {
280
+ var manual_winner_changed, matchCompetitorsWhichHaveBeenDefeatedByLoser, otherLoserId;
281
+ if (match['winner'] === winnerId || $.inArray(winnerId, match['competitors']) === -1) {
282
+ return true;
283
+ }
284
+ matchCompetitorsWhichHaveBeenDefeatedByLoser = jQuery.map(match['competitors'], function(c) {
285
+ if ($.inArray(c, _this.defeatedCompetitorsByCompetitor[loserId]) > -1) {
286
+ return c;
287
+ }
288
+ });
289
+ if (matchCompetitorsWhichHaveBeenDefeatedByLoser.length === 0) {
290
+ return true;
291
+ }
292
+ otherLoserId = _this.otherCompetitorOfMatch(match, winnerId);
293
+ manual_winner_changed = false;
294
+ if (match['winner'] !== void 0) {
295
+ _this.removeCompetitorsComparisonResult(winnerId, otherLoserId);
296
+ if (!(_this.movingCompetitorToPosition === true || match['auto_winner'] === true)) {
297
+ manual_winner_changed = true;
298
+ }
299
+ }
300
+ window.matches[index]['manual_winner_changed'] = manual_winner_changed;
301
+ _this.appointWinnerOfMatch(index, winnerId, otherLoserId, match['winner'] === void 0);
302
+ if (_this.movingCompetitorToPosition === true) {
303
+ return true;
304
+ }
305
+ window.matches[index]['auto_winner'] = true;
306
+ window.matches[index]['foot_note_competitor'] = loserId;
307
+ window.matches[index]['auto_winner_type'] = 0;
308
+ if (winnerId === _this.currentMatch['winner'] && loserId === _this.otherCompetitorOfMatch(_this.currentMatch, _this.currentMatch['winner'])) {
309
+ window.matches[index]['auto_winner_recursion'] = false;
310
+ window.matches[index]['auto_winner_reason'] = 'loser has been defeated because he loses against the loser <sup>[1]</sup> of last match';
311
+ } else {
312
+ window.matches[index]['auto_winner_recursion'] = true;
313
+ window.matches[index]['auto_winner_reason'] = 'loser has been defeated because he loses against the loser <sup>[1]</sup> of last auto winner match';
314
+ }
315
+ return _this.currentAutoWinnerMatches.push(window.matches[index]);
316
+ };
317
+ })(this));
318
+ };
319
+
320
+ CompetitiveList.prototype.removeCompetitorsComparisonResult = function(winnerId, loserId) {
321
+ var base;
322
+ (base = this.outmatchedCompetitorsByCompetitor)[winnerId] || (base[winnerId] = []);
323
+ this.outmatchedCompetitorsByCompetitor[winnerId] = this.removeItemFromArray(this.outmatchedCompetitorsByCompetitor[winnerId], loserId);
324
+ return this.defeatedCompetitorsByCompetitor[loserId] = this.removeItemFromArray(this.defeatedCompetitorsByCompetitor[loserId], winnerId);
325
+ };
326
+
327
+ CompetitiveList.prototype.letOutMatchedCompetitorsOfWinnerWinAgainstLoser = function(winnerId, loserId) {
328
+ var base;
329
+ (base = this.outmatchedCompetitorsByCompetitor)[winnerId] || (base[winnerId] = []);
330
+ return $.each(this.outmatchedCompetitorsByCompetitor[winnerId], (function(_this) {
331
+ return function(index, competitorId) {
332
+ return $.each(window.matches, function(index, match) {
333
+ var manual_winner_changed;
334
+ if ($.inArray(competitorId, match['competitors']) > -1 && $.inArray(loserId, match['competitors']) > -1 && match['winner'] !== competitorId) {
335
+ manual_winner_changed = false;
336
+ if (match['winner'] !== void 0) {
337
+ _this.removeCompetitorsComparisonResult(competitorId, loserId);
338
+ if (!(_this.movingCompetitorToPosition === true || match['auto_winner'] === true)) {
339
+ manual_winner_changed = true;
340
+ }
341
+ }
342
+ _this.appointWinnerOfMatch(index, competitorId, loserId, match['winner'] === void 0);
343
+ window.matches[index]['manual_winner_changed'] = manual_winner_changed;
344
+ if (_this.movingCompetitorToPosition === true) {
345
+ return true;
346
+ }
347
+ window.matches[index]['auto_winner'] = true;
348
+ window.matches[index]['auto_winner_type'] = 1;
349
+ window.matches[index]['foot_note_competitor'] = winnerId;
350
+ if (winnerId === _this.currentMatch['winner'] && loserId === _this.otherCompetitorOfMatch(_this.currentMatch, _this.currentMatch['winner'])) {
351
+ window.matches[index]['auto_winner_recursion'] = false;
352
+ window.matches[index]['auto_winner_reason'] = "loser of last match has been defeated by outmatched competitor of<br/>winner <sup>[1]</sup>";
353
+ } else {
354
+ window.matches[index]['auto_winner_recursion'] = true;
355
+ window.matches[index]['auto_winner_reason'] = "loser of last auto winner match has been defeated by outmatched competitor of winner <sup>[1]</sup>";
356
+ }
357
+ _this.currentAutoWinnerMatches.push(match);
358
+ return false;
359
+ }
360
+ });
361
+ };
362
+ })(this));
363
+ };
364
+
365
+ CompetitiveList.prototype.moveCompetitorToPosition = function(competitorId, position, after_update_request_proc) {
366
+ var defeatedCompetitor, outmatchedCompetitor, positionOfdefeatedCompetitor, positions;
367
+ if (after_update_request_proc == null) {
368
+ after_update_request_proc = null;
369
+ }
370
+ this.movingCompetitorToPosition = true;
371
+ this.setCompetitors();
372
+ this.competitorsOfCompetitor = {};
373
+ this.removeMatchesOfNonExistingCompetitors();
374
+ this.generateMatches();
375
+ positions = this.getPositions();
376
+ outmatchedCompetitor = null;
377
+ defeatedCompetitor = null;
378
+ positionOfdefeatedCompetitor = positions[position] === competitorId ? position + 1 : position;
379
+ if (position > Object.keys(positions).length) {
380
+ alert('This position is not available!');
381
+ if (after_update_request_proc !== null) {
382
+ after_update_request_proc();
383
+ }
384
+ this.movingCompetitorToPosition = false;
385
+ return;
386
+ }
387
+ if (!(position === 1 || (position - 1) > Object.keys(positions).length)) {
388
+ outmatchedCompetitor = positions[position - 1];
389
+ }
390
+ if (!(positionOfdefeatedCompetitor > Object.keys(positions).length)) {
391
+ defeatedCompetitor = positions[positionOfdefeatedCompetitor];
392
+ }
393
+ $.each(window.matches, (function(_this) {
394
+ return function(index, match) {
395
+ var loserId, otherCompetitorId, winnerId;
396
+ if ($.inArray(competitorId, match['competitors']) === -1) {
397
+ return true;
398
+ }
399
+ winnerId = null;
400
+ loserId = null;
401
+ otherCompetitorId = _this.otherCompetitorOfMatch(match, competitorId);
402
+ if (otherCompetitorId === outmatchedCompetitor && match['winner'] !== otherCompetitorId) {
403
+ winnerId = otherCompetitorId;
404
+ loserId = competitorId;
405
+ outmatchedCompetitor = null;
406
+ } else if (otherCompetitorId === defeatedCompetitor && match['winner'] !== competitorId) {
407
+ winnerId = competitorId;
408
+ loserId = otherCompetitorId;
409
+ defeatedCompetitor = null;
410
+ }
411
+ if (winnerId === null) {
412
+ return true;
413
+ }
414
+ if (match['winner'] !== void 0) {
415
+ _this.removeCompetitorsComparisonResult(winnerId, loserId);
416
+ }
417
+ _this.currentMatch = match;
418
+ _this.currentMatchIndex = index;
419
+ _this.appointWinnerOfMatch(index, winnerId, loserId, false);
420
+ if (outmatchedCompetitor === null && defeatedCompetitor === null) {
421
+ return false;
422
+ }
423
+ };
424
+ })(this));
425
+ this.sortByMostWins(after_update_request_proc);
426
+ return this.movingCompetitorToPosition = false;
427
+ };
428
+
429
+ CompetitiveList.prototype.sortByMostWins = function(after_update_request_proc) {
430
+ var $wrapper, data, winsByCompetitor;
431
+ if (after_update_request_proc == null) {
432
+ after_update_request_proc = null;
433
+ }
434
+ winsByCompetitor = {};
435
+ $.each(this.competitors, (function(_this) {
436
+ return function(index, competitorId) {
437
+ return winsByCompetitor[competitorId] = 0;
438
+ };
439
+ })(this));
440
+ $.each(window.matches, function(index, match) {
441
+ delete window.matches[index]['auto_winner_reason'];
442
+ return winsByCompetitor[match['winner']] += 1;
443
+ });
444
+ $.each(Object.keys(winsByCompetitor), function(index, competitorId) {
445
+ return $('#competitor_' + competitorId).data('wins', winsByCompetitor[competitorId]);
446
+ });
447
+ $wrapper = $('.competitive_list');
448
+ $wrapper.find('li').sort(function(a, b) {
449
+ return +parseInt($(b).data('wins')) - +parseInt($(a).data('wins'));
450
+ }).appendTo($wrapper);
451
+ if ($('.competitive_list').data('update-all-positions-path') !== void 0) {
452
+ data = {
453
+ _method: 'put',
454
+ positions: this.getPositions(),
455
+ matches: JSON.stringify(window.matches)
456
+ };
457
+ return $.post($('.competitive_list').data('update-all-positions-path'), data).always((function(_this) {
458
+ return function() {
459
+ if (after_update_request_proc !== null) {
460
+ return after_update_request_proc();
461
+ }
462
+ };
463
+ })(this));
464
+ }
465
+ };
466
+
467
+ CompetitiveList.prototype.getPositions = function() {
468
+ var currentPosition, positions;
469
+ positions = {};
470
+ currentPosition = 1;
471
+ $.each($('.competitive_list li'), function(index, element) {
472
+ positions[currentPosition] = $(element).data('id');
473
+ $(element).data('position', currentPosition);
474
+ $(element).find('.competitor_position').html(currentPosition);
475
+ return currentPosition += 1;
476
+ });
477
+ return positions;
478
+ };
479
+
480
+ return CompetitiveList;
481
+
482
+ })();
483
+
484
+ }).call(this);