mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 04:29:21 +03:00
Small refactoring (popup key scope optimization)
This commit is contained in:
parent
77cdc4690b
commit
a96e1d80c3
22 changed files with 226 additions and 254 deletions
|
|
@ -31,6 +31,7 @@ Enums.StateType = {
|
|||
* @enum {string}
|
||||
*/
|
||||
Enums.KeyState = {
|
||||
'All': 'all',
|
||||
'None': 'none',
|
||||
'ContactList': 'contact-list',
|
||||
'MessageList': 'message-list',
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ function KnoinAbstractViewModel(sPosition, sTemplate)
|
|||
this.sPosition = Utils.pString(sPosition);
|
||||
this.sTemplate = Utils.pString(sTemplate);
|
||||
|
||||
this.sDefaultKeyScope = Enums.KeyState.None;
|
||||
this.sCurrentKeyScope = this.sDefaultKeyScope;
|
||||
|
||||
this.viewModelName = '';
|
||||
this.viewModelVisibility = ko.observable(false);
|
||||
if ('Popups' === this.sPosition)
|
||||
|
|
@ -61,13 +64,27 @@ KnoinAbstractViewModel.prototype.cancelCommand = KnoinAbstractViewModel.prototyp
|
|||
{
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.storeAndSetKeyScope = function ()
|
||||
{
|
||||
this.sCurrentKeyScope = RL.data().keyScope();
|
||||
RL.data().keyScope(this.sDefaultKeyScope);
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.restoreKeyScope = function ()
|
||||
{
|
||||
RL.data().keyScope(this.sCurrentKeyScope);
|
||||
};
|
||||
|
||||
KnoinAbstractViewModel.prototype.registerPopupEscapeKey = function ()
|
||||
{
|
||||
key('esc', _.bind(function () {
|
||||
if (this.modalVisibility && this.modalVisibility())
|
||||
var self = this;
|
||||
$window.on('keydown', function (oEvent) {
|
||||
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility && self.modalVisibility())
|
||||
{
|
||||
Utils.delegateRun(this, 'cancelCommand');
|
||||
Utils.delegateRun(self, 'cancelCommand');
|
||||
return false;
|
||||
}
|
||||
}, this));
|
||||
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ Knoin.prototype.hideScreenPopup = function (ViewModelClassToHide)
|
|||
{
|
||||
ViewModelClassToHide.__vm.modalVisibility(false);
|
||||
Utils.delegateRun(ViewModelClassToHide.__vm, 'onHide');
|
||||
ViewModelClassToHide.__vm.restoreKeyScope();
|
||||
|
||||
RL.popupVisibilityNames.remove(ViewModelClassToHide.__name);
|
||||
|
||||
|
|
@ -168,8 +169,10 @@ Knoin.prototype.showScreenPopup = function (ViewModelClassToShow, aParameters)
|
|||
{
|
||||
ViewModelClassToShow.__dom.show();
|
||||
ViewModelClassToShow.__vm.modalVisibility(true);
|
||||
|
||||
Utils.delegateRun(ViewModelClassToShow.__vm, 'onShow', aParameters || []);
|
||||
|
||||
ViewModelClassToShow.__vm.storeAndSetKeyScope();
|
||||
|
||||
RL.popupVisibilityNames.push(ViewModelClassToShow.__name);
|
||||
|
||||
Plugins.runHook('view-model-on-show', [ViewModelClassToShow.__name, ViewModelClassToShow.__vm, aParameters || []]);
|
||||
|
|
|
|||
|
|
@ -37,13 +37,12 @@ MailBoxScreen.prototype.setNewTitle = function ()
|
|||
MailBoxScreen.prototype.onShow = function ()
|
||||
{
|
||||
this.setNewTitle();
|
||||
|
||||
RL.data().keyScope(Enums.KeyState.MessageList);
|
||||
};
|
||||
|
||||
MailBoxScreen.prototype.onHide = function ()
|
||||
{
|
||||
RL.data().keyScope(Enums.KeyState.None);
|
||||
RL.data().keyScope(Enums.KeyState.All);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5,6 +5,22 @@
|
|||
*/
|
||||
function AbstractData()
|
||||
{
|
||||
this.keyScope = ko.observable(Enums.KeyState.All);
|
||||
this.keyScope.subscribe(function (sValue) {
|
||||
|
||||
if (Enums.KeyState.Compose === sValue)
|
||||
{
|
||||
Utils.disableKeyFilter();
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.restoreKeyFilter();
|
||||
}
|
||||
|
||||
// window.console.log(sValue);
|
||||
key.setScope(sValue);
|
||||
});
|
||||
|
||||
Utils.initDataConstructorBySettings(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,22 +42,6 @@ function WebMailDataStorage()
|
|||
this.lastFoldersHash = '';
|
||||
this.remoteSuggestions = false;
|
||||
|
||||
this.keyScope = ko.observable(Enums.KeyState.None);
|
||||
this.keyScope.subscribe(function (sValue) {
|
||||
|
||||
if (Enums.KeyState.Compose === sValue)
|
||||
{
|
||||
Utils.disableKeyFilter();
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.restoreKeyFilter();
|
||||
}
|
||||
|
||||
// window.console.log(sValue);
|
||||
key.setScope(sValue);
|
||||
});
|
||||
|
||||
// system folders
|
||||
this.sentFolder = ko.observable('');
|
||||
this.draftFolder = ko.observable('');
|
||||
|
|
|
|||
|
|
@ -478,8 +478,13 @@ html.rl-no-preview-pane {
|
|||
}
|
||||
}
|
||||
|
||||
&.message-focused .b-content {
|
||||
.opacity(97);
|
||||
&.message-focused {
|
||||
.b-message-list-wrapper {
|
||||
background-color: #000;
|
||||
}
|
||||
.b-content {
|
||||
.opacity(98);
|
||||
}
|
||||
}
|
||||
|
||||
&.hideMessageListCheckbox {
|
||||
|
|
|
|||
|
|
@ -351,15 +351,11 @@ html.rl-no-preview-pane {
|
|||
}
|
||||
}
|
||||
|
||||
&.message-focused .messageItemHeader {
|
||||
background-color: #fafafa !important;
|
||||
}
|
||||
|
||||
&.message-focused .b-content {
|
||||
z-index: 102;
|
||||
.box-shadow(0px 2px 8px rgba(0, 0, 0, 0.3));
|
||||
border-color: darken(@rlMainDarkColor, 5%);
|
||||
.box-shadow(0px 2px 10px rgba(0, 0, 0, 0.3));
|
||||
.border-radius(@rlLowBorderRadius);
|
||||
border-color: darken(@rlMainDarkColor, 5%);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -588,20 +588,6 @@ MailBoxMessageListViewModel.prototype.onBuild = function (oDom)
|
|||
})
|
||||
;
|
||||
|
||||
ko.computed(function () {
|
||||
|
||||
var
|
||||
oData = RL.data(),
|
||||
bViewModelVisibility = this.viewModelVisibility(),
|
||||
bPopupVisibility = RL.popupVisibility(),
|
||||
bUseKeyboardShortcuts = oData.useKeyboardShortcuts(),
|
||||
bMessageFullScreenMode = oData.messageFullScreenMode()
|
||||
;
|
||||
|
||||
this.selector.useKeyboard(bViewModelVisibility && bUseKeyboardShortcuts && !bMessageFullScreenMode && !bPopupVisibility);
|
||||
|
||||
}, this).extend({'notify': 'always'});
|
||||
|
||||
this.initUploaderForAppend();
|
||||
this.initShortcuts();
|
||||
|
||||
|
|
|
|||
|
|
@ -496,8 +496,7 @@ MailBoxMessageViewViewModel.prototype.initShortcuts = function ()
|
|||
self.deleteCommand();
|
||||
if (handler && 'shift+delete' === handler.shortcut)
|
||||
{
|
||||
// self.deleteWithoutMoveCommand();
|
||||
self.deleteCommand();
|
||||
self.deleteWithoutMoveCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -511,7 +510,7 @@ MailBoxMessageViewViewModel.prototype.initShortcuts = function ()
|
|||
key('tab', Enums.KeyState.MessageView, function () {
|
||||
if (oData.useKeyboardShortcuts())
|
||||
{
|
||||
if (self.message())
|
||||
if (!self.fullScreenMode() && self.message())
|
||||
{
|
||||
self.message.focused(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ function PopupsAskViewModel()
|
|||
this.fNoAction = null;
|
||||
|
||||
this.bDisabeCloseOnEsc = true;
|
||||
this.sDefaultKeyScope = Enums.KeyState.PopupAsk;
|
||||
|
||||
this.sKeyScope = Enums.KeyState.MessageList;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
|
|
@ -83,9 +85,6 @@ PopupsAskViewModel.prototype.onShow = function (sAskDesc, fYesFunc, fNoFunc, sYe
|
|||
{
|
||||
this.yesButton(sNoButton);
|
||||
}
|
||||
|
||||
this.sKeyScope = RL.data().keyScope();
|
||||
RL.data().keyScope(Enums.KeyState.PopupAsk);
|
||||
};
|
||||
|
||||
PopupsAskViewModel.prototype.onFocus = function ()
|
||||
|
|
@ -93,27 +92,18 @@ PopupsAskViewModel.prototype.onFocus = function ()
|
|||
this.yesFocus(true);
|
||||
};
|
||||
|
||||
PopupsAskViewModel.prototype.onHide = function ()
|
||||
{
|
||||
RL.data().keyScope(this.sKeyScope);
|
||||
};
|
||||
|
||||
PopupsAskViewModel.prototype.onBuild = function ()
|
||||
{
|
||||
key('tab, right, left', Enums.KeyState.PopupAsk, _.bind(function () {
|
||||
if (this.modalVisibility())
|
||||
if (this.yesFocus())
|
||||
{
|
||||
if (this.yesFocus())
|
||||
{
|
||||
this.noFocus(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.yesFocus(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
this.noFocus(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.yesFocus(true);
|
||||
}
|
||||
return false;
|
||||
}, this));
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -351,7 +351,7 @@ function PopupsComposeViewModel()
|
|||
// this.driveCallback = _.bind(this.driveCallback, this);
|
||||
|
||||
this.bDisabeCloseOnEsc = true;
|
||||
this.sKeyScope = Enums.KeyState.MessageList;
|
||||
this.sDefaultKeyScope = Enums.KeyState.Compose;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
|
@ -569,8 +569,6 @@ PopupsComposeViewModel.prototype.onHide = function ()
|
|||
{
|
||||
this.reset();
|
||||
kn.routeOn();
|
||||
|
||||
RL.data().keyScope(this.sKeyScope);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -643,9 +641,6 @@ PopupsComposeViewModel.prototype.onShow = function (sType, oMessageOrArray, aToE
|
|||
{
|
||||
kn.routeOff();
|
||||
|
||||
this.sKeyScope = RL.data().keyScope();
|
||||
RL.data().keyScope(Enums.KeyState.Compose);
|
||||
|
||||
var
|
||||
self = this,
|
||||
sFrom = '',
|
||||
|
|
@ -922,7 +917,7 @@ PopupsComposeViewModel.prototype.tryToClosePopup = function ()
|
|||
|
||||
PopupsComposeViewModel.prototype.useShortcuts = function ()
|
||||
{
|
||||
return this.modalVisibility() && RL.data().useKeyboardShortcuts();
|
||||
return RL.data().useKeyboardShortcuts();
|
||||
};
|
||||
|
||||
PopupsComposeViewModel.prototype.onBuild = function ()
|
||||
|
|
@ -931,11 +926,12 @@ PopupsComposeViewModel.prototype.onBuild = function ()
|
|||
|
||||
var
|
||||
self = this,
|
||||
oData = RL.data(),
|
||||
oScript = null
|
||||
;
|
||||
|
||||
key('ctrl+s, command+s', Enums.KeyState.Compose, function () {
|
||||
if (self.useShortcuts())
|
||||
if (oData.useKeyboardShortcuts())
|
||||
{
|
||||
self.saveCommand();
|
||||
return false;
|
||||
|
|
@ -943,7 +939,7 @@ PopupsComposeViewModel.prototype.onBuild = function ()
|
|||
});
|
||||
|
||||
key('ctrl+enter, command+enter', Enums.KeyState.Compose, function () {
|
||||
if (self.useShortcuts())
|
||||
if (oData.useKeyboardShortcuts())
|
||||
{
|
||||
self.sendCommand();
|
||||
return false;
|
||||
|
|
@ -951,8 +947,11 @@ PopupsComposeViewModel.prototype.onBuild = function ()
|
|||
});
|
||||
|
||||
key('esc', Enums.KeyState.Compose, function () {
|
||||
self.tryToClosePopup();
|
||||
return false;
|
||||
if (oData.useKeyboardShortcuts())
|
||||
{
|
||||
self.tryToClosePopup();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$window.on('resize', function () {
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ function PopupsContactsViewModel()
|
|||
}
|
||||
}, this);
|
||||
|
||||
this.sKeyScope = Enums.KeyState.MessageList;
|
||||
this.sDefaultKeyScope = Enums.KeyState.ContactList;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
|
@ -587,14 +587,6 @@ PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
|||
}
|
||||
});
|
||||
|
||||
ko.computed(function () {
|
||||
var
|
||||
bModalVisibility = this.modalVisibility(),
|
||||
bUseKeyboardShortcuts = RL.data().useKeyboardShortcuts()
|
||||
;
|
||||
this.selector.useKeyboard(bModalVisibility && bUseKeyboardShortcuts);
|
||||
}, this).extend({'notify': 'always'});
|
||||
|
||||
oDom
|
||||
.on('click', '.e-pagenator .e-page', function () {
|
||||
var oPage = ko.dataFor(this);
|
||||
|
|
@ -613,9 +605,6 @@ PopupsContactsViewModel.prototype.onShow = function ()
|
|||
{
|
||||
kn.routeOff();
|
||||
this.reloadContactList(true);
|
||||
|
||||
this.sKeyScope = RL.data().keyScope();
|
||||
RL.data().keyScope(Enums.KeyState.ContactList);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.onHide = function ()
|
||||
|
|
@ -628,6 +617,4 @@ PopupsContactsViewModel.prototype.onHide = function ()
|
|||
_.each(this.contacts(), function (oItem) {
|
||||
oItem.checked(false);
|
||||
});
|
||||
|
||||
RL.data().keyScope(this.sKeyScope);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,20 +8,7 @@ function PopupsKeyboardShortcutsHelpViewModel()
|
|||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsKeyboardShortcutsHelp');
|
||||
|
||||
this.sKeyScope = Enums.KeyState.None;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsKeyboardShortcutsHelpViewModel', PopupsKeyboardShortcutsHelpViewModel);
|
||||
|
||||
PopupsKeyboardShortcutsHelpViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.sKeyScope = RL.data().keyScope();
|
||||
RL.data().keyScope(Enums.KeyState.None);
|
||||
};
|
||||
|
||||
PopupsKeyboardShortcutsHelpViewModel.prototype.onHide = function ()
|
||||
{
|
||||
RL.data().keyScope(this.sKeyScope);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ function PopupsPluginViewModel()
|
|||
}, this.hasConfiguration);
|
||||
|
||||
this.bDisabeCloseOnEsc = true;
|
||||
this.sDefaultKeyScope = Enums.KeyState.All;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
|
@ -127,11 +128,11 @@ PopupsPluginViewModel.prototype.tryToClosePopup = function ()
|
|||
|
||||
PopupsPluginViewModel.prototype.onBuild = function ()
|
||||
{
|
||||
key('esc', _.bind(function () {
|
||||
key('esc', Enums.KeyState.All, _.bind(function () {
|
||||
if (this.modalVisibility())
|
||||
{
|
||||
this.tryToClosePopup();
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
}, this));
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue