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.oSimpleHooks = {};
|
2015-02-19 09:01:59 +08:00
|
|
|
|
|
|
|
this.aUserViewModelsHooks = [];
|
|
|
|
this.aAdminViewModelsHooks = [];
|
2014-09-02 08:15:31 +08:00
|
|
|
}
|
|
|
|
|
2014-09-05 23:53:44 +08:00
|
|
|
/**
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
Plugins.prototype.oSettings = {};
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
2015-02-19 09:01:59 +08:00
|
|
|
* @type {Array}
|
|
|
|
*/
|
|
|
|
Plugins.prototype.aUserViewModelsHooks = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Array}
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2015-02-19 09:01:59 +08:00
|
|
|
Plugins.prototype.aAdminViewModelsHooks = [];
|
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
|
|
|
|
*/
|
2015-02-19 09:01:59 +08:00
|
|
|
Plugins.prototype.remoteRequest = function (fCallback, sAction, oParameters, iTimeout)
|
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
|
|
|
{
|
2015-02-19 09:01:59 +08:00
|
|
|
Globals.__APP__.remote().defaultRequest(fCallback, 'Plugin' + sAction, oParameters, iTimeout);
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-19 09:01:59 +08:00
|
|
|
/**
|
|
|
|
* @param {Function} SettingsViewModelClass
|
|
|
|
* @param {string} sLabelName
|
|
|
|
* @param {string} sTemplate
|
|
|
|
* @param {string} sRoute
|
|
|
|
*/
|
|
|
|
Plugins.prototype.addSettingsViewModel = function (SettingsViewModelClass, sTemplate, sLabelName, sRoute)
|
|
|
|
{
|
2015-02-20 06:13:27 +08:00
|
|
|
this.aUserViewModelsHooks.push([SettingsViewModelClass, sTemplate, sLabelName, sRoute]);
|
2015-02-19 09:01:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Function} SettingsViewModelClass
|
|
|
|
* @param {string} sLabelName
|
|
|
|
* @param {string} sTemplate
|
|
|
|
* @param {string} sRoute
|
|
|
|
*/
|
|
|
|
Plugins.prototype.addSettingsViewModelForAdmin = function (SettingsViewModelClass, sTemplate, sLabelName, sRoute)
|
|
|
|
{
|
|
|
|
this.aAdminViewModelsHooks.push([SettingsViewModelClass, sTemplate, sLabelName, sRoute]);
|
|
|
|
};
|
|
|
|
|
|
|
|
Plugins.prototype.runSettingsViewModelHooks = function (bAdmin)
|
|
|
|
{
|
2015-02-20 06:13:27 +08:00
|
|
|
_.each(bAdmin ? this.aAdminViewModelsHooks : this.aUserViewModelsHooks, function (aView) {
|
2015-02-19 09:01:59 +08:00
|
|
|
require('Knoin/Knoin').addSettingsViewModel(aView[0], aView[1], aView[2], aView[3]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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
|
|
|
}());
|