1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-03 18:25:35 +00:00

#5894: Get rid of eval() in JS code (patch by Ancient; 2nd part)

This commit is contained in:
Mike Gelfand 2015-04-23 19:30:40 +00:00
parent fd8e1e25a4
commit cd8ed4ff10
3 changed files with 19 additions and 12 deletions

View file

@ -24,8 +24,7 @@ Dialog.prototype = {
this._message = $('#dialog_message'); this._message = $('#dialog_message');
this._cancel_button = $('#dialog_cancel_button'); this._cancel_button = $('#dialog_cancel_button');
this._confirm_button = $('#dialog_confirm_button'); this._confirm_button = $('#dialog_confirm_button');
this._callback_function = ''; this._callback = null;
this._callback_data = null;
// Observe the buttons // Observe the buttons
this._cancel_button.bind('click', {dialog: this}, this.onCancelClicked); this._cancel_button.bind('click', {dialog: this}, this.onCancelClicked);
@ -58,7 +57,7 @@ Dialog.prototype = {
onConfirmClicked: function(event) onConfirmClicked: function(event)
{ {
var dialog = event.data.dialog; var dialog = event.data.dialog;
eval(dialog._callback_function + "(dialog._callback_data)"); dialog._callback();
dialog.hideDialog(); dialog.hideDialog();
}, },
@ -72,7 +71,7 @@ Dialog.prototype = {
* Display a confirm dialog * Display a confirm dialog
*/ */
confirm: function(dialog_heading, dialog_message, confirm_button_label, confirm: function(dialog_heading, dialog_message, confirm_button_label,
callback_function, callback_data, cancel_button_label) callback, cancel_button_label)
{ {
if (!isMobileDevice) if (!isMobileDevice)
$('.dialog_container').hide(); $('.dialog_container').hide();
@ -81,8 +80,7 @@ Dialog.prototype = {
setTextContent(this._cancel_button[0], cancel_button_label || 'Cancel'); setTextContent(this._cancel_button[0], cancel_button_label || 'Cancel');
setTextContent(this._confirm_button[0], confirm_button_label); setTextContent(this._confirm_button[0], confirm_button_label);
this._confirm_button.show(); this._confirm_button.show();
this._callback_function = callback_function; this._callback = callback;
this._callback_data = callback_data;
$('body').addClass('dialog_showing'); $('body').addClass('dialog_showing');
this._container.show(); this._container.show();
transmission.updateButtonStates(); transmission.updateButtonStates();

View file

@ -62,8 +62,9 @@ TransmissionRemote.prototype =
dialog.confirm('Connection Failed', dialog.confirm('Connection Failed',
'Could not connect to the server. You may need to reload the page to reconnect.', 'Could not connect to the server. You may need to reload the page to reconnect.',
'Details', 'Details',
'alert(remote._error);', function() {
null, alert(remote._error);
},
'Dismiss'); 'Dismiss');
remote._controller.togglePeriodicSessionRefresh(false); remote._controller.togglePeriodicSessionRefresh(false);
}, },

View file

@ -1034,13 +1034,17 @@ Transmission.prototype =
var torrent = torrents[0], var torrent = torrents[0],
header = 'Remove ' + torrent.getName() + '?', header = 'Remove ' + torrent.getName() + '?',
message = 'Once removed, continuing the transfer will require the torrent file. Are you sure you want to remove it?'; message = 'Once removed, continuing the transfer will require the torrent file. Are you sure you want to remove it?';
dialog.confirm(header, message, 'Remove', 'transmission.removeTorrents', torrents); dialog.confirm(header, message, 'Remove', function() {
transmission.removeTorrents(torrents);
});
} }
else else
{ {
var header = 'Remove ' + torrents.length + ' transfers?', var header = 'Remove ' + torrents.length + ' transfers?',
message = 'Once removed, continuing the transfers will require the torrent files. Are you sure you want to remove them?'; message = 'Once removed, continuing the transfers will require the torrent files. Are you sure you want to remove them?';
dialog.confirm(header, message, 'Remove', 'transmission.removeTorrents', torrents); dialog.confirm(header, message, 'Remove', function() {
transmission.removeTorrents(torrents);
});
} }
}, },
@ -1051,13 +1055,17 @@ Transmission.prototype =
var torrent = torrents[0], var torrent = torrents[0],
header = 'Remove ' + torrent.getName() + ' and delete data?', header = 'Remove ' + torrent.getName() + ' and delete data?',
message = 'All data downloaded for this torrent will be deleted. Are you sure you want to remove it?'; message = 'All data downloaded for this torrent will be deleted. Are you sure you want to remove it?';
dialog.confirm(header, message, 'Remove', 'transmission.removeTorrentsAndData', torrents); dialog.confirm(header, message, 'Remove', function() {
transmission.removeTorrentsAndData(torrents);
});
} }
else else
{ {
var header = 'Remove ' + torrents.length + ' transfers and delete data?', var header = 'Remove ' + torrents.length + ' transfers and delete data?',
message = 'All data downloaded for these torrents will be deleted. Are you sure you want to remove them?'; message = 'All data downloaded for these torrents will be deleted. Are you sure you want to remove them?';
dialog.confirm(header, message, 'Remove', 'transmission.removeTorrentsAndData', torrents); dialog.confirm(header, message, 'Remove', function() {
transmission.removeTorrentsAndData(torrents);
});
} }
}, },