VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-full/dist/js/mdls__absol-card__js__dashboard__DBWidget.js
/*** module: node_modules/absol-card/js/dashboard/DBWidget.js ***/
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.dir2HS = void 0;

require("../../css/dbwidget.css");

var _Core = _interopRequireDefault(require("../dom/Core"));

var _QuickMenu = _interopRequireDefault(require("absol-acomp/js/QuickMenu"));

var _ResizeSystem = _interopRequireDefault(require("absol/src/HTML5/ResizeSystem"));

var _Vec = _interopRequireDefault(require("absol/src/Math/Vec2"));

var _stringGenerate = require("absol/src/String/stringGenerate");

var _stringFormat = require("absol/src/String/stringFormat");

var _Rectangle = _interopRequireDefault(require("absol/src/Math/Rectangle"));

var _GridPosition = require("./GridPosition");

var _Dom = _interopRequireDefault(require("absol/src/HTML5/Dom"));

var _Icons = require("absol-acomp/js/Icons");

var _EventEmitter = require("absol/src/HTML5/EventEmitter");


var _ = _Core.default._;
var $ = _Core.default.$;

function createDefaultDBWidgetMenu() {
  return {
    props: {
      items: [{
        text: 'Sửa',
        icon: 'span.mdi.mdi-pencil',
        cmd: 'edit'
      }, {
        text: 'Xóa',
        icon: 'span.mdi.mdi-delete',
        cmd: 'del'
      }]
    },
    onSelect: function (item) {
      console.log(item.cmd);
    }
  };
}

var dir2HS = {
  ne: [0, 1, 1, -1],
  nw: [1, 1, -1, -1],
  se: [0, 0, 1, 1],
  sw: [1, 0, -1, 1],
  e: [0, 0, 1, 0],
  w: [1, 0, -1, 0],
  s: [0, 0, 0, 1],
  n: [0, 1, 0, -1],
  move: [1, 1, 0, 0]
};
exports.dir2HS = dir2HS;
_('style#db-wedget-style').addTo(document.head).innerHTML = Object.keys(dir2HS).map(function (name) {
  return 'body.db-resizing-' + name + ' > div';
}).join(',\n') + '{\n' + '    pointer-events: none;\n' + '}\n' + Object.keys(dir2HS).map(function (name) {
  return 'body.db-resizing-' + name + '{\n' + '    cursor: ' + name + (name === 'move' ? '' : '-resize') + ';\n' + '}';
}).join('\n');
/***
 * @extends AElement
 * @constructor
 */

function DBWidget() {
  this.gridX = 0;
  this.gridY = 0;
  this.gridWidth = 1;
  this.gridHeight = 1;
  var thisW = this;
  this.$title = $('.db-widget-title', this);
  this.$titleText = this.$title.firstChild;
  this.$header = $('.db-widget-header', this);
  this.$headerRight = $('.db-widget-header-right', this);
  this.$body = $('.db-widget-body', this);
  this.$contextBtn = $('.db-widget-context-btn', this);
  this.$filterBtn = $('.db-widget-filter-btn', this).on('click', this.eventHandler.clickFilterBtn);
  Object.keys(dir2HS).forEach(dirName => {
    this['$resizer' + dirName.toUpperCase()] = $('.db-widget-resize-' + dirName, this).on('draginit', event => {
      if (dirName === 'move') {
        if ((0, _EventEmitter.hitElement)(this.$contextBtn, event)) event.cancel();
      }
    }).on('dragstart', this._startLocalState.bind(this, dir2HS[dirName])).on('drag', this._changeLocalState.bind(this)).on('dragend', this._endLocalState.bind(this));
  });
  this._quickmenuHolder = null;
  this._quickmenuAdapter = {
    getMenuProps: function () {
      return thisW._quickmenu.props;
    },
    onSelect: function () {
      if (typeof thisW._quickmenu.onSelect == 'function') thisW._quickmenu.onSelect.apply(thisW, arguments);
    }
  };
  this._quickmenu = null;
  this.quickmenu = createDefaultDBWidgetMenu();
  this.$attachhook = $('attachhook', this);
  this.$attachhook.requestUpdateSize = this.updateSize.bind(this);
  this.$attachhook.on('attached', function () {
    _ResizeSystem.default.add(this);

    this.requestUpdateSize();
  });
  this.on('pointerdown', this.eventHandler.pointerdown);
}

