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';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
var
|
2014-08-25 23:49:01 +08:00
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
|
|
|
key = require('key'),
|
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
|
|
|
|
2015-02-23 00:35:17 +08:00
|
|
|
Remote = require('Remote/Admin/Ajax'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
|
|
|
AbstractView = require('Knoin/AbstractView')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
2014-09-06 05:44:29 +08:00
|
|
|
* @extends AbstractView
|
2014-08-21 23:08:34 +08:00
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
function PluginPopupView()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.call(this, 'Popups', 'PopupsPlugin');
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.onPluginSettingsUpdateResponse = _.bind(this.onPluginSettingsUpdateResponse, this);
|
|
|
|
|
|
|
|
this.saveError = ko.observable('');
|
|
|
|
|
|
|
|
this.name = ko.observable('');
|
|
|
|
this.readme = ko.observable('');
|
|
|
|
|
|
|
|
this.configures = ko.observableArray([]);
|
|
|
|
|
|
|
|
this.hasReadme = ko.computed(function () {
|
|
|
|
return '' !== this.readme();
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.hasConfiguration = ko.computed(function () {
|
|
|
|
return 0 < this.configures().length;
|
2013-11-16 06:21:12 +08:00
|
|
|
}, this);
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.readmePopoverConf = {
|
2015-11-19 05:11:47 +08:00
|
|
|
'placement': 'right',
|
2014-08-21 23:08:34 +08:00
|
|
|
'trigger': 'hover',
|
2015-11-19 05:11:47 +08:00
|
|
|
// 'trigger': 'click',
|
2015-03-28 06:06:56 +08:00
|
|
|
'title': Translator.i18n('POPUPS_PLUGIN/TOOLTIP_ABOUT_TITLE'),
|
2015-01-08 06:50:59 +08:00
|
|
|
'container': 'body',
|
2015-11-19 05:11:47 +08:00
|
|
|
'html': true,
|
2014-08-21 23:08:34 +08:00
|
|
|
'content': function () {
|
2015-11-19 05:11:47 +08:00
|
|
|
return '<pre>' + self.readme() + '</pre>';
|
|
|
|
// .replace(/[\r]/g, '').replace(/[\n]/g, '<br />').replace(/[\t]/g, ' ');
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
};
|
2014-03-13 06:29:33 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.saveCommand = Utils.createCommand(this, function () {
|
2014-07-10 22:44:45 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
var oList = {};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
oList['Name'] = this.name();
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
_.each(this.configures(), function (oItem) {
|
|
|
|
|
|
|
|
var mValue = oItem.value();
|
|
|
|
if (false === mValue || true === mValue)
|
|
|
|
{
|
|
|
|
mValue = mValue ? '1' : '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
oList['_' + oItem['Name']] = mValue;
|
|
|
|
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.saveError('');
|
|
|
|
Remote.pluginSettingsUpdate(this.onPluginSettingsUpdateResponse, oList);
|
|
|
|
|
|
|
|
}, this.hasConfiguration);
|
|
|
|
|
|
|
|
this.bDisabeCloseOnEsc = true;
|
|
|
|
this.sDefaultKeyScope = Enums.KeyState.All;
|
|
|
|
|
|
|
|
this.tryToClosePopup = _.debounce(_.bind(this.tryToClosePopup, this), 200);
|
|
|
|
|
|
|
|
kn.constructorEnd(this);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn.extendAsViewModel(['View/Popup/Plugin', 'PopupsPluginViewModel'], PluginPopupView);
|
|
|
|
_.extend(PluginPopupView.prototype, AbstractView.prototype);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
PluginPopupView.prototype.onPluginSettingsUpdateResponse = function (sResult, oData)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.cancelCommand();
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.saveError('');
|
|
|
|
if (oData && oData.ErrorCode)
|
|
|
|
{
|
2015-01-26 07:09:22 +08:00
|
|
|
this.saveError(Translator.getNotification(oData.ErrorCode));
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-26 07:09:22 +08:00
|
|
|
this.saveError(Translator.getNotification(Enums.Notification.CantSavePluginSettings));
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
PluginPopupView.prototype.onShow = function (oPlugin)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.name();
|
|
|
|
this.readme();
|
|
|
|
this.configures([]);
|
|
|
|
|
|
|
|
if (oPlugin)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.name(oPlugin['Name']);
|
|
|
|
this.readme(oPlugin['Readme']);
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
var aConfig = oPlugin['Config'];
|
|
|
|
if (Utils.isNonEmptyArray(aConfig))
|
2014-07-10 22:44:45 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.configures(_.map(aConfig, function (aItem) {
|
|
|
|
return {
|
|
|
|
'value': ko.observable(aItem[0]),
|
2014-09-25 23:37:11 +08:00
|
|
|
'placeholder': ko.observable(aItem[6]),
|
2014-08-21 23:08:34 +08:00
|
|
|
'Name': aItem[1],
|
|
|
|
'Type': aItem[2],
|
|
|
|
'Label': aItem[3],
|
|
|
|
'Default': aItem[4],
|
|
|
|
'Desc': aItem[5]
|
|
|
|
};
|
|
|
|
}));
|
2014-07-10 22:44:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
};
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
PluginPopupView.prototype.tryToClosePopup = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-08-27 23:59:44 +08:00
|
|
|
var
|
|
|
|
self = this,
|
2014-09-06 05:44:29 +08:00
|
|
|
PopupsAskViewModel = require('View/Popup/Ask')
|
2014-08-27 23:59:44 +08:00
|
|
|
;
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
if (!kn.isPopupVisible(PopupsAskViewModel))
|
2013-12-14 07:27:12 +08:00
|
|
|
{
|
2015-01-26 07:09:22 +08:00
|
|
|
kn.showScreenPopup(PopupsAskViewModel, [Translator.i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'), function () {
|
2014-08-21 23:08:34 +08:00
|
|
|
if (self.modalVisibility())
|
|
|
|
{
|
|
|
|
Utils.delegateRun(self, 'cancelCommand');
|
|
|
|
}
|
|
|
|
}]);
|
2013-12-14 07:27:12 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
PluginPopupView.prototype.onBuild = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
key('esc', Enums.KeyState.All, _.bind(function () {
|
|
|
|
if (this.modalVisibility())
|
|
|
|
{
|
|
|
|
this.tryToClosePopup();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}, this));
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
module.exports = PluginPopupView;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|