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__dom__WeekTable.js
/*** module: node_modules/absol-card/js/dom/WeekTable.js ***/
"use strict";

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

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

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

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

var _datetime = require("absol/src/Time/datetime");

var _CActivity = _interopRequireDefault(require("./CActivity"));

var _CActivityTooltip = _interopRequireDefault(require("./CActivityTooltip"));

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

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

var _MonthTable = _interopRequireWildcard(require("./MonthTable"));

var _SegmentMerger = _interopRequireDefault(require("../helper/SegmentMerger"));

var _SegmentFinder = _interopRequireDefault(require("../helper/SegmentFinder"));

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

var _DomSignal = _interopRequireDefault(require("absol/src/HTML5/DomSignal"));

var _BrowserDetector = _interopRequireDefault(require("absol/src/Detector/BrowserDetector"));




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

function WeekTable() {
  var thisWT = this;
  this.domSignal = new _DomSignal.default();
  this.domSignal.on('requestUpdateCardPosition', this.updateCardPosition.bind(this));
  this.domSignal.on('requestUpdateHourRows', this._updateHourRows.bind(this));
  this.domSignal.on('requestUpdateHours', this._updateHours.bind(this));
  this._focusDate = new Date();
  this._week = (0, _datetime.beginOfWeek)(this._focusDate, false, this._firstDayOfWeek);
  this._workHourStart = 8;
  this._workHourEnd = 17.5;
  this._daysOff = [];
  this._lastVisiblePeriod = null;
  /**
   * @type {Array<CActivity>}
   */

  this.activities = [];
  /**
   * @type {CActivity}
   */

  this.activeActivity = null;
  /**
   * @type {CDayOfWeekRow}
   */

  this.$dayOfWeekRow = $('cdayofweekrow', this);
  this.$dayOfWeekRow.addChildBefore(_('.cd-week-table-empty-day'), this.$dayOfWeekRow.firstChild);
  this._firstDayOfWeek = 0; //same with MonthTable

  this.firstDayOfWeek = this._firstDayOfWeek;
  this.$header = $('.cd-week-table-header', this);
  this.$hourPlaceHolder = [];
  this.$dayPlaceHolder = [];
  this.$multidayContent = $('.cd-week-table-multiday', this);
  /****
   * @type {CWeekRow}
   */

  this.$weekRow = _('cweekrow').addTo(this.$multidayContent);
  this.$emptyDay = _('.cd-week-table-empty-day');
  this.$weekRow.addChildBefore(this.$emptyDay, this.$weekRow.firstChild).on('click', this.eventHandler.clickWeekRow);
  this.$content = $('.cd-week-table-content', this).on('click', this.eventHandler.clickHourTable);
  this.$hourRows = Array.prototype.filter.call(this.$content.childNodes, function (elt) {
    return elt.containsClass && elt.containsClass('cd-week-table-hour');
  });
  this.$hours = [];
  $('.cd-week-table-hour-day', this, function (hourElt) {
    thisWT.$hours.push(hourElt);
  });
  this.$body = $('.cd-week-table-body', this).removeClass('as-bscroller');
  this.$nowLine = _('.cd-now-line').addTo(this.$body);
  this._updateNowLineTimeout = -1;
  this._selectedEltHolder = {
    type: -1
  };
  this.selectedTime = {
    type: -1,
    time: new Date()
  }; // this.$clonedDayPlaceHolder = [];
  // /**
  //  * @type {CActivity}
  //  */
  // this.clonedCard = null;
  // this._initCloneIdx = -1;
  // this._currentCloneIdx = -1;
  // this._dragTimeFactor = [0, 0];

  this.$attachook = _('attachhook').on('error', function () {
    _Dom.default.addToResizeSystem(this);

    this.requestUpdateSize();
  }).addTo(this);
  this.$attachook.requestUpdateSize = this.updateSize.bind(this);

  this._updateDays();

  this.workHourStart = 8;
  this.workHourEnd = 17.5;
  this.firstDayOfWeek = 0;
  this.daysOff = [0, 6];
  this.focusDate = new Date();
}

WeekTable.tag = "WeekTable".toLowerCase();