DBWidget.tag = 'DBWidget'.toLowerCase();

DBWidget.render = function () {
  return _({
    class: 'db-widget',
    id: (0, _stringGenerate.randomIdent)(20),
    extendEvent: ['pressfilter', 'positionchange'],
    child: [{
      tag: 'hanger',
      class: ['db-widget-header', 'db-widget-resize-move'],
      child: [{
        tag: 'span',
        class: 'db-widget-title',
        child: {
          text: ""
        }
      }, {
        class: 'db-widget-header-right',
        child: [{
          tag: 'button',
          class: ['tl-transparent-btn', 'db-widget-filter-btn'],
          child: 'span.mdi.mdi-filter'
        }, {
          tag: 'button',
          class: ['tl-transparent-btn', 'db-widget-context-btn'],
          child: 'span.mdi.mdi-dots-horizontal'
        }]
      }]
    }, {
      class: ['db-widget-body', 'as-bscroller']
    }, // 'hanger.db-widget-resize',
    'hanger.db-widget-resize-n', 'hanger.db-widget-resize-s', 'hanger.db-widget-resize-e', 'hanger.db-widget-resize-w', {
      tag: 'hanger',
      class: 'db-widget-resize-se',
      child: 'span.mdi.mdi-resize-bottom-right'
    }, 'hanger.db-widget-resize-nw', 'hanger.db-widget-resize-ne', 'hanger.db-widget-resize-sw', 'attachhook']
  });
};

['addChild', 'addChildBefore', 'addChildAfter', 'clearChild', 'findChildBefore', 'findChildAfter'].forEach(function (name) {
  DBWidget.prototype[name] = function () {
    return this.$body[name].apply(this.$body, arguments);
  };
});
DBWidget.prototype.maxScrollSpeed = 300;

DBWidget.prototype.updateSize = function () {
  var rightBound = this.$headerRight.getBoundingClientRect();
  this.$title.addStyle('width', 'calc(100% - ' + rightBound.width + 'px)');
};

DBWidget.prototype.getChildNodes = function () {
  return this.$body.getChildNodes();
};
/***
 *
 * @return {Rectangle}
 */


DBWidget.prototype.getGridPosition = function () {
  return new _Rectangle.default(this.gridX, this.gridY, this.gridWidth, this.gridHeight);
};
/***
 *
 * @param {Rectangle} position
 */


DBWidget.prototype.setGridPosition = function (position) {
  this.gridX = position.x;
  this.gridY = position.y;
  this.gridWidth = position.width;
  this.gridHeight = position.height;
};

DBWidget.property = {};
/**
 *
 * @type {{} |DBWidget}
 */

DBWidget.property.title = {
  set: function (value) {
    this.$titleText.data = value || '';
  },
  get: function () {
    return this.$titleText.data;
  }
};
DBWidget.property.quickmenu = {
  set: function (value) {
    value = value || null;

    if (value) {
      if (!this._quickmenuHolder) this._quickmenuHolder = _QuickMenu.default.toggleWhenClick(this.$contextBtn, this._quickmenuAdapter);
    } else {
      if (this._quickmenuHolder) {
        this._quickmenuHolder.remove();

        this._quickmenuHolder = null;
      }
    }

    this._quickmenu = value;
  },
  get: function () {
    return this._quickmenu;
  }
};
DBWidget.property.gridPosition = {
  set: function (value) {
    this.setGridPosition(value);
  },
  get: function () {
    return this.getGridPosition();
  }
};
DBWidget.property.waiting = {
  set: function (value) {
    if (value && !this.$waiting) {
      this.$waiting = _({
        tag: _Icons.SpinnerIco
      });
      this.$header.addChildAfter(this.$waiting, this.$title);
    } else if (!value && this.$waiting) {
      this.$waiting.remove();
      this.$waiting = null;
    }
  },
  get: function () {
    return !!this.$waiting;
  }
};
['grid-x', 'grid-y', 'grid-width', 'grid-height'].forEach(function (styleName) {
  var propertyName = (0, _stringFormat.kebabCaseToCamelCase)(styleName);
  var stylePropertyName = '--' + styleName;
  DBWidget.property[propertyName] = {
    set: function (value) {
      value = value || 0;
      this.addStyle(stylePropertyName, value + '');
    },
    get: function () {
      return parseFloat(this.getComputedStyleValue(stylePropertyName)) || 0;
    }
  };
});
/**
 * @returns {DBGridster}
 */

