forked from nutki/Goko-Live-Log-Viewer
-
Notifications
You must be signed in to change notification settings - Fork 9
/
automatchSeekPop.js
266 lines (235 loc) · 9.87 KB
/
automatchSeekPop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*jslint browser: true, devel: true, indent: 4, maxlen: 90, es5: true */
/*global jQuery, $, angular */
(function () {
"use strict"; // JSList mode
var gs = window.GokoSalvager;
gs.AM = gs.AM || {};
gs.AM.appendSeekPopup = function (viewport) {
viewport.append([
'<div id="seekAAPop" title="Looking for Match">',
'<p>Automatch is looking for players whose ',
' search criteria match your table.</p>',
'<button id="seekAAStop">Stop Looking</button>',
'<button id="seekAAOkay">Keep Looking</button>',
'</div>'
].join(''));
$('#seekAAPop').dialog({
modal: true,
width: 500,
draggable: false,
resizeable: false,
autoOpen: false
});
$('#seekAAStop').click(function () {
gs.AM.showSeekPop(false);
gs.AM.cancelSeek();
});
$('#seekAAOkay').click(function () {
gs.AM.showSeekPop(false);
});
viewport.append([
'<div id="seekPop" title="Request Automatch" ng:app ',
' ng:controller="gokoSalvagerUserSettingsController">',
' <table>',
' <tr>',
' <td colspan="2">',
' <label>Min Players:</label>',
' <select id="minPlayers" ng:model="us.automatch_min_players">',
' <option value="2">2</option>',
' <option value="3">3</option>',
' <option value="4">4</option>',
' <option value="5">5</option>',
' <option value="6">6</option>',
' </select>',
' </td>',
' <td colspan="2">',
' <label>Min Sets:</label>',
' <select id="minSets" ng:model="us.automatch_min_sets">',
' <option selected value="1">Base Only</option>',
' <option value="2">2</option>',
' <option value="3">3</option>',
' <option value="4">4</option>',
' <option value="5">5</option>',
' <option value="6">6</option>',
' <option value="7">7</option>',
' <option value="8">8</option>',
' <option value="9">9</option>',
' <option value="10">10</option>',
' <option value="12">12</option>',
' <option value="13">13</option>',
' <option value="14">14</option>',
' <option value="15">All Cards</option>',
' </select>',
' </td>',
' </tr>',
' <tr>',
' <td colspan="2">',
' <label>Max Players:</label>',
' <select id="maxPlayers" ng:model="us.automatch_max_players">',
' <option value="2">2</option>',
' <option value="3">3</option>',
' <option value="4">4</option>',
' <option value="5">5</option>',
' <option value="6">6</option>',
' </select>',
' </td>',
' <td colspan="2">',
' <label>Max Sets:</label>',
' <select id="maxSets" ng:model="us.automatch_max_sets">',
' <option value="1">Base Only</option>',
' <option value="2">2</option>',
' <option value="3">3</option>',
' <option value="4">4</option>',
' <option value="5">5</option>',
' <option value="6">6</option>',
' <option value="7">7</option>',
' <option value="8">8</option>',
' <option value="9">9</option>',
' <option value="10">10</option>',
' <option value="12">12</option>',
' <option value="13">13</option>',
' <option value="14">14</option>',
' <option selected value="15">All Cards</option>',
' </select>',
' </td>',
' </tr>',
' </table>',
' <table>',
' <tr>',
' <td colspan="1">',
' <label>Rating +/-</label>',
' </td>',
' <td colspan="1">',
' <input type="number" id="rdiff" value="2000" size="4"',
' ng:model="us.automatch_rdiff"/>',
' </td>',
' </tr>',
' <tr>',
' <td colspan="1">',
' <label>System</label>',
' </td>',
' <td colspan="1">',
' <select id="ratingSystem" ng:model="us.automatch_rSystem">',
' <option value="pro">Pro</option>',
' <option value="casual">Casual</option>',
' <option value="unrated">Unrated</option>',
' </select>',
' </td>',
' </tr>',
' <tr>',
' <td colspan="1">',
' <input type="submit" id="seekreq" value="Submit"',
' ng:click="save(us)" />',
' </td>',
' <td colspan="1">',
' <input type="submit" id="seekcan" value="Cancel" />',
' </td>',
' <td colspan="1">',
' <input type="submit" id="seekhide" value="Hide" />',
' </td>',
' </tr>',
' <tr>',
' <td colspan="4">',
' <div id="seekstatus"></div>',
' </td>',
' </tr>',
' </table>',
'</div>'
].join(''));
// Override Goko's "hide select elements by default" css
$('#seekPop select').css('visibility', 'inherit');
$('#seekPop select').css('top', 'auto');
$('#seekPop').dialog({
modal: true,
width: 550,
draggable: false,
resizeable: false,
autoOpen: false
});
// Submit request
$('#seekreq').click(function () {
var np, ns, rr, rs;
console.log('requested seek');
np = {rclass: 'NumPlayers', props: {}};
np.props.min_players = parseInt($('#minPlayers').val(), 10);
np.props.max_players = parseInt($('#maxPlayers').val(), 10);
ns = {rclass: 'NumSets', props: {}};
ns.props.min_sets = parseInt($('#minSets').val(), 10);
ns.props.max_sets = parseInt($('#maxSets').val(), 10);
rr = {rclass: 'RelativeRating', props: {}};
rr.props.pts_lower = parseInt($('#rdiff').val(), 10);
rr.props.pts_higher = parseInt($('#rdiff').val(), 10);
rr.props.rating_system = $('#ratingSystem').val();
rs = {rclass: 'RatingSystem', props: {}};
rs.props.rating_system = $('#ratingSystem').val();
// Clear any cached table information from an automatch request
// that was generated through a table create.
gs.AM.tableSettings = null;
// Send seek request
gs.AM.submitSeek({
player: gs.AM.player,
requirements: [np, ns, rr, rs]
});
// Hide the dialog
gs.AM.showSeekPop(false);
});
// Cancel outstanding request, if any, and close dialog
$('#seekcan').click(function () {
gs.AM.cancelSeek();
gs.AM.showSeekPop(false);
});
$('#seekhide').click(function () {
gs.AM.showSeekPop(false);
});
/*
* Input validation
*/
$('#minPlayers').change(function () {
if (parseInt($('#minPlayers').val(), 10)
> parseInt($('#maxPlayers').val(), 10)) {
$('#maxPlayers').val($('#minPlayers').val());
}
});
$('#maxPlayers').change(function () {
if (parseInt($('#maxPlayers').val(), 10)
< parseInt($('#minPlayers').val(), 10)) {
$('#minPlayers').val($('#maxPlayers').val());
}
});
$('#minSets').change(function () {
if (parseInt($('#minSets').val(), 10)
> parseInt($('#maxSets').val(), 10)) {
$('#maxSets').val($('#minSets').val());
}
});
$('#maxSets').change(function () {
if (parseInt($('#maxSets').val(), 10)
< parseInt($('#minSets').val(), 10)) {
$('#minSets').val($('#maxSets').val());
}
});
angular.bootstrap(window.document);
};
// Update and show/hide the dialog
gs.AM.showSeekPop = function (visible) {
var seeking, canceling;
seeking = (gs.AM.state.seek !== null);
canceling = seeking && gs.AM.state.seek.hasOwnProperty('canceling');
$('#seekPop select').prop('disabled', seeking || canceling);
$('#seekPop input').prop('disabled', seeking || canceling);
$('#seekreq').prop('disabled', seeking || canceling);
$('#seekcan').prop('disabled', canceling);
$('#seekhide').prop('disabled', false);
$('#seekstatus').html(seeking ? 'Looking for a match...' : '');
if (typeof visible === "undefined") {
visible = true;
}
if (gs.AM.state.seek !== null && gs.AM.tableSettings !== null) {
$('#seekAAPop').dialog(visible ? 'open' : 'close');
$('#seekAAOkay').focus();
} else {
$('#seekPop').dialog(visible ? 'open' : 'close');
$('#seekhide').focus();
}
};
}());