コード例 #1
0
/**
 * @constructor
 * @extends AbstractView
 */
function FolderCreateView()
{
	AbstractView.call(this, 'Popups', 'PopupsFolderCreate');

	this.folderName = ko.observable('');
	this.folderName.focused = ko.observable(false);

	this.selectedParentValue = ko.observable(Consts.UNUSED_OPTION_VALUE);

	this.parentFolderSelectList = ko.computed(function() {

		var
			aTop = [],
			fDisableCallback = null,
			fVisibleCallback = null,
			aList = FolderStore.folderList(),
			fRenameCallback = function(oItem) {
				return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
			};

		aTop.push(['', '']);

		if ('' !== FolderStore.namespace)
		{
			fDisableCallback = function(oItem)
			{
				return FolderStore.namespace !== oItem.fullNameRaw.substr(0, FolderStore.namespace.length);
			};
		}

		return Utils.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);

	}, this);

	// commands
	this.createFolder = Utils.createCommand(this, function() {

		var
			sParentFolderName = this.selectedParentValue();

		if ('' === sParentFolderName && 1 < FolderStore.namespace.length)
		{
			sParentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
		}

		require('App/User').default.foldersPromisesActionHelper(
			Promises.folderCreate(this.folderName(), sParentFolderName, FolderStore.foldersCreating),
			Enums.Notification.CantCreateFolder
		);

		this.cancelCommand();

	}, function() {
		return this.simpleFolderNameValidation(this.folderName());
	});

	this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;

	kn.constructorEnd(this);
}
コード例 #2
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function AdvancedSearchPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsAdvancedSearch');

		this.fromFocus = ko.observable(false);

		this.from = ko.observable('');
		this.to = ko.observable('');
		this.subject = ko.observable('');
		this.text = ko.observable('');
		this.selectedDateValue = ko.observable(-1);

		this.hasAttachment = ko.observable(false);
		this.starred = ko.observable(false);
		this.unseen = ko.observable(false);

		this.searchCommand = Utils.createCommand(this, function () {

			var sSearch = this.buildSearchString();
			if ('' !== sSearch)
			{
				Data.mainMessageListSearch(sSearch);
			}

			this.cancelCommand();
		});

		kn.constructorEnd(this);
	}
コード例 #3
0
	/**
	 * @constructor
	 */
	function ChangePasswordAppSetting()
	{
		this.changeProcess = ko.observable(false);

		this.errorDescription = ko.observable('');
		this.passwordMismatch = ko.observable(false);
		this.passwordUpdateError = ko.observable(false);
		this.passwordUpdateSuccess = ko.observable(false);

		this.currentPassword = ko.observable('');
		this.currentPassword.error = ko.observable(false);
		this.newPassword = ko.observable('');
		this.newPassword2 = ko.observable('');

		this.currentPassword.subscribe(function () {
			this.passwordUpdateError(false);
			this.passwordUpdateSuccess(false);
			this.currentPassword.error(false);
		}, this);

		this.newPassword.subscribe(function () {
			this.passwordUpdateError(false);
			this.passwordUpdateSuccess(false);
			this.passwordMismatch(false);
		}, this);

		this.newPassword2.subscribe(function () {
			this.passwordUpdateError(false);
			this.passwordUpdateSuccess(false);
			this.passwordMismatch(false);
		}, this);

		this.saveNewPasswordCommand = Utils.createCommand(this, function () {

			if (this.newPassword() !== this.newPassword2())
			{
				this.passwordMismatch(true);
				this.errorDescription(Utils.i18n('SETTINGS_CHANGE_PASSWORD/ERROR_PASSWORD_MISMATCH'));
			}
			else
			{
				this.changeProcess(true);

				this.passwordUpdateError(false);
				this.passwordUpdateSuccess(false);
				this.currentPassword.error(false);
				this.passwordMismatch(false);
				this.errorDescription('');

				Remote.changePassword(this.onChangePasswordResponse, this.currentPassword(), this.newPassword());
			}

		}, function () {
			return !this.changeProcess() && '' !== this.currentPassword() &&
				'' !== this.newPassword() && '' !== this.newPassword2();
		});

		this.onChangePasswordResponse = _.bind(this.onChangePasswordResponse, this);
	}
