From 258b6cf029aa006c710b5d563f6aa332f8589113 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sun, 20 Oct 2013 18:39:07 +0000 Subject: [PATCH] (trunk, web) #5510 'add file renaming to transmission web interface' -- added with patch from mark ablov --- web/javascript/remote.js | 11 +++++++- web/javascript/transmission.js | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/web/javascript/remote.js b/web/javascript/remote.js index dfd7e749f..5cb13bed8 100644 --- a/web/javascript/remote.js +++ b/web/javascript/remote.js @@ -105,7 +105,16 @@ TransmissionRemote.prototype = var o = { method: 'port-test' }; this.sendRequest(o, callback, context, async); }, - + + renameTorrent: function(torrentIds, oldpath, newname, callback, context) { + var o = { method: 'torrent-rename-path', + arguments: { 'ids': torrentIds, + 'path': oldpath, + 'name': newname } + }; + this.sendRequest(o, callback, context); + }, + loadDaemonStats: function(callback, context, async) { var o = { method: 'session-stats' }; this.sendRequest(o, callback, context, async); diff --git a/web/javascript/transmission.js b/web/javascript/transmission.js index 29dcce0cc..fba8b1e50 100644 --- a/web/javascript/transmission.js +++ b/web/javascript/transmission.js @@ -53,6 +53,10 @@ Transmission.prototype = $('#upload_confirm_button').click($.proxy(this.confirmUploadClicked,this)); $('#upload_cancel_button').click($.proxy(this.hideUploadDialog,this)); + $('#rename_confirm_button').click($.proxy(this.confirmRenameClicked,this)); + $('#rename_cancel_button').click($.proxy(this.hideRenameDialog,this)); + + $('#move_confirm_button').click($.proxy(this.confirmMoveClicked,this)); $('#move_cancel_button').click($.proxy(this.hideMoveDialog,this)); @@ -183,6 +187,7 @@ Transmission.prototype = context_remove: function() { tr.removeSelectedTorrents(); }, context_removedata: function() { tr.removeSelectedTorrentsAndData(); }, context_verify: function() { tr.verifySelectedTorrents(); }, + context_rename: function() { tr.renameSelectedTorrents(); }, context_reannounce: function() { tr.reannounceSelectedTorrents(); }, context_move_top: function() { tr.moveTop(); }, context_move_up: function() { tr.moveUp(); }, @@ -572,6 +577,17 @@ Transmission.prototype = this.hideUploadDialog(); }, + hideRenameDialog: function() { + $('body.open_showing').removeClass('open_showing'); + $('#rename_container').hide(); + }, + + confirmRenameClicked: function() { + var torrents = this.getSelectedTorrents(); + this.renameTorrent(torrents[0], $('input#torrent_rename_name').attr('value')); + this.hideRenameDialog(); + }, + removeClicked: function(ev) { if (this.isButtonEnabled(ev)) { this.removeSelectedTorrents(); @@ -1054,6 +1070,36 @@ Transmission.prototype = this.remote.removeTorrentsAndData(torrents); }, + promptToRenameTorrent: function(torrent) { + $('body').addClass('open_showing'); + $('input#torrent_rename_name').attr('value', torrent.getName()); + $('#rename_container').show(); + $('#torrent_rename_name').focus(); + }, + + renameSelectedTorrents: function() { + var torrents = this.getSelectedTorrents(); + if (torrents.length != 1) + dialog.alert("Renaming", "You can rename only one torrent at a time.", "Ok"); + else + this.promptToRenameTorrent(torrents[0]); + }, + + onTorrentRenamed: function(response) { + var torrent; + if ((response.result === 'success') && + (response.arguments) && + ((torrent = this._torrents[response.arguments.id]))) + { + torrent.refresh(response.arguments); + } + }, + + renameTorrent: function (torrent, newname) { + var oldpath = torrent.getName(); + this.remote.renameTorrent([torrent.getId()], oldpath, newname, this.onTorrentRenamed, this); + }, + verifySelectedTorrents: function() { this.verifyTorrents(this.getSelectedTorrents()); }, -- 2.40.0