WeekTable.render = function () {
  return _({
    extendEvent: 'visibleperiodchange',
    class: ['cd-week-table', _BrowserDetector.default.isMobile ? 'cd-mobile' : 'cd-desktop'],
    child: [{
      //reuse class
      class: 'cd-week-table-header',
      child: {
        tag: 'cdayofweekrow'
      }
    }, {
      class: 'cd-week-table-multiday'
    }, {
      tag: 'bscroller',
      class: 'cd-week-table-body',
      child: {
        tag: 'bscroller',
        class: 'cd-week-table-content',
        child: Array(24).fill(null).map(function (u, i) {
          return {
            class: 'cd-week-table-hour',
            child: [{
              class: 'cd-week-table-hour-value',
              child: {
                class: 'cd-week-table-hour-value-number',
                child: [{
                  text: (i == 0 ? 12 : i <= 12 ? i : i - 12) + ''
                }].concat({
                  '0': [{
                    class: 'cd-week-table-hour-value-apm',
                    child: {
                      text: "AM"
                    }
                  }],
                  '12': [{
                    class: 'cd-week-table-hour-value-apm',
                    child: {
                      text: "PM"
                    }
                  }]
                }[i + ''] || [])
              }
            }].concat(Array(7).fill('.cd-week-table-hour-day'))
          };
        })
      }
    }]
  });
};

WeekTable.prototype.requestUpdateCardPosition = _MonthTable.default.prototype.requestUpdateCardPosition;

WeekTable.prototype._updateNowLine = function () {
  var thisWT = this;
  if (this._updateNowLineTimeout > 0) clearTimeout(this._updateNowLine);
  var now = new Date();

  var bDay = (now.getTime() - (0, _datetime.beginOfDay)(now).getTime()) / _datetime.MILLIS_PER_DAY;

  var contentBound = this.$content.getBoundingClientRect();
  this.$nowLine.addStyle('top', contentBound.height * bDay + 'px');
  var dayIndex = (0, _datetime.compareDate)(now, this._week);

  if (dayIndex >= 0 && dayIndex < 7) {
    this.$nowLine.addClass('cd-current-week').addStyle('--today-left', dayIndex / 7 * 100 + '%');
  } else {
    this.$nowLine.removeClass('cd-current-week');
  }

  if (this.isDescendantOf(document.body)) {
    this._updateNowLineTimeout = setTimeout(function () {
      thisWT._updateNowLineTimeout = -1;

      thisWT._updateNowLine();
    }, 30000);
  }
};

WeekTable.prototype.updateSize = function () {
  var headBound = this.$header.getBoundingClientRect();
  var dayContentBound = this.$multidayContent.getBoundingClientRect();
  this.$body.addStyle('height', 'calc(100% - ' + (headBound.height + dayContentBound.height) + 'px)');

  this._updateNowLine();
};

WeekTable.prototype.getCellIdxByPosition = function (clientX, clientY) {
  var rect;
  var point = new _Vec.default(clientX, clientY);

  for (var i = 0; i < this.$days.length; ++i) {
    rect = _Rectangle.default.fromClientRect(this.$days[i].getBoundingClientRect());
    rect.y = 0;
    rect.height = 100000;
    if (rect.containsPoint(point)) return i;
  }

  return -1;
};

WeekTable.prototype._getTimeByPosition = function (clientX, clientY) {
  var res = {
    type: -1
  }; //none

  var weekRowBound = this.$weekRow.getBoundingClientRect();
  var emptyCellBound = this.$emptyDay.getBoundingClientRect();
  var idx;

  if (clientX >= emptyCellBound.right && clientX < weekRowBound.right) {
    idx = Math.floor((clientX - emptyCellBound.right) / ((weekRowBound.right - emptyCellBound.right) / 7));

    if (clientY >= weekRowBound.top && clientY <= weekRowBound.bottom) {
      res.time = new Date(this._week.getTime() + _datetime.MILLIS_PER_DAY * idx);
      res.type = 0;
    } else {
      var contentBound = this.$content.getBoundingClientRect();
      var hIdx = Math.floor((clientY - contentBound.top) / contentBound.height * 48);
      res.type = 1;
      res.time = new Date(this._week.getTime() + _datetime.MILLIS_PER_DAY * idx + hIdx * _datetime.MILLIS_PER_HOUR / 2);
    }
  } //todo


  return res;
};

WeekTable.prototype.dateOfCell = function (idx) {
  return new Date(this._week.getTime() + _datetime.MILLIS_PER_DAY * idx);
};