コード例 #4
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function AdvancedSearchPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsAdvancedSearch');

		this.fromFocus = ko.observable(false);

		this.from = ko.observable('');
		this.to = ko.observable('');
		this.subject = ko.observable('');
		this.text = ko.observable('');
		this.selectedDateValue = ko.observable(-1);

		this.hasAttachment = ko.observable(false);
		this.starred = ko.observable(false);
		this.unseen = ko.observable(false);

		this.searchCommand = Utils.createCommand(this, function () {

			var sSearch = this.buildSearchString();
			if ('' !== sSearch)
			{
				MessageStore.mainMessageListSearch(sSearch);
			}

			this.cancelCommand();
		});

		this.selectedDates = ko.computed(function () {
			Translator.trigger();
			return [
				{'id': -1, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_ALL')},
				{'id': 3, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_3_DAYS')},
				{'id': 7, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_7_DAYS')},
				{'id': 30, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_MONTH')},
				{'id': 90, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_3_MONTHS')},
				{'id': 180, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_6_MONTHS')},
				{'id': 365, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_YEAR')}
			];
		}, this);

		kn.constructorEnd(this);
	}
コード例 #5
0
/**
 * @constructor
 * @extends AbstractView
 */
function TwoFactorTestPopupView()
{
	AbstractView.call(this, 'Popups', 'PopupsTwoFactorTest');

	var self = this;

	this.code = ko.observable('');
	this.code.focused = ko.observable(false);
	this.code.status = ko.observable(null);

	this.koTestedTrigger = null;

	this.testing = ko.observable(false);

	// commands
	this.testCode = Utils.createCommand(this, function() {

		this.testing(true);
		Remote.testTwoFactor(function(sResult, oData) {

			self.testing(false);
			self.code.status(Enums.StorageResultType.Success === sResult && oData && !!oData.Result);

			if (self.koTestedTrigger && self.code.status())
			{
				self.koTestedTrigger(true);
			}

		}, this.code());

	}, function() {
		return '' !== this.code() && !this.testing();
	});

	kn.constructorEnd(this);
}
コード例 #6
0
/**
 * @constructor
 * @extends AbstractView
 */
function MessageOpenPgpPopupView()
{
	AbstractView.call(this, 'Popups', 'PopupsMessageOpenPgp');

	this.notification = ko.observable('');

	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.resultCallback = null;

	this.submitRequest = ko.observable(false);

	// commands
	this.doCommand = Utils.createCommand(this, function() {

		this.submitRequest(true);

		_.delay(_.bind(function() {

			var
				oPrivateKeys = [],
				oPrivateKey = null;

			try
			{
				if (this.resultCallback && this.selectedKey())
				{
					oPrivateKeys = this.selectedKey().getNativeKeys();
					oPrivateKey = oPrivateKeys && oPrivateKeys[0] ? oPrivateKeys[0] : null;

					if (oPrivateKey)
					{
						try
						{
							if (!oPrivateKey.decrypt(Utils.pString(this.password())))
							{
								Utils.log('Error: Private key cannot be decrypted');
								oPrivateKey = null;
							}
						}
						catch (e)
						{
							Utils.log(e);
							oPrivateKey = null;
						}
					}
					else
					{
						Utils.log('Error: Private key cannot be found');
					}
				}
			}
			catch (e)
			{
				Utils.log(e);
				oPrivateKey = null;
			}

			this.submitRequest(false);

			this.cancelCommand();
			this.resultCallback(oPrivateKey);

		}, this), Enums.Magics.Time100ms);

	}, function() {
		return !this.submitRequest();
	});

	this.sDefaultKeyScope = Enums.KeyState.PopupMessageOpenPGP;

	kn.constructorEnd(this);
}
コード例 #7
0
ファイル: Login.js プロジェクト: Momohime/rainloop-webmail
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function LoginUserView()
	{
		AbstractView.call(this, 'Center', 'Login');

		this.welcome = ko.observable(!!Settings.settingsGet('UseLoginWelcomePage'));

		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.logoImg = Utils.trim(Settings.settingsGet('LoginLogo'));
		this.logoPowered = !!Settings.settingsGet('LoginPowered');
		this.loginDescription = Utils.trim(Settings.settingsGet('LoginDescription'));

		this.forgotPasswordLinkUrl = Settings.settingsGet('ForgotPasswordLinkUrl');
		this.registrationLinkUrl = Settings.settingsGet('RegistrationLinkUrl');

		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.formHidden = ko.observable(false);

		this.formError = ko.computed(function () {
			return this.emailErrorAnimation() || this.passwordErrorAnimation() ||
				(this.additionalCode.visibility() && this.additionalCode.errorAnimation());
		}, this);

		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.password.subscribe(function () {
			this.passwordError(false);
		}, this);

		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.error(false);
				this.additionalCode.error('' === Utils.trim(this.additionalCode()));
			}

			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;
				}

				return false;
			}

			var
				iPluginResultCode = 0,
				sPluginResultMessage = '',
				fSubmitResult = function (iResultCode, sResultMessage) {
					iPluginResultCode = iResultCode || 0;
					sPluginResultMessage = sResultMessage || '';
				}
			;

			Plugins.runHook('user-login-submit', [fSubmitResult]);
			if (0 < iPluginResultCode)
			{
				this.submitError(Translator.getNotification(iPluginResultCode));
				return false;
			}
			else if ('' !== sPluginResultMessage)
			{
				this.submitError(sPluginResultMessage);
				return false;
			}

			this.submitRequest(true);

			var
				sPassword = this.password(),

				fLoginRequest = _.bind(function (sPassword) {

					Remote.login(_.bind(function (sResult, oData) {

						if (Enums.StorageResultType.Success === sResult && oData && 'Login' === oData.Action)
						{
							if (oData.Result)
							{
								if (oData.TwoFactorAuth)
								{
									this.additionalCode('');
									this.additionalCode.visibility(true);
									this.additionalCode.focused(true);

									this.submitRequest(false);
								}
								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(Translator.getNotificationFromResponse(oData));

								if ('' === this.submitError())
								{
									this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
								}
								else
								{
									if (oData.ErrorMessageAdditional)
									{
										this.submitErrorAddidional(oData.ErrorMessageAdditional);
									}
								}
							}
							else
							{
								this.submitRequest(false);
							}
						}
						else
						{
							this.submitRequest(false);
							this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
						}

					}, this), this.email(), '', sPassword, !!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-');

				}, this)
			;

			if (!!Settings.settingsGet('UseRsaEncryption') && Utils.rsaEncode.supported &&
				Settings.settingsGet('RsaPublicKey'))
			{
				fLoginRequest(Utils.rsaEncode(sPassword, Settings.settingsGet('RsaPublicKey')));
			}
			else
			{
				fLoginRequest(sPassword);
			}

			return true;

		}, function () {
			return !this.submitRequest();
		});

		this.facebookLoginEnabled = ko.observable(false);

		this.facebookCommand = Utils.createCommand(this, function () {

			window.open(Links.socialFacebook(), 'Facebook',
				'left=200,top=100,width=650,height=450,menubar=no,status=no,resizable=yes,scrollbars=yes');

			return true;

		}, function () {
			return !this.submitRequest() && this.facebookLoginEnabled();
		});

		this.googleLoginEnabled = ko.observable(false);
		this.googleFastLoginEnabled = ko.observable(false);

		this.googleCommand = Utils.createCommand(this, function () {

			window.open(Links.socialGoogle(), 'Google',
				'left=200,top=100,width=650,height=500,menubar=no,status=no,resizable=yes,scrollbars=yes');

			return true;

		}, function () {
			return !this.submitRequest() && this.googleLoginEnabled();
		});

		this.googleFastCommand = Utils.createCommand(this, function () {

			window.open(Links.socialGoogle(true), 'Google',
				'left=200,top=100,width=650,height=500,menubar=no,status=no,resizable=yes,scrollbars=yes');

			return true;

		}, function () {
			return !this.submitRequest() && this.googleFastLoginEnabled();
		});

		this.twitterLoginEnabled = ko.observable(false);

		this.twitterCommand = Utils.createCommand(this, function () {

			window.open(Links.socialTwitter(), 'Twitter',
				'left=200,top=100,width=650,height=450,menubar=no,status=no,resizable=yes,scrollbars=yes');

			return true;

		}, function () {
			return !this.submitRequest() && this.twitterLoginEnabled();
		});

		this.socialLoginEnabled = ko.computed(function () {

			var
				bF = this.facebookLoginEnabled(),
				bG = this.googleLoginEnabled(),
				bT = this.twitterLoginEnabled()
			;

			return bF || bG || bT;
		}, this);

		if (Settings.settingsGet('AdditionalLoginError') && !this.submitError())
		{
			this.submitError(Settings.settingsGet('AdditionalLoginError'));
		}

		kn.constructorEnd(this);
	}
コード例 #8
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function ActivatePopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsActivate');

		var self = this;

		this.domain = ko.observable('');
		this.key = ko.observable('');
		this.key.focus = ko.observable(false);
		this.activationSuccessed = ko.observable(false);

		this.licenseTrigger = LicenseStore.licenseTrigger;

		this.activateProcess = ko.observable(false);
		this.activateText = ko.observable('');
		this.activateText.isError = ko.observable(false);

		this.htmlDescription = ko.computed(function () {
			return Translator.i18n('POPUPS_ACTIVATE/HTML_DESC', {'DOMAIN': this.domain()});
		}, this);

		this.key.subscribe(function () {
			this.activateText('');
			this.activateText.isError(false);
		}, this);

		this.activationSuccessed.subscribe(function (bValue) {
			if (bValue)
			{
				this.licenseTrigger(!this.licenseTrigger());
			}
		}, this);

		this.activateCommand = Utils.createCommand(this, function () {

			this.activateProcess(true);
			if (this.validateSubscriptionKey())
			{
				Remote.licensingActivate(function (sResult, oData) {

					self.activateProcess(false);
					if (Enums.StorageResultType.Success === sResult && oData.Result)
					{
						if (true === oData.Result)
						{
							self.activationSuccessed(true);
							self.activateText(Translator.i18n('POPUPS_ACTIVATE/SUBS_KEY_ACTIVATED'));
							self.activateText.isError(false);
						}
						else
						{
							self.activateText(oData.Result);
							self.activateText.isError(true);
							self.key.focus(true);
						}
					}
					else if (oData.ErrorCode)
					{
						self.activateText(Translator.getNotification(oData.ErrorCode));
						self.activateText.isError(true);
						self.key.focus(true);
					}
					else
					{
						self.activateText(Translator.getNotification(Enums.Notification.UnknownError));
						self.activateText.isError(true);
						self.key.focus(true);
					}

				}, this.domain(), this.key());
			}
			else
			{
				this.activateProcess(false);
				this.activateText(Translator.i18n('POPUPS_ACTIVATE/ERROR_INVALID_SUBS_KEY'));
				this.activateText.isError(true);
				this.key.focus(true);
			}

		}, function () {
			return !this.activateProcess() && '' !== this.domain() && '' !== this.key() && !this.activationSuccessed();
		});

		kn.constructorEnd(this);
	}
コード例 #9
0
	Knoin.prototype.buildViewModel = function (ViewModelClass, oScreen)
	{
		if (ViewModelClass && !ViewModelClass.__builded)
		{
			var
				kn = this,
				oViewModel = new ViewModelClass(oScreen),
				sPosition = oViewModel.viewModelPosition(),
				oViewModelPlace = $('#rl-content #rl-' + sPosition.toLowerCase()),
				oViewModelDom = null
			;

			ViewModelClass.__builded = true;
			ViewModelClass.__vm = oViewModel;

			oViewModel.onShowTrigger = ko.observable(false);
			oViewModel.onHideTrigger = ko.observable(false);

			oViewModel.viewModelName = ViewModelClass.__name;
			oViewModel.viewModelNames = ViewModelClass.__names;

			if (oViewModelPlace && 1 === oViewModelPlace.length)
			{
				oViewModelDom = $('<div></div>').addClass('rl-view-model').addClass('RL-' + oViewModel.viewModelTemplate()).hide();
				oViewModelDom.appendTo(oViewModelPlace);

				oViewModel.viewModelDom = oViewModelDom;
				ViewModelClass.__dom = oViewModelDom;

				if ('Popups' === sPosition)
				{
					oViewModel.cancelCommand = oViewModel.closeCommand = Utils.createCommand(oViewModel, function () {
						kn.hideScreenPopup(ViewModelClass);
					});

					oViewModel.modalVisibility.subscribe(function (bValue) {

						var self = this;
						if (bValue)
						{
							this.viewModelDom.show();
							this.storeAndSetKeyScope();

							Globals.popupVisibilityNames.push(this.viewModelName);
							oViewModel.viewModelDom.css('z-index', 3000 + Globals.popupVisibilityNames().length + 10);

//							Utils.delegateRun(this, 'onShow'); // moved to showScreenPopup function (for parameters)

							if (this.onShowTrigger)
							{
								this.onShowTrigger(!this.onShowTrigger());
							}

							Utils.delegateRun(this, 'onShowWithDelay', [], 500);
						}
						else
						{
							Utils.delegateRun(this, 'onHide');
							Utils.delegateRun(this, 'onHideWithDelay', [], 500);

							if (this.onHideTrigger)
							{
								this.onHideTrigger(!this.onHideTrigger());
							}

							this.restoreKeyScope();

							_.each(this.viewModelNames, function (sName) {
								Plugins.runHook('view-model-on-hide', [sName, self]);
							});

							Globals.popupVisibilityNames.remove(this.viewModelName);
							oViewModel.viewModelDom.css('z-index', 2000);

							_.delay(function () {
								self.viewModelDom.hide();
							}, 300);
						}

					}, oViewModel);
				}

				_.each(ViewModelClass.__names, function (sName) {
					Plugins.runHook('view-model-pre-build', [sName, oViewModel, oViewModelDom]);
				});

				ko.applyBindingAccessorsToNode(oViewModelDom[0], {
					'translatorInit': true,
					'template': function () { return {'name': oViewModel.viewModelTemplate()};}
				}, oViewModel);

				Utils.delegateRun(oViewModel, 'onBuild', [oViewModelDom]);
				if (oViewModel && 'Popups' === sPosition)
				{
					oViewModel.registerPopupKeyDown();
				}

				_.each(ViewModelClass.__names, function (sName) {
					Plugins.runHook('view-model-post-build', [sName, oViewModel, oViewModelDom]);
				});
			}
			else
			{
				Utils.log('Cannot find view model position: ' + sPosition);
			}
		}

		return ViewModelClass ? ViewModelClass.__vm : null;
	};
コード例 #10
0
ファイル: Compose.js プロジェクト: David934/rainloop-webmail
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function ComposePopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsCompose');

		this.oEditor = null;
		this.aDraftInfo = null;
		this.sInReplyTo = '';
		this.bFromDraft = false;
		this.bSkipNext = false;
		this.sReferences = '';

		this.bCapaAdditionalIdentities = Settings.capa(Enums.Capa.AdditionalIdentities);

		var
			self = this,
			fCcAndBccCheckHelper = function (aValue) {
				if (false === self.showCcAndBcc() && 0 < aValue.length)
				{
					self.showCcAndBcc(true);
				}
			}
		;

		this.capaOpenPGP = Data.capaOpenPGP;

		this.resizer = ko.observable(false).extend({'throttle': 50});

		this.identitiesDropdownTrigger = ko.observable(false);

		this.to = ko.observable('');
		this.to.focusTrigger = ko.observable(false);
		this.cc = ko.observable('');
		this.bcc = ko.observable('');

		this.replyTo = ko.observable('');
		this.subject = ko.observable('');
		this.isHtml = ko.observable(false);

		this.requestReadReceipt = ko.observable(false);

		this.sendError = ko.observable(false);
		this.sendSuccessButSaveError = ko.observable(false);
		this.savedError = ko.observable(false);

		this.savedTime = ko.observable(0);
		this.savedOrSendingText = ko.observable('');

		this.emptyToError = ko.observable(false);
		this.attachmentsInProcessError = ko.observable(false);
		this.showCcAndBcc = ko.observable(false);

		this.cc.subscribe(fCcAndBccCheckHelper, this);
		this.bcc.subscribe(fCcAndBccCheckHelper, this);

		this.draftFolder = ko.observable('');
		this.draftUid = ko.observable('');
		this.sending = ko.observable(false);
		this.saving = ko.observable(false);
		this.attachments = ko.observableArray([]);

		this.attachmentsInProcess = this.attachments.filter(function (oItem) {
			return oItem && '' === oItem.tempName();
		});

		this.attachmentsInReady = this.attachments.filter(function (oItem) {
			return oItem && '' !== oItem.tempName();
		});

		this.attachments.subscribe(function () {
			this.triggerForResize();
		}, this);

		this.isDraftFolderMessage = ko.computed(function () {
			return '' !== this.draftFolder() && '' !== this.draftUid();
		}, this);

		this.composeUploaderButton = ko.observable(null);
		this.composeUploaderDropPlace = ko.observable(null);
		this.dragAndDropEnabled = ko.observable(false);
		this.dragAndDropOver = ko.observable(false).extend({'throttle': 1});
		this.dragAndDropVisible = ko.observable(false).extend({'throttle': 1});
		this.attacheMultipleAllowed = ko.observable(false);
		this.addAttachmentEnabled = ko.observable(false);

		this.composeEditorArea = ko.observable(null);

		this.identities = Data.identities;
		this.defaultIdentityID = Data.defaultIdentityID;
		this.currentIdentityID = ko.observable('');

		this.currentIdentityString = ko.observable('');
		this.currentIdentityResultEmail = ko.observable('');

		this.identitiesOptions = ko.computed(function () {

			var aList = [{
				'optValue': Data.accountEmail(),
				'optText': this.formattedFrom(false)
			}];

			_.each(Data.identities(), function (oItem) {
				aList.push({
					'optValue': oItem.id,
					'optText': oItem.formattedNameForCompose()
				});
			});

			return aList;

		}, this);

		ko.computed(function () {

			var
				sResult = '',
				sResultEmail = '',
				oItem = null,
				aList = this.identities(),
				sID = this.currentIdentityID()
			;

			if (this.bCapaAdditionalIdentities && sID && sID !== Data.accountEmail())
			{
				oItem = _.find(aList, function (oItem) {
					return oItem && sID === oItem['id'];
				});

				sResult = oItem ? oItem.formattedNameForCompose() : '';
				sResultEmail = oItem ? oItem.formattedNameForEmail() : '';

				if ('' === sResult && aList[0])
				{
					this.currentIdentityID(aList[0]['id']);
					return '';
				}
			}

			if ('' === sResult)
			{
				sResult = this.formattedFrom(false);
				sResultEmail = this.formattedFrom(true);
			}

			this.currentIdentityString(sResult);
			this.currentIdentityResultEmail(sResultEmail);

			return sResult;

		}, this);

		this.to.subscribe(function (sValue) {
			if (this.emptyToError() && 0 < sValue.length)
			{
				this.emptyToError(false);
			}
		}, this);

		this.attachmentsInProcess.subscribe(function (aValue) {
			if (this.attachmentsInProcessError() && Utils.isArray(aValue) && 0 === aValue.length)
			{
				this.attachmentsInProcessError(false);
			}
		}, this);

		this.editorResizeThrottle = _.throttle(_.bind(this.editorResize, this), 100);

		this.resizer.subscribe(function () {
			this.editorResizeThrottle();
		}, this);

		this.canBeSendedOrSaved = ko.computed(function () {
			return !this.sending() && !this.saving();
		}, this);

		this.deleteCommand = Utils.createCommand(this, function () {

			require('App/User').deleteMessagesFromFolderWithoutCheck(this.draftFolder(), [this.draftUid()]);
			kn.hideScreenPopup(ComposePopupView);

		}, function () {
			return this.isDraftFolderMessage();
		});

		this.sendMessageResponse = _.bind(this.sendMessageResponse, this);
		this.saveMessageResponse = _.bind(this.saveMessageResponse, this);

		this.sendCommand = Utils.createCommand(this, function () {
			var
				sTo = Utils.trim(this.to()),
				sSentFolder = Data.sentFolder(),
				aFlagsCache = []
			;

			if (0 < this.attachmentsInProcess().length)
			{
				this.attachmentsInProcessError(true);
			}
			else if (0 === sTo.length)
			{
				this.emptyToError(true);
			}
			else
			{
				if (Data.replySameFolder())
				{
					if (Utils.isArray(this.aDraftInfo) && 3 === this.aDraftInfo.length && Utils.isNormal(this.aDraftInfo[2]) && 0 < this.aDraftInfo[2].length)
					{
						sSentFolder = this.aDraftInfo[2];
					}
				}

				if ('' === sSentFolder)
				{
					kn.showScreenPopup(require('View/Popup/FolderSystem'), [Enums.SetSystemFoldersNotification.Sent]);
				}
				else
				{
					this.sendError(false);
					this.sending(true);

					if (Utils.isArray(this.aDraftInfo) && 3 === this.aDraftInfo.length)
					{
						aFlagsCache = Cache.getMessageFlagsFromCache(this.aDraftInfo[2], this.aDraftInfo[1]);
						if (aFlagsCache)
						{
							if ('forward' === this.aDraftInfo[0])
							{
								aFlagsCache[3] = true;
							}
							else
							{
								aFlagsCache[2] = true;
							}

							Cache.setMessageFlagsToCache(this.aDraftInfo[2], this.aDraftInfo[1], aFlagsCache);
							require('App/User').reloadFlagsCurrentMessageListAndMessageFromCache();
							Cache.setFolderHash(this.aDraftInfo[2], '');
						}
					}

					sSentFolder = Consts.Values.UnuseOptionValue === sSentFolder ? '' : sSentFolder;

					Cache.setFolderHash(this.draftFolder(), '');
					Cache.setFolderHash(sSentFolder, '');

					Remote.sendMessage(
						this.sendMessageResponse,
						this.draftFolder(),
						this.draftUid(),
						sSentFolder,
						this.currentIdentityResultEmail(),
						sTo,
						this.cc(),
						this.bcc(),
						this.subject(),
						this.oEditor ? this.oEditor.isHtml() : false,
						this.oEditor ? this.oEditor.getData(true) : '',
						this.prepearAttachmentsForSendOrSave(),
						this.aDraftInfo,
						this.sInReplyTo,
						this.sReferences,
						this.requestReadReceipt()
					);
				}
			}
		}, this.canBeSendedOrSaved);

		this.saveCommand = Utils.createCommand(this, function () {

			if (Data.draftFolderNotEnabled())
			{
				kn.showScreenPopup(require('View/Popup/FolderSystem'), [Enums.SetSystemFoldersNotification.Draft]);
			}
			else
			{
				this.savedError(false);
				this.saving(true);

				this.bSkipNext = true;

				Cache.setFolderHash(Data.draftFolder(), '');

				Remote.saveMessage(
					this.saveMessageResponse,
					this.draftFolder(),
					this.draftUid(),
					Data.draftFolder(),
					this.currentIdentityResultEmail(),
					this.to(),
					this.cc(),
					this.bcc(),
					this.subject(),
					this.oEditor ? this.oEditor.isHtml() : false,
					this.oEditor ? this.oEditor.getData(true) : '',
					this.prepearAttachmentsForSendOrSave(),
					this.aDraftInfo,
					this.sInReplyTo,
					this.sReferences
				);
			}

		}, this.canBeSendedOrSaved);

		Events.sub('interval.1m', function () {
			if (this.modalVisibility() && !Data.draftFolderNotEnabled() && !this.isEmptyForm(false) &&
				!this.bSkipNext && !this.saving() && !this.sending() && !this.savedError())
			{
				this.bSkipNext = false;
				this.saveCommand();
			}
		}, this);

		this.showCcAndBcc.subscribe(function () {
			this.triggerForResize();
		}, this);

		this.dropboxEnabled = ko.observable(!!Settings.settingsGet('DropboxApiKey'));

		this.dropboxCommand = Utils.createCommand(this, function () {

			if (window.Dropbox)
			{
				window.Dropbox.choose({
					//'iframe': true,
					'success': function(aFiles) {

						if (aFiles && aFiles[0] && aFiles[0]['link'])
						{
							self.addDropboxAttachment(aFiles[0]);
						}
					},
					'linkType': "direct",
					'multiselect': false
				});
			}

			return true;

		}, function () {
			return this.dropboxEnabled();
		});

		this.driveEnabled = ko.observable(Globals.bXMLHttpRequestSupported &&
			!!Settings.settingsGet('AllowGoogleSocial') && !!Settings.settingsGet('AllowGoogleSocialDrive') &&
			!!Settings.settingsGet('GoogleClientID') && !!Settings.settingsGet('GoogleApiKey'));

		this.driveVisible = ko.observable(false);

		this.driveCommand = Utils.createCommand(this, function () {

			this.driveOpenPopup();
			return true;

		}, function () {
			return this.driveEnabled();
		});

		this.driveCallback = _.bind(this.driveCallback, this);

		this.bDisabeCloseOnEsc = true;
		this.sDefaultKeyScope = Enums.KeyState.Compose;

		this.tryToClosePopup = _.debounce(_.bind(this.tryToClosePopup, this), 200);

		this.emailsSource = _.bind(this.emailsSource, this);

		kn.constructorEnd(this);
	}
