Small fixes and code refactoring

This commit is contained in:
RainLoop Team 2015-02-16 01:55:59 +04:00
parent e6c712862d
commit 1a85330770
67 changed files with 413 additions and 181 deletions

View file

@ -6,6 +6,7 @@
var
_ = require('_'),
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
kn = require('Knoin/Knoin'),
@ -37,6 +38,39 @@
return '#/' + sRoute;
};
MenuSettingsAdminView.prototype.onBuild = function (oDom)
{
key('up, down', _.throttle(function (event, handler) {
var
sH = '',
iIndex = -1,
bUp = handler && 'up' === handler.shortcut,
$items = $('.b-admin-menu .e-item', oDom)
;
if (event && $items.length)
{
iIndex = $items.index($items.filter('.selected'));
if (bUp && iIndex > 0)
{
iIndex--;
}
else if (!bUp && iIndex < $items.length - 1)
{
iIndex++;
}
sH = $items.eq(iIndex).attr('href');
if (sH)
{
kn.setHash(sH, false, true);
}
}
}, 200));
};
module.exports = MenuSettingsAdminView;
}());

View file

@ -116,7 +116,7 @@
}
};
AccountPopupView.prototype.onFocus = function ()
AccountPopupView.prototype.onShowWithDelay = function ()
{
this.emailFocus(true);
};

View file

@ -124,7 +124,7 @@
}
};
ActivatePopupView.prototype.onFocus = function ()
ActivatePopupView.prototype.onShowWithDelay = function ()
{
if (!this.activateProcess())
{

View file

@ -100,7 +100,7 @@
this.clearPopup();
};
AddOpenPgpKeyPopupView.prototype.onFocus = function ()
AddOpenPgpKeyPopupView.prototype.onShowWithDelay = function ()
{
this.key.focus(true);
};

View file

@ -148,7 +148,7 @@
this.clearPopup();
};
AdvancedSearchPopupView.prototype.onFocus = function ()
AdvancedSearchPopupView.prototype.onShowWithDelay = function ()
{
this.fromFocus(true);
};

View file