WeekTable.prototype.hourOfCell = function (idx) {
  var start = this._week;
  var col = idx % 7;
  var row = Math.floor(idx / 7);
  return new Date(start.getTime() + _datetime.MILLIS_PER_DAY * col + _datetime.MILLIS_PER_HOUR * row);
};

WeekTable.prototype.getDayCellByDate = function (date) {
  return this.$weekRow.getCellByDate(date);
};
/**
 *
 * @param {Date} date
 * @returns {Number}
 */


WeekTable.prototype.getHourCellIdxByDate = function (date) {
  var iCol = (0, _datetime.compareDate)(date, this._week);
  if (iCol < 0 || iCol >= 7) return -1;
  var h = date.getHours();
  return h * 7 + iCol;
};

WeekTable.prototype.getHourCellByDate = function (date) {
  return this.$hours[this.getHourCellIdxByDate(date)] || null;
};

WeekTable.prototype.getTimeByPosition = function (x, y) {
  var startTime = this._week;
  var pos = new _Vec.default(x, y);
  var bound;

  for (var i = 0; i < this.$days.length; ++i) {
    bound = _Rectangle.default.fromClientRect(this.$days[i].getBoundingClientRect());

    if (bound.containsPoint(pos)) {
      return {
        type: 0,
        millis: startTime.getTime() + _datetime.MILLIS_PER_DAY * i
      };
    }
  }

  for (var i = 0; i < this.$hours.length; ++i) {
    bound = _Rectangle.default.fromClientRect(this.$hours[i].getBoundingClientRect());

    if (bound.containsPoint(pos)) {
      return {
        type: 1,
        millis: startTime.getTime() + _datetime.MILLIS_PER_DAY * (i % 7) + _datetime.MILLIS_PER_HOUR * Math.floor(i / 7)
      };
    }
  }

  return null;
};

WeekTable.$dayPlacePool = [];

WeekTable.prototype._clearDayPlaceHolder = function () {
  var pool = WeekTable.$dayPlacePool;
  this.$dayPlaceHolder.forEach(function (ph) {
    ph.clearChild();
    ph.selfRemove();
    pool.push(ph);
  });
  this.$dayPlaceHolder = [];
};

WeekTable.prototype._makeOneDayPlaceHolder = function () {
  var holder;

  if (WeekTable.$dayPlacePool.length > 0) {
    holder = WeekTable.$dayPlacePool.pop();
  } else {
    holder = _('.cd-week-table-day-item-place-holder');
  }

  this.$dayPlaceHolder.push(holder);
  return holder;
};

WeekTable.$clonedDayPlacePool = [];

WeekTable.prototype._clearClonedDayPlaceHolder = function () {
  var pool = WeekTable.$clonedDayPlacePool;
  this.$clonedDayPlaceHolder.forEach(function (ph) {
    ph.clearChild();
    ph.selfRemove();
    pool.push(ph);
  });
  this.$clonedDayPlaceHolder = [];
};

WeekTable.prototype._makeOneClonedDayPlaceHolder = function () {
  var holder;

  if (WeekTable.$clonedDayPlacePool.length > 0) {
    holder = WeekTable.$clonedDayPlacePool.pop();
  } else {
    holder = _('.cd-week-table-day-item-place-holder.cd-cloned');
  }

  this.$clonedDayPlaceHolder.push(holder);
  return holder;
};

WeekTable.$hourPlacePool = [];

WeekTable.prototype._clearHourPlaceHolder = function () {
  var pool = WeekTable.$hourPlacePool;
  this.$hourPlaceHolder.forEach(function (ph) {
    ph.clearChild();
    ph.selfRemove();
    pool.push(ph);
  });
  this.$hourPlaceHolder = [];
};

WeekTable.prototype._makeOneHourPlaceHolder = function () {
  var holder;

  if (_MonthTable.default.$placePool.length > 0) {
    holder = _MonthTable.default.$placePool.pop();
  } else {
    holder = _('.cd-week-table-hour-item-place-holder');
  }

  this.$hourPlaceHolder.push(holder);
  return holder;
};
/**
 *
 * @param {Element} cell
 * @returns {Number}
 */