コード例 #11
0
ファイル: Filters.js プロジェクト: Rudloff/rainloop-webmail
/**
 * @constructor
 */
function FiltersUserSettings()
{
	var self = this;

	this.modules = FilterStore.modules;
	this.filters = FilterStore.filters;

	this.inited = ko.observable(false);
	this.serverError = ko.observable(false);
	this.serverErrorDesc = ko.observable('');
	this.haveChanges = ko.observable(false);

	this.saveErrorText = ko.observable('');

	this.filters.subscribe(Utils.windowResizeCallback);

	this.serverError.subscribe(function(bValue) {
		if (!bValue)
		{
			this.serverErrorDesc('');
		}
	}, this);

	this.filterRaw = FilterStore.raw;
	this.filterRaw.capa = FilterStore.capa;
	this.filterRaw.active = ko.observable(false);
	this.filterRaw.allow = ko.observable(false);
	this.filterRaw.error = ko.observable(false);

	this.filterForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend(
		{'toggleSubscribeProperty': [this, 'deleteAccess']});

	this.saveChanges = Utils.createCommand(this, function() {

		if (!this.filters.saving())
		{
			if (this.filterRaw.active() && '' === Utils.trim(this.filterRaw()))
			{
				this.filterRaw.error(true);
				return false;
			}

			this.filters.saving(true);
			this.saveErrorText('');

			Remote.filtersSave(function(sResult, oData) {

				self.filters.saving(false);

				if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
				{
					self.haveChanges(false);
					self.updateList();
				}
				else if (oData && oData.ErrorCode)
				{
					self.saveErrorText(oData.ErrorMessageAdditional || Translator.getNotification(oData.ErrorCode));
				}
				else
				{
					self.saveErrorText(Translator.getNotification(Enums.Notification.CantSaveFilters));
				}

			}, this.filters(), this.filterRaw(), this.filterRaw.active());
		}

		return true;

	}, function() {
		return this.haveChanges();
	});

	this.filters.subscribe(function() {
		this.haveChanges(true);
	}, this);

	this.filterRaw.subscribe(function() {
		this.haveChanges(true);
		this.filterRaw.error(false);
	}, this);

	this.haveChanges.subscribe(function() {
		this.saveErrorText('');
	}, this);

	this.filterRaw.active.subscribe(function() {
		this.haveChanges(true);
		this.filterRaw.error(false);
	}, this);
}
コード例 #12
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function ActivatePopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsActivate');

		var self = this;

		this.domain = ko.observable('');
		this.key = ko.observable('');
		this.key.focus = ko.observable(false);
		this.activationSuccessed = ko.observable(false);

		this.licenseTrigger = Data.licenseTrigger;

		this.activateProcess = ko.observable(false);
		this.activateText = ko.observable('');
		this.activateText.isError = ko.observable(false);

		this.key.subscribe(function () {
			this.activateText('');
			this.activateText.isError(false);
		}, this);

		this.activationSuccessed.subscribe(function (bValue) {
			if (bValue)
			{
				this.licenseTrigger(!this.licenseTrigger());
			}
		}, this);

		this.activateCommand = Utils.createCommand(this, function () {

			this.activateProcess(true);
			if (this.validateSubscriptionKey())
			{
				Remote.licensingActivate(function (sResult, oData) {

					self.activateProcess(false);
					if (Enums.StorageResultType.Success === sResult && oData.Result)
					{
						if (true === oData.Result)
						{
							self.activationSuccessed(true);
							self.activateText('Subscription Key Activated Successfully');
							self.activateText.isError(false);
						}
						else
						{
							self.activateText(oData.Result);
							self.activateText.isError(true);
							self.key.focus(true);
						}
					}
					else if (oData.ErrorCode)
					{
						self.activateText(Utils.getNotification(oData.ErrorCode));
						self.activateText.isError(true);
						self.key.focus(true);
					}
					else
					{
						self.activateText(Utils.getNotification(Enums.Notification.UnknownError));
						self.activateText.isError(true);
						self.key.focus(true);
					}

				}, this.domain(), this.key());
			}
			else
			{
				this.activateProcess(false);
				this.activateText('Invalid Subscription Key');
				this.activateText.isError(true);
				this.key.focus(true);
			}

		}, function () {
			return !this.activateProcess() && '' !== this.domain() && '' !== this.key() && !this.activationSuccessed();
		});

		kn.constructorEnd(this);
	}
コード例 #13
0
ファイル: FolderClear.js プロジェクト: Etiqa/rainloop-webmail
/**
 * @constructor
 * @extends AbstractView
 */
