2008-05-17 16:44:42 +04:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2014-12-08 00:52:29 +03:00
ATTACH MOCHA LINK EVENTS
Notes : Here is where you define your windows and the events that open them .
If you are not using links to run Mocha methods you can remove this function .
2012-07-01 14:23:41 +04:00
2014-12-08 00:52:29 +03:00
If you need to add link events to links within windows you are creating , do
it in the onContentLoaded function of the new window .
2008-05-17 16:44:42 +04:00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /
2014-11-30 01:40:26 +03:00
/* Define localStorage object for older browsers */
if ( typeof localStorage == 'undefined' ) {
window [ 'localStorage' ] = {
getItem : function ( name ) {
return Cookie . read ( name ) ;
} ,
setItem : function ( name , value ) {
2014-11-30 16:14:09 +03:00
Cookie . write ( name , value , {
duration : 365 * 10
} ) ;
2014-11-30 01:40:26 +03:00
}
2017-07-01 07:42:20 +03:00
} ;
2014-11-30 01:40:26 +03:00
}
2014-12-08 03:03:53 +03:00
function getLocalStorageItem ( name , defaultVal ) {
2018-09-27 06:10:51 +03:00
var val = localStorage . getItem ( name ) ;
2014-12-08 03:03:53 +03:00
if ( val === null || val === undefined )
val = defaultVal ;
return val ;
}
2015-01-29 22:29:28 +03:00
var deleteFN = function ( ) { } ;
2015-01-30 00:16:28 +03:00
var startFN = function ( ) { } ;
var pauseFN = function ( ) { } ;
2015-01-29 22:29:28 +03:00
2014-11-30 16:14:09 +03:00
initializeWindows = function ( ) {
2012-07-01 14:23:41 +04:00
2018-01-24 06:15:44 +03:00
saveWindowSize = function ( windowId ) {
var size = $ ( windowId ) . getSize ( ) ;
localStorage . setItem ( 'window_' + windowId + '_width' , size . x ) ;
localStorage . setItem ( 'window_' + windowId + '_height' , size . y ) ;
} ;
loadWindowWidth = function ( windowId , defaultValue ) {
return getLocalStorageItem ( 'window_' + windowId + '_width' , defaultValue ) ;
} ;
loadWindowHeight = function ( windowId , defaultValue ) {
return getLocalStorageItem ( 'window_' + windowId + '_height' , defaultValue ) ;
} ;
2014-11-30 16:14:09 +03:00
function addClickEvent ( el , fn ) {
[ 'Link' , 'Button' ] . each ( function ( item ) {
if ( $ ( el + item ) ) {
$ ( el + item ) . addEvent ( 'click' , fn ) ;
}
} ) ;
}
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
addClickEvent ( 'download' , function ( e ) {
new Event ( e ) . stop ( ) ;
2017-12-28 06:19:39 +03:00
showDownloadPage ( ) ;
} ) ;
showDownloadPage = function ( urls ) {
2018-01-24 06:15:44 +03:00
var id = 'downloadPage' ;
2017-12-28 06:19:39 +03:00
var contentUrl = 'download.html' ;
if ( urls && urls . length )
contentUrl += '?urls=' + urls . join ( "|" ) ;
2014-11-30 16:14:09 +03:00
new MochaUI . Window ( {
2018-01-24 06:15:44 +03:00
id : id ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Download from URLs)QBT_TR[CONTEXT=downloadFromURL]" ,
2014-11-30 16:14:09 +03:00
loadMethod : 'iframe' ,
2017-12-28 06:19:39 +03:00
contentURL : contentUrl ,
2018-03-08 09:30:13 +03:00
addClass : 'windowFrame' , // fixes iframe scrolling on iOS Safari
2014-11-30 16:14:09 +03:00
scrollbars : true ,
maximizable : false ,
closable : true ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
2018-01-24 06:15:44 +03:00
width : loadWindowWidth ( id , 500 ) ,
height : loadWindowHeight ( id , 420 ) ,
onResize : function ( ) {
saveWindowSize ( id ) ;
}
2014-11-30 16:14:09 +03:00
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2017-12-28 06:19:39 +03:00
} ;
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
addClickEvent ( 'preferences' , function ( e ) {
new Event ( e ) . stop ( ) ;
2018-01-24 06:15:44 +03:00
var id = 'preferencesPage' ;
2014-11-30 16:14:09 +03:00
new MochaUI . Window ( {
2018-01-24 06:15:44 +03:00
id : id ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Options)QBT_TR[CONTEXT=OptionsDialog]" ,
2014-11-30 16:14:09 +03:00
loadMethod : 'xhr' ,
toolbar : true ,
contentURL : 'preferences_content.html' ,
require : {
css : [ 'css/Tabs.css' ]
} ,
toolbarURL : 'preferences.html' ,
maximizable : false ,
closable : true ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
2018-01-24 06:15:44 +03:00
width : loadWindowWidth ( id , 700 ) ,
2018-08-22 07:47:00 +03:00
height : loadWindowHeight ( id , 500 ) ,
2018-01-24 06:15:44 +03:00
onResize : function ( ) {
saveWindowSize ( id ) ;
}
2014-11-30 16:14:09 +03:00
} ) ;
} ) ;
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
addClickEvent ( 'upload' , function ( e ) {
new Event ( e ) . stop ( ) ;
2018-01-24 06:15:44 +03:00
var id = 'uploadPage' ;
2014-11-30 16:14:09 +03:00
new MochaUI . Window ( {
2018-01-24 06:15:44 +03:00
id : id ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]" ,
2014-11-30 16:14:09 +03:00
loadMethod : 'iframe' ,
contentURL : 'upload.html' ,
2018-03-08 09:30:13 +03:00
addClass : 'windowFrame' , // fixes iframe scrolling on iOS Safari
2014-11-30 16:14:09 +03:00
scrollbars : true ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
2018-01-24 06:15:44 +03:00
width : loadWindowWidth ( id , 500 ) ,
height : loadWindowHeight ( id , 260 ) ,
onResize : function ( ) {
saveWindowSize ( id ) ;
}
2014-11-30 16:14:09 +03:00
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 16:14:09 +03:00
} ) ;
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
globalUploadLimitFN = function ( ) {
new MochaUI . Window ( {
id : 'uploadLimitPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Global Upload Speed Limit)QBT_TR[CONTEXT=MainWindow]" ,
2014-11-30 16:14:09 +03:00
loadMethod : 'iframe' ,
2015-02-01 20:08:45 +03:00
contentURL : 'uploadlimit.html?hashes=global' ,
2014-11-30 16:14:09 +03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
2017-07-01 07:42:20 +03:00
} ;
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
uploadLimitFN = function ( ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2014-11-30 16:14:09 +03:00
new MochaUI . Window ( {
id : 'uploadLimitPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Torrent Upload Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]" ,
2014-11-30 16:14:09 +03:00
loadMethod : 'iframe' ,
2017-08-06 12:04:39 +03:00
contentURL : 'uploadlimit.html?hashes=' + hashes . join ( "|" ) ,
2014-11-30 16:14:09 +03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
}
} ;
2012-07-01 14:23:41 +04:00
2018-03-14 07:41:16 +03:00
shareRatioFN = function ( ) {
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
var shareRatio = null ;
var torrentsHaveSameShareRatio = true ;
// check if all selected torrents have same share ratio
2018-05-30 20:06:28 +03:00
for ( var i = 0 ; i < hashes . length ; ++ i ) {
2018-03-14 07:41:16 +03:00
var hash = hashes [ i ] ;
var row = torrentsTable . rows [ hash ] . full _data ;
var origValues = row . ratio _limit + "|" + row . seeding _time _limit + "|" + row . max _ratio + "|" + row . max _seeding _time ;
// initialize value
if ( shareRatio === null )
shareRatio = origValues ;
if ( origValues !== shareRatio ) {
torrentsHaveSameShareRatio = false ;
break ;
}
}
// if all torrents have same share ratio, display that share ratio. else use the default
var orig = torrentsHaveSameShareRatio ? shareRatio : "" ;
new MochaUI . Window ( {
id : 'shareRatioPage' ,
2018-06-14 12:54:23 +03:00
title : "QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDialog]" ,
2018-03-14 07:41:16 +03:00
loadMethod : 'iframe' ,
contentURL : 'shareratio.html?hashes=' + hashes . join ( "|" ) + '&orig=' + orig ,
scrollbars : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 175
} ) ;
}
} ;
2014-12-09 19:54:35 +03:00
toggleSequentialDownloadFN = function ( ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2014-12-09 19:54:35 +03:00
new Request ( {
2018-05-12 06:40:17 +03:00
url : 'api/v2/torrents/toggleSequentialDownload' ,
2014-12-09 19:54:35 +03:00
method : 'post' ,
data : {
2017-08-06 12:04:39 +03:00
hashes : hashes . join ( "|" )
2014-12-09 19:54:35 +03:00
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-12-09 19:54:35 +03:00
}
} ;
toggleFirstLastPiecePrioFN = function ( ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2014-12-09 19:54:35 +03:00
new Request ( {
2018-05-12 06:40:17 +03:00
url : 'api/v2/torrents/toggleFirstLastPiecePrio' ,
2014-12-09 19:54:35 +03:00
method : 'post' ,
data : {
2017-08-06 12:04:39 +03:00
hashes : hashes . join ( "|" )
2014-12-09 19:54:35 +03:00
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-12-09 19:54:35 +03:00
}
} ;
2015-01-30 23:58:27 +03:00
setSuperSeedingFN = function ( val ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2015-01-30 23:58:27 +03:00
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/torrents/setSuperSeeding' ,
2015-01-30 23:58:27 +03:00
method : 'post' ,
data : {
value : val ,
2017-08-06 12:04:39 +03:00
hashes : hashes . join ( "|" )
2015-01-30 23:58:27 +03:00
}
} ) . send ( ) ;
updateMainData ( ) ;
}
} ;
2015-07-14 04:06:34 +03:00
setForceStartFN = function ( ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2015-04-15 20:13:18 +03:00
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/torrents/setForceStart' ,
2015-04-15 20:13:18 +03:00
method : 'post' ,
data : {
2015-07-14 04:06:34 +03:00
value : 'true' ,
2017-08-06 12:04:39 +03:00
hashes : hashes . join ( "|" )
2015-04-15 20:13:18 +03:00
}
} ) . send ( ) ;
updateMainData ( ) ;
}
} ;
2014-11-30 16:14:09 +03:00
globalDownloadLimitFN = function ( ) {
new MochaUI . Window ( {
id : 'downloadLimitPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Global Download Speed Limit)QBT_TR[CONTEXT=MainWindow]" ,
2014-11-30 16:14:09 +03:00
loadMethod : 'iframe' ,
2015-02-01 20:45:37 +03:00
contentURL : 'downloadlimit.html?hashes=global' ,
2014-11-30 16:14:09 +03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
2017-07-01 07:42:20 +03:00
} ;
2012-07-01 14:23:41 +04:00
2017-03-06 06:05:18 +03:00
StatisticsLinkFN = function ( ) {
2018-03-05 09:40:21 +03:00
var id = 'statisticspage' ;
2017-03-06 06:05:18 +03:00
new MochaUI . Window ( {
2018-03-05 09:40:21 +03:00
id : id ,
2017-05-01 01:45:02 +03:00
title : 'QBT_TR(Statistics)QBT_TR[CONTEXT=StatsDialog]' ,
2017-03-06 06:05:18 +03:00
loadMethod : 'xhr' ,
contentURL : 'statistics.html' ,
maximizable : false ,
2018-03-06 08:48:02 +03:00
padding : 10 ,
2018-03-05 09:40:21 +03:00
width : loadWindowWidth ( id , 275 ) ,
height : loadWindowHeight ( id , 370 ) ,
onResize : function ( ) {
saveWindowSize ( id ) ;
}
2017-07-01 07:42:20 +03:00
} ) ;
} ;
2017-03-06 06:05:18 +03:00
2014-11-30 16:14:09 +03:00
downloadLimitFN = function ( ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2014-11-30 16:14:09 +03:00
new MochaUI . Window ( {
id : 'downloadLimitPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Torrent Download Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]" ,
2014-11-30 16:14:09 +03:00
loadMethod : 'iframe' ,
2017-08-06 12:04:39 +03:00
contentURL : 'downloadlimit.html?hashes=' + hashes . join ( "|" ) ,
2014-11-30 16:14:09 +03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
}
} ;
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
deleteFN = function ( ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2014-11-30 16:14:09 +03:00
new MochaUI . Window ( {
id : 'confirmDeletionPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Deletion confirmation)QBT_TR[CONTEXT=confirmDeletionDlg]" ,
2014-11-30 16:14:09 +03:00
loadMethod : 'iframe' ,
2017-08-06 12:04:39 +03:00
contentURL : 'confirmdeletion.html?hashes=' + hashes . join ( "|" ) ,
2014-11-30 16:14:09 +03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
padding : 10 ,
width : 424 ,
height : 140
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 16:14:09 +03:00
}
} ;
2009-11-24 22:41:31 +03:00
2014-11-30 16:14:09 +03:00
addClickEvent ( 'delete' , function ( e ) {
new Event ( e ) . stop ( ) ;
deleteFN ( ) ;
} ) ;
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
pauseFN = function ( ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2017-10-14 16:27:21 +03:00
new Request ( {
url : 'api/v2/torrents/pause' ,
method : 'post' ,
data : {
hashes : hashes . join ( "|" )
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 16:14:09 +03:00
}
} ;
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
startFN = function ( ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2017-10-14 16:27:21 +03:00
new Request ( {
url : 'api/v2/torrents/resume' ,
method : 'post' ,
data : {
hashes : hashes . join ( "|" )
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 16:14:09 +03:00
}
} ;
2012-07-01 14:23:41 +04:00
2017-07-05 08:47:23 +03:00
autoTorrentManagementFN = function ( ) {
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
var enable = false ;
hashes . each ( function ( hash , index ) {
var row = torrentsTable . rows [ hash ] ;
if ( ! row . full _data . auto _tmm )
enable = true ;
} ) ;
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/torrents/setAutoManagement' ,
2017-07-05 08:47:23 +03:00
method : 'post' ,
data : {
hashes : hashes . join ( "|" ) ,
enable : enable
}
} ) . send ( ) ;
updateMainData ( ) ;
}
} ;
2014-11-30 16:14:09 +03:00
recheckFN = function ( ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2018-07-23 03:33:39 +03:00
new Request ( {
url : 'api/v2/torrents/recheck' ,
method : 'post' ,
data : {
hashes : hashes . join ( "|" ) ,
}
} ) . send ( ) ;
2015-05-15 22:54:15 +03:00
updateMainData ( ) ;
2018-07-23 03:33:17 +03:00
}
} ;
reannounceFN = function ( ) {
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
new Request ( {
url : 'api/v2/torrents/reannounce' ,
method : 'post' ,
data : {
hashes : hashes . join ( "|" ) ,
}
} ) . send ( ) ;
updateMainData ( ) ;
2014-11-30 16:14:09 +03:00
}
} ;
2008-12-29 00:12:49 +03:00
2017-08-06 12:04:39 +03:00
setLocationFN = function ( ) {
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2018-06-07 20:55:00 +03:00
var hash = hashes [ 0 ] ;
var row = torrentsTable . rows [ hash ] ;
var path = encodeURIComponent ( row . full _data . save _path ) ;
2017-08-06 12:04:39 +03:00
new MochaUI . Window ( {
id : 'setLocationPage' ,
title : "QBT_TR(Set location)QBT_TR[CONTEXT=TransferListWidget]" ,
loadMethod : 'iframe' ,
2018-06-07 20:55:00 +03:00
contentURL : 'setlocation.html?hashes=' + hashes . join ( '|' ) + '&path=' + path ,
2017-08-06 12:04:39 +03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
2018-06-07 20:55:00 +03:00
width : 400 ,
2018-06-08 09:37:34 +03:00
height : 130
2017-08-06 12:04:39 +03:00
} ) ;
}
} ;
2017-07-04 12:54:43 +03:00
renameFN = function ( ) {
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length == 1 ) {
var hash = hashes [ 0 ] ;
var row = torrentsTable . rows [ hash ] ;
if ( row ) {
new MochaUI . Window ( {
id : 'renamePage' ,
title : "QBT_TR(Rename)QBT_TR[CONTEXT=TransferListWidget]" ,
loadMethod : 'iframe' ,
2018-03-14 07:56:57 +03:00
contentURL : 'rename.html?hash=' + hashes [ 0 ] + '&name=' + row . full _data . name ,
2017-07-04 12:54:43 +03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 250 ,
height : 100
} ) ;
}
}
} ;
2018-04-05 06:59:31 +03:00
torrentNewCategoryFN = function ( ) {
2018-07-23 08:49:34 +03:00
var action = "set" ;
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2015-02-15 00:19:54 +03:00
new MochaUI . Window ( {
2016-02-09 11:56:48 +03:00
id : 'newCategoryPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(New Category)QBT_TR[CONTEXT=TransferListWidget]" ,
2015-02-15 00:19:54 +03:00
loadMethod : 'iframe' ,
2018-07-23 08:49:34 +03:00
contentURL : 'newcategory.html?action=' + action + '&hashes=' + hashes . join ( '|' ) ,
2015-02-15 00:19:54 +03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
2015-07-16 02:04:53 +03:00
width : 250 ,
2018-07-23 08:49:34 +03:00
height : 150
2015-02-15 00:19:54 +03:00
} ) ;
}
} ;
2018-04-05 06:59:31 +03:00
torrentSetCategoryFN = function ( categoryHash ) {
2016-02-09 11:56:48 +03:00
var categoryName = '' ;
2017-08-06 12:04:39 +03:00
if ( categoryHash != 0 )
2017-07-01 07:42:20 +03:00
categoryName = category _list [ categoryHash ] . name ;
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2015-07-16 02:04:53 +03:00
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/torrents/setCategory' ,
2015-07-16 02:04:53 +03:00
method : 'post' ,
data : {
2017-08-06 12:04:39 +03:00
hashes : hashes . join ( "|" ) ,
2016-02-09 11:56:48 +03:00
category : categoryName
2015-07-16 02:04:53 +03:00
}
} ) . send ( ) ;
2015-02-15 00:19:54 +03:00
}
} ;
2018-04-05 06:59:31 +03:00
createCategoryFN = function ( ) {
2018-07-23 08:49:34 +03:00
var action = "create" ;
2016-01-21 15:32:13 +03:00
new MochaUI . Window ( {
id : 'newCategoryPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(New Category)QBT_TR[CONTEXT=CategoryFilterWidget]" ,
2016-01-21 15:32:13 +03:00
loadMethod : 'iframe' ,
2018-07-23 08:49:34 +03:00
contentURL : 'newcategory.html?action=' + action ,
2016-01-21 15:32:13 +03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 250 ,
2018-07-23 08:49:34 +03:00
height : 150
} ) ;
updateMainData ( ) ;
} ;
editCategoryFN = function ( categoryHash ) {
var action = "edit" ;
var categoryName = category _list [ categoryHash ] . name ;
var savePath = category _list [ categoryHash ] . savePath ;
new MochaUI . Window ( {
id : 'editCategoryPage' ,
title : "QBT_TR(Edit Category)QBT_TR[CONTEXT=TransferListWidget]" ,
loadMethod : 'iframe' ,
contentURL : 'newcategory.html?action=' + action + '&categoryName=' + categoryName + '&savePath=' + savePath ,
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 250 ,
height : 150
2016-01-21 15:32:13 +03:00
} ) ;
updateMainData ( ) ;
} ;
2018-04-05 06:59:31 +03:00
removeCategoryFN = function ( categoryHash ) {
2016-01-21 16:42:20 +03:00
var categoryName = category _list [ categoryHash ] . name ;
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/torrents/removeCategories' ,
2016-01-21 16:42:20 +03:00
method : 'post' ,
data : {
2016-01-21 18:58:08 +03:00
categories : categoryName
}
} ) . send ( ) ;
setCategoryFilter ( CATEGORIES _ALL ) ;
} ;
2018-04-05 06:59:31 +03:00
deleteUnusedCategoriesFN = function ( ) {
2016-01-21 18:58:08 +03:00
var categories = [ ] ;
for ( var hash in category _list ) {
2017-07-01 07:42:20 +03:00
if ( torrentsTable . getFilteredTorrentsNumber ( 'all' , hash ) === 0 )
2016-01-21 18:58:08 +03:00
categories . push ( category _list [ hash ] . name ) ;
}
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/torrents/removeCategories' ,
2016-01-21 18:58:08 +03:00
method : 'post' ,
data : {
categories : categories . join ( '\n' )
2016-01-21 16:42:20 +03:00
}
} ) . send ( ) ;
setCategoryFilter ( CATEGORIES _ALL ) ;
} ;
2018-04-05 06:59:31 +03:00
startTorrentsByCategoryFN = function ( categoryHash ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . getFilteredTorrentsHashes ( 'all' , categoryHash ) ;
if ( hashes . length ) {
2017-10-14 16:27:21 +03:00
new Request ( {
url : 'api/v2/torrents/resume' ,
method : 'post' ,
data : {
hashes : hashes . join ( "|" )
}
} ) . send ( ) ;
2016-01-22 14:53:53 +03:00
updateMainData ( ) ;
}
} ;
2018-04-05 06:59:31 +03:00
pauseTorrentsByCategoryFN = function ( categoryHash ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . getFilteredTorrentsHashes ( 'all' , categoryHash ) ;
if ( hashes . length ) {
2017-10-14 16:27:21 +03:00
new Request ( {
url : 'api/v2/torrents/pause' ,
method : 'post' ,
data : {
hashes : hashes . join ( "|" )
}
} ) . send ( ) ;
2016-01-22 15:13:35 +03:00
updateMainData ( ) ;
}
} ;
2018-04-05 06:59:31 +03:00
deleteTorrentsByCategoryFN = function ( categoryHash ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . getFilteredTorrentsHashes ( 'all' , categoryHash ) ;
if ( hashes . length ) {
2016-01-22 15:13:35 +03:00
new MochaUI . Window ( {
id : 'confirmDeletionPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Deletion confirmation)QBT_TR[CONTEXT=confirmDeletionDlg]" ,
2016-01-22 15:13:35 +03:00
loadMethod : 'iframe' ,
2017-08-06 12:04:39 +03:00
contentURL : 'confirmdeletion.html?hashes=' + hashes . join ( "|" ) ,
2016-01-22 15:13:35 +03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
padding : 10 ,
width : 424 ,
height : 140
} ) ;
2016-01-22 08:43:07 +03:00
updateMainData ( ) ;
}
} ;
2017-08-06 11:35:12 +03:00
copyNameFN = function ( ) {
var selectedRows = torrentsTable . selectedRowsIds ( ) ;
var names = [ ] ;
if ( selectedRows . length ) {
var rows = torrentsTable . getFilteredAndSortedRows ( ) ;
2018-05-30 20:06:28 +03:00
for ( var i = 0 ; i < selectedRows . length ; ++ i ) {
2017-08-06 11:35:12 +03:00
var hash = selectedRows [ i ] ;
names . push ( rows [ hash ] . full _data . name ) ;
}
}
return names . join ( "\n" ) ;
} ;
copyMagnetLinkFN = function ( ) {
var selectedRows = torrentsTable . selectedRowsIds ( ) ;
var magnets = [ ] ;
if ( selectedRows . length ) {
var rows = torrentsTable . getFilteredAndSortedRows ( ) ;
2018-05-30 20:06:28 +03:00
for ( var i = 0 ; i < selectedRows . length ; ++ i ) {
2017-08-06 11:35:12 +03:00
var hash = selectedRows [ i ] ;
magnets . push ( rows [ hash ] . full _data . magnet _uri ) ;
}
}
return magnets . join ( "\n" ) ;
} ;
copyHashFN = function ( ) {
return torrentsTable . selectedRowsIds ( ) . join ( "\n" ) ;
} ;
2017-10-14 16:27:21 +03:00
[ 'pause' , 'resume' ] . each ( function ( item ) {
addClickEvent ( item + 'All' , function ( e ) {
2015-05-15 22:54:15 +03:00
new Event ( e ) . stop ( ) ;
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/torrents/' + item ,
method : 'post' ,
data : {
hashes : "all"
}
2015-05-15 22:54:15 +03:00
} ) . send ( ) ;
updateMainData ( ) ;
} ) ;
} ) ;
[ 'pause' , 'resume' , 'recheck' ] . each ( function ( item ) {
2014-11-30 16:14:09 +03:00
addClickEvent ( item , function ( e ) {
new Event ( e ) . stop ( ) ;
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
hashes . each ( function ( hash , index ) {
2014-11-30 16:14:09 +03:00
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/torrents/' + item ,
2014-11-30 16:14:09 +03:00
method : 'post' ,
data : {
2017-10-14 16:27:21 +03:00
hashes : hash
2014-11-30 16:14:09 +03:00
}
} ) . send ( ) ;
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 16:14:09 +03:00
}
} ) ;
} ) ;
2010-12-19 16:37:12 +03:00
2018-05-07 17:45:50 +03:00
[ 'decreasePrio' , 'increasePrio' , 'topPrio' , 'bottomPrio' ] . each ( function ( item ) {
2014-11-30 16:14:09 +03:00
addClickEvent ( item , function ( e ) {
new Event ( e ) . stop ( ) ;
setPriorityFN ( item ) ;
} ) ;
} ) ;
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
setPriorityFN = function ( cmd ) {
2017-08-06 12:04:39 +03:00
var hashes = torrentsTable . selectedRowsIds ( ) ;
if ( hashes . length ) {
2014-11-30 16:14:09 +03:00
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/torrents/' + cmd ,
2014-11-30 16:14:09 +03:00
method : 'post' ,
data : {
2017-08-06 12:04:39 +03:00
hashes : hashes . join ( "|" )
2014-11-30 16:14:09 +03:00
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 16:14:09 +03:00
}
2017-07-01 07:42:20 +03:00
} ;
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
addClickEvent ( 'about' , function ( e ) {
new Event ( e ) . stop ( ) ;
2018-01-24 06:15:44 +03:00
var id = 'aboutpage' ;
2014-11-30 16:14:09 +03:00
new MochaUI . Window ( {
2018-01-24 06:15:44 +03:00
id : id ,
2017-05-01 01:45:02 +03:00
title : 'QBT_TR(About)QBT_TR[CONTEXT=AboutDlg]' ,
2014-11-30 16:14:09 +03:00
loadMethod : 'xhr' ,
contentURL : 'about.html' ,
2018-01-24 06:15:44 +03:00
padding : 10 ,
width : loadWindowWidth ( id , 550 ) ,
height : loadWindowHeight ( id , 290 ) ,
onResize : function ( ) {
saveWindowSize ( id ) ;
}
2014-11-30 16:14:09 +03:00
} ) ;
} ) ;
2012-07-01 14:23:41 +04:00
2014-11-30 16:14:09 +03:00
addClickEvent ( 'logout' , function ( e ) {
2014-08-22 22:02:01 +04:00
new Event ( e ) . stop ( ) ;
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/auth/logout' ,
2017-11-02 16:05:16 +03:00
method : 'post' ,
2014-08-22 22:02:01 +04:00
onSuccess : function ( ) {
window . location . reload ( ) ;
}
} ) . send ( ) ;
} ) ;
2014-11-30 16:14:09 +03:00
addClickEvent ( 'shutdown' , function ( e ) {
new Event ( e ) . stop ( ) ;
2017-05-01 01:45:02 +03:00
if ( confirm ( 'QBT_TR(Are you sure you want to quit qBittorrent?)QBT_TR[CONTEXT=MainWindow]' ) ) {
2015-06-17 02:00:59 +03:00
new Request ( {
2017-10-14 16:27:21 +03:00
url : 'api/v2/app/shutdown' ,
2015-06-17 02:00:59 +03:00
onSuccess : function ( ) {
2017-05-01 01:45:02 +03:00
document . write ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>QBT_TR(qBittorrent has been shutdown.)QBT_TR[CONTEXT=HttpServer]</title><style type=\"text/css\">body { text-align: center; }</style></head><body><h1>QBT_TR(qBittorrent has been shutdown.)QBT_TR[CONTEXT=HttpServer]</h1></body></html>" ) ;
2015-06-17 02:00:59 +03:00
stop ( ) ;
}
} ) . send ( ) ;
}
2014-11-30 16:14:09 +03:00
} ) ;
2012-08-19 21:25:21 +04:00
2014-11-30 16:14:09 +03:00
// Deactivate menu header links
$$ ( 'a.returnFalse' ) . each ( function ( el ) {
el . addEvent ( 'click' , function ( e ) {
new Event ( e ) . stop ( ) ;
} ) ;
} ) ;
2017-07-01 07:42:20 +03:00
} ;