DBWidget.prototype.getParent = function () {
  return this.parentElement;
};

DBWidget.prototype._startLocalState = function (hs, event) {
  var cursorClass = 'db-resizing-' + (event.target.attr('class').match(/resize-([a-z]+)/) || ['', 'move'])[1];
  document.body.classList.add(cursorClass);
  this.addClass('db-moving');
  var parent = this.getParent();
  var pBound = parent.getBoundingClientRect();
  var bound = this.getBoundingClientRect();
  var pos = new _Vec.default(bound.left, bound.top);
  var pPos = new _Vec.default(pBound.left, pBound.top).sub(new _Vec.default(parent.scrollLeft, parent.scrollTop));
  this._resizeData = {
    cursorClass: cursorClass,
    hs: hs,
    bound: bound,
    position: pos.sub(pPos),
    offset: event.startingPoint.sub(pPos),
    size: new _Vec.default(bound.width, bound.height),
    currentPoint: event.currentPoint,
    $placePreview: _('.db-widget-place-preview').addTo(parent),
    startPositionList: parent.getPositionList(),
    cGridWidth: this.gridWidth,
    cGridHeight: this.gridHeight,
    cGridX: this.gridX,
    cGridY: this.gridY,
    lGridWidth: this.gridWidth,
    lGridHeight: this.gridHeight,
    lGridX: this.gridX,
    lGridY: this.gridY,
    lGridPosition: this.getGridPosition(),
    modifiedPosition: {
      error: 'NOT_INIT'
    },
    $scrollHolder: _({
      class: 'db-gridster-scroll-holder',
      style: {
        top: parent.scrollHeight - 1 + 'px'
      }
    }).addTo(parent)
  };
};

DBWidget.prototype._endLocalState = function () {
  document.body.classList.remove(this._resizeData.cursorClass);
  var parent = this.getParent();

  this._resizeData.$placePreview.remove();

  this._resizeData.$scrollHolder.remove();

  var newPosition = Object.assign({}, this._resizeData.startPositionList);

  if (!this._resizeData.modifiedPosition.error) {
    var position = parent.findPosition(this.getBoundingClientRect());
    this.addStyle(position);
    Object.assign(newPosition, this._resizeData.modifiedPosition);
    delete newPosition[this.id];
  }

  this.removeStyle('width').removeStyle('height').removeStyle('top').removeStyle('left');
  this.removeClass('db-moving');
  parent.applyPositionList(newPosition);
  var newPositionList = parent.getPositionList();

  for (var id in newPositionList) {
    if (!newPositionList[id].equals(this._resizeData.startPositionList[id])) {
      this.emit('positionchange', {
        type: 'positionchange',
        target: this,
        newPositionList: newPositionList,
        prevPositionList: Object.assign({}, this._resizeData.startPositionList)
      }, this);
      parent.emit('positionlistchange', {
        type: 'positionlistchange',
        target: parent,
        newPositionList: newPositionList,
        prevPositionList: Object.assign({}, this._resizeData.startPositionList)
      }, parent);
      break;
    }
  }

  this._resizeData = null;
};

