2013-12-14 07:27:12 +08:00
|
|
|
|
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-09-02 08:15:31 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
var
|
2014-09-02 08:15:31 +08:00
|
|
|
_ = 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'),
|
2014-08-25 15:10:51 +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 AskPopupView()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.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-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;
|
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-09-06 05:44:29 +08:00
|
|
|
kn.extendAsViewModel(['View/Popup/Ask', 'PopupsAskViewModel'], AskPopupView);
|
|
|
|
_.extend(AskPopupView.prototype, AbstractView.prototype);
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AskPopupView.prototype.clearPopup = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
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-09-06 05:44:29 +08:00
|
|
|
AskPopupView.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-09-06 05:44:29 +08:00
|
|
|
AskPopupView.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
|
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)
|
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-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
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AskPopupView.prototype.onFocus = 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
|
|
|
};
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +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));
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
module.exports = AskPopupView;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|