{"size": 3087, "ext": "js", "max_stars_repo_path": "bitrix/modules/landing/install/js/landing/error_manager.js", "max_stars_repo_name": "BuildingBridge/biznet", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bitrix/modules/landing/install/js/landing/error_manager.js", "max_issues_repo_name": "BuildingBridge/biznet", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bitrix/modules/landing/install/js/landing/error_manager.js", "max_forks_repo_name": "BuildingBridge/biznet", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.9708737864, "max_line_length": 90, "alphanum_fraction": 0.7116942015}
;(function() {
	"use strict";

	BX.namespace("BX.Landing");

	var clone = BX.Landing.Utils.clone;

	var availableActions = {
		"Landing::addBlock": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__ADD_BLOCK"),
		"Landing::deleteBlock": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__DELETE_BLOCK"),
		"Landing::upBlock": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__SAVE_CHANGES"),
		"Landing::downBlock": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__SAVE_CHANGES"),
		"Landing::showBlock": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__SAVE_CHANGES"),
		"Landing::hideBlock": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__SAVE_CHANGES"),
		"Block::cloneCard": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__CLONE_CARD"),
		"Block::removeCard": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__DELETE_CARD"),
		"Block::updateStyles": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__SAVE_CHANGES"),
		"Block::updateNodes": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__SAVE_CHANGES"),
		"Site::getList": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__SITE_GET_LIST"),
		"Block::getList": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__BLOCK_GET_LIST"),
		"Utils::uploadFile": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__UPLOAD_FILE"),
		"UNKNOWN_ACTION": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__UNKNOWN_ACTION"),
		"BAD_IMAGE": BX.Landing.Loc.getMessage("LANDING_ACTION_ERROR__BAD_IMAGE")
	};


	/**
	 * Implements interface wor works with error manager.
	 * Implements singleton design pattern. !! Don't use it as constructor
	 * use BX.Landing.ErrorManager.getInstance() for gets instance of this module
	 * @constructor
	 */
	BX.Landing.ErrorManager = function()
	{
		this.stack = [];
		this.showTimeout = null;
	};


	/**
	 * Gets manager instance
	 * @return {BX.Landing.ErrorManager}
	 */
	BX.Landing.ErrorManager.getInstance = function()
	{
		if (!top.BX.Landing.ErrorManager.instance)
		{
			top.BX.Landing.ErrorManager.instance = new BX.Landing.ErrorManager();
		}

		return top.BX.Landing.ErrorManager.instance;
	};


	BX.Landing.ErrorManager.prototype = {
		/**
		 * Adds error to collection
		 * @param error
		 * @return {*}
		 */
		add: function(error)
		{
			if (error.type === "error")
			{
				error.action = error.action in availableActions ? error.action : "UNKNOWN_ACTION";

				this.stack.push({
					action: error.action,
					description: availableActions[error.action]
				});

				return this.show();
			}
		},


		/**
		 * Shows all errors from collection
		 */
		show: function()
		{
			clearTimeout(this.showTimeout);

			this.showTimeout = setTimeout(function() {
				var stack = clone(this.stack);
				this.stack = [];
				var text = stack.map(this.createErrorMessage, this).join("");
				BX.Landing.UI.Panel.Alert.getInstance().show("error", text);
			}.bind(this), 100);
		},


		/**
		 * Creates error item html
		 * @param {{descriptions: string}} error
		 * @return {string}
		 */
		createErrorMessage: function(error)
		{
			return "<div class=\"landing-ui-error-item\">"+error.description+"</div>"
		}
	};
})();