function FolderClearPopupView()
{
	AbstractView.call(this, 'Popups', 'PopupsFolderClear');

	this.selectedFolder = ko.observable(null);
	this.clearingProcess = ko.observable(false);
	this.clearingError = ko.observable('');

	this.folderFullNameForClear = ko.computed(function() {
		var oFolder = this.selectedFolder();
		return oFolder ? oFolder.printableFullName() : '';
	}, this);

	this.folderNameForClear = ko.computed(function() {
		var oFolder = this.selectedFolder();
		return oFolder ? oFolder.localName() : '';
	}, this);

	this.dangerDescHtml = ko.computed(function() {
		return Translator.i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', {
			'FOLDER': this.folderNameForClear()
		});
	}, this);

	this.clearCommand = Utils.createCommand(this, function() {

		var
			self = this,
			oFolderToClear = this.selectedFolder();

		if (oFolderToClear)
		{
			MessageStore.message(null);
			MessageStore.messageList([]);

			this.clearingProcess(true);

			oFolderToClear.messageCountAll(0);
			oFolderToClear.messageCountUnread(0);

			Cache.setFolderHash(oFolderToClear.fullNameRaw, '');

			Remote.folderClear(function(sResult, oData) {

				self.clearingProcess(false);
				if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
				{
					require('App/User').default.reloadMessageList(true);
					self.cancelCommand();
				}
				else
				{
					if (oData && oData.ErrorCode)
					{
						self.clearingError(Translator.getNotification(oData.ErrorCode));
					}
					else
					{
						self.clearingError(Translator.getNotification(Enums.Notification.MailServerError));
					}
				}
			}, oFolderToClear.fullNameRaw);
		}

	}, function() {

		var
			oFolder = this.selectedFolder(),
			bIsClearing = this.clearingProcess();

		return !bIsClearing && null !== oFolder;

	});

	kn.constructorEnd(this);
}
コード例 #14
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function MessageViewMailBoxUserView()
	{
		AbstractView.call(this, 'Right', 'MailMessageView');

		var
			self = this,
			sLastEmail = '',
			createCommandHelper = function (sType) {
				return Utils.createCommand(self, function () {
					this.lastReplyAction(sType);
					this.replyOrforward(sType);
				}, self.canBeRepliedOrForwarded);
			}
		;

		this.oDom = null;
		this.oHeaderDom = null;
		this.oMessageScrollerDom = null;

		this.bodyBackgroundColor = ko.observable('');

		this.pswp = null;

		this.allowComposer = !!Settings.capa(Enums.Capa.Composer);
		this.allowMessageActions = !!Settings.capa(Enums.Capa.MessageActions);
		this.allowMessageListActions = !!Settings.capa(Enums.Capa.MessageListActions);

		this.logoImg = Utils.trim(Settings.settingsGet('UserLogoMessage'));
		this.logoIframe = Utils.trim(Settings.settingsGet('UserIframeMessage'));

		this.attachmentsActions = AppStore.attachmentsActions;

		this.message = MessageStore.message;
		this.messageListChecked = MessageStore.messageListChecked;
		this.hasCheckedMessages = MessageStore.hasCheckedMessages;
		this.messageListCheckedOrSelectedUidsWithSubMails = MessageStore.messageListCheckedOrSelectedUidsWithSubMails;
		this.messageLoadingThrottle = MessageStore.messageLoadingThrottle;
		this.messagesBodiesDom = MessageStore.messagesBodiesDom;
		this.useThreads = SettingsStore.useThreads;
		this.replySameFolder = SettingsStore.replySameFolder;
		this.layout = SettingsStore.layout;
		this.usePreviewPane = SettingsStore.usePreviewPane;
		this.isMessageSelected = MessageStore.isMessageSelected;
		this.messageActiveDom = MessageStore.messageActiveDom;
		this.messageError = MessageStore.messageError;

		this.fullScreenMode = MessageStore.messageFullScreenMode;

		this.messageListOfThreadsLoading = ko.observable(false).extend({'rateLimit': 1});

		this.highlightUnselectedAttachments = ko.observable(false).extend({'falseTimeout': 2000});

		this.showAttachmnetControls = ko.observable(false);

		this.allowAttachmnetControls = ko.computed(function () {
			return 0 < this.attachmentsActions().length &&
				Settings.capa(Enums.Capa.AttachmentsActions);
		}, this);

		this.downloadAsZipAllowed = ko.computed(function () {
			return -1 < Utils.inArray('zip', this.attachmentsActions()) &&
				this.allowAttachmnetControls();
		}, this);

		this.downloadAsZipLoading = ko.observable(false);
		this.downloadAsZipError = ko.observable(false).extend({'falseTimeout': 7000});

		this.saveToOwnCloudAllowed = ko.computed(function () {
			return -1 < Utils.inArray('owncloud', this.attachmentsActions()) &&
				this.allowAttachmnetControls();
		}, this);

		this.saveToOwnCloudLoading = ko.observable(false);
		this.saveToOwnCloudSuccess = ko.observable(false).extend({'falseTimeout': 2000});
		this.saveToOwnCloudError = ko.observable(false).extend({'falseTimeout': 7000});

		this.saveToOwnCloudSuccess.subscribe(function (bV) {
			if (bV)
			{
				this.saveToOwnCloudError(false);
			}
		}, this);

		this.saveToOwnCloudError.subscribe(function (bV) {
			if (bV)
			{
				this.saveToOwnCloudSuccess(false);
			}
		}, this);

		this.saveToDropboxAllowed = ko.computed(function () {
			return -1 < Utils.inArray('dropbox', this.attachmentsActions()) &&
				this.allowAttachmnetControls();
		}, this);

		this.saveToDropboxLoading = ko.observable(false);
		this.saveToDropboxSuccess = ko.observable(false).extend({'falseTimeout': 2000});
		this.saveToDropboxError = ko.observable(false).extend({'falseTimeout': 7000});

		this.saveToDropboxSuccess.subscribe(function (bV) {
			if (bV)
			{
				this.saveToDropboxError(false);
			}
		}, this);

		this.saveToDropboxError.subscribe(function (bV) {
			if (bV)
			{
				this.saveToDropboxSuccess(false);
			}
		}, this);

		this.showAttachmnetControls.subscribe(function (bV) {
			if (this.message())
			{
				_.each(this.message().attachments(), function (oItem) {
					if (oItem)
					{
						oItem.checked(!!bV);
					}
				});
			}
		}, this);

		this.lastReplyAction_ = ko.observable('');
		this.lastReplyAction = ko.computed({
			read: this.lastReplyAction_,
			write: function (sValue) {
				sValue = -1 === Utils.inArray(sValue, [
					Enums.ComposeType.Reply, Enums.ComposeType.ReplyAll, Enums.ComposeType.Forward
				]) ? Enums.ComposeType.Reply : sValue;
				this.lastReplyAction_(sValue);
			},
			owner: this
		});

		this.lastReplyAction(Local.get(Enums.ClientSideKeyName.LastReplyAction) || Enums.ComposeType.Reply);
		this.lastReplyAction_.subscribe(function (sValue) {
			Local.set(Enums.ClientSideKeyName.LastReplyAction, sValue);
		});

		this.showFullInfo = ko.observable(false);
		this.moreDropdownTrigger = ko.observable(false);
		this.messageDomFocused = ko.observable(false).extend({'rateLimit': 0});

		this.messageVisibility = ko.computed(function () {
			return !this.messageLoadingThrottle() && !!this.message();
		}, this);

		this.message.subscribe(function (oMessage) {
			if (!oMessage)
			{
				MessageStore.selectorMessageSelected(null);
			}
		}, this);

		this.canBeRepliedOrForwarded = ko.computed(function () {
			var bV = this.messageVisibility();
			return !this.isDraftFolder() && bV;
		}, this);

		// commands
		this.closeMessage = Utils.createCommand(this, function () {
			MessageStore.message(null);
		});

		this.replyCommand = createCommandHelper(Enums.ComposeType.Reply);
		this.replyAllCommand = createCommandHelper(Enums.ComposeType.ReplyAll);
		this.forwardCommand = createCommandHelper(Enums.ComposeType.Forward);
		this.forwardAsAttachmentCommand = createCommandHelper(Enums.ComposeType.ForwardAsAttachment);
		this.editAsNewCommand = createCommandHelper(Enums.ComposeType.EditAsNew);

		this.messageVisibilityCommand = Utils.createCommand(this, Utils.emptyFunction, this.messageVisibility);

		this.messageEditCommand = Utils.createCommand(this, function () {
			this.editMessage();
		}, this.messageVisibility);

		this.deleteCommand = Utils.createCommand(this, function () {
			var oMessage = this.message();
			if (oMessage && this.allowMessageListActions)
			{
				this.message(null);
				require('App/User').deleteMessagesFromFolder(Enums.FolderType.Trash,
					oMessage.folderFullNameRaw, [oMessage.uid], true);
			}
		}, this.messageVisibility);

		this.deleteWithoutMoveCommand = Utils.createCommand(this, function () {
			var oMessage = this.message();
			if (oMessage && this.allowMessageListActions)
			{
				this.message(null);
				require('App/User').deleteMessagesFromFolder(Enums.FolderType.Trash,
					oMessage.folderFullNameRaw, [oMessage.uid], false);
			}
		}, this.messageVisibility);

		this.archiveCommand = Utils.createCommand(this, function () {
			var oMessage = this.message();
			if (oMessage && this.allowMessageListActions)
			{
				this.message(null);
				require('App/User').deleteMessagesFromFolder(Enums.FolderType.Archive,
					oMessage.folderFullNameRaw, [oMessage.uid], true);
			}
		}, this.messageVisibility);

		this.spamCommand = Utils.createCommand(this, function () {
			var oMessage = this.message();
			if (oMessage && this.allowMessageListActions)
			{
				this.message(null);
				require('App/User').deleteMessagesFromFolder(Enums.FolderType.Spam,
					oMessage.folderFullNameRaw, [oMessage.uid], true);
			}
		}, this.messageVisibility);

		this.notSpamCommand = Utils.createCommand(this, function () {
			var oMessage = this.message();
			if (oMessage && this.allowMessageListActions)
			{
				this.message(null);
				require('App/User').deleteMessagesFromFolder(Enums.FolderType.NotSpam,
					oMessage.folderFullNameRaw, [oMessage.uid], true);
			}
		}, this.messageVisibility);

		this.dropboxEnabled = SocialStore.dropbox.enabled;
		this.dropboxApiKey = SocialStore.dropbox.apiKey;

		// viewer

		this.viewBodyTopValue = ko.observable(0);

		this.viewFolder = '';
		this.viewUid = '';
		this.viewHash = '';
		this.viewSubject = ko.observable('');
		this.viewFromShort = ko.observable('');
		this.viewFromDkimData = ko.observable(['none', '']);
		this.viewToShort = ko.observable('');
		this.viewFrom = ko.observable('');
		this.viewTo = ko.observable('');
		this.viewCc = ko.observable('');
		this.viewBcc = ko.observable('');
		this.viewReplyTo = ko.observable('');
		this.viewTimeStamp = ko.observable(0);
		this.viewSize = ko.observable('');
		this.viewLineAsCss = ko.observable('');
		this.viewViewLink = ko.observable('');
		this.viewDownloadLink = ko.observable('');
		this.viewUserPic = ko.observable(Consts.DataImages.UserDotPic);
		this.viewUserPicVisible = ko.observable(false);
		this.viewIsImportant = ko.observable(false);
		this.viewIsFlagged = ko.observable(false);

		this.viewFromDkimStatusIconClass = ko.computed(function () {

			var sResult = 'icon-none iconcolor-display-none';
//			var sResult = 'icon-warning-alt iconcolor-grey';
			switch (this.viewFromDkimData()[0])
			{
				case 'none':
					break;
				case 'pass':
					sResult = 'icon-ok iconcolor-green';
//					sResult = 'icon-warning-alt iconcolor-green';
					break;
				default:
					sResult = 'icon-warning-alt iconcolor-red';
					break;
			}

			return sResult;

		}, this);

		this.viewFromDkimStatusTitle = ko.computed(function () {

			var aStatus = this.viewFromDkimData();
			if (Utils.isNonEmptyArray(aStatus))
			{
				if (aStatus[0] && aStatus[1])
				{
					return aStatus[1];
				}
				else if (aStatus[0])
				{
					return 'DKIM: ' + aStatus[0];
				}
			}

			return '';

		}, this);

		this.messageActiveDom.subscribe(function (oDom) {
			this.bodyBackgroundColor(oDom ? this.detectDomBackgroundColor(oDom): '');
		}, this);

		this.message.subscribe(function (oMessage) {

			this.messageActiveDom(null);

			if (oMessage)
			{
				this.showAttachmnetControls(false);

				if (this.viewHash !== oMessage.hash)
				{
					this.scrollMessageToTop();
				}

				this.viewFolder = oMessage.folderFullNameRaw;
				this.viewUid = oMessage.uid;
				this.viewHash = oMessage.hash;
				this.viewSubject(oMessage.subject());
				this.viewFromShort(oMessage.fromToLine(true, true));
				this.viewFromDkimData(oMessage.fromDkimData());
				this.viewToShort(oMessage.toToLine(true, true));
				this.viewFrom(oMessage.fromToLine(false));
				this.viewTo(oMessage.toToLine(false));
				this.viewCc(oMessage.ccToLine(false));
				this.viewBcc(oMessage.bccToLine(false));
				this.viewReplyTo(oMessage.replyToToLine(false));
				this.viewTimeStamp(oMessage.dateTimeStampInUTC());
				this.viewSize(oMessage.friendlySize());
				this.viewLineAsCss(oMessage.lineAsCss());
				this.viewViewLink(oMessage.viewLink());
				this.viewDownloadLink(oMessage.downloadLink());
				this.viewIsImportant(oMessage.isImportant());
				this.viewIsFlagged(oMessage.flagged());

				sLastEmail = oMessage.fromAsSingleEmail();
				Cache.getUserPic(sLastEmail, function (sPic, sEmail) {
					if (sPic !== self.viewUserPic() && sLastEmail === sEmail)
					{
						self.viewUserPicVisible(false);
						self.viewUserPic(Consts.DataImages.UserDotPic);
						if ('' !== sPic)
						{
							self.viewUserPicVisible(true);
							self.viewUserPic(sPic);
						}
					}
				});
			}
			else
			{
				this.viewFolder = '';
				this.viewUid = '';
				this.viewHash = '';

				this.scrollMessageToTop();
			}

		}, this);

		this.message.viewTrigger.subscribe(function () {
			var oMessage = this.message();
			if (oMessage)
			{
				this.viewIsFlagged(oMessage.flagged());
			}
			else
			{
				this.viewIsFlagged(false);
			}
		}, this);

		this.fullScreenMode.subscribe(function (bValue) {
			Globals.$html.toggleClass('rl-message-fullscreen', bValue);
			Utils.windowResize();
		});

		this.messageLoadingThrottle.subscribe(Utils.windowResizeCallback);

		this.messageFocused = ko.computed(function () {
			return Enums.Focused.MessageView === AppStore.focusedState();
		});

		this.messageListAndMessageViewLoading = ko.computed(function () {
			return MessageStore.messageListCompleteLoadingThrottle() || MessageStore.messageLoadingThrottle();
		});

		this.goUpCommand = Utils.createCommand(this, function () {
			Events.pub('mailbox.message-list.selector.go-up', [
				Enums.Layout.NoPreview === this.layout() ? !!this.message() : true
			]);
		}, function () {
			return !this.messageListAndMessageViewLoading();
		});

		this.goDownCommand = Utils.createCommand(this, function () {
			Events.pub('mailbox.message-list.selector.go-down', [
				Enums.Layout.NoPreview === this.layout() ? !!this.message() : true
			]);
		}, function () {
			return !this.messageListAndMessageViewLoading();
		});

		Events.sub('mailbox.message-view.toggle-full-screen', function () {
			this.toggleFullScreen();
		}, this);

		kn.constructorEnd(this);
	}
コード例 #15
0
ファイル: Identity.js プロジェクト: lackd/rainloop-webmail
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function IdentityPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsIdentity');

		var self = this;

		this.id = '';
		this.edit = ko.observable(false);
		this.owner = ko.observable(false);

		this.editor = null;
		this.signatureDom = ko.observable(null);

		this.email = ko.observable('').validateEmail();
		this.email.focused = ko.observable(false);
		this.name = ko.observable('');
		this.name.focused = ko.observable(false);
		this.replyTo = ko.observable('').validateSimpleEmail();
		this.replyTo.focused = ko.observable(false);
		this.bcc = ko.observable('').validateSimpleEmail();
		this.bcc.focused = ko.observable(false);

		this.signature = ko.observable('');
		this.signatureInsertBefore = ko.observable(false);

		this.showBcc = ko.observable(false);
		this.showReplyTo = ko.observable(false);

		this.submitRequest = ko.observable(false);
		this.submitError = ko.observable('');

		this.bcc.subscribe(function (aValue) {
			if (false === self.showBcc() && 0 < aValue.length)
			{
				self.showBcc(true);
			}
		}, this);

		this.replyTo.subscribe(function (aValue) {
			if (false === self.showReplyTo() && 0 < aValue.length)
			{
				self.showReplyTo(true);
			}
		}, this);

		this.addOrEditIdentityCommand = Utils.createCommand(this, function () {

			this.populateSignatureFromEditor();

			if (!this.email.hasError())
			{
				this.email.hasError('' === Utils.trim(this.email()));
			}

			if (this.email.hasError())
			{
				if (!this.owner())
				{
					this.email.focused(true);
				}

				return false;
			}

			if (this.replyTo.hasError())
			{
				this.replyTo.focused(true);
				return false;
			}

			if (this.bcc.hasError())
			{
				this.bcc.focused(true);
				return false;
			}

			this.submitRequest(true);

			Remote.identityUpdate(_.bind(function (sResult, oData) {

				this.submitRequest(false);
				if (Enums.StorageResultType.Success === sResult && oData)
				{
					if (oData.Result)
					{
						require('App/User').accountsAndIdentities();
						this.cancelCommand();
					}
					else if (oData.ErrorCode)
					{
						this.submitError(Translator.getNotification(oData.ErrorCode));
					}
				}
				else
				{
					this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
				}

			}, this), this.id, this.email(), this.name(), this.replyTo(), this.bcc(),
				this.signature(), this.signatureInsertBefore());

			return true;

		}, function () {
			return !this.submitRequest();
		});

		kn.constructorEnd(this);
	}
コード例 #16
0
	/**
	 * @constructor
	 */
	function SecurityAdminSetting()
	{
		this.useLocalProxyForExternalImages = Data.useLocalProxyForExternalImages;

		this.weakPassword = Data.weakPassword;

		this.capaOpenPGP = ko.observable(Settings.capa(Enums.Capa.OpenPGP));
		this.capaTwoFactorAuth = ko.observable(Settings.capa(Enums.Capa.TwoFactor));

		this.verifySslCertificate = ko.observable(!!Settings.settingsGet('VerifySslCertificate'));

		this.adminLogin = ko.observable(Settings.settingsGet('AdminLogin'));
		this.adminLoginError = ko.observable(false);
		this.adminPassword = ko.observable('');
		this.adminPasswordNew = ko.observable('');
		this.adminPasswordNew2 = ko.observable('');
		this.adminPasswordNewError = ko.observable(false);

		this.adminPasswordUpdateError = ko.observable(false);
		this.adminPasswordUpdateSuccess = ko.observable(false);

		this.adminPassword.subscribe(function () {
			this.adminPasswordUpdateError(false);
			this.adminPasswordUpdateSuccess(false);
		}, this);

		this.adminLogin.subscribe(function () {
			this.adminLoginError(false);
		}, this);

		this.adminPasswordNew.subscribe(function () {
			this.adminPasswordUpdateError(false);
			this.adminPasswordUpdateSuccess(false);
			this.adminPasswordNewError(false);
		}, this);

		this.adminPasswordNew2.subscribe(function () {
			this.adminPasswordUpdateError(false);
			this.adminPasswordUpdateSuccess(false);
			this.adminPasswordNewError(false);
		}, this);

		this.saveNewAdminPasswordCommand = Utils.createCommand(this, function () {

			if ('' === Utils.trim(this.adminLogin()))
			{
				this.adminLoginError(true);
				return false;
			}

			if (this.adminPasswordNew() !== this.adminPasswordNew2())
			{
				this.adminPasswordNewError(true);
				return false;
			}

			this.adminPasswordUpdateError(false);
			this.adminPasswordUpdateSuccess(false);

			Remote.saveNewAdminPassword(this.onNewAdminPasswordResponse, {
				'Login': this.adminLogin(),
				'Password': this.adminPassword(),
				'NewPassword': this.adminPasswordNew()
			});

		}, function () {
			return '' !== Utils.trim(this.adminLogin()) && '' !== this.adminPassword();
		});

		this.onNewAdminPasswordResponse = _.bind(this.onNewAdminPasswordResponse, this);
	}
