eslint (additional rules)

This commit is contained in:
RainLoop Team 2016-06-30 03:02:45 +03:00
parent 77a1d3f3df
commit 8e8a041032
150 changed files with 21911 additions and 23106 deletions

View file

@ -1,135 +1,128 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
var
_ = require('_'),
ko = require('ko'),
Remote = require('Remote/User/Ajax'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Remote = require('Remote/User/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function AccountPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsAccount');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.isNew = ko.observable(true);
/**
* @constructor
* @extends AbstractView
*/
function AccountPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsAccount');
this.email = ko.observable('');
this.password = ko.observable('');
this.isNew = ko.observable(true);
this.emailError = ko.observable(false);
this.passwordError = ko.observable(false);
this.email = ko.observable('');
this.password = ko.observable('');
this.email.subscribe(function() {
this.emailError(false);
}, this);
this.emailError = ko.observable(false);
this.passwordError = ko.observable(false);
this.password.subscribe(function() {
this.passwordError(false);
}, this);
this.email.subscribe(function () {
this.emailError(false);
}, this);
this.submitRequest = ko.observable(false);
this.submitError = ko.observable('');
this.submitErrorAdditional = ko.observable('');
this.password.subscribe(function () {
this.passwordError(false);
}, this);
this.emailFocus = ko.observable(false);
this.submitRequest = ko.observable(false);
this.submitError = ko.observable('');
this.submitErrorAdditional = ko.observable('');
this.addAccountCommand = Utils.createCommand(this, function() {
this.emailFocus = ko.observable(false);
this.emailError('' === Utils.trim(this.email()));
this.passwordError('' === Utils.trim(this.password()));
this.addAccountCommand = Utils.createCommand(this, function () {
if (this.emailError() || this.passwordError())
{
return false;
}
this.emailError('' === Utils.trim(this.email()));
this.passwordError('' === Utils.trim(this.password()));
this.submitRequest(true);
if (this.emailError() || this.passwordError())
Remote.accountSetup(_.bind(function(sResult, oData) {
this.submitRequest(false);
if (Enums.StorageResultType.Success === sResult && oData)
{
return false;
}
this.submitRequest(true);
Remote.accountSetup(_.bind(function (sResult, oData) {
this.submitRequest(false);
if (Enums.StorageResultType.Success === sResult && oData)
if (oData.Result)
{
if (oData.Result)
{
require('App/User').default.accountsAndIdentities();
this.cancelCommand();
}
else
{
this.submitError(oData.ErrorCode ? Translator.getNotification(oData.ErrorCode) :
Translator.getNotification(Enums.Notification.UnknownError));
if (oData.ErrorMessageAdditional)
{
this.submitErrorAdditional(oData.ErrorMessageAdditional);
}
}
require('App/User').default.accountsAndIdentities();
this.cancelCommand();
}
else
{
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
this.submitErrorAdditional('');
this.submitError(oData.ErrorCode ? Translator.getNotification(oData.ErrorCode) :
Translator.getNotification(Enums.Notification.UnknownError));
if (oData.ErrorMessageAdditional)
{
this.submitErrorAdditional(oData.ErrorMessageAdditional);
}
}
}
else
{
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
this.submitErrorAdditional('');
}
}, this), this.email(), this.password(), this.isNew());
}, this), this.email(), this.password(), this.isNew());
return true;
return true;
}, function () {
return !this.submitRequest();
});
}, function() {
return !this.submitRequest();
});
kn.constructorEnd(this);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Account', 'View/Popup/AddAccount', 'PopupsAddAccountViewModel'], AccountPopupView);
_.extend(AccountPopupView.prototype, AbstractView.prototype);
AccountPopupView.prototype.clearPopup = function()
{
this.isNew(true);
this.email('');
this.password('');
this.emailError(false);
this.passwordError(false);
this.submitRequest(false);
this.submitError('');
this.submitErrorAdditional('');
};
AccountPopupView.prototype.onShow = function(oAccount)
{
this.clearPopup();
if (oAccount && oAccount.canBeEdit())
{
this.isNew(false);
this.email(oAccount.email);
}
};
kn.extendAsViewModel(['View/Popup/Account', 'View/Popup/AddAccount', 'PopupsAddAccountViewModel'], AccountPopupView);
_.extend(AccountPopupView.prototype, AbstractView.prototype);
AccountPopupView.prototype.onShowWithDelay = function()
{
this.emailFocus(true);
};
AccountPopupView.prototype.clearPopup = function ()
{
this.isNew(true);
this.email('');
this.password('');
this.emailError(false);
this.passwordError(false);
this.submitRequest(false);
this.submitError('');
this.submitErrorAdditional('');
};
AccountPopupView.prototype.onShow = function (oAccount)
{
this.clearPopup();
if (oAccount && oAccount.canBeEdit())
{
this.isNew(false);
this.email(oAccount.email);
}
};
AccountPopupView.prototype.onShowWithDelay = function ()
{
this.emailFocus(true);
};
module.exports = AccountPopupView;
}());
module.exports = AccountPopupView;

View file

@ -1,151 +1,143 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Consts = require('Common/Consts'),
Translator = require('Common/Translator'),
var
_ = require('_'),
ko = require('ko'),
Settings = require('Storage/Settings'),
Remote = require('Remote/Admin/Ajax'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Consts = require('Common/Consts'),
Translator = require('Common/Translator'),
LicenseStore = require('Stores/Admin/License'),
Settings = require('Storage/Settings'),
Remote = require('Remote/Admin/Ajax'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
LicenseStore = require('Stores/Admin/License'),
/**
* @constructor
* @extends AbstractView
*/
function ActivatePopupView()
{
AbstractView.call(this, 'Popups', 'PopupsActivate');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
var self = this;
/**
* @constructor
* @extends AbstractView
*/
function ActivatePopupView()
{
AbstractView.call(this, 'Popups', 'PopupsActivate');
this.domain = ko.observable('');
this.key = ko.observable('');
this.key.focus = ko.observable(false);
this.activationSuccessed = ko.observable(false);
var self = this;
this.licenseTrigger = LicenseStore.licenseTrigger;
this.domain = ko.observable('');
this.key = ko.observable('');
this.key.focus = ko.observable(false);
this.activationSuccessed = ko.observable(false);
this.activateProcess = ko.observable(false);
this.activateText = ko.observable('');
this.activateText.isError = ko.observable(false);
this.licenseTrigger = LicenseStore.licenseTrigger;
this.htmlDescription = ko.computed(function() {
return Translator.i18n('POPUPS_ACTIVATE/HTML_DESC', {'DOMAIN': this.domain()});
}, this);
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.htmlDescription = ko.computed(function () {
return Translator.i18n('POPUPS_ACTIVATE/HTML_DESC', {'DOMAIN': this.domain()});
}, this);
this.activationSuccessed.subscribe(function(bValue) {
if (bValue)
{
this.licenseTrigger(!this.licenseTrigger());
}
}, this);
this.key.subscribe(function () {
this.activateText('');
this.activateText.isError(false);
}, this);
this.activateCommand = Utils.createCommand(this, function() {
this.activationSuccessed.subscribe(function (bValue) {
if (bValue)
{
this.licenseTrigger(!this.licenseTrigger());
}
}, this);
this.activateProcess(true);
if (this.validateSubscriptionKey())
{
Remote.licensingActivate(function(sResult, oData) {
this.activateCommand = Utils.createCommand(this, function () {
this.activateProcess(true);
if (this.validateSubscriptionKey())
{
Remote.licensingActivate(function (sResult, oData) {
self.activateProcess(false);
if (Enums.StorageResultType.Success === sResult && oData.Result)
self.activateProcess(false);
if (Enums.StorageResultType.Success === sResult && oData.Result)
{
if (true === oData.Result)
{
if (true === oData.Result)
{
self.activationSuccessed(true);
self.activateText(Translator.i18n('POPUPS_ACTIVATE/SUBS_KEY_ACTIVATED'));
self.activateText.isError(false);
}
else
{
self.activateText(oData.Result);
self.activateText.isError(true);
self.key.focus(true);
}
}
else if (oData.ErrorCode)
{
self.activateText(Translator.getNotification(oData.ErrorCode));
self.activateText.isError(true);
self.key.focus(true);
self.activationSuccessed(true);
self.activateText(Translator.i18n('POPUPS_ACTIVATE/SUBS_KEY_ACTIVATED'));
self.activateText.isError(false);
}
else
{
self.activateText(Translator.getNotification(Enums.Notification.UnknownError));
self.activateText(oData.Result);
self.activateText.isError(true);
self.key.focus(true);
}
}
else if (oData.ErrorCode)
{
self.activateText(Translator.getNotification(oData.ErrorCode));
self.activateText.isError(true);
self.key.focus(true);
}
else
{
self.activateText(Translator.getNotification(Enums.Notification.UnknownError));
self.activateText.isError(true);
self.key.focus(true);
}
}, this.domain(), this.key());
}
else
{
this.activateProcess(false);
this.activateText(Translator.i18n('POPUPS_ACTIVATE/ERROR_INVALID_SUBS_KEY'));
this.activateText.isError(true);
this.key.focus(true);
}
}, function () {
return !this.activateProcess() && '' !== this.domain() && '' !== this.key() && !this.activationSuccessed();
});
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Activate', 'PopupsActivateViewModel'], ActivatePopupView);
_.extend(ActivatePopupView.prototype, AbstractView.prototype);
ActivatePopupView.prototype.onShow = function (bTrial)
{
this.domain(Settings.settingsGet('AdminDomain'));
if (!this.activateProcess())
{
bTrial = Utils.isUnd(bTrial) ? false : !!bTrial;
this.key(bTrial ? Consts.RAINLOOP_TRIAL_KEY : '');
this.activateText('');
this.activateText.isError(false);
this.activationSuccessed(false);
}, this.domain(), this.key());
}
};
ActivatePopupView.prototype.onShowWithDelay = function ()
{
if (!this.activateProcess())
else
{
this.activateProcess(false);
this.activateText(Translator.i18n('POPUPS_ACTIVATE/ERROR_INVALID_SUBS_KEY'));
this.activateText.isError(true);
this.key.focus(true);
}
};
/**
* @return {boolean}
*/
ActivatePopupView.prototype.validateSubscriptionKey = function ()
}, function() {
return !this.activateProcess() && '' !== this.domain() && '' !== this.key() && !this.activationSuccessed();
});
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Activate', 'PopupsActivateViewModel'], ActivatePopupView);
_.extend(ActivatePopupView.prototype, AbstractView.prototype);
ActivatePopupView.prototype.onShow = function(bTrial)
{
this.domain(Settings.settingsGet('AdminDomain'));
if (!this.activateProcess())
{
var sValue = this.key();
return '' === sValue || Consts.RAINLOOP_TRIAL_KEY === sValue ||
!!/^RL[\d]+-[A-Z0-9\-]+Z$/.test(Utils.trim(sValue));
};
bTrial = Utils.isUnd(bTrial) ? false : !!bTrial;
module.exports = ActivatePopupView;
this.key(bTrial ? Consts.RAINLOOP_TRIAL_KEY : '');
this.activateText('');
this.activateText.isError(false);
this.activationSuccessed(false);
}
};
}());
ActivatePopupView.prototype.onShowWithDelay = function()
{
if (!this.activateProcess())
{
this.key.focus(true);
}
};
/**
* @returns {boolean}
*/
ActivatePopupView.prototype.validateSubscriptionKey = function()
{
var sValue = this.key();
return '' === sValue || Consts.RAINLOOP_TRIAL_KEY === sValue || !!(/^RL[\d]+-[A-Z0-9\-]+Z$/).test(Utils.trim(sValue));
};
module.exports = ActivatePopupView;

View file

@ -1,114 +1,106 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
PgpStore = require('Stores/User/Pgp'),
Utils = require('Common/Utils'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
PgpStore = require('Stores/User/Pgp'),
/**
* @constructor
* @extends AbstractView
*/
function AddOpenPgpKeyPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsAddOpenPgpKey');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.key = ko.observable('');
this.key.error = ko.observable(false);
this.key.focus = ko.observable(false);
/**
* @constructor
* @extends AbstractView
*/
function AddOpenPgpKeyPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsAddOpenPgpKey');
this.key.subscribe(function() {
this.key.error(false);
}, this);
this.key = ko.observable('');
this.key.error = ko.observable(false);
this.key.focus = ko.observable(false);
this.addOpenPgpKeyCommand = Utils.createCommand(this, function() {
this.key.subscribe(function () {
this.key.error(false);
}, this);
var
count = 30,
match = null,
key = Utils.trim(this.key()),
reg = /[\-]{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,
openpgpKeyring = PgpStore.openpgpKeyring,
done = false;
this.addOpenPgpKeyCommand = Utils.createCommand(this, function () {
if (/[\n]/.test(key))
{
key = key.replace(/[\r]+/g, '').replace(/[\n]{2,}/g, '\n\n');
}
var
count = 30,
match = null,
key = Utils.trim(this.key()),
reg = /[\-]{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,
openpgpKeyring = PgpStore.openpgpKeyring,
done = false
;
this.key.error('' === key);
if (/[\n]/.test(key))
if (!openpgpKeyring || this.key.error())
{
return false;
}
do
{
match = reg.exec(key);
if (match && 0 > count)
{
key = key.replace(/[\r]+/g, '').replace(/[\n]{2,}/g, '\n\n');
}
this.key.error('' === key);
if (!openpgpKeyring || this.key.error())
{
return false;
}
do
{
match = reg.exec(key);
if (match && 0 > count)
if (match[0] && match[1] && match[2] && match[1] === match[2])
{
if (match[0] && match[1] && match[2] && match[1] === match[2])
if ('PRIVATE' === match[1])
{
if ('PRIVATE' === match[1])
{
openpgpKeyring.privateKeys.importKey(match[0]);
}
else if ('PUBLIC' === match[1])
{
openpgpKeyring.publicKeys.importKey(match[0]);
}
openpgpKeyring.privateKeys.importKey(match[0]);
}
else if ('PUBLIC' === match[1])
{
openpgpKeyring.publicKeys.importKey(match[0]);
}
count--;
}
done = true;
count -= 1;
}
while (done);
openpgpKeyring.store();
done = true;
require('App/User').default.reloadOpenPgpKeys();
Utils.delegateRun(this, 'cancelCommand');
}
while (done);
return true;
});
openpgpKeyring.store();
kn.constructorEnd(this);
}
require('App/User').default.reloadOpenPgpKeys();
Utils.delegateRun(this, 'cancelCommand');
kn.extendAsViewModel(['View/Popup/AddOpenPgpKey', 'PopupsAddOpenPgpKeyViewModel'], AddOpenPgpKeyPopupView);
_.extend(AddOpenPgpKeyPopupView.prototype, AbstractView.prototype);
return true;
});
AddOpenPgpKeyPopupView.prototype.clearPopup = function ()
{
this.key('');
this.key.error(false);
};
kn.constructorEnd(this);
}
AddOpenPgpKeyPopupView.prototype.onShow = function ()
{
this.clearPopup();
};
kn.extendAsViewModel(['View/Popup/AddOpenPgpKey', 'PopupsAddOpenPgpKeyViewModel'], AddOpenPgpKeyPopupView);
_.extend(AddOpenPgpKeyPopupView.prototype, AbstractView.prototype);
AddOpenPgpKeyPopupView.prototype.onShowWithDelay = function ()
{
this.key.focus(true);
};
AddOpenPgpKeyPopupView.prototype.clearPopup = function()
{
this.key('');
this.key.error(false);
};
module.exports = AddOpenPgpKeyPopupView;
AddOpenPgpKeyPopupView.prototype.onShow = function()
{
this.clearPopup();
};
}());
AddOpenPgpKeyPopupView.prototype.onShowWithDelay = function()
{
this.key.focus(true);
};
module.exports = AddOpenPgpKeyPopupView;

View file

@ -1,195 +1,187 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
MessageStore = require('Stores/User/Message'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
/**
* @constructor
* @extends AbstractView
*/
function AdvancedSearchPopupView()
{
AbstractView.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)
{
MessageStore.mainMessageListSearch(sSearch);
}
this.cancelCommand();
});
this.selectedDates = ko.computed(function() {
Translator.trigger();
return [
{'id': -1, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_ALL')},
{'id': 3, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_3_DAYS')},
{'id': 7, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_7_DAYS')},
{'id': 30, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_MONTH')},
{'id': 90, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_3_MONTHS')},
{'id': 180, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_6_MONTHS')},
{'id': 365, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_YEAR')}
];
}, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/AdvancedSearch', 'PopupsAdvancedSearchViewModel'], AdvancedSearchPopupView);
_.extend(AdvancedSearchPopupView.prototype, AbstractView.prototype);
AdvancedSearchPopupView.prototype.parseSearchStringValue = function(search)
{
var
_ = require('_'),
ko = require('ko'),
self = this,
parts = (search || '').split(/[\s]+/g);
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
_.each(parts, function(part) {
switch (part)
{
case 'has:attachment':
self.hasAttachment(true);
break;
case 'is:unseen,flagged':
self.starred(true);
/* falls through */
case 'is:unseen':
self.unseen(true);
break;
// no default
}
});
};
MessageStore = require('Stores/User/Message'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
/**
* @constructor
* @extends AbstractView
*/
function AdvancedSearchPopupView()
AdvancedSearchPopupView.prototype.buildSearchStringValue = function(sValue)
{
if (-1 < sValue.indexOf(' '))
{
AbstractView.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)
{
MessageStore.mainMessageListSearch(sSearch);
}
this.cancelCommand();
});
this.selectedDates = ko.computed(function () {
Translator.trigger();
return [
{'id': -1, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_ALL')},
{'id': 3, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_3_DAYS')},
{'id': 7, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_7_DAYS')},
{'id': 30, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_MONTH')},
{'id': 90, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_3_MONTHS')},
{'id': 180, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_6_MONTHS')},
{'id': 365, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_YEAR')}
];
}, this);
kn.constructorEnd(this);
sValue = '"' + sValue + '"';
}
kn.extendAsViewModel(['View/Popup/AdvancedSearch', 'PopupsAdvancedSearchViewModel'], AdvancedSearchPopupView);
_.extend(AdvancedSearchPopupView.prototype, AbstractView.prototype);
return sValue;
};
AdvancedSearchPopupView.prototype.parseSearchStringValue = function (search)
AdvancedSearchPopupView.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)
{
var
self = this,
parts = (search || '').split(/[\s]+/g)
;
aResult.push('from:' + this.buildSearchStringValue(sFrom));
}
_.each(parts, function(part) {
switch (part)
{
case 'has:attachment':
self.hasAttachment(true);
break;
case 'is:unseen,flagged':
self.starred(true);
/* falls through */
case 'is:unseen':
self.unseen(true);
break;
}
});
};
AdvancedSearchPopupView.prototype.buildSearchStringValue = function (sValue)
if (sTo && '' !== sTo)
{
if (-1 < sValue.indexOf(' '))
{
sValue = '"' + sValue + '"';
}
aResult.push('to:' + this.buildSearchStringValue(sTo));
}
return sValue;
};
AdvancedSearchPopupView.prototype.buildSearchString = function ()
if (sSubject && '' !== sSubject)
{
var
aResult = [],
sFrom = Utils.trim(this.from()),
sTo = Utils.trim(this.to()),
sSubject = Utils.trim(this.subject()),
sText = Utils.trim(this.text()),
aIs = [],
aHas = []
;
aResult.push('subject:' + this.buildSearchStringValue(sSubject));
}
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:' + require('Common/Momentor').searchSubtractFormatDateHelper(this.selectedDateValue()) + '/');
}
if (sText && '' !== sText)
{
aResult.push('text:' + this.buildSearchStringValue(sText));
}
return Utils.trim(aResult.join(' '));
};
AdvancedSearchPopupView.prototype.clearPopup = function ()
if (this.hasAttachment())
{
this.from('');
this.to('');
this.subject('');
this.text('');
aHas.push('attachment');
}
this.selectedDateValue(-1);
this.hasAttachment(false);
this.starred(false);
this.unseen(false);
this.fromFocus(true);
};
AdvancedSearchPopupView.prototype.onShow = function (search)
if (this.unseen())
{
this.clearPopup();
this.parseSearchStringValue(search);
};
aIs.push('unseen');
}
AdvancedSearchPopupView.prototype.onShowWithDelay = function ()
if (this.starred())
{
this.fromFocus(true);
};
aIs.push('flagged');
}
module.exports = AdvancedSearchPopupView;
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:' + require('Common/Momentor').searchSubtractFormatDateHelper(this.selectedDateValue()) + '/');
}
if (sText && '' !== sText)
{
aResult.push('text:' + this.buildSearchStringValue(sText));
}
return Utils.trim(aResult.join(' '));
};
AdvancedSearchPopupView.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);
};
AdvancedSearchPopupView.prototype.onShow = function(search)
{
this.clearPopup();
this.parseSearchStringValue(search);
};
AdvancedSearchPopupView.prototype.onShowWithDelay = function()
{
this.fromFocus(true);
};
module.exports = AdvancedSearchPopupView;

View file

@ -1,139 +1,134 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
key = require('key'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
var
_ = require('_'),
ko = require('ko'),
key = require('key'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
/**
* @constructor
* @extends AbstractView
*/
function AskPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsAsk');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.askDesc = ko.observable('');
this.yesButton = ko.observable('');
this.noButton = ko.observable('');
/**
* @constructor
* @extends AbstractView
*/
function AskPopupView()
this.yesFocus = ko.observable(false);
this.noFocus = ko.observable(false);
this.fYesAction = null;
this.fNoAction = null;
this.bFocusYesOnShow = true;
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = Enums.KeyState.PopupAsk;
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Ask', 'PopupsAskViewModel'], AskPopupView);
_.extend(AskPopupView.prototype, AbstractView.prototype);
AskPopupView.prototype.clearPopup = function()
{
this.askDesc('');
this.yesButton(Translator.i18n('POPUPS_ASK/BUTTON_YES'));
this.noButton(Translator.i18n('POPUPS_ASK/BUTTON_NO'));
this.yesFocus(false);
this.noFocus(false);
this.fYesAction = null;
this.fNoAction = null;
};
AskPopupView.prototype.yesClick = function()
{
this.cancelCommand();
if (Utils.isFunc(this.fYesAction))
{
AbstractView.call(this, 'Popups', 'PopupsAsk');
this.fYesAction.call(null);
}
};
this.askDesc = ko.observable('');
this.yesButton = ko.observable('');
this.noButton = ko.observable('');
AskPopupView.prototype.noClick = function()
{
this.cancelCommand();
this.yesFocus = ko.observable(false);
this.noFocus = ko.observable(false);
if (Utils.isFunc(this.fNoAction))
{
this.fNoAction.call(null);
}
};
this.fYesAction = null;
this.fNoAction = null;
/**
* @param {string} sAskDesc
* @param {Function=} fYesFunc
* @param {Function=} fNoFunc
* @param {string=} sYesButton
* @param {string=} sNoButton
* @param {boolean=} bFocusYesOnShow
* @returns {void}
*/
AskPopupView.prototype.onShow = function(sAskDesc, fYesFunc, fNoFunc, sYesButton, sNoButton, bFocusYesOnShow)
{
this.clearPopup();
this.bFocusYesOnShow = true;
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = Enums.KeyState.PopupAsk;
this.fYesAction = fYesFunc || null;
this.fNoAction = fNoFunc || null;
kn.constructorEnd(this);
this.askDesc(sAskDesc || '');
if (sYesButton)
{
this.yesButton(sYesButton);
}
kn.extendAsViewModel(['View/Popup/Ask', 'PopupsAskViewModel'], AskPopupView);
_.extend(AskPopupView.prototype, AbstractView.prototype);
AskPopupView.prototype.clearPopup = function ()
if (sNoButton)
{
this.askDesc('');
this.yesButton(Translator.i18n('POPUPS_ASK/BUTTON_YES'));
this.noButton(Translator.i18n('POPUPS_ASK/BUTTON_NO'));
this.noButton(sNoButton);
}
this.yesFocus(false);
this.noFocus(false);
this.bFocusYesOnShow = Utils.isUnd(bFocusYesOnShow) ? true : !!bFocusYesOnShow;
};
this.fYesAction = null;
this.fNoAction = null;
};
AskPopupView.prototype.yesClick = function ()
AskPopupView.prototype.onShowWithDelay = function()
{
if (this.bFocusYesOnShow)
{
this.cancelCommand();
this.yesFocus(true);
}
};
if (Utils.isFunc(this.fYesAction))
AskPopupView.prototype.onBuild = function()
{
key('tab, shift+tab, right, left', Enums.KeyState.PopupAsk, _.bind(function() {
if (this.yesFocus())
{
this.fYesAction.call(null);
this.noFocus(true);
}
};
AskPopupView.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
* @param {boolean=} bFocusYesOnShow
*/
AskPopupView.prototype.onShow = function (sAskDesc, fYesFunc, fNoFunc, sYesButton, sNoButton, bFocusYesOnShow)
{
this.clearPopup();
this.fYesAction = fYesFunc || null;
this.fNoAction = fNoFunc || null;
this.askDesc(sAskDesc || '');
if (sYesButton)
{
this.yesButton(sYesButton);
}
if (sYesButton)
{
this.yesButton(sNoButton);
}
this.bFocusYesOnShow = Utils.isUnd(bFocusYesOnShow) ? true : !!bFocusYesOnShow;
};
AskPopupView.prototype.onShowWithDelay = function ()
{
if (this.bFocusYesOnShow)
else
{
this.yesFocus(true);
}
};
return false;
}, this));
AskPopupView.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));
};
key('esc', Enums.KeyState.PopupAsk, _.bind(function () {
this.noClick();
return false;
}, this));
};
module.exports = AskPopupView;
}());
module.exports = AskPopupView;

