![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/libs/absol-form/js/components/ |
Upload File : |
import FCore, {$} from "../core/FCore"; import ScalableComponent from "../core/ScalableComponent"; import inheritComponentClass from "../core/inheritComponentClass"; import '../../css/imagefileinput.css'; import {openFileDialog} from "absol-acomp/js/utils"; import {AssemblerInstance} from "../core/Assembler"; import FileInputBox from "absol-acomp/js/FileInputBox"; var _ = FCore._; /*** * @extends ScalableComponent * @constructor */ function FileInput() { ScalableComponent.call(this); } inheritComponentClass(FileInput, ScalableComponent); FileInput.prototype.tag = "FileInput"; FileInput.prototype.menuIcon = "span.mdi.mdi-file-plus"; FileInput.prototype.attributes.allowUpload = true; FileInput.prototype.attributes.removable = true; FileInput.prototype.attributes.downloadable = true; FileInput.prototype.render = function () { return _({tag: FileInputBox.tag}); }; FileInput.prototype.attributeHandlers.value = { set: function (value) { var prev = this.domElt.value; this.domElt.value = value; if (prev !== this.domElt.value) { this.pinFire('value'); } }, get: function () { return this.domElt.value; }, descriptor: { type: "FileSource", sign: 'FileSource' }, export: function () { return this.value || undefined; } }; FileInput.prototype.attributeHandlers.fileName = { set: function (value) { value = value || null; this.domElt.fileName = value; }, get: function () { return this.domElt.fileName; }, descriptor: { type: 'text' }, export: function () { } } FileInput.prototype.pinHandlers.value = { get: function () { return this.attributes.value; }, descriptor: { type: "FileSource" } }; FileInput.prototype.attributeHandlers.allowUpload = { set: function (value) { this.domElt.allowUpload = value; }, get: function () { return this.domElt.allowUpload; }, descriptor: { type: 'bool' }, export: function () { return this.domElt.allowUpload ? undefined : false } }; FileInput.prototype.attributeHandlers.removable = { set: function (value) { this.domElt.removable = value; }, get: function () { return this.domElt.removable; }, descriptor: { type: 'bool' }, export: function () { return this.domElt.removable ? undefined : false } }; FileInput.prototype.attributeHandlers.downloadable = { set: function (value) { this.domElt.downloadable = value; }, get: function () { return this.domElt.downloadable; }, descriptor: { type: 'bool' }, export: function () { return this.domElt.downloadable ? undefined : false } }; FileInput.prototype.attributeHandlers.accept = { set: function (value) { this.domElt.accept = value; }, get: function () { return this.domElt.accept; }, descriptor: { type: 'text' }, export: function () { return this.domElt.accept || undefined; } }; FileInput.prototype.onCreated = function () { ScalableComponent.prototype.onCreated.call(this); this.domElt.on('change', function () { this.pinFire('value'); }.bind(this)); this.domElt.$input.on('click', function (event) { event.preventDefault(); this.openFileDialog(); }.bind(this)); }; FileInput.prototype.openFileDialog = function () { if (window.contentModule && window.contentModule.chooseFile) { window.contentModule.chooseFile({accept: this.attributes.accept}).then(function (result) { if (result) { this.attributes.value = result; } }.bind(this)); } else { openFileDialog({accept: this.attributes.accept}).then(function (files) { if (files && files.length > 0) { this.attributes.value = files[0]; } }.bind(this)); } }; FileInput.prototype.createDataBindingDescriptor = function () { var thisC = this; return { configurable: true, set: function (value) { thisC.attributes.value = value; }, get: function () { return thisC.attributes.value; } } }; AssemblerInstance.addClass(FileInput); export default FileInput;