![]() 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-full/dist/js/ |
Upload File : |
/*** module: node_modules/absol-acomp/js/FileInputBox.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; require("../css/fileinputbox.css"); var _ACore = _interopRequireWildcard(require("../ACore")); var _DropZone = _interopRequireDefault(require("./DropZone")); var _utils = require("./utils"); var _catalog = _interopRequireDefault(require("../assets/exticons/catalog.json")); var _FileSaver = require("absol/src/Network/FileSaver"); var _MessageInput = _interopRequireDefault(require("./messageinput/MessageInput")); /*** * @extends AElement * @constructor */ function FileInputBox() { this.$fileSize = (0, _ACore.$)('.as-file-input-box-file-size', this); this.$fileName = (0, _ACore.$)('.as-file-input-box-file-name', this); this.$bg = (0, _ACore.$)('.as-file-input-box-background', this); this.$input = (0, _ACore.$)('input', this).on('change', this.eventHandler.input_fileChange); this.$trigger = (0, _ACore._)({ elt: (0, _ACore.$)('.as-file-input-box-trigger', this), tag: _DropZone.default.tag, on: { fileenter: this.eventHandler.input_fileEnter, fileleave: this.eventHandler.input_fileLeave, filedrop: this.eventHandler.input_fileDrop } }); this.$downloadBtn = (0, _ACore.$)('.as-file-input-box-download-btn', this).on('click', this.download.bind(this)); this.$removeBtn = (0, _ACore.$)('.as-file-input-box-remove-btn', this).on('click', this.clearValue.bind(this, true)); this._value = null; this._fileSize = null; this._fileName = null; this._fileType = null; this._valueInfo = null; this._thumbnail = null; /*** * default true * @name allowUpload * @type {boolean} * @memberOf FileInputBox# */ this.allowUpload = true; /*** * @name value * @type {null|any} * @memberOf FileInputBox# */ /*** * @name thumbnail * @type {null|any} * @memberOf FileInputBox# */ /*** * @name fileSize * @type {null|number} * @memberOf FileInputBox# */ /*** * @name fileType * @type {null|string} * @memberOf FileInputBox# */ /*** * @name fileName * @type {null|string} * @memberOf FileInputBox# */ /*** * default: false * @name downloadable * @type {boolean} * @memberOf FileInputBox# */ } FileInputBox.tag = 'FileInputBox'.toLowerCase(); FileInputBox.render = function () { return (0, _ACore._)({ extendEvent: ['change'], class: 'as-file-input-box', child: ['.as-file-input-box-background', { tag: 'label', class: 'as-file-input-box-trigger', child: { tag: 'input', attr: { type: 'file', accept: '*', title: null } } }, { class: 'as-file-input-box-upload-overlay', child: 'span.mdi.mdi-upload' }, { class: 'as-file-input-box-info', child: [{ tag: 'span', class: 'as-file-input-box-file-name', child: { text: '' } }, 'br', { tag: 'span', class: 'as-file-input-box-file-size', child: { text: '' } }] }, { class: 'as-file-input-box-action-left', child: { tag: 'button', class: 'as-file-input-box-remove-btn', child: 'span.mdi.mdi-close' } }, { class: 'as-file-input-box-action-right', child: { tag: 'button', class: 'as-file-input-box-download-btn', child: 'span.mdi.mdi-download' } }, { class: 'as-file-input-box-checked', child: 'span.mdi.mdi-check-bold' }] }); }; FileInputBox.prototype.download = function () { var value = this.value; if (value) { if (value && value.name && value.url) { (0, _FileSaver.saveAs)(value.url, value.name); } else { (0, _FileSaver.saveAs)(value, this.fileName); } } }; FileInputBox.prototype.clearValue = function (userAction, event) { if (this.value) { this.value = null; if (userAction) { this.emit('change', { type: 'change', originalEvent: event, action: 'clear', target: this }, this); } } }; FileInputBox.prototype._updateThumbnail = function () { var previewUrl; var thumbnail = this.thumbnail; var fileType = this.fileType; if (thumbnail) { if (typeof thumbnail === "string") { previewUrl = thumbnail; } else if (thumbnail instanceof Blob || thumbnail instanceof File) { thumbnail.url = thumbnail.url || URL.createObjectURL(thumbnail); previewUrl = thumbnail.url; } } if (!previewUrl) { if (_catalog.default.indexOf(fileType) >= 0) { previewUrl = _MessageInput.default.iconAssetRoot + '/' + fileType + '.svg'; } else { previewUrl = _MessageInput.default.iconAssetRoot + '/' + 'blank' + '.svg'; } } if (previewUrl) { this.$bg.addStyle('backgroundImage', 'url("' + encodeURI(previewUrl) + '")'); } else { this.$bg.removeStyle('backgroundImage'); } }; FileInputBox.prototype._updateFileName = function () { var fileName = this.fileName; if (fileName) { this.$fileName.firstChild.data = fileName; this.addClass('as-has-file-name'); } else { this.$fileName.firstChild.data = ''; this.removeClass('as-has-file-name'); } }; FileInputBox.prototype._updateFileSize = function () { var fileSize = this.fileName; if (fileSize === null) { this.$fileSize.firstChild.data = ''; this.removeClass('as-has-file-size'); } else { this.$fileSize.firstChild.data = (0, _utils.fileSize2Text)(fileSize); this.addClass('as-has-file-size'); } }; FileInputBox.property = {}; FileInputBox.property.value = { set: function (value) { value = value || null; this._value = value; this._valueInfo = (0, _utils.fileInfoOf)(value); this._updateThumbnail(); this._updateFileName(); this._updateFileSize(); if (value) { this.addClass('as-has-value'); } else { this.removeClass('as-has-value'); } }, get: function () { return this._value; } }; FileInputBox.property.fileType = { set: function (value) { this._fileType = value; this._updateThumbnail(); }, /*** * @this FileInputBox * @return {*} */ get: function () { return this._fileType || this._valueInfo && this._valueInfo.type || null; } }; FileInputBox.property.fileName = { set: function (value) { value = typeof value === 'string' ? value : null; this._fileName = value; this._updateFileName(); }, get: function () { return this._fileName || this._valueInfo && this._valueInfo.name || null; } }; FileInputBox.property.fileSize = { set: function (value) { if ((0, _utils.isRealNumber)(value)) value = Math.max(0, value);else value = null; this._fileSize = value; this._updateFileSize(); }, get: function () { if (typeof this._fileSize === "number") return this._fileSize; if (this._valueInfo && typeof this._valueInfo.size === "number") return this._valueInfo.size; return null; } }; FileInputBox.property.thumbnail = { set: function (value) { this._thumbnail = value || null; this._updateThumbnail(); }, get: function () { return this._thumbnail; } }; FileInputBox.property.allowUpload = { set: function (value) { if (value) { this.addClass('as-allow-upload'); } else { this.removeClass('as-allow-upload'); } }, get: function () { return this.hasClass('as-allow-upload'); } }; FileInputBox.property.downloadable = { set: function (value) { if (value) { this.addClass('as-downloadable'); } else { this.removeClass('as-downloadable'); } }, get: function () { return this.hasClass('as-downloadable'); } }; FileInputBox.property.removable = { set: function (value) { if (value) { this.addClass('as-removable'); } else { this.removeClass('as-removable'); } }, get: function () { return this.hasClass('as-removable'); } }; FileInputBox.property.accept = { set: function (value) { if (!value) value = null; this.$input.attr('accept', value + ''); }, get: function () { return this.$input.attr('accept') || null; } }; FileInputBox.property.checked = { set: function (value) { if (value) { this.addClass('as-checked'); } else { this.removeClass('as-checked'); } }, get: function () { return this.hasClass('as-checked'); } }; FileInputBox.eventHandler = {}; FileInputBox.eventHandler.input_fileChange = function (event) { var files = Array.prototype.slice.call(this.$input.files); if (files.length > 0) { this.value = files[0]; this.emit('change', { type: 'change', originalEvent: event, file: files[0], action: 'file_dialog', target: this }, this); } }; FileInputBox.eventHandler.input_fileEnter = function (event) {}; FileInputBox.eventHandler.input_fileLeave = function (event) {}; FileInputBox.eventHandler.input_fileDrop = function (event) { var files = Array.prototype.slice.call(event.files); var accept = this.accept; var file; if (files.length > 0) { file = files[0]; if (!(0, _utils.fileAccept)(accept, file.type) && !(0, _utils.fileAccept)(accept, file.name)) file = null; } if (file) { this.value = file; this.emit('change', { type: 'change', originalEvent: event, file: file, action: 'drop', target: this }, this); } }; _ACore.default.install(FileInputBox); var _default = FileInputBox; exports.default = _default;