You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.2 KiB
JavaScript
68 lines
2.2 KiB
JavaScript
var _veUiMWCategoryInputWidgetPopulateLookupMenu = ve.ui.MWCategoryInputWidget.prototype.populateLookupMenu;
|
|
|
|
ve.ui.MWCategoryInputWidget.prototype.populateLookupMenu = function () {
|
|
this.allowSuggestionsWhenEmpty = true;
|
|
_veUiMWCategoryInputWidgetPopulateLookupMenu.call(this);
|
|
};
|
|
|
|
ve.ui.MWCategoryInputWidget.prototype.isekaiGetCategoryItemFromData = function (data, indent) {
|
|
indent = indent || 0;
|
|
var items = [];
|
|
data.forEach(function (cInfo) {
|
|
var item;
|
|
var indentText = ' '.repeat(indent * 2);
|
|
if (cInfo.isSection) {
|
|
item = new OO.ui.MenuSectionOptionWidget({
|
|
data: cInfo.category,
|
|
label: indentText + cInfo.label
|
|
});
|
|
} else {
|
|
item = new OO.ui.MenuOptionWidget({
|
|
data: cInfo.category,
|
|
label: indentText + cInfo.label,
|
|
})
|
|
}
|
|
items.push(item);
|
|
|
|
if (Array.isArray(cInfo.children)) {
|
|
items = items.concat(this.isekaiGetCategoryItemFromData(cInfo.children, indent + 1));
|
|
}
|
|
}.bind(this));
|
|
return items;
|
|
};
|
|
|
|
ve.ui.MWCategoryInputWidget.prototype.getLookupMenuItems = function () {
|
|
deferred = $.Deferred();
|
|
|
|
if (this.value === '') {
|
|
if (this.cachedMainCategories) {
|
|
return deferred.resolve(this.cachedMainCategories);
|
|
}
|
|
|
|
var mcUrl = mw.config.get('wgIsekaiMainCategoriesIndexUrl');
|
|
var itemWidgets = [];
|
|
|
|
// Section header
|
|
itemWidgets.push(
|
|
new OO.ui.MenuSectionOptionWidget({
|
|
data: 'mainCategories',
|
|
label: ve.msg('isekai-ve-dialog-meta-categories-input-maincategorieslabel')
|
|
})
|
|
);
|
|
|
|
return $.ajax({
|
|
url: mcUrl,
|
|
type: 'GET',
|
|
dataType: 'json',
|
|
}).then(function (data) {
|
|
var categoryItems = this.isekaiGetCategoryItemFromData(data);
|
|
itemWidgets = itemWidgets.concat(categoryItems);
|
|
this.cachedMainCategories = itemWidgets;
|
|
return deferred.resolve(itemWidgets);
|
|
}.bind(this));
|
|
} else {
|
|
return this.getRequestData().then(function (data) {
|
|
return this.getLookupMenuOptionsFromData(data);
|
|
}.bind(this));
|
|
}
|
|
}; |