~ubuntu-branches/debian/experimental/nzbget/experimental

« back to all changes in this revision

Viewing changes to webui/downloads.js

  • Committer: Package Import Robot
  • Author(s): Andreas Moog
  • Date: 2014-12-25 12:58:06 UTC
  • mfrom: (1.2.1) (3.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20141225125806-vnzgajhm7mju9933
Tags: 14.1+dfsg-1
* New Upstream release (Closes: #768863)
* debian/patches:
  - Remove 0010_unnecessary_gcryptdep.patch, included upstream
  - Refresh remaining patches
* debian/control:
  - Remove no longer needed build-depends on libpar2-dev and libsigc++-dev
* debian/nzbget.conf
  - Update sample configuration file to include new options introduced by
    new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * This file is part of nzbget
3
3
 *
4
 
 * Copyright (C) 2012-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
 
4
 * Copyright (C) 2012-2014 Andrey Prygunkov <hugbug@users.sourceforge.net>
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
17
17
 * along with this program; if not, write to the Free Software
18
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
19
 *
20
 
 * $Revision: 671 $
21
 
 * $Date: 2013-05-08 23:50:47 +0200 (Wed, 08 May 2013) $
 
20
 * $Revision: 1112 $
 
21
 * $Date: 2014-08-28 22:51:29 +0200 (Thu, 28 Aug 2014) $
22
22
 *
23
23
 */
24
24
 
40
40
        var $DownloadsTabBadgeEmpty;
41
41
        var $DownloadQueueEmpty;
42
42
        var $DownloadsRecordsPerPage;
 
43
        var $DownloadsTable_Name;
43
44
 
44
45
        // State
45
46
        var notification = null;
46
47
        var updateTabInfo;
47
48
        var groups;
48
49
        var urls;
 
50
        var nameColumnWidth = null;
 
51
        var minLevel = null;
 
52
 
 
53
        var statusData = {
 
54
                'QUEUED': { Text: 'QUEUED', PostProcess: false },
 
55
                'FETCHING': { Text: 'FETCHING', PostProcess: false },
 
56
                'DOWNLOADING': { Text: 'DOWNLOADING', PostProcess: false },
 
57
                'PP_QUEUED': { Text: 'PP-QUEUED', PostProcess: true },
 
58
                'PAUSED': { Text: 'PAUSED', PostProcess: false },
 
59
                'LOADING_PARS': { Text: 'CHECKING', PostProcess: true },
 
60
                'VERIFYING_SOURCES': { Text: 'CHECKING', PostProcess: true },
 
61
                'REPAIRING': { Text: 'REPAIRING', PostProcess: true },
 
62
                'VERIFYING_REPAIRED': { Text: 'VERIFYING', PostProcess: true },
 
63
                'RENAMING': { Text: 'RENAMING', PostProcess: true },
 
64
                'MOVING': { Text: 'MOVING', PostProcess: true },
 
65
                'UNPACKING': { Text: 'UNPACKING', PostProcess: true },
 
66
                'EXECUTING_SCRIPT': { Text: 'PROCESSING', PostProcess: true },
 
67
                'PP_FINISHED': { Text: 'FINISHED', PostProcess: false }
 
68
                };
 
69
        this.statusData = statusData;
49
70
 
50
71
        this.init = function(options)
51
72
        {
56
77
                $DownloadsTabBadgeEmpty = $('#DownloadsTabBadgeEmpty');
57
78
                $DownloadQueueEmpty = $('#DownloadQueueEmpty');
58
79
                $DownloadsRecordsPerPage = $('#DownloadsRecordsPerPage');
 
80
                $DownloadsTable_Name = $('#DownloadsTable_Name');
59
81
 
60
82
                var recordsPerPage = UISettings.read('$DownloadsRecordsPerPage', 10);
61
83
                $DownloadsRecordsPerPage.val(recordsPerPage);
93
115
 
94
116
        this.update = function()
95
117
        {
96
 
                RPC.call('listgroups', [], groups_loaded);
 
118
                if (!groups)
 
119
                {
 
120
                        $('#DownloadsTable_Category').css('width', DownloadsUI.calcCategoryColumnWidth());
 
121
                }
 
122
                
 
123
                RPC.call('listgroups', [100], groups_loaded);
97
124
        }
98
125
 
99
126
        function groups_loaded(_groups)
100
127
        {
101
128
                groups = _groups;
102
 
                RPC.call('postqueue', [100], posts_loaded);
103
 
        }
104
 
 
105
 
        function posts_loaded(posts)
106
 
        {
107
 
                mergequeues(posts);
108
129
                prepare();
109
 
                RPC.call('urlqueue', [], urls_loaded);
110
 
        }
111
 
 
112
 
        function urls_loaded(_urls)
113
 
        {
114
 
                urls = _urls;
115
130
                RPC.next();
116
131
        }
117
132
 
118
 
        function mergequeues(posts)
119
 
        {
120
 
                var lastPPItemIndex = -1;
121
 
                for (var i=0, il=posts.length; i < il; i++)
122
 
                {
123
 
                        var post = posts[i];
124
 
                        var found = false;
125
 
                        for (var j=0, jl=groups.length; j < jl; j++)
126
 
                        {
127
 
                                var group = groups[j];
128
 
                                if (group.NZBID === post.NZBID)
129
 
                                {
130
 
                                        found = true;
131
 
                                        if (!group.post)
132
 
                                        {
133
 
                                                group.post = post;
134
 
                                        }
135
 
                                        lastPPItemIndex = j;
136
 
                                        break;
137
 
                                }
138
 
                        }
139
 
 
140
 
                        if (!found)
141
 
                        {
142
 
                                // create a virtual group-item
143
 
                                var group = {post: post};
144
 
                                group.NZBID = post.NZBID;
145
 
                                group.NZBName = post.NZBName;
146
 
                                group.MaxPriority = 0;
147
 
                                group.Category = '';
148
 
                                group.LastID = 0;
149
 
                                group.MinPostTime = 0;
150
 
                                group.FileSizeMB = 0;
151
 
                                group.FileSizeLo = 0;
152
 
                                group.RemainingSizeMB = 0;
153
 
                                group.RemainingSizeLo = 0;
154
 
                                group.PausedSizeMB = 0;
155
 
                                group.PausedSizeLo = 0;
156
 
                                group.FileCount = 0;
157
 
                                group.RemainingFileCount = 0;
158
 
                                group.RemainingParCount = 0;
159
 
 
160
 
                                // insert it after the last pp-item
161
 
                                if (lastPPItemIndex > -1)
162
 
                                {
163
 
                                        groups.splice(lastPPItemIndex + 1, 0, group);
164
 
                                }
165
 
                                else
166
 
                                {
167
 
                                        groups.unshift(group);
168
 
                                }
169
 
                        }
170
 
                }
171
 
        }
172
 
 
173
133
        function prepare()
174
134
        {
175
135
                for (var j=0, jl=groups.length; j < jl; j++)
176
136
                {
177
 
                        detectStatus(groups[j]);
 
137
                        var group = groups[j];
 
138
                        group.postprocess = statusData[group.Status].PostProcess;
178
139
                }
179
140
        }
180
141
 
187
148
                Util.show($DownloadQueueEmpty, groups.length === 0);
188
149
        }
189
150
 
 
151
        this.resize = function()
 
152
        {
 
153
                calcProgressLabels();
 
154
        }
 
155
        
190
156
        /*** TABLE *************************************************************************/
191
157
 
192
158
        function redraw_table()
198
164
                        var group = groups[i];
199
165
 
200
166
                        var nametext = group.NZBName;
 
167
                        var statustext = DownloadsUI.buildStatusText(group);
201
168
                        var priority = DownloadsUI.buildPriorityText(group.MaxPriority);
202
169
                        var estimated = DownloadsUI.buildEstimated(group);
203
170
                        var age = Util.formatAge(group.MinPostTime + UISettings.timeZoneCorrection*60*60);
204
171
                        var size = Util.formatSizeMB(group.FileSizeMB, group.FileSizeLo);
205
172
                        var remaining = Util.formatSizeMB(group.RemainingSizeMB-group.PausedSizeMB, group.RemainingSizeLo-group.PausedSizeLo);
206
 
 
 
173
                        var dupe = DownloadsUI.buildDupeText(group.DupeKey, group.DupeScore, group.DupeMode);
 
174
                        
207
175
                        var item =
208
176
                        {
209
177
                                id: group.NZBID,
210
178
                                group: group,
211
179
                                data: { age: age, estimated: estimated, size: size, remaining: remaining },
212
 
                                search: group.status + ' ' + nametext + ' ' + priority + ' ' + group.Category + ' ' + age + ' ' + size + ' ' + remaining + ' ' + estimated
 
180
                                search: statustext + ' ' + nametext + ' ' + priority + ' ' + dupe + ' ' + group.Category + ' ' + age + ' ' + size + ' ' + remaining + ' ' + estimated
213
181
                        };
214
182
 
215
183
                        data.push(item);
224
192
 
225
193
                var status = DownloadsUI.buildStatus(group);
226
194
                var priority = DownloadsUI.buildPriority(group.MaxPriority);
227
 
                var progresslabel = DownloadsUI.buildProgressLabel(group);
 
195
                var progresslabel = DownloadsUI.buildProgressLabel(group, nameColumnWidth);
228
196
                var progress = DownloadsUI.buildProgress(group, item.data.size, item.data.remaining, item.data.estimated);
229
 
 
230
 
                var name = '<a href="#" nzbid="' + group.NZBID + '">' + Util.textToHtml(Util.formatNZBName(group.NZBName)) + '</a>';
 
197
                var dupe = DownloadsUI.buildDupe(group.DupeKey, group.DupeScore, group.DupeMode);
 
198
                
 
199
                var age = new Date().getTime() / 1000 - (group.MinPostTime + UISettings.timeZoneCorrection*60*60);
 
200
                var propagation = '';
 
201
                if (group.ActiveDownloads == 0 && age < parseInt(Options.option('PropagationDelay')) * 60)
 
202
                {
 
203
                        propagation = '<span class="label label-warning" title="Very recent post, temporary delayed (see option PropagationDelay)">delayed</span> ';
 
204
                }
 
205
 
 
206
                var name = '<a href="#" data-nzbid="' + group.NZBID + '">' + Util.textToHtml(Util.formatNZBName(group.NZBName)) + '</a>';
 
207
 
 
208
                var url = '';
 
209
                if (group.Kind === 'URL')
 
210
                {
 
211
                        url = '<span class="label label-info">URL</span> ';
 
212
                }
 
213
                
 
214
                var health = '';
 
215
                if (group.Health < 1000 && (!group.postprocess ||
 
216
                        (group.Status === 'PP_QUEUED' && group.PostTotalTimeSec === 0)))
 
217
                {
 
218
                        health = ' <span class="label ' + 
 
219
                                (group.Health >= group.CriticalHealth ? 'label-warning' : 'label-important') +
 
220
                                '">health: ' + Math.floor(group.Health / 10) + '%</span> ';
 
221
                }
 
222
 
 
223
                var backup = '';
 
224
                var backupPercent = calcBackupPercent(group);
 
225
                if (backupPercent > 0)
 
226
                {
 
227
                        backup = ' <a href="#" data-nzbid="' + group.NZBID + '" data-area="backup" class="badge-link"><span class="label label-warning" title="using backup news servers">backup: ' + 
 
228
                                (backupPercent < 10 ? Util.round1(backupPercent) : Util.round0(backupPercent)) + '%</span> ';
 
229
                }
 
230
                
231
231
                var category = Util.textToHtml(group.Category);
232
232
 
233
233
                if (!UISettings.miniTheme)
234
234
                {
235
 
                        var info = name + ' ' + priority + progresslabel;
 
235
                        var info = name + ' ' + url + priority + dupe + health + backup + propagation + progresslabel;
236
236
                        item.fields = ['<div class="check img-check"></div>', status, info, category, item.data.age, progress, item.data.estimated];
237
237
                }
238
238
                else
239
239
                {
240
 
                        var info = '<div class="check img-check"></div><span class="row-title">' + name + '</span>' +
241
 
                                ' ' + (group.status === 'queued' ? '' : status) + ' ' + priority;
 
240
                        var info = '<div class="check img-check"></div><span class="row-title">' + name + '</span>' + url +
 
241
                                ' ' + (group.Status === 'QUEUED' ? '' : status) + ' ' + priority + dupe + health + backup + propagation;
242
242
                        if (category)
243
243
                        {
244
244
                                info += ' <span class="label label-status">' + category + '</span>';
259
259
                        cell.className = 'text-right';
260
260
                }
261
261
        }
262
 
 
263
 
        function detectStatus(group)
 
262
        
 
263
        function calcBackupPercent(group)
264
264
        {
265
 
                group.paused = (group.PausedSizeLo != 0) && (group.RemainingSizeLo == group.PausedSizeLo);
266
 
                group.postprocess = group.post !== undefined;
267
 
                if (group.postprocess)
268
 
                {
269
 
                        switch (group.post.Stage)
270
 
                        {
271
 
                                case 'QUEUED': group.status = 'pp-queued'; break;
272
 
                                case 'LOADING_PARS': group.status = 'checking'; break;
273
 
                                case 'VERIFYING_SOURCES': group.status = 'checking'; break;
274
 
                                case 'REPAIRING': group.status = 'repairing'; break;
275
 
                                case 'VERIFYING_REPAIRED': group.status = 'verifying'; break;
276
 
                                case 'RENAMING': group.status = 'renaming'; break;
277
 
                                case 'MOVING': group.status = 'moving'; break;
278
 
                                case 'UNPACKING': group.status = 'unpacking'; break;
279
 
                                case 'EXECUTING_SCRIPT': group.status = 'processing'; break;
280
 
                                case 'FINISHED': group.status = 'finished'; break;
281
 
                                default: group.status = 'error: ' + group.post.Stage; break;
 
265
                var downloadedArticles = group.SuccessArticles + group.FailedArticles;
 
266
                if (downloadedArticles === 0)
 
267
                {
 
268
                        return 0;
 
269
                }
 
270
                
 
271
                if (minLevel === null)
 
272
                {
 
273
                        for (var i=0; i < Status.status.NewsServers.length; i++)
 
274
                        {
 
275
                                var server = Status.status.NewsServers[i];
 
276
                                var level = parseInt(Options.option('Server' + server.ID + '.Level'));
 
277
                                if (minLevel === null || minLevel > level)
 
278
                                {
 
279
                                        minLevel = level;
 
280
                                }
 
281
                        }       
 
282
                }
 
283
                
 
284
                var backupArticles = 0;
 
285
                for (var j=0; j < group.ServerStats.length; j++)
 
286
                {
 
287
                        var stat = group.ServerStats[j];
 
288
                        var level = parseInt(Options.option('Server' + stat.ServerID + '.Level'));
 
289
                        if (level > minLevel && stat.SuccessArticles > 0)
 
290
                        {
 
291
                                backupArticles += stat.SuccessArticles;
282
292
                        }
283
293
                }
284
 
                else if (group.ActiveDownloads > 0)
285
 
                {
286
 
                        group.status = 'downloading';
287
 
                }
288
 
                else if (group.paused)
289
 
                {
290
 
                        group.status = 'paused';
291
 
                }
292
 
                else
293
 
                {
294
 
                        group.status = 'queued';
295
 
                }
 
294
 
 
295
                var backupPercent = 0;
 
296
                if (backupArticles > 0)
 
297
                {
 
298
                        backupPercent = backupArticles * 100.0 / downloadedArticles;
 
299
                }
 
300
                return backupPercent;
296
301
        }
297
302
 
298
303
        this.recordsPerPageChange = function()
307
312
                updateTabInfo($DownloadsTabBadge, stat);
308
313
        }
309
314
 
 
315
        function calcProgressLabels()
 
316
        {
 
317
                var progressLabels = $('.label-inline', $DownloadsTable);
 
318
 
 
319
                if (UISettings.miniTheme)
 
320
                {
 
321
                        nameColumnWidth = null;
 
322
                        progressLabels.css('max-width', '');
 
323
                        return;
 
324
                }
 
325
 
 
326
                progressLabels.hide();
 
327
                nameColumnWidth = Math.max($DownloadsTable_Name.width(), 50) - 4*2;  // 4 - padding of span
 
328
                progressLabels.css('max-width', nameColumnWidth);
 
329
                progressLabels.show();
 
330
        }
 
331
        
310
332
        /*** EDIT ******************************************************/
311
333
 
312
 
        function itemClick()
 
334
        function itemClick(e)
313
335
        {
314
 
                var nzbid = $(this).attr('nzbid');
 
336
                e.preventDefault();
 
337
                var nzbid = $(this).attr('data-nzbid');
 
338
                var area = $(this).attr('data-area');
315
339
                $(this).blur();
316
 
                DownloadsEditDialog.showModal(nzbid, groups);
 
340
                DownloadsEditDialog.showModal(nzbid, groups, area);
317
341
        }
318
342
 
319
343
        function editCompleted()
328
352
 
329
353
        /*** CHECKMARKS ******************************************************/
330
354
 
331
 
        function checkBuildEditIDList(UseLastID)
 
355
        function checkBuildEditIDList(allowPostProcess, allowUrl)
332
356
        {
333
357
                var checkedRows = $DownloadsTable.fasttable('checkedRows');
334
358
 
339
363
                        var group = groups[i];
340
364
                        if (checkedRows.indexOf(group.NZBID) > -1)
341
365
                        {
342
 
                                if (group.postprocess)
 
366
                                if (group.postprocess && !allowPostProcess)
343
367
                                {
344
368
                                        Notification.show('#Notif_Downloads_CheckPostProcess');
345
369
                                        return null;
346
370
                                }
 
371
                                if (group.Kind === 'URL' && !allowUrl)
 
372
                                {
 
373
                                        Notification.show('#Notif_Downloads_CheckURL');
 
374
                                        return null;
 
375
                                }
347
376
 
348
 
                                checkedEditIDs.push(UseLastID ? group.LastID : group.NZBID);
 
377
                                checkedEditIDs.push(group.NZBID);
349
378
                        }
350
379
                }
351
380
 
362
391
 
363
392
        this.editClick = function()
364
393
        {
365
 
                var checkedEditIDs = checkBuildEditIDList(false);
 
394
                var checkedEditIDs = checkBuildEditIDList(false, true);
366
395
                if (!checkedEditIDs)
367
396
                {
368
397
                        return;
380
409
 
381
410
        this.mergeClick = function()
382
411
        {
383
 
                var checkedEditIDs = checkBuildEditIDList(false);
 
412
                var checkedEditIDs = checkBuildEditIDList(false, false);
384
413
                if (!checkedEditIDs)
385
414
                {
386
415
                        return;
397
426
 
398
427
        this.pauseClick = function()
399
428
        {
400
 
                var checkedEditIDs = checkBuildEditIDList(true);
 
429
                var checkedEditIDs = checkBuildEditIDList(false, false);
401
430
                if (!checkedEditIDs)
402
431
                {
403
432
                        return;
408
437
 
409
438
        this.resumeClick = function()
410
439
        {
411
 
                var checkedEditIDs = checkBuildEditIDList(true);
 
440
                var checkedEditIDs = checkBuildEditIDList(false, false);
412
441
                if (!checkedEditIDs)
413
442
                {
414
443
                        return;
432
461
                var checkedRows = $DownloadsTable.fasttable('checkedRows');
433
462
                var downloadIDs = [];
434
463
                var postprocessIDs = [];
 
464
                var hasNzb = false;
 
465
                var hasUrl = false;
435
466
                for (var i = 0; i < groups.length; i++)
436
467
                {
437
468
                        var group = groups[i];
439
470
                        {
440
471
                                if (group.postprocess)
441
472
                                {
442
 
                                        postprocessIDs.push(group.post.ID);
443
 
                                }
444
 
                                if (group.LastID > 0)
445
 
                                {
446
 
                                        downloadIDs.push(group.LastID);
447
 
                                }
 
473
                                        postprocessIDs.push(group.NZBID);
 
474
                                }
 
475
                                downloadIDs.push(group.NZBID);
 
476
                                hasNzb = hasNzb || group.Kind === 'NZB';
 
477
                                hasUrl = hasUrl || group.Kind === 'URL';
448
478
                        }
449
479
                }
450
480
 
468
498
                        }
469
499
                };
470
500
 
471
 
                var deleteGroups = function()
 
501
                var deleteGroups = function(command)
472
502
                {
473
503
                        if (downloadIDs.length > 0)
474
504
                        {
475
 
                                RPC.call('editqueue', ['GroupDelete', 0, '', downloadIDs], deletePosts);
 
505
                                RPC.call('editqueue', [command, 0, '', downloadIDs], deletePosts);
476
506
                        }
477
507
                        else
478
508
                        {
480
510
                        }
481
511
                };
482
512
 
483
 
                Util.show('#DownloadsDeleteConfirmDialog_Cleanup', Options.option('DeleteCleanupDisk') === 'yes');
484
 
                Util.show('#DownloadsDeleteConfirmDialog_Remain', Options.option('DeleteCleanupDisk') != 'yes');
485
 
                
486
 
                ConfirmDialog.showModal('DownloadsDeleteConfirmDialog', deleteGroups);
 
513
                DownloadsUI.deleteConfirm(deleteGroups, true, hasNzb, hasUrl);
487
514
        }
488
515
 
489
516
        this.moveClick = function(action)
490
517
        {
491
 
                var checkedEditIDs = checkBuildEditIDList(true);
 
518
                var checkedEditIDs = checkBuildEditIDList(true, true);
492
519
                if (!checkedEditIDs)
493
520
                {
494
521
                        return;
528
555
{
529
556
        'use strict';
530
557
        
 
558
        // State
 
559
        var categoryColumnWidth = null;
 
560
        var dupeCheck = null;
 
561
        
531
562
        this.fillPriorityCombo = function(combo)
532
563
        {
533
564
                combo.empty();
 
565
                combo.append('<option value="900">force</option>');
 
566
                combo.append('<option value="100">very high</option>');
 
567
                combo.append('<option value="50">high</option>');
 
568
                combo.append('<option value="0">normal</option>');
 
569
                combo.append('<option value="-50">low</option>');
534
570
                combo.append('<option value="-100">very low</option>');
535
 
                combo.append('<option value="-50">low</option>');
536
 
                combo.append('<option value="0">normal</option>');
537
 
                combo.append('<option value="50">high</option>');
538
 
                combo.append('<option value="100">very high</option>');
539
571
        }
540
572
 
541
573
        this.fillCategoryCombo = function(combo)
549
581
                }
550
582
        }
551
583
 
 
584
        this.buildStatusText = function(group)
 
585
        {
 
586
                var statusText = Downloads.statusData[group.Status].Text;
 
587
                if (statusText === undefined)
 
588
                {
 
589
                        statusText = 'Internal error(' + group.Status + ')';
 
590
                }
 
591
                return statusText;
 
592
        }
 
593
                
552
594
        this.buildStatus = function(group)
553
595
        {
554
 
                if (group.postprocess && group.status !== 'pp-queued')
555
 
                {
556
 
                        if (Status.status.PostPaused)
557
 
                        {
558
 
                                return '<span class="label label-status label-warning">' + group.status + '</span>';
559
 
                        }
560
 
                        else
561
 
                        {
562
 
                                return '<span class="label label-status label-success">' + group.status + '</span>';
563
 
                        }
564
 
                }
565
 
                switch (group.status)
566
 
                {
567
 
                        case 'pp-queued': return '<span class="label label-status">pp-queued</span>';
568
 
                        case 'downloading': return '<span class="label label-status label-success">downloading</span>';
569
 
                        case 'paused': return '<span class="label label-status label-warning">paused</span>';
570
 
                        case 'queued': return '<span class="label label-status">queued</span>';
571
 
                        default: return '<span class="label label-status label-important">internal error(' + group.status + ')</span>';
572
 
                }
 
596
                var statusText = Downloads.statusData[group.Status].Text;
 
597
                var badgeClass = '';
 
598
                
 
599
                if (group.postprocess && group.Status !== 'PP_QUEUED')
 
600
                {
 
601
                        badgeClass = Status.status.PostPaused && group.MinPriority < 900 ? 'label-warning' : 'label-success';
 
602
                }
 
603
                else if (group.Status === 'DOWNLOADING' || group.Status === 'FETCHING')
 
604
                {
 
605
                        badgeClass = 'label-success';
 
606
                }
 
607
                else if (group.Status === 'PAUSED')
 
608
                {
 
609
                        badgeClass = 'label-warning';
 
610
                }
 
611
                else if (statusText === undefined)
 
612
                {
 
613
                        statusText = 'INTERNAL_ERROR (' + group.Status + ')';
 
614
                        badgeClass = 'label-important';
 
615
                }
 
616
                
 
617
                return '<span class="label label-status ' + badgeClass + '">' + statusText + '</span>';
573
618
        }
574
619
 
575
620
        this.buildProgress = function(group, totalsize, remaining, estimated)
576
621
        {
577
 
                if (group.status === 'downloading' || (group.postprocess && !Status.status.PostPaused))
 
622
                if (group.Status === 'DOWNLOADING' ||
 
623
                        (group.postprocess && !(Status.status.PostPaused && group.MinPriority < 900)))
578
624
                {
579
625
                        var kind = 'progress-success';
580
626
                }
581
 
                else if (group.status === 'paused' || (group.postprocess && Status.status.PostPaused))
 
627
                else if (group.Status === 'PAUSED' ||
 
628
                        (group.postprocess && !(Status.status.PostPaused && group.MinPriority < 900)))
582
629
                {
583
630
                        var kind = 'progress-warning';
584
631
                }
596
643
                {
597
644
                        totalsize = '';
598
645
                        remaining = '';
599
 
                        percent = Math.round(group.post.StageProgress / 10);
 
646
                        percent = Math.round(group.PostStageProgress / 10);
 
647
                }
 
648
                
 
649
                if (group.Kind === 'URL')
 
650
                {
 
651
                        totalsize = '';
 
652
                        remaining = '';
600
653
                }
601
654
 
602
655
                if (!UISettings.miniTheme)
630
683
        {
631
684
                if (group.postprocess)
632
685
                {
633
 
                        if (group.post.StageProgress > 0)
 
686
                        if (group.PostStageProgress > 0)
634
687
                        {
635
 
                                return Util.formatTimeLeft(group.post.StageTimeSec / group.post.StageProgress * (1000 - group.post.StageProgress));
 
688
                                return Util.formatTimeLeft(group.PostStageTimeSec / group.PostStageProgress * (1000 - group.PostStageProgress));
636
689
                        }
637
690
                }
638
 
                else if (!group.paused && Status.status.DownloadRate > 0)
 
691
                else if (group.Status !== 'PAUSED' && Status.status.DownloadRate > 0)
639
692
                {
640
693
                        return Util.formatTimeLeft((group.RemainingSizeMB-group.PausedSizeMB)*1024/(Status.status.DownloadRate/1024));
641
694
                }
643
696
                return '';
644
697
        }
645
698
 
646
 
        this.buildProgressLabel = function(group)
 
699
        this.buildProgressLabel = function(group, maxWidth)
647
700
        {
648
701
                var text = '';
649
 
                if (group.postprocess && !Status.status.PostPaused)
 
702
                if (group.postprocess && !(Status.status.PostPaused && group.MinPriority < 900))
650
703
                {
651
 
                        switch (group.post.Stage)
 
704
                        switch (group.Status)
652
705
                        {
653
706
                                case "REPAIRING":
654
707
                                        break;
657
710
                                case "VERIFYING_REPAIRED":
658
711
                                case "UNPACKING":
659
712
                                case "RENAMING":
660
 
                                        text = group.post.ProgressLabel;
 
713
                                        text = group.PostInfoText;
661
714
                                        break;
662
715
                                case "EXECUTING_SCRIPT":
663
 
                                        if (group.post.Log && group.post.Log.length > 0)
 
716
                                        if (group.Log && group.Log.length > 0)
664
717
                                        {
665
 
                                                text = group.post.Log[group.post.Log.length-1].Text;
 
718
                                                text = group.Log[group.Log.length-1].Text;
666
719
                                                // remove "for <nzb-name>" from label text
667
720
                                                text = text.replace(' for ' + group.NZBName, ' ');
668
721
                                        }
669
722
                                        else
670
723
                                        {
671
 
                                                text = group.post.ProgressLabel;
 
724
                                                text = group.PostInfoText;
672
725
                                        }
673
726
                                        break;
674
727
                        }
675
728
                }
676
729
 
677
 
                return text !== '' ? ' <span class="label label-success">' + text + '</span>' : '';
 
730
                return text !== '' ? ' <span class="label label-success label-inline" style="max-width:' +
 
731
                        maxWidth +'px">' + text + '</span>' : '';
678
732
        }
679
733
 
680
734
        this.buildPriorityText = function(priority)
682
736
                switch (priority)
683
737
                {
684
738
                        case 0: return '';
 
739
                        case 900: return 'force priority';
685
740
                        case 100: return 'very high priority';
686
741
                        case 50: return 'high priority';
687
742
                        case -50: return 'low priority';
695
750
                switch (priority)
696
751
                {
697
752
                        case 0: return '';
 
753
                        case 900: return ' <span class="label label-priority label-important">force priority</span>';
698
754
                        case 100: return ' <span class="label label-priority label-important">very high priority</span>';
699
755
                        case 50: return ' <span class="label label-priority label-important">high priority</span>';
700
756
                        case -50: return ' <span class="label label-priority label-info">low priority</span>';
709
765
                        return ' <span class="label label-priority label-info">priority: ' + priority + '</span>';
710
766
                }
711
767
        }
 
768
        
 
769
        function formatDupeText(dupeKey, dupeScore, dupeMode)
 
770
        {
 
771
                dupeKey = dupeKey.replace('rageid=', '');
 
772
                dupeKey = dupeKey.replace('imdb=', '');
 
773
                dupeKey = dupeKey.replace('series=', '');
 
774
                dupeKey = dupeKey.replace('nzb=', '#');
 
775
                dupeKey = dupeKey.replace('=', ' ');
 
776
                dupeKey = dupeKey === '' ? 'title' : dupeKey;
 
777
                return dupeKey;
 
778
        }
 
779
 
 
780
        this.buildDupeText = function(dupeKey, dupeScore, dupeMode)
 
781
        {
 
782
                if (dupeCheck == null)
 
783
                {
 
784
                        dupeCheck = Options.option('DupeCheck') === 'yes';
 
785
                }
 
786
 
 
787
                if (dupeCheck && dupeKey != '' && UISettings.dupeBadges)
 
788
                {
 
789
                        return formatDupeText(dupeKey, dupeScore, dupeMode);
 
790
                }
 
791
                else
 
792
                {
 
793
                        return '';
 
794
                }
 
795
        }
 
796
 
 
797
        this.buildDupe = function(dupeKey, dupeScore, dupeMode)
 
798
        {
 
799
                if (dupeCheck == null)
 
800
                {
 
801
                        dupeCheck = Options.option('DupeCheck') === 'yes';
 
802
                }
 
803
 
 
804
                if (dupeCheck && dupeKey != '' && UISettings.dupeBadges)
 
805
                {
 
806
                        return ' <span class="label' + (dupeMode === 'FORCE' ? ' label-important' : '') +
 
807
                                '" title="Duplicate key: ' + dupeKey +
 
808
                                (dupeScore !== 0 ? '; score: ' + dupeScore : '') +
 
809
                                (dupeMode !== 'SCORE' ? '; mode: ' + dupeMode.toLowerCase() : '') +
 
810
                                '">' + formatDupeText(dupeKey, dupeScore, dupeMode) + '</span> ';
 
811
                }
 
812
                else
 
813
                {
 
814
                        return '';
 
815
                }
 
816
        }
 
817
 
 
818
        this.resetCategoryColumnWidth = function()
 
819
        {
 
820
                categoryColumnWidth = null;
 
821
        }
 
822
 
 
823
        this.calcCategoryColumnWidth = function()
 
824
        {
 
825
                if (categoryColumnWidth === null)
 
826
                {
 
827
                        var widthHelper = $('<div></div>').css({'position': 'absolute', 'float': 'left', 'white-space': 'nowrap', 'visibility': 'hidden'}).appendTo($('body'));
 
828
 
 
829
                        // default (min) width
 
830
                        categoryColumnWidth = 60;
 
831
 
 
832
                        for (var i = 1; ; i++)
 
833
                        {
 
834
                                var opt = Options.option('Category' + i + '.Name');
 
835
                                if (!opt)
 
836
                                {
 
837
                                        break;
 
838
                                }
 
839
                                widthHelper.text(opt);
 
840
                                var catWidth = widthHelper.width();
 
841
                                categoryColumnWidth = Math.max(categoryColumnWidth, catWidth);
 
842
                        }
 
843
                                                
 
844
                        widthHelper.remove();
 
845
                        
 
846
                        categoryColumnWidth += 'px';
 
847
                }
 
848
 
 
849
                return categoryColumnWidth;
 
850
        }
 
851
 
 
852
        this.deleteConfirm = function(actionCallback, multi, hasNzb, hasUrl)
 
853
        {
 
854
                var dupeCheck = Options.option('DupeCheck') === 'yes';
 
855
                var cleanupDisk = Options.option('DeleteCleanupDisk') === 'yes';
 
856
                var history = Options.option('KeepHistory') !== '0';
 
857
                var dialog = null;
 
858
 
 
859
                function init(_dialog)
 
860
                {
 
861
                        dialog = _dialog;
 
862
 
 
863
                        if (!multi)
 
864
                        {
 
865
                                var html = $('#ConfirmDialog_Text').html();
 
866
                                html = html.replace(/downloads/g, 'download');
 
867
                                $('#ConfirmDialog_Text').html(html);
 
868
                        }
 
869
 
 
870
                        $('#DownloadsDeleteConfirmDialog_Delete', dialog).prop('checked', true);
 
871
                        $('#DownloadsDeleteConfirmDialog_Delete', dialog).prop('checked', true);
 
872
                        $('#DownloadsDeleteConfirmDialog_DeleteDupe', dialog).prop('checked', false);
 
873
                        $('#DownloadsDeleteConfirmDialog_DeleteFinal', dialog).prop('checked', false);
 
874
                        Util.show($('#DownloadsDeleteConfirmDialog_Options', dialog), history);
 
875
                        Util.show($('#DownloadsDeleteConfirmDialog_Simple', dialog), !history);
 
876
                        Util.show($('#DownloadsDeleteConfirmDialog_DeleteDupe,#DownloadsDeleteConfirmDialog_DeleteDupeLabel', dialog), dupeCheck && hasNzb);
 
877
                        Util.show($('#DownloadsDeleteConfirmDialog_Remain', dialog), !cleanupDisk && hasNzb);
 
878
                        Util.show($('#DownloadsDeleteConfirmDialog_Cleanup', dialog), cleanupDisk && hasNzb);
 
879
                        Util.show('#ConfirmDialog_Help', history && dupeCheck && hasNzb);
 
880
                };
 
881
 
 
882
                function action()
 
883
                {
 
884
                        var deleteNormal = $('#DownloadsDeleteConfirmDialog_Delete', dialog).is(':checked');
 
885
                        var deleteDupe = $('#DownloadsDeleteConfirmDialog_DeleteDupe', dialog).is(':checked');
 
886
                        var deleteFinal = $('#DownloadsDeleteConfirmDialog_DeleteFinal', dialog).is(':checked');
 
887
                        var command = deleteNormal ? 'GroupDelete' : (deleteDupe ? 'GroupDupeDelete' : 'GroupFinalDelete');
 
888
                        actionCallback(command);
 
889
                }
 
890
 
 
891
                ConfirmDialog.showModal('DownloadsDeleteConfirmDialog', action, init);
 
892
        }
712
893
}(jQuery));