コード例 #17
0
ファイル: Domain.js プロジェクト: jamesanto/rainloop-webmail
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function DomainPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsDomain');

		this.edit = ko.observable(false);
		this.saving = ko.observable(false);
		this.savingError = ko.observable('');
		this.whiteListPage = ko.observable(false);

		this.testing = ko.observable(false);
		this.testingDone = ko.observable(false);
		this.testingImapError = ko.observable(false);
		this.testingSmtpError = ko.observable(false);
		this.testingImapErrorDesc = ko.observable('');
		this.testingSmtpErrorDesc = ko.observable('');

		this.testingImapError.subscribe(function (bValue) {
			if (!bValue)
			{
				this.testingImapErrorDesc('');
			}
		}, this);

		this.testingSmtpError.subscribe(function (bValue) {
			if (!bValue)
			{
				this.testingSmtpErrorDesc('');
			}
		}, this);

		this.testingImapErrorDesc = ko.observable('');
		this.testingSmtpErrorDesc = ko.observable('');

		this.imapServerFocus = ko.observable(false);
		this.smtpServerFocus = ko.observable(false);

		this.name = ko.observable('');
		this.name.focused = ko.observable(false);

		this.imapServer = ko.observable('');
		this.imapPort = ko.observable('' + Consts.Values.ImapDefaulPort);
		this.imapSecure = ko.observable(Enums.ServerSecure.None);
		this.imapShortLogin = ko.observable(false);
		this.smtpServer = ko.observable('');
		this.smtpPort = ko.observable('' + Consts.Values.SmtpDefaulPort);
		this.smtpSecure = ko.observable(Enums.ServerSecure.None);
		this.smtpShortLogin = ko.observable(false);
		this.smtpAuth = ko.observable(true);
		this.smtpPhpMail = ko.observable(false);
		this.whiteList = ko.observable('');

		this.enableSmartPorts = ko.observable(false);

		this.headerText = ko.computed(function () {
			var sName = this.name();
			return this.edit() ? 'Edit Domain "' + sName + '"' :
				'Add Domain' + ('' === sName ? '' : ' "' + sName + '"');
		}, this);

		this.domainIsComputed = ko.computed(function () {
			return '' !== this.name() &&
				'' !== this.imapServer() &&
				'' !== this.imapPort() &&
				'' !== this.smtpServer() &&
				'' !== this.smtpPort();
		}, this);

		this.canBeTested = ko.computed(function () {
			return !this.testing() && this.domainIsComputed();
		}, this);

		this.canBeSaved = ko.computed(function () {
			return !this.saving() && this.domainIsComputed();
		}, this);

		this.createOrAddCommand = Utils.createCommand(this, function () {
			this.saving(true);
			Remote.createOrUpdateDomain(
				_.bind(this.onDomainCreateOrSaveResponse, this),
				!this.edit(),
				this.name(),
				this.imapServer(),
				Utils.pInt(this.imapPort()),
				this.imapSecure(),
				this.imapShortLogin(),
				this.smtpServer(),
				Utils.pInt(this.smtpPort()),
				this.smtpSecure(),
				this.smtpShortLogin(),
				this.smtpAuth(),
				this.smtpPhpMail(),
				this.whiteList()
			);
		}, this.canBeSaved);

		this.testConnectionCommand = Utils.createCommand(this, function () {
			this.whiteListPage(false);
			this.testingDone(false);
			this.testingImapError(false);
			this.testingSmtpError(false);
			this.testing(true);
			Remote.testConnectionForDomain(
				_.bind(this.onTestConnectionResponse, this),
				this.name(),
				this.imapServer(),
				Utils.pInt(this.imapPort()),
				this.imapSecure(),
				this.smtpServer(),
				Utils.pInt(this.smtpPort()),
				this.smtpSecure(),
				this.smtpAuth(),
				this.smtpPhpMail()
			);
		}, this.canBeTested);

		this.whiteListCommand = Utils.createCommand(this, function () {
			this.whiteListPage(!this.whiteListPage());
		});

		// smart form improvements
		this.imapServerFocus.subscribe(function (bValue) {
			if (bValue && '' !== this.name() && '' === this.imapServer())
			{
				this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
			}
		}, this);

		this.smtpServerFocus.subscribe(function (bValue) {
			if (bValue && '' !== this.imapServer() && '' === this.smtpServer())
			{
				this.smtpServer(this.imapServer().replace(/imap/ig, 'smtp'));
			}
		}, this);

		this.imapSecure.subscribe(function (sValue) {
			if (this.enableSmartPorts())
			{
				var iPort = Utils.pInt(this.imapPort());
				sValue = Utils.pString(sValue);
				switch (sValue)
				{
					case '0':
						if (993 === iPort)
						{
							this.imapPort('143');
						}
						break;
					case '1':
						if (143 === iPort)
						{
							this.imapPort('993');
						}
						break;
				}
			}
		}, this);

		this.smtpSecure.subscribe(function (sValue) {
			if (this.enableSmartPorts())
			{
				var iPort = Utils.pInt(this.smtpPort());
				sValue = Utils.pString(sValue);
				switch (sValue)
				{
					case '0':
						if (465 === iPort || 587 === iPort)
						{
							this.smtpPort('25');
						}
						break;
					case '1':
						if (25 === iPort || 587 === iPort)
						{
							this.smtpPort('465');
						}
						break;
					case '2':
						if (25 === iPort || 465 === iPort)
						{
							this.smtpPort('587');
						}
						break;
				}
			}
		}, this);

		kn.constructorEnd(this);
	}
コード例 #18
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function PluginPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsPlugin');

		var self = this;

		this.onPluginSettingsUpdateResponse = _.bind(this.onPluginSettingsUpdateResponse, this);

		this.saveError = ko.observable('');

		this.name = ko.observable('');
		this.readme = ko.observable('');

		this.configures = ko.observableArray([]);

		this.hasReadme = ko.computed(function () {
			return '' !== this.readme();
		}, this);

		this.hasConfiguration = ko.computed(function () {
			return 0 < this.configures().length;
		}, this);

		this.readmePopoverConf = {
			'placement': 'top',
			'trigger': 'hover',
			'title': 'About',
			'content': function () {
				return self.readme();
			}
		};

		this.saveCommand = Utils.createCommand(this, function () {

			var oList = {};

			oList['Name'] = this.name();

			_.each(this.configures(), function (oItem) {

				var mValue = oItem.value();
				if (false === mValue || true === mValue)
				{
					mValue = mValue ? '1' : '0';
				}

				oList['_' + oItem['Name']] = mValue;

			}, this);

			this.saveError('');
			Remote.pluginSettingsUpdate(this.onPluginSettingsUpdateResponse, oList);

		}, this.hasConfiguration);

		this.bDisabeCloseOnEsc = true;
		this.sDefaultKeyScope = Enums.KeyState.All;

		this.tryToClosePopup = _.debounce(_.bind(this.tryToClosePopup, this), 200);

		kn.constructorEnd(this);
	}
コード例 #19
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function MessageListMailBoxUserView()
	{
		AbstractView.call(this, 'Right', 'MailMessageList');

		this.sLastUid = null;
		this.bPrefetch = false;
		this.emptySubjectValue = '';

		this.hideDangerousActions = !!Settings.settingsGet('HideDangerousActions');

		this.popupVisibility = Globals.popupVisibility;

		this.message = MessageStore.message;
		this.messageList = MessageStore.messageList;
		this.messageListDisableAutoSelect = MessageStore.messageListDisableAutoSelect;

		this.folderList = FolderStore.folderList;

		this.selectorMessageSelected = MessageStore.selectorMessageSelected;
		this.selectorMessageFocused = MessageStore.selectorMessageFocused;
		this.isMessageSelected = MessageStore.isMessageSelected;
		this.messageListSearch = MessageStore.messageListSearch;
		this.messageListThreadUid = MessageStore.messageListThreadUid;
		this.messageListError = MessageStore.messageListError;
		this.folderMenuForMove = FolderStore.folderMenuForMove;

		this.useCheckboxesInList = SettingsStore.useCheckboxesInList;

		this.mainMessageListSearch = MessageStore.mainMessageListSearch;
		this.messageListEndFolder = MessageStore.messageListEndFolder;
		this.messageListEndThreadUid = MessageStore.messageListEndThreadUid;

		this.messageListChecked = MessageStore.messageListChecked;
		this.messageListCheckedOrSelected = MessageStore.messageListCheckedOrSelected;
		this.messageListCheckedOrSelectedUidsWithSubMails = MessageStore.messageListCheckedOrSelectedUidsWithSubMails;
		this.messageListCompleteLoadingThrottle = MessageStore.messageListCompleteLoadingThrottle;
		this.messageListCompleteLoadingThrottleForAnimation = MessageStore.messageListCompleteLoadingThrottleForAnimation;

		Translator.initOnStartOrLangChange(function () {
			this.emptySubjectValue = Translator.i18n('MESSAGE_LIST/EMPTY_SUBJECT_TEXT');
		}, this);

		this.userQuota = QuotaStore.quota;
		this.userUsageSize = QuotaStore.usage;
		this.userUsageProc = QuotaStore.percentage;

		this.moveDropdownTrigger = ko.observable(false);
		this.moreDropdownTrigger = ko.observable(false);

		// append drag and drop
		this.dragOver = ko.observable(false).extend({'throttle': 1});
		this.dragOverEnter = ko.observable(false).extend({'throttle': 1});
		this.dragOverArea = ko.observable(null);
		this.dragOverBodyArea = ko.observable(null);

		this.messageListItemTemplate = ko.computed(function () {
			return Enums.Layout.SidePreview === SettingsStore.layout() ?
				'MailMessageListItem' : 'MailMessageListItemNoPreviewPane';
		});

		this.messageListSearchDesc = ko.computed(function () {
			var sValue = MessageStore.messageListEndSearch();
			return '' === sValue ? '' : Translator.i18n('MESSAGE_LIST/SEARCH_RESULT_FOR', {'SEARCH': sValue});
		});

		this.messageListPagenator = ko.computed(Utils.computedPagenatorHelper(
			MessageStore.messageListPage, MessageStore.messageListPageCount));

		this.checkAll = ko.computed({
			'read': function () {
				return 0 < MessageStore.messageListChecked().length;
			},

			'write': function (bValue) {
				bValue = !!bValue;
				_.each(MessageStore.messageList(), function (oMessage) {
					oMessage.checked(bValue);
				});
			}
		});

		this.inputMessageListSearchFocus = ko.observable(false);

		this.sLastSearchValue = '';
		this.inputProxyMessageListSearch = ko.computed({
			'read': this.mainMessageListSearch,
			'write': function (sValue) {
				this.sLastSearchValue = sValue;
			},
			'owner': this
		});

		this.isIncompleteChecked = ko.computed(function () {
			var
				iM = MessageStore.messageList().length,
				iC = MessageStore.messageListChecked().length
			;
			return 0 < iM && 0 < iC && iM > iC;
		}, this);

		this.hasMessages = ko.computed(function () {
			return 0 < this.messageList().length;
		}, this);

		this.hasCheckedOrSelectedLines = ko.computed(function () {
			return 0 < this.messageListCheckedOrSelected().length;
		}, this);

		this.isSpamFolder = ko.computed(function () {
			return FolderStore.spamFolder() === this.messageListEndFolder() &&
				'' !== FolderStore.spamFolder();
		}, this);

		this.isSpamDisabled = ko.computed(function () {
			return Consts.Values.UnuseOptionValue === FolderStore.spamFolder();
		}, this);

		this.isTrashFolder = ko.computed(function () {
			return FolderStore.trashFolder() === this.messageListEndFolder() &&
				'' !== FolderStore.trashFolder();
		}, this);

		this.isDraftFolder = ko.computed(function () {
			return FolderStore.draftFolder() === this.messageListEndFolder() &&
				'' !== FolderStore.draftFolder();
		}, this);

		this.isSentFolder = ko.computed(function () {
			return FolderStore.sentFolder() === this.messageListEndFolder() &&
				'' !== FolderStore.sentFolder();
		}, this);

		this.isArchiveFolder = ko.computed(function () {
			return FolderStore.archiveFolder() === this.messageListEndFolder() &&
				'' !== FolderStore.archiveFolder();
		}, this);

		this.isArchiveDisabled = ko.computed(function () {
			return Consts.Values.UnuseOptionValue === FolderStore.archiveFolder();
		}, this);

		this.isArchiveVisible = ko.computed(function () {
			return !this.isArchiveFolder() && !this.isArchiveDisabled() && !this.isDraftFolder();
		}, this);

		this.isSpamVisible = ko.computed(function () {
			return !this.isSpamFolder() && !this.isSpamDisabled() && !this.isDraftFolder() && !this.isSentFolder();
		}, this);

		this.isUnSpamVisible = ko.computed(function () {
			return this.isSpamFolder() && !this.isSpamDisabled() && !this.isDraftFolder() && !this.isSentFolder();
		}, this);

		this.messageListFocused = ko.computed(function () {
			return Enums.Focused.MessageList === AppStore.focusedState();
		});

		this.canBeMoved = this.hasCheckedOrSelectedLines;

		this.clearCommand = Utils.createCommand(this, function () {
			kn.showScreenPopup(require('View/Popup/FolderClear'), [FolderStore.currentFolder()]);
		});

		this.multyForwardCommand = Utils.createCommand(this, function () {
			kn.showScreenPopup(require('View/Popup/Compose'), [
				Enums.ComposeType.ForwardAsAttachment, MessageStore.messageListCheckedOrSelected()]);
		}, this.canBeMoved);

		this.deleteWithoutMoveCommand = Utils.createCommand(this, function () {
			require('App/User').deleteMessagesFromFolder(Enums.FolderType.Trash,
				FolderStore.currentFolderFullNameRaw(),
				MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), false);
		}, this.canBeMoved);

		this.deleteCommand = Utils.createCommand(this, function () {
			require('App/User').deleteMessagesFromFolder(Enums.FolderType.Trash,
				FolderStore.currentFolderFullNameRaw(),
				MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), true);
		}, this.canBeMoved);

		this.archiveCommand = Utils.createCommand(this, function () {
			require('App/User').deleteMessagesFromFolder(Enums.FolderType.Archive,
				FolderStore.currentFolderFullNameRaw(),
				MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), true);
		}, this.canBeMoved);

		this.spamCommand = Utils.createCommand(this, function () {
			require('App/User').deleteMessagesFromFolder(Enums.FolderType.Spam,
				FolderStore.currentFolderFullNameRaw(),
				MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), true);
		}, this.canBeMoved);

		this.notSpamCommand = Utils.createCommand(this, function () {
			require('App/User').deleteMessagesFromFolder(Enums.FolderType.NotSpam,
				FolderStore.currentFolderFullNameRaw(),
				MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), true);
		}, this.canBeMoved);

		this.moveCommand = Utils.createCommand(this, Utils.emptyFunction, this.canBeMoved);

		this.reloadCommand = Utils.createCommand(this, function () {
			if (!MessageStore.messageListCompleteLoadingThrottleForAnimation())
			{
				require('App/User').reloadMessageList(false, true);
			}
		});

		this.quotaTooltip = _.bind(this.quotaTooltip, this);

		this.selector = new Selector(this.messageList, this.selectorMessageSelected, this.selectorMessageFocused,
			'.messageListItem .actionHandle', '.messageListItem.selected', '.messageListItem .checkboxMessage',
				'.messageListItem.focused');

		this.selector.on('onItemSelect', _.bind(function (oMessage) {
			MessageStore.selectMessage(oMessage);
		}, this));

		this.selector.on('onItemGetUid', function (oMessage) {
			return oMessage ? oMessage.generateUid() : '';
		});

		this.selector.on('onAutoSelect', _.bind(function () {
			return this.useAutoSelect();
		}, this));

		this.selector.on('onUpUpOrDownDown', _.bind(function (bV) {
			this.goToUpUpOrDownDown(bV);
		}, this));

		Events
			.sub('mailbox.message-list.selector.go-down', function (bSelect) {
				this.selector.goDown(bSelect);
			}, this)
			.sub('mailbox.message-list.selector.go-up', function (bSelect) {
				this.selector.goUp(bSelect);
			}, this)
		;

		MessageStore.messageListEndHash.subscribe(function () {
			this.selector.scrollToTop();
		}, this);

		kn.constructorEnd(this);
	}
