mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 03:59:21 +03:00
Sieve Filters (Interface first look)
Code refactoring Small fixes
This commit is contained in:
parent
409e9fbdc2
commit
1027f319ed
43 changed files with 466 additions and 427 deletions
118
dev/ViewModels/Popups/PopupsActivateViewModel.js
Normal file
118
dev/ViewModels/Popups/PopupsActivateViewModel.js
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsActivateViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsActivate');
|
||||
|
||||
var self = this;
|
||||
|
||||
this.domain = ko.observable('');
|
||||
this.key = ko.observable('');
|
||||
this.key.focus = ko.observable(false);
|
||||
this.activationSuccessed = ko.observable(false);
|
||||
|
||||
this.licenseTrigger = RL.data().licenseTrigger;
|
||||
|
||||
this.activateProcess = ko.observable(false);
|
||||
this.activateText = ko.observable('');
|
||||
this.activateText.isError = ko.observable(false);
|
||||
|
||||
this.key.subscribe(function () {
|
||||
this.activateText('');
|
||||
this.activateText.isError(false);
|
||||
}, this);
|
||||
|
||||
this.activationSuccessed.subscribe(function (bValue) {
|
||||
if (bValue)
|
||||
{
|
||||
this.licenseTrigger(!this.licenseTrigger());
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.activateCommand = Utils.createCommand(this, function () {
|
||||
|
||||
this.activateProcess(true);
|
||||
if (this.validateSubscriptionKey())
|
||||
{
|
||||
RL.remote().licensingActivate(function (sResult, oData) {
|
||||
|
||||
self.activateProcess(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData.Result)
|
||||
{
|
||||
if (true === oData.Result)
|
||||
{
|
||||
self.activationSuccessed(true);
|
||||
self.activateText('Subscription Key Activated Successfully');
|
||||
self.activateText.isError(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.activateText(oData.Result);
|
||||
self.activateText.isError(true);
|
||||
self.key.focus(true);
|
||||
}
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
{
|
||||
self.activateText(Utils.getNotification(oData.ErrorCode));
|
||||
self.activateText.isError(true);
|
||||
self.key.focus(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.activateText(Utils.getNotification(Enums.Notification.UnknownError));
|
||||
self.activateText.isError(true);
|
||||
self.key.focus(true);
|
||||
}
|
||||
|
||||
}, this.domain(), this.key());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.activateProcess(false);
|
||||
this.activateText('Invalid Subscription Key');
|
||||
this.activateText.isError(true);
|
||||
this.key.focus(true);
|
||||
}
|
||||
|
||||
}, function () {
|
||||
return !this.activateProcess() && '' !== this.domain() && '' !== this.key() && !this.activationSuccessed();
|
||||
});
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsActivateViewModel', PopupsActivateViewModel);
|
||||
|
||||
PopupsActivateViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.domain(RL.settingsGet('AdminDomain'));
|
||||
if (!this.activateProcess())
|
||||
{
|
||||
this.key('');
|
||||
this.activateText('');
|
||||
this.activateText.isError(false);
|
||||
this.activationSuccessed(false);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsActivateViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
if (!this.activateProcess())
|
||||
{
|
||||
this.key.focus(true);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PopupsActivateViewModel.prototype.validateSubscriptionKey = function ()
|
||||
{
|
||||
var sValue = this.key();
|
||||
return '' === sValue || !!/^RL[\d]+-[A-Z0-9\-]+Z$/.test(Utils.trim(sValue));
|
||||
};
|
||||
95
dev/ViewModels/Popups/PopupsAddAccountViewModel.js
Normal file
95
dev/ViewModels/Popups/PopupsAddAccountViewModel.js
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsAddAccountViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAddAccount');
|
||||
|
||||
this.email = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
|
||||
this.emailError = ko.observable(false);
|
||||
this.passwordError = ko.observable(false);
|
||||
|
||||
this.email.subscribe(function () {
|
||||
this.emailError(false);
|
||||
}, this);
|
||||
|
||||
this.password.subscribe(function () {
|
||||
this.passwordError(false);
|
||||
}, this);
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
|
||||
this.emailFocus = ko.observable(false);
|
||||
|
||||
this.addAccountCommand = Utils.createCommand(this, function () {
|
||||
|
||||
this.emailError('' === Utils.trim(this.email()));
|
||||
this.passwordError('' === Utils.trim(this.password()));
|
||||
|
||||
if (this.emailError() || this.passwordError())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
RL.remote().accountAdd(_.bind(function (sResult, oData) {
|
||||
|
||||
this.submitRequest(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && 'AccountAdd' === oData.Action)
|
||||
{
|
||||
if (oData.Result)
|
||||
{
|
||||
RL.accountsAndIdentities();
|
||||
this.cancelCommand();
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
{
|
||||
this.submitError(Utils.getNotification(oData.ErrorCode));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitError(Utils.getNotification(Enums.Notification.UnknownError));
|
||||
}
|
||||
|
||||
}, this), this.email(), '', this.password());
|
||||
|
||||
return true;
|
||||
|
||||
}, function () {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsAddAccountViewModel', PopupsAddAccountViewModel);
|
||||
|
||||
PopupsAddAccountViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.email('');
|
||||
this.password('');
|
||||
|
||||
this.emailError(false);
|
||||
this.passwordError(false);
|
||||
|
||||
this.submitRequest(false);
|
||||
this.submitError('');
|
||||
};
|
||||
|
||||
PopupsAddAccountViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
PopupsAddAccountViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
this.emailFocus(true);
|
||||
};
|
||||
90
dev/ViewModels/Popups/PopupsAddOpenPgpKeyViewModel.js
Normal file
90
dev/ViewModels/Popups/PopupsAddOpenPgpKeyViewModel.js
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsAddOpenPgpKeyViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAddOpenPgpKey');
|
||||
|
||||
this.key = ko.observable('');
|
||||
this.key.error = ko.observable(false);
|
||||
this.key.focus = ko.observable(false);
|
||||
|
||||
this.key.subscribe(function () {
|
||||
this.key.error(false);
|
||||
}, this);
|
||||
|
||||
this.addOpenPgpKeyCommand = Utils.createCommand(this, function () {
|
||||
|
||||
var
|
||||
iCount = 30,
|
||||
aMatch = null,
|
||||
sKey = Utils.trim(this.key()),
|
||||
oReg = /[\-]{3,6}BEGIN[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[\-]{3,6}[\s\S]+?[\-]{3,6}END[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[\-]{3,6}/gi,
|
||||
oOpenpgpKeyring = RL.data().openpgpKeyring
|
||||
;
|
||||
|
||||
sKey = sKey.replace(/[\r\n]([a-zA-Z0-9]{2,}:[^\r\n]+)[\r\n]+([a-zA-Z0-9\/\\+=]{10,})/g, '\n$1!-!N!-!$2')
|
||||
.replace(/[\n\r]+/g, '\n').replace(/!-!N!-!/g, '\n\n');
|
||||
|
||||
this.key.error('' === sKey);
|
||||
|
||||
if (!oOpenpgpKeyring || this.key.error())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
aMatch = oReg.exec(sKey);
|
||||
if (!aMatch || 0 > iCount)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (aMatch[0] && aMatch[1] && aMatch[2] && aMatch[1] === aMatch[2])
|
||||
{
|
||||
if ('PRIVATE' === aMatch[1])
|
||||
{
|
||||
oOpenpgpKeyring.privateKeys.importKey(aMatch[0]);
|
||||
}
|
||||
else if ('PUBLIC' === aMatch[1])
|
||||
{
|
||||
oOpenpgpKeyring.publicKeys.importKey(aMatch[0]);
|
||||
}
|
||||
}
|
||||
|
||||
iCount--;
|
||||
}
|
||||
while (true);
|
||||
|
||||
oOpenpgpKeyring.store();
|
||||
|
||||
RL.reloadOpenPgpKeys();
|
||||
Utils.delegateRun(this, 'cancelCommand');
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsAddOpenPgpKeyViewModel', PopupsAddOpenPgpKeyViewModel);
|
||||
|
||||
PopupsAddOpenPgpKeyViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.key('');
|
||||
this.key.error(false);
|
||||
};
|
||||
|
||||
PopupsAddOpenPgpKeyViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
PopupsAddOpenPgpKeyViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
this.key.focus(true);
|
||||
};
|
||||
137
dev/ViewModels/Popups/PopupsAdvancedSearchViewModel.js
Normal file
137
dev/ViewModels/Popups/PopupsAdvancedSearchViewModel.js
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsAdvancedSearchViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAdvancedSearch');
|
||||
|
||||
this.fromFocus = ko.observable(false);
|
||||
|
||||
this.from = ko.observable('');
|
||||
this.to = ko.observable('');
|
||||
this.subject = ko.observable('');
|
||||
this.text = ko.observable('');
|
||||
this.selectedDateValue = ko.observable(-1);
|
||||
|
||||
this.hasAttachment = ko.observable(false);
|
||||
this.starred = ko.observable(false);
|
||||
this.unseen = ko.observable(false);
|
||||
|
||||
this.searchCommand = Utils.createCommand(this, function () {
|
||||
|
||||
var sSearch = this.buildSearchString();
|
||||
if ('' !== sSearch)
|
||||
{
|
||||
RL.data().mainMessageListSearch(sSearch);
|
||||
}
|
||||
|
||||
this.cancelCommand();
|
||||
});
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsAdvancedSearchViewModel', PopupsAdvancedSearchViewModel);
|
||||
|
||||
PopupsAdvancedSearchViewModel.prototype.buildSearchStringValue = function (sValue)
|
||||
{
|
||||
if (-1 < sValue.indexOf(' '))
|
||||
{
|
||||
sValue = '"' + sValue + '"';
|
||||
}
|
||||
|
||||
return sValue;
|
||||
};
|
||||
|
||||
PopupsAdvancedSearchViewModel.prototype.buildSearchString = function ()
|
||||
{
|
||||
var
|
||||
aResult = [],
|
||||
sFrom = Utils.trim(this.from()),
|
||||
sTo = Utils.trim(this.to()),
|
||||
sSubject = Utils.trim(this.subject()),
|
||||
sText = Utils.trim(this.text()),
|
||||
aIs = [],
|
||||
aHas = []
|
||||
;
|
||||
|
||||
if (sFrom && '' !== sFrom)
|
||||
{
|
||||
aResult.push('from:' + this.buildSearchStringValue(sFrom));
|
||||
}
|
||||
|
||||
if (sTo && '' !== sTo)
|
||||
{
|
||||
aResult.push('to:' + this.buildSearchStringValue(sTo));
|
||||
}
|
||||
|
||||
if (sSubject && '' !== sSubject)
|
||||
{
|
||||
aResult.push('subject:' + this.buildSearchStringValue(sSubject));
|
||||
}
|
||||
|
||||
if (this.hasAttachment())
|
||||
{
|
||||
aHas.push('attachment');
|
||||
}
|
||||
|
||||
if (this.unseen())
|
||||
{
|
||||
aIs.push('unseen');
|
||||
}
|
||||
|
||||
if (this.starred())
|
||||
{
|
||||
aIs.push('flagged');
|
||||
}
|
||||
|
||||
if (0 < aHas.length)
|
||||
{
|
||||
aResult.push('has:' + aHas.join(','));
|
||||
}
|
||||
|
||||
if (0 < aIs.length)
|
||||
{
|
||||
aResult.push('is:' + aIs.join(','));
|
||||
}
|
||||
|
||||
if (-1 < this.selectedDateValue())
|
||||
{
|
||||
aResult.push('date:' + moment().subtract('days', this.selectedDateValue()).format('YYYY.MM.DD') + '/');
|
||||
}
|
||||
|
||||
if (sText && '' !== sText)
|
||||
{
|
||||
aResult.push('text:' + this.buildSearchStringValue(sText));
|
||||
}
|
||||
|
||||
return Utils.trim(aResult.join(' '));
|
||||
};
|
||||
|
||||
PopupsAdvancedSearchViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.from('');
|
||||
this.to('');
|
||||
this.subject('');
|
||||
this.text('');
|
||||
|
||||
this.selectedDateValue(-1);
|
||||
this.hasAttachment(false);
|
||||
this.starred(false);
|
||||
this.unseen(false);
|
||||
|
||||
this.fromFocus(true);
|
||||
};
|
||||
|
||||
PopupsAdvancedSearchViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
PopupsAdvancedSearchViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
this.fromFocus(true);
|
||||
};
|
||||
112
dev/ViewModels/Popups/PopupsAskViewModel.js
Normal file
112
dev/ViewModels/Popups/PopupsAskViewModel.js
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsAskViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAsk');
|
||||
|
||||
this.askDesc = ko.observable('');
|
||||
this.yesButton = ko.observable('');
|
||||
this.noButton = ko.observable('');
|
||||
|
||||
this.yesFocus = ko.observable(false);
|
||||
this.noFocus = ko.observable(false);
|
||||
|
||||
this.fYesAction = null;
|
||||
this.fNoAction = null;
|
||||
|
||||
this.bDisabeCloseOnEsc = true;
|
||||
this.sDefaultKeyScope = Enums.KeyState.PopupAsk;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsAskViewModel', PopupsAskViewModel);
|
||||
|
||||
PopupsAskViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.askDesc('');
|
||||
this.yesButton(Utils.i18n('POPUPS_ASK/BUTTON_YES'));
|
||||
this.noButton(Utils.i18n('POPUPS_ASK/BUTTON_NO'));
|
||||
|
||||
this.yesFocus(false);
|
||||
this.noFocus(false);
|
||||
|
||||
this.fYesAction = null;
|
||||
this.fNoAction = null;
|
||||
};
|
||||
|
||||
PopupsAskViewModel.prototype.yesClick = function ()
|
||||
{
|
||||
this.cancelCommand();
|
||||
|
||||
if (Utils.isFunc(this.fYesAction))
|
||||
{
|
||||
this.fYesAction.call(null);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsAskViewModel.prototype.noClick = function ()
|
||||
{
|
||||
this.cancelCommand();
|
||||
|
||||
if (Utils.isFunc(this.fNoAction))
|
||||
{
|
||||
this.fNoAction.call(null);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sAskDesc
|
||||
* @param {Function=} fYesFunc
|
||||
* @param {Function=} fNoFunc
|
||||
* @param {string=} sYesButton
|
||||
* @param {string=} sNoButton
|
||||
*/
|
||||
PopupsAskViewModel.prototype.onShow = function (sAskDesc, fYesFunc, fNoFunc, sYesButton, sNoButton)
|
||||
{
|
||||
this.clearPopup();
|
||||
|
||||
this.fYesAction = fYesFunc || null;
|
||||
this.fNoAction = fNoFunc || null;
|
||||
|
||||
this.askDesc(sAskDesc || '');
|
||||
if (sYesButton)
|
||||
{
|
||||
this.yesButton(sYesButton);
|
||||
}
|
||||
|
||||
if (sYesButton)
|
||||
{
|
||||
this.yesButton(sNoButton);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsAskViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
this.yesFocus(true);
|
||||
};
|
||||
|
||||
PopupsAskViewModel.prototype.onBuild = function ()
|
||||
{
|
||||
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));
|
||||
};
|
||||
|
||||
241
dev/ViewModels/Popups/PopupsComposeOpenPgpViewModel.js
Normal file
241
dev/ViewModels/Popups/PopupsComposeOpenPgpViewModel.js
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsComposeOpenPgpViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsComposeOpenPgp');
|
||||
|
||||
this.notification = ko.observable('');
|
||||
|
||||
this.sign = ko.observable(true);
|
||||
this.encrypt = ko.observable(true);
|
||||
|
||||
this.password = ko.observable('');
|
||||
this.password.focus = ko.observable(false);
|
||||
this.buttonFocus = ko.observable(false);
|
||||
|
||||
this.from = ko.observable('');
|
||||
this.to = ko.observableArray([]);
|
||||
this.text = ko.observable('');
|
||||
|
||||
this.resultCallback = null;
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
|
||||
// commands
|
||||
this.doCommand = Utils.createCommand(this, function () {
|
||||
|
||||
var
|
||||
self = this,
|
||||
bResult = true,
|
||||
oData = RL.data(),
|
||||
oPrivateKey = null,
|
||||
aPublicKeys = []
|
||||
;
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
if (bResult && this.sign() && '' === this.from())
|
||||
{
|
||||
this.notification(Utils.i18n('PGP_NOTIFICATIONS/SPECIFY_FROM_EMAIL'));
|
||||
bResult = false;
|
||||
}
|
||||
|
||||
if (bResult && this.sign())
|
||||
{
|
||||
oPrivateKey = oData.findPrivateKeyByEmail(this.from(), this.password());
|
||||
if (!oPrivateKey)
|
||||
{
|
||||
this.notification(Utils.i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND_FOR', {
|
||||
'EMAIL': this.from()
|
||||
}));
|
||||
|
||||
bResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (bResult && this.encrypt() && 0 === this.to().length)
|
||||
{
|
||||
this.notification(Utils.i18n('PGP_NOTIFICATIONS/SPECIFY_AT_LEAST_ONE_RECIPIENT'));
|
||||
bResult = false;
|
||||
}
|
||||
|
||||
if (bResult && this.encrypt())
|
||||
{
|
||||
aPublicKeys = [];
|
||||
_.each(this.to(), function (sEmail) {
|
||||
var aKeys = oData.findPublicKeysByEmail(sEmail);
|
||||
if (0 === aKeys.length && bResult)
|
||||
{
|
||||
self.notification(Utils.i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND_FOR', {
|
||||
'EMAIL': sEmail
|
||||
}));
|
||||
|
||||
bResult = false;
|
||||
}
|
||||
|
||||
aPublicKeys = aPublicKeys.concat(aKeys);
|
||||
});
|
||||
|
||||
if (bResult && (0 === aPublicKeys.length || this.to().length !== aPublicKeys.length))
|
||||
{
|
||||
bResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
_.delay(function () {
|
||||
|
||||
if (self.resultCallback && bResult)
|
||||
{
|
||||
try {
|
||||
|
||||
if (oPrivateKey && 0 === aPublicKeys.length)
|
||||
{
|
||||
self.resultCallback(
|
||||
window.openpgp.signClearMessage([oPrivateKey], self.text())
|
||||
);
|
||||
}
|
||||
else if (oPrivateKey && 0 < aPublicKeys.length)
|
||||
{
|
||||
self.resultCallback(
|
||||
window.openpgp.signAndEncryptMessage(aPublicKeys, oPrivateKey, self.text())
|
||||
);
|
||||
}
|
||||
else if (!oPrivateKey && 0 < aPublicKeys.length)
|
||||
{
|
||||
self.resultCallback(
|
||||
window.openpgp.encryptMessage(aPublicKeys, self.text())
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
self.notification(Utils.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
|
||||
'ERROR': '' + e
|
||||
}));
|
||||
|
||||
bResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (bResult)
|
||||
{
|
||||
self.cancelCommand();
|
||||
}
|
||||
|
||||
self.submitRequest(false);
|
||||
|
||||
}, 10);
|
||||
|
||||
}, function () {
|
||||
return !this.submitRequest() && (this.sign() || this.encrypt());
|
||||
});
|
||||
|
||||
this.sDefaultKeyScope = Enums.KeyState.PopupComposeOpenPGP;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsComposeOpenPgpViewModel', PopupsComposeOpenPgpViewModel);
|
||||
|
||||
PopupsComposeOpenPgpViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.notification('');
|
||||
|
||||
this.password('');
|
||||
this.password.focus(false);
|
||||
this.buttonFocus(false);
|
||||
|
||||
this.from('');
|
||||
this.to([]);
|
||||
this.text('');
|
||||
|
||||
this.submitRequest(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
};
|
||||
|
||||
PopupsComposeOpenPgpViewModel.prototype.onBuild = function ()
|
||||
{
|
||||
key('tab,shift+tab', Enums.KeyState.PopupComposeOpenPGP, _.bind(function () {
|
||||
|
||||
switch (true)
|
||||
{
|
||||
case this.password.focus():
|
||||
this.buttonFocus(true);
|
||||
break;
|
||||
case this.buttonFocus():
|
||||
this.password.focus(true);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}, this));
|
||||
};
|
||||
|
||||
PopupsComposeOpenPgpViewModel.prototype.onHide = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
PopupsComposeOpenPgpViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
if (this.sign())
|
||||
{
|
||||
this.password.focus(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.buttonFocus(true);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsComposeOpenPgpViewModel.prototype.onShow = function (fCallback, sText, sFromEmail, sTo, sCc, sBcc)
|
||||
{
|
||||
this.clearPopup();
|
||||
|
||||
var
|
||||
oEmail = new EmailModel(),
|
||||
sResultFromEmail = '',
|
||||
aRec = []
|
||||
;
|
||||
|
||||
this.resultCallback = fCallback;
|
||||
|
||||
oEmail.clear();
|
||||
oEmail.mailsoParse(sFromEmail);
|
||||
if ('' !== oEmail.email)
|
||||
{
|
||||
sResultFromEmail = oEmail.email;
|
||||
}
|
||||
|
||||
if ('' !== sTo)
|
||||
{
|
||||
aRec.push(sTo);
|
||||
}
|
||||
|
||||
if ('' !== sCc)
|
||||
{
|
||||
aRec.push(sCc);
|
||||
}
|
||||
|
||||
if ('' !== sBcc)
|
||||
{
|
||||
aRec.push(sBcc);
|
||||
}
|
||||
|
||||
aRec = aRec.join(', ').split(',');
|
||||
aRec = _.compact(_.map(aRec, function (sValue) {
|
||||
oEmail.clear();
|
||||
oEmail.mailsoParse(Utils.trim(sValue));
|
||||
return '' === oEmail.email ? false : oEmail.email;
|
||||
}));
|
||||
|
||||
this.from(sResultFromEmail);
|
||||
this.to(aRec);
|
||||
this.text(sText);
|
||||
};
|
||||
1694
dev/ViewModels/Popups/PopupsComposeViewModel.js
Normal file
1694
dev/ViewModels/Popups/PopupsComposeViewModel.js
Normal file
File diff suppressed because it is too large
Load diff
743
dev/ViewModels/Popups/PopupsContactsViewModel.js
Normal file
743
dev/ViewModels/Popups/PopupsContactsViewModel.js
Normal file
|
|
@ -0,0 +1,743 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsContactsViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsContacts');
|
||||
|
||||
var
|
||||
self = this,
|
||||
fFastClearEmptyListHelper = function (aList) {
|
||||
if (aList && 0 < aList.length) {
|
||||
self.viewProperties.removeAll(aList);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
this.allowContactsSync = RL.data().allowContactsSync;
|
||||
this.enableContactsSync = RL.data().enableContactsSync;
|
||||
this.allowExport = !Globals.bMobileDevice;
|
||||
|
||||
this.search = ko.observable('');
|
||||
this.contactsCount = ko.observable(0);
|
||||
this.contacts = RL.data().contacts;
|
||||
this.contactTags = RL.data().contactTags;
|
||||
|
||||
this.currentContact = ko.observable(null);
|
||||
|
||||
this.importUploaderButton = ko.observable(null);
|
||||
|
||||
this.contactsPage = ko.observable(1);
|
||||
this.contactsPageCount = ko.computed(function () {
|
||||
var iPage = Math.ceil(this.contactsCount() / Consts.Defaults.ContactsPerPage);
|
||||
return 0 >= iPage ? 1 : iPage;
|
||||
}, this);
|
||||
|
||||
this.contactsPagenator = ko.computed(Utils.computedPagenatorHelper(this.contactsPage, this.contactsPageCount));
|
||||
|
||||
this.emptySelection = ko.observable(true);
|
||||
this.viewClearSearch = ko.observable(false);
|
||||
|
||||
this.viewID = ko.observable('');
|
||||
this.viewReadOnly = ko.observable(false);
|
||||
this.viewProperties = ko.observableArray([]);
|
||||
|
||||
this.viewTags = ko.observable('');
|
||||
this.viewTags.visibility = ko.observable(false);
|
||||
this.viewTags.focusTrigger = ko.observable(false);
|
||||
|
||||
this.viewTags.focusTrigger.subscribe(function (bValue) {
|
||||
if (!bValue && '' === this.viewTags())
|
||||
{
|
||||
this.viewTags.visibility(false);
|
||||
}
|
||||
else if (bValue)
|
||||
{
|
||||
this.viewTags.visibility(true);
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.viewSaveTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
||||
|
||||
this.viewPropertiesNames = this.viewProperties.filter(function(oProperty) {
|
||||
return -1 < Utils.inArray(oProperty.type(), [
|
||||
Enums.ContactPropertyType.FirstName, Enums.ContactPropertyType.LastName
|
||||
]);
|
||||
});
|
||||
|
||||
this.viewPropertiesOther = this.viewProperties.filter(function(oProperty) {
|
||||
return -1 < Utils.inArray(oProperty.type(), [
|
||||
Enums.ContactPropertyType.Note
|
||||
]);
|
||||
});
|
||||
|
||||
this.viewPropertiesOther = ko.computed(function () {
|
||||
|
||||
var aList = _.filter(this.viewProperties(), function (oProperty) {
|
||||
return -1 < Utils.inArray(oProperty.type(), [
|
||||
Enums.ContactPropertyType.Nick
|
||||
]);
|
||||
});
|
||||
|
||||
return _.sortBy(aList, function (oProperty) {
|
||||
return oProperty.type();
|
||||
});
|
||||
|
||||
}, this);
|
||||
|
||||
this.viewPropertiesEmails = this.viewProperties.filter(function(oProperty) {
|
||||
return Enums.ContactPropertyType.Email === oProperty.type();
|
||||
});
|
||||
|
||||
this.viewPropertiesWeb = this.viewProperties.filter(function(oProperty) {
|
||||
return Enums.ContactPropertyType.Web === oProperty.type();
|
||||
});
|
||||
|
||||
this.viewHasNonEmptyRequaredProperties = ko.computed(function() {
|
||||
|
||||
var
|
||||
aNames = this.viewPropertiesNames(),
|
||||
aEmail = this.viewPropertiesEmails(),
|
||||
fHelper = function (oProperty) {
|
||||
return '' !== Utils.trim(oProperty.value());
|
||||
}
|
||||
;
|
||||
|
||||
return !!(_.find(aNames, fHelper) || _.find(aEmail, fHelper));
|
||||
}, this);
|
||||
|
||||
this.viewPropertiesPhones = this.viewProperties.filter(function(oProperty) {
|
||||
return Enums.ContactPropertyType.Phone === oProperty.type();
|
||||
});
|
||||
|
||||
this.viewPropertiesEmailsNonEmpty = this.viewPropertiesNames.filter(function(oProperty) {
|
||||
return '' !== Utils.trim(oProperty.value());
|
||||
});
|
||||
|
||||
this.viewPropertiesEmailsEmptyAndOnFocused = this.viewPropertiesEmails.filter(function(oProperty) {
|
||||
var bF = oProperty.focused();
|
||||
return '' === Utils.trim(oProperty.value()) && !bF;
|
||||
});
|
||||
|
||||
this.viewPropertiesPhonesEmptyAndOnFocused = this.viewPropertiesPhones.filter(function(oProperty) {
|
||||
var bF = oProperty.focused();
|
||||
return '' === Utils.trim(oProperty.value()) && !bF;
|
||||
});
|
||||
|
||||
this.viewPropertiesWebEmptyAndOnFocused = this.viewPropertiesWeb.filter(function(oProperty) {
|
||||
var bF = oProperty.focused();
|
||||
return '' === Utils.trim(oProperty.value()) && !bF;
|
||||
});
|
||||
|
||||
this.viewPropertiesOtherEmptyAndOnFocused = ko.computed(function () {
|
||||
return _.filter(this.viewPropertiesOther(), function (oProperty) {
|
||||
var bF = oProperty.focused();
|
||||
return '' === Utils.trim(oProperty.value()) && !bF;
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.viewPropertiesEmailsEmptyAndOnFocused.subscribe(function(aList) {
|
||||
fFastClearEmptyListHelper(aList);
|
||||
});
|
||||
|
||||
this.viewPropertiesPhonesEmptyAndOnFocused.subscribe(function(aList) {
|
||||
fFastClearEmptyListHelper(aList);
|
||||
});
|
||||
|
||||
this.viewPropertiesWebEmptyAndOnFocused.subscribe(function(aList) {
|
||||
fFastClearEmptyListHelper(aList);
|
||||
});
|
||||
|
||||
this.viewPropertiesOtherEmptyAndOnFocused.subscribe(function(aList) {
|
||||
fFastClearEmptyListHelper(aList);
|
||||
});
|
||||
|
||||
this.viewSaving = ko.observable(false);
|
||||
|
||||
this.useCheckboxesInList = RL.data().useCheckboxesInList;
|
||||
|
||||
this.search.subscribe(function () {
|
||||
this.reloadContactList();
|
||||
}, this);
|
||||
|
||||
this.contacts.subscribe(function () {
|
||||
Utils.windowResize();
|
||||
}, this);
|
||||
|
||||
this.viewProperties.subscribe(function () {
|
||||
Utils.windowResize();
|
||||
}, this);
|
||||
|
||||
this.contactsChecked = ko.computed(function () {
|
||||
return _.filter(this.contacts(), function (oItem) {
|
||||
return oItem.checked();
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.contactsCheckedOrSelected = ko.computed(function () {
|
||||
|
||||
var
|
||||
aChecked = this.contactsChecked(),
|
||||
oSelected = this.currentContact()
|
||||
;
|
||||
|
||||
return _.union(aChecked, oSelected ? [oSelected] : []);
|
||||
|
||||
}, this);
|
||||
|
||||
this.contactsCheckedOrSelectedUids = ko.computed(function () {
|
||||
return _.map(this.contactsCheckedOrSelected(), function (oContact) {
|
||||
return oContact.idContact;
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.selector = new Selector(this.contacts, this.currentContact,
|
||||
'.e-contact-item .actionHandle', '.e-contact-item.selected', '.e-contact-item .checkboxItem',
|
||||
'.e-contact-item.focused');
|
||||
|
||||
this.selector.on('onItemSelect', _.bind(function (oContact) {
|
||||
this.populateViewContact(oContact ? oContact : null);
|
||||
if (!oContact)
|
||||
{
|
||||
this.emptySelection(true);
|
||||
}
|
||||
}, this));
|
||||
|
||||
this.selector.on('onItemGetUid', function (oContact) {
|
||||
return oContact ? oContact.generateUid() : '';
|
||||
});
|
||||
|
||||
this.newCommand = Utils.createCommand(this, function () {
|
||||
this.populateViewContact(null);
|
||||
this.currentContact(null);
|
||||
});
|
||||
|
||||
this.deleteCommand = Utils.createCommand(this, function () {
|
||||
this.deleteSelectedContacts();
|
||||
this.emptySelection(true);
|
||||
}, function () {
|
||||
return 0 < this.contactsCheckedOrSelected().length;
|
||||
});
|
||||
|
||||
this.newMessageCommand = Utils.createCommand(this, function () {
|
||||
var aC = this.contactsCheckedOrSelected(), aE = [];
|
||||
if (Utils.isNonEmptyArray(aC))
|
||||
{
|
||||
aE = _.map(aC, function (oItem) {
|
||||
if (oItem)
|
||||
{
|
||||
var
|
||||
aData = oItem.getNameAndEmailHelper(),
|
||||
oEmail = aData ? new EmailModel(aData[0], aData[1]) : null
|
||||
;
|
||||
|
||||
if (oEmail && oEmail.validate())
|
||||
{
|
||||
return oEmail;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
aE = _.compact(aE);
|
||||
}
|
||||
|
||||
if (Utils.isNonEmptyArray(aE))
|
||||
{
|
||||
kn.hideScreenPopup(PopupsContactsViewModel);
|
||||
kn.showScreenPopup(PopupsComposeViewModel, [Enums.ComposeType.Empty, null, aE]);
|
||||
}
|
||||
|
||||
}, function () {
|
||||
return 0 < this.contactsCheckedOrSelected().length;
|
||||
});
|
||||
|
||||
this.clearCommand = Utils.createCommand(this, function () {
|
||||
this.search('');
|
||||
});
|
||||
|
||||
this.saveCommand = Utils.createCommand(this, function () {
|
||||
|
||||
this.viewSaving(true);
|
||||
this.viewSaveTrigger(Enums.SaveSettingsStep.Animate);
|
||||
|
||||
var
|
||||
sRequestUid = Utils.fakeMd5(),
|
||||
aProperties = []
|
||||
;
|
||||
|
||||
_.each(this.viewProperties(), function (oItem) {
|
||||
if (oItem.type() && '' !== Utils.trim(oItem.value()))
|
||||
{
|
||||
aProperties.push([oItem.type(), oItem.value(), oItem.typeStr()]);
|
||||
}
|
||||
});
|
||||
|
||||
RL.remote().contactSave(function (sResult, oData) {
|
||||
|
||||
var bRes = false;
|
||||
self.viewSaving(false);
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result &&
|
||||
oData.Result.RequestUid === sRequestUid && 0 < Utils.pInt(oData.Result.ResultID))
|
||||
{
|
||||
if ('' === self.viewID())
|
||||
{
|
||||
self.viewID(Utils.pInt(oData.Result.ResultID));
|
||||
}
|
||||
|
||||
self.reloadContactList();
|
||||
bRes = true;
|
||||
}
|
||||
|
||||
_.delay(function () {
|
||||
self.viewSaveTrigger(bRes ? Enums.SaveSettingsStep.TrueResult : Enums.SaveSettingsStep.FalseResult);
|
||||
}, 300);
|
||||
|
||||
if (bRes)
|
||||
{
|
||||
self.watchDirty(false);
|
||||
|
||||
_.delay(function () {
|
||||
self.viewSaveTrigger(Enums.SaveSettingsStep.Idle);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
}, sRequestUid, this.viewID(), this.viewTags(), aProperties);
|
||||
|
||||
}, function () {
|
||||
var
|
||||
bV = this.viewHasNonEmptyRequaredProperties(),
|
||||
bReadOnly = this.viewReadOnly()
|
||||
;
|
||||
return !this.viewSaving() && bV && !bReadOnly;
|
||||
});
|
||||
|
||||
this.syncCommand = Utils.createCommand(this, function () {
|
||||
|
||||
var self = this;
|
||||
RL.contactsSync(function (sResult, oData) {
|
||||
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
|
||||
{
|
||||
window.alert(Utils.getNotification(
|
||||
oData && oData.ErrorCode ? oData.ErrorCode : Enums.Notification.ContactsSyncError));
|
||||
}
|
||||
|
||||
self.reloadContactList(true);
|
||||
});
|
||||
|
||||
}, function () {
|
||||
return !this.contacts.syncing() && !this.contacts.importing();
|
||||
});
|
||||
|
||||
this.bDropPageAfterDelete = false;
|
||||
|
||||
this.watchDirty = ko.observable(false);
|
||||
this.watchHash = ko.observable(false);
|
||||
|
||||
this.viewHash = ko.computed(function () {
|
||||
return '' + self.viewTags() + '|' + _.map(self.viewProperties(), function (oItem) {
|
||||
return oItem.value();
|
||||
}).join('');
|
||||
});
|
||||
|
||||
// this.saveCommandDebounce = _.debounce(_.bind(this.saveCommand, this), 1000);
|
||||
|
||||
this.viewHash.subscribe(function () {
|
||||
if (this.watchHash() && !this.viewReadOnly() && !this.watchDirty())
|
||||
{
|
||||
this.watchDirty(true);
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.sDefaultKeyScope = Enums.KeyState.ContactList;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsContactsViewModel', PopupsContactsViewModel);
|
||||
|
||||
PopupsContactsViewModel.prototype.getPropertyPlceholder = function (sType)
|
||||
{
|
||||
var sResult = '';
|
||||
switch (sType)
|
||||
{
|
||||
case Enums.ContactPropertyType.LastName:
|
||||
sResult = 'CONTACTS/PLACEHOLDER_ENTER_LAST_NAME';
|
||||
break;
|
||||
case Enums.ContactPropertyType.FirstName:
|
||||
sResult = 'CONTACTS/PLACEHOLDER_ENTER_FIRST_NAME';
|
||||
break;
|
||||
case Enums.ContactPropertyType.Nick:
|
||||
sResult = 'CONTACTS/PLACEHOLDER_ENTER_NICK_NAME';
|
||||
break;
|
||||
}
|
||||
|
||||
return sResult;
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewProperty = function (sType, sTypeStr)
|
||||
{
|
||||
this.viewProperties.push(new ContactPropertyModel(sType, sTypeStr || '', '', true, this.getPropertyPlceholder(sType)));
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewOrFocusProperty = function (sType, sTypeStr)
|
||||
{
|
||||
var oItem = _.find(this.viewProperties(), function (oItem) {
|
||||
return sType === oItem.type();
|
||||
});
|
||||
|
||||
if (oItem)
|
||||
{
|
||||
oItem.focused(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addNewProperty(sType, sTypeStr);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewTag = function ()
|
||||
{
|
||||
this.viewTags.visibility(true);
|
||||
this.viewTags.focusTrigger(true);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewEmail = function ()
|
||||
{
|
||||
this.addNewProperty(Enums.ContactPropertyType.Email, 'Home');
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewPhone = function ()
|
||||
{
|
||||
this.addNewProperty(Enums.ContactPropertyType.Phone, 'Mobile');
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewWeb = function ()
|
||||
{
|
||||
this.addNewProperty(Enums.ContactPropertyType.Web);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewNickname = function ()
|
||||
{
|
||||
this.addNewOrFocusProperty(Enums.ContactPropertyType.Nick);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewNotes = function ()
|
||||
{
|
||||
this.addNewOrFocusProperty(Enums.ContactPropertyType.Note);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewBirthday = function ()
|
||||
{
|
||||
this.addNewOrFocusProperty(Enums.ContactPropertyType.Birthday);
|
||||
};
|
||||
|
||||
//PopupsContactsViewModel.prototype.addNewAddress = function ()
|
||||
//{
|
||||
//};
|
||||
|
||||
PopupsContactsViewModel.prototype.exportVcf = function ()
|
||||
{
|
||||
RL.download(RL.link().exportContactsVcf());
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.exportCsv = function ()
|
||||
{
|
||||
RL.download(RL.link().exportContactsCsv());
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.initUploader = function ()
|
||||
{
|
||||
if (this.importUploaderButton())
|
||||
{
|
||||
var
|
||||
oJua = new Jua({
|
||||
'action': RL.link().uploadContacts(),
|
||||
'name': 'uploader',
|
||||
'queueSize': 1,
|
||||
'multipleSizeLimit': 1,
|
||||
'disableFolderDragAndDrop': true,
|
||||
'disableDragAndDrop': true,
|
||||
'disableMultiple': true,
|
||||
'disableDocumentDropPrevent': true,
|
||||
'clickElement': this.importUploaderButton()
|
||||
})
|
||||
;
|
||||
|
||||
if (oJua)
|
||||
{
|
||||
oJua
|
||||
.on('onStart', _.bind(function () {
|
||||
this.contacts.importing(true);
|
||||
}, this))
|
||||
.on('onComplete', _.bind(function (sId, bResult, oData) {
|
||||
|
||||
this.contacts.importing(false);
|
||||
this.reloadContactList();
|
||||
|
||||
if (!sId || !bResult || !oData || !oData.Result)
|
||||
{
|
||||
window.alert(Utils.i18n('CONTACTS/ERROR_IMPORT_FILE'));
|
||||
}
|
||||
|
||||
}, this))
|
||||
;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.removeCheckedOrSelectedContactsFromList = function ()
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
oKoContacts = this.contacts,
|
||||
oCurrentContact = this.currentContact(),
|
||||
iCount = this.contacts().length,
|
||||
aContacts = this.contactsCheckedOrSelected()
|
||||
;
|
||||
|
||||
if (0 < aContacts.length)
|
||||
{
|
||||
_.each(aContacts, function (oContact) {
|
||||
|
||||
if (oCurrentContact && oCurrentContact.idContact === oContact.idContact)
|
||||
{
|
||||
oCurrentContact = null;
|
||||
self.currentContact(null);
|
||||
}
|
||||
|
||||
oContact.deleted(true);
|
||||
iCount--;
|
||||
});
|
||||
|
||||
if (iCount <= 0)
|
||||
{
|
||||
this.bDropPageAfterDelete = true;
|
||||
}
|
||||
|
||||
_.delay(function () {
|
||||
|
||||
_.each(aContacts, function (oContact) {
|
||||
oKoContacts.remove(oContact);
|
||||
});
|
||||
|
||||
}, 500);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.deleteSelectedContacts = function ()
|
||||
{
|
||||
if (0 < this.contactsCheckedOrSelected().length)
|
||||
{
|
||||
RL.remote().contactsDelete(
|
||||
_.bind(this.deleteResponse, this),
|
||||
this.contactsCheckedOrSelectedUids()
|
||||
);
|
||||
|
||||
this.removeCheckedOrSelectedContactsFromList();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sResult
|
||||
* @param {AjaxJsonDefaultResponse} oData
|
||||
*/
|
||||
PopupsContactsViewModel.prototype.deleteResponse = function (sResult, oData)
|
||||
{
|
||||
if (500 < (Enums.StorageResultType.Success === sResult && oData && oData.Time ? Utils.pInt(oData.Time) : 0))
|
||||
{
|
||||
this.reloadContactList(this.bDropPageAfterDelete);
|
||||
}
|
||||
else
|
||||
{
|
||||
_.delay((function (self) {
|
||||
return function () {
|
||||
self.reloadContactList(self.bDropPageAfterDelete);
|
||||
};
|
||||
}(this)), 500);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.removeProperty = function (oProp)
|
||||
{
|
||||
this.viewProperties.remove(oProp);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {?ContactModel} oContact
|
||||
*/
|
||||
PopupsContactsViewModel.prototype.populateViewContact = function (oContact)
|
||||
{
|
||||
var
|
||||
sId = '',
|
||||
sLastName = '',
|
||||
sFirstName = '',
|
||||
aList = []
|
||||
;
|
||||
|
||||
this.watchHash(false);
|
||||
|
||||
this.emptySelection(false);
|
||||
this.viewReadOnly(false);
|
||||
this.viewTags('');
|
||||
|
||||
if (oContact)
|
||||
{
|
||||
sId = oContact.idContact;
|
||||
if (Utils.isNonEmptyArray(oContact.properties))
|
||||
{
|
||||
_.each(oContact.properties, function (aProperty) {
|
||||
if (aProperty && aProperty[0])
|
||||
{
|
||||
if (Enums.ContactPropertyType.LastName === aProperty[0])
|
||||
{
|
||||
sLastName = aProperty[1];
|
||||
}
|
||||
else if (Enums.ContactPropertyType.FirstName === aProperty[0])
|
||||
{
|
||||
sFirstName = aProperty[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
aList.push(new ContactPropertyModel(aProperty[0], aProperty[2] || '', aProperty[1]));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.viewTags(oContact.tags);
|
||||
|
||||
this.viewReadOnly(!!oContact.readOnly);
|
||||
}
|
||||
|
||||
this.viewTags.focusTrigger.valueHasMutated();
|
||||
this.viewTags.visibility('' !== this.viewTags());
|
||||
|
||||
aList.unshift(new ContactPropertyModel(Enums.ContactPropertyType.LastName, '', sLastName, false,
|
||||
this.getPropertyPlceholder(Enums.ContactPropertyType.LastName)));
|
||||
|
||||
aList.unshift(new ContactPropertyModel(Enums.ContactPropertyType.FirstName, '', sFirstName, !oContact,
|
||||
this.getPropertyPlceholder(Enums.ContactPropertyType.FirstName)));
|
||||
|
||||
this.viewID(sId);
|
||||
this.viewProperties([]);
|
||||
this.viewProperties(aList);
|
||||
|
||||
this.watchDirty(false);
|
||||
this.watchHash(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {boolean=} bDropPagePosition = false
|
||||
*/
|
||||
PopupsContactsViewModel.prototype.reloadContactList = function (bDropPagePosition)
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
iOffset = (this.contactsPage() - 1) * Consts.Defaults.ContactsPerPage
|
||||
;
|
||||
|
||||
this.bDropPageAfterDelete = false;
|
||||
|
||||
if (Utils.isUnd(bDropPagePosition) ? false : !!bDropPagePosition)
|
||||
{
|
||||
this.contactsPage(1);
|
||||
iOffset = 0;
|
||||
}
|
||||
|
||||
this.contacts.loading(true);
|
||||
RL.remote().contacts(function (sResult, oData) {
|
||||
var
|
||||
iCount = 0,
|
||||
aList = [],
|
||||
aTagsList = []
|
||||
;
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result.List)
|
||||
{
|
||||
if (Utils.isNonEmptyArray(oData.Result.List))
|
||||
{
|
||||
aList = _.map(oData.Result.List, function (oItem) {
|
||||
var oContact = new ContactModel();
|
||||
return oContact.parse(oItem) ? oContact : null;
|
||||
});
|
||||
|
||||
aList = _.compact(aList);
|
||||
|
||||
iCount = Utils.pInt(oData.Result.Count);
|
||||
iCount = 0 < iCount ? iCount : 0;
|
||||
}
|
||||
|
||||
if (Utils.isNonEmptyArray(oData.Result.Tags))
|
||||
{
|
||||
aTagsList = _.map(oData.Result.Tags, function (oItem) {
|
||||
var oContactTag = new ContactTagModel();
|
||||
return oContactTag.parse(oItem) ? oContactTag : null;
|
||||
});
|
||||
|
||||
aTagsList = _.compact(aTagsList);
|
||||
}
|
||||
}
|
||||
|
||||
self.contactsCount(iCount);
|
||||
|
||||
self.contacts(aList);
|
||||
self.contactTags(aTagsList);
|
||||
self.contacts.loading(false);
|
||||
|
||||
self.viewClearSearch('' !== self.search());
|
||||
|
||||
}, iOffset, Consts.Defaults.ContactsPerPage, this.search());
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
||||
{
|
||||
this.oContentVisible = $('.b-list-content', oDom);
|
||||
this.oContentScrollable = $('.content', this.oContentVisible);
|
||||
|
||||
this.selector.init(this.oContentVisible, this.oContentScrollable, Enums.KeyState.ContactList);
|
||||
|
||||
var self = this;
|
||||
|
||||
key('delete', Enums.KeyState.ContactList, function () {
|
||||
self.deleteCommand();
|
||||
return false;
|
||||
});
|
||||
|
||||
oDom
|
||||
.on('click', '.e-pagenator .e-page', function () {
|
||||
var oPage = ko.dataFor(this);
|
||||
if (oPage)
|
||||
{
|
||||
self.contactsPage(Utils.pInt(oPage.value));
|
||||
self.reloadContactList();
|
||||
}
|
||||
})
|
||||
;
|
||||
|
||||
this.initUploader();
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.onShow = function ()
|
||||
{
|
||||
kn.routeOff();
|
||||
this.reloadContactList(true);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.onHide = function ()
|
||||
{
|
||||
kn.routeOn();
|
||||
this.currentContact(null);
|
||||
this.emptySelection(true);
|
||||
this.search('');
|
||||
this.contactsCount(0);
|
||||
this.contacts([]);
|
||||
// _.each(this.contacts(), function (oItem) {
|
||||
// oItem.checked(false);
|
||||
// });
|
||||
};
|
||||
296
dev/ViewModels/Popups/PopupsDomainViewModel.js
Normal file
296
dev/ViewModels/Popups/PopupsDomainViewModel.js
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsDomainViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsDomain');
|
||||
|
||||
this.edit = ko.observable(false);
|
||||
this.saving = ko.observable(false);
|
||||
this.savingError = ko.observable('');
|
||||
this.whiteListPage = ko.observable(false);
|
||||
|
||||
this.testing = ko.observable(false);
|
||||
this.testingDone = ko.observable(false);
|
||||
this.testingImapError = ko.observable(false);
|
||||
this.testingSmtpError = ko.observable(false);
|
||||
this.testingImapErrorDesc = ko.observable('');
|
||||
this.testingSmtpErrorDesc = ko.observable('');
|
||||
|
||||
this.testingImapError.subscribe(function (bValue) {
|
||||
if (!bValue)
|
||||
{
|
||||
this.testingImapErrorDesc('');
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.testingSmtpError.subscribe(function (bValue) {
|
||||
if (!bValue)
|
||||
{
|
||||
this.testingSmtpErrorDesc('');
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.testingImapErrorDesc = ko.observable('');
|
||||
this.testingSmtpErrorDesc = ko.observable('');
|
||||
|
||||
this.imapServerFocus = ko.observable(false);
|
||||
this.smtpServerFocus = ko.observable(false);
|
||||
|
||||
this.name = ko.observable('');
|
||||
this.name.focused = ko.observable(false);
|
||||
|
||||
this.imapServer = ko.observable('');
|
||||
this.imapPort = ko.observable('' + Consts.Values.ImapDefaulPort);
|
||||
this.imapSecure = ko.observable(Enums.ServerSecure.None);
|
||||
this.imapShortLogin = ko.observable(false);
|
||||
this.smtpServer = ko.observable('');
|
||||
this.smtpPort = ko.observable('' + Consts.Values.SmtpDefaulPort);
|
||||
this.smtpSecure = ko.observable(Enums.ServerSecure.None);
|
||||
this.smtpShortLogin = ko.observable(false);
|
||||
this.smtpAuth = ko.observable(true);
|
||||
this.whiteList = ko.observable('');
|
||||
|
||||
this.headerText = ko.computed(function () {
|
||||
var sName = this.name();
|
||||
return this.edit() ? 'Edit Domain "' + sName + '"' :
|
||||
'Add Domain' + ('' === sName ? '' : ' "' + sName + '"');
|
||||
}, this);
|
||||
|
||||
this.domainIsComputed = ko.computed(function () {
|
||||
return '' !== this.name() &&
|
||||
'' !== this.imapServer() &&
|
||||
'' !== this.imapPort() &&
|
||||
'' !== this.smtpServer() &&
|
||||
'' !== this.smtpPort();
|
||||
}, this);
|
||||
|
||||
this.canBeTested = ko.computed(function () {
|
||||
return !this.testing() && this.domainIsComputed();
|
||||
}, this);
|
||||
|
||||
this.canBeSaved = ko.computed(function () {
|
||||
return !this.saving() && this.domainIsComputed();
|
||||
}, this);
|
||||
|
||||
this.createOrAddCommand = Utils.createCommand(this, function () {
|
||||
this.saving(true);
|
||||
RL.remote().createOrUpdateDomain(
|
||||
_.bind(this.onDomainCreateOrSaveResponse, this),
|
||||
!this.edit(),
|
||||
this.name(),
|
||||
this.imapServer(),
|
||||
Utils.pInt(this.imapPort()),
|
||||
this.imapSecure(),
|
||||
this.imapShortLogin(),
|
||||
this.smtpServer(),
|
||||
Utils.pInt(this.smtpPort()),
|
||||
this.smtpSecure(),
|
||||
this.smtpShortLogin(),
|
||||
this.smtpAuth(),
|
||||
this.whiteList()
|
||||
);
|
||||
}, this.canBeSaved);
|
||||
|
||||
this.testConnectionCommand = Utils.createCommand(this, function () {
|
||||
this.whiteListPage(false);
|
||||
this.testingDone(false);
|
||||
this.testingImapError(false);
|
||||
this.testingSmtpError(false);
|
||||
this.testing(true);
|
||||
RL.remote().testConnectionForDomain(
|
||||
_.bind(this.onTestConnectionResponse, this),
|
||||
this.name(),
|
||||
this.imapServer(),
|
||||
Utils.pInt(this.imapPort()),
|
||||
this.imapSecure(),
|
||||
this.smtpServer(),
|
||||
Utils.pInt(this.smtpPort()),
|
||||
this.smtpSecure(),
|
||||
this.smtpAuth()
|
||||
);
|
||||
}, this.canBeTested);
|
||||
|
||||
this.whiteListCommand = Utils.createCommand(this, function () {
|
||||
this.whiteListPage(!this.whiteListPage());
|
||||
});
|
||||
|
||||
// smart form improvements
|
||||
this.imapServerFocus.subscribe(function (bValue) {
|
||||
if (bValue && '' !== this.name() && '' === this.imapServer())
|
||||
{
|
||||
this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.smtpServerFocus.subscribe(function (bValue) {
|
||||
if (bValue && '' !== this.imapServer() && '' === this.smtpServer())
|
||||
{
|
||||
this.smtpServer(this.imapServer().replace(/imap/ig, 'smtp'));
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.imapSecure.subscribe(function (sValue) {
|
||||
var iPort = Utils.pInt(this.imapPort());
|
||||
sValue = Utils.pString(sValue);
|
||||
switch (sValue)
|
||||
{
|
||||
case '0':
|
||||
if (993 === iPort)
|
||||
{
|
||||
this.imapPort('143');
|
||||
}
|
||||
break;
|
||||
case '1':
|
||||
if (143 === iPort)
|
||||
{
|
||||
this.imapPort('993');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.smtpSecure.subscribe(function (sValue) {
|
||||
var iPort = Utils.pInt(this.smtpPort());
|
||||
sValue = Utils.pString(sValue);
|
||||
switch (sValue)
|
||||
{
|
||||
case '0':
|
||||
if (465 === iPort || 587 === iPort)
|
||||
{
|
||||
this.smtpPort('25');
|
||||
}
|
||||
break;
|
||||
case '1':
|
||||
if (25 === iPort || 587 === iPort)
|
||||
{
|
||||
this.smtpPort('465');
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if (25 === iPort || 465 === iPort)
|
||||
{
|
||||
this.smtpPort('587');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}, this);
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsDomainViewModel', PopupsDomainViewModel);
|
||||
|
||||
PopupsDomainViewModel.prototype.onTestConnectionResponse = function (sResult, oData)
|
||||
{
|
||||
this.testing(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData.Result)
|
||||
{
|
||||
this.testingDone(true);
|
||||
this.testingImapError(true !== oData.Result.Imap);
|
||||
this.testingSmtpError(true !== oData.Result.Smtp);
|
||||
|
||||
if (this.testingImapError() && oData.Result.Imap)
|
||||
{
|
||||
this.testingImapErrorDesc(oData.Result.Imap);
|
||||
}
|
||||
|
||||
if (this.testingSmtpError() && oData.Result.Smtp)
|
||||
{
|
||||
this.testingSmtpErrorDesc(oData.Result.Smtp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.testingImapError(true);
|
||||
this.testingSmtpError(true);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsDomainViewModel.prototype.onDomainCreateOrSaveResponse = function (sResult, oData)
|
||||
{
|
||||
this.saving(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData)
|
||||
{
|
||||
if (oData.Result)
|
||||
{
|
||||
RL.reloadDomainList();
|
||||
this.closeCommand();
|
||||
}
|
||||
else if (Enums.Notification.DomainAlreadyExists === oData.ErrorCode)
|
||||
{
|
||||
this.savingError('Domain already exists');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.savingError('Unknown error');
|
||||
}
|
||||
};
|
||||
|
||||
PopupsDomainViewModel.prototype.onHide = function ()
|
||||
{
|
||||
this.whiteListPage(false);
|
||||
};
|
||||
|
||||
PopupsDomainViewModel.prototype.onShow = function (oDomain)
|
||||
{
|
||||
this.saving(false);
|
||||
this.whiteListPage(false);
|
||||
|
||||
this.testing(false);
|
||||
this.testingDone(false);
|
||||
this.testingImapError(false);
|
||||
this.testingSmtpError(false);
|
||||
|
||||
this.clearForm();
|
||||
if (oDomain)
|
||||
{
|
||||
this.edit(true);
|
||||
|
||||
this.name(Utils.trim(oDomain.Name));
|
||||
this.imapServer(Utils.trim(oDomain.IncHost));
|
||||
this.imapPort('' + Utils.pInt(oDomain.IncPort));
|
||||
this.imapSecure(Utils.trim(oDomain.IncSecure));
|
||||
this.imapShortLogin(!!oDomain.IncShortLogin);
|
||||
this.smtpServer(Utils.trim(oDomain.OutHost));
|
||||
this.smtpPort('' + Utils.pInt(oDomain.OutPort));
|
||||
this.smtpSecure(Utils.trim(oDomain.OutSecure));
|
||||
this.smtpShortLogin(!!oDomain.OutShortLogin);
|
||||
this.smtpAuth(!!oDomain.OutAuth);
|
||||
this.whiteList(Utils.trim(oDomain.WhiteList));
|
||||
}
|
||||
};
|
||||
|
||||
PopupsDomainViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
if ('' === this.name())
|
||||
{
|
||||
this.name.focused(true);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsDomainViewModel.prototype.clearForm = function ()
|
||||
{
|
||||
this.edit(false);
|
||||
this.whiteListPage(false);
|
||||
|
||||
this.savingError('');
|
||||
|
||||
this.name('');
|
||||
this.name.focused(false);
|
||||
|
||||
this.imapServer('');
|
||||
this.imapPort('' + Consts.Values.ImapDefaulPort);
|
||||
this.imapSecure(Enums.ServerSecure.None);
|
||||
this.imapShortLogin(false);
|
||||
this.smtpServer('');
|
||||
this.smtpPort('' + Consts.Values.SmtpDefaulPort);
|
||||
this.smtpSecure(Enums.ServerSecure.None);
|
||||
this.smtpShortLogin(false);
|
||||
this.smtpAuth(true);
|
||||
this.whiteList('');
|
||||
};
|
||||
37
dev/ViewModels/Popups/PopupsFiterViewModel.js
Normal file
37
dev/ViewModels/Popups/PopupsFiterViewModel.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsFilterViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFilter');
|
||||
|
||||
this.filter = ko.observable(null);
|
||||
|
||||
this.selectedFolderValue = ko.observable(Consts.Values.UnuseOptionValue);
|
||||
this.folderSelectList = RL.data().folderMenuForMove;
|
||||
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsFilterViewModel', PopupsFilterViewModel);
|
||||
|
||||
PopupsFilterViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
PopupsFilterViewModel.prototype.onShow = function (oFilter)
|
||||
{
|
||||
this.clearPopup();
|
||||
|
||||
this.filter(oFilter);
|
||||
};
|
||||
|
||||
PopupsFilterViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
|
||||
};
|
||||
97
dev/ViewModels/Popups/PopupsFolderClearViewModel.js
Normal file
97
dev/ViewModels/Popups/PopupsFolderClearViewModel.js
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsFolderClearViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFolderClear');
|
||||
|
||||
this.selectedFolder = ko.observable(null);
|
||||
this.clearingProcess = ko.observable(false);
|
||||
this.clearingError = ko.observable('');
|
||||
|
||||
this.folderFullNameForClear = ko.computed(function () {
|
||||
var oFolder = this.selectedFolder();
|
||||
return oFolder ? oFolder.printableFullName() : '';
|
||||
}, this);
|
||||
|
||||
this.folderNameForClear = ko.computed(function () {
|
||||
var oFolder = this.selectedFolder();
|
||||
return oFolder ? oFolder.localName() : '';
|
||||
}, this);
|
||||
|
||||
this.dangerDescHtml = ko.computed(function () {
|
||||
return Utils.i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', {
|
||||
'FOLDER': this.folderNameForClear()
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.clearCommand = Utils.createCommand(this, function () {
|
||||
|
||||
var
|
||||
self = this,
|
||||
oFolderToClear = this.selectedFolder()
|
||||
;
|
||||
|
||||
if (oFolderToClear)
|
||||
{
|
||||
RL.data().message(null);
|
||||
RL.data().messageList([]);
|
||||
|
||||
this.clearingProcess(true);
|
||||
|
||||
RL.cache().setFolderHash(oFolderToClear.fullNameRaw, '');
|
||||
RL.remote().folderClear(function (sResult, oData) {
|
||||
|
||||
self.clearingProcess(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
RL.reloadMessageList(true);
|
||||
self.cancelCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oData && oData.ErrorCode)
|
||||
{
|
||||
self.clearingError(Utils.getNotification(oData.ErrorCode));
|
||||
}
|
||||
else
|
||||
{
|
||||
self.clearingError(Utils.getNotification(Enums.Notification.MailServerError));
|
||||
}
|
||||
}
|
||||
}, oFolderToClear.fullNameRaw);
|
||||
}
|
||||
|
||||
}, function () {
|
||||
|
||||
var
|
||||
oFolder = this.selectedFolder(),
|
||||
bIsClearing = this.clearingProcess()
|
||||
;
|
||||
|
||||
return !bIsClearing && null !== oFolder;
|
||||
|
||||
});
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsFolderClearViewModel', PopupsFolderClearViewModel);
|
||||
|
||||
PopupsFolderClearViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.clearingProcess(false);
|
||||
this.selectedFolder(null);
|
||||
};
|
||||
|
||||
PopupsFolderClearViewModel.prototype.onShow = function (oFolder)
|
||||
{
|
||||
this.clearPopup();
|
||||
if (oFolder)
|
||||
{
|
||||
this.selectedFolder(oFolder);
|
||||
}
|
||||
};
|
||||
111
dev/ViewModels/Popups/PopupsFolderCreateViewModel.js
Normal file
111
dev/ViewModels/Popups/PopupsFolderCreateViewModel.js
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsFolderCreateViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFolderCreate');
|
||||
|
||||
Utils.initOnStartOrLangChange(function () {
|
||||
this.sNoParentText = Utils.i18n('POPUPS_CREATE_FOLDER/SELECT_NO_PARENT');
|
||||
}, this);
|
||||
|
||||
this.folderName = ko.observable('');
|
||||
this.folderName.focused = ko.observable(false);
|
||||
|
||||
this.selectedParentValue = ko.observable(Consts.Values.UnuseOptionValue);
|
||||
|
||||
this.parentFolderSelectList = ko.computed(function () {
|
||||
|
||||
var
|
||||
oData = RL.data(),
|
||||
aTop = [],
|
||||
fDisableCallback = null,
|
||||
fVisibleCallback = null,
|
||||
aList = oData.folderList(),
|
||||
fRenameCallback = function (oItem) {
|
||||
return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
|
||||
}
|
||||
;
|
||||
|
||||
aTop.push(['', this.sNoParentText]);
|
||||
|
||||
if ('' !== oData.namespace)
|
||||
{
|
||||
fDisableCallback = function (oItem)
|
||||
{
|
||||
return oData.namespace !== oItem.fullNameRaw.substr(0, oData.namespace.length);
|
||||
};
|
||||
}
|
||||
|
||||
return RL.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);
|
||||
|
||||
}, this);
|
||||
|
||||
// commands
|
||||
this.createFolder = Utils.createCommand(this, function () {
|
||||
|
||||
var
|
||||
oData = RL.data(),
|
||||
sParentFolderName = this.selectedParentValue()
|
||||
;
|
||||
|
||||
if ('' === sParentFolderName && 1 < oData.namespace.length)
|
||||
{
|
||||
sParentFolderName = oData.namespace.substr(0, oData.namespace.length - 1);
|
||||
}
|
||||
|
||||
oData.foldersCreating(true);
|
||||
RL.remote().folderCreate(function (sResult, oData) {
|
||||
|
||||
RL.data().foldersCreating(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
RL.folders();
|
||||
}
|
||||
else
|
||||
{
|
||||
RL.data().foldersListError(
|
||||
oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) : Utils.i18n('NOTIFICATIONS/CANT_CREATE_FOLDER'));
|
||||
}
|
||||
|
||||
}, this.folderName(), sParentFolderName);
|
||||
|
||||
this.cancelCommand();
|
||||
|
||||
}, function () {
|
||||
return this.simpleFolderNameValidation(this.folderName());
|
||||
});
|
||||
|
||||
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsFolderCreateViewModel', PopupsFolderCreateViewModel);
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.sNoParentText = '';
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.simpleFolderNameValidation = function (sName)
|
||||
{
|
||||
return (/^[^\\\/]+$/g).test(Utils.trim(sName));
|
||||
};
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.folderName('');
|
||||
this.selectedParentValue('');
|
||||
this.folderName.focused(false);
|
||||
};
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
PopupsFolderCreateViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
this.folderName.focused(true);
|
||||
};
|
||||
114
dev/ViewModels/Popups/PopupsFolderSystemViewModel.js
Normal file
114
dev/ViewModels/Popups/PopupsFolderSystemViewModel.js
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsFolderSystemViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFolderSystem');
|
||||
|
||||
Utils.initOnStartOrLangChange(function () {
|
||||
this.sChooseOnText = Utils.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_CHOOSE_ONE');
|
||||
this.sUnuseText = Utils.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_UNUSE_NAME');
|
||||
}, this);
|
||||
|
||||
this.notification = ko.observable('');
|
||||
|
||||
this.folderSelectList = ko.computed(function () {
|
||||
return RL.folderListOptionsBuilder([], RL.data().folderList(), RL.data().folderListSystemNames(), [
|
||||
['', this.sChooseOnText],
|
||||
[Consts.Values.UnuseOptionValue, this.sUnuseText]
|
||||
]);
|
||||
}, this);
|
||||
|
||||
var
|
||||
oData = RL.data(),
|
||||
self = this,
|
||||
fSaveSystemFolders = null,
|
||||
fCallback = null
|
||||
;
|
||||
|
||||
this.sentFolder = oData.sentFolder;
|
||||
this.draftFolder = oData.draftFolder;
|
||||
this.spamFolder = oData.spamFolder;
|
||||
this.trashFolder = oData.trashFolder;
|
||||
this.archiveFolder = oData.archiveFolder;
|
||||
|
||||
fSaveSystemFolders = _.debounce(function () {
|
||||
|
||||
RL.settingsSet('SentFolder', self.sentFolder());
|
||||
RL.settingsSet('DraftFolder', self.draftFolder());
|
||||
RL.settingsSet('SpamFolder', self.spamFolder());
|
||||
RL.settingsSet('TrashFolder', self.trashFolder());
|
||||
RL.settingsSet('ArchiveFolder', self.archiveFolder());
|
||||
|
||||
RL.remote().saveSystemFolders(Utils.emptyFunction, {
|
||||
'SentFolder': self.sentFolder(),
|
||||
'DraftFolder': self.draftFolder(),
|
||||
'SpamFolder': self.spamFolder(),
|
||||
'TrashFolder': self.trashFolder(),
|
||||
'ArchiveFolder': self.archiveFolder(),
|
||||
'NullFolder': 'NullFolder'
|
||||
});
|
||||
|
||||
}, 1000);
|
||||
|
||||
fCallback = function () {
|
||||
|
||||
RL.settingsSet('SentFolder', self.sentFolder());
|
||||
RL.settingsSet('DraftFolder', self.draftFolder());
|
||||
RL.settingsSet('SpamFolder', self.spamFolder());
|
||||
RL.settingsSet('TrashFolder', self.trashFolder());
|
||||
RL.settingsSet('ArchiveFolder', self.archiveFolder());
|
||||
|
||||
fSaveSystemFolders();
|
||||
};
|
||||
|
||||
this.sentFolder.subscribe(fCallback);
|
||||
this.draftFolder.subscribe(fCallback);
|
||||
this.spamFolder.subscribe(fCallback);
|
||||
this.trashFolder.subscribe(fCallback);
|
||||
this.archiveFolder.subscribe(fCallback);
|
||||
|
||||
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsFolderSystemViewModel', PopupsFolderSystemViewModel);
|
||||
|
||||
PopupsFolderSystemViewModel.prototype.sChooseOnText = '';
|
||||
PopupsFolderSystemViewModel.prototype.sUnuseText = '';
|
||||
|
||||
/**
|
||||
* @param {number=} iNotificationType = Enums.SetSystemFoldersNotification.None
|
||||
*/
|
||||
PopupsFolderSystemViewModel.prototype.onShow = function (iNotificationType)
|
||||
{
|
||||
var sNotification = '';
|
||||
|
||||
iNotificationType = Utils.isUnd(iNotificationType) ? Enums.SetSystemFoldersNotification.None : iNotificationType;
|
||||
|
||||
switch (iNotificationType)
|
||||
{
|
||||
case Enums.SetSystemFoldersNotification.Sent:
|
||||
sNotification = Utils.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SENT');
|
||||
break;
|
||||
case Enums.SetSystemFoldersNotification.Draft:
|
||||
sNotification = Utils.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_DRAFTS');
|
||||
break;
|
||||
case Enums.SetSystemFoldersNotification.Spam:
|
||||
sNotification = Utils.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SPAM');
|
||||
break;
|
||||
case Enums.SetSystemFoldersNotification.Trash:
|
||||
sNotification = Utils.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_TRASH');
|
||||
break;
|
||||
case Enums.SetSystemFoldersNotification.Archive:
|
||||
sNotification = Utils.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_ARCHIVE');
|
||||
break;
|
||||
}
|
||||
|
||||
this.notification(sNotification);
|
||||
};
|
||||
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsGenerateNewOpenPgpKeyViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsGenerateNewOpenPgpKey');
|
||||
|
||||
this.email = ko.observable('');
|
||||
this.email.focus = ko.observable('');
|
||||
this.email.error = ko.observable(false);
|
||||
|
||||
this.name = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
this.keyBitLength = ko.observable(2048);
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
|
||||
this.email.subscribe(function () {
|
||||
this.email.error(false);
|
||||
}, this);
|
||||
|
||||
this.generateOpenPgpKeyCommand = Utils.createCommand(this, function () {
|
||||
|
||||
var
|
||||
self = this,
|
||||
sUserID = '',
|
||||
mKeyPair = null,
|
||||
oOpenpgpKeyring = RL.data().openpgpKeyring
|
||||
;
|
||||
|
||||
this.email.error('' === Utils.trim(this.email()));
|
||||
if (!oOpenpgpKeyring || this.email.error())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sUserID = this.email();
|
||||
if ('' !== this.name())
|
||||
{
|
||||
sUserID = this.name() + ' <' + sUserID + '>';
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
_.delay(function () {
|
||||
mKeyPair = window.openpgp.generateKeyPair(1, Utils.pInt(self.keyBitLength()), sUserID, Utils.trim(self.password()));
|
||||
// 0.6.0
|
||||
// mKeyPair = window.openpgp.generateKeyPair({
|
||||
// 'numBits': Utils.pInt(self.keyBitLength()),
|
||||
// 'userId': sUserID,
|
||||
// 'passphrase': Utils.trim(self.password())
|
||||
// });
|
||||
|
||||
if (mKeyPair && mKeyPair.privateKeyArmored)
|
||||
{
|
||||
oOpenpgpKeyring.privateKeys.importKey(mKeyPair.privateKeyArmored);
|
||||
oOpenpgpKeyring.publicKeys.importKey(mKeyPair.publicKeyArmored);
|
||||
oOpenpgpKeyring.store();
|
||||
|
||||
RL.reloadOpenPgpKeys();
|
||||
Utils.delegateRun(self, 'cancelCommand');
|
||||
}
|
||||
|
||||
self.submitRequest(false);
|
||||
}, 100);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsGenerateNewOpenPgpKeyViewModel', PopupsGenerateNewOpenPgpKeyViewModel);
|
||||
|
||||
PopupsGenerateNewOpenPgpKeyViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.name('');
|
||||
this.password('');
|
||||
|
||||
this.email('');
|
||||
this.email.error(false);
|
||||
this.keyBitLength(2048);
|
||||
};
|
||||
|
||||
PopupsGenerateNewOpenPgpKeyViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
PopupsGenerateNewOpenPgpKeyViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
this.email.focus(true);
|
||||
};
|
||||
149
dev/ViewModels/Popups/PopupsIdentityViewModel.js
Normal file
149
dev/ViewModels/Popups/PopupsIdentityViewModel.js
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsIdentityViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsIdentity');
|
||||
|
||||
this.id = '';
|
||||
this.edit = ko.observable(false);
|
||||
this.owner = ko.observable(false);
|
||||
|
||||
this.email = ko.observable('').validateEmail();
|
||||
this.email.focused = ko.observable(false);
|
||||
this.name = ko.observable('');
|
||||
this.name.focused = ko.observable(false);
|
||||
this.replyTo = ko.observable('').validateSimpleEmail();
|
||||
this.replyTo.focused = ko.observable(false);
|
||||
this.bcc = ko.observable('').validateSimpleEmail();
|
||||
this.bcc.focused = ko.observable(false);
|
||||
|
||||
// this.email.subscribe(function () {
|
||||
// this.email.hasError(false);
|
||||
// }, this);
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
|
||||
this.addOrEditIdentityCommand = Utils.createCommand(this, function () {
|
||||
|
||||
if (!this.email.hasError())
|
||||
{
|
||||
this.email.hasError('' === Utils.trim(this.email()));
|
||||
}
|
||||
|
||||
if (this.email.hasError())
|
||||
{
|
||||
if (!this.owner())
|
||||
{
|
||||
this.email.focused(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.replyTo.hasError())
|
||||
{
|
||||
this.replyTo.focused(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.bcc.hasError())
|
||||
{
|
||||
this.bcc.focused(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
RL.remote().identityUpdate(_.bind(function (sResult, oData) {
|
||||
|
||||
this.submitRequest(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData)
|
||||
{
|
||||
if (oData.Result)
|
||||
{
|
||||
RL.accountsAndIdentities();
|
||||
this.cancelCommand();
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
{
|
||||
this.submitError(Utils.getNotification(oData.ErrorCode));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitError(Utils.getNotification(Enums.Notification.UnknownError));
|
||||
}
|
||||
|
||||
}, this), this.id, this.email(), this.name(), this.replyTo(), this.bcc());
|
||||
|
||||
return true;
|
||||
|
||||
}, function () {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
|
||||
this.label = ko.computed(function () {
|
||||
return Utils.i18n('POPUPS_IDENTITIES/' + (this.edit() ? 'TITLE_UPDATE_IDENTITY': 'TITLE_ADD_IDENTITY'));
|
||||
}, this);
|
||||
|
||||
this.button = ko.computed(function () {
|
||||
return Utils.i18n('POPUPS_IDENTITIES/' + (this.edit() ? 'BUTTON_UPDATE_IDENTITY': 'BUTTON_ADD_IDENTITY'));
|
||||
}, this);
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsIdentityViewModel', PopupsIdentityViewModel);
|
||||
|
||||
PopupsIdentityViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.id = '';
|
||||
this.edit(false);
|
||||
this.owner(false);
|
||||
|
||||
this.name('');
|
||||
this.email('');
|
||||
this.replyTo('');
|
||||
this.bcc('');
|
||||
|
||||
this.email.hasError(false);
|
||||
this.replyTo.hasError(false);
|
||||
this.bcc.hasError(false);
|
||||
|
||||
this.submitRequest(false);
|
||||
this.submitError('');
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {?IdentityModel} oIdentity
|
||||
*/
|
||||
PopupsIdentityViewModel.prototype.onShow = function (oIdentity)
|
||||
{
|
||||
this.clearPopup();
|
||||
|
||||
if (oIdentity)
|
||||
{
|
||||
this.edit(true);
|
||||
|
||||
this.id = oIdentity.id;
|
||||
this.name(oIdentity.name());
|
||||
this.email(oIdentity.email());
|
||||
this.replyTo(oIdentity.replyTo());
|
||||
this.bcc(oIdentity.bcc());
|
||||
|
||||
this.owner(this.id === RL.data().accountEmail());
|
||||
}
|
||||
};
|
||||
|
||||
PopupsIdentityViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
if (!this.owner())
|
||||
{
|
||||
this.email.focused(true);
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsKeyboardShortcutsHelpViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsKeyboardShortcutsHelp');
|
||||
|
||||
this.sDefaultKeyScope = Enums.KeyState.PopupKeyboardShortcutsHelp;
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsKeyboardShortcutsHelpViewModel', PopupsKeyboardShortcutsHelpViewModel);
|
||||
|
||||
PopupsKeyboardShortcutsHelpViewModel.prototype.onBuild = function (oDom)
|
||||
{
|
||||
key('tab, shift+tab, left, right', Enums.KeyState.PopupKeyboardShortcutsHelp, _.bind(function (event, handler) {
|
||||
if (event && handler)
|
||||
{
|
||||
var
|
||||
$tabs = oDom.find('.nav.nav-tabs > li'),
|
||||
bNext = handler && ('tab' === handler.shortcut || 'right' === handler.shortcut),
|
||||
iIndex = $tabs.index($tabs.filter('.active'))
|
||||
;
|
||||
|
||||
if (!bNext && iIndex > 0)
|
||||
{
|
||||
iIndex--;
|
||||
}
|
||||
else if (bNext && iIndex < $tabs.length - 1)
|
||||
{
|
||||
iIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
iIndex = bNext ? 0 : $tabs.length - 1;
|
||||
}
|
||||
|
||||
$tabs.eq(iIndex).find('a[data-toggle="tab"]').tab('show');
|
||||
return false;
|
||||
}
|
||||
}, this));
|
||||
};
|
||||
61
dev/ViewModels/Popups/PopupsLanguagesViewModel.js
Normal file
61
dev/ViewModels/Popups/PopupsLanguagesViewModel.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsLanguagesViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsLanguages');
|
||||
|
||||
this.exp = ko.observable(false);
|
||||
|
||||
this.languages = ko.computed(function () {
|
||||
return _.map(RL.data().languages(), function (sLanguage) {
|
||||
return {
|
||||
'key': sLanguage,
|
||||
'selected': ko.observable(false),
|
||||
'fullName': Utils.convertLangName(sLanguage)
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
RL.data().mainLanguage.subscribe(function () {
|
||||
this.resetMainLanguage();
|
||||
}, this);
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsLanguagesViewModel', PopupsLanguagesViewModel);
|
||||
|
||||
PopupsLanguagesViewModel.prototype.languageEnName = function (sLanguage)
|
||||
{
|
||||
return Utils.convertLangName(sLanguage, true);
|
||||
};
|
||||
|
||||
PopupsLanguagesViewModel.prototype.resetMainLanguage = function ()
|
||||
{
|
||||
var sCurrent = RL.data().mainLanguage();
|
||||
_.each(this.languages(), function (oItem) {
|
||||
oItem['selected'](oItem['key'] === sCurrent);
|
||||
});
|
||||
};
|
||||
|
||||
PopupsLanguagesViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.exp(true);
|
||||
|
||||
this.resetMainLanguage();
|
||||
};
|
||||
|
||||
PopupsLanguagesViewModel.prototype.onHide = function ()
|
||||
{
|
||||
this.exp(false);
|
||||
};
|
||||
|
||||
PopupsLanguagesViewModel.prototype.changeLanguage = function (sLang)
|
||||
{
|
||||
RL.data().mainLanguage(sLang);
|
||||
this.cancelCommand();
|
||||
};
|
||||
143
dev/ViewModels/Popups/PopupsPluginViewModel.js
Normal file
143
dev/ViewModels/Popups/PopupsPluginViewModel.js
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsPluginViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsPlugin');
|
||||
|
||||
var self = this;
|
||||
|
||||
this.onPluginSettingsUpdateResponse = _.bind(this.onPluginSettingsUpdateResponse, this);
|
||||
|
||||
this.saveError = ko.observable('');
|
||||
|
||||
this.name = ko.observable('');
|
||||
this.readme = ko.observable('');
|
||||
|
||||
this.configures = ko.observableArray([]);
|
||||
|
||||
this.hasReadme = ko.computed(function () {
|
||||
return '' !== this.readme();
|
||||
}, this);
|
||||
|
||||
this.hasConfiguration = ko.computed(function () {
|
||||
return 0 < this.configures().length;
|
||||
}, this);
|
||||
|
||||
this.readmePopoverConf = {
|
||||
'placement': 'top',
|
||||
'trigger': 'hover',
|
||||
'title': 'About',
|
||||
'content': function () {
|
||||
return self.readme();
|
||||
}
|
||||
};
|
||||
|
||||
this.saveCommand = Utils.createCommand(this, function () {
|
||||
|
||||
var oList = {};
|
||||
|
||||
oList['Name'] = this.name();
|
||||
|
||||
_.each(this.configures(), function (oItem) {
|
||||
|
||||
var mValue = oItem.value();
|
||||
if (false === mValue || true === mValue)
|
||||
{
|
||||
mValue = mValue ? '1' : '0';
|
||||
}
|
||||
|
||||
oList['_' + oItem['Name']] = mValue;
|
||||
|
||||
}, this);
|
||||
|
||||
this.saveError('');
|
||||
RL.remote().pluginSettingsUpdate(this.onPluginSettingsUpdateResponse, oList);
|
||||
|
||||
}, this.hasConfiguration);
|
||||
|
||||
this.bDisabeCloseOnEsc = true;
|
||||
this.sDefaultKeyScope = Enums.KeyState.All;
|
||||
|
||||
this.tryToClosePopup = _.debounce(_.bind(this.tryToClosePopup, this), 200);
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsPluginViewModel', PopupsPluginViewModel);
|
||||
|
||||
PopupsPluginViewModel.prototype.onPluginSettingsUpdateResponse = function (sResult, oData)
|
||||
{
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
this.cancelCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.saveError('');
|
||||
if (oData && oData.ErrorCode)
|
||||
{
|
||||
this.saveError(Utils.getNotification(oData.ErrorCode));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.saveError(Utils.getNotification(Enums.Notification.CantSavePluginSettings));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PopupsPluginViewModel.prototype.onShow = function (oPlugin)
|
||||
{
|
||||
this.name();
|
||||
this.readme();
|
||||
this.configures([]);
|
||||
|
||||
if (oPlugin)
|
||||
{
|
||||
this.name(oPlugin['Name']);
|
||||
this.readme(oPlugin['Readme']);
|
||||
|
||||
var aConfig = oPlugin['Config'];
|
||||
if (Utils.isNonEmptyArray(aConfig))
|
||||
{
|
||||
this.configures(_.map(aConfig, function (aItem) {
|
||||
return {
|
||||
'value': ko.observable(aItem[0]),
|
||||
'Name': aItem[1],
|
||||
'Type': aItem[2],
|
||||
'Label': aItem[3],
|
||||
'Default': aItem[4],
|
||||
'Desc': aItem[5]
|
||||
};
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PopupsPluginViewModel.prototype.tryToClosePopup = function ()
|
||||
{
|
||||
var self = this;
|
||||
if (!kn.isPopupVisible(PopupsAskViewModel))
|
||||
{
|
||||
kn.showScreenPopup(PopupsAskViewModel, [Utils.i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'), function () {
|
||||
if (self.modalVisibility())
|
||||
{
|
||||
Utils.delegateRun(self, 'cancelCommand');
|
||||
}
|
||||
}]);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsPluginViewModel.prototype.onBuild = function ()
|
||||
{
|
||||
key('esc', Enums.KeyState.All, _.bind(function () {
|
||||
if (this.modalVisibility())
|
||||
{
|
||||
this.tryToClosePopup();
|
||||
}
|
||||
return false;
|
||||
}, this));
|
||||
};
|
||||
55
dev/ViewModels/Popups/PopupsTwoFactorTestViewModel.js
Normal file
55
dev/ViewModels/Popups/PopupsTwoFactorTestViewModel.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsTwoFactorTestViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsTwoFactorTest');
|
||||
|
||||
var self = this;
|
||||
|
||||
this.code = ko.observable('');
|
||||
this.code.focused = ko.observable(false);
|
||||
this.code.status = ko.observable(null);
|
||||
|
||||
this.testing = ko.observable(false);
|
||||
|
||||
// commands
|
||||
this.testCode = Utils.createCommand(this, function () {
|
||||
|
||||
this.testing(true);
|
||||
RL.remote().testTwoFactor(function (sResult, oData) {
|
||||
|
||||
self.testing(false);
|
||||
self.code.status(Enums.StorageResultType.Success === sResult && oData && oData.Result ? true : false);
|
||||
|
||||
}, this.code());
|
||||
|
||||
}, function () {
|
||||
return '' !== this.code() && !this.testing();
|
||||
});
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsTwoFactorTestViewModel', PopupsTwoFactorTestViewModel);
|
||||
|
||||
PopupsTwoFactorTestViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.code('');
|
||||
this.code.focused(false);
|
||||
this.code.status(null);
|
||||
this.testing(false);
|
||||
};
|
||||
|
||||
PopupsTwoFactorTestViewModel.prototype.onShow = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
PopupsTwoFactorTestViewModel.prototype.onFocus = function ()
|
||||
{
|
||||
this.code.focused(true);
|
||||
};
|
||||
41
dev/ViewModels/Popups/PopupsViewOpenPgpKeyViewModel.js
Normal file
41
dev/ViewModels/Popups/PopupsViewOpenPgpKeyViewModel.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function PopupsViewOpenPgpKeyViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsViewOpenPgpKey');
|
||||
|
||||
this.key = ko.observable('');
|
||||
this.keyDom = ko.observable(null);
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsViewOpenPgpKeyViewModel', PopupsViewOpenPgpKeyViewModel);
|
||||
|
||||
PopupsViewOpenPgpKeyViewModel.prototype.clearPopup = function ()
|
||||
{
|
||||
this.key('');
|
||||
};
|
||||
|
||||
PopupsViewOpenPgpKeyViewModel.prototype.selectKey = function ()
|
||||
{
|
||||
var oEl = this.keyDom();
|
||||
if (oEl)
|
||||
{
|
||||
Utils.selectElement(oEl);
|
||||
}
|
||||
};
|
||||
|
||||
PopupsViewOpenPgpKeyViewModel.prototype.onShow = function (oOpenPgpKey)
|
||||
{
|
||||
this.clearPopup();
|
||||
|
||||
if (oOpenPgpKey)
|
||||
{
|
||||
this.key(oOpenPgpKey.armor);
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue