system.mobile.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*
  2. 移动版
  3. */
  4. var system = {
  5. version: "1.6.0 beta",
  6. rootPath: "tr-web-control/",
  7. codeupdate: "20180906",
  8. configHead: "transmission-web-control",
  9. config: {
  10. autoReload: true,
  11. reloadStep: 5000,
  12. pageSize: 30,
  13. defaultSelectNode: null
  14. },
  15. lang: null,
  16. reloading: false,
  17. autoReloadTimer: null,
  18. downloadDir: "",
  19. islocal: false,
  20. B64: new Base64(),
  21. // 当前选中的种子编号
  22. currentTorrentId: 0,
  23. currentContentPage: "home",
  24. currentContentConfig: null,
  25. control: {
  26. tree: null,
  27. torrentlist: null
  28. },
  29. serverConfig: null,
  30. serverSessionStats: null,
  31. // 种子列表已选中
  32. torrentListChecked: false,
  33. debug: function (label, text) {
  34. if (window.console) {
  35. if (window.console.log) {
  36. window.console.log(label, text);
  37. }
  38. }
  39. },
  40. setlang: function (lang, callback) {
  41. // 如果未指定语言,则获取当前浏览器默认语言
  42. if (!lang) {
  43. if (this.config.defaultLang)
  44. lang = this.config.defaultLang;
  45. else
  46. lang = navigator.language || navigator.browserLanguage;
  47. //this.debug("lang",lang);
  48. }
  49. if (!lang) lang = "zh-CN";
  50. // 如果语言代码中包含-,则需要将后半部份转为大写
  51. if (lang.indexOf("-") != -1) {
  52. // 因linux对文件有大小写限制,故重新赋值
  53. lang = lang.split("-")[0].toLocaleLowerCase() + "-" + lang.split("-")[1].toLocaleUpperCase();
  54. }
  55. // 如果该语言包没有定义,则使用英文
  56. if (!this.languages[lang]) {
  57. lang = "en";
  58. }
  59. // 统一使用 _ 替代 -
  60. lang = lang.replace("-", "_");
  61. $.getJSON(system.rootPath + "i18n/" + lang + ".json", function (result) {
  62. if (result) {
  63. system.lang = $.extend(true, system.defaultLang, result);
  64. }
  65. system.resetLangText();
  66. if (callback)
  67. callback();
  68. });
  69. },
  70. // 设置语言信息
  71. resetLangText: function () {
  72. var items = $("*[system-lang]");
  73. $.each(items, function (key, item) {
  74. var name = $(item).attr("system-lang");
  75. $(item).html(eval("system.lang." + name));
  76. });
  77. },
  78. init: function (lang, islocal) {
  79. this.readConfig();
  80. transmission.options.getFolders = false;
  81. if (this.lang == null) {
  82. this.setlang(lang, function () {
  83. system.initdata()
  84. });
  85. } else {
  86. this.initdata();
  87. }
  88. },
  89. initdata: function () {
  90. $(document).attr("title", this.lang.system.title + " " + this.version);
  91. //this.control.torrentlist = $("#content-torrent-list ul");
  92. this.control.torrentlist = $("#torrent-list");
  93. this.connect();
  94. },
  95. // 从 cookies 里加载配置
  96. readConfig: function () {
  97. // 将原来的cookies的方式改为本地存储的方式
  98. var config = this.getStorageData(this.configHead + '.system');
  99. if (config) {
  100. this.config = $.extend(this.config, JSON.parse(config));
  101. }
  102. },
  103. // 在 cookies 里保存参数
  104. saveConfig: function () {
  105. this.setStorageData(this.configHead + '.system', JSON.stringify(this.config));
  106. },
  107. getStorageData: function (key, defaultValue) {
  108. return (window.localStorage[key] == null ? defaultValue : window.localStorage[key]);
  109. },
  110. setStorageData: function (key, value) {
  111. window.localStorage[key] = value;
  112. },
  113. // 连接服务器
  114. connect: function () {
  115. // 当种子总数发生变化时,重新获取种子信息
  116. transmission.on.torrentCountChange = function () {
  117. system.reloadTorrentBaseInfos();
  118. };
  119. // 提交错误时
  120. transmission.on.postError = function () {
  121. //system.reloadTorrentBaseInfos();
  122. };
  123. // 初始化连接
  124. transmission.init({
  125. islocal: true
  126. }, function () {
  127. system.reloadSession(true);
  128. system.getServerStatus();
  129. });
  130. },
  131. // 重新加载服务器信息
  132. reloadSession: function (isinit) {
  133. transmission.getSession(function (result) {
  134. system.serverConfig = result;
  135. if (result["alt-speed-enabled"] == true) {
  136. $("#status_alt_speed").show();
  137. } else {
  138. $("#status_alt_speed").hide();
  139. }
  140. system.downloadDir = result["download-dir"];
  141. // rpc-version 版本为 15 起,不再提供 download-dir-free-space 参数,需从新的方法获取
  142. if (parseInt(system.serverConfig["rpc-version"]) >= 15) {
  143. transmission.getFreeSpace(system.downloadDir, function (result) {
  144. system.serverConfig["download-dir-free-space"] = result.arguments["size-bytes"];
  145. system.showFreeSpace(result.arguments["size-bytes"]);
  146. });
  147. } else {
  148. system.showFreeSpace(system.serverConfig["download-dir-free-space"]);
  149. }
  150. });
  151. },
  152. showFreeSpace: function (size) {
  153. var tmp = size;
  154. if (tmp == -1) {
  155. tmp = system.lang["public"]["text-unknown"];
  156. } else {
  157. tmp = formatSize(tmp);
  158. }
  159. $("#status_freespace").text(tmp);
  160. },
  161. // 获取服务器当前状态
  162. getServerStatus: function () {
  163. if (this.reloading) return;
  164. clearTimeout(this.autoReloadTimer);
  165. this.reloading = true;
  166. transmission.getStatus(function (data) {
  167. system.reloading = false;
  168. $("#status_downloadspeed").html(formatSize(data["downloadSpeed"], false, "speed"));
  169. $("#status_uploadspeed").html(formatSize(data["uploadSpeed"], false, "speed"));
  170. system.serverSessionStats = data;
  171. });
  172. },
  173. // 重新获取种子信息
  174. reloadTorrentBaseInfos: function (ids) {
  175. if (this.reloading) return;
  176. clearTimeout(this.autoReloadTimer);
  177. this.reloading = true;
  178. var oldInfos = {
  179. trackers: transmission.trackers,
  180. folders: transmission.torrents.folders
  181. }
  182. // 获取所有种子id信息
  183. transmission.torrents.getallids(function (resultTorrents) {
  184. var ignore = new Array();
  185. for (var index in resultTorrents) {
  186. var item = resultTorrents[index];
  187. ignore.push(item.id);
  188. }
  189. // 错误的编号列表
  190. var errorIds = transmission.torrents.getErrorIds(ignore, true);
  191. if (errorIds.length > 0) {
  192. transmission.torrents.getallids(function () {
  193. system.resetTorrentInfos(oldInfos);
  194. }, errorIds);
  195. } else {
  196. system.resetTorrentInfos(oldInfos);
  197. }
  198. }, ids);
  199. },
  200. //
  201. resetTorrentInfos: function (oldInfos) {
  202. var currentTorrentId = this.currentTorrentId;
  203. // 已暂停
  204. if (transmission.torrents.status[transmission._status.stopped]) {
  205. this.updateCount("paused", transmission.torrents.status[transmission._status.stopped].length);
  206. } else {
  207. this.updateCount("paused", 0);
  208. }
  209. // 做种
  210. if (transmission.torrents.status[transmission._status.seed]) {
  211. this.updateCount("sending", transmission.torrents.status[transmission._status.seed].length);
  212. } else {
  213. this.updateCount("sending", 0);
  214. }
  215. // 校验
  216. if (transmission.torrents.status[transmission._status.check]) {
  217. this.updateCount("check", transmission.torrents.status[transmission._status.check].length);
  218. } else {
  219. this.updateCount("check", 0);
  220. }
  221. // 下载中
  222. if (transmission.torrents.status[transmission._status.download]) {
  223. this.updateCount("downloading", transmission.torrents.status[transmission._status.download].length);
  224. } else {
  225. this.updateCount("downloading", 0);
  226. }
  227. // 活动中
  228. this.updateCount("actively", transmission.torrents.actively.length);
  229. // 发生错误
  230. this.updateCount("error", transmission.torrents.error.length);
  231. // 警告
  232. this.updateCount("warning", transmission.torrents.warning.length);
  233. system.reloading = false;
  234. if (system.config.autoReload) {
  235. system.autoReloadTimer = setTimeout(function () {
  236. system.reloadData();
  237. }, system.config.reloadStep);
  238. }
  239. // 总大小
  240. this.updateCount("all", transmission.torrents.count);
  241. if (this.currentContentPage == "torrent-list") {
  242. var _config = this.currentContentConfig;
  243. _config.reload = true;
  244. this.showContent(_config);
  245. }
  246. },
  247. // 更新状态中
  248. updateCount: function (nodeId, count) {
  249. var item = $("#count-" + nodeId);
  250. item.text(count);
  251. if (count == 0) {
  252. item.hide();
  253. } else
  254. item.show();
  255. },
  256. // 重新加载数据
  257. reloadData: function () {
  258. this.reloadSession();
  259. this.reloading = false;
  260. this.getServerStatus();
  261. this.reloading = false;
  262. this.reloadTorrentBaseInfos();
  263. },
  264. // 显示指定的内容
  265. showContent: function (target) {
  266. var _default = {
  267. page: "",
  268. type: "",
  269. data: "",
  270. title: this.lang.system.title,
  271. reload: false,
  272. callback: null
  273. };
  274. var config = null;
  275. if (typeof (target) == "string") {
  276. _default.page = target;
  277. config = _default;
  278. } else
  279. config = jQuery.extend(_default, target);
  280. if (config.page == this.currentContentPage && !config.reload) {
  281. return;
  282. }
  283. $("#content-" + config.page).show();
  284. if (config.page != this.currentContentPage) {
  285. $("#content-" + this.currentContentPage).hide();
  286. this.control.torrentlist.find("input:checked").prop("checked", false).checkboxradio("refresh");
  287. this.torrentListChecked = false;
  288. }
  289. $("#torrent-page-bar").hide();
  290. if (!this.torrentListChecked)
  291. $("#torrent-toolbar").hide();
  292. this.currentContentPage = config.page;
  293. switch (config.type) {
  294. case "torrent-list":
  295. config.title = this.lang.tree[config.data];
  296. this.loadTorrentToList({
  297. target: config.data
  298. });
  299. break;
  300. }
  301. $("#page-title").text(config.title);
  302. config.reload = false;
  303. this.currentContentConfig = config;
  304. if (config.callback)
  305. config.callback();
  306. },
  307. getTorrentFromType: function (type) {
  308. var torrents = null;
  309. switch (type) {
  310. case "torrent-all":
  311. case "all":
  312. case "servers":
  313. torrents = transmission.torrents.all;
  314. break;
  315. case "paused":
  316. torrents = transmission.torrents.status[transmission._status.stopped];
  317. break;
  318. case "sending":
  319. torrents = transmission.torrents.status[transmission._status.seed];
  320. break;
  321. case "seedwait":
  322. torrents = transmission.torrents.status[transmission._status.seedwait];
  323. break;
  324. case "check":
  325. torrents = transmission.torrents.status[transmission._status.check];
  326. break;
  327. case "checkwait":
  328. torrents = transmission.torrents.status[transmission._status.checkwait];
  329. break;
  330. case "downloading":
  331. torrents = transmission.torrents.status[transmission._status.download];
  332. break;
  333. case "downloadwait":
  334. torrents = transmission.torrents.status[transmission._status.downloadwait];
  335. break;
  336. case "actively":
  337. torrents = transmission.torrents.actively;
  338. break;
  339. case "error":
  340. torrents = transmission.torrents.error;
  341. break;
  342. case "warning":
  343. torrents = transmission.torrents.warning;
  344. break;
  345. case "search-result":
  346. torrents = transmission.torrents.searchResult;
  347. break;
  348. default:
  349. break;
  350. }
  351. return torrents;
  352. },
  353. // 加载种子列表
  354. loadTorrentToList: function (config) {
  355. // 如果有种子选中,则不重新加载列表
  356. if (this.torrentListChecked) return;
  357. if (!transmission.torrents.all) {
  358. return;
  359. }
  360. var def = {
  361. node: null,
  362. page: 1,
  363. target: "all"
  364. };
  365. jQuery.extend(def, config);
  366. if (!config.target) return;
  367. var torrents = this.getTorrentFromType(config.target);
  368. this.config.defaultSelectNode = config.target;
  369. this.saveConfig();
  370. var datas = new Array();
  371. this.control.torrentlist.empty();
  372. for (var index in torrents) {
  373. if (!torrents[index]) {
  374. continue;
  375. }
  376. var percentDone = parseFloat(torrents[index].percentDone * 100).toFixed(2);
  377. var status = this.lang.torrent["status-text"][torrents[index].status];
  378. if (torrents[index].error != 0) {
  379. status = "<span class='text-status-error'>" + status + "</span>";
  380. } else if (torrents[index].warning) {
  381. status = "<span class='text-status-warning' title='" + torrents[index].warning + "'>" + status + "</span>";
  382. }
  383. var data = {
  384. id: torrents[index].id,
  385. name: this.getTorrentNameBar(torrents[index]),
  386. totalSize: torrents[index].totalSize,
  387. percentDone: this.getTorrentProgressBar(percentDone, torrents[index]),
  388. percentDoneNumber: percentDone,
  389. status: status,
  390. addedDate: formatLongTime(torrents[index].addedDate),
  391. completeSize: (torrents[index].totalSize - torrents[index].leftUntilDone),
  392. rateDownload: torrents[index].rateDownload,
  393. rateUpload: torrents[index].rateUpload,
  394. leecherCount: torrents[index].leecher,
  395. seederCount: torrents[index].seeder,
  396. uploadRatio: torrents[index].uploadRatio,
  397. uploadedEver: torrents[index].uploadedEver
  398. };
  399. datas.push(data);
  400. //this.appendTorrentToList(data);
  401. }
  402. if (datas.length == 0) {
  403. setTimeout(function () {
  404. system.showContent('home');
  405. }, 100);
  406. return;
  407. }
  408. if (this.torrentPager.onGotoPage == null) {
  409. this.torrentPager.onGotoPage = function (datas) {
  410. system.control.torrentlist.empty();
  411. $("#torrent-toolbar").hide();
  412. for (var key in datas) {
  413. system.appendTorrentToList(datas[key]);
  414. }
  415. // 刷新列表并指定事件
  416. $(system.control.torrentlist).listview('refresh').find("input[type='checkbox']").click(function () {
  417. system.changeTorrentToolbar(this, data);
  418. if (system.torrentListChecked) {
  419. system.control.torrentlist.find("a[name='torrent']").css("marginLeft", "0px");
  420. } else {
  421. system.control.torrentlist.find("a[name='torrent']").css("marginLeft", "0px");
  422. }
  423. }).checkboxradio();
  424. }
  425. }
  426. this.torrentPager.setDatas(datas, config.target);
  427. },
  428. // 添加种子信息到列表
  429. appendTorrentToList: function (data) {
  430. var replaces = {
  431. id: data.id,
  432. name: data.name,
  433. rateDownload: formatSize(data.rateDownload, false, "speed"),
  434. rateUpload: formatSize(data.rateUpload, false, "speed"),
  435. completeSize: formatSize(data.completeSize),
  436. totalSize: formatSize(data.totalSize),
  437. percentDone: data.percentDone
  438. };
  439. // 由于不能以对象的方式来创建 listview 子项,所以只能用拼接字符串的方式
  440. var templates = "<li id='li-torrent-$id$' torrentid='$id$' style='padding:0px;'><a name='torrent' style='padding:0px;margin-left:0px;'>" +
  441. "<label data-corners='false' style='margin:0px;border:0px;padding:0px;'>" +
  442. "<input type='checkbox' id='torrent-$id$'/><label for='torrent-$id$'>" +
  443. "<h3 style='margin:0px;'>$name$</h3>" +
  444. "<div style='padding:0px 10px 5px 0px;'>$percentDone$</div>" +
  445. "<p class='torrent-list-infos'>↓$rateDownload$ ↑$rateUpload$|$completeSize$/$totalSize$</p>" +
  446. "</label></label></a>" +
  447. "<a class='more'></a>";
  448. // 替换模板中以 $w$ 方式组成的内容
  449. templates = templates.replace(/\$([^\$]*)\$/g, function (string, key) {
  450. return replaces[key];
  451. });
  452. var li = $(templates);
  453. // 向右划动
  454. li.on("swiperight", function (event) {
  455. //system.control.torrentlist.find("#torrent-"+$(this).attr("torrentid")).click();
  456. system.control.torrentlist.find("a[name='torrent']").css("marginLeft", "0px");
  457. });
  458. li.on("swipeleft", function (event) {
  459. //system.control.torrentlist.find("#torrent-"+$(this).attr("torrentid")).click();
  460. system.control.torrentlist.find("a[name='torrent']").css("marginLeft", "0px");
  461. });
  462. li.appendTo(this.control.torrentlist);
  463. },
  464. // 获取种子名称显示区域的内容
  465. getTorrentNameBar: function (torrent) {
  466. var className = "";
  467. var tip = torrent.name;
  468. switch (torrent.status) {
  469. case transmission._status.stopped:
  470. className = "iconlabel icon-pause-small";
  471. break;
  472. case transmission._status.check:
  473. className = "iconlabel icon-checking";
  474. break;
  475. case transmission._status.download:
  476. className = "iconlabel icon-down";
  477. break;
  478. case transmission._status.seed:
  479. className = "iconlabel icon-up";
  480. break;
  481. case transmission._status.seedwait:
  482. case transmission._status.downloadwait:
  483. case transmission._status.checkwait:
  484. className = "iconlabel icon-wait";
  485. break;
  486. }
  487. if (torrent.warning) {
  488. className = "iconlabel icon-warning-type1";
  489. tip += "\n\n" + this.lang["public"]["text-info"] + ": " + torrent.warning;
  490. }
  491. if (torrent.error != 0) {
  492. className = "iconlabel icon-exclamation";
  493. tip += "\n\n" + this.lang["public"]["text-info"] + ": " + torrent.errorString;
  494. }
  495. return '<span class="' + className + '" title="' + tip + '">' + torrent.name + '</span>';
  496. },
  497. // 获取指定种子的进度条
  498. getTorrentProgressBar: function (progress, torrent) {
  499. progress = progress + "%";
  500. var className = "";
  501. switch (torrent.status) {
  502. case transmission._status.stopped:
  503. className = "torrent-progress-stop";
  504. break;
  505. case transmission._status.checkwait:
  506. case transmission._status.check:
  507. className = "torrent-progress-check";
  508. break;
  509. case transmission._status.downloadwait:
  510. case transmission._status.download:
  511. className = "torrent-progress-download";
  512. break;
  513. case transmission._status.seedwait:
  514. case transmission._status.seed:
  515. className = "torrent-progress-seed";
  516. break;
  517. }
  518. if (torrent.warning) {
  519. className = "torrent-progress-warning";
  520. }
  521. if (torrent.error != 0) {
  522. className = "torrent-progress-error";
  523. }
  524. return '<div class="torrent-progress" title="' + progress + '"><div class="torrent-progress-text">' + progress + '</div><div class="torrent-progress-bar ' + className + '" style="width:' + progress + ';"></div></div>';
  525. },
  526. // 改变种子的工具栏
  527. changeTorrentToolbar: function (source, item) {
  528. var checked = this.control.torrentlist.find("input:checked");
  529. $("#torrent-checked-count").html(checked.length);
  530. if (checked.length > 0) {
  531. this.torrentListChecked = true;
  532. $("#torrent-toolbar").show();
  533. } else {
  534. this.torrentListChecked = false;
  535. $("#torrent-toolbar").hide();
  536. }
  537. if (item)
  538. this.currentTorrentId = item.id;
  539. },
  540. // 种子列表分页处理
  541. torrentPager: {
  542. datas: null,
  543. pageSize: 30,
  544. pageNumber: 0,
  545. pageCount: 0,
  546. count: 0,
  547. onGotoPage: null,
  548. currentDatas: null,
  549. pageBar: null,
  550. controls: {
  551. prev: null,
  552. next: null,
  553. number: null
  554. },
  555. head: "",
  556. init: function (datas) {
  557. this.pageBar = $("#torrent-page-bar");
  558. this.controls.next = this.pageBar.find("#page-next");
  559. this.controls.next.click(function () {
  560. system.torrentPager.gotoPage("next");
  561. });
  562. this.controls.prev = this.pageBar.find("#page-prev");
  563. this.controls.prev.click(function () {
  564. system.torrentPager.gotoPage("prev");
  565. });
  566. this.controls.number = this.pageBar.find("#page-number");
  567. if (datas) {
  568. this.setDatas(datas);
  569. }
  570. },
  571. setDatas: function (datas, head) {
  572. if (!this.datas) {
  573. this.init();
  574. }
  575. this.datas = datas;
  576. this.pageBar.show();
  577. this.count = this.datas.length;
  578. this.pageCount = parseInt(this.count / this.pageSize);
  579. if (this.count % this.pageSize > 0) {
  580. this.pageCount++;
  581. }
  582. if (this.pageCount == 1) {
  583. this.pageBar.hide();
  584. }
  585. if (this.head == head) {
  586. this.gotoPage();
  587. } else
  588. this.gotoPage(1);
  589. this.head = head;
  590. },
  591. gotoPage: function (page) {
  592. if (typeof (page) == "number") {
  593. this.pageNumber = page;
  594. } else {
  595. switch (page) {
  596. case "next":
  597. this.pageNumber++;
  598. break;
  599. case "prev":
  600. this.pageNumber--;
  601. break;
  602. }
  603. }
  604. if (this.pageNumber > this.pageCount) {
  605. this.pageNumber = this.pageCount;
  606. }
  607. if (this.pageNumber < 1) {
  608. this.pageNumber = 1;
  609. }
  610. var start = (this.pageNumber - 1) * parseInt(this.pageSize);
  611. var end = start + parseInt(this.pageSize);
  612. this.currentDatas = (this.datas.slice(start, end));
  613. this.controls.number.text(this.pageNumber + "/" + this.pageCount);
  614. if (this.pageNumber > 1) {
  615. this.controls.prev.show();
  616. } else {
  617. this.controls.prev.hide();
  618. }
  619. if (this.pageNumber < this.pageCount) {
  620. this.controls.next.show();
  621. } else {
  622. this.controls.next.hide();
  623. }
  624. if (this.onGotoPage) {
  625. this.onGotoPage(this.currentDatas);
  626. }
  627. }
  628. },
  629. // 开始/暂停已选择的种子
  630. changeSelectedTorrentStatus: function (status, button, options) {
  631. var items = this.control.torrentlist.find("input:checked");
  632. var ids = new Array();
  633. if (!status) {
  634. status = "start";
  635. }
  636. for (var i = 0; i < items.length; i++) {
  637. ids.push(parseInt(items[i].id.replace("torrent-", "")));
  638. }
  639. if (ids.length > 0) {
  640. var arguments = {
  641. ids: ids
  642. };
  643. switch (status) {
  644. case "remove":
  645. arguments["delete-local-data"] = options.removeData;
  646. break;
  647. case "verify":
  648. if (ids.length == 1) {
  649. var torrent = transmission.torrents.all[ids[0]];
  650. if (torrent.percentDone > 0) {
  651. if (confirm(system.lang.toolbar.tip["recheck-confirm"]) == false) {
  652. return;
  653. }
  654. }
  655. } else if (confirm(system.lang.toolbar.tip["recheck-confirm"]) == false) {
  656. return;
  657. }
  658. break;
  659. }
  660. button = $(button);
  661. button.attr("disabled", true);
  662. transmission.exec({
  663. method: "torrent-" + status,
  664. arguments: arguments
  665. }, function (data) {
  666. button.attr("disabled", false);
  667. system.reloadTorrentBaseInfos();
  668. });
  669. // 操作完成后,取消所有已选择的项
  670. this.torrentListChecked = false;
  671. }
  672. },
  673. // 增加种子
  674. addTorrentsToServer: function (urls, count, autostart, savepath, callback) {
  675. //this.config.autoReload = false;
  676. var index = count - urls.length;
  677. var url = urls.shift();
  678. if (!url) {
  679. this.showStatus(this.lang.system.status.queuefinish);
  680. //this.config.autoReload = true;
  681. this.getServerStatus();
  682. if (callback)
  683. callback();
  684. return;
  685. }
  686. this.showStatus(this.lang.system.status.queue, (count - index + 1));
  687. transmission.addTorrentFromUrl(url, savepath, autostart, function (data) {
  688. system.addTorrentsToServer(urls, count, autostart, savepath, callback);
  689. });
  690. },
  691. showStatus: function (msg, count) {
  692. if (!msg) {
  693. $("#status").hide();
  694. return;
  695. }
  696. $("#status").show();
  697. $("#status-msg").html(msg);
  698. if ($.isNumeric(count))
  699. $("#status-count").html(count).show();
  700. else
  701. $("#status-count").hide();
  702. }
  703. };
  704. $(document).ready(function () {
  705. // Loads the default language content
  706. $.getJSON(system.rootPath + "i18n/en.json").done(function (result) {
  707. system.defaultLang = result;
  708. });
  709. // Loads a list of available languages
  710. $.getJSON(system.rootPath + "i18n.json").done(function (result) {
  711. system.languages = result;
  712. system.init(location.search.getQueryString("lang"), location.search.getQueryString("local"));
  713. });
  714. });