1/** 2 * Copyright �� Dave Perrett and Malcolm Jarvis 3 * 4 * This file is licensed under the GPLv2. 5 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 6 */ 7 8function Dialog(){ 9 this.initialize(); 10} 11 12Dialog.prototype = { 13 14 /* 15 * Constructor 16 */ 17 initialize: function() { 18 19 /* 20 * Private Interface Variables 21 */ 22 this._container = $('#dialog_container'); 23 this._heading = $('#dialog_heading'); 24 this._message = $('#dialog_message'); 25 this._cancel_button = $('#dialog_cancel_button'); 26 this._confirm_button = $('#dialog_confirm_button'); 27 this._callback_function = ''; 28 this._callback_data = null; 29 30 // Observe the buttons 31 this._cancel_button.bind('click', {dialog: this}, this.onCancelClicked); 32 this._confirm_button.bind('click', {dialog: this}, this.onConfirmClicked); 33 }, 34 35 36 37 38 39 /*-------------------------------------------- 40 * 41 * E V E N T F U N C T I O N S 42 * 43 *--------------------------------------------*/ 44 45 hideDialog: function() 46 { 47 $('body.dialog_showing').removeClass('dialog_showing'); 48 this._container.hide(); 49 transmission.hideMobileAddressbar(); 50 transmission.updateButtonStates(); 51 }, 52 53 onCancelClicked: function(event) 54 { 55 event.data.dialog.hideDialog(); 56 }, 57 58 onConfirmClicked: function(event) 59 { 60 var dialog = event.data.dialog; 61 eval(dialog._callback_function + "(dialog._callback_data)"); 62 dialog.hideDialog(); 63 }, 64 65 /*-------------------------------------------- 66 * 67 * I N T E R F A C E F U N C T I O N S 68 * 69 *--------------------------------------------*/ 70 71 /* 72 * Display a confirm dialog 73 */ 74 confirm: function(dialog_heading, dialog_message, confirm_button_label, 75 callback_function, callback_data, cancel_button_label) 76 { 77 if (!isMobileDevice) 78 $('.dialog_container').hide(); 79 setTextContent(this._heading[0], dialog_heading); 80 setTextContent(this._message[0], dialog_message); 81 setTextContent(this._cancel_button[0], cancel_button_label || 'Cancel'); 82 setTextContent(this._confirm_button[0], confirm_button_label); 83 this._confirm_button.show(); 84 this._callback_function = callback_function; 85 this._callback_data = callback_data; 86 $('body').addClass('dialog_showing'); 87 this._container.show(); 88 transmission.updateButtonStates(); 89 if (isMobileDevice) 90 transmission.hideMobileAddressbar(); 91 }, 92 93 /* 94 * Display an alert dialog 95 */ 96 alert: function(dialog_heading, dialog_message, cancel_button_label) { 97 if (!isMobileDevice) 98 $('.dialog_container').hide(); 99 setTextContent(this._heading[0], dialog_heading); 100 setTextContent(this._message[0], dialog_message); 101 // jquery::hide() doesn't work here in Safari for some odd reason 102 this._confirm_button.css('display', 'none'); 103 setTextContent(this._cancel_button[0], cancel_button_label); 104 // Just in case 105 $('#upload_container').hide(); 106 $('#move_container').hide(); 107 $('body').addClass('dialog_showing'); 108 transmission.updateButtonStates(); 109 if (isMobileDevice) 110 transmission.hideMobileAddressbar(); 111 this._container.show(); 112 } 113 114 115} 116