WeekTable.prototype._countDayPlaceHolder = function (cell) {
  var count = 0;
  var child;

  for (var i = 0; i < cell.childNodes.length; ++i) {
    child = cell.childNodes[i];
    if (child.containsClass && child.containsClass('cd-week-table-day-item-place-holder') && !child.containsClass('cd-cloned')) count++;
  }

  return count;
};
/**
 *
 * @param {Element} cell
 * @param {Number} n
 */


WeekTable.prototype._fillDayHolderToCell = function (cell, n) {
  var n0 = this._countDayPlaceHolder(cell);

  while (n0 < n) {
    cell.addChild(this._makeOneDayPlaceHolder());
    ++n0;
  }
};

WeekTable.prototype._updateDayOfWeek = _MonthTable.default.prototype._updateDayOfWeek; //reuse

WeekTable.prototype._updateDays = function () {
  this.$weekRow.date = this._week;
};

WeekTable.prototype._updateHours = function () {
  var hourElt;
  var dayClass;

  for (var i = 0; i < this.$hours.length; ++i) {
    hourElt = this.$hours[i];
    dayClass = 'cd-day-' + (i + this.firstDayOfWeek) % 7;

    if (hourElt.__day_class__ && dayClass != hourElt.__day_class__) {
      hourElt.removeClass(hourElt.__day_class__);
    }

    hourElt.__day_class__ = dayClass;
    hourElt.addClass(dayClass);
  }
};

WeekTable.prototype._updateHourRows = function () {
  var start = this._workHourStart;
  var end = this._workHourEnd;
  var rowElt;

  for (var i = 0; i < 24; ++i) {
    rowElt = this.$hourRows[i];

    if (start <= i) {
      if (end - i >= 1) {
        rowElt.removeClass('cd-off').removeClass('cd-off-half-before').removeClass('cd-off-half-after');
      } else if (end - i >= 0.5) {
        rowElt.removeClass('cd-off').addClass('cd-off-half-after').removeClass('cd-off-half-before');
      } else {
        rowElt.addClass('cd-off');
      }
    } else if (start - 0.5 <= i) {
      if (end >= i) {
        rowElt.removeClass('cd-off').addClass('cd-off-half-before').removeClass('cd-off-half-after');
      } else {
        rowElt.addClass('cd-off');
      }
    } else {
      rowElt.addClass('cd-off');
    }
  }
};

WeekTable.prototype.selectDate = function (date) {
  this.selectedTime.type = date ? 0 : -1;
  this.selectedTime.time = date;

  this._updateSelectedTime();
};

WeekTable.prototype.selectHour = function (date) {
  this.selectedTime.type = date ? 1 : -1;
  this.selectedTime.time = date;

  this._updateSelectedTime();
};

WeekTable.prototype._updateSelectedTime = function () {
  if (this._selectedEltHolder.type === 0) {
    this._selectedEltHolder.$cell.removeClass('cd-selected');

    this._selectedEltHolder.type = -1;
    this._selectedEltHolder.$cell = null;
  } else if (this._selectedEltHolder.type === 1) {
    this._selectedEltHolder.$beforeCell.removeClass('cd-selected-before');

    this._selectedEltHolder.$afterCell.removeClass('cd-selected-after');

    this._selectedEltHolder.type = -1;
    this._selectedEltHolder.$beforeCell = null;
    this._selectedEltHolder.$afterCell = null;
  }

  if (this.selectedTime.type === 0) {
    this._selectedEltHolder.type = 0;
    this._selectedEltHolder.$cell = this.getDayCellByDate(this.selectedTime.time);

    this._selectedEltHolder.$cell.addClass('cd-selected');
  } else if (this.selectedTime.type === 1) {
    this._selectedEltHolder.type = 1;
    var cell;
    cell = this.getHourCellByDate(this.selectedTime.time);
    this._selectedEltHolder.$afterCell = this.getHourCellByDate(this.selectedTime.time);

    this._selectedEltHolder.$afterCell.addClass('cd-selected-after');

    if (this.selectedTime.time.getMinutes() >= 30) {
      cell = this.getHourCellByDate(new Date(this.selectedTime.time.getTime() + _datetime.MILLIS_PER_HOUR));
    }

    this._selectedEltHolder.$beforeCell = cell;

    this._selectedEltHolder.$beforeCell.addClass('cd-selected-before');
  } // if (this.$selectedCell) {
  //     this.$selectedCell.removeClass('cd-selected');
  //     this.$selectedCell = null;
  // }
  // if (this.selectedTime.type == 0 && this.selectedTime.time) {
  //     this.$selectedCell = this.getDayCellByDate(this.selectedTime.time);
  // }
  // else if (this.selectedTime.type == 1 && this.selectedTime.time) {
  //     this.$selectedCell = this.getHourCellByDate(this.selectedTime.time);
  //     console.log(this.$selectedCell)
  // }
  // else {
  //     //todo: clear
  // }
  // if (this.$selectedCell) {
  //     this.$selectedCell.addClass('cd-selected');
  // }

};