DBWidget.prototype._changeLocalState = function (event) {
  if (this._resizeData.requestAnimationFrameId >= 0) {
    cancelAnimationFrame(this._resizeData.requestAnimationFrameId);
    this._resizeData.requestAnimationFrameId = -1;
  }

  var parent = this.getParent();
  var hs = this._resizeData.hs;
  var pBound = parent.getBoundingClientRect();
  var pPos = new _Vec.default(pBound.left, pBound.top).sub(new _Vec.default(parent.scrollLeft, parent.scrollTop));
  var newOffset = event.currentPoint.sub(pPos);
  var d = newOffset.sub(this._resizeData.offset);
  this.addStyle({
    width: this._resizeData.bound.width + d.x * hs[2] + 'px',
    height: this._resizeData.bound.height + d.y * hs[3] + 'px'
  });
  this.addStyle({
    left: this._resizeData.position.x + d.x * hs[0] + 'px',
    top: this._resizeData.position.y + d.y * hs[1] + 'px'
  });
  var position = parent.findPosition(this.getBoundingClientRect());

  this._resizeData.$placePreview.addStyle(position);

  if (this._resizeData.cGridWidth !== position["--grid-width"] || this._resizeData.cGridHeight !== position["--grid-height"] || this._resizeData.cGridX !== position["--grid-x"] || this._resizeData.cGridY !== position["--grid-y"]) {
    this._resizeData.cGridWidth = position["--grid-width"];
    this._resizeData.cGridHeight = position["--grid-height"];
    this._resizeData.cGridX = position["--grid-x"];
    this._resizeData.cGridY = position["--grid-y"];
    var allRects = Object.assign({}, this._resizeData.startPositionList);
    var thisRect = allRects[this.id].clone();
    thisRect.width = this._resizeData.cGridWidth;
    thisRect.height = this._resizeData.cGridHeight;
    thisRect.x = this._resizeData.cGridX;
    thisRect.y = this._resizeData.cGridY;
    delete allRects[this.id];
    var collapseRectIds = (0, _GridPosition.findCollapsedRect)(allRects, thisRect);
    var newPositionList = Object.assign({}, this._resizeData.startPositionList);
    var staticRect;
    var moveId;
    var moveRect;
    var newPos;

    for (var i = 0; i < collapseRectIds.length; ++i) {
      moveId = collapseRectIds[i];
      staticRect = Object.assign({}, allRects);
      moveRect = staticRect[moveId].clone();
      delete staticRect[moveId];
      newPos = (0, _GridPosition.findNewPosition)(staticRect, thisRect, moveRect, new _Rectangle.default(0, 0, this.getParent().nCol, this.getParent().nRow), this._resizeData.lGridPosition);

      if (newPos) {
        moveRect.x = newPos.x;
        moveRect.y = newPos.y;
        newPositionList[moveId] = moveRect;
        allRects[moveId] = moveRect;
      } else {
        newPositionList = {
          error: "FAIL"
        };
        break;
      }
    }

    if (!newPositionList.error) {
      this.getParent().applyPositionList(newPositionList);
    } else {}

    this._resizeData.modifiedPosition = newPositionList;
  }

  _ResizeSystem.default.updateDown(this);

  this._autoScroll(event);
};

