UNPKG

@syncfusion/ej2-filemanager

Version:
1,474 lines (1,463 loc) 528 kB
import { Property, ChildProperty, initializeCSPTemplate, getValue, isNullOrUndefined, matches, select, closest, createElement, setValue, detach, extend, Ajax, Fetch, remove, Internationalization, selectAll, Draggable, KeyboardEvents, EventHandler, Touch, addClass, removeClass, isVisible, getUniqueID, setStyleAttribute, formatUnit, Browser, L10n, Complex, Collection, Event, NotifyPropertyChanges, Component, SanitizeHtmlHelper } from '@syncfusion/ej2-base'; import { Splitter } from '@syncfusion/ej2-layouts'; import { Dialog, showSpinner, hideSpinner, createSpinner } from '@syncfusion/ej2-popups'; import { DataManager, Query, DataUtil } from '@syncfusion/ej2-data'; import { getUid, Grid, Resize, ContextMenu as ContextMenu$2, Sort, VirtualScroll } from '@syncfusion/ej2-grids'; import { Input, TextBox, Uploader } from '@syncfusion/ej2-inputs'; import { CheckBox, createCheckBox } from '@syncfusion/ej2-buttons'; import { ListBase } from '@syncfusion/ej2-lists'; import { DropDownButton } from '@syncfusion/ej2-splitbuttons'; import { ContextMenu as ContextMenu$1, Toolbar as Toolbar$1, TreeView } from '@syncfusion/ej2-navigations'; var __extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Specifies the Ajax settings of the File Manager. */ var AjaxSettings = /** @__PURE__ @class */ (function (_super) { __extends(AjaxSettings, _super); function AjaxSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate([ Property(null) ], AjaxSettings.prototype, "downloadUrl", void 0); __decorate([ Property(null) ], AjaxSettings.prototype, "getImageUrl", void 0); __decorate([ Property(null) ], AjaxSettings.prototype, "uploadUrl", void 0); __decorate([ Property(null) ], AjaxSettings.prototype, "url", void 0); return AjaxSettings; }(ChildProperty)); var __extends$1 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var defaultToolbarItems = ['NewFolder', 'Upload', 'Cut', 'Copy', 'Paste', 'Delete', 'Download', 'Rename', 'SortBy', 'Refresh', 'Selection', 'View', 'Details']; /** * Specifies the Toolbar settings of the FileManager. */ var ToolbarSettings = /** @__PURE__ @class */ (function (_super) { __extends$1(ToolbarSettings, _super); function ToolbarSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$1([ Property(defaultToolbarItems) ], ToolbarSettings.prototype, "items", void 0); __decorate$1([ Property(true) ], ToolbarSettings.prototype, "visible", void 0); return ToolbarSettings; }(ChildProperty)); var ToolbarItem = /** @__PURE__ @class */ (function (_super) { __extends$1(ToolbarItem, _super); function ToolbarItem() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$1([ Property('') ], ToolbarItem.prototype, "id", void 0); __decorate$1([ Property('') ], ToolbarItem.prototype, "text", void 0); __decorate$1([ Property('auto') ], ToolbarItem.prototype, "width", void 0); __decorate$1([ Property('') ], ToolbarItem.prototype, "cssClass", void 0); __decorate$1([ Property(false) ], ToolbarItem.prototype, "showAlwaysInPopup", void 0); __decorate$1([ Property(false) ], ToolbarItem.prototype, "disabled", void 0); __decorate$1([ Property('') ], ToolbarItem.prototype, "prefixIcon", void 0); __decorate$1([ Property('') ], ToolbarItem.prototype, "suffixIcon", void 0); __decorate$1([ Property(true) ], ToolbarItem.prototype, "visible", void 0); __decorate$1([ Property('None') ], ToolbarItem.prototype, "overflow", void 0); __decorate$1([ Property('') ], ToolbarItem.prototype, "template", void 0); __decorate$1([ Property('Button') ], ToolbarItem.prototype, "type", void 0); __decorate$1([ Property('Both') ], ToolbarItem.prototype, "showTextOn", void 0); __decorate$1([ Property(null) ], ToolbarItem.prototype, "htmlAttributes", void 0); __decorate$1([ Property('') ], ToolbarItem.prototype, "tooltipText", void 0); __decorate$1([ Property('Left') ], ToolbarItem.prototype, "align", void 0); __decorate$1([ Property(-1) ], ToolbarItem.prototype, "tabIndex", void 0); __decorate$1([ Property() ], ToolbarItem.prototype, "name", void 0); return ToolbarItem; }(ChildProperty)); var __extends$2 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Specifies the Search settings of the File Manager. */ var SearchSettings = /** @__PURE__ @class */ (function (_super) { __extends$2(SearchSettings, _super); function SearchSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$2([ Property(true) ], SearchSettings.prototype, "allowSearchOnTyping", void 0); __decorate$2([ Property('contains') ], SearchSettings.prototype, "filterType", void 0); __decorate$2([ Property(true) ], SearchSettings.prototype, "ignoreCase", void 0); __decorate$2([ Property(null) ], SearchSettings.prototype, "placeholder", void 0); return SearchSettings; }(ChildProperty)); var __extends$3 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Specifies the columns in the details view of the file manager. */ var columnArray = [ { field: 'name', headerText: 'Name', minWidth: 120, template: '<span class="e-fe-text">${name}</span>', customAttributes: { class: 'e-fe-grid-name' } }, { field: '_fm_modified', headerText: 'DateModified', type: 'dateTime', format: 'MMMM dd, yyyy HH:mm', minWidth: 120, width: '190' }, { field: 'size', headerText: 'Size', minWidth: 90, width: '110', // eslint-disable-next-line @typescript-eslint/no-explicit-any template: initializeCSPTemplate(function (data) { return "<span class=\"e-fe-size\">" + data.size + "</span>"; }), format: 'n2' } ]; /** * Specifies the grid settings of the File Manager. */ var DetailsViewSettings = /** @__PURE__ @class */ (function (_super) { __extends$3(DetailsViewSettings, _super); function DetailsViewSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$3([ Property(true) ], DetailsViewSettings.prototype, "columnResizing", void 0); __decorate$3([ Property(columnArray) ], DetailsViewSettings.prototype, "columns", void 0); return DetailsViewSettings; }(ChildProperty)); var __extends$4 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var fileItems = ['Open', '|', 'Cut', 'Copy', '|', 'Delete', 'Download', 'Rename', '|', 'Details']; var folderItems = ['Open', '|', 'Cut', 'Copy', 'Paste', '|', 'Delete', 'Rename', 'Download', '|', 'Details']; var layoutItems = [ 'SortBy', 'View', 'Refresh', '|', 'Paste', '|', 'NewFolder', 'Upload', '|', 'Details', '|', 'SelectAll' ]; /** * Specifies the ContextMenu settings of the File Manager. */ var ContextMenuSettings = /** @__PURE__ @class */ (function (_super) { __extends$4(ContextMenuSettings, _super); function ContextMenuSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$4([ Property(fileItems) ], ContextMenuSettings.prototype, "file", void 0); __decorate$4([ Property(folderItems) ], ContextMenuSettings.prototype, "folder", void 0); __decorate$4([ Property(layoutItems) ], ContextMenuSettings.prototype, "layout", void 0); __decorate$4([ Property(true) ], ContextMenuSettings.prototype, "visible", void 0); return ContextMenuSettings; }(ChildProperty)); var __extends$5 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$5 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Specifies the navigationpane settings of the File Manager. */ var NavigationPaneSettings = /** @__PURE__ @class */ (function (_super) { __extends$5(NavigationPaneSettings, _super); function NavigationPaneSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$5([ Property('650px') ], NavigationPaneSettings.prototype, "maxWidth", void 0); __decorate$5([ Property('240px') ], NavigationPaneSettings.prototype, "minWidth", void 0); __decorate$5([ Property(true) ], NavigationPaneSettings.prototype, "visible", void 0); __decorate$5([ Property('None') ], NavigationPaneSettings.prototype, "sortOrder", void 0); return NavigationPaneSettings; }(ChildProperty)); var __extends$6 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$6 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Specifies the Ajax settings of the File Manager. */ var UploadSettings = /** @__PURE__ @class */ (function (_super) { __extends$6(UploadSettings, _super); function UploadSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$6([ Property('') ], UploadSettings.prototype, "allowedExtensions", void 0); __decorate$6([ Property(true) ], UploadSettings.prototype, "autoUpload", void 0); __decorate$6([ Property(false) ], UploadSettings.prototype, "autoClose", void 0); __decorate$6([ Property(false) ], UploadSettings.prototype, "directoryUpload", void 0); __decorate$6([ Property(0) ], UploadSettings.prototype, "minFileSize", void 0); __decorate$6([ Property(30000000) ], UploadSettings.prototype, "maxFileSize", void 0); __decorate$6([ Property(0) ], UploadSettings.prototype, "chunkSize", void 0); return UploadSettings; }(ChildProperty)); var __extends$7 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$7 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Interface for a class Column */ /* istanbul ignore next */ var Column = /** @__PURE__ @class */ (function (_super) { __extends$7(Column, _super); function Column() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$7([ Property('') ], Column.prototype, "field", void 0); __decorate$7([ Property('') ], Column.prototype, "headerText", void 0); __decorate$7([ Property('') ], Column.prototype, "width", void 0); __decorate$7([ Property('') ], Column.prototype, "minWidth", void 0); __decorate$7([ Property('') ], Column.prototype, "maxWidth", void 0); __decorate$7([ Property('Left') ], Column.prototype, "textAlign", void 0); __decorate$7([ Property(null) ], Column.prototype, "headerTextAlign", void 0); __decorate$7([ Property(null) ], Column.prototype, "type", void 0); __decorate$7([ Property(null) ], Column.prototype, "format", void 0); __decorate$7([ Property(null) ], Column.prototype, "template", void 0); __decorate$7([ Property(null) ], Column.prototype, "sortComparer", void 0); __decorate$7([ Property(null) ], Column.prototype, "headerTemplate", void 0); __decorate$7([ Property(true) ], Column.prototype, "allowSorting", void 0); __decorate$7([ Property(true) ], Column.prototype, "allowResizing", void 0); __decorate$7([ Property(null) ], Column.prototype, "customAttributes", void 0); __decorate$7([ Property('') ], Column.prototype, "hideAtMedia", void 0); __decorate$7([ Property(null) ], Column.prototype, "customFormat", void 0); __decorate$7([ Property(false) ], Column.prototype, "isPrimaryKey", void 0); return Column; }(ChildProperty)); /** * Specifies the File Manager internal ID's */ /** @hidden */ var TOOLBAR_ID = '_toolbar'; /** @hidden */ var LAYOUT_ID = '_layout'; /** @hidden */ var NAVIGATION_ID = '_navigation'; /** @hidden */ var TREE_ID = '_tree'; /** @hidden */ var GRID_ID = '_grid'; /** @hidden */ var LARGEICON_ID = '_largeicons'; /** @hidden */ var DIALOG_ID = '_dialog'; /** @hidden */ var ALT_DIALOG_ID = '_alt_dialog'; /** @hidden */ var IMG_DIALOG_ID = '_img_dialog'; /** @hidden */ var EXTN_DIALOG_ID = '_extn_dialog'; /** @hidden */ var UPLOAD_DIALOG_ID = '_upload_dialog'; /** @hidden */ var RETRY_DIALOG_ID = '_retry_dialog'; /** @hidden */ var CONTEXT_MENU_ID = '_contextmenu'; /** @hidden */ var SORTBY_ID = '_sortby'; /** @hidden */ var VIEW_ID = '_view'; /** @hidden */ var SPLITTER_ID = '_splitter'; /** @hidden */ var CONTENT_ID = '_content'; /** @hidden */ var BREADCRUMBBAR_ID = '_breadcrumbbar'; /** @hidden */ var UPLOAD_ID = '_upload'; /** @hidden */ var RETRY_ID = '_retry'; /** @hidden */ var SEARCH_ID = '_search'; /** * Specifies the File Manager internal class names */ /** @hidden */ var ROOT = 'e-filemanager'; /** @hidden */ var CONTROL = 'e-control'; /** @hidden */ var CHECK_SELECT = 'e-fe-cb-select'; /** @hidden */ var ROOT_POPUP = 'e-fe-popup'; /** @hidden */ var MOBILE = 'e-fe-mobile'; /** @hidden */ var MOB_POPUP = 'e-fe-popup e-fe-mobile'; /** @hidden */ var MULTI_SELECT = 'e-fe-m-select'; /** @hidden */ var FILTER = 'e-fe-m-filter'; /** @hidden */ var LAYOUT = 'e-layout'; /** @hidden */ var NAVIGATION = 'e-navigation'; /** @hidden */ var LAYOUT_CONTENT = 'e-layout-content'; /** @hidden */ var LARGE_ICONS = 'e-large-icons'; /** @hidden */ var TB_ITEM = 'e-toolbar-item'; /** @hidden */ var LIST_ITEM = 'e-list-item'; /** @hidden */ var LIST_TEXT = 'e-list-text'; /** @hidden */ var LIST_PARENT = 'e-list-parent'; /** @hidden */ var TB_OPTION_TICK = 'e-icons e-fe-tick'; /** @hidden */ var TB_OPTION_DOT = 'e-icons e-fe-dot'; /** @hidden */ var BLUR = 'e-blur'; /** @hidden */ var ACTIVE = 'e-active'; /** @hidden */ var HOVER = 'e-hover'; /** @hidden */ var FOCUS = 'e-focus'; /** @hidden */ var FOCUSED = 'e-focused'; /** @hidden */ var CHECK = 'e-check'; /** @hidden */ var FRAME = 'e-frame'; /** @hidden */ var CB_WRAP = 'e-checkbox-wrapper'; /** @hidden */ var ROW = 'e-row'; /** @hidden */ var ROWCELL = 'e-rowcell'; /** @hidden */ var EMPTY = 'e-empty'; /** @hidden */ var EMPTY_CONTENT = 'e-empty-content'; /** @hidden */ var EMPTY_INNER_CONTENT = 'e-empty-inner-content'; /** @hidden */ var CLONE = 'e-fe-clone'; /** @hidden */ var DROP_FOLDER = 'e-fe-drop-folder'; /** @hidden */ var DROP_FILE = 'e-fe-drop-file'; /** @hidden */ var FOLDER = 'e-fe-folder'; /** @hidden */ var ICON_IMAGE = 'e-fe-image'; /** @hidden */ var ICON_MUSIC = 'e-fe-music'; /** @hidden */ var ICON_VIDEO = 'e-fe-video'; /** @hidden */ var LARGE_ICON = 'e-large-icon'; /** @hidden */ var LARGE_EMPTY_FOLDER = 'e-empty-icon e-fe-folder'; /** @hidden */ var LARGE_EMPTY_FOLDER_TWO = 'e-empty-icon.e-fe-folder'; /** @hidden */ var LARGE_ICON_FOLDER = 'e-fe-folder'; /** @hidden */ var SELECTED_ITEMS = 'e-items'; /** @hidden */ var TEXT_CONTENT = 'e-text-content'; /** @hidden */ var GRID_HEADER = 'e-gridheader'; /** @hidden */ var TEMPLATE_CELL = 'e-templatecell'; /** @hidden */ var TREE_VIEW = 'e-treeview'; /** @hidden */ var MENU_ITEM = 'e-menu-item'; /** @hidden */ var MENU_ICON = 'e-menu-icon'; /** @hidden */ var SUBMENU_ICON = 'e-caret'; /** @hidden */ var GRID_VIEW = 'e-content'; /** @hidden */ var GRID_CONTENT = 'e-gridcontent'; /** @hidden */ var ICON_VIEW = 'e-list-parent'; /** @hidden */ var ICON_OPEN = 'e-icons e-fe-open'; /** @hidden */ var ICON_UPLOAD = 'e-icons e-fe-upload'; /** @hidden */ var ICON_CUT = 'e-icons e-fe-cut'; /** @hidden */ var ICON_COPY = 'e-icons e-fe-copy'; /** @hidden */ var ICON_PASTE = 'e-icons e-fe-paste'; /** @hidden */ var ICON_DELETE = 'e-icons e-fe-delete'; /** @hidden */ var ICON_RENAME = 'e-icons e-fe-rename'; /** @hidden */ var ICON_NEWFOLDER = 'e-icons e-fe-newfolder'; /** @hidden */ var ICON_DETAILS = 'e-icons e-fe-details'; /** @hidden */ var ICON_SHORTBY = 'e-icons e-fe-sort'; /** @hidden */ var ICON_REFRESH = 'e-icons e-fe-refresh'; /** @hidden */ var ICON_SELECTALL = 'e-icons e-fe-select'; /** @hidden */ var ICON_DOWNLOAD = 'e-icons e-fe-download'; /** @hidden */ var ICON_OPTIONS = 'e-icons e-fe-options'; /** @hidden */ var ICON_GRID = 'e-icons e-fe-grid'; /** @hidden */ var ICON_LARGE = 'e-icons e-fe-large'; /** @hidden */ var ICON_BREADCRUMB = 'e-icons e-fe-breadcrumb'; /** @hidden */ var ICON_CLEAR = 'e-icons e-fe-clear'; /** @hidden */ var ICON_DROP_IN = 'e-icons e-fe-drop-in'; /** @hidden */ var ICON_DROP_OUT = 'e-icons e-fe-drop-out'; /** @hidden */ var ICON_NO_DROP = 'e-icons e-fe-no-drop'; /** @hidden */ var ICONS = 'e-icons'; /** @hidden */ var DETAILS_LABEL = 'e-detailslabel'; /** @hidden */ var ERROR_CONTENT = 'e-fe-errorcontent'; /** @hidden */ var STATUS = 'e-status'; /** @hidden */ var BREADCRUMBS = 'e-address'; /** @hidden */ var RTL = 'e-rtl'; /** @hidden */ var DISPLAY_NONE = 'e-display-none'; /** @hidden */ var COLLAPSED = 'e-node-collapsed'; /** @hidden */ var FULLROW = 'e-fullrow'; /** @hidden */ var ICON_COLLAPSIBLE = 'e-icon-collapsible'; /** @hidden */ var SPLIT_BAR = 'e-split-bar'; /** @hidden */ var HEADER_CHECK = 'e-headercheck'; /** @hidden */ var OVERLAY = 'e-fe-overlay'; /** @hidden */ var VALUE = 'e-fe-value'; /** * Specifies the File Manager internal variables */ /** @hidden */ var isFile = 'isFile'; /** * Specifies the File Manager internal events */ /** @hidden */ var modelChanged = 'model-changed'; /** @hidden */ var initialEnd = 'initial-end'; /** @hidden */ var finalizeEnd = 'finalize-end'; /** @hidden */ var createEnd = 'create-end'; /** @hidden */ var filterEnd = 'filter-end'; /** @hidden */ var beforeDelete = 'before-delete'; /** @hidden */ var pathDrag = 'path-drag'; /** @hidden */ var deleteInit = 'delete-init'; /** @hidden */ var deleteEnd = 'delete-end'; /** @hidden */ var refreshEnd = 'refresh-end'; /** @hidden */ var resizeEnd = 'resize-end'; /** @hidden */ var splitterResize = 'splitter-resize'; /** @hidden */ var pathChanged = 'path-changed'; /** @hidden */ var destroy = 'destroy'; /** @hidden */ var beforeRequest = 'before-request'; /** @hidden */ var upload = 'upload'; /** @hidden */ var skipUpload = 'skip-upload'; /** @hidden */ var afterRequest = 'after-request'; /** @hidden */ var download = 'download'; /** @hidden */ var layoutRefresh = 'layout-refresh'; /** @hidden */ var actionFailure = 'actionFailure'; /** @hidden */ var search = 'search'; /** @hidden */ var openInit = 'open-init'; /** @hidden */ var openEnd = 'open-end'; /** @hidden */ var selectionChanged = 'selection-changed'; /** @hidden */ var selectAllInit = 'select-all-init'; /** @hidden */ var clearAllInit = 'clear-all-init'; /** @hidden */ var clearPathInit = 'clear-path-init'; /** @hidden */ var layoutChange = 'layout-change'; /** @hidden */ var sortByChange = 'sort-by-change'; /** @hidden */ var nodeExpand = 'node-expand'; /** @hidden */ var detailsInit = 'details-init'; /** @hidden */ var menuItemData = 'menu-item-data'; /** @hidden */ var renameInit = 'rename-init'; /** @hidden */ var renameEndParent = 'rename-end-parent'; /** @hidden */ var renameEnd = 'rename-end'; /** @hidden */ var showPaste = 'show-paste'; /** @hidden */ var hidePaste = 'hide-paste'; /** @hidden */ var selectedData = 'selected-data'; /** @hidden */ var cutCopyInit = 'cut-copy-init'; /** @hidden */ var pasteInit = 'paste-init'; /** @hidden */ var pasteEnd = 'paste-end'; /** @hidden */ var cutEnd = 'cut-end'; /** @hidden */ var hideLayout = 'hide-layout'; /** @hidden */ var updateTreeSelection = 'update-tree-selection'; /** @hidden */ var treeSelect = 'select-node'; /** @hidden */ var sortColumn = 'sort-column'; /** @hidden */ var pathColumn = 'path-column'; /** @hidden */ var searchTextChange = 'search-change'; /** @hidden */ var beforeDownload = 'before-download'; /** @hidden */ var downloadInit = 'download-init'; /** @hidden */ var dropInit = 'drop-init'; /** @hidden */ var dragEnd = 'drag-end'; /** @hidden */ var dropPath = 'drop-path'; /** @hidden */ var dragHelper = 'drag-helper'; /** @hidden */ var dragging = 'dragging'; /** @hidden */ var updateSelectionData = 'update-selection-data'; /** @hidden */ var methodCall = 'method-call'; /** @hidden */ var permissionRead = 'read'; /** @hidden */ var permissionEdit = 'write'; /** @hidden */ var permissionEditContents = 'writeContents'; /** @hidden */ var permissionCopy = 'copy'; /** @hidden */ var permissionUpload = 'upload'; /** @hidden */ var permissionDownload = 'download'; /** * Utility function to compare two strings in a way similar to Windows Explorer. * Files and folders are sorted separately, with folders coming before files. * * @param {string} reference - The first string to compare. This could be a file or folder name. * @param {string} comparer - The second string to compare. This could be a file or folder name. * @returns {number} - A negative number if `reference` should come before `comparer`, a positive number if `comparer` should come before `reference`, and 0 if they are considered equal. */ function sortComparer(reference, comparer) { // Check if reference and comparer are files or folders var referenceIsFile = /\.\S+/.test(reference); var comparerIsFile = /\.\S+/.test(comparer); // If one is a file and the other is a folder, the folder should come first if (referenceIsFile && !comparerIsFile) { return 1; } if (!referenceIsFile && comparerIsFile) { return -1; } var referenceParts = []; var comparerParts = []; (reference + '').replace(/(\d+)|(\D+)/g, function (_, $1, $2) { referenceParts.push([$1 || Infinity, $2 || '']); return ''; }); (comparer + '').replace(/(\d+)|(\D+)/g, function (_, $1, $2) { comparerParts.push([$1 || Infinity, $2 || '']); return ''; }); // Compare each part of reference and comparer while (referenceParts.length && comparerParts.length) { var referencePart = referenceParts.shift(); var comparerPart = comparerParts.shift(); if (referencePart && comparerPart) { var comparisonResult = referencePart[0] - comparerPart[0] || referencePart[1].localeCompare(comparerPart[1]); if (comparisonResult) { return comparisonResult; } } } return referenceParts.length - comparerParts.length; } /** * Utility file for common actions * * @param {HTMLLIElement} node - specifies the node. * @param {Object} data - specifies the data. * @param {IFileManager} instance - specifies the control instance. * @returns {void} * @private */ function updatePath(node, data, instance) { var text = getValue('name', data); var id = node.getAttribute('data-id'); var newText = isNullOrUndefined(id) ? text : id; instance.setProperties({ path: getPath(node, newText, instance.hasId) }, true); instance.pathId = getPathId(node); instance.pathNames = getPathNames(node, text); } /** * Functions for get path in FileManager * * @param {Element | Node} element - specifies the element. * @param {string} text - specifies the text. * @param {boolean} hasId - specifies the id. * @returns {string} returns the path. * @private */ function getPath(element, text, hasId) { var matched = getParents(element, text, false, hasId); var path = '/'; var len = matched.length - (2); for (var i = len; i >= 0; i--) { path += matched[i] + '/'; } return path; } /** * Functions for get path id in FileManager * * @param {Element} node - specifies the node element. * @returns {string[]} returns the path ids. * @private */ function getPathId(node) { var matched = getParents(node, node.getAttribute('data-uid'), true); var ids = []; for (var i = matched.length - 1; i >= 0; i--) { ids.push(matched[i]); } return ids; } /** * Functions for get path names in FileManager * * @param {Element} element - specifies the node element. * @param {string} text - specifies the text. * @returns {string[]} returns the path names. * @private */ function getPathNames(element, text) { var matched = getParents(element, text, false); var names = []; for (var i = matched.length - 1; i >= 0; i--) { names.push(matched[i]); } return names; } /** * Functions for get path id in FileManager * * @param {Element} element - specifies the node element. * @param {string} text - specifies the text. * @param {boolean} isId - specifies the id. * @param {boolean} hasId - checks the id exists. * @returns {string[]} returns parent element. * @private */ function getParents(element, text, isId, hasId) { var matched = [text]; var el = element.parentNode; while (!isNullOrUndefined(el)) { if (matches(el, '.' + LIST_ITEM)) { var parentText = isId ? el.getAttribute('data-uid') : (hasId ? el.getAttribute('data-id') : select('.' + LIST_TEXT, el).textContent); matched.push(parentText); } el = el.parentNode; if (el.classList.contains(TREE_VIEW)) { break; } } return matched; } /** * Functions for generate path * * @param {IFileManager} parent - specifies the parent element. * @returns {void} * @private */ function generatePath(parent) { var key = parent.hasId ? 'id' : 'name'; var newPath = '/'; var i = 1; for (i; i < parent.pathId.length; i++) { var data = getValue(parent.pathId[parseInt(i.toString(), 10)], parent.feParent); newPath += getValue(key, data) + '/'; } parent.setProperties({ path: newPath }, true); } /** * Functions for remove active element * * @param {IFileManager} parent - specifies the parent element. * @returns {void} * @private */ function removeActive(parent) { if (parent.isCut) { removeBlur(parent); parent.selectedNodes = []; parent.actionRecords = []; parent.enablePaste = false; parent.notify(hidePaste, {}); } } /** * Selects active element in File Manager * * @param {string} action - specifies the action. * @param {IFileManager} parent - specifies the parent element. * @returns {boolean} - returns active element. * @private */ function activeElement(action, parent) { parent.isSearchCut = false; parent.actionRecords = []; parent.activeElements = []; parent.notify(cutCopyInit, {}); if (parent.activeElements.length === 0) { return false; } removeBlur(parent); var blurEle = parent.activeElements; if (parent.activeModule !== 'navigationpane') { parent.targetPath = parent.path; } else { parent.targetPath = getParentPath(parent.path); } var i = 0; if (blurEle) { getModule(parent, blurEle[0]); if (action === 'cut') { while (i < blurEle.length) { addBlur(blurEle[i]); i++; } } } i = 0; parent.selectedNodes = []; parent.enablePaste = true; parent.notify(showPaste, {}); while (i < parent.activeRecords.length) { parent.actionRecords.push(parent.activeRecords[i]); parent.selectedNodes.push(getValue('name', parent.activeRecords[i])); i++; } if ((parent.breadcrumbbarModule.searchObj.element.value !== '' || parent.isFiltered) && parent.activeModule !== 'navigationpane') { parent.selectedNodes = []; parent.isSearchCut = true; var i_1 = 0; while (i_1 < parent.selectedItems.length) { parent.selectedNodes.push(parent.selectedItems[i_1]); i_1++; } } return true; } /** * Adds blur to the elements * * @param {Element} nodes - specifies the nodes. * @returns {void} * @private */ function addBlur(nodes) { nodes.classList.add(BLUR); } /** * Removes blur from elements * * @param {IFileManager} parent - specifies the parent element. * @param {string} hover - specifies the hover string. * @returns {void} * @private */ function removeBlur(parent, hover) { var blurEle = (!hover) ? parent.element.querySelectorAll('.' + BLUR) : parent.element.querySelectorAll('.' + HOVER); var i = 0; while (i < blurEle.length) { blurEle[i].classList.remove((!hover) ? BLUR : HOVER); i++; } } /** * Gets module name * * @param {IFileManager} parent - specifies the parent element. * @param {Element} element - specifies the element. * @returns {void} * @private */ function getModule(parent, element) { if (element) { if (element.classList.contains(ROW)) { parent.activeModule = 'detailsview'; } else if (closest(element, '.' + LARGE_ICON)) { parent.activeModule = 'largeiconsview'; } else { parent.activeModule = 'navigationpane'; } } } /** * Get all child items * * @param {IFileManager} parent - specifies the parent element. * @param {string | number} parentId - specifies the parent ID. * @returns {Object[]} An array of child items * @private */ function getAllChildItems(parent, parentId) { var children = parent.fileSystemData.filter(function (item) { return String(item.parentId) === String(parentId); }); var allChildren = children.slice(); children.forEach(function (child) { var childId = child.id; allChildren = allChildren.concat(getAllChildItems(parent, childId)); }); return allChildren; } /** * Gets module name * * @param {IFileManager} parent - specifies the parent element. * @param {string} value - specifies the value. * @param {boolean} isLayoutChange - specifies the layout change. * @returns {void} * @private */ function searchWordHandler(parent, value, isLayoutChange) { var searchWord; if (value.length === 0 && !parent.isFiltered) { parent.notify(pathColumn, { args: parent }); } if (isFileSystemData(parent)) { if (value === '') { parent.itemData = parent.fileSystemData; read(parent, isLayoutChange ? layoutChange : search, parent.path); } else { parent.searchSettings.filterType = isNullOrUndefined(parent.searchSettings.filterType) ? 'contains' : parent.searchSettings.filterType; var currData = getValue(parent.pathId[parent.pathId.length - 1], parent.feParent); var parentId = getValue('id', currData); var filteredData = getAllChildItems(parent, parentId); var data = new DataManager(filteredData). executeLocal(new Query().where('name', parent.searchSettings.filterType, value, parent.searchSettings.ignoreCase)); var searchValue = parent.searchSettings.ignoreCase ? value.toLowerCase() : value; parent.itemData = data; Search(parent, isLayoutChange ? layoutChange : search, parent.path, searchValue, parent.showHiddenItems, !parent.searchSettings.ignoreCase); } return; } if (parent.searchSettings.filterType === 'startsWith') { searchWord = value + '*'; } else if (parent.searchSettings.filterType === 'endsWith') { searchWord = '*' + value; } else { searchWord = '*' + value + '*'; } parent.searchWord = searchWord; parent.itemData = [getPathObject(parent)]; if (value.length > 0) { var caseSensitive = parent.searchSettings.ignoreCase; var hiddenItems = parent.showHiddenItems; Search(parent, isLayoutChange ? layoutChange : search, parent.path, searchWord, hiddenItems, !caseSensitive); } else { if (!parent.isFiltered) { if (parent.isSortByClicked) { parent.notify(layoutChange, { files: (parent.oldView === 'Details') ? parent.detailsviewModule.gridObj.dataSource : parent.largeiconsviewModule.allItems }); parent.isSortByClicked = false; } else { read(parent, isLayoutChange ? layoutChange : search, parent.path); } } else { filter(parent, layoutChange); } } } /** * Gets updated layout * * @param {IFileManager} parent - specifies the parent element. * @param {string} view - specifies the view. * @returns {void} * @private */ function updateLayout(parent, view) { parent.oldView = parent.view; parent.setProperties({ view: view }, true); if (parent.breadcrumbbarModule.searchObj.element.value !== '' || parent.isFiltered) { parent.layoutSelectedItems = parent.selectedItems; } var searchWord = ''; if (parent.breadcrumbbarModule.searchObj.element.value) { searchWord = parent.breadcrumbbarModule.searchObj.element.value; } parent.isLayoutChange = true; searchWordHandler(parent, searchWord, true); } /* istanbul ignore next */ /** * Gets updated layout * * @param {IFileManager} parent - specifies the parent element. * @param {Element} element - specifies the element. * @returns {void} * @private */ function getTargetModule(parent, element) { var tartgetModule = ''; if (element) { if (closest(element, '.' + ROOT + '.' + CONTROL + ' .' + GRID_CONTENT)) { tartgetModule = 'detailsview'; } else if (closest(element, '.' + LARGE_ICONS)) { tartgetModule = 'largeiconsview'; } else if (element.classList.contains('e-fullrow') || element.classList.contains('e-icon-expandable')) { tartgetModule = 'navigationpane'; } else if (closest(element, '.e-address-list-item')) { tartgetModule = 'breadcrumbbar'; } else { tartgetModule = ''; } } parent.targetModule = tartgetModule; } /* istanbul ignore next */ /** * refresh the layout * * @param {IFileManager} parent - specifies the parent element. * @returns {void} * @private */ function refresh(parent) { parent.itemData = [getPathObject(parent)]; if (!hasReadAccess(parent.itemData[0])) { createDeniedDialog(parent, parent.itemData[0], permissionRead); } else { read(parent, refreshEnd, parent.path); } } /** * open action in the layout * * @param {IFileManager} parent - specifies the parent element. * @returns {void} * @private */ function openAction(parent) { read(parent, openEnd, parent.path); } /** * open action in the layout * * @param {IFileManager} parent - specifies the parent element. * @returns {Object} - returns the path data. * @private */ function getPathObject(parent) { return getValue(parent.pathId[parent.pathId.length - 1], parent.feParent); } /** * Copy files * * @param {IFileManager} parent - specifies the parent element. * @returns {void} * @private */ function copyFiles(parent) { if (!activeElement('copy', parent)) { return; } else { parent.fileAction = 'copy'; } } /** * Cut files * * @param {IFileManager} parent - specifies the parent element. * @returns {void} * @private */ function cutFiles(parent) { if (!activeElement('cut', parent)) { return; } else { parent.isCut = true; parent.fileAction = 'move'; } } /** * To add class for fileType * * @param {Object} file - specifies the file. * @returns {string} - returns the file type. * @private */ function fileType(file) { var isFile = getValue('isFile', file); if (!isFile) { return FOLDER; } var imageFormat = ['bmp', 'dib', 'jpg', 'jpeg', 'jpe', 'jfif', 'gif', 'tif', 'tiff', 'png', 'ico']; var audioFormat = ['mp3', 'wav', 'aac', 'ogg', 'wma', 'aif', 'fla', 'm4a']; var videoFormat = ['webm', 'mkv', 'flv', 'vob', 'ogv', 'ogg', 'avi', 'wmv', 'mp4', '3gp']; var knownFormat = ['css', 'exe', 'html', 'js', 'msi', 'pdf', 'pptx', 'ppt', 'rar', 'zip', 'txt', 'docx', 'doc', 'xlsx', 'xls', 'xml', 'rtf', 'php']; var filetype = getValue('type', file); filetype = filetype.toLowerCase(); if (filetype.indexOf('.') !== -1) { filetype = filetype.split('.').join(''); } var iconType; if (imageFormat.indexOf(filetype) !== -1) { iconType = ICON_IMAGE; } else if (audioFormat.indexOf(filetype) !== -1) { iconType = ICON_MUSIC; } else if (videoFormat.indexOf(filetype) !== -1) { iconType = ICON_VIDEO; } else if (knownFormat.indexOf(filetype) !== -1) { iconType = 'e-fe-' + filetype; } else { iconType = 'e-fe-unknown e-fe-' + filetype; } return iconType; } /* istanbul ignore next */ /** * To get the image URL * * @param {IFileManager} parent - specifies the parent element. * @param {Object} item - specifies the item. * @returns {string} - returns the image url. * @private */ function getImageUrl(parent, item) { var imgUrl = isFileSystemData(parent) ? getValue('imageUrl', item) : ''; if (isFileSystemData(parent)) { var eventArgs_1 = { fileDetails: [item], imageUrl: imgUrl }; parent.trigger('beforeImageLoad', eventArgs_1); return eventArgs_1.imageUrl; } var baseUrl = parent.ajaxSettings.getImageUrl ? parent.ajaxSettings.getImageUrl : parent.ajaxSettings.url; var pathUrl = (baseUrl.indexOf('?') !== -1) ? '&path=' : '?path='; var fileName = encodeURIComponent(getValue('name', item)); var fPath = getValue('filterPath', item); if (parent.hasId) { var imgId = getValue('id', item); imgUrl = baseUrl + pathUrl + parent.path + '&id=' + imgId; } else if (!isNullOrUndefined(fPath)) { imgUrl = baseUrl + pathUrl + encodeURIComponent(fPath.replace(/\\/g, '/')) + fileName; } else { imgUrl = baseUrl + pathUrl + parent.path + fileName; } imgUrl = imgUrl + '&time=' + (new Date().getTime()).toString(); var eventArgs = { fileDetails: [item], imageUrl: imgUrl }; parent.trigger('beforeImageLoad', eventArgs); return eventArgs.imageUrl; } /* istanbul ignore next */ /** * Gets the full path * * @param {IFileManager} parent - specifies the parent element. * @param {Object} data - specifies the data. * @param {string} path - specifies the path. * @returns {string} - returns the image url. * @private */ function getFullPath(parent, data, path) { var filePath = getValue(parent.hasId ? 'id' : 'name', data) + '/'; var fPath = getValue(parent.hasId ? 'filterId' : 'filterPath', data); if (!isNullOrUndefined(fPath)) { return fPath.replace(/\\/g, '/').replace(/^.*?(?=\/)/, '') + filePath; } else { return path + filePath; } } /** * Gets the name * * @param {IFileManager} parent - specifies the parent element. * @param {Object} data - specifies the data. * @returns {string} - returns the name. * @private */ function getName(parent, data) { var name = getValue('name', data); var fPath = getValue('filterPath', data); if ((parent.breadcrumbbarModule.searchObj.element.value !== '' || parent.isFiltered) && !isNullOrUndefined(fPath)) { fPath = fPath.replace(/\\/g, '/'); name = fPath.replace(parent.path, '') + name; } return name; } /** * Gets the name * * @param {IFileManager} parent - specifies the parent element. * @param {Object[]} items - specifies the item elements. * @returns {Object[]} - returns the sorted data. * @private */ function getSortedData(parent, items) { if (items.length === 0) { return items; } var query; if (parent.sortOrder !== 'None' && !isNullOrUndefined(parent.sortOrder)) { query = new Query().sortBy(parent.sortBy, parent.sortOrder.toLowerCase(), true).group('isFile'); } else { query = new Query().group('isFile'); } var lists = new DataManager(items).executeLocal(query); return getValue('records', lists); } /** * Gets the data object * * @param {IFileManager} parent - specifies the parent element. * @param {string} key - specifies the key. * @param {string} value - specifies the value. * @returns {Object} - returns the sorted data. * @private */ function getObject(parent, key, value) { var currFiles = getValue(parent.pathId[parent.pathId.length - 1], parent.feFiles); var result = currFiles.filter(function (data) { return data[key].toString() === value; }); return result.length > 0 ? result[0] : null; } /** * Creates empty element * * @param {IFileManager} parent - specifies the parent element. * @param {HTMLElement} element - specifies the element. * @param {ReadArgs | SearchArgs} args - specifies the args. * @returns {void} * @private */ function createEmptyElement(parent, element, args) { var top; var layoutElement = select('#' + parent.element.id + LAYOUT_ID, parent.element); var addressBarHeight = select('#' + parent.element.id + BREADCRUMBBAR_ID, layoutElement).offsetHeight; top = layoutElement.offsetHeight - addressBarHeight; if