2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
var
|
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
|
|
|
key = require('key'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
Enums = require('Common/Enums'),
|
|
|
|
Utils = require('Common/Utils'),
|
|
|
|
Translator = require('Common/Translator'),
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
|
|
|
AbstractView = require('Knoin/AbstractView');
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends AbstractView
|
|
|
|
*/
|
|
|
|
function AskPopupView()
|
|
|
|
{
|
|
|
|
AbstractView.call(this, 'Popups', 'PopupsAsk');
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.askDesc = ko.observable('');
|
|
|
|
this.yesButton = ko.observable('');
|
|
|
|
this.noButton = ko.observable('');
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.yesFocus = ko.observable(false);
|
|
|
|
this.noFocus = ko.observable(false);
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.fYesAction = null;
|
|
|
|
this.fNoAction = null;
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.bFocusYesOnShow = true;
|
|
|
|
this.bDisabeCloseOnEsc = true;
|
|
|
|
this.sDefaultKeyScope = Enums.KeyState.PopupAsk;
|
2014-04-08 06:36:38 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
kn.extendAsViewModel(['View/Popup/Ask', 'PopupsAskViewModel'], AskPopupView);
|
|
|
|
_.extend(AskPopupView.prototype, AbstractView.prototype);
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
AskPopupView.prototype.clearPopup = function()
|
|
|
|
{
|
|
|
|
this.askDesc('');
|
|
|
|
this.yesButton(Translator.i18n('POPUPS_ASK/BUTTON_YES'));
|
|
|
|
this.noButton(Translator.i18n('POPUPS_ASK/BUTTON_NO'));
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.yesFocus(false);
|
|
|
|
this.noFocus(false);
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.fYesAction = null;
|
|
|
|
this.fNoAction = null;
|
|
|
|
};
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
AskPopupView.prototype.yesClick = function()
|
|
|
|
{
|
|
|
|
this.cancelCommand();
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
if (Utils.isFunc(this.fYesAction))
|
2013-12-14 07:27:12 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.fYesAction.call(null);
|
|
|
|
}
|
|
|
|
};
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
AskPopupView.prototype.noClick = function()
|
|
|
|
{
|
|
|
|
this.cancelCommand();
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2016-06-30 08:02:45 +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
|
|
|
|
* @param {boolean=} bFocusYesOnShow
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
AskPopupView.prototype.onShow = function(sAskDesc, fYesFunc, fNoFunc, sYesButton, sNoButton, bFocusYesOnShow)
|
|
|
|
{
|
|
|
|
this.clearPopup();
|
|
|
|
|
|
|
|
this.fYesAction = fYesFunc || null;
|
|
|
|
this.fNoAction = fNoFunc || null;
|
|
|
|
|
|
|
|
this.askDesc(sAskDesc || '');
|
|
|
|
|
|
|
|
if (sYesButton)
|
2013-12-14 07:27:12 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.yesButton(sYesButton);
|
|
|
|
}
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
if (sNoButton)
|
2013-12-14 07:27:12 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.noButton(sNoButton);
|
|
|
|
}
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.bFocusYesOnShow = Utils.isUnd(bFocusYesOnShow) ? true : !!bFocusYesOnShow;
|
|
|
|
};
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
AskPopupView.prototype.onShowWithDelay = function()
|
|
|
|
{
|
|
|
|
if (this.bFocusYesOnShow)
|
|
|
|
{
|
|
|
|
this.yesFocus(true);
|
|
|
|
}
|
|
|
|
};
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
AskPopupView.prototype.onBuild = function()
|
|
|
|
{
|
|
|
|
key('tab, shift+tab, right, left', Enums.KeyState.PopupAsk, _.bind(function() {
|
|
|
|
if (this.yesFocus())
|
2013-12-14 07:27:12 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.noFocus(true);
|
2014-04-08 05:03:58 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
else
|
2014-12-28 03:48:55 +08:00
|
|
|
{
|
|
|
|
this.yesFocus(true);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
return false;
|
|
|
|
}, this));
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
key('esc', Enums.KeyState.PopupAsk, _.bind(function() {
|
|
|
|
this.noClick();
|
|
|
|
return false;
|
|
|
|
}, this));
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = AskPopupView;
|