2011-09-14 05:10:51 +00:00
|
|
|
/**
|
|
|
|
* Copyright © Dave Perrett and Malcolm Jarvis
|
2010-09-05 03:02:02 +00:00
|
|
|
*
|
2011-09-14 05:10:51 +00:00
|
|
|
* This file is licensed under the GPLv2.
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2010-09-05 03:02:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
function Dialog(){
|
2011-08-28 13:57:25 +00:00
|
|
|
this.initialize();
|
2010-09-05 03:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Dialog.prototype = {
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
/*
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
initialize: function() {
|
2010-09-05 03:02:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Private Interface Variables
|
|
|
|
*/
|
|
|
|
this._container = $('#dialog_container');
|
|
|
|
this._heading = $('#dialog_heading');
|
|
|
|
this._message = $('#dialog_message');
|
|
|
|
this._cancel_button = $('#dialog_cancel_button');
|
|
|
|
this._confirm_button = $('#dialog_confirm_button');
|
|
|
|
this._callback_function = '';
|
|
|
|
this._callback_data = null;
|
|
|
|
|
|
|
|
// Observe the buttons
|
2011-08-24 02:04:35 +00:00
|
|
|
this._cancel_button.bind('click', {dialog: this}, this.onCancelClicked);
|
|
|
|
this._confirm_button.bind('click', {dialog: this}, this.onConfirmClicked);
|
2010-09-05 03:02:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
/*--------------------------------------------
|
|
|
|
*
|
|
|
|
* E V E N T F U N C T I O N S
|
|
|
|
*
|
|
|
|
*--------------------------------------------*/
|
2010-09-05 03:02:02 +00:00
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
hideDialog: function()
|
2010-09-05 03:02:02 +00:00
|
|
|
{
|
|
|
|
$('body.dialog_showing').removeClass('dialog_showing');
|
2011-08-28 17:24:56 +00:00
|
|
|
this._container.hide();
|
|
|
|
transmission.hideMobileAddressbar();
|
2010-09-05 03:02:02 +00:00
|
|
|
transmission.updateButtonStates();
|
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
onCancelClicked: function(event)
|
2010-09-05 03:02:02 +00:00
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
event.data.dialog.hideDialog();
|
2010-09-05 03:02:02 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
onConfirmClicked: function(event)
|
2010-09-05 03:02:02 +00:00
|
|
|
{
|
|
|
|
var dialog = event.data.dialog;
|
2011-08-24 02:04:35 +00:00
|
|
|
eval(dialog._callback_function + "(dialog._callback_data)");
|
|
|
|
dialog.hideDialog();
|
2010-09-05 03:02:02 +00:00
|
|
|
},
|
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
/*--------------------------------------------
|
|
|
|
*
|
|
|
|
* I N T E R F A C E F U N C T I O N S
|
|
|
|
*
|
|
|
|
*--------------------------------------------*/
|
2010-09-05 03:02:02 +00:00
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
/*
|
|
|
|
* Display a confirm dialog
|
|
|
|
*/
|
|
|
|
confirm: function(dialog_heading, dialog_message, confirm_button_label,
|
|
|
|
callback_function, callback_data, cancel_button_label)
|
|
|
|
{
|
2011-08-28 17:24:56 +00:00
|
|
|
if (!isMobileDevice)
|
2010-09-05 03:02:02 +00:00
|
|
|
$('.dialog_container').hide();
|
2011-08-24 02:04:35 +00:00
|
|
|
setInnerHTML(this._heading[0], dialog_heading);
|
|
|
|
setInnerHTML(this._message[0], dialog_message);
|
2011-09-05 07:46:55 +00:00
|
|
|
setInnerHTML(this._cancel_button[0], cancel_button_label || 'Cancel');
|
2011-08-24 02:04:35 +00:00
|
|
|
setInnerHTML(this._confirm_button[0], confirm_button_label);
|
2010-09-05 03:02:02 +00:00
|
|
|
this._confirm_button.show();
|
|
|
|
this._callback_function = callback_function;
|
|
|
|
this._callback_data = callback_data;
|
|
|
|
$('body').addClass('dialog_showing');
|
|
|
|
this._container.show();
|
|
|
|
transmission.updateButtonStates();
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice)
|
|
|
|
transmission.hideMobileAddressbar();
|
2010-09-05 03:02:02 +00:00
|
|
|
},
|
2011-03-04 23:26:10 +00:00
|
|
|
|
2011-08-28 13:57:25 +00:00
|
|
|
/*
|
|
|
|
* Display an alert dialog
|
|
|
|
*/
|
|
|
|
alert: function(dialog_heading, dialog_message, cancel_button_label) {
|
2011-08-28 17:24:56 +00:00
|
|
|
if (!isMobileDevice)
|
2010-09-05 03:02:02 +00:00
|
|
|
$('.dialog_container').hide();
|
2011-08-24 02:04:35 +00:00
|
|
|
setInnerHTML(this._heading[0], dialog_heading);
|
|
|
|
setInnerHTML(this._message[0], dialog_message);
|
2010-09-05 03:02:02 +00:00
|
|
|
// jquery::hide() doesn't work here in Safari for some odd reason
|
|
|
|
this._confirm_button.css('display', 'none');
|
2011-08-24 02:04:35 +00:00
|
|
|
setInnerHTML(this._cancel_button[0], cancel_button_label);
|
2010-09-05 03:02:02 +00:00
|
|
|
// Just in case
|
2011-08-28 17:24:56 +00:00
|
|
|
$('#upload_container').hide();
|
2010-09-05 03:02:02 +00:00
|
|
|
$('body').addClass('dialog_showing');
|
|
|
|
transmission.updateButtonStates();
|
2011-08-28 17:24:56 +00:00
|
|
|
if (isMobileDevice)
|
|
|
|
transmission.hideMobileAddressbar();
|
|
|
|
this._container.show();
|
2010-09-05 03:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|