1 /** 2 * @author Gillis Haasnoot <gillis.haasnoot@gmail.com> 3 * @package Banana.Controls 4 * @summary Confirm modal 5 */ 6 7 goog.provide('Banana.Controls.ConfirmModal'); 8 9 goog.require('Banana.Controls.Modal'); 10 11 12 /** @namespace Banana.Controls.ConfirmModal */ 13 namespace('Banana.Controls').ConfirmModal = Banana.Controls.Modal.extend( 14 /** @lends Banana.Controls.ConfirmModal.prototype */ 15 { 16 /** 17 * Creates a modal in which we have confirm to continue. Handy for crucial operations. 18 * The data passed along defines the texts shown in the modal. 19 * 20 * Example: 21 22 //if we not have the confirm modal already, create it. 23 if (!this.confirm) 24 { 25 this.confirm = new Banana.Controls.ConfirmModal(); 26 this.addControl(this.confirm, true); 27 } 28 29 this.confirm.setTitle("title") 30 this.confirm.setTextTitle("texttitle"); 31 this.confirm.setText("text") 32 33 this.confirm.bind('onOk', this.getProxy(function(){ 34 35 //do things here 36 })); 37 38 //display the confirm modal 39 this.confirm.show(); 40 * 41 * @constructs 42 * @extends Banana.Controls.Modal 43 */ 44 init : function() 45 { 46 this._super(); 47 48 this.text = new Banana.Controls.Label(); 49 this.text.addCssClass('BConfirmModalText'); 50 51 this.textTitle = new Banana.Controls.Label(); 52 this.textTitle.addCssClass('BConfirmModalTitle'); 53 }, 54 55 /** 56 * @override 57 * @ignore 58 */ 59 createComponents : function() 60 { 61 this._super(); 62 this.container.addCssClass('BConfirmModal'); 63 64 var image = new Banana.Controls.Panel(); 65 image.addCssClass('BConfirmModalImage'); 66 67 var container = new Banana.Controls.Panel(); 68 container.addCssClass('BConfirmModalContainer'); 69 70 container.addControl(this.textTitle); 71 container.addControl(this.text); 72 73 this.addControl(image); 74 this.addControl(container); 75 76 var buttons = {'Ok':this.getProxy(function() 77 { 78 this.triggerEvent('onOk'); 79 this.hide(); 80 }), 81 'Cancel':this.getProxy(function() 82 { 83 this.hide(); 84 85 })}; 86 this.setButtons(buttons); 87 }, 88 89 /** 90 * 91 * @param {String} text 92 * @returns {Banana.Controls.ConfirmModal} 93 */ 94 setTextTitle : function(text) 95 { 96 this.textTitle.setData(text); 97 return this; 98 }, 99 100 /** 101 * 102 * @param {String} text 103 * @returns {Banana.Controls.ConfirmModal} 104 */ 105 setText : function(text) 106 { 107 this.text.setData(text); 108 return this; 109 }, 110 111 /** 112 * @override 113 */ 114 show : function() 115 { 116 this.textTitle.setVisible(this.textTitle.getData()); 117 this.text.setVisible(this.text.getData()); 118 119 this._super(); 120 } 121 });