Added "Default identity" setting (Closes #157)

This commit is contained in:
RainLoop Team 2014-07-16 22:57:17 +04:00
parent c82a897582
commit d80a9e8485
29 changed files with 239 additions and 67 deletions

View file

@ -13,7 +13,7 @@ function Selector(oKoList, oKoSelectedItem,
sItemSelector, sItemSelectedSelector, sItemCheckedSelector, sItemFocusedSelector)
{
this.list = oKoList;
this.listChecked = ko.computed(function () {
return _.filter(this.list(), function (oItem) {
return oItem.checked();
@ -23,11 +23,11 @@ function Selector(oKoList, oKoSelectedItem,
this.isListChecked = ko.computed(function () {
return 0 < this.listChecked().length;
}, this);
this.focusedItem = ko.observable(null);
this.selectedItem = oKoSelectedItem;
this.selectedItemUseCallback = true;
this.itemSelectedThrottle = _.debounce(_.bind(this.itemSelected, this), 300);
this.listChecked.subscribe(function (aItems) {
@ -47,7 +47,7 @@ function Selector(oKoList, oKoSelectedItem,
this.selectedItem(this.focusedItem());
}
}, this);
this.selectedItem.subscribe(function (oItem) {
if (oItem)
@ -101,12 +101,12 @@ function Selector(oKoList, oKoSelectedItem,
this.oContentVisible = null;
this.oContentScrollable = null;
this.sItemSelector = sItemSelector;
this.sItemSelectedSelector = sItemSelectedSelector;
this.sItemCheckedSelector = sItemCheckedSelector;
this.sItemFocusedSelector = sItemFocusedSelector;
this.sLastUid = '';
this.bAutoSelect = true;
this.oCallbacks = {};
@ -126,7 +126,7 @@ function Selector(oKoList, oKoSelectedItem,
mFocused = null,
mSelected = null
;
this.list.subscribe(function (aItems) {
var self = this;
@ -136,7 +136,7 @@ function Selector(oKoList, oKoSelectedItem,
if (oItem)
{
var sUid = self.getItemUid(oItem);
aCache.push(sUid);
if (oItem.checked())
{
@ -154,9 +154,9 @@ function Selector(oKoList, oKoSelectedItem,
});
}
}, this, 'beforeChange');
this.list.subscribe(function (aItems) {
var
self = this,
oTemp = null,
@ -167,7 +167,7 @@ function Selector(oKoList, oKoSelectedItem,
bSelected = false,
iLen = 0
;
this.selectedItemUseCallback = false;
this.focusedItem(null);
@ -246,7 +246,7 @@ function Selector(oKoList, oKoSelectedItem,
aCheckedCache = [];
mFocused = null;
mSelected = null;
}, this);
}
@ -284,13 +284,13 @@ Selector.prototype.init = function (oContentVisible, oContentScrollable, sKeySco
this.oContentScrollable = oContentScrollable;
sKeyScope = sKeyScope || 'all';
if (this.oContentVisible && this.oContentScrollable)
{
var
var
self = this
;
$(this.oContentVisible)
.on('selectstart', function (oEvent) {
if (oEvent && oEvent.preventDefault)
@ -666,7 +666,7 @@ Selector.prototype.actionClick = function (oItem, oEvent)
bClick = true,
sUid = this.getItemUid(oItem)
;
if (oEvent)
{
if (oEvent.shiftKey && !oEvent.ctrlKey && !oEvent.altKey)
@ -679,7 +679,7 @@ Selector.prototype.actionClick = function (oItem, oEvent)
oItem.checked(!oItem.checked());
this.eventClickFunction(oItem, oEvent);
this.focusedItem(oItem);
}
else if (oEvent.ctrlKey && !oEvent.shiftKey && !oEvent.altKey)
@ -700,6 +700,8 @@ Selector.prototype.actionClick = function (oItem, oEvent)
{
this.focusedItem(oItem);
this.selectedItem(oItem);
this.scrollToFocused();
}
}
};

View file

@ -6,9 +6,11 @@
function SettingsIdentities()
{
var oData = RL.data();
this.editor = null;
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
this.accountEmail = oData.accountEmail;
this.displayName = oData.displayName;
this.signature = oData.signature;
this.signatureToAll = oData.signatureToAll;
@ -16,11 +18,47 @@ function SettingsIdentities()
this.signatureDom = ko.observable(null);
this.defaultIdentityIDTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.displayNameTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.replyTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.signatureTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.identities = oData.identities;
this.defaultIdentityID = oData.defaultIdentityID;
this.identitiesOptions = ko.computed(function () {
var
aList = this.identities(),
aResult = []
;
if (0 < aList.length)
{
aResult.push({
'id': this.accountEmail.peek(),
'name': this.formattedAccountIdentity(),
'seporator': false
});
aResult.push({
'id': '---',
'name': '---',
'seporator': true,
'disabled': true
});
_.each(aList, function (oItem) {
aResult.push({
'id': oItem.id,
'name': oItem.formattedNameForEmail(),
'seporator': false
});
});
}
return aResult;
}, this);
this.processText = ko.computed(function () {
return oData.identitiesLoading() ? Utils.i18n('SETTINGS_IDENTITIES/LOADING_PROCESS') : '';
@ -47,6 +85,20 @@ function SettingsIdentities()
Utils.addSettingsViewModel(SettingsIdentities, 'SettingsIdentities', 'SETTINGS_LABELS/LABEL_IDENTITIES_NAME', 'identities');
/**
*
* @return {string}
*/
SettingsIdentities.prototype.formattedAccountIdentity = function ()
{
var
sDisplayName = this.displayName.peek(),
sEmail = this.accountEmail.peek()
;
return '' === sDisplayName ? sEmail : '"' + Utils.quoteName(sDisplayName) + '" <' + sEmail + '>';
};
SettingsIdentities.prototype.addNewIdentity = function ()
{
kn.showScreenPopup(PopupsIdentityViewModel);
@ -65,7 +117,7 @@ SettingsIdentities.prototype.deleteIdentity = function (oIdentityToRemove)
if (oIdentityToRemove && oIdentityToRemove.deleteAccess())
{
this.identityForDeletion(null);
var
fRemoveFolder = function (oIdentity) {
return oIdentityToRemove === oIdentity;
@ -75,7 +127,7 @@ SettingsIdentities.prototype.deleteIdentity = function (oIdentityToRemove)
if (oIdentityToRemove)
{
this.identities.remove(fRemoveFolder);
RL.remote().identityDelete(function () {
RL.accountsAndIdentities();
}, oIdentityToRemove.id);
@ -121,7 +173,7 @@ SettingsIdentities.prototype.onBuild = function (oDom)
self.editIdentity(oIdentityItem);
}
})
;
;
_.delay(function () {
@ -129,9 +181,16 @@ SettingsIdentities.prototype.onBuild = function (oDom)
oData = RL.data(),
f1 = Utils.settingsSaveHelperSimpleFunction(self.displayNameTrigger, self),
f2 = Utils.settingsSaveHelperSimpleFunction(self.replyTrigger, self),
f3 = Utils.settingsSaveHelperSimpleFunction(self.signatureTrigger, self)
f3 = Utils.settingsSaveHelperSimpleFunction(self.signatureTrigger, self),
f4 = Utils.settingsSaveHelperSimpleFunction(self.defaultIdentityIDTrigger, self)
;
oData.defaultIdentityID.subscribe(function (sValue) {
RL.remote().saveSettings(f4, {
'DefaultIdentityID': sValue
});
});
oData.displayName.subscribe(function (sValue) {
RL.remote().saveSettings(f1, {
'DisplayName': sValue

View file

@ -78,6 +78,7 @@ function WebMailDataStorage()
this.accountsLoading = ko.observable(false).extend({'throttle': 100});
// identities
this.defaultIdentityID = ko.observable('');
this.identities = ko.observableArray([]);
this.identitiesLoading = ko.observable(false).extend({'throttle': 100});
@ -476,6 +477,8 @@ WebMailDataStorage.prototype.populateDataOnStart = function()
this.accountOutLogin(RL.settingsGet('OutLogin'));
this.projectHash(RL.settingsGet('ProjectHash'));
this.defaultIdentityID(RL.settingsGet('DefaultIdentityID'));
this.displayName(RL.settingsGet('DisplayName'));
this.replyTo(RL.settingsGet('ReplyTo'));
this.signature(RL.settingsGet('Signature'));

View file

@ -91,7 +91,7 @@ function PopupsComposeViewModel()
this.composeEditorArea = ko.observable(null);
this.identities = RL.data().identities;
this.defaultIdentityID = RL.data().defaultIdentityID;
this.currentIdentityID = ko.observable('');
this.currentIdentityString = ko.observable('');
@ -433,7 +433,6 @@ PopupsComposeViewModel.prototype.findIdentityIdByMessage = function (sComposeTyp
switch (sComposeType)
{
case Enums.ComposeType.Empty:
sResult = RL.data().accountEmail();
break;
case Enums.ComposeType.Reply:
case Enums.ComposeType.ReplyAll:
@ -446,7 +445,13 @@ PopupsComposeViewModel.prototype.findIdentityIdByMessage = function (sComposeTyp
break;
}
}
else
if ('' === sResult)
{
sResult = this.defaultIdentityID();
}
if ('' === sResult)
{
sResult = RL.data().accountEmail();
}
@ -694,9 +699,9 @@ PopupsComposeViewModel.prototype.onShow = function (sType, oMessageOrArray, aToE
if (null !== mEmail)
{
oExcludeEmail[mEmail] = true;
this.currentIdentityID(this.findIdentityIdByMessage(sComposeType, oMessage));
}
this.currentIdentityID(this.findIdentityIdByMessage(sComposeType, oMessage));
this.reset();
if (Utils.isNonEmptyArray(aToEmails))