2015-11-15 08:23:16 +08:00
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
import $ from '$';
|
2015-11-15 08:23:16 +08:00
|
|
|
import ko from 'ko';
|
2016-07-02 06:49:59 +08:00
|
|
|
import {isUnd} from 'Common/Utils';
|
2015-11-15 08:23:16 +08:00
|
|
|
|
|
|
|
class AbstractComponent
|
|
|
|
{
|
2016-09-10 06:38:16 +08:00
|
|
|
disposable = [];
|
2015-11-15 08:23:16 +08:00
|
|
|
|
|
|
|
dispose() {
|
2015-11-19 01:32:29 +08:00
|
|
|
this.disposable.forEach((funcToDispose) => {
|
2015-11-15 08:23:16 +08:00
|
|
|
if (funcToDispose && funcToDispose.dispose)
|
|
|
|
{
|
|
|
|
funcToDispose.dispose();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {*} ClassObject
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {string} templateID = ''
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {Object}
|
2015-11-15 08:23:16 +08:00
|
|
|
*/
|
2016-07-02 06:49:59 +08:00
|
|
|
const componentExportHelper = (ClassObject, templateID = '') => ({
|
|
|
|
template: templateID ? {element: templateID} : '<b></b>',
|
|
|
|
viewModel: {
|
|
|
|
createViewModel: (params, componentInfo) => {
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
params = params || {};
|
|
|
|
params.element = null;
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
if (componentInfo && componentInfo.element)
|
|
|
|
{
|
|
|
|
params.component = componentInfo;
|
|
|
|
params.element = $(componentInfo.element);
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
require('Common/Translator').i18nToNodes(params.element);
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
if (!isUnd(params.inline) && ko.unwrap(params.inline))
|
|
|
|
{
|
|
|
|
params.element.css('display', 'inline-block');
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
}
|
2016-07-02 06:49:59 +08:00
|
|
|
|
|
|
|
return new ClassObject(params);
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
2016-07-02 06:49:59 +08:00
|
|
|
}
|
|
|
|
});
|
2015-11-15 08:23:16 +08:00
|
|
|
|
|
|
|
export {AbstractComponent, componentExportHelper};
|