| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ui.MWCategoryPopupWidget = function VeUiMWCategoryPopupWidget( config ) { |
| 18 |
|
| 19 |
config = ve.extendObject( { autoClose: true }, config ); |
| 20 |
|
| 21 |
|
| 22 |
ve.ui.MWCategoryPopupWidget.super.call( this, config ); |
| 23 |
|
| 24 |
|
| 25 |
this.category = null; |
| 26 |
this.origSortkey = null; |
| 27 |
this.removed = false; |
| 28 |
this.$title = $( '<label>' ); |
| 29 |
this.$menu = $( '<div>' ); |
| 30 |
this.fallbackSortKey = ve.init.target.getPageName(); |
| 31 |
this.removeButton = new OO.ui.ButtonWidget( { |
| 32 |
framed: false, |
| 33 |
icon: 'trash', |
| 34 |
title: ve.msg( 'visualeditor-inspector-remove-tooltip' ) |
| 35 |
} ); |
| 36 |
this.sortKeyInput = new OO.ui.TextInputWidget(); |
| 37 |
this.sortKeyField = new OO.ui.FieldLayout( this.sortKeyInput, { |
| 38 |
align: 'top', |
| 39 |
label: ve.msg( 'visualeditor-dialog-meta-categories-sortkey-label' ) |
| 40 |
} ); |
| 41 |
this.$sortKeyForm = $( '<form>' ).addClass( 've-ui-mwCategoryPopupWidget-sortKeyForm' ) |
| 42 |
.append( this.sortKeyField.$element ); |
| 43 |
|
| 44 |
|
| 45 |
this.connect( this, { toggle: 'onToggle' } ); |
| 46 |
this.removeButton.connect( this, { click: 'onRemoveCategory' } ); |
| 47 |
this.$sortKeyForm.on( 'submit', this.onSortKeySubmit.bind( this ) ); |
| 48 |
|
| 49 |
|
| 50 |
this.$element |
| 51 |
.addClass( 've-ui-mwCategoryPopupWidget' ); |
| 52 |
this.toggle( false ); |
| 53 |
this.$title |
| 54 |
.addClass( 've-ui-mwCategoryPopupWidget-title oo-ui-icon-tag' ) |
| 55 |
.text( ve.msg( 'visualeditor-dialog-meta-categories-category' ) ); |
| 56 |
this.$hiddenStatus = $( '<div>' ); |
| 57 |
this.$menu |
| 58 |
.addClass( 've-ui-mwCategoryPopupWidget-content' ) |
| 59 |
.append( |
| 60 |
this.$title, |
| 61 |
this.$hiddenStatus, |
| 62 |
this.removeButton.$element.addClass( 've-ui-mwCategoryPopupWidget-removeButton' ), |
| 63 |
this.$sortKeyForm |
| 64 |
); |
| 65 |
this.$body.append( this.$menu ); |
| 66 |
}; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
OO.inheritClass( ve.ui.MWCategoryPopupWidget, OO.ui.PopupWidget ); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ve.ui.MWCategoryPopupWidget.prototype.onRemoveCategory = function () { |
| 93 |
this.removed = true; |
| 94 |
this.emit( 'removeCategory', this.category ); |
| 95 |
this.closePopup(); |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
ve.ui.MWCategoryPopupWidget.prototype.onSortKeySubmit = function () { |
| 106 |
this.closePopup(); |
| 107 |
return false; |
| 108 |
}; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
ve.ui.MWCategoryPopupWidget.prototype.openPopup = function ( item ) { |
| 116 |
this.toggle( true ); |
| 117 |
this.popupOpen = true; |
| 118 |
this.category = item.value; |
| 119 |
this.loadCategoryIntoPopup( item ); |
| 120 |
this.setPopup( item ); |
| 121 |
}; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
ve.ui.MWCategoryPopupWidget.prototype.onToggle = function ( show ) { |
| 130 |
if ( show ) { |
| 131 |
return; |
| 132 |
} |
| 133 |
const newSortkey = this.sortKeyInput.$input.val(); |
| 134 |
if ( !this.removed && newSortkey !== ( this.origSortkey || '' ) ) { |
| 135 |
if ( newSortkey === this.fallbackSortKey ) { |
| 136 |
this.emit( 'updateSortkey', this.category, '' ); |
| 137 |
} else { |
| 138 |
this.emit( 'updateSortkey', this.category, this.sortKeyInput.$input.val() ); |
| 139 |
} |
| 140 |
} |
| 141 |
}; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
ve.ui.MWCategoryPopupWidget.prototype.loadCategoryIntoPopup = function ( item ) { |
| 149 |
this.origSortkey = item.sortKey || this.fallbackSortKey; |
| 150 |
if ( item.isHidden ) { |
| 151 |
this.$hiddenStatus.text( ve.msg( 'visualeditor-dialog-meta-categories-hidden' ) ); |
| 152 |
} else if ( item.isMissing ) { |
| 153 |
this.$hiddenStatus.text( ve.msg( 'visualeditor-dialog-meta-categories-missing' ) ); |
| 154 |
} else { |
| 155 |
this.$hiddenStatus.empty(); |
| 156 |
} |
| 157 |
this.sortKeyInput.$input.val( this.origSortkey ); |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
ve.ui.MWCategoryPopupWidget.prototype.closePopup = function () { |
| 164 |
this.toggle( false ); |
| 165 |
this.popupOpen = false; |
| 166 |
this.category = null; |
| 167 |
this.origSortkey = null; |
| 168 |
this.removed = false; |
| 169 |
}; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
ve.ui.MWCategoryPopupWidget.prototype.setDefaultSortKey = function ( value ) { |
| 177 |
this.fallbackSortKey = value; |
| 178 |
}; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
ve.ui.MWCategoryPopupWidget.prototype.setPopup = function ( item ) { |
| 186 |
this.setFloatableContainer( item.$element ); |
| 187 |
this.updateDimensions(); |
| 188 |
}; |