2015-11-15 08:23:16 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
import {$} from 'common';
|
2016-06-07 05:57:52 +08:00
|
|
|
import {isUnd} from 'Common/Utils';
|
2015-11-15 08:23:16 +08:00
|
|
|
import ko from 'ko';
|
|
|
|
|
|
|
|
class AbstractComponent
|
|
|
|
{
|
2016-06-28 04:54:38 +08:00
|
|
|
constructor() {
|
|
|
|
this.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
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
const componentExportHelper = (ClassObject, templateID = '') => {
|
2015-11-15 08:23:16 +08:00
|
|
|
return {
|
|
|
|
template: templateID ? {element: templateID} : '<b></b>',
|
|
|
|
viewModel: {
|
|
|
|
createViewModel: (params, componentInfo) => {
|
|
|
|
|
|
|
|
params = params || {};
|
|
|
|
params.element = null;
|
|
|
|
|
|
|
|
if (componentInfo && componentInfo.element)
|
|
|
|
{
|
|
|
|
params.component = componentInfo;
|
|
|
|
params.element = $(componentInfo.element);
|
|
|
|
|
|
|
|
require('Common/Translator').i18nToNodes(params.element);
|
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
if (!isUnd(params.inline) && ko.unwrap(params.inline))
|
2015-11-15 08:23:16 +08:00
|
|
|
{
|
|
|
|
params.element.css('display', 'inline-block');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ClassObject(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-04-21 01:12:51 +08:00
|
|
|
};
|
2015-11-15 08:23:16 +08:00
|
|
|
|
|
|
|
export {AbstractComponent, componentExportHelper};
|