File diff suppressed because it is too large Load diff

View file

@ -1,491 +1,479 @@
(function () {
var
_ = require('_'),
$ = require('$'),
ko = require('ko'),
key = require('key'),
'use strict';
Utils = require('Common/Utils'),
Enums = require('Common/Enums'),
Translator = require('Common/Translator'),
var
_ = require('_'),
$ = require('$'),
ko = require('ko'),
key = require('key'),
PgpStore = require('Stores/User/Pgp'),
Utils = require('Common/Utils'),
Enums = require('Common/Enums'),
Translator = require('Common/Translator'),
EmailModel = require('Model/Email'),
PgpStore = require('Stores/User/Pgp'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
EmailModel = require('Model/Email'),
/**
* @constructor
* @extends AbstractView
*/
function ComposeOpenPgpPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsComposeOpenPgp');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
var self = this;
/**
* @constructor
* @extends AbstractView
*/
function ComposeOpenPgpPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsComposeOpenPgp');
this.publicKeysOptionsCaption = Translator.i18n('PGP_NOTIFICATIONS/ADD_A_PUBLICK_KEY');
this.privateKeysOptionsCaption = Translator.i18n('PGP_NOTIFICATIONS/SELECT_A_PRIVATE_KEY');
var self = this;
this.notification = ko.observable('');
this.publicKeysOptionsCaption = Translator.i18n('PGP_NOTIFICATIONS/ADD_A_PUBLICK_KEY');
this.privateKeysOptionsCaption = Translator.i18n('PGP_NOTIFICATIONS/SELECT_A_PRIVATE_KEY');
this.sign = ko.observable(false);
this.encrypt = ko.observable(false);
this.notification = ko.observable('');
this.password = ko.observable('');
this.password.focus = ko.observable(false);
this.buttonFocus = ko.observable(false);
this.sign = ko.observable(false);
this.encrypt = ko.observable(false);
this.text = ko.observable('');
this.selectedPrivateKey = ko.observable(null);
this.selectedPublicKey = ko.observable(null);
this.password = ko.observable('');
this.password.focus = ko.observable(false);
this.buttonFocus = ko.observable(false);
this.signKey = ko.observable(null);
this.encryptKeys = ko.observableArray([]);
this.text = ko.observable('');
this.selectedPrivateKey = ko.observable(null);
this.selectedPublicKey = ko.observable(null);
this.encryptKeysView = ko.computed(function() {
return _.compact(_.map(this.encryptKeys(), function(oKey) {
return oKey ? oKey.key : null;
}));
}, this);
this.signKey = ko.observable(null);
this.encryptKeys = ko.observableArray([]);
this.privateKeysOptions = ko.computed(function() {
return _.compact(_.flatten(_.map(PgpStore.openpgpkeysPrivate(), function(oKey, iIndex) {
return self.signKey() && self.signKey().key.id === oKey.id ? null : _.map(oKey.users, function(sUser) {
return {
'id': oKey.guid,
'name': '(' + oKey.id.substr(-8).toUpperCase() + ') ' + sUser,
'key': oKey,
'class': iIndex % 2 ? 'odd' : 'even'
};
});
}), true));
});
this.encryptKeysView = ko.computed(function () {
return _.compact(_.map(this.encryptKeys(), function (oKey) {
return oKey ? oKey.key : null;
}));
}, this);
this.publicKeysOptions = ko.computed(function() {
return _.compact(_.flatten(_.map(PgpStore.openpgpkeysPublic(), function(oKey, iIndex) {
return -1 < Utils.inArray(oKey, self.encryptKeysView()) ? null : _.map(oKey.users, function(sUser) {
return {
'id': oKey.guid,
'name': '(' + oKey.id.substr(-8).toUpperCase() + ') ' + sUser,
'key': oKey,
'class': iIndex % 2 ? 'odd' : 'even'
};
});
}), true));
});
this.privateKeysOptions = ko.computed(function () {
return _.compact(_.flatten(_.map(PgpStore.openpgpkeysPrivate(), function (oKey, iIndex) {
return self.signKey() && self.signKey().key.id === oKey.id ? null :
_.map(oKey.users, function (sUser) {
return {
'id': oKey.guid,
'name': '(' + oKey.id.substr(-8).toUpperCase() + ') ' + sUser,
'key': oKey,
'class': iIndex % 2 ? 'odd' : 'even'
};
});
}), true));
});
this.submitRequest = ko.observable(false);
this.publicKeysOptions = ko.computed(function () {
return _.compact(_.flatten(_.map(PgpStore.openpgpkeysPublic(), function (oKey, iIndex) {
return -1 < Utils.inArray(oKey, self.encryptKeysView()) ? null :
_.map(oKey.users, function (sUser) {
return {
'id': oKey.guid,
'name': '(' + oKey.id.substr(-8).toUpperCase() + ') ' + sUser,
'key': oKey,
'class': iIndex % 2 ? 'odd' : 'even'
};
});
}), true));
});
this.resultCallback = null;
this.submitRequest = ko.observable(false);
// commands
this.doCommand = Utils.createCommand(this, function() {
this.resultCallback = null;
var
bResult = true,
oPrivateKey = null,
aPrivateKeys = [],
aPublicKeys = [];
// commands
this.doCommand = Utils.createCommand(this, function () {
this.submitRequest(true);
var
bResult = true,
oPrivateKey = null,
aPrivateKeys = [],
aPublicKeys = []
;
this.submitRequest(true);
if (bResult && this.sign())
if (bResult && this.sign())
{
if (!this.signKey())
{
if (!this.signKey())
this.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND'));
bResult = false;
}
else if (!this.signKey().key)
{
this.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND_FOR', {
'EMAIL': this.signKey().email
}));
bResult = false;
}
if (bResult)
{
aPrivateKeys = this.signKey().key.getNativeKeys();
oPrivateKey = aPrivateKeys[0] || null;
try
{
if (oPrivateKey)
{
oPrivateKey.decrypt(Utils.pString(this.password()));
}
}
catch (e)
{
oPrivateKey = null;
}
if (!oPrivateKey)
{
this.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND'));
bResult = false;
}
else if (!this.signKey().key)
}
}
if (bResult && this.encrypt())
{
if (0 === this.encryptKeys().length)
{
this.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND'));
bResult = false;
}
else if (this.encryptKeys())
{
aPublicKeys = [];
_.each(this.encryptKeys(), function(oKey) {
if (oKey && oKey.key)
{
aPublicKeys = aPublicKeys.concat(_.compact(_.flatten(oKey.key.getNativeKeys())));
}
else if (oKey && oKey.email)
{
self.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND_FOR', {
'EMAIL': oKey.email
}));
bResult = false;
}
});
if (bResult && (0 === aPublicKeys.length || this.encryptKeys().length !== aPublicKeys.length))
{
this.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND_FOR', {
'EMAIL': this.signKey().email
bResult = false;
}
}
}
if (bResult && self.resultCallback)
{
_.delay(function() {
var oPromise = null;
try
{
if (oPrivateKey && 0 === aPublicKeys.length)
{
oPromise = PgpStore.openpgp.sign({
data: self.text(),
privateKeys: [oPrivateKey]
});
}
else if (oPrivateKey && 0 < aPublicKeys.length)
{
oPromise = PgpStore.openpgp.encrypt({
data: self.text(),
publicKeys: aPublicKeys,
privateKeys: [oPrivateKey]
});
}
else if (!oPrivateKey && 0 < aPublicKeys.length)
{
oPromise = PgpStore.openpgp.encrypt({
data: self.text(),
publicKeys: aPublicKeys
});
}
}
catch (e)
{
Utils.log(e);
self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
'ERROR': '' + e
}));
bResult = false;
}
if (bResult)
if (oPromise)
{
aPrivateKeys = this.signKey().key.getNativeKeys();
oPrivateKey = aPrivateKeys[0] || null;
try
{
if (oPrivateKey)
{
oPrivateKey.decrypt(Utils.pString(this.password()));
}
}
catch (e)
{
oPrivateKey = null;
}
oPromise.then(function(mData) {
if (!oPrivateKey)
{
this.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND'));
bResult = false;
}
}
}
self.resultCallback(mData.data);
self.cancelCommand();
if (bResult && this.encrypt())
{
if (0 === this.encryptKeys().length)
{
this.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND'));
bResult = false;
}
else if (this.encryptKeys())
{
aPublicKeys = [];
_.each(this.encryptKeys(), function (oKey) {
if (oKey && oKey.key)
{
aPublicKeys = aPublicKeys.concat(_.compact(_.flatten(oKey.key.getNativeKeys())));
}
else if (oKey && oKey.email)
{
self.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND_FOR', {
'EMAIL': oKey.email
}).then(null, function(e) {
self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
'ERROR': '' + e
}));
bResult = false;
}
});
if (bResult && (0 === aPublicKeys.length || this.encryptKeys().length !== aPublicKeys.length))
{
bResult = false;
}
}
}
if (bResult && self.resultCallback)
{
_.delay(function () {
var oPromise = null;
try
{
if (oPrivateKey && 0 === aPublicKeys.length)
{
oPromise = PgpStore.openpgp.sign({
data: self.text(),
privateKeys: [oPrivateKey]
});
}
else if (oPrivateKey && 0 < aPublicKeys.length)
{
oPromise = PgpStore.openpgp.encrypt({
data: self.text(),
publicKeys: aPublicKeys,
privateKeys: [oPrivateKey]
});
}
else if (!oPrivateKey && 0 < aPublicKeys.length)
{
oPromise = PgpStore.openpgp.encrypt({
data: self.text(),
publicKeys: aPublicKeys
});
}
});
}
catch (e)
{
Utils.log(e);
self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
'ERROR': '' + e
}));
}
}
if (oPromise)
{
try
{
oPromise.then(function (mData) {
self.resultCallback(mData.data);
self.cancelCommand();
}).then(null, function (e) {
self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
'ERROR': '' + e
}));
});
}
catch (e)
{
self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
'ERROR': '' + e
}));
}
}
self.submitRequest(false);
}, 10);
}
else
{
self.submitRequest(false);
}
return bResult;
}, function () {
return !this.submitRequest() && (this.sign() || this.encrypt());
});
this.selectCommand = Utils.createCommand(this, function () {
var
sKeyId = this.selectedPrivateKey(),
oKey = null,
oOption = sKeyId ? _.find(this.privateKeysOptions(), function (oItem) {
return oItem && sKeyId === oItem.id;
}) : null
;
if (oOption)
{
oKey = {
'empty': !oOption.key,
'selected': ko.observable(!!oOption.key),
'users': oOption.key.users,
'hash': oOption.key.id.substr(-8).toUpperCase(),
'key': oOption.key
};
this.signKey(oKey);
}
});
this.addCommand = Utils.createCommand(this, function () {
var
sKeyId = this.selectedPublicKey(),
aKeys = this.encryptKeys(),
oOption = sKeyId ? _.find(this.publicKeysOptions(), function (oItem) {
return oItem && sKeyId === oItem.id;
}) : null
;
if (oOption)
{
aKeys.push({
'empty': !oOption.key,
'selected': ko.observable(!!oOption.key),
'removable': ko.observable(!this.sign() || !this.signKey() || this.signKey().key.id !== oOption.key.id),
'users': oOption.key.users,
'hash': oOption.key.id.substr(-8).toUpperCase(),
'key': oOption.key
});
this.encryptKeys(aKeys);
}
});
this.updateCommand = Utils.createCommand(this, function () {
_.each(this.encryptKeys(), function (oKey) {
oKey.removable(!self.sign() || !self.signKey() || self.signKey().key.id !== oKey.key.id);
});
});
this.selectedPrivateKey.subscribe(function (sValue) {
if (sValue)
{
this.selectCommand();
this.updateCommand();
}
}, this);
this.selectedPublicKey.subscribe(function (sValue) {
if (sValue)
{
this.addCommand();
}
}, this);
this.sDefaultKeyScope = Enums.KeyState.PopupComposeOpenPGP;
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
this.addOptionClass = function (oDomOption, oItem) {
self.defautOptionsAfterRender(oDomOption, oItem);
if (oItem && !Utils.isUnd(oItem.class) && oDomOption)
{
$(oDomOption).addClass(oItem.class);
}
};
this.deletePublickKey = _.bind(this.deletePublickKey, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/ComposeOpenPgp', 'PopupsComposeOpenPgpViewModel'], ComposeOpenPgpPopupView);
_.extend(ComposeOpenPgpPopupView.prototype, AbstractView.prototype);
ComposeOpenPgpPopupView.prototype.deletePublickKey = function (oKey)
{
this.encryptKeys.remove(oKey);
};
ComposeOpenPgpPopupView.prototype.clearPopup = function ()
{
this.notification('');
this.sign(false);
this.encrypt(false);
this.password('');
this.password.focus(false);
this.buttonFocus(false);
this.signKey(null);
this.encryptKeys([]);
this.text('');
this.resultCallback = null;
};
ComposeOpenPgpPopupView.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));
};
ComposeOpenPgpPopupView.prototype.onHideWithDelay = function ()
{
this.clearPopup();
};
ComposeOpenPgpPopupView.prototype.onShowWithDelay = function ()
{
if (this.sign())
{
this.password.focus(true);
}, 10);
}
else
{
this.buttonFocus(true);
self.submitRequest(false);
}
};
ComposeOpenPgpPopupView.prototype.onShow = function (fCallback, sText, oIdentity, sTo, sCc, sBcc)
{
this.clearPopup();
return bResult;
}, function() {
return !this.submitRequest() && (this.sign() || this.encrypt());
});
this.selectCommand = Utils.createCommand(this, function() {
var
self = this,
aRec = [],
sEmail = '',
aKeys = [],
oEmail = new EmailModel()
;
sKeyId = this.selectedPrivateKey(),
oKey = null,
oOption = sKeyId ? _.find(this.privateKeysOptions(), function(oItem) {
return oItem && sKeyId === oItem.id;
}) : null;
this.resultCallback = fCallback;
if ('' !== sTo)
if (oOption)
{
aRec.push(sTo);
}
oKey = {
'empty': !oOption.key,
'selected': ko.observable(!!oOption.key),
'users': oOption.key.users,
'hash': oOption.key.id.substr(-8).toUpperCase(),
'key': oOption.key
};
if ('' !== sCc)
this.signKey(oKey);
}
});
this.addCommand = Utils.createCommand(this, function() {
var
sKeyId = this.selectedPublicKey(),
aKeys = this.encryptKeys(),
oOption = sKeyId ? _.find(this.publicKeysOptions(), function(oItem) {
return oItem && sKeyId === oItem.id;
}) : null;
if (oOption)
{
aRec.push(sCc);
}
aKeys.push({
'empty': !oOption.key,
'selected': ko.observable(!!oOption.key),
'removable': ko.observable(!this.sign() || !this.signKey() || this.signKey().key.id !== oOption.key.id),
'users': oOption.key.users,
'hash': oOption.key.id.substr(-8).toUpperCase(),
'key': oOption.key
});
if ('' !== sBcc)
this.encryptKeys(aKeys);
}
});
this.updateCommand = Utils.createCommand(this, function() {
_.each(this.encryptKeys(), function(oKey) {
oKey.removable(!self.sign() || !self.signKey() || self.signKey().key.id !== oKey.key.id);
});
});
this.selectedPrivateKey.subscribe(function(sValue) {
if (sValue)
{
aRec.push(sBcc);
this.selectCommand();
this.updateCommand();
}
}, this);
aRec = aRec.join(', ').split(',');
aRec = _.compact(_.map(aRec, function (sValue) {
oEmail.clear();
oEmail.mailsoParse(Utils.trim(sValue));
return '' === oEmail.email ? false : oEmail.email;
}));
if (oIdentity && oIdentity.email())
this.selectedPublicKey.subscribe(function(sValue) {
if (sValue)
{
sEmail = oIdentity.email();
aRec.unshift(sEmail);
aKeys = PgpStore.findAllPrivateKeysByEmailNotNative(sEmail);
if (aKeys && aKeys[0])
{
this.signKey({
'users': aKeys[0].users || [sEmail],
'hash': aKeys[0].id.substr(-8).toUpperCase(),
'key': aKeys[0]
});
}
this.addCommand();
}
}, this);
if (this.signKey())
this.sDefaultKeyScope = Enums.KeyState.PopupComposeOpenPGP;
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
this.addOptionClass = function(oDomOption, oItem) {
self.defautOptionsAfterRender(oDomOption, oItem);
if (oItem && !Utils.isUnd(oItem.class) && oDomOption)
{
this.sign(true);
$(oDomOption).addClass(oItem.class);
}
if (aRec && 0 < aRec.length)
{
this.encryptKeys(_.uniq(_.compact(_.flatten(_.map(aRec, function (sRecEmail) {
var keys = PgpStore.findAllPublicKeysByEmailNotNative(sRecEmail);
return keys ? _.map(keys, function (oKey) {
return {
'empty': !oKey,
'selected': ko.observable(!!oKey),
'removable': ko.observable(!self.sign() || !self.signKey() || self.signKey().key.id !== oKey.id),
'users': oKey ? (oKey.users || [sRecEmail]) : [sRecEmail],
'hash': oKey ? oKey.id.substr(-8).toUpperCase() : '',
'key': oKey
};
}) : [];
}), true)), function (oEncryptKey) {
return oEncryptKey.hash;
}));
if (0 < this.encryptKeys().length)
{
this.encrypt(true);
}
}
this.text(sText);
};
module.exports = ComposeOpenPgpPopupView;
this.deletePublickKey = _.bind(this.deletePublickKey, this);
}());
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/ComposeOpenPgp', 'PopupsComposeOpenPgpViewModel'], ComposeOpenPgpPopupView);
_.extend(ComposeOpenPgpPopupView.prototype, AbstractView.prototype);
ComposeOpenPgpPopupView.prototype.deletePublickKey = function(oKey)
{
this.encryptKeys.remove(oKey);
};
ComposeOpenPgpPopupView.prototype.clearPopup = function()
{
this.notification('');
this.sign(false);
this.encrypt(false);
this.password('');
this.password.focus(false);
this.buttonFocus(false);
this.signKey(null);
this.encryptKeys([]);
this.text('');
this.resultCallback = null;
};
ComposeOpenPgpPopupView.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;
// no default
}
return false;
}, this));
};
ComposeOpenPgpPopupView.prototype.onHideWithDelay = function()
{
this.clearPopup();
};
ComposeOpenPgpPopupView.prototype.onShowWithDelay = function()
{
if (this.sign())
{
this.password.focus(true);
}
else
{
this.buttonFocus(true);
}
};
ComposeOpenPgpPopupView.prototype.onShow = function(fCallback, sText, oIdentity, sTo, sCc, sBcc)
{
this.clearPopup();
var
self = this,
aRec = [],
sEmail = '',
aKeys = [],
oEmail = new EmailModel();
this.resultCallback = fCallback;
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;
}));
if (oIdentity && oIdentity.email())
{
sEmail = oIdentity.email();
aRec.unshift(sEmail);
aKeys = PgpStore.findAllPrivateKeysByEmailNotNative(sEmail);
if (aKeys && aKeys[0])
{
this.signKey({
'users': aKeys[0].users || [sEmail],
'hash': aKeys[0].id.substr(-8).toUpperCase(),
'key': aKeys[0]
});
}
}
if (this.signKey())
{
this.sign(true);
}
if (aRec && 0 < aRec.length)
{
this.encryptKeys(_.uniq(_.compact(_.flatten(_.map(aRec, function(sRecEmail) {
var keys = PgpStore.findAllPublicKeysByEmailNotNative(sRecEmail);
return keys ? _.map(keys, function(oKey) {
return {
'empty': !oKey,
'selected': ko.observable(!!oKey),
'removable': ko.observable(!self.sign() || !self.signKey() || self.signKey().key.id !== oKey.id),
'users': oKey ? (oKey.users || [sRecEmail]) : [sRecEmail],
'hash': oKey ? oKey.id.substr(-8).toUpperCase() : '',
'key': oKey
};
}) : [];
}), true)), function(oEncryptKey) {
return oEncryptKey.hash;
}));
if (0 < this.encryptKeys().length)
{
this.encrypt(true);
}
}
this.text(sText);
};
module.exports = ComposeOpenPgpPopupView;