DBWidget.prototype._autoScroll = function (event) {
  if (!this._resizeData) return;
  var resizeData = this._resizeData;
  var scrollerX = this.getParent();
  var overflowStyle;

  while (scrollerX) {
    overflowStyle = window.getComputedStyle(scrollerX)['overflow'];
    if ((overflowStyle === 'auto' || overflowStyle === 'auto hidden' || overflowStyle === 'scroll' || scrollerX.tagName === 'HTML') && scrollerX.clientWidth < scrollerX.scrollWidth) break;
    scrollerX = scrollerX.parentElement;
  }

  var scrollerY = this.getParent();

  while (scrollerY) {
    overflowStyle = window.getComputedStyle(scrollerY)['overflow'];
    if ((overflowStyle === 'auto' || overflowStyle === 'hidden auto' || overflowStyle === 'scroll' || scrollerY.tagName === 'HTML') && scrollerY.clientHeight < scrollerY.scrollHeight) break;
    scrollerY = scrollerY.parentElement;
  }

  var outBound;
  var bBound;

  var screenSize = _Dom.default.getScreenSize();

  var vx = 0;
  var vy = 0;
  bBound = this.getBoundingClientRect();

  if (scrollerX) {
    if (resizeData.$scrollerX !== scrollerX || !event.repeated) {
      resizeData.scrollerXValue = scrollerX.scrollLeft;
      resizeData.$scrollerX = scrollerX;
    }

    outBound = scrollerX.getBoundingClientRect();
    outBound = {
      left: Math.max(outBound.left, 0),
      top: Math.max(outBound.top, 0),
      bottom: Math.min(outBound.bottom, screenSize.height),
      right: Math.min(outBound.right, screenSize.width)
    };

    if (bBound.left < outBound.left) {
      vx = bBound.left - outBound.left;
    } else if (bBound.right > outBound.right) {
      vx = bBound.right - outBound.right;
    }
  } else {
    resizeData.$scrollerX = null;
  }

  if (scrollerY) {
    if (resizeData.$scrollerY !== scrollerY || !event.repeated) {
      resizeData.scrollerYValue = scrollerY.scrollTop;
      resizeData.$scrollerY = scrollerY;
    }

    outBound = scrollerY.getBoundingClientRect();
    outBound = {
      left: Math.max(outBound.left, 0),
      top: Math.max(outBound.top, 0),
      bottom: Math.min(outBound.bottom, screenSize.height),
      right: Math.min(outBound.right, screenSize.width)
    };

    if (bBound.top < outBound.top) {
      vy = bBound.top - outBound.top;
    } else if (bBound.bottom > outBound.bottom) {
      vy = bBound.bottom - outBound.bottom;
    }
  } else {
    resizeData.$scrollerY = null;
  }

  vx = Math.max(-this.maxScrollSpeed, Math.min(this.maxScrollSpeed, vx * Math.sqrt(Math.abs(vx))));
  vy = Math.max(-this.maxScrollSpeed, Math.min(this.maxScrollSpeed, vy * Math.sqrt(Math.abs(vy))));

  if (vx !== 0 || vy !== 0) {
    var cEvent = Object.assign({
      repeated: true
    }, event);
    var thisBT = this;
    var now = new Date().getTime();

    if (resizeData.requestAnimationFrameId >= 0) {
      cancelAnimationFrame(resizeData.requestAnimationFrameId);
      resizeData.requestAnimationFrameId = -1;
    }

    resizeData.requestAnimationFrameId = requestAnimationFrame(function () {
      resizeData.requestAnimationFrameId = -1;
      var dt = (new Date().getTime() - now) / 1000;
      var cont = false;

      if (resizeData.$scrollerY && vy !== 0 && bBound.height < resizeData.$scrollerY.clientHeight) {
        resizeData.scrollerYValue += vy * dt;
        resizeData.scrollerYValue = Math.max(0, Math.min(resizeData.$scrollerY.scrollHeight - resizeData.$scrollerY.clientHeight, resizeData.scrollerYValue));
        resizeData.$scrollerY.scrollTop = resizeData.scrollerYValue;
        cont = true;
      }

      if (resizeData.$scrollerX && bBound.width < resizeData.$scrollerX.clientHeight) {
        resizeData.scrollerXValue += vx * dt;
        resizeData.scrollerXValue = Math.max(0, Math.min(resizeData.$scrollerX.scrollWidth - resizeData.$scrollerX.clientWidth, resizeData.scrollerXValue));
        resizeData.$scrollerX.scrollLeft = resizeData.scrollerXValue;
        cont = true;
      }

      if (thisBT._resizeData && cont) {
        thisBT._changeLocalState(cEvent);
      }
    });
  }
};
/***
 *
 * @type {DBWidget|{}}
 */


DBWidget.eventHandler = {};

DBWidget.eventHandler.pointerdown = function () {
  if (this.containsClass('cd-active')) return;
  var parent = this.getParent();

  if (parent) {
    parent.activeWidget(this);
  }
};

DBWidget.eventHandler.clickFilterBtn = function (event) {
  this.emit('pressfilter', {
    originEvent: event,
    type: 'pressfilter',
    target: this
  }, this);
};

_Core.default.install(DBWidget);

var _default = DBWidget;
exports.default = _default;

VaKeR 2022