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