403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/stepprocessing/src/fields/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/stepprocessing/src/fields/checkbox-field.js
// @flow

import {Type, Tag} from 'main.core';
import type { OptionsField } from '../process-types';
import { BaseField } from './base-field';
import { DialogStyle } from '../dialog';

export class CheckboxField extends BaseField
{
	type: string = 'checkbox';
	list: Array = [];
	multiple: boolean = false;
	className: string = DialogStyle.ProcessOptionCheckbox;

	constructor(options: OptionsField)
	{
		super(options);

		if ('list' in options)
		{
			this.list = options.list;
		}
		this.multiple = (this.list.length > 1);
		if (this.multiple)
		{
			this.class = DialogStyle.ProcessOptionMultiple;
		}
	}

	setValue(value: any)
	{
		if (this.multiple)
		{
			this.value = Type.isArray(value) ? value : [value];
		}
		else
		{
			if (value === 'Y' || value === 'N' || value === null || value === undefined)
			{
				value = (value === 'Y');//Boolean
			}
			this.value = value;
		}
		if (this.field)
		{
			if (this.multiple)
			{
				const optionElements = this.field.querySelectorAll("input[type=checkbox]");
				if (optionElements)
				{
					for (let k = 0; k < optionElements.length; k++)
					{
						optionElements[k].checked = (this.value.indexOf(optionElements[k].value) !== -1);
					}
				}
			}
			else
			{
				const optionElement = this.field.querySelector("input[type=checkbox]");
				if (optionElement)
				{
					optionElement.checked =
						Type.isBoolean(this.value) ? this.value : (optionElement.value === this.value);
				}
			}
		}
		return this;
	}
	getValue(): any
	{
		if (this.field && this.disabled !== true)
		{
			if (this.multiple)
			{
				this.value = [];
				const optionElements = this.field.querySelectorAll("input[type=checkbox]");
				if (optionElements)
				{
					for (let k = 0; k < optionElements.length; k++)
					{
						if (optionElements[k].checked)
						{
							this.value.push(optionElements[k].value);
						}
					}
				}
			}
			else
			{
				const optionElement = this.field.querySelector("input[type=checkbox]");
				if (optionElement)
				{
					if (optionElement.value && optionElement.value !== 'Y')
					{
						this.value = optionElement.checked ? optionElement.value : '';
					}
					else
					{
						this.value = optionElement.checked;
					}
				}
			}
		}
		return this.value;
	}

	isFilled(): boolean
	{
		if (this.field)
		{
			const optionElements = this.field.querySelectorAll("input[type=checkbox]");
			if (optionElements)
			{
				return true;
			}
		}
		return false;
	}

	getInput(): ?HTMLElement | ?HTMLElement[]
	{
		if (this.field)
		{
			if (this.multiple)
			{
				const optionElements = this.field.querySelectorAll("input[type=checkbox]");
				if (optionElements)
				{
					return optionElements;
				}
			}
			else
			{
				const optionElement = this.field.querySelector("input[type=checkbox]");
				if (optionElement)
				{
					return optionElement;
				}
			}
		}
		return null;
	}

	render(): HTMLElement
	{
		if (!this.field)
		{
			this.field = Tag.render`<div id="${this.id}"></div>`;
		}
		if (this.multiple)
		{
			Object.keys(this.list).forEach(itemId => {
				if (this.value.indexOf(itemId) !== -1)
				{
					this.field.appendChild(Tag.render`<label><input type="checkbox" name="${this.name}[]" value="${itemId}" checked>${this.list[itemId]}</label>`);
				}
				else
				{
					this.field.appendChild(Tag.render`<label><input type="checkbox" name="${this.name}[]" value="${itemId}">${this.list[itemId]}</label>`);
				}
			});
		}
		else
		{
			if (Type.isBoolean(this.value))
			{
				if (this.value)
				{
					this.field.appendChild(Tag.render`<input type="checkbox" id="${this.id}_inp" name="${this.name}" value="Y" checked>`);
				}
				else
				{
					this.field.appendChild(Tag.render`<input type="checkbox" id="${this.id}_inp" name="${this.name}" value="Y">`);
				}
			}
			else
			{
				if (this.value !== '')
				{
					this.field.appendChild(Tag.render`<input type="checkbox" id="${this.id}_inp" name="${this.name}" value="${this.value}" checked>`);
				}
				else
				{
					this.field.appendChild(Tag.render`<input type="checkbox" id="${this.id}_inp" name="${this.name}" value="${this.value}>"`);
				}
			}
		}

		return this.field;
	}

	lock(flag: boolean = true)
	{
		this.disabled = flag;
		if (this.field)
		{
			const optionElements = this.field.querySelectorAll("input[type=checkbox]");
			if (optionElements)
			{
				for (let k = 0; k < optionElements.length; k++)
				{
					optionElements[k].disabled = !!flag;
				}
			}
		}
		return this;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit