2013-02-20 19:44:44 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface Dialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UserInterface dialog.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
*
|
|
|
|
* @constructor
|
2013-03-12 21:05:25 +00:00
|
|
|
* @param {ve.Surface} surface
|
2013-02-20 19:44:44 +00:00
|
|
|
*/
|
|
|
|
ve.ui.Dialog = function VeUiDialog( surface ) {
|
2013-03-06 22:04:20 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.EventEmitter.call( this );
|
|
|
|
|
2013-02-20 19:44:44 +00:00
|
|
|
// Properties
|
|
|
|
this.surface = surface;
|
|
|
|
this.visible = false;
|
|
|
|
this.$ = $( '<div class="ve-ui-dialog"></div>' );
|
2013-03-06 22:04:20 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.cancelButton = new ve.ui.ButtonWidget( { 'label': ve.msg( 'cancel' ) } );
|
2013-03-08 21:51:58 +00:00
|
|
|
this.cancelButton.on( 'click', ve.bind( surface.target.closeDialog, surface.target ) );
|
2013-03-06 22:04:20 +00:00
|
|
|
|
|
|
|
this.applyButton = new ve.ui.ButtonWidget( {
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-label-apply' ),
|
|
|
|
'flags': ['constructive'],
|
|
|
|
'disabled': false
|
|
|
|
} );
|
2013-03-08 21:51:58 +00:00
|
|
|
this.applyButton.on( 'click', ve.bind( this.onApply, this ) );
|
2013-03-06 22:04:20 +00:00
|
|
|
|
|
|
|
// Base elements
|
|
|
|
this.$title = $( '<div class="ve-ui-dialog-title"></div>' ).text(
|
|
|
|
ve.msg( this.constructor.static.dialogTitleMessage )
|
|
|
|
);
|
|
|
|
this.$actions = $( '<div class="ve-ui-dialog-actions"><div>' ).append(
|
|
|
|
this.cancelButton.$, this.applyButton.$
|
|
|
|
);
|
|
|
|
this.$.append( this.$title, this.$actions, $( '<div class="ve-ui-dialog-container"></div>' ) );
|
2013-02-20 19:44:44 +00:00
|
|
|
};
|
|
|
|
|
2013-03-06 22:04:20 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.ui.Dialog, ve.EventEmitter );
|
|
|
|
|
2013-02-20 19:44:44 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
ve.ui.Dialog.prototype.isVisible = function () {
|
|
|
|
return this.visible;
|
|
|
|
};
|
|
|
|
|
2013-03-06 22:04:20 +00:00
|
|
|
ve.ui.Dialog.prototype.open = function () {
|
|
|
|
this.emit( 'open' );
|
2013-02-20 19:44:44 +00:00
|
|
|
this.$.show();
|
|
|
|
this.visible = true;
|
|
|
|
};
|
|
|
|
|
2013-03-06 22:04:20 +00:00
|
|
|
ve.ui.Dialog.prototype.close = function () {
|
|
|
|
this.emit( 'close' );
|
2013-02-20 19:44:44 +00:00
|
|
|
this.$.hide();
|
|
|
|
this.visible = false;
|
|
|
|
};
|
2013-03-08 21:51:58 +00:00
|
|
|
|
|
|
|
ve.ui.Dialog.prototype.onApply = function () {
|
|
|
|
this.emit( 'apply' );
|
|
|
|
this.surface.target.closeDialog();
|
|
|
|
};
|