WeekTable.prototype.getVisiblePeriod = function () {
  return {
    startTime: this._week,
    endTime: new Date(this._week.getTime() + _datetime.MILLIS_PER_DAY * 7)
  };
};

WeekTable.prototype.prevPeriod = function () {
  var newDate = new Date(this._week.getTime() - _datetime.MILLIS_PER_DAY * 7);
  this.focusInto(newDate);
  return newDate;
};

WeekTable.prototype.nextPeriod = function () {
  var newDate = new Date(this._week.getTime() + _datetime.MILLIS_PER_DAY * 7);
  this.focusInto(newDate);
  return newDate;
};

WeekTable.prototype.focusInto = function (date) {
  var startTime = this.startTime;
  var endTime = this.endTime;

  if ((0, _datetime.compareDate)(date, startTime, false) < 0 || (0, _datetime.compareDate)(endTime, date, false) <= 0) {
    this.focusDate = date;
  }

  this.selectDate(date);
  this.notifyPeriodChangeIfNeed();
};

WeekTable.prototype.notifyPeriodChange = function () {
  this.emit('visibleperiodchange', {
    target: this,
    visiblePeriod: this._lastVisiblePeriod || this.getVisiblePeriod()
  }, this);
};

WeekTable.prototype.notifyPeriodChangeIfNeed = function () {
  var currentVisiblePeriod = this.getVisiblePeriod();

  if (!this._lastVisiblePeriod || (0, _datetime.compareDate)(currentVisiblePeriod.startTime, this._lastVisiblePeriod.startTime) !== 0) {
    this._lastVisiblePeriod = currentVisiblePeriod;
    this.notifyPeriodChange();
  }
};

WeekTable.prototype.updateCardPosition = function () {
  var thisWT = this;

  this._clearDayPlaceHolder();

  var segments = [];
  var activities = this.activities.slice();
  activities.sort(_MonthTable.ItemCmp);
  var sf = new _SegmentFinder.default();
  var singleCActivitys = [];
  var act;
  var segments;

  while (activities.length > 0) {
    act = activities.shift();

    if (act.isSingleDay()) {
      singleCActivitys.push(act);
      continue;
    }

    segments = act.getVisibleDaySegments();
    segments.forEach(function (seg) {
      var pHolder = thisWT._makeOneDayPlaceHolder();

      pHolder.addChild(seg.$item);
      var cell = thisWT.getDayCellByDate(seg.startTime);

      if (cell) {
        var idx = (0, _datetime.compareDate)(seg.startTime, thisWT._week);
        var yMin = sf.getMinYFreeAt(idx);

        thisWT._fillDayHolderToCell(cell, yMin);

        cell.addChild(pHolder);
        sf.push(idx, idx + seg.dayLength, yMin, seg);
      } else {
        throw new Error("Bug");
      }
    });
  }

  this._clearHourPlaceHolder();

  var sm = new _SegmentMerger.default();

  while (singleCActivitys.length > 0) {
    act = singleCActivitys.shift();
    sm.addItem(act, act.startTime.getTime(), act.endTime.getTime() - act.startTime.getTime());
  }

  var week = this._week;
  var minTop = 10000000;
  var topHourItem = null;
  sm.segments.forEach(function (group) {
    var startTime = (0, _datetime.beginOfDay)(new Date(group.start));
    var colIdx = (0, _datetime.compareDate)(startTime, week);
    if (colIdx < 0 || colIdx >= 7) return; // out of calendar

    var firsCell = thisWT.$hours[colIdx];
    /**
     * @type {Array<CActivity>}
     */

    var activities = group.items;

    var holder = thisWT._makeOneHourPlaceHolder();

    firsCell.addChild(holder);
    var segments = activities.map(function (act) {
      return act.getVisibleHourSegment();
    });
    var sf = new _SegmentFinder.default();
    segments.sort(function (a, b) {
      var d = a.startTime.getTime() - b.startTime.getTime();
      if (d == 0) d = b.endTime.getTime() - a.endTime.getTime();
      return d;
    });
    segments.forEach(function (segment) {
      var y = sf.getMinYFreeAt(segment.startTime.getTime());
      sf.push(segment.startTime.getTime(), segment.endTime.getTime(), y, segment);
    });
    var nCol = sf.getMaxY() + 1;
    holder.style.setProperty('--child-width', 100 / nCol + '%');
    sf.segments.forEach(function (seg) {
      var itemElt = seg.data.$item;
      var top = (seg.data.startTime.getTime() - startTime.getTime()) / _datetime.MILLIS_PER_HOUR * 100;

      if (top < minTop) {
        minTop = top;
        topHourItem = itemElt;
      }

      itemElt.addStyle({
        left: 100 * seg.y / nCol + '%',
        top: top + '%'
      });
      holder.addChild(itemElt);
    });
  });
  this.updateSize();

  if (topHourItem) {
    this.$body.scrollTop = (this.$body.getFontSize() * 4 + 1) * minTop / 100;
  }
};
/**
 * @param {import('./CActivity').MonthTableItemProperty} props
 */


