mediawiki-extensions-Visual.../modules/ve/ui/widgets/ve.ui.MWCategoryPopupWidget.js
Trevor Parscal 8409d16f0f Fieldsets and default sort keys
Objective:
* Add default sort key field to meta dialog
* Replace PagePanelLayout with a generic panel containing one or more FieldsetLayout elements

Changes:

*.php
* Added/removed file links

ve.dm.MWDefaultSortMetaItem.js
* Added getContent method

ve.dm.MetaItem.js
* Added replaceWith method

ve.dm.MetaList.js
* Allow insertion at the end by omitting offset and index

ve.dm.MWMetaDialog.js
* Added default sort key field
* Put category and default sort fields inside fieldsets
* Added loading/saving default sort key

ve.ui.PagedLayout.js
* Changed class used for pages to generic panel layout

ve.ui.PagePanelLayout
* Moved title/icon stuff to field set

ve.ui.FieldsetLayout.js
* New class, adds fieldset with legend

ve.ui.StackPanelLayout.js
* Moved up to the layouts directory

ve.ui.Dialog.css
* Moved style for paged panel from layout stylesheet

ve.ui.Layout.css
* Added styles for fieldsets

ve.ui.Widget.css
* Adjusted margins of input label widgets

ve.ui.MWCategoryWidget.js, ve.ui.MWCategoryPopupWidget.js
* Added setDefaultSortKey method

Change-Id: I979f5e3f08a688790c9f54086206ed1999af13ea
2013-05-10 16:46:08 -07:00

110 lines
3 KiB
JavaScript

/*!
* VisualEditor UserInterface MWCategoryPopupWidget class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates an ve.ui.MWCategoryPopupWidget object.
*
* @class
* @extends ve.ui.PopupWidget
*
* @constructor
* @param {Object} [config] Config options
*/
ve.ui.MWCategoryPopupWidget = function VeUiMwCategoryPopupWidget ( config ) {
// Parent constructor
ve.ui.PopupWidget.call( this, config );
// Properties
this.category = null;
this.$title = this.$$( '<label>' );
this.$menu = this.$$( '<div>' );
this.removeButton = new ve.ui.IconButtonWidget( {
'$$': this.$$, 'icon': 'remove', 'title': ve.msg( 'visualeditor-inspector-remove-tooltip' )
} );
this.sortKeyInput = new ve.ui.TextInputWidget( { '$$': this.$$ } );
this.sortKeyLabel = new ve.ui.InputLabelWidget(
{ '$$': this.$$, '$input': this.sortKeyInput, 'label': 'Page name in category' }
);
this.$sortKeyForm = this.$$( '<form>' ).addClass( 've-ui-mwCategorySortkeyForm' )
.append( this.sortKeyLabel.$, this.sortKeyInput.$ );
// Events
this.removeButton.connect( this, { 'click': 'onRemoveCategory' } );
this.$sortKeyForm.on( 'submit', ve.bind( this.onSortKeySubmit, this ) );
// Initialization
this.$.addClass( 've-ui-mwCategoryPopupMenu' ).hide();
this.$title
.addClass( 've-ui-mwCategoryPopupTitle ve-ui-icon-tag' )
.text( ve.msg( 'visualeditor-category-settings-label' ) );
this.$menu.append(
this.$title,
this.removeButton.$.addClass( 've-ui-mwCategoryRemoveButton' ),
this.$sortKeyForm
);
this.$body.append( this.$menu );
config.$overlay.append( this.$ );
};
/* Inheritance */
ve.inheritClass( ve.ui.MWCategoryPopupWidget, ve.ui.PopupWidget );
/* Events */
/**
* @event removeCategory
*/
/**
* @event updateSortkey
*/
/* Methods */
ve.ui.MWCategoryPopupWidget.prototype.onRemoveCategory = function () {
this.emit( 'removeCategory', this.category );
this.closePopup();
};
ve.ui.MWCategoryPopupWidget.prototype.onSortKeySubmit = function () {
this.emit( 'updateSortkey', this.category, this.sortKeyInput.$input.val() );
this.closePopup();
return false;
};
ve.ui.MWCategoryPopupWidget.prototype.openPopup = function ( item ) {
this.show();
this.popupOpen = true;
this.category = item.value;
this.loadCategoryIntoPopup( item );
this.setPopup( item );
};
ve.ui.MWCategoryPopupWidget.prototype.loadCategoryIntoPopup = function ( item ) {
this.sortKeyInput.$input.val( item.sortKey );
};
ve.ui.MWCategoryPopupWidget.prototype.closePopup = function () {
this.hide();
this.popupOpen = false;
};
ve.ui.MWCategoryPopupWidget.prototype.setDefaultSortKey = function ( value ) {
this.sortKeyInput.$input.attr( 'placeholder', value );
};
ve.ui.MWCategoryPopupWidget.prototype.setPopup = function ( item ) {
var left = item.$.offset().left + ( item.$.width() - 17 ),
top = item.$.offset().top + item.$.height(),
width = this.$menu.outerWidth( true ),
height = this.$menu.outerHeight( true );
this.$.css( { 'left': left, 'top': top } );
this.display( left, top, width, height );
};