Your IP : 13.59.156.144


Current Path : /var/www/axolotl/data/www/arhangelsk.axolotls.ru/a537b/
Upload File :
Current File : /var/www/axolotl/data/www/arhangelsk.axolotls.ru/a537b/toolbar.tar

manager.php000066400000001576150044645540006711 0ustar00<?php

namespace Bitrix\UI\Toolbar;

use Bitrix\Main\ArgumentException;

final class Manager
{
	/** @var  Manager */
	private static $instance;
	/** @var Toolbar[] */
	protected $toolbars = [];

	private function __construct()
	{}

	private function __clone()
	{}

	/**
	 * Returns Singleton of Manager
	 * @return Manager
	 */
	public static function getInstance()
	{
		if (!isset(self::$instance))
		{
			self::$instance = new Manager;
		}

		return self::$instance;
	}

	/**
	 * @param $id
	 *
	 * @return Toolbar|null
	 */
	public function getToolbarById($id)
	{
		if (isset($this->toolbars[$id]))
		{
			return $this->toolbars[$id];
		}

		return null;
	}

	public function createToolbar($id, $options)
	{
		if (empty($id))
		{
			throw new ArgumentException("id is required", 'id');
		}

		$toolbar = new Toolbar($id, $options);
		$this->toolbars[$id] = $toolbar;

		return $toolbar;
	}
}toolbar.php000066400000010731150044645540006732 0ustar00<?

namespace Bitrix\UI\Toolbar;

use Bitrix\Main\ArgumentTypeException;
use Bitrix\UI\Buttons\BaseButton;
use Bitrix\UI\Buttons\Button;

class Toolbar
{
	private $id;
	private $filter;
	private $titleMinWidth;
	private $titleMaxWidth;
	private $favoriteStar = true;

	/**
	 * @param Button[] $buttons
	 */
	private $afterTitleButtons = [];
	/**
	 * @param Button[] $buttons
	 */
	private $buttons = [];
	private $filterButtons = [];
	private $options;

	/**
	 * Toolbar constructor.
	 *
	 * @param string $id
	 * @param array $options
	 */
	public function __construct($id, $options)
	{
		$this->id = $id;
		$this->options = $options;

		if (isset($this->options['filter']))
		{
			$this->addFilter($this->options['filter']);
		}
	}

	/**
	 * @return string
	 */
	public function getId()
	{
		return $this->id;
	}

	/**
	 * @param array|Button $button
	 * @param string $location
	 * @see ButtonLocation
	 *
	 * @throws ArgumentTypeException
	 */
	public function addButton($button, $location = ButtonLocation::RIGHT)
	{
		if (is_array($button))
		{
			$button = new Button($button);
		}

		if (!($button instanceof Button))
		{
			throw new ArgumentTypeException("button", Button::class);
		}

		if ($location === ButtonLocation::AFTER_FILTER)
		{
			$this->filterButtons[] = $button;
		}
		elseif($location === ButtonLocation::AFTER_TITLE)
		{
			$this->afterTitleButtons[] = $button;
		}
		else
		{
			$this->buttons[] = $button;
		}
	}

	public function deleteButtons(\Closure $closure)
	{
		foreach ($this->buttons as $i => $button)
		{
			if ($closure($button, ButtonLocation::RIGHT) === true)
			{
				unset($this->buttons[$i]);
			}
		}

		foreach ($this->filterButtons as $i => $button)
		{
			if ($closure($button, ButtonLocation::AFTER_FILTER) === true)
			{
				unset($this->filterButtons[$i]);
			}
		}
	}

	public function shuffleButtons(\Closure $closure, $buttonLocation)
	{
		$buttonList = null;
		switch ($buttonLocation)
		{
			case ButtonLocation::RIGHT:
				$buttonList = $this->buttons;
				break;
			case ButtonLocation::AFTER_FILTER:
				$buttonList = $this->filterButtons;
				break;
		}

		if ($buttonList)
		{
			$buttonList = $closure($buttonList);
			if (!is_array($buttonList))
			{
				throw new ArgumentTypeException('buttonList', 'array');
			}

			switch ($buttonLocation)
			{
				case ButtonLocation::RIGHT:
					$this->buttons = $buttonList;
					break;
				case ButtonLocation::AFTER_FILTER:
					$this->filterButtons = $buttonList;
					break;
			}
		}
	}

	public function hasFavoriteStar()
	{
		return (bool)$this->favoriteStar;
	}

	public function addFavoriteStar()
	{
		$this->favoriteStar = true;

		return $this;
	}

	public function deleteFavoriteStar()
	{
		$this->favoriteStar = false;

		return $this;
	}

	public function addFilter(array $filterOptions = [])
	{
		ob_start();
		$GLOBALS['APPLICATION']->includeComponent('bitrix:main.ui.filter', '', $filterOptions);
		$this->filter = ob_get_clean();
	}

	public function getFilter()
	{
		return $this->filter;
	}

	/**
	 * @return BaseButton[]
	 */
	public function getButtons()
	{
		return array_merge($this->afterTitleButtons, $this->filterButtons, $this->buttons);
	}