@ -106,7 +106,7 @@
this.bFocusYesOnShow = Utils.isUnd(bFocusYesOnShow) ? true : !!bFocusYesOnShow;
};
AskPopupView.prototype.onFocus = function ()
AskPopupView.prototype.onShowWithDelay = function ()
{
if (this.bFocusYesOnShow)
{

View file

@ -80,6 +80,8 @@
this.bFromDraft = false;
this.sReferences = '';
this.sLastFocusedField = 'to';
this.resizerTrigger = _.bind(this.resizerTrigger, this);
this.allowContacts = !!AppStore.contactsIsAllowed();
@ -93,10 +95,28 @@
this.identitiesDropdownTrigger = ko.observable(false);
this.to = ko.observable('');
this.to.focusTrigger = ko.observable(false);
this.to.focused = ko.observable(false);
this.cc = ko.observable('');
this.cc.focused = ko.observable(false);
this.bcc = ko.observable('');
this.bcc.focused = ko.observable(false);
this.replyTo = ko.observable('');
this.replyTo.focused = ko.observable(false);
ko.computed(function () {
switch (true)
{
case this.to.focused():
this.sLastFocusedField = 'to';
break;
case this.cc.focused():
this.sLastFocusedField = 'cc';
break;
case this.bcc.focused():
this.sLastFocusedField = 'bcc';
break;
}
}, this).extend({'notify': 'always'});
this.subject = ko.observable('');
this.isHtml = ko.observable(false);
@ -411,8 +431,13 @@
{
this.skipCommand();
var self = this;
window.console.log(this.sLastFocusedField);
_.delay(function () {
kn.showScreenPopup(require('View/Popup/Contacts'), [true]);
kn.showScreenPopup(require('View/Popup/Contacts'),
[true, self.sLastFocusedField]);
}, 200);
}
@ -1233,11 +1258,11 @@
this.resizerTrigger();
};
ComposePopupView.prototype.onFocus = function ()
ComposePopupView.prototype.onShowWithDelay = function ()
{
if ('' === this.to())
{
this.to.focusTrigger(!this.to.focusTrigger());
this.to.focused(true);
}
else if (this.oEditor)
{

View file

@ -198,12 +198,12 @@
}, this));
};
ComposeOpenPgpPopupView.prototype.onHide = function ()
ComposeOpenPgpPopupView.prototype.onHideWithDelay = function ()
{
this.clearPopup();
};
ComposeOpenPgpPopupView.prototype.onFocus = function ()
ComposeOpenPgpPopupView.prototype.onShowWithDelay = function ()
{
if (this.sign())
{

View file

@ -50,6 +50,7 @@
;
this.bBackToCompose = false;
this.sLastComposeFocusedField = '';
this.allowContactsSync = Data.allowContactsSync;
this.enableContactsSync = Data.enableContactsSync;
@ -236,7 +237,15 @@
});
this.newMessageCommand = Utils.createCommand(this, function () {
var aC = this.contactsCheckedOrSelected(), aE = [];
var
aE = [],
aC = this.contactsCheckedOrSelected(),
aToEmails = null,
aCcEmails = null,
aBccEmails = null,
aReplyToEmails = null
;
if (Utils.isNonEmptyArray(aC))
{
aE = _.map(aC, function (oItem) {
@ -265,8 +274,25 @@
kn.hideScreenPopup(require('View/Popup/Contacts'));
switch (self.sLastComposeFocusedField)
{
default:
case 'to':
aToEmails = aE;
break;
case 'cc':
aCcEmails = aE;
break;
case 'bcc':
aBccEmails = aE;
break;
}
self.sLastComposeFocusedField = '';
_.delay(function () {
kn.showScreenPopup(require('View/Popup/Compose'), [Enums.ComposeType.Empty, null, aE]);
kn.showScreenPopup(require('View/Popup/Compose'),
[Enums.ComposeType.Empty, null, aToEmails, aCcEmails, aBccEmails]);
}, 200);
}
@ -721,9 +747,10 @@
this.initUploader();
};
ContactsPopupView.prototype.onShow = function (bBackToCompose)
ContactsPopupView.prototype.onShow = function (bBackToCompose, sLastComposeFocusedField)
{
this.bBackToCompose = Utils.isUnd(bBackToCompose) ? false : !!bBackToCompose;
this.sLastComposeFocusedField = Utils.isUnd(sLastComposeFocusedField) ? '' : sLastComposeFocusedField;
kn.routeOff();
this.reloadContactList(true);
@ -732,6 +759,7 @@
ContactsPopupView.prototype.onHide = function ()
{
kn.routeOn();
this.currentContact(null);
this.emptySelection(true);
this.search('');
@ -740,6 +768,8 @@
Utils.delegateRunOnDestroy(this.contacts());
this.contacts([]);
this.sLastComposeFocusedField = '';
if (this.bBackToCompose)
{
this.bBackToCompose = false;

View file

@ -410,7 +410,7 @@
}
};
DomainPopupView.prototype.onFocus = function ()
DomainPopupView.prototype.onShowWithDelay = function ()
{
if ('' === this.name())
{

View file

@ -184,7 +184,7 @@
}
};
FilterPopupView.prototype.onFocus = function ()
FilterPopupView.prototype.onShowWithDelay = function ()
{
if (this.isNew() && this.filter())
{

View file

@ -123,7 +123,7 @@
this.clearPopup();
};
FolderCreateView.prototype.onFocus = function ()
FolderCreateView.prototype.onShowWithDelay = function ()
{
this.folderName.focused(true);
};

View file

@ -164,6 +164,31 @@
}
};
IdentityPopupView.prototype.populateSignatureFromEditor = function ()
{
if (this.editor)
{
this.signature(this.editor.getDataWithHtmlMark());
}
};
IdentityPopupView.prototype.editorSetSignature = function (sSignature)
{
if (!this.editor && this.signatureDom())
{
var self = this;
this.editor = new HtmlEditor(self.signatureDom(), function () {
self.populateSignatureFromEditor();
}, function () {
self.editor.setHtmlOrPlain(sSignature);
});
}
else
{
this.editor.setHtmlOrPlain(sSignature);
}
};
/**
* @param {?IdentityModel} oIdentity
*/
@ -189,60 +214,23 @@
{
this.id = Utils.fakeMd5();
}
this.editorSetSignature(this.signature());
};
IdentityPopupView.prototype.onHide = function ()
IdentityPopupView.prototype.onShowWithDelay = function ()
{
this.clearPopup();
};
IdentityPopupView.prototype.setSignature = function (sSignature)
{
if (this.editor)
{
if (':HTML:' === sSignature.substr(0, 6))
{
this.editor.setHtml(sSignature.substr(6), false);
}
else
{
this.editor.setPlain(sSignature, false);
}
}
};
IdentityPopupView.prototype.populateSignatureFromEditor = function ()
{
if (this.editor)
{
this.signature(
(this.editor.isHtml() ? ':HTML:' : '') + this.editor.getData()
);
}
};
IdentityPopupView.prototype.onFocus = function ()
{
if (!this.editor && this.signatureDom())
{
var self = this;
this.editor = new HtmlEditor(self.signatureDom(), function () {
self.populateSignatureFromEditor();
}, function () {
self.setSignature(self.signature());
});
}
else
{
this.setSignature(this.signature());
}
if (!this.owner())
{
this.email.focused(true);
}
};
IdentityPopupView.prototype.onHideWithDelay = function ()
{
this.clearPopup();
};
module.exports = IdentityPopupView;
}());

View file

@ -104,7 +104,7 @@
this.clearPopup();
};
NewOpenPgpKeyPopupView.prototype.onFocus = function ()
NewOpenPgpKeyPopupView.prototype.onShowWithDelay = function ()
{
this.email.focus(true);
};