コード例 #20
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function ComposeOpenPgpPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsComposeOpenPgp');

		var self = this;

		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.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.text = ko.observable('');
		this.selectedPrivateKey = ko.observable(null);
		this.selectedPublicKey = ko.observable(null);

		this.signKey = ko.observable(null);
		this.encryptKeys = ko.observableArray([]);

		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 {
							'id': oKey.guid,
							'name': '(' + oKey.id.substr(-8).toUpperCase() + ') ' + sUser,
							'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,
				aPrivateKeys = [],
				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;
				}

				if (bResult)
				{
					aPrivateKeys = this.signKey().key.getNativeKeys();
					oPrivateKey = aPrivateKeys[0] || null;

					try
					{
						if (oPrivateKey)
						{
							oPrivateKey.decrypt(Utils.pString(this.password()));
						}
					}
					catch (e)
					{
						oPrivateKey = null;
					}

					if (!oPrivateKey)
					{
						this.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND'));
						bResult = false;
					}
				}
			}

			if (bResult && this.encrypt())
			{
				if (0 === this.encryptKeys().length)
				{
					this.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND'));
					bResult = false;
				}
				else if (this.encryptKeys())
				{
					aPublicKeys = [];

					_.each(this.encryptKeys(), function (oKey) {
						if (oKey && oKey.key)
						{
							aPublicKeys = aPublicKeys.concat(_.compact(_.flatten(oKey.key.getNativeKeys())));
						}
						else if (oKey && oKey.email)
						{
							self.notification(Translator.i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND_FOR', {
								'EMAIL': oKey.email
							}));

							bResult = false;
						}
					});

					if (bResult && (0 === aPublicKeys.length || this.encryptKeys().length !== aPublicKeys.length))
					{
						bResult = false;
					}
				}
			}

			if (bResult && self.resultCallback)
			{
				_.delay(function () {

					var oPromise = null;

					try
					{
						if (oPrivateKey && 0 === aPublicKeys.length)
						{
							oPromise = PgpStore.openpgp.signClearMessage([oPrivateKey], self.text());
						}
						else if (oPrivateKey && 0 < aPublicKeys.length)
						{
							oPromise = PgpStore.openpgp.signAndEncryptMessage(aPublicKeys, oPrivateKey, self.text());
						}
						else if (!oPrivateKey && 0 < aPublicKeys.length)
						{
							oPromise = PgpStore.openpgp.encryptMessage(aPublicKeys, self.text());
						}
					}
					catch (e)
					{
						Utils.log(e);

						self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
							'ERROR': '' + e
						}));
					}

					if (oPromise)
					{
						try
						{
							oPromise.then(function (mData) {

								self.resultCallback(mData);
								self.cancelCommand();

							})['catch'](function (e) {
								self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
									'ERROR': '' + e
								}));
							});
						}
						catch (e)
						{
							self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
								'ERROR': '' + e
							}));
						}
					}

					self.submitRequest(false);

				}, 10);
			}
			else
			{
				self.submitRequest(false);
			}

			return bResult;

		}, function () {
			return !this.submitRequest() &&	(this.sign() || this.encrypt());
		});

		this.selectCommand = Utils.createCommand(this, function () {

			var
				sKeyId = this.selectedPrivateKey(),
				oKey = null,
				oOption = sKeyId ? _.find(this.privateKeysOptions(), function (oItem) {
					return oItem && sKeyId === oItem.id;
				}) : null
			;

			if (oOption)
			{
				oKey = {
					'empty': !oOption.key,
					'selected': ko.observable(!!oOption.key),
					'users': oOption.key.users,
					'hash': oOption.key.id.substr(-8).toUpperCase(),
					'key': oOption.key
				};

				this.signKey(oKey);
			}
		});

		this.addCommand = Utils.createCommand(this, function () {

			var
				sKeyId = this.selectedPublicKey(),
				aKeys = this.encryptKeys(),
				oOption = sKeyId ? _.find(this.publicKeysOptions(), function (oItem) {
					return oItem && sKeyId === oItem.id;
				}) : null
			;

			if (oOption)
			{
				aKeys.push({
					'empty': !oOption.key,
					'selected': ko.observable(!!oOption.key),
					'removable': ko.observable(!this.sign() || !this.signKey() || this.signKey().key.id !== oOption.key.id),
					'users': oOption.key.users,
					'hash': oOption.key.id.substr(-8).toUpperCase(),
					'key': oOption.key
				});

				this.encryptKeys(aKeys);
			}
		});

		this.updateCommand = Utils.createCommand(this, function () {

			var self = this;

			_.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);
	}
コード例 #21
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function FolderCreateView()
	{
		AbstractView.call(this, 'Popups', 'PopupsFolderCreate');

		Utils.initOnStartOrLangChange(function () {
			this.sNoParentText = Utils.i18n('POPUPS_CREATE_FOLDER/SELECT_NO_PARENT');
		}, this);

		this.folderName = ko.observable('');
		this.folderName.focused = ko.observable(false);

		this.selectedParentValue = ko.observable(Consts.Values.UnuseOptionValue);

		this.parentFolderSelectList = ko.computed(function () {

			var
				aTop = [],
				fDisableCallback = null,
				fVisibleCallback = null,
				aList = Data.folderList(),
				fRenameCallback = function (oItem) {
					return oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '';
				}
			;

			aTop.push(['', this.sNoParentText]);

			if ('' !== Data.namespace)
			{
				fDisableCallback = function (oItem)
				{
					return Data.namespace !== oItem.fullNameRaw.substr(0, Data.namespace.length);
				};
			}

			return Utils.folderListOptionsBuilder([], aList, [], aTop, null, fDisableCallback, fVisibleCallback, fRenameCallback);

		}, this);

		// commands
		this.createFolder = Utils.createCommand(this, function () {

			var
				sParentFolderName = this.selectedParentValue()
			;

			if ('' === sParentFolderName && 1 < Data.namespace.length)
			{
				sParentFolderName = Data.namespace.substr(0, Data.namespace.length - 1);
			}

			Data.foldersCreating(true);
			Remote.folderCreate(function (sResult, oData) {

				Data.foldersCreating(false);
				if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
				{
					require('App/App').folders();
				}
				else
				{
					Data.foldersListError(
						oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) : Utils.i18n('NOTIFICATIONS/CANT_CREATE_FOLDER'));
				}

			},	this.folderName(), sParentFolderName);

			this.cancelCommand();

		}, function () {
			return this.simpleFolderNameValidation(this.folderName());
		});

		this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;

		kn.constructorEnd(this);
	}
コード例 #22
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function AddOpenPgpKeyPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsAddOpenPgpKey');

		this.key = ko.observable('');
		this.key.error = ko.observable(false);
		this.key.focus = ko.observable(false);

		this.key.subscribe(function () {
			this.key.error(false);
		}, this);

		this.addOpenPgpKeyCommand = Utils.createCommand(this, function () {

			var
				iCount = 30,
				aMatch = null,
				sKey = Utils.trim(this.key()),
				oReg = /[\-]{3,6}BEGIN[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[\-]{3,6}[\s\S]+?[\-]{3,6}END[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[\-]{3,6}/gi,
				oOpenpgpKeyring = Data.openpgpKeyring
			;

			sKey = sKey.replace(/[\r\n]([a-zA-Z0-9]{2,}:[^\r\n]+)[\r\n]+([a-zA-Z0-9\/\\+=]{10,})/g, '\n$1!-!N!-!$2')
				.replace(/[\n\r]+/g, '\n').replace(/!-!N!-!/g, '\n\n');

			this.key.error('' === sKey);

			if (!oOpenpgpKeyring || this.key.error())
			{
				return false;
			}

			do
			{
				aMatch = oReg.exec(sKey);
				if (!aMatch || 0 > iCount)
				{
					break;
				}

				if (aMatch[0] && aMatch[1] && aMatch[2] && aMatch[1] === aMatch[2])
				{
					if ('PRIVATE' === aMatch[1])
					{
						oOpenpgpKeyring.privateKeys.importKey(aMatch[0]);
					}
					else if ('PUBLIC' === aMatch[1])
					{
						oOpenpgpKeyring.publicKeys.importKey(aMatch[0]);
					}
				}

				iCount--;
			}
			while (true);

			oOpenpgpKeyring.store();

			require('App/User').reloadOpenPgpKeys();
			Utils.delegateRun(this, 'cancelCommand');

			return true;
		});

		kn.constructorEnd(this);
	}
コード例 #23
0
			createCommandHelper = function (sType) {
				return Utils.createCommand(self, function () {
					this.lastReplyAction(sType);
					this.replyOrforward(sType);
				}, self.canBeRepliedOrForwarded);
			}
コード例 #24
0
ファイル: NewOpenPgpKey.js プロジェクト: 1os/rainloop-webmail
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function NewOpenPgpKeyPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsNewOpenPgpKey');

		this.email = ko.observable('');
		this.email.focus = ko.observable('');
		this.email.error = ko.observable(false);

		this.name = ko.observable('');
		this.password = ko.observable('');
		this.keyBitLength = ko.observable(2048);

		this.submitRequest = ko.observable(false);

		this.email.subscribe(function () {
			this.email.error(false);
		}, this);

		this.generateOpenPgpKeyCommand = Utils.createCommand(this, function () {

			var
				self = this,
				sUserID = '',
				oOpenpgpKeyring = PgpStore.openpgpKeyring
			;

			this.email.error('' === Utils.trim(this.email()));
			if (!oOpenpgpKeyring || this.email.error())
			{
				return false;
			}

			sUserID = this.email();
			if ('' !== this.name())
			{
				sUserID = this.name() + ' <' + sUserID + '>';
			}

			this.submitRequest(true);

			_.delay(function () {

				var mPromise = false;

				try {

					mPromise = PgpStore.openpgp.generateKeyPair({
						'userId': sUserID,
						'numBits': Utils.pInt(self.keyBitLength()),
						'passphrase': Utils.trim(self.password())
					});

					mPromise.then(function (mKeyPair) {

						self.submitRequest(false);

						if (mKeyPair && mKeyPair.privateKeyArmored)
						{
							oOpenpgpKeyring.privateKeys.importKey(mKeyPair.privateKeyArmored);
							oOpenpgpKeyring.publicKeys.importKey(mKeyPair.publicKeyArmored);

							oOpenpgpKeyring.store();

							require('App/User').default.reloadOpenPgpKeys();
							Utils.delegateRun(self, 'cancelCommand');
						}

					})['catch'](function() {
						self.submitRequest(false);
					});
				}
				catch (e)
				{
					Utils.log(e);
					self.submitRequest(false);
				}

			}, 100);

			return true;
		});

		kn.constructorEnd(this);
	}
