2013-04-29 21:01:56 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWCategoryPopupWidget class.
|
|
|
|
*
|
2019-01-01 13:24:23 +00:00
|
|
|
* @copyright 2011-2019 VisualEditor Team and others; see AUTHORS.txt
|
2013-04-29 21:01:56 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an ve.ui.MWCategoryPopupWidget object.
|
|
|
|
*
|
|
|
|
* @class
|
2013-10-09 20:09:59 +00:00
|
|
|
* @extends OO.ui.PopupWidget
|
2013-04-29 21:01:56 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
2014-05-15 16:12:43 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget = function VeUiMWCategoryPopupWidget( config ) {
|
2013-05-16 19:34:18 +00:00
|
|
|
// Configuration initialization
|
2014-08-22 20:50:48 +00:00
|
|
|
config = ve.extendObject( { autoClose: true }, config );
|
2013-05-16 19:34:18 +00:00
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.super.call( this, config );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.category = null;
|
2013-06-10 22:48:01 +00:00
|
|
|
this.origSortkey = null;
|
|
|
|
this.removed = false;
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$title = $( '<label>' );
|
|
|
|
this.$menu = $( '<div>' );
|
2018-10-30 23:51:34 +00:00
|
|
|
this.fallbackSortKey = mw.config.get( 'wgTitle' );
|
2014-01-17 14:24:12 +00:00
|
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
2017-05-31 23:30:17 +00:00
|
|
|
icon: 'trash',
|
2014-08-22 20:50:48 +00:00
|
|
|
title: ve.msg( 'visualeditor-inspector-remove-tooltip' )
|
2013-04-29 21:01:56 +00:00
|
|
|
} );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.sortKeyInput = new OO.ui.TextInputWidget();
|
2014-01-22 20:13:59 +00:00
|
|
|
this.sortKeyField = new OO.ui.FieldLayout( this.sortKeyInput, {
|
2014-08-22 20:50:48 +00:00
|
|
|
align: 'top',
|
2015-01-31 00:41:37 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-categories-sortkey-label' )
|
2014-01-22 20:13:59 +00:00
|
|
|
} );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$sortKeyForm = $( '<form>' ).addClass( 've-ui-mwCategoryPopupWidget-sortKeyForm' )
|
2014-01-22 20:13:59 +00:00
|
|
|
.append( this.sortKeyField.$element );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Events
|
2014-10-21 19:16:16 +00:00
|
|
|
this.connect( this, { toggle: 'onToggle' } );
|
2014-08-22 20:50:48 +00:00
|
|
|
this.removeButton.connect( this, { click: 'onRemoveCategory' } );
|
2014-07-08 22:33:32 +00:00
|
|
|
this.$sortKeyForm.on( 'submit', this.onSortKeySubmit.bind( this ) );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Initialization
|
2015-01-29 23:09:47 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwCategoryPopupWidget' );
|
|
|
|
this.toggle( false );
|
2013-04-29 21:01:56 +00:00
|
|
|
this.$title
|
2013-10-09 20:09:59 +00:00
|
|
|
.addClass( 've-ui-mwCategoryPopupWidget-title oo-ui-icon-tag' )
|
2013-06-12 23:43:23 +00:00
|
|
|
.text( ve.msg( 'visualeditor-dialog-meta-categories-category' ) );
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$hiddenStatus = $( '<div>' );
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$menu
|
|
|
|
.addClass( 've-ui-mwCategoryPopupWidget-content' )
|
|
|
|
.append(
|
|
|
|
this.$title,
|
2014-02-14 20:03:42 +00:00
|
|
|
this.$hiddenStatus,
|
2013-11-01 19:45:59 +00:00
|
|
|
this.removeButton.$element.addClass( 've-ui-mwCategoryPopupWidget-removeButton' ),
|
2013-10-02 00:00:57 +00:00
|
|
|
this.$sortKeyForm
|
|
|
|
);
|
2013-04-29 21:01:56 +00:00
|
|
|
this.$body.append( this.$menu );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.inheritClass( ve.ui.MWCategoryPopupWidget, OO.ui.PopupWidget );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event removeCategory
|
2013-06-10 22:22:30 +00:00
|
|
|
* @param {string} category Category name
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event updateSortkey
|
2013-06-10 22:22:30 +00:00
|
|
|
* @param {string} category Category name
|
|
|
|
* @param {string} sortkey New sortkey
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Handle category remove events.
|
|
|
|
*
|
|
|
|
* @method
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires removeCategory
|
2013-06-10 22:22:30 +00:00
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.onRemoveCategory = function () {
|
2013-06-10 22:48:01 +00:00
|
|
|
this.removed = true;
|
2013-04-29 21:01:56 +00:00
|
|
|
this.emit( 'removeCategory', this.category );
|
|
|
|
this.closePopup();
|
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Handle sort key form submit events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Form submit event
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {boolean}
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires updateSortkey
|
2013-06-10 22:22:30 +00:00
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.onSortKeySubmit = function () {
|
|
|
|
this.closePopup();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Open a category item popup.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.ui.MWCategoryItemWidget} item Category item
|
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.openPopup = function ( item ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.toggle( true );
|
2013-04-29 21:01:56 +00:00
|
|
|
this.popupOpen = true;
|
|
|
|
this.category = item.value;
|
|
|
|
this.loadCategoryIntoPopup( item );
|
|
|
|
this.setPopup( item );
|
|
|
|
};
|
|
|
|
|
2013-06-12 23:25:28 +00:00
|
|
|
/**
|
2014-10-21 19:16:16 +00:00
|
|
|
* Handle popup toggle events.
|
2013-06-12 23:25:28 +00:00
|
|
|
*
|
2014-10-21 19:16:16 +00:00
|
|
|
* @param {boolean} show Widget is being made visible
|
2013-06-12 23:25:28 +00:00
|
|
|
* @method
|
|
|
|
*/
|
2014-10-21 19:16:16 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.onToggle = function ( show ) {
|
2015-08-19 18:05:01 +00:00
|
|
|
var newSortkey;
|
2014-10-21 19:16:16 +00:00
|
|
|
if ( show ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-19 18:05:01 +00:00
|
|
|
newSortkey = this.sortKeyInput.$input.val();
|
2013-11-27 17:26:49 +00:00
|
|
|
if ( !this.removed && newSortkey !== ( this.origSortkey || '' ) ) {
|
2018-10-30 23:51:34 +00:00
|
|
|
if ( newSortkey === this.fallbackSortKey ) {
|
|
|
|
this.emit( 'updateSortkey', this.category, '' );
|
|
|
|
} else {
|
|
|
|
this.emit( 'updateSortkey', this.category, this.sortKeyInput.$input.val() );
|
|
|
|
}
|
2013-06-12 23:25:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Load item information into the popup.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.ui.MWCategoryItemWidget} item Category item
|
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.loadCategoryIntoPopup = function ( item ) {
|
2018-10-30 23:51:34 +00:00
|
|
|
this.origSortkey = item.sortKey || this.fallbackSortKey;
|
2014-02-14 20:03:42 +00:00
|
|
|
if ( item.isHidden ) {
|
|
|
|
this.$hiddenStatus.text( ve.msg( 'visualeditor-dialog-meta-categories-hidden' ) );
|
2014-11-05 22:45:09 +00:00
|
|
|
} else if ( item.isMissing ) {
|
|
|
|
this.$hiddenStatus.text( ve.msg( 'visualeditor-dialog-meta-categories-missing' ) );
|
2014-02-14 20:03:42 +00:00
|
|
|
} else {
|
|
|
|
this.$hiddenStatus.empty();
|
|
|
|
}
|
2018-10-30 23:51:34 +00:00
|
|
|
this.sortKeyInput.$input.val( this.origSortkey );
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Close the popup.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.closePopup = function () {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.toggle( false );
|
2013-04-29 21:01:56 +00:00
|
|
|
this.popupOpen = false;
|
2016-09-13 03:17:20 +00:00
|
|
|
this.category = null;
|
2018-10-30 19:37:22 +00:00
|
|
|
this.origSortkey = null;
|
|
|
|
this.removed = false;
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Set the default sort key.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} value Default sort key value
|
|
|
|
*/
|
2013-05-03 22:17:35 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.setDefaultSortKey = function ( value ) {
|
2018-10-30 23:51:34 +00:00
|
|
|
this.fallbackSortKey = value;
|
2013-05-03 22:17:35 +00:00
|
|
|
};
|
|
|
|
|
2013-06-10 22:22:30 +00:00
|
|
|
/**
|
|
|
|
* Display the popup next to an item.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.ui.MWCategoryItemWidget} item Category item
|
|
|
|
*/
|
2013-04-29 21:01:56 +00:00
|
|
|
ve.ui.MWCategoryPopupWidget.prototype.setPopup = function ( item ) {
|
2017-04-19 20:48:16 +00:00
|
|
|
this.setFloatableContainer( item.$element );
|
2015-04-02 23:50:25 +00:00
|
|
|
this.updateDimensions();
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|