File diff suppressed because it is too large Load diff

View file

@ -1,495 +1,486 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
Translator = require('Common/Translator'),
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
CapaAdminStore = require('Stores/Admin/Capa'),
Translator = require('Common/Translator'),
Remote = require('Remote/Admin/Ajax'),
CapaAdminStore = require('Stores/Admin/Capa'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Remote = require('Remote/Admin/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function DomainPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsDomain');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.edit = ko.observable(false);
this.saving = ko.observable(false);
this.savingError = ko.observable('');
this.page = ko.observable('main');
this.sieveSettings = ko.observable(false);
/**
* @constructor
* @extends AbstractView
*/
function DomainPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsDomain');
this.testing = ko.observable(false);
this.testingDone = ko.observable(false);
this.testingImapError = ko.observable(false);
this.testingSieveError = ko.observable(false);
this.testingSmtpError = ko.observable(false);
this.testingImapErrorDesc = ko.observable('');
this.testingSieveErrorDesc = ko.observable('');
this.testingSmtpErrorDesc = ko.observable('');
this.edit = ko.observable(false);
this.saving = ko.observable(false);
this.savingError = ko.observable('');
this.page = ko.observable('main');
this.sieveSettings = ko.observable(false);
this.testing = ko.observable(false);
this.testingDone = ko.observable(false);
this.testingImapError = ko.observable(false);
this.testingSieveError = ko.observable(false);
this.testingSmtpError = ko.observable(false);
this.testingImapErrorDesc = ko.observable('');
this.testingSieveErrorDesc = ko.observable('');
this.testingSmtpErrorDesc = ko.observable('');
this.testingImapError.subscribe(function (bValue) {
if (!bValue)
{
this.testingImapErrorDesc('');
}
}, this);
this.testingSieveError.subscribe(function (bValue) {
if (!bValue)
{
this.testingSieveErrorDesc('');
}
}, this);
this.testingSmtpError.subscribe(function (bValue) {
if (!bValue)
{
this.testingSmtpErrorDesc('');
}
}, this);
this.imapServerFocus = ko.observable(false);
this.sieveServerFocus = 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.IMAP_DEFAULT_PORT);
this.imapSecure = ko.observable(Enums.ServerSecure.None);
this.imapShortLogin = ko.observable(false);
this.useSieve = ko.observable(false);
this.sieveAllowRaw = ko.observable(false);
this.sieveServer = ko.observable('');
this.sievePort = ko.observable('' + Consts.SIEVE_DEFAULT_PORT);
this.sieveSecure = ko.observable(Enums.ServerSecure.None);
this.smtpServer = ko.observable('');
this.smtpPort = ko.observable('' + Consts.SMTP_DEFAULT_PORT);
this.smtpSecure = ko.observable(Enums.ServerSecure.None);
this.smtpShortLogin = ko.observable(false);
this.smtpAuth = ko.observable(true);
this.smtpPhpMail = ko.observable(false);
this.whiteList = ko.observable('');
this.aliasName = ko.observable('');
this.enableSmartPorts = ko.observable(false);
this.allowSieve = ko.computed(function () {
return CapaAdminStore.filters() && CapaAdminStore.sieve();
}, this);
this.headerText = ko.computed(function () {
var
sName = this.name(),
sAliasName = this.aliasName(),
sResult = ''
;
if (this.edit())
{
sResult = Translator.i18n('POPUPS_DOMAIN/TITLE_EDIT_DOMAIN', {'NAME': sName});
if (sAliasName)
{
sResult += ' ← ' + sAliasName;
}
}
else
{
sResult = ('' === sName ? Translator.i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN') :
Translator.i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN_WITH_NAME', {'NAME': sName}))
;
}
return sResult;
}, this);
this.domainDesc = ko.computed(function () {
var sName = this.name();
return !this.edit() && sName ? Translator.i18n('POPUPS_DOMAIN/NEW_DOMAIN_DESC', {'NAME': '*@' + sName}) : '';
}, this);
this.domainIsComputed = ko.computed(function () {
var
bPhpMail = this.smtpPhpMail(),
bAllowSieve = this.allowSieve(),
bUseSieve = this.useSieve()
;
return '' !== this.name() &&
'' !== this.imapServer() &&
'' !== this.imapPort() &&
(bAllowSieve && bUseSieve ? ('' !== this.sieveServer() && '' !== this.sievePort()) : true) &&
(('' !== this.smtpServer() && '' !== this.smtpPort()) || bPhpMail);
}, 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);
Remote.createOrUpdateDomain(
_.bind(this.onDomainCreateOrSaveResponse, this),
!this.edit(),
this.name(),
this.imapServer(),
Utils.pInt(this.imapPort()),
this.imapSecure(),
this.imapShortLogin(),
this.useSieve(),
this.sieveAllowRaw(),
this.sieveServer(),
Utils.pInt(this.sievePort()),
this.sieveSecure(),
this.smtpServer(),
Utils.pInt(this.smtpPort()),
this.smtpSecure(),
this.smtpShortLogin(),
this.smtpAuth(),
this.smtpPhpMail(),
this.whiteList()
);
}, this.canBeSaved);
this.testConnectionCommand = Utils.createCommand(this, function () {
this.page('main');
this.testingDone(false);
this.testingImapError(false);
this.testingSieveError(false);
this.testingSmtpError(false);
this.testing(true);
Remote.testConnectionForDomain(
_.bind(this.onTestConnectionResponse, this),
this.name(),
this.imapServer(),
Utils.pInt(this.imapPort()),
this.imapSecure(),
this.useSieve(),
this.sieveServer(),
Utils.pInt(this.sievePort()),
this.sieveSecure(),
this.smtpServer(),
Utils.pInt(this.smtpPort()),
this.smtpSecure(),
this.smtpAuth(),
this.smtpPhpMail()
);
}, this.canBeTested);
this.whiteListCommand = Utils.createCommand(this, function () {
this.page('white-list');
});
this.backCommand = Utils.createCommand(this, function () {
this.page('main');
});
this.sieveCommand = Utils.createCommand(this, function () {
this.sieveSettings(!this.sieveSettings());
this.clearTesting();
});
this.page.subscribe(function () {
this.sieveSettings(false);
}, this);
// smart form improvements
this.imapServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.name() && '' === this.imapServer())
{
this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
}
}, this);
this.sieveServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.imapServer() && '' === this.sieveServer())
{
this.sieveServer(this.imapServer());
}
}, 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) {
if (this.enableSmartPorts())
{
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) {
if (this.enableSmartPorts())
{
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);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Domain', 'PopupsDomainViewModel'], DomainPopupView);
_.extend(DomainPopupView.prototype, AbstractView.prototype);
DomainPopupView.prototype.onTestConnectionResponse = function (sResult, oData)
{
this.testing(false);
if (Enums.StorageResultType.Success === sResult && oData.Result)
this.testingImapError.subscribe(function(bValue) {
if (!bValue)
{
var
bImap = false,
bSieve = false
;
this.testingImapErrorDesc('');
}
}, this);
this.testingDone(true);
this.testingImapError(true !== oData.Result.Imap);
this.testingSieveError(true !== oData.Result.Sieve);
this.testingSmtpError(true !== oData.Result.Smtp);
this.testingSieveError.subscribe(function(bValue) {
if (!bValue)
{
this.testingSieveErrorDesc('');
}
}, this);
if (this.testingImapError() && oData.Result.Imap)
{
bImap = true;
this.testingImapErrorDesc('');
this.testingImapErrorDesc(oData.Result.Imap);
}
this.testingSmtpError.subscribe(function(bValue) {
if (!bValue)
{
this.testingSmtpErrorDesc('');
}
}, this);
if (this.testingSieveError() && oData.Result.Sieve)
{
bSieve = true;
this.testingSieveErrorDesc('');
this.testingSieveErrorDesc(oData.Result.Sieve);
}
this.imapServerFocus = ko.observable(false);
this.sieveServerFocus = ko.observable(false);
this.smtpServerFocus = ko.observable(false);
if (this.testingSmtpError() && oData.Result.Smtp)
{
this.testingSmtpErrorDesc('');
this.testingSmtpErrorDesc(oData.Result.Smtp);
}
this.name = ko.observable('');
this.name.focused = ko.observable(false);
if (this.sieveSettings())
this.imapServer = ko.observable('');
this.imapPort = ko.observable('' + Consts.IMAP_DEFAULT_PORT);
this.imapSecure = ko.observable(Enums.ServerSecure.None);
this.imapShortLogin = ko.observable(false);
this.useSieve = ko.observable(false);
this.sieveAllowRaw = ko.observable(false);
this.sieveServer = ko.observable('');
this.sievePort = ko.observable('' + Consts.SIEVE_DEFAULT_PORT);
this.sieveSecure = ko.observable(Enums.ServerSecure.None);
this.smtpServer = ko.observable('');
this.smtpPort = ko.observable('' + Consts.SMTP_DEFAULT_PORT);
this.smtpSecure = ko.observable(Enums.ServerSecure.None);
this.smtpShortLogin = ko.observable(false);
this.smtpAuth = ko.observable(true);
this.smtpPhpMail = ko.observable(false);
this.whiteList = ko.observable('');
this.aliasName = ko.observable('');
this.enableSmartPorts = ko.observable(false);
this.allowSieve = ko.computed(function() {
return CapaAdminStore.filters() && CapaAdminStore.sieve();
}, this);
this.headerText = ko.computed(function() {
var
sName = this.name(),
sAliasName = this.aliasName(),
sResult = '';
if (this.edit())
{
sResult = Translator.i18n('POPUPS_DOMAIN/TITLE_EDIT_DOMAIN', {'NAME': sName});
if (sAliasName)
{
if (!bSieve && bImap)
{
this.sieveSettings(false);
}
}
else
{
if (bSieve && !bImap)
{
this.sieveSettings(true);
}
sResult += ' ← ' + sAliasName;
}
}
else
{
this.testingImapError(true);
this.testingSieveError(true);
this.testingSmtpError(true);
this.sieveSettings(false);
sResult = ('' === sName ? Translator.i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN') :
Translator.i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN_WITH_NAME', {'NAME': sName}));
}
};
DomainPopupView.prototype.onDomainCreateOrSaveResponse = function (sResult, oData)
{
this.saving(false);
if (Enums.StorageResultType.Success === sResult && oData)
{
if (oData.Result)
{
require('App/Admin').default.reloadDomainList();
this.closeCommand();
}
else if (Enums.Notification.DomainAlreadyExists === oData.ErrorCode)
{
this.savingError(Translator.i18n('ERRORS/DOMAIN_ALREADY_EXISTS'));
}
}
else
{
this.savingError(Translator.i18n('ERRORS/UNKNOWN_ERROR'));
}
};
return sResult;
}, this);
this.domainDesc = ko.computed(function() {
var sName = this.name();
return !this.edit() && sName ? Translator.i18n('POPUPS_DOMAIN/NEW_DOMAIN_DESC', {'NAME': '*@' + sName}) : '';
}, this);
this.domainIsComputed = ko.computed(function() {
var
bPhpMail = this.smtpPhpMail(),
bAllowSieve = this.allowSieve(),
bUseSieve = this.useSieve();
return '' !== this.name() &&
'' !== this.imapServer() &&
'' !== this.imapPort() &&
(bAllowSieve && bUseSieve ? ('' !== this.sieveServer() && '' !== this.sievePort()) : true) &&
(('' !== this.smtpServer() && '' !== this.smtpPort()) || bPhpMail);
}, 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);
Remote.createOrUpdateDomain(
_.bind(this.onDomainCreateOrSaveResponse, this),
!this.edit(),
this.name(),
this.imapServer(),
Utils.pInt(this.imapPort()),
this.imapSecure(),
this.imapShortLogin(),
this.useSieve(),
this.sieveAllowRaw(),
this.sieveServer(),
Utils.pInt(this.sievePort()),
this.sieveSecure(),
this.smtpServer(),
Utils.pInt(this.smtpPort()),
this.smtpSecure(),
this.smtpShortLogin(),
this.smtpAuth(),
this.smtpPhpMail(),
this.whiteList()
);
}, this.canBeSaved);
this.testConnectionCommand = Utils.createCommand(this, function() {
this.page('main');
DomainPopupView.prototype.clearTesting = function ()
{
this.testing(false);
this.testingDone(false);
this.testingImapError(false);
this.testingSieveError(false);
this.testingSmtpError(false);
};
this.testing(true);
DomainPopupView.prototype.onHide = function ()
{
Remote.testConnectionForDomain(
_.bind(this.onTestConnectionResponse, this),
this.name(),
this.imapServer(),
Utils.pInt(this.imapPort()),
this.imapSecure(),
this.useSieve(),
this.sieveServer(),
Utils.pInt(this.sievePort()),
this.sieveSecure(),
this.smtpServer(),
Utils.pInt(this.smtpPort()),
this.smtpSecure(),
this.smtpAuth(),
this.smtpPhpMail()
);
}, this.canBeTested);
this.whiteListCommand = Utils.createCommand(this, function() {
this.page('white-list');
});
this.backCommand = Utils.createCommand(this, function() {
this.page('main');
this.sieveSettings(false);
};
DomainPopupView.prototype.onShow = function (oDomain)
{
this.saving(false);
this.page('main');
this.sieveSettings(false);
});
this.sieveCommand = Utils.createCommand(this, function() {
this.sieveSettings(!this.sieveSettings());
this.clearTesting();
});
this.clearForm();
if (oDomain)
{
this.enableSmartPorts(false);
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.useSieve(!!oDomain.UseSieve);
this.sieveAllowRaw(!!oDomain.SieveAllowRaw);
this.sieveServer(Utils.trim(oDomain.SieveHost));
this.sievePort('' + Utils.pInt(oDomain.SievePort));
this.sieveSecure(Utils.trim(oDomain.SieveSecure));
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.smtpPhpMail(!!oDomain.OutUsePhpMail);
this.whiteList(Utils.trim(oDomain.WhiteList));
this.aliasName(Utils.trim(oDomain.AliasName));
this.enableSmartPorts(true);
}
};
DomainPopupView.prototype.onShowWithDelay = function ()
{
if ('' === this.name() && !Globals.bMobile)
{
this.name.focused(true);
}
};
DomainPopupView.prototype.clearForm = function ()
{
this.edit(false);
this.page('main');
this.page.subscribe(function() {
this.sieveSettings(false);
}, this);
// smart form improvements
this.imapServerFocus.subscribe(function(bValue) {
if (bValue && '' !== this.name() && '' === this.imapServer())
{
this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
}
}, this);
this.sieveServerFocus.subscribe(function(bValue) {
if (bValue && '' !== this.imapServer() && '' === this.sieveServer())
{
this.sieveServer(this.imapServer());
}
}, 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) {
if (this.enableSmartPorts())
{
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;
// no default
}
}
}, this);
this.smtpSecure.subscribe(function(sValue) {
if (this.enableSmartPorts())
{
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;
// no default
}
}
}, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Domain', 'PopupsDomainViewModel'], DomainPopupView);
_.extend(DomainPopupView.prototype, AbstractView.prototype);
DomainPopupView.prototype.onTestConnectionResponse = function(sResult, oData)
{
this.testing(false);
if (Enums.StorageResultType.Success === sResult && oData.Result)
{
var
bImap = false,
bSieve = false;
this.testingDone(true);
this.testingImapError(true !== oData.Result.Imap);
this.testingSieveError(true !== oData.Result.Sieve);
this.testingSmtpError(true !== oData.Result.Smtp);
if (this.testingImapError() && oData.Result.Imap)
{
bImap = true;
this.testingImapErrorDesc('');
this.testingImapErrorDesc(oData.Result.Imap);
}
if (this.testingSieveError() && oData.Result.Sieve)
{
bSieve = true;
this.testingSieveErrorDesc('');
this.testingSieveErrorDesc(oData.Result.Sieve);
}
if (this.testingSmtpError() && oData.Result.Smtp)
{
this.testingSmtpErrorDesc('');
this.testingSmtpErrorDesc(oData.Result.Smtp);
}
if (this.sieveSettings())
{
if (!bSieve && bImap)
{
this.sieveSettings(false);
}
}
else
{
if (bSieve && !bImap)
{
this.sieveSettings(true);
}
}
}
else
{
this.testingImapError(true);
this.testingSieveError(true);
this.testingSmtpError(true);
this.sieveSettings(false);
}
};
DomainPopupView.prototype.onDomainCreateOrSaveResponse = function(sResult, oData)
{
this.saving(false);
if (Enums.StorageResultType.Success === sResult && oData)
{
if (oData.Result)
{
require('App/Admin').default.reloadDomainList();
this.closeCommand();
}
else if (Enums.Notification.DomainAlreadyExists === oData.ErrorCode)
{
this.savingError(Translator.i18n('ERRORS/DOMAIN_ALREADY_EXISTS'));
}
}
else
{
this.savingError(Translator.i18n('ERRORS/UNKNOWN_ERROR'));
}
};
DomainPopupView.prototype.clearTesting = function()
{
this.testing(false);
this.testingDone(false);
this.testingImapError(false);
this.testingSieveError(false);
this.testingSmtpError(false);
};
DomainPopupView.prototype.onHide = function()
{
this.page('main');
this.sieveSettings(false);
};
DomainPopupView.prototype.onShow = function(oDomain)
{
this.saving(false);
this.page('main');
this.sieveSettings(false);
this.clearTesting();
this.clearForm();
if (oDomain)
{
this.enableSmartPorts(false);
this.savingError('');
this.edit(true);
this.name('');
this.name.focused(false);
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.useSieve(!!oDomain.UseSieve);
this.sieveAllowRaw(!!oDomain.SieveAllowRaw);
this.sieveServer(Utils.trim(oDomain.SieveHost));
this.sievePort('' + Utils.pInt(oDomain.SievePort));
this.sieveSecure(Utils.trim(oDomain.SieveSecure));
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.smtpPhpMail(!!oDomain.OutUsePhpMail);
this.whiteList(Utils.trim(oDomain.WhiteList));
this.aliasName(Utils.trim(oDomain.AliasName));
this.imapServer('');
this.imapPort('' + Consts.IMAP_DEFAULT_PORT);
this.imapSecure(Enums.ServerSecure.None);
this.imapShortLogin(false);
this.useSieve(false);
this.sieveAllowRaw(false);
this.sieveServer('');
this.sievePort('' + Consts.SIEVE_DEFAULT_PORT);
this.sieveSecure(Enums.ServerSecure.None);
this.smtpServer('');
this.smtpPort('' + Consts.SMTP_DEFAULT_PORT);
this.smtpSecure(Enums.ServerSecure.None);
this.smtpShortLogin(false);
this.smtpAuth(true);
this.smtpPhpMail(false);
this.whiteList('');
this.aliasName('');
this.enableSmartPorts(true);
};
}
};
module.exports = DomainPopupView;
DomainPopupView.prototype.onShowWithDelay = function()
{
if ('' === this.name() && !Globals.bMobile)
{
this.name.focused(true);
}
};
}());
DomainPopupView.prototype.clearForm = function()
{
this.edit(false);
this.page('main');
this.sieveSettings(false);
this.enableSmartPorts(false);
this.savingError('');
this.name('');
this.name.focused(false);
this.imapServer('');
this.imapPort('' + Consts.IMAP_DEFAULT_PORT);
this.imapSecure(Enums.ServerSecure.None);
this.imapShortLogin(false);
this.useSieve(false);
this.sieveAllowRaw(false);
this.sieveServer('');
this.sievePort('' + Consts.SIEVE_DEFAULT_PORT);
this.sieveSecure(Enums.ServerSecure.None);
this.smtpServer('');
this.smtpPort('' + Consts.SMTP_DEFAULT_PORT);
this.smtpSecure(Enums.ServerSecure.None);
this.smtpShortLogin(false);
this.smtpAuth(true);
this.smtpPhpMail(false);
this.whiteList('');
this.aliasName('');
this.enableSmartPorts(true);
};
module.exports = DomainPopupView;