コード例 #25
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function ContactsPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsContacts');

		var
			self = this,
			fFastClearEmptyListHelper = function (aList) {
				if (aList && 0 < aList.length) {
					self.viewProperties.removeAll(aList);
				}
			}
		;

		this.allowContactsSync = Data.allowContactsSync;
		this.enableContactsSync = Data.enableContactsSync;
		this.allowExport = !Globals.bMobileDevice;

		this.search = ko.observable('');
		this.contactsCount = ko.observable(0);
		this.contacts = Data.contacts;
		this.contactTags = Data.contactTags;

		this.currentContact = ko.observable(null);

		this.importUploaderButton = ko.observable(null);

		this.contactsPage = ko.observable(1);
		this.contactsPageCount = ko.computed(function () {
			var iPage = window.Math.ceil(this.contactsCount() / Consts.Defaults.ContactsPerPage);
			return 0 >= iPage ? 1 : iPage;
		}, this);

		this.contactsPagenator = ko.computed(Utils.computedPagenatorHelper(this.contactsPage, this.contactsPageCount));

		this.emptySelection = ko.observable(true);
		this.viewClearSearch = ko.observable(false);

		this.viewID = ko.observable('');
		this.viewReadOnly = ko.observable(false);
		this.viewProperties = ko.observableArray([]);

		this.viewTags = ko.observable('');
		this.viewTags.visibility = ko.observable(false);
		this.viewTags.focusTrigger = ko.observable(false);

		this.viewTags.focusTrigger.subscribe(function (bValue) {
			if (!bValue && '' === this.viewTags())
			{
				this.viewTags.visibility(false);
			}
			else if (bValue)
			{
				this.viewTags.visibility(true);
			}
		}, this);

		this.viewSaveTrigger = ko.observable(Enums.SaveSettingsStep.Idle);

		this.viewPropertiesNames = this.viewProperties.filter(function(oProperty) {
			return -1 < Utils.inArray(oProperty.type(), [
				Enums.ContactPropertyType.FirstName, Enums.ContactPropertyType.LastName
			]);
		});

		this.viewPropertiesOther = this.viewProperties.filter(function(oProperty) {
			return -1 < Utils.inArray(oProperty.type(), [
				Enums.ContactPropertyType.Note
			]);
		});

		this.viewPropertiesOther = ko.computed(function () {

			var aList = _.filter(this.viewProperties(), function (oProperty) {
				return -1 < Utils.inArray(oProperty.type(), [
					Enums.ContactPropertyType.Nick
				]);
			});

			return _.sortBy(aList, function (oProperty) {
				return oProperty.type();
			});

		}, this);

		this.viewPropertiesEmails = this.viewProperties.filter(function(oProperty) {
			return Enums.ContactPropertyType.Email === oProperty.type();
		});

		this.viewPropertiesWeb = this.viewProperties.filter(function(oProperty) {
			return Enums.ContactPropertyType.Web === oProperty.type();
		});

		this.viewHasNonEmptyRequaredProperties = ko.computed(function() {

			var
				aNames = this.viewPropertiesNames(),
				aEmail = this.viewPropertiesEmails(),
				fHelper = function (oProperty) {
					return '' !== Utils.trim(oProperty.value());
				}
			;

			return !!(_.find(aNames, fHelper) || _.find(aEmail, fHelper));
		}, this);

		this.viewPropertiesPhones = this.viewProperties.filter(function(oProperty) {
			return Enums.ContactPropertyType.Phone === oProperty.type();
		});

		this.viewPropertiesEmailsNonEmpty = this.viewPropertiesNames.filter(function(oProperty) {
			return '' !== Utils.trim(oProperty.value());
		});

		this.viewPropertiesEmailsEmptyAndOnFocused = this.viewPropertiesEmails.filter(function(oProperty) {
			var bF = oProperty.focused();
			return '' === Utils.trim(oProperty.value()) && !bF;
		});

		this.viewPropertiesPhonesEmptyAndOnFocused = this.viewPropertiesPhones.filter(function(oProperty) {
			var bF = oProperty.focused();
			return '' === Utils.trim(oProperty.value()) && !bF;
		});

		this.viewPropertiesWebEmptyAndOnFocused = this.viewPropertiesWeb.filter(function(oProperty) {
			var bF = oProperty.focused();
			return '' === Utils.trim(oProperty.value()) && !bF;
		});

		this.viewPropertiesOtherEmptyAndOnFocused = ko.computed(function () {
			return _.filter(this.viewPropertiesOther(), function (oProperty) {
				var bF = oProperty.focused();
				return '' === Utils.trim(oProperty.value()) && !bF;
			});
		}, this);

		this.viewPropertiesEmailsEmptyAndOnFocused.subscribe(function(aList) {
			fFastClearEmptyListHelper(aList);
		});

		this.viewPropertiesPhonesEmptyAndOnFocused.subscribe(function(aList) {
			fFastClearEmptyListHelper(aList);
		});

		this.viewPropertiesWebEmptyAndOnFocused.subscribe(function(aList) {
			fFastClearEmptyListHelper(aList);
		});

		this.viewPropertiesOtherEmptyAndOnFocused.subscribe(function(aList) {
			fFastClearEmptyListHelper(aList);
		});

		this.viewSaving = ko.observable(false);

		this.useCheckboxesInList = Data.useCheckboxesInList;

		this.search.subscribe(function () {
			this.reloadContactList();
		}, this);

		this.contacts.subscribe(function () {
			Utils.windowResize();
		}, this);

		this.viewProperties.subscribe(function () {
			Utils.windowResize();
		}, this);

		this.contactsChecked = ko.computed(function () {
			return _.filter(this.contacts(), function (oItem) {
				return oItem.checked();
			});
		}, this);

		this.contactsCheckedOrSelected = ko.computed(function () {

			var
				aChecked = this.contactsChecked(),
				oSelected = this.currentContact()
			;

			return _.union(aChecked, oSelected ? [oSelected] : []);

		}, this);

		this.contactsCheckedOrSelectedUids = ko.computed(function () {
			return _.map(this.contactsCheckedOrSelected(), function (oContact) {
				return oContact.idContact;
			});
		}, this);

		this.selector = new Selector(this.contacts, this.currentContact,
			'.e-contact-item .actionHandle', '.e-contact-item.selected', '.e-contact-item .checkboxItem',
				'.e-contact-item.focused');

		this.selector.on('onItemSelect', _.bind(function (oContact) {
			this.populateViewContact(oContact ? oContact : null);
			if (!oContact)
			{
				this.emptySelection(true);
			}
		}, this));

		this.selector.on('onItemGetUid', function (oContact) {
			return oContact ? oContact.generateUid() : '';
		});

		this.newCommand = Utils.createCommand(this, function () {
			this.populateViewContact(null);
			this.currentContact(null);
		});

		this.deleteCommand = Utils.createCommand(this, function () {
			this.deleteSelectedContacts();
			this.emptySelection(true);
		}, function () {
			return 0 < this.contactsCheckedOrSelected().length;
		});

		this.newMessageCommand = Utils.createCommand(this, function () {
			var aC = this.contactsCheckedOrSelected(), aE = [];
			if (Utils.isNonEmptyArray(aC))
			{
				aE = _.map(aC, function (oItem) {
					if (oItem)
					{
						var
							aData = oItem.getNameAndEmailHelper(),
							oEmail = aData ? new EmailModel(aData[0], aData[1]) : null
						;

						if (oEmail && oEmail.validate())
						{
							return oEmail;
						}
					}

					return null;
				});

				aE = _.compact(aE);
			}

			if (Utils.isNonEmptyArray(aE))
			{
				kn.hideScreenPopup(require('View/Popup/Contacts'));
				kn.showScreenPopup(require('View/Popup/Compose'), [Enums.ComposeType.Empty, null, aE]);
			}

		}, function () {
			return 0 < this.contactsCheckedOrSelected().length;
		});

		this.clearCommand = Utils.createCommand(this, function () {
			this.search('');
		});

		this.saveCommand = Utils.createCommand(this, function () {

			this.viewSaving(true);
			this.viewSaveTrigger(Enums.SaveSettingsStep.Animate);

			var
				sRequestUid = Utils.fakeMd5(),
				aProperties = []
			;

			_.each(this.viewProperties(), function (oItem) {
				if (oItem.type() && '' !== Utils.trim(oItem.value()))
				{
					aProperties.push([oItem.type(), oItem.value(), oItem.typeStr()]);
				}
			});

			Remote.contactSave(function (sResult, oData) {

				var bRes = false;
				self.viewSaving(false);

				if (Enums.StorageResultType.Success === sResult && oData && oData.Result &&
					oData.Result.RequestUid === sRequestUid && 0 < Utils.pInt(oData.Result.ResultID))
				{
					if ('' === self.viewID())
					{
						self.viewID(Utils.pInt(oData.Result.ResultID));
					}

					self.reloadContactList();
					bRes = true;
				}

				_.delay(function () {
					self.viewSaveTrigger(bRes ? Enums.SaveSettingsStep.TrueResult : Enums.SaveSettingsStep.FalseResult);
				}, 300);

				if (bRes)
				{
					self.watchDirty(false);

					_.delay(function () {
						self.viewSaveTrigger(Enums.SaveSettingsStep.Idle);
					}, 1000);
				}

			}, sRequestUid, this.viewID(), this.viewTags(), aProperties);

		}, function () {
			var
				bV = this.viewHasNonEmptyRequaredProperties(),
				bReadOnly = this.viewReadOnly()
			;
			return !this.viewSaving() && bV && !bReadOnly;
		});

		this.syncCommand = Utils.createCommand(this, function () {

			var self = this;
			require('App/App').contactsSync(function (sResult, oData) {
				if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
				{
					window.alert(Utils.getNotification(
						oData && oData.ErrorCode ? oData.ErrorCode : Enums.Notification.ContactsSyncError));
				}

				self.reloadContactList(true);
			});

		}, function () {
			return !this.contacts.syncing() && !this.contacts.importing();
		});

		this.bDropPageAfterDelete = false;

		this.watchDirty = ko.observable(false);
		this.watchHash = ko.observable(false);

		this.viewHash = ko.computed(function () {
			return '' + self.viewTags() + '|' + _.map(self.viewProperties(), function (oItem) {
				return oItem.value();
			}).join('');
		});

	//	this.saveCommandDebounce = _.debounce(_.bind(this.saveCommand, this), 1000);

		this.viewHash.subscribe(function () {
			if (this.watchHash() && !this.viewReadOnly() && !this.watchDirty())
			{
				this.watchDirty(true);
			}
		}, this);

		this.sDefaultKeyScope = Enums.KeyState.ContactList;

		this.contactTagsSource = _.bind(this.contactTagsSource, this);

		kn.constructorEnd(this);
	}
コード例 #26
0
/**
 * @constructor
 * @extends AbstractView
 */
function LoginAdminView()
{
	AbstractView.call(this, 'Center', 'AdminLogin');

	this.logoPowered = !!Settings.settingsGet('LoginPowered');

	this.mobile = !!Settings.appSettingsGet('mobile');
	this.mobileDevice = !!Settings.appSettingsGet('mobileDevice');

	this.login = ko.observable('');
	this.password = ko.observable('');

	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.loginFocus = ko.observable(false);

	this.formHidden = ko.observable(false);

	this.formError = ko.computed(function() {
		return this.loginErrorAnimation() || this.passwordErrorAnimation();
	}, this);

	this.login.subscribe(function() {
		this.loginError(false);
	}, this);

	this.password.subscribe(function() {
		this.passwordError(false);
	}, this);

	this.loginError.subscribe(function(bV) {
		this.loginErrorAnimation(!!bV);
	}, this);

	this.passwordError.subscribe(function(bV) {
		this.passwordErrorAnimation(!!bV);
	}, this);

	this.submitRequest = ko.observable(false);
	this.submitError = ko.observable('');

	this.submitCommand = Utils.createCommand(this, function() {

		Utils.triggerAutocompleteInputChange();

		this.loginError(false);
		this.passwordError(false);

		this.loginError('' === Utils.trim(this.login()));
		this.passwordError('' === Utils.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 (oData.Result)
				{
					require('App/Admin').default.loginAndLogoutReload(true);
				}
				else if (oData.ErrorCode)
				{
					this.submitRequest(false);
					this.submitError(Translator.getNotification(oData.ErrorCode));
				}
			}
			else
			{
				this.submitRequest(false);
				this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
			}

		}, this), this.login(), this.password());

		return true;

	}, function() {
		return !this.submitRequest();
	});

	kn.constructorEnd(this);
}
コード例 #27
0
ファイル: Filter.js プロジェクト: Etiqa/rainloop-webmail
/**
 * @constructor
 * @extends AbstractView
 */