	public function renderAfterTitleButtons()
	{
		return implode(array_map(function(Button $button) {
			return self::processButtonRender($button);
		}, $this->afterTitleButtons));
	}

	public function renderRightButtons()
	{
		return implode(array_map(function(Button $button) {
			return self::processButtonRender($button);
		}, $this->buttons));
	}

	public function renderAfterFilterButtons()
	{
		return implode(array_map(function(Button $button) {
			return self::processButtonRender($button);
		}, $this->filterButtons));
	}

	/**
	 * @deprecated
	 * @return string
	 */
	public function renderFilterRightButtons()
	{
		return $this->renderAfterFilterButtons();
	}

	protected function processButtonRender(Button $button)
	{
		$shouldAddThemeModifier = (bool)array_intersect($button->getClassList(), [
			'ui-btn-light-border',
			'ui-btn-light',
			'ui-btn-link',
		]);

		if ($shouldAddThemeModifier)
		{
			$button->addClass('ui-btn-themes');
		}

		return $button->render(false);
	}

	public function setTitleMinWidth($width)
	{
		if (is_int($width) && $width > 0)
		{
			$this->titleMinWidth = $width;
		}
	}

	public function getTitleMinWidth()
	{
		return $this->titleMinWidth;
	}

	public function setTitleMaxWidth($width)
	{
		if (is_int($width) && $width > 0)
		{
			$this->titleMaxWidth = $width;
		}
	}

	public function getTitleMaxWidth()
	{
		return $this->titleMaxWidth;
	}
}buttonlocation.php000066400000000354150044645540010334 0ustar00<?

namespace Bitrix\UI\Toolbar;

abstract class ButtonLocation
{
	const AFTER_TITLE  = "after_title";
	const RIGHT        = "right";
	const AFTER_FILTER = "after_filter";
	/** @deprecated  */
	const FILTER_RIGHT = self::AFTER_FILTER;
}facade/toolbar.php000066400000004353150044645540010140 0ustar00<?php

namespace Bitrix\UI\Toolbar\Facade;

use Bitrix\UI\Toolbar\ButtonLocation;
use Bitrix\UI\Toolbar\Manager;

/**
 * Class Toolbar
 * @package Bitrix\UI\Toolbar\Facade
 * @method static addButton($button, $location = ButtonLocation::RIGHT);
 * @see \Bitrix\UI\Toolbar\Toolbar::addButton
 * @method static addFilter($options = []);
 * @see \Bitrix\UI\Toolbar\Toolbar::addFilter
 * @method static hasFavoriteStar();
 * @see \Bitrix\UI\Toolbar\Toolbar::hasFavoriteStar
 * @method static addFavoriteStar();
 * @see \Bitrix\UI\Toolbar\Toolbar::addFavoriteStar
 * @method static deleteFavoriteStar();
 * @see \Bitrix\UI\Toolbar\Toolbar::deleteFavoriteStar
 * @method static getId();
 * @see \Bitrix\UI\Toolbar\Toolbar::getId
 * @method static getFilter();
 * @see \Bitrix\UI\Toolbar\Toolbar::getFilter
 * @method static renderAfterTitleButtons();
 * @see \Bitrix\UI\Toolbar\Toolbar::renderAfterTitleButtons
 * @method static renderRightButtons();
 * @see \Bitrix\UI\Toolbar\Toolbar::renderRightButtons
 * @method static renderAfterFilterButtons();
 * @see \Bitrix\UI\Toolbar\Toolbar::renderAfterFilterButtons
 * @method static renderFilterRightButtons();
 * @see \Bitrix\UI\Toolbar\Toolbar::renderFilterRightButtons
 * @method static setTitleMinWidth($width);
 * @see \Bitrix\UI\Toolbar\Toolbar::setTitleMinWidth
 * @method static getTitleMinWidth();
 * @see \Bitrix\UI\Toolbar\Toolbar::getTitleMinWidth
 * @method static setTitleMaxWidth($width);
 * @see \Bitrix\UI\Toolbar\Toolbar::setTitleMaxWidth
 * @method static getTitleMaxWidth();
 * @see \Bitrix\UI\Toolbar\Toolbar::getTitleMaxWidth
 * @method static deleteButtons(\Closure $closure)
 * @see \Bitrix\UI\Toolbar\Toolbar::deleteButtons
 * @method static shuffleButtons(\Closure $closure, $buttonLocation)
 * @see \Bitrix\UI\Toolbar\Toolbar::shuffleButtons
 * @method static getButtons()
 * @see \Bitrix\UI\Toolbar\Toolbar::getButtons
 */
final class Toolbar
{
	const DEFAULT_ID = 'default-toolbar';

	public static function __callStatic($name, $arguments)
	{
		$manager = Manager::getInstance();
		$toolbar = $manager->getToolbarById(self::DEFAULT_ID)?: $manager->createToolbar(self::DEFAULT_ID, []);
		if (!$toolbar)
		{
			//or exception?
			return null;
		}

		return call_user_func_array([$toolbar, $name], $arguments);
	}
}