snappymail/dev/ViewModels/Popups/PopupsAskViewModel.js

128 lines
2.6 KiB
JavaScript
Raw Normal View History

/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
2014-08-21 23:08:34 +08:00
(function (module) {
'use strict';
var
ko = require('../../External/ko.js'),
key = require('../../External/key.js'),
Enums = require('../../Common/Enums.js'),
Utils = require('../../Common/Utils.js'),
kn = require('../../Knoin/Knoin.js'),
KnoinAbstractViewModel = require('../../Knoin/KnoinAbstractViewModel.js')
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsAskViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAsk');
2014-08-21 23:08:34 +08:00
this.askDesc = ko.observable('');
this.yesButton = ko.observable('');
this.noButton = ko.observable('');
2014-08-21 23:08:34 +08:00
this.yesFocus = ko.observable(false);
this.noFocus = ko.observable(false);
2014-08-21 23:08:34 +08:00
this.fYesAction = null;
this.fNoAction = null;
2014-08-21 23:08:34 +08:00
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = Enums.KeyState.PopupAsk;
2014-08-21 23:08:34 +08:00
kn.constructorEnd(this);
}
2014-08-21 23:08:34 +08:00
kn.extendAsViewModel('PopupsAskViewModel', PopupsAskViewModel);
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'));
2014-08-21 23:08:34 +08:00
this.yesFocus(false);
this.noFocus(false);
2014-08-21 23:08:34 +08:00
this.fYesAction = null;
this.fNoAction = null;
};
2014-08-21 23:08:34 +08:00
PopupsAskViewModel.prototype.yesClick = function ()
{
2014-08-21 23:08:34 +08:00
this.cancelCommand();
2014-08-21 23:08:34 +08:00
if (Utils.isFunc(this.fYesAction))
{
this.fYesAction.call(null);
}
};
2014-08-21 23:08:34 +08:00
PopupsAskViewModel.prototype.noClick = function ()
{
2014-08-21 23:08:34 +08:00
this.cancelCommand();
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)
{
2014-08-21 23:08:34 +08:00
this.clearPopup();
2014-08-21 23:08:34 +08:00
this.fYesAction = fYesFunc || null;
this.fNoAction = fNoFunc || null;
2014-08-21 23:08:34 +08:00
this.askDesc(sAskDesc || '');
if (sYesButton)
{
2014-08-21 23:08:34 +08:00
this.yesButton(sYesButton);
}
2014-08-21 23:08:34 +08:00
if (sYesButton)
{
2014-08-21 23:08:34 +08:00
this.yesButton(sNoButton);
}
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);
};
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
}(module));