devexpress-reporting
Version:
DevExpress Reporting provides the capability to develop a reporting application to create and customize reports.
63 lines (62 loc) • 2.51 kB
JavaScript
/**
* DevExpress HTML/JS Reporting (designer\bands\sortableBand.js)
* Version: 25.2.3
* Build date: Dec 15, 2025
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* License: https://www.devexpress.com/Support/EULAs/universal.xml
*/
import * as ko from 'knockout';
import { BandViewModel } from './xrBand';
import { changeLevels, coerceNewLevelValueOnReordering, getExistedSameLevelBand, getMaxLevel, levelSetup } from './_bandUtils';
export class SortableBandViewModel extends BandViewModel {
constructor(band, parent, serializer) {
super(band, parent, serializer);
this._level = this._level ?? ko.observable(0);
this._disposables.push(this.level = ko.pureComputed({
read: () => this._level(),
write: (newValue) => levelSetup(this, newValue)
}));
levelSetup(this, this.level());
this._disposables.push(this.maxLevel = ko.pureComputed(() => getMaxLevel(this.getFilteredParentBands()) + 1));
}
getFilteredParentBands() {
return this.parentModel().bands().filter(b => b.constructor === this.constructor);
}
_reorderLevelsCore(newLevelValue) {
const parentDetailBands = this.getFilteredParentBands();
const existedSameLevelBand = getExistedSameLevelBand(parentDetailBands, newLevelValue);
const startIndex = parentDetailBands.indexOf(existedSameLevelBand);
const endIndex = parentDetailBands.indexOf(this);
changeLevels(parentDetailBands, startIndex, endIndex);
this._level(newLevelValue);
}
coerceDefaultLevelValue(newValue) {
return newValue === this.getDefaultLevel() ? 0 : newValue;
}
getDefaultLevel() {
return 0;
}
isPropertyModified(name) {
if (name === 'level') {
return this.level() !== this._getInitialLevel();
}
return super.isPropertyModified(name);
}
getPropertyDefaultValue(propertyName) {
if (propertyName === 'level') {
return this._getInitialLevel();
}
return super.getPropertyDefaultValue(propertyName);
}
reorderLevels(maxLevel, newValue) {
newValue = coerceNewLevelValueOnReordering(newValue, 0, maxLevel);
this._reorderLevelsCore(newValue);
}
updateLevelsOnInsert(maxLevel, newValue) {
this._level(maxLevel + 1);
this._initialLevel = this._level();
}
_getInitialLevel() {
return this._initialLevel ?? this.getDefaultLevel();
}
}