View file

@ -115,22 +115,8 @@
if (this.editor)
{
this.setBody('');
}
};
TemplatePopupView.prototype.setBody = function (sBody)
{
if (this.editor)
{
if (':HTML:' === sBody.substr(0, 6))
{
this.editor.setHtml(sBody.substr(6), false);
}
else
{
this.editor.setPlain(sBody, false);
}
this.editor.setPlain('', false);
this.editor.setReadOnly(true);
}
};
@ -138,9 +124,7 @@
{
if (this.editor)
{
this.body(
(this.editor.isHtml() ? ':HTML:' : '') + this.editor.getData()
);
this.body(this.editor.getDataWithHtmlMark());
}
};
@ -152,12 +136,12 @@
this.editor = new HtmlEditor(self.signatureDom(), function () {
self.populateBodyFromEditor();
}, function () {
self.setBody(sBody);
self.editor.setHtmlOrPlain(sBody);
});
}
else
{
this.setBody(sBody);
this.editor.setHtmlOrPlain(sBody);
}
};
@ -212,7 +196,7 @@
}
};
TemplatePopupView.prototype.onFocus = function ()
TemplatePopupView.prototype.onShowWithDelay = function ()
{
this.name.focus(true);
};

View file

@ -30,6 +30,8 @@
this.code.focused = ko.observable(false);
this.code.status = ko.observable(null);
this.koTestedTrigger = null;
this.testing = ko.observable(false);
// commands
@ -41,6 +43,11 @@
self.testing(false);
self.code.status(Enums.StorageResultType.Success === sResult && oData && oData.Result ? true : false);
if (self.koTestedTrigger && self.code.status())
{
self.koTestedTrigger(true);
}
}, this.code());
}, function () {
@ -59,14 +66,18 @@
this.code.focused(false);
this.code.status(null);
this.testing(false);
this.koTestedTrigger = null;
};
TwoFactorTestPopupView.prototype.onShow = function ()
TwoFactorTestPopupView.prototype.onShow = function (koTestedTrigger)
{
this.clearPopup();
this.koTestedTrigger = koTestedTrigger;
};
TwoFactorTestPopupView.prototype.onFocus = function ()
TwoFactorTestPopupView.prototype.onShowWithDelay = function ()
{
this.code.focused(true);
};

View file

@ -252,10 +252,19 @@
this.selector.scrollToTop();
}, this);
Data.messageListEndFolder.subscribe(function (sFolder) {
var oMessage = Data.message();
if (oMessage && sFolder && sFolder !== oMessage.folderFullNameRaw)
{
Data.message(null);
}
}, this);
SettingsStore.layout.subscribe(function (mValue) {
this.selector.autoSelect(Enums.Layout.NoPreview !== mValue);
}, this);
SettingsStore.layout.valueHasMutated();
Events

View file

@ -5,7 +5,9 @@
var
_ = require('_'),
key = require('key'),
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Links = require('Common/Links'),
@ -35,6 +37,44 @@
kn.extendAsViewModel(['View/User/Settings/Menu', 'View/App/Settings/Menu', 'SettingsMenuViewModel'], MenuSettingsUserView);
_.extend(MenuSettingsUserView.prototype, AbstractView.prototype);
MenuSettingsUserView.prototype.onBuild = function (oDom)
{
// var self = this;
// key('esc', Enums.KeyState.Settings, function () {
// self.backToMailBoxClick();
// });
key('up, down', Enums.KeyState.Settings, _.throttle(function (event, handler) {
var
sH = '',
iIndex = -1,
bUp = handler && 'up' === handler.shortcut,
$items = $('.b-settings-menu .e-item', oDom)
;
if (event && $items.length)
{
iIndex = $items.index($items.filter('.selected'));
if (bUp && iIndex > 0)
{
iIndex--;
}
else if (!bUp && iIndex < $items.length - 1)
{
iIndex++;
}
sH = $items.eq(iIndex).attr('href');
if (sH)
{
kn.setHash(sH, false, true);
}
}
}, 200));
};
MenuSettingsUserView.prototype.link = function (sRoute)
{
return Links.settings(sRoute);

View file

@ -5,9 +5,7 @@
var
_ = require('_'),
key = require('key'),
Enums = require('Common/Enums'),
Links = require('Common/Links'),
Data = require('Storage/User/Data'),
@ -31,14 +29,6 @@
kn.extendAsViewModel(['View/User/Settings/Pane', 'View/App/Settings/Pane', 'SettingsPaneViewModel'], PaneSettingsUserView);
_.extend(PaneSettingsUserView.prototype, AbstractView.prototype);
PaneSettingsUserView.prototype.onBuild = function ()
{
var self = this;
key('esc', Enums.KeyState.Settings, function () {
self.backToMailBoxClick();
});
};
PaneSettingsUserView.prototype.onShow = function ()
{
Data.message(null);