View file

@ -1,117 +1,110 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
Translator = require('Common/Translator'),
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
DomainStore = require('Stores/Admin/Domain'),
Translator = require('Common/Translator'),
Remote = require('Remote/Admin/Ajax'),
DomainStore = require('Stores/Admin/Domain'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Remote = require('Remote/Admin/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function DomainAliasPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsDomainAlias');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.saving = ko.observable(false);
this.savingError = ko.observable('');
/**
* @constructor
* @extends AbstractView
*/
function DomainAliasPopupView()
this.name = ko.observable('');
this.name.focused = ko.observable(false);
this.alias = ko.observable('');
this.domains = DomainStore.domainsWithoutAliases;
this.domainsOptions = ko.computed(function() {
return _.map(this.domains(), function(item) {
return {
optValue: item.name,
optText: item.name
};
});
}, this);
this.canBeSaved = ko.computed(function() {
return !this.saving() && '' !== this.name() && '' !== this.alias();
}, this);
this.createCommand = Utils.createCommand(this, function() {
this.saving(true);
Remote.createDomainAlias(
_.bind(this.onDomainAliasCreateOrSaveResponse, this),
this.name(),
this.alias()
);
}, this.canBeSaved);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/DomainAlias', 'PopupsDomainAliasViewModel'], DomainAliasPopupView);
_.extend(DomainAliasPopupView.prototype, AbstractView.prototype);
DomainAliasPopupView.prototype.onDomainAliasCreateOrSaveResponse = function(sResult, oData)
{
this.saving(false);
if (Enums.StorageResultType.Success === sResult && oData)
{
AbstractView.call(this, 'Popups', 'PopupsDomainAlias');
this.saving = ko.observable(false);
this.savingError = ko.observable('');
this.name = ko.observable('');
this.name.focused = ko.observable(false);
this.alias = ko.observable('');
this.domains = DomainStore.domainsWithoutAliases;
this.domainsOptions = ko.computed(function () {
return _.map(this.domains(), function(item) {
return {
optValue: item.name,
optText: item.name
};
});
}, this);
this.canBeSaved = ko.computed(function () {
return !this.saving() && '' !== this.name() && '' !== this.alias();
}, this);
this.createCommand = Utils.createCommand(this, function () {
this.saving(true);
Remote.createDomainAlias(
_.bind(this.onDomainAliasCreateOrSaveResponse, this),
this.name(),
this.alias()
);
}, this.canBeSaved);
kn.constructorEnd(this);
if (oData.Result)
{
require('App/Admin').default.reloadDomainList();
this.closeCommand();
}
else if (Enums.Notification.DomainAlreadyExists === oData.ErrorCode)
{
this.savingError(Translator.i18n('ERRORS/DOMAIN_ALREADY_EXISTS'));
}
}
kn.extendAsViewModel(['View/Popup/DomainAlias', 'PopupsDomainAliasViewModel'], DomainAliasPopupView);
_.extend(DomainAliasPopupView.prototype, AbstractView.prototype);
DomainAliasPopupView.prototype.onDomainAliasCreateOrSaveResponse = function (sResult, oData)
else
{
this.saving(false);
if (Enums.StorageResultType.Success === sResult && oData)
{
if (oData.Result)
{
require('App/Admin').default.reloadDomainList();
this.closeCommand();
}
else if (Enums.Notification.DomainAlreadyExists === oData.ErrorCode)
{
this.savingError(Translator.i18n('ERRORS/DOMAIN_ALREADY_EXISTS'));
}
}
else
{
this.savingError(Translator.i18n('ERRORS/UNKNOWN_ERROR'));
}
};
this.savingError(Translator.i18n('ERRORS/UNKNOWN_ERROR'));
}
};
DomainAliasPopupView.prototype.onShow = function ()
DomainAliasPopupView.prototype.onShow = function()
{
this.clearForm();
};
DomainAliasPopupView.prototype.onShowWithDelay = function()
{
if ('' === this.name() && !Globals.bMobile)
{
this.clearForm();
};
this.name.focused(true);
}
};
DomainAliasPopupView.prototype.onShowWithDelay = function ()
{
if ('' === this.name() && !Globals.bMobile)
{
this.name.focused(true);
}
};
DomainAliasPopupView.prototype.clearForm = function()
{
this.saving(false);
this.savingError('');
DomainAliasPopupView.prototype.clearForm = function ()
{
this.saving(false);
this.savingError('');
this.name('');
this.name.focused(false);
this.name('');
this.name.focused(false);
this.alias('');
};
this.alias('');
};
module.exports = DomainAliasPopupView;
}());
module.exports = DomainAliasPopupView;

View file

