2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
(function () {
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
'use strict';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
var
|
2014-08-25 23:49:01 +08:00
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
Enums = require('Common/Enums'),
|
|
|
|
Utils = require('Common/Utils'),
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator = require('Common/Translator'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
Settings = require('Storage/Settings'),
|
2015-01-27 05:06:00 +08:00
|
|
|
PluginStore = require('Stores/Admin/Plugin'),
|
2014-09-06 05:44:29 +08:00
|
|
|
Remote = require('Storage/Admin/Remote')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-10-30 21:59:25 +08:00
|
|
|
function PluginsAdminSettings()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-08-27 23:59:44 +08:00
|
|
|
this.enabledPlugins = ko.observable(!!Settings.settingsGet('EnabledPlugins'));
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
this.plugins = PluginStore.collection;
|
|
|
|
this.pluginsError = PluginStore.collection.error;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
this.visibility = ko.computed(function () {
|
2015-01-27 05:06:00 +08:00
|
|
|
return PluginStore.collection.loading() ? 'visible' : 'hidden';
|
2014-08-21 23:08:34 +08:00
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.onPluginLoadRequest = _.bind(this.onPluginLoadRequest, this);
|
|
|
|
this.onPluginDisableRequest = _.bind(this.onPluginDisableRequest, this);
|
|
|
|
}
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
PluginsAdminSettings.prototype.disablePlugin = function (oPlugin)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
oPlugin.disabled(!oPlugin.disabled());
|
|
|
|
Remote.pluginDisable(this.onPluginDisableRequest, oPlugin.name, oPlugin.disabled());
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
PluginsAdminSettings.prototype.configurePlugin = function (oPlugin)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
Remote.plugin(this.onPluginLoadRequest, oPlugin.name);
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
PluginsAdminSettings.prototype.onBuild = function (oDom)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
oDom
|
|
|
|
.on('click', '.e-item .configure-plugin-action', function () {
|
|
|
|
var oPlugin = ko.dataFor(this);
|
|
|
|
if (oPlugin)
|
|
|
|
{
|
|
|
|
self.configurePlugin(oPlugin);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('click', '.e-item .disabled-plugin', function () {
|
|
|
|
var oPlugin = ko.dataFor(this);
|
|
|
|
if (oPlugin)
|
|
|
|
{
|
|
|
|
self.disablePlugin(oPlugin);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
;
|
|
|
|
|
|
|
|
this.enabledPlugins.subscribe(function (bValue) {
|
|
|
|
Remote.saveAdminConfig(Utils.emptyFunction, {
|
|
|
|
'EnabledPlugins': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
PluginsAdminSettings.prototype.onShow = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-01-27 05:06:00 +08:00
|
|
|
PluginStore.collection.error('');
|
2014-09-06 05:44:29 +08:00
|
|
|
require('App/Admin').reloadPluginList();
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
PluginsAdminSettings.prototype.onPluginLoadRequest = function (sResult, oData)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Plugin'), [oData.Result]);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
PluginsAdminSettings.prototype.onPluginDisableRequest = function (sResult, oData)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData)
|
|
|
|
{
|
|
|
|
if (!oData.Result && oData.ErrorCode)
|
|
|
|
{
|
|
|
|
if (Enums.Notification.UnsupportedPluginPackage === oData.ErrorCode && oData.ErrorMessage && '' !== oData.ErrorMessage)
|
|
|
|
{
|
2015-01-27 05:06:00 +08:00
|
|
|
PluginStore.collection.error(oData.ErrorMessage);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-27 05:06:00 +08:00
|
|
|
PluginStore.collection.error(Translator.getNotification(oData.ErrorCode));
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
require('App/Admin').reloadPluginList();
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
module.exports = PluginsAdminSettings;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|