2017-11-21 18:53:09 +08:00
|
|
|
let _appendContentCallbacks = {};
|
|
|
|
function appendContent(pluginApiIdentifiers, contentFunction) {
|
|
|
|
if (Ember.isNone(_appendContentCallbacks[pluginApiIdentifiers])) {
|
|
|
|
_appendContentCallbacks[pluginApiIdentifiers] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
_appendContentCallbacks[pluginApiIdentifiers].push(contentFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
let _prependContentCallbacks = {};
|
|
|
|
function prependContent(pluginApiIdentifiers, contentFunction) {
|
|
|
|
if (Ember.isNone(_prependContentCallbacks[pluginApiIdentifiers])) {
|
|
|
|
_prependContentCallbacks[pluginApiIdentifiers] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
_prependContentCallbacks[pluginApiIdentifiers].push(contentFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
let _modifyContentCallbacks = {};
|
|
|
|
function modifyContent(pluginApiIdentifiers, contentFunction) {
|
|
|
|
if (Ember.isNone(_modifyContentCallbacks[pluginApiIdentifiers])) {
|
|
|
|
_modifyContentCallbacks[pluginApiIdentifiers] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
_modifyContentCallbacks[pluginApiIdentifiers].push(contentFunction);
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:52:32 +08:00
|
|
|
let _modifyHeaderComputedContentCallbacks = {};
|
|
|
|
function modifyHeaderComputedContent(pluginApiIdentifiers, contentFunction) {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
Ember.isNone(_modifyHeaderComputedContentCallbacks[pluginApiIdentifiers])
|
|
|
|
) {
|
2018-01-09 17:52:32 +08:00
|
|
|
_modifyHeaderComputedContentCallbacks[pluginApiIdentifiers] = [];
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
_modifyHeaderComputedContentCallbacks[pluginApiIdentifiers].push(
|
|
|
|
contentFunction
|
|
|
|
);
|
2018-01-09 17:52:32 +08:00
|
|
|
}
|
|
|
|
|
2018-01-26 21:42:24 +08:00
|
|
|
let _modifyCollectionHeaderCallbacks = {};
|
|
|
|
function modifyCollectionHeader(pluginApiIdentifiers, contentFunction) {
|
|
|
|
if (Ember.isNone(_modifyCollectionHeaderCallbacks[pluginApiIdentifiers])) {
|
|
|
|
_modifyCollectionHeaderCallbacks[pluginApiIdentifiers] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
_modifyCollectionHeaderCallbacks[pluginApiIdentifiers].push(contentFunction);
|
|
|
|
}
|
|
|
|
|
2018-09-05 23:18:52 +08:00
|
|
|
let _onSelectNoneCallbacks = {};
|
|
|
|
function onSelectNone(pluginApiIdentifiers, mutationFunction) {
|
|
|
|
if (Ember.isNone(_onSelectNoneCallbacks[pluginApiIdentifiers])) {
|
|
|
|
_onSelectNoneCallbacks[pluginApiIdentifiers] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
_onSelectNoneCallbacks[pluginApiIdentifiers].push(mutationFunction);
|
|
|
|
}
|
|
|
|
|
2017-11-22 17:34:12 +08:00
|
|
|
let _onSelectCallbacks = {};
|
|
|
|
function onSelect(pluginApiIdentifiers, mutationFunction) {
|
|
|
|
if (Ember.isNone(_onSelectCallbacks[pluginApiIdentifiers])) {
|
|
|
|
_onSelectCallbacks[pluginApiIdentifiers] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
_onSelectCallbacks[pluginApiIdentifiers].push(mutationFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function applyContentPluginApiCallbacks(identifiers, content, context) {
|
2018-06-15 23:03:24 +08:00
|
|
|
identifiers.forEach(key => {
|
|
|
|
(_prependContentCallbacks[key] || []).forEach(c => {
|
2019-02-07 21:43:33 +08:00
|
|
|
content = c()
|
|
|
|
.concat(content)
|
|
|
|
.uniqBy("id");
|
2017-11-21 18:53:09 +08:00
|
|
|
});
|
2018-06-15 23:03:24 +08:00
|
|
|
(_appendContentCallbacks[key] || []).forEach(c => {
|
2019-02-07 21:43:33 +08:00
|
|
|
content = content.concat(c()).uniqBy("id");
|
2017-11-21 18:53:09 +08:00
|
|
|
});
|
2018-06-15 23:03:24 +08:00
|
|
|
(_modifyContentCallbacks[key] || []).forEach(c => {
|
2019-02-07 21:43:33 +08:00
|
|
|
content = c(context, content).uniqBy("id");
|
2017-11-21 18:53:09 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
export function applyHeaderContentPluginApiCallbacks(
|
|
|
|
identifiers,
|
|
|
|
content,
|
|
|
|
context
|
|
|
|
) {
|
|
|
|
identifiers.forEach(key => {
|
|
|
|
(_modifyHeaderComputedContentCallbacks[key] || []).forEach(c => {
|
2018-01-09 17:52:32 +08:00
|
|
|
content = c(context, content);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2018-01-26 21:42:24 +08:00
|
|
|
export function applyCollectionHeaderCallbacks(identifiers, content, context) {
|
2018-06-15 23:03:24 +08:00
|
|
|
identifiers.forEach(key => {
|
|
|
|
(_modifyCollectionHeaderCallbacks[key] || []).forEach(c => {
|
2018-01-26 21:42:24 +08:00
|
|
|
content = c(context, content);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2017-11-22 17:34:12 +08:00
|
|
|
export function applyOnSelectPluginApiCallbacks(identifiers, val, context) {
|
2018-06-15 23:03:24 +08:00
|
|
|
identifiers.forEach(key => {
|
|
|
|
(_onSelectCallbacks[key] || []).forEach(c => c(context, val));
|
2017-11-22 17:34:12 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-05 23:18:52 +08:00
|
|
|
export function applyOnSelectNonePluginApiCallbacks(identifiers, context) {
|
|
|
|
identifiers.forEach(key => {
|
|
|
|
(_onSelectNoneCallbacks[key] || []).forEach(c => c(context));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-21 18:53:09 +08:00
|
|
|
export function modifySelectKit(pluginApiIdentifiers) {
|
|
|
|
return {
|
2018-06-15 23:03:24 +08:00
|
|
|
appendContent: content => {
|
|
|
|
appendContent(pluginApiIdentifiers, () => {
|
|
|
|
return content;
|
|
|
|
});
|
2017-11-21 18:53:09 +08:00
|
|
|
return modifySelectKit(pluginApiIdentifiers);
|
|
|
|
},
|
2018-06-15 23:03:24 +08:00
|
|
|
prependContent: content => {
|
|
|
|
prependContent(pluginApiIdentifiers, () => {
|
|
|
|
return content;
|
|
|
|
});
|
2017-11-21 18:53:09 +08:00
|
|
|
return modifySelectKit(pluginApiIdentifiers);
|
|
|
|
},
|
2018-06-15 23:03:24 +08:00
|
|
|
modifyContent: callback => {
|
2017-11-21 18:53:09 +08:00
|
|
|
modifyContent(pluginApiIdentifiers, callback);
|
|
|
|
return modifySelectKit(pluginApiIdentifiers);
|
2017-11-22 17:34:12 +08:00
|
|
|
},
|
2018-06-15 23:03:24 +08:00
|
|
|
modifyHeaderComputedContent: callback => {
|
2018-01-09 17:52:32 +08:00
|
|
|
modifyHeaderComputedContent(pluginApiIdentifiers, callback);
|
|
|
|
return modifySelectKit(pluginApiIdentifiers);
|
|
|
|
},
|
2018-06-15 23:03:24 +08:00
|
|
|
modifyCollectionHeader: callback => {
|
2018-01-26 21:42:24 +08:00
|
|
|
modifyCollectionHeader(pluginApiIdentifiers, callback);
|
|
|
|
return modifySelectKit(pluginApiIdentifiers);
|
|
|
|
},
|
2018-06-15 23:03:24 +08:00
|
|
|
onSelect: callback => {
|
2017-11-22 17:34:12 +08:00
|
|
|
onSelect(pluginApiIdentifiers, callback);
|
|
|
|
return modifySelectKit(pluginApiIdentifiers);
|
2018-09-05 23:18:52 +08:00
|
|
|
},
|
|
|
|
onSelectNone: callback => {
|
|
|
|
onSelectNone(pluginApiIdentifiers, callback);
|
|
|
|
return modifySelectKit(pluginApiIdentifiers);
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function clearCallbacks() {
|
|
|
|
_appendContentCallbacks = {};
|
|
|
|
_prependContentCallbacks = {};
|
|
|
|
_modifyContentCallbacks = {};
|
2018-01-09 17:52:32 +08:00
|
|
|
_modifyHeaderComputedContentCallbacks = {};
|
2018-01-26 21:42:24 +08:00
|
|
|
_modifyCollectionHeaderCallbacks = {};
|
2017-11-22 17:34:12 +08:00
|
|
|
_onSelectCallbacks = {};
|
2018-09-05 23:18:52 +08:00
|
|
|
_onSelectNoneCallbacks = {};
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const EMPTY_ARRAY = Object.freeze([]);
|
|
|
|
export default Ember.Mixin.create({
|
|
|
|
concatenatedProperties: ["pluginApiIdentifiers"],
|
|
|
|
pluginApiIdentifiers: EMPTY_ARRAY
|
|
|
|
});
|