@ -1,210 +1,203 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
var
_ = require('_'),
ko = require('ko'),
FilterStore = require('Stores/User/Filter'),
FolderStore = require('Stores/User/Folder'),
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
FilterStore = require('Stores/User/Filter'),
FolderStore = require('Stores/User/Folder'),
/**
* @constructor
* @extends AbstractView
*/
function FilterPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsFilter');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.isNew = ko.observable(true);
/**
* @constructor
* @extends AbstractView
*/
function FilterPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsFilter');
this.modules = FilterStore.modules;
this.isNew = ko.observable(true);
this.fTrueCallback = null;
this.filter = ko.observable(null);
this.modules = FilterStore.modules;
this.allowMarkAsRead = ko.observable(false);
this.fTrueCallback = null;
this.filter = ko.observable(null);
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
this.folderSelectList = FolderStore.folderMenuForFilters;
this.selectedFolderValue = ko.observable('');
this.allowMarkAsRead = ko.observable(false);
this.selectedFolderValue.subscribe(function() {
if (this.filter())
{
this.filter().actionValue.error(false);
}
}, this);
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
this.folderSelectList = FolderStore.folderMenuForFilters;
this.selectedFolderValue = ko.observable('');
this.saveFilter = Utils.createCommand(this, function() {
this.selectedFolderValue.subscribe(function() {
if (this.filter())
if (this.filter())
{
if (Enums.FiltersAction.MoveTo === this.filter().actionType())
{
this.filter().actionValue.error(false);
}
}, this);
this.saveFilter = Utils.createCommand(this, function () {
if (this.filter())
{
if (Enums.FiltersAction.MoveTo === this.filter().actionType())
{
this.filter().actionValue(this.selectedFolderValue());
}
if (!this.filter().verify())
{
return false;
}
if (this.fTrueCallback)
{
this.fTrueCallback(this.filter());
}
if (this.modalVisibility())
{
Utils.delegateRun(this, 'closeCommand');
}
this.filter().actionValue(this.selectedFolderValue());
}
return true;
});
if (!this.filter().verify())
{
return false;
}
this.actionTypeOptions = ko.observableArray([]);
this.fieldOptions = ko.observableArray([]);
this.typeOptions = ko.observableArray([]);
this.typeOptionsSize = ko.observableArray([]);
if (this.fTrueCallback)
{
this.fTrueCallback(this.filter());
}
Translator.initOnStartOrLangChange(this.populateOptions, this);
if (this.modalVisibility())
{
Utils.delegateRun(this, 'closeCommand');
}
}
this.modules.subscribe(this.populateOptions, this);
return true;
});
kn.constructorEnd(this);
}
this.actionTypeOptions = ko.observableArray([]);
this.fieldOptions = ko.observableArray([]);
this.typeOptions = ko.observableArray([]);
this.typeOptionsSize = ko.observableArray([]);
kn.extendAsViewModel(['View/Popup/Filter', 'PopupsFilterViewModel'], FilterPopupView);
_.extend(FilterPopupView.prototype, AbstractView.prototype);
Translator.initOnStartOrLangChange(this.populateOptions, this);
FilterPopupView.prototype.populateOptions = function ()
{
this.actionTypeOptions([]);
this.modules.subscribe(this.populateOptions, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Filter', 'PopupsFilterViewModel'], FilterPopupView);
_.extend(FilterPopupView.prototype, AbstractView.prototype);
FilterPopupView.prototype.populateOptions = function()
{
this.actionTypeOptions([]);
// this.actionTypeOptions.push({'id': Enums.FiltersAction.None,
// 'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_NONE')});
var oModules = this.modules();
if (oModules)
{
if (oModules.markasread)
{
this.allowMarkAsRead(true);
}
if (oModules.moveto)
{
this.actionTypeOptions.push({'id': Enums.FiltersAction.MoveTo,
'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_MOVE_TO')});
}
if (oModules.redirect)
{
this.actionTypeOptions.push({'id': Enums.FiltersAction.Forward,
'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_FORWARD_TO')});
}
if (oModules.reject)
{
this.actionTypeOptions.push({'id': Enums.FiltersAction.Reject,
'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_REJECT')});
}
if (oModules.vacation)
{
this.actionTypeOptions.push({'id': Enums.FiltersAction.Vacation,
'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_VACATION_MESSAGE')});
}
}
this.actionTypeOptions.push({'id': Enums.FiltersAction.Discard,
'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_DISCARD')});
this.fieldOptions([
{'id': Enums.FilterConditionField.From, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_FROM')},
{'id': Enums.FilterConditionField.Recipient, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_RECIPIENTS')},
{'id': Enums.FilterConditionField.Subject, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_SUBJECT')},
{'id': Enums.FilterConditionField.Size, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_SIZE')},
{'id': Enums.FilterConditionField.Header, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_HEADER')}
]);
this.typeOptions([
{'id': Enums.FilterConditionType.Contains, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_CONTAINS')},
{'id': Enums.FilterConditionType.NotContains, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_NOT_CONTAINS')},
{'id': Enums.FilterConditionType.EqualTo, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_EQUAL_TO')},
{'id': Enums.FilterConditionType.NotEqualTo, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_NOT_EQUAL_TO')}
]);
if (oModules && oModules.regex)
{
this.typeOptions.push({'id': Enums.FilterConditionType.Regex, 'name': 'Regex'});
}
this.typeOptionsSize([
{'id': Enums.FilterConditionType.Over, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_OVER')},
{'id': Enums.FilterConditionType.Under, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_UNDER')}
]);
};
FilterPopupView.prototype.removeCondition = function (oConditionToDelete)
var oModules = this.modules();
if (oModules)
{
if (this.filter())
if (oModules.markasread)
{
this.filter().removeCondition(oConditionToDelete);
this.allowMarkAsRead(true);
}
};
FilterPopupView.prototype.clearPopup = function ()
if (oModules.moveto)
{
this.actionTypeOptions.push({'id': Enums.FiltersAction.MoveTo,
'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_MOVE_TO')});
}
if (oModules.redirect)
{
this.actionTypeOptions.push({'id': Enums.FiltersAction.Forward,
'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_FORWARD_TO')});
}
if (oModules.reject)
{
this.actionTypeOptions.push({'id': Enums.FiltersAction.Reject,
'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_REJECT')});
}
if (oModules.vacation)
{
this.actionTypeOptions.push({'id': Enums.FiltersAction.Vacation,
'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_VACATION_MESSAGE')});
}
}
this.actionTypeOptions.push({'id': Enums.FiltersAction.Discard,
'name': Translator.i18n('POPUPS_FILTER/SELECT_ACTION_DISCARD')});
this.fieldOptions([
{'id': Enums.FilterConditionField.From, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_FROM')},
{'id': Enums.FilterConditionField.Recipient, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_RECIPIENTS')},
{'id': Enums.FilterConditionField.Subject, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_SUBJECT')},
{'id': Enums.FilterConditionField.Size, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_SIZE')},
{'id': Enums.FilterConditionField.Header, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_HEADER')}
]);
this.typeOptions([
{'id': Enums.FilterConditionType.Contains, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_CONTAINS')},
{'id': Enums.FilterConditionType.NotContains, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_NOT_CONTAINS')},
{'id': Enums.FilterConditionType.EqualTo, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_EQUAL_TO')},
{'id': Enums.FilterConditionType.NotEqualTo, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_NOT_EQUAL_TO')}
]);
if (oModules && oModules.regex)
{
this.isNew(true);
this.typeOptions.push({'id': Enums.FilterConditionType.Regex, 'name': 'Regex'});
}
this.fTrueCallback = null;
this.filter(null);
};
this.typeOptionsSize([
{'id': Enums.FilterConditionType.Over, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_OVER')},
{'id': Enums.FilterConditionType.Under, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_UNDER')}
]);
};
FilterPopupView.prototype.onShow = function (oFilter, fTrueCallback, bEdit)
FilterPopupView.prototype.removeCondition = function(oConditionToDelete)
{
if (this.filter())
{
this.clearPopup();
this.filter().removeCondition(oConditionToDelete);
}
};
this.fTrueCallback = fTrueCallback;
this.filter(oFilter);
FilterPopupView.prototype.clearPopup = function()
{
this.isNew(true);
if (oFilter)
{
this.selectedFolderValue(oFilter.actionValue());
}
this.fTrueCallback = null;
this.filter(null);
};
this.isNew(!bEdit);
FilterPopupView.prototype.onShow = function(oFilter, fTrueCallback, bEdit)
{
this.clearPopup();
if (!bEdit && oFilter)
{
oFilter.name.focused(true);
}
};
this.fTrueCallback = fTrueCallback;
this.filter(oFilter);
FilterPopupView.prototype.onShowWithDelay = function ()
if (oFilter)
{
if (this.isNew() && this.filter() && !Globals.bMobile)
{
this.filter().name.focused(true);
}
};
this.selectedFolderValue(oFilter.actionValue());
}
module.exports = FilterPopupView;
this.isNew(!bEdit);
}());
if (!bEdit && oFilter)
{
oFilter.name.focused(true);
}
};
FilterPopupView.prototype.onShowWithDelay = function()
{
if (this.isNew() && this.filter() && !Globals.bMobile)
{
this.filter().name.focused(true);
}
};
module.exports = FilterPopupView;

View file

@ -1,127 +1,118 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
var
_ = require('_'),
ko = require('ko'),
Cache = require('Common/Cache'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
MessageStore = require('Stores/User/Message'),
Cache = require('Common/Cache'),
Remote = require('Remote/User/Ajax'),
MessageStore = require('Stores/User/Message'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Remote = require('Remote/User/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function FolderClearPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsFolderClear');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.selectedFolder = ko.observable(null);
this.clearingProcess = ko.observable(false);
this.clearingError = ko.observable('');
/**
* @constructor
* @extends AbstractView
*/
function FolderClearPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsFolderClear');
this.folderFullNameForClear = ko.computed(function() {
var oFolder = this.selectedFolder();
return oFolder ? oFolder.printableFullName() : '';
}, this);
this.selectedFolder = ko.observable(null);
this.clearingProcess = ko.observable(false);
this.clearingError = ko.observable('');
this.folderNameForClear = ko.computed(function() {
var oFolder = this.selectedFolder();
return oFolder ? oFolder.localName() : '';
}, this);
this.folderFullNameForClear = ko.computed(function () {
var oFolder = this.selectedFolder();
return oFolder ? oFolder.printableFullName() : '';
}, this);
this.dangerDescHtml = ko.computed(function() {
return Translator.i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', {
'FOLDER': this.folderNameForClear()
});
}, this);
this.folderNameForClear = ko.computed(function () {
var oFolder = this.selectedFolder();
return oFolder ? oFolder.localName() : '';
}, this);
this.clearCommand = Utils.createCommand(this, function() {
this.dangerDescHtml = ko.computed(function () {
return Translator.i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', {
'FOLDER': this.folderNameForClear()
});
}, this);
var
self = this,
oFolderToClear = this.selectedFolder();
this.clearCommand = Utils.createCommand(this, function () {
if (oFolderToClear)
{
MessageStore.message(null);
MessageStore.messageList([]);
var
self = this,
oFolderToClear = this.selectedFolder()
;
this.clearingProcess(true);
if (oFolderToClear)
{
MessageStore.message(null);
MessageStore.messageList([]);
oFolderToClear.messageCountAll(0);
oFolderToClear.messageCountUnread(0);
this.clearingProcess(true);
Cache.setFolderHash(oFolderToClear.fullNameRaw, '');
oFolderToClear.messageCountAll(0);
oFolderToClear.messageCountUnread(0);
Remote.folderClear(function(sResult, oData) {
Cache.setFolderHash(oFolderToClear.fullNameRaw, '');
Remote.folderClear(function (sResult, oData) {
self.clearingProcess(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
self.clearingProcess(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
require('App/User').default.reloadMessageList(true);
self.cancelCommand();
}
else
{
if (oData && oData.ErrorCode)
{
require('App/User').default.reloadMessageList(true);
self.cancelCommand();
self.clearingError(Translator.getNotification(oData.ErrorCode));
}
else
{
if (oData && oData.ErrorCode)
{
self.clearingError(Translator.getNotification(oData.ErrorCode));
}
else
{
self.clearingError(Translator.getNotification(Enums.Notification.MailServerError));
}
self.clearingError(Translator.getNotification(Enums.Notification.MailServerError));
}
}, oFolderToClear.fullNameRaw);
}
}, function () {
var
oFolder = this.selectedFolder(),
bIsClearing = this.clearingProcess()
;
return !bIsClearing && null !== oFolder;
});
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/FolderClear', 'PopupsFolderClearViewModel'], FolderClearPopupView);
_.extend(FolderClearPopupView.prototype, AbstractView.prototype);
FolderClearPopupView.prototype.clearPopup = function ()
{
this.clearingProcess(false);
this.selectedFolder(null);
};
FolderClearPopupView.prototype.onShow = function (oFolder)
{
this.clearPopup();
if (oFolder)
{
this.selectedFolder(oFolder);
}
}, oFolderToClear.fullNameRaw);
}
};
module.exports = FolderClearPopupView;
}, function() {
}());
var
oFolder = this.selectedFolder(),
bIsClearing = this.clearingProcess();
return !bIsClearing && null !== oFolder;
});
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/FolderClear', 'PopupsFolderClearViewModel'], FolderClearPopupView);
_.extend(FolderClearPopupView.prototype, AbstractView.prototype);
FolderClearPopupView.prototype.clearPopup = function()
{
this.clearingProcess(false);
this.selectedFolder(null);
};
FolderClearPopupView.prototype.onShow = function(oFolder)
{
this.clearPopup();
if (oFolder)
{
this.selectedFolder(oFolder);
}
};
module.exports = FolderClearPopupView;

View file

@ -1,120 +1,111 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
FolderStore = require('Stores/User/Folder'),
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Promises = require('Promises/User/Ajax'),
FolderStore = require('Stores/User/Folder'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Promises = require('Promises/User/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function FolderCreateView()
{
AbstractView.call(this, 'Popups', 'PopupsFolderCreate');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.folderName = ko.observable('');
this.folderName.focused = ko.observable(false);
/**
* @constructor
* @extends AbstractView
*/
function FolderCreateView()
{
AbstractView.call(this, 'Popups', 'PopupsFolderCreate');
this.selectedParentValue = ko.observable(Consts.UNUSED_OPTION_VALUE);
this.folderName = ko.observable('');
this.folderName.focused = ko.observable(false);
this.parentFolderSelectList = ko.computed(function() {
this.selectedParentValue = ko.observable(Consts.UNUSED_OPTION_VALUE);
var
aTop = [],
fDisableCallback = null,
fVisibleCallback = null,
aList = FolderStore.folderList(),
fRenameCallback = function(oItem) {
return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
};
this.parentFolderSelectList = ko.computed(function () {
aTop.push(['', '']);
var
aTop = [],
fDisableCallback = null,
fVisibleCallback = null,
aList = FolderStore.folderList(),
fRenameCallback = function (oItem) {
return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
}
;
aTop.push(['', '']);
if ('' !== FolderStore.namespace)
{
fDisableCallback = function (oItem)
{
return FolderStore.namespace !== oItem.fullNameRaw.substr(0, FolderStore.namespace.length);
};
}
return Utils.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);
}, this);
// commands
this.createFolder = Utils.createCommand(this, function () {
var
sParentFolderName = this.selectedParentValue()
;
if ('' === sParentFolderName && 1 < FolderStore.namespace.length)
{
sParentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
}
require('App/User').default.foldersPromisesActionHelper(
Promises.folderCreate(this.folderName(), sParentFolderName, FolderStore.foldersCreating),
Enums.Notification.CantCreateFolder
);
this.cancelCommand();
}, function () {
return this.simpleFolderNameValidation(this.folderName());
});
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/FolderCreate', 'PopupsFolderCreateViewModel'], FolderCreateView);
_.extend(FolderCreateView.prototype, AbstractView.prototype);
FolderCreateView.prototype.simpleFolderNameValidation = function (sName)
{
return (/^[^\\\/]+$/g).test(Utils.trim(sName));
};
FolderCreateView.prototype.clearPopup = function ()
{
this.folderName('');
this.selectedParentValue('');
this.folderName.focused(false);
};
FolderCreateView.prototype.onShow = function ()
{
this.clearPopup();
};
FolderCreateView.prototype.onShowWithDelay = function ()
{
if (!Globals.bMobile)
if ('' !== FolderStore.namespace)
{
this.folderName.focused(true);
fDisableCallback = function(oItem)
{
return FolderStore.namespace !== oItem.fullNameRaw.substr(0, FolderStore.namespace.length);
};
}
};
module.exports = FolderCreateView;
return Utils.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);
}());
}, this);
// commands
this.createFolder = Utils.createCommand(this, function() {
var
sParentFolderName = this.selectedParentValue();
if ('' === sParentFolderName && 1 < FolderStore.namespace.length)
{
sParentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
}
require('App/User').default.foldersPromisesActionHelper(
Promises.folderCreate(this.folderName(), sParentFolderName, FolderStore.foldersCreating),
Enums.Notification.CantCreateFolder
);
this.cancelCommand();
}, function() {
return this.simpleFolderNameValidation(this.folderName());
});
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/FolderCreate', 'PopupsFolderCreateViewModel'], FolderCreateView);
_.extend(FolderCreateView.prototype, AbstractView.prototype);
FolderCreateView.prototype.simpleFolderNameValidation = function(sName)
{
return (/^[^\\\/]+$/g).test(Utils.trim(sName));
};
FolderCreateView.prototype.clearPopup = function()
{
this.folderName('');
this.selectedParentValue('');
this.folderName.focused(false);
};
FolderCreateView.prototype.onShow = function()
{
this.clearPopup();
};
FolderCreateView.prototype.onShowWithDelay = function()
{
if (!Globals.bMobile)
{
this.folderName.focused(true);
}
};
module.exports = FolderCreateView;

View file

@ -1,137 +1,130 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
FolderStore = require('Stores/User/Folder'),
Settings = require('Storage/Settings'),
Remote = require('Remote/User/Ajax'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
/**
* @constructor
* @extends AbstractView
*/
function FolderSystemPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsFolderSystem');
Translator.initOnStartOrLangChange(function() {
this.sChooseOnText = Translator.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_CHOOSE_ONE');
this.sUnuseText = Translator.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_UNUSE_NAME');
}, this);
this.notification = ko.observable('');
this.folderSelectList = ko.computed(function() {
return Utils.folderListOptionsBuilder([], FolderStore.folderList(), FolderStore.folderListSystemNames(), [
['', this.sChooseOnText],
[Consts.UNUSED_OPTION_VALUE, this.sUnuseText]
], null, null, null, null, null, true);
}, this);
var
_ = require('_'),
ko = require('ko'),
fSaveSystemFolders = null,
fCallback = null;
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
this.sentFolder = FolderStore.sentFolder;
this.draftFolder = FolderStore.draftFolder;
this.spamFolder = FolderStore.spamFolder;
this.trashFolder = FolderStore.trashFolder;
this.archiveFolder = FolderStore.archiveFolder;
FolderStore = require('Stores/User/Folder'),
fSaveSystemFolders = _.debounce(function() {
Settings = require('Storage/Settings'),
Remote = require('Remote/User/Ajax'),
Settings.settingsSet('SentFolder', FolderStore.sentFolder());
Settings.settingsSet('DraftFolder', FolderStore.draftFolder());
Settings.settingsSet('SpamFolder', FolderStore.spamFolder());
Settings.settingsSet('TrashFolder', FolderStore.trashFolder());
Settings.settingsSet('ArchiveFolder', FolderStore.archiveFolder());
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
Remote.saveSystemFolders(Utils.noop, {
'SentFolder': FolderStore.sentFolder(),
'DraftFolder': FolderStore.draftFolder(),
'SpamFolder': FolderStore.spamFolder(),
'TrashFolder': FolderStore.trashFolder(),
'ArchiveFolder': FolderStore.archiveFolder(),
'NullFolder': 'NullFolder'
});
/**
* @constructor
* @extends AbstractView
*/
function FolderSystemPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsFolderSystem');
}, 1000);
Translator.initOnStartOrLangChange(function () {
this.sChooseOnText = Translator.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_CHOOSE_ONE');
this.sUnuseText = Translator.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_UNUSE_NAME');
}, this);
fCallback = function() {
this.notification = ko.observable('');
Settings.settingsSet('SentFolder', FolderStore.sentFolder());
Settings.settingsSet('DraftFolder', FolderStore.draftFolder());
Settings.settingsSet('SpamFolder', FolderStore.spamFolder());
Settings.settingsSet('TrashFolder', FolderStore.trashFolder());
Settings.settingsSet('ArchiveFolder', FolderStore.archiveFolder());
this.folderSelectList = ko.computed(function () {
return Utils.folderListOptionsBuilder([], FolderStore.folderList(), FolderStore.folderListSystemNames(), [
['', this.sChooseOnText],
[Consts.UNUSED_OPTION_VALUE, this.sUnuseText]
], null, null, null, null, null, true);
}, this);
var
fSaveSystemFolders = null,
fCallback = null
;
this.sentFolder = FolderStore.sentFolder;
this.draftFolder = FolderStore.draftFolder;
this.spamFolder = FolderStore.spamFolder;
this.trashFolder = FolderStore.trashFolder;
this.archiveFolder = FolderStore.archiveFolder;
fSaveSystemFolders = _.debounce(function () {
Settings.settingsSet('SentFolder', FolderStore.sentFolder());
Settings.settingsSet('DraftFolder', FolderStore.draftFolder());
Settings.settingsSet('SpamFolder', FolderStore.spamFolder());
Settings.settingsSet('TrashFolder', FolderStore.trashFolder());
Settings.settingsSet('ArchiveFolder', FolderStore.archiveFolder());
Remote.saveSystemFolders(Utils.noop, {
'SentFolder': FolderStore.sentFolder(),
'DraftFolder': FolderStore.draftFolder(),
'SpamFolder': FolderStore.spamFolder(),
'TrashFolder': FolderStore.trashFolder(),
'ArchiveFolder': FolderStore.archiveFolder(),
'NullFolder': 'NullFolder'
});
}, 1000);
fCallback = function () {
Settings.settingsSet('SentFolder', FolderStore.sentFolder());
Settings.settingsSet('DraftFolder', FolderStore.draftFolder());
Settings.settingsSet('SpamFolder', FolderStore.spamFolder());
Settings.settingsSet('TrashFolder', FolderStore.trashFolder());
Settings.settingsSet('ArchiveFolder', FolderStore.archiveFolder());
fSaveSystemFolders();
};
FolderStore.sentFolder.subscribe(fCallback);
FolderStore.draftFolder.subscribe(fCallback);
FolderStore.spamFolder.subscribe(fCallback);
FolderStore.trashFolder.subscribe(fCallback);
FolderStore.archiveFolder.subscribe(fCallback);
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/FolderSystem', 'PopupsFolderSystemViewModel'], FolderSystemPopupView);
_.extend(FolderSystemPopupView.prototype, AbstractView.prototype);
FolderSystemPopupView.prototype.sChooseOnText = '';
FolderSystemPopupView.prototype.sUnuseText = '';
/**
* @param {number=} iNotificationType = Enums.SetSystemFoldersNotification.None
*/
FolderSystemPopupView.prototype.onShow = function (iNotificationType)
{
var sNotification = '';
iNotificationType = Utils.isUnd(iNotificationType) ? Enums.SetSystemFoldersNotification.None : iNotificationType;
switch (iNotificationType)
{
case Enums.SetSystemFoldersNotification.Sent:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SENT');
break;
case Enums.SetSystemFoldersNotification.Draft:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_DRAFTS');
break;
case Enums.SetSystemFoldersNotification.Spam:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SPAM');
break;
case Enums.SetSystemFoldersNotification.Trash:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_TRASH');
break;
case Enums.SetSystemFoldersNotification.Archive:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_ARCHIVE');
break;
}
this.notification(sNotification);
fSaveSystemFolders();
};
module.exports = FolderSystemPopupView;
FolderStore.sentFolder.subscribe(fCallback);
FolderStore.draftFolder.subscribe(fCallback);
FolderStore.spamFolder.subscribe(fCallback);
FolderStore.trashFolder.subscribe(fCallback);
FolderStore.archiveFolder.subscribe(fCallback);
}());
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/FolderSystem', 'PopupsFolderSystemViewModel'], FolderSystemPopupView);
_.extend(FolderSystemPopupView.prototype, AbstractView.prototype);
FolderSystemPopupView.prototype.sChooseOnText = '';
FolderSystemPopupView.prototype.sUnuseText = '';
/**
* @param {number=} iNotificationType = Enums.SetSystemFoldersNotification.None
*/
FolderSystemPopupView.prototype.onShow = function(iNotificationType)
{
var sNotification = '';
iNotificationType = Utils.isUnd(iNotificationType) ? Enums.SetSystemFoldersNotification.None : iNotificationType;
switch (iNotificationType)
{
case Enums.SetSystemFoldersNotification.Sent:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SENT');
break;
case Enums.SetSystemFoldersNotification.Draft:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_DRAFTS');
break;
case Enums.SetSystemFoldersNotification.Spam:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SPAM');
break;
case Enums.SetSystemFoldersNotification.Trash:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_TRASH');
break;
case Enums.SetSystemFoldersNotification.Archive:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_ARCHIVE');
break;
// no default
}
this.notification(sNotification);
};
module.exports = FolderSystemPopupView;

View file

@ -1,204 +1,197 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
var
_ = require('_'),
ko = require('ko'),
Remote = require('Remote/User/Ajax'),
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Remote = require('Remote/User/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function IdentityPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsIdentity');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
var self = this;
/**
* @constructor
* @extends AbstractView
*/
function IdentityPopupView()
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.signature = ko.observable('');
this.signatureInsertBefore = ko.observable(false);
this.showBcc = ko.observable(false);
this.showReplyTo = ko.observable(false);
this.submitRequest = ko.observable(false);
this.submitError = ko.observable('');
this.bcc.subscribe(function(aValue) {
if (false === self.showBcc() && 0 < aValue.length)
{
self.showBcc(true);
}
}, this);
this.replyTo.subscribe(function(aValue) {
if (false === self.showReplyTo() && 0 < aValue.length)
{
self.showReplyTo(true);
}
}, this);
this.addOrEditIdentityCommand = Utils.createCommand(this, function() {
if (this.signature && this.signature.__fetchEditorValue)
{
this.signature.__fetchEditorValue();
}
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);
Remote.identityUpdate(_.bind(function(sResult, oData) {
this.submitRequest(false);
if (Enums.StorageResultType.Success === sResult && oData)
{
if (oData.Result)
{
require('App/User').default.accountsAndIdentities();
this.cancelCommand();
}
else if (oData.ErrorCode)
{
this.submitError(Translator.getNotification(oData.ErrorCode));
}
}
else
{
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
}
}, this), this.id, this.email(), this.name(), this.replyTo(), this.bcc(),
this.signature(), this.signatureInsertBefore());
return true;
}, function() {
return !this.submitRequest();
});
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Identity', 'PopupsIdentityViewModel'], IdentityPopupView);
_.extend(IdentityPopupView.prototype, AbstractView.prototype);
IdentityPopupView.prototype.clearPopup = function()
{
this.id = '';
this.edit(false);
this.owner(false);
this.name('');
this.email('');
this.replyTo('');
this.bcc('');
this.signature('');
this.signatureInsertBefore(false);
this.email.hasError(false);
this.replyTo.hasError(false);
this.bcc.hasError(false);
this.showBcc(false);
this.showReplyTo(false);
this.submitRequest(false);
this.submitError('');
};
/**
* @param {?IdentityModel} oIdentity
*/
IdentityPopupView.prototype.onShow = function(oIdentity)
{
this.clearPopup();
if (oIdentity)
{
AbstractView.call(this, 'Popups', 'PopupsIdentity');
this.edit(true);
var self = this;
this.id = oIdentity.id() || '';
this.name(oIdentity.name());
this.email(oIdentity.email());
this.replyTo(oIdentity.replyTo());
this.bcc(oIdentity.bcc());
this.signature(oIdentity.signature());
this.signatureInsertBefore(oIdentity.signatureInsertBefore());
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.signature = ko.observable('');
this.signatureInsertBefore = ko.observable(false);
this.showBcc = ko.observable(false);
this.showReplyTo = ko.observable(false);
this.submitRequest = ko.observable(false);
this.submitError = ko.observable('');
this.bcc.subscribe(function (aValue) {
if (false === self.showBcc() && 0 < aValue.length)
{
self.showBcc(true);
}
}, this);
this.replyTo.subscribe(function (aValue) {
if (false === self.showReplyTo() && 0 < aValue.length)
{
self.showReplyTo(true);
}
}, this);
this.addOrEditIdentityCommand = Utils.createCommand(this, function () {
if (this.signature && this.signature.__fetchEditorValue)
{
this.signature.__fetchEditorValue();
}
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);
Remote.identityUpdate(_.bind(function (sResult, oData) {
this.submitRequest(false);
if (Enums.StorageResultType.Success === sResult && oData)
{
if (oData.Result)
{
require('App/User').default.accountsAndIdentities();
this.cancelCommand();
}
else if (oData.ErrorCode)
{
this.submitError(Translator.getNotification(oData.ErrorCode));
}
}
else
{
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
}
}, this), this.id, this.email(), this.name(), this.replyTo(), this.bcc(),
this.signature(), this.signatureInsertBefore());
return true;
}, function () {
return !this.submitRequest();
});
kn.constructorEnd(this);
this.owner('' === this.id);
}
kn.extendAsViewModel(['View/Popup/Identity', 'PopupsIdentityViewModel'], IdentityPopupView);
_.extend(IdentityPopupView.prototype, AbstractView.prototype);
IdentityPopupView.prototype.clearPopup = function ()
else
{
this.id = '';
this.edit(false);
this.owner(false);
this.id = Utils.fakeMd5();
}
};
this.name('');
this.email('');
this.replyTo('');
this.bcc('');
this.signature('');
this.signatureInsertBefore(false);
this.email.hasError(false);
this.replyTo.hasError(false);
this.bcc.hasError(false);
this.showBcc(false);
this.showReplyTo(false);
this.submitRequest(false);
this.submitError('');
};
/**
* @param {?IdentityModel} oIdentity
*/
IdentityPopupView.prototype.onShow = function (oIdentity)
IdentityPopupView.prototype.onShowWithDelay = function()
{
if (!this.owner() && !Globals.bMobile)
{
this.clearPopup();
this.email.focused(true);
}
};
if (oIdentity)
{
this.edit(true);
IdentityPopupView.prototype.onHideWithDelay = function()
{
this.clearPopup();
};
this.id = oIdentity.id() || '';
this.name(oIdentity.name());
this.email(oIdentity.email());
this.replyTo(oIdentity.replyTo());
this.bcc(oIdentity.bcc());
this.signature(oIdentity.signature());
this.signatureInsertBefore(oIdentity.signatureInsertBefore());
this.owner(this.id === '');
}
else
{
this.id = Utils.fakeMd5();
}
};
IdentityPopupView.prototype.onShowWithDelay = function ()
{
if (!this.owner() && !Globals.bMobile)
{
this.email.focused(true);
}
};
IdentityPopupView.prototype.onHideWithDelay = function ()
{
this.clearPopup();
};
module.exports = IdentityPopupView;
}());
module.exports = IdentityPopupView;

View file

@ -1,64 +1,56 @@
(function () {
var
_ = require('_'),
key = require('key'),
'use strict';
Enums = require('Common/Enums'),
var
_ = require('_'),
key = require('key'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Enums = require('Common/Enums'),
/**
* @constructor
* @extends AbstractView
*/
function KeyboardShortcutsHelpPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsKeyboardShortcutsHelp');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.sDefaultKeyScope = Enums.KeyState.PopupKeyboardShortcutsHelp;
/**
* @constructor
* @extends AbstractView
*/
function KeyboardShortcutsHelpPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsKeyboardShortcutsHelp');
kn.constructorEnd(this);
}
this.sDefaultKeyScope = Enums.KeyState.PopupKeyboardShortcutsHelp;
kn.extendAsViewModel(['View/Popup/KeyboardShortcutsHelp', 'PopupsKeyboardShortcutsHelpViewModel'], KeyboardShortcutsHelpPopupView);
_.extend(KeyboardShortcutsHelpPopupView.prototype, AbstractView.prototype);
kn.constructorEnd(this);
}
KeyboardShortcutsHelpPopupView.prototype.onBuild = function(oDom)
{
key('tab, shift+tab, left, right', Enums.KeyState.PopupKeyboardShortcutsHelp, _.throttle(_.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'));
kn.extendAsViewModel(['View/Popup/KeyboardShortcutsHelp', 'PopupsKeyboardShortcutsHelpViewModel'], KeyboardShortcutsHelpPopupView);
_.extend(KeyboardShortcutsHelpPopupView.prototype, AbstractView.prototype);
KeyboardShortcutsHelpPopupView.prototype.onBuild = function (oDom)
{
key('tab, shift+tab, left, right', Enums.KeyState.PopupKeyboardShortcutsHelp, _.throttle(_.bind(function (event, handler) {
if (event && handler)
if (!bNext && 0 < iIndex)
{
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;
iIndex -= 1;
}
else if (bNext && iIndex < $tabs.length - 1)
{
iIndex += 1;
}
else
{
iIndex = bNext ? 0 : $tabs.length - 1;
}
}, this), 100));
};
module.exports = KeyboardShortcutsHelpPopupView;
$tabs.eq(iIndex).find('a[data-toggle="tab"]').tab('show');
return false;
}
}, this), 100));
};
}());
module.exports = KeyboardShortcutsHelpPopupView;

