snappymail/dev/Common/Plugins.js

110 lines
2.1 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-20 23:03:12 +08:00
var
2014-08-25 23:49:01 +08:00
_ = require('_'),
Globals = require('Common/Globals'),
2014-09-05 06:49:03 +08:00
Utils = require('Common/Utils')
2014-08-20 23:03:12 +08:00
;
/**
* @constructor
2014-08-20 23:03:12 +08:00
*/
function Plugins()
{
this.oSettings = require('Storage/Settings');
this.oViewModelsHooks = {};
this.oSimpleHooks = {};
}
/**
* @type {Object}
*/
Plugins.prototype.oSettings = {};
2014-08-20 23:03:12 +08:00
/**
* @type {Object}
*/
Plugins.prototype.oViewModelsHooks = {};
2014-08-20 23:03:12 +08:00
/**
* @type {Object}
2014-08-20 23:03:12 +08:00
*/
Plugins.prototype.oSimpleHooks = {};
2014-08-20 23:03:12 +08:00
/**
* @param {string} sName
* @param {Function} fCallback
*/
Plugins.prototype.addHook = function (sName, fCallback)
{
2014-08-20 23:03:12 +08:00
if (Utils.isFunc(fCallback))
{
if (!Utils.isArray(this.oSimpleHooks[sName]))
2014-08-20 23:03:12 +08:00
{
this.oSimpleHooks[sName] = [];
2014-08-20 23:03:12 +08:00
}
this.oSimpleHooks[sName].push(fCallback);
}
2014-08-20 23:03:12 +08:00
};
2014-08-20 23:03:12 +08:00
/**
* @param {string} sName
* @param {Array=} aArguments
*/
Plugins.prototype.runHook = function (sName, aArguments)
{
if (Utils.isArray(this.oSimpleHooks[sName]))
2014-08-20 23:03:12 +08:00
{
aArguments = aArguments || [];
_.each(this.oSimpleHooks[sName], function (fCallback) {
2014-08-20 23:03:12 +08:00
fCallback.apply(null, aArguments);
});
}
};
/**
* @param {string} sName
* @return {?}
*/
Plugins.prototype.mainSettingsGet = function (sName)
2014-08-20 23:03:12 +08:00
{
return this.oSettings.settingsGet(sName);
2014-08-20 23:03:12 +08:00
};
2014-08-20 23:03:12 +08:00
/**
* @param {Function} fCallback
* @param {string} sAction
* @param {Object=} oParameters
* @param {?number=} iTimeout
* @param {string=} sGetAdd = ''
* @param {Array=} aAbortActions = []
*/
Plugins.prototype.remoteRequest = function (fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions)
{
if (Globals.__APP__)
2014-08-20 23:03:12 +08:00
{
Globals.__APP__.remote().defaultRequest(fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions);
2014-08-20 23:03:12 +08:00
}
};
2014-08-20 23:03:12 +08:00
/**
* @param {string} sPluginSection
* @param {string} sName
* @return {?}
*/
Plugins.prototype.settingsGet = function (sPluginSection, sName)
2014-08-20 23:03:12 +08:00
{
var oPlugin = this.oSettings.settingsGet('Plugins');
2014-08-26 14:31:20 +08:00
oPlugin = oPlugin && !Utils.isUnd(oPlugin[sPluginSection]) ? oPlugin[sPluginSection] : null;
2014-08-20 23:03:12 +08:00
return oPlugin ? (Utils.isUnd(oPlugin[sName]) ? null : oPlugin[sName]) : null;
};
module.exports = new Plugins();
2014-09-05 06:49:03 +08:00
}());