mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 12:09:20 +03:00
es5 -> es2015 (last stage)
Signature plugin fixes Add view decorator A large number of fixes
This commit is contained in:
parent
e88c193334
commit
17669b7be0
153 changed files with 21193 additions and 21115 deletions
|
|
@ -1,141 +1,131 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
import _ from '_';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {
|
||||
trim, createCommand,
|
||||
triggerAutocompleteInputChange
|
||||
} from 'Common/Utils';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
Remote = require('Remote/Admin/Ajax'),
|
||||
import {StorageResultType, Notification, Magics} from 'Common/Enums';
|
||||
import {getNotification} from 'Common/Translator';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function LoginAdminView()
|
||||
import Remote from 'Remote/Admin/Ajax';
|
||||
|
||||
import {getApp} from 'Helper/Apps/Admin';
|
||||
|
||||
import {view, ViewType, routeOff} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/Admin/Login',
|
||||
type: ViewType.Center,
|
||||
templateID: 'AdminLogin'
|
||||
})
|
||||
class LoginAdminView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Center', 'AdminLogin');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.logoPowered = !!Settings.settingsGet('LoginPowered');
|
||||
this.logoPowered = !!Settings.settingsGet('LoginPowered');
|
||||
|
||||
this.mobile = !!Settings.appSettingsGet('mobile');
|
||||
this.mobileDevice = !!Settings.appSettingsGet('mobileDevice');
|
||||
this.mobile = !!Settings.appSettingsGet('mobile');
|
||||
this.mobileDevice = !!Settings.appSettingsGet('mobileDevice');
|
||||
|
||||
this.login = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
this.login = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
|
||||
this.loginError = ko.observable(false);
|
||||
this.passwordError = ko.observable(false);
|
||||
this.loginError = ko.observable(false);
|
||||
this.passwordError = ko.observable(false);
|
||||
|
||||
this.loginErrorAnimation = ko.observable(false).extend({'falseTimeout': 500});
|
||||
this.passwordErrorAnimation = ko.observable(false).extend({'falseTimeout': 500});
|
||||
this.loginErrorAnimation = ko.observable(false).extend({'falseTimeout': 500});
|
||||
this.passwordErrorAnimation = ko.observable(false).extend({'falseTimeout': 500});
|
||||
|
||||
this.loginFocus = ko.observable(false);
|
||||
this.loginFocus = ko.observable(false);
|
||||
|
||||
this.formHidden = ko.observable(false);
|
||||
this.formHidden = ko.observable(false);
|
||||
|
||||
this.formError = ko.computed(function() {
|
||||
return this.loginErrorAnimation() || this.passwordErrorAnimation();
|
||||
}, this);
|
||||
this.formError = ko.computed(() => this.loginErrorAnimation() || this.passwordErrorAnimation());
|
||||
|
||||
this.login.subscribe(function() {
|
||||
this.loginError(false);
|
||||
}, this);
|
||||
this.login.subscribe(() => this.loginError(false));
|
||||
|
||||
this.password.subscribe(function() {
|
||||
this.passwordError(false);
|
||||
}, this);
|
||||
this.password.subscribe(() => this.passwordError(false));
|
||||
|
||||
this.loginError.subscribe(function(bV) {
|
||||
this.loginErrorAnimation(!!bV);
|
||||
}, this);
|
||||
this.loginError.subscribe((v) => this.loginErrorAnimation(!!v));
|
||||
|
||||
this.passwordError.subscribe(function(bV) {
|
||||
this.passwordErrorAnimation(!!bV);
|
||||
}, this);
|
||||
this.passwordError.subscribe((v) => {
|
||||
this.passwordErrorAnimation(!!v);
|
||||
});
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
|
||||
this.submitCommand = Utils.createCommand(this, function() {
|
||||
this.submitCommand = createCommand(() => {
|
||||
|
||||
Utils.triggerAutocompleteInputChange();
|
||||
triggerAutocompleteInputChange();
|
||||
|
||||
this.loginError(false);
|
||||
this.passwordError(false);
|
||||
this.loginError(false);
|
||||
this.passwordError(false);
|
||||
|
||||
this.loginError('' === Utils.trim(this.login()));
|
||||
this.passwordError('' === Utils.trim(this.password()));
|
||||
this.loginError('' === trim(this.login()));
|
||||
this.passwordError('' === trim(this.password()));
|
||||
|
||||
if (this.loginError() || this.passwordError())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
Remote.adminLogin(_.bind(function(sResult, oData) {
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && 'AdminLogin' === oData.Action)
|
||||
if (this.loginError() || this.passwordError())
|
||||
{
|
||||
if (oData.Result)
|
||||
return false;
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
Remote.adminLogin((sResult, oData) => {
|
||||
|
||||
if (StorageResultType.Success === sResult && oData && 'AdminLogin' === oData.Action)
|
||||
{
|
||||
require('App/Admin').default.loginAndLogoutReload(true);
|
||||
if (oData.Result)
|
||||
{
|
||||
getApp().loginAndLogoutReload(true);
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
{
|
||||
this.submitRequest(false);
|
||||
this.submitError(getNotification(oData.ErrorCode));
|
||||
}
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
else
|
||||
{
|
||||
this.submitRequest(false);
|
||||
this.submitError(Translator.getNotification(oData.ErrorCode));
|
||||
this.submitError(getNotification(Notification.UnknownError));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitRequest(false);
|
||||
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
|
||||
}
|
||||
|
||||
}, this), this.login(), this.password());
|
||||
}, this.login(), this.password());
|
||||
|
||||
return true;
|
||||
return true;
|
||||
|
||||
}, function() {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
}, () => !this.submitRequest());
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
onShow() {
|
||||
|
||||
routeOff();
|
||||
|
||||
_.delay(() => {
|
||||
this.loginFocus(true);
|
||||
}, Magics.Time100ms);
|
||||
}
|
||||
|
||||
onHide() {
|
||||
this.loginFocus(false);
|
||||
}
|
||||
|
||||
onBuild() {
|
||||
triggerAutocompleteInputChange(true);
|
||||
}
|
||||
|
||||
submitForm() {
|
||||
this.submitCommand();
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Admin/Login', 'AdminLoginViewModel'], LoginAdminView);
|
||||
_.extend(LoginAdminView.prototype, AbstractView.prototype);
|
||||
|
||||
LoginAdminView.prototype.onShow = function()
|
||||
{
|
||||
kn.routeOff();
|
||||
|
||||
_.delay(_.bind(function() {
|
||||
this.loginFocus(true);
|
||||
}, this), Enums.Magics.Time100ms);
|
||||
|
||||
};
|
||||
|
||||
LoginAdminView.prototype.onHide = function()
|
||||
{
|
||||
this.loginFocus(false);
|
||||
};
|
||||
|
||||
LoginAdminView.prototype.onBuild = function()
|
||||
{
|
||||
Utils.triggerAutocompleteInputChange(true);
|
||||
};
|
||||
|
||||
LoginAdminView.prototype.submitForm = function()
|
||||
{
|
||||
this.submitCommand();
|
||||
};
|
||||
|
||||
module.exports = LoginAdminView;
|
||||
export {LoginAdminView, LoginAdminView as default};
|
||||
|
|
|
|||
|
|
@ -1,69 +1,66 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
$ = require('$'),
|
||||
key = require('key'),
|
||||
import _ from '_';
|
||||
import $ from '$';
|
||||
import key from 'key';
|
||||
|
||||
Globals = require('Common/Globals'),
|
||||
Enums = require('Common/Enums'),
|
||||
import {leftPanelDisabled} from 'Common/Globals';
|
||||
import {Magics} from 'Common/Enums';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType, setHash} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {?} oScreen
|
||||
*
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function MenuSettingsAdminView(oScreen)
|
||||
@view({
|
||||
name: 'View/Admin/Settings/Menu',
|
||||
type: ViewType.Left,
|
||||
templateID: 'AdminMenu'
|
||||
})
|
||||
class MenuSettingsAdminView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Left', 'AdminMenu');
|
||||
/**
|
||||
* @param {?} screen
|
||||
*/
|
||||
constructor(screen) {
|
||||
|
||||
this.leftPanelDisabled = Globals.leftPanelDisabled;
|
||||
super();
|
||||
|
||||
this.menu = oScreen.menu;
|
||||
this.leftPanelDisabled = leftPanelDisabled;
|
||||
|
||||
kn.constructorEnd(this);
|
||||
this.menu = screen.menu;
|
||||
}
|
||||
|
||||
link(route) {
|
||||
return '#/' + route;
|
||||
}
|
||||
|
||||
onBuild(dom) {
|
||||
|
||||
key('up, down', _.throttle((event, handler) => {
|
||||
|
||||
const
|
||||
up = handler && 'up' === handler.shortcut,
|
||||
$items = $('.b-admin-menu .e-item', dom);
|
||||
|
||||
if (event && $items.length)
|
||||
{
|
||||
let index = $items.index($items.filter('.selected'));
|
||||
if (up && 0 < index)
|
||||
{
|
||||
index -= 1;
|
||||
}
|
||||
else if (!up && index < $items.length - 1)
|
||||
{
|
||||
index += 1;
|
||||
}
|
||||
|
||||
const sH = $items.eq(index).attr('href');
|
||||
if (sH)
|
||||
{
|
||||
setHash(sH, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
}, Magics.Time200ms));
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Admin/Settings/Menu', 'AdminSettingsMenuViewModel'], MenuSettingsAdminView);
|
||||
_.extend(MenuSettingsAdminView.prototype, AbstractView.prototype);
|
||||
|
||||
MenuSettingsAdminView.prototype.link = function(sRoute)
|
||||
{
|
||||
return '#/' + sRoute;
|
||||
};
|
||||
|
||||
MenuSettingsAdminView.prototype.onBuild = function(oDom)
|
||||
{
|
||||
key('up, down', _.throttle(function(event, handler) {
|
||||
|
||||
var
|
||||
sH = '',
|
||||
bUp = handler && 'up' === handler.shortcut,
|
||||
$items = $('.b-admin-menu .e-item', oDom);
|
||||
|
||||
if (event && $items.length)
|
||||
{
|
||||
var index = $items.index($items.filter('.selected'));
|
||||
if (bUp && 0 < index)
|
||||
{
|
||||
index -= 1;
|
||||
}
|
||||
else if (!bUp && index < $items.length - 1)
|
||||
{
|
||||
index += 1;
|
||||
}
|
||||
|
||||
sH = $items.eq(index).attr('href');
|
||||
if (sH)
|
||||
{
|
||||
kn.setHash(sH, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
}, Enums.Magics.Time200ms));
|
||||
};
|
||||
|
||||
module.exports = MenuSettingsAdminView;
|
||||
export {MenuSettingsAdminView, MenuSettingsAdminView as default};
|
||||
|
|
|
|||
|
|
@ -1,51 +1,55 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
/* global RL_COMMUNITY */
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
Remote = require('Remote/Admin/Ajax'),
|
||||
import ko from 'ko';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function PaneSettingsAdminView()
|
||||
import Remote from 'Remote/Admin/Ajax';
|
||||
|
||||
import DomainStore from 'Stores/Admin/Domain';
|
||||
import PluginStore from 'Stores/Admin/Plugin';
|
||||
import PackageStore from 'Stores/Admin/Package';
|
||||
|
||||
import {getApp} from 'Helper/Apps/Admin';
|
||||
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/Admin/Settings/Pane',
|
||||
type: ViewType.Right,
|
||||
templateID: 'AdminPane'
|
||||
})
|
||||
class PaneSettingsAdminView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Right', 'AdminPane');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.adminDomain = ko.observable(Settings.settingsGet('AdminDomain'));
|
||||
this.version = ko.observable(Settings.appSettingsGet('version'));
|
||||
this.adminDomain = ko.observable(Settings.settingsGet('AdminDomain'));
|
||||
this.version = ko.observable(Settings.appSettingsGet('version'));
|
||||
|
||||
this.capa = !!Settings.settingsGet('PremType');
|
||||
this.community = RL_COMMUNITY;
|
||||
this.capa = !!Settings.settingsGet('PremType');
|
||||
this.community = RL_COMMUNITY;
|
||||
|
||||
this.adminManLoading = ko.computed(function() {
|
||||
return '000' !== [
|
||||
require('Stores/Admin/Domain').domains.loading() ? '1' : '0',
|
||||
require('Stores/Admin/Plugin').plugins.loading() ? '1' : '0',
|
||||
require('Stores/Admin/Package').packages.loading() ? '1' : '0'
|
||||
].join('');
|
||||
}, this);
|
||||
this.adminManLoading = ko.computed(
|
||||
() => '000' !== [
|
||||
DomainStore.domains.loading() ? '1' : '0',
|
||||
PluginStore.plugins.loading() ? '1' : '0',
|
||||
PackageStore.packages.loading() ? '1' : '0'
|
||||
].join('')
|
||||
);
|
||||
|
||||
this.adminManLoadingVisibility = ko.computed(function() {
|
||||
return this.adminManLoading() ? 'visible' : 'hidden';
|
||||
}, this).extend({'rateLimit': 300});
|
||||
this.adminManLoadingVisibility = ko.computed(
|
||||
() => (this.adminManLoading() ? 'visible' : 'hidden')
|
||||
).extend({rateLimit: 300});
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
logoutClick() {
|
||||
Remote.adminLogout(() => {
|
||||
getApp().loginAndLogoutReload(true, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Admin/Settings/Pane', 'AdminSettingsPaneViewModel'], PaneSettingsAdminView);
|
||||
_.extend(PaneSettingsAdminView.prototype, AbstractView.prototype);
|
||||
|
||||
PaneSettingsAdminView.prototype.logoutClick = function()
|
||||
{
|
||||
Remote.adminLogout(function() {
|
||||
require('App/Admin').default.loginAndLogoutReload(true, true);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = PaneSettingsAdminView;
|
||||
export {PaneSettingsAdminView, PaneSettingsAdminView as default};
|
||||
|
|
|
|||
|
|
@ -1,128 +1,121 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {trim, createCommand} from 'Common/Utils';
|
||||
import {getNotification} from 'Common/Translator';
|
||||
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function AccountPopupView()
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/Popup/Account',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsAccount'
|
||||
})
|
||||
class AccountPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsAccount');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.isNew = ko.observable(true);
|
||||
this.isNew = ko.observable(true);
|
||||
|
||||
this.email = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
this.email = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
|
||||
this.emailError = ko.observable(false);
|
||||
this.passwordError = ko.observable(false);
|
||||
this.emailError = ko.observable(false);
|
||||
this.passwordError = ko.observable(false);
|
||||
|
||||
this.email.subscribe(function() {
|
||||
this.emailError(false);
|
||||
}, this);
|
||||
this.email.subscribe(() => {
|
||||
this.emailError(false);
|
||||
});
|
||||
|
||||
this.password.subscribe(function() {
|
||||
this.passwordError(false);
|
||||
}, this);
|
||||
this.password.subscribe(() => {
|
||||
this.passwordError(false);
|
||||
});
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
this.submitErrorAdditional = ko.observable('');
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
this.submitErrorAdditional = ko.observable('');
|
||||
|
||||
this.emailFocus = ko.observable(false);
|
||||
this.emailFocus = ko.observable(false);
|
||||
|
||||
this.addAccountCommand = Utils.createCommand(this, function() {
|
||||
this.addAccountCommand = createCommand(() => {
|
||||
|
||||
this.emailError('' === Utils.trim(this.email()));
|
||||
this.passwordError('' === Utils.trim(this.password()));
|
||||
this.emailError('' === trim(this.email()));
|
||||
this.passwordError('' === trim(this.password()));
|
||||
|
||||
if (this.emailError() || this.passwordError())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
Remote.accountSetup(_.bind(function(sResult, oData) {
|
||||
|
||||
this.submitRequest(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData)
|
||||
if (this.emailError() || this.passwordError())
|
||||
{
|
||||
if (oData.Result)
|
||||
return false;
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
Remote.accountSetup((result, data) => {
|
||||
|
||||
this.submitRequest(false);
|
||||
if (StorageResultType.Success === result && data)
|
||||
{
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
this.cancelCommand();
|
||||
if (data.Result)
|
||||
{
|
||||
getApp().accountsAndIdentities();
|
||||
this.cancelCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitError(data.ErrorCode ? getNotification(data.ErrorCode) :
|
||||
getNotification(Notification.UnknownError));
|
||||
|
||||
if (data.ErrorMessageAdditional)
|
||||
{
|
||||
this.submitErrorAdditional(data.ErrorMessageAdditional);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitError(oData.ErrorCode ? Translator.getNotification(oData.ErrorCode) :
|
||||
Translator.getNotification(Enums.Notification.UnknownError));
|
||||
|
||||
if (oData.ErrorMessageAdditional)
|
||||
{
|
||||
this.submitErrorAdditional(oData.ErrorMessageAdditional);
|
||||
}
|
||||
this.submitError(getNotification(Notification.UnknownError));
|
||||
this.submitErrorAdditional('');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
|
||||
this.submitErrorAdditional('');
|
||||
}
|
||||
|
||||
}, this), this.email(), this.password(), this.isNew());
|
||||
}, this.email(), this.password(), this.isNew());
|
||||
|
||||
return true;
|
||||
return true;
|
||||
|
||||
}, function() {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
}, () => !this.submitRequest());
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
clearPopup() {
|
||||
this.isNew(true);
|
||||
|
||||
this.email('');
|
||||
this.password('');
|
||||
|
||||
this.emailError(false);
|
||||
this.passwordError(false);
|
||||
|
||||
this.submitRequest(false);
|
||||
this.submitError('');
|
||||
this.submitErrorAdditional('');
|
||||
}
|
||||
|
||||
onShow(account) {
|
||||
this.clearPopup();
|
||||
if (account && account.canBeEdit())
|
||||
{
|
||||
this.isNew(false);
|
||||
this.email(account.email);
|
||||
}
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
this.emailFocus(true);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
AccountPopupView.prototype.onShowWithDelay = function()
|
||||
{
|
||||
this.emailFocus(true);
|
||||
};
|
||||
|
||||
module.exports = AccountPopupView;
|
||||
|
|
|
|||
|
|
@ -1,143 +1,130 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Consts = require('Common/Consts'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {trim, isUnd, createCommand} from 'Common/Utils';
|
||||
import {RAINLOOP_TRIAL_KEY} from 'Common/Consts';
|
||||
import {i18n, getNotification} from 'Common/Translator';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
Remote = require('Remote/Admin/Ajax'),
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
LicenseStore = require('Stores/Admin/License'),
|
||||
import Remote from 'Remote/Admin/Ajax';
|
||||
import LicenseStore from 'Stores/Admin/License';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function ActivatePopupView()
|
||||
@view({
|
||||
name: 'View/Popup/Activate',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsActivate'
|
||||
})
|
||||
class ActivatePopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsActivate');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
var self = this;
|
||||
this.domain = ko.observable('');
|
||||
this.key = ko.observable('');
|
||||
this.key.focus = ko.observable(false);
|
||||
this.activationSuccessed = ko.observable(false);
|
||||
|
||||
this.domain = ko.observable('');
|
||||
this.key = ko.observable('');
|
||||
this.key.focus = ko.observable(false);
|
||||
this.activationSuccessed = ko.observable(false);
|
||||
this.licenseTrigger = LicenseStore.licenseTrigger;
|
||||
|
||||
this.licenseTrigger = LicenseStore.licenseTrigger;
|
||||
this.activateProcess = ko.observable(false);
|
||||
this.activateText = ko.observable('');
|
||||
this.activateText.isError = ko.observable(false);
|
||||
|
||||
this.activateProcess = ko.observable(false);
|
||||
this.activateText = ko.observable('');
|
||||
this.activateText.isError = ko.observable(false);
|
||||
this.htmlDescription = ko.computed(() => i18n('POPUPS_ACTIVATE/HTML_DESC', {'DOMAIN': this.domain()}));
|
||||
|
||||
this.htmlDescription = ko.computed(function() {
|
||||
return Translator.i18n('POPUPS_ACTIVATE/HTML_DESC', {'DOMAIN': this.domain()});
|
||||
}, this);
|
||||
this.key.subscribe(() => {
|
||||
this.activateText('');
|
||||
this.activateText.isError(false);
|
||||
});
|
||||
|
||||
this.key.subscribe(function() {
|
||||
this.activateText('');
|
||||
this.activateText.isError(false);
|
||||
}, this);
|
||||
this.activationSuccessed.subscribe((value) => {
|
||||
if (value)
|
||||
{
|
||||
this.licenseTrigger(!this.licenseTrigger());
|
||||
}
|
||||
});
|
||||
|
||||
this.activationSuccessed.subscribe(function(bValue) {
|
||||
if (bValue)
|
||||
{
|
||||
this.licenseTrigger(!this.licenseTrigger());
|
||||
}
|
||||
}, this);
|
||||
this.activateCommand = createCommand(() => {
|
||||
|
||||
this.activateCommand = Utils.createCommand(this, function() {
|
||||
this.activateProcess(true);
|
||||
if (this.validateSubscriptionKey())
|
||||
{
|
||||
Remote.licensingActivate((sResult, oData) => {
|
||||
|
||||
this.activateProcess(true);
|
||||
if (this.validateSubscriptionKey())
|
||||
{
|
||||
Remote.licensingActivate(function(sResult, oData) {
|
||||
|
||||
self.activateProcess(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData.Result)
|
||||
{
|
||||
if (true === oData.Result)
|
||||
this.activateProcess(false);
|
||||
if (StorageResultType.Success === sResult && oData.Result)
|
||||
{
|
||||
self.activationSuccessed(true);
|
||||
self.activateText(Translator.i18n('POPUPS_ACTIVATE/SUBS_KEY_ACTIVATED'));
|
||||
self.activateText.isError(false);
|
||||
if (true === oData.Result)
|
||||
{
|
||||
this.activationSuccessed(true);
|
||||
this.activateText(i18n('POPUPS_ACTIVATE/SUBS_KEY_ACTIVATED'));
|
||||
this.activateText.isError(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.activateText(oData.Result);
|
||||
this.activateText.isError(true);
|
||||
this.key.focus(true);
|
||||
}
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
{
|
||||
this.activateText(getNotification(oData.ErrorCode));
|
||||
this.activateText.isError(true);
|
||||
this.key.focus(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.activateText(oData.Result);
|
||||
self.activateText.isError(true);
|
||||
self.key.focus(true);
|
||||
this.activateText(getNotification(Notification.UnknownError));
|
||||
this.activateText.isError(true);
|
||||
this.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.domain(), this.key());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.activateProcess(false);
|
||||
this.activateText(i18n('POPUPS_ACTIVATE/ERROR_INVALID_SUBS_KEY'));
|
||||
this.activateText.isError(true);
|
||||
this.key.focus(true);
|
||||
}
|
||||
|
||||
}, () => !this.activateProcess() && '' !== this.domain() && '' !== this.key() && !this.activationSuccessed());
|
||||
}
|
||||
|
||||
onShow(isTrial) {
|
||||
this.domain(Settings.settingsGet('AdminDomain'));
|
||||
if (!this.activateProcess())
|
||||
{
|
||||
isTrial = isUnd(isTrial) ? false : !!isTrial;
|
||||
|
||||
this.key(isTrial ? RAINLOOP_TRIAL_KEY : '');
|
||||
this.activateText('');
|
||||
this.activateText.isError(false);
|
||||
this.activationSuccessed(false);
|
||||
}
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
if (!this.activateProcess())
|
||||
{
|
||||
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);
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
validateSubscriptionKey() {
|
||||
const value = this.key();
|
||||
return '' === value || RAINLOOP_TRIAL_KEY === value || !!(/^RL[\d]+-[A-Z0-9\-]+Z$/).test(trim(value));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,108 +1,122 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
import {trim, delegateRun, createCommand, log} from 'Common/Utils';
|
||||
|
||||
Utils = require('Common/Utils'),
|
||||
import PgpStore from 'Stores/User/Pgp';
|
||||
|
||||
PgpStore = require('Stores/User/Pgp'),
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function AddOpenPgpKeyPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/AddOpenPgpKey',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsAddOpenPgpKey'
|
||||
})
|
||||
class AddOpenPgpKeyPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsAddOpenPgpKey');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.key = ko.observable('');
|
||||
this.key.error = ko.observable(false);
|
||||
this.key.focus = ko.observable(false);
|
||||
this.key = ko.observable('');
|
||||
this.key.focus = ko.observable(false);
|
||||
this.key.error = ko.observable(false);
|
||||
this.key.errorMessage = ko.observable('');
|
||||
|
||||
this.key.subscribe(function() {
|
||||
this.key.error(false);
|
||||
}, this);
|
||||
this.key.subscribe(() => {
|
||||
this.key.error(false);
|
||||
this.key.errorMessage('');
|
||||
});
|
||||
|
||||
this.addOpenPgpKeyCommand = Utils.createCommand(this, function() {
|
||||
this.addOpenPgpKeyCommand = createCommand(() => {
|
||||
|
||||
var
|
||||
count = 30,
|
||||
keyTrimmed = 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;
|
||||
const
|
||||
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;
|
||||
|
||||
if (/[\n]/.test(keyTrimmed))
|
||||
{
|
||||
keyTrimmed = keyTrimmed.replace(/[\r]+/g, '').replace(/[\n]{2,}/g, '\n\n');
|
||||
}
|
||||
let keyTrimmed = trim(this.key());
|
||||
|
||||
this.key.error('' === keyTrimmed);
|
||||
|
||||
if (!openpgpKeyring || this.key.error())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var done = false;
|
||||
|
||||
do
|
||||
{
|
||||
var match = reg.exec(keyTrimmed);
|
||||
if (match && 0 < count)
|
||||
if (/[\n]/.test(keyTrimmed))
|
||||
{
|
||||
if (match[0] && match[1] && match[2] && match[1] === match[2])
|
||||
{
|
||||
if ('PRIVATE' === match[1])
|
||||
{
|
||||
openpgpKeyring.privateKeys.importKey(match[0]);
|
||||
}
|
||||
else if ('PUBLIC' === match[1])
|
||||
{
|
||||
openpgpKeyring.publicKeys.importKey(match[0]);
|
||||
}
|
||||
}
|
||||
keyTrimmed = keyTrimmed.replace(/[\r]+/g, '').replace(/[\n]{2,}/g, '\n\n');
|
||||
}
|
||||
|
||||
count -= 1;
|
||||
this.key.error('' === keyTrimmed);
|
||||
this.key.errorMessage('');
|
||||
|
||||
if (!openpgpKeyring || this.key.error())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
let
|
||||
match = null,
|
||||
count = 30,
|
||||
done = false;
|
||||
}
|
||||
else
|
||||
|
||||
do
|
||||
{
|
||||
done = true;
|
||||
match = reg.exec(keyTrimmed);
|
||||
if (match && 0 < count)
|
||||
{
|
||||
if (match[0] && match[1] && match[2] && match[1] === match[2])
|
||||
{
|
||||
let err = null;
|
||||
if ('PRIVATE' === match[1])
|
||||
{
|
||||
err = openpgpKeyring.privateKeys.importKey(match[0]);
|
||||
}
|
||||
else if ('PUBLIC' === match[1])
|
||||
{
|
||||
err = openpgpKeyring.publicKeys.importKey(match[0]);
|
||||
}
|
||||
|
||||
if (err)
|
||||
{
|
||||
this.key.error(true);
|
||||
this.key.errorMessage(err && err[0] ? '' + err[0] : '');
|
||||
log(err);
|
||||
}
|
||||
}
|
||||
|
||||
count -= 1;
|
||||
done = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!done);
|
||||
while (!done);
|
||||
|
||||
openpgpKeyring.store();
|
||||
openpgpKeyring.store();
|
||||
|
||||
require('App/User').default.reloadOpenPgpKeys();
|
||||
Utils.delegateRun(this, 'cancelCommand');
|
||||
getApp().reloadOpenPgpKeys();
|
||||
|
||||
return true;
|
||||
});
|
||||
if (this.key.error())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
delegateRun(this, 'cancelCommand');
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.key('');
|
||||
this.key.error(false);
|
||||
this.key.errorMessage('');
|
||||
}
|
||||
|
||||
onShow() {
|
||||
this.clearPopup();
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
this.key.focus(true);
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/AddOpenPgpKey', 'PopupsAddOpenPgpKeyViewModel'], AddOpenPgpKeyPopupView);
|
||||
_.extend(AddOpenPgpKeyPopupView.prototype, AbstractView.prototype);
|
||||
|
||||
AddOpenPgpKeyPopupView.prototype.clearPopup = function()
|
||||
{
|
||||
this.key('');
|
||||
this.key.error(false);
|
||||
};
|
||||
|
||||
AddOpenPgpKeyPopupView.prototype.onShow = function()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
AddOpenPgpKeyPopupView.prototype.onShowWithDelay = function()
|
||||
{
|
||||
this.key.focus(true);
|
||||
};
|
||||
|
||||
module.exports = AddOpenPgpKeyPopupView;
|
||||
|
|
|
|||
|
|
@ -1,187 +1,174 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {trim, createCommand} from 'Common/Utils';
|
||||
import {i18n, trigger as translatorTrigger} from 'Common/Translator';
|
||||
import {searchSubtractFormatDateHelper} from 'Common/Momentor';
|
||||
|
||||
MessageStore = require('Stores/User/Message'),
|
||||
import MessageStore from 'Stores/User/Message';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function AdvancedSearchPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/AdvancedSearch',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsAdvancedSearch'
|
||||
})
|
||||
class AdvancedSearchPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsAdvancedSearch');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.fromFocus = ko.observable(false);
|
||||
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.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.hasAttachment = ko.observable(false);
|
||||
this.starred = ko.observable(false);
|
||||
this.unseen = ko.observable(false);
|
||||
|
||||
this.searchCommand = Utils.createCommand(this, function() {
|
||||
this.searchCommand = createCommand(() => {
|
||||
const search = this.buildSearchString();
|
||||
if ('' !== search)
|
||||
{
|
||||
MessageStore.mainMessageListSearch(search);
|
||||
}
|
||||
|
||||
var sSearch = this.buildSearchString();
|
||||
if ('' !== sSearch)
|
||||
this.cancelCommand();
|
||||
});
|
||||
|
||||
this.selectedDates = ko.computed(() => {
|
||||
translatorTrigger();
|
||||
return [
|
||||
{id: -1, name: i18n('SEARCH/LABEL_ADV_DATE_ALL')},
|
||||
{id: 3, name: i18n('SEARCH/LABEL_ADV_DATE_3_DAYS')},
|
||||
{id: 7, name: i18n('SEARCH/LABEL_ADV_DATE_7_DAYS')},
|
||||
{id: 30, name: i18n('SEARCH/LABEL_ADV_DATE_MONTH')},
|
||||
{id: 90, name: i18n('SEARCH/LABEL_ADV_DATE_3_MONTHS')},
|
||||
{id: 180, name: i18n('SEARCH/LABEL_ADV_DATE_6_MONTHS')},
|
||||
{id: 365, name: i18n('SEARCH/LABEL_ADV_DATE_YEAR')}
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
parseSearchStringValue(search) {
|
||||
const parts = (search || '').split(/[\s]+/g);
|
||||
_.each(parts, (part) => {
|
||||
switch (part)
|
||||
{
|
||||
case 'has:attachment':
|
||||
this.hasAttachment(true);
|
||||
break;
|
||||
case 'is:unseen,flagged':
|
||||
this.starred(true);
|
||||
/* falls through */
|
||||
case 'is:unseen':
|
||||
this.unseen(true);
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
buildSearchStringValue(value) {
|
||||
if (-1 < value.indexOf(' '))
|
||||
{
|
||||
MessageStore.mainMessageListSearch(sSearch);
|
||||
value = '"' + value + '"';
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
buildSearchString() {
|
||||
const
|
||||
result = [],
|
||||
from_ = trim(this.from()),
|
||||
to = trim(this.to()),
|
||||
subject = trim(this.subject()),
|
||||
text = trim(this.text()),
|
||||
isPart = [],
|
||||
hasPart = [];
|
||||
|
||||
if (from_ && '' !== from_)
|
||||
{
|
||||
result.push('from:' + this.buildSearchStringValue(from_));
|
||||
}
|
||||
|
||||
this.cancelCommand();
|
||||
});
|
||||
if (to && '' !== to)
|
||||
{
|
||||
result.push('to:' + this.buildSearchStringValue(to));
|
||||
}
|
||||
|
||||
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);
|
||||
if (subject && '' !== subject)
|
||||
{
|
||||
result.push('subject:' + this.buildSearchStringValue(subject));
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
if (this.hasAttachment())
|
||||
{
|
||||
hasPart.push('attachment');
|
||||
}
|
||||
|
||||
if (this.unseen())
|
||||
{
|
||||
isPart.push('unseen');
|
||||
}
|
||||
|
||||
if (this.starred())
|
||||
{
|
||||
isPart.push('flagged');
|
||||
}
|
||||
|
||||
if (0 < hasPart.length)
|
||||
{
|
||||
result.push('has:' + hasPart.join(','));
|
||||
}
|
||||
|
||||
if (0 < isPart.length)
|
||||
{
|
||||
result.push('is:' + isPart.join(','));
|
||||
}
|
||||
|
||||
if (-1 < this.selectedDateValue())
|
||||
{
|
||||
result.push('date:' + searchSubtractFormatDateHelper(this.selectedDateValue()) + '/');
|
||||
}
|
||||
|
||||
if (text && '' !== text)
|
||||
{
|
||||
result.push('text:' + this.buildSearchStringValue(text));
|
||||
}
|
||||
|
||||
return trim(result.join(' '));
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.from('');
|
||||
this.to('');
|
||||
this.subject('');
|
||||
this.text('');
|
||||
|
||||
this.selectedDateValue(-1);
|
||||
this.hasAttachment(false);
|
||||
this.starred(false);
|
||||
this.unseen(false);
|
||||
|
||||
this.fromFocus(true);
|
||||
}
|
||||
|
||||
onShow(search) {
|
||||
this.clearPopup();
|
||||
this.parseSearchStringValue(search);
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
this.fromFocus(true);
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/AdvancedSearch', 'PopupsAdvancedSearchViewModel'], AdvancedSearchPopupView);
|
||||
_.extend(AdvancedSearchPopupView.prototype, AbstractView.prototype);
|
||||
|
||||
AdvancedSearchPopupView.prototype.parseSearchStringValue = function(search)
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
parts = (search || '').split(/[\s]+/g);
|
||||
|
||||
_.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
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
AdvancedSearchPopupView.prototype.buildSearchStringValue = function(sValue)
|
||||
{
|
||||
if (-1 < sValue.indexOf(' '))
|
||||
{
|
||||
sValue = '"' + sValue + '"';
|
||||
}
|
||||
|
||||
return sValue;
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,134 +1,125 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
key = require('key'),
|
||||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {KeyState} from 'Common/Enums';
|
||||
import {isFunc} from 'Common/Utils';
|
||||
import {i18n} from 'Common/Translator';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function AskPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/Ask',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsAsk'
|
||||
})
|
||||
class AskPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsAsk');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.askDesc = ko.observable('');
|
||||
this.yesButton = ko.observable('');
|
||||
this.noButton = ko.observable('');
|
||||
this.askDesc = ko.observable('');
|
||||
this.yesButton = ko.observable('');
|
||||
this.noButton = ko.observable('');
|
||||
|
||||
this.yesFocus = ko.observable(false);
|
||||
this.noFocus = ko.observable(false);
|
||||
this.yesFocus = ko.observable(false);
|
||||
this.noFocus = ko.observable(false);
|
||||
|
||||
this.fYesAction = null;
|
||||
this.fNoAction = null;
|
||||
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))
|
||||
{
|
||||
this.fYesAction.call(null);
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
* @returns {void}
|
||||
*/
|
||||
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);
|
||||
this.bFocusYesOnShow = true;
|
||||
this.bDisabeCloseOnEsc = true;
|
||||
this.sDefaultKeyScope = KeyState.PopupAsk;
|
||||
}
|
||||
|
||||
if (sNoButton)
|
||||
{
|
||||
this.noButton(sNoButton);
|
||||
clearPopup() {
|
||||
this.askDesc('');
|
||||
this.yesButton(i18n('POPUPS_ASK/BUTTON_YES'));
|
||||
this.noButton(i18n('POPUPS_ASK/BUTTON_NO'));
|
||||
|
||||
this.yesFocus(false);
|
||||
this.noFocus(false);
|
||||
|
||||
this.fYesAction = null;
|
||||
this.fNoAction = null;
|
||||
}
|
||||
|
||||
this.bFocusYesOnShow = Utils.isUnd(bFocusYesOnShow) ? true : !!bFocusYesOnShow;
|
||||
};
|
||||
yesClick() {
|
||||
this.cancelCommand();
|
||||
|
||||
AskPopupView.prototype.onShowWithDelay = function()
|
||||
{
|
||||
if (this.bFocusYesOnShow)
|
||||
{
|
||||
this.yesFocus(true);
|
||||
}
|
||||
};
|
||||
|
||||
AskPopupView.prototype.onBuild = function()
|
||||
{
|
||||
key('tab, shift+tab, right, left', Enums.KeyState.PopupAsk, _.bind(function() {
|
||||
if (this.yesFocus())
|
||||
if (isFunc(this.fYesAction))
|
||||
{
|
||||
this.noFocus(true);
|
||||
this.fYesAction.call(null);
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
noClick() {
|
||||
this.cancelCommand();
|
||||
|
||||
if (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 = true
|
||||
* @returns {void}
|
||||
*/
|
||||
onShow(askDesc, fYesFunc = null, fNoFunc = null, yesButton = '', noButton = '', isFocusYesOnShow = true) {
|
||||
|
||||
this.clearPopup();
|
||||
|
||||
this.fYesAction = fYesFunc || null;
|
||||
this.fNoAction = fNoFunc || null;
|
||||
|
||||
this.askDesc(askDesc || '');
|
||||
|
||||
if (yesButton)
|
||||
{
|
||||
this.yesButton(yesButton);
|
||||
}
|
||||
|
||||
if (noButton)
|
||||
{
|
||||
this.noButton(noButton);
|
||||
}
|
||||
|
||||
this.bFocusYesOnShow = !!isFocusYesOnShow;
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
if (this.bFocusYesOnShow)
|
||||
{
|
||||
this.yesFocus(true);
|
||||
}
|
||||
return false;
|
||||
}, this));
|
||||
}
|
||||
|
||||
key('esc', Enums.KeyState.PopupAsk, _.bind(function() {
|
||||
this.noClick();
|
||||
return false;
|
||||
}, this));
|
||||
};
|
||||
onBuild() {
|
||||
key('tab, shift+tab, right, left', KeyState.PopupAsk, () => {
|
||||
if (this.yesFocus())
|
||||
{
|
||||
this.noFocus(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.yesFocus(true);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
key('esc', KeyState.PopupAsk, () => {
|
||||
this.noClick();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AskPopupView;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,475 +1,460 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
$ = require('$'),
|
||||
ko = require('ko'),
|
||||
key = require('key'),
|
||||
import _ from '_';
|
||||
import $ from '$';
|
||||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
|
||||
Utils = require('Common/Utils'),
|
||||
Enums = require('Common/Enums'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {
|
||||
inArray, createCommand,
|
||||
pString, log, isUnd, trim,
|
||||
defautOptionsAfterRender
|
||||
} from 'Common/Utils';
|
||||
|
||||
PgpStore = require('Stores/User/Pgp'),
|
||||
import {Magics, KeyState} from 'Common/Enums';
|
||||
import {i18n} from 'Common/Translator';
|
||||
|
||||
EmailModel = require('Model/Email').default,
|
||||
import PgpStore from 'Stores/User/Pgp';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {EmailModel} from 'Model/Email';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function ComposeOpenPgpPopupView()
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/Popup/ComposeOpenPgp',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsComposeOpenPgp'
|
||||
})
|
||||
class ComposeOpenPgpPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsComposeOpenPgp');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
var self = this;
|
||||
this.publicKeysOptionsCaption = i18n('PGP_NOTIFICATIONS/ADD_A_PUBLICK_KEY');
|
||||
this.privateKeysOptionsCaption = i18n('PGP_NOTIFICATIONS/SELECT_A_PRIVATE_KEY');
|
||||
|
||||
this.publicKeysOptionsCaption = Translator.i18n('PGP_NOTIFICATIONS/ADD_A_PUBLICK_KEY');
|
||||
this.privateKeysOptionsCaption = Translator.i18n('PGP_NOTIFICATIONS/SELECT_A_PRIVATE_KEY');
|
||||
this.notification = ko.observable('');
|
||||
|
||||
this.notification = ko.observable('');
|
||||
this.sign = ko.observable(false);
|
||||
this.encrypt = ko.observable(false);
|
||||
|
||||
this.sign = ko.observable(false);
|
||||
this.encrypt = ko.observable(false);
|
||||
this.password = ko.observable('');
|
||||
this.password.focus = ko.observable(false);
|
||||
this.buttonFocus = ko.observable(false);
|
||||
|
||||
this.password = ko.observable('');
|
||||
this.password.focus = ko.observable(false);
|
||||
this.buttonFocus = ko.observable(false);
|
||||
this.text = ko.observable('');
|
||||
this.selectedPrivateKey = ko.observable(null);
|
||||
this.selectedPublicKey = ko.observable(null);
|
||||
|
||||
this.text = ko.observable('');
|
||||
this.selectedPrivateKey = ko.observable(null);
|
||||
this.selectedPublicKey = ko.observable(null);
|
||||
this.signKey = ko.observable(null);
|
||||
this.encryptKeys = ko.observableArray([]);
|
||||
|
||||
this.signKey = ko.observable(null);
|
||||
this.encryptKeys = ko.observableArray([]);
|
||||
this.encryptKeysView = ko.computed(
|
||||
() => _.compact(_.map(this.encryptKeys(), (oKey) => (oKey ? oKey.key : null)))
|
||||
);
|
||||
|
||||
this.encryptKeysView = ko.computed(function() {
|
||||
return _.compact(_.map(this.encryptKeys(), function(oKey) {
|
||||
return oKey ? oKey.key : null;
|
||||
}));
|
||||
}, this);
|
||||
|
||||
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 {
|
||||
this.privateKeysOptions = ko.computed(() => {
|
||||
const opts = _.map(PgpStore.openpgpkeysPrivate(), (oKey, iIndex) => {
|
||||
if (this.signKey() && this.signKey().key.id === oKey.id)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _.map(oKey.users, (user) => ({
|
||||
'id': oKey.guid,
|
||||
'name': '(' + oKey.id.substr(-8).toUpperCase() + ') ' + sUser,
|
||||
'name': '(' + oKey.id.substr(-8).toUpperCase() + ') ' + user,
|
||||
'key': oKey,
|
||||
'class': iIndex % 2 ? 'odd' : 'even'
|
||||
};
|
||||
});
|
||||
}), true));
|
||||
});
|
||||
|
||||
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.submitRequest = ko.observable(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
|
||||
// commands
|
||||
this.doCommand = Utils.createCommand(this, function() {
|
||||
|
||||
var
|
||||
bResult = true,
|
||||
oPrivateKey = null,
|
||||
aPublicKeys = [];
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
if (bResult && this.sign())
|
||||
{
|
||||
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;
|
||||
}
|
||||
return _.compact(_.flatten(opts, true));
|
||||
});
|
||||
|
||||
if (bResult)
|
||||
{
|
||||
var aPrivateKeys = this.signKey().key.getNativeKeys();
|
||||
oPrivateKey = aPrivateKeys[0] || null;
|
||||
|
||||
try
|
||||
this.publicKeysOptions = ko.computed(() => {
|
||||
const opts = _.map(PgpStore.openpgpkeysPublic(), (oKey, index) => {
|
||||
if (-1 < inArray(oKey, this.encryptKeysView()))
|
||||
{
|
||||
if (oPrivateKey)
|
||||
{
|
||||
oPrivateKey.decrypt(Utils.pString(this.password()));
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
oPrivateKey = null;
|
||||
return null;
|
||||
}
|
||||
return _.map(oKey.users, (user) => ({
|
||||
'id': oKey.guid,
|
||||
'name': '(' + oKey.id.substr(-8).toUpperCase() + ') ' + user,
|
||||
'key': oKey,
|
||||
'class': index % 2 ? 'odd' : 'even'
|
||||
}));
|
||||
});
|
||||
return _.compact(_.flatten(opts, true));
|
||||
});
|
||||
|
||||
if (!oPrivateKey)
|
||||
{
|
||||
this.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND'));
|
||||
bResult = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.submitRequest = ko.observable(false);
|
||||
|
||||
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())
|
||||
{
|
||||
this.resultCallback = null;
|
||||
|
||||
// commands
|
||||
this.doCommand = createCommand(() => {
|
||||
|
||||
let
|
||||
result = true,
|
||||
privateKey = null,
|
||||
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
|
||||
}));
|
||||
this.submitRequest(true);
|
||||
|
||||
bResult = false;
|
||||
}
|
||||
});
|
||||
|
||||
if (bResult && (0 === aPublicKeys.length || this.encryptKeys().length !== aPublicKeys.length))
|
||||
if (result && this.sign())
|
||||
{
|
||||
if (!this.signKey())
|
||||
{
|
||||
bResult = false;
|
||||
this.notification(i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND'));
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bResult && self.resultCallback)
|
||||
{
|
||||
_.delay(function() {
|
||||
|
||||
var oPromise = null;
|
||||
|
||||
try
|
||||
else if (!this.signKey().key)
|
||||
{
|
||||
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
|
||||
this.notification(i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND_FOR', {
|
||||
'EMAIL': this.signKey().email
|
||||
}));
|
||||
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (oPromise)
|
||||
if (result)
|
||||
{
|
||||
const privateKeys = this.signKey().key.getNativeKeys();
|
||||
privateKey = privateKeys[0] || null;
|
||||
|
||||
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
|
||||
}));
|
||||
});
|
||||
if (privateKey)
|
||||
{
|
||||
privateKey.decrypt(pString(this.password()));
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
|
||||
privateKey = null;
|
||||
}
|
||||
|
||||
if (!privateKey)
|
||||
{
|
||||
this.notification(i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND'));
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result && this.encrypt())
|
||||
{
|
||||
if (0 === this.encryptKeys().length)
|
||||
{
|
||||
this.notification(i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND'));
|
||||
result = false;
|
||||
}
|
||||
else if (this.encryptKeys())
|
||||
{
|
||||
aPublicKeys = [];
|
||||
|
||||
_.each(this.encryptKeys(), (oKey) => {
|
||||
if (oKey && oKey.key)
|
||||
{
|
||||
aPublicKeys = aPublicKeys.concat(_.compact(_.flatten(oKey.key.getNativeKeys())));
|
||||
}
|
||||
else if (oKey && oKey.email)
|
||||
{
|
||||
this.notification(i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND_FOR', {
|
||||
'EMAIL': oKey.email
|
||||
}));
|
||||
|
||||
result = false;
|
||||
}
|
||||
});
|
||||
|
||||
if (result && (0 === aPublicKeys.length || this.encryptKeys().length !== aPublicKeys.length))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result && this.resultCallback)
|
||||
{
|
||||
_.delay(() => {
|
||||
|
||||
let pgpPromise = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (privateKey && 0 === aPublicKeys.length)
|
||||
{
|
||||
pgpPromise = PgpStore.openpgp.sign({
|
||||
data: this.text(),
|
||||
privateKeys: [privateKey]
|
||||
});
|
||||
}
|
||||
else if (privateKey && 0 < aPublicKeys.length)
|
||||
{
|
||||
pgpPromise = PgpStore.openpgp.encrypt({
|
||||
data: this.text(),
|
||||
publicKeys: aPublicKeys,
|
||||
privateKeys: [privateKey]
|
||||
});
|
||||
}
|
||||
else if (!privateKey && 0 < aPublicKeys.length)
|
||||
{
|
||||
pgpPromise = PgpStore.openpgp.encrypt({
|
||||
data: this.text(),
|
||||
publicKeys: aPublicKeys
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
log(e);
|
||||
|
||||
this.notification(i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
|
||||
'ERROR': '' + e
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
self.submitRequest(false);
|
||||
if (pgpPromise)
|
||||
{
|
||||
try
|
||||
{
|
||||
pgpPromise.then((mData) => {
|
||||
this.resultCallback(mData.data);
|
||||
this.cancelCommand();
|
||||
}).catch((e) => {
|
||||
this.notification(i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
|
||||
'ERROR': '' + e
|
||||
}));
|
||||
});
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
this.notification(i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
|
||||
'ERROR': '' + e
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
}, Enums.Magics.Time20ms);
|
||||
this.submitRequest(false);
|
||||
|
||||
}, Magics.Time20ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitRequest(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}, () => !this.submitRequest() && (this.sign() || this.encrypt()));
|
||||
|
||||
this.selectCommand = createCommand(() => {
|
||||
|
||||
const
|
||||
keyId = this.selectedPrivateKey(),
|
||||
option = keyId ? _.find(this.privateKeysOptions(), (oItem) => oItem && keyId === oItem.id) : null;
|
||||
|
||||
if (option)
|
||||
{
|
||||
this.signKey({
|
||||
'empty': !option.key,
|
||||
'selected': ko.observable(!!option.key),
|
||||
'users': option.key.users,
|
||||
'hash': option.key.id.substr(-8).toUpperCase(),
|
||||
'key': option.key
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.addCommand = createCommand(() => {
|
||||
|
||||
const
|
||||
keyId = this.selectedPublicKey(),
|
||||
keys = this.encryptKeys(),
|
||||
option = keyId ? _.find(this.publicKeysOptions(), (item) => (item && keyId === item.id)) : null;
|
||||
|
||||
if (option)
|
||||
{
|
||||
keys.push({
|
||||
'empty': !option.key,
|
||||
'selected': ko.observable(!!option.key),
|
||||
'removable': ko.observable(!this.sign() || !this.signKey() || this.signKey().key.id !== option.key.id),
|
||||
'users': option.key.users,
|
||||
'hash': option.key.id.substr(-8).toUpperCase(),
|
||||
'key': option.key
|
||||
});
|
||||
|
||||
this.encryptKeys(keys);
|
||||
}
|
||||
});
|
||||
|
||||
this.updateCommand = createCommand(() => {
|
||||
_.each(this.encryptKeys(), (oKey) => {
|
||||
oKey.removable(!this.sign() || !this.signKey() || this.signKey().key.id !== oKey.key.id);
|
||||
});
|
||||
});
|
||||
|
||||
this.selectedPrivateKey.subscribe((value) => {
|
||||
if (value)
|
||||
{
|
||||
this.selectCommand();
|
||||
this.updateCommand();
|
||||
}
|
||||
});
|
||||
|
||||
this.selectedPublicKey.subscribe((value) => {
|
||||
if (value)
|
||||
{
|
||||
this.addCommand();
|
||||
}
|
||||
});
|
||||
|
||||
this.sDefaultKeyScope = KeyState.PopupComposeOpenPGP;
|
||||
|
||||
this.defautOptionsAfterRender = defautOptionsAfterRender;
|
||||
|
||||
this.addOptionClass = (domOption, item) => {
|
||||
|
||||
this.defautOptionsAfterRender(domOption, item);
|
||||
|
||||
if (item && !isUnd(item.class) && domOption)
|
||||
{
|
||||
$(domOption).addClass(item.class);
|
||||
}
|
||||
};
|
||||
|
||||
this.deletePublickKey = _.bind(this.deletePublickKey, this);
|
||||
}
|
||||
|
||||
deletePublickKey(publicKey) {
|
||||
this.encryptKeys.remove(publicKey);
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
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;
|
||||
}
|
||||
|
||||
onBuild() {
|
||||
key('tab,shift+tab', KeyState.PopupComposeOpenPGP, () => {
|
||||
switch (true)
|
||||
{
|
||||
case this.password.focus():
|
||||
this.buttonFocus(true);
|
||||
break;
|
||||
case this.buttonFocus():
|
||||
this.password.focus(true);
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
onHideWithDelay() {
|
||||
this.clearPopup();
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
if (this.sign())
|
||||
{
|
||||
this.password.focus(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.submitRequest(false);
|
||||
}
|
||||
|
||||
return bResult;
|
||||
|
||||
}, function() {
|
||||
return !this.submitRequest() && (this.sign() || this.encrypt());
|
||||
});
|
||||
|
||||
this.selectCommand = Utils.createCommand(this, function() {
|
||||
|
||||
var
|
||||
sKeyId = this.selectedPrivateKey(),
|
||||
oOption = sKeyId ? _.find(this.privateKeysOptions(), function(oItem) {
|
||||
return oItem && sKeyId === oItem.id;
|
||||
}) : null;
|
||||
|
||||
if (oOption)
|
||||
{
|
||||
this.signKey({
|
||||
'empty': !oOption.key,
|
||||
'selected': ko.observable(!!oOption.key),
|
||||
'users': oOption.key.users,
|
||||
'hash': oOption.key.id.substr(-8).toUpperCase(),
|
||||
'key': oOption.key
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
// 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 = '',
|
||||
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);
|
||||
|
||||
var 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.buttonFocus(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.signKey())
|
||||
{
|
||||
this.sign(true);
|
||||
}
|
||||
onShow(fCallback, sText, identity, sTo, sCc, sBcc) {
|
||||
|
||||
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;
|
||||
this.clearPopup();
|
||||
|
||||
let
|
||||
rec = [],
|
||||
emailLine = '';
|
||||
|
||||
const email = new EmailModel();
|
||||
|
||||
this.resultCallback = fCallback;
|
||||
|
||||
if ('' !== sTo)
|
||||
{
|
||||
rec.push(sTo);
|
||||
}
|
||||
|
||||
if ('' !== sCc)
|
||||
{
|
||||
rec.push(sCc);
|
||||
}
|
||||
|
||||
if ('' !== sBcc)
|
||||
{
|
||||
rec.push(sBcc);
|
||||
}
|
||||
|
||||
rec = rec.join(', ').split(',');
|
||||
rec = _.compact(_.map(rec, (value) => {
|
||||
email.clear();
|
||||
email.mailsoParse(trim(value));
|
||||
return '' === email.email ? false : email.email;
|
||||
}));
|
||||
|
||||
if (0 < this.encryptKeys().length)
|
||||
if (identity && identity.email())
|
||||
{
|
||||
this.encrypt(true);
|
||||
}
|
||||
}
|
||||
emailLine = identity.email();
|
||||
rec.unshift(emailLine);
|
||||
|
||||
this.text(sText);
|
||||
};
|
||||
const keys = PgpStore.findAllPrivateKeysByEmailNotNative(emailLine);
|
||||
if (keys && keys[0])
|
||||
{
|
||||
this.signKey({
|
||||
'users': keys[0].users || [emailLine],
|
||||
'hash': keys[0].id.substr(-8).toUpperCase(),
|
||||
'key': keys[0]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (this.signKey())
|
||||
{
|
||||
this.sign(true);
|
||||
}
|
||||
|
||||
if (rec && 0 < rec.length)
|
||||
{
|
||||
this.encryptKeys(_.uniq(_.compact(_.flatten(_.map(rec, (recEmail) => {
|
||||
const keys = PgpStore.findAllPublicKeysByEmailNotNative(recEmail);
|
||||
return keys ? _.map(keys, (oKey) => ({
|
||||
'empty': !oKey,
|
||||
'selected': ko.observable(!!oKey),
|
||||
'removable': ko.observable(!this.sign() || !this.signKey() || this.signKey().key.id !== oKey.id),
|
||||
'users': oKey ? (oKey.users || [recEmail]) : [recEmail],
|
||||
'hash': oKey ? oKey.id.substr(-8).toUpperCase() : '',
|
||||
'key': oKey
|
||||
})) : [];
|
||||
}), true)), (encryptKey) => encryptKey.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
|
|
@ -1,483 +1,465 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Consts = require('Common/Consts'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
import {StorageResultType, ServerSecure, Ports, Notification} from 'Common/Enums';
|
||||
import {IMAP_DEFAULT_PORT, SIEVE_DEFAULT_PORT, SMTP_DEFAULT_PORT} from 'Common/Consts';
|
||||
import {bMobileDevice} from 'Common/Globals';
|
||||
import {createCommand, trim, pInt, pString} from 'Common/Utils';
|
||||
import {i18n} from 'Common/Translator';
|
||||
|
||||
Translator = require('Common/Translator'),
|
||||
import CapaAdminStore from 'Stores/Admin/Capa';
|
||||
|
||||
CapaAdminStore = require('Stores/Admin/Capa'),
|
||||
import Remote from 'Remote/Admin/Ajax';
|
||||
|
||||
Remote = require('Remote/Admin/Ajax'),
|
||||
import {getApp} from 'Helper/Apps/Admin';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function DomainPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/Domain',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsDomain'
|
||||
})
|
||||
class DomainPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsDomain');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
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.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.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)
|
||||
this.testingImapError.subscribe((value) => {
|
||||
if (!value)
|
||||
{
|
||||
sResult += ' ← ' + sAliasName;
|
||||
this.testingImapErrorDesc('');
|
||||
}
|
||||
}
|
||||
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());
|
||||
switch (Utils.pString(sValue))
|
||||
this.testingSieveError.subscribe((value) => {
|
||||
if (!value)
|
||||
{
|
||||
case '0':
|
||||
if (Enums.Ports.ImapSsl === iPort)
|
||||
{
|
||||
this.imapPort(Utils.pString(Enums.Ports.Imap));
|
||||
}
|
||||
break;
|
||||
case '1':
|
||||
if (Enums.Ports.Imap === iPort)
|
||||
{
|
||||
this.imapPort(Utils.pString(Enums.Ports.ImapSsl));
|
||||
}
|
||||
break;
|
||||
// no default
|
||||
this.testingSieveErrorDesc('');
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
});
|
||||
|
||||
this.smtpSecure.subscribe(function(sValue) {
|
||||
if (this.enableSmartPorts())
|
||||
{
|
||||
var iPort = Utils.pInt(this.smtpPort());
|
||||
switch (Utils.pString(sValue))
|
||||
this.testingSmtpError.subscribe((value) => {
|
||||
if (!value)
|
||||
{
|
||||
case '0':
|
||||
if (Enums.Ports.SmtpSsl === iPort || Enums.Ports.SmtpStartTls === iPort)
|
||||
{
|
||||
this.smtpPort(Utils.pString(Enums.Ports.Smtp));
|
||||
}
|
||||
break;
|
||||
case '1':
|
||||
if (Enums.Ports.Smtp === iPort || Enums.Ports.SmtpStartTls === iPort)
|
||||
{
|
||||
this.smtpPort(Utils.pString(Enums.Ports.SmtpSsl));
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if (Enums.Ports.Smtp === iPort || Enums.Ports.SmtpSsl === iPort)
|
||||
{
|
||||
this.smtpPort(Utils.pString(Enums.Ports.SmtpStartTls));
|
||||
}
|
||||
break;
|
||||
// no default
|
||||
this.testingSmtpErrorDesc('');
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
});
|
||||
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
this.imapServerFocus = ko.observable(false);
|
||||
this.sieveServerFocus = ko.observable(false);
|
||||
this.smtpServerFocus = ko.observable(false);
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/Domain', 'PopupsDomainViewModel'], DomainPopupView);
|
||||
_.extend(DomainPopupView.prototype, AbstractView.prototype);
|
||||
this.name = ko.observable('');
|
||||
this.name.focused = ko.observable(false);
|
||||
|
||||
DomainPopupView.prototype.onTestConnectionResponse = function(sResult, oData)
|
||||
{
|
||||
this.testing(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData.Result)
|
||||
{
|
||||
var
|
||||
bImap = false,
|
||||
bSieve = false;
|
||||
this.imapServer = ko.observable('');
|
||||
this.imapPort = ko.observable('' + IMAP_DEFAULT_PORT);
|
||||
this.imapSecure = ko.observable(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('' + SIEVE_DEFAULT_PORT);
|
||||
this.sieveSecure = ko.observable(ServerSecure.None);
|
||||
this.smtpServer = ko.observable('');
|
||||
this.smtpPort = ko.observable('' + SMTP_DEFAULT_PORT);
|
||||
this.smtpSecure = ko.observable(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.testingDone(true);
|
||||
this.testingImapError(true !== oData.Result.Imap);
|
||||
this.testingSieveError(true !== oData.Result.Sieve);
|
||||
this.testingSmtpError(true !== oData.Result.Smtp);
|
||||
this.enableSmartPorts = ko.observable(false);
|
||||
|
||||
if (this.testingImapError() && oData.Result.Imap)
|
||||
{
|
||||
bImap = true;
|
||||
this.testingImapErrorDesc('');
|
||||
this.testingImapErrorDesc(oData.Result.Imap);
|
||||
}
|
||||
this.allowSieve = ko.computed(() => CapaAdminStore.filters() && CapaAdminStore.sieve());
|
||||
|
||||
if (this.testingSieveError() && oData.Result.Sieve)
|
||||
{
|
||||
bSieve = true;
|
||||
this.testingSieveErrorDesc('');
|
||||
this.testingSieveErrorDesc(oData.Result.Sieve);
|
||||
}
|
||||
this.headerText = ko.computed(() => {
|
||||
|
||||
if (this.testingSmtpError() && oData.Result.Smtp)
|
||||
{
|
||||
this.testingSmtpErrorDesc('');
|
||||
this.testingSmtpErrorDesc(oData.Result.Smtp);
|
||||
}
|
||||
const
|
||||
name = this.name(),
|
||||
aliasName = this.aliasName();
|
||||
|
||||
if (this.sieveSettings())
|
||||
{
|
||||
if (!bSieve && bImap)
|
||||
let result = '';
|
||||
|
||||
if (this.edit())
|
||||
{
|
||||
this.sieveSettings(false);
|
||||
result = i18n('POPUPS_DOMAIN/TITLE_EDIT_DOMAIN', {'NAME': name});
|
||||
if (aliasName)
|
||||
{
|
||||
result += ' ← ' + aliasName;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
result = ('' === name ? i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN') :
|
||||
i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN_WITH_NAME', {'NAME': name}));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
});
|
||||
|
||||
this.domainDesc = ko.computed(() => {
|
||||
const name = this.name();
|
||||
return !this.edit() && name ? i18n('POPUPS_DOMAIN/NEW_DOMAIN_DESC', {'NAME': '*@' + name}) : '';
|
||||
});
|
||||
|
||||
this.domainIsComputed = ko.computed(() => {
|
||||
|
||||
const
|
||||
usePhpMail = this.smtpPhpMail(),
|
||||
allowSieve = this.allowSieve(),
|
||||
useSieve = this.useSieve();
|
||||
|
||||
return '' !== this.name() &&
|
||||
'' !== this.imapServer() &&
|
||||
'' !== this.imapPort() &&
|
||||
(allowSieve && useSieve ? ('' !== this.sieveServer() && '' !== this.sievePort()) : true) &&
|
||||
(('' !== this.smtpServer() && '' !== this.smtpPort()) || usePhpMail);
|
||||
|
||||
});
|
||||
|
||||
this.canBeTested = ko.computed(() => !this.testing() && this.domainIsComputed());
|
||||
this.canBeSaved = ko.computed(() => !this.saving() && this.domainIsComputed());
|
||||
|
||||
this.createOrAddCommand = createCommand(() => {
|
||||
this.saving(true);
|
||||
Remote.createOrUpdateDomain(
|
||||
_.bind(this.onDomainCreateOrSaveResponse, this),
|
||||
!this.edit(),
|
||||
this.name(),
|
||||
|
||||
this.imapServer(),
|
||||
pInt(this.imapPort()),
|
||||
this.imapSecure(),
|
||||
this.imapShortLogin(),
|
||||
|
||||
this.useSieve(),
|
||||
this.sieveAllowRaw(),
|
||||
this.sieveServer(),
|
||||
pInt(this.sievePort()),
|
||||
this.sieveSecure(),
|
||||
|
||||
this.smtpServer(),
|
||||
pInt(this.smtpPort()),
|
||||
this.smtpSecure(),
|
||||
this.smtpShortLogin(),
|
||||
this.smtpAuth(),
|
||||
this.smtpPhpMail(),
|
||||
|
||||
this.whiteList()
|
||||
);
|
||||
}, this.canBeSaved);
|
||||
|
||||
this.testConnectionCommand = createCommand(() => {
|
||||
|
||||
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(),
|
||||
pInt(this.imapPort()),
|
||||
this.imapSecure(),
|
||||
|
||||
this.useSieve(),
|
||||
this.sieveServer(),
|
||||
pInt(this.sievePort()),
|
||||
this.sieveSecure(),
|
||||
|
||||
this.smtpServer(),
|
||||
pInt(this.smtpPort()),
|
||||
this.smtpSecure(),
|
||||
this.smtpAuth(),
|
||||
this.smtpPhpMail()
|
||||
);
|
||||
}, this.canBeTested);
|
||||
|
||||
this.whiteListCommand = createCommand(() => {
|
||||
this.page('white-list');
|
||||
});
|
||||
|
||||
this.backCommand = createCommand(() => {
|
||||
this.page('main');
|
||||
});
|
||||
|
||||
this.sieveCommand = createCommand(() => {
|
||||
this.sieveSettings(!this.sieveSettings());
|
||||
this.clearTesting();
|
||||
});
|
||||
|
||||
this.page.subscribe(() => {
|
||||
this.sieveSettings(false);
|
||||
});
|
||||
|
||||
// smart form improvements
|
||||
this.imapServerFocus.subscribe((value) => {
|
||||
if (value && '' !== this.name() && '' === this.imapServer())
|
||||
{
|
||||
this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
|
||||
}
|
||||
});
|
||||
|
||||
this.sieveServerFocus.subscribe((value) => {
|
||||
if (value && '' !== this.imapServer() && '' === this.sieveServer())
|
||||
{
|
||||
this.sieveServer(this.imapServer());
|
||||
}
|
||||
});
|
||||
|
||||
this.smtpServerFocus.subscribe((value) => {
|
||||
if (value && '' !== this.imapServer() && '' === this.smtpServer())
|
||||
{
|
||||
this.smtpServer(this.imapServer().replace(/imap/ig, 'smtp'));
|
||||
}
|
||||
});
|
||||
|
||||
this.imapSecure.subscribe((value) => {
|
||||
if (this.enableSmartPorts())
|
||||
{
|
||||
const port = pInt(this.imapPort());
|
||||
switch (pString(value))
|
||||
{
|
||||
case '0':
|
||||
if (Ports.ImapSsl === port)
|
||||
{
|
||||
this.imapPort(pString(Ports.Imap));
|
||||
}
|
||||
break;
|
||||
case '1':
|
||||
if (Ports.Imap === port)
|
||||
{
|
||||
this.imapPort(pString(Ports.ImapSsl));
|
||||
}
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.smtpSecure.subscribe((value) => {
|
||||
if (this.enableSmartPorts())
|
||||
{
|
||||
const port = pInt(this.smtpPort());
|
||||
switch (pString(value))
|
||||
{
|
||||
case '0':
|
||||
if (Ports.SmtpSsl === port || Ports.SmtpStartTls === port)
|
||||
{
|
||||
this.smtpPort(pString(Ports.Smtp));
|
||||
}
|
||||
break;
|
||||
case '1':
|
||||
if (Ports.Smtp === port || Ports.SmtpStartTls === port)
|
||||
{
|
||||
this.smtpPort(pString(Ports.SmtpSsl));
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if (Ports.Smtp === port || Ports.SmtpSsl === port)
|
||||
{
|
||||
this.smtpPort(pString(Ports.SmtpStartTls));
|
||||
}
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onTestConnectionResponse(sResult, oData) {
|
||||
this.testing(false);
|
||||
if (StorageResultType.Success === sResult && oData.Result)
|
||||
{
|
||||
if (bSieve && !bImap)
|
||||
let
|
||||
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);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.testingImapError(true);
|
||||
this.testingSieveError(true);
|
||||
this.testingSmtpError(true);
|
||||
|
||||
onDomainCreateOrSaveResponse(sResult, oData) {
|
||||
this.saving(false);
|
||||
if (StorageResultType.Success === sResult && oData)
|
||||
{
|
||||
if (oData.Result)
|
||||
{
|
||||
getApp().reloadDomainList();
|
||||
this.closeCommand();
|
||||
}
|
||||
else if (Notification.DomainAlreadyExists === oData.ErrorCode)
|
||||
{
|
||||
this.savingError(i18n('ERRORS/DOMAIN_ALREADY_EXISTS'));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.savingError(i18n('ERRORS/UNKNOWN_ERROR'));
|
||||
}
|
||||
}
|
||||
|
||||
clearTesting() {
|
||||
this.testing(false);
|
||||
this.testingDone(false);
|
||||
this.testingImapError(false);
|
||||
this.testingSieveError(false);
|
||||
this.testingSmtpError(false);
|
||||
}
|
||||
|
||||
onHide() {
|
||||
this.page('main');
|
||||
this.sieveSettings(false);
|
||||
}
|
||||
};
|
||||
|
||||
DomainPopupView.prototype.onDomainCreateOrSaveResponse = function(sResult, oData)
|
||||
{
|
||||
this.saving(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData)
|
||||
{
|
||||
if (oData.Result)
|
||||
onShow(oDomain) {
|
||||
this.saving(false);
|
||||
|
||||
this.page('main');
|
||||
this.sieveSettings(false);
|
||||
|
||||
this.clearTesting();
|
||||
|
||||
this.clearForm();
|
||||
if (oDomain)
|
||||
{
|
||||
require('App/Admin').default.reloadDomainList();
|
||||
this.closeCommand();
|
||||
}
|
||||
else if (Enums.Notification.DomainAlreadyExists === oData.ErrorCode)
|
||||
{
|
||||
this.savingError(Translator.i18n('ERRORS/DOMAIN_ALREADY_EXISTS'));
|
||||
this.enableSmartPorts(false);
|
||||
|
||||
this.edit(true);
|
||||
|
||||
this.name(trim(oDomain.Name));
|
||||
this.imapServer(trim(oDomain.IncHost));
|
||||
this.imapPort('' + pInt(oDomain.IncPort));
|
||||
this.imapSecure(trim(oDomain.IncSecure));
|
||||
this.imapShortLogin(!!oDomain.IncShortLogin);
|
||||
this.useSieve(!!oDomain.UseSieve);
|
||||
this.sieveAllowRaw(!!oDomain.SieveAllowRaw);
|
||||
this.sieveServer(trim(oDomain.SieveHost));
|
||||
this.sievePort('' + pInt(oDomain.SievePort));
|
||||
this.sieveSecure(trim(oDomain.SieveSecure));
|
||||
this.smtpServer(trim(oDomain.OutHost));
|
||||
this.smtpPort('' + pInt(oDomain.OutPort));
|
||||
this.smtpSecure(trim(oDomain.OutSecure));
|
||||
this.smtpShortLogin(!!oDomain.OutShortLogin);
|
||||
this.smtpAuth(!!oDomain.OutAuth);
|
||||
this.smtpPhpMail(!!oDomain.OutUsePhpMail);
|
||||
this.whiteList(trim(oDomain.WhiteList));
|
||||
this.aliasName(trim(oDomain.AliasName));
|
||||
|
||||
this.enableSmartPorts(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.savingError(Translator.i18n('ERRORS/UNKNOWN_ERROR'));
|
||||
|
||||
onShowWithDelay() {
|
||||
if ('' === this.name() && !bMobileDevice)
|
||||
{
|
||||
this.name.focused(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DomainPopupView.prototype.clearTesting = function()
|
||||
{
|
||||
this.testing(false);
|
||||
this.testingDone(false);
|
||||
this.testingImapError(false);
|
||||
this.testingSieveError(false);
|
||||
this.testingSmtpError(false);
|
||||
};
|
||||
clearForm() {
|
||||
this.edit(false);
|
||||
|
||||
DomainPopupView.prototype.onHide = function()
|
||||
{
|
||||
this.page('main');
|
||||
this.sieveSettings(false);
|
||||
};
|
||||
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.edit(true);
|
||||
this.savingError('');
|
||||
|
||||
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.name('');
|
||||
this.name.focused(false);
|
||||
|
||||
this.imapServer('');
|
||||
this.imapPort('' + IMAP_DEFAULT_PORT);
|
||||
this.imapSecure(ServerSecure.None);
|
||||
this.imapShortLogin(false);
|
||||
|
||||
this.useSieve(false);
|
||||
this.sieveAllowRaw(false);
|
||||
this.sieveServer('');
|
||||
this.sievePort('' + SIEVE_DEFAULT_PORT);
|
||||
this.sieveSecure(ServerSecure.None);
|
||||
|
||||
this.smtpServer('');
|
||||
this.smtpPort('' + SMTP_DEFAULT_PORT);
|
||||
this.smtpSecure(ServerSecure.None);
|
||||
this.smtpShortLogin(false);
|
||||
this.smtpAuth(true);
|
||||
this.smtpPhpMail(false);
|
||||
|
||||
this.whiteList('');
|
||||
this.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.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;
|
||||
|
|
|
|||
|
|
@ -1,110 +1,99 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {bMobileDevice} from 'Common/Globals';
|
||||
import {createCommand} from 'Common/Utils';
|
||||
import {i18n} from 'Common/Translator';
|
||||
|
||||
Translator = require('Common/Translator'),
|
||||
import DomainStore from 'Stores/Admin/Domain';
|
||||
|
||||
DomainStore = require('Stores/Admin/Domain'),
|
||||
import Remote from 'Remote/Admin/Ajax';
|
||||
|
||||
Remote = require('Remote/Admin/Ajax'),
|
||||
import {getApp} from 'Helper/Apps/Admin';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function DomainAliasPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/DomainAlias',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsDomainAlias'
|
||||
})
|
||||
class DomainAliasPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsDomainAlias');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.saving = ko.observable(false);
|
||||
this.savingError = ko.observable('');
|
||||
this.saving = ko.observable(false);
|
||||
this.savingError = ko.observable('');
|
||||
|
||||
this.name = ko.observable('');
|
||||
this.name.focused = ko.observable(false);
|
||||
this.name = ko.observable('');
|
||||
this.name.focused = ko.observable(false);
|
||||
|
||||
this.alias = ko.observable('');
|
||||
this.alias = ko.observable('');
|
||||
|
||||
this.domains = DomainStore.domainsWithoutAliases;
|
||||
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.domainsOptions = ko.computed(
|
||||
() => _.map(this.domains(), (item) => ({optValue: item.name, optText: item.name}))
|
||||
);
|
||||
}, this.canBeSaved);
|
||||
|
||||
kn.constructorEnd(this);
|
||||
this.canBeSaved = ko.computed(() => !this.saving() && '' !== this.name() && '' !== this.alias());
|
||||
|
||||
this.createCommand = createCommand(() => {
|
||||
this.saving(true);
|
||||
Remote.createDomainAlias(
|
||||
this.onDomainAliasCreateOrSaveResponse,
|
||||
this.name(),
|
||||
this.alias()
|
||||
);
|
||||
}, this.canBeSaved);
|
||||
|
||||
this.onDomainAliasCreateOrSaveResponse = _.bind(this.onDomainAliasCreateOrSaveResponse, this);
|
||||
}
|
||||
|
||||
onDomainAliasCreateOrSaveResponse(result, data) {
|
||||
this.saving(false);
|
||||
if (StorageResultType.Success === result && data)
|
||||
{
|
||||
if (data.Result)
|
||||
{
|
||||
getApp().reloadDomainList();
|
||||
this.closeCommand();
|
||||
}
|
||||
else if (Notification.DomainAlreadyExists === data.ErrorCode)
|
||||
{
|
||||
this.savingError(i18n('ERRORS/DOMAIN_ALREADY_EXISTS'));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.savingError(i18n('ERRORS/UNKNOWN_ERROR'));
|
||||
}
|
||||
}
|
||||
|
||||
onShow() {
|
||||
this.clearForm();
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
if ('' === this.name() && !bMobileDevice)
|
||||
{
|
||||
this.name.focused(true);
|
||||
}
|
||||
}
|
||||
|
||||
clearForm() {
|
||||
this.saving(false);
|
||||
this.savingError('');
|
||||
|
||||
this.name('');
|
||||
this.name.focused(false);
|
||||
|
||||
this.alias('');
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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'));
|
||||
}
|
||||
};
|
||||
|
||||
DomainAliasPopupView.prototype.onShow = function()
|
||||
{
|
||||
this.clearForm();
|
||||
};
|
||||
|
||||
DomainAliasPopupView.prototype.onShowWithDelay = function()
|
||||
{
|
||||
if ('' === this.name() && !Globals.bMobile)
|
||||
{
|
||||
this.name.focused(true);
|
||||
}
|
||||
};
|
||||
|
||||
DomainAliasPopupView.prototype.clearForm = function()
|
||||
{
|
||||
this.saving(false);
|
||||
this.savingError('');
|
||||
|
||||
this.name('');
|
||||
this.name.focused(false);
|
||||
|
||||
this.alias('');
|
||||
};
|
||||
|
||||
module.exports = DomainAliasPopupView;
|
||||
|
|
|
|||
|
|
@ -1,202 +1,194 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {FiltersAction, FilterConditionField, FilterConditionType} from 'Common/Enums';
|
||||
import {bMobileDevice} from 'Common/Globals';
|
||||
import {defautOptionsAfterRender, createCommand, delegateRun} from 'Common/Utils';
|
||||
import {i18n, initOnStartOrLangChange} from 'Common/Translator';
|
||||
|
||||
FilterStore = require('Stores/User/Filter'),
|
||||
FolderStore = require('Stores/User/Folder'),
|
||||
import FilterStore from 'Stores/User/Filter';
|
||||
import FolderStore from 'Stores/User/Folder';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function FilterPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/Filter',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsFilter'
|
||||
})
|
||||
class FilterPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsFilter');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.isNew = ko.observable(true);
|
||||
this.isNew = ko.observable(true);
|
||||
|
||||
this.modules = FilterStore.modules;
|
||||
this.modules = FilterStore.modules;
|
||||
|
||||
this.fTrueCallback = null;
|
||||
this.filter = ko.observable(null);
|
||||
this.fTrueCallback = null;
|
||||
this.filter = ko.observable(null);
|
||||
|
||||
this.allowMarkAsRead = ko.observable(false);
|
||||
this.allowMarkAsRead = ko.observable(false);
|
||||
|
||||
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
|
||||
this.folderSelectList = FolderStore.folderMenuForFilters;
|
||||
this.selectedFolderValue = ko.observable('');
|
||||
this.defautOptionsAfterRender = defautOptionsAfterRender;
|
||||
this.folderSelectList = FolderStore.folderMenuForFilters;
|
||||
this.selectedFolderValue = ko.observable('');
|
||||
|
||||
this.selectedFolderValue.subscribe(function() {
|
||||
if (this.filter())
|
||||
this.selectedFolderValue.subscribe(() => {
|
||||
if (this.filter())
|
||||
{
|
||||
this.filter().actionValue.error(false);
|
||||
}
|
||||
});
|
||||
|
||||
this.saveFilter = createCommand(() => {
|
||||
|
||||
if (this.filter())
|
||||
{
|
||||
if (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())
|
||||
{
|
||||
delegateRun(this, 'closeCommand');
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
this.actionTypeOptions = ko.observableArray([]);
|
||||
this.fieldOptions = ko.observableArray([]);
|
||||
this.typeOptions = ko.observableArray([]);
|
||||
this.typeOptionsSize = ko.observableArray([]);
|
||||
|
||||
initOnStartOrLangChange(_.bind(this.populateOptions, this));
|
||||
|
||||
this.modules.subscribe(this.populateOptions, this);
|
||||
}
|
||||
|
||||
populateOptions() {
|
||||
this.actionTypeOptions([]);
|
||||
|
||||
// this.actionTypeOptions.push({'id': FiltersAction.None,
|
||||
// 'name': i18n('POPUPS_FILTER/SELECT_ACTION_NONE')});
|
||||
|
||||
const modules = this.modules();
|
||||
if (modules)
|
||||
{
|
||||
this.filter().actionValue.error(false);
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.saveFilter = Utils.createCommand(this, function() {
|
||||
|
||||
if (this.filter())
|
||||
{
|
||||
if (Enums.FiltersAction.MoveTo === this.filter().actionType())
|
||||
if (modules.markasread)
|
||||
{
|
||||
this.filter().actionValue(this.selectedFolderValue());
|
||||
this.allowMarkAsRead(true);
|
||||
}
|
||||
|
||||
if (!this.filter().verify())
|
||||
if (modules.moveto)
|
||||
{
|
||||
return false;
|
||||
this.actionTypeOptions.push({'id': FiltersAction.MoveTo,
|
||||
'name': i18n('POPUPS_FILTER/SELECT_ACTION_MOVE_TO')});
|
||||
}
|
||||
|
||||
if (this.fTrueCallback)
|
||||
if (modules.redirect)
|
||||
{
|
||||
this.fTrueCallback(this.filter());
|
||||
this.actionTypeOptions.push({'id': FiltersAction.Forward,
|
||||
'name': i18n('POPUPS_FILTER/SELECT_ACTION_FORWARD_TO')});
|
||||
}
|
||||
|
||||
if (this.modalVisibility())
|
||||
if (modules.reject)
|
||||
{
|
||||
Utils.delegateRun(this, 'closeCommand');
|
||||
this.actionTypeOptions.push({'id': FiltersAction.Reject,
|
||||
'name': i18n('POPUPS_FILTER/SELECT_ACTION_REJECT')});
|
||||
}
|
||||
|
||||
if (modules.vacation)
|
||||
{
|
||||
this.actionTypeOptions.push({'id': FiltersAction.Vacation,
|
||||
'name': i18n('POPUPS_FILTER/SELECT_ACTION_VACATION_MESSAGE')});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
this.actionTypeOptions.push({'id': FiltersAction.Discard,
|
||||
'name': i18n('POPUPS_FILTER/SELECT_ACTION_DISCARD')});
|
||||
|
||||
this.actionTypeOptions = ko.observableArray([]);
|
||||
this.fieldOptions = ko.observableArray([]);
|
||||
this.typeOptions = ko.observableArray([]);
|
||||
this.typeOptionsSize = ko.observableArray([]);
|
||||
this.fieldOptions([
|
||||
{'id': FilterConditionField.From, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_FROM')},
|
||||
{'id': FilterConditionField.Recipient, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_RECIPIENTS')},
|
||||
{'id': FilterConditionField.Subject, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_SUBJECT')},
|
||||
{'id': FilterConditionField.Size, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_SIZE')},
|
||||
{'id': FilterConditionField.Header, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_HEADER')}
|
||||
]);
|
||||
|
||||
Translator.initOnStartOrLangChange(_.bind(this.populateOptions, this));
|
||||
this.typeOptions([
|
||||
{'id': FilterConditionType.Contains, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_CONTAINS')},
|
||||
{'id': FilterConditionType.NotContains, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_NOT_CONTAINS')},
|
||||
{'id': FilterConditionType.EqualTo, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_EQUAL_TO')},
|
||||
{'id': FilterConditionType.NotEqualTo, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_NOT_EQUAL_TO')}
|
||||
]);
|
||||
|
||||
this.modules.subscribe(this.populateOptions, this);
|
||||
if (modules && modules.regex)
|
||||
{
|
||||
this.typeOptions.push({'id': FilterConditionType.Regex, 'name': 'Regex'});
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
this.typeOptionsSize([
|
||||
{'id': FilterConditionType.Over, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_OVER')},
|
||||
{'id': FilterConditionType.Under, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_UNDER')}
|
||||
]);
|
||||
}
|
||||
|
||||
removeCondition(oConditionToDelete) {
|
||||
if (this.filter())
|
||||
{
|
||||
this.filter().removeCondition(oConditionToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.isNew(true);
|
||||
|
||||
this.fTrueCallback = null;
|
||||
this.filter(null);
|
||||
}
|
||||
|
||||
onShow(oFilter, fTrueCallback, bEdit) {
|
||||
this.clearPopup();
|
||||
|
||||
this.fTrueCallback = fTrueCallback;
|
||||
this.filter(oFilter);
|
||||
|
||||
if (oFilter)
|
||||
{
|
||||
this.selectedFolderValue(oFilter.actionValue());
|
||||
}
|
||||
|
||||
this.isNew(!bEdit);
|
||||
|
||||
if (!bEdit && oFilter)
|
||||
{
|
||||
oFilter.name.focused(true);
|
||||
}
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
if (this.isNew() && this.filter() && !bMobileDevice)
|
||||
{
|
||||
this.filter().name.focused(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (this.filter())
|
||||
{
|
||||
this.filter().removeCondition(oConditionToDelete);
|
||||
}
|
||||
};
|
||||
|
||||
FilterPopupView.prototype.clearPopup = function()
|
||||
{
|
||||
this.isNew(true);
|
||||
|
||||
this.fTrueCallback = null;
|
||||
this.filter(null);
|
||||
};
|
||||
|
||||
FilterPopupView.prototype.onShow = function(oFilter, fTrueCallback, bEdit)
|
||||
{
|
||||
this.clearPopup();
|
||||
|
||||
this.fTrueCallback = fTrueCallback;
|
||||
this.filter(oFilter);
|
||||
|
||||
if (oFilter)
|
||||
{
|
||||
this.selectedFolderValue(oFilter.actionValue());
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,118 +1,106 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {createCommand} from 'Common/Utils';
|
||||
import {i18n, getNotification} from 'Common/Translator';
|
||||
import {setFolderHash} from 'Common/Cache';
|
||||
|
||||
Cache = require('Common/Cache'),
|
||||
import MessageStore from 'Stores/User/Message';
|
||||
|
||||
MessageStore = require('Stores/User/Message'),
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function FolderClearPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/FolderClear',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsFolderClear'
|
||||
})
|
||||
class FolderClearPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsFolderClear');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.selectedFolder = ko.observable(null);
|
||||
this.clearingProcess = ko.observable(false);
|
||||
this.clearingError = ko.observable('');
|
||||
this.selectedFolder = ko.observable(null);
|
||||
this.clearingProcess = ko.observable(false);
|
||||
this.clearingError = ko.observable('');
|
||||
|
||||
this.folderFullNameForClear = ko.computed(function() {
|
||||
var oFolder = this.selectedFolder();
|
||||
return oFolder ? oFolder.printableFullName() : '';
|
||||
}, this);
|
||||
|
||||
this.folderNameForClear = ko.computed(function() {
|
||||
var oFolder = this.selectedFolder();
|
||||
return oFolder ? oFolder.localName() : '';
|
||||
}, this);
|
||||
|
||||
this.dangerDescHtml = ko.computed(function() {
|
||||
return Translator.i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', {
|
||||
'FOLDER': this.folderNameForClear()
|
||||
this.folderFullNameForClear = ko.computed(() => {
|
||||
const folder = this.selectedFolder();
|
||||
return folder ? folder.printableFullName() : '';
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.clearCommand = Utils.createCommand(this, function() {
|
||||
this.folderNameForClear = ko.computed(() => {
|
||||
const folder = this.selectedFolder();
|
||||
return folder ? folder.localName() : '';
|
||||
});
|
||||
|
||||
var
|
||||
self = this,
|
||||
oFolderToClear = this.selectedFolder();
|
||||
this.dangerDescHtml = ko.computed(
|
||||
() => i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', {'FOLDER': this.folderNameForClear()})
|
||||
);
|
||||
|
||||
if (oFolderToClear)
|
||||
{
|
||||
MessageStore.message(null);
|
||||
MessageStore.messageList([]);
|
||||
this.clearCommand = createCommand(() => {
|
||||
|
||||
this.clearingProcess(true);
|
||||
const folderToClear = this.selectedFolder();
|
||||
if (folderToClear)
|
||||
{
|
||||
MessageStore.message(null);
|
||||
MessageStore.messageList([]);
|
||||
|
||||
oFolderToClear.messageCountAll(0);
|
||||
oFolderToClear.messageCountUnread(0);
|
||||
this.clearingProcess(true);
|
||||
|
||||
Cache.setFolderHash(oFolderToClear.fullNameRaw, '');
|
||||
folderToClear.messageCountAll(0);
|
||||
folderToClear.messageCountUnread(0);
|
||||
|
||||
Remote.folderClear(function(sResult, oData) {
|
||||
setFolderHash(folderToClear.fullNameRaw, '');
|
||||
|
||||
self.clearingProcess(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
require('App/User').default.reloadMessageList(true);
|
||||
self.cancelCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oData && oData.ErrorCode)
|
||||
Remote.folderClear((result, data) => {
|
||||
|
||||
this.clearingProcess(false);
|
||||
if (StorageResultType.Success === result && data && data.Result)
|
||||
{
|
||||
self.clearingError(Translator.getNotification(oData.ErrorCode));
|
||||
getApp().reloadMessageList(true);
|
||||
this.cancelCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
self.clearingError(Translator.getNotification(Enums.Notification.MailServerError));
|
||||
if (data && data.ErrorCode)
|
||||
{
|
||||
this.clearingError(getNotification(data.ErrorCode));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.clearingError(getNotification(Notification.MailServerError));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, oFolderToClear.fullNameRaw);
|
||||
}, folderToClear.fullNameRaw);
|
||||
}
|
||||
|
||||
}, () => {
|
||||
const
|
||||
folder = this.selectedFolder(),
|
||||
isClearing = this.clearingProcess();
|
||||
|
||||
return !isClearing && null !== folder;
|
||||
});
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.clearingProcess(false);
|
||||
this.selectedFolder(null);
|
||||
}
|
||||
|
||||
onShow(folder) {
|
||||
this.clearPopup();
|
||||
if (folder)
|
||||
{
|
||||
this.selectedFolder(folder);
|
||||
}
|
||||
|
||||
}, 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;
|
||||
|
|
|
|||
|
|
@ -1,111 +1,95 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Consts = require('Common/Consts'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
import {Notification} from 'Common/Enums';
|
||||
import {UNUSED_OPTION_VALUE} from 'Common/Consts';
|
||||
import {bMobileDevice} from 'Common/Globals';
|
||||
import {trim, createCommand, defautOptionsAfterRender, folderListOptionsBuilder} from 'Common/Utils';
|
||||
|
||||
FolderStore = require('Stores/User/Folder'),
|
||||
import FolderStore from 'Stores/User/Folder';
|
||||
|
||||
Promises = require('Promises/User/Ajax'),
|
||||
import Promises from 'Promises/User/Ajax';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function FolderCreateView()
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/Popup/FolderCreate',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsFolderCreate'
|
||||
})
|
||||
class FolderCreateView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsFolderCreate');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.folderName = ko.observable('');
|
||||
this.folderName.focused = ko.observable(false);
|
||||
this.folderName = ko.observable('');
|
||||
this.folderName.focused = ko.observable(false);
|
||||
|
||||
this.selectedParentValue = ko.observable(Consts.UNUSED_OPTION_VALUE);
|
||||
this.selectedParentValue = ko.observable(UNUSED_OPTION_VALUE);
|
||||
|
||||
this.parentFolderSelectList = ko.computed(function() {
|
||||
this.parentFolderSelectList = ko.computed(() => {
|
||||
|
||||
var
|
||||
aTop = [],
|
||||
fDisableCallback = null,
|
||||
fVisibleCallback = null,
|
||||
aList = FolderStore.folderList(),
|
||||
fRenameCallback = function(oItem) {
|
||||
return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
|
||||
};
|
||||
const
|
||||
top = [],
|
||||
list = FolderStore.folderList(),
|
||||
fRenameCallback = (oItem) => (oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '');
|
||||
|
||||
aTop.push(['', '']);
|
||||
top.push(['', '']);
|
||||
|
||||
if ('' !== FolderStore.namespace)
|
||||
{
|
||||
fDisableCallback = function(oItem)
|
||||
let fDisableCallback = null;
|
||||
if ('' !== FolderStore.namespace)
|
||||
{
|
||||
return FolderStore.namespace !== oItem.fullNameRaw.substr(0, FolderStore.namespace.length);
|
||||
};
|
||||
}
|
||||
fDisableCallback = (item) => FolderStore.namespace !== item.fullNameRaw.substr(0, FolderStore.namespace.length);
|
||||
}
|
||||
|
||||
return Utils.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);
|
||||
return folderListOptionsBuilder([], list, [], top, null, fDisableCallback, null, fRenameCallback);
|
||||
|
||||
}, this);
|
||||
});
|
||||
|
||||
// commands
|
||||
this.createFolder = Utils.createCommand(this, function() {
|
||||
// commands
|
||||
this.createFolder = createCommand(() => {
|
||||
|
||||
var
|
||||
sParentFolderName = this.selectedParentValue();
|
||||
let parentFolderName = this.selectedParentValue();
|
||||
if ('' === parentFolderName && 1 < FolderStore.namespace.length)
|
||||
{
|
||||
parentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
|
||||
}
|
||||
|
||||
if ('' === sParentFolderName && 1 < FolderStore.namespace.length)
|
||||
getApp().foldersPromisesActionHelper(
|
||||
Promises.folderCreate(this.folderName(), parentFolderName, FolderStore.foldersCreating),
|
||||
Notification.CantCreateFolder
|
||||
);
|
||||
|
||||
this.cancelCommand();
|
||||
|
||||
}, () => this.simpleFolderNameValidation(this.folderName()));
|
||||
|
||||
this.defautOptionsAfterRender = defautOptionsAfterRender;
|
||||
}
|
||||
|
||||
simpleFolderNameValidation(sName) {
|
||||
return (/^[^\\\/]+$/g).test(trim(sName));
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.folderName('');
|
||||
this.selectedParentValue('');
|
||||
this.folderName.focused(false);
|
||||
}
|
||||
|
||||
onShow() {
|
||||
this.clearPopup();
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
if (!bMobileDevice)
|
||||
{
|
||||
sParentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
|
||||
this.folderName.focused(true);
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,126 +1,113 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Consts = require('Common/Consts'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {SetSystemFoldersNotification, Magics} from 'Common/Enums';
|
||||
import {UNUSED_OPTION_VALUE} from 'Common/Consts';
|
||||
import {folderListOptionsBuilder, noop, defautOptionsAfterRender} from 'Common/Utils';
|
||||
import {initOnStartOrLangChange, i18n} from 'Common/Translator';
|
||||
|
||||
FolderStore = require('Stores/User/Folder'),
|
||||
import FolderStore from 'Stores/User/Folder';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
import * as Settings from 'Storage/Settings';
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function FolderSystemPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/FolderSystem',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsFolderSystem'
|
||||
})
|
||||
class FolderSystemPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsFolderSystem');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
Translator.initOnStartOrLangChange(_.bind(function() {
|
||||
this.sChooseOnText = Translator.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_CHOOSE_ONE');
|
||||
this.sUnuseText = Translator.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_UNUSE_NAME');
|
||||
}, this));
|
||||
this.sChooseOnText = '';
|
||||
this.sUnuseText = '';
|
||||
|
||||
this.notification = ko.observable('');
|
||||
initOnStartOrLangChange(() => {
|
||||
this.sChooseOnText = i18n('POPUPS_SYSTEM_FOLDERS/SELECT_CHOOSE_ONE');
|
||||
this.sUnuseText = i18n('POPUPS_SYSTEM_FOLDERS/SELECT_UNUSE_NAME');
|
||||
});
|
||||
|
||||
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);
|
||||
this.notification = ko.observable('');
|
||||
|
||||
this.sentFolder = FolderStore.sentFolder;
|
||||
this.draftFolder = FolderStore.draftFolder;
|
||||
this.spamFolder = FolderStore.spamFolder;
|
||||
this.trashFolder = FolderStore.trashFolder;
|
||||
this.archiveFolder = FolderStore.archiveFolder;
|
||||
this.folderSelectList = ko.computed(
|
||||
() => folderListOptionsBuilder([], FolderStore.folderList(), FolderStore.folderListSystemNames(), [
|
||||
['', this.sChooseOnText], [UNUSED_OPTION_VALUE, this.sUnuseText]
|
||||
], null, null, null, null, null, true)
|
||||
);
|
||||
|
||||
var
|
||||
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());
|
||||
this.sentFolder = FolderStore.sentFolder;
|
||||
this.draftFolder = FolderStore.draftFolder;
|
||||
this.spamFolder = FolderStore.spamFolder;
|
||||
this.trashFolder = FolderStore.trashFolder;
|
||||
this.archiveFolder = FolderStore.archiveFolder;
|
||||
|
||||
Remote.saveSystemFolders(Utils.noop, {
|
||||
'SentFolder': FolderStore.sentFolder(),
|
||||
'DraftFolder': FolderStore.draftFolder(),
|
||||
'SpamFolder': FolderStore.spamFolder(),
|
||||
'TrashFolder': FolderStore.trashFolder(),
|
||||
'ArchiveFolder': FolderStore.archiveFolder(),
|
||||
'NullFolder': 'NullFolder'
|
||||
});
|
||||
const
|
||||
fSetSystemFolders = () => {
|
||||
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 = _.debounce(() => {
|
||||
fSetSystemFolders();
|
||||
Remote.saveSystemFolders(noop, {
|
||||
SentFolder: FolderStore.sentFolder(),
|
||||
DraftFolder: FolderStore.draftFolder(),
|
||||
SpamFolder: FolderStore.spamFolder(),
|
||||
TrashFolder: FolderStore.trashFolder(),
|
||||
ArchiveFolder: FolderStore.archiveFolder(),
|
||||
NullFolder: 'NullFolder'
|
||||
});
|
||||
}, Magics.Time1s),
|
||||
fCallback = () => {
|
||||
fSetSystemFolders();
|
||||
fSaveSystemFolders();
|
||||
};
|
||||
|
||||
}, Enums.Magics.Time1s);
|
||||
FolderStore.sentFolder.subscribe(fCallback);
|
||||
FolderStore.draftFolder.subscribe(fCallback);
|
||||
FolderStore.spamFolder.subscribe(fCallback);
|
||||
FolderStore.trashFolder.subscribe(fCallback);
|
||||
FolderStore.archiveFolder.subscribe(fCallback);
|
||||
|
||||
var
|
||||
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;
|
||||
// no default
|
||||
this.defautOptionsAfterRender = defautOptionsAfterRender;
|
||||
}
|
||||
|
||||
this.notification(sNotification);
|
||||
};
|
||||
/**
|
||||
* @param {number=} notificationType = SetSystemFoldersNotification.None
|
||||
*/
|
||||
onShow(notificationType = SetSystemFoldersNotification.None) {
|
||||
|
||||
let notification = '';
|
||||
switch (notificationType)
|
||||
{
|
||||
case SetSystemFoldersNotification.Sent:
|
||||
notification = i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SENT');
|
||||
break;
|
||||
case SetSystemFoldersNotification.Draft:
|
||||
notification = i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_DRAFTS');
|
||||
break;
|
||||
case SetSystemFoldersNotification.Spam:
|
||||
notification = i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SPAM');
|
||||
break;
|
||||
case SetSystemFoldersNotification.Trash:
|
||||
notification = i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_TRASH');
|
||||
break;
|
||||
case SetSystemFoldersNotification.Archive:
|
||||
notification = i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_ARCHIVE');
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
|
||||
this.notification(notification);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FolderSystemPopupView;
|
||||
|
|
|
|||
|
|
@ -1,197 +1,187 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {bMobileDevice} from 'Common/Globals';
|
||||
import {createCommand, trim, fakeMd5} from 'Common/Utils';
|
||||
import {getNotification} from 'Common/Translator';
|
||||
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function IdentityPopupView()
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/Popup/Identity',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsIdentity'
|
||||
})
|
||||
class IdentityPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsIdentity');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
var self = this;
|
||||
this.id = '';
|
||||
this.edit = ko.observable(false);
|
||||
this.owner = ko.observable(false);
|
||||
|
||||
this.id = '';
|
||||
this.edit = ko.observable(false);
|
||||
this.owner = ko.observable(false);
|
||||
this.email = ko.observable('').validateEmail();
|
||||
this.email.focused = ko.observable(false);
|
||||
this.name = ko.observable('');
|
||||
this.name.focused = ko.observable(false);
|
||||
this.replyTo = ko.observable('').validateSimpleEmail();
|
||||
this.replyTo.focused = ko.observable(false);
|
||||
this.bcc = ko.observable('').validateSimpleEmail();
|
||||
this.bcc.focused = ko.observable(false);
|
||||
|
||||
this.email = 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.signature = ko.observable('');
|
||||
this.signatureInsertBefore = ko.observable(false);
|
||||
this.showBcc = ko.observable(false);
|
||||
this.showReplyTo = ko.observable(false);
|
||||
|
||||
this.showBcc = ko.observable(false);
|
||||
this.showReplyTo = ko.observable(false);
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
|
||||
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.bcc.subscribe((value) => {
|
||||
if (false === this.showBcc() && 0 < value.length)
|
||||
{
|
||||
this.email.focused(true);
|
||||
this.showBcc(true);
|
||||
}
|
||||
});
|
||||
|
||||
this.replyTo.subscribe((value) => {
|
||||
if (false === this.showReplyTo() && 0 < value.length)
|
||||
{
|
||||
this.showReplyTo(true);
|
||||
}
|
||||
});
|
||||
|
||||
this.addOrEditIdentityCommand = createCommand(() => {
|
||||
|
||||
if (this.signature && this.signature.__fetchEditorValue)
|
||||
{
|
||||
this.signature.__fetchEditorValue();
|
||||
}
|
||||
|
||||
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 (!this.email.hasError())
|
||||
{
|
||||
if (oData.Result)
|
||||
this.email.hasError('' === trim(this.email()));
|
||||
}
|
||||
|
||||
if (this.email.hasError())
|
||||
{
|
||||
if (!this.owner())
|
||||
{
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
this.cancelCommand();
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
{
|
||||
this.submitError(Translator.getNotification(oData.ErrorCode));
|
||||
this.email.focused(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
if (this.replyTo.hasError())
|
||||
{
|
||||
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
|
||||
this.replyTo.focused(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
}, this), this.id, this.email(), this.name(), this.replyTo(), this.bcc(),
|
||||
this.signature(), this.signatureInsertBefore());
|
||||
if (this.bcc.hasError())
|
||||
{
|
||||
this.bcc.focused(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
this.submitRequest(true);
|
||||
|
||||
}, function() {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
Remote.identityUpdate((result, data) => {
|
||||
|
||||
kn.constructorEnd(this);
|
||||
this.submitRequest(false);
|
||||
if (StorageResultType.Success === result && data)
|
||||
{
|
||||
if (data.Result)
|
||||
{
|
||||
getApp().accountsAndIdentities();
|
||||
this.cancelCommand();
|
||||
}
|
||||
else if (data.ErrorCode)
|
||||
{
|
||||
this.submitError(getNotification(data.ErrorCode));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitError(getNotification(Notification.UnknownError));
|
||||
}
|
||||
|
||||
}, this.id, this.email(), this.name(), this.replyTo(), this.bcc(), this.signature(), this.signatureInsertBefore());
|
||||
|
||||
return true;
|
||||
|
||||
}, () => !this.submitRequest());
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
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
|
||||
*/
|
||||
onShow(identity) {
|
||||
|
||||
this.clearPopup();
|
||||
|
||||
if (identity)
|
||||
{
|
||||
this.edit(true);
|
||||
|
||||
this.id = identity.id() || '';
|
||||
this.name(identity.name());
|
||||
this.email(identity.email());
|
||||
this.replyTo(identity.replyTo());
|
||||
this.bcc(identity.bcc());
|
||||
this.signature(identity.signature());
|
||||
this.signatureInsertBefore(identity.signatureInsertBefore());
|
||||
|
||||
this.owner('' === this.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.id = fakeMd5();
|
||||
}
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
if (!this.owner() && !bMobileDevice)
|
||||
{
|
||||
this.email.focused(true);
|
||||
}
|
||||
}
|
||||
|
||||
onHideWithDelay() {
|
||||
this.clearPopup();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
this.edit(true);
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,60 +1,55 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
key = require('key'),
|
||||
import _ from '_';
|
||||
import key from 'key';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
import {KeyState, Magics} from 'Common/Enums';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function KeyboardShortcutsHelpPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/KeyboardShortcutsHelp',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsKeyboardShortcutsHelp'
|
||||
})
|
||||
class KeyboardShortcutsHelpPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsKeyboardShortcutsHelp');
|
||||
constructor() {
|
||||
super();
|
||||
this.sDefaultKeyScope = KeyState.PopupKeyboardShortcutsHelp;
|
||||
}
|
||||
|
||||
this.sDefaultKeyScope = Enums.KeyState.PopupKeyboardShortcutsHelp;
|
||||
onBuild(dom) {
|
||||
key('tab, shift+tab, left, right', KeyState.PopupKeyboardShortcutsHelp, _.throttle((event, handler) => {
|
||||
|
||||
kn.constructorEnd(this);
|
||||
if (event && handler)
|
||||
{
|
||||
const
|
||||
$tabs = dom.find('.nav.nav-tabs > li'),
|
||||
isNext = handler && ('tab' === handler.shortcut || 'right' === handler.shortcut);
|
||||
|
||||
let index = $tabs.index($tabs.filter('.active'));
|
||||
if (!isNext && 0 < index)
|
||||
{
|
||||
index -= 1;
|
||||
}
|
||||
else if (isNext && index < $tabs.length - 1)
|
||||
{
|
||||
index += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
index = isNext ? 0 : $tabs.length - 1;
|
||||
}
|
||||
|
||||
$tabs.eq(index).find('a[data-toggle="tab"]').tab('show');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}, Magics.Time100ms));
|
||||
}
|
||||
}
|
||||
|
||||
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(function(event, handler) {
|
||||
|
||||
if (event && handler)
|
||||
{
|
||||
var
|
||||
$tabs = oDom.find('.nav.nav-tabs > li'),
|
||||
isNext = handler && ('tab' === handler.shortcut || 'right' === handler.shortcut),
|
||||
index = $tabs.index($tabs.filter('.active'));
|
||||
|
||||
if (!isNext && 0 < index)
|
||||
{
|
||||
index -= 1;
|
||||
}
|
||||
else if (isNext && index < $tabs.length - 1)
|
||||
{
|
||||
index += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
index = isNext ? 0 : $tabs.length - 1;
|
||||
}
|
||||
|
||||
$tabs.eq(index).find('a[data-toggle="tab"]').tab('show');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}, Enums.Magics.Time100ms));
|
||||
};
|
||||
|
||||
module.exports = KeyboardShortcutsHelpPopupView;
|
||||
|
|
|
|||
|
|
@ -1,88 +1,76 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Utils = require('Common/Utils'),
|
||||
import {convertLangName} from 'Common/Utils';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function LanguagesPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/Languages',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsLanguages'
|
||||
})
|
||||
class LanguagesPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsLanguages');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
var self = this;
|
||||
this.fLang = null;
|
||||
this.userLanguage = ko.observable('');
|
||||
|
||||
this.fLang = null;
|
||||
this.userLanguage = ko.observable('');
|
||||
this.langs = ko.observableArray([]);
|
||||
|
||||
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(() => {
|
||||
const userLanguage = this.userLanguage();
|
||||
return _.map(this.langs(), (language) => ({
|
||||
key: language,
|
||||
user: language === userLanguage,
|
||||
selected: ko.observable(false),
|
||||
fullName: convertLangName(language)
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
this.langs.subscribe(function() {
|
||||
this.setLanguageSelection();
|
||||
}, 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);
|
||||
this.langs.subscribe(() => {
|
||||
this.setLanguageSelection();
|
||||
});
|
||||
}
|
||||
|
||||
this.cancelCommand();
|
||||
};
|
||||
languageTooltipName(language) {
|
||||
const result = convertLangName(language, true);
|
||||
return convertLangName(language, false) === result ? '' : result;
|
||||
}
|
||||
|
||||
setLanguageSelection() {
|
||||
const currentLang = this.fLang ? ko.unwrap(this.fLang) : '';
|
||||
_.each(this.languages(), (item) => {
|
||||
item.selected(item.key === currentLang);
|
||||
});
|
||||
}
|
||||
|
||||
onBeforeShow() {
|
||||
this.fLang = null;
|
||||
this.userLanguage('');
|
||||
|
||||
this.langs([]);
|
||||
}
|
||||
|
||||
onShow(fLanguage, langs, userLanguage) {
|
||||
this.fLang = fLanguage;
|
||||
this.userLanguage(userLanguage || '');
|
||||
|
||||
this.langs(langs);
|
||||
}
|
||||
|
||||
changeLanguage(lang) {
|
||||
if (this.fLang)
|
||||
{
|
||||
this.fLang(lang);
|
||||
}
|
||||
|
||||
this.cancelCommand();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LanguagesPopupView;
|
||||
|
|
|
|||
|
|
@ -1,175 +1,165 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
key = require('key'),
|
||||
$ = require('$'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
import $ from '$';
|
||||
|
||||
Utils = require('Common/Utils'),
|
||||
Enums = require('Common/Enums'),
|
||||
import {createCommand, pString, log} from 'Common/Utils';
|
||||
import {KeyState, Magics} from 'Common/Enums';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function MessageOpenPgpPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/MessageOpenPgp',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsMessageOpenPgp'
|
||||
})
|
||||
class MessageOpenPgpPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsMessageOpenPgp');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.notification = ko.observable('');
|
||||
this.notification = ko.observable('');
|
||||
|
||||
this.selectedKey = ko.observable(null);
|
||||
this.privateKeys = ko.observableArray([]);
|
||||
this.selectedKey = ko.observable(null);
|
||||
this.privateKeys = ko.observableArray([]);
|
||||
|
||||
this.password = ko.observable('');
|
||||
this.password.focus = ko.observable(false);
|
||||
this.buttonFocus = ko.observable(false);
|
||||
this.password = ko.observable('');
|
||||
this.password.focus = ko.observable(false);
|
||||
this.buttonFocus = ko.observable(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
this.resultCallback = null;
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitRequest = ko.observable(false);
|
||||
|
||||
// commands
|
||||
this.doCommand = Utils.createCommand(this, function() {
|
||||
// commands
|
||||
this.doCommand = createCommand(() => {
|
||||
|
||||
this.submitRequest(true);
|
||||
this.submitRequest(true);
|
||||
|
||||
_.delay(_.bind(function() {
|
||||
_.delay(() => {
|
||||
|
||||
var oPrivateKey = null;
|
||||
let privateKey = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (this.resultCallback && this.selectedKey())
|
||||
try
|
||||
{
|
||||
var oPrivateKeys = this.selectedKey().getNativeKeys();
|
||||
oPrivateKey = oPrivateKeys && oPrivateKeys[0] ? oPrivateKeys[0] : null;
|
||||
|
||||
if (oPrivateKey)
|
||||
if (this.resultCallback && this.selectedKey())
|
||||
{
|
||||
try
|
||||
const privateKeys = this.selectedKey().getNativeKeys();
|
||||
privateKey = privateKeys && privateKeys[0] ? privateKeys[0] : null;
|
||||
|
||||
if (privateKey)
|
||||
{
|
||||
if (!oPrivateKey.decrypt(Utils.pString(this.password())))
|
||||
try
|
||||
{
|
||||
Utils.log('Error: Private key cannot be decrypted');
|
||||
oPrivateKey = null;
|
||||
if (!privateKey.decrypt(pString(this.password())))
|
||||
{
|
||||
log('Error: Private key cannot be decrypted');
|
||||
privateKey = null;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
log(e);
|
||||
privateKey = null;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
else
|
||||
{
|
||||
Utils.log(e);
|
||||
oPrivateKey = null;
|
||||
log('Error: Private key cannot be found');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.log('Error: Private key cannot be found');
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
catch (e)
|
||||
{
|
||||
log(e);
|
||||
privateKey = null;
|
||||
}
|
||||
|
||||
this.submitRequest(false);
|
||||
|
||||
this.cancelCommand();
|
||||
this.resultCallback(privateKey);
|
||||
|
||||
}, Magics.Time100ms);
|
||||
|
||||
}, () => !this.submitRequest());
|
||||
|
||||
this.sDefaultKeyScope = KeyState.PopupMessageOpenPGP;
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.notification('');
|
||||
|
||||
this.password('');
|
||||
this.password.focus(false);
|
||||
this.buttonFocus(false);
|
||||
|
||||
this.selectedKey(false);
|
||||
this.submitRequest(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
this.privateKeys([]);
|
||||
}
|
||||
|
||||
onBuild(oDom) {
|
||||
key('tab,shift+tab', KeyState.PopupMessageOpenPGP, () => {
|
||||
|
||||
switch (true)
|
||||
{
|
||||
Utils.log(e);
|
||||
oPrivateKey = null;
|
||||
case this.password.focus():
|
||||
this.buttonFocus(true);
|
||||
break;
|
||||
case this.buttonFocus():
|
||||
this.password.focus(true);
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
|
||||
this.submitRequest(false);
|
||||
return false;
|
||||
|
||||
this.cancelCommand();
|
||||
this.resultCallback(oPrivateKey);
|
||||
});
|
||||
|
||||
}, this), Enums.Magics.Time100ms);
|
||||
const self = this;
|
||||
|
||||
}, function() {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
oDom
|
||||
.on('click', '.key-list__item', function() { // eslint-disable-line prefer-arrow-callback
|
||||
|
||||
this.sDefaultKeyScope = Enums.KeyState.PopupMessageOpenPGP;
|
||||
oDom.find('.key-list__item .key-list__item__radio')
|
||||
.addClass('icon-radio-unchecked')
|
||||
.removeClass('icon-radio-checked');
|
||||
|
||||
kn.constructorEnd(this);
|
||||
$(this).find('.key-list__item__radio') // eslint-disable-line no-invalid-this
|
||||
.removeClass('icon-radio-unchecked')
|
||||
.addClass('icon-radio-checked');
|
||||
|
||||
self.selectedKey(ko.dataFor(this)); // eslint-disable-line no-invalid-this
|
||||
|
||||
self.password.focus(true);
|
||||
});
|
||||
}
|
||||
|
||||
onHideWithDelay() {
|
||||
this.clearPopup();
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
this.password.focus(true);
|
||||
// this.buttonFocus(true);
|
||||
}
|
||||
|
||||
onShow(fCallback, privateKeys) {
|
||||
this.clearPopup();
|
||||
|
||||
this.resultCallback = fCallback;
|
||||
this.privateKeys(privateKeys);
|
||||
|
||||
if (this.viewModelDom)
|
||||
{
|
||||
this.viewModelDom.find('.key-list__item').first().click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/MessageOpenPgp'], MessageOpenPgpPopupView);
|
||||
_.extend(MessageOpenPgpPopupView.prototype, AbstractView.prototype);
|
||||
|
||||
MessageOpenPgpPopupView.prototype.clearPopup = function()
|
||||
{
|
||||
this.notification('');
|
||||
|
||||
this.password('');
|
||||
this.password.focus(false);
|
||||
this.buttonFocus(false);
|
||||
|
||||
this.selectedKey(false);
|
||||
this.submitRequest(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
this.privateKeys([]);
|
||||
};
|
||||
|
||||
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;
|
||||
// no default
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,135 +1,129 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
import {Magics} from 'Common/Enums';
|
||||
import {trim, log, createCommand, delegateRun, pInt} from 'Common/Utils';
|
||||
|
||||
PgpStore = require('Stores/User/Pgp'),
|
||||
import PgpStore from 'Stores/User/Pgp';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function NewOpenPgpKeyPopupView()
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/Popup/NewOpenPgpKey',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsNewOpenPgpKey'
|
||||
})
|
||||
class NewOpenPgpKeyPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsNewOpenPgpKey');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.email = ko.observable('');
|
||||
this.email.focus = ko.observable('');
|
||||
this.email.error = ko.observable(false);
|
||||
this.email = ko.observable('');
|
||||
this.email.focus = ko.observable('');
|
||||
this.email.error = ko.observable(false);
|
||||
|
||||
this.name = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
this.keyBitLength = ko.observable(Enums.Magics.BitLength2048);
|
||||
this.name = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
this.keyBitLength = ko.observable(Magics.BitLength2048);
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
|
||||
this.email.subscribe(function() {
|
||||
this.email.error(false);
|
||||
}, this);
|
||||
this.email.subscribe(() => {
|
||||
this.email.error(false);
|
||||
});
|
||||
|
||||
this.generateOpenPgpKeyCommand = Utils.createCommand(this, function() {
|
||||
this.generateOpenPgpKeyCommand = createCommand(() => {
|
||||
|
||||
var
|
||||
self = this,
|
||||
oUserId = {},
|
||||
oOpenpgpKeyring = PgpStore.openpgpKeyring;
|
||||
const
|
||||
userId = {},
|
||||
openpgpKeyring = 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);
|
||||
this.submitError('');
|
||||
|
||||
_.delay(function() {
|
||||
|
||||
try {
|
||||
|
||||
PgpStore.openpgp.generateKey({
|
||||
userIds: [oUserId],
|
||||
numBits: Utils.pInt(self.keyBitLength()),
|
||||
passphrase: Utils.trim(self.password())
|
||||
}).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(e) {
|
||||
self.submitRequest(false);
|
||||
self.showError(e);
|
||||
});
|
||||
}
|
||||
catch (e)
|
||||
this.email.error('' === trim(this.email()));
|
||||
if (!openpgpKeyring || this.email.error())
|
||||
{
|
||||
self.submitRequest(false);
|
||||
self.showError(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}, Enums.Magics.Time100ms);
|
||||
userId.email = this.email();
|
||||
if ('' !== this.name())
|
||||
{
|
||||
userId.name = this.name();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
this.submitRequest(true);
|
||||
this.submitError('');
|
||||
|
||||
kn.constructorEnd(this);
|
||||
_.delay(() => {
|
||||
|
||||
try {
|
||||
|
||||
PgpStore.openpgp.generateKey({
|
||||
userIds: [userId],
|
||||
numBits: pInt(this.keyBitLength()),
|
||||
passphrase: trim(this.password())
|
||||
}).then((keyPair) => {
|
||||
|
||||
this.submitRequest(false);
|
||||
|
||||
if (keyPair && keyPair.privateKeyArmored)
|
||||
{
|
||||
openpgpKeyring.privateKeys.importKey(keyPair.privateKeyArmored);
|
||||
openpgpKeyring.publicKeys.importKey(keyPair.publicKeyArmored);
|
||||
|
||||
openpgpKeyring.store();
|
||||
|
||||
getApp().reloadOpenPgpKeys();
|
||||
delegateRun(this, 'cancelCommand');
|
||||
}
|
||||
|
||||
}).catch((e) => {
|
||||
this.submitRequest(false);
|
||||
this.showError(e);
|
||||
});
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
this.submitRequest(false);
|
||||
this.showError(e);
|
||||
}
|
||||
|
||||
}, Magics.Time100ms);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
showError(e) {
|
||||
log(e);
|
||||
if (e && e.message)
|
||||
{
|
||||
this.submitError(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.name('');
|
||||
this.password('');
|
||||
|
||||
this.email('');
|
||||
this.email.error(false);
|
||||
this.keyBitLength(Magics.BitLength2048);
|
||||
|
||||
this.submitError('');
|
||||
}
|
||||
|
||||
onShow() {
|
||||
this.clearPopup();
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
this.email.focus(true);
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/NewOpenPgpKey', 'PopupsNewOpenPgpKeyViewModel'], NewOpenPgpKeyPopupView);
|
||||
_.extend(NewOpenPgpKeyPopupView.prototype, AbstractView.prototype);
|
||||
|
||||
NewOpenPgpKeyPopupView.prototype.showError = function(e)
|
||||
{
|
||||
Utils.log(e);
|
||||
if (e && e.message)
|
||||
{
|
||||
this.submitError(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
NewOpenPgpKeyPopupView.prototype.clearPopup = function()
|
||||
{
|
||||
this.name('');
|
||||
this.password('');
|
||||
|
||||
this.email('');
|
||||
this.email.error(false);
|
||||
this.keyBitLength(Enums.Magics.BitLength2048);
|
||||
|
||||
this.submitError('');
|
||||
};
|
||||
|
||||
NewOpenPgpKeyPopupView.prototype.onShow = function()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
NewOpenPgpKeyPopupView.prototype.onShowWithDelay = function()
|
||||
{
|
||||
this.email.focus(true);
|
||||
};
|
||||
|
||||
module.exports = NewOpenPgpKeyPopupView;
|
||||
|
|
|
|||
|
|
@ -1,168 +1,141 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
key = require('key'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {KeyState, Magics, StorageResultType, Notification} from 'Common/Enums';
|
||||
import {createCommand, isNonEmptyArray, delegateRun} from 'Common/Utils';
|
||||
import {getNotification, i18n} from 'Common/Translator';
|
||||
|
||||
Remote = require('Remote/Admin/Ajax'),
|
||||
import Remote from 'Remote/Admin/Ajax';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType, isPopupVisible, showScreenPopup} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function PluginPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/Plugin',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsPlugin'
|
||||
})
|
||||
class PluginPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsPlugin');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
var self = this;
|
||||
this.onPluginSettingsUpdateResponse = _.bind(this.onPluginSettingsUpdateResponse, this);
|
||||
|
||||
this.onPluginSettingsUpdateResponse = _.bind(this.onPluginSettingsUpdateResponse, this);
|
||||
this.saveError = ko.observable('');
|
||||
|
||||
this.saveError = ko.observable('');
|
||||
this.name = ko.observable('');
|
||||
this.readme = ko.observable('');
|
||||
|
||||
this.name = ko.observable('');
|
||||
this.readme = ko.observable('');
|
||||
this.configures = ko.observableArray([]);
|
||||
|
||||
this.configures = ko.observableArray([]);
|
||||
this.hasReadme = ko.computed(() => '' !== this.readme());
|
||||
this.hasConfiguration = ko.computed(() => 0 < this.configures().length);
|
||||
|
||||
this.hasReadme = ko.computed(function() {
|
||||
return '' !== this.readme();
|
||||
}, this);
|
||||
this.readmePopoverConf = {
|
||||
'placement': 'right',
|
||||
'trigger': 'hover',
|
||||
'title': i18n('POPUPS_PLUGIN/TOOLTIP_ABOUT_TITLE'),
|
||||
'container': 'body',
|
||||
'html': true,
|
||||
'content': () => `<pre>${this.readme()}</pre>`
|
||||
};
|
||||
|
||||
this.hasConfiguration = ko.computed(function() {
|
||||
return 0 < this.configures().length;
|
||||
}, this);
|
||||
this.saveCommand = createCommand(() => {
|
||||
|
||||
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>';
|
||||
// .replace(/[\r]/g, '').replace(/[\n]/g, '<br />').replace(/[\t]/g, ' ');
|
||||
}
|
||||
};
|
||||
const list = {};
|
||||
list.Name = this.name();
|
||||
|
||||
this.saveCommand = Utils.createCommand(this, function() {
|
||||
_.each(this.configures(), (oItem) => {
|
||||
let value = oItem.value();
|
||||
if (false === value || true === value)
|
||||
{
|
||||
value = value ? '1' : '0';
|
||||
}
|
||||
list['_' + oItem.Name] = value;
|
||||
});
|
||||
|
||||
var list = {};
|
||||
this.saveError('');
|
||||
Remote.pluginSettingsUpdate(this.onPluginSettingsUpdateResponse, list);
|
||||
|
||||
list.Name = this.name();
|
||||
}, this.hasConfiguration);
|
||||
|
||||
_.each(this.configures(), function(oItem) {
|
||||
var value = oItem.value();
|
||||
this.bDisabeCloseOnEsc = true;
|
||||
this.sDefaultKeyScope = KeyState.All;
|
||||
|
||||
if (false === value || true === value)
|
||||
{
|
||||
value = value ? '1' : '0';
|
||||
}
|
||||
|
||||
list['_' + oItem.Name] = value;
|
||||
}, this);
|
||||
|
||||
this.saveError('');
|
||||
Remote.pluginSettingsUpdate(this.onPluginSettingsUpdateResponse, list);
|
||||
|
||||
}, this.hasConfiguration);
|
||||
|
||||
this.bDisabeCloseOnEsc = true;
|
||||
this.sDefaultKeyScope = Enums.KeyState.All;
|
||||
|
||||
this.tryToClosePopup = _.debounce(_.bind(this.tryToClosePopup, this), Enums.Magics.Time200ms);
|
||||
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/Plugin', 'PopupsPluginViewModel'], PluginPopupView);
|
||||
_.extend(PluginPopupView.prototype, AbstractView.prototype);
|
||||
|
||||
PluginPopupView.prototype.onPluginSettingsUpdateResponse = function(sResult, oData)
|
||||
{
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
this.cancelCommand();
|
||||
this.tryToClosePopup = _.debounce(_.bind(this.tryToClosePopup, this), Magics.Time200ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.saveError('');
|
||||
if (oData && oData.ErrorCode)
|
||||
|
||||
onPluginSettingsUpdateResponse(result, data) {
|
||||
if (StorageResultType.Success === result && data && data.Result)
|
||||
{
|
||||
this.saveError(Translator.getNotification(oData.ErrorCode));
|
||||
this.cancelCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.saveError(Translator.getNotification(Enums.Notification.CantSavePluginSettings));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PluginPopupView.prototype.onShow = function(oPlugin)
|
||||
{
|
||||
this.name();
|
||||
this.readme();
|
||||
this.configures([]);
|
||||
|
||||
if (oPlugin)
|
||||
{
|
||||
this.name(oPlugin.Name);
|
||||
this.readme(oPlugin.Readme);
|
||||
|
||||
var aConfig = oPlugin.Config;
|
||||
|
||||
if (Utils.isNonEmptyArray(aConfig))
|
||||
{
|
||||
this.configures(_.map(aConfig, function(aItem) {
|
||||
return {
|
||||
'value': ko.observable(aItem[0]),
|
||||
'placeholder': ko.observable(aItem[6]),
|
||||
'Name': aItem[1],
|
||||
'Type': aItem[2],
|
||||
'Label': aItem[3],
|
||||
'Default': aItem[4],
|
||||
'Desc': aItem[5]
|
||||
};
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PluginPopupView.prototype.tryToClosePopup = function()
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
PopupsAskViewModel = require('View/Popup/Ask');
|
||||
|
||||
if (!kn.isPopupVisible(PopupsAskViewModel))
|
||||
{
|
||||
kn.showScreenPopup(PopupsAskViewModel, [Translator.i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'), function() {
|
||||
if (self.modalVisibility())
|
||||
this.saveError('');
|
||||
if (data && data.ErrorCode)
|
||||
{
|
||||
Utils.delegateRun(self, 'cancelCommand');
|
||||
this.saveError(getNotification(data.ErrorCode));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.saveError(getNotification(Notification.CantSavePluginSettings));
|
||||
}
|
||||
}]);
|
||||
}
|
||||
};
|
||||
|
||||
PluginPopupView.prototype.onBuild = function()
|
||||
{
|
||||
key('esc', Enums.KeyState.All, _.bind(function() {
|
||||
if (this.modalVisibility())
|
||||
{
|
||||
this.tryToClosePopup();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}, this));
|
||||
};
|
||||
onShow(oPlugin) {
|
||||
this.name();
|
||||
this.readme();
|
||||
this.configures([]);
|
||||
|
||||
if (oPlugin)
|
||||
{
|
||||
this.name(oPlugin.Name);
|
||||
this.readme(oPlugin.Readme);
|
||||
|
||||
const config = oPlugin.Config;
|
||||
if (isNonEmptyArray(config))
|
||||
{
|
||||
this.configures(_.map(config, (item) => ({
|
||||
'value': ko.observable(item[0]),
|
||||
'placeholder': ko.observable(item[6]),
|
||||
'Name': item[1],
|
||||
'Type': item[2],
|
||||
'Label': item[3],
|
||||
'Default': item[4],
|
||||
'Desc': item[5]
|
||||
})));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tryToClosePopup() {
|
||||
const PopupsAskViewModel = require('View/Popup/Ask');
|
||||
if (!isPopupVisible(PopupsAskViewModel))
|
||||
{
|
||||
showScreenPopup(PopupsAskViewModel, [i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'), () => {
|
||||
if (this.modalVisibility())
|
||||
{
|
||||
delegateRun(this, 'cancelCommand');
|
||||
}
|
||||
}]);
|
||||
}
|
||||
}
|
||||
|
||||
onBuild() {
|
||||
key('esc', KeyState.All, () => {
|
||||
if (this.modalVisibility())
|
||||
{
|
||||
this.tryToClosePopup();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PluginPopupView;
|
||||
|
|
|
|||
|
|
@ -1,199 +1,186 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
HtmlEditor = require('Common/HtmlEditor').default,
|
||||
import {StorageResultType, Notification} from 'Common/Enums';
|
||||
import {trim, isNormal, createCommand} from 'Common/Utils';
|
||||
import {getNotification} from 'Common/Translator';
|
||||
import {HtmlEditor} from 'Common/HtmlEditor';
|
||||
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function TemplatePopupView()
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/Popup/Template',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsTemplate'
|
||||
})
|
||||
class TemplatePopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsTemplate');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.editor = null;
|
||||
this.signatureDom = ko.observable(null);
|
||||
this.editor = null;
|
||||
this.signatureDom = ko.observable(null);
|
||||
|
||||
this.id = ko.observable('');
|
||||
this.id = ko.observable('');
|
||||
|
||||
this.name = ko.observable('');
|
||||
this.name.error = ko.observable(false);
|
||||
this.name.focus = 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.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.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)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
if (!this.editor && this.signatureDom())
|
||||
{
|
||||
this.editor = new HtmlEditor(self.signatureDom(), function() {
|
||||
self.populateBodyFromEditor();
|
||||
}, function() {
|
||||
self.editor.setHtmlOrPlain(sBody);
|
||||
this.name.subscribe(() => {
|
||||
this.name.error(false);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.editor.setHtmlOrPlain(sBody);
|
||||
}
|
||||
};
|
||||
|
||||
TemplatePopupView.prototype.onShow = function(oTemplate)
|
||||
{
|
||||
var self = this;
|
||||
this.body.subscribe(() => {
|
||||
this.body.error(false);
|
||||
});
|
||||
|
||||
this.clearPopup();
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
|
||||
if (oTemplate && oTemplate.id)
|
||||
{
|
||||
this.id(oTemplate.id);
|
||||
this.name(oTemplate.name);
|
||||
this.body(oTemplate.body);
|
||||
this.addTemplateCommand = createCommand(() => {
|
||||
|
||||
if (oTemplate.populated)
|
||||
{
|
||||
self.editorSetBody(this.body());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.body.loading(true);
|
||||
self.body.error(false);
|
||||
this.populateBodyFromEditor();
|
||||
|
||||
Remote.templateGetById(function(sResult, oData) {
|
||||
this.name.error('' === trim(this.name()));
|
||||
this.body.error('' === trim(this.body()) || ':HTML:' === trim(this.body()));
|
||||
|
||||
self.body.loading(false);
|
||||
if (this.name.error() || this.body.error())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result &&
|
||||
'Object/Template' === oData.Result['@Object'] && Utils.isNormal(oData.Result.Body))
|
||||
this.submitRequest(true);
|
||||
|
||||
Remote.templateSetup((result, data) => {
|
||||
|
||||
this.submitRequest(false);
|
||||
if (StorageResultType.Success === result && data)
|
||||
{
|
||||
oTemplate.body = oData.Result.Body;
|
||||
oTemplate.populated = true;
|
||||
|
||||
self.body(oTemplate.body);
|
||||
self.body.error(false);
|
||||
if (data.Result)
|
||||
{
|
||||
getApp().templates();
|
||||
this.cancelCommand();
|
||||
}
|
||||
else if (data.ErrorCode)
|
||||
{
|
||||
this.submitError(getNotification(data.ErrorCode));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self.body('');
|
||||
self.body.error(true);
|
||||
this.submitError(getNotification(Notification.UnknownError));
|
||||
}
|
||||
|
||||
self.editorSetBody(self.body());
|
||||
}, this.id(), this.name(), this.body());
|
||||
|
||||
}, this.id());
|
||||
return true;
|
||||
|
||||
}, () => !this.submitRequest());
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self.editorSetBody('');
|
||||
}
|
||||
};
|
||||
|
||||
TemplatePopupView.prototype.onShowWithDelay = function()
|
||||
{
|
||||
this.name.focus(true);
|
||||
};
|
||||
populateBodyFromEditor() {
|
||||
if (this.editor)
|
||||
{
|
||||
this.body(this.editor.getDataWithHtmlMark());
|
||||
}
|
||||
}
|
||||
|
||||
editorSetBody(sBody) {
|
||||
if (!this.editor && this.signatureDom())
|
||||
{
|
||||
this.editor = new HtmlEditor(this.signatureDom(), () => {
|
||||
this.populateBodyFromEditor();
|
||||
}, () => {
|
||||
this.editor.setHtmlOrPlain(sBody);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.editor.setHtmlOrPlain(sBody);
|
||||
}
|
||||
}
|
||||
|
||||
onShow(template) {
|
||||
|
||||
this.clearPopup();
|
||||
|
||||
if (template && template.id)
|
||||
{
|
||||
this.id(template.id);
|
||||
this.name(template.name);
|
||||
this.body(template.body);
|
||||
|
||||
if (template.populated)
|
||||
{
|
||||
this.editorSetBody(this.body());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.body.loading(true);
|
||||
this.body.error(false);
|
||||
|
||||
Remote.templateGetById((result, data) => {
|
||||
|
||||
this.body.loading(false);
|
||||
|
||||
if (StorageResultType.Success === result && data && data.Result &&
|
||||
'Object/Template' === data.Result['@Object'] && isNormal(data.Result.Body))
|
||||
{
|
||||
template.body = data.Result.Body;
|
||||
template.populated = true;
|
||||
|
||||
this.body(template.body);
|
||||
this.body.error(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.body('');
|
||||
this.body.error(true);
|
||||
}
|
||||
|
||||
this.editorSetBody(this.body());
|
||||
|
||||
}, this.id());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.editorSetBody('');
|
||||
}
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
this.name.focus(true);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TemplatePopupView;
|
||||
|
|
|
|||
|
|
@ -1,240 +1,217 @@
|
|||
|
||||
var
|
||||
window = require('window'),
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
qr = require('qr'),
|
||||
import window from 'window';
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
import qr from 'qr';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
import {Capa, StorageResultType} from 'Common/Enums';
|
||||
import {pString} from 'Common/Utils';
|
||||
import {i18n, trigger as translatorTrigger} from 'Common/Translator';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function TwoFactorConfigurationPopupView()
|
||||
import {view, ViewType, showScreenPopup} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/Popup/TwoFactorConfiguration',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsTwoFactorConfiguration'
|
||||
})
|
||||
class TwoFactorConfigurationPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsTwoFactorConfiguration');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.lock = ko.observable(false);
|
||||
this.lock = ko.observable(false);
|
||||
|
||||
this.capaTwoFactor = Settings.capa(Enums.Capa.TwoFactor);
|
||||
this.capaTwoFactor = Settings.capa(Capa.TwoFactor);
|
||||
|
||||
this.processing = ko.observable(false);
|
||||
this.clearing = ko.observable(false);
|
||||
this.secreting = ko.observable(false);
|
||||
this.processing = ko.observable(false);
|
||||
this.clearing = ko.observable(false);
|
||||
this.secreting = ko.observable(false);
|
||||
|
||||
this.viewUser = ko.observable('');
|
||||
this.twoFactorStatus = ko.observable(false);
|
||||
this.viewUser = ko.observable('');
|
||||
this.twoFactorStatus = ko.observable(false);
|
||||
|
||||
this.twoFactorTested = ko.observable(false);
|
||||
this.twoFactorTested = ko.observable(false);
|
||||
|
||||
this.viewSecret = ko.observable('');
|
||||
this.viewBackupCodes = ko.observable('');
|
||||
this.viewUrlTitle = ko.observable('');
|
||||
this.viewUrl = ko.observable('');
|
||||
this.viewSecret = ko.observable('');
|
||||
this.viewBackupCodes = ko.observable('');
|
||||
this.viewUrlTitle = ko.observable('');
|
||||
this.viewUrl = ko.observable('');
|
||||
|
||||
this.viewEnable_ = ko.observable(false);
|
||||
this.viewEnable_ = ko.observable(false);
|
||||
|
||||
this.viewEnable = ko.computed({
|
||||
'owner': this,
|
||||
'read': this.viewEnable_,
|
||||
'write': function(bValue) {
|
||||
|
||||
var self = this;
|
||||
|
||||
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)
|
||||
this.viewEnable = ko.computed({
|
||||
read: this.viewEnable_,
|
||||
write: (value) => {
|
||||
value = !!value;
|
||||
if (value && this.twoFactorTested())
|
||||
{
|
||||
this.viewEnable_(bValue);
|
||||
this.viewEnable_(value);
|
||||
Remote.enableTwoFactor((result, data) => {
|
||||
if (StorageResultType.Success !== result || !data || !data.Result)
|
||||
{
|
||||
this.viewEnable_(false);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
Remote.enableTwoFactor(function(sResult, oData) {
|
||||
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
|
||||
else
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
self.viewEnable_(false);
|
||||
this.viewEnable_(value);
|
||||
}
|
||||
|
||||
}, false);
|
||||
Remote.enableTwoFactor((result, data) => {
|
||||
if (StorageResultType.Success !== result || !data || !data.Result)
|
||||
{
|
||||
this.viewEnable_(false);
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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.viewTwoFactorEnableTooltip = ko.computed(() => {
|
||||
translatorTrigger();
|
||||
return this.twoFactorTested() || this.viewEnable_() ? '' :
|
||||
i18n('POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_TEST_BEFORE_DESC');
|
||||
});
|
||||
|
||||
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);
|
||||
this.viewTwoFactorStatus = ko.computed(() => {
|
||||
translatorTrigger();
|
||||
return i18n(this.twoFactorStatus() ?
|
||||
'POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_CONFIGURED_DESC' :
|
||||
'POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_NOT_CONFIGURED_DESC'
|
||||
);
|
||||
});
|
||||
|
||||
this.twoFactorAllowedEnable = ko.computed(function() {
|
||||
return this.viewEnable() || this.twoFactorTested();
|
||||
}, this);
|
||||
this.twoFactorAllowedEnable = ko.computed(() => this.viewEnable() || this.twoFactorTested());
|
||||
|
||||
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();
|
||||
this.onResult = _.bind(this.onResult, this);
|
||||
this.onShowSecretResult = _.bind(this.onShowSecretResult, this);
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
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()}));
|
||||
showSecret() {
|
||||
this.secreting(true);
|
||||
Remote.showTwoFactorSecret(this.onShowSecretResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.viewUser('');
|
||||
this.viewEnable_(false);
|
||||
this.twoFactorStatus(false);
|
||||
|
||||
hideSecret() {
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrlTitle('');
|
||||
this.viewUrl('');
|
||||
}
|
||||
|
||||
createTwoFactor() {
|
||||
this.processing(true);
|
||||
Remote.createTwoFactor(this.onResult);
|
||||
}
|
||||
|
||||
logout() {
|
||||
getApp().logout();
|
||||
}
|
||||
|
||||
testTwoFactor() {
|
||||
showScreenPopup(require('View/Popup/TwoFactorTest'), [this.twoFactorTested]);
|
||||
}
|
||||
|
||||
clearTwoFactor() {
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrlTitle('');
|
||||
this.viewUrl('');
|
||||
|
||||
this.twoFactorTested(false);
|
||||
|
||||
this.clearing(true);
|
||||
Remote.clearTwoFactor(this.onResult);
|
||||
}
|
||||
|
||||
onShow(bLock) {
|
||||
this.lock(!!bLock);
|
||||
|
||||
this.viewSecret('');
|
||||
this.viewBackupCodes('');
|
||||
this.viewUrlTitle('');
|
||||
this.viewUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.onShowSecretResult = function(sResult, oData)
|
||||
{
|
||||
this.secreting(false);
|
||||
onHide() {
|
||||
if (this.lock())
|
||||
{
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
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()}));
|
||||
getQr() {
|
||||
return 'otpauth://totp/' + window.encodeURIComponent(this.viewUser()) +
|
||||
'?secret=' + window.encodeURIComponent(this.viewSecret()) +
|
||||
'&issuer=' + window.encodeURIComponent('');
|
||||
}
|
||||
else
|
||||
{
|
||||
this.viewSecret('');
|
||||
this.viewUrlTitle('');
|
||||
this.viewUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
TwoFactorConfigurationPopupView.prototype.onBuild = function()
|
||||
{
|
||||
if (this.capaTwoFactor)
|
||||
{
|
||||
this.processing(true);
|
||||
Remote.getTwoFactor(this.onResult);
|
||||
onResult(sResult, oData) {
|
||||
this.processing(false);
|
||||
this.clearing(false);
|
||||
|
||||
if (StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
this.viewUser(pString(oData.Result.User));
|
||||
this.viewEnable_(!!oData.Result.Enable);
|
||||
this.twoFactorStatus(!!oData.Result.IsSet);
|
||||
this.twoFactorTested(!!oData.Result.Tested);
|
||||
|
||||
this.viewSecret(pString(oData.Result.Secret));
|
||||
this.viewBackupCodes(pString(oData.Result.BackupCodes).replace(/[\s]+/g, ' '));
|
||||
|
||||
this.viewUrlTitle(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('');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onShowSecretResult(result, data) {
|
||||
this.secreting(false);
|
||||
|
||||
if (StorageResultType.Success === result && data && data.Result)
|
||||
{
|
||||
this.viewSecret(pString(data.Result.Secret));
|
||||
this.viewUrlTitle(pString(data.Result.UrlTitle));
|
||||
this.viewUrl(qr.toDataURL({level: 'M', size: 6, value: this.getQr()}));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.viewSecret('');
|
||||
this.viewUrlTitle('');
|
||||
this.viewUrl('');
|
||||
}
|
||||
}
|
||||
|
||||
onBuild() {
|
||||
if (this.capaTwoFactor)
|
||||
{
|
||||
this.processing(true);
|
||||
Remote.getTwoFactor(this.onResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TwoFactorConfigurationPopupView;
|
||||
|
|
|
|||
|
|
@ -1,84 +1,73 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Globals = require('Common/Globals'),
|
||||
Utils = require('Common/Utils'),
|
||||
import {StorageResultType} from 'Common/Enums';
|
||||
import {bMobileDevice} from 'Common/Globals';
|
||||
import {createCommand} from 'Common/Utils';
|
||||
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function TwoFactorTestPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/TwoFactorTest',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsTwoFactorTest'
|
||||
})
|
||||
class TwoFactorTestPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsTwoFactorTest');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
var self = this;
|
||||
this.code = ko.observable('');
|
||||
this.code.focused = ko.observable(false);
|
||||
this.code.status = ko.observable(null);
|
||||
|
||||
this.code = ko.observable('');
|
||||
this.code.focused = ko.observable(false);
|
||||
this.code.status = ko.observable(null);
|
||||
this.koTestedTrigger = null;
|
||||
|
||||
this.koTestedTrigger = null;
|
||||
this.testing = ko.observable(false);
|
||||
|
||||
this.testing = ko.observable(false);
|
||||
// commands
|
||||
this.testCode = createCommand(() => {
|
||||
|
||||
// commands
|
||||
this.testCode = Utils.createCommand(this, function() {
|
||||
this.testing(true);
|
||||
Remote.testTwoFactor((result, data) => {
|
||||
|
||||
this.testing(true);
|
||||
Remote.testTwoFactor(function(sResult, oData) {
|
||||
this.testing(false);
|
||||
this.code.status(StorageResultType.Success === result && data && !!data.Result);
|
||||
|
||||
self.testing(false);
|
||||
self.code.status(Enums.StorageResultType.Success === sResult && oData && !!oData.Result);
|
||||
if (this.koTestedTrigger && this.code.status())
|
||||
{
|
||||
this.koTestedTrigger(true);
|
||||
}
|
||||
|
||||
if (self.koTestedTrigger && self.code.status())
|
||||
{
|
||||
self.koTestedTrigger(true);
|
||||
}
|
||||
}, this.code());
|
||||
|
||||
}, this.code());
|
||||
}, () => '' !== this.code() && !this.testing());
|
||||
}
|
||||
|
||||
}, function() {
|
||||
return '' !== this.code() && !this.testing();
|
||||
});
|
||||
clearPopup() {
|
||||
this.code('');
|
||||
this.code.focused(false);
|
||||
this.code.status(null);
|
||||
this.testing(false);
|
||||
|
||||
kn.constructorEnd(this);
|
||||
this.koTestedTrigger = null;
|
||||
}
|
||||
|
||||
onShow(koTestedTrigger) {
|
||||
this.clearPopup();
|
||||
|
||||
this.koTestedTrigger = koTestedTrigger;
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
if (!bMobileDevice)
|
||||
{
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,64 +1,56 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
key = require('key'),
|
||||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
import {KeyState} from 'Common/Enums';
|
||||
import {selectElement} from 'Common/Utils';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function ViewOpenPgpKeyPopupView()
|
||||
@view({
|
||||
name: 'View/Popup/ViewOpenPgpKey',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsTwoFactorTest'
|
||||
})
|
||||
class ViewOpenPgpKeyPopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsViewOpenPgpKey');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.key = ko.observable('');
|
||||
this.keyDom = ko.observable(null);
|
||||
this.key = ko.observable('');
|
||||
this.keyDom = ko.observable(null);
|
||||
|
||||
this.sDefaultKeyScope = Enums.KeyState.PopupViewOpenPGP;
|
||||
this.sDefaultKeyScope = KeyState.PopupViewOpenPGP;
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
clearPopup() {
|
||||
this.key('');
|
||||
}
|
||||
|
||||
selectKey() {
|
||||
const el = this.keyDom();
|
||||
if (el)
|
||||
{
|
||||
selectElement(el);
|
||||
}
|
||||
}
|
||||
|
||||
onShow(oOpenPgpKey) {
|
||||
this.clearPopup();
|
||||
|
||||
if (oOpenPgpKey)
|
||||
{
|
||||
this.key(oOpenPgpKey.armor);
|
||||
}
|
||||
}
|
||||
|
||||
onBuild() {
|
||||
key('ctrl+a, command+a', KeyState.PopupViewOpenPGP, () => {
|
||||
this.selectKey();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Utils.selectElement(oEl);
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,56 +1,48 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Promises = require('Promises/User/Ajax'),
|
||||
import Promises from 'Promises/User/Ajax';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function WelcomePagePopupView()
|
||||
@view({
|
||||
name: 'View/Popup/WelcomePage',
|
||||
type: ViewType.Popup,
|
||||
templateID: 'PopupsWelcomePage'
|
||||
})
|
||||
class WelcomePagePopupView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsWelcomePage');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.welcomePageURL = ko.observable('');
|
||||
this.welcomePageURL = ko.observable('');
|
||||
|
||||
this.closeFocused = ko.observable(false);
|
||||
this.closeFocused = ko.observable(false);
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
clearPopup() {
|
||||
this.welcomePageURL('');
|
||||
this.closeFocused(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} sUrl
|
||||
* @returns {void}
|
||||
*/
|
||||
onShow(sUrl) {
|
||||
this.clearPopup();
|
||||
|
||||
this.welcomePageURL(sUrl);
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
this.closeFocused(true);
|
||||
}
|
||||
|
||||
onHide() {
|
||||
Promises.welcomeClose();
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/WelcomePage', 'WelcomePagePopupViewModel'], WelcomePagePopupView);
|
||||
_.extend(WelcomePagePopupView.prototype, AbstractView.prototype);
|
||||
|
||||
WelcomePagePopupView.prototype.clearPopup = function()
|
||||
{
|
||||
this.welcomePageURL('');
|
||||
this.closeFocused(false);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sUrl
|
||||
* @returns {void}
|
||||
*/
|
||||
WelcomePagePopupView.prototype.onShow = function(sUrl)
|
||||
{
|
||||
this.clearPopup();
|
||||
|
||||
this.welcomePageURL(sUrl);
|
||||
};
|
||||
|
||||
WelcomePagePopupView.prototype.onShowWithDelay = function()
|
||||
{
|
||||
this.closeFocused(true);
|
||||
};
|
||||
|
||||
WelcomePagePopupView.prototype.onHide = function()
|
||||
{
|
||||
Promises.welcomeClose();
|
||||
};
|
||||
|
||||
module.exports = WelcomePagePopupView;
|
||||
|
|
|
|||
|
|
@ -1,27 +1,23 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import ko from 'ko';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function AboutUserView()
|
||||
@view({
|
||||
name: 'View/User/About',
|
||||
type: ViewType.Center,
|
||||
templateID: 'About'
|
||||
})
|
||||
class AboutUserView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Center', 'About');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.version = ko.observable(Settings.appSettingsGet('version'));
|
||||
|
||||
kn.constructorEnd(this);
|
||||
this.version = ko.observable(Settings.appSettingsGet('version'));
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/User/About', 'View/App/About', 'AboutViewModel'], AboutUserView);
|
||||
_.extend(AboutUserView.prototype, AbstractView.prototype);
|
||||
|
||||
module.exports = AboutUserView;
|
||||
export {AboutUserView, AboutUserView as default};
|
||||
|
|
|
|||
|
|
@ -1,138 +1,121 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
key = require('key'),
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Links = require('Common/Links'),
|
||||
Events = require('Common/Events'),
|
||||
import AppStore from 'Stores/User/App';
|
||||
import AccountStore from 'Stores/User/Account';
|
||||
import MessageStore from 'Stores/User/Message';
|
||||
|
||||
AppStore = require('Stores/User/App'),
|
||||
AccountStore = require('Stores/User/Account'),
|
||||
MessageStore = require('Stores/User/Message'),
|
||||
import {Capa, Magics, KeyState} from 'Common/Enums';
|
||||
import {trim, isUnd} from 'Common/Utils';
|
||||
import {settings} from 'Common/Links';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
import * as Events from 'Common/Events';
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function AbstractSystemDropDownUserView()
|
||||
import {view, ViewType, showScreenPopup, setHash} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
type: ViewType.Right,
|
||||
templateID: 'SystemDropDown'
|
||||
})
|
||||
class AbstractSystemDropDownUserView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Right', 'SystemDropDown');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.logoImg = Utils.trim(Settings.settingsGet('UserLogo'));
|
||||
this.logoTitle = Utils.trim(Settings.settingsGet('UserLogoTitle'));
|
||||
this.logoImg = trim(Settings.settingsGet('UserLogo'));
|
||||
this.logoTitle = trim(Settings.settingsGet('UserLogoTitle'));
|
||||
|
||||
this.mobile = !!Settings.appSettingsGet('mobile');
|
||||
this.mobileDevice = !!Settings.appSettingsGet('mobileDevice');
|
||||
this.mobile = !!Settings.appSettingsGet('mobile');
|
||||
this.mobileDevice = !!Settings.appSettingsGet('mobileDevice');
|
||||
|
||||
this.allowSettings = !!Settings.capa(Enums.Capa.Settings);
|
||||
this.allowHelp = !!Settings.capa(Enums.Capa.Help);
|
||||
this.allowSettings = !!Settings.capa(Capa.Settings);
|
||||
this.allowHelp = !!Settings.capa(Capa.Help);
|
||||
|
||||
this.currentAudio = AppStore.currentAudio;
|
||||
this.currentAudio = AppStore.currentAudio;
|
||||
|
||||
this.accountEmail = AccountStore.email;
|
||||
this.accountEmail = AccountStore.email;
|
||||
|
||||
this.accounts = AccountStore.accounts;
|
||||
this.accountsUnreadCount = AccountStore.accountsUnreadCount;
|
||||
this.accounts = AccountStore.accounts;
|
||||
this.accountsUnreadCount = AccountStore.accountsUnreadCount;
|
||||
|
||||
this.accountMenuDropdownTrigger = ko.observable(false);
|
||||
this.capaAdditionalAccounts = ko.observable(Settings.capa(Enums.Capa.AdditionalAccounts));
|
||||
this.accountMenuDropdownTrigger = ko.observable(false);
|
||||
this.capaAdditionalAccounts = ko.observable(Settings.capa(Capa.AdditionalAccounts));
|
||||
|
||||
this.accountClick = _.bind(this.accountClick, this);
|
||||
this.addAccountClick = _.bind(this.addAccountClick, this);
|
||||
|
||||
this.accountClick = _.bind(this.accountClick, this);
|
||||
Events.sub('audio.stop', () => AppStore.currentAudio(''));
|
||||
Events.sub('audio.start', (sName) => AppStore.currentAudio(sName));
|
||||
}
|
||||
|
||||
Events.sub('audio.stop', function() {
|
||||
AppStore.currentAudio('');
|
||||
});
|
||||
stopPlay() {
|
||||
Events.pub('audio.api.stop');
|
||||
}
|
||||
|
||||
Events.sub('audio.start', function(sName) {
|
||||
AppStore.currentAudio(sName);
|
||||
});
|
||||
accountClick(oAccount, oEvent) {
|
||||
if (oAccount && oEvent && !isUnd(oEvent.which) && 1 === oEvent.which)
|
||||
{
|
||||
AccountStore.accounts.loading(true);
|
||||
_.delay(() => AccountStore.accounts.loading(false), Magics.Time1s);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
emailTitle() {
|
||||
return AccountStore.email();
|
||||
}
|
||||
|
||||
settingsClick() {
|
||||
if (Settings.capa(Capa.Settings))
|
||||
{
|
||||
setHash(settings());
|
||||
}
|
||||
}
|
||||
|
||||
settingsHelp()
|
||||
{
|
||||
if (Settings.capa(Capa.Help))
|
||||
{
|
||||
showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
|
||||
}
|
||||
}
|
||||
|
||||
addAccountClick() {
|
||||
if (this.capaAdditionalAccounts())
|
||||
{
|
||||
showScreenPopup(require('View/Popup/Account'));
|
||||
}
|
||||
}
|
||||
|
||||
logoutClick() {
|
||||
getApp().logout();
|
||||
}
|
||||
|
||||
onBuild() {
|
||||
key('`', [KeyState.MessageList, KeyState.MessageView, KeyState.Settings], () => {
|
||||
if (this.viewModelVisibility())
|
||||
{
|
||||
MessageStore.messageFullScreenMode(false);
|
||||
this.accountMenuDropdownTrigger(true);
|
||||
}
|
||||
});
|
||||
|
||||
// shortcuts help
|
||||
key('shift+/', [KeyState.MessageList, KeyState.MessageView, KeyState.Settings], () => {
|
||||
if (this.viewModelVisibility())
|
||||
{
|
||||
showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_.extend(AbstractSystemDropDownUserView.prototype, AbstractView.prototype);
|
||||
|
||||
AbstractSystemDropDownUserView.prototype.stopPlay = function()
|
||||
{
|
||||
Events.pub('audio.api.stop');
|
||||
};
|
||||
|
||||
AbstractSystemDropDownUserView.prototype.accountClick = function(oAccount, oEvent)
|
||||
{
|
||||
if (oAccount && oEvent && !Utils.isUnd(oEvent.which) && 1 === oEvent.which)
|
||||
{
|
||||
AccountStore.accounts.loading(true);
|
||||
|
||||
_.delay(function() {
|
||||
AccountStore.accounts.loading(false);
|
||||
}, Enums.Magics.Time1s);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
AbstractSystemDropDownUserView.prototype.emailTitle = function()
|
||||
{
|
||||
return AccountStore.email();
|
||||
};
|
||||
|
||||
AbstractSystemDropDownUserView.prototype.settingsClick = function()
|
||||
{
|
||||
if (Settings.capa(Enums.Capa.Settings))
|
||||
{
|
||||
require('Knoin/Knoin').setHash(Links.settings());
|
||||
}
|
||||
};
|
||||
|
||||
AbstractSystemDropDownUserView.prototype.settingsHelp = function()
|
||||
{
|
||||
if (Settings.capa(Enums.Capa.Help))
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
|
||||
}
|
||||
};
|
||||
|
||||
AbstractSystemDropDownUserView.prototype.addAccountClick = function()
|
||||
{
|
||||
if (this.capaAdditionalAccounts())
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'));
|
||||
}
|
||||
};
|
||||
|
||||
AbstractSystemDropDownUserView.prototype.logoutClick = function()
|
||||
{
|
||||
require('App/User').default.logout();
|
||||
};
|
||||
|
||||
AbstractSystemDropDownUserView.prototype.onBuild = function()
|
||||
{
|
||||
var self = this;
|
||||
key('`', [Enums.KeyState.MessageList, Enums.KeyState.MessageView, Enums.KeyState.Settings], function() {
|
||||
if (self.viewModelVisibility())
|
||||
{
|
||||
MessageStore.messageFullScreenMode(false);
|
||||
|
||||
self.accountMenuDropdownTrigger(true);
|
||||
}
|
||||
});
|
||||
|
||||
// shortcuts help
|
||||
key('shift+/', [Enums.KeyState.MessageList, Enums.KeyState.MessageView, Enums.KeyState.Settings], function() {
|
||||
if (self.viewModelVisibility())
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = AbstractSystemDropDownUserView;
|
||||
export {AbstractSystemDropDownUserView, AbstractSystemDropDownUserView as default};
|
||||
|
|
|
|||
|
|
@ -3,487 +3,474 @@ import window from 'window';
|
|||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
var
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Links = require('Common/Links'),
|
||||
import {
|
||||
LoginSignMeType,
|
||||
LoginSignMeTypeAsString,
|
||||
ClientSideKeyName,
|
||||
StorageResultType,
|
||||
Magics,
|
||||
Notification
|
||||
} from 'Common/Enums';
|
||||
|
||||
Translator = require('Common/Translator'),
|
||||
import {
|
||||
trim, inArray, pInt,
|
||||
convertLangName,
|
||||
createCommand,
|
||||
triggerAutocompleteInputChange
|
||||
} from 'Common/Utils';
|
||||
|
||||
Plugins = require('Common/Plugins'),
|
||||
import {socialFacebook, socialGoogle, socialTwitter} from 'Common/Links';
|
||||
import {getNotification, getNotificationFromResponse, reload as translatorReload} from 'Common/Translator';
|
||||
|
||||
LanguageStore = require('Stores/Language'),
|
||||
AppStore = require('Stores/User/App'),
|
||||
import * as Plugins from 'Common/Plugins';
|
||||
|
||||
Local = require('Storage/Client'),
|
||||
Settings = require('Storage/Settings'),
|
||||
import AppStore from 'Stores/User/App';
|
||||
import LanguageStore from 'Stores/Language';
|
||||
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
import * as Settings from 'Storage/Settings';
|
||||
import * as Local from 'Storage/Client';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function LoginUserView()
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
import {view, ViewType, routeOff, showScreenPopup} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
@view({
|
||||
name: 'View/User/Login',
|
||||
type: ViewType.Center,
|
||||
templateID: 'Login'
|
||||
})
|
||||
class LoginUserView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Center', 'Login');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.welcome = ko.observable(!!Settings.settingsGet('UseLoginWelcomePage'));
|
||||
this.welcome = ko.observable(!!Settings.settingsGet('UseLoginWelcomePage'));
|
||||
|
||||
this.email = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
this.signMe = ko.observable(false);
|
||||
this.email = ko.observable('');
|
||||
this.password = ko.observable('');
|
||||
this.signMe = ko.observable(false);
|
||||
|
||||
this.additionalCode = ko.observable('');
|
||||
this.additionalCode.error = ko.observable(false);
|
||||
this.additionalCode.errorAnimation = ko.observable(false).extend({'falseTimeout': 500});
|
||||
this.additionalCode.focused = ko.observable(false);
|
||||
this.additionalCode.visibility = ko.observable(false);
|
||||
this.additionalCodeSignMe = ko.observable(false);
|
||||
this.additionalCode = ko.observable('');
|
||||
this.additionalCode.error = ko.observable(false);
|
||||
this.additionalCode.errorAnimation = ko.observable(false).extend({falseTimeout: 500});
|
||||
this.additionalCode.focused = ko.observable(false);
|
||||
this.additionalCode.visibility = ko.observable(false);
|
||||
this.additionalCodeSignMe = ko.observable(false);
|
||||
|
||||
this.logoImg = Utils.trim(Settings.settingsGet('LoginLogo'));
|
||||
this.logoPowered = !!Settings.settingsGet('LoginPowered');
|
||||
this.loginDescription = Utils.trim(Settings.settingsGet('LoginDescription'));
|
||||
this.logoImg = trim(Settings.settingsGet('LoginLogo'));
|
||||
this.logoPowered = !!Settings.settingsGet('LoginPowered');
|
||||
this.loginDescription = trim(Settings.settingsGet('LoginDescription'));
|
||||
|
||||
this.mobile = !!Settings.appSettingsGet('mobile');
|
||||
this.mobileDevice = !!Settings.appSettingsGet('mobileDevice');
|
||||
this.mobile = !!Settings.appSettingsGet('mobile');
|
||||
this.mobileDevice = !!Settings.appSettingsGet('mobileDevice');
|
||||
|
||||
this.forgotPasswordLinkUrl = Settings.appSettingsGet('forgotPasswordLinkUrl');
|
||||
this.registrationLinkUrl = Settings.appSettingsGet('registrationLinkUrl');
|
||||
this.forgotPasswordLinkUrl = Settings.appSettingsGet('forgotPasswordLinkUrl');
|
||||
this.registrationLinkUrl = Settings.appSettingsGet('registrationLinkUrl');
|
||||
|
||||
this.emailError = ko.observable(false);
|
||||
this.passwordError = ko.observable(false);
|
||||
this.emailError = ko.observable(false);
|
||||
this.passwordError = ko.observable(false);
|
||||
|
||||
this.emailErrorAnimation = ko.observable(false).extend({'falseTimeout': 500});
|
||||
this.passwordErrorAnimation = ko.observable(false).extend({'falseTimeout': 500});
|
||||
this.emailErrorAnimation = ko.observable(false).extend({falseTimeout: 500});
|
||||
this.passwordErrorAnimation = ko.observable(false).extend({falseTimeout: 500});
|
||||
|
||||
this.formHidden = ko.observable(false);
|
||||
this.formHidden = ko.observable(false);
|
||||
|
||||
this.formError = ko.computed(function() {
|
||||
return this.emailErrorAnimation() || this.passwordErrorAnimation() ||
|
||||
(this.additionalCode.visibility() && this.additionalCode.errorAnimation());
|
||||
}, this);
|
||||
this.formError = ko.computed(
|
||||
() => this.emailErrorAnimation() || this.passwordErrorAnimation() ||
|
||||
(this.additionalCode.visibility() && this.additionalCode.errorAnimation())
|
||||
);
|
||||
|
||||
this.emailFocus = ko.observable(false);
|
||||
this.passwordFocus = ko.observable(false);
|
||||
this.submitFocus = ko.observable(false);
|
||||
this.emailFocus = ko.observable(false);
|
||||
this.passwordFocus = ko.observable(false);
|
||||
this.submitFocus = ko.observable(false);
|
||||
|
||||
this.email.subscribe(function() {
|
||||
this.emailError(false);
|
||||
this.additionalCode('');
|
||||
this.additionalCode.visibility(false);
|
||||
}, this);
|
||||
this.email.subscribe(() => {
|
||||
this.emailError(false);
|
||||
this.additionalCode('');
|
||||
this.additionalCode.visibility(false);
|
||||
});
|
||||
|
||||
this.password.subscribe(function() {
|
||||
this.passwordError(false);
|
||||
}, this);
|
||||
this.password.subscribe(() => {
|
||||
this.passwordError(false);
|
||||
});
|
||||
|
||||
this.additionalCode.subscribe(function() {
|
||||
this.additionalCode.error(false);
|
||||
}, this);
|
||||
|
||||
this.additionalCode.visibility.subscribe(function() {
|
||||
this.additionalCode.error(false);
|
||||
}, this);
|
||||
|
||||
this.emailError.subscribe(function(bV) {
|
||||
this.emailErrorAnimation(!!bV);
|
||||
}, this);
|
||||
|
||||
this.passwordError.subscribe(function(bV) {
|
||||
this.passwordErrorAnimation(!!bV);
|
||||
}, this);
|
||||
|
||||
this.additionalCode.error.subscribe(function(bV) {
|
||||
this.additionalCode.errorAnimation(!!bV);
|
||||
}, this);
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
this.submitErrorAddidional = ko.observable('');
|
||||
|
||||
this.submitError.subscribe(function(sValue) {
|
||||
if ('' === sValue)
|
||||
{
|
||||
this.submitErrorAddidional('');
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.allowLanguagesOnLogin = AppStore.allowLanguagesOnLogin;
|
||||
|
||||
this.langRequest = ko.observable(false);
|
||||
this.language = LanguageStore.language;
|
||||
this.languages = LanguageStore.languages;
|
||||
|
||||
this.bSendLanguage = false;
|
||||
|
||||
this.languageFullName = ko.computed(function() {
|
||||
return Utils.convertLangName(this.language());
|
||||
}, this);
|
||||
|
||||
this.signMeType = ko.observable(Enums.LoginSignMeType.Unused);
|
||||
|
||||
this.signMeType.subscribe(function(iValue) {
|
||||
this.signMe(Enums.LoginSignMeType.DefaultOn === iValue);
|
||||
}, this);
|
||||
|
||||
this.signMeVisibility = ko.computed(function() {
|
||||
return Enums.LoginSignMeType.Unused !== this.signMeType();
|
||||
}, this);
|
||||
|
||||
this.submitCommand = Utils.createCommand(this, function() {
|
||||
Utils.triggerAutocompleteInputChange();
|
||||
|
||||
this.emailError(false);
|
||||
this.passwordError(false);
|
||||
|
||||
this.emailError('' === Utils.trim(this.email()));
|
||||
this.passwordError('' === Utils.trim(this.password()));
|
||||
|
||||
if (this.additionalCode.visibility())
|
||||
{
|
||||
this.additionalCode.subscribe(() => {
|
||||
this.additionalCode.error(false);
|
||||
this.additionalCode.error('' === Utils.trim(this.additionalCode()));
|
||||
}
|
||||
});
|
||||
|
||||
if (this.emailError() || this.passwordError() ||
|
||||
(this.additionalCode.visibility() && this.additionalCode.error()))
|
||||
{
|
||||
switch (true)
|
||||
this.additionalCode.visibility.subscribe(() => {
|
||||
this.additionalCode.error(false);
|
||||
});
|
||||
|
||||
this.emailError.subscribe((bV) => {
|
||||
this.emailErrorAnimation(!!bV);
|
||||
});
|
||||
|
||||
this.passwordError.subscribe((bV) => {
|
||||
this.passwordErrorAnimation(!!bV);
|
||||
});
|
||||
|
||||
this.additionalCode.error.subscribe((bV) => {
|
||||
this.additionalCode.errorAnimation(!!bV);
|
||||
});
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
this.submitErrorAddidional = ko.observable('');
|
||||
|
||||
this.submitError.subscribe((value) => {
|
||||
if ('' === value)
|
||||
{
|
||||
case this.emailError():
|
||||
this.emailFocus(true);
|
||||
break;
|
||||
case this.passwordError():
|
||||
this.passwordFocus(true);
|
||||
break;
|
||||
case this.additionalCode.visibility() && this.additionalCode.error():
|
||||
this.additionalCode.focused(true);
|
||||
break;
|
||||
// no default
|
||||
this.submitErrorAddidional('');
|
||||
}
|
||||
});
|
||||
|
||||
this.allowLanguagesOnLogin = AppStore.allowLanguagesOnLogin;
|
||||
|
||||
this.langRequest = ko.observable(false);
|
||||
this.language = LanguageStore.language;
|
||||
this.languages = LanguageStore.languages;
|
||||
|
||||
this.bSendLanguage = false;
|
||||
|
||||
this.languageFullName = ko.computed(
|
||||
() => convertLangName(this.language())
|
||||
);
|
||||
|
||||
this.signMeType = ko.observable(LoginSignMeType.Unused);
|
||||
|
||||
this.signMeType.subscribe((iValue) => {
|
||||
this.signMe(LoginSignMeType.DefaultOn === iValue);
|
||||
});
|
||||
|
||||
this.signMeVisibility = ko.computed(
|
||||
() => LoginSignMeType.Unused !== this.signMeType()
|
||||
);
|
||||
|
||||
this.submitCommand = createCommand(() => {
|
||||
triggerAutocompleteInputChange();
|
||||
|
||||
this.emailError(false);
|
||||
this.passwordError(false);
|
||||
|
||||
this.emailError('' === trim(this.email()));
|
||||
this.passwordError('' === trim(this.password()));
|
||||
|
||||
if (this.additionalCode.visibility())
|
||||
{
|
||||
this.additionalCode.error(false);
|
||||
this.additionalCode.error('' === trim(this.additionalCode()));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
if (this.emailError() || this.passwordError() ||
|
||||
(this.additionalCode.visibility() && this.additionalCode.error()))
|
||||
{
|
||||
switch (true)
|
||||
{
|
||||
case this.emailError():
|
||||
this.emailFocus(true);
|
||||
break;
|
||||
case this.passwordError():
|
||||
this.passwordFocus(true);
|
||||
break;
|
||||
case this.additionalCode.visibility() && this.additionalCode.error():
|
||||
this.additionalCode.focused(true);
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
|
||||
var
|
||||
iPluginResultCode = 0,
|
||||
sPluginResultMessage = '',
|
||||
fSubmitResult = function(iResultCode, sResultMessage) {
|
||||
iPluginResultCode = iResultCode || 0;
|
||||
sPluginResultMessage = sResultMessage || '';
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugins.runHook('user-login-submit', [fSubmitResult]);
|
||||
if (0 < iPluginResultCode)
|
||||
{
|
||||
this.submitError(Translator.getNotification(iPluginResultCode));
|
||||
return false;
|
||||
}
|
||||
else if ('' !== sPluginResultMessage)
|
||||
{
|
||||
this.submitError(sPluginResultMessage);
|
||||
return false;
|
||||
}
|
||||
let
|
||||
pluginResultCode = 0,
|
||||
pluginResultMessage = '';
|
||||
|
||||
this.submitRequest(true);
|
||||
const
|
||||
fSubmitResult = (iResultCode, sResultMessage) => {
|
||||
pluginResultCode = iResultCode || 0;
|
||||
pluginResultMessage = sResultMessage || '';
|
||||
};
|
||||
|
||||
var
|
||||
self = this,
|
||||
sPassword = this.password(),
|
||||
Plugins.runHook('user-login-submit', [fSubmitResult]);
|
||||
if (0 < pluginResultCode)
|
||||
{
|
||||
this.submitError(getNotification(pluginResultCode));
|
||||
return false;
|
||||
}
|
||||
else if ('' !== pluginResultMessage)
|
||||
{
|
||||
this.submitError(pluginResultMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
fLoginRequest = _.bind(function(sLoginPassword) {
|
||||
this.submitRequest(true);
|
||||
|
||||
Remote.login(_.bind(function(sResult, oData) {
|
||||
const
|
||||
fLoginRequest = (sLoginPassword) => {
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && 'Login' === oData.Action)
|
||||
{
|
||||
if (oData.Result)
|
||||
Remote.login((sResult, oData) => {
|
||||
|
||||
if (StorageResultType.Success === sResult && oData && 'Login' === oData.Action)
|
||||
{
|
||||
if (oData.TwoFactorAuth)
|
||||
if (oData.Result)
|
||||
{
|
||||
if (oData.TwoFactorAuth)
|
||||
{
|
||||
this.additionalCode('');
|
||||
this.additionalCode.visibility(true);
|
||||
this.submitRequest(false);
|
||||
|
||||
_.delay(() => this.additionalCode.focused(true), Magics.Time100ms);
|
||||
}
|
||||
else if (oData.Admin)
|
||||
{
|
||||
getApp().redirectToAdminPanel();
|
||||
}
|
||||
else
|
||||
{
|
||||
getApp().loginAndLogoutReload(false);
|
||||
}
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
{
|
||||
this.additionalCode('');
|
||||
this.additionalCode.visibility(true);
|
||||
this.submitRequest(false);
|
||||
if (-1 < inArray(oData.ErrorCode, [Notification.InvalidInputArgument]))
|
||||
{
|
||||
oData.ErrorCode = Notification.AuthError;
|
||||
}
|
||||
|
||||
_.delay(function() {
|
||||
self.additionalCode.focused(true);
|
||||
}, Enums.Magics.Time100ms);
|
||||
}
|
||||
else if (oData.Admin)
|
||||
{
|
||||
require('App/User').default.redirectToAdminPanel();
|
||||
}
|
||||
else
|
||||
{
|
||||
require('App/User').default.loginAndLogoutReload(false);
|
||||
}
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
{
|
||||
this.submitRequest(false);
|
||||
if (-1 < Utils.inArray(oData.ErrorCode, [Enums.Notification.InvalidInputArgument]))
|
||||
{
|
||||
oData.ErrorCode = Enums.Notification.AuthError;
|
||||
}
|
||||
this.submitError(getNotificationFromResponse(oData));
|
||||
|
||||
this.submitError(Translator.getNotificationFromResponse(oData));
|
||||
|
||||
if ('' === this.submitError())
|
||||
{
|
||||
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oData.ErrorMessageAdditional)
|
||||
if ('' === this.submitError())
|
||||
{
|
||||
this.submitError(getNotification(Notification.UnknownError));
|
||||
}
|
||||
else if (oData.ErrorMessageAdditional)
|
||||
{
|
||||
this.submitErrorAddidional(oData.ErrorMessageAdditional);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitRequest(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitRequest(false);
|
||||
this.submitError(getNotification(Notification.UnknownError));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitRequest(false);
|
||||
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
|
||||
}
|
||||
|
||||
}, this), this.email(), '', sLoginPassword, !!this.signMe(),
|
||||
this.bSendLanguage ? this.language() : '',
|
||||
this.additionalCode.visibility() ? this.additionalCode() : '',
|
||||
this.additionalCode.visibility() ? !!this.additionalCodeSignMe() : false
|
||||
);
|
||||
}, this.email(), '', sLoginPassword, !!this.signMe(),
|
||||
this.bSendLanguage ? this.language() : '',
|
||||
this.additionalCode.visibility() ? this.additionalCode() : '',
|
||||
this.additionalCode.visibility() ? !!this.additionalCodeSignMe() : false
|
||||
);
|
||||
|
||||
Local.set(Enums.ClientSideKeyName.LastSignMe, this.signMe() ? '-1-' : '-0-');
|
||||
Local.set(ClientSideKeyName.LastSignMe, this.signMe() ? '-1-' : '-0-');
|
||||
|
||||
}, this);
|
||||
};
|
||||
|
||||
fLoginRequest(sPassword);
|
||||
fLoginRequest(this.password());
|
||||
|
||||
return true;
|
||||
}, function() {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
return true;
|
||||
|
||||
this.facebookLoginEnabled = ko.observable(false);
|
||||
}, () => !this.submitRequest());
|
||||
|
||||
this.facebookCommand = Utils.createCommand(this, function() {
|
||||
window.open(Links.socialFacebook(), 'Facebook',
|
||||
'left=200,top=100,width=500,height=500,menubar=no,status=no,resizable=yes,scrollbars=yes');
|
||||
return true;
|
||||
}, function() {
|
||||
return !this.submitRequest() && this.facebookLoginEnabled();
|
||||
});
|
||||
this.facebookLoginEnabled = ko.observable(false);
|
||||
|
||||
this.googleLoginEnabled = ko.observable(false);
|
||||
this.googleFastLoginEnabled = ko.observable(false);
|
||||
this.facebookCommand = createCommand(() => {
|
||||
window.open(socialFacebook(), 'Facebook',
|
||||
'left=200,top=100,width=500,height=500,menubar=no,status=no,resizable=yes,scrollbars=yes');
|
||||
return true;
|
||||
}, () => !this.submitRequest() && this.facebookLoginEnabled());
|
||||
|
||||
this.googleCommand = Utils.createCommand(this, function() {
|
||||
window.open(Links.socialGoogle(), 'Google',
|
||||
'left=200,top=100,width=550,height=550,menubar=no,status=no,resizable=yes,scrollbars=yes');
|
||||
return true;
|
||||
}, function() {
|
||||
return !this.submitRequest() && this.googleLoginEnabled();
|
||||
});
|
||||
this.googleLoginEnabled = ko.observable(false);
|
||||
this.googleFastLoginEnabled = ko.observable(false);
|
||||
|
||||
this.googleFastCommand = Utils.createCommand(this, function() {
|
||||
window.open(Links.socialGoogle(true), 'Google',
|
||||
'left=200,top=100,width=550,height=550,menubar=no,status=no,resizable=yes,scrollbars=yes');
|
||||
return true;
|
||||
}, function() {
|
||||
return !this.submitRequest() && this.googleFastLoginEnabled();
|
||||
});
|
||||
this.googleCommand = createCommand(() => {
|
||||
window.open(socialGoogle(), 'Google',
|
||||
'left=200,top=100,width=550,height=550,menubar=no,status=no,resizable=yes,scrollbars=yes');
|
||||
return true;
|
||||
}, () => !this.submitRequest() && this.googleLoginEnabled());
|
||||
|
||||
this.twitterLoginEnabled = ko.observable(false);
|
||||
this.googleFastCommand = createCommand(() => {
|
||||
window.open(socialGoogle(true), 'Google',
|
||||
'left=200,top=100,width=550,height=550,menubar=no,status=no,resizable=yes,scrollbars=yes');
|
||||
return true;
|
||||
}, () => !this.submitRequest() && this.googleFastLoginEnabled());
|
||||
|
||||
this.twitterCommand = Utils.createCommand(this, function() {
|
||||
window.open(Links.socialTwitter(), 'Twitter',
|
||||
'left=200,top=100,width=500,height=500,menubar=no,status=no,resizable=yes,scrollbars=yes');
|
||||
return true;
|
||||
}, function() {
|
||||
return !this.submitRequest() && this.twitterLoginEnabled();
|
||||
});
|
||||
this.twitterLoginEnabled = ko.observable(false);
|
||||
|
||||
this.socialLoginEnabled = ko.computed(function() {
|
||||
var
|
||||
bF = this.facebookLoginEnabled(),
|
||||
bG = this.googleLoginEnabled(),
|
||||
bT = this.twitterLoginEnabled();
|
||||
this.twitterCommand = createCommand(() => {
|
||||
window.open(socialTwitter(), 'Twitter',
|
||||
'left=200,top=100,width=500,height=500,menubar=no,status=no,resizable=yes,scrollbars=yes');
|
||||
return true;
|
||||
}, () => !this.submitRequest() && this.twitterLoginEnabled());
|
||||
|
||||
return bF || bG || bT;
|
||||
}, this);
|
||||
|
||||
if (Settings.settingsGet('AdditionalLoginError') && !this.submitError())
|
||||
{
|
||||
this.submitError(Settings.settingsGet('AdditionalLoginError'));
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/User/Login', 'View/App/Login', 'LoginViewModel'], LoginUserView);
|
||||
_.extend(LoginUserView.prototype, AbstractView.prototype);
|
||||
|
||||
LoginUserView.prototype.displayMainForm = function()
|
||||
{
|
||||
this.welcome(false);
|
||||
};
|
||||
|
||||
LoginUserView.prototype.onShow = function()
|
||||
{
|
||||
kn.routeOff();
|
||||
};
|
||||
|
||||
LoginUserView.prototype.onShowWithDelay = function()
|
||||
{
|
||||
if ('' !== this.email() && '' !== this.password())
|
||||
{
|
||||
this.submitFocus(true);
|
||||
}
|
||||
else if ('' === this.email())
|
||||
{
|
||||
this.emailFocus(true);
|
||||
}
|
||||
else if ('' === this.password())
|
||||
{
|
||||
this.passwordFocus(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.emailFocus(true);
|
||||
}
|
||||
};
|
||||
|
||||
LoginUserView.prototype.onHide = function()
|
||||
{
|
||||
this.submitFocus(false);
|
||||
this.emailFocus(false);
|
||||
this.passwordFocus(false);
|
||||
};
|
||||
|
||||
LoginUserView.prototype.onBuild = function()
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
sSignMeLocal = Local.get(Enums.ClientSideKeyName.LastSignMe),
|
||||
sSignMe = (Settings.settingsGet('SignMe') || 'unused').toLowerCase(),
|
||||
sJsHash = Settings.appSettingsGet('jsHash'),
|
||||
fSocial = function(iErrorCode) {
|
||||
iErrorCode = Utils.pInt(iErrorCode);
|
||||
if (0 === iErrorCode)
|
||||
{
|
||||
self.submitRequest(true);
|
||||
require('App/User').default.loginAndLogoutReload(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.submitError(Translator.getNotification(iErrorCode));
|
||||
}
|
||||
};
|
||||
|
||||
this.facebookLoginEnabled(!!Settings.settingsGet('AllowFacebookSocial'));
|
||||
this.twitterLoginEnabled(!!Settings.settingsGet('AllowTwitterSocial'));
|
||||
this.googleLoginEnabled(!!Settings.settingsGet('AllowGoogleSocial') &&
|
||||
!!Settings.settingsGet('AllowGoogleSocialAuth'));
|
||||
this.googleFastLoginEnabled(!!Settings.settingsGet('AllowGoogleSocial') &&
|
||||
!!Settings.settingsGet('AllowGoogleSocialAuthFast'));
|
||||
|
||||
switch (sSignMe)
|
||||
{
|
||||
case Enums.LoginSignMeTypeAsString.DefaultOff:
|
||||
case Enums.LoginSignMeTypeAsString.DefaultOn:
|
||||
|
||||
this.signMeType(Enums.LoginSignMeTypeAsString.DefaultOn === sSignMe ?
|
||||
Enums.LoginSignMeType.DefaultOn : Enums.LoginSignMeType.DefaultOff);
|
||||
|
||||
switch (sSignMeLocal)
|
||||
{
|
||||
case '-1-':
|
||||
this.signMeType(Enums.LoginSignMeType.DefaultOn);
|
||||
break;
|
||||
case '-0-':
|
||||
this.signMeType(Enums.LoginSignMeType.DefaultOff);
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
|
||||
break;
|
||||
case Enums.LoginSignMeTypeAsString.Unused:
|
||||
default:
|
||||
this.signMeType(Enums.LoginSignMeType.Unused);
|
||||
break;
|
||||
}
|
||||
|
||||
this.email(AppStore.devEmail);
|
||||
this.password(AppStore.devPassword);
|
||||
|
||||
if (this.googleLoginEnabled() || this.googleFastLoginEnabled())
|
||||
{
|
||||
window['rl_' + sJsHash + '_google_login_service'] = fSocial;
|
||||
}
|
||||
|
||||
if (this.facebookLoginEnabled())
|
||||
{
|
||||
window['rl_' + sJsHash + '_facebook_login_service'] = fSocial;
|
||||
}
|
||||
|
||||
if (this.twitterLoginEnabled())
|
||||
{
|
||||
window['rl_' + sJsHash + '_twitter_login_service'] = fSocial;
|
||||
}
|
||||
|
||||
_.delay(function() {
|
||||
|
||||
LanguageStore.language.subscribe(function(sValue) {
|
||||
|
||||
self.langRequest(true);
|
||||
|
||||
Translator.reload(false, sValue).then(function() {
|
||||
self.langRequest(false);
|
||||
self.bSendLanguage = true;
|
||||
}, function() {
|
||||
self.langRequest(false);
|
||||
});
|
||||
this.socialLoginEnabled = ko.computed(() => {
|
||||
const
|
||||
bF = this.facebookLoginEnabled(),
|
||||
bG = this.googleLoginEnabled(),
|
||||
bT = this.twitterLoginEnabled();
|
||||
|
||||
return bF || bG || bT;
|
||||
});
|
||||
|
||||
}, Enums.Magics.Time50ms);
|
||||
|
||||
Utils.triggerAutocompleteInputChange(true);
|
||||
};
|
||||
|
||||
LoginUserView.prototype.submitForm = function()
|
||||
{
|
||||
this.submitCommand();
|
||||
};
|
||||
|
||||
LoginUserView.prototype.selectLanguage = function()
|
||||
{
|
||||
kn.showScreenPopup(require('View/Popup/Languages'), [
|
||||
this.language, this.languages(), LanguageStore.userLanguage()
|
||||
]);
|
||||
};
|
||||
|
||||
LoginUserView.prototype.selectLanguageOnTab = function(bShift)
|
||||
{
|
||||
if (!bShift)
|
||||
{
|
||||
var self = this;
|
||||
_.delay(function() {
|
||||
self.emailFocus(true);
|
||||
}, Enums.Magics.Time50ms);
|
||||
|
||||
return false;
|
||||
if (Settings.settingsGet('AdditionalLoginError') && !this.submitError())
|
||||
{
|
||||
this.submitError(Settings.settingsGet('AdditionalLoginError'));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
displayMainForm() {
|
||||
this.welcome(false);
|
||||
}
|
||||
|
||||
module.exports = LoginUserView;
|
||||
onShow() {
|
||||
routeOff();
|
||||
}
|
||||
|
||||
onShowWithDelay() {
|
||||
if ('' !== this.email() && '' !== this.password())
|
||||
{
|
||||
this.submitFocus(true);
|
||||
}
|
||||
else if ('' === this.email())
|
||||
{
|
||||
this.emailFocus(true);
|
||||
}
|
||||
else if ('' === this.password())
|
||||
{
|
||||
this.passwordFocus(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.emailFocus(true);
|
||||
}
|
||||
}
|
||||
|
||||
onHide() {
|
||||
this.submitFocus(false);
|
||||
this.emailFocus(false);
|
||||
this.passwordFocus(false);
|
||||
}
|
||||
|
||||
onBuild() {
|
||||
const
|
||||
signMeLocal = Local.get(ClientSideKeyName.LastSignMe),
|
||||
signMe = (Settings.settingsGet('SignMe') || 'unused').toLowerCase(),
|
||||
jsHash = Settings.appSettingsGet('jsHash'),
|
||||
fSocial = (iErrorCode) => {
|
||||
iErrorCode = pInt(iErrorCode);
|
||||
if (0 === iErrorCode)
|
||||
{
|
||||
this.submitRequest(true);
|
||||
getApp().loginAndLogoutReload(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitError(getNotification(iErrorCode));
|
||||
}
|
||||
};
|
||||
|
||||
this.facebookLoginEnabled(!!Settings.settingsGet('AllowFacebookSocial'));
|
||||
this.twitterLoginEnabled(!!Settings.settingsGet('AllowTwitterSocial'));
|
||||
this.googleLoginEnabled(!!Settings.settingsGet('AllowGoogleSocial') &&
|
||||
!!Settings.settingsGet('AllowGoogleSocialAuth'));
|
||||
this.googleFastLoginEnabled(!!Settings.settingsGet('AllowGoogleSocial') &&
|
||||
!!Settings.settingsGet('AllowGoogleSocialAuthFast'));
|
||||
|
||||
switch (signMe)
|
||||
{
|
||||
case LoginSignMeTypeAsString.DefaultOff:
|
||||
case LoginSignMeTypeAsString.DefaultOn:
|
||||
|
||||
this.signMeType(LoginSignMeTypeAsString.DefaultOn === signMe ?
|
||||
LoginSignMeType.DefaultOn : LoginSignMeType.DefaultOff);
|
||||
|
||||
switch (signMeLocal)
|
||||
{
|
||||
case '-1-':
|
||||
this.signMeType(LoginSignMeType.DefaultOn);
|
||||
break;
|
||||
case '-0-':
|
||||
this.signMeType(LoginSignMeType.DefaultOff);
|
||||
break;
|
||||
// no default
|
||||
}
|
||||
|
||||
break;
|
||||
case LoginSignMeTypeAsString.Unused:
|
||||
default:
|
||||
this.signMeType(LoginSignMeType.Unused);
|
||||
break;
|
||||
}
|
||||
|
||||
this.email(AppStore.devEmail);
|
||||
this.password(AppStore.devPassword);
|
||||
|
||||
if (this.googleLoginEnabled() || this.googleFastLoginEnabled())
|
||||
{
|
||||
window['rl_' + jsHash + '_google_login_service'] = fSocial;
|
||||
}
|
||||
|
||||
if (this.facebookLoginEnabled())
|
||||
{
|
||||
window['rl_' + jsHash + '_facebook_login_service'] = fSocial;
|
||||
}
|
||||
|
||||
if (this.twitterLoginEnabled())
|
||||
{
|
||||
window['rl_' + jsHash + '_twitter_login_service'] = fSocial;
|
||||
}
|
||||
|
||||
_.delay(() => {
|
||||
|
||||
LanguageStore.language.subscribe((sValue) => {
|
||||
|
||||
this.langRequest(true);
|
||||
|
||||
translatorReload(false, sValue).then(() => {
|
||||
this.langRequest(false);
|
||||
this.bSendLanguage = true;
|
||||
}, () => {
|
||||
this.langRequest(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}, Magics.Time50ms);
|
||||
|
||||
triggerAutocompleteInputChange(true);
|
||||
}
|
||||
|
||||
submitForm() {
|
||||
this.submitCommand();
|
||||
}
|
||||
|
||||
selectLanguage() {
|
||||
showScreenPopup(require('View/Popup/Languages'), [
|
||||
this.language, this.languages(), LanguageStore.userLanguage()
|
||||
]);
|
||||
}
|
||||
|
||||
selectLanguageOnTab(bShift) {
|
||||
if (!bShift)
|
||||
{
|
||||
_.delay(() => {
|
||||
this.emailFocus(true);
|
||||
}, Magics.Time50ms);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export {LoginUserView, LoginUserView as default};
|
||||
|
|
|
|||
|
|
@ -1,306 +1,290 @@
|
|||
|
||||
var
|
||||
window = require('window'),
|
||||
_ = require('_'),
|
||||
$ = require('$'),
|
||||
ko = require('ko'),
|
||||
key = require('key'),
|
||||
import window from 'window';
|
||||
import $ from '$';
|
||||
import ko from 'ko';
|
||||
import key from 'key';
|
||||
|
||||
Utils = require('Common/Utils'),
|
||||
Enums = require('Common/Enums'),
|
||||
Globals = require('Common/Globals'),
|
||||
Links = require('Common/Links'),
|
||||
import {trim, isNormal, isArray, windowResize} from 'Common/Utils';
|
||||
import {Capa, Focused, Layout, KeyState, EventKeyCode, Magics} from 'Common/Enums';
|
||||
import {$html, leftPanelDisabled} from 'Common/Globals';
|
||||
import {mailBox, settings} from 'Common/Links';
|
||||
import {setFolderHash} from 'Common/Cache';
|
||||
|
||||
Cache = require('Common/Cache'),
|
||||
import AppStore from 'Stores/User/App';
|
||||
import SettingsStore from 'Stores/User/Settings';
|
||||
import FolderStore from 'Stores/User/Folder';
|
||||
import MessageStore from 'Stores/User/Message';
|
||||
|
||||
AppStore = require('Stores/User/App'),
|
||||
SettingsStore = require('Stores/User/Settings'),
|
||||
FolderStore = require('Stores/User/Folder'),
|
||||
MessageStore = require('Stores/User/Message'),
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
import {getApp} from 'Helper/Apps/User';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType, showScreenPopup, setHash} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function FolderListMailBoxUserView()
|
||||
@view({
|
||||
name: 'View/User/MailBox/FolderList',
|
||||
type: ViewType.Left,
|
||||
templateID: 'MailFolderList'
|
||||
})
|
||||
class FolderListMailBoxUserView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Left', 'MailFolderList');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.oContentVisible = null;
|
||||
this.oContentScrollable = null;
|
||||
this.oContentVisible = null;
|
||||
this.oContentScrollable = null;
|
||||
|
||||
this.composeInEdit = AppStore.composeInEdit;
|
||||
this.composeInEdit = AppStore.composeInEdit;
|
||||
|
||||
this.messageList = MessageStore.messageList;
|
||||
this.folderList = FolderStore.folderList;
|
||||
this.folderListSystem = FolderStore.folderListSystem;
|
||||
this.foldersChanging = FolderStore.foldersChanging;
|
||||
this.messageList = MessageStore.messageList;
|
||||
this.folderList = FolderStore.folderList;
|
||||
this.folderListSystem = FolderStore.folderListSystem;
|
||||
this.foldersChanging = FolderStore.foldersChanging;
|
||||
|
||||
this.foldersListWithSingleInboxRootFolder = FolderStore.foldersListWithSingleInboxRootFolder;
|
||||
this.foldersListWithSingleInboxRootFolder = FolderStore.foldersListWithSingleInboxRootFolder;
|
||||
|
||||
this.leftPanelDisabled = Globals.leftPanelDisabled;
|
||||
this.leftPanelDisabled = leftPanelDisabled;
|
||||
|
||||
this.iDropOverTimer = 0;
|
||||
this.iDropOverTimer = 0;
|
||||
|
||||
this.allowComposer = !!Settings.capa(Enums.Capa.Composer);
|
||||
this.allowContacts = !!AppStore.contactsIsAllowed();
|
||||
this.allowFolders = !!Settings.capa(Enums.Capa.Folders);
|
||||
this.allowComposer = !!Settings.capa(Capa.Composer);
|
||||
this.allowContacts = !!AppStore.contactsIsAllowed();
|
||||
this.allowFolders = !!Settings.capa(Capa.Folders);
|
||||
|
||||
this.folderListFocused = ko.computed(function() {
|
||||
return Enums.Focused.FolderList === AppStore.focusedState();
|
||||
});
|
||||
this.folderListFocused = ko.computed(() => Focused.FolderList === AppStore.focusedState());
|
||||
|
||||
this.isInboxStarred = ko.computed(function() {
|
||||
return FolderStore.currentFolder() &&
|
||||
FolderStore.currentFolder().isInbox() &&
|
||||
-1 < Utils.trim(MessageStore.messageListSearch()).indexOf('is:flagged');
|
||||
});
|
||||
this.isInboxStarred = ko.computed(
|
||||
() => FolderStore.currentFolder() &&
|
||||
FolderStore.currentFolder().isInbox() &&
|
||||
-1 < trim(MessageStore.messageListSearch()).indexOf('is:flagged')
|
||||
);
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
onBuild(dom) {
|
||||
|
||||
kn.extendAsViewModel(['View/User/MailBox/FolderList', 'View/App/MailBox/FolderList', 'MailBoxFolderListViewModel'], FolderListMailBoxUserView);
|
||||
_.extend(FolderListMailBoxUserView.prototype, AbstractView.prototype);
|
||||
this.oContentVisible = $('.b-content', dom);
|
||||
this.oContentScrollable = $('.content', this.oContentVisible);
|
||||
|
||||
FolderListMailBoxUserView.prototype.onBuild = function(oDom)
|
||||
{
|
||||
this.oContentVisible = $('.b-content', oDom);
|
||||
this.oContentScrollable = $('.content', this.oContentVisible);
|
||||
const
|
||||
self = this,
|
||||
isMobile = Settings.appSettingsGet('mobile'),
|
||||
fSelectFolder = (el, event, starred) => {
|
||||
|
||||
var
|
||||
self = this,
|
||||
bMobile = Settings.appSettingsGet('mobile'),
|
||||
fSelectFolder = function(oEvent, bStarred) {
|
||||
|
||||
if (bMobile)
|
||||
{
|
||||
Globals.leftPanelDisabled(true);
|
||||
}
|
||||
|
||||
oEvent.preventDefault();
|
||||
|
||||
if (bStarred)
|
||||
{
|
||||
oEvent.stopPropagation();
|
||||
}
|
||||
|
||||
var
|
||||
oFolder = ko.dataFor(this);
|
||||
|
||||
if (oFolder)
|
||||
{
|
||||
if (Enums.Layout.NoPreview === SettingsStore.layout())
|
||||
if (isMobile)
|
||||
{
|
||||
MessageStore.message(null);
|
||||
leftPanelDisabled(true);
|
||||
}
|
||||
|
||||
if (oFolder.fullNameRaw === FolderStore.currentFolderFullNameRaw())
|
||||
event.preventDefault();
|
||||
|
||||
if (starred)
|
||||
{
|
||||
Cache.setFolderHash(oFolder.fullNameRaw, '');
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
if (bStarred)
|
||||
const folder = ko.dataFor(el);
|
||||
if (folder)
|
||||
{
|
||||
kn.setHash(Links.mailBox(oFolder.fullNameHash, 1, 'is:flagged'));
|
||||
if (Layout.NoPreview === SettingsStore.layout())
|
||||
{
|
||||
MessageStore.message(null);
|
||||
}
|
||||
|
||||
if (folder.fullNameRaw === FolderStore.currentFolderFullNameRaw())
|
||||
{
|
||||
setFolderHash(folder.fullNameRaw, '');
|
||||
}
|
||||
|
||||
if (starred)
|
||||
{
|
||||
setHash(mailBox(folder.fullNameHash, 1, 'is:flagged'));
|
||||
}
|
||||
else
|
||||
{
|
||||
setHash(mailBox(folder.fullNameHash));
|
||||
}
|
||||
}
|
||||
else
|
||||
};
|
||||
|
||||
dom
|
||||
.on('click', '.b-folders .e-item .e-link .e-collapsed-sign', function(event) { // eslint-disable-line prefer-arrow-callback
|
||||
const folder = ko.dataFor(this); // eslint-disable-line no-invalid-this
|
||||
if (folder && event)
|
||||
{
|
||||
kn.setHash(Links.mailBox(oFolder.fullNameHash));
|
||||
const collapsed = folder.collapsed();
|
||||
getApp().setExpandedFolder(folder.fullNameHash, collapsed);
|
||||
|
||||
folder.collapsed(!collapsed);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
};
|
||||
})
|
||||
.on('click', '.b-folders .e-item .e-link.selectable .inbox-star-icon', function(event) { // eslint-disable-line prefer-arrow-callback
|
||||
fSelectFolder(this, event, !self.isInboxStarred()); // eslint-disable-line no-invalid-this
|
||||
})
|
||||
.on('click', '.b-folders .e-item .e-link.selectable', function(event) { // eslint-disable-line prefer-arrow-callback
|
||||
fSelectFolder(this, event, false); // eslint-disable-line no-invalid-this
|
||||
});
|
||||
|
||||
oDom
|
||||
.on('click', '.b-folders .e-item .e-link .e-collapsed-sign', function(oEvent) {
|
||||
key('up, down', KeyState.FolderList, (event, handler) => {
|
||||
|
||||
var oFolder = ko.dataFor(this);
|
||||
if (oFolder && oEvent)
|
||||
const
|
||||
keyCode = handler && 'up' === handler.shortcut ? EventKeyCode.Up : EventKeyCode.Down,
|
||||
$items = $('.b-folders .e-item .e-link:not(.hidden):visible', dom);
|
||||
|
||||
if (event && $items.length)
|
||||
{
|
||||
var bCollapsed = oFolder.collapsed();
|
||||
require('App/User').default.setExpandedFolder(oFolder.fullNameHash, bCollapsed);
|
||||
let index = $items.index($items.filter('.focused'));
|
||||
if (-1 < index)
|
||||
{
|
||||
$items.eq(index).removeClass('focused');
|
||||
}
|
||||
|
||||
oFolder.collapsed(!bCollapsed);
|
||||
oEvent.preventDefault();
|
||||
oEvent.stopPropagation();
|
||||
if (EventKeyCode.Up === keyCode && 0 < index)
|
||||
{
|
||||
index -= 1;
|
||||
}
|
||||
else if (EventKeyCode.Down === keyCode && index < $items.length - 1)
|
||||
{
|
||||
index += 1;
|
||||
}
|
||||
|
||||
$items.eq(index).addClass('focused');
|
||||
self.scrollToFocused();
|
||||
}
|
||||
})
|
||||
.on('click', '.b-folders .e-item .e-link.selectable .inbox-star-icon', function(oEvent) {
|
||||
fSelectFolder.call(this, oEvent, !self.isInboxStarred());
|
||||
})
|
||||
.on('click', '.b-folders .e-item .e-link.selectable', function(oEvent) {
|
||||
fSelectFolder.call(this, oEvent, false);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
key('up, down', Enums.KeyState.FolderList, function(event, handler) {
|
||||
|
||||
var
|
||||
iKeyCode = handler && 'up' === handler.shortcut ? Enums.EventKeyCode.Up : Enums.EventKeyCode.Down,
|
||||
$items = $('.b-folders .e-item .e-link:not(.hidden):visible', oDom);
|
||||
|
||||
if (event && $items.length)
|
||||
{
|
||||
var iIndex = $items.index($items.filter('.focused'));
|
||||
if (-1 < iIndex)
|
||||
key('enter', KeyState.FolderList, () => {
|
||||
const $items = $('.b-folders .e-item .e-link:not(.hidden).focused', dom);
|
||||
if ($items.length && $items[0])
|
||||
{
|
||||
$items.eq(iIndex).removeClass('focused');
|
||||
AppStore.focusedState(Focused.MessageList);
|
||||
$items.click();
|
||||
}
|
||||
|
||||
if (Enums.EventKeyCode.Up === iKeyCode && 0 < iIndex)
|
||||
return false;
|
||||
});
|
||||
|
||||
key('space', KeyState.FolderList, () => {
|
||||
const $items = $('.b-folders .e-item .e-link:not(.hidden).focused', dom);
|
||||
if ($items.length && $items[0])
|
||||
{
|
||||
iIndex -= 1;
|
||||
}
|
||||
else if (Enums.EventKeyCode.Down === iKeyCode && iIndex < $items.length - 1)
|
||||
{
|
||||
iIndex += 1;
|
||||
const folder = ko.dataFor($items[0]);
|
||||
if (folder)
|
||||
{
|
||||
const collapsed = folder.collapsed();
|
||||
getApp().setExpandedFolder(folder.fullNameHash, collapsed);
|
||||
folder.collapsed(!collapsed);
|
||||
}
|
||||
}
|
||||
|
||||
$items.eq(iIndex).addClass('focused');
|
||||
self.scrollToFocused();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
key('esc, tab, shift+tab, right', KeyState.FolderList, () => {
|
||||
AppStore.focusedState(Focused.MessageList);
|
||||
return false;
|
||||
});
|
||||
|
||||
key('enter', Enums.KeyState.FolderList, function() {
|
||||
var $items = $('.b-folders .e-item .e-link:not(.hidden).focused', oDom);
|
||||
if ($items.length && $items[0])
|
||||
{
|
||||
AppStore.focusedState(Enums.Focused.MessageList);
|
||||
$items.click();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
key('space', Enums.KeyState.FolderList, function() {
|
||||
var $items = $('.b-folders .e-item .e-link:not(.hidden).focused', oDom);
|
||||
if ($items.length && $items[0])
|
||||
{
|
||||
var oFolder = ko.dataFor($items[0]);
|
||||
if (oFolder)
|
||||
AppStore.focusedState.subscribe((value) => {
|
||||
$('.b-folders .e-item .e-link.focused', dom).removeClass('focused');
|
||||
if (Focused.FolderList === value)
|
||||
{
|
||||
var bCollapsed = oFolder.collapsed();
|
||||
require('App/User').default.setExpandedFolder(oFolder.fullNameHash, bCollapsed);
|
||||
oFolder.collapsed(!bCollapsed);
|
||||
$('.b-folders .e-item .e-link.selected', dom).addClass('focused');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
messagesDropOver(folder) {
|
||||
window.clearTimeout(this.iDropOverTimer);
|
||||
if (folder && folder.collapsed())
|
||||
{
|
||||
this.iDropOverTimer = window.setTimeout(() => {
|
||||
folder.collapsed(false);
|
||||
getApp().setExpandedFolder(folder.fullNameHash, true);
|
||||
windowResize();
|
||||
}, Magics.Time500ms);
|
||||
}
|
||||
}
|
||||
|
||||
messagesDropOut() {
|
||||
window.clearTimeout(this.iDropOverTimer);
|
||||
}
|
||||
|
||||
scrollToFocused() {
|
||||
if (!this.oContentVisible || !this.oContentScrollable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const
|
||||
offset = 20,
|
||||
focused = $('.e-item .e-link.focused', this.oContentScrollable),
|
||||
pos = focused.position(),
|
||||
visibleHeight = this.oContentVisible.height(),
|
||||
focusedHeight = focused.outerHeight();
|
||||
|
||||
if (pos && (0 > pos.top || pos.top + focusedHeight > visibleHeight))
|
||||
{
|
||||
if (0 > pos.top)
|
||||
{
|
||||
this.oContentScrollable.scrollTop(this.oContentScrollable.scrollTop() + pos.top - offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.oContentScrollable.scrollTop(this.oContentScrollable.scrollTop() + pos.top - visibleHeight + focusedHeight + offset);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {FolderModel} toFolder
|
||||
* @param {{helper:jQuery}} ui
|
||||
* @returns {void}
|
||||
*/
|
||||
messagesDrop(toFolder, ui) {
|
||||
if (toFolder && ui && ui.helper)
|
||||
{
|
||||
const
|
||||
fromFolderFullNameRaw = ui.helper.data('rl-folder'),
|
||||
copy = $html.hasClass('rl-ctrl-key-pressed'),
|
||||
uids = ui.helper.data('rl-uids');
|
||||
|
||||
if (isNormal(fromFolderFullNameRaw) && '' !== fromFolderFullNameRaw && isArray(uids))
|
||||
{
|
||||
getApp().moveMessagesToFolder(fromFolderFullNameRaw, uids, toFolder.fullNameRaw, copy);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
key('esc, tab, shift+tab, right', Enums.KeyState.FolderList, function() {
|
||||
AppStore.focusedState(Enums.Focused.MessageList);
|
||||
return false;
|
||||
});
|
||||
|
||||
AppStore.focusedState.subscribe(function(mValue) {
|
||||
$('.b-folders .e-item .e-link.focused', oDom).removeClass('focused');
|
||||
if (Enums.Focused.FolderList === mValue)
|
||||
{
|
||||
$('.b-folders .e-item .e-link.selected', oDom).addClass('focused');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
FolderListMailBoxUserView.prototype.messagesDropOver = function(oFolder)
|
||||
{
|
||||
window.clearTimeout(this.iDropOverTimer);
|
||||
if (oFolder && oFolder.collapsed())
|
||||
{
|
||||
this.iDropOverTimer = window.setTimeout(function() {
|
||||
oFolder.collapsed(false);
|
||||
require('App/User').default.setExpandedFolder(oFolder.fullNameHash, true);
|
||||
Utils.windowResize();
|
||||
}, Enums.Magics.Time500ms);
|
||||
}
|
||||
};
|
||||
|
||||
FolderListMailBoxUserView.prototype.messagesDropOut = function()
|
||||
{
|
||||
window.clearTimeout(this.iDropOverTimer);
|
||||
};
|
||||
|
||||
FolderListMailBoxUserView.prototype.scrollToFocused = function()
|
||||
{
|
||||
if (!this.oContentVisible || !this.oContentScrollable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var
|
||||
iOffset = 20,
|
||||
oFocused = $('.e-item .e-link.focused', this.oContentScrollable),
|
||||
oPos = oFocused.position(),
|
||||
iVisibleHeight = this.oContentVisible.height(),
|
||||
iFocusedHeight = oFocused.outerHeight();
|
||||
|
||||
if (oPos && (0 > oPos.top || oPos.top + iFocusedHeight > iVisibleHeight))
|
||||
{
|
||||
if (0 > oPos.top)
|
||||
composeClick() {
|
||||
if (Settings.capa(Capa.Composer))
|
||||
{
|
||||
this.oContentScrollable.scrollTop(this.oContentScrollable.scrollTop() + oPos.top - iOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.oContentScrollable.scrollTop(this.oContentScrollable.scrollTop() + oPos.top - iVisibleHeight + iFocusedHeight + iOffset);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {FolderModel} oToFolder
|
||||
* @param {{helper:jQuery}} oUi
|
||||
* @returns {void}
|
||||
*/
|
||||
FolderListMailBoxUserView.prototype.messagesDrop = function(oToFolder, oUi)
|
||||
{
|
||||
if (oToFolder && oUi && oUi.helper)
|
||||
{
|
||||
var
|
||||
sFromFolderFullNameRaw = oUi.helper.data('rl-folder'),
|
||||
bCopy = Globals.$html.hasClass('rl-ctrl-key-pressed'),
|
||||
aUids = oUi.helper.data('rl-uids');
|
||||
|
||||
if (Utils.isNormal(sFromFolderFullNameRaw) && '' !== sFromFolderFullNameRaw && Utils.isArray(aUids))
|
||||
{
|
||||
require('App/User').default.moveMessagesToFolder(sFromFolderFullNameRaw, aUids, oToFolder.fullNameRaw, bCopy);
|
||||
showScreenPopup(require('View/Popup/Compose'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FolderListMailBoxUserView.prototype.composeClick = function()
|
||||
{
|
||||
if (Settings.capa(Enums.Capa.Composer))
|
||||
{
|
||||
kn.showScreenPopup(require('View/Popup/Compose'));
|
||||
createFolder() {
|
||||
showScreenPopup(require('View/Popup/FolderCreate'));
|
||||
}
|
||||
};
|
||||
|
||||
FolderListMailBoxUserView.prototype.createFolder = function()
|
||||
{
|
||||
kn.showScreenPopup(require('View/Popup/FolderCreate'));
|
||||
};
|
||||
|
||||
FolderListMailBoxUserView.prototype.configureFolders = function()
|
||||
{
|
||||
kn.setHash(Links.settings('folders'));
|
||||
};
|
||||
|
||||
FolderListMailBoxUserView.prototype.contactsClick = function()
|
||||
{
|
||||
if (this.allowContacts)
|
||||
{
|
||||
kn.showScreenPopup(require('View/Popup/Contacts'));
|
||||
configureFolders() {
|
||||
setHash(settings('folders'));
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = FolderListMailBoxUserView;
|
||||
contactsClick() {
|
||||
if (this.allowContacts)
|
||||
{
|
||||
showScreenPopup(require('View/Popup/Contacts'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {FolderListMailBoxUserView, FolderListMailBoxUserView as default};
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,21 +1,10 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
import {view} from 'Knoin/Knoin';
|
||||
import {AbstractSystemDropDownUserView} from 'View/User/AbstractSystemDropDown';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractSystemDropDownViewModel = require('View/User/AbstractSystemDropDown');
|
||||
@view({
|
||||
name: 'View/User/MailBox/SystemDropDown'
|
||||
})
|
||||
class SystemDropDownMailBoxUserView extends AbstractSystemDropDownUserView {}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractSystemDropDownViewModel
|
||||
*/
|
||||
function SystemDropDownMailBoxUserView()
|
||||
{
|
||||
AbstractSystemDropDownViewModel.call(this);
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/User/MailBox/SystemDropDown', 'View/App/MailBox/SystemDropDown', 'MailBoxSystemDropDownViewModel'], SystemDropDownMailBoxUserView);
|
||||
_.extend(SystemDropDownMailBoxUserView.prototype, AbstractSystemDropDownViewModel.prototype);
|
||||
|
||||
module.exports = SystemDropDownMailBoxUserView;
|
||||
export {SystemDropDownMailBoxUserView, SystemDropDownMailBoxUserView as default};
|
||||
|
|
|
|||
|
|
@ -1,85 +1,81 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
$ = require('$'),
|
||||
key = require('key'),
|
||||
import _ from '_';
|
||||
import $ from '$';
|
||||
import key from 'key';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Globals = require('Common/Globals'),
|
||||
Links = require('Common/Links'),
|
||||
import {KeyState, Magics} from 'Common/Enums';
|
||||
import {leftPanelDisabled} from 'Common/Globals';
|
||||
import {settings, inbox} from 'Common/Links';
|
||||
import {getFolderInboxName} from 'Common/Cache';
|
||||
|
||||
Cache = require('Common/Cache'),
|
||||
Settings = require('Storage/Settings'),
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType, setHash} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object} oScreen
|
||||
*/
|
||||
function MenuSettingsUserView(oScreen)
|
||||
@view({
|
||||
name: 'View/User/Settings/Menu',
|
||||
type: ViewType.Left,
|
||||
templateID: 'SettingsMenu'
|
||||
})
|
||||
class MenuSettingsUserView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Left', 'SettingsMenu');
|
||||
/**
|
||||
* @param {Object} screen
|
||||
*/
|
||||
constructor(screen) {
|
||||
super();
|
||||
|
||||
this.leftPanelDisabled = Globals.leftPanelDisabled;
|
||||
this.leftPanelDisabled = leftPanelDisabled;
|
||||
|
||||
this.mobile = Settings.appSettingsGet('mobile');
|
||||
this.mobile = Settings.appSettingsGet('mobile');
|
||||
|
||||
this.menu = oScreen.menu;
|
||||
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/User/Settings/Menu', 'View/App/Settings/Menu', 'SettingsMenuViewModel'], MenuSettingsUserView);
|
||||
_.extend(MenuSettingsUserView.prototype, AbstractView.prototype);
|
||||
|
||||
MenuSettingsUserView.prototype.onBuild = function(oDom)
|
||||
{
|
||||
if (this.mobile)
|
||||
{
|
||||
oDom
|
||||
.on('click', '.b-settings-menu .e-item.selectable', function() {
|
||||
Globals.leftPanelDisabled(true);
|
||||
});
|
||||
this.menu = screen.menu;
|
||||
}
|
||||
|
||||
key('up, down', Enums.KeyState.Settings, _.throttle(function(event, handler) {
|
||||
|
||||
var
|
||||
bUp = handler && 'up' === handler.shortcut,
|
||||
$items = $('.b-settings-menu .e-item', oDom);
|
||||
|
||||
if (event && $items.length)
|
||||
onBuild(dom) {
|
||||
if (this.mobile)
|
||||
{
|
||||
var iIndex = $items.index($items.filter('.selected'));
|
||||
if (bUp && 0 < iIndex)
|
||||
{
|
||||
iIndex -= 1;
|
||||
}
|
||||
else if (!bUp && iIndex < $items.length - 1)
|
||||
{
|
||||
iIndex += 1;
|
||||
}
|
||||
|
||||
var sH = $items.eq(iIndex).attr('href');
|
||||
if (sH)
|
||||
{
|
||||
kn.setHash(sH, false, true);
|
||||
}
|
||||
dom.on('click', '.b-settings-menu .e-item.selectable', () => {
|
||||
leftPanelDisabled(true);
|
||||
});
|
||||
}
|
||||
|
||||
}, 200)); // eslint-disable-line no-magic-numbers
|
||||
};
|
||||
key('up, down', KeyState.Settings, _.throttle((event, handler) => {
|
||||
|
||||
MenuSettingsUserView.prototype.link = function(sRoute)
|
||||
{
|
||||
return Links.settings(sRoute);
|
||||
};
|
||||
const
|
||||
up = handler && 'up' === handler.shortcut,
|
||||
$items = $('.b-settings-menu .e-item', dom);
|
||||
|
||||
MenuSettingsUserView.prototype.backToMailBoxClick = function()
|
||||
{
|
||||
kn.setHash(Links.inbox(Cache.getFolderInboxName()));
|
||||
};
|
||||
if (event && $items.length)
|
||||
{
|
||||
let iIndex = $items.index($items.filter('.selected'));
|
||||
if (up && 0 < iIndex)
|
||||
{
|
||||
iIndex -= 1;
|
||||
}
|
||||
else if (!up && iIndex < $items.length - 1)
|
||||
{
|
||||
iIndex += 1;
|
||||
}
|
||||
|
||||
module.exports = MenuSettingsUserView;
|
||||
const sH = $items.eq(iIndex).attr('href');
|
||||
if (sH)
|
||||
{
|
||||
setHash(sH, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
}, Magics.Time200ms));
|
||||
}
|
||||
|
||||
link(sRoute) {
|
||||
return settings(sRoute);
|
||||
}
|
||||
|
||||
backToMailBoxClick() {
|
||||
setHash(inbox(getFolderInboxName()));
|
||||
}
|
||||
}
|
||||
|
||||
export {MenuSettingsUserView, MenuSettingsUserView as default};
|
||||
|
|
|
|||
|
|
@ -1,68 +1,60 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
import {inbox} from 'Common/Links';
|
||||
import {getFolderInboxName} from 'Common/Cache';
|
||||
import {leftPanelDisabled} from 'Common/Globals';
|
||||
|
||||
Globals = require('Common/Globals'),
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
import MessageStore from 'Stores/User/Message';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView');
|
||||
import {view, ViewType, setHash} from 'Knoin/Knoin';
|
||||
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function PaneSettingsUserView()
|
||||
@view({
|
||||
name: 'View/User/Settings/Pane',
|
||||
type: ViewType.Right,
|
||||
templateID: 'SettingsPane'
|
||||
})
|
||||
class PaneSettingsUserView extends AbstractViewNext
|
||||
{
|
||||
AbstractView.call(this, 'Right', 'SettingsPane');
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.mobile = Settings.appSettingsGet('mobile');
|
||||
this.mobile = Settings.appSettingsGet('mobile');
|
||||
|
||||
this.leftPanelDisabled = Globals.leftPanelDisabled;
|
||||
this.leftPanelDisabled = leftPanelDisabled;
|
||||
}
|
||||
|
||||
kn.constructorEnd(this);
|
||||
onShow() {
|
||||
MessageStore.message(null);
|
||||
}
|
||||
|
||||
hideLeft(oItem, oEvent) {
|
||||
oEvent.preventDefault();
|
||||
oEvent.stopPropagation();
|
||||
|
||||
leftPanelDisabled(true);
|
||||
}
|
||||
|
||||
showLeft(oItem, oEvent) {
|
||||
oEvent.preventDefault();
|
||||
oEvent.stopPropagation();
|
||||
|
||||
leftPanelDisabled(false);
|
||||
}
|
||||
|
||||
onBuild(dom) {
|
||||
if (this.mobile)
|
||||
{
|
||||
dom.on('click', () => {
|
||||
leftPanelDisabled(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
backToMailBoxClick() {
|
||||
setHash(inbox(getFolderInboxName()));
|
||||
}
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/User/Settings/Pane', 'View/App/Settings/Pane', 'SettingsPaneViewModel'], PaneSettingsUserView);
|
||||
_.extend(PaneSettingsUserView.prototype, AbstractView.prototype);
|
||||
|
||||
PaneSettingsUserView.prototype.onShow = function()
|
||||
{
|
||||
require('Stores/User/Message').message(null);
|
||||
};
|
||||
|
||||
PaneSettingsUserView.prototype.hideLeft = function(oItem, oEvent)
|
||||
{
|
||||
oEvent.preventDefault();
|
||||
oEvent.stopPropagation();
|
||||
|
||||
Globals.leftPanelDisabled(true);
|
||||
};
|
||||
|
||||
PaneSettingsUserView.prototype.showLeft = function(oItem, oEvent)
|
||||
{
|
||||
oEvent.preventDefault();
|
||||
oEvent.stopPropagation();
|
||||
|
||||
Globals.leftPanelDisabled(false);
|
||||
};
|
||||
|
||||
PaneSettingsUserView.prototype.onBuild = function(oDom)
|
||||
{
|
||||
if (this.mobile)
|
||||
{
|
||||
oDom
|
||||
.on('click', function() {
|
||||
Globals.leftPanelDisabled(true);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
PaneSettingsUserView.prototype.backToMailBoxClick = function()
|
||||
{
|
||||
kn.setHash(require('Common/Links').inbox(
|
||||
require('Common/Cache').getFolderInboxName()));
|
||||
};
|
||||
|
||||
module.exports = PaneSettingsUserView;
|
||||
export {PaneSettingsUserView, PaneSettingsUserView as default};
|
||||
|
|
|
|||
|
|
@ -1,21 +1,10 @@
|
|||
|
||||
var
|
||||
_ = require('_'),
|
||||
import {view} from 'Knoin/Knoin';
|
||||
import {AbstractSystemDropDownUserView} from 'View/User/AbstractSystemDropDown';
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractSystemDropDownUserView = require('View/User/AbstractSystemDropDown');
|
||||
@view({
|
||||
name: 'View/User/Settings/SystemDropDown'
|
||||
})
|
||||
class SystemDropDownSettingsUserView extends AbstractSystemDropDownUserView {}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractSystemDropDownUserView
|
||||
*/
|
||||
function SystemDropDownSettingsUserView()
|
||||
{
|
||||
AbstractSystemDropDownUserView.call(this);
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/User/Settings/SystemDropDown', 'View/App/Settings/SystemDropDown', 'SettingsSystemDropDownViewModel'], SystemDropDownSettingsUserView);
|
||||
_.extend(SystemDropDownSettingsUserView.prototype, AbstractSystemDropDownUserView.prototype);
|
||||
|
||||
module.exports = SystemDropDownSettingsUserView;
|
||||
export {SystemDropDownSettingsUserView, SystemDropDownSettingsUserView as default};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue