<commit_before>/*
    Copyright (c) 2016 eyeOS

    This file is part of Open365.

    Open365 is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

define([
	"jquery",
	"emile",
	"js/translator",
	"js/settings"
], function ($, emile, Translator, Settings) {

	var Prepare = function (settings, translator) {
		this.platformSettings = window.platformSettings || {};
		this.translator = translator || new Translator();
		this.settings = settings || Settings;
	};

	Prepare.prototype.prepareLoginSubmit = function (callback) {
		$("#loginform").on("submit", callback);
	};

	Prepare.prototype.prepareForgotSubmit = function (callback) {
		$("#forgotform").on("submit", callback);
	};

	Prepare.prototype.prepareRecoverSubmit = function (callback) {
		$("#recoverform").on("submit", callback);
	};

	Prepare.prototype.prepareForgotPassClick = function(callback) {
		$("#forgotPassLink").click(callback);
	};

	Prepare.prototype.prepareLoginTermsAndConditionsClick = function(callback) {
		$("#termsAndConditions a").click(callback);
	};

	Prepare.prototype.prepareForgotAskForHelpClick = function(callback) {
		$("#forgotPassHelpText a").click(callback);
	};

	Prepare.prototype.linkTermsAndConditions = function() {
		var urlTermsConditions = "terms_conditions/" + this.translator.getUserLanguage() + "/terms-and-conditions.html";
		$("#termsAndConditions a").attr("href", urlTermsConditions);
	};

	Prepare.prototype.linkAskForHelp = function() {
		var userLanguage = this.translator.getUserLanguage();
		if (userLanguage.localeCompare("en") != 0 && userLanguage.localeCompare("es") != 0) {
			userLanguage = "en";
		}
		var urlHelp = "https://support.open365.io/index.php/" + userLanguage + "/forum";
		$("#forgotPassHelpText a").attr("href", urlHelp);
	};

	Prepare.prototype.showForgotForm = function() {
		this.hideLoginForm();
		this.hideRecoverForm();
		$("#forgotform").removeClass("hidden");
	};

	Prepare.prototype.showRecoverForm = function() {
		this.hideLoginForm();
		this.hideForgotForm();
		$("#recoverform").removeClass("hidden");
	};

	Prepare.prototype.hideForgotForm = function() {
		$("#forgotform").addClass("hidden");
	};

	Prepare.prototype.hideRecoverForm = function() {
		$("#recoverform").addClass("hidden");
	};

	Prepare.prototype.hideLoginForm = function() {
		$("#loginform").addClass("hidden");
	};

	Prepare.prototype.prepareRecoverFormFocus = function() {
		$("#newPassword").focus();
	};

	Prepare.prototype.prepareLoginFormFocus = function () {
		// focus on username when the page is loaded.
		$("#username").focus();
	};

	Prepare.prototype.prepareKeyPress = function () {
		var self = this;
		// focus on username/password when login button lost its focus
		$('#loginButtonBox').blur();
        var input = 'username';
        if (self.hasCaptcha()) {
            input = 'password';
        }
        $("#" +input).focus();
	};

	Prepare.prototype.shakeBox = function () {
		//third party
		function bounce(pos) {
			pos += 1.941626;
			if (pos > 2.170804) {
				return 0;
			}
			return Math.sin(10 * pos * pos) / (pos);
		}

		emile(document.getElementById('loginGeneralContainer'), 'margin-left: 100px', {duration: 1000, easing: bounce});
	};

	Prepare.prototype.prepareCaptcha = function (url, callback) {
		if (!this.hasCaptcha()) {
			$('#captchaBox').show();
			this.prepareRefreshButton(callback);
			$("#captchaText").prop('required', true);
		}
		this.setCaptchaImage(url);
	};

	Prepare.prototype.prepareUsernameInput = function () {
		var self = this;
		$("#username").change(function () {
			if (self.hasCaptcha()) {
				$("#captchaText").prop('required', false);
				$('#captchaBox').hide();
				$("#errorMessage").html("");
				$("#errorMessage").addClass('hidden');
			}
		});
	};

	Prepare.prototype.hasCaptcha = function () {
		return $('#captchaBox').is(":visible");
	};

	Prepare.prototype.setCaptchaImage = function (url) {
		$('#captchaImage').attr("src", url);
	};

	Prepare.prototype.prepareErrorMessage = function (message) {
		$("#errorMessage").html(this.translator.messageTranslation(message));
		if(message.length > 0){
			$("#errorMessage").removeClass('hidden');
			$("#successMessage").addClass('hidden');
		}else{
			$("#errorMessage").addClass('hidden');
		}
	};

	Prepare.prototype.prepareSuccessMessage = function (message) {
		$("#successMessage").html(this.translator.messageTranslation(message));
		if(message.length > 0){
			$("#successMessage").removeClass('hidden');
			$("#errorMessage").addClass('hidden');
		}else{
			$("#successMessage").addClass('hidden');
		}
	};

	Prepare.prototype.prepareCaptchaErrorMessage = function (message) {
		$("#errorCaptchaMessage").html(this.translator.messageTranslation(message));
		if(message.length > 0){
			$("#errorCaptchaMessage").removeClass('hidden');
		}else{<commit_msg>Hide all notification messages when forms are showed<commit_after>/*
    Copyright (c) 2016 eyeOS

    This file is part of Open365.

    Open365 is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

define([
	"jquery",
	"emile",
	"js/translator",
	"js/settings"
], function ($, emile, Translator, Settings) {

	var Prepare = function (settings, translator) {
		this.platformSettings = window.platformSettings || {};
		this.translator = translator || new Translator();
		this.settings = settings || Settings;
	};

	Prepare.prototype.prepareLoginSubmit = function (callback) {
		$("#loginform").on("submit", callback);
	};

	Prepare.prototype.prepareForgotSubmit = function (callback) {
		$("#forgotform").on("submit", callback);
	};

	Prepare.prototype.prepareRecoverSubmit = function (callback) {
		$("#recoverform").on("submit", callback);
	};

	Prepare.prototype.prepareForgotPassClick = function(callback) {
		$("#forgotPassLink").click(callback);
	};

	Prepare.prototype.prepareLoginTermsAndConditionsClick = function(callback) {
		$("#termsAndConditions a").click(callback);
	};

	Prepare.prototype.prepareForgotAskForHelpClick = function(callback) {
		$("#forgotPassHelpText a").click(callback);
	};

	Prepare.prototype.linkTermsAndConditions = function() {
		var urlTermsConditions = "terms_conditions/" + this.translator.getUserLanguage() + "/terms-and-conditions.html";
		$("#termsAndConditions a").attr("href", urlTermsConditions);
	};

	Prepare.prototype.linkAskForHelp = function() {
		var userLanguage = this.translator.getUserLanguage();
		if (userLanguage.localeCompare("en") != 0 && userLanguage.localeCompare("es") != 0) {
			userLanguage = "en";
		}
		var urlHelp = "https://support.open365.io/index.php/" + userLanguage + "/forum";
		$("#forgotPassHelpText a").attr("href", urlHelp);
	};

	Prepare.prototype.showForgotForm = function() {
		this.hideErrorMessage();
		this.hideSuccessMessage();
		this.hideLoginForm();
		this.hideRecoverForm();
		$("#forgotform").removeClass("hidden");
	};

	Prepare.prototype.showRecoverForm = function() {
		this.hideErrorMessage();
		this.hideSuccessMessage();
		this.hideLoginForm();
		this.hideForgotForm();
		$("#recoverform").removeClass("hidden");
	};

	Prepare.prototype.showErrorMessage = function() {
		$("#errorMessage").removeClass('hidden');
	};

	Prepare.prototype.showSuccessMessage = function() {
		$("#successMessage").removeClass('hidden');
	};

	Prepare.prototype.hideForgotForm = function() {
		$("#forgotform").addClass("hidden");
	};

	Prepare.prototype.hideRecoverForm = function() {
		$("#recoverform").addClass("hidden");
	};

	Prepare.prototype.hideLoginForm = function() {
		$("#loginform").addClass("hidden");
	};

	Prepare.prototype.hideErrorMessage = function() {
		$("#errorMessage").addClass('hidden');
	};

	Prepare.prototype.hideSuccessMessage = function() {
		$("#successMessage").addClass('hidden');
	};

	Prepare.prototype.prepareRecoverFormFocus = function() {
		$("#newPassword").focus();
	};

	Prepare.prototype.prepareLoginFormFocus = function () {
		// focus on username when the page is loaded.
		$("#username").focus();
	};

	Prepare.prototype.prepareKeyPress = function () {
		var self = this;
		// focus on username/password when login button lost its focus
		$('#loginButtonBox').blur();
        var input = 'username';
        if (self.hasCaptcha()) {
            input = 'password';
        }
        $("#" +input).focus();
	};

	Prepare.prototype.shakeBox = function () {
		//third party
		function bounce(pos) {
			pos += 1.941626;
			if (pos > 2.170804) {
				return 0;
			}
			return Math.sin(10 * pos * pos) / (pos);
		}

		emile(document.getElementById('loginGeneralContainer'), 'margin-left: 100px', {duration: 1000, easing: bounce});
	};

	Prepare.prototype.prepareCaptcha = function (url, callback) {
		if (!this.hasCaptcha()) {
			$('#captchaBox').show();
			this.prepareRefreshButton(callback);
			$("#captchaText").prop('required', true);
		}
		this.setCaptchaImage(url);
	};

	Prepare.prototype.prepareUsernameInput = function () {
		var self = this;
		$("#username").change(function () {
			if (self.hasCaptcha()) {
				$("#captchaText").prop('required', false);
				$('#captchaBox').hide();
				$("#errorMessage").html("");
				self.hideErrorMessage();
			}
		});
	};

	Prepare.prototype.hasCaptcha = function () {
		return $('#captchaBox').is(":visible");
	};

	Prepare.prototype.setCaptchaImage = function (url) {
		$('#captchaImage').attr("src", url);
	};

	Prepare.prototype.prepareErrorMessage = function (message) {
		$("#errorMessage").html(this.translator.messageTranslation(message));
		if(message.length > 0){
			this.showErrorMessage();
			this.hideSuccessMessage();
		}else{
			this.hideErrorMessage();
		}
	};

	Prepare.prototype.prepareSuccessMessage = function (message) {
		$("#successMessage").html(this.translator.messageTranslation(message));
		if(message.length > 0){
			this.showSuccessMessage();
			this.hideErrorMessage();
		}else{
			this.hideSuccessMessage();
		}
	};

	Prepare.prototype.prepareCaptchaErrorMessage = function (message) {
		$("#errorCaptchaMessage").html(this.translator.messageTranslation(message));
		if(message.length > 0){
			$("#errorCaptchaMessage").removeClass('hidden');
		}else{
{'fraction_non_alphanumeric': 0.16404514351728428, 'fraction_numerical': 0.007642406469385942, 'mean_word_length': 4.532940019665683, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '761327', 'n_tokens_mistral': 3676, 'n_tokens_neox': 3356, 'n_words': 688}