snappymail/dev/View/Popup/Ask.js

139 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
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
_ = require('_'),
2014-08-25 23:49:01 +08:00
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'),
Translator = require('Common/Translator'),
2014-08-25 15:10:51 +08:00
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
* @extends AbstractView
2014-08-21 23:08:34 +08:00
*/
function AskPopupView()
2014-08-21 23:08:34 +08:00
{
AbstractView.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-12-28 03:48:55 +08:00
this.bFocusYesOnShow = true;
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);
}
kn.extendAsViewModel(['View/Popup/Ask', 'PopupsAskViewModel'], AskPopupView);
_.extend(AskPopupView.prototype, AbstractView.prototype);
AskPopupView.prototype.clearPopup = function ()
2014-08-21 23:08:34 +08:00
{
this.askDesc('');
this.yesButton(Translator.i18n('POPUPS_ASK/BUTTON_YES'));
this.noButton(Translator.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;
};
AskPopupView.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);
}
};
AskPopupView.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
2014-12-28 03:48:55 +08:00
* @param {boolean=} bFocusYesOnShow
2014-08-21 23:08:34 +08:00
*/
2014-12-28 03:48:55 +08:00
AskPopupView.prototype.onShow = function (sAskDesc, fYesFunc, fNoFunc, sYesButton, sNoButton, bFocusYesOnShow)
{
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-12-28 03:48:55 +08:00
this.bFocusYesOnShow = Utils.isUnd(bFocusYesOnShow) ? true : !!bFocusYesOnShow;
2014-08-21 23:08:34 +08:00
};
2014-07-10 22:44:45 +08:00
2015-02-16 05:55:59 +08:00
AskPopupView.prototype.onShowWithDelay = function ()
2014-08-21 23:08:34 +08:00
{
2014-12-28 03:48:55 +08:00
if (this.bFocusYesOnShow)
{
this.yesFocus(true);
}
2014-08-21 23:08:34 +08:00
};
AskPopupView.prototype.onBuild = function ()
2014-08-21 23:08:34 +08:00
{
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));
};
module.exports = AskPopupView;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());