View file

@ -1,95 +1,88 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Utils = require('Common/Utils'),
/**
* @constructor
* @extends AbstractView
*/
function LanguagesPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsLanguages');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
var self = this;
/**
* @constructor
* @extends AbstractView
*/
function LanguagesPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsLanguages');
this.fLang = null;
this.userLanguage = ko.observable('');
var self = this;
this.langs = ko.observableArray([]);
this.fLang = null;
this.userLanguage = ko.observable('');
this.langs = ko.observableArray([]);
this.languages = ko.computed(function () {
var sUserLanguage = self.userLanguage();
return _.map(self.langs(), function (sLanguage) {
return {
'key': sLanguage,
'user': sLanguage === sUserLanguage,
'selected': ko.observable(false),
'fullName': Utils.convertLangName(sLanguage)
};
});
this.languages = ko.computed(function() {
var sUserLanguage = self.userLanguage();
return _.map(self.langs(), function(sLanguage) {
return {
'key': sLanguage,
'user': sLanguage === sUserLanguage,
'selected': ko.observable(false),
'fullName': Utils.convertLangName(sLanguage)
};
});
});
this.langs.subscribe(function () {
this.setLanguageSelection();
}, this);
this.langs.subscribe(function() {
this.setLanguageSelection();
}, this);
kn.constructorEnd(this);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Languages', 'PopupsLanguagesViewModel'], LanguagesPopupView);
_.extend(LanguagesPopupView.prototype, AbstractView.prototype);
LanguagesPopupView.prototype.languageTooltipName = function(sLanguage)
{
var sResult = Utils.convertLangName(sLanguage, true);
return Utils.convertLangName(sLanguage, false) === sResult ? '' : sResult;
};
LanguagesPopupView.prototype.setLanguageSelection = function()
{
var currentLang = this.fLang ? ko.unwrap(this.fLang) : '';
_.each(this.languages(), function(item) {
item.selected(item.key === currentLang);
});
};
LanguagesPopupView.prototype.onBeforeShow = function()
{
this.fLang = null;
this.userLanguage('');
this.langs([]);
};
LanguagesPopupView.prototype.onShow = function(fLanguage, aLangs, sUserLanguage)
{
this.fLang = fLanguage;
this.userLanguage(sUserLanguage || '');
this.langs(aLangs);
};
LanguagesPopupView.prototype.changeLanguage = function(sLang)
{
if (this.fLang)
{
this.fLang(sLang);
}
kn.extendAsViewModel(['View/Popup/Languages', 'PopupsLanguagesViewModel'], LanguagesPopupView);
_.extend(LanguagesPopupView.prototype, AbstractView.prototype);
this.cancelCommand();
};
LanguagesPopupView.prototype.languageTooltipName = function (sLanguage)
{
var sResult = Utils.convertLangName(sLanguage, true);
return Utils.convertLangName(sLanguage, false) === sResult ? '' : sResult;
};
LanguagesPopupView.prototype.setLanguageSelection = function ()
{
var currentLang = this.fLang ? ko.unwrap(this.fLang) : '';
_.each(this.languages(), function (item) {
item.selected(item.key === currentLang);
});
};
LanguagesPopupView.prototype.onBeforeShow = function ()
{
this.fLang = null;
this.userLanguage('');
this.langs([]);
};
LanguagesPopupView.prototype.onShow = function (fLanguage, aLangs, sUserLanguage)
{
this.fLang = fLanguage;
this.userLanguage(sUserLanguage || '');
this.langs(aLangs);
};
LanguagesPopupView.prototype.changeLanguage = function (sLang)
{
if (this.fLang)
{
this.fLang(sLang);
}
this.cancelCommand();
};
module.exports = LanguagesPopupView;
}());
module.exports = LanguagesPopupView;

View file

