2013-12-14 07:27:12 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
(function (module, require) {
|
2014-08-21 23:08:34 +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
|
|
|
ko = require('ko'),
|
|
|
|
key = require('key'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
Enums = require('Enums'),
|
|
|
|
Utils = require('Utils'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
kn = require('kn'),
|
|
|
|
KnoinAbstractViewModel = require('KnoinAbstractViewModel')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends KnoinAbstractViewModel
|
|
|
|
*/
|
|
|
|
function PopupsAskViewModel()
|
|
|
|
{
|
|
|
|
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAsk');
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.askDesc = ko.observable('');
|
|
|
|
this.yesButton = ko.observable('');
|
|
|
|
this.noButton = ko.observable('');
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.yesFocus = ko.observable(false);
|
|
|
|
this.noFocus = ko.observable(false);
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.fYesAction = null;
|
|
|
|
this.fNoAction = null;
|
2014-04-08 06:36:38 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.bDisabeCloseOnEsc = true;
|
|
|
|
this.sDefaultKeyScope = Enums.KeyState.PopupAsk;
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
kn.extendAsViewModel('PopupsAskViewModel', PopupsAskViewModel);
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsAskViewModel.prototype.clearPopup = function ()
|
|
|
|
{
|
|
|
|
this.askDesc('');
|
|
|
|
this.yesButton(Utils.i18n('POPUPS_ASK/BUTTON_YES'));
|
|
|
|
this.noButton(Utils.i18n('POPUPS_ASK/BUTTON_NO'));
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.yesFocus(false);
|
|
|
|
this.noFocus(false);
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.fYesAction = null;
|
|
|
|
this.fNoAction = null;
|
|
|
|
};
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsAskViewModel.prototype.yesClick = function ()
|
2013-12-14 07:27:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.cancelCommand();
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
if (Utils.isFunc(this.fYesAction))
|
|
|
|
{
|
|
|
|
this.fYesAction.call(null);
|
|
|
|
}
|
|
|
|
};
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsAskViewModel.prototype.noClick = function ()
|
2013-12-14 07:27:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.cancelCommand();
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
if (Utils.isFunc(this.fNoAction))
|
|
|
|
{
|
|
|
|
this.fNoAction.call(null);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} sAskDesc
|
|
|
|
* @param {Function=} fYesFunc
|
|
|
|
* @param {Function=} fNoFunc
|
|
|
|
* @param {string=} sYesButton
|
|
|
|
* @param {string=} sNoButton
|
|
|
|
*/
|
|
|
|
PopupsAskViewModel.prototype.onShow = function (sAskDesc, fYesFunc, fNoFunc, sYesButton, sNoButton)
|
2013-12-14 07:27:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.clearPopup();
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.fYesAction = fYesFunc || null;
|
|
|
|
this.fNoAction = fNoFunc || null;
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.askDesc(sAskDesc || '');
|
|
|
|
if (sYesButton)
|
2014-04-08 06:36:38 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.yesButton(sYesButton);
|
2014-04-08 06:36:38 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
if (sYesButton)
|
2013-12-14 07:27:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.yesButton(sNoButton);
|
2014-04-08 05:03:58 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
2014-07-10 22:44:45 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsAskViewModel.prototype.onFocus = function ()
|
|
|
|
{
|
|
|
|
this.yesFocus(true);
|
|
|
|
};
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsAskViewModel.prototype.onBuild = function ()
|
|
|
|
{
|
|
|
|
key('tab, shift+tab, right, left', Enums.KeyState.PopupAsk, _.bind(function () {
|
|
|
|
if (this.yesFocus())
|
|
|
|
{
|
|
|
|
this.noFocus(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.yesFocus(true);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}, this));
|
|
|
|
|
|
|
|
key('esc', Enums.KeyState.PopupAsk, _.bind(function () {
|
|
|
|
this.noClick();
|
|
|
|
return false;
|
|
|
|
}, this));
|
|
|
|
};
|
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
module.exports = PopupsAskViewModel;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
}(module, require));
|