-
Notifications
You must be signed in to change notification settings - Fork 278
/
display-show.js
417 lines (370 loc) · 14.4 KB
/
display-show.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
MEDUSA.home.displayShow = function() { // eslint-disable-line max-lines
$('.imdbPlot').on('click', function() {
$(this).prev('span').toggle();
if ($(this).html() === '..show less') {
$(this).html('..show more');
} else {
$(this).html('..show less');
}
moveSummaryBackground();
movecheckboxControlsBackground();
});
// Adjust the summary background position and size on page load and resize
function moveSummaryBackground() {
const height = $('#summary').height() + 10;
const top = $('#summary').offset().top + 5;
$('#summaryBackground').height(height);
$('#summaryBackground').offset({ top, left: 0 });
$('#summaryBackground').show();
}
function movecheckboxControlsBackground() {
const height = $('#checkboxControls').height() + 10;
const top = $('#checkboxControls').offset().top - 3;
$('#checkboxControlsBackground').height(height);
$('#checkboxControlsBackground').offset({ top, left: 0 });
$('#checkboxControlsBackground').show();
}
$(window).resize(() => {
moveSummaryBackground();
movecheckboxControlsBackground();
});
$(() => {
moveSummaryBackground();
movecheckboxControlsBackground();
});
$.ajaxEpSearch({
colorRow: true
});
startAjaxEpisodeSubtitles(); // eslint-disable-line no-undef
$.ajaxEpSubtitlesSearch();
$.ajaxEpRedownloadSubtitle();
$('#seasonJump').on('change', function() {
const id = $('#seasonJump option:selected').val();
if (id && id !== 'jump') {
const season = $('#seasonJump option:selected').data('season');
$('html,body').animate({ scrollTop: $('[name="' + id.substring(1) + '"]').offset().top - 100 }, 'slow');
$('#collapseSeason-' + season).collapse('show');
location.hash = id;
}
$(this).val('jump');
});
$('#changeStatus').on('click', () => {
const epArr = [];
$('.epCheck').each(function() {
if (this.checked === true) {
epArr.push($(this).attr('id'));
}
});
if (epArr.length === 0) {
return false;
}
window.location.href = $('base').attr('href') + 'home/setStatus?' +
'indexername=' + $('#indexer-name').attr('value') +
'&seriesid=' + $('#series-id').attr('value') +
'&eps=' + epArr.join('|') +
'&status=' + $('#statusSelect').val();
});
$('.seasonCheck').on('click', function() {
const seasCheck = this;
const seasNo = $(seasCheck).attr('id');
$('#collapseSeason-' + seasNo).collapse('show');
$('.epCheck:visible').each(function() {
const epParts = $(this).attr('id').split('x');
if (epParts[0] === seasNo) {
this.checked = seasCheck.checked;
}
});
});
let lastCheck = null;
$('.epCheck').on('click', function(event) {
if (!lastCheck || !event.shiftKey) {
lastCheck = this;
return;
}
const check = this;
let found = 0;
$('.epCheck').each(function() {
if (found === 1) {
this.checked = lastCheck.checked;
}
if (found === 2) {
return false;
}
if (this === check || this === lastCheck) {
found++;
}
});
});
// Selects all visible episode checkboxes.
$('.seriesCheck').on('click', () => {
$('.epCheck:visible').each(function() {
this.checked = true;
});
$('.seasonCheck:visible').each(function() {
this.checked = true;
});
});
// Clears all visible episode checkboxes and the season selectors
$('.clearAll').on('click', () => {
$('.epCheck:visible').each(function() {
this.checked = false;
});
$('.seasonCheck:visible').each(function() {
this.checked = false;
});
});
// Show/hide different types of rows when the checkboxes are changed
$('#checkboxControls input').on('change', function() {
const whichClass = $(this).attr('id');
$(this).showHideRows(whichClass);
});
// Initially show/hide all the rows according to the checkboxes
$('#checkboxControls input').each(function() {
const status = $(this).prop('checked');
$('tr.' + $(this).attr('id')).each(function() {
if (status) {
$(this).show();
} else {
$(this).hide();
}
});
});
$.fn.showHideRows = function(whichClass) {
const status = $('#checkboxControls > input, #' + whichClass).prop('checked');
$('tr.' + whichClass).each(function() {
if (status) {
$(this).show();
} else {
$(this).hide();
}
});
// Hide season headers with no episodes under them
$('tr.seasonheader').each(function() {
let numRows = 0;
const seasonNo = $(this).attr('id');
$('tr.' + seasonNo + ' :visible').each(() => {
numRows++;
});
if (numRows === 0) {
$(this).hide();
$('#' + seasonNo + '-cols').hide();
} else {
$(this).show();
$('#' + seasonNo + '-cols').show();
}
});
};
function setEpisodeSceneNumbering(forSeason, forEpisode, sceneSeason, sceneEpisode) {
const indexerName = $('#indexer-name').val();
const seriesId = $('#series-id').val();
if (sceneSeason === '') {
sceneSeason = null;
}
if (sceneEpisode === '') {
sceneEpisode = null;
}
$.getJSON('home/setSceneNumbering', {
indexername: indexerName,
seriesid: seriesId,
forSeason,
forEpisode,
sceneSeason,
sceneEpisode
}, data => {
// Set the values we get back
if (data.sceneSeason === null || data.sceneEpisode === null) {
$('#sceneSeasonXEpisode_' + seriesId + '_' + forSeason + '_' + forEpisode).val('');
} else {
$('#sceneSeasonXEpisode_' + seriesId + '_' + forSeason + '_' + forEpisode).val(data.sceneSeason + 'x' + data.sceneEpisode);
}
if (!data.success) {
if (data.errorMessage) {
alert(data.errorMessage); // eslint-disable-line no-alert
} else {
alert('Update failed.'); // eslint-disable-line no-alert
}
}
});
}
function setAbsoluteSceneNumbering(forAbsolute, sceneAbsolute) {
const indexerName = $('#indexer-name').val();
const seriesId = $('#series-id').val();
if (sceneAbsolute === '') {
sceneAbsolute = null;
}
$.getJSON('home/setSceneNumbering', {
indexername: indexerName,
seriesid: seriesId,
forAbsolute,
sceneAbsolute
}, data => {
// Set the values we get back
if (data.sceneAbsolute === null) {
$('#sceneAbsolute_' + seriesId + '_' + forAbsolute).val('');
} else {
$('#sceneAbsolute_' + seriesId + '_' + forAbsolute).val(data.sceneAbsolute);
}
if (!data.success) {
if (data.errorMessage) {
alert(data.errorMessage); // eslint-disable-line no-alert
} else {
alert('Update failed.'); // eslint-disable-line no-alert
}
}
});
}
function setInputValidInvalid(valid, el) {
if (valid) {
$(el).css({
'background-color': '#90EE90', // Green
'color': '#FFF', // eslint-disable-line quote-props
'font-weight': 'bold'
});
return true;
}
$(el).css({
'background-color': '#FF0000', // Red
'color': '#FFF!important', // eslint-disable-line quote-props
'font-weight': 'bold'
});
return false;
}
$('.sceneSeasonXEpisode').on('change', function() {
// Strip non-numeric characters
const value = $(this).val();
$(this).val(value.replace(/[^0-9xX]*/g, ''));
const forSeason = $(this).attr('data-for-season');
const forEpisode = $(this).attr('data-for-episode');
// If empty reset the field
if (value === '') {
setEpisodeSceneNumbering(forSeason, forEpisode, null, null);
return;
}
const m = $(this).val().match(/^(\d+)x(\d+)$/i);
const onlyEpisode = $(this).val().match(/^(\d+)$/i);
let sceneSeason = null;
let sceneEpisode = null;
let isValid = false;
if (m) {
sceneSeason = m[1];
sceneEpisode = m[2];
isValid = setInputValidInvalid(true, $(this));
} else if (onlyEpisode) {
// For example when '5' is filled in instead of '1x5', asume it's the first season
sceneSeason = forSeason;
sceneEpisode = onlyEpisode[1];
isValid = setInputValidInvalid(true, $(this));
} else {
isValid = setInputValidInvalid(false, $(this));
}
if (isValid) {
setEpisodeSceneNumbering(forSeason, forEpisode, sceneSeason, sceneEpisode);
}
});
$('.sceneAbsolute').on('change', function() {
// Strip non-numeric characters
$(this).val($(this).val().replace(/[^0-9xX]*/g, ''));
const forAbsolute = $(this).attr('data-for-absolute');
const m = $(this).val().match(/^(\d{1,3})$/i);
let sceneAbsolute = null;
if (m) {
sceneAbsolute = m[1];
}
setAbsoluteSceneNumbering(forAbsolute, sceneAbsolute);
});
$.fn.generateStars = function() {
return this.each((i, e) => {
$(e).html($('<span/>').width($(e).text() * 12));
});
};
$('.imdbstars').generateStars();
$('#showTable, #animeTable').tablesorter({
widgets: ['saveSort', 'stickyHeaders', 'columnSelector'],
widgetOptions: {
columnSelector_saveColumns: true, // eslint-disable-line camelcase
columnSelector_layout: '<label><input type="checkbox">{name}</label>', // eslint-disable-line camelcase
columnSelector_mediaquery: false, // eslint-disable-line camelcase
columnSelector_cssChecked: 'checked' // eslint-disable-line camelcase
}
});
$('#popover').popover({
placement: 'bottom',
html: true, // Required if content has HTML
content: '<div id="popover-target"></div>'
}).on('shown.bs.popover', () => { // Bootstrap popover event triggered when the popover opens
$.tablesorter.columnSelector.attachTo($('#showTable, #animeTable'), '#popover-target');
});
// Moved and rewritten this from displayShow. This changes the button when clicked for collapsing/expanding the
// Season to Show Episodes or Hide Episodes.
$(() => {
$('.collapse.toggle').on('hide.bs.collapse', function() {
const reg = /collapseSeason-(\d+)/g;
const result = reg.exec(this.id);
$('#showseason-' + result[1]).text('Show Episodes');
$('#season-' + result[1] + '-cols').addClass('shadow');
});
$('.collapse.toggle').on('show.bs.collapse', function() {
const reg = /collapseSeason-(\d+)/g;
const result = reg.exec(this.id);
$('#showseason-' + result[1]).text('Hide Episodes');
$('#season-' + result[1] + '-cols').removeClass('shadow');
});
});
// Set the season exception based on using the get_xem_numbering_for_show() for animes if available in data.xemNumbering,
// or else try to map using just the data.season_exceptions.
function setSeasonSceneException(data) {
$.each(data.seasonExceptions, (season, nameExceptions) => {
let foundInXem = false;
// Check if it is a season name exception, we don't handle the show name exceptions here
if (season >= 0) {
// Loop through the xem mapping, and check if there is a xem_season, that needs to show the season name exception
$.each(data.xemNumbering, (indexerSeason, xemSeason) => {
if (xemSeason === parseInt(season, 10)) {
foundInXem = true;
$('<img>', {
id: 'xem-exception-season-' + xemSeason,
alt: '[xem]',
height: '16',
width: '16',
src: 'images/xem.png',
title: nameExceptions.join(', ')
}).appendTo('[data-season=' + indexerSeason + ']');
}
});
// This is not a xem season exception, let's set the exceptions as a medusa exception
if (!foundInXem) {
$('<img>', {
id: 'xem-exception-season-' + season,
alt: '[medusa]',
height: '16',
width: '16',
src: 'images/ico/favicon-16.png',
title: nameExceptions.join(', ')
}).appendTo('[data-season=' + season + ']');
}
}
});
}
// @TODO: OMG: This is just a basic json, in future it should be based on the CRUD route.
// Get the season exceptions and the xem season mappings.
$.getJSON('home/getSeasonSceneExceptions', {
indexername: $('#indexer-name').val(),
seriesid: $('#series-id').val() // eslint-disable-line camelcase
}, data => {
setSeasonSceneException(data);
});
$('.display-specials a').on('click', function() {
api.patch('config/main', {
layout: {
show: {
specials: $(this).text() !== 'Hide'
}
}
}).then(response => {
log.info(response.data);
window.location.reload();
}).catch(error => {
log.error(error.data);
});
});
};