function FilterPopupView()
{
	AbstractView.call(this, 'Popups', 'PopupsFilter');

	this.isNew = ko.observable(true);

	this.modules = FilterStore.modules;

	this.fTrueCallback = null;
	this.filter = ko.observable(null);

	this.allowMarkAsRead = ko.observable(false);

	this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
	this.folderSelectList = FolderStore.folderMenuForFilters;
	this.selectedFolderValue = ko.observable('');

	this.selectedFolderValue.subscribe(function() {
		if (this.filter())
		{
			this.filter().actionValue.error(false);
		}
	}, this);

	this.saveFilter = Utils.createCommand(this, function() {

		if (this.filter())
		{
			if (Enums.FiltersAction.MoveTo === this.filter().actionType())
			{
				this.filter().actionValue(this.selectedFolderValue());
			}

			if (!this.filter().verify())
			{
				return false;
			}

			if (this.fTrueCallback)
			{
				this.fTrueCallback(this.filter());
			}

			if (this.modalVisibility())
			{
				Utils.delegateRun(this, 'closeCommand');
			}
		}

		return true;
	});

	this.actionTypeOptions = ko.observableArray([]);
	this.fieldOptions = ko.observableArray([]);
	this.typeOptions = ko.observableArray([]);
	this.typeOptionsSize = ko.observableArray([]);

	Translator.initOnStartOrLangChange(_.bind(this.populateOptions, this));

	this.modules.subscribe(this.populateOptions, this);

	kn.constructorEnd(this);
}
コード例 #28
0
ファイル: Domain.js プロジェクト: 1os/rainloop-webmail
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function DomainPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsDomain');

		this.edit = ko.observable(false);
		this.saving = ko.observable(false);
		this.savingError = ko.observable('');
		this.page = ko.observable('main');
		this.sieveSettings = ko.observable(false);

		this.testing = ko.observable(false);
		this.testingDone = ko.observable(false);
		this.testingImapError = ko.observable(false);
		this.testingSieveError = ko.observable(false);
		this.testingSmtpError = ko.observable(false);
		this.testingImapErrorDesc = ko.observable('');
		this.testingSieveErrorDesc = ko.observable('');
		this.testingSmtpErrorDesc = ko.observable('');

		this.testingImapError.subscribe(function (bValue) {
			if (!bValue)
			{
				this.testingImapErrorDesc('');
			}
		}, this);

		this.testingSieveError.subscribe(function (bValue) {
			if (!bValue)
			{
				this.testingSieveErrorDesc('');
			}
		}, this);

		this.testingSmtpError.subscribe(function (bValue) {
			if (!bValue)
			{
				this.testingSmtpErrorDesc('');
			}
		}, this);

		this.imapServerFocus = ko.observable(false);
		this.sieveServerFocus = ko.observable(false);
		this.smtpServerFocus = ko.observable(false);

		this.name = ko.observable('');
		this.name.focused = ko.observable(false);

		this.imapServer = ko.observable('');
		this.imapPort = ko.observable('' + Consts.IMAP_DEFAULT_PORT);
		this.imapSecure = ko.observable(Enums.ServerSecure.None);
		this.imapShortLogin = ko.observable(false);
		this.useSieve = ko.observable(false);
		this.sieveAllowRaw = ko.observable(false);
		this.sieveServer = ko.observable('');
		this.sievePort = ko.observable('' + Consts.SIEVE_DEFAULT_PORT);
		this.sieveSecure = ko.observable(Enums.ServerSecure.None);
		this.smtpServer = ko.observable('');
		this.smtpPort = ko.observable('' + Consts.SMTP_DEFAULT_PORT);
		this.smtpSecure = ko.observable(Enums.ServerSecure.None);
		this.smtpShortLogin = ko.observable(false);
		this.smtpAuth = ko.observable(true);
		this.smtpPhpMail = ko.observable(false);
		this.whiteList = ko.observable('');

		this.enableSmartPorts = ko.observable(false);

		this.allowSieve = ko.computed(function () {
			return CapaAdminStore.filters() && CapaAdminStore.sieve();
		}, this);

		this.headerText = ko.computed(function () {
			var sName = this.name();
			return this.edit() ? Translator.i18n('POPUPS_DOMAIN/TITLE_EDIT_DOMAIN', {'NAME': sName}) :
				('' === sName ? Translator.i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN') :
					Translator.i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN_WITH_NAME', {'NAME': sName}));
		}, this);

		this.domainDesc = ko.computed(function () {
			var sName = this.name();
			return !this.edit() && sName ? Translator.i18n('POPUPS_DOMAIN/NEW_DOMAIN_DESC', {'NAME': '*@' + sName}) : '';
		}, this);

		this.domainIsComputed = ko.computed(function () {

			var
				bPhpMail = this.smtpPhpMail(),
				bAllowSieve = this.allowSieve(),
				bUseSieve = this.useSieve()
			;

			return '' !== this.name() &&
				'' !== this.imapServer() &&
				'' !== this.imapPort() &&
				(bAllowSieve && bUseSieve ? ('' !== this.sieveServer() && '' !== this.sievePort()) : true) &&
				(('' !== this.smtpServer() && '' !== this.smtpPort()) || bPhpMail);

		}, this);

		this.canBeTested = ko.computed(function () {
			return !this.testing() && this.domainIsComputed();
		}, this);

		this.canBeSaved = ko.computed(function () {
			return !this.saving() && this.domainIsComputed();
		}, this);

		this.createOrAddCommand = Utils.createCommand(this, function () {
			this.saving(true);
			Remote.createOrUpdateDomain(
				_.bind(this.onDomainCreateOrSaveResponse, this),
				!this.edit(),
				this.name(),

				this.imapServer(),
				Utils.pInt(this.imapPort()),
				this.imapSecure(),
				this.imapShortLogin(),

				this.useSieve(),
				this.sieveAllowRaw(),
				this.sieveServer(),
				Utils.pInt(this.sievePort()),
				this.sieveSecure(),

				this.smtpServer(),
				Utils.pInt(this.smtpPort()),
				this.smtpSecure(),
				this.smtpShortLogin(),
				this.smtpAuth(),
				this.smtpPhpMail(),

				this.whiteList()
			);
		}, this.canBeSaved);

		this.testConnectionCommand = Utils.createCommand(this, function () {

			this.page('main');

			this.testingDone(false);
			this.testingImapError(false);
			this.testingSieveError(false);
			this.testingSmtpError(false);
			this.testing(true);

			Remote.testConnectionForDomain(
				_.bind(this.onTestConnectionResponse, this),
				this.name(),

				this.imapServer(),
				Utils.pInt(this.imapPort()),
				this.imapSecure(),

				this.useSieve(),
				this.sieveServer(),
				Utils.pInt(this.sievePort()),
				this.sieveSecure(),

				this.smtpServer(),
				Utils.pInt(this.smtpPort()),
				this.smtpSecure(),
				this.smtpAuth(),
				this.smtpPhpMail()
			);
		}, this.canBeTested);

		this.whiteListCommand = Utils.createCommand(this, function () {
			this.page('white-list');
		});

		this.backCommand = Utils.createCommand(this, function () {
			this.page('main');
		});

		this.sieveCommand = Utils.createCommand(this, function () {
			this.sieveSettings(!this.sieveSettings());
			this.clearTesting();
		});

		this.page.subscribe(function () {
			this.sieveSettings(false);
		}, this);

		// smart form improvements
		this.imapServerFocus.subscribe(function (bValue) {
			if (bValue && '' !== this.name() && '' === this.imapServer())
			{
				this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
			}
		}, this);

		this.sieveServerFocus.subscribe(function (bValue) {
			if (bValue && '' !== this.imapServer() && '' === this.sieveServer())
			{
				this.sieveServer(this.imapServer());
			}
		}, this);

		this.smtpServerFocus.subscribe(function (bValue) {
			if (bValue && '' !== this.imapServer() && '' === this.smtpServer())
			{
				this.smtpServer(this.imapServer().replace(/imap/ig, 'smtp'));
			}
		}, this);

		this.imapSecure.subscribe(function (sValue) {
			if (this.enableSmartPorts())
			{
				var iPort = Utils.pInt(this.imapPort());
				sValue = Utils.pString(sValue);
				switch (sValue)
				{
					case '0':
						if (993 === iPort)
						{
							this.imapPort('143');
						}
						break;
					case '1':
						if (143 === iPort)
						{
							this.imapPort('993');
						}
						break;
				}
			}
		}, this);

		this.smtpSecure.subscribe(function (sValue) {
			if (this.enableSmartPorts())
			{
				var iPort = Utils.pInt(this.smtpPort());
				sValue = Utils.pString(sValue);
				switch (sValue)
				{
					case '0':
						if (465 === iPort || 587 === iPort)
						{
							this.smtpPort('25');
						}
						break;
					case '1':
						if (25 === iPort || 587 === iPort)
						{
							this.smtpPort('465');
						}
						break;
					case '2':
						if (25 === iPort || 465 === iPort)
						{
							this.smtpPort('587');
						}
						break;
				}
			}
		}, this);

		kn.constructorEnd(this);
	}
コード例 #29
0
ファイル: Social.js プロジェクト: Rona111/rainloop-webmail
	/**
	 * @constructor
	 */
	function SocialUserSettings()
	{
		var
			Utils = require('Common/Utils'),
			SocialStore = require('Stores/Social')
		;

		this.googleEnable = SocialStore.google.enabled;
		this.googleEnableAuth = SocialStore.google.capa.auth;
		this.googleEnableAuthFast = SocialStore.google.capa.authFast;
		this.googleEnableDrive = SocialStore.google.capa.drive;
		this.googleEnablePreview = SocialStore.google.capa.preview;

		this.googleActions = SocialStore.google.loading;
		this.googleLoggined = SocialStore.google.loggined;
		this.googleUserName = SocialStore.google.userName;

		this.facebookEnable = SocialStore.facebook.enabled;

		this.facebookActions = SocialStore.facebook.loading;
		this.facebookLoggined = SocialStore.facebook.loggined;
		this.facebookUserName = SocialStore.facebook.userName;

		this.twitterEnable = SocialStore.twitter.enabled;

		this.twitterActions = SocialStore.twitter.loading;
		this.twitterLoggined = SocialStore.twitter.loggined;
		this.twitterUserName = SocialStore.twitter.userName;

		this.connectGoogle = Utils.createCommand(this, function () {
			if (!this.googleLoggined())
			{
				require('App/User').googleConnect();
			}
		}, function () {
			return !this.googleLoggined() && !this.googleActions();
		});

		this.disconnectGoogle = Utils.createCommand(this, function () {
			require('App/User').googleDisconnect();
		});

		this.connectFacebook = Utils.createCommand(this, function () {
			if (!this.facebookLoggined())
			{
				require('App/User').facebookConnect();
			}
		}, function () {
			return !this.facebookLoggined() && !this.facebookActions();
		});

		this.disconnectFacebook = Utils.createCommand(this, function () {
			require('App/User').facebookDisconnect();
		});

		this.connectTwitter = Utils.createCommand(this, function () {
			if (!this.twitterLoggined())
			{
				require('App/User').twitterConnect();
			}
		}, function () {
			return !this.twitterLoggined() && !this.twitterActions();
		});

		this.disconnectTwitter = Utils.createCommand(this, function () {
			require('App/User').twitterDisconnect();
		});
	}
コード例 #30
0
	/**
	 * @constructor
	 * @extends AbstractView
	 */
	function IdentityPopupView()
	{
		AbstractView.call(this, 'Popups', 'PopupsIdentity');

		this.id = '';
		this.edit = ko.observable(false);
		this.owner = ko.observable(false);

		this.email = ko.observable('').validateEmail();
		this.email.focused = ko.observable(false);
		this.name = ko.observable('');
		this.name.focused = ko.observable(false);
		this.replyTo = ko.observable('').validateSimpleEmail();
		this.replyTo.focused = ko.observable(false);
		this.bcc = ko.observable('').validateSimpleEmail();
		this.bcc.focused = ko.observable(false);

	//	this.email.subscribe(function () {
	//		this.email.hasError(false);
	//	}, this);

		this.submitRequest = ko.observable(false);
		this.submitError = ko.observable('');

		this.addOrEditIdentityCommand = Utils.createCommand(this, function () {

			if (!this.email.hasError())
			{
				this.email.hasError('' === Utils.trim(this.email()));
			}

			if (this.email.hasError())
			{
				if (!this.owner())
				{
					this.email.focused(true);
				}

				return false;
			}

			if (this.replyTo.hasError())
			{
				this.replyTo.focused(true);
				return false;
			}

			if (this.bcc.hasError())
			{
				this.bcc.focused(true);
				return false;
			}

			this.submitRequest(true);

			Remote.identityUpdate(_.bind(function (sResult, oData) {

				this.submitRequest(false);
				if (Enums.StorageResultType.Success === sResult && oData)
				{
					if (oData.Result)
					{
						require('App/App').accountsAndIdentities();
						this.cancelCommand();
					}
					else if (oData.ErrorCode)
					{
						this.submitError(Utils.getNotification(oData.ErrorCode));
					}
				}
				else
				{
					this.submitError(Utils.getNotification(Enums.Notification.UnknownError));
				}

			}, this), this.id, this.email(), this.name(), this.replyTo(), this.bcc());

			return true;

		}, function () {
			return !this.submitRequest();
		});

		this.label = ko.computed(function () {
			return Utils.i18n('POPUPS_IDENTITIES/' + (this.edit() ? 'TITLE_UPDATE_IDENTITY': 'TITLE_ADD_IDENTITY'));
		}, this);

		this.button = ko.computed(function () {
			return Utils.i18n('POPUPS_IDENTITIES/' + (this.edit() ? 'BUTTON_UPDATE_IDENTITY': 'BUTTON_ADD_IDENTITY'));
		}, this);

		kn.constructorEnd(this);
	}