WeekTable.prototype.addActivity = function (props) {
  var mc = new _CActivity.default(this, props);
  mc.on('click', this.eventHandler.clickActivity).on('mouseenter', this.eventHandler.enterActivity).on('mouseleave', this.eventHandler.leaveActivity);
  this.activities.push(mc);
  this.requestUpdateCardPosition();
  return mc;
};
/**
 * @param {CActivity} act
 */


WeekTable.prototype.removeActivity = function (act) {
  var cardIndex = this.activities.indexOf(act);

  if (cardIndex >= 0) {
    this.activities.splice(cardIndex, 1);
    act.removeAllSegment();
    act.$table = null;
    act.off('mouseenter', this.eventHandler.enterActivity).off('mouseleave', this.eventHandler.leaveActivity).off('dragstart', this.eventHandler.dragStartCard).off('dragend', this.eventHandler.dragEndCard).off('drag', this.eventHandler.dragCard);
  } else {
    throw new Error("Card is not a member of MonthTable");
  }

  this.requestUpdateCardPosition();
};

WeekTable.prototype.removeAllActivity = function () {
  var act;

  for (var i = 0; i < this.activities.length; ++i) {
    act = this.activities[i];
    act.removeAllDaySegment();
    act.$table = null;
    act.off('mouseenter', this.eventHandler.enterActivity).off('mouseleave', this.eventHandler.leaveActivity);
  }

  this.activities = [];
  this.requestUpdateCardPosition();
};
/**
 * @param {CActivity} act
 */


WeekTable.prototype.containsActivity = function (act) {
  var cardIndex = this.activities.indexOf(act);
  return cardIndex >= 0;
};

WeekTable.prototype._updateClonedCActivityPosition = function () {
  this._clearClonedDayPlaceHolder();

  var thisWT = this;
  this.clonedSegments = this.clonedCard.getVisibleDaySegments();
  this.clonedSegments.forEach(function (seg) {
    var pHolder = thisWT._makeOneClonedDayPlaceHolder();

    var cell = thisWT.getDayCellByDate(seg.startTime);
    var cellBound = cell.getBoundingClientRect();
    var contentBound = thisWT.$multidayContent.getBoundingClientRect();
    var firstHolder = $('.cd-week-table-day-item-place-holder', cell.parentElement);

    if (firstHolder) {
      var holderBound = firstHolder.getBoundingClientRect();
      pHolder.addStyle({
        width: cellBound.width - 1 + 'px',
        left: cellBound.left - contentBound.left + 1 + 'px',
        top: holderBound.top - contentBound.top + 'px'
      });
    } else {
      pHolder.addStyle({
        width: cellBound.width - 1 + 'px',
        left: cellBound.left - contentBound.left + 1 + 'px',
        top: cellBound.top - contentBound.top + 30 + 'px'
      });
    }

    thisWT.$multidayContent.addChild(pHolder);
    pHolder.addChild(seg.$item);
  });
};