@ -1,53 +1,47 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
key = require('key'),
$ = require('$'),
'use strict';
Utils = require('Common/Utils'),
Enums = require('Common/Enums'),
var
_ = require('_'),
ko = require('ko'),
key = require('key'),
$ = require('$'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Utils = require('Common/Utils'),
Enums = require('Common/Enums'),
/**
* @constructor
* @extends AbstractView
*/
function MessageOpenPgpPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsMessageOpenPgp');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.notification = ko.observable('');
/**
* @constructor
* @extends AbstractView
*/
function MessageOpenPgpPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsMessageOpenPgp');
this.selectedKey = ko.observable(null);
this.privateKeys = ko.observableArray([]);
this.notification = ko.observable('');
this.password = ko.observable('');
this.password.focus = ko.observable(false);
this.buttonFocus = ko.observable(false);
this.selectedKey = ko.observable(null);
this.privateKeys = ko.observableArray([]);
this.resultCallback = null;
this.password = ko.observable('');
this.password.focus = ko.observable(false);
this.buttonFocus = ko.observable(false);
this.submitRequest = ko.observable(false);
this.resultCallback = null;
// commands
this.doCommand = Utils.createCommand(this, function() {
this.submitRequest = ko.observable(false);
this.submitRequest(true);
// commands
this.doCommand = Utils.createCommand(this, function () {
this.submitRequest(true);
_.delay(_.bind(function() {
_.delay(_.bind(function() {
var
oPrivateKeys = [],
oPrivateKey = null
;
oPrivateKey = null;
try
{
@ -89,99 +83,95 @@ _.delay(_.bind(function() {
this.cancelCommand();
this.resultCallback(oPrivateKey);
}, this), 100);
}, this), 100);
}, function () {
return !this.submitRequest();
});
}, function() {
return !this.submitRequest();
});
this.sDefaultKeyScope = Enums.KeyState.PopupMessageOpenPGP;
this.sDefaultKeyScope = Enums.KeyState.PopupMessageOpenPGP;
kn.constructorEnd(this);
}
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/MessageOpenPgp'], MessageOpenPgpPopupView);
_.extend(MessageOpenPgpPopupView.prototype, AbstractView.prototype);
kn.extendAsViewModel(['View/Popup/MessageOpenPgp'], MessageOpenPgpPopupView);
_.extend(MessageOpenPgpPopupView.prototype, AbstractView.prototype);
MessageOpenPgpPopupView.prototype.clearPopup = function ()
{
this.notification('');
MessageOpenPgpPopupView.prototype.clearPopup = function()
{
this.notification('');
this.password('');
this.password.focus(false);
this.buttonFocus(false);
this.password('');
this.password.focus(false);
this.buttonFocus(false);
this.selectedKey(false);
this.submitRequest(false);
this.selectedKey(false);
this.submitRequest(false);
this.resultCallback = null;
this.privateKeys([]);
};
this.resultCallback = null;
this.privateKeys([]);
};
MessageOpenPgpPopupView.prototype.onBuild = function (oDom)
{
key('tab,shift+tab', Enums.KeyState.PopupMessageOpenPGP, _.bind(function () {
MessageOpenPgpPopupView.prototype.onBuild = function(oDom)
{
key('tab,shift+tab', Enums.KeyState.PopupMessageOpenPGP, _.bind(function() {
switch (true)
{
case this.password.focus():
this.buttonFocus(true);
break;
case this.buttonFocus():
this.password.focus(true);
break;
}
return false;
}, this));
var self = this;
oDom
.on('click', '.key-list__item', function () {
oDom.find('.key-list__item .key-list__item__radio')
.addClass('icon-radio-unchecked')
.removeClass('icon-radio-checked')
;
$(this).find('.key-list__item__radio')
.removeClass('icon-radio-unchecked')
.addClass('icon-radio-checked')
;
self.selectedKey(ko.dataFor(this));
self.password.focus(true);
})
;
};
MessageOpenPgpPopupView.prototype.onHideWithDelay = function ()
{
this.clearPopup();
};
MessageOpenPgpPopupView.prototype.onShowWithDelay = function ()
{
this.password.focus(true);
// this.buttonFocus(true);
};
MessageOpenPgpPopupView.prototype.onShow = function (fCallback, aPrivateKeys)
{
this.clearPopup();
this.resultCallback = fCallback;
this.privateKeys(aPrivateKeys);
if (this.viewModelDom)
switch (true)
{
this.viewModelDom.find('.key-list__item').first().click();
case this.password.focus():
this.buttonFocus(true);
break;
case this.buttonFocus():
this.password.focus(true);
break;
// no default
}
};
module.exports = MessageOpenPgpPopupView;
return false;
}());
}, this));
var self = this;
oDom
.on('click', '.key-list__item', function() {
oDom.find('.key-list__item .key-list__item__radio')
.addClass('icon-radio-unchecked')
.removeClass('icon-radio-checked');
$(this).find('.key-list__item__radio')
.removeClass('icon-radio-unchecked')
.addClass('icon-radio-checked');
self.selectedKey(ko.dataFor(this));
self.password.focus(true);
});
};
MessageOpenPgpPopupView.prototype.onHideWithDelay = function()
{
this.clearPopup();
};
MessageOpenPgpPopupView.prototype.onShowWithDelay = function()
{
this.password.focus(true);
// this.buttonFocus(true);
};
MessageOpenPgpPopupView.prototype.onShow = function(fCallback, aPrivateKeys)
{
this.clearPopup();
this.resultCallback = fCallback;
this.privateKeys(aPrivateKeys);
if (this.viewModelDom)
{
this.viewModelDom.find('.key-list__item').first().click();
}
};
module.exports = MessageOpenPgpPopupView;

View file

@ -1,132 +1,124 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
PgpStore = require('Stores/User/Pgp'),
Utils = require('Common/Utils'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
PgpStore = require('Stores/User/Pgp'),
/**
* @constructor
* @extends AbstractView
*/
function NewOpenPgpKeyPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsNewOpenPgpKey');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.email = ko.observable('');
this.email.focus = ko.observable('');
this.email.error = ko.observable(false);
/**
* @constructor
* @extends AbstractView
*/
function NewOpenPgpKeyPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsNewOpenPgpKey');
this.name = ko.observable('');
this.password = ko.observable('');
this.keyBitLength = ko.observable(2048);
this.email = ko.observable('');
this.email.focus = ko.observable('');
this.email.error = ko.observable(false);
this.submitRequest = 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,
oUserId = {},
oOpenpgpKeyring = PgpStore.openpgpKeyring
;
this.email.error('' === Utils.trim(this.email()));
if (!oOpenpgpKeyring || this.email.error())
{
return false;
}
oUserId.email = this.email();
if ('' !== this.name())
{
oUserId.name = this.name();
}
this.submitRequest(true);
_.delay(function () {
var mPromise = false;
try {
mPromise = PgpStore.openpgp.generateKey({
userIds: [oUserId],
numBits: Utils.pInt(self.keyBitLength()),
passphrase: Utils.trim(self.password())
});
mPromise.then(function (mKeyPair) {
self.submitRequest(false);
if (mKeyPair && mKeyPair.privateKeyArmored)
{
oOpenpgpKeyring.privateKeys.importKey(mKeyPair.privateKeyArmored);
oOpenpgpKeyring.publicKeys.importKey(mKeyPair.publicKeyArmored);
oOpenpgpKeyring.store();
require('App/User').default.reloadOpenPgpKeys();
Utils.delegateRun(self, 'cancelCommand');
}
}).then(null, function() {
self.submitRequest(false);
});
}
catch (e)
{
Utils.log(e);
self.submitRequest(false);
}
}, 100);
return true;
});
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/NewOpenPgpKey', 'PopupsNewOpenPgpKeyViewModel'], NewOpenPgpKeyPopupView);
_.extend(NewOpenPgpKeyPopupView.prototype, AbstractView.prototype);
NewOpenPgpKeyPopupView.prototype.clearPopup = function ()
{
this.name('');
this.password('');
this.email('');
this.email.subscribe(function() {
this.email.error(false);
this.keyBitLength(2048);
};
}, this);
NewOpenPgpKeyPopupView.prototype.onShow = function ()
{
this.clearPopup();
};
this.generateOpenPgpKeyCommand = Utils.createCommand(this, function() {
NewOpenPgpKeyPopupView.prototype.onShowWithDelay = function ()
{
this.email.focus(true);
};
var
self = this,
oUserId = {},
oOpenpgpKeyring = PgpStore.openpgpKeyring;
module.exports = NewOpenPgpKeyPopupView;
this.email.error('' === Utils.trim(this.email()));
if (!oOpenpgpKeyring || this.email.error())
{
return false;
}
}());
oUserId.email = this.email();
if ('' !== this.name())
{
oUserId.name = this.name();
}
this.submitRequest(true);
_.delay(function() {
var mPromise = false;
try {
mPromise = PgpStore.openpgp.generateKey({
userIds: [oUserId],
numBits: Utils.pInt(self.keyBitLength()),
passphrase: Utils.trim(self.password())
});
mPromise.then(function(mKeyPair) {
self.submitRequest(false);
if (mKeyPair && mKeyPair.privateKeyArmored)
{
oOpenpgpKeyring.privateKeys.importKey(mKeyPair.privateKeyArmored);
oOpenpgpKeyring.publicKeys.importKey(mKeyPair.publicKeyArmored);
oOpenpgpKeyring.store();
require('App/User').default.reloadOpenPgpKeys();
Utils.delegateRun(self, 'cancelCommand');
}
}).then(null, function() {
self.submitRequest(false);
});
}
catch (e)
{
Utils.log(e);
self.submitRequest(false);
}
}, 100);
return true;
});
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/NewOpenPgpKey', 'PopupsNewOpenPgpKeyViewModel'], NewOpenPgpKeyPopupView);
_.extend(NewOpenPgpKeyPopupView.prototype, AbstractView.prototype);
NewOpenPgpKeyPopupView.prototype.clearPopup = function()
{
this.name('');
this.password('');
this.email('');
this.email.error(false);
this.keyBitLength(2048);
};
NewOpenPgpKeyPopupView.prototype.onShow = function()
{
this.clearPopup();
};
NewOpenPgpKeyPopupView.prototype.onShowWithDelay = function()
{
this.email.focus(true);
};
module.exports = NewOpenPgpKeyPopupView;

View file

@ -1,175 +1,167 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
key = require('key'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
var
_ = require('_'),
ko = require('ko'),
key = require('key'),
Remote = require('Remote/Admin/Ajax'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Remote = require('Remote/Admin/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function PluginPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsPlugin');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
var self = this;
/**
* @constructor
* @extends AbstractView
*/
function PluginPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsPlugin');
this.onPluginSettingsUpdateResponse = _.bind(this.onPluginSettingsUpdateResponse, this);
var self = this;
this.saveError = ko.observable('');
this.onPluginSettingsUpdateResponse = _.bind(this.onPluginSettingsUpdateResponse, this);
this.name = ko.observable('');
this.readme = ko.observable('');
this.saveError = ko.observable('');
this.configures = ko.observableArray([]);
this.name = ko.observable('');
this.readme = ko.observable('');
this.hasReadme = ko.computed(function() {
return '' !== this.readme();
}, this);
this.configures = ko.observableArray([]);
this.hasConfiguration = ko.computed(function() {
return 0 < this.configures().length;
}, this);
this.hasReadme = ko.computed(function () {
return '' !== this.readme();
}, this);
this.hasConfiguration = ko.computed(function () {
return 0 < this.configures().length;
}, this);
this.readmePopoverConf = {
'placement': 'right',
'trigger': 'hover',
this.readmePopoverConf = {
'placement': 'right',
'trigger': 'hover',
// 'trigger': 'click',
'title': Translator.i18n('POPUPS_PLUGIN/TOOLTIP_ABOUT_TITLE'),
'container': 'body',
'html': true,
'content': function () {
return '<pre>' + self.readme() + '</pre>';
'title': Translator.i18n('POPUPS_PLUGIN/TOOLTIP_ABOUT_TITLE'),
'container': 'body',
'html': true,
'content': function() {
return '<pre>' + self.readme() + '</pre>';
// .replace(/[\r]/g, '').replace(/[\n]/g, '<br />').replace(/[\t]/g, '&nbsp;&nbsp;&nbsp;');
}
};
this.saveCommand = Utils.createCommand(this, function() {
var list = {};
list.Name = this.name();
_.each(this.configures(), function(oItem) {
var value = oItem.value();
if (false === value || true === value)
{
value = value ? '1' : '0';
}
};
this.saveCommand = Utils.createCommand(this, function () {
list['_' + oItem.Name] = value;
var list = {};
}, this);
list.Name = this.name();
this.saveError('');
Remote.pluginSettingsUpdate(this.onPluginSettingsUpdateResponse, list);
_.each(this.configures(), function (oItem) {
}, this.hasConfiguration);
var value = oItem.value();
if (false === value || true === value)
{
value = value ? '1' : '0';
}
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = Enums.KeyState.All;
list['_' + oItem.Name] = value;
this.tryToClosePopup = _.debounce(_.bind(this.tryToClosePopup, this), 200);
}, this);
kn.constructorEnd(this);
}
this.saveError('');
Remote.pluginSettingsUpdate(this.onPluginSettingsUpdateResponse, list);
kn.extendAsViewModel(['View/Popup/Plugin', 'PopupsPluginViewModel'], PluginPopupView);
_.extend(PluginPopupView.prototype, AbstractView.prototype);
}, this.hasConfiguration);
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = Enums.KeyState.All;
this.tryToClosePopup = _.debounce(_.bind(this.tryToClosePopup, this), 200);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Plugin', 'PopupsPluginViewModel'], PluginPopupView);
_.extend(PluginPopupView.prototype, AbstractView.prototype);
PluginPopupView.prototype.onPluginSettingsUpdateResponse = function (sResult, oData)
PluginPopupView.prototype.onPluginSettingsUpdateResponse = function(sResult, oData)
{
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
this.cancelCommand();
}
else
{
this.saveError('');
if (oData && oData.ErrorCode)
{
this.cancelCommand();
this.saveError(Translator.getNotification(oData.ErrorCode));
}
else
{
this.saveError('');
if (oData && oData.ErrorCode)
{
this.saveError(Translator.getNotification(oData.ErrorCode));
}
else
{
this.saveError(Translator.getNotification(Enums.Notification.CantSavePluginSettings));
}
this.saveError(Translator.getNotification(Enums.Notification.CantSavePluginSettings));
}
};
}
};
PluginPopupView.prototype.onShow = function (oPlugin)
PluginPopupView.prototype.onShow = function(oPlugin)
{
this.name();
this.readme();
this.configures([]);
if (oPlugin)
{
this.name();
this.readme();
this.configures([]);
this.name(oPlugin.Name);
this.readme(oPlugin.Readme);
if (oPlugin)
var aConfig = oPlugin.Config;
if (Utils.isNonEmptyArray(aConfig))
{
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]),
'placeholder': ko.observable(aItem[6]),
'Name': aItem[1],
'Type': aItem[2],
'Label': aItem[3],
'Default': aItem[4],
'Desc': aItem[5]
};
}));
}
this.configures(_.map(aConfig, function(aItem) {
return {
'value': ko.observable(aItem[0]),
'placeholder': ko.observable(aItem[6]),
'Name': aItem[1],
'Type': aItem[2],
'Label': aItem[3],
'Default': aItem[4],
'Desc': aItem[5]
};
}));
}
};
}
};
PluginPopupView.prototype.tryToClosePopup = function ()
PluginPopupView.prototype.tryToClosePopup = function()
{
var
self = this,
PopupsAskViewModel = require('View/Popup/Ask');
if (!kn.isPopupVisible(PopupsAskViewModel))
{
var
self = this,
PopupsAskViewModel = require('View/Popup/Ask')
;
kn.showScreenPopup(PopupsAskViewModel, [Translator.i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'), function() {
if (self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
}
}]);
}
};
if (!kn.isPopupVisible(PopupsAskViewModel))
PluginPopupView.prototype.onBuild = function()
{
key('esc', Enums.KeyState.All, _.bind(function() {
if (this.modalVisibility())
{
kn.showScreenPopup(PopupsAskViewModel, [Translator.i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'), function () {
if (self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
}
}]);
this.tryToClosePopup();
}
};
return false;
}, this));
};
PluginPopupView.prototype.onBuild = function ()
{
key('esc', Enums.KeyState.All, _.bind(function () {
if (this.modalVisibility())
{
this.tryToClosePopup();
}
return false;
}, this));
};
module.exports = PluginPopupView;
}());
module.exports = PluginPopupView;

View file

