2008-05-17 12:44:42 +00: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 13:23:41 +03: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 12:44:42 +00: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 14:14:09 +01:00
Cookie . write ( name , value , {
duration : 365 * 10
} ) ;
2014-11-30 01:40:26 +03:00
}
}
}
2014-12-08 03:03:53 +03:00
function getLocalStorageItem ( name , defaultVal ) {
val = localStorage . getItem ( name ) ;
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 14:14:09 +01:00
initializeWindows = function ( ) {
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
function addClickEvent ( el , fn ) {
[ 'Link' , 'Button' ] . each ( function ( item ) {
if ( $ ( el + item ) ) {
$ ( el + item ) . addEvent ( 'click' , fn ) ;
}
} ) ;
}
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'download' , function ( e ) {
new Event ( e ) . stop ( ) ;
new MochaUI . Window ( {
id : 'downloadPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Download from URLs)QBT_TR[CONTEXT=downloadFromURL]" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'iframe' ,
contentURL : 'download.html' ,
scrollbars : true ,
resizable : false ,
maximizable : false ,
closable : true ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 500 ,
2015-10-22 00:06:36 -04:30
height : 360
2014-11-30 14:14:09 +01:00
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'preferences' , function ( e ) {
new Event ( e ) . stop ( ) ;
new MochaUI . Window ( {
id : 'preferencesPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Options)QBT_TR[CONTEXT=OptionsDialog]" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'xhr' ,
toolbar : true ,
contentURL : 'preferences_content.html' ,
require : {
css : [ 'css/Tabs.css' ]
} ,
toolbarURL : 'preferences.html' ,
resizable : true ,
maximizable : false ,
closable : true ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 700 ,
height : 300
} ) ;
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'upload' , function ( e ) {
new Event ( e ) . stop ( ) ;
new MochaUI . Window ( {
id : 'uploadPage' ,
2017-05-01 01:45:02 +03:00
title : "QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'iframe' ,
contentURL : 'upload.html' ,
scrollbars : true ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
2015-10-22 00:06:36 -04:30
width : 500 ,
2017-03-11 01:28:22 +08:00
height : 220
2014-11-30 14:14:09 +01:00
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01: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 14:14:09 +01:00
loadMethod : 'iframe' ,
2015-02-01 12:08:45 -05:00
contentURL : 'uploadlimit.html?hashes=global' ,
2014-11-30 14:14:09 +01:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
}
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
uploadLimitFN = function ( ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2014-11-30 14:14:09 +01:00
if ( h . length ) {
var hash = h [ 0 ] ;
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 14:14:09 +01:00
loadMethod : 'iframe' ,
2015-02-01 12:08:45 -05:00
contentURL : 'uploadlimit.html?hashes=' + h . join ( "|" ) ,
2014-11-30 14:14:09 +01:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
}
} ;
2012-07-01 13:23:41 +03:00
2014-12-09 19:54:35 +03:00
toggleSequentialDownloadFN = function ( ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2014-12-09 19:54:35 +03:00
if ( h . length ) {
new Request ( {
url : 'command/toggleSequentialDownload' ,
method : 'post' ,
data : {
hashes : h . join ( "|" )
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-12-09 19:54:35 +03:00
}
} ;
toggleFirstLastPiecePrioFN = function ( ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2014-12-09 19:54:35 +03:00
if ( h . length ) {
new Request ( {
url : 'command/toggleFirstLastPiecePrio' ,
method : 'post' ,
data : {
hashes : h . join ( "|" )
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-12-09 19:54:35 +03:00
}
} ;
2015-01-30 15:58:27 -05:00
setSuperSeedingFN = function ( val ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2015-01-30 15:58:27 -05:00
if ( h . length ) {
new Request ( {
url : 'command/setSuperSeeding' ,
method : 'post' ,
data : {
value : val ,
hashes : h . join ( "|" )
}
} ) . send ( ) ;
updateMainData ( ) ;
}
} ;
2015-07-14 03:06:34 +02:00
setForceStartFN = function ( ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2015-04-15 19:13:18 +02:00
if ( h . length ) {
new Request ( {
url : 'command/setForceStart' ,
method : 'post' ,
data : {
2015-07-14 03:06:34 +02:00
value : 'true' ,
2015-04-15 19:13:18 +02:00
hashes : h . join ( "|" )
}
} ) . send ( ) ;
updateMainData ( ) ;
}
} ;
2014-11-30 14:14:09 +01: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 14:14:09 +01:00
loadMethod : 'iframe' ,
2015-02-01 12:45:37 -05:00
contentURL : 'downloadlimit.html?hashes=global' ,
2014-11-30 14:14:09 +01:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
}
2012-07-01 13:23:41 +03:00
2017-03-06 03:05:18 +00:00
StatisticsLinkFN = function ( ) {
new MochaUI . Window ( {
id : 'statisticspage' ,
2017-05-01 01:45:02 +03:00
title : 'QBT_TR(Statistics)QBT_TR[CONTEXT=StatsDialog]' ,
2017-03-06 03:05:18 +00:00
loadMethod : 'xhr' ,
contentURL : 'statistics.html' ,
scrollbars : false ,
resizable : false ,
maximizable : false ,
width : 275 ,
height : 370 ,
padding : 10
} ) ;
}
2014-11-30 14:14:09 +01:00
downloadLimitFN = function ( ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2014-11-30 14:14:09 +01:00
if ( h . length ) {
var hash = h [ 0 ] ;
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 14:14:09 +01:00
loadMethod : 'iframe' ,
2015-02-01 12:45:37 -05:00
contentURL : 'downloadlimit.html?hashes=' + h . join ( "|" ) ,
2014-11-30 14:14:09 +01:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
}
} ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
deleteFN = function ( ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2014-11-30 14:14:09 +01:00
if ( h . length ) {
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 14:14:09 +01:00
loadMethod : 'iframe' ,
2015-09-17 17:48:38 +02:00
contentURL : 'confirmdeletion.html?hashes=' + h . join ( "|" ) ,
2014-11-30 14:14:09 +01: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 14:14:09 +01:00
}
} ;
2009-11-24 19:41:31 +00:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'delete' , function ( e ) {
new Event ( e ) . stop ( ) ;
deleteFN ( ) ;
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
pauseFN = function ( ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2014-11-30 14:14:09 +01:00
if ( h . length ) {
h . each ( function ( hash , index ) {
new Request ( {
url : 'command/pause' ,
method : 'post' ,
data : {
hash : hash
}
} ) . send ( ) ;
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
}
} ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
startFN = function ( ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2014-11-30 14:14:09 +01:00
if ( h . length ) {
h . each ( function ( hash , index ) {
new Request ( {
url : 'command/resume' ,
method : 'post' ,
data : {
hash : hash
}
} ) . send ( ) ;
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
}
} ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
recheckFN = function ( ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2014-11-30 14:14:09 +01:00
if ( h . length ) {
h . each ( function ( hash , index ) {
new Request ( {
url : 'command/recheck' ,
method : 'post' ,
data : {
hash : hash
}
} ) . send ( ) ;
} ) ;
2015-05-15 21:54:15 +02:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
}
} ;
2008-12-28 21:12:49 +00:00
2016-01-21 15:32:13 +03:00
torrentNewCategoryFN = function ( ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2015-02-14 18:19:54 -03:00
if ( h . length ) {
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-14 18:19:54 -03:00
loadMethod : 'iframe' ,
2016-02-09 11:56:48 +03:00
contentURL : 'newcategory.html?hashes=' + h . join ( '|' ) ,
2015-02-14 18:19:54 -03:00
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
2015-07-16 01:04:53 +02:00
width : 250 ,
height : 100
2015-02-14 18:19:54 -03:00
} ) ;
}
} ;
2016-01-21 15:32:13 +03:00
torrentSetCategoryFN = function ( categoryHash ) {
2016-02-09 11:56:48 +03:00
var categoryName = '' ;
if ( categoryHash != 0 )
var categoryName = category _list [ categoryHash ] . name ;
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2015-02-14 18:19:54 -03:00
if ( h . length ) {
2015-07-16 01:04:53 +02:00
new Request ( {
2016-02-09 11:56:48 +03:00
url : 'command/setCategory' ,
2015-07-16 01:04:53 +02:00
method : 'post' ,
data : {
hashes : h . join ( "|" ) ,
2016-02-09 11:56:48 +03:00
category : categoryName
2015-07-16 01:04:53 +02:00
}
} ) . send ( ) ;
2015-02-14 18:19:54 -03:00
}
} ;
2016-01-21 15:32:13 +03:00
createCategoryFN = function ( ) {
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' ,
contentURL : 'newcategory.html' ,
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 250 ,
height : 100
} ) ;
updateMainData ( ) ;
} ;
2016-01-21 16:42:20 +03:00
removeCategoryFN = function ( categoryHash ) {
var categoryName = category _list [ categoryHash ] . name ;
new Request ( {
2016-01-21 18:58:08 +03:00
url : 'command/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 ) ;
} ;
deleteUnusedCategoriesFN = function ( ) {
var categories = [ ] ;
for ( var hash in category _list ) {
if ( torrentsTable . getFilteredTorrentsNumber ( 'all' , hash ) == 0 )
categories . push ( category _list [ hash ] . name ) ;
}
new Request ( {
url : 'command/removeCategories' ,
method : 'post' ,
data : {
categories : categories . join ( '\n' )
2016-01-21 16:42:20 +03:00
}
} ) . send ( ) ;
setCategoryFilter ( CATEGORIES _ALL ) ;
} ;
2016-01-22 08:43:07 +03:00
startTorrentsByCategoryFN = function ( categoryHash ) {
var h = torrentsTable . getFilteredTorrentsHashes ( 'all' , categoryHash ) ;
if ( h . length ) {
h . each ( function ( hash , index ) {
new Request ( {
url : 'command/resume' ,
method : 'post' ,
data : {
hash : hash
}
} ) . send ( ) ;
} ) ;
2016-01-22 14:53:53 +03:00
updateMainData ( ) ;
}
} ;
pauseTorrentsByCategoryFN = function ( categoryHash ) {
var h = torrentsTable . getFilteredTorrentsHashes ( 'all' , categoryHash ) ;
if ( h . length ) {
h . each ( function ( hash , index ) {
new Request ( {
url : 'command/pause' ,
method : 'post' ,
data : {
hash : hash
}
} ) . send ( ) ;
} ) ;
2016-01-22 15:13:35 +03:00
updateMainData ( ) ;
}
} ;
deleteTorrentsByCategoryFN = function ( categoryHash ) {
var h = torrentsTable . getFilteredTorrentsHashes ( 'all' , categoryHash ) ;
if ( h . length ) {
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' ,
contentURL : 'confirmdeletion.html?hashes=' + h . join ( "|" ) ,
scrollbars : false ,
resizable : false ,
maximizable : false ,
padding : 10 ,
width : 424 ,
height : 140
} ) ;
2016-01-22 08:43:07 +03:00
updateMainData ( ) ;
}
} ;
2015-05-15 21:54:15 +02:00
[ 'pauseAll' , 'resumeAll' ] . each ( function ( item ) {
addClickEvent ( item , function ( e ) {
new Event ( e ) . stop ( ) ;
new Request ( {
url : 'command/' + item
} ) . send ( ) ;
updateMainData ( ) ;
} ) ;
} ) ;
[ 'pause' , 'resume' , 'recheck' ] . each ( function ( item ) {
2014-11-30 14:14:09 +01:00
addClickEvent ( item , function ( e ) {
new Event ( e ) . stop ( ) ;
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2014-11-30 14:14:09 +01:00
if ( h . length ) {
h . each ( function ( hash , index ) {
new Request ( {
url : 'command/' + item ,
method : 'post' ,
data : {
hash : hash
}
} ) . send ( ) ;
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
}
} ) ;
} ) ;
2010-12-19 13:37:12 +00:00
2014-11-30 14:14:09 +01:00
[ 'decreasePrio' , 'increasePrio' , 'topPrio' , 'bottomPrio' ] . each ( function ( item ) {
addClickEvent ( item , function ( e ) {
new Event ( e ) . stop ( ) ;
setPriorityFN ( item ) ;
} ) ;
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
setPriorityFN = function ( cmd ) {
2015-11-11 22:58:30 +03:00
var h = torrentsTable . selectedRowsIds ( ) ;
2014-11-30 14:14:09 +01:00
if ( h . length ) {
new Request ( {
url : 'command/' + cmd ,
method : 'post' ,
data : {
hashes : h . join ( "|" )
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
}
}
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'about' , function ( e ) {
new Event ( e ) . stop ( ) ;
new MochaUI . Window ( {
id : 'aboutpage' ,
2017-05-01 01:45:02 +03:00
title : 'QBT_TR(About)QBT_TR[CONTEXT=AboutDlg]' ,
2014-11-30 14:14:09 +01:00
loadMethod : 'xhr' ,
contentURL : 'about.html' ,
2015-06-17 01:00:59 +02:00
width : 550 ,
height : 290 ,
2014-11-30 14:14:09 +01:00
padding : 10
} ) ;
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'logout' , function ( e ) {
2014-08-22 22:02:01 +04:00
new Event ( e ) . stop ( ) ;
new Request ( {
2015-05-17 13:48:06 +02:00
url : 'logout' ,
2014-08-22 22:02:01 +04:00
method : 'get' ,
onSuccess : function ( ) {
window . location . reload ( ) ;
}
} ) . send ( ) ;
} ) ;
2014-11-30 14:14:09 +01: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 01:00:59 +02:00
new Request ( {
url : 'command/shutdown' ,
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 01:00:59 +02:00
stop ( ) ;
}
} ) . send ( ) ;
}
2014-11-30 14:14:09 +01:00
} ) ;
2012-08-19 19:25:21 +02:00
2014-11-30 14:14:09 +01:00
// Deactivate menu header links
$$ ( 'a.returnFalse' ) . each ( function ( el ) {
el . addEvent ( 'click' , function ( e ) {
new Event ( e ) . stop ( ) ;
} ) ;
} ) ;
2015-05-17 13:48:06 +02:00
}