WeekTable.prototype.requestUpdateCardPosition = _MonthTable.default.prototype.requestUpdateCardPosition;

WeekTable.prototype.requestUpdateHourRows = function () {
  this.domSignal.emit('requestUpdateHourRows');
};

WeekTable.prototype.requestUpdateHours = function () {
  this.domSignal.emit('requestUpdateHours');
};

WeekTable.prototype.selectActivity = function (act) {
  if (act == this.activeActivity) return;

  if (this.activeActivity) {
    this.activeActivity.active = false;
    this.activeActivity.updateActive();
  }

  this.activeActivity = act;

  if (this.activeActivity) {
    this.activeActivity.active = true;
    this.activeActivity.updateActive();
  }
};

WeekTable.property = {};
/**
 * @type {WeekTable}
 */

WeekTable.property.focusDate = {
  set: function (date) {
    if ((0, _datetime.compareDate)(this._focusDate, date) == 0) return;
    this._focusDate = date;
    this._week = (0, _datetime.beginOfWeek)(date, false, this._firstDayOfWeek);

    this._updateDays();

    this.requestUpdateCardPosition();
  },
  get: function () {
    return this._focusDate;
  }
};
WeekTable.property.startTime = {
  get: function () {
    return this._week;
  }
};
WeekTable.property.endTime = {
  get: function () {
    return new Date(this._week.getTime() + _datetime.MILLIS_PER_DAY * 7);
  }
};
/**
 * @type {WeekTable}
 */

WeekTable.property.firstDayOfWeek = {
  set: function set(value) {
    if (!(value >= 0 && value < 7)) {
      value = 0;
    }

    if (this._firstDayOfWeek == value) return;
    this._firstDayOfWeek = value;
    this._week = (0, _datetime.beginOfWeek)(this._focusDate, false, this._firstDayOfWeek);
    this.$dayOfWeekRow.firstDay = value;

    this._updateDays();

    this.requestUpdateHours();
    this.requestUpdateCardPosition();
  },
  get: function get() {
    return this._firstDayOfWeek;
  }
};
/**
 * @type {WeekTable}
 */

WeekTable.property.workHourStart = {
  set: function (value) {
    this._workHourStart = value;
    this.requestUpdateHourRows();
  },
  get: function () {
    return this._workHourStart;
  }
};
/**
 * @type {WeekTable}
 */

WeekTable.property.workHourEnd = {
  set: function (value) {
    this._workHourEnd = value;
    this.requestUpdateHourRows();
  },
  get: function () {
    return this._workHourEnd;
  }
};
/**
 * @type {WeekTable}
 */

WeekTable.property.daysOff = {
  set: function (value) {
    value = value || [];
    var contentElt = this.$content;

    this._daysOff.forEach(function (d) {
      contentElt.removeClass('cd-off-day-' + d);
    });

    this._daysOff = value;

    this._daysOff.forEach(function (d) {
      contentElt.addClass('cd-off-day-' + d);
    });
  },
  get: function () {
    return this._daysOff;
  }
};
/**
 * @type {WeekTable}
 */

WeekTable.eventHandler = {}; // WeekTable.eventHandler.clickDay = function (idx, event) {
//     var target = event.target;
//     if (target.containsClass
//         && (target.containsClass('cd-month-table-day')
//         )
//     ) {
//         this.selectDate(this.dayOfCell(idx))
//     }
// };

/**
 * @param {MouseEvent} event
 * @param {CActivity} sender
 */

WeekTable.eventHandler.clickActivity = function (event, sender) {
  this.selectActivity(sender);
  this.selectDate(null);
};
/**
 * @param {MouseEvent} event
 * @param {CActivity} sender
 */


WeekTable.eventHandler.enterActivity = function (event, sender) {
  if (this._showTooltipTimeout > 0) {
    clearTimeout(this._showTooltipTimeout);
    this._showTooltipTimeout = -1;
  }

  var pos = new _Vec.default(event.clientX, event.clientY);
  this._showTooltipOf = sender;
  this._showTooltipTimeout = setTimeout(function () {
    sender.tooltipToken = _CActivityTooltip.default.show(pos, {
      name: sender.name,
      time: sender.getTimeText(),
      board: sender.boardName || '',
      list: sender.listName || '',
      card: sender.cardName || ''
    });
  }, 200);
};
/**
 * @param {MouseEvent} event
 * @param {CActivity} event
 */


