snappymail/dev/Component/Abstract.js

77 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-10-29 06:05:50 +08:00
(function () {
'use strict';
var
_ = require('_'),
ko = require('ko'),
Utils = require('Common/Utils')
;
/**
* @constructor
*/
function AbstractComponent()
{
this.disposable = [];
}
/**
* @type {Array}
*/
AbstractComponent.prototype.disposable = [];
AbstractComponent.prototype.dispose = function ()
{
_.each(this.disposable, function (fFuncToDispose) {
if (fFuncToDispose && fFuncToDispose.dispose)
{
fFuncToDispose.dispose();
}
});
};
/**
2014-10-30 23:09:48 +08:00
* @param {*} ClassObject
2014-10-29 06:05:50 +08:00
* @param {string} sTemplateID
* @return {Object}
*/
2014-10-30 23:09:48 +08:00
AbstractComponent.componentExportHelper = function (ClassObject, sTemplateID) {
var oComponent = {
2014-10-29 06:05:50 +08:00
viewModel: {
createViewModel: function(oParams, oComponentInfo) {
2014-10-29 06:05:50 +08:00
oParams = oParams || {};
oParams.element = null;
if (oComponentInfo.element)
2014-10-29 06:05:50 +08:00
{
oParams.component = oComponentInfo;
oParams.element = $(oComponentInfo.element);
2014-10-29 06:05:50 +08:00
2015-03-07 08:32:06 +08:00
require('Common/Translator').i18nToNodes(oParams.element);
2014-10-29 06:05:50 +08:00
if (!Utils.isUnd(oParams.inline) && ko.unwrap(oParams.inline))
{
oParams.element.css('display', 'inline-block');
}
}
2014-10-30 23:09:48 +08:00
return new ClassObject(oParams);
2014-10-29 06:05:50 +08:00
}
}
};
oComponent['template'] = sTemplateID ? {
element: sTemplateID
} : '<b></b>';
return oComponent;
2014-10-29 06:05:50 +08:00
};
module.exports = AbstractComponent;
}());