@ -1,205 +1,198 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
HtmlEditor = require('Common/HtmlEditor'),
var
_ = require('_'),
ko = require('ko'),
Remote = require('Remote/User/Ajax'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
HtmlEditor = require('Common/HtmlEditor'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Remote = require('Remote/User/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function TemplatePopupView()
{
AbstractView.call(this, 'Popups', 'PopupsTemplate');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.editor = null;
this.signatureDom = ko.observable(null);
/**
* @constructor
* @extends AbstractView
*/
function TemplatePopupView()
{
AbstractView.call(this, 'Popups', 'PopupsTemplate');
this.id = ko.observable('');
this.editor = null;
this.signatureDom = ko.observable(null);
this.name = ko.observable('');
this.name.error = ko.observable(false);
this.name.focus = ko.observable(false);
this.id = ko.observable('');
this.body = ko.observable('');
this.body.loading = ko.observable(false);
this.body.error = ko.observable(false);
this.name = ko.observable('');
this.name.error = ko.observable(false);
this.name.focus = ko.observable(false);
this.body = ko.observable('');
this.body.loading = ko.observable(false);
this.body.error = ko.observable(false);
this.name.subscribe(function () {
this.name.error(false);
}, this);
this.body.subscribe(function () {
this.body.error(false);
}, this);
this.submitRequest = ko.observable(false);
this.submitError = ko.observable('');
this.addTemplateCommand = Utils.createCommand(this, function () {
this.populateBodyFromEditor();
this.name.error('' === Utils.trim(this.name()));
this.body.error('' === Utils.trim(this.body()) ||
':HTML:' === Utils.trim(this.body()));
if (this.name.error() || this.body.error())
{
return false;
}
this.submitRequest(true);
Remote.templateSetup(_.bind(function (sResult, oData) {
this.submitRequest(false);
if (Enums.StorageResultType.Success === sResult && oData)
{
if (oData.Result)
{
require('App/User').default.templates();
this.cancelCommand();
}
else if (oData.ErrorCode)
{
this.submitError(Translator.getNotification(oData.ErrorCode));
}
}
else
{
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
}
}, this), this.id(), this.name(), this.body());
return true;
}, function () {
return !this.submitRequest();
});
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Template'], TemplatePopupView);
_.extend(TemplatePopupView.prototype, AbstractView.prototype);
TemplatePopupView.prototype.clearPopup = function ()
{
this.id('');
this.name('');
this.name.subscribe(function() {
this.name.error(false);
}, this);
this.body('');
this.body.loading(false);
this.body.subscribe(function() {
this.body.error(false);
}, this);
this.submitRequest(false);
this.submitError('');
this.submitRequest = ko.observable(false);
this.submitError = ko.observable('');
if (this.editor)
this.addTemplateCommand = Utils.createCommand(this, function() {
this.populateBodyFromEditor();
this.name.error('' === Utils.trim(this.name()));
this.body.error('' === Utils.trim(this.body()) ||
':HTML:' === Utils.trim(this.body()));
if (this.name.error() || this.body.error())
{
this.editor.setPlain('', false);
return false;
}
};
TemplatePopupView.prototype.populateBodyFromEditor = function ()
{
if (this.editor)
{
this.body(this.editor.getDataWithHtmlMark());
}
};
this.submitRequest(true);
TemplatePopupView.prototype.editorSetBody = function (sBody)
{
if (!this.editor && this.signatureDom())
{
var self = this;
this.editor = new HtmlEditor(self.signatureDom(), function () {
self.populateBodyFromEditor();
}, function () {
self.editor.setHtmlOrPlain(sBody);
});
}
else
{
this.editor.setHtmlOrPlain(sBody);
}
};
Remote.templateSetup(_.bind(function(sResult, oData) {
TemplatePopupView.prototype.onShow = function (oTemplate)
{
var self = this;
this.clearPopup();
if (oTemplate && oTemplate.id)
{
this.id(oTemplate.id);
this.name(oTemplate.name);
this.body(oTemplate.body);
if (oTemplate.populated)
this.submitRequest(false);
if (Enums.StorageResultType.Success === sResult && oData)
{
self.editorSetBody(this.body());
if (oData.Result)
{
require('App/User').default.templates();
this.cancelCommand();
}
else if (oData.ErrorCode)
{
this.submitError(Translator.getNotification(oData.ErrorCode));
}
}
else
{
this.body.loading(true);
self.body.error(false);
Remote.templateGetById(function (sResult, oData) {
self.body.loading(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result &&
'Object/Template' === oData.Result['@Object'] && Utils.isNormal(oData.Result.Body))
{
oTemplate.body = oData.Result.Body;
oTemplate.populated = true;
self.body(oTemplate.body);
self.body.error(false);
}
else
{
self.body('');
self.body.error(true);
}
self.editorSetBody(self.body());
}, this.id());
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
}
}, this), this.id(), this.name(), this.body());
return true;
}, function() {
return !this.submitRequest();
});
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/Template'], TemplatePopupView);
_.extend(TemplatePopupView.prototype, AbstractView.prototype);
TemplatePopupView.prototype.clearPopup = function()
{
this.id('');
this.name('');
this.name.error(false);
this.body('');
this.body.loading(false);
this.body.error(false);
this.submitRequest(false);
this.submitError('');
if (this.editor)
{
this.editor.setPlain('', false);
}
};
TemplatePopupView.prototype.populateBodyFromEditor = function()
{
if (this.editor)
{
this.body(this.editor.getDataWithHtmlMark());
}
};
TemplatePopupView.prototype.editorSetBody = function(sBody)
{
if (!this.editor && this.signatureDom())
{
var self = this;
this.editor = new HtmlEditor(self.signatureDom(), function() {
self.populateBodyFromEditor();
}, function() {
self.editor.setHtmlOrPlain(sBody);
});
}
else
{
this.editor.setHtmlOrPlain(sBody);
}
};
TemplatePopupView.prototype.onShow = function(oTemplate)
{
var self = this;
this.clearPopup();
if (oTemplate && oTemplate.id)
{
this.id(oTemplate.id);
this.name(oTemplate.name);
this.body(oTemplate.body);
if (oTemplate.populated)
{
self.editorSetBody(this.body());
}
else
{
self.editorSetBody('');
this.body.loading(true);
self.body.error(false);
Remote.templateGetById(function(sResult, oData) {
self.body.loading(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result &&
'Object/Template' === oData.Result['@Object'] && Utils.isNormal(oData.Result.Body))
{
oTemplate.body = oData.Result.Body;
oTemplate.populated = true;
self.body(oTemplate.body);
self.body.error(false);
}
else
{
self.body('');
self.body.error(true);
}
self.editorSetBody(self.body());
}, this.id());
}
};
TemplatePopupView.prototype.onShowWithDelay = function ()
}
else
{
this.name.focus(true);
};
self.editorSetBody('');
}
};
module.exports = TemplatePopupView;
TemplatePopupView.prototype.onShowWithDelay = function()
{
this.name.focus(true);
};
}());
module.exports = TemplatePopupView;

View file

@ -1,249 +1,242 @@
(function () {
var
window = require('window'),
_ = require('_'),
ko = require('ko'),
qr = require('qr'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
var
window = require('window'),
_ = require('_'),
ko = require('ko'),
qr = require('qr'),
Settings = require('Storage/Settings'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
Remote = require('Remote/User/Ajax'),
Settings = require('Storage/Settings'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Remote = require('Remote/User/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function TwoFactorConfigurationPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsTwoFactorConfiguration');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.lock = ko.observable(false);
/**
* @constructor
* @extends AbstractView
*/
function TwoFactorConfigurationPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsTwoFactorConfiguration');
this.capaTwoFactor = Settings.capa(Enums.Capa.TwoFactor);
this.lock = ko.observable(false);
this.processing = ko.observable(false);
this.clearing = ko.observable(false);
this.secreting = ko.observable(false);
this.capaTwoFactor = Settings.capa(Enums.Capa.TwoFactor);
this.viewUser = ko.observable('');
this.twoFactorStatus = ko.observable(false);
this.processing = ko.observable(false);
this.clearing = ko.observable(false);
this.secreting = ko.observable(false);
this.twoFactorTested = ko.observable(false);
this.viewUser = ko.observable('');
this.twoFactorStatus = ko.observable(false);
this.viewSecret = ko.observable('');
this.viewBackupCodes = ko.observable('');
this.viewUrlTitle = ko.observable('');
this.viewUrl = ko.observable('');
this.twoFactorTested = ko.observable(false);
this.viewEnable_ = ko.observable(false);
this.viewSecret = ko.observable('');
this.viewBackupCodes = ko.observable('');
this.viewUrlTitle = ko.observable('');
this.viewUrl = ko.observable('');
this.viewEnable = ko.computed({
'owner': this,
'read': this.viewEnable_,
'write': function(bValue) {
this.viewEnable_ = ko.observable(false);
var self = this;
this.viewEnable = ko.computed({
'owner': this,
'read': this.viewEnable_,
'write': function (bValue) {
bValue = !!bValue;
var self = this;
if (bValue && this.twoFactorTested())
{
this.viewEnable_(bValue);
bValue = !!bValue;
if (bValue && this.twoFactorTested())
{
this.viewEnable_(bValue);
Remote.enableTwoFactor(function (sResult, oData) {
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
self.viewEnable_(false);
}
}, true);
}
else
{
if (!bValue)
Remote.enableTwoFactor(function(sResult, oData) {
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
this.viewEnable_(bValue);
self.viewEnable_(false);
}
Remote.enableTwoFactor(function (sResult, oData) {
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
self.viewEnable_(false);
}
}, false);
}
}, true);
}
});
else
{
if (!bValue)
{
this.viewEnable_(bValue);
}
this.viewTwoFactorEnableTooltip = ko.computed(function () {
Translator.trigger();
return this.twoFactorTested() || this.viewEnable_() ? '' :
Translator.i18n('POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_TEST_BEFORE_DESC');
}, this);
Remote.enableTwoFactor(function(sResult, oData) {
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
self.viewEnable_(false);
}
this.viewTwoFactorStatus = ko.computed(function () {
Translator.trigger();
return Translator.i18n(
this.twoFactorStatus() ?
'POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_CONFIGURED_DESC' :
'POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_NOT_CONFIGURED_DESC'
);
}, this);
}, false);
}
}
});
this.twoFactorAllowedEnable = ko.computed(function () {
return this.viewEnable() || this.twoFactorTested();
}, this);
this.viewTwoFactorEnableTooltip = ko.computed(function() {
Translator.trigger();
return this.twoFactorTested() || this.viewEnable_() ? '' :
Translator.i18n('POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_TEST_BEFORE_DESC');
}, this);
this.onResult = _.bind(this.onResult, this);
this.onShowSecretResult = _.bind(this.onShowSecretResult, this);
this.viewTwoFactorStatus = ko.computed(function() {
Translator.trigger();
return Translator.i18n(
this.twoFactorStatus() ?
'POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_CONFIGURED_DESC' :
'POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_NOT_CONFIGURED_DESC'
);
}, this);
kn.constructorEnd(this);
this.twoFactorAllowedEnable = ko.computed(function() {
return this.viewEnable() || this.twoFactorTested();
}, this);
this.onResult = _.bind(this.onResult, this);
this.onShowSecretResult = _.bind(this.onShowSecretResult, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/TwoFactorConfiguration', 'TwoFactorConfigurationPopupView'], TwoFactorConfigurationPopupView);
_.extend(TwoFactorConfigurationPopupView.prototype, AbstractView.prototype);
TwoFactorConfigurationPopupView.prototype.showSecret = function()
{
this.secreting(true);
Remote.showTwoFactorSecret(this.onShowSecretResult);
};
TwoFactorConfigurationPopupView.prototype.hideSecret = function()
{
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
};
TwoFactorConfigurationPopupView.prototype.createTwoFactor = function()
{
this.processing(true);
Remote.createTwoFactor(this.onResult);
};
TwoFactorConfigurationPopupView.prototype.logout = function()
{
require('App/User').default.logout();
};
TwoFactorConfigurationPopupView.prototype.testTwoFactor = function()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/TwoFactorTest'), [this.twoFactorTested]);
};
TwoFactorConfigurationPopupView.prototype.clearTwoFactor = function()
{
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
this.twoFactorTested(false);
this.clearing(true);
Remote.clearTwoFactor(this.onResult);
};
TwoFactorConfigurationPopupView.prototype.onShow = function(bLock)
{
this.lock(!!bLock);
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
};
TwoFactorConfigurationPopupView.prototype.onHide = function()
{
if (this.lock())
{
window.location.reload();
}
};
kn.extendAsViewModel(['View/Popup/TwoFactorConfiguration', 'TwoFactorConfigurationPopupView'], TwoFactorConfigurationPopupView);
_.extend(TwoFactorConfigurationPopupView.prototype, AbstractView.prototype);
TwoFactorConfigurationPopupView.prototype.getQr = function()
{
return 'otpauth://totp/' + window.encodeURIComponent(this.viewUser()) +
'?secret=' + window.encodeURIComponent(this.viewSecret()) +
'&issuer=' + window.encodeURIComponent('');
};
TwoFactorConfigurationPopupView.prototype.onResult = function(sResult, oData)
{
this.processing(false);
this.clearing(false);
TwoFactorConfigurationPopupView.prototype.showSecret = function ()
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
this.secreting(true);
Remote.showTwoFactorSecret(this.onShowSecretResult);
};
this.viewUser(Utils.pString(oData.Result.User));
this.viewEnable_(!!oData.Result.Enable);
this.twoFactorStatus(!!oData.Result.IsSet);
this.twoFactorTested(!!oData.Result.Tested);
TwoFactorConfigurationPopupView.prototype.hideSecret = function ()
this.viewSecret(Utils.pString(oData.Result.Secret));
this.viewBackupCodes(Utils.pString(oData.Result.BackupCodes).replace(/[\s]+/g, ' '));
this.viewUrlTitle(Utils.pString(oData.Result.UrlTitle));
this.viewUrl(qr.toDataURL({level: 'M', size: 8, value: this.getQr()}));
}
else
{
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
};
TwoFactorConfigurationPopupView.prototype.createTwoFactor = function ()
{
this.processing(true);
Remote.createTwoFactor(this.onResult);
};
TwoFactorConfigurationPopupView.prototype.logout = function ()
{
require('App/User').default.logout();
};
TwoFactorConfigurationPopupView.prototype.testTwoFactor = function ()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/TwoFactorTest'), [this.twoFactorTested]);
};
TwoFactorConfigurationPopupView.prototype.clearTwoFactor = function ()
{
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
this.viewUser('');
this.viewEnable_(false);
this.twoFactorStatus(false);
this.twoFactorTested(false);
this.clearing(true);
Remote.clearTwoFactor(this.onResult);
};
TwoFactorConfigurationPopupView.prototype.onShow = function (bLock)
{
this.lock(!!bLock);
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
};
}
};
TwoFactorConfigurationPopupView.prototype.onHide = function ()
TwoFactorConfigurationPopupView.prototype.onShowSecretResult = function(sResult, oData)
{
this.secreting(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
if (this.lock())
{
window.location.reload();
}
};
TwoFactorConfigurationPopupView.prototype.getQr = function ()
this.viewSecret(Utils.pString(oData.Result.Secret));
this.viewUrlTitle(Utils.pString(oData.Result.UrlTitle));
this.viewUrl(qr.toDataURL({level: 'M', size: 6, value: this.getQr()}));
}
else
{
return 'otpauth://totp/' + window.encodeURIComponent(this.viewUser()) +
'?secret=' + window.encodeURIComponent(this.viewSecret()) +
'&issuer=' + window.encodeURIComponent('');
};
this.viewSecret('');
this.viewUrlTitle('');
this.viewUrl('');
}
};
TwoFactorConfigurationPopupView.prototype.onResult = function (sResult, oData)
TwoFactorConfigurationPopupView.prototype.onBuild = function()
{
if (this.capaTwoFactor)
{
this.processing(false);
this.clearing(false);
this.processing(true);
Remote.getTwoFactor(this.onResult);
}
};
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
this.viewUser(Utils.pString(oData.Result.User));
this.viewEnable_(!!oData.Result.Enable);
this.twoFactorStatus(!!oData.Result.IsSet);
this.twoFactorTested(!!oData.Result.Tested);
this.viewSecret(Utils.pString(oData.Result.Secret));
this.viewBackupCodes(Utils.pString(oData.Result.BackupCodes).replace(/[\s]+/g, ' '));
this.viewUrlTitle(Utils.pString(oData.Result.UrlTitle));
this.viewUrl(qr.toDataURL({level: 'M', size: 8, value: this.getQr()}));
}
else
{
this.viewUser('');
this.viewEnable_(false);
this.twoFactorStatus(false);
this.twoFactorTested(false);
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
}
};
TwoFactorConfigurationPopupView.prototype.onShowSecretResult = function (sResult, oData)
{
this.secreting(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
this.viewSecret(Utils.pString(oData.Result.Secret));
this.viewUrlTitle(Utils.pString(oData.Result.UrlTitle));
this.viewUrl(qr.toDataURL({level: 'M', size: 6, value: this.getQr()}));
}
else
{
this.viewSecret('');
this.viewUrlTitle('');
this.viewUrl('');
}
};
TwoFactorConfigurationPopupView.prototype.onBuild = function ()
{
if (this.capaTwoFactor)
{
this.processing(true);
Remote.getTwoFactor(this.onResult);
}
};
module.exports = TwoFactorConfigurationPopupView;
}());
module.exports = TwoFactorConfigurationPopupView;

View file

@ -1,91 +1,84 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
Remote = require('Remote/User/Ajax'),
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Remote = require('Remote/User/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function TwoFactorTestPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsTwoFactorTest');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
var self = this;
/**
* @constructor
* @extends AbstractView
*/
function TwoFactorTestPopupView()
this.code = ko.observable('');
this.code.focused = ko.observable(false);
this.code.status = ko.observable(null);
this.koTestedTrigger = null;
this.testing = ko.observable(false);
// commands
this.testCode = Utils.createCommand(this, function() {
this.testing(true);
Remote.testTwoFactor(function(sResult, oData) {
self.testing(false);
self.code.status(Enums.StorageResultType.Success === sResult && oData && !!oData.Result);
if (self.koTestedTrigger && self.code.status())
{
self.koTestedTrigger(true);
}
}, this.code());
}, function() {
return '' !== this.code() && !this.testing();
});
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/TwoFactorTest', 'PopupsTwoFactorTestViewModel'], TwoFactorTestPopupView);
_.extend(TwoFactorTestPopupView.prototype, AbstractView.prototype);
TwoFactorTestPopupView.prototype.clearPopup = function()
{
this.code('');
this.code.focused(false);
this.code.status(null);
this.testing(false);
this.koTestedTrigger = null;
};
TwoFactorTestPopupView.prototype.onShow = function(koTestedTrigger)
{
this.clearPopup();
this.koTestedTrigger = koTestedTrigger;
};
TwoFactorTestPopupView.prototype.onShowWithDelay = function()
{
if (!Globals.bMobile)
{
AbstractView.call(this, 'Popups', 'PopupsTwoFactorTest');
var self = this;
this.code = ko.observable('');
this.code.focused = ko.observable(false);
this.code.status = ko.observable(null);
this.koTestedTrigger = null;
this.testing = ko.observable(false);
// commands
this.testCode = Utils.createCommand(this, function () {
this.testing(true);
Remote.testTwoFactor(function (sResult, oData) {
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 () {
return '' !== this.code() && !this.testing();
});
kn.constructorEnd(this);
this.code.focused(true);
}
};
kn.extendAsViewModel(['View/Popup/TwoFactorTest', 'PopupsTwoFactorTestViewModel'], TwoFactorTestPopupView);
_.extend(TwoFactorTestPopupView.prototype, AbstractView.prototype);
TwoFactorTestPopupView.prototype.clearPopup = function ()
{
this.code('');
this.code.focused(false);
this.code.status(null);
this.testing(false);
this.koTestedTrigger = null;
};
TwoFactorTestPopupView.prototype.onShow = function (koTestedTrigger)
{
this.clearPopup();
this.koTestedTrigger = koTestedTrigger;
};
TwoFactorTestPopupView.prototype.onShowWithDelay = function ()
{
if (!Globals.bMobile)
{
this.code.focused(true);
}
};
module.exports = TwoFactorTestPopupView;
}());
module.exports = TwoFactorTestPopupView;

View file

@ -1,71 +1,64 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
key = require('key'),
'use strict';
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
var
_ = require('_'),
ko = require('ko'),
key = require('key'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
/**
* @constructor
* @extends AbstractView
*/
function ViewOpenPgpKeyPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsViewOpenPgpKey');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.key = ko.observable('');
this.keyDom = ko.observable(null);
/**
* @constructor
* @extends AbstractView
*/
function ViewOpenPgpKeyPopupView()
this.sDefaultKeyScope = Enums.KeyState.PopupViewOpenPGP;
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/ViewOpenPgpKey', 'PopupsViewOpenPgpKeyViewModel'], ViewOpenPgpKeyPopupView);
_.extend(ViewOpenPgpKeyPopupView.prototype, AbstractView.prototype);
ViewOpenPgpKeyPopupView.prototype.clearPopup = function()
{
this.key('');
};
ViewOpenPgpKeyPopupView.prototype.selectKey = function()
{
var oEl = this.keyDom();
if (oEl)
{
AbstractView.call(this, 'Popups', 'PopupsViewOpenPgpKey');
this.key = ko.observable('');
this.keyDom = ko.observable(null);
this.sDefaultKeyScope = Enums.KeyState.PopupViewOpenPGP;
kn.constructorEnd(this);
Utils.selectElement(oEl);
}
};
kn.extendAsViewModel(['View/Popup/ViewOpenPgpKey', 'PopupsViewOpenPgpKeyViewModel'], ViewOpenPgpKeyPopupView);
_.extend(ViewOpenPgpKeyPopupView.prototype, AbstractView.prototype);
ViewOpenPgpKeyPopupView.prototype.onShow = function(oOpenPgpKey)
{
this.clearPopup();
ViewOpenPgpKeyPopupView.prototype.clearPopup = function ()
if (oOpenPgpKey)
{
this.key('');
};
this.key(oOpenPgpKey.armor);
}
};
ViewOpenPgpKeyPopupView.prototype.selectKey = function ()
{
var oEl = this.keyDom();
if (oEl)
{
Utils.selectElement(oEl);
}
};
ViewOpenPgpKeyPopupView.prototype.onBuild = function()
{
key('ctrl+a, command+a', Enums.KeyState.PopupViewOpenPGP, _.bind(function() {
this.selectKey();
return false;
}, this));
};
ViewOpenPgpKeyPopupView.prototype.onShow = function (oOpenPgpKey)
{
this.clearPopup();
if (oOpenPgpKey)
{
this.key(oOpenPgpKey.armor);
}
};
ViewOpenPgpKeyPopupView.prototype.onBuild = function ()
{
key('ctrl+a, command+a', Enums.KeyState.PopupViewOpenPGP, _.bind(function () {
this.selectKey();
return false;
}, this));
};
module.exports = ViewOpenPgpKeyPopupView;
}());
module.exports = ViewOpenPgpKeyPopupView;

View file

@ -1,62 +1,56 @@
(function () {
var
_ = require('_'),
ko = require('ko'),
'use strict';
Promises = require('Promises/User/Ajax'),
var
_ = require('_'),
ko = require('ko'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
Promises = require('Promises/User/Ajax'),
/**
* @constructor
* @extends AbstractView
*/
function WelcomePagePopupView()
{
AbstractView.call(this, 'Popups', 'PopupsWelcomePage');
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
this.welcomePageURL = ko.observable('');
/**
* @constructor
* @extends AbstractView
*/
function WelcomePagePopupView()
{
AbstractView.call(this, 'Popups', 'PopupsWelcomePage');
this.closeFocused = ko.observable(false);
this.welcomePageURL = ko.observable('');
kn.constructorEnd(this);
}
this.closeFocused = ko.observable(false);
kn.extendAsViewModel(['View/Popup/WelcomePage', 'WelcomePagePopupViewModel'], WelcomePagePopupView);
_.extend(WelcomePagePopupView.prototype, AbstractView.prototype);
kn.constructorEnd(this);
}
WelcomePagePopupView.prototype.clearPopup = function()
{
this.welcomePageURL('');
this.closeFocused(false);
};
kn.extendAsViewModel(['View/Popup/WelcomePage', 'WelcomePagePopupViewModel'], WelcomePagePopupView);
_.extend(WelcomePagePopupView.prototype, AbstractView.prototype);
/**
* @param {string} sUrl
* @returns {void}
*/
WelcomePagePopupView.prototype.onShow = function(sUrl)
{
this.clearPopup();
WelcomePagePopupView.prototype.clearPopup = function ()
{
this.welcomePageURL('');
this.closeFocused(false);
};
this.welcomePageURL(sUrl);
};
/**
* @param {string} sUrl
*/
WelcomePagePopupView.prototype.onShow = function (sUrl)
{
this.clearPopup();
WelcomePagePopupView.prototype.onShowWithDelay = function()
{
this.closeFocused(true);
};
this.welcomePageURL(sUrl);
};
WelcomePagePopupView.prototype.onHide = function()
{
Promises.welcomeClose();
};
WelcomePagePopupView.prototype.onShowWithDelay = function ()
{
this.closeFocused(true);
};
WelcomePagePopupView.prototype.onHide = function ()
{
Promises.welcomeClose();
};
module.exports = WelcomePagePopupView;
}());
module.exports = WelcomePagePopupView;