WeekTable.eventHandler.leaveActivity = function (event, sender) {
  if (this._showTooltipOf == sender && this._showTooltipTimeout > 0) {
    clearTimeout(this._showTooltipTimeout);
    this._showTooltipTimeout = -1;
  }

  _CActivityTooltip.default.close(sender.tooltipToken);
};

WeekTable.eventHandler.dragEndCard = function (event, sender) {
  return;
  this.getTimeByPosition(event.clientX, event.clientY);
  return;

  if (this.clonedCard) {
    if (this.clonedCard.cloneFrom.startTime.getTime() != this.clonedCard.startTime.getTime() || this.clonedCard.cloneFrom.endTime.getTime() != this.clonedCard.endTime.getTime()) {
      //TODO: emit event or call plugin
      this.clonedCard.cloneFrom.startTime = this.clonedCard.startTime;
      this.clonedCard.cloneFrom.endTime = this.clonedCard.endTime;
      this.updateCardPosition();
    }

    this.clonedCard.remove();

    this._clearClonedDayPlaceHolder();

    this.clonedCard = null;
  }

  document.body.classList.remove('cd-moving-activity');
};

WeekTable.eventHandler.dragStartCard = function (event, sender) {
  return;
  this.getTimeByPosition(event.clientX, event.clientY);
  return;
  this._dragTimeFactor = [1, 1];

  if (event.target.classList.contains('cd-month-table-item-right-drag-line')) {
    this._dragTimeFactor[0] = 0;
  } else if (event.target.classList.contains('cd-month-table-item-left-drag-line')) {
    this._dragTimeFactor[1] = 0;
  }

  this.eventHandler.clickActivity(event, sender);
  this.clonedCard = this.activeActivity.clone();
  this._initCloneIdx = this.getCellIdxByPosition(event.clientX, event.clientY);
  this._currentCloneIdx = this._initCloneIdx;

  this._updateClonedCActivityPosition();

  document.body.classList.add('cd-moving-activity');
};

WeekTable.eventHandler.dragCard = function (event, sender) {
  return;
  var timeInfo = this.getTimeByPosition(event.clientX, event.clientY);
  if (!timeInfo) return;
  return;
  var newIdx = this.getCellIdxByPosition(event.clientX, event.clientY);

  if (newIdx != -1 && newIdx != this._currentCloneIdx) {
    this._currentCloneIdx = newIdx;
    var dMil = _datetime.MILLIS_PER_DAY * (newIdx - this._initCloneIdx);

    var newStartTimeMil = this.clonedCard.cloneFrom.startTime.getTime() + dMil * this._dragTimeFactor[0];

    var newEndTimeMil = this.clonedCard.cloneFrom.endTime.getTime() + dMil * this._dragTimeFactor[1];

    if (newEndTimeMil > newStartTimeMil) {
      //valid time
      this.clonedCard.startTime = new Date(newStartTimeMil);
      this.clonedCard.endTime = new Date(newEndTimeMil);

      this._updateClonedCActivityPosition();
    }
  }
};
/***
 *
 * @param {MouseEvent} event
 */


WeekTable.eventHandler.clickWeekRow = function (event) {
  var target = event.target;

  if (target.containsClass && target.containsClass('cd-day-cell')) {
    var time = this._getTimeByPosition(event.clientX, event.clientY);

    if (time.type === 0) {
      this.selectedTime.vlue = time.time;
    }

    this.selectDate(this._getTimeByPosition(event.clientX, event.clientY).time);
    this.selectActivity(null);
  }
};

WeekTable.eventHandler.clickHourTable = function (event) {
  var time = this._getTimeByPosition(event.clientX, event.clientY).time;

  this.selectHour(time);
  this.selectActivity(null); // var bound = cellElt.getBoundingClientRect();
  // var dmil = 0;
  // if (event.clientY > bound.top + bound.height / 2) {
  //     dmil = MILLIS_PER_HOUR / 2;
  // }
  // console.log(idx);
  // this.selectedTime.type = 1;
  // this.selectedTime.time = new Date(this.hourOfCell(idx).getTime() + dmil);
  // console.log(this.selectedTime);
  // // this._updateSelectedCell();
};

_Core.default.install(WeekTable);

var _default = WeekTable;
exports.default = _default;

VaKeR 2022