UNPKG

@true-directive/base

Version:

The set of base classes for the TrueDirective Grid

141 lines (140 loc) 6.94 kB
var __decorate = (this && this.__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 __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; /** * Copyright (c) 2018-2019 Aleksey Melnikov, True Directive Company. * @link https://truedirective.com/ * @license MIT */ import { AxInject } from '../classes/ax-inject.class'; import { ColumnType, GridPart } from '../classes/enums'; import { Column } from '../classes/column.class'; import { ColumnBand } from '../classes/column-band.class'; import { GridSettings } from '../classes/grid-settings.class'; import { DataSource } from '../classes/data-source.class'; import { ColumnCollection } from '../classes/column-collection.class'; import { Selection } from '../classes/selection.class'; import { LayoutsHandler } from './layouts.handler'; import { GridCheckHandler } from './grid-check.handler'; var GridDragHandler = /** @class */ (function () { function GridDragHandler() { /** * The list of columns' fieldnames which are being dragged. */ this.disabledFields = []; } Object.defineProperty(GridDragHandler.prototype, "columns", { get: function () { return this.columnCollection.columns; }, enumerable: true, configurable: true }); // Настройка компонента для визуализации перетаскиваемого заголовка столбца GridDragHandler.prototype.setDragItem = function (e) { var _this = this; this.disabledFields.splice(0, this.disabledFields.length); if (e.target instanceof Column) { var newCol = new Column(e.target.fieldName, e.target.caption, e.targetWidth, ColumnType.STRING, ''); newCol.allowFilter = true; newCol.fixed = GridPart.DRAG_ITEM; this.disabledFields.push(newCol.fieldName); this.layoutsHandler.layoutDrag.update([newCol], this.settings.widthUnit, this.settings.levelIndent, 300, false); } else { if (e.target instanceof ColumnBand) { // Вознамерились перетащить бэнд var band = e.target; var newCol = new Column('', band.caption, e.targetWidth, ColumnType.STRING, ''); newCol.fixed = GridPart.DRAG_ITEM; // Все колонки окрасятся в серый цвет на время перетаскивания band.columns.forEach(function (c) { return _this.disabledFields.push(c.fieldName); }); this.layoutsHandler.layoutDrag.update([newCol], this.settings.widthUnit, this.settings.levelIndent, 300, false); } else { // Строка? // Первые 4 колонки? var dragColumns = []; for (var i = 0; i < this.columns.length; i++) { var col = this.columns[i]; if (!col.visible) { continue; } var dCol = col.clone(); dCol.fixed = GridPart.DRAG_ITEM; dragColumns.push(dCol); if (dragColumns.length > 3) { break; } } this.layoutsHandler.layoutDrag.update(dragColumns, this.settings.widthUnit, this.settings.levelIndent); // Колонки добавлены // Теперь строки... // 1. Сфокусированная if (this.check.isRowChecked(this.selection.focusedRow)) { // Берем все выделенные строки e.target = []; this.dataSource.resultRows.forEach(function (r) { if (_this.check.isRowChecked(r) && !r.__ax_isGroup) { e.target.push(r); } }); } else { e.target = [this.selection.focusedRow]; } } } }; // Очистка компонента для визуализации перетаскиваемого заголовка столбца GridDragHandler.prototype.clearDragItem = function () { this.disabledFields.splice(0, this.disabledFields.length); this.layoutsHandler.layoutDrag.update([]); }; // Один из дочерних компонентов говорит нам, что что-то тащится. // Передаем заинтересованным слушателям GridDragHandler.prototype.drag = function (e) { this.events.dragEvent(e); }; // Один из дочерних компонентов говорит нам, что что-то брошено. // Передаем заинтересованным слушателям GridDragHandler.prototype.drop = function (e) { this.events.dropEvent(e); }; __decorate([ AxInject('events'), __metadata("design:type", Object) ], GridDragHandler.prototype, "events", void 0); __decorate([ AxInject('layouts'), __metadata("design:type", LayoutsHandler) ], GridDragHandler.prototype, "layoutsHandler", void 0); __decorate([ AxInject('dataSource'), __metadata("design:type", DataSource) ], GridDragHandler.prototype, "dataSource", void 0); __decorate([ AxInject('settings'), __metadata("design:type", GridSettings) ], GridDragHandler.prototype, "settings", void 0); __decorate([ AxInject('columns'), __metadata("design:type", ColumnCollection) ], GridDragHandler.prototype, "columnCollection", void 0); __decorate([ AxInject('selection'), __metadata("design:type", Selection) ], GridDragHandler.prototype, "selection", void 0); __decorate([ AxInject('check'), __metadata("design:type", GridCheckHandler) ], GridDragHandler.prototype, "check", void 0); return GridDragHandler; }()); export { GridDragHandler };