1/* 2@license 3 4dhtmlxGantt v.6.3.5 Standard 5 6This version of dhtmlxGantt is distributed under GPL 2.0 license and can be legally used in GPL projects. 7 8To use dhtmlxGantt in non-GPL projects (and get Pro version of the product), please obtain Commercial/Enterprise or Ultimate license on our site https://dhtmlx.com/docs/products/dhtmlxGantt/#licensing or contact us at sales@dhtmlx.com 9 10(c) XB Software Ltd. 11 12*/ 13(function webpackUniversalModuleDefinition(root, factory) { 14 if(typeof exports === 'object' && typeof module === 'object') 15 module.exports = factory(); 16 else if(typeof define === 'function' && define.amd) 17 define("dhtmlxgantt", [], factory); 18 else if(typeof exports === 'object') 19 exports["dhtmlxgantt"] = factory(); 20 else 21 root["dhtmlxgantt"] = factory(); 22})(window, function() { 23return /******/ (function(modules) { // webpackBootstrap 24/******/ // The module cache 25/******/ var installedModules = {}; 26/******/ 27/******/ // The require function 28/******/ function __webpack_require__(moduleId) { 29/******/ 30/******/ // Check if module is in cache 31/******/ if(installedModules[moduleId]) { 32/******/ return installedModules[moduleId].exports; 33/******/ } 34/******/ // Create a new module (and put it into the cache) 35/******/ var module = installedModules[moduleId] = { 36/******/ i: moduleId, 37/******/ l: false, 38/******/ exports: {} 39/******/ }; 40/******/ 41/******/ // Execute the module function 42/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 43/******/ 44/******/ // Flag the module as loaded 45/******/ module.l = true; 46/******/ 47/******/ // Return the exports of the module 48/******/ return module.exports; 49/******/ } 50/******/ 51/******/ 52/******/ // expose the modules object (__webpack_modules__) 53/******/ __webpack_require__.m = modules; 54/******/ 55/******/ // expose the module cache 56/******/ __webpack_require__.c = installedModules; 57/******/ 58/******/ // define getter function for harmony exports 59/******/ __webpack_require__.d = function(exports, name, getter) { 60/******/ if(!__webpack_require__.o(exports, name)) { 61/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 62/******/ } 63/******/ }; 64/******/ 65/******/ // define __esModule on exports 66/******/ __webpack_require__.r = function(exports) { 67/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 68/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 69/******/ } 70/******/ Object.defineProperty(exports, '__esModule', { value: true }); 71/******/ }; 72/******/ 73/******/ // create a fake namespace object 74/******/ // mode & 1: value is a module id, require it 75/******/ // mode & 2: merge all properties of value into the ns 76/******/ // mode & 4: return value when already ns object 77/******/ // mode & 8|1: behave like require 78/******/ __webpack_require__.t = function(value, mode) { 79/******/ if(mode & 1) value = __webpack_require__(value); 80/******/ if(mode & 8) return value; 81/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 82/******/ var ns = Object.create(null); 83/******/ __webpack_require__.r(ns); 84/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 85/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 86/******/ return ns; 87/******/ }; 88/******/ 89/******/ // getDefaultExport function for compatibility with non-harmony modules 90/******/ __webpack_require__.n = function(module) { 91/******/ var getter = module && module.__esModule ? 92/******/ function getDefault() { return module['default']; } : 93/******/ function getModuleExports() { return module; }; 94/******/ __webpack_require__.d(getter, 'a', getter); 95/******/ return getter; 96/******/ }; 97/******/ 98/******/ // Object.prototype.hasOwnProperty.call 99/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 100/******/ 101/******/ // __webpack_public_path__ 102/******/ __webpack_require__.p = "/codebase/sources/"; 103/******/ 104/******/ 105/******/ // Load entry module and return exports 106/******/ return __webpack_require__(__webpack_require__.s = "./sources/dhtmlxgantt.gpl.ts"); 107/******/ }) 108/************************************************************************/ 109/******/ ({ 110 111/***/ "./node_modules/bluebird/js/browser/bluebird.js": 112/*!******************************************************!*\ 113 !*** ./node_modules/bluebird/js/browser/bluebird.js ***! 114 \******************************************************/ 115/*! no static exports found */ 116/***/ (function(module, exports, __webpack_require__) { 117 118/* WEBPACK VAR INJECTION */(function(process, global, setImmediate) {/* @preserve 119 * The MIT License (MIT) 120 * 121 * Copyright (c) 2013-2018 Petka Antonov 122 * 123 * Permission is hereby granted, free of charge, to any person obtaining a copy 124 * of this software and associated documentation files (the "Software"), to deal 125 * in the Software without restriction, including without limitation the rights 126 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 127 * copies of the Software, and to permit persons to whom the Software is 128 * furnished to do so, subject to the following conditions: 129 * 130 * The above copyright notice and this permission notice shall be included in 131 * all copies or substantial portions of the Software. 132 * 133 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 134 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 135 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 136 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 137 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 138 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 139 * THE SOFTWARE. 140 * 141 */ 142/** 143 * bluebird build version 3.5.4 144 * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each 145*/ 146!function(e){if(true)module.exports=e();else { var f; }}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ 147"use strict"; 148module.exports = function(Promise) { 149var SomePromiseArray = Promise._SomePromiseArray; 150function any(promises) { 151 var ret = new SomePromiseArray(promises); 152 var promise = ret.promise(); 153 ret.setHowMany(1); 154 ret.setUnwrap(); 155 ret.init(); 156 return promise; 157} 158 159Promise.any = function (promises) { 160 return any(promises); 161}; 162 163Promise.prototype.any = function () { 164 return any(this); 165}; 166 167}; 168 169},{}],2:[function(_dereq_,module,exports){ 170"use strict"; 171var firstLineError; 172try {throw new Error(); } catch (e) {firstLineError = e;} 173var schedule = _dereq_("./schedule"); 174var Queue = _dereq_("./queue"); 175var util = _dereq_("./util"); 176 177function Async() { 178 this._customScheduler = false; 179 this._isTickUsed = false; 180 this._lateQueue = new Queue(16); 181 this._normalQueue = new Queue(16); 182 this._haveDrainedQueues = false; 183 this._trampolineEnabled = true; 184 var self = this; 185 this.drainQueues = function () { 186 self._drainQueues(); 187 }; 188 this._schedule = schedule; 189} 190 191Async.prototype.setScheduler = function(fn) { 192 var prev = this._schedule; 193 this._schedule = fn; 194 this._customScheduler = true; 195 return prev; 196}; 197 198Async.prototype.hasCustomScheduler = function() { 199 return this._customScheduler; 200}; 201 202Async.prototype.enableTrampoline = function() { 203 this._trampolineEnabled = true; 204}; 205 206Async.prototype.disableTrampolineIfNecessary = function() { 207 if (util.hasDevTools) { 208 this._trampolineEnabled = false; 209 } 210}; 211 212Async.prototype.haveItemsQueued = function () { 213 return this._isTickUsed || this._haveDrainedQueues; 214}; 215 216 217Async.prototype.fatalError = function(e, isNode) { 218 if (isNode) { 219 process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e) + 220 "\n"); 221 process.exit(2); 222 } else { 223 this.throwLater(e); 224 } 225}; 226 227Async.prototype.throwLater = function(fn, arg) { 228 if (arguments.length === 1) { 229 arg = fn; 230 fn = function () { throw arg; }; 231 } 232 if (typeof setTimeout !== "undefined") { 233 setTimeout(function() { 234 fn(arg); 235 }, 0); 236 } else try { 237 this._schedule(function() { 238 fn(arg); 239 }); 240 } catch (e) { 241 throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 242 } 243}; 244 245function AsyncInvokeLater(fn, receiver, arg) { 246 this._lateQueue.push(fn, receiver, arg); 247 this._queueTick(); 248} 249 250function AsyncInvoke(fn, receiver, arg) { 251 this._normalQueue.push(fn, receiver, arg); 252 this._queueTick(); 253} 254 255function AsyncSettlePromises(promise) { 256 this._normalQueue._pushOne(promise); 257 this._queueTick(); 258} 259 260if (!util.hasDevTools) { 261 Async.prototype.invokeLater = AsyncInvokeLater; 262 Async.prototype.invoke = AsyncInvoke; 263 Async.prototype.settlePromises = AsyncSettlePromises; 264} else { 265 Async.prototype.invokeLater = function (fn, receiver, arg) { 266 if (this._trampolineEnabled) { 267 AsyncInvokeLater.call(this, fn, receiver, arg); 268 } else { 269 this._schedule(function() { 270 setTimeout(function() { 271 fn.call(receiver, arg); 272 }, 100); 273 }); 274 } 275 }; 276 277 Async.prototype.invoke = function (fn, receiver, arg) { 278 if (this._trampolineEnabled) { 279 AsyncInvoke.call(this, fn, receiver, arg); 280 } else { 281 this._schedule(function() { 282 fn.call(receiver, arg); 283 }); 284 } 285 }; 286 287 Async.prototype.settlePromises = function(promise) { 288 if (this._trampolineEnabled) { 289 AsyncSettlePromises.call(this, promise); 290 } else { 291 this._schedule(function() { 292 promise._settlePromises(); 293 }); 294 } 295 }; 296} 297 298function _drainQueue(queue) { 299 while (queue.length() > 0) { 300 _drainQueueStep(queue); 301 } 302} 303 304function _drainQueueStep(queue) { 305 var fn = queue.shift(); 306 if (typeof fn !== "function") { 307 fn._settlePromises(); 308 } else { 309 var receiver = queue.shift(); 310 var arg = queue.shift(); 311 fn.call(receiver, arg); 312 } 313} 314 315Async.prototype._drainQueues = function () { 316 _drainQueue(this._normalQueue); 317 this._reset(); 318 this._haveDrainedQueues = true; 319 _drainQueue(this._lateQueue); 320}; 321 322Async.prototype._queueTick = function () { 323 if (!this._isTickUsed) { 324 this._isTickUsed = true; 325 this._schedule(this.drainQueues); 326 } 327}; 328 329Async.prototype._reset = function () { 330 this._isTickUsed = false; 331}; 332 333module.exports = Async; 334module.exports.firstLineError = firstLineError; 335 336},{"./queue":26,"./schedule":29,"./util":36}],3:[function(_dereq_,module,exports){ 337"use strict"; 338module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) { 339var calledBind = false; 340var rejectThis = function(_, e) { 341 this._reject(e); 342}; 343 344var targetRejected = function(e, context) { 345 context.promiseRejectionQueued = true; 346 context.bindingPromise._then(rejectThis, rejectThis, null, this, e); 347}; 348 349var bindingResolved = function(thisArg, context) { 350 if (((this._bitField & 50397184) === 0)) { 351 this._resolveCallback(context.target); 352 } 353}; 354 355var bindingRejected = function(e, context) { 356 if (!context.promiseRejectionQueued) this._reject(e); 357}; 358 359Promise.prototype.bind = function (thisArg) { 360 if (!calledBind) { 361 calledBind = true; 362 Promise.prototype._propagateFrom = debug.propagateFromFunction(); 363 Promise.prototype._boundValue = debug.boundValueFunction(); 364 } 365 var maybePromise = tryConvertToPromise(thisArg); 366 var ret = new Promise(INTERNAL); 367 ret._propagateFrom(this, 1); 368 var target = this._target(); 369 ret._setBoundTo(maybePromise); 370 if (maybePromise instanceof Promise) { 371 var context = { 372 promiseRejectionQueued: false, 373 promise: ret, 374 target: target, 375 bindingPromise: maybePromise 376 }; 377 target._then(INTERNAL, targetRejected, undefined, ret, context); 378 maybePromise._then( 379 bindingResolved, bindingRejected, undefined, ret, context); 380 ret._setOnCancel(maybePromise); 381 } else { 382 ret._resolveCallback(target); 383 } 384 return ret; 385}; 386 387Promise.prototype._setBoundTo = function (obj) { 388 if (obj !== undefined) { 389 this._bitField = this._bitField | 2097152; 390 this._boundTo = obj; 391 } else { 392 this._bitField = this._bitField & (~2097152); 393 } 394}; 395 396Promise.prototype._isBound = function () { 397 return (this._bitField & 2097152) === 2097152; 398}; 399 400Promise.bind = function (thisArg, value) { 401 return Promise.resolve(value).bind(thisArg); 402}; 403}; 404 405},{}],4:[function(_dereq_,module,exports){ 406"use strict"; 407var old; 408if (typeof Promise !== "undefined") old = Promise; 409function noConflict() { 410 try { if (Promise === bluebird) Promise = old; } 411 catch (e) {} 412 return bluebird; 413} 414var bluebird = _dereq_("./promise")(); 415bluebird.noConflict = noConflict; 416module.exports = bluebird; 417 418},{"./promise":22}],5:[function(_dereq_,module,exports){ 419"use strict"; 420var cr = Object.create; 421if (cr) { 422 var callerCache = cr(null); 423 var getterCache = cr(null); 424 callerCache[" size"] = getterCache[" size"] = 0; 425} 426 427module.exports = function(Promise) { 428var util = _dereq_("./util"); 429var canEvaluate = util.canEvaluate; 430var isIdentifier = util.isIdentifier; 431 432var getMethodCaller; 433var getGetter; 434if (false) { var getCompiled, makeGetter, makeMethodCaller; } 435 436function ensureMethod(obj, methodName) { 437 var fn; 438 if (obj != null) fn = obj[methodName]; 439 if (typeof fn !== "function") { 440 var message = "Object " + util.classString(obj) + " has no method '" + 441 util.toString(methodName) + "'"; 442 throw new Promise.TypeError(message); 443 } 444 return fn; 445} 446 447function caller(obj) { 448 var methodName = this.pop(); 449 var fn = ensureMethod(obj, methodName); 450 return fn.apply(obj, this); 451} 452Promise.prototype.call = function (methodName) { 453 var args = [].slice.call(arguments, 1);; 454 if (false) { var maybeCaller; } 455 args.push(methodName); 456 return this._then(caller, undefined, undefined, args, undefined); 457}; 458 459function namedGetter(obj) { 460 return obj[this]; 461} 462function indexedGetter(obj) { 463 var index = +this; 464 if (index < 0) index = Math.max(0, index + obj.length); 465 return obj[index]; 466} 467Promise.prototype.get = function (propertyName) { 468 var isIndex = (typeof propertyName === "number"); 469 var getter; 470 if (!isIndex) { 471 if (canEvaluate) { 472 var maybeGetter = getGetter(propertyName); 473 getter = maybeGetter !== null ? maybeGetter : namedGetter; 474 } else { 475 getter = namedGetter; 476 } 477 } else { 478 getter = indexedGetter; 479 } 480 return this._then(getter, undefined, undefined, propertyName, undefined); 481}; 482}; 483 484},{"./util":36}],6:[function(_dereq_,module,exports){ 485"use strict"; 486module.exports = function(Promise, PromiseArray, apiRejection, debug) { 487var util = _dereq_("./util"); 488var tryCatch = util.tryCatch; 489var errorObj = util.errorObj; 490var async = Promise._async; 491 492Promise.prototype["break"] = Promise.prototype.cancel = function() { 493 if (!debug.cancellation()) return this._warn("cancellation is disabled"); 494 495 var promise = this; 496 var child = promise; 497 while (promise._isCancellable()) { 498 if (!promise._cancelBy(child)) { 499 if (child._isFollowing()) { 500 child._followee().cancel(); 501 } else { 502 child._cancelBranched(); 503 } 504 break; 505 } 506 507 var parent = promise._cancellationParent; 508 if (parent == null || !parent._isCancellable()) { 509 if (promise._isFollowing()) { 510 promise._followee().cancel(); 511 } else { 512 promise._cancelBranched(); 513 } 514 break; 515 } else { 516 if (promise._isFollowing()) promise._followee().cancel(); 517 promise._setWillBeCancelled(); 518 child = promise; 519 promise = parent; 520 } 521 } 522}; 523 524Promise.prototype._branchHasCancelled = function() { 525 this._branchesRemainingToCancel--; 526}; 527 528Promise.prototype._enoughBranchesHaveCancelled = function() { 529 return this._branchesRemainingToCancel === undefined || 530 this._branchesRemainingToCancel <= 0; 531}; 532 533Promise.prototype._cancelBy = function(canceller) { 534 if (canceller === this) { 535 this._branchesRemainingToCancel = 0; 536 this._invokeOnCancel(); 537 return true; 538 } else { 539 this._branchHasCancelled(); 540 if (this._enoughBranchesHaveCancelled()) { 541 this._invokeOnCancel(); 542 return true; 543 } 544 } 545 return false; 546}; 547 548Promise.prototype._cancelBranched = function() { 549 if (this._enoughBranchesHaveCancelled()) { 550 this._cancel(); 551 } 552}; 553 554Promise.prototype._cancel = function() { 555 if (!this._isCancellable()) return; 556 this._setCancelled(); 557 async.invoke(this._cancelPromises, this, undefined); 558}; 559 560Promise.prototype._cancelPromises = function() { 561 if (this._length() > 0) this._settlePromises(); 562}; 563 564Promise.prototype._unsetOnCancel = function() { 565 this._onCancelField = undefined; 566}; 567 568Promise.prototype._isCancellable = function() { 569 return this.isPending() && !this._isCancelled(); 570}; 571 572Promise.prototype.isCancellable = function() { 573 return this.isPending() && !this.isCancelled(); 574}; 575 576Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) { 577 if (util.isArray(onCancelCallback)) { 578 for (var i = 0; i < onCancelCallback.length; ++i) { 579 this._doInvokeOnCancel(onCancelCallback[i], internalOnly); 580 } 581 } else if (onCancelCallback !== undefined) { 582 if (typeof onCancelCallback === "function") { 583 if (!internalOnly) { 584 var e = tryCatch(onCancelCallback).call(this._boundValue()); 585 if (e === errorObj) { 586 this._attachExtraTrace(e.e); 587 async.throwLater(e.e); 588 } 589 } 590 } else { 591 onCancelCallback._resultCancelled(this); 592 } 593 } 594}; 595 596Promise.prototype._invokeOnCancel = function() { 597 var onCancelCallback = this._onCancel(); 598 this._unsetOnCancel(); 599 async.invoke(this._doInvokeOnCancel, this, onCancelCallback); 600}; 601 602Promise.prototype._invokeInternalOnCancel = function() { 603 if (this._isCancellable()) { 604 this._doInvokeOnCancel(this._onCancel(), true); 605 this._unsetOnCancel(); 606 } 607}; 608 609Promise.prototype._resultCancelled = function() { 610 this.cancel(); 611}; 612 613}; 614 615},{"./util":36}],7:[function(_dereq_,module,exports){ 616"use strict"; 617module.exports = function(NEXT_FILTER) { 618var util = _dereq_("./util"); 619var getKeys = _dereq_("./es5").keys; 620var tryCatch = util.tryCatch; 621var errorObj = util.errorObj; 622 623function catchFilter(instances, cb, promise) { 624 return function(e) { 625 var boundTo = promise._boundValue(); 626 predicateLoop: for (var i = 0; i < instances.length; ++i) { 627 var item = instances[i]; 628 629 if (item === Error || 630 (item != null && item.prototype instanceof Error)) { 631 if (e instanceof item) { 632 return tryCatch(cb).call(boundTo, e); 633 } 634 } else if (typeof item === "function") { 635 var matchesPredicate = tryCatch(item).call(boundTo, e); 636 if (matchesPredicate === errorObj) { 637 return matchesPredicate; 638 } else if (matchesPredicate) { 639 return tryCatch(cb).call(boundTo, e); 640 } 641 } else if (util.isObject(e)) { 642 var keys = getKeys(item); 643 for (var j = 0; j < keys.length; ++j) { 644 var key = keys[j]; 645 if (item[key] != e[key]) { 646 continue predicateLoop; 647 } 648 } 649 return tryCatch(cb).call(boundTo, e); 650 } 651 } 652 return NEXT_FILTER; 653 }; 654} 655 656return catchFilter; 657}; 658 659},{"./es5":13,"./util":36}],8:[function(_dereq_,module,exports){ 660"use strict"; 661module.exports = function(Promise) { 662var longStackTraces = false; 663var contextStack = []; 664 665Promise.prototype._promiseCreated = function() {}; 666Promise.prototype._pushContext = function() {}; 667Promise.prototype._popContext = function() {return null;}; 668Promise._peekContext = Promise.prototype._peekContext = function() {}; 669 670function Context() { 671 this._trace = new Context.CapturedTrace(peekContext()); 672} 673Context.prototype._pushContext = function () { 674 if (this._trace !== undefined) { 675 this._trace._promiseCreated = null; 676 contextStack.push(this._trace); 677 } 678}; 679 680Context.prototype._popContext = function () { 681 if (this._trace !== undefined) { 682 var trace = contextStack.pop(); 683 var ret = trace._promiseCreated; 684 trace._promiseCreated = null; 685 return ret; 686 } 687 return null; 688}; 689 690function createContext() { 691 if (longStackTraces) return new Context(); 692} 693 694function peekContext() { 695 var lastIndex = contextStack.length - 1; 696 if (lastIndex >= 0) { 697 return contextStack[lastIndex]; 698 } 699 return undefined; 700} 701Context.CapturedTrace = null; 702Context.create = createContext; 703Context.deactivateLongStackTraces = function() {}; 704Context.activateLongStackTraces = function() { 705 var Promise_pushContext = Promise.prototype._pushContext; 706 var Promise_popContext = Promise.prototype._popContext; 707 var Promise_PeekContext = Promise._peekContext; 708 var Promise_peekContext = Promise.prototype._peekContext; 709 var Promise_promiseCreated = Promise.prototype._promiseCreated; 710 Context.deactivateLongStackTraces = function() { 711 Promise.prototype._pushContext = Promise_pushContext; 712 Promise.prototype._popContext = Promise_popContext; 713 Promise._peekContext = Promise_PeekContext; 714 Promise.prototype._peekContext = Promise_peekContext; 715 Promise.prototype._promiseCreated = Promise_promiseCreated; 716 longStackTraces = false; 717 }; 718 longStackTraces = true; 719 Promise.prototype._pushContext = Context.prototype._pushContext; 720 Promise.prototype._popContext = Context.prototype._popContext; 721 Promise._peekContext = Promise.prototype._peekContext = peekContext; 722 Promise.prototype._promiseCreated = function() { 723 var ctx = this._peekContext(); 724 if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this; 725 }; 726}; 727return Context; 728}; 729 730},{}],9:[function(_dereq_,module,exports){ 731"use strict"; 732module.exports = function(Promise, Context) { 733var getDomain = Promise._getDomain; 734var async = Promise._async; 735var Warning = _dereq_("./errors").Warning; 736var util = _dereq_("./util"); 737var es5 = _dereq_("./es5"); 738var canAttachTrace = util.canAttachTrace; 739var unhandledRejectionHandled; 740var possiblyUnhandledRejection; 741var bluebirdFramePattern = 742 /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/; 743var nodeFramePattern = /\((?:timers\.js):\d+:\d+\)/; 744var parseLinePattern = /[\/<\(](.+?):(\d+):(\d+)\)?\s*$/; 745var stackFramePattern = null; 746var formatStack = null; 747var indentStackFrames = false; 748var printWarning; 749var debugging = !!(util.env("BLUEBIRD_DEBUG") != 0 && 750 (true || 751 util.env("BLUEBIRD_DEBUG") || 752 util.env("NODE_ENV") === "development")); 753 754var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 && 755 (debugging || util.env("BLUEBIRD_WARNINGS"))); 756 757var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 && 758 (debugging || util.env("BLUEBIRD_LONG_STACK_TRACES"))); 759 760var wForgottenReturn = util.env("BLUEBIRD_W_FORGOTTEN_RETURN") != 0 && 761 (warnings || !!util.env("BLUEBIRD_W_FORGOTTEN_RETURN")); 762 763Promise.prototype.suppressUnhandledRejections = function() { 764 var target = this._target(); 765 target._bitField = ((target._bitField & (~1048576)) | 766 524288); 767}; 768 769Promise.prototype._ensurePossibleRejectionHandled = function () { 770 if ((this._bitField & 524288) !== 0) return; 771 this._setRejectionIsUnhandled(); 772 var self = this; 773 setTimeout(function() { 774 self._notifyUnhandledRejection(); 775 }, 1); 776}; 777 778Promise.prototype._notifyUnhandledRejectionIsHandled = function () { 779 fireRejectionEvent("rejectionHandled", 780 unhandledRejectionHandled, undefined, this); 781}; 782 783Promise.prototype._setReturnedNonUndefined = function() { 784 this._bitField = this._bitField | 268435456; 785}; 786 787Promise.prototype._returnedNonUndefined = function() { 788 return (this._bitField & 268435456) !== 0; 789}; 790 791Promise.prototype._notifyUnhandledRejection = function () { 792 if (this._isRejectionUnhandled()) { 793 var reason = this._settledValue(); 794 this._setUnhandledRejectionIsNotified(); 795 fireRejectionEvent("unhandledRejection", 796 possiblyUnhandledRejection, reason, this); 797 } 798}; 799 800Promise.prototype._setUnhandledRejectionIsNotified = function () { 801 this._bitField = this._bitField | 262144; 802}; 803 804Promise.prototype._unsetUnhandledRejectionIsNotified = function () { 805 this._bitField = this._bitField & (~262144); 806}; 807 808Promise.prototype._isUnhandledRejectionNotified = function () { 809 return (this._bitField & 262144) > 0; 810}; 811 812Promise.prototype._setRejectionIsUnhandled = function () { 813 this._bitField = this._bitField | 1048576; 814}; 815 816Promise.prototype._unsetRejectionIsUnhandled = function () { 817 this._bitField = this._bitField & (~1048576); 818 if (this._isUnhandledRejectionNotified()) { 819 this._unsetUnhandledRejectionIsNotified(); 820 this._notifyUnhandledRejectionIsHandled(); 821 } 822}; 823 824Promise.prototype._isRejectionUnhandled = function () { 825 return (this._bitField & 1048576) > 0; 826}; 827 828Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) { 829 return warn(message, shouldUseOwnTrace, promise || this); 830}; 831 832Promise.onPossiblyUnhandledRejection = function (fn) { 833 var domain = getDomain(); 834 possiblyUnhandledRejection = 835 typeof fn === "function" ? (domain === null ? 836 fn : util.domainBind(domain, fn)) 837 : undefined; 838}; 839 840Promise.onUnhandledRejectionHandled = function (fn) { 841 var domain = getDomain(); 842 unhandledRejectionHandled = 843 typeof fn === "function" ? (domain === null ? 844 fn : util.domainBind(domain, fn)) 845 : undefined; 846}; 847 848var disableLongStackTraces = function() {}; 849Promise.longStackTraces = function () { 850 if (async.haveItemsQueued() && !config.longStackTraces) { 851 throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 852 } 853 if (!config.longStackTraces && longStackTracesIsSupported()) { 854 var Promise_captureStackTrace = Promise.prototype._captureStackTrace; 855 var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace; 856 var Promise_dereferenceTrace = Promise.prototype._dereferenceTrace; 857 config.longStackTraces = true; 858 disableLongStackTraces = function() { 859 if (async.haveItemsQueued() && !config.longStackTraces) { 860 throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 861 } 862 Promise.prototype._captureStackTrace = Promise_captureStackTrace; 863 Promise.prototype._attachExtraTrace = Promise_attachExtraTrace; 864 Promise.prototype._dereferenceTrace = Promise_dereferenceTrace; 865 Context.deactivateLongStackTraces(); 866 async.enableTrampoline(); 867 config.longStackTraces = false; 868 }; 869 Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace; 870 Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace; 871 Promise.prototype._dereferenceTrace = longStackTracesDereferenceTrace; 872 Context.activateLongStackTraces(); 873 async.disableTrampolineIfNecessary(); 874 } 875}; 876 877Promise.hasLongStackTraces = function () { 878 return config.longStackTraces && longStackTracesIsSupported(); 879}; 880 881var fireDomEvent = (function() { 882 try { 883 if (typeof CustomEvent === "function") { 884 var event = new CustomEvent("CustomEvent"); 885 util.global.dispatchEvent(event); 886 return function(name, event) { 887 var eventData = { 888 detail: event, 889 cancelable: true 890 }; 891 es5.defineProperty( 892 eventData, "promise", {value: event.promise}); 893 es5.defineProperty(eventData, "reason", {value: event.reason}); 894 var domEvent = new CustomEvent(name.toLowerCase(), eventData); 895 return !util.global.dispatchEvent(domEvent); 896 }; 897 } else if (typeof Event === "function") { 898 var event = new Event("CustomEvent"); 899 util.global.dispatchEvent(event); 900 return function(name, event) { 901 var domEvent = new Event(name.toLowerCase(), { 902 cancelable: true 903 }); 904 domEvent.detail = event; 905 es5.defineProperty(domEvent, "promise", {value: event.promise}); 906 es5.defineProperty(domEvent, "reason", {value: event.reason}); 907 return !util.global.dispatchEvent(domEvent); 908 }; 909 } else { 910 var event = document.createEvent("CustomEvent"); 911 event.initCustomEvent("testingtheevent", false, true, {}); 912 util.global.dispatchEvent(event); 913 return function(name, event) { 914 var domEvent = document.createEvent("CustomEvent"); 915 domEvent.initCustomEvent(name.toLowerCase(), false, true, 916 event); 917 return !util.global.dispatchEvent(domEvent); 918 }; 919 } 920 } catch (e) {} 921 return function() { 922 return false; 923 }; 924})(); 925 926var fireGlobalEvent = (function() { 927 if (util.isNode) { 928 return function() { 929 return process.emit.apply(process, arguments); 930 }; 931 } else { 932 if (!util.global) { 933 return function() { 934 return false; 935 }; 936 } 937 return function(name) { 938 var methodName = "on" + name.toLowerCase(); 939 var method = util.global[methodName]; 940 if (!method) return false; 941 method.apply(util.global, [].slice.call(arguments, 1)); 942 return true; 943 }; 944 } 945})(); 946 947function generatePromiseLifecycleEventObject(name, promise) { 948 return {promise: promise}; 949} 950 951var eventToObjectGenerator = { 952 promiseCreated: generatePromiseLifecycleEventObject, 953 promiseFulfilled: generatePromiseLifecycleEventObject, 954 promiseRejected: generatePromiseLifecycleEventObject, 955 promiseResolved: generatePromiseLifecycleEventObject, 956 promiseCancelled: generatePromiseLifecycleEventObject, 957 promiseChained: function(name, promise, child) { 958 return {promise: promise, child: child}; 959 }, 960 warning: function(name, warning) { 961 return {warning: warning}; 962 }, 963 unhandledRejection: function (name, reason, promise) { 964 return {reason: reason, promise: promise}; 965 }, 966 rejectionHandled: generatePromiseLifecycleEventObject 967}; 968 969var activeFireEvent = function (name) { 970 var globalEventFired = false; 971 try { 972 globalEventFired = fireGlobalEvent.apply(null, arguments); 973 } catch (e) { 974 async.throwLater(e); 975 globalEventFired = true; 976 } 977 978 var domEventFired = false; 979 try { 980 domEventFired = fireDomEvent(name, 981 eventToObjectGenerator[name].apply(null, arguments)); 982 } catch (e) { 983 async.throwLater(e); 984 domEventFired = true; 985 } 986 987 return domEventFired || globalEventFired; 988}; 989 990Promise.config = function(opts) { 991 opts = Object(opts); 992 if ("longStackTraces" in opts) { 993 if (opts.longStackTraces) { 994 Promise.longStackTraces(); 995 } else if (!opts.longStackTraces && Promise.hasLongStackTraces()) { 996 disableLongStackTraces(); 997 } 998 } 999 if ("warnings" in opts) { 1000 var warningsOption = opts.warnings; 1001 config.warnings = !!warningsOption; 1002 wForgottenReturn = config.warnings; 1003 1004 if (util.isObject(warningsOption)) { 1005 if ("wForgottenReturn" in warningsOption) { 1006 wForgottenReturn = !!warningsOption.wForgottenReturn; 1007 } 1008 } 1009 } 1010 if ("cancellation" in opts && opts.cancellation && !config.cancellation) { 1011 if (async.haveItemsQueued()) { 1012 throw new Error( 1013 "cannot enable cancellation after promises are in use"); 1014 } 1015 Promise.prototype._clearCancellationData = 1016 cancellationClearCancellationData; 1017 Promise.prototype._propagateFrom = cancellationPropagateFrom; 1018 Promise.prototype._onCancel = cancellationOnCancel; 1019 Promise.prototype._setOnCancel = cancellationSetOnCancel; 1020 Promise.prototype._attachCancellationCallback = 1021 cancellationAttachCancellationCallback; 1022 Promise.prototype._execute = cancellationExecute; 1023 propagateFromFunction = cancellationPropagateFrom; 1024 config.cancellation = true; 1025 } 1026 if ("monitoring" in opts) { 1027 if (opts.monitoring && !config.monitoring) { 1028 config.monitoring = true; 1029 Promise.prototype._fireEvent = activeFireEvent; 1030 } else if (!opts.monitoring && config.monitoring) { 1031 config.monitoring = false; 1032 Promise.prototype._fireEvent = defaultFireEvent; 1033 } 1034 } 1035 return Promise; 1036}; 1037 1038function defaultFireEvent() { return false; } 1039 1040Promise.prototype._fireEvent = defaultFireEvent; 1041Promise.prototype._execute = function(executor, resolve, reject) { 1042 try { 1043 executor(resolve, reject); 1044 } catch (e) { 1045 return e; 1046 } 1047}; 1048Promise.prototype._onCancel = function () {}; 1049Promise.prototype._setOnCancel = function (handler) { ; }; 1050Promise.prototype._attachCancellationCallback = function(onCancel) { 1051 ; 1052}; 1053Promise.prototype._captureStackTrace = function () {}; 1054Promise.prototype._attachExtraTrace = function () {}; 1055Promise.prototype._dereferenceTrace = function () {}; 1056Promise.prototype._clearCancellationData = function() {}; 1057Promise.prototype._propagateFrom = function (parent, flags) { 1058 ; 1059 ; 1060}; 1061 1062function cancellationExecute(executor, resolve, reject) { 1063 var promise = this; 1064 try { 1065 executor(resolve, reject, function(onCancel) { 1066 if (typeof onCancel !== "function") { 1067 throw new TypeError("onCancel must be a function, got: " + 1068 util.toString(onCancel)); 1069 } 1070 promise._attachCancellationCallback(onCancel); 1071 }); 1072 } catch (e) { 1073 return e; 1074 } 1075} 1076 1077function cancellationAttachCancellationCallback(onCancel) { 1078 if (!this._isCancellable()) return this; 1079 1080 var previousOnCancel = this._onCancel(); 1081 if (previousOnCancel !== undefined) { 1082 if (util.isArray(previousOnCancel)) { 1083 previousOnCancel.push(onCancel); 1084 } else { 1085 this._setOnCancel([previousOnCancel, onCancel]); 1086 } 1087 } else { 1088 this._setOnCancel(onCancel); 1089 } 1090} 1091 1092function cancellationOnCancel() { 1093 return this._onCancelField; 1094} 1095 1096function cancellationSetOnCancel(onCancel) { 1097 this._onCancelField = onCancel; 1098} 1099 1100function cancellationClearCancellationData() { 1101 this._cancellationParent = undefined; 1102 this._onCancelField = undefined; 1103} 1104 1105function cancellationPropagateFrom(parent, flags) { 1106 if ((flags & 1) !== 0) { 1107 this._cancellationParent = parent; 1108 var branchesRemainingToCancel = parent._branchesRemainingToCancel; 1109 if (branchesRemainingToCancel === undefined) { 1110 branchesRemainingToCancel = 0; 1111 } 1112 parent._branchesRemainingToCancel = branchesRemainingToCancel + 1; 1113 } 1114 if ((flags & 2) !== 0 && parent._isBound()) { 1115 this._setBoundTo(parent._boundTo); 1116 } 1117} 1118 1119function bindingPropagateFrom(parent, flags) { 1120 if ((flags & 2) !== 0 && parent._isBound()) { 1121 this._setBoundTo(parent._boundTo); 1122 } 1123} 1124var propagateFromFunction = bindingPropagateFrom; 1125 1126function boundValueFunction() { 1127 var ret = this._boundTo; 1128 if (ret !== undefined) { 1129 if (ret instanceof Promise) { 1130 if (ret.isFulfilled()) { 1131 return ret.value(); 1132 } else { 1133 return undefined; 1134 } 1135 } 1136 } 1137 return ret; 1138} 1139 1140function longStackTracesCaptureStackTrace() { 1141 this._trace = new CapturedTrace(this._peekContext()); 1142} 1143 1144function longStackTracesAttachExtraTrace(error, ignoreSelf) { 1145 if (canAttachTrace(error)) { 1146 var trace = this._trace; 1147 if (trace !== undefined) { 1148 if (ignoreSelf) trace = trace._parent; 1149 } 1150 if (trace !== undefined) { 1151 trace.attachExtraTrace(error); 1152 } else if (!error.__stackCleaned__) { 1153 var parsed = parseStackAndMessage(error); 1154 util.notEnumerableProp(error, "stack", 1155 parsed.message + "\n" + parsed.stack.join("\n")); 1156 util.notEnumerableProp(error, "__stackCleaned__", true); 1157 } 1158 } 1159} 1160 1161function longStackTracesDereferenceTrace() { 1162 this._trace = undefined; 1163} 1164 1165function checkForgottenReturns(returnValue, promiseCreated, name, promise, 1166 parent) { 1167 if (returnValue === undefined && promiseCreated !== null && 1168 wForgottenReturn) { 1169 if (parent !== undefined && parent._returnedNonUndefined()) return; 1170 if ((promise._bitField & 65535) === 0) return; 1171 1172 if (name) name = name + " "; 1173 var handlerLine = ""; 1174 var creatorLine = ""; 1175 if (promiseCreated._trace) { 1176 var traceLines = promiseCreated._trace.stack.split("\n"); 1177 var stack = cleanStack(traceLines); 1178 for (var i = stack.length - 1; i >= 0; --i) { 1179 var line = stack[i]; 1180 if (!nodeFramePattern.test(line)) { 1181 var lineMatches = line.match(parseLinePattern); 1182 if (lineMatches) { 1183 handlerLine = "at " + lineMatches[1] + 1184 ":" + lineMatches[2] + ":" + lineMatches[3] + " "; 1185 } 1186 break; 1187 } 1188 } 1189 1190 if (stack.length > 0) { 1191 var firstUserLine = stack[0]; 1192 for (var i = 0; i < traceLines.length; ++i) { 1193 1194 if (traceLines[i] === firstUserLine) { 1195 if (i > 0) { 1196 creatorLine = "\n" + traceLines[i - 1]; 1197 } 1198 break; 1199 } 1200 } 1201 1202 } 1203 } 1204 var msg = "a promise was created in a " + name + 1205 "handler " + handlerLine + "but was not returned from it, " + 1206 "see http://goo.gl/rRqMUw" + 1207 creatorLine; 1208 promise._warn(msg, true, promiseCreated); 1209 } 1210} 1211 1212function deprecated(name, replacement) { 1213 var message = name + 1214 " is deprecated and will be removed in a future version."; 1215 if (replacement) message += " Use " + replacement + " instead."; 1216 return warn(message); 1217} 1218 1219function warn(message, shouldUseOwnTrace, promise) { 1220 if (!config.warnings) return; 1221 var warning = new Warning(message); 1222 var ctx; 1223 if (shouldUseOwnTrace) { 1224 promise._attachExtraTrace(warning); 1225 } else if (config.longStackTraces && (ctx = Promise._peekContext())) { 1226 ctx.attachExtraTrace(warning); 1227 } else { 1228 var parsed = parseStackAndMessage(warning); 1229 warning.stack = parsed.message + "\n" + parsed.stack.join("\n"); 1230 } 1231 1232 if (!activeFireEvent("warning", warning)) { 1233 formatAndLogError(warning, "", true); 1234 } 1235} 1236 1237function reconstructStack(message, stacks) { 1238 for (var i = 0; i < stacks.length - 1; ++i) { 1239 stacks[i].push("From previous event:"); 1240 stacks[i] = stacks[i].join("\n"); 1241 } 1242 if (i < stacks.length) { 1243 stacks[i] = stacks[i].join("\n"); 1244 } 1245 return message + "\n" + stacks.join("\n"); 1246} 1247 1248function removeDuplicateOrEmptyJumps(stacks) { 1249 for (var i = 0; i < stacks.length; ++i) { 1250 if (stacks[i].length === 0 || 1251 ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) { 1252 stacks.splice(i, 1); 1253 i--; 1254 } 1255 } 1256} 1257 1258function removeCommonRoots(stacks) { 1259 var current = stacks[0]; 1260 for (var i = 1; i < stacks.length; ++i) { 1261 var prev = stacks[i]; 1262 var currentLastIndex = current.length - 1; 1263 var currentLastLine = current[currentLastIndex]; 1264 var commonRootMeetPoint = -1; 1265 1266 for (var j = prev.length - 1; j >= 0; --j) { 1267 if (prev[j] === currentLastLine) { 1268 commonRootMeetPoint = j; 1269 break; 1270 } 1271 } 1272 1273 for (var j = commonRootMeetPoint; j >= 0; --j) { 1274 var line = prev[j]; 1275 if (current[currentLastIndex] === line) { 1276 current.pop(); 1277 currentLastIndex--; 1278 } else { 1279 break; 1280 } 1281 } 1282 current = prev; 1283 } 1284} 1285 1286function cleanStack(stack) { 1287 var ret = []; 1288 for (var i = 0; i < stack.length; ++i) { 1289 var line = stack[i]; 1290 var isTraceLine = " (No stack trace)" === line || 1291 stackFramePattern.test(line); 1292 var isInternalFrame = isTraceLine && shouldIgnore(line); 1293 if (isTraceLine && !isInternalFrame) { 1294 if (indentStackFrames && line.charAt(0) !== " ") { 1295 line = " " + line; 1296 } 1297 ret.push(line); 1298 } 1299 } 1300 return ret; 1301} 1302 1303function stackFramesAsArray(error) { 1304 var stack = error.stack.replace(/\s+$/g, "").split("\n"); 1305 for (var i = 0; i < stack.length; ++i) { 1306 var line = stack[i]; 1307 if (" (No stack trace)" === line || stackFramePattern.test(line)) { 1308 break; 1309 } 1310 } 1311 if (i > 0 && error.name != "SyntaxError") { 1312 stack = stack.slice(i); 1313 } 1314 return stack; 1315} 1316 1317function parseStackAndMessage(error) { 1318 var stack = error.stack; 1319 var message = error.toString(); 1320 stack = typeof stack === "string" && stack.length > 0 1321 ? stackFramesAsArray(error) : [" (No stack trace)"]; 1322 return { 1323 message: message, 1324 stack: error.name == "SyntaxError" ? stack : cleanStack(stack) 1325 }; 1326} 1327 1328function formatAndLogError(error, title, isSoft) { 1329 if (typeof console !== "undefined") { 1330 var message; 1331 if (util.isObject(error)) { 1332 var stack = error.stack; 1333 message = title + formatStack(stack, error); 1334 } else { 1335 message = title + String(error); 1336 } 1337 if (typeof printWarning === "function") { 1338 printWarning(message, isSoft); 1339 } else if (typeof console.log === "function" || 1340 typeof console.log === "object") { 1341 console.log(message); 1342 } 1343 } 1344} 1345 1346function fireRejectionEvent(name, localHandler, reason, promise) { 1347 var localEventFired = false; 1348 try { 1349 if (typeof localHandler === "function") { 1350 localEventFired = true; 1351 if (name === "rejectionHandled") { 1352 localHandler(promise); 1353 } else { 1354 localHandler(reason, promise); 1355 } 1356 } 1357 } catch (e) { 1358 async.throwLater(e); 1359 } 1360 1361 if (name === "unhandledRejection") { 1362 if (!activeFireEvent(name, reason, promise) && !localEventFired) { 1363 formatAndLogError(reason, "Unhandled rejection "); 1364 } 1365 } else { 1366 activeFireEvent(name, promise); 1367 } 1368} 1369 1370function formatNonError(obj) { 1371 var str; 1372 if (typeof obj === "function") { 1373 str = "[function " + 1374 (obj.name || "anonymous") + 1375 "]"; 1376 } else { 1377 str = obj && typeof obj.toString === "function" 1378 ? obj.toString() : util.toString(obj); 1379 var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/; 1380 if (ruselessToString.test(str)) { 1381 try { 1382 var newStr = JSON.stringify(obj); 1383 str = newStr; 1384 } 1385 catch(e) { 1386 1387 } 1388 } 1389 if (str.length === 0) { 1390 str = "(empty array)"; 1391 } 1392 } 1393 return ("(<" + snip(str) + ">, no stack trace)"); 1394} 1395 1396function snip(str) { 1397 var maxChars = 41; 1398 if (str.length < maxChars) { 1399 return str; 1400 } 1401 return str.substr(0, maxChars - 3) + "..."; 1402} 1403 1404function longStackTracesIsSupported() { 1405 return typeof captureStackTrace === "function"; 1406} 1407 1408var shouldIgnore = function() { return false; }; 1409var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/; 1410function parseLineInfo(line) { 1411 var matches = line.match(parseLineInfoRegex); 1412 if (matches) { 1413 return { 1414 fileName: matches[1], 1415 line: parseInt(matches[2], 10) 1416 }; 1417 } 1418} 1419 1420function setBounds(firstLineError, lastLineError) { 1421 if (!longStackTracesIsSupported()) return; 1422 var firstStackLines = firstLineError.stack.split("\n"); 1423 var lastStackLines = lastLineError.stack.split("\n"); 1424 var firstIndex = -1; 1425 var lastIndex = -1; 1426 var firstFileName; 1427 var lastFileName; 1428 for (var i = 0; i < firstStackLines.length; ++i) { 1429 var result = parseLineInfo(firstStackLines[i]); 1430 if (result) { 1431 firstFileName = result.fileName; 1432 firstIndex = result.line; 1433 break; 1434 } 1435 } 1436 for (var i = 0; i < lastStackLines.length; ++i) { 1437 var result = parseLineInfo(lastStackLines[i]); 1438 if (result) { 1439 lastFileName = result.fileName; 1440 lastIndex = result.line; 1441 break; 1442 } 1443 } 1444 if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName || 1445 firstFileName !== lastFileName || firstIndex >= lastIndex) { 1446 return; 1447 } 1448 1449 shouldIgnore = function(line) { 1450 if (bluebirdFramePattern.test(line)) return true; 1451 var info = parseLineInfo(line); 1452 if (info) { 1453 if (info.fileName === firstFileName && 1454 (firstIndex <= info.line && info.line <= lastIndex)) { 1455 return true; 1456 } 1457 } 1458 return false; 1459 }; 1460} 1461 1462function CapturedTrace(parent) { 1463 this._parent = parent; 1464 this._promisesCreated = 0; 1465 var length = this._length = 1 + (parent === undefined ? 0 : parent._length); 1466 captureStackTrace(this, CapturedTrace); 1467 if (length > 32) this.uncycle(); 1468} 1469util.inherits(CapturedTrace, Error); 1470Context.CapturedTrace = CapturedTrace; 1471 1472CapturedTrace.prototype.uncycle = function() { 1473 var length = this._length; 1474 if (length < 2) return; 1475 var nodes = []; 1476 var stackToIndex = {}; 1477 1478 for (var i = 0, node = this; node !== undefined; ++i) { 1479 nodes.push(node); 1480 node = node._parent; 1481 } 1482 length = this._length = i; 1483 for (var i = length - 1; i >= 0; --i) { 1484 var stack = nodes[i].stack; 1485 if (stackToIndex[stack] === undefined) { 1486 stackToIndex[stack] = i; 1487 } 1488 } 1489 for (var i = 0; i < length; ++i) { 1490 var currentStack = nodes[i].stack; 1491 var index = stackToIndex[currentStack]; 1492 if (index !== undefined && index !== i) { 1493 if (index > 0) { 1494 nodes[index - 1]._parent = undefined; 1495 nodes[index - 1]._length = 1; 1496 } 1497 nodes[i]._parent = undefined; 1498 nodes[i]._length = 1; 1499 var cycleEdgeNode = i > 0 ? nodes[i - 1] : this; 1500 1501 if (index < length - 1) { 1502 cycleEdgeNode._parent = nodes[index + 1]; 1503 cycleEdgeNode._parent.uncycle(); 1504 cycleEdgeNode._length = 1505 cycleEdgeNode._parent._length + 1; 1506 } else { 1507 cycleEdgeNode._parent = undefined; 1508 cycleEdgeNode._length = 1; 1509 } 1510 var currentChildLength = cycleEdgeNode._length + 1; 1511 for (var j = i - 2; j >= 0; --j) { 1512 nodes[j]._length = currentChildLength; 1513 currentChildLength++; 1514 } 1515 return; 1516 } 1517 } 1518}; 1519 1520CapturedTrace.prototype.attachExtraTrace = function(error) { 1521 if (error.__stackCleaned__) return; 1522 this.uncycle(); 1523 var parsed = parseStackAndMessage(error); 1524 var message = parsed.message; 1525 var stacks = [parsed.stack]; 1526 1527 var trace = this; 1528 while (trace !== undefined) { 1529 stacks.push(cleanStack(trace.stack.split("\n"))); 1530 trace = trace._parent; 1531 } 1532 removeCommonRoots(stacks); 1533 removeDuplicateOrEmptyJumps(stacks); 1534 util.notEnumerableProp(error, "stack", reconstructStack(message, stacks)); 1535 util.notEnumerableProp(error, "__stackCleaned__", true); 1536}; 1537 1538var captureStackTrace = (function stackDetection() { 1539 var v8stackFramePattern = /^\s*at\s*/; 1540 var v8stackFormatter = function(stack, error) { 1541 if (typeof stack === "string") return stack; 1542 1543 if (error.name !== undefined && 1544 error.message !== undefined) { 1545 return error.toString(); 1546 } 1547 return formatNonError(error); 1548 }; 1549 1550 if (typeof Error.stackTraceLimit === "number" && 1551 typeof Error.captureStackTrace === "function") { 1552 Error.stackTraceLimit += 6; 1553 stackFramePattern = v8stackFramePattern; 1554 formatStack = v8stackFormatter; 1555 var captureStackTrace = Error.captureStackTrace; 1556 1557 shouldIgnore = function(line) { 1558 return bluebirdFramePattern.test(line); 1559 }; 1560 return function(receiver, ignoreUntil) { 1561 Error.stackTraceLimit += 6; 1562 captureStackTrace(receiver, ignoreUntil); 1563 Error.stackTraceLimit -= 6; 1564 }; 1565 } 1566 var err = new Error(); 1567 1568 if (typeof err.stack === "string" && 1569 err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) { 1570 stackFramePattern = /@/; 1571 formatStack = v8stackFormatter; 1572 indentStackFrames = true; 1573 return function captureStackTrace(o) { 1574 o.stack = new Error().stack; 1575 }; 1576 } 1577 1578 var hasStackAfterThrow; 1579 try { throw new Error(); } 1580 catch(e) { 1581 hasStackAfterThrow = ("stack" in e); 1582 } 1583 if (!("stack" in err) && hasStackAfterThrow && 1584 typeof Error.stackTraceLimit === "number") { 1585 stackFramePattern = v8stackFramePattern; 1586 formatStack = v8stackFormatter; 1587 return function captureStackTrace(o) { 1588 Error.stackTraceLimit += 6; 1589 try { throw new Error(); } 1590 catch(e) { o.stack = e.stack; } 1591 Error.stackTraceLimit -= 6; 1592 }; 1593 } 1594 1595 formatStack = function(stack, error) { 1596 if (typeof stack === "string") return stack; 1597 1598 if ((typeof error === "object" || 1599 typeof error === "function") && 1600 error.name !== undefined && 1601 error.message !== undefined) { 1602 return error.toString(); 1603 } 1604 return formatNonError(error); 1605 }; 1606 1607 return null; 1608 1609})([]); 1610 1611if (typeof console !== "undefined" && typeof console.warn !== "undefined") { 1612 printWarning = function (message) { 1613 console.warn(message); 1614 }; 1615 if (util.isNode && process.stderr.isTTY) { 1616 printWarning = function(message, isSoft) { 1617 var color = isSoft ? "\u001b[33m" : "\u001b[31m"; 1618 console.warn(color + message + "\u001b[0m\n"); 1619 }; 1620 } else if (!util.isNode && typeof (new Error().stack) === "string") { 1621 printWarning = function(message, isSoft) { 1622 console.warn("%c" + message, 1623 isSoft ? "color: darkorange" : "color: red"); 1624 }; 1625 } 1626} 1627 1628var config = { 1629 warnings: warnings, 1630 longStackTraces: false, 1631 cancellation: false, 1632 monitoring: false 1633}; 1634 1635if (longStackTraces) Promise.longStackTraces(); 1636 1637return { 1638 longStackTraces: function() { 1639 return config.longStackTraces; 1640 }, 1641 warnings: function() { 1642 return config.warnings; 1643 }, 1644 cancellation: function() { 1645 return config.cancellation; 1646 }, 1647 monitoring: function() { 1648 return config.monitoring; 1649 }, 1650 propagateFromFunction: function() { 1651 return propagateFromFunction; 1652 }, 1653 boundValueFunction: function() { 1654 return boundValueFunction; 1655 }, 1656 checkForgottenReturns: checkForgottenReturns, 1657 setBounds: setBounds, 1658 warn: warn, 1659 deprecated: deprecated, 1660 CapturedTrace: CapturedTrace, 1661 fireDomEvent: fireDomEvent, 1662 fireGlobalEvent: fireGlobalEvent 1663}; 1664}; 1665 1666},{"./errors":12,"./es5":13,"./util":36}],10:[function(_dereq_,module,exports){ 1667"use strict"; 1668module.exports = function(Promise) { 1669function returner() { 1670 return this.value; 1671} 1672function thrower() { 1673 throw this.reason; 1674} 1675 1676Promise.prototype["return"] = 1677Promise.prototype.thenReturn = function (value) { 1678 if (value instanceof Promise) value.suppressUnhandledRejections(); 1679 return this._then( 1680 returner, undefined, undefined, {value: value}, undefined); 1681}; 1682 1683Promise.prototype["throw"] = 1684Promise.prototype.thenThrow = function (reason) { 1685 return this._then( 1686 thrower, undefined, undefined, {reason: reason}, undefined); 1687}; 1688 1689Promise.prototype.catchThrow = function (reason) { 1690 if (arguments.length <= 1) { 1691 return this._then( 1692 undefined, thrower, undefined, {reason: reason}, undefined); 1693 } else { 1694 var _reason = arguments[1]; 1695 var handler = function() {throw _reason;}; 1696 return this.caught(reason, handler); 1697 } 1698}; 1699 1700Promise.prototype.catchReturn = function (value) { 1701 if (arguments.length <= 1) { 1702 if (value instanceof Promise) value.suppressUnhandledRejections(); 1703 return this._then( 1704 undefined, returner, undefined, {value: value}, undefined); 1705 } else { 1706 var _value = arguments[1]; 1707 if (_value instanceof Promise) _value.suppressUnhandledRejections(); 1708 var handler = function() {return _value;}; 1709 return this.caught(value, handler); 1710 } 1711}; 1712}; 1713 1714},{}],11:[function(_dereq_,module,exports){ 1715"use strict"; 1716module.exports = function(Promise, INTERNAL) { 1717var PromiseReduce = Promise.reduce; 1718var PromiseAll = Promise.all; 1719 1720function promiseAllThis() { 1721 return PromiseAll(this); 1722} 1723 1724function PromiseMapSeries(promises, fn) { 1725 return PromiseReduce(promises, fn, INTERNAL, INTERNAL); 1726} 1727 1728Promise.prototype.each = function (fn) { 1729 return PromiseReduce(this, fn, INTERNAL, 0) 1730 ._then(promiseAllThis, undefined, undefined, this, undefined); 1731}; 1732 1733Promise.prototype.mapSeries = function (fn) { 1734 return PromiseReduce(this, fn, INTERNAL, INTERNAL); 1735}; 1736 1737Promise.each = function (promises, fn) { 1738 return PromiseReduce(promises, fn, INTERNAL, 0) 1739 ._then(promiseAllThis, undefined, undefined, promises, undefined); 1740}; 1741 1742Promise.mapSeries = PromiseMapSeries; 1743}; 1744 1745 1746},{}],12:[function(_dereq_,module,exports){ 1747"use strict"; 1748var es5 = _dereq_("./es5"); 1749var Objectfreeze = es5.freeze; 1750var util = _dereq_("./util"); 1751var inherits = util.inherits; 1752var notEnumerableProp = util.notEnumerableProp; 1753 1754function subError(nameProperty, defaultMessage) { 1755 function SubError(message) { 1756 if (!(this instanceof SubError)) return new SubError(message); 1757 notEnumerableProp(this, "message", 1758 typeof message === "string" ? message : defaultMessage); 1759 notEnumerableProp(this, "name", nameProperty); 1760 if (Error.captureStackTrace) { 1761 Error.captureStackTrace(this, this.constructor); 1762 } else { 1763 Error.call(this); 1764 } 1765 } 1766 inherits(SubError, Error); 1767 return SubError; 1768} 1769 1770var _TypeError, _RangeError; 1771var Warning = subError("Warning", "warning"); 1772var CancellationError = subError("CancellationError", "cancellation error"); 1773var TimeoutError = subError("TimeoutError", "timeout error"); 1774var AggregateError = subError("AggregateError", "aggregate error"); 1775try { 1776 _TypeError = TypeError; 1777 _RangeError = RangeError; 1778} catch(e) { 1779 _TypeError = subError("TypeError", "type error"); 1780 _RangeError = subError("RangeError", "range error"); 1781} 1782 1783var methods = ("join pop push shift unshift slice filter forEach some " + 1784 "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" "); 1785 1786for (var i = 0; i < methods.length; ++i) { 1787 if (typeof Array.prototype[methods[i]] === "function") { 1788 AggregateError.prototype[methods[i]] = Array.prototype[methods[i]]; 1789 } 1790} 1791 1792es5.defineProperty(AggregateError.prototype, "length", { 1793 value: 0, 1794 configurable: false, 1795 writable: true, 1796 enumerable: true 1797}); 1798AggregateError.prototype["isOperational"] = true; 1799var level = 0; 1800AggregateError.prototype.toString = function() { 1801 var indent = Array(level * 4 + 1).join(" "); 1802 var ret = "\n" + indent + "AggregateError of:" + "\n"; 1803 level++; 1804 indent = Array(level * 4 + 1).join(" "); 1805 for (var i = 0; i < this.length; ++i) { 1806 var str = this[i] === this ? "[Circular AggregateError]" : this[i] + ""; 1807 var lines = str.split("\n"); 1808 for (var j = 0; j < lines.length; ++j) { 1809 lines[j] = indent + lines[j]; 1810 } 1811 str = lines.join("\n"); 1812 ret += str + "\n"; 1813 } 1814 level--; 1815 return ret; 1816}; 1817 1818function OperationalError(message) { 1819 if (!(this instanceof OperationalError)) 1820 return new OperationalError(message); 1821 notEnumerableProp(this, "name", "OperationalError"); 1822 notEnumerableProp(this, "message", message); 1823 this.cause = message; 1824 this["isOperational"] = true; 1825 1826 if (message instanceof Error) { 1827 notEnumerableProp(this, "message", message.message); 1828 notEnumerableProp(this, "stack", message.stack); 1829 } else if (Error.captureStackTrace) { 1830 Error.captureStackTrace(this, this.constructor); 1831 } 1832 1833} 1834inherits(OperationalError, Error); 1835 1836var errorTypes = Error["__BluebirdErrorTypes__"]; 1837if (!errorTypes) { 1838 errorTypes = Objectfreeze({ 1839 CancellationError: CancellationError, 1840 TimeoutError: TimeoutError, 1841 OperationalError: OperationalError, 1842 RejectionError: OperationalError, 1843 AggregateError: AggregateError 1844 }); 1845 es5.defineProperty(Error, "__BluebirdErrorTypes__", { 1846 value: errorTypes, 1847 writable: false, 1848 enumerable: false, 1849 configurable: false 1850 }); 1851} 1852 1853module.exports = { 1854 Error: Error, 1855 TypeError: _TypeError, 1856 RangeError: _RangeError, 1857 CancellationError: errorTypes.CancellationError, 1858 OperationalError: errorTypes.OperationalError, 1859 TimeoutError: errorTypes.TimeoutError, 1860 AggregateError: errorTypes.AggregateError, 1861 Warning: Warning 1862}; 1863 1864},{"./es5":13,"./util":36}],13:[function(_dereq_,module,exports){ 1865var isES5 = (function(){ 1866 "use strict"; 1867 return this === undefined; 1868})(); 1869 1870if (isES5) { 1871 module.exports = { 1872 freeze: Object.freeze, 1873 defineProperty: Object.defineProperty, 1874 getDescriptor: Object.getOwnPropertyDescriptor, 1875 keys: Object.keys, 1876 names: Object.getOwnPropertyNames, 1877 getPrototypeOf: Object.getPrototypeOf, 1878 isArray: Array.isArray, 1879 isES5: isES5, 1880 propertyIsWritable: function(obj, prop) { 1881 var descriptor = Object.getOwnPropertyDescriptor(obj, prop); 1882 return !!(!descriptor || descriptor.writable || descriptor.set); 1883 } 1884 }; 1885} else { 1886 var has = {}.hasOwnProperty; 1887 var str = {}.toString; 1888 var proto = {}.constructor.prototype; 1889 1890 var ObjectKeys = function (o) { 1891 var ret = []; 1892 for (var key in o) { 1893 if (has.call(o, key)) { 1894 ret.push(key); 1895 } 1896 } 1897 return ret; 1898 }; 1899 1900 var ObjectGetDescriptor = function(o, key) { 1901 return {value: o[key]}; 1902 }; 1903 1904 var ObjectDefineProperty = function (o, key, desc) { 1905 o[key] = desc.value; 1906 return o; 1907 }; 1908 1909 var ObjectFreeze = function (obj) { 1910 return obj; 1911 }; 1912 1913 var ObjectGetPrototypeOf = function (obj) { 1914 try { 1915 return Object(obj).constructor.prototype; 1916 } 1917 catch (e) { 1918 return proto; 1919 } 1920 }; 1921 1922 var ArrayIsArray = function (obj) { 1923 try { 1924 return str.call(obj) === "[object Array]"; 1925 } 1926 catch(e) { 1927 return false; 1928 } 1929 }; 1930 1931 module.exports = { 1932 isArray: ArrayIsArray, 1933 keys: ObjectKeys, 1934 names: ObjectKeys, 1935 defineProperty: ObjectDefineProperty, 1936 getDescriptor: ObjectGetDescriptor, 1937 freeze: ObjectFreeze, 1938 getPrototypeOf: ObjectGetPrototypeOf, 1939 isES5: isES5, 1940 propertyIsWritable: function() { 1941 return true; 1942 } 1943 }; 1944} 1945 1946},{}],14:[function(_dereq_,module,exports){ 1947"use strict"; 1948module.exports = function(Promise, INTERNAL) { 1949var PromiseMap = Promise.map; 1950 1951Promise.prototype.filter = function (fn, options) { 1952 return PromiseMap(this, fn, options, INTERNAL); 1953}; 1954 1955Promise.filter = function (promises, fn, options) { 1956 return PromiseMap(promises, fn, options, INTERNAL); 1957}; 1958}; 1959 1960},{}],15:[function(_dereq_,module,exports){ 1961"use strict"; 1962module.exports = function(Promise, tryConvertToPromise, NEXT_FILTER) { 1963var util = _dereq_("./util"); 1964var CancellationError = Promise.CancellationError; 1965var errorObj = util.errorObj; 1966var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER); 1967 1968function PassThroughHandlerContext(promise, type, handler) { 1969 this.promise = promise; 1970 this.type = type; 1971 this.handler = handler; 1972 this.called = false; 1973 this.cancelPromise = null; 1974} 1975 1976PassThroughHandlerContext.prototype.isFinallyHandler = function() { 1977 return this.type === 0; 1978}; 1979 1980function FinallyHandlerCancelReaction(finallyHandler) { 1981 this.finallyHandler = finallyHandler; 1982} 1983 1984FinallyHandlerCancelReaction.prototype._resultCancelled = function() { 1985 checkCancel(this.finallyHandler); 1986}; 1987 1988function checkCancel(ctx, reason) { 1989 if (ctx.cancelPromise != null) { 1990 if (arguments.length > 1) { 1991 ctx.cancelPromise._reject(reason); 1992 } else { 1993 ctx.cancelPromise._cancel(); 1994 } 1995 ctx.cancelPromise = null; 1996 return true; 1997 } 1998 return false; 1999} 2000 2001function succeed() { 2002 return finallyHandler.call(this, this.promise._target()._settledValue()); 2003} 2004function fail(reason) { 2005 if (checkCancel(this, reason)) return; 2006 errorObj.e = reason; 2007 return errorObj; 2008} 2009function finallyHandler(reasonOrValue) { 2010 var promise = this.promise; 2011 var handler = this.handler; 2012 2013 if (!this.called) { 2014 this.called = true; 2015 var ret = this.isFinallyHandler() 2016 ? handler.call(promise._boundValue()) 2017 : handler.call(promise._boundValue(), reasonOrValue); 2018 if (ret === NEXT_FILTER) { 2019 return ret; 2020 } else if (ret !== undefined) { 2021 promise._setReturnedNonUndefined(); 2022 var maybePromise = tryConvertToPromise(ret, promise); 2023 if (maybePromise instanceof Promise) { 2024 if (this.cancelPromise != null) { 2025 if (maybePromise._isCancelled()) { 2026 var reason = 2027 new CancellationError("late cancellation observer"); 2028 promise._attachExtraTrace(reason); 2029 errorObj.e = reason; 2030 return errorObj; 2031 } else if (maybePromise.isPending()) { 2032 maybePromise._attachCancellationCallback( 2033 new FinallyHandlerCancelReaction(this)); 2034 } 2035 } 2036 return maybePromise._then( 2037 succeed, fail, undefined, this, undefined); 2038 } 2039 } 2040 } 2041 2042 if (promise.isRejected()) { 2043 checkCancel(this); 2044 errorObj.e = reasonOrValue; 2045 return errorObj; 2046 } else { 2047 checkCancel(this); 2048 return reasonOrValue; 2049 } 2050} 2051 2052Promise.prototype._passThrough = function(handler, type, success, fail) { 2053 if (typeof handler !== "function") return this.then(); 2054 return this._then(success, 2055 fail, 2056 undefined, 2057 new PassThroughHandlerContext(this, type, handler), 2058 undefined); 2059}; 2060 2061Promise.prototype.lastly = 2062Promise.prototype["finally"] = function (handler) { 2063 return this._passThrough(handler, 2064 0, 2065 finallyHandler, 2066 finallyHandler); 2067}; 2068 2069 2070Promise.prototype.tap = function (handler) { 2071 return this._passThrough(handler, 1, finallyHandler); 2072}; 2073 2074Promise.prototype.tapCatch = function (handlerOrPredicate) { 2075 var len = arguments.length; 2076 if(len === 1) { 2077 return this._passThrough(handlerOrPredicate, 2078 1, 2079 undefined, 2080 finallyHandler); 2081 } else { 2082 var catchInstances = new Array(len - 1), 2083 j = 0, i; 2084 for (i = 0; i < len - 1; ++i) { 2085 var item = arguments[i]; 2086 if (util.isObject(item)) { 2087 catchInstances[j++] = item; 2088 } else { 2089 return Promise.reject(new TypeError( 2090 "tapCatch statement predicate: " 2091 + "expecting an object but got " + util.classString(item) 2092 )); 2093 } 2094 } 2095 catchInstances.length = j; 2096 var handler = arguments[i]; 2097 return this._passThrough(catchFilter(catchInstances, handler, this), 2098 1, 2099 undefined, 2100 finallyHandler); 2101 } 2102 2103}; 2104 2105return PassThroughHandlerContext; 2106}; 2107 2108},{"./catch_filter":7,"./util":36}],16:[function(_dereq_,module,exports){ 2109"use strict"; 2110module.exports = function(Promise, 2111 apiRejection, 2112 INTERNAL, 2113 tryConvertToPromise, 2114 Proxyable, 2115 debug) { 2116var errors = _dereq_("./errors"); 2117var TypeError = errors.TypeError; 2118var util = _dereq_("./util"); 2119var errorObj = util.errorObj; 2120var tryCatch = util.tryCatch; 2121var yieldHandlers = []; 2122 2123function promiseFromYieldHandler(value, yieldHandlers, traceParent) { 2124 for (var i = 0; i < yieldHandlers.length; ++i) { 2125 traceParent._pushContext(); 2126 var result = tryCatch(yieldHandlers[i])(value); 2127 traceParent._popContext(); 2128 if (result === errorObj) { 2129 traceParent._pushContext(); 2130 var ret = Promise.reject(errorObj.e); 2131 traceParent._popContext(); 2132 return ret; 2133 } 2134 var maybePromise = tryConvertToPromise(result, traceParent); 2135 if (maybePromise instanceof Promise) return maybePromise; 2136 } 2137 return null; 2138} 2139 2140function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) { 2141 if (debug.cancellation()) { 2142 var internal = new Promise(INTERNAL); 2143 var _finallyPromise = this._finallyPromise = new Promise(INTERNAL); 2144 this._promise = internal.lastly(function() { 2145 return _finallyPromise; 2146 }); 2147 internal._captureStackTrace(); 2148 internal._setOnCancel(this); 2149 } else { 2150 var promise = this._promise = new Promise(INTERNAL); 2151 promise._captureStackTrace(); 2152 } 2153 this._stack = stack; 2154 this._generatorFunction = generatorFunction; 2155 this._receiver = receiver; 2156 this._generator = undefined; 2157 this._yieldHandlers = typeof yieldHandler === "function" 2158 ? [yieldHandler].concat(yieldHandlers) 2159 : yieldHandlers; 2160 this._yieldedPromise = null; 2161 this._cancellationPhase = false; 2162} 2163util.inherits(PromiseSpawn, Proxyable); 2164 2165PromiseSpawn.prototype._isResolved = function() { 2166 return this._promise === null; 2167}; 2168 2169PromiseSpawn.prototype._cleanup = function() { 2170 this._promise = this._generator = null; 2171 if (debug.cancellation() && this._finallyPromise !== null) { 2172 this._finallyPromise._fulfill(); 2173 this._finallyPromise = null; 2174 } 2175}; 2176 2177PromiseSpawn.prototype._promiseCancelled = function() { 2178 if (this._isResolved()) return; 2179 var implementsReturn = typeof this._generator["return"] !== "undefined"; 2180 2181 var result; 2182 if (!implementsReturn) { 2183 var reason = new Promise.CancellationError( 2184 "generator .return() sentinel"); 2185 Promise.coroutine.returnSentinel = reason; 2186 this._promise._attachExtraTrace(reason); 2187 this._promise._pushContext(); 2188 result = tryCatch(this._generator["throw"]).call(this._generator, 2189 reason); 2190 this._promise._popContext(); 2191 } else { 2192 this._promise._pushContext(); 2193 result = tryCatch(this._generator["return"]).call(this._generator, 2194 undefined); 2195 this._promise._popContext(); 2196 } 2197 this._cancellationPhase = true; 2198 this._yieldedPromise = null; 2199 this._continue(result); 2200}; 2201 2202PromiseSpawn.prototype._promiseFulfilled = function(value) { 2203 this._yieldedPromise = null; 2204 this._promise._pushContext(); 2205 var result = tryCatch(this._generator.next).call(this._generator, value); 2206 this._promise._popContext(); 2207 this._continue(result); 2208}; 2209 2210PromiseSpawn.prototype._promiseRejected = function(reason) { 2211 this._yieldedPromise = null; 2212 this._promise._attachExtraTrace(reason); 2213 this._promise._pushContext(); 2214 var result = tryCatch(this._generator["throw"]) 2215 .call(this._generator, reason); 2216 this._promise._popContext(); 2217 this._continue(result); 2218}; 2219 2220PromiseSpawn.prototype._resultCancelled = function() { 2221 if (this._yieldedPromise instanceof Promise) { 2222 var promise = this._yieldedPromise; 2223 this._yieldedPromise = null; 2224 promise.cancel(); 2225 } 2226}; 2227 2228PromiseSpawn.prototype.promise = function () { 2229 return this._promise; 2230}; 2231 2232PromiseSpawn.prototype._run = function () { 2233 this._generator = this._generatorFunction.call(this._receiver); 2234 this._receiver = 2235 this._generatorFunction = undefined; 2236 this._promiseFulfilled(undefined); 2237}; 2238 2239PromiseSpawn.prototype._continue = function (result) { 2240 var promise = this._promise; 2241 if (result === errorObj) { 2242 this._cleanup(); 2243 if (this._cancellationPhase) { 2244 return promise.cancel(); 2245 } else { 2246 return promise._rejectCallback(result.e, false); 2247 } 2248 } 2249 2250 var value = result.value; 2251 if (result.done === true) { 2252 this._cleanup(); 2253 if (this._cancellationPhase) { 2254 return promise.cancel(); 2255 } else { 2256 return promise._resolveCallback(value); 2257 } 2258 } else { 2259 var maybePromise = tryConvertToPromise(value, this._promise); 2260 if (!(maybePromise instanceof Promise)) { 2261 maybePromise = 2262 promiseFromYieldHandler(maybePromise, 2263 this._yieldHandlers, 2264 this._promise); 2265 if (maybePromise === null) { 2266 this._promiseRejected( 2267 new TypeError( 2268 "A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/MqrFmX\u000a\u000a".replace("%s", String(value)) + 2269 "From coroutine:\u000a" + 2270 this._stack.split("\n").slice(1, -7).join("\n") 2271 ) 2272 ); 2273 return; 2274 } 2275 } 2276 maybePromise = maybePromise._target(); 2277 var bitField = maybePromise._bitField; 2278 ; 2279 if (((bitField & 50397184) === 0)) { 2280 this._yieldedPromise = maybePromise; 2281 maybePromise._proxy(this, null); 2282 } else if (((bitField & 33554432) !== 0)) { 2283 Promise._async.invoke( 2284 this._promiseFulfilled, this, maybePromise._value() 2285 ); 2286 } else if (((bitField & 16777216) !== 0)) { 2287 Promise._async.invoke( 2288 this._promiseRejected, this, maybePromise._reason() 2289 ); 2290 } else { 2291 this._promiseCancelled(); 2292 } 2293 } 2294}; 2295 2296Promise.coroutine = function (generatorFunction, options) { 2297 if (typeof generatorFunction !== "function") { 2298 throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 2299 } 2300 var yieldHandler = Object(options).yieldHandler; 2301 var PromiseSpawn$ = PromiseSpawn; 2302 var stack = new Error().stack; 2303 return function () { 2304 var generator = generatorFunction.apply(this, arguments); 2305 var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler, 2306 stack); 2307 var ret = spawn.promise(); 2308 spawn._generator = generator; 2309 spawn._promiseFulfilled(undefined); 2310 return ret; 2311 }; 2312}; 2313 2314Promise.coroutine.addYieldHandler = function(fn) { 2315 if (typeof fn !== "function") { 2316 throw new TypeError("expecting a function but got " + util.classString(fn)); 2317 } 2318 yieldHandlers.push(fn); 2319}; 2320 2321Promise.spawn = function (generatorFunction) { 2322 debug.deprecated("Promise.spawn()", "Promise.coroutine()"); 2323 if (typeof generatorFunction !== "function") { 2324 return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 2325 } 2326 var spawn = new PromiseSpawn(generatorFunction, this); 2327 var ret = spawn.promise(); 2328 spawn._run(Promise.spawn); 2329 return ret; 2330}; 2331}; 2332 2333},{"./errors":12,"./util":36}],17:[function(_dereq_,module,exports){ 2334"use strict"; 2335module.exports = 2336function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, 2337 getDomain) { 2338var util = _dereq_("./util"); 2339var canEvaluate = util.canEvaluate; 2340var tryCatch = util.tryCatch; 2341var errorObj = util.errorObj; 2342var reject; 2343 2344if (false) { var i, promiseSetters, thenCallbacks, holderClasses, generateHolderClass, promiseSetter, thenCallback; } 2345 2346Promise.join = function () { 2347 var last = arguments.length - 1; 2348 var fn; 2349 if (last > 0 && typeof arguments[last] === "function") { 2350 fn = arguments[last]; 2351 if (false) { var domain, bitField, maybePromise, i, callbacks, holder, HolderClass, ret; } 2352 } 2353 var args = [].slice.call(arguments);; 2354 if (fn) args.pop(); 2355 var ret = new PromiseArray(args).promise(); 2356 return fn !== undefined ? ret.spread(fn) : ret; 2357}; 2358 2359}; 2360 2361},{"./util":36}],18:[function(_dereq_,module,exports){ 2362"use strict"; 2363module.exports = function(Promise, 2364 PromiseArray, 2365 apiRejection, 2366 tryConvertToPromise, 2367 INTERNAL, 2368 debug) { 2369var getDomain = Promise._getDomain; 2370var util = _dereq_("./util"); 2371var tryCatch = util.tryCatch; 2372var errorObj = util.errorObj; 2373var async = Promise._async; 2374 2375function MappingPromiseArray(promises, fn, limit, _filter) { 2376 this.constructor$(promises); 2377 this._promise._captureStackTrace(); 2378 var domain = getDomain(); 2379 this._callback = domain === null ? fn : util.domainBind(domain, fn); 2380 this._preservedValues = _filter === INTERNAL 2381 ? new Array(this.length()) 2382 : null; 2383 this._limit = limit; 2384 this._inFlight = 0; 2385 this._queue = []; 2386 async.invoke(this._asyncInit, this, undefined); 2387} 2388util.inherits(MappingPromiseArray, PromiseArray); 2389 2390MappingPromiseArray.prototype._asyncInit = function() { 2391 this._init$(undefined, -2); 2392}; 2393 2394MappingPromiseArray.prototype._init = function () {}; 2395 2396MappingPromiseArray.prototype._promiseFulfilled = function (value, index) { 2397 var values = this._values; 2398 var length = this.length(); 2399 var preservedValues = this._preservedValues; 2400 var limit = this._limit; 2401 2402 if (index < 0) { 2403 index = (index * -1) - 1; 2404 values[index] = value; 2405 if (limit >= 1) { 2406 this._inFlight--; 2407 this._drainQueue(); 2408 if (this._isResolved()) return true; 2409 } 2410 } else { 2411 if (limit >= 1 && this._inFlight >= limit) { 2412 values[index] = value; 2413 this._queue.push(index); 2414 return false; 2415 } 2416 if (preservedValues !== null) preservedValues[index] = value; 2417 2418 var promise = this._promise; 2419 var callback = this._callback; 2420 var receiver = promise._boundValue(); 2421 promise._pushContext(); 2422 var ret = tryCatch(callback).call(receiver, value, index, length); 2423 var promiseCreated = promise._popContext(); 2424 debug.checkForgottenReturns( 2425 ret, 2426 promiseCreated, 2427 preservedValues !== null ? "Promise.filter" : "Promise.map", 2428 promise 2429 ); 2430 if (ret === errorObj) { 2431 this._reject(ret.e); 2432 return true; 2433 } 2434 2435 var maybePromise = tryConvertToPromise(ret, this._promise); 2436 if (maybePromise instanceof Promise) { 2437 maybePromise = maybePromise._target(); 2438 var bitField = maybePromise._bitField; 2439 ; 2440 if (((bitField & 50397184) === 0)) { 2441 if (limit >= 1) this._inFlight++; 2442 values[index] = maybePromise; 2443 maybePromise._proxy(this, (index + 1) * -1); 2444 return false; 2445 } else if (((bitField & 33554432) !== 0)) { 2446 ret = maybePromise._value(); 2447 } else if (((bitField & 16777216) !== 0)) { 2448 this._reject(maybePromise._reason()); 2449 return true; 2450 } else { 2451 this._cancel(); 2452 return true; 2453 } 2454 } 2455 values[index] = ret; 2456 } 2457 var totalResolved = ++this._totalResolved; 2458 if (totalResolved >= length) { 2459 if (preservedValues !== null) { 2460 this._filter(values, preservedValues); 2461 } else { 2462 this._resolve(values); 2463 } 2464 return true; 2465 } 2466 return false; 2467}; 2468 2469MappingPromiseArray.prototype._drainQueue = function () { 2470 var queue = this._queue; 2471 var limit = this._limit; 2472 var values = this._values; 2473 while (queue.length > 0 && this._inFlight < limit) { 2474 if (this._isResolved()) return; 2475 var index = queue.pop(); 2476 this._promiseFulfilled(values[index], index); 2477 } 2478}; 2479 2480MappingPromiseArray.prototype._filter = function (booleans, values) { 2481 var len = values.length; 2482 var ret = new Array(len); 2483 var j = 0; 2484 for (var i = 0; i < len; ++i) { 2485 if (booleans[i]) ret[j++] = values[i]; 2486 } 2487 ret.length = j; 2488 this._resolve(ret); 2489}; 2490 2491MappingPromiseArray.prototype.preservedValues = function () { 2492 return this._preservedValues; 2493}; 2494 2495function map(promises, fn, options, _filter) { 2496 if (typeof fn !== "function") { 2497 return apiRejection("expecting a function but got " + util.classString(fn)); 2498 } 2499 2500 var limit = 0; 2501 if (options !== undefined) { 2502 if (typeof options === "object" && options !== null) { 2503 if (typeof options.concurrency !== "number") { 2504 return Promise.reject( 2505 new TypeError("'concurrency' must be a number but it is " + 2506 util.classString(options.concurrency))); 2507 } 2508 limit = options.concurrency; 2509 } else { 2510 return Promise.reject(new TypeError( 2511 "options argument must be an object but it is " + 2512 util.classString(options))); 2513 } 2514 } 2515 limit = typeof limit === "number" && 2516 isFinite(limit) && limit >= 1 ? limit : 0; 2517 return new MappingPromiseArray(promises, fn, limit, _filter).promise(); 2518} 2519 2520Promise.prototype.map = function (fn, options) { 2521 return map(this, fn, options, null); 2522}; 2523 2524Promise.map = function (promises, fn, options, _filter) { 2525 return map(promises, fn, options, _filter); 2526}; 2527 2528 2529}; 2530 2531},{"./util":36}],19:[function(_dereq_,module,exports){ 2532"use strict"; 2533module.exports = 2534function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) { 2535var util = _dereq_("./util"); 2536var tryCatch = util.tryCatch; 2537 2538Promise.method = function (fn) { 2539 if (typeof fn !== "function") { 2540 throw new Promise.TypeError("expecting a function but got " + util.classString(fn)); 2541 } 2542 return function () { 2543 var ret = new Promise(INTERNAL); 2544 ret._captureStackTrace(); 2545 ret._pushContext(); 2546 var value = tryCatch(fn).apply(this, arguments); 2547 var promiseCreated = ret._popContext(); 2548 debug.checkForgottenReturns( 2549 value, promiseCreated, "Promise.method", ret); 2550 ret._resolveFromSyncValue(value); 2551 return ret; 2552 }; 2553}; 2554 2555Promise.attempt = Promise["try"] = function (fn) { 2556 if (typeof fn !== "function") { 2557 return apiRejection("expecting a function but got " + util.classString(fn)); 2558 } 2559 var ret = new Promise(INTERNAL); 2560 ret._captureStackTrace(); 2561 ret._pushContext(); 2562 var value; 2563 if (arguments.length > 1) { 2564 debug.deprecated("calling Promise.try with more than 1 argument"); 2565 var arg = arguments[1]; 2566 var ctx = arguments[2]; 2567 value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg) 2568 : tryCatch(fn).call(ctx, arg); 2569 } else { 2570 value = tryCatch(fn)(); 2571 } 2572 var promiseCreated = ret._popContext(); 2573 debug.checkForgottenReturns( 2574 value, promiseCreated, "Promise.try", ret); 2575 ret._resolveFromSyncValue(value); 2576 return ret; 2577}; 2578 2579Promise.prototype._resolveFromSyncValue = function (value) { 2580 if (value === util.errorObj) { 2581 this._rejectCallback(value.e, false); 2582 } else { 2583 this._resolveCallback(value, true); 2584 } 2585}; 2586}; 2587 2588},{"./util":36}],20:[function(_dereq_,module,exports){ 2589"use strict"; 2590var util = _dereq_("./util"); 2591var maybeWrapAsError = util.maybeWrapAsError; 2592var errors = _dereq_("./errors"); 2593var OperationalError = errors.OperationalError; 2594var es5 = _dereq_("./es5"); 2595 2596function isUntypedError(obj) { 2597 return obj instanceof Error && 2598 es5.getPrototypeOf(obj) === Error.prototype; 2599} 2600 2601var rErrorKey = /^(?:name|message|stack|cause)$/; 2602function wrapAsOperationalError(obj) { 2603 var ret; 2604 if (isUntypedError(obj)) { 2605 ret = new OperationalError(obj); 2606 ret.name = obj.name; 2607 ret.message = obj.message; 2608 ret.stack = obj.stack; 2609 var keys = es5.keys(obj); 2610 for (var i = 0; i < keys.length; ++i) { 2611 var key = keys[i]; 2612 if (!rErrorKey.test(key)) { 2613 ret[key] = obj[key]; 2614 } 2615 } 2616 return ret; 2617 } 2618 util.markAsOriginatingFromRejection(obj); 2619 return obj; 2620} 2621 2622function nodebackForPromise(promise, multiArgs) { 2623 return function(err, value) { 2624 if (promise === null) return; 2625 if (err) { 2626 var wrapped = wrapAsOperationalError(maybeWrapAsError(err)); 2627 promise._attachExtraTrace(wrapped); 2628 promise._reject(wrapped); 2629 } else if (!multiArgs) { 2630 promise._fulfill(value); 2631 } else { 2632 var args = [].slice.call(arguments, 1);; 2633 promise._fulfill(args); 2634 } 2635 promise = null; 2636 }; 2637} 2638 2639module.exports = nodebackForPromise; 2640 2641},{"./errors":12,"./es5":13,"./util":36}],21:[function(_dereq_,module,exports){ 2642"use strict"; 2643module.exports = function(Promise) { 2644var util = _dereq_("./util"); 2645var async = Promise._async; 2646var tryCatch = util.tryCatch; 2647var errorObj = util.errorObj; 2648 2649function spreadAdapter(val, nodeback) { 2650 var promise = this; 2651 if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback); 2652 var ret = 2653 tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val)); 2654 if (ret === errorObj) { 2655 async.throwLater(ret.e); 2656 } 2657} 2658 2659function successAdapter(val, nodeback) { 2660 var promise = this; 2661 var receiver = promise._boundValue(); 2662 var ret = val === undefined 2663 ? tryCatch(nodeback).call(receiver, null) 2664 : tryCatch(nodeback).call(receiver, null, val); 2665 if (ret === errorObj) { 2666 async.throwLater(ret.e); 2667 } 2668} 2669function errorAdapter(reason, nodeback) { 2670 var promise = this; 2671 if (!reason) { 2672 var newReason = new Error(reason + ""); 2673 newReason.cause = reason; 2674 reason = newReason; 2675 } 2676 var ret = tryCatch(nodeback).call(promise._boundValue(), reason); 2677 if (ret === errorObj) { 2678 async.throwLater(ret.e); 2679 } 2680} 2681 2682Promise.prototype.asCallback = Promise.prototype.nodeify = function (nodeback, 2683 options) { 2684 if (typeof nodeback == "function") { 2685 var adapter = successAdapter; 2686 if (options !== undefined && Object(options).spread) { 2687 adapter = spreadAdapter; 2688 } 2689 this._then( 2690 adapter, 2691 errorAdapter, 2692 undefined, 2693 this, 2694 nodeback 2695 ); 2696 } 2697 return this; 2698}; 2699}; 2700 2701},{"./util":36}],22:[function(_dereq_,module,exports){ 2702"use strict"; 2703module.exports = function() { 2704var makeSelfResolutionError = function () { 2705 return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 2706}; 2707var reflectHandler = function() { 2708 return new Promise.PromiseInspection(this._target()); 2709}; 2710var apiRejection = function(msg) { 2711 return Promise.reject(new TypeError(msg)); 2712}; 2713function Proxyable() {} 2714var UNDEFINED_BINDING = {}; 2715var util = _dereq_("./util"); 2716 2717var getDomain; 2718if (util.isNode) { 2719 getDomain = function() { 2720 var ret = process.domain; 2721 if (ret === undefined) ret = null; 2722 return ret; 2723 }; 2724} else { 2725 getDomain = function() { 2726 return null; 2727 }; 2728} 2729util.notEnumerableProp(Promise, "_getDomain", getDomain); 2730 2731var es5 = _dereq_("./es5"); 2732var Async = _dereq_("./async"); 2733var async = new Async(); 2734es5.defineProperty(Promise, "_async", {value: async}); 2735var errors = _dereq_("./errors"); 2736var TypeError = Promise.TypeError = errors.TypeError; 2737Promise.RangeError = errors.RangeError; 2738var CancellationError = Promise.CancellationError = errors.CancellationError; 2739Promise.TimeoutError = errors.TimeoutError; 2740Promise.OperationalError = errors.OperationalError; 2741Promise.RejectionError = errors.OperationalError; 2742Promise.AggregateError = errors.AggregateError; 2743var INTERNAL = function(){}; 2744var APPLY = {}; 2745var NEXT_FILTER = {}; 2746var tryConvertToPromise = _dereq_("./thenables")(Promise, INTERNAL); 2747var PromiseArray = 2748 _dereq_("./promise_array")(Promise, INTERNAL, 2749 tryConvertToPromise, apiRejection, Proxyable); 2750var Context = _dereq_("./context")(Promise); 2751 /*jshint unused:false*/ 2752var createContext = Context.create; 2753var debug = _dereq_("./debuggability")(Promise, Context); 2754var CapturedTrace = debug.CapturedTrace; 2755var PassThroughHandlerContext = 2756 _dereq_("./finally")(Promise, tryConvertToPromise, NEXT_FILTER); 2757var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER); 2758var nodebackForPromise = _dereq_("./nodeback"); 2759var errorObj = util.errorObj; 2760var tryCatch = util.tryCatch; 2761function check(self, executor) { 2762 if (self == null || self.constructor !== Promise) { 2763 throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 2764 } 2765 if (typeof executor !== "function") { 2766 throw new TypeError("expecting a function but got " + util.classString(executor)); 2767 } 2768 2769} 2770 2771function Promise(executor) { 2772 if (executor !== INTERNAL) { 2773 check(this, executor); 2774 } 2775 this._bitField = 0; 2776 this._fulfillmentHandler0 = undefined; 2777 this._rejectionHandler0 = undefined; 2778 this._promise0 = undefined; 2779 this._receiver0 = undefined; 2780 this._resolveFromExecutor(executor); 2781 this._promiseCreated(); 2782 this._fireEvent("promiseCreated", this); 2783} 2784 2785Promise.prototype.toString = function () { 2786 return "[object Promise]"; 2787}; 2788 2789Promise.prototype.caught = Promise.prototype["catch"] = function (fn) { 2790 var len = arguments.length; 2791 if (len > 1) { 2792 var catchInstances = new Array(len - 1), 2793 j = 0, i; 2794 for (i = 0; i < len - 1; ++i) { 2795 var item = arguments[i]; 2796 if (util.isObject(item)) { 2797 catchInstances[j++] = item; 2798 } else { 2799 return apiRejection("Catch statement predicate: " + 2800 "expecting an object but got " + util.classString(item)); 2801 } 2802 } 2803 catchInstances.length = j; 2804 fn = arguments[i]; 2805 return this.then(undefined, catchFilter(catchInstances, fn, this)); 2806 } 2807 return this.then(undefined, fn); 2808}; 2809 2810Promise.prototype.reflect = function () { 2811 return this._then(reflectHandler, 2812 reflectHandler, undefined, this, undefined); 2813}; 2814 2815Promise.prototype.then = function (didFulfill, didReject) { 2816 if (debug.warnings() && arguments.length > 0 && 2817 typeof didFulfill !== "function" && 2818 typeof didReject !== "function") { 2819 var msg = ".then() only accepts functions but was passed: " + 2820 util.classString(didFulfill); 2821 if (arguments.length > 1) { 2822 msg += ", " + util.classString(didReject); 2823 } 2824 this._warn(msg); 2825 } 2826 return this._then(didFulfill, didReject, undefined, undefined, undefined); 2827}; 2828 2829Promise.prototype.done = function (didFulfill, didReject) { 2830 var promise = 2831 this._then(didFulfill, didReject, undefined, undefined, undefined); 2832 promise._setIsFinal(); 2833}; 2834 2835Promise.prototype.spread = function (fn) { 2836 if (typeof fn !== "function") { 2837 return apiRejection("expecting a function but got " + util.classString(fn)); 2838 } 2839 return this.all()._then(fn, undefined, undefined, APPLY, undefined); 2840}; 2841 2842Promise.prototype.toJSON = function () { 2843 var ret = { 2844 isFulfilled: false, 2845 isRejected: false, 2846 fulfillmentValue: undefined, 2847 rejectionReason: undefined 2848 }; 2849 if (this.isFulfilled()) { 2850 ret.fulfillmentValue = this.value(); 2851 ret.isFulfilled = true; 2852 } else if (this.isRejected()) { 2853 ret.rejectionReason = this.reason(); 2854 ret.isRejected = true; 2855 } 2856 return ret; 2857}; 2858 2859Promise.prototype.all = function () { 2860 if (arguments.length > 0) { 2861 this._warn(".all() was passed arguments but it does not take any"); 2862 } 2863 return new PromiseArray(this).promise(); 2864}; 2865 2866Promise.prototype.error = function (fn) { 2867 return this.caught(util.originatesFromRejection, fn); 2868}; 2869 2870Promise.getNewLibraryCopy = module.exports; 2871 2872Promise.is = function (val) { 2873 return val instanceof Promise; 2874}; 2875 2876Promise.fromNode = Promise.fromCallback = function(fn) { 2877 var ret = new Promise(INTERNAL); 2878 ret._captureStackTrace(); 2879 var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs 2880 : false; 2881 var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs)); 2882 if (result === errorObj) { 2883 ret._rejectCallback(result.e, true); 2884 } 2885 if (!ret._isFateSealed()) ret._setAsyncGuaranteed(); 2886 return ret; 2887}; 2888 2889Promise.all = function (promises) { 2890 return new PromiseArray(promises).promise(); 2891}; 2892 2893Promise.cast = function (obj) { 2894 var ret = tryConvertToPromise(obj); 2895 if (!(ret instanceof Promise)) { 2896 ret = new Promise(INTERNAL); 2897 ret._captureStackTrace(); 2898 ret._setFulfilled(); 2899 ret._rejectionHandler0 = obj; 2900 } 2901 return ret; 2902}; 2903 2904Promise.resolve = Promise.fulfilled = Promise.cast; 2905 2906Promise.reject = Promise.rejected = function (reason) { 2907 var ret = new Promise(INTERNAL); 2908 ret._captureStackTrace(); 2909 ret._rejectCallback(reason, true); 2910 return ret; 2911}; 2912 2913Promise.setScheduler = function(fn) { 2914 if (typeof fn !== "function") { 2915 throw new TypeError("expecting a function but got " + util.classString(fn)); 2916 } 2917 return async.setScheduler(fn); 2918}; 2919 2920Promise.prototype._then = function ( 2921 didFulfill, 2922 didReject, 2923 _, receiver, 2924 internalData 2925) { 2926 var haveInternalData = internalData !== undefined; 2927 var promise = haveInternalData ? internalData : new Promise(INTERNAL); 2928 var target = this._target(); 2929 var bitField = target._bitField; 2930 2931 if (!haveInternalData) { 2932 promise._propagateFrom(this, 3); 2933 promise._captureStackTrace(); 2934 if (receiver === undefined && 2935 ((this._bitField & 2097152) !== 0)) { 2936 if (!((bitField & 50397184) === 0)) { 2937 receiver = this._boundValue(); 2938 } else { 2939 receiver = target === this ? undefined : this._boundTo; 2940 } 2941 } 2942 this._fireEvent("promiseChained", this, promise); 2943 } 2944 2945 var domain = getDomain(); 2946 if (!((bitField & 50397184) === 0)) { 2947 var handler, value, settler = target._settlePromiseCtx; 2948 if (((bitField & 33554432) !== 0)) { 2949 value = target._rejectionHandler0; 2950 handler = didFulfill; 2951 } else if (((bitField & 16777216) !== 0)) { 2952 value = target._fulfillmentHandler0; 2953 handler = didReject; 2954 target._unsetRejectionIsUnhandled(); 2955 } else { 2956 settler = target._settlePromiseLateCancellationObserver; 2957 value = new CancellationError("late cancellation observer"); 2958 target._attachExtraTrace(value); 2959 handler = didReject; 2960 } 2961 2962 async.invoke(settler, target, { 2963 handler: domain === null ? handler 2964 : (typeof handler === "function" && 2965 util.domainBind(domain, handler)), 2966 promise: promise, 2967 receiver: receiver, 2968 value: value 2969 }); 2970 } else { 2971 target._addCallbacks(didFulfill, didReject, promise, receiver, domain); 2972 } 2973 2974 return promise; 2975}; 2976 2977Promise.prototype._length = function () { 2978 return this._bitField & 65535; 2979}; 2980 2981Promise.prototype._isFateSealed = function () { 2982 return (this._bitField & 117506048) !== 0; 2983}; 2984 2985Promise.prototype._isFollowing = function () { 2986 return (this._bitField & 67108864) === 67108864; 2987}; 2988 2989Promise.prototype._setLength = function (len) { 2990 this._bitField = (this._bitField & -65536) | 2991 (len & 65535); 2992}; 2993 2994Promise.prototype._setFulfilled = function () { 2995 this._bitField = this._bitField | 33554432; 2996 this._fireEvent("promiseFulfilled", this); 2997}; 2998 2999Promise.prototype._setRejected = function () { 3000 this._bitField = this._bitField | 16777216; 3001 this._fireEvent("promiseRejected", this); 3002}; 3003 3004Promise.prototype._setFollowing = function () { 3005 this._bitField = this._bitField | 67108864; 3006 this._fireEvent("promiseResolved", this); 3007}; 3008 3009Promise.prototype._setIsFinal = function () { 3010 this._bitField = this._bitField | 4194304; 3011}; 3012 3013Promise.prototype._isFinal = function () { 3014 return (this._bitField & 4194304) > 0; 3015}; 3016 3017Promise.prototype._unsetCancelled = function() { 3018 this._bitField = this._bitField & (~65536); 3019}; 3020 3021Promise.prototype._setCancelled = function() { 3022 this._bitField = this._bitField | 65536; 3023 this._fireEvent("promiseCancelled", this); 3024}; 3025 3026Promise.prototype._setWillBeCancelled = function() { 3027 this._bitField = this._bitField | 8388608; 3028}; 3029 3030Promise.prototype._setAsyncGuaranteed = function() { 3031 if (async.hasCustomScheduler()) return; 3032 this._bitField = this._bitField | 134217728; 3033}; 3034 3035Promise.prototype._receiverAt = function (index) { 3036 var ret = index === 0 ? this._receiver0 : this[ 3037 index * 4 - 4 + 3]; 3038 if (ret === UNDEFINED_BINDING) { 3039 return undefined; 3040 } else if (ret === undefined && this._isBound()) { 3041 return this._boundValue(); 3042 } 3043 return ret; 3044}; 3045 3046Promise.prototype._promiseAt = function (index) { 3047 return this[ 3048 index * 4 - 4 + 2]; 3049}; 3050 3051Promise.prototype._fulfillmentHandlerAt = function (index) { 3052 return this[ 3053 index * 4 - 4 + 0]; 3054}; 3055 3056Promise.prototype._rejectionHandlerAt = function (index) { 3057 return this[ 3058 index * 4 - 4 + 1]; 3059}; 3060 3061Promise.prototype._boundValue = function() {}; 3062 3063Promise.prototype._migrateCallback0 = function (follower) { 3064 var bitField = follower._bitField; 3065 var fulfill = follower._fulfillmentHandler0; 3066 var reject = follower._rejectionHandler0; 3067 var promise = follower._promise0; 3068 var receiver = follower._receiverAt(0); 3069 if (receiver === undefined) receiver = UNDEFINED_BINDING; 3070 this._addCallbacks(fulfill, reject, promise, receiver, null); 3071}; 3072 3073Promise.prototype._migrateCallbackAt = function (follower, index) { 3074 var fulfill = follower._fulfillmentHandlerAt(index); 3075 var reject = follower._rejectionHandlerAt(index); 3076 var promise = follower._promiseAt(index); 3077 var receiver = follower._receiverAt(index); 3078 if (receiver === undefined) receiver = UNDEFINED_BINDING; 3079 this._addCallbacks(fulfill, reject, promise, receiver, null); 3080}; 3081 3082Promise.prototype._addCallbacks = function ( 3083 fulfill, 3084 reject, 3085 promise, 3086 receiver, 3087 domain 3088) { 3089 var index = this._length(); 3090 3091 if (index >= 65535 - 4) { 3092 index = 0; 3093 this._setLength(0); 3094 } 3095 3096 if (index === 0) { 3097 this._promise0 = promise; 3098 this._receiver0 = receiver; 3099 if (typeof fulfill === "function") { 3100 this._fulfillmentHandler0 = 3101 domain === null ? fulfill : util.domainBind(domain, fulfill); 3102 } 3103 if (typeof reject === "function") { 3104 this._rejectionHandler0 = 3105 domain === null ? reject : util.domainBind(domain, reject); 3106 } 3107 } else { 3108 var base = index * 4 - 4; 3109 this[base + 2] = promise; 3110 this[base + 3] = receiver; 3111 if (typeof fulfill === "function") { 3112 this[base + 0] = 3113 domain === null ? fulfill : util.domainBind(domain, fulfill); 3114 } 3115 if (typeof reject === "function") { 3116 this[base + 1] = 3117 domain === null ? reject : util.domainBind(domain, reject); 3118 } 3119 } 3120 this._setLength(index + 1); 3121 return index; 3122}; 3123 3124Promise.prototype._proxy = function (proxyable, arg) { 3125 this._addCallbacks(undefined, undefined, arg, proxyable, null); 3126}; 3127 3128Promise.prototype._resolveCallback = function(value, shouldBind) { 3129 if (((this._bitField & 117506048) !== 0)) return; 3130 if (value === this) 3131 return this._rejectCallback(makeSelfResolutionError(), false); 3132 var maybePromise = tryConvertToPromise(value, this); 3133 if (!(maybePromise instanceof Promise)) return this._fulfill(value); 3134 3135 if (shouldBind) this._propagateFrom(maybePromise, 2); 3136 3137 var promise = maybePromise._target(); 3138 3139 if (promise === this) { 3140 this._reject(makeSelfResolutionError()); 3141 return; 3142 } 3143 3144 var bitField = promise._bitField; 3145 if (((bitField & 50397184) === 0)) { 3146 var len = this._length(); 3147 if (len > 0) promise._migrateCallback0(this); 3148 for (var i = 1; i < len; ++i) { 3149 promise._migrateCallbackAt(this, i); 3150 } 3151 this._setFollowing(); 3152 this._setLength(0); 3153 this._setFollowee(promise); 3154 } else if (((bitField & 33554432) !== 0)) { 3155 this._fulfill(promise._value()); 3156 } else if (((bitField & 16777216) !== 0)) { 3157 this._reject(promise._reason()); 3158 } else { 3159 var reason = new CancellationError("late cancellation observer"); 3160 promise._attachExtraTrace(reason); 3161 this._reject(reason); 3162 } 3163}; 3164 3165Promise.prototype._rejectCallback = 3166function(reason, synchronous, ignoreNonErrorWarnings) { 3167 var trace = util.ensureErrorObject(reason); 3168 var hasStack = trace === reason; 3169 if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) { 3170 var message = "a promise was rejected with a non-error: " + 3171 util.classString(reason); 3172 this._warn(message, true); 3173 } 3174 this._attachExtraTrace(trace, synchronous ? hasStack : false); 3175 this._reject(reason); 3176}; 3177 3178Promise.prototype._resolveFromExecutor = function (executor) { 3179 if (executor === INTERNAL) return; 3180 var promise = this; 3181 this._captureStackTrace(); 3182 this._pushContext(); 3183 var synchronous = true; 3184 var r = this._execute(executor, function(value) { 3185 promise._resolveCallback(value); 3186 }, function (reason) { 3187 promise._rejectCallback(reason, synchronous); 3188 }); 3189 synchronous = false; 3190 this._popContext(); 3191 3192 if (r !== undefined) { 3193 promise._rejectCallback(r, true); 3194 } 3195}; 3196 3197Promise.prototype._settlePromiseFromHandler = function ( 3198 handler, receiver, value, promise 3199) { 3200 var bitField = promise._bitField; 3201 if (((bitField & 65536) !== 0)) return; 3202 promise._pushContext(); 3203 var x; 3204 if (receiver === APPLY) { 3205 if (!value || typeof value.length !== "number") { 3206 x = errorObj; 3207 x.e = new TypeError("cannot .spread() a non-array: " + 3208 util.classString(value)); 3209 } else { 3210 x = tryCatch(handler).apply(this._boundValue(), value); 3211 } 3212 } else { 3213 x = tryCatch(handler).call(receiver, value); 3214 } 3215 var promiseCreated = promise._popContext(); 3216 bitField = promise._bitField; 3217 if (((bitField & 65536) !== 0)) return; 3218 3219 if (x === NEXT_FILTER) { 3220 promise._reject(value); 3221 } else if (x === errorObj) { 3222 promise._rejectCallback(x.e, false); 3223 } else { 3224 debug.checkForgottenReturns(x, promiseCreated, "", promise, this); 3225 promise._resolveCallback(x); 3226 } 3227}; 3228 3229Promise.prototype._target = function() { 3230 var ret = this; 3231 while (ret._isFollowing()) ret = ret._followee(); 3232 return ret; 3233}; 3234 3235Promise.prototype._followee = function() { 3236 return this._rejectionHandler0; 3237}; 3238 3239Promise.prototype._setFollowee = function(promise) { 3240 this._rejectionHandler0 = promise; 3241}; 3242 3243Promise.prototype._settlePromise = function(promise, handler, receiver, value) { 3244 var isPromise = promise instanceof Promise; 3245 var bitField = this._bitField; 3246 var asyncGuaranteed = ((bitField & 134217728) !== 0); 3247 if (((bitField & 65536) !== 0)) { 3248 if (isPromise) promise._invokeInternalOnCancel(); 3249 3250 if (receiver instanceof PassThroughHandlerContext && 3251 receiver.isFinallyHandler()) { 3252 receiver.cancelPromise = promise; 3253 if (tryCatch(handler).call(receiver, value) === errorObj) { 3254 promise._reject(errorObj.e); 3255 } 3256 } else if (handler === reflectHandler) { 3257 promise._fulfill(reflectHandler.call(receiver)); 3258 } else if (receiver instanceof Proxyable) { 3259 receiver._promiseCancelled(promise); 3260 } else if (isPromise || promise instanceof PromiseArray) { 3261 promise._cancel(); 3262 } else { 3263 receiver.cancel(); 3264 } 3265 } else if (typeof handler === "function") { 3266 if (!isPromise) { 3267 handler.call(receiver, value, promise); 3268 } else { 3269 if (asyncGuaranteed) promise._setAsyncGuaranteed(); 3270 this._settlePromiseFromHandler(handler, receiver, value, promise); 3271 } 3272 } else if (receiver instanceof Proxyable) { 3273 if (!receiver._isResolved()) { 3274 if (((bitField & 33554432) !== 0)) { 3275 receiver._promiseFulfilled(value, promise); 3276 } else { 3277 receiver._promiseRejected(value, promise); 3278 } 3279 } 3280 } else if (isPromise) { 3281 if (asyncGuaranteed) promise._setAsyncGuaranteed(); 3282 if (((bitField & 33554432) !== 0)) { 3283 promise._fulfill(value); 3284 } else { 3285 promise._reject(value); 3286 } 3287 } 3288}; 3289 3290Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) { 3291 var handler = ctx.handler; 3292 var promise = ctx.promise; 3293 var receiver = ctx.receiver; 3294 var value = ctx.value; 3295 if (typeof handler === "function") { 3296 if (!(promise instanceof Promise)) { 3297 handler.call(receiver, value, promise); 3298 } else { 3299 this._settlePromiseFromHandler(handler, receiver, value, promise); 3300 } 3301 } else if (promise instanceof Promise) { 3302 promise._reject(value); 3303 } 3304}; 3305 3306Promise.prototype._settlePromiseCtx = function(ctx) { 3307 this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value); 3308}; 3309 3310Promise.prototype._settlePromise0 = function(handler, value, bitField) { 3311 var promise = this._promise0; 3312 var receiver = this._receiverAt(0); 3313 this._promise0 = undefined; 3314 this._receiver0 = undefined; 3315 this._settlePromise(promise, handler, receiver, value); 3316}; 3317 3318Promise.prototype._clearCallbackDataAtIndex = function(index) { 3319 var base = index * 4 - 4; 3320 this[base + 2] = 3321 this[base + 3] = 3322 this[base + 0] = 3323 this[base + 1] = undefined; 3324}; 3325 3326Promise.prototype._fulfill = function (value) { 3327 var bitField = this._bitField; 3328 if (((bitField & 117506048) >>> 16)) return; 3329 if (value === this) { 3330 var err = makeSelfResolutionError(); 3331 this._attachExtraTrace(err); 3332 return this._reject(err); 3333 } 3334 this._setFulfilled(); 3335 this._rejectionHandler0 = value; 3336 3337 if ((bitField & 65535) > 0) { 3338 if (((bitField & 134217728) !== 0)) { 3339 this._settlePromises(); 3340 } else { 3341 async.settlePromises(this); 3342 } 3343 this._dereferenceTrace(); 3344 } 3345}; 3346 3347Promise.prototype._reject = function (reason) { 3348 var bitField = this._bitField; 3349 if (((bitField & 117506048) >>> 16)) return; 3350 this._setRejected(); 3351 this._fulfillmentHandler0 = reason; 3352 3353 if (this._isFinal()) { 3354 return async.fatalError(reason, util.isNode); 3355 } 3356 3357 if ((bitField & 65535) > 0) { 3358 async.settlePromises(this); 3359 } else { 3360 this._ensurePossibleRejectionHandled(); 3361 } 3362}; 3363 3364Promise.prototype._fulfillPromises = function (len, value) { 3365 for (var i = 1; i < len; i++) { 3366 var handler = this._fulfillmentHandlerAt(i); 3367 var promise = this._promiseAt(i); 3368 var receiver = this._receiverAt(i); 3369 this._clearCallbackDataAtIndex(i); 3370 this._settlePromise(promise, handler, receiver, value); 3371 } 3372}; 3373 3374Promise.prototype._rejectPromises = function (len, reason) { 3375 for (var i = 1; i < len; i++) { 3376 var handler = this._rejectionHandlerAt(i); 3377 var promise = this._promiseAt(i); 3378 var receiver = this._receiverAt(i); 3379 this._clearCallbackDataAtIndex(i); 3380 this._settlePromise(promise, handler, receiver, reason); 3381 } 3382}; 3383 3384Promise.prototype._settlePromises = function () { 3385 var bitField = this._bitField; 3386 var len = (bitField & 65535); 3387 3388 if (len > 0) { 3389 if (((bitField & 16842752) !== 0)) { 3390 var reason = this._fulfillmentHandler0; 3391 this._settlePromise0(this._rejectionHandler0, reason, bitField); 3392 this._rejectPromises(len, reason); 3393 } else { 3394 var value = this._rejectionHandler0; 3395 this._settlePromise0(this._fulfillmentHandler0, value, bitField); 3396 this._fulfillPromises(len, value); 3397 } 3398 this._setLength(0); 3399 } 3400 this._clearCancellationData(); 3401}; 3402 3403Promise.prototype._settledValue = function() { 3404 var bitField = this._bitField; 3405 if (((bitField & 33554432) !== 0)) { 3406 return this._rejectionHandler0; 3407 } else if (((bitField & 16777216) !== 0)) { 3408 return this._fulfillmentHandler0; 3409 } 3410}; 3411 3412function deferResolve(v) {this.promise._resolveCallback(v);} 3413function deferReject(v) {this.promise._rejectCallback(v, false);} 3414 3415Promise.defer = Promise.pending = function() { 3416 debug.deprecated("Promise.defer", "new Promise"); 3417 var promise = new Promise(INTERNAL); 3418 return { 3419 promise: promise, 3420 resolve: deferResolve, 3421 reject: deferReject 3422 }; 3423}; 3424 3425util.notEnumerableProp(Promise, 3426 "_makeSelfResolutionError", 3427 makeSelfResolutionError); 3428 3429_dereq_("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection, 3430 debug); 3431_dereq_("./bind")(Promise, INTERNAL, tryConvertToPromise, debug); 3432_dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug); 3433_dereq_("./direct_resolve")(Promise); 3434_dereq_("./synchronous_inspection")(Promise); 3435_dereq_("./join")( 3436 Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain); 3437Promise.Promise = Promise; 3438Promise.version = "3.5.4"; 3439_dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug); 3440_dereq_('./call_get.js')(Promise); 3441_dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug); 3442_dereq_('./timers.js')(Promise, INTERNAL, debug); 3443_dereq_('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug); 3444_dereq_('./nodeify.js')(Promise); 3445_dereq_('./promisify.js')(Promise, INTERNAL); 3446_dereq_('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection); 3447_dereq_('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection); 3448_dereq_('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug); 3449_dereq_('./settle.js')(Promise, PromiseArray, debug); 3450_dereq_('./some.js')(Promise, PromiseArray, apiRejection); 3451_dereq_('./filter.js')(Promise, INTERNAL); 3452_dereq_('./each.js')(Promise, INTERNAL); 3453_dereq_('./any.js')(Promise); 3454 3455 util.toFastProperties(Promise); 3456 util.toFastProperties(Promise.prototype); 3457 function fillTypes(value) { 3458 var p = new Promise(INTERNAL); 3459 p._fulfillmentHandler0 = value; 3460 p._rejectionHandler0 = value; 3461 p._promise0 = value; 3462 p._receiver0 = value; 3463 } 3464 // Complete slack tracking, opt out of field-type tracking and 3465 // stabilize map 3466 fillTypes({a: 1}); 3467 fillTypes({b: 2}); 3468 fillTypes({c: 3}); 3469 fillTypes(1); 3470 fillTypes(function(){}); 3471 fillTypes(undefined); 3472 fillTypes(false); 3473 fillTypes(new Promise(INTERNAL)); 3474 debug.setBounds(Async.firstLineError, util.lastLineError); 3475 return Promise; 3476 3477}; 3478 3479},{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(_dereq_,module,exports){ 3480"use strict"; 3481module.exports = function(Promise, INTERNAL, tryConvertToPromise, 3482 apiRejection, Proxyable) { 3483var util = _dereq_("./util"); 3484var isArray = util.isArray; 3485 3486function toResolutionValue(val) { 3487 switch(val) { 3488 case -2: return []; 3489 case -3: return {}; 3490 case -6: return new Map(); 3491 } 3492} 3493 3494function PromiseArray(values) { 3495 var promise = this._promise = new Promise(INTERNAL); 3496 if (values instanceof Promise) { 3497 promise._propagateFrom(values, 3); 3498 } 3499 promise._setOnCancel(this); 3500 this._values = values; 3501 this._length = 0; 3502 this._totalResolved = 0; 3503 this._init(undefined, -2); 3504} 3505util.inherits(PromiseArray, Proxyable); 3506 3507PromiseArray.prototype.length = function () { 3508 return this._length; 3509}; 3510 3511PromiseArray.prototype.promise = function () { 3512 return this._promise; 3513}; 3514 3515PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) { 3516 var values = tryConvertToPromise(this._values, this._promise); 3517 if (values instanceof Promise) { 3518 values = values._target(); 3519 var bitField = values._bitField; 3520 ; 3521 this._values = values; 3522 3523 if (((bitField & 50397184) === 0)) { 3524 this._promise._setAsyncGuaranteed(); 3525 return values._then( 3526 init, 3527 this._reject, 3528 undefined, 3529 this, 3530 resolveValueIfEmpty 3531 ); 3532 } else if (((bitField & 33554432) !== 0)) { 3533 values = values._value(); 3534 } else if (((bitField & 16777216) !== 0)) { 3535 return this._reject(values._reason()); 3536 } else { 3537 return this._cancel(); 3538 } 3539 } 3540 values = util.asArray(values); 3541 if (values === null) { 3542 var err = apiRejection( 3543 "expecting an array or an iterable object but got " + util.classString(values)).reason(); 3544 this._promise._rejectCallback(err, false); 3545 return; 3546 } 3547 3548 if (values.length === 0) { 3549 if (resolveValueIfEmpty === -5) { 3550 this._resolveEmptyArray(); 3551 } 3552 else { 3553 this._resolve(toResolutionValue(resolveValueIfEmpty)); 3554 } 3555 return; 3556 } 3557 this._iterate(values); 3558}; 3559 3560PromiseArray.prototype._iterate = function(values) { 3561 var len = this.getActualLength(values.length); 3562 this._length = len; 3563 this._values = this.shouldCopyValues() ? new Array(len) : this._values; 3564 var result = this._promise; 3565 var isResolved = false; 3566 var bitField = null; 3567 for (var i = 0; i < len; ++i) { 3568 var maybePromise = tryConvertToPromise(values[i], result); 3569 3570 if (maybePromise instanceof Promise) { 3571 maybePromise = maybePromise._target(); 3572 bitField = maybePromise._bitField; 3573 } else { 3574 bitField = null; 3575 } 3576 3577 if (isResolved) { 3578 if (bitField !== null) { 3579 maybePromise.suppressUnhandledRejections(); 3580 } 3581 } else if (bitField !== null) { 3582 if (((bitField & 50397184) === 0)) { 3583 maybePromise._proxy(this, i); 3584 this._values[i] = maybePromise; 3585 } else if (((bitField & 33554432) !== 0)) { 3586 isResolved = this._promiseFulfilled(maybePromise._value(), i); 3587 } else if (((bitField & 16777216) !== 0)) { 3588 isResolved = this._promiseRejected(maybePromise._reason(), i); 3589 } else { 3590 isResolved = this._promiseCancelled(i); 3591 } 3592 } else { 3593 isResolved = this._promiseFulfilled(maybePromise, i); 3594 } 3595 } 3596 if (!isResolved) result._setAsyncGuaranteed(); 3597}; 3598 3599PromiseArray.prototype._isResolved = function () { 3600 return this._values === null; 3601}; 3602 3603PromiseArray.prototype._resolve = function (value) { 3604 this._values = null; 3605 this._promise._fulfill(value); 3606}; 3607 3608PromiseArray.prototype._cancel = function() { 3609 if (this._isResolved() || !this._promise._isCancellable()) return; 3610 this._values = null; 3611 this._promise._cancel(); 3612}; 3613 3614PromiseArray.prototype._reject = function (reason) { 3615 this._values = null; 3616 this._promise._rejectCallback(reason, false); 3617}; 3618 3619PromiseArray.prototype._promiseFulfilled = function (value, index) { 3620 this._values[index] = value; 3621 var totalResolved = ++this._totalResolved; 3622 if (totalResolved >= this._length) { 3623 this._resolve(this._values); 3624 return true; 3625 } 3626 return false; 3627}; 3628 3629PromiseArray.prototype._promiseCancelled = function() { 3630 this._cancel(); 3631 return true; 3632}; 3633 3634PromiseArray.prototype._promiseRejected = function (reason) { 3635 this._totalResolved++; 3636 this._reject(reason); 3637 return true; 3638}; 3639 3640PromiseArray.prototype._resultCancelled = function() { 3641 if (this._isResolved()) return; 3642 var values = this._values; 3643 this._cancel(); 3644 if (values instanceof Promise) { 3645 values.cancel(); 3646 } else { 3647 for (var i = 0; i < values.length; ++i) { 3648 if (values[i] instanceof Promise) { 3649 values[i].cancel(); 3650 } 3651 } 3652 } 3653}; 3654 3655PromiseArray.prototype.shouldCopyValues = function () { 3656 return true; 3657}; 3658 3659PromiseArray.prototype.getActualLength = function (len) { 3660 return len; 3661}; 3662 3663return PromiseArray; 3664}; 3665 3666},{"./util":36}],24:[function(_dereq_,module,exports){ 3667"use strict"; 3668module.exports = function(Promise, INTERNAL) { 3669var THIS = {}; 3670var util = _dereq_("./util"); 3671var nodebackForPromise = _dereq_("./nodeback"); 3672var withAppended = util.withAppended; 3673var maybeWrapAsError = util.maybeWrapAsError; 3674var canEvaluate = util.canEvaluate; 3675var TypeError = _dereq_("./errors").TypeError; 3676var defaultSuffix = "Async"; 3677var defaultPromisified = {__isPromisified__: true}; 3678var noCopyProps = [ 3679 "arity", "length", 3680 "name", 3681 "arguments", 3682 "caller", 3683 "callee", 3684 "prototype", 3685 "__isPromisified__" 3686]; 3687var noCopyPropsPattern = new RegExp("^(?:" + noCopyProps.join("|") + ")$"); 3688 3689var defaultFilter = function(name) { 3690 return util.isIdentifier(name) && 3691 name.charAt(0) !== "_" && 3692 name !== "constructor"; 3693}; 3694 3695function propsFilter(key) { 3696 return !noCopyPropsPattern.test(key); 3697} 3698 3699function isPromisified(fn) { 3700 try { 3701 return fn.__isPromisified__ === true; 3702 } 3703 catch (e) { 3704 return false; 3705 } 3706} 3707 3708function hasPromisified(obj, key, suffix) { 3709 var val = util.getDataPropertyOrDefault(obj, key + suffix, 3710 defaultPromisified); 3711 return val ? isPromisified(val) : false; 3712} 3713function checkValid(ret, suffix, suffixRegexp) { 3714 for (var i = 0; i < ret.length; i += 2) { 3715 var key = ret[i]; 3716 if (suffixRegexp.test(key)) { 3717 var keyWithoutAsyncSuffix = key.replace(suffixRegexp, ""); 3718 for (var j = 0; j < ret.length; j += 2) { 3719 if (ret[j] === keyWithoutAsyncSuffix) { 3720 throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/MqrFmX\u000a" 3721 .replace("%s", suffix)); 3722 } 3723 } 3724 } 3725 } 3726} 3727 3728function promisifiableMethods(obj, suffix, suffixRegexp, filter) { 3729 var keys = util.inheritedDataKeys(obj); 3730 var ret = []; 3731 for (var i = 0; i < keys.length; ++i) { 3732 var key = keys[i]; 3733 var value = obj[key]; 3734 var passesDefaultFilter = filter === defaultFilter 3735 ? true : defaultFilter(key, value, obj); 3736 if (typeof value === "function" && 3737 !isPromisified(value) && 3738 !hasPromisified(obj, key, suffix) && 3739 filter(key, value, obj, passesDefaultFilter)) { 3740 ret.push(key, value); 3741 } 3742 } 3743 checkValid(ret, suffix, suffixRegexp); 3744 return ret; 3745} 3746 3747var escapeIdentRegex = function(str) { 3748 return str.replace(/([$])/, "\\$"); 3749}; 3750 3751var makeNodePromisifiedEval; 3752if (false) { var parameterCount, parameterDeclaration, argumentSequence, switchCaseArgumentOrder; } 3753 3754function makeNodePromisifiedClosure(callback, receiver, _, fn, __, multiArgs) { 3755 var defaultThis = (function() {return this;})(); 3756 var method = callback; 3757 if (typeof method === "string") { 3758 callback = fn; 3759 } 3760 function promisified() { 3761 var _receiver = receiver; 3762 if (receiver === THIS) _receiver = this; 3763 var promise = new Promise(INTERNAL); 3764 promise._captureStackTrace(); 3765 var cb = typeof method === "string" && this !== defaultThis 3766 ? this[method] : callback; 3767 var fn = nodebackForPromise(promise, multiArgs); 3768 try { 3769 cb.apply(_receiver, withAppended(arguments, fn)); 3770 } catch(e) { 3771 promise._rejectCallback(maybeWrapAsError(e), true, true); 3772 } 3773 if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); 3774 return promise; 3775 } 3776 util.notEnumerableProp(promisified, "__isPromisified__", true); 3777 return promisified; 3778} 3779 3780var makeNodePromisified = canEvaluate 3781 ? makeNodePromisifiedEval 3782 : makeNodePromisifiedClosure; 3783 3784function promisifyAll(obj, suffix, filter, promisifier, multiArgs) { 3785 var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$"); 3786 var methods = 3787 promisifiableMethods(obj, suffix, suffixRegexp, filter); 3788 3789 for (var i = 0, len = methods.length; i < len; i+= 2) { 3790 var key = methods[i]; 3791 var fn = methods[i+1]; 3792 var promisifiedKey = key + suffix; 3793 if (promisifier === makeNodePromisified) { 3794 obj[promisifiedKey] = 3795 makeNodePromisified(key, THIS, key, fn, suffix, multiArgs); 3796 } else { 3797 var promisified = promisifier(fn, function() { 3798 return makeNodePromisified(key, THIS, key, 3799 fn, suffix, multiArgs); 3800 }); 3801 util.notEnumerableProp(promisified, "__isPromisified__", true); 3802 obj[promisifiedKey] = promisified; 3803 } 3804 } 3805 util.toFastProperties(obj); 3806 return obj; 3807} 3808 3809function promisify(callback, receiver, multiArgs) { 3810 return makeNodePromisified(callback, receiver, undefined, 3811 callback, null, multiArgs); 3812} 3813 3814Promise.promisify = function (fn, options) { 3815 if (typeof fn !== "function") { 3816 throw new TypeError("expecting a function but got " + util.classString(fn)); 3817 } 3818 if (isPromisified(fn)) { 3819 return fn; 3820 } 3821 options = Object(options); 3822 var receiver = options.context === undefined ? THIS : options.context; 3823 var multiArgs = !!options.multiArgs; 3824 var ret = promisify(fn, receiver, multiArgs); 3825 util.copyDescriptors(fn, ret, propsFilter); 3826 return ret; 3827}; 3828 3829Promise.promisifyAll = function (target, options) { 3830 if (typeof target !== "function" && typeof target !== "object") { 3831 throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 3832 } 3833 options = Object(options); 3834 var multiArgs = !!options.multiArgs; 3835 var suffix = options.suffix; 3836 if (typeof suffix !== "string") suffix = defaultSuffix; 3837 var filter = options.filter; 3838 if (typeof filter !== "function") filter = defaultFilter; 3839 var promisifier = options.promisifier; 3840 if (typeof promisifier !== "function") promisifier = makeNodePromisified; 3841 3842 if (!util.isIdentifier(suffix)) { 3843 throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 3844 } 3845 3846 var keys = util.inheritedDataKeys(target); 3847 for (var i = 0; i < keys.length; ++i) { 3848 var value = target[keys[i]]; 3849 if (keys[i] !== "constructor" && 3850 util.isClass(value)) { 3851 promisifyAll(value.prototype, suffix, filter, promisifier, 3852 multiArgs); 3853 promisifyAll(value, suffix, filter, promisifier, multiArgs); 3854 } 3855 } 3856 3857 return promisifyAll(target, suffix, filter, promisifier, multiArgs); 3858}; 3859}; 3860 3861 3862},{"./errors":12,"./nodeback":20,"./util":36}],25:[function(_dereq_,module,exports){ 3863"use strict"; 3864module.exports = function( 3865 Promise, PromiseArray, tryConvertToPromise, apiRejection) { 3866var util = _dereq_("./util"); 3867var isObject = util.isObject; 3868var es5 = _dereq_("./es5"); 3869var Es6Map; 3870if (typeof Map === "function") Es6Map = Map; 3871 3872var mapToEntries = (function() { 3873 var index = 0; 3874 var size = 0; 3875 3876 function extractEntry(value, key) { 3877 this[index] = value; 3878 this[index + size] = key; 3879 index++; 3880 } 3881 3882 return function mapToEntries(map) { 3883 size = map.size; 3884 index = 0; 3885 var ret = new Array(map.size * 2); 3886 map.forEach(extractEntry, ret); 3887 return ret; 3888 }; 3889})(); 3890 3891var entriesToMap = function(entries) { 3892 var ret = new Es6Map(); 3893 var length = entries.length / 2 | 0; 3894 for (var i = 0; i < length; ++i) { 3895 var key = entries[length + i]; 3896 var value = entries[i]; 3897 ret.set(key, value); 3898 } 3899 return ret; 3900}; 3901 3902function PropertiesPromiseArray(obj) { 3903 var isMap = false; 3904 var entries; 3905 if (Es6Map !== undefined && obj instanceof Es6Map) { 3906 entries = mapToEntries(obj); 3907 isMap = true; 3908 } else { 3909 var keys = es5.keys(obj); 3910 var len = keys.length; 3911 entries = new Array(len * 2); 3912 for (var i = 0; i < len; ++i) { 3913 var key = keys[i]; 3914 entries[i] = obj[key]; 3915 entries[i + len] = key; 3916 } 3917 } 3918 this.constructor$(entries); 3919 this._isMap = isMap; 3920 this._init$(undefined, isMap ? -6 : -3); 3921} 3922util.inherits(PropertiesPromiseArray, PromiseArray); 3923 3924PropertiesPromiseArray.prototype._init = function () {}; 3925 3926PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) { 3927 this._values[index] = value; 3928 var totalResolved = ++this._totalResolved; 3929 if (totalResolved >= this._length) { 3930 var val; 3931 if (this._isMap) { 3932 val = entriesToMap(this._values); 3933 } else { 3934 val = {}; 3935 var keyOffset = this.length(); 3936 for (var i = 0, len = this.length(); i < len; ++i) { 3937 val[this._values[i + keyOffset]] = this._values[i]; 3938 } 3939 } 3940 this._resolve(val); 3941 return true; 3942 } 3943 return false; 3944}; 3945 3946PropertiesPromiseArray.prototype.shouldCopyValues = function () { 3947 return false; 3948}; 3949 3950PropertiesPromiseArray.prototype.getActualLength = function (len) { 3951 return len >> 1; 3952}; 3953 3954function props(promises) { 3955 var ret; 3956 var castValue = tryConvertToPromise(promises); 3957 3958 if (!isObject(castValue)) { 3959 return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 3960 } else if (castValue instanceof Promise) { 3961 ret = castValue._then( 3962 Promise.props, undefined, undefined, undefined, undefined); 3963 } else { 3964 ret = new PropertiesPromiseArray(castValue).promise(); 3965 } 3966 3967 if (castValue instanceof Promise) { 3968 ret._propagateFrom(castValue, 2); 3969 } 3970 return ret; 3971} 3972 3973Promise.prototype.props = function () { 3974 return props(this); 3975}; 3976 3977Promise.props = function (promises) { 3978 return props(promises); 3979}; 3980}; 3981 3982},{"./es5":13,"./util":36}],26:[function(_dereq_,module,exports){ 3983"use strict"; 3984function arrayMove(src, srcIndex, dst, dstIndex, len) { 3985 for (var j = 0; j < len; ++j) { 3986 dst[j + dstIndex] = src[j + srcIndex]; 3987 src[j + srcIndex] = void 0; 3988 } 3989} 3990 3991function Queue(capacity) { 3992 this._capacity = capacity; 3993 this._length = 0; 3994 this._front = 0; 3995} 3996 3997Queue.prototype._willBeOverCapacity = function (size) { 3998 return this._capacity < size; 3999}; 4000 4001Queue.prototype._pushOne = function (arg) { 4002 var length = this.length(); 4003 this._checkCapacity(length + 1); 4004 var i = (this._front + length) & (this._capacity - 1); 4005 this[i] = arg; 4006 this._length = length + 1; 4007}; 4008 4009Queue.prototype.push = function (fn, receiver, arg) { 4010 var length = this.length() + 3; 4011 if (this._willBeOverCapacity(length)) { 4012 this._pushOne(fn); 4013 this._pushOne(receiver); 4014 this._pushOne(arg); 4015 return; 4016 } 4017 var j = this._front + length - 3; 4018 this._checkCapacity(length); 4019 var wrapMask = this._capacity - 1; 4020 this[(j + 0) & wrapMask] = fn; 4021 this[(j + 1) & wrapMask] = receiver; 4022 this[(j + 2) & wrapMask] = arg; 4023 this._length = length; 4024}; 4025 4026Queue.prototype.shift = function () { 4027 var front = this._front, 4028 ret = this[front]; 4029 4030 this[front] = undefined; 4031 this._front = (front + 1) & (this._capacity - 1); 4032 this._length--; 4033 return ret; 4034}; 4035 4036Queue.prototype.length = function () { 4037 return this._length; 4038}; 4039 4040Queue.prototype._checkCapacity = function (size) { 4041 if (this._capacity < size) { 4042 this._resizeTo(this._capacity << 1); 4043 } 4044}; 4045 4046Queue.prototype._resizeTo = function (capacity) { 4047 var oldCapacity = this._capacity; 4048 this._capacity = capacity; 4049 var front = this._front; 4050 var length = this._length; 4051 var moveItemsCount = (front + length) & (oldCapacity - 1); 4052 arrayMove(this, 0, this, oldCapacity, moveItemsCount); 4053}; 4054 4055module.exports = Queue; 4056 4057},{}],27:[function(_dereq_,module,exports){ 4058"use strict"; 4059module.exports = function( 4060 Promise, INTERNAL, tryConvertToPromise, apiRejection) { 4061var util = _dereq_("./util"); 4062 4063var raceLater = function (promise) { 4064 return promise.then(function(array) { 4065 return race(array, promise); 4066 }); 4067}; 4068 4069function race(promises, parent) { 4070 var maybePromise = tryConvertToPromise(promises); 4071 4072 if (maybePromise instanceof Promise) { 4073 return raceLater(maybePromise); 4074 } else { 4075 promises = util.asArray(promises); 4076 if (promises === null) 4077 return apiRejection("expecting an array or an iterable object but got " + util.classString(promises)); 4078 } 4079 4080 var ret = new Promise(INTERNAL); 4081 if (parent !== undefined) { 4082 ret._propagateFrom(parent, 3); 4083 } 4084 var fulfill = ret._fulfill; 4085 var reject = ret._reject; 4086 for (var i = 0, len = promises.length; i < len; ++i) { 4087 var val = promises[i]; 4088 4089 if (val === undefined && !(i in promises)) { 4090 continue; 4091 } 4092 4093 Promise.cast(val)._then(fulfill, reject, undefined, ret, null); 4094 } 4095 return ret; 4096} 4097 4098Promise.race = function (promises) { 4099 return race(promises, undefined); 4100}; 4101 4102Promise.prototype.race = function () { 4103 return race(this, undefined); 4104}; 4105 4106}; 4107 4108},{"./util":36}],28:[function(_dereq_,module,exports){ 4109"use strict"; 4110module.exports = function(Promise, 4111 PromiseArray, 4112 apiRejection, 4113 tryConvertToPromise, 4114 INTERNAL, 4115 debug) { 4116var getDomain = Promise._getDomain; 4117var util = _dereq_("./util"); 4118var tryCatch = util.tryCatch; 4119 4120function ReductionPromiseArray(promises, fn, initialValue, _each) { 4121 this.constructor$(promises); 4122 var domain = getDomain(); 4123 this._fn = domain === null ? fn : util.domainBind(domain, fn); 4124 if (initialValue !== undefined) { 4125 initialValue = Promise.resolve(initialValue); 4126 initialValue._attachCancellationCallback(this); 4127 } 4128 this._initialValue = initialValue; 4129 this._currentCancellable = null; 4130 if(_each === INTERNAL) { 4131 this._eachValues = Array(this._length); 4132 } else if (_each === 0) { 4133 this._eachValues = null; 4134 } else { 4135 this._eachValues = undefined; 4136 } 4137 this._promise._captureStackTrace(); 4138 this._init$(undefined, -5); 4139} 4140util.inherits(ReductionPromiseArray, PromiseArray); 4141 4142ReductionPromiseArray.prototype._gotAccum = function(accum) { 4143 if (this._eachValues !== undefined && 4144 this._eachValues !== null && 4145 accum !== INTERNAL) { 4146 this._eachValues.push(accum); 4147 } 4148}; 4149 4150ReductionPromiseArray.prototype._eachComplete = function(value) { 4151 if (this._eachValues !== null) { 4152 this._eachValues.push(value); 4153 } 4154 return this._eachValues; 4155}; 4156 4157ReductionPromiseArray.prototype._init = function() {}; 4158 4159ReductionPromiseArray.prototype._resolveEmptyArray = function() { 4160 this._resolve(this._eachValues !== undefined ? this._eachValues 4161 : this._initialValue); 4162}; 4163 4164ReductionPromiseArray.prototype.shouldCopyValues = function () { 4165 return false; 4166}; 4167 4168ReductionPromiseArray.prototype._resolve = function(value) { 4169 this._promise._resolveCallback(value); 4170 this._values = null; 4171}; 4172 4173ReductionPromiseArray.prototype._resultCancelled = function(sender) { 4174 if (sender === this._initialValue) return this._cancel(); 4175 if (this._isResolved()) return; 4176 this._resultCancelled$(); 4177 if (this._currentCancellable instanceof Promise) { 4178 this._currentCancellable.cancel(); 4179 } 4180 if (this._initialValue instanceof Promise) { 4181 this._initialValue.cancel(); 4182 } 4183}; 4184 4185ReductionPromiseArray.prototype._iterate = function (values) { 4186 this._values = values; 4187 var value; 4188 var i; 4189 var length = values.length; 4190 if (this._initialValue !== undefined) { 4191 value = this._initialValue; 4192 i = 0; 4193 } else { 4194 value = Promise.resolve(values[0]); 4195 i = 1; 4196 } 4197 4198 this._currentCancellable = value; 4199 4200 if (!value.isRejected()) { 4201 for (; i < length; ++i) { 4202 var ctx = { 4203 accum: null, 4204 value: values[i], 4205 index: i, 4206 length: length, 4207 array: this 4208 }; 4209 value = value._then(gotAccum, undefined, undefined, ctx, undefined); 4210 } 4211 } 4212 4213 if (this._eachValues !== undefined) { 4214 value = value 4215 ._then(this._eachComplete, undefined, undefined, this, undefined); 4216 } 4217 value._then(completed, completed, undefined, value, this); 4218}; 4219 4220Promise.prototype.reduce = function (fn, initialValue) { 4221 return reduce(this, fn, initialValue, null); 4222}; 4223 4224Promise.reduce = function (promises, fn, initialValue, _each) { 4225 return reduce(promises, fn, initialValue, _each); 4226}; 4227 4228function completed(valueOrReason, array) { 4229 if (this.isFulfilled()) { 4230 array._resolve(valueOrReason); 4231 } else { 4232 array._reject(valueOrReason); 4233 } 4234} 4235 4236function reduce(promises, fn, initialValue, _each) { 4237 if (typeof fn !== "function") { 4238 return apiRejection("expecting a function but got " + util.classString(fn)); 4239 } 4240 var array = new ReductionPromiseArray(promises, fn, initialValue, _each); 4241 return array.promise(); 4242} 4243 4244function gotAccum(accum) { 4245 this.accum = accum; 4246 this.array._gotAccum(accum); 4247 var value = tryConvertToPromise(this.value, this.array._promise); 4248 if (value instanceof Promise) { 4249 this.array._currentCancellable = value; 4250 return value._then(gotValue, undefined, undefined, this, undefined); 4251 } else { 4252 return gotValue.call(this, value); 4253 } 4254} 4255 4256function gotValue(value) { 4257 var array = this.array; 4258 var promise = array._promise; 4259 var fn = tryCatch(array._fn); 4260 promise._pushContext(); 4261 var ret; 4262 if (array._eachValues !== undefined) { 4263 ret = fn.call(promise._boundValue(), value, this.index, this.length); 4264 } else { 4265 ret = fn.call(promise._boundValue(), 4266 this.accum, value, this.index, this.length); 4267 } 4268 if (ret instanceof Promise) { 4269 array._currentCancellable = ret; 4270 } 4271 var promiseCreated = promise._popContext(); 4272 debug.checkForgottenReturns( 4273 ret, 4274 promiseCreated, 4275 array._eachValues !== undefined ? "Promise.each" : "Promise.reduce", 4276 promise 4277 ); 4278 return ret; 4279} 4280}; 4281 4282},{"./util":36}],29:[function(_dereq_,module,exports){ 4283"use strict"; 4284var util = _dereq_("./util"); 4285var schedule; 4286var noAsyncScheduler = function() { 4287 throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 4288}; 4289var NativePromise = util.getNativePromise(); 4290if (util.isNode && typeof MutationObserver === "undefined") { 4291 var GlobalSetImmediate = global.setImmediate; 4292 var ProcessNextTick = process.nextTick; 4293 schedule = util.isRecentNode 4294 ? function(fn) { GlobalSetImmediate.call(global, fn); } 4295 : function(fn) { ProcessNextTick.call(process, fn); }; 4296} else if (typeof NativePromise === "function" && 4297 typeof NativePromise.resolve === "function") { 4298 var nativePromise = NativePromise.resolve(); 4299 schedule = function(fn) { 4300 nativePromise.then(fn); 4301 }; 4302} else if ((typeof MutationObserver !== "undefined") && 4303 !(typeof window !== "undefined" && 4304 window.navigator && 4305 (window.navigator.standalone || window.cordova))) { 4306 schedule = (function() { 4307 var div = document.createElement("div"); 4308 var opts = {attributes: true}; 4309 var toggleScheduled = false; 4310 var div2 = document.createElement("div"); 4311 var o2 = new MutationObserver(function() { 4312 div.classList.toggle("foo"); 4313 toggleScheduled = false; 4314 }); 4315 o2.observe(div2, opts); 4316 4317 var scheduleToggle = function() { 4318 if (toggleScheduled) return; 4319 toggleScheduled = true; 4320 div2.classList.toggle("foo"); 4321 }; 4322 4323 return function schedule(fn) { 4324 var o = new MutationObserver(function() { 4325 o.disconnect(); 4326 fn(); 4327 }); 4328 o.observe(div, opts); 4329 scheduleToggle(); 4330 }; 4331 })(); 4332} else if (typeof setImmediate !== "undefined") { 4333 schedule = function (fn) { 4334 setImmediate(fn); 4335 }; 4336} else if (typeof setTimeout !== "undefined") { 4337 schedule = function (fn) { 4338 setTimeout(fn, 0); 4339 }; 4340} else { 4341 schedule = noAsyncScheduler; 4342} 4343module.exports = schedule; 4344 4345},{"./util":36}],30:[function(_dereq_,module,exports){ 4346"use strict"; 4347module.exports = 4348 function(Promise, PromiseArray, debug) { 4349var PromiseInspection = Promise.PromiseInspection; 4350var util = _dereq_("./util"); 4351 4352function SettledPromiseArray(values) { 4353 this.constructor$(values); 4354} 4355util.inherits(SettledPromiseArray, PromiseArray); 4356 4357SettledPromiseArray.prototype._promiseResolved = function (index, inspection) { 4358 this._values[index] = inspection; 4359 var totalResolved = ++this._totalResolved; 4360 if (totalResolved >= this._length) { 4361 this._resolve(this._values); 4362 return true; 4363 } 4364 return false; 4365}; 4366 4367SettledPromiseArray.prototype._promiseFulfilled = function (value, index) { 4368 var ret = new PromiseInspection(); 4369 ret._bitField = 33554432; 4370 ret._settledValueField = value; 4371 return this._promiseResolved(index, ret); 4372}; 4373SettledPromiseArray.prototype._promiseRejected = function (reason, index) { 4374 var ret = new PromiseInspection(); 4375 ret._bitField = 16777216; 4376 ret._settledValueField = reason; 4377 return this._promiseResolved(index, ret); 4378}; 4379 4380Promise.settle = function (promises) { 4381 debug.deprecated(".settle()", ".reflect()"); 4382 return new SettledPromiseArray(promises).promise(); 4383}; 4384 4385Promise.prototype.settle = function () { 4386 return Promise.settle(this); 4387}; 4388}; 4389 4390},{"./util":36}],31:[function(_dereq_,module,exports){ 4391"use strict"; 4392module.exports = 4393function(Promise, PromiseArray, apiRejection) { 4394var util = _dereq_("./util"); 4395var RangeError = _dereq_("./errors").RangeError; 4396var AggregateError = _dereq_("./errors").AggregateError; 4397var isArray = util.isArray; 4398var CANCELLATION = {}; 4399 4400 4401function SomePromiseArray(values) { 4402 this.constructor$(values); 4403 this._howMany = 0; 4404 this._unwrap = false; 4405 this._initialized = false; 4406} 4407util.inherits(SomePromiseArray, PromiseArray); 4408 4409SomePromiseArray.prototype._init = function () { 4410 if (!this._initialized) { 4411 return; 4412 } 4413 if (this._howMany === 0) { 4414 this._resolve([]); 4415 return; 4416 } 4417 this._init$(undefined, -5); 4418 var isArrayResolved = isArray(this._values); 4419 if (!this._isResolved() && 4420 isArrayResolved && 4421 this._howMany > this._canPossiblyFulfill()) { 4422 this._reject(this._getRangeError(this.length())); 4423 } 4424}; 4425 4426SomePromiseArray.prototype.init = function () { 4427 this._initialized = true; 4428 this._init(); 4429}; 4430 4431SomePromiseArray.prototype.setUnwrap = function () { 4432 this._unwrap = true; 4433}; 4434 4435SomePromiseArray.prototype.howMany = function () { 4436 return this._howMany; 4437}; 4438 4439SomePromiseArray.prototype.setHowMany = function (count) { 4440 this._howMany = count; 4441}; 4442 4443SomePromiseArray.prototype._promiseFulfilled = function (value) { 4444 this._addFulfilled(value); 4445 if (this._fulfilled() === this.howMany()) { 4446 this._values.length = this.howMany(); 4447 if (this.howMany() === 1 && this._unwrap) { 4448 this._resolve(this._values[0]); 4449 } else { 4450 this._resolve(this._values); 4451 } 4452 return true; 4453 } 4454 return false; 4455 4456}; 4457SomePromiseArray.prototype._promiseRejected = function (reason) { 4458 this._addRejected(reason); 4459 return this._checkOutcome(); 4460}; 4461 4462SomePromiseArray.prototype._promiseCancelled = function () { 4463 if (this._values instanceof Promise || this._values == null) { 4464 return this._cancel(); 4465 } 4466 this._addRejected(CANCELLATION); 4467 return this._checkOutcome(); 4468}; 4469 4470SomePromiseArray.prototype._checkOutcome = function() { 4471 if (this.howMany() > this._canPossiblyFulfill()) { 4472 var e = new AggregateError(); 4473 for (var i = this.length(); i < this._values.length; ++i) { 4474 if (this._values[i] !== CANCELLATION) { 4475 e.push(this._values[i]); 4476 } 4477 } 4478 if (e.length > 0) { 4479 this._reject(e); 4480 } else { 4481 this._cancel(); 4482 } 4483 return true; 4484 } 4485 return false; 4486}; 4487 4488SomePromiseArray.prototype._fulfilled = function () { 4489 return this._totalResolved; 4490}; 4491 4492SomePromiseArray.prototype._rejected = function () { 4493 return this._values.length - this.length(); 4494}; 4495 4496SomePromiseArray.prototype._addRejected = function (reason) { 4497 this._values.push(reason); 4498}; 4499 4500SomePromiseArray.prototype._addFulfilled = function (value) { 4501 this._values[this._totalResolved++] = value; 4502}; 4503 4504SomePromiseArray.prototype._canPossiblyFulfill = function () { 4505 return this.length() - this._rejected(); 4506}; 4507 4508SomePromiseArray.prototype._getRangeError = function (count) { 4509 var message = "Input array must contain at least " + 4510 this._howMany + " items but contains only " + count + " items"; 4511 return new RangeError(message); 4512}; 4513 4514SomePromiseArray.prototype._resolveEmptyArray = function () { 4515 this._reject(this._getRangeError(0)); 4516}; 4517 4518function some(promises, howMany) { 4519 if ((howMany | 0) !== howMany || howMany < 0) { 4520 return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 4521 } 4522 var ret = new SomePromiseArray(promises); 4523 var promise = ret.promise(); 4524 ret.setHowMany(howMany); 4525 ret.init(); 4526 return promise; 4527} 4528 4529Promise.some = function (promises, howMany) { 4530 return some(promises, howMany); 4531}; 4532 4533Promise.prototype.some = function (howMany) { 4534 return some(this, howMany); 4535}; 4536 4537Promise._SomePromiseArray = SomePromiseArray; 4538}; 4539 4540},{"./errors":12,"./util":36}],32:[function(_dereq_,module,exports){ 4541"use strict"; 4542module.exports = function(Promise) { 4543function PromiseInspection(promise) { 4544 if (promise !== undefined) { 4545 promise = promise._target(); 4546 this._bitField = promise._bitField; 4547 this._settledValueField = promise._isFateSealed() 4548 ? promise._settledValue() : undefined; 4549 } 4550 else { 4551 this._bitField = 0; 4552 this._settledValueField = undefined; 4553 } 4554} 4555 4556PromiseInspection.prototype._settledValue = function() { 4557 return this._settledValueField; 4558}; 4559 4560var value = PromiseInspection.prototype.value = function () { 4561 if (!this.isFulfilled()) { 4562 throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 4563 } 4564 return this._settledValue(); 4565}; 4566 4567var reason = PromiseInspection.prototype.error = 4568PromiseInspection.prototype.reason = function () { 4569 if (!this.isRejected()) { 4570 throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a"); 4571 } 4572 return this._settledValue(); 4573}; 4574 4575var isFulfilled = PromiseInspection.prototype.isFulfilled = function() { 4576 return (this._bitField & 33554432) !== 0; 4577}; 4578 4579var isRejected = PromiseInspection.prototype.isRejected = function () { 4580 return (this._bitField & 16777216) !== 0; 4581}; 4582 4583var isPending = PromiseInspection.prototype.isPending = function () { 4584 return (this._bitField & 50397184) === 0; 4585}; 4586 4587var isResolved = PromiseInspection.prototype.isResolved = function () { 4588 return (this._bitField & 50331648) !== 0; 4589}; 4590 4591PromiseInspection.prototype.isCancelled = function() { 4592 return (this._bitField & 8454144) !== 0; 4593}; 4594 4595Promise.prototype.__isCancelled = function() { 4596 return (this._bitField & 65536) === 65536; 4597}; 4598 4599Promise.prototype._isCancelled = function() { 4600 return this._target().__isCancelled(); 4601}; 4602 4603Promise.prototype.isCancelled = function() { 4604 return (this._target()._bitField & 8454144) !== 0; 4605}; 4606 4607Promise.prototype.isPending = function() { 4608 return isPending.call(this._target()); 4609}; 4610 4611Promise.prototype.isRejected = function() { 4612 return isRejected.call(this._target()); 4613}; 4614 4615Promise.prototype.isFulfilled = function() { 4616 return isFulfilled.call(this._target()); 4617}; 4618 4619Promise.prototype.isResolved = function() { 4620 return isResolved.call(this._target()); 4621}; 4622 4623Promise.prototype.value = function() { 4624 return value.call(this._target()); 4625}; 4626 4627Promise.prototype.reason = function() { 4628 var target = this._target(); 4629 target._unsetRejectionIsUnhandled(); 4630 return reason.call(target); 4631}; 4632 4633Promise.prototype._value = function() { 4634 return this._settledValue(); 4635}; 4636 4637Promise.prototype._reason = function() { 4638 this._unsetRejectionIsUnhandled(); 4639 return this._settledValue(); 4640}; 4641 4642Promise.PromiseInspection = PromiseInspection; 4643}; 4644 4645},{}],33:[function(_dereq_,module,exports){ 4646"use strict"; 4647module.exports = function(Promise, INTERNAL) { 4648var util = _dereq_("./util"); 4649var errorObj = util.errorObj; 4650var isObject = util.isObject; 4651 4652function tryConvertToPromise(obj, context) { 4653 if (isObject(obj)) { 4654 if (obj instanceof Promise) return obj; 4655 var then = getThen(obj); 4656 if (then === errorObj) { 4657 if (context) context._pushContext(); 4658 var ret = Promise.reject(then.e); 4659 if (context) context._popContext(); 4660 return ret; 4661 } else if (typeof then === "function") { 4662 if (isAnyBluebirdPromise(obj)) { 4663 var ret = new Promise(INTERNAL); 4664 obj._then( 4665 ret._fulfill, 4666 ret._reject, 4667 undefined, 4668 ret, 4669 null 4670 ); 4671 return ret; 4672 } 4673 return doThenable(obj, then, context); 4674 } 4675 } 4676 return obj; 4677} 4678 4679function doGetThen(obj) { 4680 return obj.then; 4681} 4682 4683function getThen(obj) { 4684 try { 4685 return doGetThen(obj); 4686 } catch (e) { 4687 errorObj.e = e; 4688 return errorObj; 4689 } 4690} 4691 4692var hasProp = {}.hasOwnProperty; 4693function isAnyBluebirdPromise(obj) { 4694 try { 4695 return hasProp.call(obj, "_promise0"); 4696 } catch (e) { 4697 return false; 4698 } 4699} 4700 4701function doThenable(x, then, context) { 4702 var promise = new Promise(INTERNAL); 4703 var ret = promise; 4704 if (context) context._pushContext(); 4705 promise._captureStackTrace(); 4706 if (context) context._popContext(); 4707 var synchronous = true; 4708 var result = util.tryCatch(then).call(x, resolve, reject); 4709 synchronous = false; 4710 4711 if (promise && result === errorObj) { 4712 promise._rejectCallback(result.e, true, true); 4713 promise = null; 4714 } 4715 4716 function resolve(value) { 4717 if (!promise) return; 4718 promise._resolveCallback(value); 4719 promise = null; 4720 } 4721 4722 function reject(reason) { 4723 if (!promise) return; 4724 promise._rejectCallback(reason, synchronous, true); 4725 promise = null; 4726 } 4727 return ret; 4728} 4729 4730return tryConvertToPromise; 4731}; 4732 4733},{"./util":36}],34:[function(_dereq_,module,exports){ 4734"use strict"; 4735module.exports = function(Promise, INTERNAL, debug) { 4736var util = _dereq_("./util"); 4737var TimeoutError = Promise.TimeoutError; 4738 4739function HandleWrapper(handle) { 4740 this.handle = handle; 4741} 4742 4743HandleWrapper.prototype._resultCancelled = function() { 4744 clearTimeout(this.handle); 4745}; 4746 4747var afterValue = function(value) { return delay(+this).thenReturn(value); }; 4748var delay = Promise.delay = function (ms, value) { 4749 var ret; 4750 var handle; 4751 if (value !== undefined) { 4752 ret = Promise.resolve(value) 4753 ._then(afterValue, null, null, ms, undefined); 4754 if (debug.cancellation() && value instanceof Promise) { 4755 ret._setOnCancel(value); 4756 } 4757 } else { 4758 ret = new Promise(INTERNAL); 4759 handle = setTimeout(function() { ret._fulfill(); }, +ms); 4760 if (debug.cancellation()) { 4761 ret._setOnCancel(new HandleWrapper(handle)); 4762 } 4763 ret._captureStackTrace(); 4764 } 4765 ret._setAsyncGuaranteed(); 4766 return ret; 4767}; 4768 4769Promise.prototype.delay = function (ms) { 4770 return delay(ms, this); 4771}; 4772 4773var afterTimeout = function (promise, message, parent) { 4774 var err; 4775 if (typeof message !== "string") { 4776 if (message instanceof Error) { 4777 err = message; 4778 } else { 4779 err = new TimeoutError("operation timed out"); 4780 } 4781 } else { 4782 err = new TimeoutError(message); 4783 } 4784 util.markAsOriginatingFromRejection(err); 4785 promise._attachExtraTrace(err); 4786 promise._reject(err); 4787 4788 if (parent != null) { 4789 parent.cancel(); 4790 } 4791}; 4792 4793function successClear(value) { 4794 clearTimeout(this.handle); 4795 return value; 4796} 4797 4798function failureClear(reason) { 4799 clearTimeout(this.handle); 4800 throw reason; 4801} 4802 4803Promise.prototype.timeout = function (ms, message) { 4804 ms = +ms; 4805 var ret, parent; 4806 4807 var handleWrapper = new HandleWrapper(setTimeout(function timeoutTimeout() { 4808 if (ret.isPending()) { 4809 afterTimeout(ret, message, parent); 4810 } 4811 }, ms)); 4812 4813 if (debug.cancellation()) { 4814 parent = this.then(); 4815 ret = parent._then(successClear, failureClear, 4816 undefined, handleWrapper, undefined); 4817 ret._setOnCancel(handleWrapper); 4818 } else { 4819 ret = this._then(successClear, failureClear, 4820 undefined, handleWrapper, undefined); 4821 } 4822 4823 return ret; 4824}; 4825 4826}; 4827 4828},{"./util":36}],35:[function(_dereq_,module,exports){ 4829"use strict"; 4830module.exports = function (Promise, apiRejection, tryConvertToPromise, 4831 createContext, INTERNAL, debug) { 4832 var util = _dereq_("./util"); 4833 var TypeError = _dereq_("./errors").TypeError; 4834 var inherits = _dereq_("./util").inherits; 4835 var errorObj = util.errorObj; 4836 var tryCatch = util.tryCatch; 4837 var NULL = {}; 4838 4839 function thrower(e) { 4840 setTimeout(function(){throw e;}, 0); 4841 } 4842 4843 function castPreservingDisposable(thenable) { 4844 var maybePromise = tryConvertToPromise(thenable); 4845 if (maybePromise !== thenable && 4846 typeof thenable._isDisposable === "function" && 4847 typeof thenable._getDisposer === "function" && 4848 thenable._isDisposable()) { 4849 maybePromise._setDisposable(thenable._getDisposer()); 4850 } 4851 return maybePromise; 4852 } 4853 function dispose(resources, inspection) { 4854 var i = 0; 4855 var len = resources.length; 4856 var ret = new Promise(INTERNAL); 4857 function iterator() { 4858 if (i >= len) return ret._fulfill(); 4859 var maybePromise = castPreservingDisposable(resources[i++]); 4860 if (maybePromise instanceof Promise && 4861 maybePromise._isDisposable()) { 4862 try { 4863 maybePromise = tryConvertToPromise( 4864 maybePromise._getDisposer().tryDispose(inspection), 4865 resources.promise); 4866 } catch (e) { 4867 return thrower(e); 4868 } 4869 if (maybePromise instanceof Promise) { 4870 return maybePromise._then(iterator, thrower, 4871 null, null, null); 4872 } 4873 } 4874 iterator(); 4875 } 4876 iterator(); 4877 return ret; 4878 } 4879 4880 function Disposer(data, promise, context) { 4881 this._data = data; 4882 this._promise = promise; 4883 this._context = context; 4884 } 4885 4886 Disposer.prototype.data = function () { 4887 return this._data; 4888 }; 4889 4890 Disposer.prototype.promise = function () { 4891 return this._promise; 4892 }; 4893 4894 Disposer.prototype.resource = function () { 4895 if (this.promise().isFulfilled()) { 4896 return this.promise().value(); 4897 } 4898 return NULL; 4899 }; 4900 4901 Disposer.prototype.tryDispose = function(inspection) { 4902 var resource = this.resource(); 4903 var context = this._context; 4904 if (context !== undefined) context._pushContext(); 4905 var ret = resource !== NULL 4906 ? this.doDispose(resource, inspection) : null; 4907 if (context !== undefined) context._popContext(); 4908 this._promise._unsetDisposable(); 4909 this._data = null; 4910 return ret; 4911 }; 4912 4913 Disposer.isDisposer = function (d) { 4914 return (d != null && 4915 typeof d.resource === "function" && 4916 typeof d.tryDispose === "function"); 4917 }; 4918 4919 function FunctionDisposer(fn, promise, context) { 4920 this.constructor$(fn, promise, context); 4921 } 4922 inherits(FunctionDisposer, Disposer); 4923 4924 FunctionDisposer.prototype.doDispose = function (resource, inspection) { 4925 var fn = this.data(); 4926 return fn.call(resource, resource, inspection); 4927 }; 4928 4929 function maybeUnwrapDisposer(value) { 4930 if (Disposer.isDisposer(value)) { 4931 this.resources[this.index]._setDisposable(value); 4932 return value.promise(); 4933 } 4934 return value; 4935 } 4936 4937 function ResourceList(length) { 4938 this.length = length; 4939 this.promise = null; 4940 this[length-1] = null; 4941 } 4942 4943 ResourceList.prototype._resultCancelled = function() { 4944 var len = this.length; 4945 for (var i = 0; i < len; ++i) { 4946 var item = this[i]; 4947 if (item instanceof Promise) { 4948 item.cancel(); 4949 } 4950 } 4951 }; 4952 4953 Promise.using = function () { 4954 var len = arguments.length; 4955 if (len < 2) return apiRejection( 4956 "you must pass at least 2 arguments to Promise.using"); 4957 var fn = arguments[len - 1]; 4958 if (typeof fn !== "function") { 4959 return apiRejection("expecting a function but got " + util.classString(fn)); 4960 } 4961 var input; 4962 var spreadArgs = true; 4963 if (len === 2 && Array.isArray(arguments[0])) { 4964 input = arguments[0]; 4965 len = input.length; 4966 spreadArgs = false; 4967 } else { 4968 input = arguments; 4969 len--; 4970 } 4971 var resources = new ResourceList(len); 4972 for (var i = 0; i < len; ++i) { 4973 var resource = input[i]; 4974 if (Disposer.isDisposer(resource)) { 4975 var disposer = resource; 4976 resource = resource.promise(); 4977 resource._setDisposable(disposer); 4978 } else { 4979 var maybePromise = tryConvertToPromise(resource); 4980 if (maybePromise instanceof Promise) { 4981 resource = 4982 maybePromise._then(maybeUnwrapDisposer, null, null, { 4983 resources: resources, 4984 index: i 4985 }, undefined); 4986 } 4987 } 4988 resources[i] = resource; 4989 } 4990 4991 var reflectedResources = new Array(resources.length); 4992 for (var i = 0; i < reflectedResources.length; ++i) { 4993 reflectedResources[i] = Promise.resolve(resources[i]).reflect(); 4994 } 4995 4996 var resultPromise = Promise.all(reflectedResources) 4997 .then(function(inspections) { 4998 for (var i = 0; i < inspections.length; ++i) { 4999 var inspection = inspections[i]; 5000 if (inspection.isRejected()) { 5001 errorObj.e = inspection.error(); 5002 return errorObj; 5003 } else if (!inspection.isFulfilled()) { 5004 resultPromise.cancel(); 5005 return; 5006 } 5007 inspections[i] = inspection.value(); 5008 } 5009 promise._pushContext(); 5010 5011 fn = tryCatch(fn); 5012 var ret = spreadArgs 5013 ? fn.apply(undefined, inspections) : fn(inspections); 5014 var promiseCreated = promise._popContext(); 5015 debug.checkForgottenReturns( 5016 ret, promiseCreated, "Promise.using", promise); 5017 return ret; 5018 }); 5019 5020 var promise = resultPromise.lastly(function() { 5021 var inspection = new Promise.PromiseInspection(resultPromise); 5022 return dispose(resources, inspection); 5023 }); 5024 resources.promise = promise; 5025 promise._setOnCancel(resources); 5026 return promise; 5027 }; 5028 5029 Promise.prototype._setDisposable = function (disposer) { 5030 this._bitField = this._bitField | 131072; 5031 this._disposer = disposer; 5032 }; 5033 5034 Promise.prototype._isDisposable = function () { 5035 return (this._bitField & 131072) > 0; 5036 }; 5037 5038 Promise.prototype._getDisposer = function () { 5039 return this._disposer; 5040 }; 5041 5042 Promise.prototype._unsetDisposable = function () { 5043 this._bitField = this._bitField & (~131072); 5044 this._disposer = undefined; 5045 }; 5046 5047 Promise.prototype.disposer = function (fn) { 5048 if (typeof fn === "function") { 5049 return new FunctionDisposer(fn, this, createContext()); 5050 } 5051 throw new TypeError(); 5052 }; 5053 5054}; 5055 5056},{"./errors":12,"./util":36}],36:[function(_dereq_,module,exports){ 5057"use strict"; 5058var es5 = _dereq_("./es5"); 5059var canEvaluate = typeof navigator == "undefined"; 5060 5061var errorObj = {e: {}}; 5062var tryCatchTarget; 5063var globalObject = typeof self !== "undefined" ? self : 5064 typeof window !== "undefined" ? window : 5065 typeof global !== "undefined" ? global : 5066 this !== undefined ? this : null; 5067 5068function tryCatcher() { 5069 try { 5070 var target = tryCatchTarget; 5071 tryCatchTarget = null; 5072 return target.apply(this, arguments); 5073 } catch (e) { 5074 errorObj.e = e; 5075 return errorObj; 5076 } 5077} 5078function tryCatch(fn) { 5079 tryCatchTarget = fn; 5080 return tryCatcher; 5081} 5082 5083var inherits = function(Child, Parent) { 5084 var hasProp = {}.hasOwnProperty; 5085 5086 function T() { 5087 this.constructor = Child; 5088 this.constructor$ = Parent; 5089 for (var propertyName in Parent.prototype) { 5090 if (hasProp.call(Parent.prototype, propertyName) && 5091 propertyName.charAt(propertyName.length-1) !== "$" 5092 ) { 5093 this[propertyName + "$"] = Parent.prototype[propertyName]; 5094 } 5095 } 5096 } 5097 T.prototype = Parent.prototype; 5098 Child.prototype = new T(); 5099 return Child.prototype; 5100}; 5101 5102 5103function isPrimitive(val) { 5104 return val == null || val === true || val === false || 5105 typeof val === "string" || typeof val === "number"; 5106 5107} 5108 5109function isObject(value) { 5110 return typeof value === "function" || 5111 typeof value === "object" && value !== null; 5112} 5113 5114function maybeWrapAsError(maybeError) { 5115 if (!isPrimitive(maybeError)) return maybeError; 5116 5117 return new Error(safeToString(maybeError)); 5118} 5119 5120function withAppended(target, appendee) { 5121 var len = target.length; 5122 var ret = new Array(len + 1); 5123 var i; 5124 for (i = 0; i < len; ++i) { 5125 ret[i] = target[i]; 5126 } 5127 ret[i] = appendee; 5128 return ret; 5129} 5130 5131function getDataPropertyOrDefault(obj, key, defaultValue) { 5132 if (es5.isES5) { 5133 var desc = Object.getOwnPropertyDescriptor(obj, key); 5134 5135 if (desc != null) { 5136 return desc.get == null && desc.set == null 5137 ? desc.value 5138 : defaultValue; 5139 } 5140 } else { 5141 return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined; 5142 } 5143} 5144 5145function notEnumerableProp(obj, name, value) { 5146 if (isPrimitive(obj)) return obj; 5147 var descriptor = { 5148 value: value, 5149 configurable: true, 5150 enumerable: false, 5151 writable: true 5152 }; 5153 es5.defineProperty(obj, name, descriptor); 5154 return obj; 5155} 5156 5157function thrower(r) { 5158 throw r; 5159} 5160 5161var inheritedDataKeys = (function() { 5162 var excludedPrototypes = [ 5163 Array.prototype, 5164 Object.prototype, 5165 Function.prototype 5166 ]; 5167 5168 var isExcludedProto = function(val) { 5169 for (var i = 0; i < excludedPrototypes.length; ++i) { 5170 if (excludedPrototypes[i] === val) { 5171 return true; 5172 } 5173 } 5174 return false; 5175 }; 5176 5177 if (es5.isES5) { 5178 var getKeys = Object.getOwnPropertyNames; 5179 return function(obj) { 5180 var ret = []; 5181 var visitedKeys = Object.create(null); 5182 while (obj != null && !isExcludedProto(obj)) { 5183 var keys; 5184 try { 5185 keys = getKeys(obj); 5186 } catch (e) { 5187 return ret; 5188 } 5189 for (var i = 0; i < keys.length; ++i) { 5190 var key = keys[i]; 5191 if (visitedKeys[key]) continue; 5192 visitedKeys[key] = true; 5193 var desc = Object.getOwnPropertyDescriptor(obj, key); 5194 if (desc != null && desc.get == null && desc.set == null) { 5195 ret.push(key); 5196 } 5197 } 5198 obj = es5.getPrototypeOf(obj); 5199 } 5200 return ret; 5201 }; 5202 } else { 5203 var hasProp = {}.hasOwnProperty; 5204 return function(obj) { 5205 if (isExcludedProto(obj)) return []; 5206 var ret = []; 5207 5208 /*jshint forin:false */ 5209 enumeration: for (var key in obj) { 5210 if (hasProp.call(obj, key)) { 5211 ret.push(key); 5212 } else { 5213 for (var i = 0; i < excludedPrototypes.length; ++i) { 5214 if (hasProp.call(excludedPrototypes[i], key)) { 5215 continue enumeration; 5216 } 5217 } 5218 ret.push(key); 5219 } 5220 } 5221 return ret; 5222 }; 5223 } 5224 5225})(); 5226 5227var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/; 5228function isClass(fn) { 5229 try { 5230 if (typeof fn === "function") { 5231 var keys = es5.names(fn.prototype); 5232 5233 var hasMethods = es5.isES5 && keys.length > 1; 5234 var hasMethodsOtherThanConstructor = keys.length > 0 && 5235 !(keys.length === 1 && keys[0] === "constructor"); 5236 var hasThisAssignmentAndStaticMethods = 5237 thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0; 5238 5239 if (hasMethods || hasMethodsOtherThanConstructor || 5240 hasThisAssignmentAndStaticMethods) { 5241 return true; 5242 } 5243 } 5244 return false; 5245 } catch (e) { 5246 return false; 5247 } 5248} 5249 5250function toFastProperties(obj) { 5251 /*jshint -W027,-W055,-W031*/ 5252 function FakeConstructor() {} 5253 FakeConstructor.prototype = obj; 5254 var receiver = new FakeConstructor(); 5255 function ic() { 5256 return typeof receiver.foo; 5257 } 5258 ic(); 5259 ic(); 5260 return obj; 5261 eval(obj); 5262} 5263 5264var rident = /^[a-z$_][a-z$_0-9]*$/i; 5265function isIdentifier(str) { 5266 return rident.test(str); 5267} 5268 5269function filledRange(count, prefix, suffix) { 5270 var ret = new Array(count); 5271 for(var i = 0; i < count; ++i) { 5272 ret[i] = prefix + i + suffix; 5273 } 5274 return ret; 5275} 5276 5277function safeToString(obj) { 5278 try { 5279 return obj + ""; 5280 } catch (e) { 5281 return "[no string representation]"; 5282 } 5283} 5284 5285function isError(obj) { 5286 return obj instanceof Error || 5287 (obj !== null && 5288 typeof obj === "object" && 5289 typeof obj.message === "string" && 5290 typeof obj.name === "string"); 5291} 5292 5293function markAsOriginatingFromRejection(e) { 5294 try { 5295 notEnumerableProp(e, "isOperational", true); 5296 } 5297 catch(ignore) {} 5298} 5299 5300function originatesFromRejection(e) { 5301 if (e == null) return false; 5302 return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) || 5303 e["isOperational"] === true); 5304} 5305 5306function canAttachTrace(obj) { 5307 return isError(obj) && es5.propertyIsWritable(obj, "stack"); 5308} 5309 5310var ensureErrorObject = (function() { 5311 if (!("stack" in new Error())) { 5312 return function(value) { 5313 if (canAttachTrace(value)) return value; 5314 try {throw new Error(safeToString(value));} 5315 catch(err) {return err;} 5316 }; 5317 } else { 5318 return function(value) { 5319 if (canAttachTrace(value)) return value; 5320 return new Error(safeToString(value)); 5321 }; 5322 } 5323})(); 5324 5325function classString(obj) { 5326 return {}.toString.call(obj); 5327} 5328 5329function copyDescriptors(from, to, filter) { 5330 var keys = es5.names(from); 5331 for (var i = 0; i < keys.length; ++i) { 5332 var key = keys[i]; 5333 if (filter(key)) { 5334 try { 5335 es5.defineProperty(to, key, es5.getDescriptor(from, key)); 5336 } catch (ignore) {} 5337 } 5338 } 5339} 5340 5341var asArray = function(v) { 5342 if (es5.isArray(v)) { 5343 return v; 5344 } 5345 return null; 5346}; 5347 5348if (typeof Symbol !== "undefined" && Symbol.iterator) { 5349 var ArrayFrom = typeof Array.from === "function" ? function(v) { 5350 return Array.from(v); 5351 } : function(v) { 5352 var ret = []; 5353 var it = v[Symbol.iterator](); 5354 var itResult; 5355 while (!((itResult = it.next()).done)) { 5356 ret.push(itResult.value); 5357 } 5358 return ret; 5359 }; 5360 5361 asArray = function(v) { 5362 if (es5.isArray(v)) { 5363 return v; 5364 } else if (v != null && typeof v[Symbol.iterator] === "function") { 5365 return ArrayFrom(v); 5366 } 5367 return null; 5368 }; 5369} 5370 5371var isNode = typeof process !== "undefined" && 5372 classString(process).toLowerCase() === "[object process]"; 5373 5374var hasEnvVariables = typeof process !== "undefined" && 5375 typeof process.env !== "undefined"; 5376 5377function env(key) { 5378 return hasEnvVariables ? process.env[key] : undefined; 5379} 5380 5381function getNativePromise() { 5382 if (typeof Promise === "function") { 5383 try { 5384 var promise = new Promise(function(){}); 5385 if ({}.toString.call(promise) === "[object Promise]") { 5386 return Promise; 5387 } 5388 } catch (e) {} 5389 } 5390} 5391 5392function domainBind(self, cb) { 5393 return self.bind(cb); 5394} 5395 5396var ret = { 5397 isClass: isClass, 5398 isIdentifier: isIdentifier, 5399 inheritedDataKeys: inheritedDataKeys, 5400 getDataPropertyOrDefault: getDataPropertyOrDefault, 5401 thrower: thrower, 5402 isArray: es5.isArray, 5403 asArray: asArray, 5404 notEnumerableProp: notEnumerableProp, 5405 isPrimitive: isPrimitive, 5406 isObject: isObject, 5407 isError: isError, 5408 canEvaluate: canEvaluate, 5409 errorObj: errorObj, 5410 tryCatch: tryCatch, 5411 inherits: inherits, 5412 withAppended: withAppended, 5413 maybeWrapAsError: maybeWrapAsError, 5414 toFastProperties: toFastProperties, 5415 filledRange: filledRange, 5416 toString: safeToString, 5417 canAttachTrace: canAttachTrace, 5418 ensureErrorObject: ensureErrorObject, 5419 originatesFromRejection: originatesFromRejection, 5420 markAsOriginatingFromRejection: markAsOriginatingFromRejection, 5421 classString: classString, 5422 copyDescriptors: copyDescriptors, 5423 hasDevTools: typeof chrome !== "undefined" && chrome && 5424 typeof chrome.loadTimes === "function", 5425 isNode: isNode, 5426 hasEnvVariables: hasEnvVariables, 5427 env: env, 5428 global: globalObject, 5429 getNativePromise: getNativePromise, 5430 domainBind: domainBind 5431}; 5432ret.isRecentNode = ret.isNode && (function() { 5433 var version; 5434 if (process.versions && process.versions.node) { 5435 version = process.versions.node.split(".").map(Number); 5436 } else if (process.version) { 5437 version = process.version.split(".").map(Number); 5438 } 5439 return (version[0] === 0 && version[1] > 10) || (version[0] > 0); 5440})(); 5441 5442if (ret.isNode) ret.toFastProperties(process); 5443 5444try {throw new Error(); } catch (e) {ret.lastLineError = e;} 5445module.exports = ret; 5446 5447},{"./es5":13}]},{},[4])(4) 5448}); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; } 5449/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../process/browser.js */ "./node_modules/process/browser.js"), __webpack_require__(/*! ./../../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"), __webpack_require__(/*! ./../../../timers-browserify/main.js */ "./node_modules/timers-browserify/main.js").setImmediate)) 5450 5451/***/ }), 5452 5453/***/ "./node_modules/process/browser.js": 5454/*!*****************************************!*\ 5455 !*** ./node_modules/process/browser.js ***! 5456 \*****************************************/ 5457/*! no static exports found */ 5458/***/ (function(module, exports) { 5459 5460// shim for using process in browser 5461var process = module.exports = {}; 5462 5463// cached from whatever global is present so that test runners that stub it 5464// don't break things. But we need to wrap it in a try catch in case it is 5465// wrapped in strict mode code which doesn't define any globals. It's inside a 5466// function because try/catches deoptimize in certain engines. 5467 5468var cachedSetTimeout; 5469var cachedClearTimeout; 5470 5471function defaultSetTimout() { 5472 throw new Error('setTimeout has not been defined'); 5473} 5474function defaultClearTimeout () { 5475 throw new Error('clearTimeout has not been defined'); 5476} 5477(function () { 5478 try { 5479 if (typeof setTimeout === 'function') { 5480 cachedSetTimeout = setTimeout; 5481 } else { 5482 cachedSetTimeout = defaultSetTimout; 5483 } 5484 } catch (e) { 5485 cachedSetTimeout = defaultSetTimout; 5486 } 5487 try { 5488 if (typeof clearTimeout === 'function') { 5489 cachedClearTimeout = clearTimeout; 5490 } else { 5491 cachedClearTimeout = defaultClearTimeout; 5492 } 5493 } catch (e) { 5494 cachedClearTimeout = defaultClearTimeout; 5495 } 5496} ()) 5497function runTimeout(fun) { 5498 if (cachedSetTimeout === setTimeout) { 5499 //normal enviroments in sane situations 5500 return setTimeout(fun, 0); 5501 } 5502 // if setTimeout wasn't available but was latter defined 5503 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { 5504 cachedSetTimeout = setTimeout; 5505 return setTimeout(fun, 0); 5506 } 5507 try { 5508 // when when somebody has screwed with setTimeout but no I.E. maddness 5509 return cachedSetTimeout(fun, 0); 5510 } catch(e){ 5511 try { 5512 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally 5513 return cachedSetTimeout.call(null, fun, 0); 5514 } catch(e){ 5515 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error 5516 return cachedSetTimeout.call(this, fun, 0); 5517 } 5518 } 5519 5520 5521} 5522function runClearTimeout(marker) { 5523 if (cachedClearTimeout === clearTimeout) { 5524 //normal enviroments in sane situations 5525 return clearTimeout(marker); 5526 } 5527 // if clearTimeout wasn't available but was latter defined 5528 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { 5529 cachedClearTimeout = clearTimeout; 5530 return clearTimeout(marker); 5531 } 5532 try { 5533 // when when somebody has screwed with setTimeout but no I.E. maddness 5534 return cachedClearTimeout(marker); 5535 } catch (e){ 5536 try { 5537 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally 5538 return cachedClearTimeout.call(null, marker); 5539 } catch (e){ 5540 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. 5541 // Some versions of I.E. have different rules for clearTimeout vs setTimeout 5542 return cachedClearTimeout.call(this, marker); 5543 } 5544 } 5545 5546 5547 5548} 5549var queue = []; 5550var draining = false; 5551var currentQueue; 5552var queueIndex = -1; 5553 5554function cleanUpNextTick() { 5555 if (!draining || !currentQueue) { 5556 return; 5557 } 5558 draining = false; 5559 if (currentQueue.length) { 5560 queue = currentQueue.concat(queue); 5561 } else { 5562 queueIndex = -1; 5563 } 5564 if (queue.length) { 5565 drainQueue(); 5566 } 5567} 5568 5569function drainQueue() { 5570 if (draining) { 5571 return; 5572 } 5573 var timeout = runTimeout(cleanUpNextTick); 5574 draining = true; 5575 5576 var len = queue.length; 5577 while(len) { 5578 currentQueue = queue; 5579 queue = []; 5580 while (++queueIndex < len) { 5581 if (currentQueue) { 5582 currentQueue[queueIndex].run(); 5583 } 5584 } 5585 queueIndex = -1; 5586 len = queue.length; 5587 } 5588 currentQueue = null; 5589 draining = false; 5590 runClearTimeout(timeout); 5591} 5592 5593process.nextTick = function (fun) { 5594 var args = new Array(arguments.length - 1); 5595 if (arguments.length > 1) { 5596 for (var i = 1; i < arguments.length; i++) { 5597 args[i - 1] = arguments[i]; 5598 } 5599 } 5600 queue.push(new Item(fun, args)); 5601 if (queue.length === 1 && !draining) { 5602 runTimeout(drainQueue); 5603 } 5604}; 5605 5606// v8 likes predictible objects 5607function Item(fun, array) { 5608 this.fun = fun; 5609 this.array = array; 5610} 5611Item.prototype.run = function () { 5612 this.fun.apply(null, this.array); 5613}; 5614process.title = 'browser'; 5615process.browser = true; 5616process.env = {}; 5617process.argv = []; 5618process.version = ''; // empty string to avoid regexp issues 5619process.versions = {}; 5620 5621function noop() {} 5622 5623process.on = noop; 5624process.addListener = noop; 5625process.once = noop; 5626process.off = noop; 5627process.removeListener = noop; 5628process.removeAllListeners = noop; 5629process.emit = noop; 5630process.prependListener = noop; 5631process.prependOnceListener = noop; 5632 5633process.listeners = function (name) { return [] } 5634 5635process.binding = function (name) { 5636 throw new Error('process.binding is not supported'); 5637}; 5638 5639process.cwd = function () { return '/' }; 5640process.chdir = function (dir) { 5641 throw new Error('process.chdir is not supported'); 5642}; 5643process.umask = function() { return 0; }; 5644 5645 5646/***/ }), 5647 5648/***/ "./node_modules/setimmediate/setImmediate.js": 5649/*!***************************************************!*\ 5650 !*** ./node_modules/setimmediate/setImmediate.js ***! 5651 \***************************************************/ 5652/*! no static exports found */ 5653/***/ (function(module, exports, __webpack_require__) { 5654 5655/* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) { 5656 "use strict"; 5657 5658 if (global.setImmediate) { 5659 return; 5660 } 5661 5662 var nextHandle = 1; // Spec says greater than zero 5663 var tasksByHandle = {}; 5664 var currentlyRunningATask = false; 5665 var doc = global.document; 5666 var registerImmediate; 5667 5668 function setImmediate(callback) { 5669 // Callback can either be a function or a string 5670 if (typeof callback !== "function") { 5671 callback = new Function("" + callback); 5672 } 5673 // Copy function arguments 5674 var args = new Array(arguments.length - 1); 5675 for (var i = 0; i < args.length; i++) { 5676 args[i] = arguments[i + 1]; 5677 } 5678 // Store and register the task 5679 var task = { callback: callback, args: args }; 5680 tasksByHandle[nextHandle] = task; 5681 registerImmediate(nextHandle); 5682 return nextHandle++; 5683 } 5684 5685 function clearImmediate(handle) { 5686 delete tasksByHandle[handle]; 5687 } 5688 5689 function run(task) { 5690 var callback = task.callback; 5691 var args = task.args; 5692 switch (args.length) { 5693 case 0: 5694 callback(); 5695 break; 5696 case 1: 5697 callback(args[0]); 5698 break; 5699 case 2: 5700 callback(args[0], args[1]); 5701 break; 5702 case 3: 5703 callback(args[0], args[1], args[2]); 5704 break; 5705 default: 5706 callback.apply(undefined, args); 5707 break; 5708 } 5709 } 5710 5711 function runIfPresent(handle) { 5712 // From the spec: "Wait until any invocations of this algorithm started before this one have completed." 5713 // So if we're currently running a task, we'll need to delay this invocation. 5714 if (currentlyRunningATask) { 5715 // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a 5716 // "too much recursion" error. 5717 setTimeout(runIfPresent, 0, handle); 5718 } else { 5719 var task = tasksByHandle[handle]; 5720 if (task) { 5721 currentlyRunningATask = true; 5722 try { 5723 run(task); 5724 } finally { 5725 clearImmediate(handle); 5726 currentlyRunningATask = false; 5727 } 5728 } 5729 } 5730 } 5731 5732 function installNextTickImplementation() { 5733 registerImmediate = function(handle) { 5734 process.nextTick(function () { runIfPresent(handle); }); 5735 }; 5736 } 5737 5738 function canUsePostMessage() { 5739 // The test against `importScripts` prevents this implementation from being installed inside a web worker, 5740 // where `global.postMessage` means something completely different and can't be used for this purpose. 5741 if (global.postMessage && !global.importScripts) { 5742 var postMessageIsAsynchronous = true; 5743 var oldOnMessage = global.onmessage; 5744 global.onmessage = function() { 5745 postMessageIsAsynchronous = false; 5746 }; 5747 global.postMessage("", "*"); 5748 global.onmessage = oldOnMessage; 5749 return postMessageIsAsynchronous; 5750 } 5751 } 5752 5753 function installPostMessageImplementation() { 5754 // Installs an event handler on `global` for the `message` event: see 5755 // * https://developer.mozilla.org/en/DOM/window.postMessage 5756 // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages 5757 5758 var messagePrefix = "setImmediate$" + Math.random() + "$"; 5759 var onGlobalMessage = function(event) { 5760 if (event.source === global && 5761 typeof event.data === "string" && 5762 event.data.indexOf(messagePrefix) === 0) { 5763 runIfPresent(+event.data.slice(messagePrefix.length)); 5764 } 5765 }; 5766 5767 if (global.addEventListener) { 5768 global.addEventListener("message", onGlobalMessage, false); 5769 } else { 5770 global.attachEvent("onmessage", onGlobalMessage); 5771 } 5772 5773 registerImmediate = function(handle) { 5774 global.postMessage(messagePrefix + handle, "*"); 5775 }; 5776 } 5777 5778 function installMessageChannelImplementation() { 5779 var channel = new MessageChannel(); 5780 channel.port1.onmessage = function(event) { 5781 var handle = event.data; 5782 runIfPresent(handle); 5783 }; 5784 5785 registerImmediate = function(handle) { 5786 channel.port2.postMessage(handle); 5787 }; 5788 } 5789 5790 function installReadyStateChangeImplementation() { 5791 var html = doc.documentElement; 5792 registerImmediate = function(handle) { 5793 // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted 5794 // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called. 5795 var script = doc.createElement("script"); 5796 script.onreadystatechange = function () { 5797 runIfPresent(handle); 5798 script.onreadystatechange = null; 5799 html.removeChild(script); 5800 script = null; 5801 }; 5802 html.appendChild(script); 5803 }; 5804 } 5805 5806 function installSetTimeoutImplementation() { 5807 registerImmediate = function(handle) { 5808 setTimeout(runIfPresent, 0, handle); 5809 }; 5810 } 5811 5812 // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live. 5813 var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global); 5814 attachTo = attachTo && attachTo.setTimeout ? attachTo : global; 5815 5816 // Don't get fooled by e.g. browserify environments. 5817 if ({}.toString.call(global.process) === "[object process]") { 5818 // For Node.js before 0.9 5819 installNextTickImplementation(); 5820 5821 } else if (canUsePostMessage()) { 5822 // For non-IE10 modern browsers 5823 installPostMessageImplementation(); 5824 5825 } else if (global.MessageChannel) { 5826 // For web workers, where supported 5827 installMessageChannelImplementation(); 5828 5829 } else if (doc && "onreadystatechange" in doc.createElement("script")) { 5830 // For IE 6–8 5831 installReadyStateChangeImplementation(); 5832 5833 } else { 5834 // For older browsers 5835 installSetTimeoutImplementation(); 5836 } 5837 5838 attachTo.setImmediate = setImmediate; 5839 attachTo.clearImmediate = clearImmediate; 5840}(typeof self === "undefined" ? typeof global === "undefined" ? this : global : self)); 5841 5842/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"), __webpack_require__(/*! ./../process/browser.js */ "./node_modules/process/browser.js"))) 5843 5844/***/ }), 5845 5846/***/ "./node_modules/timers-browserify/main.js": 5847/*!************************************************!*\ 5848 !*** ./node_modules/timers-browserify/main.js ***! 5849 \************************************************/ 5850/*! no static exports found */ 5851/***/ (function(module, exports, __webpack_require__) { 5852 5853/* WEBPACK VAR INJECTION */(function(global) {var scope = (typeof global !== "undefined" && global) || 5854 (typeof self !== "undefined" && self) || 5855 window; 5856var apply = Function.prototype.apply; 5857 5858// DOM APIs, for completeness 5859 5860exports.setTimeout = function() { 5861 return new Timeout(apply.call(setTimeout, scope, arguments), clearTimeout); 5862}; 5863exports.setInterval = function() { 5864 return new Timeout(apply.call(setInterval, scope, arguments), clearInterval); 5865}; 5866exports.clearTimeout = 5867exports.clearInterval = function(timeout) { 5868 if (timeout) { 5869 timeout.close(); 5870 } 5871}; 5872 5873function Timeout(id, clearFn) { 5874 this._id = id; 5875 this._clearFn = clearFn; 5876} 5877Timeout.prototype.unref = Timeout.prototype.ref = function() {}; 5878Timeout.prototype.close = function() { 5879 this._clearFn.call(scope, this._id); 5880}; 5881 5882// Does not start the time, just sets up the members needed. 5883exports.enroll = function(item, msecs) { 5884 clearTimeout(item._idleTimeoutId); 5885 item._idleTimeout = msecs; 5886}; 5887 5888exports.unenroll = function(item) { 5889 clearTimeout(item._idleTimeoutId); 5890 item._idleTimeout = -1; 5891}; 5892 5893exports._unrefActive = exports.active = function(item) { 5894 clearTimeout(item._idleTimeoutId); 5895 5896 var msecs = item._idleTimeout; 5897 if (msecs >= 0) { 5898 item._idleTimeoutId = setTimeout(function onTimeout() { 5899 if (item._onTimeout) 5900 item._onTimeout(); 5901 }, msecs); 5902 } 5903}; 5904 5905// setimmediate attaches itself to the global object 5906__webpack_require__(/*! setimmediate */ "./node_modules/setimmediate/setImmediate.js"); 5907// On some exotic environments, it's not clear which object `setimmediate` was 5908// able to install onto. Search each possibility in the same order as the 5909// `setimmediate` library. 5910exports.setImmediate = (typeof self !== "undefined" && self.setImmediate) || 5911 (typeof global !== "undefined" && global.setImmediate) || 5912 (this && this.setImmediate); 5913exports.clearImmediate = (typeof self !== "undefined" && self.clearImmediate) || 5914 (typeof global !== "undefined" && global.clearImmediate) || 5915 (this && this.clearImmediate); 5916 5917/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"))) 5918 5919/***/ }), 5920 5921/***/ "./node_modules/webpack/buildin/global.js": 5922/*!***********************************!*\ 5923 !*** (webpack)/buildin/global.js ***! 5924 \***********************************/ 5925/*! no static exports found */ 5926/***/ (function(module, exports) { 5927 5928var g; 5929 5930// This works in non-strict mode 5931g = (function() { 5932 return this; 5933})(); 5934 5935try { 5936 // This works if eval is allowed (see CSP) 5937 g = g || Function("return this")() || (1, eval)("this"); 5938} catch (e) { 5939 // This works if the window reference is available 5940 if (typeof window === "object") g = window; 5941} 5942 5943// g can still be undefined, but nothing to do about it... 5944// We return undefined, instead of nothing here, so it's 5945// easier to handle this case. if(!global) { ...} 5946 5947module.exports = g; 5948 5949 5950/***/ }), 5951 5952/***/ "./sources/constants/index.js": 5953/*!************************************!*\ 5954 !*** ./sources/constants/index.js ***! 5955 \************************************/ 5956/*! no static exports found */ 5957/***/ (function(module, exports) { 5958 5959module.exports = { 5960 KEY_CODES: { 5961 UP: 38, 5962 DOWN: 40, 5963 LEFT: 37, 5964 RIGHT: 39, 5965 SPACE: 32, 5966 ENTER: 13, 5967 DELETE: 46, 5968 ESC: 27, 5969 TAB: 9 5970 } 5971}; 5972 5973/***/ }), 5974 5975/***/ "./sources/core/cached_functions.js": 5976/*!******************************************!*\ 5977 !*** ./sources/core/cached_functions.js ***! 5978 \******************************************/ 5979/*! no static exports found */ 5980/***/ (function(module, exports) { 5981 5982/* 5983 reuse results of functions that can be recalculated during rendering 5984 greatly increases the rendering speed when critical path enabled 5985 Sample - 94_dev/critical_path.html 5986 5987 */ 5988module.exports = function(gantt){ 5989 5990gantt._cached_functions = { 5991 cache: {}, 5992 mode: false, 5993 critical_path_mode: false, 5994 wrap_methods : function(methods, object){ 5995 if(object._prefetch_originals){ 5996 for(var i in object._prefetch_originals){ 5997 object[i] = object._prefetch_originals[i]; 5998 } 5999 } 6000 object._prefetch_originals = {}; 6001 for(var i = 0; i < methods.length; i++) 6002 this.prefetch(methods[i], object); 6003 6004 }, 6005 prefetch : function(methodname, host){ 6006 var original = host[methodname]; 6007 if(original){ 6008 var optimizer = this; 6009 6010 host._prefetch_originals[methodname] = original; 6011 host[methodname] = function get_prefetched_value(){ 6012 6013 var argumentsArray = new Array(arguments.length); 6014 for (var i = 0, l = arguments.length; i < l; i++) { 6015 argumentsArray[i] = arguments[i]; 6016 } 6017 6018 if(optimizer.active){ 6019 var args = optimizer.get_arguments_hash(Array.prototype.slice.call(argumentsArray)); 6020 if(!optimizer.cache[methodname]){ 6021 optimizer.cache[methodname] = {}; 6022 } 6023 6024 var cached_values = optimizer.cache[methodname]; 6025 6026 if(optimizer.has_cached_value(cached_values, args)){ 6027 return optimizer.get_cached_value(cached_values, args); 6028 }else{ 6029 var value = original.apply(this, argumentsArray); 6030 optimizer.cache_value(cached_values, args, value); 6031 return value; 6032 } 6033 } 6034 6035 return original.apply(this, argumentsArray); 6036 }; 6037 } 6038 return original; 6039 }, 6040 cache_value: function(cache, arguments_hash, value){ 6041 if(this.is_date(value)) 6042 value = new Date(value); 6043 cache[arguments_hash] = value; 6044 }, 6045 has_cached_value: function(cache, arguments_hash){ 6046 return cache.hasOwnProperty(arguments_hash); 6047 }, 6048 get_cached_value: function(cache, arguments_hash){ 6049 var data = cache[arguments_hash]; 6050 6051 //for cached dates - return copy 6052 if(this.is_date(data)){ 6053 data = new Date(data); 6054 } 6055 return data; 6056 }, 6057 is_date: function(value){ 6058 return (value && value.getUTCDate); 6059 }, 6060 get_arguments_hash:function(args){ 6061 var values = []; 6062 for(var i = 0; i < args.length; i++){ 6063 values.push(this.stringify_argument(args[i])); 6064 } 6065 return "(" + values.join(";") + ")"; 6066 }, 6067 stringify_argument: function(value){ 6068 //expecting task or link, or any other data entries, dates and primitive values 6069 var ret = ""; 6070 if(value.id){ 6071 ret = value.id; 6072 }else if(this.is_date(value)){ 6073 ret = value.valueOf(); 6074 }else{ 6075 ret = value; 6076 } 6077 return ret + ""; 6078 }, 6079 activate: function(){ 6080 this.clear(); 6081 this.active = true; 6082 }, 6083 deactivate: function(){ 6084 this.clear(); 6085 this.active = false; 6086 }, 6087 clear: function(){ 6088 this.cache = {}; 6089 }, 6090 6091 setup: function(gantt){ 6092 var override_gantt = []; 6093 6094 var gantt_methods = [ 6095 '_isProjectEnd', 6096 '_getProjectEnd', 6097 '_getSlack' 6098 ]; 6099 6100 6101 6102 if(this.mode == 'auto'){ 6103 if(gantt.config.highlight_critical_path){ 6104 override_gantt = gantt_methods; 6105 } 6106 }else if(this.mode === true){ 6107 override_gantt = gantt_methods; 6108 } 6109 6110 this.wrap_methods(override_gantt, gantt); 6111 6112 }, 6113 update_if_changed: function(gantt){ 6114 var changed = (this.critical_path_mode != gantt.config.highlight_critical_path || 6115 this.mode !== gantt.config.optimize_render); 6116 if(changed){ 6117 this.critical_path_mode = gantt.config.highlight_critical_path; 6118 this.mode = gantt.config.optimize_render; 6119 this.setup(gantt); 6120 } 6121 } 6122}; 6123 6124function activate(){ 6125 gantt._cached_functions.update_if_changed(gantt); 6126 if(!gantt._cached_functions.active){ 6127 gantt._cached_functions.activate(); 6128 } 6129 return true; 6130} 6131gantt.attachEvent("onBeforeGanttRender", activate); 6132gantt.attachEvent("onBeforeDataRender", activate); 6133gantt.attachEvent("onBeforeSmartRender", function(){ 6134 activate(); 6135}); 6136gantt.attachEvent("onBeforeParse", activate); 6137gantt.attachEvent("onDataRender", function(){ 6138 gantt._cached_functions.deactivate(); 6139}); 6140var deactivTimeout = null; 6141gantt.attachEvent("onSmartRender", function(){ 6142 if(deactivTimeout) 6143 clearTimeout(deactivTimeout); 6144 deactivTimeout = setTimeout(function(){ 6145 gantt._cached_functions.deactivate(); 6146 }, 1000); 6147}); 6148 6149gantt.attachEvent("onBeforeGanttReady", function(){ 6150 gantt._cached_functions.update_if_changed(gantt); 6151 return true; 6152}); 6153 6154}; 6155 6156/***/ }), 6157 6158/***/ "./sources/core/common/ajax.js": 6159/*!*************************************!*\ 6160 !*** ./sources/core/common/ajax.js ***! 6161 \*************************************/ 6162/*! no static exports found */ 6163/***/ (function(module, exports, __webpack_require__) { 6164 6165var env = __webpack_require__(/*! ../../utils/env */ "./sources/utils/env.js"); 6166var serialize = __webpack_require__(/*! ./serialize */ "./sources/core/common/serialize.ts").default; 6167 6168function createConfig(method, args) { 6169 var result = { 6170 method: method 6171 }; 6172 6173 if (args.length === 0) { 6174 throw new Error("Arguments list of query is wrong."); 6175 } 6176 if (args.length === 1) { 6177 if (typeof args[0] === "string") { 6178 result.url = args[0]; 6179 result.async = true; 6180 } else { 6181 result.url = args[0].url; 6182 result.async = (args[0].async || true); 6183 result.callback = args[0].callback; 6184 result.headers = args[0].headers; 6185 } 6186 if (method === "POST" || "PUT") { 6187 if (args[0].data) { 6188 if (typeof args[0].data !== "string") { 6189 result.data = serialize(args[0].data); 6190 } else { 6191 result.data = args[0].data; 6192 } 6193 } else { 6194 result.data = ""; 6195 } 6196 } 6197 return result; 6198 } 6199 6200 result.url = args[0]; 6201 switch(method) { 6202 case "GET": 6203 case "DELETE": 6204 result.callback = args[1]; 6205 result.headers = args[2]; 6206 break; 6207 case "POST": 6208 case "PUT": 6209 if (args[1]) { 6210 if (typeof args[1] !== "string") { 6211 result.data = serialize(args[1]); 6212 } else { 6213 result.data = args[1]; 6214 } 6215 } else { 6216 result.data = ""; 6217 } 6218 result.callback = args[2]; 6219 result.headers = args[3]; 6220 break; 6221 } 6222 return result; 6223} 6224 6225module.exports = function(gantt) { 6226 return { 6227 6228 // if false - dhxr param will added to prevent caching on client side (default), 6229 // if true - do not add extra params 6230 cache: true, 6231 6232 // default method for load/loadStruct, post/get allowed 6233 // get - since 4.1.1, this should fix 412 error for macos safari 6234 method: "get", 6235 6236 parse: function(data) { 6237 if (typeof data !== "string") return data; 6238 6239 var obj; 6240 data = data.replace(/^[\s]+/,""); 6241 if (window.DOMParser && !env.isIE) { // ff,ie9 6242 obj = (new window.DOMParser()).parseFromString(data, "text/xml"); 6243 } else if (window.ActiveXObject !== window.undefined) { 6244 obj = new window.ActiveXObject("Microsoft.XMLDOM"); 6245 obj.async = "false"; 6246 obj.loadXML(data); 6247 } 6248 return obj; 6249 }, 6250 xmltop: function(tagname, xhr, obj) { 6251 if (typeof xhr.status == "undefined" || xhr.status < 400) { 6252 var xml = (!xhr.responseXML) ? this.parse(xhr.responseText || xhr) : (xhr.responseXML || xhr); 6253 if (xml && xml.documentElement !== null && !xml.getElementsByTagName("parsererror").length) { 6254 return xml.getElementsByTagName(tagname)[0]; 6255 } 6256 } 6257 if (obj !== -1) gantt.callEvent("onLoadXMLError",["Incorrect XML", arguments[1], obj]); 6258 return document.createElement("DIV"); 6259 }, 6260 xpath: function(xpathExp, docObj) { 6261 if (!docObj.nodeName) docObj = docObj.responseXML || docObj; 6262 if (env.isIE) { 6263 return docObj.selectNodes(xpathExp)||[]; 6264 } else { 6265 var rows = []; 6266 var first; 6267 var col = (docObj.ownerDocument||docObj).evaluate(xpathExp, docObj, null, XPathResult.ANY_TYPE, null); 6268 6269 while (true){ 6270 first = col.iterateNext(); 6271 if(first){ 6272 rows.push(first); 6273 }else{ 6274 break; 6275 } 6276 } 6277 return rows; 6278 } 6279 }, 6280 query: function(config) { 6281 return this._call( 6282 (config.method || "GET"), 6283 config.url, 6284 config.data || "", 6285 (config.async || true), 6286 config.callback, 6287 config.headers 6288 ); 6289 }, 6290 get: function(url, onLoad, headers) { 6291 var config = createConfig("GET", arguments); 6292 return this.query(config); 6293 }, 6294 getSync: function(url, headers) { 6295 var config = createConfig("GET", arguments); 6296 config.async = false; 6297 return this.query(config); 6298 }, 6299 put: function(url, postData, onLoad, headers) { 6300 var config = createConfig("PUT", arguments); 6301 return this.query(config); 6302 }, 6303 del: function(url, onLoad, headers) { 6304 /** 6305 * https://tools.ietf.org/html/rfc7231#section-4.3.5 6306 * A payload within a DELETE request message has no defined semantics; 6307 * sending a payload body on a DELETE request might cause some existing 6308 * implementations to reject the request. 6309 */ 6310 var config = createConfig("DELETE", arguments); 6311 return this.query(config); 6312 }, 6313 post: function(url, postData, onLoad, headers) { 6314 if (arguments.length == 1) { 6315 postData = ""; 6316 } else if (arguments.length == 2 && (typeof(postData) == "function" || typeof(window[postData]) == "function")) { 6317 onLoad = postData; 6318 postData = ""; 6319 } 6320 var config = createConfig("POST", arguments); 6321 return this.query(config); 6322 }, 6323 postSync: function(url, postData, headers) { 6324 postData = (postData === null ? "" : String(postData)); 6325 6326 var config = createConfig("POST", arguments); 6327 config.async = false; 6328 return this.query(config); 6329 }, 6330 _call: function(method, url, postData, async, onLoad, headers) { 6331 return new gantt.Promise(function(resolve, reject) { 6332 var t = (window.XMLHttpRequest && !env.isIE ? new XMLHttpRequest() : new window.ActiveXObject("Microsoft.XMLHTTP")); 6333 var isQt = (navigator.userAgent.match(/AppleWebKit/) !== null && navigator.userAgent.match(/Qt/) !== null && navigator.userAgent.match(/Safari/) !== null); 6334 6335 if (!!async) { 6336 t.onreadystatechange = function() { 6337 if ((t.readyState == 4) || (isQt && t.readyState == 3)) { // what for long response and status 404? 6338 if (t.status != 200 || t.responseText === "") 6339 if (!gantt.callEvent("onAjaxError", [t])) return; 6340 6341 window.setTimeout(function() { 6342 if (typeof(onLoad) == "function") { 6343 onLoad.apply(window, [{xmlDoc:t, filePath:url}]); // dhtmlx-compat, response.xmlDoc.responseXML/responseText 6344 } 6345 resolve(t); 6346 if (typeof(onLoad) == "function") { 6347 onLoad = null; 6348 t = null; 6349 } 6350 }, 0); 6351 } 6352 }; 6353 } 6354 6355 if (method == "GET" && !this.cache) { 6356 url += (url.indexOf("?")>=0?"&":"?")+"dhxr"+new Date().getTime()+"=1"; 6357 } 6358 6359 t.open(method, url, async); 6360 6361 if (headers){ 6362 for (var key in headers) 6363 t.setRequestHeader(key, headers[key]); 6364 } else if (method.toUpperCase() == "POST" || method == "PUT" || method == "DELETE") { 6365 t.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 6366 } else if (method == "GET") { 6367 postData = null; 6368 } 6369 6370 t.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 6371 6372 t.send(postData); 6373 6374 if (!async) return {xmlDoc:t, filePath:url}; // dhtmlx-compat, response.xmlDoc.responseXML/responseText 6375 }); 6376 }, 6377 urlSeparator: function(str){ 6378 if (str.indexOf("?") != -1) 6379 return "&"; 6380 else 6381 return "?"; 6382 } 6383 }; 6384}; 6385 6386 6387/***/ }), 6388 6389/***/ "./sources/core/common/assert.js": 6390/*!***************************************!*\ 6391 !*** ./sources/core/common/assert.js ***! 6392 \***************************************/ 6393/*! no static exports found */ 6394/***/ (function(module, exports) { 6395 6396/* 6397 asserts will be removed in final code, so you can place them anythere 6398 without caring about performance impacts 6399*/ 6400 6401module.exports = function(gantt){ 6402 return function assert(check, message){ 6403 if (!check){ 6404 if(gantt.config.show_errors && gantt.callEvent("onError",[message]) !== false) { 6405 gantt.message({type: "error", text: message, expire: -1}); 6406 6407 // eslint-disable-next-line no-debugger 6408 debugger; 6409 } 6410 } 6411 }; 6412}; 6413 6414/***/ }), 6415 6416/***/ "./sources/core/common/config.ts": 6417/*!***************************************!*\ 6418 !*** ./sources/core/common/config.ts ***! 6419 \***************************************/ 6420/*! no static exports found */ 6421/***/ (function(module, exports, __webpack_require__) { 6422 6423"use strict"; 6424 6425Object.defineProperty(exports, "__esModule", { value: true }); 6426module.exports = function () { 6427 var result = { 6428 layout: { 6429 css: "gantt_container", 6430 rows: [ 6431 { 6432 cols: [ 6433 { view: "grid", scrollX: "scrollHor", scrollY: "scrollVer" }, 6434 { resizer: true, width: 1 }, 6435 { view: "timeline", scrollX: "scrollHor", scrollY: "scrollVer" }, 6436 { view: "scrollbar", id: "scrollVer" } 6437 ] 6438 }, 6439 { view: "scrollbar", id: "scrollHor", height: 20 } 6440 ] 6441 }, 6442 links: { 6443 finish_to_start: "0", 6444 start_to_start: "1", 6445 finish_to_finish: "2", 6446 start_to_finish: "3" 6447 }, 6448 types: { 6449 task: "task", 6450 project: "project", 6451 milestone: "milestone" 6452 }, 6453 auto_types: false, 6454 duration_unit: "day", 6455 work_time: false, 6456 correct_work_time: false, 6457 skip_off_time: false, 6458 cascade_delete: true, 6459 autosize: false, 6460 autosize_min_width: 0, 6461 autoscroll: true, 6462 autoscroll_speed: 30, 6463 show_links: true, 6464 show_task_cells: true, 6465 // replace backgroung of the task area with a canvas img 6466 static_background: false, 6467 static_background_cells: true, 6468 branch_loading: false, 6469 branch_loading_property: "$has_child", 6470 show_loading: false, 6471 show_chart: true, 6472 show_grid: true, 6473 min_duration: 60 * 60 * 1000, 6474 date_format: "%d-%m-%Y %H:%i", 6475 xml_date: undefined, 6476 start_on_monday: true, 6477 server_utc: false, 6478 show_progress: true, 6479 fit_tasks: false, 6480 select_task: true, 6481 scroll_on_click: true, 6482 smart_rendering: true, 6483 preserve_scroll: true, 6484 readonly: false, 6485 /*grid */ 6486 date_grid: "%Y-%m-%d", 6487 drag_links: true, 6488 drag_progress: true, 6489 drag_resize: true, 6490 drag_project: false, 6491 drag_move: true, 6492 drag_mode: { 6493 resize: "resize", 6494 progress: "progress", 6495 move: "move", 6496 ignore: "ignore" 6497 }, 6498 round_dnd_dates: true, 6499 link_wrapper_width: 20, 6500 root_id: 0, 6501 autofit: false, 6502 columns: [ 6503 { name: "text", tree: true, width: "*", resize: true }, 6504 { name: "start_date", align: "center", resize: true }, 6505 { name: "duration", align: "center" }, 6506 { name: "add", width: 44 } 6507 ], 6508 /*scale*/ 6509 scale_offset_minimal: true, 6510 inherit_scale_class: false, 6511 scales: [ 6512 { 6513 unit: "day", 6514 step: 1, 6515 date: "%d %M" 6516 } 6517 ], 6518 // date_scale: "%d %M", 6519 time_step: 60, 6520 duration_step: 1, 6521 task_date: "%d %F %Y", 6522 time_picker: "%H:%i", 6523 task_attribute: "task_id", 6524 link_attribute: "link_id", 6525 layer_attribute: "data-layer", 6526 buttons_left: [ 6527 "gantt_save_btn", 6528 "gantt_cancel_btn" 6529 ], 6530 _migrate_buttons: { 6531 dhx_save_btn: "gantt_save_btn", 6532 dhx_cancel_btn: "gantt_cancel_btn", 6533 dhx_delete_btn: "gantt_delete_btn" 6534 }, 6535 buttons_right: [ 6536 "gantt_delete_btn" 6537 ], 6538 lightbox: { 6539 sections: [ 6540 { name: "description", height: 70, map_to: "text", type: "textarea", focus: true }, 6541 { name: "time", type: "duration", map_to: "auto" } 6542 ], 6543 project_sections: [ 6544 { name: "description", height: 70, map_to: "text", type: "textarea", focus: true }, 6545 { name: "type", type: "typeselect", map_to: "type" }, 6546 { name: "time", type: "duration", readonly: true, map_to: "auto" } 6547 ], 6548 milestone_sections: [ 6549 { name: "description", height: 70, map_to: "text", type: "textarea", focus: true }, 6550 { name: "type", type: "typeselect", map_to: "type" }, 6551 { name: "time", type: "duration", single_date: true, map_to: "auto" } 6552 ] 6553 }, 6554 drag_lightbox: true, 6555 sort: false, 6556 details_on_create: true, 6557 details_on_dblclick: true, 6558 initial_scroll: true, 6559 task_scroll_offset: 100, 6560 order_branch: false, 6561 order_branch_free: false, 6562 task_height: "full", 6563 min_column_width: 70, 6564 // min width for grid column (when resizing) 6565 min_grid_column_width: 70, 6566 // name of the attribute with column index for resize element 6567 grid_resizer_column_attribute: "column_index", 6568 // name of the attribute with column index for resize element 6569 grid_resizer_attribute: "grid_resizer", 6570 // grid width can be increased after the column has been resized 6571 keep_grid_width: false, 6572 // grid width can be adjusted 6573 grid_resize: false, 6574 show_tasks_outside_timescale: false, 6575 show_unscheduled: true, 6576 // 6577 readonly_property: "readonly", 6578 editable_property: "editable", 6579 calendar_property: "calendar_id", 6580 resource_calendars: {}, 6581 inherit_calendar: false, 6582 type_renderers: {}, 6583 open_tree_initially: false, 6584 optimize_render: true, 6585 prevent_default_scroll: false, 6586 show_errors: true, 6587 wai_aria_attributes: true, 6588 smart_scales: true, 6589 rtl: false, 6590 placeholder_task: false, 6591 horizontal_scroll_key: "shiftKey", 6592 drag_timeline: { 6593 useKey: undefined, 6594 ignore: ".gantt_task_line, .gantt_task_link" 6595 }, 6596 drag_multiple: true 6597 }; 6598 return result; 6599}; 6600 6601 6602/***/ }), 6603 6604/***/ "./sources/core/common/date.js": 6605/*!*************************************!*\ 6606 !*** ./sources/core/common/date.js ***! 6607 \*************************************/ 6608/*! no static exports found */ 6609/***/ (function(module, exports) { 6610 6611/* 6612 %d - the day as a number with a leading zero ( 01 to 31 ); 6613 %j - the day as a number without a leading zero ( 1 to 31 ); 6614 %D - the day as an abbreviation ( Sun to Sat ); 6615 %l - the day as a full name ( Sunday to Saturday ); 6616 %W - the ISO-8601 week number of the year. Weeks start on Monday; 1) 6617 %m - the month as a number without a leading zero ( 1 to 12 ); 6618 %n - the month as a number with a leading zero ( 01 to 12); 6619 %M - the month as an abbreviation ( Jan to Dec ); 6620 %F - the month as a full name ( January to December ); 6621 %y - the year as a two-digit number ( 00 to 99 ); 6622 %Y - the year as a four-digit number ( 1900–9999 ); 6623 %h - the hour based on the 12-hour clock ( 00 to 11 ); 6624 %H - the hour based on the 24-hour clock ( 00 to 23 ); 6625 %i - the minute as a number with a leading zero ( 00 to 59 ); 6626 %s - the second as a number without a leading zero ( 00 to 59 ); 2) 6627 %a - displays am (for times from midnight until noon) and pm (for times from noon until midnight); 6628 %A - displays AM (for times from midnight until noon) and PM (for times from noon until midnight). 6629*/ 6630 6631module.exports = function(gantt) { 6632 var dateHelper = { 6633 init: function () { 6634 var locale = gantt.locale; 6635 6636 var s = locale.date.month_short; 6637 var t = locale.date.month_short_hash = {}; 6638 for (var i = 0; i < s.length; i++) 6639 t[s[i]] = i; 6640 6641 var s = locale.date.month_full; 6642 var t = locale.date.month_full_hash = {}; 6643 for (var i = 0; i < s.length; i++) 6644 t[s[i]] = i; 6645 }, 6646 date_part: function (date) { 6647 var old = new Date(date); 6648 date.setHours(0); 6649 this.hour_start(date); 6650 if (date.getHours() && //shift to yesterday on dst 6651 (date.getDate() < old.getDate() || date.getMonth() < old.getMonth() || date.getFullYear() < old.getFullYear())) 6652 date.setTime(date.getTime() + 60 * 60 * 1000 * (24 - date.getHours())); 6653 return date; 6654 }, 6655 time_part: function (date) { 6656 return (date.valueOf() / 1000 - date.getTimezoneOffset() * 60) % 86400; 6657 }, 6658 week_start: function (date) { 6659 var shift = date.getDay(); 6660 if (gantt.config.start_on_monday) { 6661 if (shift === 0) shift = 6; 6662 else shift--; 6663 } 6664 return this.date_part(this.add(date, -1 * shift, "day")); 6665 }, 6666 month_start: function (date) { 6667 date.setDate(1); 6668 return this.date_part(date); 6669 }, 6670 quarter_start: function (date) { 6671 this.month_start(date); 6672 var m = date.getMonth(), 6673 res_month; 6674 6675 if (m >= 9) { 6676 res_month = 9; 6677 } else if (m >= 6) { 6678 res_month = 6; 6679 } else if (m >= 3) { 6680 res_month = 3; 6681 } else { 6682 res_month = 0; 6683 } 6684 6685 date.setMonth(res_month); 6686 return date; 6687 }, 6688 year_start: function (date) { 6689 date.setMonth(0); 6690 return this.month_start(date); 6691 }, 6692 day_start: function (date) { 6693 return this.date_part(date); 6694 }, 6695 hour_start: function (date) { 6696 if (date.getMinutes()) 6697 date.setMinutes(0); 6698 this.minute_start(date); 6699 6700 return date; 6701 }, 6702 minute_start: function (date) { 6703 if (date.getSeconds()) 6704 date.setSeconds(0); 6705 if (date.getMilliseconds()) 6706 date.setMilliseconds(0); 6707 return date; 6708 }, 6709 _add_days: function (date, inc) { 6710 var ndate = new Date(date.valueOf()); 6711 6712 ndate.setDate(ndate.getDate() + inc); 6713 if (inc >= 0 && (!date.getHours() && ndate.getHours()) &&//shift to yesterday on dst 6714 (ndate.getDate() <= date.getDate() || ndate.getMonth() < date.getMonth() || ndate.getFullYear() < date.getFullYear())) 6715 ndate.setTime(ndate.getTime() + 60 * 60 * 1000 * (24 - ndate.getHours())); 6716 return ndate; 6717 }, 6718 6719 add: function (date, inc, mode) { 6720 /*jsl:ignore*/ 6721 var ndate = new Date(date.valueOf()); 6722 switch (mode) { 6723 case "day": 6724 ndate = this._add_days(ndate, inc); 6725 break; 6726 case "week": 6727 ndate = this._add_days(ndate, inc * 7); 6728 break; 6729 case "month": 6730 ndate.setMonth(ndate.getMonth() + inc); 6731 break; 6732 case "year": 6733 ndate.setYear(ndate.getFullYear() + inc); 6734 break; 6735 case "hour": 6736 /* 6737 adding hours/minutes via setHour(getHour() + inc) gives weird result when 6738 adding one hour to the time before switch to a Daylight Saving time 6739 6740 example: //Sun Mar 30 2014 01:00:00 GMT+0100 (W. Europe Standard Time) 6741 new Date(2014, 02, 30, 1).setHours(2) 6742 >>Sun Mar 30 2014 01:00:00 GMT+0100 (W. Europe Standard Time) 6743 6744 setTime seems working as expected 6745 */ 6746 ndate.setTime(ndate.getTime() + inc * 60 * 60 * 1000); 6747 break; 6748 case "minute": 6749 6750 ndate.setTime(ndate.getTime() + inc * 60 * 1000); 6751 6752 break; 6753 default: 6754 return this["add_" + mode](date, inc, mode); 6755 } 6756 return ndate; 6757 /*jsl:end*/ 6758 }, 6759 add_quarter: function (date, inc) { 6760 return this.add(date, inc * 3, "month"); 6761 }, 6762 6763 to_fixed: function (num) { 6764 if (num < 10) return "0" + num; 6765 return num; 6766 }, 6767 copy: function (date) { 6768 return new Date(date.valueOf()); 6769 }, 6770 date_to_str: function (format, utc) { 6771 format = format.replace(/%[a-zA-Z]/g, function (a) { 6772 switch (a) { 6773 case "%d": 6774 return "\"+to_fixed(date.getDate())+\""; 6775 case "%m": 6776 return "\"+to_fixed((date.getMonth()+1))+\""; 6777 case "%j": 6778 return "\"+date.getDate()+\""; 6779 case "%n": 6780 return "\"+(date.getMonth()+1)+\""; 6781 case "%y": 6782 return "\"+to_fixed(date.getFullYear()%100)+\""; 6783 case "%Y": 6784 return "\"+date.getFullYear()+\""; 6785 case "%D": 6786 return "\"+locale.date.day_short[date.getDay()]+\""; 6787 case "%l": 6788 return "\"+locale.date.day_full[date.getDay()]+\""; 6789 case "%M": 6790 return "\"+locale.date.month_short[date.getMonth()]+\""; 6791 case "%F": 6792 return "\"+locale.date.month_full[date.getMonth()]+\""; 6793 case "%h": 6794 return "\"+to_fixed((date.getHours()+11)%12+1)+\""; 6795 case "%g": 6796 return "\"+((date.getHours()+11)%12+1)+\""; 6797 case "%G": 6798 return "\"+date.getHours()+\""; 6799 case "%H": 6800 return "\"+to_fixed(date.getHours())+\""; 6801 case "%i": 6802 return "\"+to_fixed(date.getMinutes())+\""; 6803 case "%a": 6804 return "\"+(date.getHours()>11?\"pm\":\"am\")+\""; 6805 case "%A": 6806 return "\"+(date.getHours()>11?\"PM\":\"AM\")+\""; 6807 case "%s": 6808 return "\"+to_fixed(date.getSeconds())+\""; 6809 case "%W": 6810 return "\"+to_fixed(getISOWeek(date))+\""; 6811 case "%w": 6812 return "\"+to_fixed(getWeek(date))+\""; 6813 default: 6814 return a; 6815 } 6816 }); 6817 if (utc) format = format.replace(/date\.get/g, "date.getUTC"); 6818 var dateToStr = new Function("date", "to_fixed", "locale", "getISOWeek", "getWeek", "return \"" + format + "\";"); 6819 6820 return function (date) { 6821 return dateToStr(date, dateHelper.to_fixed, gantt.locale, dateHelper.getISOWeek, dateHelper.getWeek); 6822 }; 6823 }, 6824 str_to_date: function (format, utc) { 6825 var splt = "var temp=date.match(/[a-zA-Z]+|[0-9]+/g);"; 6826 var mask = format.match(/%[a-zA-Z]/g); 6827 for (var i = 0; i < mask.length; i++) { 6828 switch (mask[i]) { 6829 case "%j": 6830 case "%d": 6831 splt += "set[2]=temp[" + i + "]||1;"; 6832 break; 6833 case "%n": 6834 case "%m": 6835 splt += "set[1]=(temp[" + i + "]||1)-1;"; 6836 break; 6837 case "%y": 6838 splt += "set[0]=temp[" + i + "]*1+(temp[" + i + "]>50?1900:2000);"; 6839 break; 6840 case "%g": 6841 case "%G": 6842 case "%h": 6843 case "%H": 6844 splt += "set[3]=temp[" + i + "]||0;"; 6845 break; 6846 case "%i": 6847 splt += "set[4]=temp[" + i + "]||0;"; 6848 break; 6849 case "%Y": 6850 splt += "set[0]=temp[" + i + "]||0;"; 6851 break; 6852 case "%a": 6853 case "%A": 6854 splt += "set[3]=set[3]%12+((temp[" + i + "]||'').toLowerCase()=='am'?0:12);"; 6855 break; 6856 case "%s": 6857 splt += "set[5]=temp[" + i + "]||0;"; 6858 break; 6859 case "%M": 6860 splt += "set[1]=locale.date.month_short_hash[temp[" + i + "]]||0;"; 6861 break; 6862 case "%F": 6863 splt += "set[1]=locale.date.month_full_hash[temp[" + i + "]]||0;"; 6864 break; 6865 default: 6866 break; 6867 } 6868 } 6869 var code = "set[0],set[1],set[2],set[3],set[4],set[5]"; 6870 if (utc) code = " Date.UTC(" + code + ")"; 6871 var strToDate = new Function("date", "locale", "var set=[0,0,1,0,0,0]; " + splt + " return new Date(" + code + ");"); 6872 6873 return function (dateString) { 6874 return strToDate(dateString, gantt.locale); 6875 }; 6876 }, 6877 getISOWeek: function (ndate) { 6878 return gantt.date._getWeekNumber(ndate, true); 6879 }, 6880 _getWeekNumber: function(ndate, isoWeek){ 6881 if (!ndate) return false; 6882 var nday = ndate.getDay(); 6883 if(isoWeek){ 6884 if (nday === 0) { 6885 nday = 7; 6886 } 6887 } 6888 var first_thursday = new Date(ndate.valueOf()); 6889 first_thursday.setDate(ndate.getDate() + (4 - nday)); 6890 var year_number = first_thursday.getFullYear(); // year of the first Thursday 6891 var ordinal_date = Math.round((first_thursday.getTime() - new Date(year_number, 0, 1).getTime()) / 86400000); //ordinal date of the first Thursday - 1 (so not really ordinal date) 6892 var week_number = 1 + Math.floor(ordinal_date / 7); 6893 return week_number; 6894 }, 6895 6896 getWeek: function(ndate){ 6897 return gantt.date._getWeekNumber(ndate, gantt.config.start_on_monday); 6898 }, 6899 getUTCISOWeek: function (ndate) { 6900 return gantt.date.getISOWeek(ndate); 6901 }, 6902 convert_to_utc: function (date) { 6903 return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds()); 6904 }, 6905 parseDate: function (date, format) { 6906 // raw date may be of type string, number (timestamp) or something else 6907 // do not check for instanceof Date explicitly, since we may swap native date with different date implementation at some point 6908 if (date && !date.getFullYear) { 6909 if (typeof(format) !== "function") { 6910 if (typeof(format) === "string") { 6911 if (format === "parse_date") { 6912 format = gantt.templates.parse_date; 6913 if (gantt.defined(gantt.templates.xml_date) && gantt.templates.parse_date !== gantt.templates.xml_date) { 6914 format = gantt.templates.xml_date; 6915 } 6916 } else { 6917 format = gantt.defined(gantt.templates[format]) ? gantt.templates[format] : gantt.date.str_to_date(format); 6918 } 6919 } else { 6920 format = gantt.templates.xml_date !== gantt.templates.parse_date ? gantt.templates.xml_date : gantt.templates.parse_date; 6921 } 6922 } 6923 if (date) { 6924 date = format(date); 6925 } else { 6926 date = null; 6927 } 6928 } 6929 return date; 6930 } 6931 }; 6932 return dateHelper; 6933}; 6934 6935/***/ }), 6936 6937/***/ "./sources/core/common/dnd.js": 6938/*!************************************!*\ 6939 !*** ./sources/core/common/dnd.js ***! 6940 \************************************/ 6941/*! no static exports found */ 6942/***/ (function(module, exports, __webpack_require__) { 6943 6944var eventable = __webpack_require__(/*! ../../utils/eventable */ "./sources/utils/eventable.js"); 6945var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 6946var timeout = __webpack_require__(/*! ../../utils/timeout */ "./sources/utils/timeout.js"); 6947 6948module.exports = function(gantt){ 6949 6950 function copyDomEvent(e){ 6951 return { 6952 target: e.target || e.srcElement, 6953 pageX: e.pageX, 6954 pageY: e.pageY, 6955 clientX: e.clientX, 6956 clientY: e.clientY, 6957 metaKey: e.metaKey, 6958 shiftKey: e.shiftKey, 6959 ctrlKey: e.ctrlKey, 6960 altKey: e.altKey 6961 }; 6962 } 6963 6964 function DnD(obj, config) { 6965 this._obj = obj; 6966 this._settings = config || {}; 6967 eventable(this); 6968 6969 var inputMethods = this.getInputMethods(); 6970 6971 this._drag_start_timer = null; 6972 gantt.attachEvent("onGanttScroll", utils.bind(function (left, top) { 6973 this.clearDragTimer(); 6974 }, this)); 6975 6976 for(var i = 0; i < inputMethods.length; i++){ 6977 (utils.bind(function(input){ 6978 6979 gantt.event(obj, input.down, utils.bind(function (e) { 6980 if(!input.accessor(e)){ 6981 return; 6982 } 6983 6984 this._settings.original_target = copyDomEvent(e); 6985 6986 if (gantt.config.touch) { 6987 this.clearDragTimer(); 6988 6989 this._drag_start_timer = setTimeout(utils.bind(function () { 6990 this.dragStart(obj, e, input); 6991 }, this), gantt.config.touch_drag); 6992 } 6993 else { 6994 this.dragStart(obj, e, input); 6995 } 6996 }, this)); 6997 6998 gantt.event(document.body, input.up, utils.bind(function (e) { 6999 if(!input.accessor(e)){ 7000 return; 7001 } 7002 this.clearDragTimer(); 7003 }, this)); 7004 7005 }, this))(inputMethods[i]); 7006 } 7007 } 7008 7009 DnD.prototype = { 7010 traceDragEvents: function (domElement, inputMethod) { 7011 var mousemove = utils.bind(function (e) { 7012 return this.dragMove(domElement, e, inputMethod.accessor); 7013 }, this); 7014 utils.bind(function (e) { 7015 return this.dragScroll(domElement, e); 7016 }, this); 7017 7018 var limited_mousemove = utils.bind(function (e) { 7019 if (this.config.started && utils.defined(this.config.updates_per_second)) { 7020 if (!timeout(this, this.config.updates_per_second)) 7021 return; 7022 } 7023 7024 var dndActive = mousemove(e); 7025 7026 if (dndActive) { 7027 if (e && e.preventDefault) //Cancel default action on DND 7028 e.preventDefault(); 7029 e .cancelBubble = true; 7030 } 7031 7032 return dndActive; 7033 }, this); 7034 7035 var mouseup = utils.bind(function (e) { 7036 gantt.eventRemove(document.body, inputMethod.move, limited_mousemove); 7037 gantt.eventRemove(document.body, inputMethod.up, mouseup); 7038 return this.dragEnd(domElement); 7039 }, this); 7040 7041 gantt.event(document.body, inputMethod.move, limited_mousemove); 7042 gantt.event(document.body, inputMethod.up, mouseup); 7043 }, 7044 checkPositionChange: function (pos) { 7045 var diff_x = pos.x - this.config.pos.x; 7046 var diff_y = pos.y - this.config.pos.y; 7047 var distance = Math.sqrt(Math.pow(Math.abs(diff_x), 2) + Math.pow(Math.abs(diff_y), 2)); 7048 7049 if (distance > this.config.sensitivity) { 7050 return true; 7051 } else { 7052 return false; 7053 } 7054 }, 7055 initDnDMarker: function () { 7056 // create dnd placeholder and put it in dom 7057 var marker = this.config.marker = document.createElement("div"); 7058 marker.className = "gantt_drag_marker"; 7059 marker.innerHTML = "Dragging object"; 7060 document.body.appendChild(marker); 7061 }, 7062 backupEventTarget: function (domEvent, getEvent) { 7063 if (!gantt.config.touch) { 7064 return; 7065 } 7066 7067 // keep original event target in DOM in order to keep dnd on touchmove event 7068 var e = getEvent(domEvent); 7069 7070 var el = e.target || e.srcElement; 7071 var copy = el.cloneNode(true); 7072 //this.config.target.target = copy; 7073 this.config.original_target = copyDomEvent(e); 7074 this.config.original_target.target = copy; 7075 this.config.backup_element = el; 7076 el.parentNode.appendChild(copy); 7077 7078 el.style.display = "none"; 7079 document.body.appendChild(el); 7080 }, 7081 getInputMethods: function () { 7082 // bind actions to browser events 7083 var inputMethods = []; 7084 7085 inputMethods.push({ 7086 "move": "mousemove", 7087 "down": "mousedown", 7088 "up": "mouseup", 7089 "accessor": function (e) { 7090 return e; 7091 } 7092 }); 7093 7094 if (gantt.config.touch) { 7095 7096 var touchEventsSupported = true; 7097 try{ 7098 document.createEvent("TouchEvent"); 7099 }catch (e){ 7100 touchEventsSupported = false; 7101 } 7102 7103 if(touchEventsSupported){ 7104 inputMethods.push({ 7105 "move": "touchmove", 7106 "down": "touchstart", 7107 "up": "touchend", 7108 "accessor": function (ev) { 7109 if (ev.touches && ev.touches.length > 1) return null; 7110 if (ev.touches[0]) 7111 return { 7112 target: document.elementFromPoint(ev.touches[0].clientX, ev.touches[0].clientY), 7113 pageX: ev.touches[0].pageX, 7114 pageY: ev.touches[0].pageY, 7115 clientX: ev.touches[0].clientX, 7116 clientY: ev.touches[0].clientY 7117 }; 7118 else 7119 return ev; 7120 } 7121 }); 7122 }else if(window.navigator.pointerEnabled){ 7123 inputMethods.push({ 7124 "move": "pointermove", 7125 "down": "pointerdown", 7126 "up": "pointerup", 7127 "accessor": function (ev) { 7128 if (ev.pointerType == "mouse") return null; 7129 return ev; 7130 } 7131 }); 7132 7133 }else if (window.navigator.msPointerEnabled){ 7134 inputMethods.push({ 7135 "move": "MSPointerMove", 7136 "down": "MSPointerDown", 7137 "up": "MSPointerUp", 7138 "accessor": function (ev) { 7139 if (ev.pointerType == ev.MSPOINTER_TYPE_MOUSE) return null; 7140 return ev; 7141 } 7142 }); 7143 } 7144 } 7145 7146 return inputMethods; 7147 }, 7148 clearDragTimer: function () { 7149 if (this._drag_start_timer) { 7150 clearTimeout(this._drag_start_timer); 7151 this._drag_start_timer = null; 7152 } 7153 }, 7154 dragStart: function (obj, e, inputMethod) { 7155 if (this.config && this.config.started) { 7156 return; 7157 } 7158 this.config = { 7159 obj: obj, 7160 marker: null, 7161 started: false, 7162 pos: this.getPosition(e), 7163 sensitivity: 4 7164 }; 7165 if (this._settings) 7166 utils.mixin(this.config, this._settings, true); 7167 7168 7169 this.traceDragEvents(obj, inputMethod); 7170 7171 gantt._prevent_touch_scroll = true; 7172 document.body.className += " gantt_noselect"; 7173 7174 if (gantt.config.touch) { 7175 this.dragMove(obj, e, inputMethod.accessor); 7176 } 7177 7178 }, 7179 dragMove: function (obj, e, getEvent) { 7180 var source = getEvent(e); 7181 if (!source) return false; 7182 7183 if (!this.config.marker && !this.config.started) { 7184 var pos = this.getPosition(source); 7185 7186 if (gantt.config.touch || this.checkPositionChange(pos)) { 7187 // real drag starts here, 7188 // when user moves mouse at first time after onmousedown 7189 this.config.started = true; 7190 this.config.ignore = false; 7191 if (this.callEvent("onBeforeDragStart", [obj, this.config.original_target]) === false) { 7192 this.config.ignore = true; 7193 return false; 7194 } 7195 this.backupEventTarget(e, getEvent); 7196 this.initDnDMarker(); 7197 gantt._touch_feedback(); 7198 this.callEvent("onAfterDragStart", [obj, this.config.original_target]); 7199 } else { 7200 this.config.ignore = true; 7201 } 7202 } 7203 7204 if (!this.config.ignore) { 7205 source.pos = this.getPosition(source); 7206 this.config.marker.style.left = source.pos.x + "px"; 7207 this.config.marker.style.top = source.pos.y + "px"; 7208 this.callEvent("onDragMove", [obj, source]); 7209 return true; 7210 } 7211 return false; 7212 }, 7213 7214 dragEnd: function (obj) { 7215 var target = this.config.backup_element; 7216 if (target && target.parentNode) { 7217 target.parentNode.removeChild(target); 7218 } 7219 gantt._prevent_touch_scroll = false; 7220 if (this.config.marker) { 7221 this.config.marker.parentNode.removeChild(this.config.marker); 7222 this.config.marker = null; 7223 7224 this.callEvent("onDragEnd", []); 7225 } 7226 this.config.started = false; 7227 document.body.className = document.body.className.replace(" gantt_noselect", ""); 7228 }, 7229 7230 getPosition: function (e) { 7231 var x = 0, y = 0; 7232 e = e || window.event; 7233 if (e.pageX || e.pageY) { 7234 x = e.pageX; 7235 y = e.pageY; 7236 } else if (e.clientX || e.clientY) { 7237 x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; 7238 y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; 7239 } 7240 return {x: x, y: y}; 7241 } 7242 }; 7243 7244 return DnD; 7245}; 7246 7247 7248/***/ }), 7249 7250/***/ "./sources/core/common/duration_formatter_numeric.ts": 7251/*!***********************************************************!*\ 7252 !*** ./sources/core/common/duration_formatter_numeric.ts ***! 7253 \***********************************************************/ 7254/*! no static exports found */ 7255/***/ (function(module, exports, __webpack_require__) { 7256 7257"use strict"; 7258 7259Object.defineProperty(exports, "__esModule", { value: true }); 7260var DurationFormatterNumeric = /** @class */ (function () { 7261 function DurationFormatterNumeric() { 7262 var _this = this; 7263 this.canParse = function (value) { 7264 return !isNaN(_this.parse(value)); 7265 }; 7266 this.format = function (value) { 7267 return String(value); 7268 }; 7269 this.parse = function (value) { 7270 return parseInt(value, 10); 7271 }; 7272 } 7273 DurationFormatterNumeric.create = function (settings) { 7274 if (settings === void 0) { settings = null; } 7275 return new DurationFormatterNumeric(); 7276 }; 7277 return DurationFormatterNumeric; 7278}()); 7279exports.default = DurationFormatterNumeric; 7280 7281 7282/***/ }), 7283 7284/***/ "./sources/core/common/import.js": 7285/*!***************************************!*\ 7286 !*** ./sources/core/common/import.js ***! 7287 \***************************************/ 7288/*! no static exports found */ 7289/***/ (function(module, exports) { 7290 7291module.exports = function(gantt){ 7292 gantt.$inject = function(module){ 7293 return module(this.$services); 7294 }; 7295}; 7296 7297/***/ }), 7298 7299/***/ "./sources/core/common/link_formatter_simple.ts": 7300/*!******************************************************!*\ 7301 !*** ./sources/core/common/link_formatter_simple.ts ***! 7302 \******************************************************/ 7303/*! no static exports found */ 7304/***/ (function(module, exports, __webpack_require__) { 7305 7306"use strict"; 7307 7308Object.defineProperty(exports, "__esModule", { value: true }); 7309var LinkFormatterSimple = /** @class */ (function () { 7310 function LinkFormatterSimple(gantt) { 7311 var _this = this; 7312 this.format = function (link) { 7313 var wbs = _this._getWBSCode(link.source); 7314 return wbs; 7315 }; 7316 this.canParse = function (value) { 7317 return _this._linkReg.test(value); 7318 }; 7319 this.parse = function (value) { 7320 if (!_this.canParse(value)) { 7321 return null; 7322 } 7323 var linkPart = _this._linkReg.exec(value)[0].trim(); 7324 var source = _this._findSource(linkPart) || null; 7325 return { 7326 id: undefined, 7327 source: source, 7328 target: null, 7329 type: _this._gantt.config.links.finish_to_start, 7330 lag: 0 7331 }; 7332 }; 7333 this._getWBSCode = function (source) { 7334 var pred = _this._gantt.getTask(source); 7335 return _this._gantt.getWBSCode(pred); 7336 }; 7337 this._findSource = function (value) { 7338 var reqTemplate = new RegExp("^[0-9\.]+", "i"); 7339 if (reqTemplate.exec(value)) { 7340 var wbs = reqTemplate.exec(value)[0]; 7341 var task = _this._gantt.getTaskByWBSCode(wbs); 7342 if (task) { 7343 return task.id; 7344 } 7345 } 7346 return null; 7347 }; 7348 this._linkReg = /^[0-9\.]+/; 7349 this._gantt = gantt; 7350 } 7351 LinkFormatterSimple.create = function (settings, gantt) { 7352 if (settings === void 0) { settings = null; } 7353 return new LinkFormatterSimple(gantt); 7354 }; 7355 return LinkFormatterSimple; 7356}()); 7357exports.default = LinkFormatterSimple; 7358 7359 7360/***/ }), 7361 7362/***/ "./sources/core/common/serialize.ts": 7363/*!******************************************!*\ 7364 !*** ./sources/core/common/serialize.ts ***! 7365 \******************************************/ 7366/*! no static exports found */ 7367/***/ (function(module, exports, __webpack_require__) { 7368 7369"use strict"; 7370 7371Object.defineProperty(exports, "__esModule", { value: true }); 7372function serialize(data) { 7373 if (typeof data === "string" || typeof data === "number") { 7374 return data; 7375 } 7376 var result = ""; 7377 for (var key in data) { 7378 var serialized = ""; 7379 if (data.hasOwnProperty(key)) { 7380 if (typeof data[key] === "string") { 7381 serialized = encodeURIComponent(data[key]); 7382 } 7383 else if (typeof data[key] === "number") { 7384 serialized = data[key]; 7385 } 7386 else { 7387 serialized = encodeURIComponent(JSON.stringify(data[key])); 7388 } 7389 serialized = key + "=" + serialized; 7390 if (result.length) { 7391 serialized = "&" + serialized; 7392 } 7393 result += serialized; 7394 } 7395 } 7396 return result; 7397} 7398exports.default = serialize; 7399 7400 7401/***/ }), 7402 7403/***/ "./sources/core/common/services.js": 7404/*!*****************************************!*\ 7405 !*** ./sources/core/common/services.js ***! 7406 \*****************************************/ 7407/*! no static exports found */ 7408/***/ (function(module, exports) { 7409 7410module.exports = function(){ 7411 var services = {}; 7412 function register (name, getter){ 7413 services[name] = getter; 7414 } 7415 7416 function getService(name){ 7417 if(!services[name]){ 7418 return null; 7419 } 7420 return services[name](); 7421 } 7422 7423 function dropService(name) { 7424 if (services[name]) { 7425 delete services[name]; 7426 } 7427 } 7428 7429 var servicesEnum = { 7430 "config": "config", 7431 "templates": "templates", 7432 "locale": "locale" 7433 }; 7434 7435 return { 7436 services: servicesEnum, 7437 setService: register, 7438 getService: getService, 7439 dropService: dropService, 7440 config: function(){ 7441 return this.getService("config"); 7442 }, 7443 templates: function(){ 7444 return this.getService("templates"); 7445 }, 7446 locale: function(){ 7447 return this.getService("locale"); 7448 }, 7449 destructor: function(){ 7450 for(var i in services){ 7451 if(services[i]){ 7452 var service = services[i]; 7453 if(service && service.destructor){ 7454 service.destructor(); 7455 } 7456 } 7457 } 7458 services = null; 7459 } 7460 }; 7461}; 7462 7463 7464/***/ }), 7465 7466/***/ "./sources/core/common/state.js": 7467/*!**************************************!*\ 7468 !*** ./sources/core/common/state.js ***! 7469 \**************************************/ 7470/*! no static exports found */ 7471/***/ (function(module, exports, __webpack_require__) { 7472 7473var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 7474 7475var StateService = (function(){ 7476 var stateProviders = {}; 7477 7478 function getState(name){ 7479 if(name){ 7480 return stateProviders[name].method(); 7481 }else{ 7482 var res = {}; 7483 for(var i in stateProviders){ 7484 if(!stateProviders[i].internal) 7485 utils.mixin(res, stateProviders[i].method(), true); 7486 } 7487 return res; 7488 } 7489 } 7490 7491 function registerProvider(name, provider, internal){ 7492 stateProviders[name] = { method: provider, internal: internal}; 7493 } 7494 7495 function unregisterProvider(name){ 7496 delete stateProviders[name]; 7497 } 7498 7499 return { 7500 getState: getState, 7501 registerProvider: registerProvider, 7502 unregisterProvider: unregisterProvider 7503 }; 7504}); 7505 7506module.exports = StateService; 7507 7508 7509 7510/***/ }), 7511 7512/***/ "./sources/core/common/templates.js": 7513/*!******************************************!*\ 7514 !*** ./sources/core/common/templates.js ***! 7515 \******************************************/ 7516/*! no static exports found */ 7517/***/ (function(module, exports) { 7518 7519module.exports = function(gantt) { 7520 7521 var regTemplates = {}; 7522 7523 function initTemplate(name, initial, template_name) { 7524 template_name = template_name || name; 7525 var config = gantt.config, 7526 templates = gantt.templates; 7527 7528 if (gantt.config[name] && regTemplates[template_name] != config[name]) { 7529 if (!(initial && templates[template_name])) { 7530 templates[template_name] = gantt.date.date_to_str(config[name]); 7531 regTemplates[template_name] = config[name]; 7532 } 7533 } 7534 } 7535 7536 function initTemplates() { 7537 var labels = gantt.locale.labels; 7538 labels.gantt_save_btn = labels.icon_save; 7539 labels.gantt_cancel_btn = labels.icon_cancel; 7540 labels.gantt_delete_btn = labels.icon_delete; 7541 7542 7543 var date = gantt.date; 7544 7545 //build configuration based templates 7546 var d = date.date_to_str; 7547 var c = gantt.config; 7548 var format_date = d(c.xml_date || c.date_format, c.server_utc); 7549 var parse_date = date.str_to_date(c.xml_date || c.date_format, c.server_utc); 7550 7551 initTemplate("date_scale", true, undefined, gantt.config, gantt.templates); 7552 initTemplate("date_grid", true, "grid_date_format", gantt.config, gantt.templates); 7553 initTemplate("task_date", true, undefined, gantt.config, gantt.templates); 7554 7555 gantt.mixin(gantt.templates, { 7556 xml_format: format_date, // deprecated 7557 format_date: format_date, 7558 7559 xml_date: parse_date, // deprecated 7560 parse_date: parse_date, 7561 7562 progress_text: function (start, end, task) { 7563 return ""; 7564 }, 7565 grid_header_class: function (column, config) { 7566 return ""; 7567 }, 7568 7569 task_text: function (start, end, task) { 7570 return task.text; 7571 }, 7572 task_class: function (start, end, task) { 7573 return ""; 7574 }, 7575 task_end_date: function (date) { 7576 return gantt.templates.task_date(date); 7577 }, 7578 grid_row_class: function (start, end, task) { 7579 return ""; 7580 }, 7581 task_row_class: function (start, end, task) { 7582 return ""; 7583 }, 7584 timeline_cell_class: function (item, date) { 7585 return ""; 7586 }, 7587 scale_cell_class: function (date) { 7588 return ""; 7589 }, 7590 scale_row_class: function (date) { 7591 return ""; 7592 }, 7593 7594 grid_indent: function (item) { 7595 return "<div class='gantt_tree_indent'></div>"; 7596 }, 7597 grid_folder: function (item) { 7598 return "<div class='gantt_tree_icon gantt_folder_" + (item.$open ? "open" : "closed") + "'></div>"; 7599 }, 7600 grid_file: function (item) { 7601 return "<div class='gantt_tree_icon gantt_file'></div>"; 7602 }, 7603 grid_open: function (item) { 7604 return "<div class='gantt_tree_icon gantt_" + (item.$open ? "close" : "open") + "'></div>"; 7605 }, 7606 grid_blank: function (item) { 7607 return "<div class='gantt_tree_icon gantt_blank'></div>"; 7608 }, 7609 date_grid: function (date, item, column) { 7610 if (item && gantt.isUnscheduledTask(item) && gantt.config.show_unscheduled) { 7611 return gantt.templates.task_unscheduled_time(item); 7612 } else { 7613 return gantt.templates.grid_date_format(date, column); 7614 } 7615 }, 7616 7617 task_time: function (start, end, ev) { 7618 if (gantt.isUnscheduledTask(ev) && gantt.config.show_unscheduled) { 7619 return gantt.templates.task_unscheduled_time(ev); 7620 } else { 7621 return gantt.templates.task_date(start) + " - " + gantt.templates.task_end_date(end); 7622 } 7623 }, 7624 7625 task_unscheduled_time: function (task) { 7626 return ""; 7627 }, 7628 7629 time_picker: d(c.time_picker), 7630 link_class: function (link) { 7631 return ""; 7632 }, 7633 link_description: function (link) { 7634 var from = gantt.getTask(link.source), 7635 to = gantt.getTask(link.target); 7636 7637 return "<b>" + from.text + "</b> – <b>" + to.text + "</b>"; 7638 }, 7639 7640 drag_link: function (from, from_start, to, to_start) { 7641 from = gantt.getTask(from); 7642 var labels = gantt.locale.labels; 7643 7644 var text = "<b>" + from.text + "</b> " + (from_start ? labels.link_start : labels.link_end) + "<br/>"; 7645 if (to) { 7646 to = gantt.getTask(to); 7647 text += "<b> " + to.text + "</b> " + (to_start ? labels.link_start : labels.link_end) + "<br/>"; 7648 } 7649 return text; 7650 }, 7651 drag_link_class: function (from, from_start, to, to_start) { 7652 var add = ""; 7653 7654 if (from && to) { 7655 var allowed = gantt.isLinkAllowed(from, to, from_start, to_start); 7656 add = " " + (allowed ? "gantt_link_allow" : "gantt_link_deny"); 7657 } 7658 7659 return "gantt_link_tooltip" + add; 7660 }, 7661 7662 /* used for aria-labels of bar elements and for tooltip.js */ 7663 tooltip_date_format: date.date_to_str("%Y-%m-%d"), 7664 tooltip_text: function (start, end, event) { 7665 return "<b>Task:</b> " + event.text + "<br/><b>Start date:</b> " + gantt.templates.tooltip_date_format(start) + "<br/><b>End date:</b> " + gantt.templates.tooltip_date_format(end); 7666 } 7667 }); 7668 } 7669 7670 return { 7671 initTemplates: initTemplates, 7672 initTemplate: initTemplate 7673 }; 7674 7675}; 7676 7677/***/ }), 7678 7679/***/ "./sources/core/data.js": 7680/*!******************************!*\ 7681 !*** ./sources/core/data.js ***! 7682 \******************************/ 7683/*! no static exports found */ 7684/***/ (function(module, exports, __webpack_require__) { 7685 7686var helpers = __webpack_require__(/*! ../utils/helpers */ "./sources/utils/helpers.js"); 7687 7688module.exports = function(gantt) { 7689 7690 gantt.isUnscheduledTask = function (task) { 7691 gantt.assert(task && task instanceof Object, "Invalid argument <b>task</b>="+task+" of gantt.isUnscheduledTask. Task object was expected"); 7692 return (!!task.unscheduled || !task.start_date); 7693 }; 7694 7695 gantt._isAllowedUnscheduledTask = function (task) { 7696 return !!(task.unscheduled && gantt.config.show_unscheduled); 7697 }; 7698 7699 gantt._isTaskInTimelineLimits = function(task) { 7700 var taskStart = task.start_date ? task.start_date.valueOf() : null; 7701 var taskEnd = task.end_date ? task.end_date.valueOf() : null; 7702 return !!(taskStart && taskEnd && taskStart <= this._max_date.valueOf() && taskEnd >= this._min_date.valueOf()); 7703 }; 7704 gantt.isTaskVisible = function (id) { 7705 if (!this.isTaskExists(id)) { 7706 return false; 7707 } 7708 7709 var task = this.getTask(id); 7710 if (!(this._isAllowedUnscheduledTask(task) || this._isTaskInTimelineLimits(task))) { 7711 return false; 7712 } 7713 7714 return !!(this.getGlobalTaskIndex(id) >= 0); 7715 }; 7716 7717 gantt._getProjectEnd = function() { 7718 if(gantt.config.project_end){ 7719 return gantt.config.project_end; 7720 }else{ 7721 var tasks = gantt.getTaskByTime(); 7722 tasks = tasks.sort(function (a, b) { 7723 return +a.end_date > +b.end_date ? 1 : -1; 7724 }); 7725 return tasks.length ? tasks[tasks.length - 1].end_date : null; 7726 } 7727 }; 7728 gantt._getProjectStart = function() { 7729 if (gantt.config.project_start) { 7730 return gantt.config.project_start; 7731 } 7732 7733 // use timeline start if project start is not specified 7734 if (gantt.config.start_date) { 7735 return gantt.config.start_date; 7736 } 7737 if (gantt.getState().min_date) { 7738 return gantt.getState().min_date; 7739 } 7740 7741 // earliest task start if neither project start nor timeline are specified 7742 var tasks = gantt.getTaskByTime(); 7743 tasks = tasks.sort(function (a, b) { 7744 return +a.start_date > +b.start_date ? 1 : -1; 7745 }); 7746 return tasks.length ? tasks[0].start_date : null; 7747 }; 7748 7749 gantt._defaultTaskDate = function (item, parent_id) { 7750 var parent = (parent_id && parent_id != gantt.config.root_id) ? gantt.getTask(parent_id) : false, 7751 startDate = null; 7752 if (parent) { 7753 if(gantt.config.schedule_from_end){ 7754 startDate = gantt.calculateEndDate({ 7755 start_date: parent.end_date, 7756 duration: - gantt.config.duration_step, 7757 task:item 7758 }); 7759 }else{ 7760 startDate = parent.start_date; 7761 } 7762 7763 } else if(gantt.config.schedule_from_end) { 7764 startDate = gantt.calculateEndDate({ 7765 start_date: gantt._getProjectEnd(), 7766 duration: - gantt.config.duration_step, 7767 task:item 7768 }); 7769 } else { 7770 var first = gantt.getTaskByIndex(0); 7771 startDate = first ? (first.start_date ? first.start_date : (first.end_date ? gantt.calculateEndDate({ 7772 start_date: first.end_date, 7773 duration: -gantt.config.duration_step, 7774 task:item 7775 }) : null)) : gantt.config.start_date || gantt.getState().min_date; 7776 } 7777 gantt.assert(startDate, "Invalid dates"); 7778 return new Date(startDate); 7779 }; 7780 7781 gantt._set_default_task_timing = function (task) { 7782 task.start_date = task.start_date || gantt._defaultTaskDate(task, gantt.getParent(task)); 7783 task.duration = task.duration || gantt.config.duration_step; 7784 task.end_date = task.end_date || gantt.calculateEndDate(task); 7785 }; 7786 7787 gantt.createTask = function (item, parent, index) { 7788 item = item || {}; 7789 7790 if (!gantt.defined(item.id)) 7791 item.id = gantt.uid(); 7792 7793 if (!item.start_date) { 7794 item.start_date = gantt._defaultTaskDate(item, parent); 7795 } 7796 if (item.text === undefined) { 7797 item.text = gantt.locale.labels.new_task; 7798 } 7799 if (item.duration === undefined) { 7800 item.duration = 1; 7801 } 7802 7803 if (this.isTaskExists(parent)) { 7804 this.setParent(item, parent, true); 7805 var parentObj = this.getTask(parent); 7806 parentObj.$open = true; 7807 } 7808 7809 if (!this.callEvent("onTaskCreated", [item])) { 7810 return null; 7811 } 7812 if (this.config.details_on_create) { 7813 item.$new = true; 7814 this.silent(function(){ 7815 gantt.$data.tasksStore.addItem(item, index); 7816 }); 7817 this.selectTask(item.id); 7818 this.refreshData(); 7819 this.showLightbox(item.id); 7820 } else { 7821 if (this.addTask(item, parent, index)) { 7822 this.showTask(item.id); 7823 this.selectTask(item.id); 7824 } 7825 } 7826 return item.id; 7827 }; 7828 7829 gantt._update_flags = function (oldid, newid) { 7830 // TODO: need a proper way to update all possible flags 7831 var store = gantt.$data.tasksStore; 7832 if (oldid === undefined) { 7833 this._lightbox_id = null; 7834 7835 store.silent(function(){ 7836 store.unselect(); 7837 }); 7838 7839 if (this._tasks_dnd && this._tasks_dnd.drag) { 7840 this._tasks_dnd.drag.id = null; 7841 } 7842 } else { 7843 if (this._lightbox_id == oldid) 7844 this._lightbox_id = newid; 7845 7846 // TODO: probably can be removed 7847 if (store.getSelectedId() == oldid) { 7848 store.silent(function(){ 7849 store.unselect(oldid); 7850 store.select(newid); 7851 }); 7852 } 7853 if (this._tasks_dnd && this._tasks_dnd.drag && this._tasks_dnd.drag.id == oldid) { 7854 this._tasks_dnd.drag.id = newid; 7855 } 7856 } 7857 }; 7858 7859 gantt._get_task_timing_mode = function (task, force) { 7860 var task_type = this.getTaskType(task.type); 7861 7862 var state = { 7863 type: task_type, 7864 $no_start: false, 7865 $no_end: false 7866 }; 7867 7868 if (!force && task_type == task.$rendered_type) { 7869 state.$no_start = task.$no_start; 7870 state.$no_end = task.$no_end; 7871 return state; 7872 } 7873 7874 if (task_type == this.config.types.project) { 7875 //project duration is always defined by children duration 7876 state.$no_end = state.$no_start = true; 7877 } else if (task_type != this.config.types.milestone) { 7878 //tasks can have fixed duration, children duration(as projects), or one date fixed, and other defined by nested items 7879 state.$no_end = !(task.end_date || task.duration); 7880 state.$no_start = !task.start_date; 7881 7882 if (this._isAllowedUnscheduledTask(task)) { 7883 state.$no_end = state.$no_start = false; 7884 } 7885 } 7886 7887 return state; 7888 }; 7889 7890 gantt._init_task_timing = function (task) { 7891 var task_mode = gantt._get_task_timing_mode(task, true); 7892 7893 var dirty = task.$rendered_type != task_mode.type; 7894 7895 var task_type = task_mode.type; 7896 7897 if (dirty) { 7898 task.$no_start = task_mode.$no_start; 7899 task.$no_end = task_mode.$no_end; 7900 task.$rendered_type = task_mode.type; 7901 } 7902 7903 if (dirty && task_type != this.config.types.milestone) { 7904 if (task_type == this.config.types.project) { 7905 //project duration is always defined by children duration 7906 this._set_default_task_timing(task); 7907 } 7908 } 7909 7910 if (task_type == this.config.types.milestone) { 7911 task.end_date = task.start_date; 7912 } 7913 if (task.start_date && task.end_date) { 7914 task.duration = this.calculateDuration(task); 7915 } 7916 7917 if (!task.end_date) { 7918 task.end_date = task.start_date; 7919 } 7920 7921 task.duration = task.duration || 0; 7922 }; 7923 7924 gantt.isSummaryTask = function (task) { 7925 gantt.assert(task && task instanceof Object, "Invalid argument <b>task</b>="+task+" of gantt.isSummaryTask. Task object was expected"); 7926 7927 var mode = gantt._get_task_timing_mode(task); 7928 7929 return !!(mode.$no_end || mode.$no_start); 7930 }; 7931 7932// downward calculation of project duration 7933 gantt.resetProjectDates = function (task) { 7934 var taskMode = this._get_task_timing_mode(task); 7935 if (taskMode.$no_end || taskMode.$no_start) { 7936 var dates = this.getSubtaskDates(task.id); 7937 this._assign_project_dates(task, dates.start_date, dates.end_date); 7938 } 7939 }; 7940 7941 gantt.getSubtaskDuration = function (task_id) { 7942 var res = 0, 7943 root = task_id !== undefined ? task_id : gantt.config.root_id; 7944 7945 this.eachTask(function (child) { 7946 if (this.getTaskType(child.type) == gantt.config.types.project || this.isUnscheduledTask(child)) 7947 return; 7948 7949 res += child.duration; 7950 }, root); 7951 7952 return res; 7953 }; 7954 7955 gantt.getSubtaskDates = function (task_id) { 7956 var min = null, 7957 max = null, 7958 root = task_id !== undefined ? task_id : gantt.config.root_id; 7959 7960 this.eachTask(function (child) { 7961 if (this.getTaskType(child.type) == gantt.config.types.project || this.isUnscheduledTask(child)) 7962 return; 7963 7964 if ((child.start_date && !child.$no_start) && (!min || min > child.start_date.valueOf())) 7965 min = child.start_date.valueOf(); 7966 if ((child.end_date && !child.$no_end) && (!max || max < child.end_date.valueOf())) 7967 max = child.end_date.valueOf(); 7968 }, root); 7969 7970 return { 7971 start_date: min ? new Date(min) : null, 7972 end_date: max ? new Date(max) : null 7973 }; 7974 }; 7975 7976 gantt._assign_project_dates = function (task, from, to) { 7977 var taskTiming = this._get_task_timing_mode(task); 7978 if (taskTiming.$no_start) { 7979 if (from && from != Infinity) { 7980 task.start_date = new Date(from); 7981 } else { 7982 task.start_date = this._defaultTaskDate(task, this.getParent(task)); 7983 } 7984 } 7985 7986 if (taskTiming.$no_end) { 7987 if (to && to != -Infinity) { 7988 task.end_date = new Date(to); 7989 } else { 7990 task.end_date = this.calculateEndDate({ 7991 start_date: task.start_date, 7992 duration: this.config.duration_step, 7993 task: task 7994 }); 7995 } 7996 } 7997 if (taskTiming.$no_start || taskTiming.$no_end) { 7998 this._init_task_timing(task); 7999 } 8000 }; 8001 8002// upward calculation of project duration 8003 gantt._update_parents = function (taskId, silent) { 8004 if (!taskId) return; 8005 8006 var task = this.getTask(taskId); 8007 var pid = this.getParent(task); 8008 8009 var taskTiming = this._get_task_timing_mode(task); 8010 8011 var has_changed = true; 8012 8013 if (taskTiming.$no_start || taskTiming.$no_end) { 8014 var oldStart = task.start_date.valueOf(), 8015 oldEnd = task.end_date.valueOf(); 8016 8017 gantt.resetProjectDates(task); 8018 8019 // not refresh parent projects if dates hasn't changed 8020 if (oldStart == task.start_date.valueOf() && oldEnd == task.end_date.valueOf()) { 8021 has_changed = false; 8022 } 8023 8024 if (has_changed && !silent) { 8025 this.refreshTask(task.id, true); 8026 } 8027 } 8028 8029 8030 if (has_changed && pid && this.isTaskExists(pid)) { 8031 this._update_parents(pid, silent); 8032 } 8033 }; 8034 8035 gantt.roundDate = function (config) { 8036 var scale = gantt.getScale(); 8037 8038 if (helpers.isDate(config)) { 8039 config = { 8040 date: config, 8041 unit: scale ? scale.unit : gantt.config.duration_unit, 8042 step: scale ? scale.step : gantt.config.duration_step 8043 }; 8044 } 8045 var date = config.date, 8046 steps = config.step, 8047 unit = config.unit; 8048 8049 if(!scale){ 8050 return date; 8051 } 8052 8053 var upper, lower, colIndex; 8054 if (unit == scale.unit && steps == scale.step && 8055 +date >= +scale.min_date && +date <= +scale.max_date) { 8056 //find date in time scale config 8057 colIndex = Math.floor(gantt.columnIndexByDate(date)); 8058 8059 if (!scale.trace_x[colIndex]) { 8060 colIndex -= 1;// end of time scale 8061 if(scale.rtl){ 8062 colIndex = 0; 8063 } 8064 } 8065 lower = new Date(scale.trace_x[colIndex]); 8066 upper = gantt.date.add(lower, steps, unit); 8067 } else { 8068 colIndex = Math.floor(gantt.columnIndexByDate(date)); 8069 8070 upper = gantt.date[unit + "_start"](new Date(scale.min_date)); 8071 if (scale.trace_x[colIndex]) { 8072 upper = gantt.date[unit + "_start"](scale.trace_x[colIndex]);// end of time scale 8073 } 8074 8075 while (+upper < +date) { 8076 upper = gantt.date[unit + "_start"](gantt.date.add(upper, steps, unit)); 8077 8078 var tzOffset = upper.getTimezoneOffset(); 8079 8080 upper = gantt._correct_dst_change(upper, tzOffset, upper, unit); 8081 if (gantt.date[unit + '_start']) 8082 upper = gantt.date[unit + '_start'](upper); 8083 } 8084 8085 lower = gantt.date.add(upper, -1 * steps, unit); 8086 8087 } 8088 if (config.dir && config.dir == 'future') 8089 return upper; 8090 if (config.dir && config.dir == 'past') 8091 return lower; 8092 8093 if (Math.abs(date - lower) < Math.abs(upper - date)) { 8094 return lower; 8095 } else { 8096 return upper; 8097 } 8098 8099 }; 8100 8101 gantt.correctTaskWorkTime = function (task) { 8102 if (gantt.config.work_time && gantt.config.correct_work_time) { 8103 if (!this.isWorkTime(task.start_date, undefined, task)) { 8104 task.start_date = this.getClosestWorkTime({date: task.start_date, dir: 'future', task: task}); 8105 task.end_date = this.calculateEndDate(task); 8106 } else if (!this.isWorkTime(new Date(+task.end_date - 1), undefined, task)) { 8107 task.end_date = this.calculateEndDate(task); 8108 } 8109 } 8110 }; 8111 8112 gantt.attachEvent("onBeforeTaskUpdate", function (id, task) { 8113 gantt._init_task_timing(task); 8114 return true; 8115 }); 8116 gantt.attachEvent("onBeforeTaskAdd", function (id, task) { 8117 gantt._init_task_timing(task); 8118 return true; 8119 }); 8120 8121}; 8122 8123/***/ }), 8124 8125/***/ "./sources/core/data_task_layers.gpl.js": 8126/*!**********************************************!*\ 8127 !*** ./sources/core/data_task_layers.gpl.js ***! 8128 \**********************************************/ 8129/*! no static exports found */ 8130/***/ (function(module, exports) { 8131 8132module.exports = function(gantt) { 8133 delete gantt.addTaskLayer; 8134 delete gantt.addLinkLayer; 8135}; 8136 8137/***/ }), 8138 8139/***/ "./sources/core/data_task_types.gpl.js": 8140/*!*********************************************!*\ 8141 !*** ./sources/core/data_task_types.gpl.js ***! 8142 \*********************************************/ 8143/*! no static exports found */ 8144/***/ (function(module, exports) { 8145 8146module.exports = function(gantt) { 8147 8148 gantt.getTaskType = function (type) { 8149 return "task"; 8150 }; 8151}; 8152 8153/***/ }), 8154 8155/***/ "./sources/core/dataprocessor/data_processor.ts": 8156/*!******************************************************!*\ 8157 !*** ./sources/core/dataprocessor/data_processor.ts ***! 8158 \******************************************************/ 8159/*! no static exports found */ 8160/***/ (function(module, exports, __webpack_require__) { 8161 8162"use strict"; 8163 8164Object.defineProperty(exports, "__esModule", { value: true }); 8165var eventable = __webpack_require__(/*! ../../utils/eventable */ "./sources/utils/eventable.js"); 8166var helpers = __webpack_require__(/*! ../../utils/helpers */ "./sources/utils/helpers.js"); 8167var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 8168var data_processor_events_1 = __webpack_require__(/*! ./data_processor_events */ "./sources/core/dataprocessor/data_processor_events.ts"); 8169var extend_gantt_1 = __webpack_require__(/*! ./extend_gantt */ "./sources/core/dataprocessor/extend_gantt.ts"); 8170var simple_storage_1 = __webpack_require__(/*! ./simple_storage */ "./sources/core/dataprocessor/simple_storage.ts"); 8171function createDataProcessor(config) { 8172 var router; 8173 var tMode; 8174 if (config instanceof Function) { 8175 router = config; 8176 } 8177 else if (config.hasOwnProperty("router")) { 8178 router = config.router; 8179 } 8180 else if (config.hasOwnProperty("link") && config.hasOwnProperty("task")) { 8181 router = config; 8182 } 8183 if (router) { 8184 tMode = "CUSTOM"; 8185 } 8186 else { 8187 tMode = config.mode || "REST-JSON"; 8188 } 8189 var gantt = this; // tslint:disable-line 8190 var dp = new DataProcessor(config.url); 8191 dp.init(gantt); 8192 dp.setTransactionMode({ 8193 mode: tMode, 8194 router: router 8195 }, config.batchUpdate); 8196 return dp; 8197} 8198exports.createDataProcessor = createDataProcessor; 8199var DataProcessor = /** @class */ (function () { 8200 function DataProcessor(serverProcessorURL) { 8201 this.serverProcessor = serverProcessorURL; 8202 this.action_param = "!nativeeditor_status"; 8203 this.object = null; 8204 this.updatedRows = []; // ids of updated rows 8205 this.autoUpdate = true; 8206 this.updateMode = "cell"; 8207 this._headers = null; 8208 this._payload = null; 8209 this._postDelim = "_"; 8210 this._waitMode = 0; 8211 this._in_progress = {}; // ? 8212 this._storage = simple_storage_1.default.create(); 8213 this._invalid = {}; 8214 this.messages = []; 8215 this.styles = { 8216 updated: "font-weight:bold;", 8217 inserted: "font-weight:bold;", 8218 deleted: "text-decoration : line-through;", 8219 invalid: "background-color:FFE0E0;", 8220 invalid_cell: "border-bottom:2px solid red;", 8221 error: "color:red;", 8222 clear: "font-weight:normal;text-decoration:none;" 8223 }; 8224 this.enableUTFencoding(true); 8225 eventable(this); 8226 } 8227 DataProcessor.prototype.setTransactionMode = function (mode, total) { 8228 if (typeof mode === "object") { 8229 this._tMode = mode.mode || this._tMode; 8230 if (utils.defined(mode.headers)) { 8231 this._headers = mode.headers; 8232 } 8233 if (utils.defined(mode.payload)) { 8234 this._payload = mode.payload; 8235 } 8236 } 8237 else { 8238 this._tMode = mode; 8239 this._tSend = total; 8240 } 8241 if (this._tMode === "REST") { 8242 this._tSend = false; 8243 this._endnm = true; 8244 } 8245 if (this._tMode === "JSON" || this._tMode === "REST-JSON") { 8246 this._tSend = false; 8247 this._endnm = true; 8248 this._serializeAsJson = true; 8249 this._headers = this._headers || {}; 8250 this._headers["Content-type"] = "application/json"; 8251 } 8252 if (this._tMode === "CUSTOM") { 8253 this._tSend = false; 8254 this._endnm = true; 8255 this._router = mode.router; 8256 } 8257 }; 8258 DataProcessor.prototype.escape = function (data) { 8259 if (this._utf) { 8260 return encodeURIComponent(data); 8261 } 8262 else { 8263 return escape(data); 8264 } 8265 }; 8266 /** 8267 * @desc: allows to set escaping mode 8268 * @param: true - utf based escaping, simple - use current page encoding 8269 * @type: public 8270 */ 8271 DataProcessor.prototype.enableUTFencoding = function (mode) { 8272 this._utf = !!mode; 8273 }; 8274 /** 8275 * @desc: allows to define, which column may trigger update 8276 * @param: val - array or list of true/false values 8277 * @type: public 8278 */ 8279 DataProcessor.prototype.setDataColumns = function (val) { 8280 this._columns = (typeof val === "string") ? val.split(",") : val; 8281 }; 8282 /** 8283 * @desc: get state of updating 8284 * @returns: true - all in sync with server, false - some items not updated yet. 8285 * @type: public 8286 */ 8287 DataProcessor.prototype.getSyncState = function () { 8288 return !this.updatedRows.length; 8289 }; 8290 /** 8291 * @desc: enable/disable named field for data syncing, will use column ids for grid 8292 * @param: mode - true/false 8293 * @type: public 8294 */ 8295 DataProcessor.prototype.enableDataNames = function (mode) { 8296 this._endnm = !!mode; 8297 }; 8298 /** 8299 * @desc: enable/disable mode , when only changed fields and row id send to the server side, instead of all fields in default mode 8300 * @param: mode - true/false 8301 * @type: public 8302 */ 8303 DataProcessor.prototype.enablePartialDataSend = function (mode) { 8304 this._changed = !!mode; 8305 }; 8306 /** 8307 * @desc: set if rows should be send to server automatically 8308 * @param: mode - "row" - based on row selection changed, "cell" - based on cell editing finished, "off" - manual data sending 8309 * @type: public 8310 */ 8311 DataProcessor.prototype.setUpdateMode = function (mode, dnd) { 8312 this.autoUpdate = (mode === "cell"); 8313 this.updateMode = mode; 8314 this.dnd = dnd; 8315 }; 8316 DataProcessor.prototype.ignore = function (code, master) { 8317 this._silent_mode = true; 8318 code.call(master || window); 8319 this._silent_mode = false; 8320 }; 8321 /** 8322 * @desc: mark row as updated/normal. check mandatory fields, initiate autoupdate (if turned on) 8323 * @param: rowId - id of row to set update-status for 8324 * @param: state - true for "updated", false for "not updated" 8325 * @param: mode - update mode name 8326 * @type: public 8327 */ 8328 DataProcessor.prototype.setUpdated = function (rowId, state, mode) { 8329 if (this._silent_mode) { 8330 return; 8331 } 8332 var ind = this.findRow(rowId); 8333 mode = mode || "updated"; 8334 var existing = this.$gantt.getUserData(rowId, this.action_param); 8335 if (existing && mode === "updated") { 8336 mode = existing; 8337 } 8338 if (state) { 8339 this.set_invalid(rowId, false); // clear previous error flag 8340 this.updatedRows[ind] = rowId; 8341 this.$gantt.setUserData(rowId, this.action_param, mode); 8342 if (this._in_progress[rowId]) { 8343 this._in_progress[rowId] = "wait"; 8344 } 8345 } 8346 else { 8347 if (!this.is_invalid(rowId)) { 8348 this.updatedRows.splice(ind, 1); 8349 this.$gantt.setUserData(rowId, this.action_param, ""); 8350 } 8351 } 8352 this.markRow(rowId, state, mode); 8353 if (state && this.autoUpdate) { 8354 this.sendData(rowId); 8355 } 8356 }; 8357 DataProcessor.prototype.markRow = function (id, state, mode) { 8358 var str = ""; 8359 var invalid = this.is_invalid(id); 8360 if (invalid) { 8361 str = this.styles[invalid]; 8362 state = true; 8363 } 8364 if (this.callEvent("onRowMark", [id, state, mode, invalid])) { 8365 // default logic 8366 str = this.styles[state ? mode : "clear"] + str; 8367 this.$gantt[this._methods[0]](id, str); 8368 if (invalid && invalid.details) { 8369 str += this.styles[invalid + "_cell"]; 8370 for (var i = 0; i < invalid.details.length; i++) { 8371 if (invalid.details[i]) { 8372 this.$gantt[this._methods[1]](id, i, str); 8373 } 8374 } 8375 } 8376 } 8377 }; 8378 DataProcessor.prototype.getActionByState = function (state) { 8379 if (state === "inserted") { 8380 return "create"; 8381 } 8382 if (state === "updated") { 8383 return "update"; 8384 } 8385 if (state === "deleted") { 8386 return "delete"; 8387 } 8388 // reorder 8389 return "update"; 8390 }; 8391 DataProcessor.prototype.getState = function (id) { 8392 return this.$gantt.getUserData(id, this.action_param); 8393 }; 8394 DataProcessor.prototype.is_invalid = function (id) { 8395 return this._invalid[id]; 8396 }; 8397 DataProcessor.prototype.set_invalid = function (id, mode, details) { 8398 if (details) { 8399 mode = { 8400 value: mode, 8401 details: details, 8402 toString: function () { 8403 return this.value.toString(); 8404 } 8405 }; 8406 } 8407 this._invalid[id] = mode; 8408 }; 8409 /** 8410 * @desc: check mandatory fields and verify values of cells, initiate update (if specified). Can be redefined in order to provide custom validation 8411 * @param: rowId - id of row to set update-status for 8412 * @type: public 8413 */ 8414 // tslint:disable-next-line 8415 DataProcessor.prototype.checkBeforeUpdate = function (rowId) { 8416 return true; 8417 }; 8418 /** 8419 * @desc: send row(s) values to server 8420 * @param: rowId - id of row which data to send. If not specified, then all "updated" rows will be send 8421 * @type: public 8422 */ 8423 DataProcessor.prototype.sendData = function (rowId) { 8424 if (this.$gantt.editStop) { 8425 this.$gantt.editStop(); 8426 } 8427 if (typeof rowId === "undefined" || this._tSend) { 8428 return this.sendAllData(); 8429 } 8430 if (this._in_progress[rowId]) { 8431 return false; 8432 } 8433 this.messages = []; 8434 if (!this.checkBeforeUpdate(rowId) && this.callEvent("onValidationError", [rowId, this.messages])) { 8435 return false; 8436 } 8437 this._beforeSendData(this._getRowData(rowId), rowId); 8438 }; 8439 DataProcessor.prototype.serialize = function (data, id) { 8440 if (this._serializeAsJson) { 8441 return this._serializeAsJSON(data); 8442 } 8443 if (typeof data === "string") { 8444 return data; 8445 } 8446 if (typeof id !== "undefined") { 8447 return this.serialize_one(data, ""); 8448 } 8449 else { 8450 var stack = []; 8451 var keys = []; 8452 for (var key in data) { 8453 if (data.hasOwnProperty(key)) { 8454 stack.push(this.serialize_one(data[key], key + this._postDelim)); 8455 keys.push(key); 8456 } 8457 } 8458 stack.push("ids=" + this.escape(keys.join(","))); 8459 if (this.$gantt.security_key) { 8460 stack.push("dhx_security=" + this.$gantt.security_key); 8461 } 8462 return stack.join("&"); 8463 } 8464 }; 8465 DataProcessor.prototype.serialize_one = function (data, pref) { 8466 if (typeof data === "string") { 8467 return data; 8468 } 8469 var stack = []; 8470 var serialized = ""; 8471 for (var key in data) 8472 if (data.hasOwnProperty(key)) { 8473 if ((key === "id" || 8474 key == this.action_param) && // tslint:disable-line 8475 this._tMode === "REST") { 8476 continue; 8477 } 8478 if (typeof data[key] === "string" || typeof data[key] === "number") { 8479 serialized = data[key]; 8480 } 8481 else { 8482 serialized = JSON.stringify(data[key]); 8483 } 8484 stack.push(this.escape((pref || "") + key) + "=" + this.escape(serialized)); 8485 } 8486 return stack.join("&"); 8487 }; 8488 DataProcessor.prototype.sendAllData = function () { 8489 if (!this.updatedRows.length) { 8490 return; 8491 } 8492 this.messages = []; 8493 var valid = true; 8494 this._forEachUpdatedRow(function (rowId) { 8495 valid = valid && this.checkBeforeUpdate(rowId); 8496 }); 8497 if (!valid && !this.callEvent("onValidationError", ["", this.messages])) { 8498 return false; 8499 } 8500 if (this._tSend) { 8501 this._sendData(this._getAllData()); 8502 } 8503 else { 8504 // this.updatedRows can be spliced from onBeforeUpdate via dp.setUpdated false 8505 // use an iterator instead of for(var i = 0; i < this.updatedRows; i++) then 8506 this._forEachUpdatedRow(function (rowId) { 8507 if (!this._in_progress[rowId]) { 8508 if (this.is_invalid(rowId)) { 8509 return; 8510 } 8511 this._beforeSendData(this._getRowData(rowId), rowId); 8512 } 8513 }); 8514 } 8515 }; 8516 DataProcessor.prototype.findRow = function (pattern) { 8517 var i = 0; 8518 for (i = 0; i < this.updatedRows.length; i++) { 8519 if (pattern == this.updatedRows[i]) { // tslint:disable-line 8520 break; 8521 } 8522 } 8523 return i; 8524 }; 8525 /** 8526 * @desc: define custom actions 8527 * @param: name - name of action, same as value of action attribute 8528 * @param: handler - custom function, which receives a XMl response content for action 8529 * @type: private 8530 */ 8531 DataProcessor.prototype.defineAction = function (name, handler) { 8532 if (!this._uActions) { 8533 this._uActions = {}; 8534 } 8535 this._uActions[name] = handler; 8536 }; 8537 /** 8538 * @desc: used in combination with setOnBeforeUpdateHandler to create custom client-server transport system 8539 * @param: sid - id of item before update 8540 * @param: tid - id of item after up0ate 8541 * @param: action - action name 8542 * @type: public 8543 * @topic: 0 8544 */ 8545 DataProcessor.prototype.afterUpdateCallback = function (sid, tid, action, btag, ganttMode) { 8546 if (!this.$gantt) { 8547 // destructor has been called before the callback 8548 return; 8549 } 8550 this.setGanttMode(ganttMode); 8551 var marker = sid; 8552 var correct = (action !== "error" && action !== "invalid"); 8553 if (!correct) { 8554 this.set_invalid(sid, action); 8555 } 8556 if ((this._uActions) && (this._uActions[action]) && (!this._uActions[action](btag))) { 8557 return (delete this._in_progress[marker]); 8558 } 8559 if (this._in_progress[marker] !== "wait") { 8560 this.setUpdated(sid, false); 8561 } 8562 var originalSid = sid; 8563 switch (action) { 8564 case "inserted": 8565 case "insert": 8566 if (tid != sid) { // tslint:disable-line 8567 this.setUpdated(sid, false); 8568 this.$gantt[this._methods[2]](sid, tid); 8569 sid = tid; 8570 } 8571 break; 8572 case "delete": 8573 case "deleted": 8574 this.$gantt.setUserData(sid, this.action_param, "true_deleted"); 8575 this.$gantt[this._methods[3]](sid); 8576 delete this._in_progress[marker]; 8577 return this.callEvent("onAfterUpdate", [sid, action, tid, btag]); 8578 } 8579 if (this._in_progress[marker] !== "wait") { 8580 if (correct) { 8581 this.$gantt.setUserData(sid, this.action_param, ""); 8582 } 8583 delete this._in_progress[marker]; 8584 } 8585 else { 8586 delete this._in_progress[marker]; 8587 this.setUpdated(tid, true, this.$gantt.getUserData(sid, this.action_param)); 8588 } 8589 this.callEvent("onAfterUpdate", [originalSid, action, tid, btag]); 8590 }; 8591 /** 8592 * @desc: response from server 8593 * @param: xml - XMLLoader object with response XML 8594 * @type: private 8595 */ 8596 DataProcessor.prototype.afterUpdate = function (that, xml, id) { 8597 var _xml; 8598 if (arguments.length === 3) { 8599 _xml = arguments[1]; 8600 } 8601 else { 8602 // old dataprocessor 8603 _xml = arguments[4]; 8604 } 8605 var mode = this.getGanttMode(); 8606 var reqUrl = _xml.filePath || _xml.url; 8607 if (this._tMode !== "REST" && this._tMode !== "REST-JSON") { 8608 if (reqUrl.indexOf("gantt_mode=links") !== -1) { 8609 mode = "link"; 8610 } 8611 else { 8612 mode = "task"; 8613 } 8614 } 8615 else { 8616 if (reqUrl.indexOf("/link") > reqUrl.indexOf("/task")) { 8617 mode = "link"; 8618 } 8619 else { 8620 mode = "task"; 8621 } 8622 } 8623 this.setGanttMode(mode); 8624 var ajax = this.$gantt.ajax; 8625 // try to use json first 8626 if (window.JSON) { 8627 var tag = void 0; 8628 try { 8629 tag = JSON.parse(xml.xmlDoc.responseText); 8630 } 8631 catch (e) { 8632 // empty response also can be processed by json handler 8633 if (!xml.xmlDoc.responseText.length) { 8634 tag = {}; 8635 } 8636 } 8637 if (tag) { 8638 var action = tag.action || this.getState(id) || "updated"; 8639 var sid = tag.sid || id[0]; 8640 var tid = tag.tid || id[0]; 8641 that.afterUpdateCallback(sid, tid, action, tag, mode); 8642 that.finalizeUpdate(); 8643 this.setGanttMode(mode); 8644 return; 8645 } 8646 } 8647 // xml response 8648 var top = ajax.xmltop("data", xml.xmlDoc); // fix incorrect content type in IE 8649 if (!top) { 8650 return this.cleanUpdate(id); 8651 } 8652 var atag = ajax.xpath("//data/action", top); 8653 if (!atag.length) { 8654 return this.cleanUpdate(id); 8655 } 8656 for (var i = 0; i < atag.length; i++) { 8657 var btag = atag[i]; 8658 var action = btag.getAttribute("type"); 8659 var sid = btag.getAttribute("sid"); 8660 var tid = btag.getAttribute("tid"); 8661 that.afterUpdateCallback(sid, tid, action, btag, mode); 8662 } 8663 that.finalizeUpdate(); 8664 }; 8665 DataProcessor.prototype.cleanUpdate = function (id) { 8666 if (id) { 8667 for (var i = 0; i < id.length; i++) { 8668 delete this._in_progress[id[i]]; 8669 } 8670 } 8671 }; 8672 DataProcessor.prototype.finalizeUpdate = function () { 8673 if (this._waitMode) { 8674 this._waitMode--; 8675 } 8676 this.callEvent("onAfterUpdateFinish", []); 8677 if (!this.updatedRows.length) { 8678 this.callEvent("onFullSync", []); 8679 } 8680 }; 8681 /** 8682 * @desc: initializes data-processor 8683 * @param: gantt - dhtmlxGantt object to attach this data-processor to 8684 * @type: public 8685 */ 8686 DataProcessor.prototype.init = function (gantt) { 8687 if (this._initialized) { 8688 return; 8689 } 8690 this.$gantt = gantt; 8691 if (this.$gantt._dp_init) { 8692 this.$gantt._dp_init(this); 8693 } 8694 this._setDefaultTransactionMode(); 8695 this.styles = { 8696 updated: "gantt_updated", 8697 order: "gantt_updated", 8698 inserted: "gantt_inserted", 8699 deleted: "gantt_deleted", 8700 invalid: "gantt_invalid", 8701 error: "gantt_error", 8702 clear: "" 8703 }; 8704 this._methods = ["_row_style", "setCellTextStyle", "_change_id", "_delete_task"]; 8705 extend_gantt_1.default(this.$gantt, this); 8706 var dataProcessorEvents = new data_processor_events_1.default(this.$gantt, this); 8707 dataProcessorEvents.attach(); 8708 this.attachEvent("onDestroy", function () { 8709 delete this.setGanttMode; 8710 delete this._getRowData; 8711 delete this.$gantt._dp; 8712 delete this.$gantt._change_id; 8713 delete this.$gantt._row_style; 8714 delete this.$gantt._delete_task; 8715 delete this.$gantt._sendTaskOrder; 8716 delete this.$gantt; 8717 dataProcessorEvents.detach(); 8718 }); 8719 this.$gantt.callEvent("onDataProcessorReady", [this]); 8720 this._initialized = true; 8721 }; 8722 DataProcessor.prototype.setOnAfterUpdate = function (handler) { 8723 this.attachEvent("onAfterUpdate", handler); 8724 }; 8725 DataProcessor.prototype.setOnBeforeUpdateHandler = function (handler) { 8726 this.attachEvent("onBeforeDataSending", handler); 8727 }; 8728 /* starts autoupdate mode 8729 @param interval time interval for sending update requests 8730 */ 8731 DataProcessor.prototype.setAutoUpdate = function (interval, user) { 8732 var _this = this; 8733 interval = interval || 2000; 8734 this._user = user || (new Date()).valueOf(); 8735 this._needUpdate = false; 8736 this._updateBusy = false; 8737 this.attachEvent("onAfterUpdate", this.afterAutoUpdate); // arguments sid, action, tid, xml_node; 8738 this.attachEvent("onFullSync", this.fullSync); 8739 window.setInterval(function () { 8740 _this.loadUpdate(); 8741 }, interval); 8742 }; 8743 /* process updating request response 8744 if status == collision version is deprecated 8745 set flag for autoupdating immediately 8746 */ 8747 DataProcessor.prototype.afterAutoUpdate = function (sid, action, tid, xml_node) { 8748 if (action === "collision") { 8749 this._needUpdate = true; 8750 return false; 8751 } 8752 else { 8753 return true; 8754 } 8755 }; 8756 /* callback function for onFillSync event 8757 call update function if it's need 8758 */ 8759 DataProcessor.prototype.fullSync = function () { 8760 if (this._needUpdate) { 8761 this._needUpdate = false; 8762 this.loadUpdate(); 8763 } 8764 return true; 8765 }; 8766 /* sends query to the server and call callback function 8767 */ 8768 DataProcessor.prototype.getUpdates = function (url, callback) { 8769 var ajax = this.$gantt.ajax; 8770 if (this._updateBusy) { 8771 return false; 8772 } 8773 else { 8774 this._updateBusy = true; 8775 } 8776 ajax.get(url, callback); 8777 }; 8778 /* loads updates and processes them 8779 */ 8780 DataProcessor.prototype.loadUpdate = function () { 8781 var _this = this; 8782 var ajax = this.$gantt.ajax; 8783 var version = this.$gantt.getUserData(0, "version"); 8784 var url = this.serverProcessor + ajax.urlSeparator(this.serverProcessor) + ["dhx_user=" + this._user, "dhx_version=" + version].join("&"); 8785 url = url.replace("editing=true&", ""); 8786 this.getUpdates(url, function (xml) { 8787 var vers = ajax.xpath("//userdata", xml); 8788 _this.obj.setUserData(0, "version", _this._getXmlNodeValue(vers[0])); 8789 var updates = ajax.xpath("//update", xml); 8790 if (updates.length) { 8791 _this._silent_mode = true; 8792 for (var i = 0; i < updates.length; i++) { 8793 var status_1 = updates[i].getAttribute("status"); 8794 var id = updates[i].getAttribute("id"); 8795 var parent_1 = updates[i].getAttribute("parent"); 8796 switch (status_1) { 8797 case "inserted": 8798 _this.callEvent("insertCallback", [updates[i], id, parent_1]); 8799 break; 8800 case "updated": 8801 _this.callEvent("updateCallback", [updates[i], id, parent_1]); 8802 break; 8803 case "deleted": 8804 _this.callEvent("deleteCallback", [updates[i], id, parent_1]); 8805 break; 8806 } 8807 } 8808 _this._silent_mode = false; 8809 } 8810 _this._updateBusy = false; 8811 }); 8812 }; 8813 DataProcessor.prototype.destructor = function () { 8814 this.callEvent("onDestroy", []); 8815 this.detachAllEvents(); 8816 this.updatedRows = []; 8817 this._in_progress = {}; // ? 8818 this._invalid = {}; 8819 this._storage.clear(); 8820 this._storage = null; 8821 this._headers = null; 8822 this._payload = null; 8823 delete this._initialized; 8824 }; 8825 DataProcessor.prototype.setGanttMode = function (mode) { 8826 if (mode === "tasks") { 8827 mode = "task"; 8828 } 8829 else if (mode === "links") { 8830 mode = "link"; 8831 } 8832 var modes = this.modes || {}; 8833 var ganttMode = this.getGanttMode(); 8834 if (ganttMode) { 8835 modes[ganttMode] = { 8836 _in_progress: this._in_progress, 8837 _invalid: this._invalid, 8838 _storage: this._storage, 8839 updatedRows: this.updatedRows 8840 }; 8841 } 8842 var newState = modes[mode]; 8843 if (!newState) { 8844 newState = modes[mode] = { 8845 _in_progress: {}, 8846 _invalid: {}, 8847 _storage: simple_storage_1.default.create(), 8848 updatedRows: [] 8849 }; 8850 } 8851 this._in_progress = newState._in_progress; 8852 this._invalid = newState._invalid; 8853 this._storage = newState._storage; 8854 this.updatedRows = newState.updatedRows; 8855 this.modes = modes; 8856 this._ganttMode = mode; 8857 }; 8858 DataProcessor.prototype.getGanttMode = function () { 8859 return this._ganttMode; 8860 }; 8861 DataProcessor.prototype.storeItem = function (item) { 8862 this._storage.storeItem(item); 8863 }; 8864 DataProcessor.prototype.url = function (url) { 8865 this.serverProcessor = this._serverProcessor = url; 8866 }; 8867 DataProcessor.prototype._beforeSendData = function (data, rowId) { 8868 if (!this.callEvent("onBeforeUpdate", [rowId, this.getState(rowId), data])) { 8869 return false; 8870 } 8871 this._sendData(data, rowId); 8872 }; 8873 DataProcessor.prototype._serializeAsJSON = function (data) { 8874 if (typeof data === "string") { 8875 return data; 8876 } 8877 var copy = utils.copy(data); 8878 if (this._tMode === "REST-JSON") { 8879 delete copy.id; 8880 delete copy[this.action_param]; 8881 } 8882 return JSON.stringify(copy); 8883 }; 8884 DataProcessor.prototype._applyPayload = function (url) { 8885 var ajax = this.$gantt.ajax; 8886 if (this._payload) { 8887 for (var key in this._payload) { 8888 url = url + ajax.urlSeparator(url) + this.escape(key) + "=" + this.escape(this._payload[key]); 8889 } 8890 } 8891 return url; 8892 }; 8893 // GET/POST/JSON modes of the dataProcessor didn't send the whole data items in 'delete' requests 8894 // clear extra info from the data in order not to change the request format 8895 DataProcessor.prototype._cleanupArgumentsBeforeSend = function (dataToSend) { 8896 var processedData; 8897 if (dataToSend[this.action_param] === undefined) { // hash of updated items, and not an individual item 8898 processedData = {}; 8899 for (var i in dataToSend) { 8900 processedData[i] = this._cleanupArgumentsBeforeSend(dataToSend[i]); 8901 } 8902 } 8903 else { 8904 processedData = this._cleanupItemBeforeSend(dataToSend); 8905 } 8906 return processedData; 8907 }; 8908 DataProcessor.prototype._cleanupItemBeforeSend = function (updatedItem) { 8909 var output = null; 8910 if (updatedItem) { 8911 if (updatedItem[this.action_param] === "deleted") { 8912 output = {}; 8913 output.id = updatedItem.id; 8914 output[this.action_param] = updatedItem[this.action_param]; 8915 } 8916 else { 8917 output = updatedItem; 8918 } 8919 } 8920 return output; 8921 }; 8922 DataProcessor.prototype._sendData = function (dataToSend, rowId) { 8923 var _this = this; 8924 if (!dataToSend) { 8925 return; // nothing to send 8926 } 8927 if (!this.callEvent("onBeforeDataSending", rowId ? [rowId, this.getState(rowId), dataToSend] : [null, null, dataToSend])) { 8928 return false; 8929 } 8930 if (rowId) { 8931 this._in_progress[rowId] = (new Date()).valueOf(); 8932 } 8933 var ajax = this.$gantt.ajax; 8934 if (this._tMode === "CUSTOM") { 8935 var taskState_1 = this.getState(rowId); 8936 var taskAction = this.getActionByState(taskState_1); 8937 var ganttMode_1 = this.getGanttMode(); 8938 var _onResolvedCreateUpdate = function (tag) { 8939 var action = taskState_1 || "updated"; 8940 var sid = rowId; 8941 var tid = rowId; 8942 if (tag) { 8943 action = tag.action || taskState_1; 8944 sid = tag.sid || sid; 8945 tid = tag.id || tag.tid || tid; 8946 } 8947 _this.afterUpdateCallback(sid, tid, action, tag, ganttMode_1); 8948 }; 8949 var actionPromise = void 0; 8950 if (this._router instanceof Function) { 8951 actionPromise = this._router(ganttMode_1, taskAction, dataToSend, rowId); 8952 } 8953 else if (this._router[ganttMode_1] instanceof Function) { 8954 actionPromise = this._router[ganttMode_1](taskAction, dataToSend, rowId); 8955 } 8956 else { 8957 switch (taskState_1) { 8958 case "inserted": 8959 actionPromise = this._router[ganttMode_1].create(dataToSend); 8960 break; 8961 case "deleted": 8962 actionPromise = this._router[ganttMode_1].delete(rowId); 8963 break; 8964 default: 8965 actionPromise = this._router[ganttMode_1].update(dataToSend, rowId); 8966 break; 8967 } 8968 } 8969 if (actionPromise) { 8970 // neither promise nor {tid: newId} response object 8971 if (!actionPromise.then && 8972 (actionPromise.id === undefined && actionPromise.tid === undefined)) { 8973 throw new Error("Incorrect router return value. A Promise or a response object is expected"); 8974 } 8975 if (actionPromise.then) { 8976 actionPromise.then(_onResolvedCreateUpdate); 8977 } 8978 else { 8979 // custom method may return a response object in case of sync action 8980 _onResolvedCreateUpdate(actionPromise); 8981 } 8982 } 8983 else { 8984 _onResolvedCreateUpdate(null); 8985 } 8986 return; 8987 } 8988 var queryParams; 8989 queryParams = { 8990 callback: function (xml) { 8991 var ids = []; 8992 if (rowId) { 8993 ids.push(rowId); 8994 } 8995 else if (dataToSend) { 8996 for (var key in dataToSend) { 8997 ids.push(key); 8998 } 8999 } 9000 return _this.afterUpdate(_this, xml, ids); 9001 }, 9002 headers: this._headers 9003 }; 9004 var urlParams = this.serverProcessor + (this._user ? (ajax.urlSeparator(this.serverProcessor) + ["dhx_user=" + this._user, "dhx_version=" + this.$gantt.getUserData(0, "version")].join("&")) : ""); 9005 var url = this._applyPayload(urlParams); 9006 var data; 9007 switch (this._tMode) { 9008 case "GET": 9009 data = this._cleanupArgumentsBeforeSend(dataToSend); 9010 queryParams.url = url + ajax.urlSeparator(url) + this.serialize(data, rowId); 9011 queryParams.method = "GET"; 9012 break; 9013 case "POST": 9014 data = this._cleanupArgumentsBeforeSend(dataToSend); 9015 queryParams.url = url; 9016 queryParams.method = "POST"; 9017 queryParams.data = this.serialize(data, rowId); 9018 break; 9019 case "JSON": 9020 data = {}; 9021 var preprocessedData = this._cleanupItemBeforeSend(dataToSend); 9022 for (var key in preprocessedData) { 9023 if (key === this.action_param || key === "id" || key === "gr_id") { 9024 continue; 9025 } 9026 data[key] = preprocessedData[key]; 9027 } 9028 queryParams.url = url; 9029 queryParams.method = "POST"; 9030 queryParams.data = JSON.stringify({ 9031 id: rowId, 9032 action: dataToSend[this.action_param], 9033 data: data 9034 }); 9035 break; 9036 case "REST": 9037 case "REST-JSON": 9038 url = urlParams.replace(/(&|\?)editing=true/, ""); 9039 data = ""; 9040 switch (this.getState(rowId)) { 9041 case "inserted": 9042 queryParams.method = "POST"; 9043 queryParams.data = this.serialize(dataToSend, rowId); 9044 break; 9045 case "deleted": 9046 queryParams.method = "DELETE"; 9047 url = url + (url.slice(-1) === "/" ? "" : "/") + rowId; 9048 break; 9049 default: 9050 queryParams.method = "PUT"; 9051 queryParams.data = this.serialize(dataToSend, rowId); 9052 url = url + (url.slice(-1) === "/" ? "" : "/") + rowId; 9053 break; 9054 } 9055 queryParams.url = this._applyPayload(url); 9056 break; 9057 } 9058 this._waitMode++; 9059 return ajax.query(queryParams); 9060 }; 9061 DataProcessor.prototype._forEachUpdatedRow = function (code) { 9062 var updatedRows = this.updatedRows.slice(); 9063 for (var i = 0; i < updatedRows.length; i++) { 9064 var rowId = updatedRows[i]; 9065 if (this.$gantt.getUserData(rowId, this.action_param)) { 9066 code.call(this, rowId); 9067 } 9068 } 9069 }; 9070 DataProcessor.prototype._setDefaultTransactionMode = function () { 9071 if (this.serverProcessor) { 9072 this.setTransactionMode("POST", true); 9073 this.serverProcessor += (this.serverProcessor.indexOf("?") !== -1 ? "&" : "?") + "editing=true"; 9074 this._serverProcessor = this.serverProcessor; 9075 } 9076 }; 9077 /* returns xml node value 9078 @param node 9079 xml node 9080 */ 9081 DataProcessor.prototype._getXmlNodeValue = function (node) { 9082 if (node.firstChild) { 9083 return node.firstChild.nodeValue; 9084 } 9085 return ""; 9086 }; 9087 DataProcessor.prototype._getAllData = function () { 9088 var out = {}; 9089 var hasOne = false; 9090 this._forEachUpdatedRow(function (id) { 9091 if (this._in_progress[id] || this.is_invalid(id)) { 9092 return; 9093 } 9094 var row = this._getRowData(id); 9095 if (!this.callEvent("onBeforeUpdate", [id, this.getState(id), row])) { 9096 return; 9097 } 9098 out[id] = row; 9099 hasOne = true; 9100 this._in_progress[id] = (new Date()).valueOf(); 9101 }); 9102 return hasOne ? out : null; 9103 }; 9104 DataProcessor.prototype._prepareDataItem = function (rawItem) { 9105 var processedItem = {}; 9106 for (var key in rawItem) { 9107 if (key.substr(0, 1) === "$") { 9108 continue; 9109 } 9110 var value = rawItem[key]; 9111 if (helpers.isDate(value)) { 9112 processedItem[key] = this.$gantt.templates.xml_format !== this.$gantt.templates.format_date ? this.$gantt.templates.xml_format(value) : this.$gantt.templates.format_date(value); 9113 } 9114 else if (value === null) { 9115 processedItem[key] = ""; 9116 } 9117 else { 9118 processedItem[key] = value; 9119 } 9120 } 9121 processedItem[this.action_param] = this.$gantt.getUserData(rawItem.id, this.action_param); 9122 return processedItem; 9123 }; 9124 DataProcessor.prototype.getStoredItem = function (id) { 9125 return this._storage.getStoredItem(id); 9126 }; 9127 DataProcessor.prototype._getRowData = function (id) { 9128 var dataItem; 9129 var gantt = this.$gantt; 9130 if (this.getGanttMode() === "task") { 9131 if (gantt.isTaskExists(id)) { 9132 dataItem = this.$gantt.getTask(id); 9133 } 9134 } 9135 else { 9136 if (gantt.isLinkExists(id)) { 9137 dataItem = this.$gantt.getLink(id); 9138 } 9139 } 9140 if (!dataItem) { 9141 dataItem = this.getStoredItem(id); 9142 } 9143 if (!dataItem) { 9144 dataItem = { id: id }; 9145 } 9146 return this._prepareDataItem(dataItem); 9147 }; 9148 return DataProcessor; 9149}()); 9150exports.DataProcessor = DataProcessor; 9151 9152 9153/***/ }), 9154 9155/***/ "./sources/core/dataprocessor/data_processor_events.ts": 9156/*!*************************************************************!*\ 9157 !*** ./sources/core/dataprocessor/data_processor_events.ts ***! 9158 \*************************************************************/ 9159/*! no static exports found */ 9160/***/ (function(module, exports, __webpack_require__) { 9161 9162"use strict"; 9163 9164Object.defineProperty(exports, "__esModule", { value: true }); 9165var helpers = __webpack_require__(/*! ../../utils/helpers */ "./sources/utils/helpers.js"); 9166var DataProcessorEvents = /** @class */ (function () { 9167 function DataProcessorEvents(gantt, dp) { 9168 this.$gantt = gantt; 9169 this.$dp = dp; 9170 this._dataProcessorHandlers = []; 9171 } 9172 DataProcessorEvents.prototype.attach = function () { 9173 var dp = this.$dp; 9174 var gantt = this.$gantt; 9175 var treeHelper = __webpack_require__(/*! ../../utils/task_tree_helpers */ "./sources/utils/task_tree_helpers.js"); 9176 var cascadeDelete = {}; 9177 function clientSideDelete(id) { 9178 var updated = dp.updatedRows.slice(); 9179 var clientOnly = false; 9180 for (var i = 0; i < updated.length && !dp._in_progress[id]; i++) { 9181 if (updated[i] === id) { 9182 if (gantt.getUserData(id, "!nativeeditor_status") === "inserted") { 9183 clientOnly = true; 9184 } 9185 dp.setUpdated(id, false); 9186 } 9187 } 9188 return clientOnly; 9189 } 9190 function getTaskLinks(task) { 9191 var _links = []; 9192 if (task.$source) { 9193 _links = _links.concat(task.$source); 9194 } 9195 if (task.$target) { 9196 _links = _links.concat(task.$target); 9197 } 9198 return _links; 9199 } 9200 this._dataProcessorHandlers.push(gantt.attachEvent("onAfterTaskAdd", function (id, item) { 9201 if (gantt.isTaskExists(id)) { 9202 dp.setGanttMode("tasks"); 9203 dp.setUpdated(id, true, "inserted"); 9204 } 9205 })); 9206 this._dataProcessorHandlers.push(gantt.attachEvent("onAfterTaskUpdate", function (id, item) { 9207 if (gantt.isTaskExists(id)) { 9208 dp.setGanttMode("tasks"); 9209 dp.setUpdated(id, true); 9210 // gantt can be destroyed/reinitialized after dp.setUpdated 9211 if (gantt._sendTaskOrder) { 9212 gantt._sendTaskOrder(id, item); 9213 } 9214 } 9215 })); 9216 this._dataProcessorHandlers.push(gantt.attachEvent("onBeforeTaskDelete", function (id, item) { 9217 if (!gantt.config.cascade_delete) { 9218 return true; 9219 } 9220 cascadeDelete[id] = { 9221 tasks: treeHelper.getSubtreeTasks(gantt, id), 9222 links: treeHelper.getSubtreeLinks(gantt, id) 9223 }; 9224 return true; 9225 })); 9226 this._dataProcessorHandlers.push(gantt.attachEvent("onAfterTaskDelete", function (id, item) { 9227 dp.setGanttMode("tasks"); 9228 // not send delete request if item is not inserted into the db - just remove it from the client 9229 var needDbDelete = !clientSideDelete(id); 9230 if (!needDbDelete) { 9231 return; 9232 } 9233 if (gantt.config.cascade_delete && cascadeDelete[id]) { 9234 var dpMode = dp.updateMode; 9235 dp.setUpdateMode("off"); 9236 var cascade = cascadeDelete[id]; 9237 for (var i in cascade.tasks) { 9238 if (!clientSideDelete(i)) { 9239 dp.storeItem(cascade.tasks[i]); 9240 dp.setUpdated(i, true, "deleted"); 9241 } 9242 } 9243 dp.setGanttMode("links"); 9244 for (var i in cascade.links) { 9245 if (!clientSideDelete(i)) { 9246 dp.storeItem(cascade.links[i]); 9247 dp.setUpdated(i, true, "deleted"); 9248 } 9249 } 9250 cascadeDelete[id] = null; 9251 if (dpMode !== "off") { 9252 dp.sendAllData(); 9253 } 9254 dp.setGanttMode("tasks"); 9255 dp.setUpdateMode(dpMode); 9256 } 9257 dp.storeItem(item); 9258 dp.setUpdated(id, true, "deleted"); 9259 if (dp.updateMode !== "off" && !dp._tSend) { 9260 dp.sendAllData(); 9261 } 9262 })); 9263 this._dataProcessorHandlers.push(gantt.attachEvent("onAfterLinkUpdate", function (id, item) { 9264 if (gantt.isLinkExists(id)) { 9265 dp.setGanttMode("links"); 9266 dp.setUpdated(id, true); 9267 } 9268 })); 9269 this._dataProcessorHandlers.push(gantt.attachEvent("onAfterLinkAdd", function (id, item) { 9270 if (gantt.isLinkExists(id)) { 9271 dp.setGanttMode("links"); 9272 dp.setUpdated(id, true, "inserted"); 9273 } 9274 })); 9275 this._dataProcessorHandlers.push(gantt.attachEvent("onAfterLinkDelete", function (id, item) { 9276 dp.setGanttMode("links"); 9277 var needDbDelete = !clientSideDelete(id); 9278 if (!needDbDelete) { 9279 return; 9280 } 9281 dp.storeItem(item); 9282 dp.setUpdated(id, true, "deleted"); 9283 })); 9284 this._dataProcessorHandlers.push(gantt.attachEvent("onRowDragEnd", function (id, target) { 9285 gantt._sendTaskOrder(id, gantt.getTask(id)); 9286 })); 9287 var tasks = null; 9288 var links = null; 9289 this._dataProcessorHandlers.push(gantt.attachEvent("onTaskIdChange", function (oldId, newId) { 9290 if (!dp._waitMode) { 9291 return; 9292 } 9293 var children = gantt.getChildren(newId); 9294 if (children.length) { 9295 tasks = tasks || {}; 9296 for (var i = 0; i < children.length; i++) { 9297 var ch = this.getTask(children[i]); 9298 tasks[ch.id] = ch; 9299 } 9300 } 9301 var item = this.getTask(newId); 9302 var itemLinks = getTaskLinks(item); 9303 if (itemLinks.length) { 9304 links = links || {}; 9305 for (var i = 0; i < itemLinks.length; i++) { 9306 var link = this.getLink(itemLinks[i]); 9307 links[link.id] = link; 9308 } 9309 } 9310 })); 9311 dp.attachEvent("onAfterUpdateFinish", function () { 9312 if (tasks || links) { 9313 gantt.batchUpdate(function () { 9314 for (var id in tasks) { 9315 gantt.updateTask(tasks[id].id); 9316 } 9317 for (var id in links) { 9318 gantt.updateLink(links[id].id); 9319 } 9320 tasks = null; 9321 links = null; 9322 }); 9323 if (tasks) { 9324 gantt._dp.setGanttMode("tasks"); 9325 } 9326 else { 9327 gantt._dp.setGanttMode("links"); 9328 } 9329 } 9330 }); 9331 dp.attachEvent("onBeforeDataSending", function () { 9332 if (this._tMode === "CUSTOM") { 9333 return true; 9334 } 9335 var url = this._serverProcessor; 9336 if (this._tMode === "REST-JSON" || this._tMode === "REST") { 9337 var mode = this._ganttMode; 9338 url = url.substring(0, url.indexOf("?") > -1 ? url.indexOf("?") : url.length); 9339 // editing=true& 9340 this.serverProcessor = url + (url.slice(-1) === "/" ? "" : "/") + mode; 9341 } 9342 else { 9343 var pluralizedMode = this._ganttMode + "s"; 9344 this.serverProcessor = url + gantt.ajax.urlSeparator(url) + "gantt_mode=" + pluralizedMode; 9345 } 9346 return true; 9347 }); 9348 dp.attachEvent("insertCallback", function insertCallback(upd, id, parent, mode) { 9349 var data = upd.data || gantt.xml._xmlNodeToJSON(upd.firstChild); 9350 var methods = { 9351 add: gantt.addTask, 9352 isExist: gantt.isTaskExists 9353 }; 9354 if (mode === "links") { 9355 methods.add = gantt.addLink; 9356 methods.isExist = gantt.isLinkExists; 9357 } 9358 if (methods.isExist.call(gantt, id)) { 9359 return; 9360 } 9361 data.id = id; 9362 methods.add.call(gantt, data); 9363 }); 9364 dp.attachEvent("updateCallback", function updateCallback(upd, id) { 9365 var data = upd.data || gantt.xml._xmlNodeToJSON(upd.firstChild); 9366 if (!gantt.isTaskExists(id)) { 9367 return; 9368 } 9369 var objData = gantt.getTask(id); 9370 for (var key in data) { 9371 var property = data[key]; 9372 switch (key) { 9373 case "id": 9374 continue; 9375 case "start_date": 9376 case "end_date": 9377 property = gantt.templates.xml_date !== gantt.templates.parse_date ? gantt.templates.xml_date(property) : gantt.templates.parse_date(property); 9378 break; 9379 case "duration": 9380 objData.end_date = gantt.calculateEndDate({ start_date: objData.start_date, duration: property, task: objData }); 9381 break; 9382 } 9383 objData[key] = property; 9384 } 9385 gantt.updateTask(id); 9386 gantt.refreshData(); 9387 }); 9388 dp.attachEvent("deleteCallback", function deleteCallback(upd, id, parent, mode) { 9389 var methods = { 9390 delete: gantt.deleteTask, 9391 isExist: gantt.isTaskExists 9392 }; 9393 if (mode === "links") { 9394 methods.delete = gantt.deleteLink; 9395 methods.isExist = gantt.isLinkExists; 9396 } 9397 if (methods.isExist.call(gantt, id)) { 9398 methods.delete.call(gantt, id); 9399 } 9400 }); 9401 }; 9402 DataProcessorEvents.prototype.detach = function () { 9403 var _this = this; 9404 helpers.forEach(this._dataProcessorHandlers, function (e) { 9405 _this.$gantt.detachEvent(e); 9406 }); 9407 this._dataProcessorHandlers = []; 9408 }; 9409 return DataProcessorEvents; 9410}()); 9411exports.default = DataProcessorEvents; 9412 9413 9414/***/ }), 9415 9416/***/ "./sources/core/dataprocessor/extend_gantt.ts": 9417/*!****************************************************!*\ 9418 !*** ./sources/core/dataprocessor/extend_gantt.ts ***! 9419 \****************************************************/ 9420/*! no static exports found */ 9421/***/ (function(module, exports, __webpack_require__) { 9422 9423"use strict"; 9424 9425Object.defineProperty(exports, "__esModule", { value: true }); 9426function extendGantt(gantt, dp) { 9427 gantt.getUserData = function (id, name) { 9428 if (!this.userdata) { 9429 this.userdata = {}; 9430 } 9431 if (this.userdata[id] && this.userdata[id][name]) { 9432 return this.userdata[id][name]; 9433 } 9434 return ""; 9435 }; 9436 gantt.setUserData = function (id, name, value) { 9437 if (!this.userdata) { 9438 this.userdata = {}; 9439 } 9440 if (!this.userdata[id]) { 9441 this.userdata[id] = {}; 9442 } 9443 this.userdata[id][name] = value; 9444 }; 9445 gantt._change_id = function (oldId, newId) { 9446 if (this._dp._ganttMode !== "task") { 9447 this.changeLinkId(oldId, newId); 9448 } 9449 else { 9450 this.changeTaskId(oldId, newId); 9451 } 9452 }; 9453 gantt._row_style = function (rowId, classname) { 9454 if (this._dp._ganttMode !== "task") { 9455 return; 9456 } 9457 if (!gantt.isTaskExists(rowId)) { 9458 return; 9459 } 9460 var task = gantt.getTask(rowId); 9461 task.$dataprocessor_class = classname; 9462 gantt.refreshTask(rowId); 9463 }; 9464 // fake method for dataprocessor 9465 gantt._delete_task = function (rowId, node) { }; // tslint:disable-line 9466 gantt._sendTaskOrder = function (id, item) { 9467 if (item.$drop_target) { 9468 this._dp.setGanttMode("task"); 9469 this.getTask(id).target = item.$drop_target; 9470 this._dp.setUpdated(id, true, "order"); 9471 delete this.getTask(id).$drop_target; 9472 } 9473 }; 9474 gantt.setDp = function () { 9475 this._dp = dp; 9476 }; 9477 gantt.setDp(); 9478} 9479exports.default = extendGantt; 9480 9481 9482/***/ }), 9483 9484/***/ "./sources/core/dataprocessor/index.js": 9485/*!*********************************************!*\ 9486 !*** ./sources/core/dataprocessor/index.js ***! 9487 \*********************************************/ 9488/*! no static exports found */ 9489/***/ (function(module, exports, __webpack_require__) { 9490 9491var DataProcessor = __webpack_require__(/*! ./data_processor */ "./sources/core/dataprocessor/data_processor.ts"); 9492module.exports = { 9493 DEPRECATED_api: function(server) { 9494 return new (DataProcessor.DataProcessor)(server); 9495 }, 9496 createDataProcessor: DataProcessor.createDataProcessor, 9497 getDataProcessorModes: DataProcessor.getAvailableModes 9498}; 9499 9500/***/ }), 9501 9502/***/ "./sources/core/dataprocessor/simple_storage.ts": 9503/*!******************************************************!*\ 9504 !*** ./sources/core/dataprocessor/simple_storage.ts ***! 9505 \******************************************************/ 9506/*! no static exports found */ 9507/***/ (function(module, exports, __webpack_require__) { 9508 9509"use strict"; 9510 9511Object.defineProperty(exports, "__esModule", { value: true }); 9512var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 9513var SimpleStorage = /** @class */ (function () { 9514 function SimpleStorage() { 9515 var _this = this; 9516 this.clear = function () { 9517 _this._storage = {}; 9518 }; 9519 this.storeItem = function (item) { 9520 _this._storage[item.id] = utils.copy(item); 9521 }; 9522 this.getStoredItem = function (id) { 9523 return _this._storage[id] || null; 9524 }; 9525 this._storage = {}; 9526 } 9527 SimpleStorage.create = function () { 9528 return new SimpleStorage(); 9529 }; 9530 return SimpleStorage; 9531}()); 9532exports.default = SimpleStorage; 9533 9534 9535/***/ }), 9536 9537/***/ "./sources/core/datastore/datastore.js": 9538/*!*********************************************!*\ 9539 !*** ./sources/core/datastore/datastore.js ***! 9540 \*********************************************/ 9541/*! no static exports found */ 9542/***/ (function(module, exports, __webpack_require__) { 9543 9544var powerArray = __webpack_require__(/*! ./power_array */ "./sources/core/datastore/power_array.js"); 9545var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 9546var eventable = __webpack_require__(/*! ../../utils/eventable */ "./sources/utils/eventable.js"); 9547 9548var DataStore = function(config){ 9549 this.pull = {}; 9550 this.$initItem = config.initItem; 9551 this.visibleOrder = powerArray.$create(); 9552 this.fullOrder = powerArray.$create(); 9553 this._skip_refresh = false; 9554 this._filterRule = null; 9555 this._searchVisibleOrder = {}; 9556 this.$config = config; 9557 eventable(this); 9558 return this; 9559}; 9560DataStore.prototype = { 9561 9562 _parseInner: function(data){ 9563 var item = null, 9564 loaded = []; 9565 for(var i = 0, len = data.length; i< len; i++){ 9566 item = data[i]; 9567 if(this.$initItem){ 9568 item = this.$initItem(utils.copy(item)); 9569 } 9570 if(this.callEvent("onItemLoading", [item])){ 9571 if (!this.pull.hasOwnProperty(item.id)) { 9572 this.fullOrder.push(item.id); 9573 } 9574 loaded.push(item); 9575 this.pull[item.id] = item; 9576 } 9577 } 9578 return loaded; 9579 }, 9580 parse: function(data){ 9581 this.callEvent("onBeforeParse", [data]); 9582 var loaded = this._parseInner(data); 9583 this.refresh(); 9584 this.callEvent("onParse", [loaded]); 9585 }, 9586 getItem: function(id){ 9587 return this.pull[id]; 9588 }, 9589 9590 _updateOrder: function(code){ 9591 code.call(this.visibleOrder); 9592 code.call(this.fullOrder); 9593 }, 9594 updateItem: function(id, item){ 9595 if (!utils.defined(item)) item = this.getItem(id); 9596 9597 if (!this._skip_refresh) { 9598 if (this.callEvent("onBeforeUpdate", [item.id, item]) === false) return false; 9599 } 9600 this.pull[id]=item; 9601 if (!this._skip_refresh) { 9602 this.callEvent("onAfterUpdate", [item.id, item]); 9603 this.callEvent("onStoreUpdated", [item.id, item, "update"]); 9604 } 9605 }, 9606 9607 _removeItemInner: function(id){ 9608 //clear from collections 9609 //this.visibleOrder.$remove(id); 9610 this._updateOrder(function(){ this.$remove(id);}); 9611 delete this.pull[id]; 9612 }, 9613 9614 removeItem: function(id){ 9615 //utils.assert(this.exists(id), "Not existing ID in remove command"+id); 9616 9617 var obj = this.getItem(id); //save for later event 9618 if (!this._skip_refresh) { 9619 if (this.callEvent("onBeforeDelete", [obj.id, obj]) === false) return false; 9620 } 9621 9622 this._removeItemInner(id); 9623 9624 if (!this._skip_refresh) { 9625 this.filter(); 9626 this.callEvent("onAfterDelete", [obj.id, obj]); 9627 //repaint signal 9628 this.callEvent("onStoreUpdated", [obj.id, obj, "delete"]); 9629 } 9630 }, 9631 9632 _addItemInner: function(item, index){ 9633 //in case of treetable order is sent as 3rd parameter 9634 //var order = index; 9635 9636 if(this.exists(item.id)){ 9637 this.silent(function(){this.updateItem(item.id, item);}); 9638 }else{ 9639 var order = this.visibleOrder; 9640 9641 //by default item is added to the end of the list 9642 var data_size = order.length; 9643 9644 if (!utils.defined(index) || index < 0) 9645 index = data_size; 9646 //check to prevent too big indexes 9647 if (index > data_size){ 9648 //dhx.log("Warning","DataStore:add","Index of out of bounds"); 9649 index = Math.min(order.length,index); 9650 } 9651 } 9652 9653 9654 //gantt.assert(!this.exists(id), "Not unique ID"); 9655 9656 this.pull[item.id]=item; 9657 if (!this._skip_refresh){ 9658 this._updateOrder(function(){ 9659 if(this.$find(item.id) === -1) 9660 this.$insertAt(item.id,index); 9661 }); 9662 } 9663 this.filter(); 9664 //order.$insertAt(item.id,index); 9665 }, 9666 9667 9668 isVisible: function(id){ 9669 return this.visibleOrder.$find(id) > -1; 9670 }, 9671 getVisibleItems: function(){ 9672 return this.getIndexRange(); 9673 }, 9674 9675 addItem: function(item, index){ 9676 if (!utils.defined(item.id)) 9677 item.id = utils.uid(); 9678 9679 if(this.$initItem){ 9680 item = this.$initItem(item); 9681 } 9682 9683 if (!this._skip_refresh){ 9684 if (this.callEvent("onBeforeAdd", [item.id, item]) === false) return false; 9685 } 9686 9687 9688 this._addItemInner(item, index); 9689 9690 if (!this._skip_refresh){ 9691 this.callEvent("onAfterAdd",[item.id, item]); 9692 //repaint signal 9693 this.callEvent("onStoreUpdated",[item.id,item,"add"]); 9694 } 9695 return item.id; 9696 }, 9697 9698 _changeIdInner: function(oldId, newId){ 9699 if(this.pull[oldId]) 9700 this.pull[newId] = this.pull[oldId]; 9701 9702 var visibleOrder = this._searchVisibleOrder[oldId]; 9703 this.pull[newId].id = newId; 9704 this._updateOrder(function(){ 9705 this[this.$find(oldId)] = newId; 9706 }); 9707 this._searchVisibleOrder[newId] = visibleOrder; 9708 delete this._searchVisibleOrder[oldId]; 9709 9710 //this.visibleOrder[this.visibleOrder.$find(oldId)]=newId; 9711 delete this.pull[oldId]; 9712 }, 9713 changeId: function(oldId, newId){ 9714 this._changeIdInner(oldId, newId); 9715 9716 this.callEvent("onIdChange", [oldId, newId]); 9717 9718 }, 9719 exists: function(id){ 9720 return !!(this.pull[id]); 9721 }, 9722 9723 _moveInner: function(sindex, tindex){ 9724 var id = this.getIdByIndex(sindex); 9725 9726 this._updateOrder(function(){ 9727 this.$removeAt(sindex); 9728 this.$insertAt(id,Math.min(this.length, tindex)); 9729 }); 9730 //this.visibleOrder.$removeAt(sindex); //remove at old position 9731 //if (sindex<tindex) tindex--; //correct shift, caused by element removing 9732 //this.visibleOrder.$insertAt(id,Math.min(this.visibleOrder.length, tindex)); //insert at new position 9733 }, 9734 9735 move: function(sindex, tindex){ 9736 //gantt.assert(sindex>=0 && tindex>=0, "DataStore::move","Incorrect indexes"); 9737 9738 var id = this.getIdByIndex(sindex); 9739 var obj = this.getItem(id); 9740 this._moveInner(sindex, tindex); 9741 9742 9743 if (!this._skip_refresh) { 9744 //repaint signal 9745 this.callEvent("onStoreUpdated", [obj.id, obj, "move"]); 9746 } 9747 }, 9748 clearAll: function(){ 9749 this.pull = {}; 9750 this.visibleOrder = powerArray.$create(); 9751 this.fullOrder = powerArray.$create(); 9752 if (this._skip_refresh) return; 9753 this.callEvent("onClearAll",[]); 9754 this.refresh(); 9755 }, 9756 9757 silent:function(code, master){ 9758 this._skip_refresh = true; 9759 code.call(master||this); 9760 this._skip_refresh = false; 9761 }, 9762 9763 arraysEqual: function (arr1, arr2) { 9764 if(arr1.length !== arr2.length) 9765 return false; 9766 for(var i = 0; i < arr1.length; i++) { 9767 if(arr1[i] !== arr2[i]) 9768 return false; 9769 } 9770 9771 return true; 9772 }, 9773 9774 refresh: function(id, quick){ 9775 if (this._skip_refresh) return; 9776 9777 var args; 9778 if (id){ 9779 args = [id, this.pull[id], "paint"]; 9780 }else{ 9781 args = [null,null,null]; 9782 } 9783 9784 if(this.callEvent("onBeforeStoreUpdate", args) === false){ 9785 return; 9786 } 9787 9788 if(id){ 9789 // if item changes visible order (e.g. expand-collapse branch) - do a complete repaint 9790 if(!quick){ 9791 var oldOrder = this.visibleOrder; 9792 this.filter(); 9793 if(!this.arraysEqual(oldOrder, this.visibleOrder)){ 9794 id = undefined; 9795 } 9796 } 9797 9798 }else{ 9799 this.filter(); 9800 } 9801 9802 if (id){ 9803 args = [id, this.pull[id], "paint"]; 9804 }else{ 9805 args = [null,null,null]; 9806 } 9807 9808 this.callEvent("onStoreUpdated",args); 9809 }, 9810 9811 count: function(){ 9812 return this.fullOrder.length; 9813 }, 9814 countVisible: function(){ 9815 return this.visibleOrder.length; 9816 }, 9817 9818 sort: function(sort){}, 9819 9820 serialize: function(){}, 9821 9822 eachItem: function(code){ 9823 for (var i=0; i<this.fullOrder.length; i++) { 9824 var item = this.pull[this.fullOrder[i]]; 9825 code.call(this, item); 9826 } 9827 }, 9828 9829 filter: function(rule){ 9830 this.callEvent("onBeforeFilter", []); 9831 var filteredOrder = powerArray.$create(); 9832 this.eachItem(function(item){ 9833 if(this.callEvent("onFilterItem", [item.id, item])){ 9834 filteredOrder.push(item.id); 9835 } 9836 }); 9837 9838 this.visibleOrder = filteredOrder; 9839 this._searchVisibleOrder = {}; 9840 for(var i = 0; i < this.visibleOrder.length; i++){ 9841 this._searchVisibleOrder[this.visibleOrder[i]] = i; 9842 } 9843 this.callEvent("onFilter", []); 9844 }, 9845 9846 getIndexRange: function(from, to){ 9847 to=Math.min((to||Infinity),this.countVisible()-1); 9848 9849 var ret= []; 9850 for (var i=(from||0); i <= to; i++) 9851 ret.push(this.getItem(this.visibleOrder[i])); 9852 return ret; 9853 }, 9854 getItems: function(){ 9855 var res = []; 9856 for(var i in this.pull){ 9857 res.push(this.pull[i]); 9858 } 9859 /* for(var i = 0; i < this.fullOrder.length; i++){ 9860 9861 }*/ 9862 return res; 9863 }, 9864 9865 getIdByIndex: function(index){ 9866 return this.visibleOrder[index]; 9867 }, 9868 getIndexById: function(id){ 9869 var res = this._searchVisibleOrder[id]; 9870 if(res === undefined){ 9871 res = -1; 9872 } 9873 return res; 9874 }, 9875 _getNullIfUndefined: function(value){ 9876 if(value === undefined){ 9877 return null; 9878 }else{ 9879 return value; 9880 } 9881 }, 9882 getFirst: function(){ 9883 return this._getNullIfUndefined(this.visibleOrder[0]); 9884 }, 9885 getLast: function(){ 9886 return this._getNullIfUndefined(this.visibleOrder[this.visibleOrder.length-1]); 9887 }, 9888 getNext: function(id){ 9889 return this._getNullIfUndefined(this.visibleOrder[this.getIndexById(id) + 1]); 9890 }, 9891 getPrev: function(id){ 9892 return this._getNullIfUndefined(this.visibleOrder[this.getIndexById(id) - 1]); 9893 }, 9894 destructor: function(){ 9895 this.detachAllEvents(); 9896 this.pull = null; 9897 this.$initItem = null; 9898 this.visibleOrder = null; 9899 this.fullOrder = null; 9900 this._skip_refresh = null; 9901 this._filterRule = null; 9902 this._searchVisibleOrder = null; 9903 } 9904}; 9905 9906module.exports = DataStore; 9907 9908/***/ }), 9909 9910/***/ "./sources/core/datastore/datastore_hooks.js": 9911/*!***************************************************!*\ 9912 !*** ./sources/core/datastore/datastore_hooks.js ***! 9913 \***************************************************/ 9914/*! no static exports found */ 9915/***/ (function(module, exports, __webpack_require__) { 9916 9917var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 9918var facadeFactory = __webpack_require__(/*! ./../facades/datastore */ "./sources/core/facades/datastore.js"); 9919var calculateScaleRange = __webpack_require__(/*! ../gantt_data_range */ "./sources/core/gantt_data_range.js"); 9920function initDataStores(gantt){ 9921 9922 var facade = facadeFactory.create(); 9923 utils.mixin(gantt, facade); 9924 var tasksStore = gantt.createDatastore({ 9925 name: "task", 9926 type: "treeDatastore", 9927 rootId: function() { return gantt.config.root_id; }, 9928 initItem: utils.bind(_init_task, gantt), 9929 getConfig: function() { return gantt.config; } 9930 }); 9931 9932 var linksStore = gantt.createDatastore({ 9933 name: "link", 9934 initItem: utils.bind(_init_link, gantt) 9935 }); 9936 9937 gantt.attachEvent("onDestroy", function(){ 9938 tasksStore.destructor(); 9939 linksStore.destructor(); 9940 }); 9941 9942 tasksStore.attachEvent("onBeforeRefreshAll", function(){ 9943 9944 var order = tasksStore.getVisibleItems(); 9945 9946 for(var i=0; i < order.length; i++){ 9947 var item = order[i]; 9948 item.$index = i; 9949 gantt.resetProjectDates(item); 9950 } 9951 9952 }); 9953 9954 tasksStore.attachEvent("onFilterItem", function(id, task) { 9955 if (gantt.config.show_tasks_outside_timescale) { 9956 return true; 9957 } 9958 var min = null, max = null; 9959 if (gantt.config.start_date && gantt.config.end_date) { 9960 if (gantt._isAllowedUnscheduledTask(task)) return true; 9961 min = gantt.config.start_date.valueOf(); 9962 max = gantt.config.end_date.valueOf(); 9963 9964 if (+task.start_date > max || +task.end_date < +min) 9965 return false; 9966 } 9967 return true; 9968 }); 9969 9970 tasksStore.attachEvent("onIdChange", function(oldId, newId){ 9971 gantt._update_flags(oldId, newId); 9972 }); 9973 9974 tasksStore.attachEvent("onAfterUpdate", function(id){ 9975 gantt._update_parents(id); 9976 if(gantt.getState("batchUpdate").batch_update){ 9977 return true; 9978 } 9979 9980 var task = tasksStore.getItem(id); 9981 for (var i = 0; i < task.$source.length; i++) { 9982 linksStore.refresh(task.$source[i]); 9983 } 9984 for (var i = 0; i < task.$target.length; i++) { 9985 linksStore.refresh(task.$target[i]); 9986 } 9987 }); 9988 9989 tasksStore.attachEvent("onAfterItemMove", function(sid, parent, tindex){ 9990 var source = gantt.getTask(sid); 9991 9992 if(this.getNextSibling(sid) !== null){ 9993 source.$drop_target = this.getNextSibling(sid); 9994 } else if(this.getPrevSibling(sid) !== null){ 9995 source.$drop_target = "next:" + this.getPrevSibling(sid); 9996 }else{ 9997 source.$drop_target = "next:null"; 9998 } 9999 10000 }); 10001 10002 tasksStore.attachEvent("onStoreUpdated", function(id, item, action){ 10003 if(action == "delete"){ 10004 gantt._update_flags(id, null); 10005 } 10006 10007 var state = gantt.$services.getService("state"); 10008 if(state.getState("batchUpdate").batch_update){ 10009 return; 10010 } 10011 10012 if(gantt.config.fit_tasks && action !== "paint"){ 10013 var oldState = gantt.getState(); 10014 calculateScaleRange(gantt); 10015 var newState = gantt.getState(); 10016 10017 //this._init_tasks_range(); 10018 if (+oldState.min_date != +newState.min_date || +oldState.max_date != +newState.max_date) { 10019 gantt.render(); 10020 10021 gantt.callEvent("onScaleAdjusted", []); 10022 return true; 10023 } 10024 10025 } 10026 10027 if(action == "add" || action == "move" || action == "delete"){ 10028 gantt.$layout.resize(); 10029 }else if(!id){ 10030 linksStore.refresh(); 10031 } 10032 10033 }); 10034 10035 linksStore.attachEvent("onAfterAdd", function(id, link){ 10036 sync_link(link); 10037 }); 10038 linksStore.attachEvent("onAfterUpdate", function(id, link){ 10039 sync_links(); 10040 }); 10041 linksStore.attachEvent("onAfterDelete", function(id, link){ 10042 sync_link_delete(link); 10043 }); 10044 linksStore.attachEvent("onBeforeIdChange", function(oldId, newId){ 10045 sync_link_delete(gantt.mixin({id:oldId}, gantt.$data.linksStore.getItem(newId))); 10046 sync_link(gantt.$data.linksStore.getItem(newId)); 10047 }); 10048 10049 function checkLinkedTaskVisibility(taskId){ 10050 var isVisible = gantt.isTaskVisible(taskId); 10051 if(!isVisible && gantt.isTaskExists(taskId)){ 10052 var parent = gantt.getParent(taskId); 10053 if(gantt.isTaskExists(parent) && gantt.isTaskVisible(parent)){ 10054 parent = gantt.getTask(parent); 10055 if(gantt.isSplitTask(parent)){ 10056 isVisible = true; 10057 } 10058 } 10059 } 10060 return isVisible; 10061 } 10062 10063 linksStore.attachEvent("onFilterItem", function(id, link){ 10064 if (!gantt.config.show_links) { 10065 return false; 10066 } 10067 10068 var sourceVisible = checkLinkedTaskVisibility(link.source); 10069 var targetVisible = checkLinkedTaskVisibility(link.target); 10070 10071 if (!(sourceVisible && targetVisible) || 10072 gantt._isAllowedUnscheduledTask(gantt.getTask(link.source)) || gantt._isAllowedUnscheduledTask(gantt.getTask(link.target))) 10073 return false; 10074 10075 return gantt.callEvent("onBeforeLinkDisplay", [id, link]); 10076 }); 10077 10078 10079 (function(){ 10080 // delete all connected links after task is deleted 10081 var treeHelper = __webpack_require__(/*! ../../utils/task_tree_helpers */ "./sources/utils/task_tree_helpers.js"); 10082 var deletedLinks = {}; 10083 10084 gantt.attachEvent("onBeforeTaskDelete", function(id, item){ 10085 deletedLinks[id] = treeHelper.getSubtreeLinks(gantt, id); 10086 return true; 10087 }); 10088 10089 gantt.attachEvent("onAfterTaskDelete", function(id, item) { 10090 if(deletedLinks[id]){ 10091 gantt.$data.linksStore.silent(function(){ 10092 for(var i in deletedLinks[id]){ 10093 gantt.$data.linksStore.removeItem(i); 10094 sync_link_delete(deletedLinks[id][i]); 10095 } 10096 10097 deletedLinks[id] = null; 10098 }); 10099 } 10100 }); 10101 })(); 10102 10103 gantt.attachEvent("onAfterLinkDelete", function(id, link) { 10104 gantt.refreshTask(link.source); 10105 gantt.refreshTask(link.target); 10106 }); 10107 10108 gantt.attachEvent("onParse", sync_links); 10109 10110 mapEvents({ 10111 source: linksStore, 10112 target: gantt, 10113 events:{ 10114 "onItemLoading":"onLinkLoading", 10115 "onBeforeAdd":"onBeforeLinkAdd", 10116 "onAfterAdd":"onAfterLinkAdd", 10117 "onBeforeUpdate":"onBeforeLinkUpdate", 10118 "onAfterUpdate":"onAfterLinkUpdate", 10119 "onBeforeDelete":"onBeforeLinkDelete", 10120 "onAfterDelete":"onAfterLinkDelete", 10121 "onIdChange":"onLinkIdChange" 10122 } 10123 }); 10124 10125 mapEvents({ 10126 source: tasksStore, 10127 target: gantt, 10128 events:{ 10129 "onItemLoading":"onTaskLoading", 10130 "onBeforeAdd":"onBeforeTaskAdd", 10131 "onAfterAdd":"onAfterTaskAdd", 10132 "onBeforeUpdate":"onBeforeTaskUpdate", 10133 "onAfterUpdate":"onAfterTaskUpdate", 10134 "onBeforeDelete":"onBeforeTaskDelete", 10135 "onAfterDelete":"onAfterTaskDelete", 10136 "onIdChange":"onTaskIdChange", 10137 "onBeforeItemMove":"onBeforeTaskMove", 10138 "onAfterItemMove":"onAfterTaskMove", 10139 "onFilterItem":"onBeforeTaskDisplay", 10140 "onItemOpen":"onTaskOpened", 10141 "onItemClose":"onTaskClosed", 10142 "onBeforeSelect":"onBeforeTaskSelected", 10143 "onAfterSelect":"onTaskSelected", 10144 "onAfterUnselect":"onTaskUnselected" 10145 } 10146 }); 10147 10148 gantt.$data = { 10149 tasksStore: tasksStore, 10150 linksStore: linksStore 10151 }; 10152 10153 function sync_link(link){ 10154 if(gantt.isTaskExists(link.source)){ 10155 var sourceTask = gantt.getTask(link.source); 10156 sourceTask.$source = sourceTask.$source || []; 10157 sourceTask.$source.push(link.id); 10158 } 10159 if(gantt.isTaskExists(link.target)){ 10160 var targetTask = gantt.getTask(link.target); 10161 targetTask.$target = targetTask.$target || []; 10162 targetTask.$target.push(link.id); 10163 } 10164 } 10165 10166 function sync_link_delete(link){ 10167 if(gantt.isTaskExists(link.source)){ 10168 var sourceTask = gantt.getTask(link.source); 10169 for(var i = 0; i < sourceTask.$source.length; i++){ 10170 if(sourceTask.$source[i] == link.id){ 10171 sourceTask.$source.splice(i, 1); 10172 break; 10173 } 10174 } 10175 } 10176 if(gantt.isTaskExists(link.target)){ 10177 var targetTask = gantt.getTask(link.target); 10178 for(var i = 0; i < targetTask.$target.length; i++){ 10179 if(targetTask.$target[i] == link.id){ 10180 targetTask.$target.splice(i, 1); 10181 break; 10182 } 10183 } 10184 } 10185 } 10186 10187 function sync_links() { 10188 var task = null; 10189 var tasks = gantt.$data.tasksStore.getItems(); 10190 10191 for(var i = 0, len = tasks.length; i < len; i++){ 10192 task = tasks[i]; 10193 task.$source = []; 10194 task.$target = []; 10195 } 10196 10197 var links = gantt.$data.linksStore.getItems(); 10198 for (var i = 0, len = links.length; i < len; i++) { 10199 10200 var link = links[i]; 10201 sync_link(link); 10202 } 10203 } 10204 10205 function mapEvents(conf){ 10206 var mapFrom = conf.source; 10207 var mapTo = conf.target; 10208 for(var i in conf.events){ 10209 (function(sourceEvent, targetEvent){ 10210 mapFrom.attachEvent(sourceEvent, function(){ 10211 return mapTo.callEvent(targetEvent, Array.prototype.slice.call(arguments)); 10212 }, targetEvent); 10213 })(i, conf.events[i]); 10214 } 10215 } 10216 10217 function _init_task(task) { 10218 if (!this.defined(task.id)) 10219 task.id = this.uid(); 10220 10221 if (task.start_date) 10222 task.start_date = gantt.date.parseDate(task.start_date, "parse_date"); 10223 if (task.end_date) 10224 task.end_date = gantt.date.parseDate(task.end_date, "parse_date"); 10225 10226 10227 var duration = null; 10228 if (task.duration || task.duration === 0) { 10229 task.duration = duration = task.duration * 1; 10230 } 10231 10232 if (duration) { 10233 if (task.start_date && !task.end_date) { 10234 task.end_date = this.calculateEndDate(task); 10235 } else if (!task.start_date && task.end_date) { 10236 task.start_date = this.calculateEndDate({ 10237 start_date: task.end_date, 10238 duration: -task.duration, 10239 task: task 10240 }); 10241 } 10242 } 10243 10244 task.progress = Number(task.progress) || 0; 10245 10246 if (this._isAllowedUnscheduledTask(task)) { 10247 this._set_default_task_timing(task); 10248 } 10249 this._init_task_timing(task); 10250 if (task.start_date && task.end_date) 10251 this.correctTaskWorkTime(task); 10252 10253 task.$source = []; 10254 task.$target = []; 10255 10256 var originalTask = this.$data.tasksStore.getItem(task.id); 10257 if (originalTask && !utils.defined(task.open)) { 10258 // if a task with the same id is already in the gantt and the new object doesn't specify the `open` state - 10259 // restore the `open` state we already have in the chart 10260 task.$open = originalTask.$open; 10261 } 10262 10263 if (task.parent === undefined) { 10264 task.parent = this.config.root_id; 10265 } 10266 return task; 10267 } 10268 10269 function _init_link(link) { 10270 if (!this.defined(link.id)) 10271 link.id = this.uid(); 10272 return link; 10273 } 10274} 10275 10276 10277module.exports = initDataStores; 10278 10279 10280/***/ }), 10281 10282/***/ "./sources/core/datastore/datastore_render.js": 10283/*!****************************************************!*\ 10284 !*** ./sources/core/datastore/datastore_render.js ***! 10285 \****************************************************/ 10286/*! no static exports found */ 10287/***/ (function(module, exports) { 10288 10289var storeRenderCreator = function(name, gantt){ 10290 var store = gantt.getDatastore(name); 10291 10292 var itemRepainter = { 10293 renderItem: function(id, renderer){ 10294 10295 var renders = renderer.getLayers(); 10296 10297 var item = store.getItem(id); 10298 if(item && store.isVisible(id)) { 10299 for (var i = 0; i < renders.length; i++) 10300 renders[i].render_item(item); 10301 } 10302 }, 10303 renderItems: function(renderer){ 10304 var renderers = renderer.getLayers(); 10305 for (var i = 0; i < renderers.length; i++) { 10306 renderers[i].clear(); 10307 } 10308 10309 var data = store.getVisibleItems(); 10310 10311 for (var i = 0; i < renderers.length; i++) { 10312 renderers[i].render_items(data); 10313 } 10314 }, 10315 updateItems: function(layer) { 10316 if(layer.update_items){ 10317 var data = store.getVisibleItems(); 10318 layer.update_items(data); 10319 } 10320 } 10321 }; 10322 10323 store.attachEvent("onStoreUpdated", function(id, item, action){ 10324 var renderer = gantt.$services.getService("layers").getDataRender(name); 10325 if(renderer){ 10326 renderer.onUpdateRequest = function(layer){ 10327 itemRepainter.updateItems(layer); 10328 }; 10329 } 10330 }); 10331 10332 function skipRepaint(gantt){ 10333 var state = gantt.$services.getService("state"); 10334 if(state.getState("batchUpdate").batch_update){ 10335 return true; 10336 }else{ 10337 return false; 10338 } 10339 } 10340 10341 store.attachEvent("onStoreUpdated", function(id, item, action){ 10342 if(skipRepaint(gantt)){ 10343 return; 10344 } 10345 10346 var renderer = gantt.$services.getService("layers").getDataRender(name); 10347 10348 if(renderer){ 10349 if(!id || action == "move" || action == "delete"){ 10350 store.callEvent("onBeforeRefreshAll", []); 10351 itemRepainter.renderItems(renderer); 10352 store.callEvent("onAfterRefreshAll", []); 10353 }else{ 10354 store.callEvent("onBeforeRefreshItem", [item.id]); 10355 itemRepainter.renderItem(item.id, renderer); 10356 store.callEvent("onAfterRefreshItem", [item.id]); 10357 } 10358 } 10359 10360 }); 10361 10362 // TODO: probably can be done more in a more efficient way 10363 store.attachEvent("onItemOpen", function(){ 10364 gantt.render(); 10365 }); 10366 10367 store.attachEvent("onItemClose", function(){ 10368 gantt.render(); 10369 }); 10370 10371 function refreshId(renders, oldId, newId, item) { 10372 for (var i = 0; i < renders.length; i++) { 10373 renders[i].change_id(oldId, newId); 10374 } 10375 } 10376 10377 store.attachEvent("onIdChange", function(oldId, newId){ 10378 10379 // in case of linked datastores (tasks <-> links), id change should recalculate something in linked datastore before any repaint 10380 // use onBeforeIdChange for this hook. 10381 // TODO: use something more reasonable instead 10382 store.callEvent("onBeforeIdChange", [oldId, newId]); 10383 10384 if(skipRepaint(gantt)){ 10385 return; 10386 } 10387 var renderer = gantt.$services.getService("layers").getDataRender(name); 10388 refreshId(renderer.getLayers(), oldId, newId, store.getItem(newId)); 10389 itemRepainter.renderItem(newId, renderer); 10390 }); 10391 10392}; 10393 10394module.exports = { 10395 bindDataStore: storeRenderCreator 10396}; 10397 10398/***/ }), 10399 10400/***/ "./sources/core/datastore/power_array.js": 10401/*!***********************************************!*\ 10402 !*** ./sources/core/datastore/power_array.js ***! 10403 \***********************************************/ 10404/*! no static exports found */ 10405/***/ (function(module, exports, __webpack_require__) { 10406 10407var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 10408 10409var $powerArray = { 10410 $create: function(array){ 10411 return utils.mixin(array || [], this); 10412 }, 10413 //remove element at specified position 10414 $removeAt:function(pos,len){ 10415 if (pos>=0) this.splice(pos,(len||1)); 10416 }, 10417 //find element in collection and remove it 10418 $remove:function(value){ 10419 this.$removeAt(this.$find(value)); 10420 }, 10421 //add element to collection at specific position 10422 $insertAt:function(data,pos){ 10423 if (!pos && pos!==0) //add to the end by default 10424 this.push(data); 10425 else { 10426 var b = this.splice(pos,(this.length-pos)); 10427 this[pos] = data; 10428 this.push.apply(this,b); //reconstruct array without loosing this pointer 10429 } 10430 }, 10431 //return index of element, -1 if it doesn't exists 10432 $find:function(data){ 10433 for (var i=0; i<this.length; i++) 10434 if (data==this[i]) return i; 10435 return -1; 10436 }, 10437 //execute some method for each element of array 10438 $each:function(functor,master){ 10439 for (var i=0; i < this.length; i++) 10440 functor.call((master||this),this[i]); 10441 }, 10442 //create new array from source, by using results of functor 10443 $map:function(functor,master){ 10444 for (var i=0; i < this.length; i++) 10445 this[i]=functor.call((master||this),this[i]); 10446 return this; 10447 }, 10448 $filter:function(functor, master){ 10449 for (var i=0; i < this.length; i++) 10450 if (!functor.call((master||this),this[i])){ 10451 this.splice(i,1); 10452 i--; 10453 } 10454 return this; 10455 } 10456}; 10457 10458module.exports = $powerArray; 10459 10460/***/ }), 10461 10462/***/ "./sources/core/datastore/select.js": 10463/*!******************************************!*\ 10464 !*** ./sources/core/datastore/select.js ***! 10465 \******************************************/ 10466/*! no static exports found */ 10467/***/ (function(module, exports) { 10468 10469function createDataStoreSelectMixin(store){ 10470 var selectedId = null; 10471 10472 var deleteItem = store._removeItemInner; 10473 10474 function unselect(id){ 10475 selectedId = null; 10476 this.callEvent("onAfterUnselect", [id]); 10477 } 10478 10479 store._removeItemInner = function(id){ 10480 if(selectedId == id){ 10481 unselect.call(this, id); 10482 } 10483 10484 if(selectedId && this.eachItem){ 10485 this.eachItem(function(subItem){ 10486 if(subItem.id == selectedId){ 10487 unselect.call(this, subItem.id); 10488 } 10489 }, id); 10490 } 10491 10492 return deleteItem.apply(this, arguments); 10493 }; 10494 10495 store.attachEvent("onIdChange", function(oldId, newId) { 10496 if (store.getSelectedId() == oldId) { 10497 store.silent(function () { 10498 store.unselect(oldId); 10499 store.select(newId); 10500 }); 10501 } 10502 }); 10503 10504 return { 10505 select: function(id){ 10506 if (id){ 10507 10508 if(selectedId == id) 10509 return selectedId; 10510 10511 if(!this._skip_refresh) { 10512 if (!this.callEvent("onBeforeSelect", [id])) { 10513 return false; 10514 } 10515 } 10516 10517 this.unselect(); 10518 10519 selectedId = id; 10520 10521 if(!this._skip_refresh) { 10522 this.refresh(id); 10523 this.callEvent("onAfterSelect", [id]); 10524 } 10525 } 10526 return selectedId; 10527 }, 10528 getSelectedId: function(){ 10529 return selectedId; 10530 }, 10531 isSelected: function(id){ 10532 return id == selectedId; 10533 }, 10534 unselect: function(id){ 10535 var id = id || selectedId; 10536 if(!id) 10537 return; 10538 selectedId = null; 10539 if(!this._skip_refresh){ 10540 this.refresh(id); 10541 unselect.call(this, id); 10542 } 10543 } 10544 }; 10545} 10546 10547module.exports = createDataStoreSelectMixin; 10548 10549/***/ }), 10550 10551/***/ "./sources/core/datastore/treedatastore.js": 10552/*!*************************************************!*\ 10553 !*** ./sources/core/datastore/treedatastore.js ***! 10554 \*************************************************/ 10555/*! no static exports found */ 10556/***/ (function(module, exports, __webpack_require__) { 10557 10558var powerArray = __webpack_require__(/*! ./power_array */ "./sources/core/datastore/power_array.js"); 10559var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 10560var DataStore = __webpack_require__(/*! ./datastore */ "./sources/core/datastore/datastore.js"); 10561 10562var TreeDataStore = function(config){ 10563 DataStore.apply(this, [config]); 10564 this._branches = {}; 10565 10566 this.pull = {}; 10567 this.$initItem = config.initItem; 10568 this.$parentProperty = config.parentProperty || "parent"; 10569 10570 if(typeof config.rootId !== "function"){ 10571 this.$getRootId = (function(val){ 10572 return function(){return val;}; 10573 })(config.rootId || 0); 10574 }else{ 10575 this.$getRootId = config.rootId; 10576 } 10577 10578 // TODO: replace with live reference to gantt config 10579 this.$openInitially = config.openInitially; 10580 10581 this.visibleOrder = powerArray.$create(); 10582 this.fullOrder = powerArray.$create(); 10583 this._searchVisibleOrder = {}; 10584 this._skip_refresh = false; 10585 10586 this._ganttConfig = null; 10587 if(config.getConfig){ 10588 this._ganttConfig = config.getConfig(); 10589 } 10590 10591 this.attachEvent("onFilterItem", function(id, item){ 10592 10593 var canOpenSplitTasks = false; 10594 if(this._ganttConfig){ 10595 var canOpenSplitTasks = this._ganttConfig.open_split_tasks; 10596 } 10597 10598 var open = true; 10599 this.eachParent(function(parent){ 10600 open = open && parent.$open && (canOpenSplitTasks || !this._isSplitItem(parent)); 10601 }, item); 10602 return !!open; 10603 }); 10604 10605 return this; 10606}; 10607 10608TreeDataStore.prototype = utils.mixin({ 10609 10610 _buildTree: function(data){ 10611 var item = null; 10612 var rootId = this.$getRootId(); 10613 for (var i = 0, len = data.length; i < len; i++){ 10614 item = data[i]; 10615 this.setParent(item, this.getParent(item) || rootId); 10616 } 10617 10618 // calculating $level for each item 10619 for (var i = 0, len = data.length; i < len; i++){ 10620 item = data[i]; 10621 this._add_branch(item); 10622 item.$level = this.calculateItemLevel(item); 10623 10624 if (!utils.defined(item.$open)) { 10625 item.$open = utils.defined(item.open) ? item.open : this.$openInitially(); 10626 } 10627 10628 } 10629 this._updateOrder(); 10630 }, 10631 _isSplitItem: function(item){ 10632 return (item.render == "split" && this.hasChild(item.id)); 10633 }, 10634 parse: function(data){ 10635 this.callEvent("onBeforeParse", [data]); 10636 var loaded = this._parseInner(data); 10637 this._buildTree(loaded); 10638 this.filter(); 10639 this.callEvent("onParse", [loaded]); 10640 }, 10641 10642 _addItemInner: function(item, index){ 10643 10644 var parent = this.getParent(item); 10645 10646 if(!utils.defined(parent)){ 10647 parent = this.$getRootId(); 10648 this.setParent(item, parent); 10649 } 10650 10651 var parentIndex = this.getIndexById(parent); 10652 var targetIndex = parentIndex + Math.min(Math.max(index, 0), this.visibleOrder.length); 10653 10654 if(targetIndex*1 !== targetIndex){ 10655 targetIndex = undefined; 10656 } 10657 DataStore.prototype._addItemInner.call(this, item, targetIndex); 10658 this.setParent(item, parent); 10659 10660 if(item.hasOwnProperty("$rendered_parent")){ 10661 this._move_branch(item, item.$rendered_parent); 10662 } 10663 this._add_branch(item, index); 10664 }, 10665 _changeIdInner: function(oldId, newId){ 10666 var children = this.getChildren(oldId); 10667 var visibleOrder = this._searchVisibleOrder[oldId]; 10668 10669 DataStore.prototype._changeIdInner.call(this, oldId, newId); 10670 10671 var parent = this.getParent(newId); 10672 10673 this._replace_branch_child(parent, oldId, newId); 10674 for(var i = 0; i < children.length; i++){ 10675 this.setParent(this.getItem(children[i]), newId); 10676 } 10677 10678 this._searchVisibleOrder[newId] = visibleOrder; 10679 delete this._branches[oldId]; 10680 }, 10681 10682 _traverseBranches: function(code, parent){ 10683 parent = parent || this.$getRootId(); 10684 var branch = this._branches[parent]; 10685 if (branch) { 10686 for (var i = 0; i < branch.length; i++) { 10687 var itemId = branch[i]; 10688 code.call(this, itemId); 10689 if (this._branches[itemId]) 10690 this._traverseBranches(code, itemId); 10691 } 10692 } 10693 }, 10694 10695 _updateOrder: function(code){ 10696 10697 this.fullOrder = powerArray.$create(); 10698 this._traverseBranches(function(taskId){ 10699 this.fullOrder.push(taskId); 10700 }); 10701 10702 if(code) 10703 DataStore.prototype._updateOrder.call(this, code); 10704 }, 10705 10706 _removeItemInner: function(id){ 10707 10708 var items = []; 10709 this.eachItem(function(child){ 10710 items.push(child); 10711 }, id); 10712 10713 items.push(this.getItem(id)); 10714 10715 for(var i = 0; i < items.length; i++){ 10716 10717 this._move_branch(items[i], this.getParent(items[i]), null); 10718 DataStore.prototype._removeItemInner.call(this, items[i].id); 10719 this._move_branch(items[i], this.getParent(items[i]), null); 10720 } 10721 }, 10722 10723 move: function(sid, tindex, parent){ 10724 //target id as 4th parameter 10725 var id = arguments[3]; 10726 if (id) { 10727 if (id === sid) return; 10728 10729 parent = this.getParent(id); 10730 tindex = this.getBranchIndex(id); 10731 } 10732 if(sid == parent){ 10733 return; 10734 } 10735 parent = parent || this.$getRootId(); 10736 var source = this.getItem(sid); 10737 var source_pid = this.getParent(source.id); 10738 10739 var tbranch = this.getChildren(parent); 10740 10741 if (tindex == -1) 10742 tindex = tbranch.length + 1; 10743 if (source_pid == parent) { 10744 var sindex = this.getBranchIndex(sid); 10745 if (sindex == tindex) return; 10746 } 10747 10748 if(this.callEvent("onBeforeItemMove", [sid, parent, tindex]) === false) 10749 return false; 10750 10751 this._replace_branch_child(source_pid, sid); 10752 tbranch = this.getChildren(parent); 10753 10754 var tid = tbranch[tindex]; 10755 if (!tid) //adding as last element 10756 tbranch.push(sid); 10757 else 10758 tbranch = tbranch.slice(0, tindex).concat([ sid ]).concat(tbranch.slice(tindex)); 10759 10760 this.setParent(source, parent); 10761 this._branches[parent] = tbranch; 10762 10763 var diff = this.calculateItemLevel(source) - source.$level; 10764 source.$level += diff; 10765 this.eachItem(function(item){ 10766 item.$level += diff; 10767 }, source.id, this); 10768 10769 10770 this._moveInner(this.getIndexById(sid), this.getIndexById(parent) + tindex); 10771 10772 this.callEvent("onAfterItemMove", [sid, parent, tindex]); 10773 this.refresh(); 10774 }, 10775 10776 getBranchIndex: function(id){ 10777 var branch = this.getChildren(this.getParent(id)); 10778 for (var i = 0; i < branch.length; i++) 10779 if (branch[i] == id) 10780 return i; 10781 10782 return -1; 10783 }, 10784 hasChild: function(id){ 10785 return (utils.defined(this._branches[id]) && this._branches[id].length); 10786 }, 10787 getChildren: function(id){ 10788 return utils.defined(this._branches[id]) ? this._branches[id] : powerArray.$create(); 10789 }, 10790 10791 isChildOf: function(childId, parentId){ 10792 if (!this.exists(childId)) 10793 return false; 10794 if (parentId === this.$getRootId()) 10795 return true; 10796 10797 if (!this.hasChild(parentId)) 10798 return false; 10799 10800 var item = this.getItem(childId); 10801 var pid = this.getParent(childId); 10802 10803 var parent = this.getItem(parentId); 10804 if(parent.$level >= item.$level){ 10805 return false; 10806 } 10807 10808 while (item && this.exists(pid)) { 10809 item = this.getItem(pid); 10810 10811 if (item && item.id == parentId) 10812 return true; 10813 pid = this.getParent(item); 10814 } 10815 return false; 10816 }, 10817 10818 getSiblings: function(id){ 10819 if(!this.exists(id)){ 10820 return powerArray.$create(); 10821 } 10822 var parent = this.getParent(id); 10823 return this.getChildren(parent); 10824 10825 }, 10826 getNextSibling: function(id){ 10827 var siblings = this.getSiblings(id); 10828 for(var i= 0, len = siblings.length; i < len; i++){ 10829 if(siblings[i] == id) 10830 return siblings[i+1] || null; 10831 } 10832 return null; 10833 }, 10834 getPrevSibling: function(id){ 10835 var siblings = this.getSiblings(id); 10836 for(var i= 0, len = siblings.length; i < len; i++){ 10837 if(siblings[i] == id) 10838 return siblings[i-1] || null; 10839 } 10840 return null; 10841 }, 10842 getParent: function(id){ 10843 var item = null; 10844 if(id.id !== undefined){ 10845 item = id; 10846 }else{ 10847 item = this.getItem(id); 10848 } 10849 10850 var parent; 10851 if(item){ 10852 parent = item[this.$parentProperty]; 10853 }else{ 10854 parent = this.$getRootId(); 10855 } 10856 return parent; 10857 10858 }, 10859 10860 clearAll: function(){ 10861 this._branches = {}; 10862 DataStore.prototype.clearAll.call(this); 10863 }, 10864 10865 calculateItemLevel: function(item){ 10866 var level = 0; 10867 this.eachParent(function(){ 10868 level++; 10869 }, item); 10870 return level; 10871 }, 10872 10873 _setParentInner: function(item, new_pid, silent){ 10874 if(!silent){ 10875 if(item.hasOwnProperty("$rendered_parent")){ 10876 this._move_branch(item, item.$rendered_parent, new_pid); 10877 }else{ 10878 this._move_branch(item, item[this.$parentProperty], new_pid); 10879 } 10880 } 10881 }, 10882 setParent: function(item, new_pid, silent){ 10883 this._setParentInner(item, new_pid, silent); 10884 10885 item[this.$parentProperty] = new_pid; 10886 }, 10887 eachItem: function(code, parent){ 10888 parent = parent || this.$getRootId(); 10889 10890 10891 var branch = this.getChildren(parent); 10892 if (branch) 10893 for (var i=0; i<branch.length; i++){ 10894 var item = this.pull[branch[i]]; 10895 code.call(this, item); 10896 if (this.hasChild(item.id)) 10897 this.eachItem(code, item.id); 10898 } 10899 }, 10900 eachParent: function(code, startItem) { 10901 var parentsHash = {}; 10902 var item = startItem; 10903 var parent = this.getParent(item); 10904 10905 while (this.exists(parent)) { 10906 if (parentsHash[parent]) { 10907 throw new Error("Invalid tasks tree. Cyclic reference has been detected on task " + parent); 10908 } 10909 parentsHash[parent] = true; 10910 item = this.getItem(parent); 10911 code.call(this, item); 10912 parent = this.getParent(item); 10913 } 10914 }, 10915 _add_branch: function(item, index, parent){ 10916 var pid = parent === undefined ? this.getParent(item) : parent; 10917 if (!this.hasChild(pid)) 10918 this._branches[pid] = powerArray.$create(); 10919 var branch = this.getChildren(pid); 10920 var added_already = false; 10921 for(var i = 0, length = branch.length; i < length; i++){ 10922 if(branch[i] == item.id){ 10923 added_already = true; 10924 break; 10925 } 10926 } 10927 if(!added_already){ 10928 if(index*1 == index){ 10929 10930 branch.splice(index, 0, item.id); 10931 }else{ 10932 branch.push(item.id); 10933 } 10934 10935 item.$rendered_parent = pid; 10936 } 10937 }, 10938 _move_branch: function(item, old_parent, new_parent){ 10939 //this.setParent(item, new_parent); 10940 //this._sync_parent(task); 10941 this._replace_branch_child(old_parent, item.id); 10942 if(this.exists(new_parent) || new_parent == this.$getRootId()){ 10943 10944 this._add_branch(item, undefined, new_parent); 10945 }else{ 10946 delete this._branches[item.id]; 10947 } 10948 item.$level = this.calculateItemLevel(item); 10949 this.eachItem(function(child){ 10950 child.$level = this.calculateItemLevel(child); 10951 }, item.id); 10952 }, 10953 10954 _replace_branch_child: function(node, old_id, new_id){ 10955 var branch = this.getChildren(node); 10956 if (branch && node !== undefined){ 10957 var newbranch = powerArray.$create(); 10958 for (var i=0; i<branch.length; i++){ 10959 if (branch[i] != old_id) 10960 newbranch.push(branch[i]); 10961 else if (new_id) 10962 newbranch.push(new_id); 10963 } 10964 this._branches[node] = newbranch; 10965 } 10966 10967 }, 10968 10969 sort: function(field, desc, parent){ 10970 if (!this.exists(parent)) { 10971 parent = this.$getRootId(); 10972 } 10973 10974 if (!field) field = "order"; 10975 var criteria = (typeof(field) == "string") ? (function(a, b) { 10976 if(a[field] == b[field]){ 10977 return 0; 10978 } 10979 10980 var result = a[field] > b[field]; 10981 return result ? 1 : -1; 10982 }) : field; 10983 10984 if (desc) { 10985 var original_criteria = criteria; 10986 criteria = function (a, b) { 10987 return original_criteria(b, a); 10988 }; 10989 } 10990 10991 var els = this.getChildren(parent); 10992 10993 if (els){ 10994 var temp = []; 10995 for (var i = els.length - 1; i >= 0; i--) 10996 temp[i] = this.getItem(els[i]); 10997 10998 temp.sort(criteria); 10999 11000 for (var i = 0; i < temp.length; i++) { 11001 els[i] = temp[i].id; 11002 this.sort(field, desc, els[i]); 11003 } 11004 } 11005 }, 11006 11007 filter: function(rule){ 11008 for(var i in this.pull){ 11009 if(this.pull[i].$rendered_parent !== this.getParent(this.pull[i])){ 11010 this._move_branch(this.pull[i], this.pull[i].$rendered_parent, this.getParent(this.pull[i])); 11011 } 11012 } 11013 return DataStore.prototype.filter.apply(this, arguments); 11014 }, 11015 11016 open: function(id){ 11017 if(this.exists(id)){ 11018 this.getItem(id).$open = true; 11019 this.callEvent("onItemOpen", [id]); 11020 } 11021 }, 11022 11023 close: function(id){ 11024 if(this.exists(id)){ 11025 this.getItem(id).$open = false; 11026 this.callEvent("onItemClose", [id]); 11027 } 11028 }, 11029 11030 destructor: function(){ 11031 DataStore.prototype.destructor.call(this); 11032 this._branches = null; 11033 } 11034 }, 11035 DataStore.prototype 11036); 11037 11038module.exports = TreeDataStore; 11039 11040/***/ }), 11041 11042/***/ "./sources/core/deprecated_warnings.js": 11043/*!*********************************************!*\ 11044 !*** ./sources/core/deprecated_warnings.js ***! 11045 \*********************************************/ 11046/*! no static exports found */ 11047/***/ (function(module, exports) { 11048 11049module.exports = function(gantt){ 11050 11051 // no deprecated methods for now 11052 11053 // eslint-disable-next-line no-unused-vars 11054 function deprecated(badCode, goodCode, versionDeprecated, versionDeleted) { 11055 11056 var formatting = gantt.env.isIE ? "" : "%c"; 11057 versionDeprecated = versionDeprecated || "v6.0"; 11058 versionDeleted = versionDeleted || "v7.0"; 11059 11060 var message = [ 11061 formatting, "\"", badCode, "\"", formatting, 11062 " has been deprecated in dhtmlxGantt ", versionDeprecated, " and will stop working in ", versionDeleted,". Use ", 11063 formatting, "\"", goodCode, "\"", formatting, 11064 " instead. \nSee more details at http://docs.dhtmlx.com/gantt/migrating.html " 11065 ].join(""); 11066 11067 var log = window.console.warn || window.console.log; 11068 11069 var args = [message]; 11070 if(!gantt.env.isIE){ 11071 args = args.concat(["font-weight:bold", "font-weight:normal", "font-weight:bold", "font-weight:normal"]); 11072 } 11073 11074 log.apply(window.console, args); 11075 } 11076 11077 // gantt.getSlack is defined inside an extension, leave it without message for now 11078 11079}; 11080 11081/***/ }), 11082 11083/***/ "./sources/core/destructor.js": 11084/*!************************************!*\ 11085 !*** ./sources/core/destructor.js ***! 11086 \************************************/ 11087/*! no static exports found */ 11088/***/ (function(module, exports) { 11089 11090function extend(gantt){ 11091 11092 gantt.destructor = function(){ 11093 gantt.callEvent("onDestroy", []); 11094 this.clearAll(); 11095 11096 if(this.$root){ 11097 delete this.$root.gantt; 11098 } 11099 11100 this._eventRemoveAll(); 11101 if(this.$layout){ 11102 this.$layout.destructor(); 11103 } 11104 11105 this.resetLightbox(); 11106 11107 if(this._dp && this._dp.destructor){ 11108 this._dp.destructor(); 11109 } 11110 this.$services.destructor(); 11111 11112 // detachAllEvents should be called last, because in components may be attached events 11113 this.detachAllEvents(); 11114 11115 for(var i in this){ 11116 if(i.indexOf("$") === 0){ 11117 delete this[i]; 11118 } 11119 } 11120 gantt.$destroyed = true; 11121 }; 11122} 11123 11124module.exports = extend; 11125 11126 11127/***/ }), 11128 11129/***/ "./sources/core/dynamic_loading.gpl.js": 11130/*!*********************************************!*\ 11131 !*** ./sources/core/dynamic_loading.gpl.js ***! 11132 \*********************************************/ 11133/*! no static exports found */ 11134/***/ (function(module, exports) { 11135 11136module.exports = function(gantt) { 11137}; 11138 11139/***/ }), 11140 11141/***/ "./sources/core/facades/datastore.js": 11142/*!*******************************************!*\ 11143 !*** ./sources/core/facades/datastore.js ***! 11144 \*******************************************/ 11145/*! no static exports found */ 11146/***/ (function(module, exports, __webpack_require__) { 11147 11148var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 11149var createTasksFacade = __webpack_require__(/*! ./datastore_tasks */ "./sources/core/facades/datastore_tasks.js"), 11150 createLinksFacade = __webpack_require__(/*! ./datastore_links */ "./sources/core/facades/datastore_links.js"), 11151 DataStore = __webpack_require__(/*! ../datastore/datastore */ "./sources/core/datastore/datastore.js"), 11152 TreeDataStore = __webpack_require__(/*! ../datastore/treedatastore */ "./sources/core/datastore/treedatastore.js"), 11153 createDatastoreSelect = __webpack_require__(/*! ../datastore/select */ "./sources/core/datastore/select.js"); 11154var datastoreRender = __webpack_require__(/*! ../datastore/datastore_render */ "./sources/core/datastore/datastore_render.js"); 11155 11156function getDatastores(){ 11157 var storeNames = this.$services.getService("datastores"); 11158 var res = []; 11159 for(var i = 0; i < storeNames.length; i++){ 11160 res.push(this.getDatastore(storeNames[i])); 11161 } 11162 return res; 11163} 11164 11165var createDatastoreFacade = function(){ 11166 return { 11167 createDatastore: function(config){ 11168 11169 var $StoreType = (config.type || "").toLowerCase() == "treedatastore" ? TreeDataStore : DataStore; 11170 11171 if (config) { 11172 var self = this; 11173 config.openInitially = function(){ return self.config.open_tree_initially; }; 11174 } 11175 11176 var store = new $StoreType(config); 11177 this.mixin(store, createDatastoreSelect(store)); 11178 11179 if (config.name) { 11180 var servicePrefix = "datastore:"; 11181 11182 this.$services.dropService(servicePrefix + config.name); 11183 this.$services.setService(servicePrefix + config.name, function() { return store; } ); 11184 11185 var storeList = this.$services.getService("datastores"); 11186 if (!storeList) { 11187 storeList = []; 11188 this.$services.setService("datastores", function() { return storeList; }); 11189 storeList.push(config.name); 11190 } else if (storeList.indexOf(config.name) < 0) { 11191 storeList.push(config.name); 11192 } 11193 11194 datastoreRender.bindDataStore(config.name, this); 11195 } 11196 11197 return store; 11198 }, 11199 getDatastore: function(name){ 11200 return this.$services.getService("datastore:" + name); 11201 }, 11202 11203 refreshData: function () { 11204 var scrollState = this.getScrollState(); 11205 this.callEvent("onBeforeDataRender", []); 11206 11207 var stores = getDatastores.call(this); 11208 for(var i = 0; i < stores.length; i++){ 11209 stores[i].refresh(); 11210 } 11211 11212 if(scrollState.x || scrollState.y){ 11213 this.scrollTo(scrollState.x, scrollState.y); 11214 } 11215 this.callEvent("onDataRender", []); 11216 }, 11217 11218 isChildOf: function(childId, parentId){ 11219 return this.$data.tasksStore.isChildOf(childId, parentId); 11220 }, 11221 11222 refreshTask: function (taskId, refresh_links) { 11223 var task = this.getTask(taskId); 11224 if (task && this.isTaskVisible(taskId)) { 11225 11226 this.$data.tasksStore.refresh(taskId, !!this.getState().drag_id);// do quick refresh during drag and drop 11227 11228 if (refresh_links !== undefined && !refresh_links) 11229 return; 11230 for (var i = 0; i < task.$source.length; i++) { 11231 this.refreshLink(task.$source[i]); 11232 } 11233 for (var i = 0; i < task.$target.length; i++) { 11234 this.refreshLink(task.$target[i]); 11235 } 11236 }else if(this.isTaskExists(taskId) && this.isTaskExists(this.getParent(taskId))){ 11237 this.refreshTask(this.getParent(taskId)); 11238 } 11239 11240 }, 11241 refreshLink: function (linkId) { 11242 this.$data.linksStore.refresh(linkId, !!this.getState().drag_id);// do quick refresh during drag and drop 11243 }, 11244 11245 silent: function(code){ 11246 var gantt = this; 11247 gantt.$data.tasksStore.silent(function(){ 11248 gantt.$data.linksStore.silent(function(){ 11249 code(); 11250 }); 11251 }); 11252 }, 11253 11254 clearAll: function () { 11255 var stores = getDatastores.call(this); 11256 for(var i = 0; i < stores.length; i++){ 11257 stores[i].clearAll(); 11258 } 11259 11260 this._update_flags(); 11261 this.userdata = {}; 11262 this.callEvent("onClear", []); 11263 this.render(); 11264 }, 11265 _clear_data: function () { 11266 this.$data.tasksStore.clearAll(); 11267 this.$data.linksStore.clearAll(); 11268 this._update_flags(); 11269 this.userdata = {}; 11270 }, 11271 11272 selectTask: function(id){ 11273 var store = this.$data.tasksStore; 11274 if(!this.config.select_task) 11275 return false; 11276 if (id){ 11277 11278 store.select(id); 11279 } 11280 return store.getSelectedId(); 11281 }, 11282 unselectTask: function(id){ 11283 var store = this.$data.tasksStore; 11284 store.unselect(id); 11285 }, 11286 isSelectedTask: function(id){ 11287 return this.$data.tasksStore.isSelected(id); 11288 }, 11289 getSelectedId: function() { 11290 return this.$data.tasksStore.getSelectedId(); 11291 } 11292}; 11293}; 11294 11295function createFacade(){ 11296 var res = utils.mixin({}, createDatastoreFacade()); 11297 utils.mixin(res, createTasksFacade()); 11298 utils.mixin(res, createLinksFacade()); 11299 return res; 11300} 11301 11302 11303 11304 11305module.exports = {create: createFacade}; 11306 11307/***/ }), 11308 11309/***/ "./sources/core/facades/datastore_links.js": 11310/*!*************************************************!*\ 11311 !*** ./sources/core/facades/datastore_links.js ***! 11312 \*************************************************/ 11313/*! no static exports found */ 11314/***/ (function(module, exports, __webpack_require__) { 11315 11316var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 11317 11318 11319var createLinksStoreFacade = function(){ 11320 return { 11321 getLinkCount: function () { 11322 return this.$data.linksStore.count(); 11323 }, 11324 11325 getLink : function (id) { 11326 return this.$data.linksStore.getItem(id); 11327 }, 11328 11329 getLinks : function () { 11330 return this.$data.linksStore.getItems(); 11331 }, 11332 11333 isLinkExists : function (id) { 11334 return this.$data.linksStore.exists(id); 11335 }, 11336 11337 addLink : function (link) { 11338 return this.$data.linksStore.addItem(link); 11339 }, 11340 11341 updateLink : function (id, data) { 11342 if (!utils.defined(data)) 11343 data = this.getLink(id); 11344 this.$data.linksStore.updateItem(id, data); 11345 }, 11346 11347 deleteLink : function (id) { 11348 return this.$data.linksStore.removeItem(id); 11349 }, 11350 11351 changeLinkId : function (oldid, newid) { 11352 return this.$data.linksStore.changeId(oldid, newid); 11353 } 11354}; 11355}; 11356 11357module.exports = createLinksStoreFacade; 11358 11359/***/ }), 11360 11361/***/ "./sources/core/facades/datastore_tasks.js": 11362/*!*************************************************!*\ 11363 !*** ./sources/core/facades/datastore_tasks.js ***! 11364 \*************************************************/ 11365/*! no static exports found */ 11366/***/ (function(module, exports, __webpack_require__) { 11367 11368var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 11369 11370var createTasksDatastoreFacade = function(){ 11371 return { 11372 getTask: function (id) { 11373 this.assert(id, "Invalid argument for gantt.getTask"); 11374 var task = this.$data.tasksStore.getItem(id); 11375 this.assert(task, "Task not found id=" + id); 11376 return task; 11377 }, 11378 getTaskByTime: function (from, to) { 11379 var p = this.$data.tasksStore.getItems(); 11380 11381 var res = []; 11382 11383 if (!(from || to)) { 11384 res = p; 11385 } else { 11386 from = +from || -Infinity; 11387 to = +to || Infinity; 11388 for (var t = 0; t < p.length; t++){ 11389 var task = p[t]; 11390 if (+task.start_date < to && +task.end_date > from) 11391 res.push(task); 11392 } 11393 } 11394 return res; 11395 }, 11396 isTaskExists: function (id) { 11397 if(!this.$data || !this.$data.tasksStore){ 11398 return false; 11399 } 11400 return this.$data.tasksStore.exists(id); 11401 }, 11402 updateTask: function (id, item) { 11403 if (!utils.defined(item)) item = this.getTask(id); 11404 this.$data.tasksStore.updateItem(id, item); 11405 if(this.isTaskExists(id)) 11406 this.refreshTask(id); 11407 }, 11408 addTask: function (item, parent, index) { 11409 if (!utils.defined(item.id)) 11410 item.id = utils.uid(); 11411 11412 if (!utils.defined(parent)) parent = this.getParent(item) || 0; 11413 if (!this.isTaskExists(parent)) parent = this.config.root_id; 11414 this.setParent(item, parent); 11415 11416 return this.$data.tasksStore.addItem(item, index, parent); 11417 }, 11418 deleteTask: function (id) { 11419 return this.$data.tasksStore.removeItem(id); 11420 }, 11421 getTaskCount: function () { 11422 return this.$data.tasksStore.count(); 11423 }, 11424 getVisibleTaskCount: function () { 11425 return this.$data.tasksStore.countVisible(); 11426 }, 11427 getTaskIndex: function (id) { 11428 return this.$data.tasksStore.getBranchIndex(id); 11429 }, 11430 getGlobalTaskIndex: function (id) { 11431 this.assert(id, "Invalid argument"); 11432 return this.$data.tasksStore.getIndexById(id); 11433 }, 11434 eachTask: function (code, parent, master) { 11435 return this.$data.tasksStore.eachItem(utils.bind(code, master||this), parent); 11436 }, 11437 eachParent: function (callback, startTask, master) { 11438 return this.$data.tasksStore.eachParent(utils.bind(callback, master || this), startTask); 11439 }, 11440 changeTaskId: function (oldid, newid) { 11441 this.$data.tasksStore.changeId(oldid, newid); 11442 var task = this.$data.tasksStore.getItem(newid); 11443 11444 var links = []; 11445 11446 if (task.$source) { 11447 links = links.concat(task.$source); 11448 } 11449 if (task.$target) { 11450 links = links.concat(task.$target); 11451 } 11452 11453 for (var i = 0; i < links.length; i++) { 11454 var link = this.getLink(links[i]); 11455 if (link.source == oldid) { 11456 link.source = newid; 11457 } 11458 if (link.target == oldid) { 11459 link.target = newid; 11460 } 11461 } 11462 }, 11463 calculateTaskLevel: function (item) { 11464 return this.$data.tasksStore.calculateItemLevel(item); 11465 }, 11466 getNext: function (id) { 11467 return this.$data.tasksStore.getNext(id); 11468 }, 11469 getPrev: function (id) { 11470 return this.$data.tasksStore.getPrev(id); 11471 }, 11472 getParent: function (id) { 11473 return this.$data.tasksStore.getParent(id); 11474 }, 11475 setParent: function (task, new_pid, silent) { 11476 return this.$data.tasksStore.setParent(task, new_pid, silent); 11477 }, 11478 getSiblings: function (id) { 11479 return this.$data.tasksStore.getSiblings(id).slice(); 11480 }, 11481 getNextSibling: function (id) { 11482 return this.$data.tasksStore.getNextSibling(id); 11483 }, 11484 getPrevSibling: function (id) { 11485 return this.$data.tasksStore.getPrevSibling(id); 11486 }, 11487 getTaskByIndex: function(index){ 11488 var id = this.$data.tasksStore.getIdByIndex(index); 11489 if(this.isTaskExists(id)){ 11490 return this.getTask(id); 11491 }else{ 11492 return null; 11493 } 11494 }, 11495 getChildren: function (id) { 11496 if(!this.hasChild(id)){ 11497 return []; 11498 }else{ 11499 return this.$data.tasksStore.getChildren(id).slice(); 11500 } 11501 }, 11502 hasChild: function (id) { 11503 return this.$data.tasksStore.hasChild(id); 11504 }, 11505 open: function (id) { 11506 this.$data.tasksStore.open(id); 11507 }, 11508 close: function (id) { 11509 this.$data.tasksStore.close(id); 11510 }, 11511 moveTask: function (sid, tindex, parent) { 11512 return this.$data.tasksStore.move.apply(this.$data.tasksStore, arguments); 11513 }, 11514 sort: function(field, desc, parent, silent) { 11515 var render = !silent;//4th argument to cancel redraw after sorting 11516 11517 this.$data.tasksStore.sort(field, desc, parent); 11518 this.callEvent("onAfterSort", [field, desc, parent]); 11519 11520 if (render) { 11521 this.render(); 11522 } 11523 } 11524}; 11525}; 11526 11527module.exports = createTasksDatastoreFacade; 11528 11529 11530 11531 11532/***/ }), 11533 11534/***/ "./sources/core/facades/layout.js": 11535/*!****************************************!*\ 11536 !*** ./sources/core/facades/layout.js ***! 11537 \****************************************/ 11538/*! no static exports found */ 11539/***/ (function(module, exports) { 11540 11541function createLayoutFacade(){ 11542 11543 function getTimeline(gantt){ 11544 return gantt.$ui.getView("timeline"); 11545 } 11546 11547 function getGrid(gantt){ 11548 return gantt.$ui.getView("grid"); 11549 } 11550 11551 function getVerticalScrollbar(gantt){ 11552 return gantt.$ui.getView("scrollVer"); 11553 } 11554 11555 function getHorizontalScrollbar(gantt){ 11556 return gantt.$ui.getView("scrollHor"); 11557 } 11558 11559 var DEFAULT_VALUE = "DEFAULT_VALUE"; 11560 11561 function tryCall(getView, method, args, fallback){ 11562 var view = getView(this); 11563 if (!(view && view.isVisible())) { 11564 if(fallback){ 11565 return fallback(); 11566 }else{ 11567 return DEFAULT_VALUE; 11568 } 11569 } else { 11570 return view[method].apply(view, args); 11571 } 11572 } 11573 11574 return { 11575 11576 getColumnIndex: function(name) { 11577 var res = tryCall.call(this, getGrid, "getColumnIndex", [name]); 11578 if(res === DEFAULT_VALUE){ 11579 return 0; 11580 }else{ 11581 return res; 11582 } 11583 }, 11584 11585 dateFromPos: function(x) { 11586 var res = tryCall.call(this, getTimeline, "dateFromPos", Array.prototype.slice.call(arguments)); 11587 if(res === DEFAULT_VALUE){ 11588 return this.getState().min_date; 11589 }else{ 11590 return res; 11591 } 11592 }, 11593 11594 posFromDate: function(date) { 11595 var res = tryCall.call(this, getTimeline, "posFromDate", [date]); 11596 if(res === DEFAULT_VALUE){ 11597 return 0; 11598 }else{ 11599 return res; 11600 } 11601 }, 11602 11603 getRowTop: function(index) { 11604 var self = this; 11605 var res = tryCall.call(self, getTimeline, "getRowTop", [index], 11606 function(){ return tryCall.call(self, getGrid, "getRowTop", [index]);} 11607 ); 11608 11609 if(res === DEFAULT_VALUE){ 11610 return 0; 11611 }else{ 11612 return res; 11613 } 11614 }, 11615 11616 getTaskTop: function(id) { 11617 var self = this; 11618 var res = tryCall.call(self, getTimeline, "getItemTop", [id], 11619 function(){ return tryCall.call(self, getGrid, "getItemTop", [id]);} 11620 ); 11621 11622 if(res === DEFAULT_VALUE){ 11623 return 0; 11624 }else{ 11625 return res; 11626 } 11627 }, 11628 11629 11630 getTaskPosition: function(task, start_date, end_date) { 11631 var res = tryCall.call(this, getTimeline, "getItemPosition", [task, start_date, end_date]); 11632 11633 if(res === DEFAULT_VALUE){ 11634 var top = this.getTaskTop(task.id); 11635 var height = this.getTaskHeight(); 11636 11637 return { 11638 left: 0, 11639 top: top, 11640 height: height, 11641 width: 0 11642 }; 11643 }else{ 11644 return res; 11645 } 11646 }, 11647 11648 getTaskHeight: function() { 11649 var self = this; 11650 var res = tryCall.call(self, getTimeline, "getItemHeight", [], 11651 function(){ return tryCall.call(self, getGrid, "getItemHeight", []);} 11652 ); 11653 11654 if(res === DEFAULT_VALUE){ 11655 return 0; 11656 }else{ 11657 return res; 11658 } 11659 }, 11660 11661 11662 columnIndexByDate: function(date) { 11663 var res = tryCall.call(this, getTimeline, "columnIndexByDate", [date]); 11664 if(res === DEFAULT_VALUE){ 11665 return 0; 11666 }else{ 11667 return res; 11668 } 11669 }, 11670 11671 roundTaskDates: function() { 11672 tryCall.call(this, getTimeline, "roundTaskDates", []); 11673 }, 11674 11675 getScale: function() { 11676 var res = tryCall.call(this, getTimeline, "getScale", []); 11677 if(res === DEFAULT_VALUE){ 11678 return null; 11679 }else{ 11680 return res; 11681 } 11682 }, 11683 11684 getTaskNode: function(id) { 11685 var timeline = getTimeline(this); 11686 if (!timeline || !timeline.isVisible()) { 11687 return null; 11688 } else { 11689 return timeline._taskRenderer.rendered[id]; 11690 } 11691 }, 11692 11693 11694 getLinkNode: function(id) { 11695 var timeline = getTimeline(this); 11696 if (!timeline.isVisible()) { 11697 return null; 11698 } else { 11699 return timeline._linkRenderer.rendered[id]; 11700 } 11701 }, 11702 11703 scrollTo: function(left, top){ 11704 var vertical = getVerticalScrollbar(this); 11705 var horizontal = getHorizontalScrollbar(this); 11706 11707 var oldH = {position: 0}, 11708 oldV = {position: 0}; 11709 11710 if(vertical){ 11711 oldV = vertical.getScrollState(); 11712 } 11713 if(horizontal){ 11714 oldH = horizontal.getScrollState(); 11715 } 11716 11717 if (horizontal && left*1 == left){ 11718 horizontal.scroll(left); 11719 } 11720 if(vertical && top*1 == top){ 11721 vertical.scroll(top); 11722 } 11723 11724 var newV = {position: 0}, 11725 newH = {position: 0}; 11726 if(vertical){ 11727 newV = vertical.getScrollState(); 11728 } 11729 if(horizontal){ 11730 newH = horizontal.getScrollState(); 11731 } 11732 11733 this.callEvent("onGanttScroll", [oldH.position, oldV.position, newH.position, newV.position]); 11734 }, 11735 11736 showDate: function(date){ 11737 var date_x = this.posFromDate(date); 11738 var scroll_to = Math.max(date_x - this.config.task_scroll_offset, 0); 11739 this.scrollTo(scroll_to); 11740 }, 11741 showTask: function(id) { 11742 var pos = this.getTaskPosition(this.getTask(id)); 11743 11744 var left = Math.max(pos.left - this.config.task_scroll_offset, 0); 11745 11746 var dataHeight = this._scroll_state().y; 11747 var top; 11748 if(!dataHeight){ 11749 top = pos.top; 11750 }else{ 11751 top = pos.top - (dataHeight - this.config.row_height)/2; 11752 } 11753 11754 this.scrollTo(left, top); 11755 }, 11756 _scroll_state: function(){ 11757 var result = { 11758 x: false, 11759 y: false, 11760 x_pos: 0, 11761 y_pos: 0, 11762 scroll_size: this.config.scroll_size + 1,//1px for inner content 11763 x_inner: 0, 11764 y_inner: 0 11765 }; 11766 11767 var scrollVer = getVerticalScrollbar(this), 11768 scrollHor = getHorizontalScrollbar(this); 11769 if(scrollHor){ 11770 var horState = scrollHor.getScrollState(); 11771 if(horState.visible){ 11772 result.x = horState.size; 11773 result.x_inner = horState.scrollSize; 11774 } 11775 result.x_pos = horState.position || 0; 11776 } 11777 11778 if(scrollVer){ 11779 var verState = scrollVer.getScrollState(); 11780 if(verState.visible){ 11781 result.y = verState.size; 11782 11783 result.y_inner = verState.scrollSize; 11784 } 11785 result.y_pos = verState.position || 0; 11786 } 11787 11788 return result; 11789 }, 11790 getScrollState: function(){ 11791 var state = this._scroll_state(); 11792 return { x:state.x_pos, y:state.y_pos, inner_width:state.x, inner_height:state.y, width: state.x_inner, height: state.y_inner }; 11793 } 11794 11795 }; 11796 11797} 11798 11799module.exports = createLayoutFacade; 11800 11801/***/ }), 11802 11803/***/ "./sources/core/facades/worktime_calendars.js": 11804/*!****************************************************!*\ 11805 !*** ./sources/core/facades/worktime_calendars.js ***! 11806 \****************************************************/ 11807/*! no static exports found */ 11808/***/ (function(module, exports, __webpack_require__) { 11809 11810// TODO: rework public api for date methods 11811var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 11812 11813var createWorktimeFacade = function(calendarManager, timeCalculator){ 11814 return { 11815 getWorkHours: function (date) { 11816 return timeCalculator.getWorkHours(date); 11817 }, 11818 11819 setWorkTime: function (config) { 11820 return timeCalculator.setWorkTime(config); 11821 }, 11822 11823 unsetWorkTime: function (config) { 11824 timeCalculator.unsetWorkTime(config); 11825 }, 11826 11827 isWorkTime: function (date, unit, task) { 11828 return timeCalculator.isWorkTime(date, unit, task); 11829 }, 11830 11831 getClosestWorkTime: function (config) { 11832 return timeCalculator.getClosestWorkTime(config); 11833 }, 11834 11835 calculateDuration: function (start_date, end_date, task) { 11836 return timeCalculator.calculateDuration(start_date, end_date, task); 11837 }, 11838 _hasDuration: function (start_date, end_date, task) { 11839 return timeCalculator.hasDuration(start_date, end_date, task); 11840 }, 11841 11842 calculateEndDate: function (start, duration, unit, task) { 11843 return timeCalculator.calculateEndDate(start, duration, unit, task); 11844 }, 11845 11846 createCalendar: utils.bind(calendarManager.createCalendar, calendarManager), 11847 addCalendar: utils.bind(calendarManager.addCalendar, calendarManager), 11848 getCalendar: utils.bind(calendarManager.getCalendar, calendarManager), 11849 getCalendars: utils.bind(calendarManager.getCalendars, calendarManager), 11850 getTaskCalendar: utils.bind(calendarManager.getTaskCalendar, calendarManager), 11851 deleteCalendar: utils.bind(calendarManager.deleteCalendar, calendarManager) 11852 }; 11853}; 11854 11855 11856module.exports = { create: createWorktimeFacade }; 11857 11858 11859/***/ }), 11860 11861/***/ "./sources/core/gantt.js": 11862/*!*******************************!*\ 11863 !*** ./sources/core/gantt.js ***! 11864 \*******************************/ 11865/*! no static exports found */ 11866/***/ (function(module, exports, __webpack_require__) { 11867 11868__webpack_require__(/*! css/skins/terrace.less */ "./sources/css/skins/terrace.less"); 11869 11870function DHXGantt(){ 11871 this.constants = __webpack_require__(/*! ./../constants */ "./sources/constants/index.js"); 11872 this.version = "6.3.5"; 11873 this.license = "gpl"; 11874 this.templates = {}; 11875 this.ext = {}; 11876 this.keys = { 11877 edit_save: this.constants.KEY_CODES.ENTER, 11878 edit_cancel: this.constants.KEY_CODES.ESC 11879 }; 11880} 11881 11882module.exports = function() { 11883 // use a named constructor to make gantt instance discoverable in heap snapshots 11884 var gantt = new DHXGantt(); 11885 11886 __webpack_require__(/*! ./common/import */ "./sources/core/common/import.js")(gantt); 11887 11888 gantt.$services = gantt.$inject(__webpack_require__(/*! ./common/services */ "./sources/core/common/services.js")); 11889 gantt.config = gantt.$inject(__webpack_require__(/*! ./common/config */ "./sources/core/common/config.ts")); 11890 gantt.ajax = __webpack_require__(/*! ./common/ajax */ "./sources/core/common/ajax.js")(gantt); 11891 gantt.date = __webpack_require__(/*! ./common/date */ "./sources/core/common/date.js")(gantt); 11892 var dnd = __webpack_require__(/*! ./common/dnd */ "./sources/core/common/dnd.js")(gantt); 11893 gantt.$services.setService("dnd", function(){return dnd;}); 11894 11895 gantt.$services.setService("config", function () { 11896 return gantt.config; 11897 }); 11898 gantt.$services.setService("date", function () { 11899 return gantt.date; 11900 }); 11901 gantt.$services.setService("locale", function () { 11902 return gantt.locale; 11903 }); 11904 gantt.$services.setService("templates", function () { 11905 return gantt.templates; 11906 }); 11907 11908 var templatesLoader = __webpack_require__(/*! ./common/templates */ "./sources/core/common/templates.js")(gantt); 11909 gantt.$services.setService("templateLoader", function () { 11910 return templatesLoader; 11911 }); 11912 11913 var eventable = __webpack_require__(/*! ../utils/eventable */ "./sources/utils/eventable.js"); 11914 eventable(gantt); 11915 11916 var StateService = __webpack_require__(/*! ./common/state */ "./sources/core/common/state.js"); 11917 var stateService = new StateService(); 11918 11919 stateService.registerProvider("global", function () { 11920 var res = { 11921 min_date: gantt._min_date, 11922 max_date: gantt._max_date, 11923 selected_task: null 11924 }; 11925 11926 // do not throw error if getState called from non-initialized gantt 11927 if(gantt.$data && gantt.$data.tasksStore){ 11928 res.selected_task = gantt.$data.tasksStore.getSelectedId(); 11929 } 11930 return res; 11931 }); 11932 gantt.getState = stateService.getState; 11933 gantt.$services.setService("state", function () { 11934 return stateService; 11935 }); 11936 11937 var utils = __webpack_require__(/*! ../utils/utils */ "./sources/utils/utils.js"); 11938 utils.mixin(gantt, utils); 11939 11940 gantt.Promise = __webpack_require__(/*! ../utils/promise */ "./sources/utils/promise.js"); 11941 gantt.env = __webpack_require__(/*! ../utils/env */ "./sources/utils/env.js"); 11942 11943 var domHelpers = __webpack_require__(/*! ../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 11944 gantt.utils = { 11945 dom: { 11946 getNodePosition: domHelpers.getNodePosition, 11947 getRelativeEventPosition: domHelpers.getRelativeEventPosition, 11948 isChildOf: domHelpers.isChildOf, 11949 hasClass: domHelpers.hasClass, 11950 closest: domHelpers.closest 11951 } 11952 }; 11953 11954 var domEvents = __webpack_require__(/*! ../utils/dom_event_scope */ "./sources/utils/dom_event_scope.js")(); 11955 gantt.event = domEvents.attach; 11956 gantt.eventRemove = domEvents.detach; 11957 gantt._eventRemoveAll = domEvents.detachAll; 11958 gantt._createDomEventScope = domEvents.extend; 11959 11960 utils.mixin(gantt, __webpack_require__(/*! ./message */ "./sources/core/message.js")(gantt)); 11961 var uiApi = __webpack_require__(/*! ./ui/index */ "./sources/core/ui/index.js").init(gantt); 11962 gantt.$ui = uiApi.factory; 11963 gantt.$ui.layers = uiApi.render; 11964 gantt.$mouseEvents = uiApi.mouseEvents; 11965 gantt.$services.setService("mouseEvents", function () { 11966 return gantt.$mouseEvents; 11967 }); 11968 gantt.mixin(gantt, uiApi.layersApi); 11969 11970 __webpack_require__(/*! ./data_task_layers */ "./sources/core/data_task_layers.gpl.js")(gantt); 11971 11972 gantt.$services.setService("layers", function () { 11973 return uiApi.layersService; 11974 }); 11975 11976 var createLayoutFacade = __webpack_require__(/*! ./facades/layout */ "./sources/core/facades/layout.js"); 11977 gantt.mixin(gantt, createLayoutFacade()); 11978 11979 __webpack_require__(/*! ./datastore/datastore_hooks */ "./sources/core/datastore/datastore_hooks.js")(gantt); 11980 11981 var DataProcessor = __webpack_require__(/*! ./dataprocessor */ "./sources/core/dataprocessor/index.js"); 11982 gantt.dataProcessor = DataProcessor.DEPRECATED_api; 11983 gantt.createDataProcessor = DataProcessor.createDataProcessor; 11984 11985 __webpack_require__(/*! ./plugins */ "./sources/core/plugins/index.js")(gantt); 11986 11987 __webpack_require__(/*! ./dynamic_loading */ "./sources/core/dynamic_loading.gpl.js")(gantt); 11988 __webpack_require__(/*! ./grid_column_api */ "./sources/core/grid_column_api.gpl.js")(gantt); 11989 __webpack_require__(/*! ./wai_aria */ "./sources/core/wai_aria.js")(gantt); 11990 __webpack_require__(/*! ./tasks */ "./sources/core/tasks.js")(gantt); 11991 __webpack_require__(/*! ./load */ "./sources/core/load.js")(gantt); 11992 __webpack_require__(/*! ./worktime/work_time */ "./sources/core/worktime/work_time.js")(gantt); 11993 __webpack_require__(/*! ./data */ "./sources/core/data.js")(gantt); 11994 11995 __webpack_require__(/*! ../publish_helpers/void_script_second */ "./sources/publish_helpers/void_script_second.ts").default(gantt); 11996 11997 __webpack_require__(/*! ./lightbox */ "./sources/core/lightbox/index.js")(gantt); 11998 __webpack_require__(/*! ./lightbox_optional_time */ "./sources/core/lightbox_optional_time.js")(gantt); 11999 __webpack_require__(/*! ./data_task_types */ "./sources/core/data_task_types.gpl.js")(gantt); 12000 __webpack_require__(/*! ./cached_functions */ "./sources/core/cached_functions.js")(gantt); 12001 __webpack_require__(/*! ./skin */ "./sources/core/skin.js")(gantt); 12002 __webpack_require__(/*! ../css/skins/skyblue */ "./sources/css/skins/skyblue.js")(gantt); 12003 __webpack_require__(/*! ../css/skins/meadow */ "./sources/css/skins/meadow.js")(gantt); 12004 __webpack_require__(/*! ../css/skins/terrace */ "./sources/css/skins/terrace.js")(gantt); 12005 __webpack_require__(/*! ../css/skins/broadway */ "./sources/css/skins/broadway.js")(gantt); 12006 __webpack_require__(/*! ../css/skins/material */ "./sources/css/skins/material.js")(gantt); 12007 __webpack_require__(/*! ../css/skins/contrast_black */ "./sources/css/skins/contrast_black.js")(gantt); 12008 __webpack_require__(/*! ../css/skins/contrast_white */ "./sources/css/skins/contrast_white.js")(gantt); 12009 __webpack_require__(/*! ./touch */ "./sources/core/touch.js")(gantt); 12010 __webpack_require__(/*! ../locale */ "./sources/locale/index.js")(gantt); 12011 __webpack_require__(/*! ./gantt_core */ "./sources/core/gantt_core.js")(gantt); 12012 __webpack_require__(/*! ./destructor */ "./sources/core/destructor.js")(gantt); 12013 __webpack_require__(/*! ../publish_helpers/void_script_third */ "./sources/publish_helpers/void_script_third.ts").default(gantt); 12014 return gantt; 12015}; 12016 12017/***/ }), 12018 12019/***/ "./sources/core/gantt_core.js": 12020/*!************************************!*\ 12021 !*** ./sources/core/gantt_core.js ***! 12022 \************************************/ 12023/*! no static exports found */ 12024/***/ (function(module, exports, __webpack_require__) { 12025 12026var domHelpers = __webpack_require__(/*! ../utils/dom_helpers */ "./sources/utils/dom_helpers.js"), 12027 helpers = __webpack_require__(/*! ../utils/helpers */ "./sources/utils/helpers.js"); 12028 12029module.exports = function(gantt){ 12030 var calculateScaleRange = __webpack_require__(/*! ./gantt_data_range */ "./sources/core/gantt_data_range.js"); 12031 12032 gantt.assert = __webpack_require__(/*! ./common/assert */ "./sources/core/common/assert.js")(gantt); 12033 12034//initial initialization 12035 gantt.init = function(node, from, to){ 12036 if(from && to){ 12037 this.config.start_date = this._min_date = new Date(from); 12038 this.config.end_date = this._max_date = new Date(to); 12039 } 12040 this.date.init(); 12041 12042 if (!this.config.scroll_size) 12043 this.config.scroll_size = domHelpers.getScrollSize() || 1; 12044 12045 //can be called only once 12046 this.init = function(node){ 12047 if (this.$container && this.$container.parentNode){ 12048 this.$container.parentNode.removeChild(this.$container); 12049 this.$container = null; 12050 } 12051 12052 if(this.$layout){ 12053 this.$layout.clear(); 12054 } 12055 this._reinit(node); 12056 }; 12057 12058 this._reinit(node); 12059 }; 12060 12061 12062 var dropLayout = (function dropLayout(){ 12063 if(this.$layout){ 12064 this.$layout.destructor(); 12065 this.$layout = null; 12066 this.$ui.reset(); 12067 } 12068 }).bind(gantt); 12069 12070 var rebuildLayout = (function rebuildLayout(){ 12071 12072 this.$root.innerHTML = ""; 12073 12074 this.$root.gantt = this; 12075 calculateScaleRange(this); 12076 this.config.layout.id = "main"; 12077 this.$layout = this.$ui.createView("layout", this.$root, this.config.layout); 12078 12079 this.$layout.attachEvent("onBeforeResize", function(){ 12080 var storeNames = gantt.$services.getService("datastores"); 12081 for(var i = 0; i < storeNames.length; i++){ 12082 gantt.getDatastore(storeNames[i]).filter(); 12083 } 12084 }); 12085 12086 this.$layout.attachEvent("onResize", function(){ 12087 gantt.refreshData(); 12088 }); 12089 12090 this.callEvent("onGanttLayoutReady", []); 12091 this.$layout.render(); 12092 12093 this.$container = this.$layout.$container.firstChild; 12094 12095 addResizeListener(this); 12096 }).bind(gantt); 12097 12098 gantt.resetLayout = function(){ 12099 dropLayout(); 12100 rebuildLayout(); 12101 this.render(); 12102 }; 12103 12104 gantt._reinit = function(node){ 12105 this.callEvent("onBeforeGanttReady", []); 12106 12107 // detach listeners before clearing old DOM, possible IE errors when accessing detached nodes 12108 this._eventRemoveAll(); 12109 this.$mouseEvents.reset(); 12110 12111 this.resetLightbox(); 12112 this._update_flags(); 12113 12114 12115 var config = this.$services.getService("templateLoader"); 12116 config.initTemplates(this); 12117 12118 this._clearTaskLayers(); 12119 this._clearLinkLayers(); 12120 12121 dropLayout(); 12122 this.$root = domHelpers.toNode(node); 12123 rebuildLayout(); 12124 //this.clear 12125 12126 this.callEvent("onTemplatesReady",[]); 12127 this.$mouseEvents.reset(this.$root); 12128 this.callEvent("onGanttReady", []); 12129 12130 this.render(); 12131 }; 12132 12133 function addResizeListener(gantt){ 12134 var containerStyles = window.getComputedStyle(gantt.$root); 12135 if(containerStyles.getPropertyValue("position") == "static"){ 12136 gantt.$root.style.position = "relative"; 12137 } 12138 12139 var resizeWatcher = document.createElement('iframe'); 12140 resizeWatcher.className = "gantt_container_resize_watcher"; 12141 resizeWatcher.tabIndex = -1; 12142 if(gantt.config.wai_aria_attributes){ 12143 resizeWatcher.setAttribute("role", "none"); 12144 resizeWatcher.setAttribute("aria-hidden", true); 12145 } 12146 12147 // in some environments (namely, in SalesForce) iframe.contentWindow is not available 12148 gantt.$root.appendChild(resizeWatcher); 12149 if (resizeWatcher.contentWindow) { 12150 listenWindowResize(gantt, resizeWatcher.contentWindow); 12151 } else { 12152 // if so - ditch the iframe and fallback to listening the main window resize 12153 gantt.$root.removeChild(resizeWatcher); 12154 listenWindowResize(gantt, window); 12155 } 12156 } 12157 12158 function listenWindowResize(gantt, window){ 12159 var resizeDelay; 12160 gantt.event(window, "resize", function(){ 12161 clearTimeout(resizeDelay); 12162 resizeDelay = setTimeout(function(){ 12163 gantt.render(); 12164 }, 300); 12165 }); 12166 } 12167 12168 gantt.$click={ 12169 buttons:{ 12170 "edit": function(id) { 12171 if (gantt.isReadonly(gantt.getTask(id))) { 12172 return; 12173 } 12174 gantt.showLightbox(id); 12175 }, 12176 "delete": function(id) { 12177 var task = gantt.getTask(id); 12178 if (gantt.isReadonly(task)) { 12179 return; 12180 } 12181 var question = gantt.locale.labels.confirm_deleting; 12182 var title = gantt.locale.labels.confirm_deleting_title; 12183 12184 gantt._dhtmlx_confirm(question, title, function(){ 12185 if(!gantt.isTaskExists(id)){ 12186 gantt.hideLightbox(); 12187 return; 12188 } 12189 12190 if(task.$new){ 12191 gantt.silent(function(){ 12192 gantt.deleteTask(id, true); 12193 }); 12194 gantt.refreshData(); 12195 }else{ 12196 gantt.deleteTask(id); 12197 } 12198 12199 gantt.hideLightbox(); 12200 }); 12201 } 12202 } 12203 }; 12204 12205//renders self 12206 gantt.render = function(){ 12207 this.callEvent("onBeforeGanttRender", []); 12208 12209 if (!this.config.sort && this._sort) { 12210 this._sort = undefined; 12211 } 12212 12213 var pos = this.getScrollState(); 12214 var posX = pos ? pos.x : 0; 12215 if(this._getHorizontalScrollbar()){ 12216 var scrollbar = this._getHorizontalScrollbar(); 12217 posX = scrollbar.$config.codeScrollLeft || posX || 0; 12218 } 12219 12220 12221 var visible_date = null; 12222 if(posX){ 12223 visible_date = gantt.dateFromPos(posX + this.config.task_scroll_offset); 12224 } 12225 calculateScaleRange(this); 12226 12227 this.$layout.$config.autosize = this.config.autosize; 12228 this.$layout.resize(); 12229 12230 if(this.config.preserve_scroll && pos){ 12231 12232 if(posX){ 12233 var new_pos = gantt.getScrollState(); 12234 var new_date = gantt.dateFromPos(new_pos.x); 12235 if(!(+visible_date == +new_date && new_pos.y == pos.y)){ 12236 if(visible_date){ 12237 this.showDate(visible_date); 12238 } 12239 if(pos.y) 12240 gantt.scrollTo(undefined, pos.y); 12241 } 12242 } 12243 } 12244 12245 this.callEvent("onGanttRender", []); 12246 }; 12247 12248 //TODO: add layout.resize method that wouldn't trigger data repaint 12249 gantt.setSizes = gantt.render; 12250 12251 gantt.locate = function(e) { 12252 var trg = domHelpers.getTargetNode(e); 12253 12254 //ignore empty cells 12255 var className = domHelpers.getClassName(trg); 12256 if ((className || "").indexOf("gantt_task_cell") >= 0) return null; 12257 12258 var targetAttribute = arguments[1] || this.config.task_attribute; 12259 12260 var node = domHelpers.locateAttribute(trg, targetAttribute); 12261 if(node){ 12262 return node.getAttribute(targetAttribute); 12263 }else{ 12264 return null; 12265 } 12266 }; 12267 12268 gantt._locate_css = function(e, classname, strict){ 12269 return domHelpers.locateClassName(e, classname, strict); 12270 }; 12271 12272 gantt._locateHTML = function(e, attribute) { 12273 return domHelpers.locateAttribute(e, attribute || this.config.task_attribute); 12274 }; 12275 12276 gantt.getTaskRowNode = function(id) { 12277 var els = this.$grid_data.childNodes; 12278 var attribute = this.config.task_attribute; 12279 for (var i = 0; i < els.length; i++) { 12280 if (els[i].getAttribute) { 12281 var value = els[i].getAttribute(attribute); 12282 if (value == id) return els[i]; 12283 } 12284 } 12285 return null; 12286 }; 12287 12288 gantt.changeLightboxType = function(type){ 12289 if(this.getLightboxType() == type) 12290 return true; 12291 gantt._silent_redraw_lightbox(type); 12292 }; 12293 12294 12295 gantt._get_link_type = function (from_start, to_start) { 12296 var type = null; 12297 if (from_start && to_start) { 12298 type = gantt.config.links.start_to_start; 12299 } else if (!from_start && to_start) { 12300 type = gantt.config.links.finish_to_start; 12301 } else if (!from_start && !to_start) { 12302 type = gantt.config.links.finish_to_finish; 12303 } else if (from_start && !to_start) { 12304 type = gantt.config.links.start_to_finish; 12305 } 12306 return type; 12307 }; 12308 12309 gantt.isLinkAllowed = function (from, to, from_start, to_start) { 12310 var link = null; 12311 if (typeof(from) == "object") { 12312 link = from; 12313 } else { 12314 link = {source: from, target: to, type: this._get_link_type(from_start, to_start)}; 12315 } 12316 12317 if (!link) return false; 12318 if (!(link.source && link.target && link.type)) return false; 12319 if (link.source == link.target) return false; 12320 12321 var res = true; 12322 //any custom rules 12323 if (this.checkEvent("onLinkValidation")) 12324 res = this.callEvent("onLinkValidation", [link]); 12325 12326 return res; 12327 }; 12328 12329 12330 gantt._correct_dst_change = function(date, prevOffset, step, unit){ 12331 var time_unit = helpers.getSecondsInUnit(unit) * step; 12332 if(time_unit > 60*60 && time_unit < 60*60*24){ 12333 //correct dst change only if current unit is more than one hour and less than day (days have own checking), e.g. 12h 12334 var offsetChanged = date.getTimezoneOffset() - prevOffset; 12335 if(offsetChanged){ 12336 date = gantt.date.add(date, offsetChanged, "minute"); 12337 } 12338 } 12339 return date; 12340 }; 12341 12342 gantt.isSplitTask = function(task){ 12343 gantt.assert(task && task instanceof Object, "Invalid argument <b>task</b>="+task+" of gantt.isSplitTask. Task object was expected"); 12344 return this.$data.tasksStore._isSplitItem(task); 12345 }; 12346 12347 gantt._is_icon_open_click = function(e) { 12348 if (!e) 12349 return false; 12350 var target = e.target || e.srcElement; 12351 if (!(target && target.className)) 12352 return false; 12353 var className = domHelpers.getClassName(target); 12354 if (className.indexOf("gantt_tree_icon") !== -1 && (className.indexOf("gantt_close") !== -1 || className.indexOf("gantt_open") !== -1)) 12355 return true; 12356 return false; 12357 }; 12358 12359}; 12360 12361/***/ }), 12362 12363/***/ "./sources/core/gantt_data_range.js": 12364/*!******************************************!*\ 12365 !*** ./sources/core/gantt_data_range.js ***! 12366 \******************************************/ 12367/*! no static exports found */ 12368/***/ (function(module, exports, __webpack_require__) { 12369 12370var ScaleHelper = __webpack_require__(/*! ./ui/timeline/scales_ignore */ "./sources/core/ui/timeline/scales.js"); 12371var PrimaryScaleHelper = __webpack_require__(/*! ./ui/timeline/scales */ "./sources/core/ui/timeline/scales.js"); 12372 12373 12374function dateRangeResolver(gantt){ 12375 //reset project timing 12376 //_get_tasks_data(gantt); 12377 return gantt.getSubtaskDates(); 12378} 12379 12380function defaultRangeResolver(){ 12381 return { 12382 start_date: new Date(), 12383 end_date: new Date() 12384 }; 12385} 12386 12387function resolveConfigRange(unit, gantt){ 12388 var range = { 12389 start_date:null, 12390 end_date:null 12391 }; 12392 12393 if (gantt.config.start_date && gantt.config.end_date) { 12394 range.start_date = gantt.date[unit + "_start"](new Date(gantt.config.start_date)); 12395 12396 var end = new Date(gantt.config.end_date); 12397 var start_interval = gantt.date[unit + "_start"](new Date(end)); 12398 if (+end != +start_interval) { 12399 end = gantt.date.add(start_interval, 1, unit); 12400 } else { 12401 end = start_interval; 12402 } 12403 12404 range.end_date = end; 12405 } 12406 return range; 12407} 12408 12409function _scale_range_unit(gantt) { 12410 var primaryScale = (new PrimaryScaleHelper(gantt)).primaryScale(); 12411 var unit = primaryScale.unit; 12412 var step = primaryScale.step; 12413 if (gantt.config.scale_offset_minimal) { 12414 12415 var helper = new ScaleHelper(gantt); 12416 var scales = [helper.primaryScale()].concat(helper.getSubScales()); 12417 12418 helper.sortScales(scales); 12419 unit = scales[scales.length - 1].unit; 12420 step = scales[scales.length - 1].step || 1; 12421 } 12422 return { unit:unit, step:step }; 12423} 12424 12425function _init_tasks_range(gantt) { 12426 var cfg = _scale_range_unit(gantt); 12427 var unit = cfg.unit, 12428 step = cfg.step; 12429 var range = resolveConfigRange(unit, gantt); 12430 12431 if(!(range.start_date && range.end_date)){ 12432 range = dateRangeResolver(gantt); 12433 if(!range.start_date || !range.end_date){ 12434 range = defaultRangeResolver(gantt); 12435 } 12436 12437 range.start_date = gantt.date[unit + "_start"](range.start_date); 12438 range.start_date = gantt.calculateEndDate({ 12439 start_date: gantt.date[unit + "_start"](range.start_date), 12440 duration: -1, 12441 unit: unit, 12442 step:step 12443 });//one free column before first task 12444 12445 range.end_date = gantt.date[unit + "_start"](range.end_date); 12446 range.end_date = gantt.calculateEndDate({start_date: range.end_date, duration: 2, unit: unit, step:step});//one free column after last task 12447 } 12448 12449 gantt._min_date = range.start_date; 12450 gantt._max_date = range.end_date; 12451} 12452 12453function _adjust_scales(gantt) { 12454 if (gantt.config.fit_tasks) { 12455 var old_min = +gantt._min_date, 12456 old_max = +gantt._max_date; 12457 //this._init_tasks_range(); 12458 if (+gantt._min_date != old_min || +gantt._max_date != old_max) { 12459 gantt.render(); 12460 12461 gantt.callEvent("onScaleAdjusted", []); 12462 return true; 12463 } 12464 } 12465 return false; 12466} 12467 12468module.exports = function updateTasksRange(gantt){ 12469 _init_tasks_range(gantt); 12470 _adjust_scales(gantt); 12471}; 12472 12473 12474/***/ }), 12475 12476/***/ "./sources/core/grid_column_api.gpl.js": 12477/*!*********************************************!*\ 12478 !*** ./sources/core/grid_column_api.gpl.js ***! 12479 \*********************************************/ 12480/*! no static exports found */ 12481/***/ (function(module, exports) { 12482 12483module.exports = function(gantt) { 12484 gantt.getGridColumn = function(name) { 12485 var columns = gantt.config.columns; 12486 12487 for (var i = 0; i < columns.length; i++) { 12488 if (columns[i].name == name) 12489 return columns[i]; 12490 } 12491 12492 return null; 12493 }; 12494 12495 gantt.getGridColumns = function() { 12496 return gantt.config.columns.slice(); 12497 }; 12498}; 12499 12500/***/ }), 12501 12502/***/ "./sources/core/lightbox/controls/base_control.js": 12503/*!********************************************************!*\ 12504 !*** ./sources/core/lightbox/controls/base_control.js ***! 12505 \********************************************************/ 12506/*! no static exports found */ 12507/***/ (function(module, exports) { 12508 12509function dummy() { 12510 // eslint-disable-next-line 12511 console.log("Method is not implemented."); 12512} 12513function BaseControl() { 12514} 12515 12516// base methods will be runned in gantt context 12517BaseControl.prototype.render = dummy; // arguments: sns 12518BaseControl.prototype.set_value = dummy; // arguments: node, value, ev, sns(config) 12519BaseControl.prototype.get_value = dummy; // arguments node, ev, sns(config) 12520BaseControl.prototype.focus = dummy; // arguments: node 12521 12522module.exports = function(gantt) { // we could send current instance of gantt to module 12523 return BaseControl; 12524}; 12525 12526/***/ }), 12527 12528/***/ "./sources/core/lightbox/controls/checkbox_control.js": 12529/*!************************************************************!*\ 12530 !*** ./sources/core/lightbox/controls/checkbox_control.js ***! 12531 \************************************************************/ 12532/*! no static exports found */ 12533/***/ (function(module, exports, __webpack_require__) { 12534 12535var helpers = __webpack_require__(/*! ../../../utils/helpers */ "./sources/utils/helpers.js"); 12536var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"); 12537 12538module.exports = function(gantt) { 12539 var _super = __webpack_require__(/*! ./base_control */ "./sources/core/lightbox/controls/base_control.js")(gantt); 12540 12541 function CheckboxControl() { 12542 var self = _super.apply(this, arguments) || this; 12543 12544 return self; 12545 } 12546 12547 __extends(CheckboxControl, _super); 12548 12549 CheckboxControl.prototype.render = function(sns) { 12550 var height = (sns.height || "23") + "px"; 12551 var html = "<div class='gantt_cal_ltext' style='height:" + height + ";'>"; 12552 12553 if (sns.options && sns.options.length) { 12554 for (var i = 0; i < sns.options.length; i++) { 12555 html += "<label><input type='checkbox' value='" + sns.options[i].key + "' name='" + sns.name + "'>" + sns.options[i].label + "</label>"; 12556 } 12557 } 12558 html += "</div>"; 12559 return html; 12560 }; 12561 12562 CheckboxControl.prototype.set_value = function(node, value, ev, sns) { 12563 var checkboxes = Array.prototype.slice.call(node.querySelectorAll("input[type=checkbox]")); 12564 12565 if (!node._dhx_onchange && sns.onchange) { 12566 node.onchange = sns.onchange; 12567 node._dhx_onchange = true; 12568 } 12569 12570 helpers.forEach(checkboxes, function(entry) { 12571 entry.checked = value ? value.indexOf(entry.value) >= 0 : false; 12572 }); 12573 }; 12574 12575 CheckboxControl.prototype.get_value = function(node) { 12576 return helpers.arrayMap(Array.prototype.slice.call(node.querySelectorAll("input[type=checkbox]:checked")), function(entry) { 12577 return entry.value; 12578 }); 12579 }; 12580 12581 CheckboxControl.prototype.focus = function(node) { 12582 gantt._focus(node.querySelector("input[type=checkbox]")); 12583 }; 12584 12585 return CheckboxControl; 12586}; 12587 12588/***/ }), 12589 12590/***/ "./sources/core/lightbox/controls/constraint_control.js": 12591/*!**************************************************************!*\ 12592 !*** ./sources/core/lightbox/controls/constraint_control.js ***! 12593 \**************************************************************/ 12594/*! no static exports found */ 12595/***/ (function(module, exports, __webpack_require__) { 12596 12597var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"); 12598var htmlHelpers = __webpack_require__(/*! ../../../utils/html_helpers */ "./sources/utils/html_helpers.js"); 12599 12600module.exports = function (gantt) { 12601 var _super = __webpack_require__(/*! ./base_control */ "./sources/core/lightbox/controls/base_control.js")(gantt); 12602 12603 function ConstraintControl() { 12604 var self = _super.apply(this, arguments) || this; 12605 return self; 12606 } 12607 12608 __extends(ConstraintControl, _super); 12609 12610 function isNonTimedConstraint(value) { 12611 if (!value || value === gantt.config.constraint_types.ASAP || value === gantt.config.constraint_types.ALAP) { 12612 return true; 12613 } else { 12614 return false; 12615 } 12616 } 12617 12618 function toggleTimeSelect(timeSelects, typeValue) { 12619 var isNonTimed = isNonTimedConstraint(typeValue); 12620 for (var i = 0; i < timeSelects.length; i++) { 12621 timeSelects[i].disabled = isNonTimed; 12622 } 12623 } 12624 12625 ConstraintControl.prototype.render = function (sns) { 12626 var height = (sns.height || 30) + "px"; 12627 var html = "<div class='gantt_cal_ltext gantt_section_" + sns.name + "' style='height:" + height + ";'>"; 12628 12629 var options = []; 12630 for (var i in gantt.config.constraint_types) { 12631 options.push({ key: gantt.config.constraint_types[i], label: gantt.locale.labels[gantt.config.constraint_types[i]] }); 12632 } 12633 12634 sns.options = sns.options || options; 12635 12636 html += "<span data-constraint-type-select>" + htmlHelpers.getHtmlSelect(sns.options, [{ key: "data-type", value: "constraint-type" }]) + "</span>"; 12637 12638 var timeLabel = gantt.locale.labels["constraint_date"] || "Constraint date"; 12639 html += "<label data-constraint-time-select>" + timeLabel + ": " + gantt.form_blocks.getTimePicker.call(this, sns) + "</label>"; 12640 12641 html += "</div>"; 12642 return html; 12643 }; 12644 12645 ConstraintControl.prototype.set_value = function (node, value, task, config) { 12646 var typeSelect = node.querySelector("[data-constraint-type-select] select"); 12647 var timeSelects = node.querySelectorAll("[data-constraint-time-select] select"); 12648 var map = config._time_format_order; 12649 12650 var mapping = gantt._resolve_default_mapping(config); 12651 12652 if (!typeSelect._eventsInitialized) { 12653 typeSelect.addEventListener("change", function (e) { 12654 toggleTimeSelect(timeSelects, e.target.value); 12655 }); 12656 typeSelect._eventsInitialized = true; 12657 } 12658 12659 var constraintDate = task[mapping.constraint_date] || new Date(); 12660 gantt.form_blocks._fill_lightbox_select(timeSelects, 0, constraintDate, map, config); 12661 12662 var constraintType = task[mapping.constraint_type] || gantt.getConstraintType(task); 12663 typeSelect.value = constraintType; 12664 toggleTimeSelect(timeSelects, constraintType); 12665 }; 12666 12667 ConstraintControl.prototype.get_value = function (node, task, config) { 12668 var typeSelect = node.querySelector("[data-constraint-type-select] select"); 12669 var timeSelects = node.querySelectorAll("[data-constraint-time-select] select"); 12670 12671 var constraintType = typeSelect.value; 12672 var constraintDate = null; 12673 if (!isNonTimedConstraint(constraintType)) { 12674 constraintDate = gantt.form_blocks.getTimePickerValue(timeSelects, config); 12675 } 12676 12677 return { 12678 constraint_type: constraintType, 12679 constraint_date: constraintDate 12680 }; 12681 }; 12682 12683 ConstraintControl.prototype.focus = function (node) { 12684 gantt._focus(node.querySelector("select")); 12685 }; 12686 12687 return ConstraintControl; 12688}; 12689 12690/***/ }), 12691 12692/***/ "./sources/core/lightbox/controls/duration_control.js": 12693/*!************************************************************!*\ 12694 !*** ./sources/core/lightbox/controls/duration_control.js ***! 12695 \************************************************************/ 12696/*! no static exports found */ 12697/***/ (function(module, exports, __webpack_require__) { 12698 12699var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"); 12700var DurationFormatterNumeric = __webpack_require__(/*! ../../common/duration_formatter_numeric */ "./sources/core/common/duration_formatter_numeric.ts").default; 12701module.exports = function(gantt) { 12702 var _super = __webpack_require__(/*! ./base_control */ "./sources/core/lightbox/controls/base_control.js")(gantt); 12703 12704 function DurationControl() { 12705 var self = _super.apply(this, arguments) || this; 12706 12707 return self; 12708 } 12709 12710 function getFormatter(config) { 12711 return config.formatter || new DurationFormatterNumeric(); 12712 } 12713 12714 __extends(DurationControl, _super); 12715 12716 DurationControl.prototype.render = function(sns) { 12717 var time = "<div class='gantt_time_selects'>" + gantt.form_blocks.getTimePicker.call(this, sns) + "</div>"; 12718 var label = " "+ gantt.locale.labels[gantt.config.duration_unit + "s"] +" "; 12719 var singleDate = sns.single_date ? " style='display:none'" : ""; 12720 var readonly = sns.readonly ? " disabled='disabled'" : ""; 12721 var ariaAttr = gantt._waiAria.lightboxDurationInputAttrString(sns); 12722 12723 var durationInputClass = "gantt_duration_value"; 12724 if(sns.formatter) { 12725 label = ""; 12726 durationInputClass += " gantt_duration_value_formatted" ; 12727 } 12728 12729 var duration = "<div class='gantt_duration' " + singleDate + ">" + 12730 "<input type='button' class='gantt_duration_dec' value='−'" + readonly + ">" + 12731 "<input type='text' value='5days' class='"+durationInputClass+"'" + readonly + " " + ariaAttr + ">" + 12732 "<input type='button' class='gantt_duration_inc' value='+'" + readonly + ">"+label+"<span></span>" + 12733 "</div>"; 12734 var html = "<div style='height:" + (sns.height || 30) + "px;padding-top:0px;font-size:inherit;' class='gantt_section_time'>" + time + " " + duration + "</div>"; 12735 return html; 12736 }; 12737 12738 DurationControl.prototype.set_value = function(node, value, ev, config) { 12739 var s = node.getElementsByTagName("select"); 12740 var inps = node.getElementsByTagName("input"); 12741 var duration = inps[1]; 12742 var btns = [inps[0], inps[2]]; 12743 var endspan = node.getElementsByTagName("span")[0]; 12744 var map = config._time_format_order; 12745 var mapping; 12746 var start_date; 12747 var end_date; 12748 var duration_val; 12749 12750 function _calc_date() { 12751 var start_date = _getStartDate.call(gantt, node, config); 12752 var duration = _getDuration.call(gantt, node, config); 12753 var end_date = gantt.calculateEndDate({start_date: start_date, duration: duration, task: ev}); 12754 12755 var template = gantt.templates.task_end_date || gantt.templates.task_date; 12756 endspan.innerHTML = template(end_date); 12757 } 12758 12759 function _change_duration(step) { 12760 var value = duration.value; 12761 12762 value = getFormatter(config).parse(value); 12763 if (window.isNaN(value)) 12764 value = 0; 12765 value += step; 12766 if (value < 1) value = 1; 12767 duration.value = getFormatter(config).format(value); 12768 _calc_date(); 12769 } 12770 12771 btns[0].onclick = gantt.bind(function() { 12772 _change_duration(-1 * gantt.config.duration_step); 12773 }, this); 12774 btns[1].onclick = gantt.bind(function() { 12775 _change_duration(1 * gantt.config.duration_step); 12776 }, this); 12777 s[0].onchange = _calc_date; 12778 s[1].onchange = _calc_date; 12779 s[2].onchange = _calc_date; 12780 if (s[3]) s[3].onchange = _calc_date; 12781 12782 duration.onkeydown = gantt.bind(function(e) { 12783 var code; 12784 12785 e = e || window.event; 12786 code = (e.charCode || e.keyCode || e.which); 12787 12788 if (code == gantt.constants.KEY_CODES.DOWN) { 12789 _change_duration(-1 * gantt.config.duration_step); 12790 return false; 12791 } 12792 12793 if (code == gantt.constants.KEY_CODES.UP) { 12794 _change_duration(1 * gantt.config.duration_step); 12795 return false; 12796 } 12797 window.setTimeout(_calc_date, 1); 12798 }, this); 12799 12800 duration.onchange = gantt.bind(_calc_date, this); 12801 12802 mapping = gantt._resolve_default_mapping(config); 12803 if (typeof(mapping) === "string") mapping = {start_date: mapping}; 12804 12805 start_date = ev[mapping.start_date] || new Date(); 12806 end_date = ev[mapping.end_date] || gantt.calculateEndDate({ 12807 start_date: start_date, 12808 duration: 1, 12809 task: ev 12810 }); 12811 duration_val = Math.round(ev[mapping.duration]) || gantt.calculateDuration({ 12812 start_date: start_date, 12813 end_date: end_date, 12814 task: ev 12815 }); 12816 duration_val = getFormatter(config).format(duration_val); 12817 12818 gantt.form_blocks._fill_lightbox_select(s, 0, start_date, map, config); 12819 duration.value = duration_val; 12820 _calc_date(); 12821 }; 12822 12823 DurationControl.prototype.get_value = function(node, ev, config) { 12824 var startDate = _getStartDate(node, config); 12825 var duration = _getDuration(node, config); 12826 var endDate = gantt.calculateEndDate({start_date: startDate, duration: duration, task: ev}); 12827 12828 if (typeof gantt._resolve_default_mapping(config) == "string") { 12829 return startDate; 12830 } 12831 12832 return { 12833 start_date: startDate, 12834 end_date: endDate, 12835 duration: duration 12836 }; 12837 }; 12838 12839 DurationControl.prototype.focus = function(node) { 12840 gantt._focus(node.getElementsByTagName("select")[0]); 12841 }; 12842 12843 12844 function _getStartDate(node, config) { 12845 var s = node.getElementsByTagName("select"); 12846 var map = config._time_format_order; 12847 var hours = 0; 12848 var minutes = 0; 12849 12850 if (gantt.defined(map[3])) { 12851 var input = s[map[3]]; 12852 var time = parseInt(input.value, 10); 12853 if (isNaN(time) && input.hasAttribute("data-value")) { 12854 time = parseInt(input.getAttribute("data-value"), 10); 12855 } 12856 12857 hours = Math.floor(time / 60); 12858 minutes = time % 60; 12859 } 12860 return new Date(s[map[2]].value, s[map[1]].value, s[map[0]].value, hours, minutes); 12861 } 12862 12863 function _getDuration(node, config) { 12864 var duration = node.getElementsByTagName("input")[1]; 12865 12866 duration = getFormatter(config).parse(duration.value); 12867 if (!duration || window.isNaN(duration)) duration = 1; 12868 if (duration < 0) duration *= -1; 12869 return duration; 12870 } 12871 12872 return DurationControl; 12873}; 12874 12875/***/ }), 12876 12877/***/ "./sources/core/lightbox/controls/parent_control.js": 12878/*!**********************************************************!*\ 12879 !*** ./sources/core/lightbox/controls/parent_control.js ***! 12880 \**********************************************************/ 12881/*! no static exports found */ 12882/***/ (function(module, exports, __webpack_require__) { 12883 12884var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"); 12885 12886module.exports = function(gantt) { 12887 var _super = __webpack_require__(/*! ./select_control */ "./sources/core/lightbox/controls/select_control.js")(gantt); 12888 12889 function ParentControl() { 12890 var self = _super.apply(this, arguments) || this; 12891 12892 return self; 12893 } 12894 12895 __extends(ParentControl, _super); 12896 12897 12898 ParentControl.prototype.render = function(sns) { 12899 return _display(sns, false); 12900 }; 12901 12902 ParentControl.prototype.set_value = function(node, value, ev, config) { 12903 var tmpDom = document.createElement("div"); 12904 tmpDom.innerHTML = _display(config, ev.id); 12905 var newOptions = tmpDom.removeChild(tmpDom.firstChild); 12906 node.onselect = null; 12907 node.parentNode.replaceChild(newOptions, node); 12908 12909 return gantt.form_blocks.select.set_value.apply(gantt, [newOptions, value, ev, config]); 12910 }; 12911 12912 function _display(config, item_id) { 12913 var tasks = [], 12914 options = []; 12915 if (item_id) { 12916 tasks = gantt.getTaskByTime(); 12917 if (config.allow_root) { 12918 tasks.unshift({id: gantt.config.root_id, text: config.root_label || ""}); 12919 } 12920 tasks = _filter(tasks, config, item_id); 12921 if (config.sort) { 12922 tasks.sort(config.sort); 12923 } 12924 } 12925 var text = config.template || gantt.templates.task_text; 12926 for (var i = 0; i < tasks.length; i++) { 12927 var label = text.apply(gantt, [tasks[i].start_date, tasks[i].end_date, tasks[i]]); 12928 if (label === undefined) { 12929 label = ""; 12930 } 12931 options.push({ 12932 key: tasks[i].id, 12933 label: label 12934 }); 12935 } 12936 config.options = options; 12937 config.map_to = config.map_to || "parent"; 12938 return gantt.form_blocks.select.render.apply(this, arguments); 12939 } 12940 12941 function _filter(options, config, item_id) { 12942 var filter = config.filter || function() { 12943 return true; 12944 }; 12945 12946 options = options.slice(0); 12947 12948 for (var i = 0; i < options.length; i++) { 12949 var task = options[i]; 12950 if (task.id == item_id || gantt.isChildOf(task.id, item_id) || filter(task.id, task) === false) { 12951 options.splice(i, 1); 12952 i--; 12953 } 12954 } 12955 return options; 12956 } 12957 return ParentControl; 12958}; 12959 12960/***/ }), 12961 12962/***/ "./sources/core/lightbox/controls/radio_control.js": 12963/*!*********************************************************!*\ 12964 !*** ./sources/core/lightbox/controls/radio_control.js ***! 12965 \*********************************************************/ 12966/*! no static exports found */ 12967/***/ (function(module, exports, __webpack_require__) { 12968 12969var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"); 12970 12971module.exports = function(gantt) { 12972 var _super = __webpack_require__(/*! ./base_control */ "./sources/core/lightbox/controls/base_control.js")(gantt); 12973 12974 function RadioControl() { 12975 var self = _super.apply(this, arguments) || this; 12976 12977 return self; 12978 } 12979 12980 __extends(RadioControl, _super); 12981 12982 RadioControl.prototype.render = function(sns) { 12983 var height = (sns.height || "23") + "px"; 12984 var html = "<div class='gantt_cal_ltext' style='height:" + height + ";'>"; 12985 12986 if (sns.options && sns.options.length) { 12987 for (var i = 0; i < sns.options.length; i++) { 12988 html += "<label><input type='radio' value='" + sns.options[i].key + "' name='" + sns.name + "'>" + sns.options[i].label + "</label>"; 12989 } 12990 } 12991 12992 html += "</div>"; 12993 return html; 12994 }; 12995 12996 RadioControl.prototype.set_value = function(node, value, ev, sns) { 12997 var radio; 12998 12999 if (!sns.options || !sns.options.length) return; 13000 13001 radio = node.querySelector("input[type=radio][value='" + value + "']") || 13002 node.querySelector("input[type=radio][value='" + sns.default_value + "']"); 13003 13004 if (!radio) return; 13005 13006 if (!node._dhx_onchange && sns.onchange) { 13007 node.onchange = sns.onchange; 13008 node._dhx_onchange = true; 13009 } 13010 13011 radio.checked = true; 13012 }; 13013 13014 RadioControl.prototype.get_value = function(node, ev) { 13015 var result = node.querySelector("input[type=radio]:checked"); 13016 13017 return result ? result.value : ""; 13018 }; 13019 13020 RadioControl.prototype.focus = function(node) { 13021 gantt._focus(node.querySelector("input[type=radio]")); 13022 }; 13023 13024 return RadioControl; 13025}; 13026 13027/***/ }), 13028 13029/***/ "./sources/core/lightbox/controls/select_control.js": 13030/*!**********************************************************!*\ 13031 !*** ./sources/core/lightbox/controls/select_control.js ***! 13032 \**********************************************************/ 13033/*! no static exports found */ 13034/***/ (function(module, exports, __webpack_require__) { 13035 13036var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"); 13037var htmlHelpers = __webpack_require__(/*! ../../../utils/html_helpers */ "./sources/utils/html_helpers.js"); 13038 13039module.exports = function(gantt) { 13040 var _super = __webpack_require__(/*! ./base_control */ "./sources/core/lightbox/controls/base_control.js")(gantt); 13041 13042 function SelectControl() { 13043 var self = _super.apply(this, arguments) || this; 13044 13045 return self; 13046 } 13047 13048 __extends(SelectControl, _super); 13049 13050 SelectControl.prototype.render = function(sns) { 13051 var height = (sns.height || "23") + "px"; 13052 var html = "<div class='gantt_cal_ltext' style='height:" + height + ";'>"; 13053 13054 html += htmlHelpers.getHtmlSelect(sns.options, [{ key: "style", value: "width:100%;" }]); 13055 html += "</div>"; 13056 return html; 13057 }; 13058 13059 SelectControl.prototype.set_value = function(node, value, ev, sns) { 13060 var select = node.firstChild; 13061 if (!select._dhx_onchange && sns.onchange) { 13062 select.onchange = sns.onchange; 13063 select._dhx_onchange = true; 13064 } 13065 if (typeof value === "undefined") 13066 value = (select.options[0] || {}).value; 13067 select.value = value || ""; 13068 }; 13069 13070 SelectControl.prototype.get_value = function(node) { 13071 return node.firstChild.value; 13072 }; 13073 13074 SelectControl.prototype.focus = function(node) { 13075 var a = node.firstChild; 13076 gantt._focus(a, true); 13077 }; 13078 13079 return SelectControl; 13080}; 13081 13082/***/ }), 13083 13084/***/ "./sources/core/lightbox/controls/template_control.js": 13085/*!************************************************************!*\ 13086 !*** ./sources/core/lightbox/controls/template_control.js ***! 13087 \************************************************************/ 13088/*! no static exports found */ 13089/***/ (function(module, exports, __webpack_require__) { 13090 13091var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"); 13092 13093module.exports = function(gantt) { 13094 var _super = __webpack_require__(/*! ./base_control */ "./sources/core/lightbox/controls/base_control.js")(gantt); 13095 13096 function TemplateControl() { 13097 var self = _super.apply(this, arguments) || this; 13098 return self; 13099 } 13100 13101 __extends(TemplateControl, _super); 13102 13103 13104 TemplateControl.prototype.render = function(sns) { 13105 var height = (sns.height || "30") + "px"; 13106 return "<div class='gantt_cal_ltext gantt_cal_template' style='height:" + height + ";'></div>"; 13107 }; 13108 13109 TemplateControl.prototype.set_value = function(node, value) { 13110 node.innerHTML = value || ""; 13111 }; 13112 13113 TemplateControl.prototype.get_value = function(node) { 13114 return node.innerHTML || ""; 13115 }; 13116 13117 TemplateControl.prototype.focus = function() {}; 13118 13119 return TemplateControl; 13120}; 13121 13122/***/ }), 13123 13124/***/ "./sources/core/lightbox/controls/textarea_control.js": 13125/*!************************************************************!*\ 13126 !*** ./sources/core/lightbox/controls/textarea_control.js ***! 13127 \************************************************************/ 13128/*! no static exports found */ 13129/***/ (function(module, exports, __webpack_require__) { 13130 13131var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"); 13132 13133module.exports = function(gantt) { 13134 var _super = __webpack_require__(/*! ./base_control */ "./sources/core/lightbox/controls/base_control.js")(gantt); 13135 13136 function TextareaControl() { 13137 var self = _super.apply(this, arguments) || this; 13138 13139 return self; 13140 } 13141 13142 __extends(TextareaControl, _super); 13143 13144 TextareaControl.prototype.render = function(sns) { 13145 var height = (sns.height || "130") + "px"; 13146 return "<div class='gantt_cal_ltext' style='height:" + height + ";'><textarea></textarea></div>"; 13147 }; 13148 13149 TextareaControl.prototype.set_value = function(node, value) { 13150 gantt.form_blocks.textarea._get_input(node).value = value || ""; 13151 }; 13152 13153 TextareaControl.prototype.get_value = function(node) { 13154 return gantt.form_blocks.textarea._get_input(node).value; 13155 }; 13156 13157 TextareaControl.prototype.focus = function(node) { 13158 var a = gantt.form_blocks.textarea._get_input(node); 13159 gantt._focus(a, true); 13160 }; 13161 13162 TextareaControl.prototype._get_input = function(node) { 13163 return node.querySelector("textarea"); 13164 }; 13165 13166 return TextareaControl; 13167}; 13168 13169/***/ }), 13170 13171/***/ "./sources/core/lightbox/controls/time_control.js": 13172/*!********************************************************!*\ 13173 !*** ./sources/core/lightbox/controls/time_control.js ***! 13174 \********************************************************/ 13175/*! no static exports found */ 13176/***/ (function(module, exports, __webpack_require__) { 13177 13178var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"); 13179 13180module.exports = function (gantt) { 13181 var _super = __webpack_require__(/*! ./base_control */ "./sources/core/lightbox/controls/base_control.js")(gantt); 13182 13183 function TimeControl() { 13184 var self = _super.apply(this, arguments) || this; 13185 13186 return self; 13187 } 13188 13189 __extends(TimeControl, _super); 13190 13191 TimeControl.prototype.render = function (sns) { 13192 var time = gantt.form_blocks.getTimePicker.call(this, sns); 13193 var html = "<div style='height:" + (sns.height || 30) + "px;padding-top:0px;font-size:inherit;text-align:center;' class='gantt_section_time'>"; 13194 html += time; 13195 13196 if (sns.single_date) { 13197 time = gantt.form_blocks.getTimePicker.call(this, sns, true); 13198 html += "<span></span>"; 13199 } else { 13200 html += "<span style='font-weight:normal; font-size:10pt;'> – </span>"; 13201 } 13202 13203 html += time; 13204 html += "</div>"; 13205 return html; 13206 }; 13207 13208 TimeControl.prototype.set_value = function (node, value, ev, config) { 13209 var cfg = config; 13210 var s = node.getElementsByTagName("select"); 13211 var map = config._time_format_order; 13212 13213 if (cfg.auto_end_date) { 13214 var _update_lightbox_select = function () { 13215 start_date = new Date(s[map[2]].value, s[map[1]].value, s[map[0]].value, 0, 0); 13216 end_date = gantt.calculateEndDate({ start_date: start_date, duration: 1, task: ev }); 13217 gantt.form_blocks._fill_lightbox_select(s, map.size, end_date, map, cfg); 13218 }; 13219 for (var i = 0; i < 4; i++) { 13220 s[i].onchange = _update_lightbox_select; 13221 } 13222 } 13223 13224 var mapping = gantt._resolve_default_mapping(config); 13225 13226 if (typeof (mapping) === "string") mapping = { start_date: mapping }; 13227 13228 var start_date = ev[mapping.start_date] || new Date(); 13229 var end_date = ev[mapping.end_date] || gantt.calculateEndDate({ 13230 start_date: start_date, 13231 duration: 1, 13232 task: ev 13233 }); 13234 13235 gantt.form_blocks._fill_lightbox_select(s, 0, start_date, map, cfg); 13236 gantt.form_blocks._fill_lightbox_select(s, map.size, end_date, map, cfg); 13237 }; 13238 13239 TimeControl.prototype.get_value = function (node, ev, config) { 13240 var selects = node.getElementsByTagName("select"); 13241 var startDate; 13242 var map = config._time_format_order; 13243 function _getEndDate(selects, map, startDate) { 13244 var endDate = gantt.form_blocks.getTimePickerValue(selects, config, map.size); 13245 13246 if (endDate <= startDate) { 13247 return gantt.date.add(startDate, gantt._get_timepicker_step(), "minute"); 13248 } 13249 return endDate; 13250 } 13251 13252 startDate = gantt.form_blocks.getTimePickerValue(selects, config); 13253 13254 if (typeof gantt._resolve_default_mapping(config) === "string") { 13255 return startDate; 13256 } 13257 13258 return { 13259 start_date: startDate, 13260 end_date: _getEndDate(selects, map, startDate) 13261 }; 13262 }; 13263 13264 TimeControl.prototype.focus = function (node) { 13265 gantt._focus(node.getElementsByTagName("select")[0]); 13266 }; 13267 13268 return TimeControl; 13269}; 13270 13271/***/ }), 13272 13273/***/ "./sources/core/lightbox/index.js": 13274/*!****************************************!*\ 13275 !*** ./sources/core/lightbox/index.js ***! 13276 \****************************************/ 13277/*! no static exports found */ 13278/***/ (function(module, exports, __webpack_require__) { 13279 13280module.exports = function (gantt) { 13281 var domHelpers = __webpack_require__(/*! ../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 13282 var helpers = __webpack_require__(/*! ../../utils/helpers */ "./sources/utils/helpers.js"); 13283 13284 var TemplateControl = __webpack_require__(/*! ./controls/template_control */ "./sources/core/lightbox/controls/template_control.js")(gantt); 13285 var TextareaControl = __webpack_require__(/*! ./controls/textarea_control */ "./sources/core/lightbox/controls/textarea_control.js")(gantt); 13286 var TimeControl = __webpack_require__(/*! ./controls/time_control */ "./sources/core/lightbox/controls/time_control.js")(gantt); 13287 var SelectControl = __webpack_require__(/*! ./controls/select_control */ "./sources/core/lightbox/controls/select_control.js")(gantt); 13288 var CheckboxControl = __webpack_require__(/*! ./controls/checkbox_control */ "./sources/core/lightbox/controls/checkbox_control.js")(gantt); 13289 var RadioControl = __webpack_require__(/*! ./controls/radio_control */ "./sources/core/lightbox/controls/radio_control.js")(gantt); 13290 var DurationControl = __webpack_require__(/*! ./controls/duration_control */ "./sources/core/lightbox/controls/duration_control.js")(gantt); 13291 var ParentControl = __webpack_require__(/*! ./controls/parent_control */ "./sources/core/lightbox/controls/parent_control.js")(gantt); 13292 var ResourcesControl = __webpack_require__(/*! ./controls/resources_control */ "./sources/core/lightbox/controls/select_control.js")(gantt); 13293 var ConstraintControl = __webpack_require__(/*! ./controls/constraint_control */ "./sources/core/lightbox/controls/constraint_control.js")(gantt); 13294 13295 13296 gantt._lightbox_methods = {}; 13297 gantt._lightbox_template = "<div class='gantt_cal_ltitle'><span class='gantt_mark'> </span><span class='gantt_time'></span><span class='gantt_title'></span></div><div class='gantt_cal_larea'></div>"; 13298 13299 13300 //TODO: gantt._lightbox_id is changed from data.js and accessed from autoscheduling, check if it can be removed from gantt object 13301 var state = gantt.$services.getService("state"); 13302 state.registerProvider("lightbox", function () { 13303 return { 13304 lightbox: gantt._lightbox_id 13305 }; 13306 }); 13307 13308 gantt.showLightbox = function (id) { 13309 if (!this.callEvent("onBeforeLightbox", [id])) return; 13310 13311 var task = this.getTask(id); 13312 13313 var box = this.getLightbox(this.getTaskType(task.type)); 13314 this._center_lightbox(box); 13315 this.showCover(); 13316 this._fill_lightbox(id, box); 13317 13318 this._waiAria.lightboxVisibleAttr(box); 13319 13320 this.callEvent("onLightbox", [id]); 13321 }; 13322 13323 function _is_chart_visible(gantt) { 13324 var timeline = gantt.$ui.getView("timeline"); 13325 if (timeline && timeline.isVisible()) { 13326 return true; 13327 } else { 13328 return false; 13329 } 13330 } 13331 13332 gantt._get_timepicker_step = function () { 13333 if (this.config.round_dnd_dates) { 13334 var step; 13335 if (_is_chart_visible(this)) { 13336 var scale = gantt.getScale(); 13337 step = (helpers.getSecondsInUnit(scale.unit) * scale.step) / 60;//timepicker step is measured in minutes 13338 } 13339 13340 if (!step || step >= 60 * 24) { 13341 step = this.config.time_step; 13342 } 13343 return step; 13344 } 13345 return this.config.time_step; 13346 }; 13347 gantt.getLabel = function (property, key) { 13348 var sections = this._get_typed_lightbox_config(); 13349 for (var i = 0; i < sections.length; i++) { 13350 if (sections[i].map_to == property) { 13351 var options = sections[i].options; 13352 for (var j = 0; j < options.length; j++) { 13353 if (options[j].key == key) { 13354 return options[j].label; 13355 } 13356 } 13357 } 13358 } 13359 return ""; 13360 }; 13361 13362 gantt.updateCollection = function (list_name, collection) { 13363 collection = collection.slice(0); 13364 var list = gantt.serverList(list_name); 13365 if (!list) return false; 13366 list.splice(0, list.length); 13367 list.push.apply(list, collection || []); 13368 gantt.resetLightbox(); 13369 }; 13370 gantt.getLightboxType = function () { 13371 return this.getTaskType(this._lightbox_type); 13372 }; 13373 gantt.getLightbox = function (type) { 13374 var lightboxDiv; 13375 var fullWidth; 13376 var html; 13377 var sns; 13378 var ds; 13379 var classNames = ""; 13380 13381 if (type === undefined) 13382 type = this.getLightboxType(); 13383 13384 if (!this._lightbox || this.getLightboxType() != this.getTaskType(type)) { 13385 this._lightbox_type = this.getTaskType(type); 13386 lightboxDiv = document.createElement("div"); 13387 classNames = "gantt_cal_light"; 13388 fullWidth = this._is_lightbox_timepicker(); 13389 13390 if (gantt.config.wide_form || fullWidth) 13391 classNames += " gantt_cal_light_wide"; 13392 13393 if (fullWidth) { 13394 gantt.config.wide_form = true; 13395 classNames += " gantt_cal_light_full"; 13396 } 13397 13398 lightboxDiv.className = classNames; 13399 13400 lightboxDiv.style.visibility = "hidden"; 13401 html = this._lightbox_template; 13402 13403 html += getHtmlButtons(this.config.buttons_left); 13404 html += getHtmlButtons(this.config.buttons_right, true); 13405 13406 lightboxDiv.innerHTML = html; 13407 13408 gantt._waiAria.lightboxAttr(lightboxDiv); 13409 13410 if (gantt.config.drag_lightbox) { 13411 lightboxDiv.firstChild.onmousedown = gantt._ready_to_dnd; 13412 lightboxDiv.firstChild.onselectstart = function () { 13413 return false; 13414 }; 13415 lightboxDiv.firstChild.style.cursor = "pointer"; 13416 gantt._init_dnd_events(); 13417 } 13418 13419 document.body.insertBefore(lightboxDiv, document.body.firstChild); 13420 this._lightbox = lightboxDiv; 13421 13422 sns = this._get_typed_lightbox_config(type); 13423 html = this._render_sections(sns); 13424 13425 ds = lightboxDiv.querySelector("div.gantt_cal_larea"); 13426 ds.innerHTML = html; 13427 13428 bindLabelsToInputs(sns); 13429 13430 //sizes 13431 this.resizeLightbox(); 13432 13433 this._init_lightbox_events(this); 13434 lightboxDiv.style.display = "none"; 13435 lightboxDiv.style.visibility = "visible"; 13436 } 13437 return this._lightbox; 13438 }; 13439 13440 gantt._render_sections = function (sns) { 13441 var html = ""; 13442 for (var i = 0; i < sns.length; i++) { 13443 var block = this.form_blocks[sns[i].type]; 13444 if (!block) continue; //ignore incorrect blocks 13445 sns[i].id = "area_" + this.uid(); 13446 13447 var display = sns[i].hidden ? " style='display:none'" : ""; 13448 var button = ""; 13449 if (sns[i].button) { 13450 button = "<div class='gantt_custom_button' data-index='" + i + "'><div class='gantt_custom_button_" + sns[i].button + "'></div><div class='gantt_custom_button_label'>" + this.locale.labels["button_" + sns[i].button] + "</div></div>"; 13451 } 13452 if (this.config.wide_form) { 13453 html += "<div class='gantt_wrap_section' " + display + ">"; 13454 } 13455 html += "<div id='" + sns[i].id + "' class='gantt_cal_lsection'><label>" + button + this.locale.labels["section_" + sns[i].name] + "</label></div>" + block.render.call(this, sns[i]); 13456 html += "</div>"; 13457 } 13458 return html; 13459 }; 13460 13461 13462 gantt.resizeLightbox = function () { 13463 if (!this._lightbox) return; 13464 13465 var con = this._lightbox.childNodes[1]; 13466 con.style.height = "0px"; 13467 con.style.height = con.scrollHeight + "px"; 13468 this._lightbox.style.height = con.scrollHeight + this.config.lightbox_additional_height + "px"; 13469 con.style.height = con.scrollHeight + "px"; //it is incredible , how ugly IE can be 13470 }; 13471 13472 gantt._center_lightbox = function (box) { 13473 if (box) { 13474 box.style.display = "block"; 13475 13476 var scroll_top = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop; 13477 var scroll_left = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft; 13478 13479 var view_height = window.innerHeight || document.documentElement.clientHeight; 13480 13481 if (scroll_top) // if vertical scroll on window 13482 box.style.top = Math.round(scroll_top + Math.max((view_height - box.offsetHeight) / 2, 0)) + "px"; 13483 else // vertical scroll on body 13484 box.style.top = Math.round(Math.max(((view_height - box.offsetHeight) / 2), 0) + 9) + "px"; // +9 for compatibility with auto tests 13485 13486 // not quite accurate but used for compatibility reasons 13487 if (document.documentElement.scrollWidth > document.body.offsetWidth) // if horizontal scroll on the window 13488 box.style.left = Math.round(scroll_left + (document.body.offsetWidth - box.offsetWidth) / 2) + "px"; 13489 else // horizontal scroll on the body 13490 box.style.left = Math.round((document.body.offsetWidth - box.offsetWidth) / 2) + "px"; 13491 } 13492 }; 13493 gantt.showCover = function () { 13494 if (this._cover) return; 13495 13496 this._cover = document.createElement("DIV"); 13497 this._cover.className = "gantt_cal_cover"; 13498 var _document_height = ((document.height !== undefined) ? document.height : document.body.offsetHeight); 13499 var _scroll_height = ((document.documentElement) ? document.documentElement.scrollHeight : 0); 13500 this._cover.style.height = Math.max(_document_height, _scroll_height) + "px"; 13501 document.body.appendChild(this._cover); 13502 }; 13503 13504 13505 gantt._init_lightbox_events = function () { 13506 gantt.lightbox_events = {}; 13507 13508 13509 gantt.lightbox_events.gantt_save_btn = function () { 13510 gantt._save_lightbox(); 13511 }; 13512 13513 13514 gantt.lightbox_events.gantt_delete_btn = function () { 13515 if (!gantt.callEvent("onLightboxDelete", [gantt._lightbox_id])) 13516 return; 13517 13518 if (gantt.isTaskExists(gantt._lightbox_id)) { 13519 gantt.$click.buttons["delete"](gantt._lightbox_id); 13520 } else { 13521 gantt.hideLightbox(); 13522 } 13523 13524 }; 13525 13526 13527 gantt.lightbox_events.gantt_cancel_btn = function () { 13528 gantt._cancel_lightbox(); 13529 }; 13530 13531 13532 gantt.lightbox_events["default"] = function (e, src) { 13533 if (src.getAttribute("data-dhx-button")) { 13534 gantt.callEvent("onLightboxButton", [src.className, src, e]); 13535 } else { 13536 var index, block, sec; 13537 13538 var className = domHelpers.getClassName(src); 13539 if (className.indexOf("gantt_custom_button") != -1) { 13540 if (className.indexOf("gantt_custom_button_") != -1) { 13541 index = src.parentNode.getAttribute("data-index"); 13542 sec = src; 13543 while (sec && domHelpers.getClassName(sec).indexOf("gantt_cal_lsection") == -1) { 13544 sec = sec.parentNode; 13545 } 13546 } else { 13547 index = src.getAttribute("data-index"); 13548 sec = src.parentNode; 13549 src = src.firstChild; 13550 } 13551 } 13552 13553 var sections = gantt._get_typed_lightbox_config(); 13554 13555 if (index) { 13556 index = index * 1; 13557 block = gantt.form_blocks[sections[index * 1].type]; 13558 block.button_click(index, src, sec, sec.nextSibling); 13559 } 13560 } 13561 }; 13562 this.event(gantt.getLightbox(), "click", function (e) { 13563 e = e || window.event; 13564 var src = e.target ? e.target : e.srcElement; 13565 13566 var className = domHelpers.getClassName(src); 13567 if (!className) { 13568 src = src.previousSibling; 13569 className = domHelpers.getClassName(src); 13570 } 13571 if (src && className && className.indexOf("gantt_btn_set") === 0) { 13572 src = src.firstChild; 13573 className = domHelpers.getClassName(src); 13574 } 13575 if (src && className) { 13576 var func = gantt.defined(gantt.lightbox_events[src.className]) ? gantt.lightbox_events[src.className] : gantt.lightbox_events["default"]; 13577 return func(e, src); 13578 } 13579 return false; 13580 }); 13581 13582 gantt.getLightbox().onkeydown = function (e) { 13583 var event = e || window.event; 13584 var target = e.target || e.srcElement; 13585 var buttonTarget = domHelpers.getClassName(target).indexOf("gantt_btn_set") > -1; 13586 13587 switch ((e || event).keyCode) { 13588 case gantt.constants.KEY_CODES.SPACE: { 13589 if ((e || event).shiftKey) return; 13590 if (buttonTarget && target.click) { 13591 target.click(); 13592 } 13593 break; 13594 } 13595 case gantt.keys.edit_save: 13596 if ((e || event).shiftKey) return; 13597 if (buttonTarget && target.click) { 13598 target.click(); 13599 } else { 13600 gantt._save_lightbox(); 13601 } 13602 break; 13603 case gantt.keys.edit_cancel: 13604 gantt._cancel_lightbox(); 13605 break; 13606 default: 13607 break; 13608 } 13609 }; 13610 }; 13611 13612 gantt._cancel_lightbox = function () { 13613 var task = this.getLightboxValues(); 13614 this.callEvent("onLightboxCancel", [this._lightbox_id, task.$new]); 13615 if (gantt.isTaskExists(task.id) && task.$new) { 13616 this.silent(function () { 13617 gantt.$data.tasksStore.removeItem(task.id); 13618 gantt._update_flags(task.id, null); 13619 }); 13620 } 13621 13622 this.refreshData(); 13623 this.hideLightbox(); 13624 }; 13625 13626 gantt._save_lightbox = function () { 13627 var task = this.getLightboxValues(); 13628 if (!this.callEvent("onLightboxSave", [this._lightbox_id, task, !!task.$new])) 13629 return; 13630 13631 if (task.$new) { 13632 delete task.$new; 13633 this.addTask(task, task.parent, this.getTaskIndex(task.id)); 13634 } else if (this.isTaskExists(task.id)) { 13635 this.mixin(this.getTask(task.id), task, true); 13636 this.refreshTask(task.id); 13637 this.updateTask(task.id); 13638 } 13639 this.refreshData(); 13640 13641 // TODO: do we need any blockable events here to prevent closing lightbox? 13642 this.hideLightbox(); 13643 }; 13644 13645 gantt._resolve_default_mapping = function (section) { 13646 var mapping = section.map_to; 13647 var time_controls = { "time": true, "time_optional": true, "duration": true, "duration_optional": true }; 13648 if (time_controls[section.type]) { 13649 if (section.map_to == "auto") { 13650 mapping = { start_date: "start_date", end_date: "end_date", duration: "duration" }; 13651 } else if (typeof (section.map_to) === "string") { 13652 mapping = { start_date: section.map_to }; 13653 } 13654 } else if (section.type === "constraint") { 13655 if (!section.map_to || typeof (section.map_to) === "string") { 13656 mapping = { constraint_type: "constraint_type", constraint_date: "constraint_date" }; 13657 } 13658 } 13659 13660 return mapping; 13661 }; 13662 13663 gantt.getLightboxValues = function () { 13664 var task = {}; 13665 13666 if (gantt.isTaskExists(this._lightbox_id)) { 13667 task = this.mixin({}, this.getTask(this._lightbox_id)); 13668 } 13669 13670 var sns = this._get_typed_lightbox_config(); 13671 for (var i = 0; i < sns.length; i++) { 13672 var node = document.getElementById(sns[i].id); 13673 node = (node ? node.nextSibling : node); 13674 var block = this.form_blocks[sns[i].type]; 13675 if (!block) continue; 13676 var res = block.get_value.call(this, node, task, sns[i]); 13677 var map_to = gantt._resolve_default_mapping(sns[i]); 13678 if (typeof map_to == "string" && map_to != "auto") { 13679 task[map_to] = res; 13680 } else if (typeof map_to == "object") { 13681 for (var property in map_to) { 13682 if (map_to[property]) 13683 task[map_to[property]] = res[property]; 13684 } 13685 } 13686 } 13687 return task; 13688 }; 13689 13690 13691 gantt.hideLightbox = function () { 13692 var box = this.getLightbox(); 13693 if (box) box.style.display = "none"; 13694 13695 this._waiAria.lightboxHiddenAttr(box); 13696 this._lightbox_id = null; 13697 13698 this.hideCover(); 13699 this.callEvent("onAfterLightbox", []); 13700 }; 13701 gantt.hideCover = function () { 13702 if (this._cover) 13703 this._cover.parentNode.removeChild(this._cover); 13704 this._cover = null; 13705 }; 13706 13707 gantt.resetLightbox = function () { 13708 if (gantt._lightbox && !gantt._custom_lightbox) 13709 gantt._lightbox.parentNode.removeChild(gantt._lightbox); 13710 gantt._lightbox = null; 13711 gantt.hideCover(); 13712 }; 13713 gantt._set_lightbox_values = function (data, box) { 13714 var task = data; 13715 var s = box.getElementsByTagName("span"); 13716 var lightboxHeader = []; 13717 if (gantt.templates.lightbox_header) { 13718 lightboxHeader.push(""); 13719 lightboxHeader.push(gantt.templates.lightbox_header(task.start_date, task.end_date, task)); 13720 s[1].innerHTML = ""; 13721 s[2].innerHTML = gantt.templates.lightbox_header(task.start_date, task.end_date, task); 13722 } else { 13723 lightboxHeader.push(this.templates.task_time(task.start_date, task.end_date, task)); 13724 lightboxHeader.push(String(this.templates.task_text(task.start_date, task.end_date, task) || "").substr(0, 70)); //IE6 fix 13725 s[1].innerHTML = this.templates.task_time(task.start_date, task.end_date, task); 13726 s[2].innerHTML = String(this.templates.task_text(task.start_date, task.end_date, task) || "").substr(0, 70); //IE6 fix 13727 } 13728 s[1].innerHTML = lightboxHeader[0]; 13729 s[2].innerHTML = lightboxHeader[1]; 13730 13731 gantt._waiAria.lightboxHeader(box, lightboxHeader.join(" ")); 13732 13733 var sns = this._get_typed_lightbox_config(this.getLightboxType()); 13734 for (var i = 0; i < sns.length; i++) { 13735 var section = sns[i]; 13736 13737 if (!this.form_blocks[section.type]) { 13738 continue;//skip incorrect sections, same check is done during rendering 13739 } 13740 13741 13742 var node = document.getElementById(section.id).nextSibling; 13743 var block = this.form_blocks[section.type]; 13744 var map_to = gantt._resolve_default_mapping(sns[i]); 13745 var value = this.defined(task[map_to]) ? task[map_to] : section.default_value; 13746 block.set_value.call(gantt, node, value, task, section); 13747 13748 if (section.focus) 13749 block.focus.call(gantt, node); 13750 } 13751 if (data.id) 13752 gantt._lightbox_id = data.id; 13753 }; 13754 gantt._fill_lightbox = function (id, box) { 13755 var task = this.getTask(id); 13756 this._set_lightbox_values(task, box); 13757 }; 13758 13759 13760 gantt.getLightboxSection = function (name) { 13761 var config = this._get_typed_lightbox_config(); 13762 var i = 0; 13763 for (i; i < config.length; i++) 13764 if (config[i].name == name) 13765 break; 13766 var section = config[i]; 13767 if (!section) 13768 return null; 13769 13770 if (!this._lightbox) 13771 this.getLightbox(); 13772 var header = document.getElementById(section.id); 13773 var node = header.nextSibling; 13774 13775 var result = { 13776 section: section, 13777 header: header, 13778 node: node, 13779 getValue: function (ev) { 13780 return gantt.form_blocks[section.type].get_value.call(gantt, node, (ev || {}), section); 13781 }, 13782 setValue: function (value, ev) { 13783 return gantt.form_blocks[section.type].set_value.call(gantt, node, value, (ev || {}), section); 13784 } 13785 }; 13786 13787 var handler = this._lightbox_methods["get_" + section.type + "_control"]; 13788 return handler ? handler(result) : result; 13789 }; 13790 13791 gantt._lightbox_methods.get_template_control = function (result) { 13792 result.control = result.node; 13793 return result; 13794 }; 13795 gantt._lightbox_methods.get_select_control = function (result) { 13796 result.control = result.node.getElementsByTagName("select")[0]; 13797 return result; 13798 }; 13799 gantt._lightbox_methods.get_textarea_control = function (result) { 13800 result.control = result.node.getElementsByTagName("textarea")[0]; 13801 return result; 13802 }; 13803 gantt._lightbox_methods.get_time_control = function (result) { 13804 result.control = result.node.getElementsByTagName("select"); // array 13805 return result; 13806 }; 13807 13808 13809 gantt._init_dnd_events = function () { 13810 this.event(document.body, "mousemove", gantt._move_while_dnd); 13811 this.event(document.body, "mouseup", gantt._finish_dnd); 13812 gantt._init_dnd_events = function () { 13813 }; 13814 }; 13815 gantt._move_while_dnd = function (e) { 13816 if (gantt._dnd_start_lb) { 13817 if (!document.gantt_unselectable) { 13818 document.body.className += " gantt_unselectable"; 13819 document.gantt_unselectable = true; 13820 } 13821 var lb = gantt.getLightbox(); 13822 var now = (e && e.target) ? [e.pageX, e.pageY] : [event.clientX, event.clientY]; 13823 lb.style.top = gantt._lb_start[1] + now[1] - gantt._dnd_start_lb[1] + "px"; 13824 lb.style.left = gantt._lb_start[0] + now[0] - gantt._dnd_start_lb[0] + "px"; 13825 } 13826 }; 13827 gantt._ready_to_dnd = function (e) { 13828 var lb = gantt.getLightbox(); 13829 gantt._lb_start = [parseInt(lb.style.left, 10), parseInt(lb.style.top, 10)]; 13830 gantt._dnd_start_lb = (e && e.target) ? [e.pageX, e.pageY] : [event.clientX, event.clientY]; 13831 }; 13832 gantt._finish_dnd = function () { 13833 if (gantt._lb_start) { 13834 gantt._lb_start = gantt._dnd_start_lb = false; 13835 document.body.className = document.body.className.replace(" gantt_unselectable", ""); 13836 document.gantt_unselectable = false; 13837 } 13838 }; 13839 13840 13841 gantt._focus = function (node, select) { 13842 if (node && node.focus) { 13843 if (gantt.config.touch) { 13844 //do not focus editor, to prevent auto-zoom 13845 } else { 13846 try { 13847 if (select && node.select) node.select(); 13848 node.focus(); 13849 } catch (e) { 13850 // silent errors 13851 } 13852 } 13853 } 13854 }; 13855 13856 13857 gantt.form_blocks = { 13858 getTimePicker: function (sns, hidden) { 13859 var html = ""; 13860 var cfg = this.config; 13861 var i; 13862 var options; 13863 var ariaAttrs; 13864 var readonly; 13865 var display; 13866 var settings = { 13867 first: 0, 13868 last: 24 * 60, 13869 date: this.date.date_part(new Date(gantt._min_date.valueOf())), 13870 timeFormat: getTimeFormat(sns) 13871 }; 13872 13873 // map: default order => real one 13874 sns._time_format_order = { size: 0 }; 13875 13876 if (gantt.config.limit_time_select) { 13877 settings.first = 60 * cfg.first_hour; 13878 settings.last = 60 * cfg.last_hour + 1; 13879 settings.date.setHours(cfg.first_hour); 13880 } 13881 13882 for (i = 0; i < settings.timeFormat.length; i++) { 13883 // adding spaces between selects 13884 if (i > 0) { 13885 html += " "; 13886 } 13887 13888 options = getHtmlTimePickerOptions(sns, i, settings); 13889 13890 if (options) { 13891 ariaAttrs = gantt._waiAria.lightboxSelectAttrString(settings.timeFormat[i]); 13892 readonly = sns.readonly ? "disabled='disabled'" : ""; 13893 display = hidden ? " style='display:none' " : ""; 13894 html += "<select " + readonly + display + ariaAttrs + ">" + options + "</select>"; 13895 } 13896 } 13897 return html; 13898 }, 13899 getTimePickerValue: function (selects, config, offset) { 13900 var map = config._time_format_order; 13901 var needSetTime = gantt.defined(map[3]); 13902 13903 var time; 13904 var hours = 0; 13905 var minutes = 0; 13906 13907 var mapOffset = offset || 0; 13908 13909 if (needSetTime) { 13910 time = parseInt(selects[map[3] + mapOffset].value, 10); 13911 hours = Math.floor(time / 60); 13912 minutes = time % 60; 13913 } 13914 return new Date(selects[map[2] + mapOffset].value, selects[map[1] + mapOffset].value, selects[map[0] + mapOffset].value, hours, minutes); 13915 }, 13916 13917 _fill_lightbox_select: function (s, i, d, map) { 13918 s[i + map[0]].value = d.getDate(); 13919 s[i + map[1]].value = d.getMonth(); 13920 s[i + map[2]].value = d.getFullYear(); 13921 if (gantt.defined(map[3])) { 13922 var v = d.getHours() * 60 + d.getMinutes(); 13923 v = Math.round(v / gantt._get_timepicker_step()) * gantt._get_timepicker_step(); 13924 var input = s[i + map[3]]; 13925 input.value = v; 13926 //in case option not shown 13927 input.setAttribute("data-value", v); 13928 } 13929 }, 13930 template: new TemplateControl(), 13931 textarea: new TextareaControl(), 13932 select: new SelectControl(), 13933 time: new TimeControl(), 13934 duration: new DurationControl(), 13935 parent: new ParentControl(), 13936 radio: new RadioControl(), 13937 checkbox: new CheckboxControl(), 13938 resources: new ResourcesControl(), 13939 constraint: new ConstraintControl() 13940 }; 13941 13942 gantt._is_lightbox_timepicker = function () { 13943 var s = this._get_typed_lightbox_config(); 13944 for (var i = 0; i < s.length; i++) 13945 if (s[i].name == "time" && s[i].type == "time") 13946 return true; 13947 return false; 13948 }; 13949 13950 gantt._dhtmlx_confirm = function (message, title, callback, ok) { 13951 if (!message) 13952 return callback(); 13953 var opts = { text: message }; 13954 if (title) 13955 opts.title = title; 13956 if (ok) { 13957 opts.ok = ok; 13958 } 13959 if (callback) { 13960 opts.callback = function (result) { 13961 if (result) 13962 callback(); 13963 }; 13964 } 13965 gantt.confirm(opts); 13966 }; 13967 13968 function _get_type_name(type_value) { 13969 for (var i in this.config.types) { 13970 if (this.config.types[i] == type_value) { 13971 return i; 13972 } 13973 } 13974 return "task"; 13975 } 13976 13977 gantt._get_typed_lightbox_config = function (type) { 13978 if (type === undefined) { 13979 type = this.getLightboxType(); 13980 } 13981 13982 var field = _get_type_name.call(this, type); 13983 13984 if (gantt.config.lightbox[field + "_sections"]) { 13985 return gantt.config.lightbox[field + "_sections"]; 13986 } else { 13987 return gantt.config.lightbox.sections; 13988 } 13989 }; 13990 13991 gantt._silent_redraw_lightbox = function (type) { 13992 var oldType = this.getLightboxType(); 13993 13994 if (this.getState().lightbox) { 13995 var taskId = this.getState().lightbox; 13996 var formData = this.getLightboxValues(), 13997 task = this.copy(this.getTask(taskId)); 13998 13999 this.resetLightbox(); 14000 14001 var updTask = this.mixin(task, formData, true); 14002 var box = this.getLightbox(type ? type : undefined); 14003 this._center_lightbox(this.getLightbox()); 14004 this._set_lightbox_values(updTask, box); 14005 this.showCover(); 14006 } else { 14007 this.resetLightbox(); 14008 this.getLightbox(type ? type : undefined); 14009 } 14010 this.callEvent("onLightboxChange", [oldType, this.getLightboxType()]); 14011 }; 14012 14013 function bindLabelsToInputs(sns) { 14014 var section; 14015 var label; 14016 var labelBlock; 14017 var inputBlock; 14018 var input; 14019 var i; 14020 14021 for (i = 0; i < sns.length; i++) { 14022 section = sns[i]; 14023 labelBlock = document.getElementById(section.id); 14024 14025 if (!section.id || !labelBlock) continue; 14026 14027 label = labelBlock.querySelector("label"); 14028 inputBlock = labelBlock.nextSibling; 14029 14030 if (!inputBlock) continue; 14031 14032 input = inputBlock.querySelector("input, select, textarea"); 14033 if (input) { 14034 input.id = input.id || "input_" + gantt.uid(); 14035 section.inputId = input.id; 14036 label.setAttribute("for", section.inputId); 14037 } 14038 } 14039 } 14040 14041 function getHtmlButtons(buttons, floatRight) { 14042 var button; 14043 var ariaAttr; 14044 var html = ""; 14045 var i; 14046 14047 for (i = 0; i < buttons.length; i++) { 14048 // needed to migrate from 'dhx_something' to 'gantt_something' naming in a lightbox 14049 button = gantt.config._migrate_buttons[buttons[i]] ? gantt.config._migrate_buttons[buttons[i]] : buttons[i]; 14050 14051 ariaAttr = gantt._waiAria.lightboxButtonAttrString(button); 14052 html += "<div " + ariaAttr + " class='gantt_btn_set gantt_left_btn_set " + button + "_set'" + (floatRight ? " style='float:right;'" : "") + "><div dhx_button='1' data-dhx-button='1' class='" + button + "'></div><div>" + gantt.locale.labels[button] + "</div></div>"; 14053 } 14054 return html; 14055 } 14056 14057 function getTimeFormat(sns) { 14058 var scale; 14059 var unit; 14060 var result; 14061 14062 if (sns.time_format) return sns.time_format; 14063 14064 // default order 14065 result = ["%d", "%m", "%Y"]; 14066 scale = gantt.getScale(); 14067 unit = scale ? scale.unit : gantt.config.duration_unit; 14068 if (helpers.getSecondsInUnit(unit) < helpers.getSecondsInUnit("day")) { 14069 result.push("%H:%i"); 14070 } 14071 return result; 14072 } 14073 14074 function getHtmlTimePickerOptions(sns, index, settings) { 14075 var range; 14076 var offset; 14077 var start_year; 14078 var end_year; 14079 var i; 14080 var time; 14081 var diff; 14082 var tdate; 14083 var html = ""; 14084 14085 switch (settings.timeFormat[index]) { 14086 case "%Y": 14087 sns._time_format_order[2] = index; 14088 sns._time_format_order.size++; 14089 //year 14090 14091 if (sns.year_range) { 14092 if (!isNaN(sns.year_range)) { 14093 range = sns.year_range; 14094 } else if (sns.year_range.push) { 14095 // if 14096 start_year = sns.year_range[0]; 14097 end_year = sns.year_range[1]; 14098 } 14099 } 14100 14101 range = range || 10; 14102 offset = offset || Math.floor(range / 2); 14103 start_year = start_year || settings.date.getFullYear() - offset; 14104 end_year = end_year || start_year + range; 14105 14106 for (i = start_year; i < end_year; i++) 14107 html += "<option value='" + (i) + "'>" + (i) + "</option>"; 14108 break; 14109 case "%m": 14110 sns._time_format_order[1] = index; 14111 sns._time_format_order.size++; 14112 //month 14113 for (i = 0; i < 12; i++) 14114 html += "<option value='" + i + "'>" + gantt.locale.date.month_full[i] + "</option>"; 14115 break; 14116 case "%d": 14117 sns._time_format_order[0] = index; 14118 sns._time_format_order.size++; 14119 //days 14120 for (i = 1; i < 32; i++) 14121 html += "<option value='" + i + "'>" + i + "</option>"; 14122 break; 14123 case "%H:%i": 14124 // var last = 24*60, first = 0; 14125 sns._time_format_order[3] = index; 14126 sns._time_format_order.size++; 14127 //hours 14128 i = settings.first; 14129 tdate = settings.date.getDate(); 14130 sns._time_values = []; 14131 14132 while (i < settings.last) { 14133 time = gantt.templates.time_picker(settings.date); 14134 html += "<option value='" + i + "'>" + time + "</option>"; 14135 sns._time_values.push(i); 14136 settings.date.setTime(settings.date.valueOf() + gantt._get_timepicker_step() * 60 * 1000); 14137 diff = (settings.date.getDate() != tdate) ? 1 : 0; // moved or not to the next day 14138 i = diff * 24 * 60 + settings.date.getHours() * 60 + settings.date.getMinutes(); 14139 } 14140 break; 14141 default: 14142 break; 14143 } 14144 return html; 14145 } 14146}; 14147 14148/***/ }), 14149 14150/***/ "./sources/core/lightbox_optional_time.js": 14151/*!************************************************!*\ 14152 !*** ./sources/core/lightbox_optional_time.js ***! 14153 \************************************************/ 14154/*! no static exports found */ 14155/***/ (function(module, exports) { 14156 14157module.exports = function(gantt) { 14158 14159 gantt._extend_to_optional = function (lightbox_block) { 14160 14161 var duration = lightbox_block; 14162 var optional_time = { 14163 render: duration.render, 14164 focus: duration.focus, 14165 set_value: function (node, value, task, section) { 14166 var mapping = gantt._resolve_default_mapping(section); 14167 if (!task[mapping.start_date] || (mapping.start_date == "start_date" && this._isAllowedUnscheduledTask(task))) { 14168 optional_time.disable(node, section); 14169 var val = {}; 14170 14171 for (var i in mapping) { 14172 //take default values from the time control from task start/end dates 14173 val[mapping[i]] = task[i]; 14174 } 14175 14176 return duration.set_value.call(gantt, node, value, val, section);//set default value 14177 } else { 14178 optional_time.enable(node, section); 14179 return duration.set_value.call(gantt, node, value, task, section); 14180 } 14181 }, 14182 get_value: function (node, task, section) { 14183 if (section.disabled) { 14184 return {start_date: null}; 14185 } else { 14186 return duration.get_value.call(gantt, node, task, section); 14187 } 14188 }, 14189 update_block: function (node, section) { 14190 gantt.callEvent("onSectionToggle", [gantt._lightbox_id, section]); 14191 node.style.display = section.disabled ? "none" : "block"; 14192 14193 if (section.button) { 14194 var button = node.previousSibling.querySelector(".gantt_custom_button_label"), 14195 labels = gantt.locale.labels; 14196 14197 var button_text = section.disabled ? labels[section.name + "_enable_button"] : labels[section.name + "_disable_button"]; 14198 14199 button.innerHTML = button_text; 14200 } 14201 gantt.resizeLightbox(); 14202 }, 14203 disable: function (node, section) { 14204 section.disabled = true; 14205 optional_time.update_block(node, section); 14206 14207 }, 14208 enable: function (node, section) { 14209 section.disabled = false; 14210 optional_time.update_block(node, section); 14211 }, 14212 button_click: function (index, el, section, container) { 14213 if (gantt.callEvent("onSectionButton", [gantt._lightbox_id, section]) === false) { 14214 return; 14215 } 14216 var config = gantt._get_typed_lightbox_config()[index]; 14217 if (config.disabled) { 14218 optional_time.enable(container, config); 14219 } else { 14220 optional_time.disable(container, config); 14221 } 14222 } 14223 }; 14224 return optional_time; 14225 }; 14226 14227 gantt.form_blocks.duration_optional = gantt._extend_to_optional(gantt.form_blocks.duration); 14228 gantt.form_blocks.time_optional = gantt._extend_to_optional(gantt.form_blocks.time); 14229 14230}; 14231 14232/***/ }), 14233 14234/***/ "./sources/core/load.js": 14235/*!******************************!*\ 14236 !*** ./sources/core/load.js ***! 14237 \******************************/ 14238/*! no static exports found */ 14239/***/ (function(module, exports, __webpack_require__) { 14240 14241var helpers = __webpack_require__(/*! ../utils/helpers */ "./sources/utils/helpers.js"); 14242 14243module.exports = function(gantt) { 14244 14245 gantt.load = function (url, type, callback) { 14246 this._load_url = url; 14247 this.assert(arguments.length, "Invalid load arguments"); 14248 14249 var tp = 'json', cl = null; 14250 if (arguments.length >= 3) { 14251 tp = type; 14252 cl = callback; 14253 } else { 14254 if (typeof arguments[1] == "string") 14255 tp = arguments[1]; 14256 else if (typeof arguments[1] == "function") 14257 cl = arguments[1]; 14258 } 14259 14260 this._load_type = tp; 14261 14262 this.callEvent("onLoadStart", [url, tp]); 14263 14264 return this.ajax.get(url, gantt.bind(function (l) { 14265 this.on_load(l, tp); 14266 this.callEvent("onLoadEnd", [url, tp]); 14267 if (typeof cl == "function") 14268 cl.call(this); 14269 }, this)); 14270 }; 14271 gantt.parse = function (data, type) { 14272 this.on_load({xmlDoc: {responseText: data}}, type); 14273 }; 14274 14275 gantt.serialize = function (type) { 14276 type = type || "json"; 14277 return this[type].serialize(); 14278 }; 14279 14280 /* 14281 tasks and relations 14282 { 14283 data:[ 14284 { 14285 "id":"string", 14286 "text":"...", 14287 "start_date":"Date or string", 14288 "end_date":"Date or string", 14289 "duration":"number", 14290 "progress":"0..1", 14291 "parent_id":"string", 14292 "order":"number" 14293 },...], 14294 links:[ 14295 { 14296 id:"string", 14297 source:"string", 14298 target:"string", 14299 type:"string" 14300 },...], 14301 collections:{ 14302 collectionName:[ 14303 {key:, label:, optional:...},... 14304 ],... 14305 } 14306 } 14307 14308 * */ 14309 14310 gantt.on_load = function (resp, type) { 14311 if(resp.xmlDoc && resp.xmlDoc.status === 404){ // work if we don't have a file at current url 14312 this.assert(false, "Failed to load the data from <a href='" + resp.xmlDoc.responseURL + "' target='_blank'>" 14313 + resp.xmlDoc.responseURL + "</a>, server returns 404"); 14314 return; 14315 } 14316 this.callEvent("onBeforeParse", []); 14317 if (!type) 14318 type = "json"; 14319 this.assert(this[type], "Invalid data type:'" + type + "'"); 14320 14321 var raw = resp.xmlDoc.responseText; 14322 14323 var data = this[type].parse(raw, resp); 14324 this._process_loading(data); 14325 }; 14326 14327 gantt._process_loading = function (data) { 14328 if(data.collections) 14329 this._load_collections(data.collections); 14330 14331 this.$data.tasksStore.parse(data.data); 14332 var links = data.links || (data.collections ? data.collections.links : []); 14333 this.$data.linksStore.parse(links); 14334 14335 //this._sync_links(); 14336 this.callEvent("onParse", []); 14337 this.render(); 14338 if(this.config.initial_scroll){ 14339 var firstTask = this.getTaskByIndex(0); 14340 var id = firstTask ? firstTask.id : this.config.root_id; 14341 if(this.isTaskExists(id)) 14342 this.showTask(id); 14343 } 14344 }; 14345 14346 14347 gantt._load_collections = function (collections) { 14348 var collections_loaded = false; 14349 for (var key in collections) { 14350 if (collections.hasOwnProperty(key)) { 14351 collections_loaded = true; 14352 var collection = collections[key]; 14353 var arr = this.serverList[key]; 14354 if (!arr) continue; 14355 arr.splice(0, arr.length); //clear old options 14356 for (var j = 0; j < collection.length; j++) { 14357 var option = collection[j]; 14358 var obj = this.copy(option); 14359 obj.key = obj.value;// resulting option object 14360 14361 for (var option_key in option) { 14362 if (option.hasOwnProperty(option_key)) { 14363 if (option_key == "value" || option_key == "label") 14364 continue; 14365 obj[option_key] = option[option_key]; // obj['value'] = option['value'] 14366 } 14367 } 14368 arr.push(obj); 14369 } 14370 } 14371 } 14372 if (collections_loaded) 14373 this.callEvent("onOptionsLoad", []); 14374 }; 14375 14376 gantt.attachEvent("onBeforeTaskDisplay", function (id, task) { 14377 return !task.$ignore; 14378 }); 14379 14380 function jsonParseError(data){ 14381 gantt.assert(false, "Can't parse data: incorrect value of gantt.parse or gantt.load method. " 14382 + "Actual argument value: " + JSON.stringify(data)); 14383 throw new Error("Invalid argument for gantt.parse or gantt.load. An object or a JSON string of format https://docs.dhtmlx.com/gantt/desktop__supported_data_formats.html#json is expected. Actual argument value: " 14384 + JSON.stringify(data)); 14385 } 14386 14387 gantt.json = { 14388 parse: function (data) { 14389 if(!data){ 14390 jsonParseError(data); 14391 } 14392 14393 if (typeof data == "string") { 14394 if (window.JSON){ 14395 try{ 14396 data = JSON.parse(data); 14397 } 14398 catch(e) { 14399 jsonParseError(data); 14400 } 14401 } else { 14402 gantt.assert(false, "JSON is not supported"); 14403 } 14404 } 14405 14406 if(!data.data){ 14407 jsonParseError(data); 14408 } 14409 14410 if (data.dhx_security) 14411 gantt.security_key = data.dhx_security; 14412 return data; 14413 }, 14414 serializeTask: function (task) { 14415 return this._copyObject(task); 14416 }, 14417 serializeLink: function (link) { 14418 return this._copyLink(link); 14419 }, 14420 _copyLink: function (obj) { 14421 var copy = {}; 14422 for (var key in obj) 14423 copy[key] = obj[key]; 14424 return copy; 14425 }, 14426 _copyObject: function (obj) { 14427 var copy = {}; 14428 for (var key in obj) { 14429 if (key.charAt(0) == "$") 14430 continue; 14431 copy[key] = obj[key]; 14432 14433 if (helpers.isDate(copy[key])) { 14434 copy[key] = gantt.templates.xml_format !== gantt.templates.formate_date ? gantt.templates.xml_format(copy[key]) : gantt.templates.formate_date(copy[key]); 14435 } 14436 } 14437 return copy; 14438 }, 14439 serialize: function () { 14440 var tasks = []; 14441 var links = []; 14442 14443 gantt.eachTask(function (obj) { 14444 gantt.resetProjectDates(obj); 14445 tasks.push(this.serializeTask(obj)); 14446 }, gantt.config.root_id, this); 14447 14448 var rawLinks = gantt.getLinks(); 14449 for (var i = 0; i < rawLinks.length; i++) { 14450 links.push(this.serializeLink(rawLinks[i])); 14451 } 14452 14453 return { 14454 data: tasks, 14455 links: links 14456 }; 14457 } 14458 }; 14459 14460 /* 14461 <data> 14462 <task id:"some" parent_id="0" progress="0.5"> 14463 <text>My task 1</text> 14464 <start_date>16.08.2013</start_date> 14465 <end_date>22.08.2013</end_date> 14466 </task> 14467 <coll_options> 14468 <links> 14469 <link source='a1' target='b2' type='c3' /> 14470 </links> 14471 </coll_options> 14472 </data> 14473 */ 14474 14475 function xmlParseError(data){ 14476 gantt.assert(false, "Can't parse data: incorrect value of gantt.parse or gantt.load method. " 14477 + "Actual argument value: " + JSON.stringify(data)); 14478 throw new Error("Invalid argument for gantt.parse or gantt.load. An XML of format https://docs.dhtmlx.com/gantt/desktop__supported_data_formats.html#xmldhtmlxgantt20 is expected. Actual argument value: " 14479 + JSON.stringify(data)); 14480 } 14481 14482 gantt.xml = { 14483 _xmlNodeToJSON: function (node, attrs_only) { 14484 var t = {}; 14485 for (var i = 0; i < node.attributes.length; i++) 14486 t[node.attributes[i].name] = node.attributes[i].value; 14487 14488 if (!attrs_only) { 14489 for (var i = 0; i < node.childNodes.length; i++) { 14490 var child = node.childNodes[i]; 14491 if (child.nodeType == 1) 14492 t[child.tagName] = child.firstChild ? child.firstChild.nodeValue : ""; 14493 } 14494 14495 if (!t.text) t.text = node.firstChild ? node.firstChild.nodeValue : ""; 14496 } 14497 14498 return t; 14499 }, 14500 _getCollections: function (loader) { 14501 var collection = {}; 14502 var opts = gantt.ajax.xpath("//coll_options", loader); 14503 for (var i = 0; i < opts.length; i++) { 14504 var bind = opts[i].getAttribute("for"); 14505 var arr = collection[bind] = []; 14506 var itms = gantt.ajax.xpath(".//item", opts[i]); 14507 for (var j = 0; j < itms.length; j++) { 14508 var itm = itms[j]; 14509 var attrs = itm.attributes; 14510 var obj = {key: itms[j].getAttribute("value"), label: itms[j].getAttribute("label")}; 14511 for (var k = 0; k < attrs.length; k++) { 14512 var attr = attrs[k]; 14513 if (attr.nodeName == "value" || attr.nodeName == "label") 14514 continue; 14515 obj[attr.nodeName] = attr.nodeValue; 14516 } 14517 arr.push(obj); 14518 } 14519 } 14520 return collection; 14521 }, 14522 _getXML: function (text, loader, toptag) { 14523 toptag = toptag || "data"; 14524 if (!loader.getXMLTopNode) { 14525 loader = gantt.ajax.parse(loader); 14526 } 14527 14528 var xml = gantt.ajax.xmltop(toptag, loader.xmlDoc); 14529 if (!xml || xml.tagName != toptag) { 14530 xmlParseError(text); 14531 } 14532 14533 var skey = xml.getAttribute("dhx_security"); 14534 if (skey) 14535 gantt.security_key = skey; 14536 14537 return xml; 14538 }, 14539 parse: function (text, loader) { 14540 loader = this._getXML(text, loader); 14541 var data = {}; 14542 14543 var evs = data.data = []; 14544 var xml = gantt.ajax.xpath("//task", loader); 14545 14546 for (var i = 0; i < xml.length; i++) 14547 evs[i] = this._xmlNodeToJSON(xml[i]); 14548 14549 data.collections = this._getCollections(loader); 14550 return data; 14551 }, 14552 _copyLink: function (obj) { 14553 return "<item id='" + obj.id + "' source='" + obj.source + "' target='" + obj.target + "' type='" + obj.type + "' />"; 14554 }, 14555 _copyObject: function (obj) { 14556 return "<task id='" + obj.id + "' parent='" + (obj.parent || "") + "' start_date='" + obj.start_date + "' duration='" + obj.duration + "' open='" + (!!obj.open) + "' progress='" + obj.progress + "' end_date='" + obj.end_date + "'><![CDATA[" + obj.text + "]]></task>"; 14557 }, 14558 serialize: function () { 14559 var tasks = []; 14560 var links = []; 14561 14562 var json = gantt.json.serialize(); 14563 for (var i = 0, len = json.data.length; i < len; i++) { 14564 tasks.push(this._copyObject(json.data[i])); 14565 } 14566 for (var i = 0, len = json.links.length; i < len; i++) { 14567 links.push(this._copyLink(json.links[i])); 14568 } 14569 return "<data>" + tasks.join("") + "<coll_options for='links'>" + links.join("") + "</coll_options></data>"; 14570 } 14571 }; 14572 14573 14574 gantt.oldxml = { 14575 parse: function (text, loader) { 14576 loader = gantt.xml._getXML(text, loader, "projects"); 14577 var data = {collections: {links: []}}; 14578 14579 var evs = data.data = []; 14580 var xml = gantt.ajax.xpath("//task", loader); 14581 14582 for (var i = 0; i < xml.length; i++) { 14583 evs[i] = gantt.xml._xmlNodeToJSON(xml[i]); 14584 var parent = xml[i].parentNode; 14585 14586 if (parent.tagName == "project") 14587 evs[i].parent = "project-" + parent.getAttribute("id"); 14588 else 14589 evs[i].parent = parent.parentNode.getAttribute("id"); 14590 } 14591 14592 xml = gantt.ajax.xpath("//project", loader); 14593 for (var i = 0; i < xml.length; i++) { 14594 var ev = gantt.xml._xmlNodeToJSON(xml[i], true); 14595 ev.id = "project-" + ev.id; 14596 evs.push(ev); 14597 } 14598 14599 for (var i = 0; i < evs.length; i++) { 14600 var ev = evs[i]; 14601 ev.start_date = ev.startdate || ev.est; 14602 ev.end_date = ev.enddate; 14603 ev.text = ev.name; 14604 ev.duration = ev.duration / 8; 14605 ev.open = 1; 14606 if (!ev.duration && !ev.end_date) ev.duration = 1; 14607 if (ev.predecessortasks) 14608 data.collections.links.push({ 14609 target: ev.id, 14610 source: ev.predecessortasks, 14611 type: gantt.config.links.finish_to_start 14612 }); 14613 } 14614 14615 return data; 14616 }, 14617 serialize: function () { 14618 gantt.message("Serialization to 'old XML' is not implemented"); 14619 } 14620 }; 14621 14622 gantt.serverList = function (name, array) { 14623 if (array) { 14624 this.serverList[name] = array.slice(0); 14625 } else if (!this.serverList[name]) { 14626 this.serverList[name] = []; 14627 } 14628 return this.serverList[name]; 14629 }; 14630 14631}; 14632 14633/***/ }), 14634 14635/***/ "./sources/core/message.js": 14636/*!*********************************!*\ 14637 !*** ./sources/core/message.js ***! 14638 \*********************************/ 14639/*! no static exports found */ 14640/***/ (function(module, exports, __webpack_require__) { 14641 14642var utils = __webpack_require__(/*! ../utils/utils */ "./sources/utils/utils.js"); 14643var domHelpers = __webpack_require__(/*! ../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 14644 14645module.exports = function(gantt) { 14646 14647 var boxAttribute = "data-dhxbox"; 14648 14649 var _dhx_msg_cfg = null; 14650 14651 function callback(config, result) { 14652 var usercall = config.callback; 14653 modalBox.hide(config.box); 14654 14655 _dhx_msg_cfg = config.box = null; 14656 if (usercall) 14657 usercall(result); 14658 } 14659 14660 function modal_key(e) { 14661 if (_dhx_msg_cfg) { 14662 e = e || event; 14663 var code = e.which || event.keyCode; 14664 var preventDefault = false; 14665 14666 if (messageBox.keyboard) { 14667 if (code == 13 || code == 32) { 14668 // default behavior is to confirm/submit popup on space/enter 14669 // if browser focus is set on button element - do button click instead of default behavior 14670 var target = e.target || e.srcElement; 14671 if (domHelpers.getClassName(target).indexOf("gantt_popup_button") > -1 && target.click) { 14672 target.click(); 14673 } else { 14674 callback(_dhx_msg_cfg, true); 14675 preventDefault = true; 14676 } 14677 } 14678 14679 if (code == 27) { 14680 callback(_dhx_msg_cfg, false); 14681 preventDefault = true; 14682 } 14683 } 14684 14685 if (preventDefault) { 14686 if (e.preventDefault) 14687 e.preventDefault(); 14688 return !(e.cancelBubble = true); 14689 } 14690 return; 14691 } 14692 } 14693 14694 gantt.event(document, "keydown", modal_key, true); 14695 14696 function modality(mode) { 14697 if (!modality.cover) { 14698 modality.cover = document.createElement("div"); 14699 //necessary for IE only 14700 modality.cover.onkeydown = modal_key; 14701 modality.cover.className = "dhx_modal_cover"; 14702 document.body.appendChild(modality.cover); 14703 } 14704 14705 modality.cover.style.display = mode ? "inline-block" : "none"; 14706 } 14707 14708 function button(text, className, result) { 14709 var buttonAriaAttrs = gantt._waiAria.messageButtonAttrString(text); 14710 var name = className.toLowerCase().replace(/ /g, "_"); 14711 var button_css = "gantt_" + name + "_button" + " dhtmlx_" + name + "_button"; // dhtmlx_ok_button, dhtmlx_click_me_button 14712 return "<div " + buttonAriaAttrs + " class='gantt_popup_button dhtmlx_popup_button " + button_css + "' data-result='" + result + "' result='" + result + "' ><div>" + text + "</div></div>"; 14713 } 14714 14715 function info(text) { 14716 if (!messageBox.area) { 14717 messageBox.area = document.createElement("div"); 14718 messageBox.area.className = "gantt_message_area dhtmlx_message_area"; 14719 messageBox.area.style[messageBox.position] = "5px"; 14720 document.body.appendChild(messageBox.area); 14721 } 14722 14723 messageBox.hide(text.id); 14724 var message = document.createElement("div"); 14725 message.innerHTML = "<div>" + text.text + "</div>"; 14726 message.className = "gantt-info dhtmlx-info gantt-" + text.type + " dhtmlx-" + text.type; 14727 message.onclick = function () { 14728 messageBox.hide(text.id); 14729 text = null; 14730 }; 14731 14732 gantt._waiAria.messageInfoAttr(message); 14733 14734 if (messageBox.position == "bottom" && messageBox.area.firstChild) 14735 messageBox.area.insertBefore(message, messageBox.area.firstChild); 14736 else 14737 messageBox.area.appendChild(message); 14738 14739 if (text.expire > 0) 14740 messageBox.timers[text.id] = window.setTimeout(function () { 14741 messageBox.hide(text.id); 14742 }, text.expire); 14743 14744 messageBox.pull[text.id] = message; 14745 message = null; 14746 14747 return text.id; 14748 } 14749 14750 function getFirstDefined() { 14751 var values = [].slice.apply(arguments, [0]); 14752 14753 for (var i = 0; i < values.length; i++) { 14754 if (values[i]) { 14755 return values[i]; 14756 } 14757 } 14758 14759 } 14760 14761 function _boxStructure(config, ok, cancel) { 14762 var box = document.createElement("div"); 14763 14764 var contentId = utils.uid(); 14765 gantt._waiAria.messageModalAttr(box, contentId); 14766 14767 14768 box.className = " gantt_modal_box dhtmlx_modal_box gantt-" + config.type + " dhtmlx-" + config.type; 14769 box.setAttribute(boxAttribute, 1); 14770 14771 var inner = ''; 14772 14773 if (config.width) 14774 box.style.width = config.width; 14775 if (config.height) 14776 box.style.height = config.height; 14777 if (config.title) 14778 inner += '<div class="gantt_popup_title dhtmlx_popup_title">' + config.title + '</div>'; 14779 inner += '<div class="gantt_popup_text dhtmlx_popup_text" id="' + contentId + '"><span>' + (config.content ? '' : config.text) + '</span></div><div class="gantt_popup_controls dhtmlx_popup_controls">'; 14780 if (ok) 14781 inner += button(getFirstDefined(config.ok, gantt.locale.labels.message_ok, "OK"), "ok", true); 14782 if (cancel) 14783 inner += button(getFirstDefined(config.cancel, gantt.locale.labels.message_cancel, "Cancel"), "cancel", false); 14784 14785 if (config.buttons) { 14786 for (var i = 0; i < config.buttons.length; i++) { 14787 var btn = config.buttons[i]; 14788 if (typeof btn == "object") { 14789 // Support { label:"Save", css:"main_button", value:"save" } 14790 var label = btn.label; 14791 var css = btn.css || ("gantt_" + btn.label.toLowerCase() + "_button dhtmlx_" + btn.label.toLowerCase() + "_button"); 14792 var value = btn.value || i; 14793 inner += button(label, css, value); 14794 } else { 14795 inner += button(btn, btn, i); 14796 } 14797 } 14798 } 14799 14800 inner += '</div>'; 14801 box.innerHTML = inner; 14802 14803 if (config.content) { 14804 var node = config.content; 14805 if (typeof node == "string") 14806 node = document.getElementById(node); 14807 if (node.style.display == 'none') 14808 node.style.display = ""; 14809 box.childNodes[config.title ? 1 : 0].appendChild(node); 14810 } 14811 14812 box.onclick = function (e) { 14813 e = e || event; 14814 var source = e.target || e.srcElement; 14815 if (!source.className) source = source.parentNode; 14816 if (source.className.split(" ")[0] == "gantt_popup_button") { 14817 var result = source.getAttribute("data-result"); 14818 result = (result == "true") || (result == "false" ? false : result); 14819 callback(config, result); 14820 } 14821 }; 14822 config.box = box; 14823 if (ok || cancel) 14824 _dhx_msg_cfg = config; 14825 14826 return box; 14827 } 14828 14829 function _createBox(config, ok, cancel) { 14830 var box = config.tagName ? config : _boxStructure(config, ok, cancel); 14831 14832 if (!config.hidden) 14833 modality(true); 14834 document.body.appendChild(box); 14835 var x = Math.abs(Math.floor(((window.innerWidth || document.documentElement.offsetWidth) - box.offsetWidth) / 2)); 14836 var y = Math.abs(Math.floor(((window.innerHeight || document.documentElement.offsetHeight) - box.offsetHeight) / 2)); 14837 if (config.position == "top") 14838 box.style.top = "-3px"; 14839 else 14840 box.style.top = y + 'px'; 14841 box.style.left = x + 'px'; 14842 //necessary for IE only 14843 box.onkeydown = modal_key; 14844 14845 modalBox.focus(box); 14846 14847 if (config.hidden) 14848 modalBox.hide(box); 14849 14850 gantt.callEvent("onMessagePopup", [box]); 14851 return box; 14852 } 14853 14854 function alertPopup(config) { 14855 return _createBox(config, true, false); 14856 } 14857 14858 function confirmPopup(config) { 14859 return _createBox(config, true, true); 14860 } 14861 14862 function boxPopup(config) { 14863 return _createBox(config); 14864 } 14865 14866 function box_params(text, type, callback) { 14867 if (typeof text != "object") { 14868 if (typeof type == "function") { 14869 callback = type; 14870 type = ""; 14871 } 14872 text = {text: text, type: type, callback: callback}; 14873 } 14874 return text; 14875 } 14876 14877 function params(text, type, expire, id) { 14878 if (typeof text != "object") 14879 text = {text: text, type: type, expire: expire, id: id}; 14880 text.id = text.id || utils.uid(); 14881 text.expire = text.expire || messageBox.expire; 14882 return text; 14883 } 14884 14885 var alertBox = function () { 14886 var text = box_params.apply(this, arguments); 14887 text.type = text.type || "confirm"; 14888 return alertPopup(text); 14889 }; 14890 var confirmBox = function () { 14891 var text = box_params.apply(this, arguments); 14892 text.type = text.type || "alert"; 14893 return confirmPopup(text); 14894 }; 14895 var modalBox = function () { 14896 var text = box_params.apply(this, arguments); 14897 text.type = text.type || "alert"; 14898 return boxPopup(text); 14899 }; 14900 modalBox.hide = function (node) { 14901 while (node && node.getAttribute && !node.getAttribute(boxAttribute)) 14902 node = node.parentNode; 14903 if (node) { 14904 node.parentNode.removeChild(node); 14905 modality(false); 14906 14907 gantt.callEvent("onAfterMessagePopup", [node]); 14908 } 14909 }; 14910 14911 modalBox.focus = function (node) { 14912 setTimeout(function () { 14913 var focusable = domHelpers.getFocusableNodes(node); 14914 if (focusable.length) { 14915 if (focusable[0].focus) focusable[0].focus(); 14916 } 14917 }, 1); 14918 }; 14919 14920 var messageBox = function (text, type, expire, id) { 14921 text = params.apply(this, arguments); 14922 text.type = text.type || "info"; 14923 14924 var subtype = text.type.split("-")[0]; 14925 switch (subtype) { 14926 case "alert": 14927 return alertPopup(text); 14928 case "confirm": 14929 return confirmPopup(text); 14930 case "modalbox": 14931 return boxPopup(text); 14932 default: 14933 return info(text); 14934 } 14935 }; 14936 14937 messageBox.seed = (new Date()).valueOf(); 14938 messageBox.uid = utils.uid; 14939 messageBox.expire = 4000; 14940 messageBox.keyboard = true; 14941 messageBox.position = "top"; 14942 messageBox.pull = {}; 14943 messageBox.timers = {}; 14944 14945 messageBox.hideAll = function () { 14946 for (var key in messageBox.pull) 14947 messageBox.hide(key); 14948 }; 14949 messageBox.hide = function (id) { 14950 var obj = messageBox.pull[id]; 14951 if (obj && obj.parentNode) { 14952 window.setTimeout(function () { 14953 obj.parentNode.removeChild(obj); 14954 obj = null; 14955 }, 2000); 14956 obj.className += " hidden"; 14957 14958 if (messageBox.timers[id]) 14959 window.clearTimeout(messageBox.timers[id]); 14960 delete messageBox.pull[id]; 14961 } 14962 }; 14963 14964 var popups = []; 14965 gantt.attachEvent("onMessagePopup", function(box){ 14966 popups.push(box); 14967 }); 14968 gantt.attachEvent("onAfterMessagePopup", function(box){ 14969 for(var i = 0; i < popups.length; i++){ 14970 if(popups[i] === box){ 14971 popups.splice(i, 1); 14972 i--; 14973 } 14974 } 14975 }); 14976 14977 gantt.attachEvent("onDestroy", function(){ 14978 if(modality.cover && modality.cover.parentNode){ 14979 modality.cover.parentNode.removeChild(modality.cover); 14980 } 14981 14982 for(var i = 0; i < popups.length; i++){ 14983 if(popups[i].parentNode){ 14984 popups[i].parentNode.removeChild(popups[i]); 14985 } 14986 } 14987 popups = null; 14988 14989 if(messageBox.area && messageBox.area.parentNode){ 14990 messageBox.area.parentNode.removeChild(messageBox.area); 14991 } 14992 messageBox = null; 14993 }); 14994 14995 return { 14996 alert: alertBox, 14997 confirm: confirmBox, 14998 message: messageBox, 14999 modalbox: modalBox 15000 }; 15001}; 15002 15003/***/ }), 15004 15005/***/ "./sources/core/plugins/auto_task_types.js": 15006/*!*************************************************!*\ 15007 !*** ./sources/core/plugins/auto_task_types.js ***! 15008 \*************************************************/ 15009/*! no static exports found */ 15010/***/ (function(module, exports) { 15011 15012module.exports = function(gantt) { 15013 function isEnabled() { 15014 return gantt.config.auto_types && // if enabled 15015 (gantt.getTaskType(gantt.config.types.project) == gantt.config.types.project);// and supported 15016 } 15017 15018 function callIfEnabled(callback) { 15019 return function() { 15020 if (!isEnabled()) { 15021 return true; 15022 } 15023 return callback.apply(this, arguments); 15024 }; 15025 } 15026 15027 function updateParents(childId) { 15028 gantt.batchUpdate(function() { 15029 checkParent(childId); 15030 }); 15031 } 15032 15033 var delTaskParent; 15034 15035 function checkParent(id) { 15036 setTaskType(id); 15037 var parent = gantt.getParent(id); 15038 15039 if (parent != gantt.config.root_id) { 15040 checkParent(parent); 15041 } 15042 } 15043 15044 function setTaskType(id) { 15045 id = id.id || id; 15046 var task = gantt.getTask(id); 15047 var targetType = getTaskTypeToUpdate(task); 15048 15049 if (targetType !== false) { 15050 updateTaskType(task, targetType); 15051 } 15052 } 15053 15054 function updateTaskType(task, targetType) { 15055 if(!gantt.getState().group_mode){ 15056 task.type = targetType; 15057 gantt.updateTask(task.id); 15058 } 15059 } 15060 15061 function getTaskTypeToUpdate(task) { 15062 var allTypes = gantt.config.types; 15063 var hasChildren = gantt.hasChild(task.id); 15064 var taskType = gantt.getTaskType(task.type); 15065 15066 if (hasChildren && taskType === allTypes.task) { 15067 return allTypes.project; 15068 } 15069 15070 if (!hasChildren && taskType === allTypes.project) { 15071 return allTypes.task; 15072 } 15073 15074 return false; 15075 } 15076 15077 var isParsingDone = true; 15078 15079 gantt.attachEvent("onParse", callIfEnabled(function() { 15080 isParsingDone = false; 15081 15082 gantt.batchUpdate(function() { 15083 gantt.eachTask(function(task) { 15084 var targetType = getTaskTypeToUpdate(task); 15085 if (targetType !== false) { 15086 updateTaskType(task, targetType); 15087 } 15088 }); 15089 }); 15090 15091 isParsingDone = true; 15092 })); 15093 15094 gantt.attachEvent("onAfterTaskAdd", callIfEnabled(function(id) { 15095 if (isParsingDone) { 15096 updateParents(id); 15097 } 15098 })); 15099 15100 gantt.attachEvent("onAfterTaskUpdate", callIfEnabled(function(id) { 15101 if (isParsingDone) { 15102 updateParents(id); 15103 } 15104 })); 15105 15106 function updateAfterRemoveChild(id){ 15107 if (id != gantt.config.root_id && gantt.isTaskExists(id)) { 15108 updateParents(id); 15109 } 15110 } 15111 15112 gantt.attachEvent("onBeforeTaskDelete", callIfEnabled(function(id, task) { 15113 delTaskParent = gantt.getParent(id); 15114 return true; 15115 })); 15116 15117 gantt.attachEvent("onAfterTaskDelete", callIfEnabled(function(id, task) { 15118 updateAfterRemoveChild(delTaskParent); 15119 })); 15120 15121 15122 var originalRowDndParent; 15123 15124 gantt.attachEvent("onRowDragStart", callIfEnabled(function(id, target, e) { 15125 originalRowDndParent = gantt.getParent(id); 15126 return true; 15127 })); 15128 15129 gantt.attachEvent("onRowDragEnd", callIfEnabled(function(id, target) { 15130 updateAfterRemoveChild(originalRowDndParent); 15131 updateParents(id); 15132 })); 15133 15134 var originalMoveTaskParent; 15135 15136 gantt.attachEvent("onBeforeTaskMove", callIfEnabled(function(sid, parent, tindex) { 15137 originalMoveTaskParent = gantt.getParent(sid); 15138 return true; 15139 })); 15140 15141 gantt.attachEvent("onAfterTaskMove", callIfEnabled(function(id, parent, tindex) { 15142 if (document.querySelector(".gantt_drag_marker")) { 15143 // vertical dnd in progress 15144 return; 15145 } 15146 updateAfterRemoveChild(originalMoveTaskParent); 15147 updateParents(id); 15148 })); 15149}; 15150 15151/***/ }), 15152 15153/***/ "./sources/core/plugins/autoscroll.js": 15154/*!********************************************!*\ 15155 !*** ./sources/core/plugins/autoscroll.js ***! 15156 \********************************************/ 15157/*! no static exports found */ 15158/***/ (function(module, exports, __webpack_require__) { 15159 15160var domHelpers = __webpack_require__(/*! ../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 15161 15162module.exports = function(gantt){ 15163 15164 var scrollRange = 50, 15165 scrollStep = 30, 15166 scrollDelay = 10, 15167 scrollSpeed = 50; 15168 15169 var interval = null, 15170 isMove = false, 15171 delayTimeout = null, 15172 startPos = { 15173 started: false 15174 }, 15175 eventPos = {}; 15176 15177 15178 function isDisplayed(element){ 15179 return element && 15180 domHelpers.isChildOf(element, gantt.$root) && 15181 element.offsetHeight; 15182 } 15183 15184 function getAutoscrollContainer(){ 15185 var element; 15186 if(isDisplayed(gantt.$task)){ 15187 element = gantt.$task; 15188 }else if(isDisplayed(gantt.$grid)){ 15189 element = gantt.$grid; 15190 }else{ 15191 element = gantt.$root; 15192 } 15193 15194 return element; 15195 } 15196 15197 function isScrollState() { 15198 var dragMarker = !!document.querySelector(".gantt_drag_marker"); 15199 var isResize = !!document.querySelector(".gantt_drag_marker.gantt_grid_resize_area"); 15200 var isLink = !!document.querySelector(".gantt_link_direction"); 15201 var state = gantt.getState(); 15202 var isClickDrag = state.autoscroll; 15203 isMove = dragMarker && !isResize && !isLink; 15204 15205 return !((!state.drag_mode && !dragMarker) || isResize) || isClickDrag; 15206 } 15207 15208 function defineDelayTimeout(state) { 15209 if (delayTimeout) { 15210 clearTimeout(delayTimeout); 15211 delayTimeout = null; 15212 } 15213 if (state) { 15214 var speed = gantt.config.autoscroll_speed; 15215 if (speed && speed < 10) // limit speed value to 10 15216 speed = 10; 15217 15218 delayTimeout = setTimeout(function() { 15219 interval = setInterval(tick, speed || scrollSpeed); 15220 }, gantt.config.autoscroll_delay || scrollDelay); 15221 } 15222 } 15223 15224 function defineScrollInterval(state) { 15225 if (state) { 15226 defineDelayTimeout(true); 15227 if (!startPos.started) { 15228 startPos.x = eventPos.x; 15229 startPos.y = eventPos.y; 15230 startPos.started = true; 15231 } 15232 } else { 15233 if (interval) { 15234 clearInterval(interval); 15235 interval = null; 15236 } 15237 defineDelayTimeout(false); 15238 startPos.started = false; 15239 } 15240 } 15241 15242 function autoscrollInterval(event) { 15243 15244 var isScroll = isScrollState(); 15245 15246 if ((interval || delayTimeout) && !isScroll) { 15247 defineScrollInterval(false); 15248 } 15249 15250 if (!gantt.config.autoscroll || !isScroll) { 15251 return false; 15252 } 15253 15254 eventPos = { 15255 x: event.clientX, 15256 y: event.clientY 15257 }; 15258 15259 if (!interval && isScroll) { 15260 defineScrollInterval(true); 15261 } 15262 } 15263 15264 function tick() { 15265 15266 if (!isScrollState()) { 15267 defineScrollInterval(false); 15268 return false; 15269 } 15270 15271 var box = domHelpers.getNodePosition(getAutoscrollContainer()); 15272 var posX = eventPos.x - box.x; 15273 var posY = eventPos.y - box.y; 15274 15275 var scrollLeft = isMove ? 0 : need_scroll(posX, box.width, startPos.x - box.x); 15276 var scrollTop = need_scroll(posY, box.height, startPos.y - box.y); 15277 15278 var scrollState = gantt.getScrollState(); 15279 15280 var currentScrollTop = scrollState.y, 15281 scrollOuterHeight = scrollState.inner_height, 15282 scrollInnerHeight = scrollState.height, 15283 currentScrollLeft = scrollState.x, 15284 scrollOuterWidth = scrollState.inner_width, 15285 scrollInnerWidth = scrollState.width; 15286 15287 // do scrolling only if we have scrollable area to do so 15288 if (scrollTop && !scrollOuterHeight) { 15289 scrollTop = 0; 15290 } else if (scrollTop < 0 && !currentScrollTop) { 15291 scrollTop = 0; 15292 } else if (scrollTop > 0 && currentScrollTop + scrollOuterHeight >= scrollInnerHeight + 2) { 15293 scrollTop = 0; 15294 } 15295 15296 if (scrollLeft && !scrollOuterWidth) { 15297 scrollLeft = 0; 15298 } else if (scrollLeft < 0 && !currentScrollLeft) { 15299 scrollLeft = 0; 15300 } else if (scrollLeft > 0 && currentScrollLeft + scrollOuterWidth >= scrollInnerWidth) { 15301 scrollLeft = 0; 15302 } 15303 15304 var step = gantt.config.autoscroll_step; 15305 15306 if (step && step < 2) // limit step value to 2 15307 step = 2; 15308 15309 scrollLeft = scrollLeft * (step || scrollStep); 15310 scrollTop = scrollTop * (step || scrollStep); 15311 15312 if (scrollLeft || scrollTop) { 15313 scroll(scrollLeft, scrollTop); 15314 } 15315 } 15316 15317 function need_scroll(pos, boxSize, startCoord) { 15318 if ((pos - scrollRange < 0) && (pos < startCoord)) 15319 return -1; 15320 else if ((pos > boxSize - scrollRange) && (pos > startCoord)) 15321 return 1; 15322 return 0; 15323 } 15324 15325 function scroll(left, top) { 15326 var scrollState = gantt.getScrollState(); 15327 15328 var scrollLeft = null, 15329 scrollTop = null; 15330 15331 if (left) { 15332 scrollLeft = scrollState.x + left; 15333 scrollLeft = Math.min(scrollState.width, scrollLeft); 15334 scrollLeft = Math.max(0, scrollLeft); 15335 } 15336 15337 if (top) { 15338 scrollTop = scrollState.y + top; 15339 scrollTop = Math.min(scrollState.height, scrollTop); 15340 scrollTop = Math.max(0, scrollTop); 15341 } 15342 15343 gantt.scrollTo(scrollLeft, scrollTop); 15344 } 15345 15346 gantt.attachEvent("onGanttReady", function() { 15347 gantt.eventRemove(document.body, "mousemove", autoscrollInterval); 15348 gantt.event(document.body, "mousemove", autoscrollInterval); 15349 }); 15350 15351}; 15352 15353/***/ }), 15354 15355/***/ "./sources/core/plugins/batch_update.js": 15356/*!**********************************************!*\ 15357 !*** ./sources/core/plugins/batch_update.js ***! 15358 \**********************************************/ 15359/*! no static exports found */ 15360/***/ (function(module, exports) { 15361 15362function createMethod(gantt){ 15363 var methods = {}; 15364 var isActive = false; 15365 function disableMethod(methodName, dummyMethod){ 15366 dummyMethod = typeof dummyMethod == "function" ? dummyMethod : function(){}; 15367 15368 if(!methods[methodName]){ 15369 methods[methodName] = this[methodName]; 15370 this[methodName] = dummyMethod; 15371 } 15372 } 15373 function restoreMethod(methodName){ 15374 if(methods[methodName]){ 15375 this[methodName] = methods[methodName]; 15376 methods[methodName] = null; 15377 } 15378 } 15379 function disableMethods(methodsHash){ 15380 for(var i in methodsHash){ 15381 disableMethod.call(this, i, methodsHash[i]); 15382 } 15383 } 15384 function restoreMethods(){ 15385 for(var i in methods){ 15386 restoreMethod.call(this, i); 15387 } 15388 } 15389 15390 function batchUpdatePayload(callback){ 15391 try{ 15392 callback(); 15393 }catch(e){ 15394 window.console.error(e); 15395 } 15396 } 15397 15398 var state = gantt.$services.getService("state"); 15399 state.registerProvider("batchUpdate", function(){ 15400 return { 15401 batch_update: isActive 15402 }; 15403 }, false); 15404 15405 return function batchUpdate(callback, noRedraw) { 15406 if(isActive){ 15407 // batch mode is already active 15408 batchUpdatePayload(callback); 15409 return; 15410 } 15411 15412 var call_dp = (this._dp && this._dp.updateMode != "off"); 15413 var dp_mode; 15414 if (call_dp){ 15415 dp_mode = this._dp.updateMode; 15416 this._dp.setUpdateMode("off"); 15417 } 15418 15419 // temporary disable some methods while updating multiple tasks 15420 var resetProjects = {}; 15421 var methods = { 15422 "render":true, 15423 "refreshData":true, 15424 "refreshTask":true, 15425 "refreshLink":true, 15426 "resetProjectDates":function(task){ 15427 resetProjects[task.id] = task; 15428 } 15429 }; 15430 15431 disableMethods.call(this, methods); 15432 15433 isActive = true; 15434 this.callEvent("onBeforeBatchUpdate", []); 15435 15436 batchUpdatePayload(callback); 15437 15438 this.callEvent("onAfterBatchUpdate", []); 15439 15440 restoreMethods.call(this); 15441 15442 // do required updates after changes applied 15443 for(var i in resetProjects){ 15444 this.resetProjectDates(resetProjects[i]); 15445 } 15446 15447 isActive = false; 15448 15449 if(!noRedraw){ 15450 this.render(); 15451 } 15452 15453 if (call_dp) { 15454 this._dp.setUpdateMode(dp_mode); 15455 this._dp.setGanttMode("task"); 15456 this._dp.sendData(); 15457 this._dp.setGanttMode("link"); 15458 this._dp.sendData(); 15459 } 15460 }; 15461 15462 15463 15464} 15465 15466module.exports = function(gantt){ 15467 gantt.batchUpdate = createMethod(gantt); 15468}; 15469 15470/***/ }), 15471 15472/***/ "./sources/core/plugins/dhtmlx_hooks.js": 15473/*!**********************************************!*\ 15474 !*** ./sources/core/plugins/dhtmlx_hooks.js ***! 15475 \**********************************************/ 15476/*! no static exports found */ 15477/***/ (function(module, exports) { 15478 15479if (window.dhtmlx){ 15480 15481 if (!window.dhtmlx.attaches) 15482 window.dhtmlx.attaches = {}; 15483 15484 window.dhtmlx.attaches.attachGantt=function(start, end, gantt){ 15485 var obj = document.createElement("DIV"); 15486 15487 gantt = gantt || window.gantt; 15488 15489 obj.id = "gantt_"+ gantt.uid(); 15490 obj.style.width = "100%"; 15491 obj.style.height = "100%"; 15492 obj.cmp = "grid"; 15493 15494 document.body.appendChild(obj); 15495 this.attachObject(obj.id); 15496 this.dataType = "gantt"; 15497 this.dataObj = gantt; 15498 15499 var that = this.vs[this.av]; 15500 that.grid = gantt; 15501 15502 gantt.init(obj.id, start, end); 15503 obj.firstChild.style.border = "none"; 15504 15505 that.gridId = obj.id; 15506 that.gridObj = obj; 15507 15508 var method_name="_viewRestore"; 15509 return this.vs[this[method_name]()].grid; 15510 }; 15511 15512} 15513if (typeof(window.dhtmlXCellObject) != "undefined") { 15514 15515 window.dhtmlXCellObject.prototype.attachGantt=function(start, end, gantt){ 15516 gantt = gantt || window.gantt; 15517 15518 var obj = document.createElement("DIV"); 15519 obj.id = "gantt_"+gantt.uid(); 15520 obj.style.width = "100%"; 15521 obj.style.height = "100%"; 15522 obj.cmp = "grid"; 15523 15524 document.body.appendChild(obj); 15525 this.attachObject(obj.id); 15526 15527 this.dataType = "gantt"; 15528 this.dataObj = gantt; 15529 15530 gantt.init(obj.id, start, end); 15531 obj.firstChild.style.border = "none"; 15532 15533 obj = null; 15534 this.callEvent("_onContentAttach",[]); 15535 15536 return this.dataObj; 15537 }; 15538} 15539 15540module.exports = null; 15541 15542/***/ }), 15543 15544/***/ "./sources/core/plugins/formatters.js": 15545/*!********************************************!*\ 15546 !*** ./sources/core/plugins/formatters.js ***! 15547 \********************************************/ 15548/*! no static exports found */ 15549/***/ (function(module, exports, __webpack_require__) { 15550 15551 15552var DurationFormatter = __webpack_require__(/*! ../common/duration_formatter */ "./sources/core/common/duration_formatter_numeric.ts").default; 15553var LinkFormatter = __webpack_require__(/*! ../common/link_formatter */ "./sources/core/common/link_formatter_simple.ts").default; 15554 15555module.exports = function(gantt){ 15556 gantt.ext.formatters = { 15557 durationFormatter: function(settings){ 15558 if(!settings){ 15559 settings = {}; 15560 } 15561 if(!settings.store){ 15562 settings.store = gantt.config.duration_unit; 15563 } 15564 if(!settings.enter){ 15565 settings.enter = gantt.config.duration_unit; 15566 } 15567 return DurationFormatter.create(settings, gantt); 15568 }, 15569 linkFormatter: function(settings){ 15570 return LinkFormatter.create(settings, gantt); 15571 } 15572 }; 15573}; 15574 15575/***/ }), 15576 15577/***/ "./sources/core/plugins/index.js": 15578/*!***************************************!*\ 15579 !*** ./sources/core/plugins/index.js ***! 15580 \***************************************/ 15581/*! no static exports found */ 15582/***/ (function(module, exports, __webpack_require__) { 15583 15584module.exports = function(gantt){ 15585 if(!gantt.ext){ 15586 gantt.ext = {}; 15587 } 15588 15589 var modules = [ 15590 __webpack_require__(/*! ./autoscroll */ "./sources/core/plugins/autoscroll.js"), 15591 __webpack_require__(/*! ./batch_update */ "./sources/core/plugins/batch_update.js"), 15592 __webpack_require__(/*! ./wbs */ "./sources/core/plugins/wbs.js"), 15593 __webpack_require__(/*! ./jquery_hooks */ "./sources/core/plugins/jquery_hooks.js"), 15594 __webpack_require__(/*! ./dhtmlx_hooks */ "./sources/core/plugins/dhtmlx_hooks.js"), 15595 __webpack_require__(/*! ./resources */ "./sources/core/plugins/resources.js"), 15596 __webpack_require__(/*! ./new_task_placeholder */ "./sources/core/plugins/new_task_placeholder.js"), 15597 __webpack_require__(/*! ./auto_task_types */ "./sources/core/plugins/auto_task_types.js"), 15598 __webpack_require__(/*! ./formatters */ "./sources/core/plugins/formatters.js") 15599 ]; 15600 15601 for(var i = 0; i < modules.length; i++){ 15602 if(modules[i]) 15603 modules[i](gantt); 15604 } 15605 15606 var TimelineZoom = __webpack_require__(/*! ./timeline_zoom */ "./sources/core/plugins/timeline_zoom.ts").default; 15607 gantt.ext.zoom = new TimelineZoom(gantt); 15608}; 15609 15610/***/ }), 15611 15612/***/ "./sources/core/plugins/jquery_hooks.js": 15613/*!**********************************************!*\ 15614 !*** ./sources/core/plugins/jquery_hooks.js ***! 15615 \**********************************************/ 15616/*! no static exports found */ 15617/***/ (function(module, exports) { 15618 15619if (window.jQuery){ 15620 15621 (function( $ ){ 15622 15623 var methods = []; 15624 $.fn.dhx_gantt = function(config){ 15625 config = config || {}; 15626 if (typeof(config) === 'string') { 15627 if (methods[config] ) { 15628 return methods[config].apply(this, []); 15629 }else { 15630 $.error('Method ' + config + ' does not exist on jQuery.dhx_gantt'); 15631 } 15632 } else { 15633 var views = []; 15634 this.each(function() { 15635 if (this && this.getAttribute){ 15636 if (!this.gantt && !(window.gantt.$root == this)){ 15637 15638 var newgantt = (window.gantt.$container && window.Gantt) ? window.Gantt.getGanttInstance():window.gantt; 15639 for (var key in config) 15640 if (key!="data") 15641 newgantt.config[key] = config[key]; 15642 15643 newgantt.init(this); 15644 if (config.data) 15645 newgantt.parse(config.data); 15646 15647 views.push(newgantt); 15648 } else 15649 views.push(typeof this.gantt == "object" ? this.gantt : window.gantt); 15650 } 15651 }); 15652 15653 15654 if (views.length === 1) return views[0]; 15655 return views; 15656 } 15657 }; 15658 15659 })(window.jQuery); 15660 15661} 15662 15663 15664module.exports = null; 15665 15666/***/ }), 15667 15668/***/ "./sources/core/plugins/new_task_placeholder.js": 15669/*!******************************************************!*\ 15670 !*** ./sources/core/plugins/new_task_placeholder.js ***! 15671 \******************************************************/ 15672/*! no static exports found */ 15673/***/ (function(module, exports) { 15674 15675module.exports = function addPlaceholder(gantt){ 15676 function isEnabled(){ 15677 return gantt.config.placeholder_task; 15678 } 15679 15680 function callIfEnabled(callback){ 15681 return function(){ 15682 if(!isEnabled()){ 15683 return true; 15684 } 15685 return callback.apply(this, arguments); 15686 }; 15687 } 15688 15689 function silenceDataProcessor(dataProcessor){ 15690 if(dataProcessor && !dataProcessor._silencedPlaceholder){ 15691 dataProcessor._silencedPlaceholder = true; 15692 dataProcessor.attachEvent("onBeforeUpdate", callIfEnabled(function(id, state, data){ 15693 if(data.type == gantt.config.types.placeholder){ 15694 dataProcessor.setUpdated(id, false); 15695 return false; 15696 } 15697 return true; 15698 })); 15699 } 15700 } 15701 15702 function insertPlaceholder(){ 15703 var placeholders = gantt.getTaskBy("type", gantt.config.types.placeholder); 15704 if(!placeholders.length || !gantt.isTaskExists(placeholders[0].id)){ 15705 var placeholder = { 15706 unscheduled: true, 15707 type: gantt.config.types.placeholder, 15708 duration:0, 15709 text: gantt.locale.labels.new_task 15710 }; 15711 if(gantt.callEvent("onTaskCreated", [placeholder]) === false){ 15712 return; 15713 } 15714 15715 gantt.addTask(placeholder); 15716 15717 } 15718 } 15719 15720 function afterEdit(id){ 15721 var item = gantt.getTask(id); 15722 if(item.type == gantt.config.types.placeholder) { 15723 if(item.start_date && item.end_date && item.unscheduled){ 15724 item.unscheduled = false; 15725 } 15726 15727 gantt.batchUpdate(function(){ 15728 var newTask = gantt.copy(item); 15729 gantt.silent(function(){ 15730 gantt.deleteTask(item.id); 15731 }); 15732 15733 delete newTask["!nativeeditor_status"]; 15734 newTask.type = gantt.config.types.task; 15735 newTask.id = gantt.uid(); 15736 gantt.addTask(newTask); 15737 15738 //insertPlaceholder(); 15739 }); 15740 15741 } 15742 } 15743 15744 gantt.config.types.placeholder = "placeholder"; 15745 gantt.attachEvent("onDataProcessorReady", callIfEnabled(silenceDataProcessor)); 15746 15747 var ready = false; 15748 gantt.attachEvent("onGanttReady", function(){ 15749 if(ready){ 15750 return; 15751 } 15752 ready = true; 15753 gantt.attachEvent("onAfterTaskUpdate", callIfEnabled(afterEdit)); 15754 gantt.attachEvent("onAfterTaskAdd", callIfEnabled(function(id, task){ 15755 if(task.type != gantt.config.types.placeholder){ 15756 var placeholders = gantt.getTaskBy("type", gantt.config.types.placeholder); 15757 placeholders.forEach(function(p){ 15758 gantt.silent(function(){ 15759 if(gantt.isTaskExists(p.id)) 15760 gantt.deleteTask(p.id); 15761 }); 15762 }); 15763 insertPlaceholder(); 15764 } 15765 })); 15766 gantt.attachEvent("onParse", callIfEnabled(insertPlaceholder)); 15767 }); 15768 15769 function isPlaceholderTask(taskId){ 15770 if(gantt.config.types.placeholder && gantt.isTaskExists(taskId)){ 15771 var task = gantt.getTask(taskId); 15772 if(task.type == gantt.config.types.placeholder){ 15773 return true; 15774 } 15775 } 15776 return false; 15777 } 15778 function isPlaceholderLink(link){ 15779 if(isPlaceholderTask(link.source) || isPlaceholderTask(link.target)){ 15780 return true; 15781 } 15782 return false; 15783 } 15784 gantt.attachEvent("onLinkValidation", function(link){ 15785 if(isPlaceholderLink(link)){ 15786 return false; 15787 } 15788 return true; 15789 }); 15790 gantt.attachEvent("onBeforeLinkAdd", function(id,link){ 15791 if(isPlaceholderLink(link)){ 15792 return false; 15793 } 15794 return true; 15795 }); 15796 15797 gantt.attachEvent("onBeforeUndoStack", function(action){ 15798 for(var i = 0; i < action.commands.length; i++){ 15799 var command = action.commands[i]; 15800 if(command.entity === "task" && command.value.type === gantt.config.types.placeholder){ 15801 action.commands.splice(i,1); 15802 i--; 15803 } 15804 } 15805 return true; 15806 }); 15807 15808}; 15809 15810/***/ }), 15811 15812/***/ "./sources/core/plugins/resources.js": 15813/*!*******************************************!*\ 15814 !*** ./sources/core/plugins/resources.js ***! 15815 \*******************************************/ 15816/*! no static exports found */ 15817/***/ (function(module, exports, __webpack_require__) { 15818 15819var helpers = __webpack_require__(/*! ../../utils/helpers */ "./sources/utils/helpers.js"); 15820var getRectangle = __webpack_require__(/*! ../ui/render/viewport/get_bg_row_rectangle */ "./sources/core/ui/render/viewport/get_bg_row_rectangle.js"); 15821 15822function createResourceMethods(gantt){ 15823 15824 var resourceTaskCache = {}; 15825 15826 gantt.$data.tasksStore.attachEvent("onStoreUpdated", function(){ 15827 resourceTaskCache = {}; 15828 }); 15829 15830 function getTaskBy(propertyName, propertyValue) { 15831 if (typeof propertyName == "function") { 15832 return filterResourceTasks(propertyName); 15833 } else { 15834 if (helpers.isArray(propertyValue)) { 15835 return getResourceTasks(propertyName, propertyValue); 15836 } else { 15837 return getResourceTasks(propertyName, [propertyValue]); 15838 } 15839 } 15840 } 15841 15842 function filterResourceTasks(filter) { 15843 var res = []; 15844 gantt.eachTask(function (task) { 15845 if (filter(task)) { 15846 res.push(task); 15847 } 15848 }); 15849 return res; 15850 } 15851 15852 var falsyValuePreffix = String(Math.random()); 15853 function resourceHashFunction(value){ 15854 if (value === null){ 15855 return falsyValuePreffix + String(value); 15856 } 15857 return String(value); 15858 } 15859 15860 function getResourceTasks(property, resourceIds) { 15861 var res; 15862 var cacheKey = resourceIds.join("_") + "_" + property; 15863 var resourceHash = {}; 15864 helpers.forEach(resourceIds, function(resourceId) { 15865 resourceHash[resourceHashFunction(resourceId)] = true; 15866 }); 15867 15868 if (!resourceTaskCache[cacheKey]) { 15869 res = resourceTaskCache[cacheKey] = []; 15870 gantt.eachTask(function (task) { 15871 if (task.type == gantt.config.types.project) return; 15872 if (property in task) { 15873 var resourceValue; 15874 if (!helpers.isArray(task[property])) { 15875 resourceValue = [task[property]]; 15876 } else { 15877 resourceValue = task[property]; 15878 } 15879 helpers.forEach(resourceValue, function(value) { 15880 if (resourceHash[resourceHashFunction(value)] || (value && resourceHash[resourceHashFunction(value.resource_id)])) { 15881 res.push(task); 15882 } 15883 }); 15884 15885 } 15886 }); 15887 } else { 15888 res = resourceTaskCache[cacheKey]; 15889 } 15890 15891 return res; 15892 } 15893 15894 function getResourceLoad(resource, resourceProperty, scale, timeline){ 15895 var cacheKey = resource.id + "_" + resourceProperty + "_" + scale.unit + "_" + scale.step; 15896 var res; 15897 if (!resourceTaskCache[cacheKey]) { 15898 res = resourceTaskCache[cacheKey] = calculateResourceLoad(resource, resourceProperty, scale, timeline); 15899 15900 } else { 15901 res = resourceTaskCache[cacheKey]; 15902 } 15903 return res; 15904 } 15905 15906 function calculateResourceLoad(resource, resourceProperty, scale, timeline) { 15907 15908 var tasks; 15909 if(resource.$role == "task"){ 15910 tasks = []; 15911 }else{ 15912 tasks = getTaskBy(resourceProperty, resource.id); 15913 } 15914 var scaleUnit = scale.unit; 15915 var scaleStep = scale.step; 15916 var timegrid = {}; 15917 15918 for (var i = 0; i < tasks.length; i++) { 15919 var task = tasks[i]; 15920 15921 var currDate = gantt.date[scaleUnit + "_start"](new Date(task.start_date)); 15922 15923 while (currDate < task.end_date) { 15924 15925 var date = currDate; 15926 currDate = gantt.date.add(currDate, scaleStep, scaleUnit); 15927 15928 if (!gantt.isWorkTime({date: date, task: task, unit: scaleUnit})) { 15929 continue; 15930 } 15931 15932 var timestamp = date.valueOf(); 15933 if (!timegrid[timestamp]){ 15934 timegrid[timestamp] = []; 15935 } 15936 15937 timegrid[timestamp].push(task); 15938 } 15939 } 15940 15941 var timetable = []; 15942 var start, end, tasks; 15943 var config = timeline.$getConfig(); 15944 15945 for(var i = 0; i < scale.trace_x.length; i++){ 15946 start = new Date(scale.trace_x[i]); 15947 end = gantt.date.add(start, scaleStep, scaleUnit); 15948 tasks = timegrid[start.valueOf()] || []; 15949 if(tasks.length || config.resource_render_empty_cells){ 15950 timetable.push({ 15951 start_date: start, 15952 end_date: end, 15953 tasks: tasks 15954 }); 15955 } 15956 15957 } 15958 15959 return timetable; 15960 } 15961 15962 function generateRenderResourceLine(){ 15963 15964 var renderedResourceLines = {}; 15965 15966 function renderResourceLineCell(resource, day, templates, config, timeline){ 15967 var css = templates.resource_cell_class(day.start_date, day.end_date, resource, day.tasks); 15968 var content = templates.resource_cell_value(day.start_date, day.end_date, resource, day.tasks); 15969 15970 if (css || content){ 15971 var sizes = timeline.getItemPosition(resource, day.start_date, day.end_date); 15972 var el = document.createElement('div'); 15973 el.className = ["gantt_resource_marker", css].join(" "); 15974 15975 el.style.cssText = [ 15976 'left:' + sizes.left + 'px', 15977 'width:' + sizes.width + 'px', 15978 'height:' + (config.row_height - 1) + 'px', 15979 'line-height:' + (config.row_height - 1) + 'px', 15980 'top:' + sizes.top + 'px' 15981 ].join(";"); 15982 15983 if(content) 15984 el.innerHTML = content; 15985 15986 return el; 15987 } 15988 return null; 15989 } 15990 15991 function detachRenderedResourceLine(id, index){ 15992 if(renderedResourceLines[id] && renderedResourceLines[id][index] && 15993 renderedResourceLines[id][index].parentNode 15994 ){ 15995 renderedResourceLines[id][index].parentNode.removeChild(renderedResourceLines[id][index]); 15996 } 15997 } 15998 15999 function renderResourceLine(resource, timeline, viewport) { 16000 var config = timeline.$getConfig(), 16001 templates = timeline.$getTemplates(); 16002 var scale = timeline.getScale(); 16003 var timetable = getResourceLoad(resource, config.resource_property, timeline.getScale(), timeline); 16004 var smartRendering = !!viewport;//no viewport means smart rendering is disabled 16005 var cells = []; 16006 renderedResourceLines[resource.id] = {}; 16007 for (var i = 0; i < timetable.length; i++) { 16008 16009 var day = timetable[i]; 16010 var columnIndex = scale.trace_indexes[day.start_date.valueOf()]; 16011 if(smartRendering && !isColumnVisible(columnIndex, scale, viewport)){ 16012 continue; 16013 } 16014 16015 var cell = renderResourceLineCell(resource, day, templates, config, timeline); 16016 if(cell){ 16017 cells.push(cell); 16018 renderedResourceLines[resource.id][columnIndex] = cell; 16019 } 16020 } 16021 16022 var row = null; 16023 if(cells.length){ 16024 row = document.createElement("div"); 16025 for(var i = 0; i < cells.length; i++){ 16026 row.appendChild(cells[i]); 16027 } 16028 } 16029 return row; 16030 } 16031 16032 function updateResourceLine(resource, node, timeline, viewport) { 16033 var config = timeline.$getConfig(), 16034 templates = timeline.$getTemplates(); 16035 var scale = timeline.getScale(); 16036 var timetable = getResourceLoad(resource, config.resource_property, timeline.getScale(), timeline); 16037 16038 for (var i = 0; i < timetable.length; i++) { 16039 16040 var day = timetable[i]; 16041 var columnIndex = scale.trace_indexes[day.start_date.valueOf()]; 16042 if(!isColumnVisible(columnIndex, scale, viewport)){ 16043 detachRenderedResourceLine(resource.id, columnIndex); 16044 continue; 16045 } 16046 16047 if(!renderedResourceLines[resource.id] || !renderedResourceLines[resource.id][columnIndex]){ 16048 var cell = renderResourceLineCell(resource, day, templates, config, timeline); 16049 if(cell){ 16050 node.appendChild(cell); 16051 renderedResourceLines[resource.id][columnIndex] = cell; 16052 } 16053 } 16054 else if(renderedResourceLines[resource.id] && renderedResourceLines[resource.id][columnIndex] && !renderedResourceLines[resource.id][columnIndex].parentNode){ 16055 node.appendChild(renderedResourceLines[resource.id][columnIndex]); 16056 } 16057 } 16058 } 16059 16060 return { 16061 render: renderResourceLine, 16062 update: updateResourceLine, 16063 getRectangle: getRectangle 16064 }; 16065 } 16066 16067 function renderBar(level, start, end, timeline){ 16068 var top = (1 - (level*1||0))*100; 16069 var left = timeline.posFromDate(start); 16070 var right = timeline.posFromDate(end); 16071 var element = document.createElement("div"); 16072 element.className = "gantt_histogram_hor_bar"; 16073 element.style.top = top + '%'; 16074 element.style.left = left + "px"; 16075 element.style.width = (right - left + 1) + "px"; 16076 return element; 16077 } 16078 function renderConnection(prevLevel, nextLevel, left){ 16079 if(prevLevel === nextLevel){ 16080 return null; 16081 } 16082 16083 var top = 1 - Math.max(prevLevel, nextLevel); 16084 var height = Math.abs(prevLevel - nextLevel); 16085 var element = document.createElement("div"); 16086 element.className = "gantt_histogram_vert_bar"; 16087 element.style.top = top*100 + "%"; 16088 element.style.height = height*100 + "%"; 16089 element.style.left = left + "px"; 16090 16091 return element; 16092 } 16093 16094 function isColumnVisible(columnIndex, scale, viewPort){ 16095 var width = scale.width[columnIndex]; 16096 var cellLeftCoord = scale.left[columnIndex] - width; 16097 var cellRightCoord = scale.left[columnIndex] + width; 16098 return (width > 0 && cellLeftCoord <= viewPort.x_end && cellRightCoord >= viewPort.x);//do not render skipped columns 16099 } 16100 16101 16102 16103 function generateRenderResourceHistogram(){ 16104 16105 var renderedHistogramCells = {}; 16106 var renderedHistogramRows = {}; 16107 var renderedHistogramCapacity = {}; 16108 16109 function detachRenderedHistogramCell(id, index){ 16110 16111 var renderedRow = renderedHistogramCells[id]; 16112 if(renderedRow && renderedRow[index] && 16113 renderedRow[index].parentNode 16114 ){ 16115 renderedRow[index].parentNode.removeChild(renderedRow[index]); 16116 } 16117 } 16118 16119 function renderHistogramLine(capacity, timeline, maxCapacity, viewPort){ 16120 var scale = timeline.getScale(); 16121 16122 var el = document.createElement("div"); 16123 var smartRendering = !!viewPort;//no viewport means smart rendering is disabled 16124 for(var i = 0; i < scale.trace_x.length; i++){ 16125 if(smartRendering && !isColumnVisible(i, scale, viewPort)){ 16126 continue; 16127 } 16128 16129 var colStart = scale.trace_x[i]; 16130 var colEnd = scale.trace_x[i + 1] || gantt.date.add(colStart, scale.step, scale.unit); 16131 var col = scale.trace_x[i].valueOf(); 16132 var level = Math.min(capacity[col]/maxCapacity, 1) || 0; 16133 // do not render histogram for lines with below zero capacity, as it's reserved for folders 16134 if(level < 0){ 16135 return null; 16136 } 16137 16138 var nextLevel = Math.min(capacity[colEnd.valueOf()]/maxCapacity, 1) || 0; 16139 var bar = renderBar(level, colStart, colEnd, timeline); 16140 if(bar){ 16141 el.appendChild(bar); 16142 } 16143 var connection = renderConnection(level, nextLevel, timeline.posFromDate(colEnd)); 16144 if(connection){ 16145 el.appendChild(connection); 16146 } 16147 16148 } 16149 return el; 16150 } 16151 16152 function renderCapacityElement(resource, sizes, capacityMatrix, config, timeline, maxCapacity, viewport){ 16153 16154 var renderedElement = renderedHistogramCapacity[resource.id]; 16155 if(renderedElement && renderedElement.parentNode){ 16156 renderedElement.parentNode.removeChild(renderedElement); 16157 } 16158 16159 var capacityElement = renderHistogramLine(capacityMatrix, timeline, maxCapacity, viewport); 16160 if (capacityElement) { 16161 capacityElement.setAttribute("data-resource-id", resource.id); 16162 capacityElement.style.position = "absolute"; 16163 capacityElement.style.top = (sizes.top + 1) + "px"; 16164 capacityElement.style.height = (config.row_height - 1) + "px"; 16165 capacityElement.style.left = 0; 16166 } 16167 return capacityElement; 16168 } 16169 16170 function renderHistogramCell(resource, sizes, maxCapacity, config, templates, day){ 16171 var css = templates.histogram_cell_class(day.start_date, day.end_date, resource, day.tasks); 16172 var content = templates.histogram_cell_label(day.start_date, day.end_date, resource, day.tasks); 16173 var fill = templates.histogram_cell_allocated(day.start_date, day.end_date, resource, day.tasks); 16174 if(css || content){ 16175 var el = document.createElement('div'); 16176 el.className = ["gantt_histogram_cell", css].join(" "); 16177 16178 el.style.cssText = [ 16179 'left:' + sizes.left + 'px', 16180 'width:' + sizes.width + 'px', 16181 'height:' + (config.row_height - 1) + 'px', 16182 'line-height:' + (config.row_height - 1) + 'px', 16183 'top:' + (sizes.top + 1) + 'px' 16184 ].join(";"); 16185 16186 16187 if (content) { 16188 content = "<div class='gantt_histogram_label'>" + content +"</div>"; 16189 } 16190 16191 if (fill) { 16192 content = "<div class='gantt_histogram_fill' style='height:"+(Math.min(fill/maxCapacity||0, 1)*100)+"%;'></div>" + content; 16193 } 16194 16195 if (content) { 16196 el.innerHTML = content; 16197 } 16198 16199 return el; 16200 } 16201 return null; 16202 } 16203 16204 function renderResourceHistogram(resource, timeline, viewport) { 16205 var config = timeline.$getConfig(), 16206 templates = timeline.$getTemplates(); 16207 var scale = timeline.getScale(); 16208 var timetable = getResourceLoad(resource, config.resource_property, scale, timeline); 16209 16210 var cells = []; 16211 var capacityMatrix = {}; 16212 var maxCapacity = resource.capacity || timeline.$config.capacity || 24; 16213 renderedHistogramCells[resource.id] = {}; 16214 renderedHistogramRows[resource.id] = null; 16215 renderedHistogramCapacity[resource.id] = null; 16216 16217 var smartRendering = !!viewport;//no viewport means smart rendering is disabled 16218 for (var i = 0; i < timetable.length; i++) { 16219 var day = timetable[i]; 16220 var columnIndex = scale.trace_indexes[day.start_date.valueOf()]; 16221 if(smartRendering && !isColumnVisible(columnIndex, scale, viewport)){ 16222 continue; 16223 } 16224 16225 var capacity = templates.histogram_cell_capacity(day.start_date, day.end_date, resource, day.tasks); 16226 capacityMatrix[day.start_date.valueOf()] = capacity || 0; 16227 var sizes = timeline.getItemPosition(resource, day.start_date, day.end_date); 16228 16229 var el = renderHistogramCell(resource, sizes, maxCapacity, config, templates, day); 16230 if(el){ 16231 cells.push(el); 16232 renderedHistogramCells[resource.id][columnIndex] = el; 16233 } 16234 } 16235 16236 var row = null; 16237 if (cells.length) { 16238 row = document.createElement("div"); 16239 for (var i = 0; i < cells.length; i++) { 16240 row.appendChild(cells[i]); 16241 } 16242 16243 var capacityElement = renderCapacityElement(resource, sizes, capacityMatrix, config, timeline, maxCapacity, viewport); 16244 if(capacityElement){ 16245 row.appendChild(capacityElement); 16246 renderedHistogramCapacity[resource.id] = capacityElement; 16247 } 16248 renderedHistogramRows[resource.id] = row; 16249 } 16250 16251 return row; 16252 } 16253 16254 function updateResourceHistogram(resource, node, timeline, viewport) { 16255 var config = timeline.$getConfig(), 16256 templates = timeline.$getTemplates(); 16257 var scale = timeline.getScale(); 16258 var timetable = getResourceLoad(resource, config.resource_property, scale, timeline); 16259 var maxCapacity = resource.capacity || timeline.$config.capacity || 24; 16260 var capacityMatrix = {}; 16261 16262 var smartRendering = !!viewport;//no viewport means smart rendering is disabled 16263 for (var i = 0; i < timetable.length; i++) { 16264 var day = timetable[i]; 16265 var columnIndex = scale.trace_indexes[day.start_date.valueOf()]; 16266 var capacity = templates.histogram_cell_capacity(day.start_date, day.end_date, resource, day.tasks); 16267 capacityMatrix[day.start_date.valueOf()] = capacity || 0; 16268 var sizes = timeline.getItemPosition(resource, day.start_date, day.end_date); 16269 16270 if(smartRendering && !isColumnVisible(columnIndex, scale, viewport)){ 16271 detachRenderedHistogramCell(resource.id, columnIndex); 16272 continue; 16273 } 16274 16275 var renderedCell = renderedHistogramCells[resource.id]; 16276 if(!renderedCell || !renderedCell[columnIndex]){ 16277 var el = renderHistogramCell(resource, sizes, maxCapacity, config, templates, day); 16278 if(el){ 16279 node.appendChild(el); 16280 renderedHistogramCells[resource.id][columnIndex] = el; 16281 } 16282 } 16283 else if(renderedCell && renderedCell[columnIndex] && !renderedCell[columnIndex].parentNode){ 16284 node.appendChild(renderedCell[columnIndex]); 16285 } 16286 } 16287 16288 var capacityElement = renderCapacityElement(resource, sizes, capacityMatrix, config, timeline, maxCapacity, viewport); 16289 if(capacityElement){ 16290 node.appendChild(capacityElement); 16291 renderedHistogramCapacity[resource.id] = capacityElement; 16292 } 16293 } 16294 16295 return { 16296 render: renderResourceHistogram, 16297 update: updateResourceHistogram, 16298 getRectangle: getRectangle 16299 }; 16300 } 16301 16302 16303 function selectAssignments(resourceId, taskId, result){ 16304 var property = gantt.config.resource_property; 16305 var owners = []; 16306 if (gantt.getDatastore("task").exists(taskId)) { 16307 var task = gantt.getTask(taskId); 16308 owners = task[property] || []; 16309 } 16310 16311 if (!Array.isArray(owners)) { 16312 owners = [owners]; 16313 } 16314 for (var i = 0; i < owners.length; i++) { 16315 if (owners[i].resource_id == resourceId) { 16316 result.push({task_id: task.id, resource_id:owners[i].resource_id, value:owners[i].value}); 16317 } 16318 } 16319 } 16320 16321 function getResourceAssignments(resourceId, taskId){ 16322 // resource assignment as an independent module: 16323 // {taskId:, resourceId, value} 16324 // TODO: probably should add a separate datastore for these 16325 var assignments = []; 16326 var property = gantt.config.resource_property; 16327 if(taskId !== undefined){ 16328 selectAssignments(resourceId, taskId, assignments); 16329 }else{ 16330 var tasks = gantt.getTaskBy(property, resourceId); 16331 tasks.forEach(function(task){ 16332 selectAssignments(resourceId, task.id, assignments); 16333 }); 16334 } 16335 return assignments; 16336 } 16337 16338 return { 16339 renderLine: generateRenderResourceLine, 16340 renderHistogram: generateRenderResourceHistogram, 16341 filterTasks: getTaskBy, 16342 getResourceAssignments: getResourceAssignments 16343 }; 16344} 16345 16346module.exports = function(gantt){ 16347 var methods = createResourceMethods(gantt); 16348 16349 gantt.getTaskBy = methods.filterTasks; 16350 gantt.getResourceAssignments = methods.getResourceAssignments; 16351 gantt.$ui.layers.resourceRow = methods.renderLine; 16352 gantt.$ui.layers.resourceHistogram = methods.renderHistogram; 16353 gantt.config.resource_property = "owner_id"; 16354 gantt.config.resource_store = "resource"; 16355 gantt.config.resource_render_empty_cells = false; 16356 16357 /** 16358 * these are placeholder functions that should be redefined by the user 16359 */ 16360 gantt.templates.histogram_cell_class = function(start_date, end_date, resource, tasks) {}; 16361 gantt.templates.histogram_cell_label = function(start_date, end_date, resource, tasks) { 16362 return tasks.length + "/3"; 16363 }; 16364 gantt.templates.histogram_cell_allocated = function(start_date, end_date, resource, tasks) { 16365 return tasks.length / 3; 16366 }; 16367 gantt.templates.histogram_cell_capacity = function(start_date, end_date, resource, tasks) { 16368 return 0; 16369 }; 16370 16371 16372 16373 gantt.templates.resource_cell_class = function(start, end, resource, tasks) { 16374 var css = ""; 16375 if (tasks.length <= 1) { 16376 css = "gantt_resource_marker_ok"; 16377 } else { 16378 css = "gantt_resource_marker_overtime"; 16379 } 16380 return css; 16381 }; 16382 16383 gantt.templates.resource_cell_value = function(start, end, resource, tasks) { 16384 return tasks.length * 8; 16385 }; 16386}; 16387 16388 16389 16390 16391/***/ }), 16392 16393/***/ "./sources/core/plugins/timeline_zoom.ts": 16394/*!***********************************************!*\ 16395 !*** ./sources/core/plugins/timeline_zoom.ts ***! 16396 \***********************************************/ 16397/*! no static exports found */ 16398/***/ (function(module, exports, __webpack_require__) { 16399 16400"use strict"; 16401 16402Object.defineProperty(exports, "__esModule", { value: true }); 16403var env = __webpack_require__(/*! ../../utils/env */ "./sources/utils/env.js"); 16404var eventable = __webpack_require__(/*! ../../utils/eventable */ "./sources/utils/eventable.js"); 16405var USE_KEY = ["ctrlKey", "altKey", "shiftKey", "metaKey"]; 16406var _defaultScales = [ 16407 [ 16408 { 16409 unit: "month", 16410 date: "%M", 16411 step: 1 16412 }, 16413 { 16414 unit: "day", 16415 date: "%d", 16416 step: 1 16417 } 16418 ], 16419 [ 16420 { 16421 unit: "day", 16422 date: "%d %M", 16423 step: 1 16424 } 16425 ], 16426 [ 16427 { 16428 unit: "day", 16429 date: "%d %M", 16430 step: 1 16431 }, 16432 { 16433 unit: "hour", 16434 date: "%H:00", 16435 step: 8 16436 }, 16437 ], 16438 [ 16439 { 16440 unit: "day", 16441 date: "%d %M", 16442 step: 1 16443 }, 16444 { 16445 unit: "hour", 16446 date: "%H:00", 16447 step: 1 16448 }, 16449 ], 16450]; 16451var TimelineZoom = /** @class */ (function () { 16452 function TimelineZoom(gantt) { 16453 var _this = this; 16454 this.zoomIn = function () { 16455 var index = _this.getCurrentLevel() - 1; 16456 if (index < 0) { 16457 return; 16458 } 16459 _this.setLevel(index); 16460 }; 16461 this.zoomOut = function () { 16462 var index = _this.getCurrentLevel() + 1; 16463 if (index > _this._levels.length - 1) { 16464 return; 16465 } 16466 _this.setLevel(index); 16467 }; 16468 this.getCurrentLevel = function () { 16469 return _this._activeLevelIndex; 16470 }; 16471 this.getLevels = function () { 16472 return _this._levels; 16473 }; 16474 this.setLevel = function (level) { 16475 var zoomLevel = _this._getZoomIndexByName(level); 16476 if (zoomLevel === -1) { 16477 _this.$gantt.assert(zoomLevel !== -1, "Invalid zoom level for gantt.ext.zoom.setLevel. " + level + " is not an expected value."); 16478 } 16479 _this._setLevel(zoomLevel, 0); 16480 }; 16481 this._getZoomIndexByName = function (levelName) { 16482 var zoomLevel = -1; 16483 if (typeof levelName === "string") { 16484 if (!isNaN(Number(levelName)) && _this._levels[Number(levelName)]) { 16485 zoomLevel = Number(levelName); 16486 } 16487 else { 16488 for (var i = 0; i < _this._levels.length; i++) { 16489 if (_this._levels[i].name === levelName) { 16490 zoomLevel = i; 16491 break; 16492 } 16493 } 16494 } 16495 } 16496 else { 16497 zoomLevel = levelName; 16498 } 16499 return zoomLevel; 16500 }; 16501 this._getVisibleDate = function () { 16502 var scrollPos = _this.$gantt.getScrollState().x; 16503 var viewPort = _this.$gantt.$task.offsetWidth; 16504 _this._visibleDate = _this.$gantt.dateFromPos(scrollPos + viewPort / 2); 16505 }; 16506 this._setLevel = function (level, cursorOffset) { 16507 _this._activeLevelIndex = level; 16508 var gantt = _this.$gantt; 16509 var nextConfig = gantt.copy(_this._levels[_this._activeLevelIndex]); 16510 var chartConfig = gantt.copy(nextConfig); 16511 delete chartConfig.name; 16512 gantt.mixin(gantt.config, chartConfig, true); 16513 var isRendered = !!gantt.$root; 16514 if (isRendered) { 16515 if (cursorOffset) { 16516 var cursorDate = _this.$gantt.dateFromPos(cursorOffset + _this.$gantt.getScrollState().x); 16517 _this.$gantt.render(); 16518 var newPosition = _this.$gantt.posFromDate(cursorDate); 16519 _this.$gantt.scrollTo(newPosition - cursorOffset); 16520 } 16521 else { 16522 var viewPort = _this.$gantt.$task.offsetWidth; 16523 if (!_this._visibleDate) { 16524 _this._getVisibleDate(); 16525 } 16526 var middleDate = _this._visibleDate; 16527 _this.$gantt.render(); 16528 var newPosition = _this.$gantt.posFromDate(middleDate); 16529 _this.$gantt.scrollTo(newPosition - viewPort / 2); 16530 } 16531 _this.callEvent("onAfterZoom", [_this._activeLevelIndex, nextConfig]); 16532 } 16533 }; 16534 this._attachWheelEvent = function (config) { 16535 var event = env.isFF ? "wheel" : "mousewheel"; 16536 var el; 16537 if (typeof config.element === "function") { 16538 el = config.element(); 16539 } 16540 else { 16541 el = config.element; 16542 } 16543 if (!el) { 16544 return; 16545 } 16546 _this._domEvents.attach(el, event, _this.$gantt.bind(function (e) { 16547 if (this._useKey) { 16548 if (USE_KEY.indexOf(this._useKey) < 0) { 16549 return false; 16550 } 16551 if (!e[this._useKey]) { 16552 return false; 16553 } 16554 } 16555 if (typeof this._handler === "function") { 16556 this._handler.apply(this, [e]); 16557 return true; 16558 } 16559 }, _this)); 16560 }; 16561 this._defaultHandler = function (e) { 16562 var timelineOffset = _this.$gantt.$task.getBoundingClientRect().x; 16563 var cursorOffset = e.clientX - timelineOffset; 16564 var wheelY = _this.$gantt.env.isFF ? (e.deltaY * -40) : e.wheelDelta; 16565 var wheelUp = false; 16566 if (wheelY > 0) { 16567 wheelUp = true; 16568 } 16569 e.preventDefault(); 16570 e.stopPropagation(); 16571 _this._setScaleSettings(wheelUp, cursorOffset); 16572 }; 16573 this._setScaleDates = function () { 16574 if (_this._initialStartDate && _this._initialEndDate) { 16575 _this.$gantt.config.start_date = _this._initialStartDate; 16576 _this.$gantt.config.end_date = _this._initialEndDate; 16577 } 16578 }; 16579 this.$gantt = gantt; 16580 this._domEvents = this.$gantt._createDomEventScope(); 16581 } 16582 TimelineZoom.prototype.init = function (config) { 16583 var _this = this; 16584 this._initialStartDate = config.startDate; 16585 this._initialEndDate = config.endDate; 16586 this._activeLevelIndex = config.activeLevelIndex ? config.activeLevelIndex : 0; 16587 this._levels = this._mapScales(config.levels || _defaultScales); 16588 this._handler = config.handler || this._defaultHandler; 16589 this._minColumnWidth = config.minColumnWidth || 60; 16590 this._maxColumnWidth = config.maxColumnWidth || 240; 16591 this._widthStep = config.widthStep || 3 / 8 * config.minColumnWidth; 16592 this._useKey = config.useKey; 16593 if (!this._initialized) { 16594 eventable(this); 16595 this.$gantt.attachEvent("onGanttScroll", function () { 16596 _this._getVisibleDate(); 16597 }); 16598 } 16599 this._domEvents.detachAll(); 16600 if (config.trigger === "wheel") { 16601 if (this.$gantt.$root) { 16602 this._attachWheelEvent(config); 16603 } 16604 else { 16605 this.$gantt.attachEvent("onGanttReady", function () { 16606 _this._attachWheelEvent(config); 16607 }); 16608 } 16609 } 16610 this._initialized = true; 16611 this.setLevel(this._activeLevelIndex); 16612 }; 16613 TimelineZoom.prototype._mapScales = function (levels) { 16614 return levels.map(function (l) { 16615 if (Array.isArray(l)) { 16616 return { 16617 scales: l 16618 }; 16619 } 16620 else { 16621 return l; 16622 } 16623 }); 16624 }; 16625 TimelineZoom.prototype._setScaleSettings = function (wheelUp, cursorOffset) { 16626 if (wheelUp) { 16627 this._stepUp(cursorOffset); 16628 } 16629 else { 16630 this._stepDown(cursorOffset); 16631 } 16632 }; 16633 TimelineZoom.prototype._stepUp = function (cursorOffset) { 16634 if (this._activeLevelIndex >= this._levels.length - 1) { 16635 return; 16636 } 16637 var nextLevel = this._activeLevelIndex; 16638 this._setScaleDates(); 16639 if (this._widthStep) { 16640 var newColumnWidth = this.$gantt.config.min_column_width + this._widthStep; 16641 if (newColumnWidth > this._maxColumnWidth) { 16642 newColumnWidth = this._minColumnWidth; 16643 nextLevel++; 16644 } 16645 this.$gantt.config.min_column_width = newColumnWidth; 16646 } 16647 else { 16648 nextLevel++; 16649 } 16650 this._setLevel(nextLevel, cursorOffset); 16651 }; 16652 TimelineZoom.prototype._stepDown = function (cursorOffset) { 16653 if (this._activeLevelIndex < 1) { 16654 return; 16655 } 16656 var nextLevel = this._activeLevelIndex; 16657 this._setScaleDates(); 16658 if (this._widthStep) { 16659 var newColumnWidth = this.$gantt.config.min_column_width - this._widthStep; 16660 if (newColumnWidth < this._minColumnWidth) { 16661 newColumnWidth = this._maxColumnWidth; 16662 nextLevel--; 16663 } 16664 this.$gantt.config.min_column_width = newColumnWidth; 16665 } 16666 else { 16667 nextLevel--; 16668 } 16669 this._setLevel(nextLevel, cursorOffset); 16670 }; 16671 return TimelineZoom; 16672}()); 16673exports.default = TimelineZoom; 16674 16675 16676/***/ }), 16677 16678/***/ "./sources/core/plugins/wbs.js": 16679/*!*************************************!*\ 16680 !*** ./sources/core/plugins/wbs.js ***! 16681 \*************************************/ 16682/*! no static exports found */ 16683/***/ (function(module, exports) { 16684 16685var createWbs = (function(gantt){ 16686 return { 16687 _needRecalc: true, 16688 reset: function(){ 16689 this._needRecalc = true; 16690 }, 16691 _isRecalcNeeded: function(){ 16692 return (!this._isGroupSort() && this._needRecalc); 16693 }, 16694 _isGroupSort: function() { 16695 return !!(gantt.getState().group_mode); 16696 }, 16697 _getWBSCode: function(task) { 16698 if(!task) return ""; 16699 16700 if(this._isRecalcNeeded()){ 16701 this._calcWBS(); 16702 } 16703 16704 if(task.$virtual) return ""; 16705 if(this._isGroupSort()) return task.$wbs || ""; 16706 16707 if(!task.$wbs) { 16708 this.reset(); 16709 this._calcWBS(); 16710 } 16711 return task.$wbs; 16712 }, 16713 _setWBSCode: function(task, value) { 16714 task.$wbs = value; 16715 }, 16716 getWBSCode: function(task) { 16717 return this._getWBSCode(task); 16718 }, 16719 getByWBSCode: function(code){ 16720 var parts = code.split("."); 16721 var currentNode = gantt.config.root_id; 16722 for(var i = 0; i < parts.length; i++){ 16723 var children = gantt.getChildren(currentNode); 16724 var index = parts[i]*1 - 1; 16725 if(gantt.isTaskExists(children[index])){ 16726 currentNode = children[index]; 16727 }else{ 16728 return null; 16729 } 16730 } 16731 if(gantt.isTaskExists(currentNode)){ 16732 return gantt.getTask(currentNode); 16733 }else{ 16734 return null; 16735 } 16736 }, 16737 _calcWBS: function() { 16738 if(!this._isRecalcNeeded()) return; 16739 16740 var _isFirst = true; 16741 gantt.eachTask(function(ch) { 16742 if(_isFirst) { 16743 _isFirst = false; 16744 this._setWBSCode(ch, "1"); 16745 return; 16746 } 16747 var _prevSibling = gantt.getPrevSibling(ch.id); 16748 if (_prevSibling !== null) { 16749 var _wbs = gantt.getTask(_prevSibling).$wbs; 16750 if(_wbs) { 16751 _wbs = _wbs.split("."); 16752 _wbs[_wbs.length-1]++; 16753 this._setWBSCode(ch, _wbs.join(".")); 16754 } 16755 } else { 16756 var _parent = gantt.getParent(ch.id); 16757 this._setWBSCode(ch, gantt.getTask(_parent).$wbs + ".1"); 16758 } 16759 }, gantt.config.root_id, this); 16760 16761 this._needRecalc = false; 16762 } 16763}; 16764}); 16765 16766module.exports = function(gantt){ 16767 var wbs = createWbs(gantt); 16768 gantt.getWBSCode = function getWBSCode(task) { 16769 return wbs.getWBSCode(task); 16770 }; 16771 16772 gantt.getTaskByWBSCode = function(code) { 16773 return wbs.getByWBSCode(code); 16774 }; 16775 16776 function resetCache(){ 16777 wbs.reset(); 16778 return true; 16779 } 16780 16781 gantt.attachEvent("onAfterTaskMove", resetCache); 16782 gantt.attachEvent("onBeforeParse", resetCache); 16783 gantt.attachEvent("onAfterTaskDelete", resetCache); 16784 gantt.attachEvent("onAfterTaskAdd", resetCache); 16785 gantt.attachEvent("onAfterSort", resetCache); 16786 16787}; 16788 16789 16790/***/ }), 16791 16792/***/ "./sources/core/skin.js": 16793/*!******************************!*\ 16794 !*** ./sources/core/skin.js ***! 16795 \******************************/ 16796/*! no static exports found */ 16797/***/ (function(module, exports) { 16798 16799function _configure(col, data, force) { 16800 for (var key in data) 16801 if (typeof col[key] == "undefined" || force) 16802 col[key] = data[key]; 16803} 16804 16805function _get_skin(force, gantt) { 16806 var skin = gantt.skin; 16807 if (!skin || force) { 16808 var links = document.getElementsByTagName("link"); 16809 for (var i = 0; i < links.length; i++) { 16810 var res = links[i].href.match("dhtmlxgantt_([a-z_]+).css"); 16811 if (res) { 16812 if (gantt.skins[res[1]] || !skin) { 16813 skin = res[1]; 16814 break; 16815 } 16816 } 16817 } 16818 } 16819 16820 gantt.skin = skin || "terrace"; 16821 var skinset = gantt.skins[gantt.skin] || gantt.skins["terrace"]; 16822 16823 //apply skin related settings 16824 _configure(gantt.config, skinset.config, force); 16825 16826 var config = gantt.getGridColumns(); 16827 if (config[1] && !gantt.defined(config[1].width)) 16828 config[1].width = skinset._second_column_width; 16829 if (config[2] && !gantt.defined(config[2].width)) 16830 config[2].width = skinset._third_column_width; 16831 16832 for (var i=0; i<config.length; i++) { 16833 var column = config[i]; 16834 if (column.name == "add") { 16835 if(!column.width){ 16836 column.width = 44; 16837 } 16838 if (!(gantt.defined(column.min_width) && gantt.defined(column.max_width))) { 16839 column.min_width = column.min_width || column.width; 16840 column.max_width = column.max_width || column.width; 16841 } 16842 if (column.min_width) 16843 column.min_width = +column.min_width; 16844 if (column.max_width) 16845 column.max_width = +column.max_width; 16846 if (column.width) { 16847 column.width = +column.width; 16848 column.width = (column.min_width && column.min_width > column.width) ? column.min_width : column.width; 16849 column.width = (column.max_width && column.max_width < column.width) ? column.max_width : column.width; 16850 } 16851 } 16852 } 16853 16854 if (skinset.config.task_height) 16855 gantt.config.task_height = skinset.config.task_height || "full"; 16856 16857 if (skinset._lightbox_template) 16858 gantt._lightbox_template = skinset._lightbox_template; 16859 16860 if (skinset._redefine_lightbox_buttons) { 16861 gantt.config.buttons_right = skinset._redefine_lightbox_buttons["buttons_right"]; 16862 gantt.config.buttons_left = skinset._redefine_lightbox_buttons["buttons_left"]; 16863 } 16864 16865 16866 gantt.resetLightbox(); 16867} 16868 16869module.exports = function(gantt) { 16870 if(!gantt.resetSkin){ 16871 gantt.resetSkin = function () { 16872 this.skin = ""; 16873 _get_skin(true, this); 16874 }; 16875 gantt.skins = {}; 16876 16877 gantt.attachEvent("onGanttLayoutReady", function(){ 16878 _get_skin(false, this); 16879 }); 16880 } 16881}; 16882 16883/***/ }), 16884 16885/***/ "./sources/core/tasks.js": 16886/*!*******************************!*\ 16887 !*** ./sources/core/tasks.js ***! 16888 \*******************************/ 16889/*! no static exports found */ 16890/***/ (function(module, exports) { 16891 16892module.exports = function(gantt) { 16893 gantt.isReadonly = function (item) { 16894 if (item && item[this.config.editable_property]) { 16895 return false; 16896 } else { 16897 return (item && item[this.config.readonly_property]) || this.config.readonly; 16898 } 16899 }; 16900}; 16901 16902/***/ }), 16903 16904/***/ "./sources/core/touch.js": 16905/*!*******************************!*\ 16906 !*** ./sources/core/touch.js ***! 16907 \*******************************/ 16908/*! no static exports found */ 16909/***/ (function(module, exports) { 16910 16911module.exports = function(gantt) { 16912 16913 gantt.config.touch_drag = 500; //nearly immediate dnd 16914 gantt.config.touch = true; 16915 gantt.config.touch_feedback = true; 16916 gantt.config.touch_feedback_duration = 1; 16917 gantt._prevent_touch_scroll = false; 16918 16919 16920 gantt._touch_feedback = function () { 16921 if (gantt.config.touch_feedback) { 16922 if (navigator.vibrate) 16923 navigator.vibrate(gantt.config.touch_feedback_duration); 16924 } 16925 }; 16926 16927 gantt.attachEvent("onGanttReady", gantt.bind(function(){ 16928 if (this.config.touch != "force") 16929 this.config.touch = this.config.touch && 16930 ((navigator.userAgent.indexOf("Mobile") != -1) || 16931 (navigator.userAgent.indexOf("iPad") != -1) || 16932 (navigator.userAgent.indexOf("Android") != -1) || 16933 (navigator.userAgent.indexOf("Touch") != -1)); 16934 16935 if (this.config.touch) { 16936 16937 var touchEventsSupported = true; 16938 try { 16939 document.createEvent("TouchEvent"); 16940 } catch (e) { 16941 touchEventsSupported = false; 16942 } 16943 16944 if (touchEventsSupported) { 16945 this._touch_events(["touchmove", "touchstart", "touchend"], function (ev) { 16946 if (ev.touches && ev.touches.length > 1) return null; 16947 if (ev.touches[0]) 16948 return { 16949 target: ev.target, 16950 pageX: ev.touches[0].pageX, 16951 pageY: ev.touches[0].pageY, 16952 clientX: ev.touches[0].clientX, 16953 clientY: ev.touches[0].clientY 16954 }; 16955 else 16956 return ev; 16957 }, function () { 16958 return false; 16959 }); 16960 } else if (window.navigator.pointerEnabled) { 16961 this._touch_events(["pointermove", "pointerdown", "pointerup"], function (ev) { 16962 if (ev.pointerType == "mouse") return null; 16963 return ev; 16964 }, function (ev) { 16965 return (!ev || (ev.pointerType == "mouse" )); 16966 }); 16967 } else if (window.navigator.msPointerEnabled) { 16968 this._touch_events(["MSPointerMove", "MSPointerDown", "MSPointerUp"], function (ev) { 16969 if (ev.pointerType == ev.MSPOINTER_TYPE_MOUSE) return null; 16970 return ev; 16971 }, function (ev) { 16972 return (!ev || ev.pointerType == ev.MSPOINTER_TYPE_MOUSE); 16973 }); 16974 } 16975 16976 } 16977 }, gantt)); 16978 16979 16980 function getTaskDND(){ 16981 var _tasks_dnd; 16982 if(gantt.$ui.getView("timeline")){ 16983 _tasks_dnd = gantt.$ui.getView("timeline")._tasks_dnd; 16984 } 16985 return _tasks_dnd; 16986 } 16987 16988 var touchHandlers = []; 16989 16990//we can't use native scrolling, as we need to sync momentum between different parts 16991//so we will block native scroll and use the custom one 16992//in future we can add custom momentum 16993 gantt._touch_events = function (names, accessor, ignore) { 16994 //webkit on android need to be handled separately 16995 var dblclicktime = 0; 16996 var action_mode = false; 16997 var scroll_mode = false; 16998 var action_start = null; 16999 var scroll_state; 17000 var long_tap_timer = null; 17001 var current_target = null; 17002 17003 17004 17005 for(var i = 0; i < touchHandlers.length; i++){ 17006 gantt.eventRemove(touchHandlers[i][0], touchHandlers[i][1], touchHandlers[i][2]); 17007 } 17008 touchHandlers = []; 17009 17010 //touch move 17011 touchHandlers.push([gantt.$container, names[0], function (e) { 17012 var _tasks_dnd = getTaskDND(); 17013 17014 if (ignore(e)) return; 17015 17016 //ignore common and scrolling moves 17017 if (!action_mode) return; 17018 17019 if (long_tap_timer) clearTimeout(long_tap_timer); 17020 17021 var source = accessor(e); 17022 if (_tasks_dnd && (_tasks_dnd.drag.id || _tasks_dnd.drag.start_drag)) { 17023 _tasks_dnd.on_mouse_move(source); 17024 if (e.preventDefault) 17025 e.preventDefault(); 17026 e.cancelBubble = true; 17027 return false; 17028 } 17029 if (!gantt._prevent_touch_scroll) { 17030 if (source && action_start) { 17031 var dx = action_start.pageX - source.pageX; 17032 var dy = action_start.pageY - source.pageY; 17033 if (!scroll_mode && (Math.abs(dx) > 5 || Math.abs(dy) > 5)) { 17034 gantt._touch_scroll_active = scroll_mode = true; 17035 dblclicktime = 0; 17036 scroll_state = gantt.getScrollState(); 17037 } 17038 17039 if (scroll_mode) { 17040 gantt.scrollTo(scroll_state.x + dx, scroll_state.y + dy); 17041 var new_scroll_state = gantt.getScrollState(); 17042 17043 if ((scroll_state.x != new_scroll_state.x && dy > 2 * dx) || 17044 (scroll_state.y != new_scroll_state.y && dx > 2 * dy )) { 17045 return block_action(e); 17046 } 17047 } 17048 } 17049 return block_action(e); 17050 } 17051 return true; 17052 }]); 17053 17054 17055 //block touch context menu in IE10 17056 touchHandlers.push([this.$container, "contextmenu", function (e) { 17057 if (action_mode) 17058 return block_action(e); 17059 }]); 17060 17061 //touch start 17062 touchHandlers.push([this.$container, names[1], function (e) { 17063 if (ignore(e)) return; 17064 if (e.touches && e.touches.length > 1) { 17065 action_mode = false; 17066 return; 17067 } 17068 17069 action_start = accessor(e); 17070 if (!gantt._locate_css(action_start, "gantt_hor_scroll") && !gantt._locate_css(action_start, "gantt_ver_scroll")) { 17071 action_mode = true; 17072 } 17073 var _tasks_dnd = getTaskDND(); 17074 17075 //long tap 17076 long_tap_timer = setTimeout(function () { 17077 var taskId = gantt.locate(action_start); 17078 if (_tasks_dnd && (taskId && !gantt._locate_css(action_start, "gantt_link_control") && !gantt._locate_css(action_start, "gantt_grid_data"))) { 17079 _tasks_dnd.on_mouse_down(action_start); 17080 17081 if (_tasks_dnd.drag && _tasks_dnd.drag.start_drag) { 17082 cloneTaskRendered(taskId); 17083 _tasks_dnd._start_dnd(action_start); 17084 gantt._touch_drag = true; 17085 17086 gantt.refreshTask(taskId); 17087 17088 gantt._touch_feedback(); 17089 } 17090 17091 } 17092 17093 long_tap_timer = null; 17094 }, gantt.config.touch_drag); 17095 }]); 17096 17097 //touch end 17098 touchHandlers.push([this.$container, names[2], function (e) { 17099 if (ignore(e)) return; 17100 if (long_tap_timer) clearTimeout(long_tap_timer); 17101 gantt._touch_drag = false; 17102 action_mode = false; 17103 var source = accessor(e); 17104 17105 var _tasks_dnd = getTaskDND(); 17106 17107 if(_tasks_dnd) 17108 _tasks_dnd.on_mouse_up(source); 17109 17110 if (current_target) { 17111 gantt.refreshTask(gantt.locate(current_target)); 17112 if (current_target.parentNode) { 17113 current_target.parentNode.removeChild(current_target); 17114 gantt._touch_feedback(); 17115 } 17116 } 17117 17118 gantt._touch_scroll_active = action_mode = scroll_mode = false; 17119 current_target = null; 17120 17121 //dbl-tap handling 17122 if (action_start && dblclicktime) { 17123 var now = new Date(); 17124 if ((now - dblclicktime) < 500) { 17125 17126 var mouseEvents = gantt.$services.getService("mouseEvents"); 17127 mouseEvents.onDoubleClick(action_start); 17128 block_action(e); 17129 } else 17130 dblclicktime = now; 17131 } else { 17132 dblclicktime = new Date(); 17133 } 17134 }]); 17135 17136 for(var i = 0; i < touchHandlers.length; i++){ 17137 gantt.event(touchHandlers[i][0], touchHandlers[i][1], touchHandlers[i][2]); 17138 } 17139 17140 //common helper, prevents event 17141 function block_action(e) { 17142 if (e && e.preventDefault) 17143 e.preventDefault(); 17144 (e || event).cancelBubble = true; 17145 return false; 17146 } 17147 17148 function cloneTaskRendered(taskId) { 17149 var renders = gantt._getTaskLayers(); 17150 var task = gantt.getTask(taskId); 17151 if (task && gantt.isTaskVisible(taskId)) { 17152 for (var i = 0; i < renders.length; i++) { 17153 task = renders[i].rendered[taskId]; 17154 if (task && task.getAttribute(gantt.config.task_attribute) && task.getAttribute(gantt.config.task_attribute) == taskId) { 17155 var copy = task.cloneNode(true); 17156 current_target = task; 17157 renders[i].rendered[taskId] = copy; 17158 task.style.display = "none"; 17159 copy.className += " gantt_drag_move "; 17160 task.parentNode.appendChild(copy); 17161 //return copy; 17162 } 17163 } 17164 } 17165 } 17166 }; 17167 17168}; 17169 17170/***/ }), 17171 17172/***/ "./sources/core/ui/configurable.js": 17173/*!*****************************************!*\ 17174 !*** ./sources/core/ui/configurable.js ***! 17175 \*****************************************/ 17176/*! no static exports found */ 17177/***/ (function(module, exports, __webpack_require__) { 17178 17179var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 17180 17181function ViewSettings(config){ 17182 utils.mixin(this, config, true); 17183} 17184 17185 17186function extendSettings (store, parentSettings){ 17187 var own = this.$config[store]; 17188 17189 if(own){ 17190 if(own instanceof ViewSettings){ 17191 return own; 17192 }else{ 17193 ViewSettings.prototype = parentSettings; 17194 this.$config[store] = new ViewSettings(own); 17195 return this.$config[store]; 17196 } 17197 }else{ 17198 return parentSettings; 17199 } 17200} 17201 17202var configurable = function(parentView){ 17203 var parentConfig, 17204 parentTemplates; 17205 17206 return { 17207 $getConfig: function(){ 17208 if(!parentConfig){ 17209 parentConfig = parentView ? parentView.$getConfig() : this.$gantt.config; 17210 } 17211 if(!this.$config.config){ 17212 return parentConfig; 17213 }else{ 17214 return extendSettings.call(this, "config", parentConfig); 17215 } 17216 }, 17217 $getTemplates: function(){ 17218 if(!parentTemplates){ 17219 parentTemplates = parentView ? parentView.$getTemplates() : this.$gantt.templates; 17220 } 17221 if(!this.$config.templates){ 17222 return parentTemplates; 17223 }else{ 17224 return extendSettings.call(this, "templates", parentTemplates); 17225 } 17226 } 17227 }; 17228}; 17229 17230module.exports = function(obj, parent){ 17231 utils.mixin(obj, configurable(parent)); 17232}; 17233 17234/***/ }), 17235 17236/***/ "./sources/core/ui/gantt_layers.js": 17237/*!*****************************************!*\ 17238 !*** ./sources/core/ui/gantt_layers.js ***! 17239 \*****************************************/ 17240/*! no static exports found */ 17241/***/ (function(module, exports, __webpack_require__) { 17242 17243var createLayerFactory = __webpack_require__(/*! ./render/layer_engine */ "./sources/core/ui/render/layer_engine.js"); 17244 17245function initLayer(layer, gantt){ 17246 if(!layer.view){ 17247 return; 17248 } 17249 17250 var view = layer.view; 17251 if(typeof view === "string"){ 17252 view = gantt.$ui.getView(view); 17253 } 17254 17255 if(view && view.attachEvent){ 17256 view.attachEvent("onScroll", function(){ 17257 if(layer.requestUpdate){ 17258 layer.requestUpdate(); 17259 } 17260 }); 17261 } 17262} 17263 17264var createLayerEngine = function(gantt){ 17265 var factory = createLayerFactory(gantt); 17266 return { 17267 getDataRender: function(name){ 17268 return gantt.$services.getService("layer:" + name) || null; 17269 }, 17270 createDataRender: function(config){ 17271 var name = config.name, 17272 defaultContainer = config.defaultContainer, 17273 previusSiblingContainer = config.defaultContainerSibling; 17274 17275 var layers = factory.createGroup( 17276 defaultContainer, 17277 previusSiblingContainer, 17278 function(itemId, item){ 17279 if(layers.filters){ 17280 for(var i = 0; i < layers.filters.length; i++){ 17281 if(layers.filters[i](itemId, item) === false){ 17282 return false; 17283 } 17284 } 17285 }else{ 17286 return true; 17287 } 17288 }, 17289 initLayer 17290 ); 17291 17292 gantt.$services.setService("layer:" + name, function(){ 17293 return layers; 17294 }); 17295 17296 gantt.attachEvent("onGanttReady", function () { 17297 layers.addLayer();// init layers on start 17298 }); 17299 17300 return layers; 17301 }, 17302 init: function(){ 17303 var taskLayers = this.createDataRender({ 17304 name: "task", 17305 defaultContainer: function(){ 17306 if(gantt.$task_data){ 17307 return gantt.$task_data; 17308 }else if(gantt.$ui.getView("timeline")){ 17309 return gantt.$ui.getView("timeline").$task_data; 17310 } 17311 }, 17312 defaultContainerSibling: function(){ 17313 if(gantt.$task_links){ 17314 return gantt.$task_links; 17315 }else if(gantt.$ui.getView("timeline")){ 17316 return gantt.$ui.getView("timeline").$task_links; 17317 } 17318 }, 17319 filter: function(item){ 17320 17321 } 17322 }, gantt); 17323 17324 var linkLayers = this.createDataRender({ 17325 name: "link", 17326 defaultContainer: function(){ 17327 if(gantt.$task_data){ 17328 return gantt.$task_data; 17329 }else if(gantt.$ui.getView("timeline")){ 17330 return gantt.$ui.getView("timeline").$task_data; 17331 } 17332 } 17333 }, gantt); 17334 17335 return { 17336 addTaskLayer: function(config){ 17337 if(typeof config === "function"){ 17338 config = { 17339 renderer: config 17340 }; 17341 } 17342 config.view = "timeline"; 17343 17344 return taskLayers.addLayer(config); 17345 }, 17346 17347 _getTaskLayers: function(){ 17348 return taskLayers.getLayers(); 17349 }, 17350 removeTaskLayer: function(id){ 17351 taskLayers.removeLayer(id); 17352 }, 17353 17354 _clearTaskLayers: function(){ 17355 taskLayers.clear(); 17356 }, 17357 addLinkLayer: function(config){ 17358 if(typeof config === "function"){ 17359 config = { 17360 renderer: config 17361 }; 17362 } 17363 config.view = "timeline"; 17364 return linkLayers.addLayer(config); 17365 }, 17366 17367 _getLinkLayers: function(){ 17368 return linkLayers.getLayers(); 17369 }, 17370 removeLinkLayer: function(id){ 17371 linkLayers.removeLayer(id); 17372 }, 17373 17374 _clearLinkLayers: function(){ 17375 linkLayers.clear(); 17376 } 17377 }; 17378 } 17379 }; 17380}; 17381 17382module.exports = createLayerEngine; 17383 17384/***/ }), 17385 17386/***/ "./sources/core/ui/grid/editors/controller.js": 17387/*!****************************************************!*\ 17388 !*** ./sources/core/ui/grid/editors/controller.js ***! 17389 \****************************************************/ 17390/*! no static exports found */ 17391/***/ (function(module, exports, __webpack_require__) { 17392 17393var getKeyboardMapping = __webpack_require__(/*! ./keyboard_mappings */ "./sources/core/ui/grid/editors/keyboard_mappings.js"); 17394var textEditorFactory = __webpack_require__(/*! ./editors/text */ "./sources/core/ui/grid/editors/editors/text.js"), 17395 numberEditorFactory = __webpack_require__(/*! ./editors/number */ "./sources/core/ui/grid/editors/editors/number.js"), 17396 selectEditorFactory = __webpack_require__(/*! ./editors/select */ "./sources/core/ui/grid/editors/editors/select.js"), 17397 dateEditorFactory = __webpack_require__(/*! ./editors/date */ "./sources/core/ui/grid/editors/editors/date.js"), 17398 predecessorEditorFactory = __webpack_require__(/*! ./editors/predecessor */ "./sources/core/ui/grid/editors/editors/predecessor.js"), 17399 durationEditorFactory = __webpack_require__(/*! ./editors/duration */ "./sources/core/ui/grid/editors/editors/duration.js"); 17400var utils = __webpack_require__(/*! ../../../../utils/utils */ "./sources/utils/utils.js"); 17401var domHelpers = __webpack_require__(/*! ../../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 17402var eventable = __webpack_require__(/*! ../../../../utils/eventable */ "./sources/utils/eventable.js"); 17403var linkedPropertiesProcessor = __webpack_require__(/*! ./linked_properties */ "./sources/core/ui/grid/editors/linked_properties.js"); 17404 17405function initConfigs(gantt){ 17406 gantt.config.editor_types = { 17407 text: new (textEditorFactory(gantt))(), 17408 number: new (numberEditorFactory(gantt))(), 17409 select: new (selectEditorFactory(gantt))(), 17410 date: new (dateEditorFactory(gantt))(), 17411 predecessor: new (predecessorEditorFactory(gantt))(), 17412 duration: new (durationEditorFactory(gantt))() 17413 }; 17414} 17415 17416function create(gantt){ 17417 var keyboardMapping = getKeyboardMapping(gantt); 17418 17419 var eventBus = {}; 17420 eventable(eventBus); 17421 17422 function createGridEditors(grid) { 17423 17424 function _getGridCellFromNode(node){ 17425 if(!domHelpers.isChildOf(node, grid.$grid)){ 17426 return null; 17427 } 17428 17429 var row = domHelpers.locateAttribute(node, grid.$config.item_attribute); 17430 var cell = domHelpers.locateAttribute(node, "data-column-name"); 17431 if(cell){ 17432 var columnName = cell.getAttribute("data-column-name"); 17433 var id = row.getAttribute(grid.$config.item_attribute); 17434 return { 17435 id: id, 17436 columnName: columnName 17437 }; 17438 } 17439 return null; 17440 17441 } 17442 17443 function _getEditorPosition(itemId, columnName) { 17444 var top = grid.getItemTop(itemId); 17445 var height = grid.getItemHeight(itemId); 17446 var cols = grid.getGridColumns(); 17447 var left = 0, 17448 width = 0; 17449 17450 for (var i = 0; i < cols.length; i++) { 17451 if (cols[i].name == columnName) { 17452 width = cols[i].width; 17453 break; 17454 } 17455 left += cols[i].width; 17456 } 17457 return { 17458 top: top, 17459 left: left, 17460 height: height, 17461 width: width 17462 }; 17463 } 17464 17465 function findVisibleIndex(grid, columnName) { 17466 var columns = grid.getGridColumns(); 17467 for (var i = 0; i < columns.length; i++){ 17468 if(columns[i].name == columnName){ 17469 return i; 17470 } 17471 } 17472 return 0; 17473 } 17474 17475 function _createPlaceholder(itemId, columnName) { 17476 var pos = _getEditorPosition(itemId, columnName); 17477 var el = document.createElement("div"); 17478 el.className = "gantt_grid_editor_placeholder"; 17479 el.setAttribute(grid.$config.item_attribute, itemId); 17480 el.setAttribute("data-column-name", columnName); 17481 17482 var visibleIndex = findVisibleIndex(grid, columnName); 17483 el.setAttribute("data-column-index", visibleIndex); 17484 17485 el.style.cssText = [ 17486 "top:" + pos.top + "px", 17487 "left:" + pos.left + "px", 17488 "width:" + pos.width + "px", 17489 "height:" + pos.height + "px" 17490 ].join(";"); 17491 17492 return el; 17493 } 17494 17495 var updateTaskDateProperties = linkedPropertiesProcessor(gantt); 17496 17497 var handlers = []; 17498 var store = null; 17499 var controller = { 17500 _itemId: null, 17501 _columnName: null, 17502 _editor: null, 17503 _editorType: null, 17504 _placeholder: null, 17505 17506 locateCell: _getGridCellFromNode, 17507 getEditorConfig: function (columnName) { 17508 var column = grid.getColumn(columnName); 17509 return column.editor; 17510 }, 17511 17512 init: function () { 17513 var mapping = keyboardMapping.getMapping(); 17514 if(mapping.init){ 17515 mapping.init(this, grid); 17516 } 17517 17518 store = grid.$gantt.getDatastore(grid.$config.bind); 17519 17520 var self = this; 17521 17522 handlers.push(store.attachEvent("onIdChange", function(oldId, newId){ 17523 if(self._itemId == oldId){ 17524 self._itemId = newId; 17525 } 17526 })); 17527 handlers.push(store.attachEvent("onStoreUpdated", function(){ 17528 if(grid.$gantt.getState("batchUpdate").batch_update){ 17529 return; 17530 } 17531 17532 if(self.isVisible() && !store.isVisible(self._itemId)){ 17533 self.hide(); 17534 } 17535 })); 17536 17537 this.init = function(){}; 17538 }, 17539 17540 getState: function(){ 17541 return { 17542 editor: this._editor, 17543 editorType: this._editorType, 17544 placeholder: this._placeholder, 17545 id: this._itemId, 17546 columnName: this._columnName 17547 }; 17548 }, 17549 17550 startEdit: function(itemId, columnName) { 17551 if (this.isVisible()) { 17552 this.save(); 17553 } 17554 17555 if(!store.exists(itemId)){ 17556 return; 17557 } 17558 17559 var editorState = {id: itemId, columnName: columnName}; 17560 if (gantt.isReadonly(store.getItem(itemId))) { 17561 this.callEvent("onEditPrevent", [editorState]); 17562 return; 17563 } 17564 17565 if (this.callEvent("onBeforeEditStart", [editorState]) === false) { 17566 this.callEvent("onEditPrevent", [editorState]); 17567 return; 17568 } 17569 17570 this.show(editorState.id, editorState.columnName); 17571 this.setValue(); 17572 17573 this.callEvent("onEditStart", [editorState]); 17574 }, 17575 isVisible: function(){ 17576 return !!(this._editor && domHelpers.isChildOf(this._placeholder, document.body)); 17577 }, 17578 show: function (itemId, columnName) { 17579 if (this.isVisible()) { 17580 this.save(); 17581 } 17582 var editorState = {id: itemId, columnName: columnName}; 17583 17584 var column = grid.getColumn(editorState.columnName); 17585 var editorConfig = this.getEditorConfig(column.name); 17586 if(!editorConfig) 17587 return; 17588 17589 var editor = grid.$getConfig().editor_types[editorConfig.type]; 17590 17591 var placeholder = _createPlaceholder(editorState.id, editorState.columnName); 17592 grid.$grid_data.appendChild(placeholder); 17593 editor.show(editorState.id, column, editorConfig, placeholder); 17594 this._editor = editor; 17595 this._placeholder = placeholder; 17596 this._itemId = editorState.id; 17597 this._columnName = editorState.columnName; 17598 this._editorType = editorConfig.type; 17599 17600 var mapping = keyboardMapping.getMapping(); 17601 if(mapping.onShow){ 17602 mapping.onShow(this, placeholder, grid); 17603 } 17604 }, 17605 17606 setValue: function () { 17607 var state = this.getState(); 17608 var itemId = state.id, 17609 columnName = state.columnName; 17610 17611 var column = grid.getColumn(columnName); 17612 var item = store.getItem(itemId); 17613 var editorConfig = this.getEditorConfig(columnName); 17614 17615 if(!editorConfig) 17616 return; 17617 17618 var value = item[editorConfig.map_to]; 17619 if(editorConfig.map_to == "auto"){ 17620 value = store.getItem(itemId); 17621 } 17622 17623 this._editor.set_value(value, itemId, column, this._placeholder); 17624 this.focus(); 17625 }, 17626 17627 focus: function(){ 17628 this._editor.focus(this._placeholder); 17629 }, 17630 17631 getValue: function () { 17632 var column = grid.getColumn(this._columnName); 17633 return this._editor.get_value(this._itemId, column, this._placeholder); 17634 }, 17635 17636 _getItemValue: function() { 17637 var editorConfig = this.getEditorConfig(this._columnName); 17638 17639 if(!editorConfig) 17640 return; 17641 17642 var item = gantt.getTask(this._itemId); 17643 var value = item[editorConfig.map_to]; 17644 if(editorConfig.map_to == "auto"){ 17645 value = store.getItem(this._itemId); 17646 } 17647 return value; 17648 }, 17649 17650 isChanged: function(){ 17651 17652 var column = grid.getColumn(this._columnName); 17653 17654 var value = this._getItemValue(); 17655 17656 return this._editor.is_changed(value, this._itemId, column, this._placeholder); 17657 }, 17658 17659 hide: function () { 17660 if(!this._itemId) 17661 return; 17662 17663 var itemId = this._itemId, 17664 columnName = this._columnName; 17665 17666 var mapping = keyboardMapping.getMapping(); 17667 if(mapping.onHide){ 17668 mapping.onHide(this, this._placeholder, grid); 17669 } 17670 17671 this._itemId = null; 17672 this._columnName = null; 17673 this._editorType = null; 17674 if (!this._placeholder) return; 17675 17676 if (this._editor) { 17677 this._editor.hide(this._placeholder); 17678 } 17679 this._editor = null; 17680 if (this._placeholder.parentNode) { 17681 this._placeholder.parentNode.removeChild(this._placeholder); 17682 } 17683 this._placeholder = null; 17684 17685 this.callEvent("onEditEnd", [{id: itemId, columnName: columnName}]); 17686 }, 17687 save: function () { 17688 if(!(this.isVisible() && store.exists(this._itemId) && this.isChanged())) { 17689 this.hide(); 17690 return; 17691 } 17692 17693 var itemId = this._itemId, 17694 columnName = this._columnName; 17695 17696 if(!store.exists(itemId)) { 17697 return; 17698 } 17699 17700 var item = store.getItem(itemId); 17701 var editorConfig = this.getEditorConfig(columnName); 17702 var editorState = { 17703 id: itemId, 17704 columnName: columnName, 17705 newValue: this.getValue(), 17706 oldValue: this._getItemValue() 17707 }; 17708 if (this.callEvent("onBeforeSave", [editorState]) !== false) { 17709 if (this._editor.is_valid(editorState.newValue, editorState.id, editorState.columnName, this._placeholder)) { 17710 17711 var mapTo = editorConfig.map_to; 17712 var value = editorState.newValue; 17713 if (mapTo != "auto") { 17714 item[mapTo] = value; 17715 updateTaskDateProperties(item, mapTo, gantt.config.inline_editors_date_processing); 17716 17717 store.updateItem(itemId); 17718 } else { 17719 this._editor.save(itemId, grid.getColumn(columnName), this._placeholder); 17720 } 17721 this.callEvent("onSave", [editorState]); 17722 } 17723 } 17724 this.hide(); 17725 }, 17726 17727 _findEditableCell: function findEditableCell(start, direction){ 17728 var nextIndex = start; 17729 var columns = grid.getGridColumns(); 17730 var nextColumn = columns[nextIndex]; 17731 17732 var columnName = nextColumn ? nextColumn.name : null; 17733 if(columnName){ 17734 while(columnName && !this.getEditorConfig(columnName)){ 17735 columnName = this._findEditableCell(start + direction, direction); 17736 } 17737 return columnName; 17738 } 17739 return null; 17740 }, 17741 17742 getNextCell: function moveCell(dir){ 17743 return this._findEditableCell(grid.getColumnIndex(this._columnName) + dir, dir); 17744 }, 17745 17746 getFirstCell: function getFirstCell(){ 17747 return this._findEditableCell(0, 1); 17748 }, 17749 17750 getLastCell: function getLastCell(){ 17751 return this._findEditableCell(grid.getGridColumns().length - 1, -1); 17752 }, 17753 17754 editNextCell: function nextCell(canChangeRow){ 17755 var cell = this.getNextCell(1); 17756 if(cell){ 17757 var nextColumn = this.getNextCell(1); 17758 if(nextColumn && this.getEditorConfig(nextColumn)){ 17759 this.startEdit(this._itemId, nextColumn); 17760 } 17761 }else if(canChangeRow && this.moveRow(1)){ 17762 var task = this.moveRow(1); 17763 cell = this.getFirstCell(); 17764 if(cell && this.getEditorConfig(cell)){ 17765 this.startEdit(task, cell); 17766 } 17767 } 17768 }, 17769 17770 editPrevCell: function prevCell(canChangeRow){ 17771 var cell = this.getNextCell(-1); 17772 if(cell){ 17773 var nextColumn = this.getNextCell(-1); 17774 if(nextColumn && this.getEditorConfig(nextColumn)){ 17775 this.startEdit(this._itemId, nextColumn); 17776 } 17777 }else if(canChangeRow && this.moveRow(-1)){ 17778 var task = this.moveRow(-1); 17779 cell = this.getLastCell(); 17780 if(cell && this.getEditorConfig(cell)){ 17781 this.startEdit(task, cell); 17782 } 17783 } 17784 }, 17785 17786 moveRow: function moveRow(dir) { 17787 var moveTask = dir > 0 ? gantt.getNext : gantt.getPrev; 17788 moveTask = gantt.bind(moveTask, gantt); 17789 17790 var nextItem = moveTask(this._itemId); 17791 // skip readonly rows 17792 while (gantt.isTaskExists(nextItem) && gantt.isReadonly(gantt.getTask(nextItem))) { 17793 nextItem = moveTask(nextItem); 17794 } 17795 return nextItem; 17796 }, 17797 17798 editNextRow: function nextRow(){ 17799 var row = this.getNextCell(1); 17800 if(row){ 17801 this.startEdit(row, this._columnName); 17802 } 17803 }, 17804 17805 editPrevRow: function prevRow(){ 17806 var row = this.getNextCell(-1); 17807 if(row){ 17808 this.startEdit(row, this._columnName); 17809 } 17810 }, 17811 destructor: function(){ 17812 handlers.forEach(function(handlerId){ 17813 store.detachEvent(handlerId); 17814 }); 17815 store = null; 17816 this.hide(); 17817 this.detachAllEvents(); 17818 } 17819 }; 17820 17821 utils.mixin(controller, keyboardMapping); 17822 utils.mixin(controller, eventBus); 17823 17824 return controller; 17825 } 17826 17827 17828 var inlineEditController = { 17829 init: initConfigs, 17830 createEditors: createGridEditors 17831 }; 17832 17833 utils.mixin(inlineEditController, keyboardMapping); 17834 utils.mixin(inlineEditController, eventBus); 17835 17836 return inlineEditController; 17837} 17838 17839 17840 17841 17842module.exports = create; 17843 17844/***/ }), 17845 17846/***/ "./sources/core/ui/grid/editors/editors/base.js": 17847/*!******************************************************!*\ 17848 !*** ./sources/core/ui/grid/editors/editors/base.js ***! 17849 \******************************************************/ 17850/*! no static exports found */ 17851/***/ (function(module, exports) { 17852 17853module.exports = function (gantt) { 17854 17855 var BaseEditor = function () { 17856 }; 17857 17858 BaseEditor.prototype = { 17859 show: function (id, column, config, placeholder) { 17860 }, 17861 hide: function () { 17862 }, 17863 set_value: function (value, id, column, node) { 17864 this.get_input(node).value = value; 17865 }, 17866 get_value: function (id, column, node) { 17867 return this.get_input(node).value || ""; 17868 }, 17869 is_changed: function (value, id, column, node) { 17870 var currentValue = this.get_value(id, column, node); 17871 if (currentValue && value && currentValue.valueOf && value.valueOf) { 17872 return currentValue.valueOf() != value.valueOf(); 17873 } else { 17874 return currentValue != value; 17875 } 17876 }, 17877 is_valid: function (value, id, column, node) { 17878 return true; 17879 }, 17880 17881 save: function (id, column, node) { 17882 17883 }, 17884 get_input: function (node) { 17885 return node.querySelector("input"); 17886 }, 17887 focus: function (node) { 17888 var input = this.get_input(node); 17889 if (!input) { 17890 return; 17891 } 17892 if (input.focus) { 17893 input.focus(); 17894 } 17895 17896 if (input.select) { 17897 input.select(); 17898 } 17899 } 17900 }; 17901 return BaseEditor; 17902}; 17903 17904/***/ }), 17905 17906/***/ "./sources/core/ui/grid/editors/editors/date.js": 17907/*!******************************************************!*\ 17908 !*** ./sources/core/ui/grid/editors/editors/date.js ***! 17909 \******************************************************/ 17910/*! no static exports found */ 17911/***/ (function(module, exports, __webpack_require__) { 17912 17913module.exports = function (gantt) { 17914 var BaseEditor = __webpack_require__(/*! ./base */ "./sources/core/ui/grid/editors/editors/base.js")(gantt), 17915 utils = __webpack_require__(/*! ../../../../../utils/utils */ "./sources/utils/utils.js"); 17916 var __extends = __webpack_require__(/*! ../../../../../utils/extends */ "./sources/utils/extends.js"); 17917 17918 var html5DateFormat = "%Y-%m-%d"; 17919 17920 var dateToStr = null; 17921 var strToDate = null; 17922 17923 function init() { 17924 if (!dateToStr) { 17925 dateToStr = gantt.date.date_to_str(html5DateFormat); 17926 } 17927 if (!strToDate) { 17928 strToDate = gantt.date.str_to_date(html5DateFormat); 17929 } 17930 } 17931 17932 function DateEditor() { 17933 var self = BaseEditor.apply(this, arguments) || this; 17934 17935 return self; 17936 } 17937 17938 __extends(DateEditor, BaseEditor); 17939 17940 utils.mixin(DateEditor.prototype, { 17941 show: function (id, column, config, placeholder) { 17942 init(); 17943 var minValue = null; 17944 var maxValue = null; 17945 17946 if(typeof config.min === "function"){ 17947 minValue = config.min(id, column); 17948 }else{ 17949 minValue = config.min; 17950 } 17951 17952 if(typeof config.max === "function"){ 17953 maxValue = config.max(id, column); 17954 }else{ 17955 maxValue = config.max; 17956 } 17957 17958 var minAttr = minValue ? " min='" + dateToStr(minValue)+"' " : ""; 17959 var maxAttr = maxValue ? " max='" + dateToStr(maxValue)+"' " : ""; 17960 var html = "<div style='width:140px'><input type='date' " + minAttr + maxAttr + " name='" + column.name + "'></div>"; 17961 placeholder.innerHTML = html; 17962 }, 17963 set_value: function (value, id, column, node) { 17964 if (value && value.getFullYear) { 17965 this.get_input(node).value = dateToStr(value); 17966 } else { 17967 this.get_input(node).value = value; 17968 } 17969 }, 17970 is_valid: function (value, id, column, node) { 17971 if (!value || isNaN(value.getTime())) 17972 return false; 17973 return true; 17974 }, 17975 get_value: function (id, column, node) { 17976 var parsed; 17977 try { 17978 parsed = strToDate(this.get_input(node).value || ""); 17979 } catch (e) { 17980 parsed = null;// return null will cancel changes 17981 } 17982 17983 return parsed; 17984 } 17985 }, true); 17986 17987 return DateEditor; 17988}; 17989 17990 17991/***/ }), 17992 17993/***/ "./sources/core/ui/grid/editors/editors/duration.js": 17994/*!**********************************************************!*\ 17995 !*** ./sources/core/ui/grid/editors/editors/duration.js ***! 17996 \**********************************************************/ 17997/*! no static exports found */ 17998/***/ (function(module, exports, __webpack_require__) { 17999 18000module.exports = function(gantt) { 18001 18002 var BaseEditor = __webpack_require__(/*! ./base */ "./sources/core/ui/grid/editors/editors/base.js")(gantt), 18003 utils = __webpack_require__(/*! ../../../../../utils/utils */ "./sources/utils/utils.js"); 18004 var __extends = __webpack_require__(/*! ../../../../../utils/extends */ "./sources/utils/extends.js"); 18005 18006 function TextEditor() { 18007 var self = BaseEditor.apply(this, arguments) || this; 18008 return self; 18009 } 18010 18011 __extends(TextEditor, BaseEditor); 18012 18013 function getFormatter(config) { 18014 return config.formatter || gantt.ext.formatters.durationFormatter(); 18015 } 18016 utils.mixin(TextEditor.prototype, { 18017 show: function (id, column, config, placeholder) { 18018 var html = "<div><input type='text' name='" + column.name + "'></div>"; 18019 placeholder.innerHTML = html; 18020 }, 18021 set_value: function (value, id, column, node) { 18022 this.get_input(node).value = getFormatter(column.editor).format(value); 18023 }, 18024 get_value: function (id, column, node) { 18025 return getFormatter(column.editor).parse(this.get_input(node).value || ""); 18026 } 18027 }, true); 18028 18029 return TextEditor; 18030}; 18031 18032/***/ }), 18033 18034/***/ "./sources/core/ui/grid/editors/editors/number.js": 18035/*!********************************************************!*\ 18036 !*** ./sources/core/ui/grid/editors/editors/number.js ***! 18037 \********************************************************/ 18038/*! no static exports found */ 18039/***/ (function(module, exports, __webpack_require__) { 18040 18041module.exports = function (gantt) { 18042 18043 var BaseEditor = __webpack_require__(/*! ./base */ "./sources/core/ui/grid/editors/editors/base.js")(gantt), 18044 utils = __webpack_require__(/*! ../../../../../utils/utils */ "./sources/utils/utils.js"); 18045 var __extends = __webpack_require__(/*! ../../../../../utils/extends */ "./sources/utils/extends.js"); 18046 18047 function NumberEditor() { 18048 var self = BaseEditor.apply(this, arguments) || this; 18049 return self; 18050 } 18051 18052 __extends(NumberEditor, BaseEditor); 18053 18054 utils.mixin(NumberEditor.prototype, { 18055 show: function (id, column, config, placeholder) { 18056 var min = config.min || 0, 18057 max = config.max || 100; 18058 18059 var html = "<div><input type='number' min='" + min + "' max='" + max + "' name='" + column.name + "'></div>"; 18060 placeholder.innerHTML = html; 18061 }, 18062 get_value: function (id, column, node) { 18063 return this.get_input(node).value || ""; 18064 }, 18065 is_valid: function (value, id, column, node) { 18066 return !isNaN(parseInt(value, 10)); 18067 } 18068 }, true); 18069 18070 return NumberEditor; 18071}; 18072 18073/***/ }), 18074 18075/***/ "./sources/core/ui/grid/editors/editors/predecessor.js": 18076/*!*************************************************************!*\ 18077 !*** ./sources/core/ui/grid/editors/editors/predecessor.js ***! 18078 \*************************************************************/ 18079/*! no static exports found */ 18080/***/ (function(module, exports, __webpack_require__) { 18081 18082module.exports = function (gantt) { 18083 18084 var BaseEditor = __webpack_require__(/*! ./base */ "./sources/core/ui/grid/editors/editors/base.js")(gantt), 18085 utils = __webpack_require__(/*! ../../../../../utils/utils */ "./sources/utils/utils.js"); 18086 var __extends = __webpack_require__(/*! ../../../../../utils/extends */ "./sources/utils/extends.js"); 18087 18088 function PredecessorEditor() { 18089 var self = BaseEditor.apply(this, arguments) || this; 18090 return self; 18091 } 18092 18093 __extends(PredecessorEditor, BaseEditor); 18094 18095 function getFormatter(config) { 18096 return config.formatter || gantt.ext.formatters.linkFormatter(); 18097 } 18098 18099 function parseInputString(value, config) { 18100 var predecessors = (value || "").split(config.delimiter || ","); 18101 for (var i = 0; i < predecessors.length; i++) { 18102 var val = predecessors[i].trim(); 18103 if (val) { 18104 predecessors[i] = val; 18105 } else { 18106 predecessors.splice(i, 1); 18107 i--; 18108 } 18109 } 18110 predecessors.sort(); 18111 return predecessors; 18112 } 18113 18114 function formatPredecessors(task, config, gantt) { 18115 var links = task.$target; 18116 var labels = []; 18117 for (var i = 0; i < links.length; i++) { 18118 var link = gantt.getLink(links[i]); 18119 labels.push(getFormatter(config).format(link)); 18120 } 18121 return labels.join((config.delimiter || ",") + " "); 18122 } 18123 18124 function getSelectedLinks(taskId, predecessorCodes, config) { 18125 var links = []; 18126 predecessorCodes.forEach(function (code) { 18127 var link = getFormatter(config).parse(code); 18128 if(link){ 18129 link.target = taskId; 18130 if (gantt.isLinkAllowed(link)) { 18131 links.push(link); 18132 } 18133 } 18134 }); 18135 return links; 18136 } 18137 18138 function formatLinkKey(link){ 18139 return link.source + "_" + link.target + "_" + link.type + "_" + (link.lag||0); 18140 } 18141 18142 function getLinksDiff(task, predecessorCodes, config) { 18143 var selectedLinks = getSelectedLinks(task.id, predecessorCodes, config); 18144 var existingLinksSearch = {}; 18145 task.$target.forEach(function (linkId) { 18146 var link = gantt.getLink(linkId); 18147 existingLinksSearch[formatLinkKey(link)] = link.id; 18148 }); 18149 18150 var linksToAdd = []; 18151 selectedLinks.forEach(function (link) { 18152 var linkKey = formatLinkKey(link); 18153 if (!existingLinksSearch[linkKey]) { 18154 linksToAdd.push(link); 18155 } else { 18156 delete existingLinksSearch[linkKey]; 18157 } 18158 }); 18159 18160 var linksToDelete = []; 18161 for (var i in existingLinksSearch) { 18162 linksToDelete.push(existingLinksSearch[i]); 18163 } 18164 18165 return { 18166 add: linksToAdd, 18167 remove: linksToDelete 18168 }; 18169 } 18170 18171 utils.mixin(PredecessorEditor.prototype, { 18172 show: function (id, column, config, placeholder) { 18173 var html = "<div><input type='text' name='" + column.name + "'></div>"; 18174 placeholder.innerHTML = html; 18175 }, 18176 hide: function () { 18177 }, 18178 set_value: function (value, id, column, node) { 18179 this.get_input(node).value = formatPredecessors(value, column.editor, gantt); 18180 }, 18181 get_value: function (id, column, node) { 18182 return parseInputString((this.get_input(node).value || ""), column.editor); 18183 }, 18184 save: function (id, column, node) { 18185 var task = gantt.getTask(id); 18186 18187 var linksDiff = getLinksDiff(task, this.get_value(id, column, node), column.editor); 18188 18189 if (linksDiff.add.length || linksDiff.remove.length) { 18190 gantt.batchUpdate(function () { 18191 linksDiff.add.forEach(function (link) { 18192 gantt.addLink(link); 18193 }); 18194 linksDiff.remove.forEach(function (linkId) { 18195 gantt.deleteLink(linkId); 18196 }); 18197 18198 if (gantt.autoSchedule) 18199 gantt.autoSchedule(); 18200 }); 18201 } 18202 }, 18203 is_changed: function (value, id, column, node) { 18204 var inputPredecessors = this.get_value(id, column, node); 18205 var taskPredecessors = parseInputString(formatPredecessors(value, column.editor, gantt), column.editor); 18206 18207 return inputPredecessors.join() !== taskPredecessors.join(); 18208 } 18209 }, true); 18210 18211 return PredecessorEditor; 18212}; 18213 18214/***/ }), 18215 18216/***/ "./sources/core/ui/grid/editors/editors/select.js": 18217/*!********************************************************!*\ 18218 !*** ./sources/core/ui/grid/editors/editors/select.js ***! 18219 \********************************************************/ 18220/*! no static exports found */ 18221/***/ (function(module, exports, __webpack_require__) { 18222 18223module.exports = function(gantt) { 18224 var BaseEditor = __webpack_require__(/*! ./base */ "./sources/core/ui/grid/editors/editors/base.js")(gantt), 18225 utils = __webpack_require__(/*! ../../../../../utils/utils */ "./sources/utils/utils.js"); 18226 var __extends = __webpack_require__(/*! ../../../../../utils/extends */ "./sources/utils/extends.js"); 18227 18228 function SelectEditor() { 18229 var self = BaseEditor.apply(this, arguments) || this; 18230 return self; 18231 } 18232 18233 __extends(SelectEditor, BaseEditor); 18234 18235 utils.mixin(SelectEditor.prototype, { 18236 show: function (id, column, config, placeholder) { 18237 var html = "<div><select name='" + column.name + "'>"; 18238 var optionsHtml = [], 18239 options = config.options || []; 18240 18241 for (var i = 0; i < options.length; i++) { 18242 optionsHtml.push("<option value='" + config.options[i].key + "'>" + options[i].label + "</option>"); 18243 } 18244 18245 html += optionsHtml.join("") + "</select></div>"; 18246 placeholder.innerHTML = html; 18247 }, 18248 get_input: function (node) { 18249 return node.querySelector("select"); 18250 } 18251 }, true); 18252 18253 return SelectEditor; 18254}; 18255 18256/***/ }), 18257 18258/***/ "./sources/core/ui/grid/editors/editors/text.js": 18259/*!******************************************************!*\ 18260 !*** ./sources/core/ui/grid/editors/editors/text.js ***! 18261 \******************************************************/ 18262/*! no static exports found */ 18263/***/ (function(module, exports, __webpack_require__) { 18264 18265module.exports = function(gantt) { 18266 18267 var BaseEditor = __webpack_require__(/*! ./base */ "./sources/core/ui/grid/editors/editors/base.js")(gantt), 18268 utils = __webpack_require__(/*! ../../../../../utils/utils */ "./sources/utils/utils.js"); 18269 var __extends = __webpack_require__(/*! ../../../../../utils/extends */ "./sources/utils/extends.js"); 18270 18271 function TextEditor() { 18272 var self = BaseEditor.apply(this, arguments) || this; 18273 return self; 18274 } 18275 18276 __extends(TextEditor, BaseEditor); 18277 18278 utils.mixin(TextEditor.prototype, { 18279 show: function (id, column, config, placeholder) { 18280 var html = "<div><input type='text' name='" + column.name + "'></div>"; 18281 placeholder.innerHTML = html; 18282 } 18283 }, true); 18284 18285 return TextEditor; 18286}; 18287 18288/***/ }), 18289 18290/***/ "./sources/core/ui/grid/editors/keyboard_mappings.js": 18291/*!***********************************************************!*\ 18292 !*** ./sources/core/ui/grid/editors/keyboard_mappings.js ***! 18293 \***********************************************************/ 18294/*! no static exports found */ 18295/***/ (function(module, exports, __webpack_require__) { 18296 18297var defaultMapping = __webpack_require__(/*! ./keyboard_mappings/default */ "./sources/core/ui/grid/editors/keyboard_mappings/default.js"); 18298var keyNavMappings = __webpack_require__(/*! ./keyboard_mappings/keyboard_navigation */ "./sources/core/ui/grid/editors/keyboard_mappings/keyboard_navigation.js"); 18299 18300module.exports = function(gantt){ 18301 18302 var mapping = null; 18303 18304 return { 18305 setMapping: function(map){ 18306 mapping = map; 18307 }, 18308 getMapping: function(){ 18309 18310 if(mapping){ 18311 return mapping; 18312 }else if(gantt.config.keyboard_navigation_cells){ 18313 return keyNavMappings; 18314 }else{ 18315 return defaultMapping; 18316 } 18317 } 18318 }; 18319}; 18320 18321 18322/***/ }), 18323 18324/***/ "./sources/core/ui/grid/editors/keyboard_mappings/default.js": 18325/*!*******************************************************************!*\ 18326 !*** ./sources/core/ui/grid/editors/keyboard_mappings/default.js ***! 18327 \*******************************************************************/ 18328/*! no static exports found */ 18329/***/ (function(module, exports) { 18330 18331module.exports = { 18332 init: function (controller, grid) { 18333 var gantt = grid.$gantt; 18334 18335 gantt.attachEvent("onTaskClick", function (id, e) { 18336 if (gantt._is_icon_open_click(e)) 18337 return true; 18338 var state = controller.getState(); 18339 var cell = controller.locateCell(e.target); 18340 18341 if (cell && controller.getEditorConfig(cell.columnName)) { 18342 if (controller.isVisible() && state.id == cell.id && state.columnName == cell.columnName) { 18343 // do nothing if editor is already active in this cell 18344 } else { 18345 controller.startEdit(cell.id, cell.columnName); 18346 } 18347 return false; 18348 } 18349 return true; 18350 }); 18351 18352 gantt.attachEvent("onEmptyClick", function () { 18353 if (controller.isVisible() && controller.isChanged()) { 18354 controller.save(); 18355 } else { 18356 controller.hide(); 18357 } 18358 return true; 18359 }); 18360 18361 gantt.attachEvent("onTaskDblClick", function (id, e) { 18362 var state = controller.getState(); 18363 var cell = controller.locateCell(e.target); 18364 if (cell && controller.isVisible() && cell.columnName == state.columnName) { 18365 controller.hide(); 18366 return false; 18367 } 18368 return true; 18369 }); 18370 }, 18371 18372 onShow: function (controller, placeholder, grid) { 18373 var gantt = grid.$gantt; 18374 18375 18376 if(gantt.ext && gantt.ext.keyboardNavigation){ 18377 var keyNav = gantt.ext.keyboardNavigation; 18378 keyNav.attachEvent("onKeyDown", function(command, e){ 18379 var keyboard = gantt.constants.KEY_CODES; 18380 var keyCode = e.keyCode; 18381 var preventKeyNav = false; 18382 18383 switch (keyCode){ 18384 case keyboard.SPACE: 18385 if(controller.isVisible()){ 18386 preventKeyNav = true; 18387 } 18388 break; 18389 } 18390 if (preventKeyNav){ 18391 return false; 18392 } else{ 18393 return true; 18394 } 18395 }); 18396 } 18397 18398 placeholder.onkeydown = function (e) { 18399 e = e || window.event; 18400 18401 var keyboard = gantt.constants.KEY_CODES; 18402 if (e.defaultPrevented || (e.shiftKey && e.keyCode != keyboard.TAB)) { 18403 return; 18404 } 18405 18406 var shouldPrevent = true; 18407 switch (e.keyCode) { 18408 case gantt.keys.edit_save: 18409 controller.save(); 18410 break; 18411 case gantt.keys.edit_cancel: 18412 controller.hide(); 18413 break; 18414 case keyboard.UP: 18415 case keyboard.DOWN: 18416 if (controller.isVisible()) { 18417 controller.hide(); 18418 shouldPrevent = false; 18419 } 18420 break; 18421 case keyboard.TAB: 18422 if (e.shiftKey) { 18423 controller.editPrevCell(true); 18424 } else { 18425 controller.editNextCell(true); 18426 } 18427 break; 18428 default: 18429 shouldPrevent = false; 18430 break; 18431 } 18432 18433 if (shouldPrevent) { 18434 e.preventDefault(); 18435 } 18436 }; 18437 }, 18438 onHide: function () { 18439 18440 }, 18441 18442 destroy: function () { 18443 18444 } 18445}; 18446 18447 18448 18449/***/ }), 18450 18451/***/ "./sources/core/ui/grid/editors/keyboard_mappings/keyboard_navigation.js": 18452/*!*******************************************************************************!*\ 18453 !*** ./sources/core/ui/grid/editors/keyboard_mappings/keyboard_navigation.js ***! 18454 \*******************************************************************************/ 18455/*! no static exports found */ 18456/***/ (function(module, exports) { 18457 18458module.exports = { 18459 init: function(controller, grid){ 18460 var self = controller; 18461 var gantt = grid.$gantt; 18462 18463 var onBlurDelay = null; 18464 var keyNav = gantt.ext.keyboardNavigation; 18465 keyNav.attachEvent("onBeforeFocus", function (node) { 18466 var activeCell = controller.locateCell(node); 18467 clearTimeout(onBlurDelay); 18468 if (activeCell) { 18469 var columnName = activeCell.columnName; 18470 var id = activeCell.id; 18471 18472 var editorState = self.getState(); 18473 if(self.isVisible()){ 18474 if(editorState.id == id && editorState.columnName === columnName) { 18475 return false; 18476 } 18477 } 18478 } 18479 return true; 18480 }); 18481 18482 keyNav.attachEvent("onFocus", function (node) { 18483 var activeCell = controller.locateCell(node); 18484 var state = controller.getState(); 18485 clearTimeout(onBlurDelay); 18486 if (activeCell && !(activeCell.id == state.id && activeCell.columnName == state.columnName)) { 18487 if(self.isVisible()){ 18488 self.save(); 18489 } 18490 } 18491 return true; 18492 }); 18493 18494 controller.attachEvent("onHide", function(){ 18495 clearTimeout(onBlurDelay); 18496 }); 18497 18498 keyNav.attachEvent("onBlur", function () { 18499 onBlurDelay = setTimeout(function(){ 18500 self.save(); 18501 }); 18502 18503 return true; 18504 }); 18505 18506 gantt.attachEvent("onTaskDblClick", function(id,e){ 18507 // block lightbox on double click inside editor 18508 var state = controller.getState(); 18509 var cell = controller.locateCell(e.target); 18510 if(cell && controller.isVisible() && cell.columnName == state.columnName){ 18511 return false; 18512 } 18513 return true; 18514 }); 18515 18516 gantt.attachEvent("onTaskClick", function (id, e) { 18517 if(gantt._is_icon_open_click(e)) 18518 return true; 18519 18520 var state = controller.getState(); 18521 var cell = controller.locateCell(e.target); 18522 18523 if (cell && controller.getEditorConfig(cell.columnName)) { 18524 if(controller.isVisible() && state.id == cell.id && state.columnName == cell.columnName){ 18525 // do nothing if editor is already active in this cell 18526 }else{ 18527 controller.startEdit(cell.id, cell.columnName); 18528 } 18529 return false; 18530 } 18531 return true; 18532 }); 18533 gantt.attachEvent("onEmptyClick", function () { 18534 self.save(); 18535 return true; 18536 }); 18537 18538 keyNav.attachEvent("onKeyDown", function(command, e){ 18539 var activeCell = controller.locateCell(e.target); 18540 var hasEditor = activeCell ? controller.getEditorConfig(activeCell.columnName) : false; 18541 18542 var state = controller.getState(); 18543 var keyboard = gantt.constants.KEY_CODES; 18544 var keyCode = e.keyCode; 18545 var preventKeyNav = false; 18546 18547 switch (keyCode){ 18548 case keyboard.ENTER: 18549 if(controller.isVisible()){ 18550 controller.save(); 18551 e.preventDefault(); 18552 preventKeyNav = true; 18553 }else if(hasEditor && !(e.ctrlKey || e.metaKey || e.shiftKey)){ 18554 self.startEdit(activeCell.id, activeCell.columnName); 18555 e.preventDefault(); 18556 preventKeyNav = true; 18557 } 18558 break; 18559 case keyboard.ESC: 18560 if(controller.isVisible()){ 18561 controller.hide(); 18562 e.preventDefault(); 18563 preventKeyNav = true; 18564 } 18565 break; 18566 case keyboard.UP: 18567 case keyboard.DOWN: 18568 break; 18569 case keyboard.LEFT: 18570 case keyboard.RIGHT: 18571 if((hasEditor && controller.isVisible()) || state.editorType === "date"){ 18572 preventKeyNav = true; 18573 } 18574 break; 18575 case keyboard.SPACE: 18576 if(controller.isVisible()){ 18577 preventKeyNav = true; 18578 } 18579 18580 if(hasEditor && !controller.isVisible()){ 18581 self.startEdit(activeCell.id, activeCell.columnName); 18582 e.preventDefault(); 18583 preventKeyNav = true; 18584 } 18585 break; 18586 case keyboard.DELETE: 18587 if(hasEditor && !controller.isVisible()){ 18588 self.startEdit(activeCell.id, activeCell.columnName); 18589 preventKeyNav = true; 18590 } else if(hasEditor && controller.isVisible()){ 18591 preventKeyNav = true; 18592 } 18593 break; 18594 case keyboard.TAB: 18595 if(controller.isVisible()){ 18596 18597 if(e.shiftKey){ 18598 controller.editPrevCell(true); 18599 }else{ 18600 controller.editNextCell(true); 18601 } 18602 var newState = controller.getState(); 18603 if(newState.id){ 18604 keyNav.focus({type:"taskCell", id: newState.id, column:newState.columnName}); 18605 } 18606 e.preventDefault(); 18607 preventKeyNav = true; 18608 } 18609 break; 18610 default: 18611 if(controller.isVisible()) 18612 preventKeyNav = true; 18613 else{ 18614 18615 // start editing on character key 18616 if((keyCode >= 48 && keyCode <= 57) || // [0-9] 18617 (keyCode > 95 && keyCode < 112) || // numpad 18618 (keyCode >= 64 && keyCode <= 91) || // [a-z] 18619 (keyCode > 185 && keyCode < 193) || //;=-,etc 18620 (keyCode > 218 && keyCode < 223) 18621 ){ 18622 var modifiers = command.modifiers; 18623 18624 var anyModifier = modifiers.alt || modifiers.ctrl || modifiers.meta || modifiers.shift; 18625 if(modifiers.alt){ 18626 // don't start editing on alt+key 18627 }else if (anyModifier && keyNav.getCommandHandler(command, "taskCell")){ 18628 // don't start editing if command already have a keyboard shortcut 18629 }else if(hasEditor && !controller.isVisible()){ 18630 self.startEdit(activeCell.id, activeCell.columnName); 18631 preventKeyNav = true; 18632 } 18633 } 18634 } 18635 18636 break; 18637 } 18638 18639 if (preventKeyNav){ 18640 return false; 18641 } else{ 18642 return true; 18643 } 18644 18645 }); 18646 }, 18647 onShow: function(controller, placeholder, grid){}, 18648 onHide: function(controller, placeholder, grid){ 18649 var gantt = grid.$gantt; 18650 gantt.focus(); 18651 18652 }, 18653 destroy: function(){} 18654}; 18655 18656 18657 18658/***/ }), 18659 18660/***/ "./sources/core/ui/grid/editors/linked_properties.js": 18661/*!***********************************************************!*\ 18662 !*** ./sources/core/ui/grid/editors/linked_properties.js ***! 18663 \***********************************************************/ 18664/*! no static exports found */ 18665/***/ (function(module, exports) { 18666 18667module.exports = function (gantt) { 18668 return function processTaskDateProperties(item, mapTo, mode) { 18669 if (mode == "keepDates") { 18670 keepDatesOnEdit(item, mapTo); 18671 } else if (mode == "keepDuration") { 18672 keepDurationOnEdit(item, mapTo); 18673 } else { 18674 defaultActionOnEdit(item, mapTo); 18675 } 18676 }; 18677 18678 // resize task 18679 // resize task when start/end/duration changes 18680 function keepDatesOnEdit(item, mapTo) { 18681 if (mapTo == "duration") { 18682 item.end_date = gantt.calculateEndDate(item); 18683 } else if (mapTo == "end_date" || mapTo == "start_date") { 18684 item.duration = gantt.calculateDuration(item); 18685 } 18686 } 18687 18688 // move task(before 6.2) 18689 // move task when start/end dates changes 18690 // resize task when duration changes 18691 function keepDurationOnEdit(item, mapTo) { 18692 if (mapTo == "end_date") { 18693 item.start_date = gantt.calculateEndDate({ 18694 start_date: item.end_date, 18695 duration: -item.duration, 18696 task: item 18697 } 18698 ); 18699 } else if (mapTo == "start_date" || mapTo == "duration") { 18700 item.end_date = gantt.calculateEndDate(item); 18701 } 18702 } 18703 18704 // default behavior 18705 // move task when start date changes 18706 // resize task when end date/duration changes 18707 function defaultActionOnEdit(item, mapTo) { 18708 if (mapTo == "start_date" || mapTo == "duration") { 18709 item.end_date = gantt.calculateEndDate(item); 18710 } else if (mapTo == "end_date") { 18711 item.duration = gantt.calculateDuration(item); 18712 } 18713 } 18714}; 18715 18716/***/ }), 18717 18718/***/ "./sources/core/ui/grid/grid.js": 18719/*!**************************************!*\ 18720 !*** ./sources/core/ui/grid/grid.js ***! 18721 \**************************************/ 18722/*! no static exports found */ 18723/***/ (function(module, exports, __webpack_require__) { 18724 18725var domHelpers = __webpack_require__(/*! ../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"), 18726 utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"), 18727 eventable = __webpack_require__(/*! ../../../utils/eventable */ "./sources/utils/eventable.js"), 18728 gridResize = __webpack_require__(/*! ./grid_resize */ "./sources/core/ui/grid/grid_resize.gpl.js"), 18729 topPositionMixin = __webpack_require__(/*! ../row_position_mixin */ "./sources/core/ui/row_position_mixin.js"); 18730 18731var Grid = function (parent, config, factory, gantt) { 18732 this.$config = utils.mixin({}, config || {}); 18733 this.$gantt = gantt; 18734 this.$parent = parent; 18735 eventable(this); 18736 this.$state = {}; 18737 utils.mixin(this, topPositionMixin()); 18738}; 18739 18740 18741Grid.prototype = { 18742 init: function (container) { 18743 var gantt = this.$gantt; 18744 var gridAriaAttr = gantt._waiAria.gridAttrString(); 18745 var gridDataAriaAttr = gantt._waiAria.gridDataAttrString(); 18746 18747 18748 container.innerHTML = "<div class='gantt_grid' style='height:inherit;width:inherit;' " + gridAriaAttr + "></div>"; 18749 this.$grid = container.childNodes[0]; 18750 18751 this.$grid.innerHTML = "<div class='gantt_grid_scale' " + 18752 gantt._waiAria.gridScaleRowAttrString() + "></div><div class='gantt_grid_data' " + gridDataAriaAttr + "></div>"; 18753 18754 this.$grid_scale = this.$grid.childNodes[0]; 18755 this.$grid_data = this.$grid.childNodes[1]; 18756 18757 var attr = this.$getConfig()[this.$config.bind + "_attribute"]; 18758 if (!attr && this.$config.bind) { 18759 attr = this.$config.bind + "_id"; 18760 } 18761 this.$config.item_attribute = attr || null; 18762 18763 if (!this.$config.layers) { 18764 var layers = this._createLayerConfig(); 18765 this.$config.layers = layers; 18766 } 18767 18768 var resizer = gridResize(gantt, this); 18769 resizer.init(); 18770 this._renderHeaderResizers = resizer.doOnRender; 18771 this._mouseDelegates = __webpack_require__(/*! ../mouse_event_container */ "./sources/core/ui/mouse_event_container.js")(gantt); 18772 18773 this._addLayers(this.$gantt); 18774 this._initEvents(); 18775 this.callEvent("onReady", []); 18776 //this.refresh(); 18777 }, 18778 18779 _validateColumnWidth: function (column, property) { 18780 // user can set {name:"text", width:"200",...} for some reason, 18781 // check and convert it to number when possible 18782 var value = column[property]; 18783 if (value && value != "*") { 18784 var gantt = this.$gantt; 18785 var numericWidth = value * 1; 18786 if (isNaN(numericWidth)) { 18787 gantt.assert(false, "Wrong " + property + " value of column " + column.name); 18788 } else { 18789 column[property] = numericWidth; 18790 } 18791 } 18792 }, 18793 18794 setSize: function (width, height) { 18795 this.$config.width = this.$state.width = width; 18796 this.$config.height = this.$state.height = height; 18797 18798 // TODO: maybe inherit and override in a subclass instead of extending here 18799 18800 var columns = this.getGridColumns(), 18801 innerWidth = 0; 18802 18803 for (var i = 0, l = columns.length; i < l; i++) { 18804 this._validateColumnWidth(columns[i], "min_width"); 18805 this._validateColumnWidth(columns[i], "max_width"); 18806 this._validateColumnWidth(columns[i], "width"); 18807 18808 innerWidth += columns[i].width * 1; 18809 } 18810 18811 var outerWidth; 18812 if (isNaN(innerWidth) || !this.$config.scrollable) { 18813 outerWidth = this._setColumnsWidth(width + 1); 18814 innerWidth = outerWidth; 18815 } 18816 18817 if (this.$config.scrollable) { 18818 this.$grid_scale.style.width = innerWidth + "px"; 18819 this.$grid_data.style.width = innerWidth + "px"; 18820 } else { 18821 this.$grid_scale.style.width = "inherit"; 18822 this.$grid_data.style.width = "inherit"; 18823 } 18824 this.$config.width -= 1; 18825 18826 var config = this.$getConfig(); 18827 if (outerWidth !== width) { 18828 if(outerWidth !== undefined){ 18829 config.grid_width = outerWidth; 18830 this.$config.width = outerWidth - 1; 18831 }else{ 18832 if(!isNaN(innerWidth)){ 18833 this._setColumnsWidth(innerWidth); 18834 config.grid_width = innerWidth; 18835 this.$config.width = innerWidth - 1; 18836 } 18837 } 18838 } 18839 18840 var dataHeight = Math.max(this.$state.height - config.scale_height, 0); 18841 this.$grid_data.style.height = dataHeight + "px"; 18842 this.refresh(); 18843 }, 18844 getSize: function () { 18845 18846 var config = this.$getConfig(); 18847 18848 var store = this.$config.rowStore; 18849 18850 var contentHeight = store ? config.row_height * store.countVisible() : 0, 18851 contentWidth = this._getGridWidth(); 18852 18853 var size = { 18854 x: this.$state.width, 18855 y: this.$state.height, 18856 contentX: this.isVisible() ? contentWidth : 0, 18857 contentY: this.isVisible() ? (config.scale_height + contentHeight) : 0, 18858 scrollHeight: this.isVisible() ? contentHeight : 0, 18859 scrollWidth: this.isVisible() ? contentWidth : 0 18860 }; 18861 18862 return size; 18863 }, 18864 18865 _bindStore: function () { 18866 if (this.$config.bind){ 18867 var rowStore = this.$gantt.getDatastore(this.$config.bind); 18868 this.$config.rowStore = rowStore; 18869 if(rowStore && !rowStore._gridCacheAttached){ 18870 var self = this; 18871 rowStore._gridCacheAttached = rowStore.attachEvent("onBeforeFilter", function(){ 18872 self._resetTopPositionHeight(); 18873 }); 18874 } 18875 } 18876 }, 18877 _unbindStore: function(){ 18878 if (this.$config.bind){ 18879 var rowStore = this.$gantt.getDatastore(this.$config.bind); 18880 if(rowStore._gridCacheAttached){ 18881 rowStore.detachEvent(rowStore._gridCacheAttached); 18882 rowStore._gridCacheAttached = false; 18883 } 18884 } 18885 }, 18886 18887 refresh: function () { 18888 this._bindStore(); 18889 18890 this._resetTopPositionHeight(); 18891 this._initSmartRenderingPlaceholder(); 18892 18893 this._calculateGridWidth(); 18894 this._renderGridHeader(); 18895 }, 18896 18897 getViewPort: function(){ 18898 var scrollLeft = this.$config.scrollLeft || 0; 18899 var scrollTop = this.$config.scrollTop || 0; 18900 var height = this.$config.height || 0; 18901 var width = this.$config.width || 0; 18902 return { 18903 y: scrollTop, 18904 y_end: scrollTop + height, 18905 x: scrollLeft, 18906 x_end: scrollLeft + width, 18907 height: height, 18908 width: width 18909 }; 18910 }, 18911 18912 scrollTo: function (left, top) { 18913 if (!this.isVisible()) 18914 return; 18915 18916 var scrolled = false; 18917 18918 this.$config.scrollTop = this.$config.scrollTop || 0; 18919 this.$config.scrollLeft = this.$config.scrollLeft || 0; 18920 18921 if (left * 1 == left) { 18922 this.$config.scrollLeft = this.$state.scrollLeft = this.$grid.scrollLeft = left; 18923 scrolled = true; 18924 } 18925 18926 // var config = this.$getConfig(); 18927 if (top * 1 == top) { 18928 this.$config.scrollTop = this.$state.scrollTop = this.$grid_data.scrollTop = top; 18929 scrolled = true; 18930 } 18931 18932 if(scrolled){ 18933 this.callEvent("onScroll", [this.$config.scrollLeft, this.$config.scrollTop]); 18934 } 18935 }, 18936 18937 getColumnIndex: function (name) { 18938 var columns = this.$getConfig().columns; 18939 18940 for (var i = 0; i < columns.length; i++) { 18941 if (columns[i].name == name) { 18942 return i; 18943 } 18944 } 18945 return null; 18946 }, 18947 18948 getColumn: function (name) { 18949 var index = this.getColumnIndex(name); 18950 if (index === null) { 18951 return null; 18952 } 18953 return this.$getConfig().columns[index]; 18954 }, 18955 18956 getGridColumns: function () { 18957 var config = this.$getConfig(); 18958 return config.columns.slice(); 18959 }, 18960 isVisible: function () { 18961 if (this.$parent && this.$parent.$config) { 18962 return !this.$parent.$config.hidden; 18963 } else { 18964 return this.$grid.offsetWidth; 18965 } 18966 }, 18967 18968 getItemHeight: function () { 18969 var config = this.$getConfig(); 18970 return config.row_height; 18971 }, 18972 18973 _createLayerConfig: function () { 18974 var gantt = this.$gantt; 18975 var self = this; 18976 var layers = [ 18977 { 18978 renderer: gantt.$ui.layers.gridLine(), 18979 container: this.$grid_data, 18980 filter: [function () { 18981 return self.isVisible(); 18982 }] 18983 } 18984 ]; 18985 return layers; 18986 }, 18987 18988 _addLayers: function (gantt) { 18989 if (!this.$config.bind) 18990 return; 18991 18992 this._taskLayers = []; 18993 18994 var self = this; 18995 18996 var layers = this.$gantt.$services.getService("layers"); 18997 var taskRenderer = layers.getDataRender(this.$config.bind); 18998 18999 if (!taskRenderer) { 19000 taskRenderer = layers.createDataRender({ 19001 name: this.$config.bind, 19002 defaultContainer: function () { return self.$grid_data; } 19003 }); 19004 } 19005 19006 var taskLayers = this.$config.layers; 19007 for (var i = 0; taskLayers && i < taskLayers.length; i++) { 19008 var layer = taskLayers[i]; 19009 layer.view = this; 19010 19011 var bar_layer = taskRenderer.addLayer(layer); 19012 this._taskLayers.push(bar_layer); 19013 } 19014 19015 this._bindStore(); 19016 19017 this._initSmartRenderingPlaceholder(); 19018 }, 19019 19020 _refreshPlaceholderOnStoreUpdate: function (id) { 19021 var config = this.$getConfig(), 19022 store = this.$config.rowStore; 19023 19024 if (!store || id !== null || !this.isVisible() || !config.smart_rendering) { 19025 return; 19026 } 19027 19028 var contentHeight; 19029 if (this.$config.scrollY) { 19030 var scroll = this.$gantt.$ui.getView(this.$config.scrollY); 19031 if (scroll) 19032 contentHeight = scroll.getScrollState().scrollSize; 19033 } 19034 19035 if (!contentHeight) { 19036 contentHeight = store ? config.row_height * store.countVisible() : 0; 19037 } 19038 19039 if (contentHeight) { 19040 if (this.$rowsPlaceholder && this.$rowsPlaceholder.parentNode) { 19041 this.$rowsPlaceholder.parentNode.removeChild(this.$rowsPlaceholder); 19042 } 19043 19044 var placeholder = this.$rowsPlaceholder = document.createElement("div"); 19045 placeholder.style.visibility = "hidden"; 19046 placeholder.style.height = contentHeight + "px"; 19047 placeholder.style.width = "1px"; 19048 this.$grid_data.appendChild(placeholder); 19049 } 19050 }, 19051 19052 _initSmartRenderingPlaceholder: function () { 19053 var store = this.$config.rowStore; 19054 if (!store) { 19055 return; 19056 } else { 19057 this._initSmartRenderingPlaceholder = function () { }; 19058 } 19059 this._staticBgHandler = store.attachEvent("onStoreUpdated", utils.bind(this._refreshPlaceholderOnStoreUpdate, this)); 19060 }, 19061 19062 _initEvents: function () { 19063 var gantt = this.$gantt; 19064 this._mouseDelegates.delegate("click", "gantt_close", gantt.bind(function (e, id, trg) { 19065 var store = this.$config.rowStore; 19066 if (!store) return true; 19067 19068 var target = domHelpers.locateAttribute(e, this.$config.item_attribute); 19069 if (target) { 19070 store.close(target.getAttribute(this.$config.item_attribute)); 19071 19072 } 19073 return false; 19074 }, this), this.$grid); 19075 19076 this._mouseDelegates.delegate("click", "gantt_open", gantt.bind(function (e, id, trg) { 19077 var store = this.$config.rowStore; 19078 if (!store) return true; 19079 19080 var target = domHelpers.locateAttribute(e, this.$config.item_attribute); 19081 if (target) { 19082 store.open(target.getAttribute(this.$config.item_attribute)); 19083 19084 } 19085 return false; 19086 }, this), this.$grid); 19087 }, 19088 19089 _clearLayers: function (gantt) { 19090 var layers = this.$gantt.$services.getService("layers"); 19091 var taskRenderer = layers.getDataRender(this.$config.bind); 19092 19093 if (this._taskLayers) { 19094 for (var i = 0; i < this._taskLayers.length; i++) { 19095 taskRenderer.removeLayer(this._taskLayers[i]); 19096 } 19097 } 19098 19099 this._taskLayers = []; 19100 }, 19101 19102 _getColumnWidth: function (column, config, width) { 19103 var min_width = column.min_width || config.min_grid_column_width; 19104 var new_width = Math.max(width, min_width || 10); 19105 if (column.max_width) 19106 new_width = Math.min(new_width, column.max_width); 19107 return new_width; 19108 }, 19109 // return min and max possible grid width according to restricts 19110 _getGridWidthLimits: function () { 19111 var config = this.$getConfig(), 19112 columns = this.getGridColumns(), 19113 min_limit = 0, 19114 max_limit = 0; 19115 19116 for (var i = 0; i < columns.length; i++) { 19117 min_limit += columns[i].min_width ? columns[i].min_width : config.min_grid_column_width; 19118 if (max_limit !== undefined) { 19119 max_limit = columns[i].max_width ? (max_limit + columns[i].max_width) : undefined; 19120 } 19121 } 19122 19123 return [min_limit, max_limit]; 19124 }, 19125 // resize columns to get total newWidth, starting from columns[start_index] 19126 _setColumnsWidth: function (newWidth, start_index) { 19127 var config = this.$getConfig(); 19128 var columns = this.getGridColumns(), 19129 columns_width = 0, 19130 final_width = newWidth; 19131 19132 start_index = !window.isNaN(start_index) ? start_index : -1; 19133 19134 for (var i = 0, l = columns.length; i < l; i++) { 19135 columns_width += columns[i].width * 1; 19136 } 19137 19138 if (window.isNaN(columns_width)) { 19139 this._calculateGridWidth(); 19140 columns_width = 0; 19141 for (var i = 0, l = columns.length; i < l; i++) { 19142 columns_width += columns[i].width * 1; 19143 } 19144 } 19145 19146 var extra_width = final_width - columns_width; 19147 19148 var start_width = 0; 19149 for (var i = 0; i < start_index + 1; i++) { 19150 start_width += columns[i].width; 19151 } 19152 19153 columns_width -= start_width; 19154 19155 for (var i = start_index + 1; i < columns.length; i++) { 19156 19157 var col = columns[i]; 19158 var share = Math.round(extra_width * (col.width / columns_width)); 19159 19160 // columns have 2 additional restrict fields - min_width & max_width that are set by user 19161 if (extra_width < 0) { 19162 if (col.min_width && col.width + share < col.min_width) 19163 share = col.min_width - col.width; 19164 else if (!col.min_width && config.min_grid_column_width && col.width + share < config.min_grid_column_width) 19165 share = config.min_grid_column_width - col.width; 19166 } else if (col.max_width && col.width + share > col.max_width) 19167 share = col.max_width - col.width; 19168 19169 columns_width -= col.width; 19170 col.width += share; 19171 extra_width -= share; 19172 19173 } 19174 19175 var iterator = extra_width > 0 ? 1 : -1; 19176 while ((extra_width > 0 && iterator === 1) || (extra_width < 0 && iterator === -1)) { 19177 var curExtra = extra_width; 19178 for (i = start_index + 1; i < columns.length; i++) { 19179 var new_width = columns[i].width + iterator; 19180 19181 if (new_width == this._getColumnWidth(columns[i], config, new_width)) { 19182 extra_width -= iterator; 19183 columns[i].width = new_width; 19184 } 19185 19186 if (!extra_width) 19187 break; 19188 19189 } 19190 19191 if (curExtra == extra_width) 19192 break; 19193 } 19194 19195 // if impossible to resize the right-side columns, resize the start column 19196 if (extra_width && start_index > -1) { 19197 var new_width = columns[start_index].width + extra_width; 19198 if (new_width == this._getColumnWidth(columns[start_index], config, new_width)) 19199 columns[start_index].width = new_width; 19200 } 19201 19202 //if (this.callEvent("onGridResizeEnd", [config.grid_width, final_width]) === false) 19203 // return; 19204 19205 return this._getColsTotalWidth(); 19206 }, 19207 19208 _getColsTotalWidth: function () { 19209 var columns = this.getGridColumns(); 19210 var cols_width = 0; 19211 19212 for (var i = 0; i < columns.length; i++) { 19213 var v = parseFloat(columns[i].width); 19214 if (window.isNaN(v)) { 19215 return false; 19216 } 19217 cols_width += v; 19218 } 19219 return cols_width; 19220 }, 19221 _calculateGridWidth: function () { 19222 var config = this.$getConfig(); 19223 var columns = this.getGridColumns(); 19224 var cols_width = 0; 19225 var unknown = []; 19226 var width = []; 19227 19228 for (var i = 0; i < columns.length; i++) { 19229 var v = parseFloat(columns[i].width); 19230 if (window.isNaN(v)) { 19231 v = config.min_grid_column_width || 10; 19232 unknown.push(i); 19233 } 19234 width[i] = v; 19235 cols_width += v; 19236 } 19237 var gridWidth = this._getGridWidth() + 1; 19238 if (config.autofit || unknown.length) { 19239 var diff = gridWidth - cols_width; 19240 // TODO: logic may be improved for proportional changing of width 19241 if (config.autofit) { 19242 // delta must be added for all columns 19243 for (var i = 0; i < width.length; i++) { 19244 var delta = Math.round(diff / (width.length - i)); 19245 width[i] += delta; 19246 var new_width = this._getColumnWidth(columns[i], config, width[i]); 19247 19248 if (new_width != width[i]) { 19249 delta = new_width - width[i]; 19250 width[i] = new_width; 19251 } 19252 diff -= delta; 19253 } 19254 } else if (unknown.length) { 19255 // there are several columns with undefined width 19256 for (var i = 0; i < unknown.length; i++) { 19257 var delta = Math.round(diff / (unknown.length - i)); // no float values, just integer 19258 var index = unknown[i]; 19259 width[index] += delta; 19260 var new_width = this._getColumnWidth(columns[index], config, width[index]); 19261 if (new_width != width[index]) { 19262 delta = new_width - width[index]; 19263 width[index] = new_width; 19264 } 19265 diff -= delta; 19266 } 19267 } 19268 19269 for (var i = 0; i < width.length; i++) { 19270 columns[i].width = width[i]; 19271 } 19272 } else { 19273 var changed = (gridWidth != cols_width); 19274 this.$config.width = cols_width - 1; 19275 config.grid_width = cols_width; 19276 if (changed) { 19277 this.$parent._setContentSize(this.$config.width, null); 19278 } 19279 } 19280 19281 }, 19282 19283 _renderGridHeader: function () { 19284 var gantt = this.$gantt; 19285 var config = this.$getConfig(); 19286 var locale = this.$gantt.locale; 19287 var templates = this.$gantt.templates; 19288 19289 var columns = this.getGridColumns(); 19290 if (config.rtl) { 19291 columns = columns.reverse(); 19292 } 19293 var cells = []; 19294 var width = 0, 19295 labels = locale.labels; 19296 19297 var lineHeigth = config.scale_height - 1; 19298 19299 for (var i = 0; i < columns.length; i++) { 19300 var last = i == columns.length - 1; 19301 var col = columns[i]; 19302 19303 // ensure columns have non-empty names 19304 if (!col.name) { 19305 col.name = gantt.uid() + ""; 19306 } 19307 19308 var colWidth = col.width * 1; 19309 19310 var gridWidth = this._getGridWidth(); 19311 if (last && gridWidth > width + colWidth) 19312 col.width = colWidth = gridWidth - width; 19313 width += colWidth; 19314 var sort = (gantt._sort && col.name == gantt._sort.name) ? ("<div class='gantt_sort gantt_" + gantt._sort.direction + "'></div>") : ""; 19315 var cssClass = ["gantt_grid_head_cell", 19316 ("gantt_grid_head_" + col.name), 19317 (last ? "gantt_last_cell" : ""), 19318 templates.grid_header_class(col.name, col)].join(" "); 19319 19320 var style = "width:" + (colWidth - (last ? 1 : 0)) + "px;"; 19321 var label = (col.label || labels["column_" + col.name] || labels[col.name]); 19322 label = label || ""; 19323 19324 var ariaAttrs = gantt._waiAria.gridScaleCellAttrString(col, label); 19325 19326 var cell = "<div class='" + cssClass + "' style='" + style + "' " + ariaAttrs + " data-column-id='" + col.name + "' column_id='" + col.name + "'>" + label + sort + "</div>"; 19327 cells.push(cell); 19328 } 19329 this.$grid_scale.style.height = (config.scale_height) + "px"; 19330 this.$grid_scale.style.lineHeight = lineHeigth + "px"; 19331 //this.$grid_scale.style.width = "inherit"; 19332 this.$grid_scale.innerHTML = cells.join(""); 19333 19334 if (this._renderHeaderResizers) { 19335 this._renderHeaderResizers(); 19336 } 19337 }, 19338 19339 _getGridWidth: function () { 19340 // TODO: refactor/remove/comment some of _getGridWidth/this.$config.width/this.$state.width, it's not clear what they do 19341 return this.$config.width; 19342 }, 19343 19344 destructor: function () { 19345 this._clearLayers(this.$gantt); 19346 if (this._mouseDelegates) { 19347 this._mouseDelegates.destructor(); 19348 this._mouseDelegates = null; 19349 } 19350 this._unbindStore(); 19351 this.$grid = null; 19352 this.$grid_scale = null; 19353 this.$grid_data = null; 19354 this.$gantt = null; 19355 if (this.$config.rowStore) { 19356 this.$config.rowStore.detachEvent(this._staticBgHandler); 19357 this.$config.rowStore = null; 19358 } 19359 19360 this.callEvent("onDestroy", []); 19361 this.detachAllEvents(); 19362 } 19363}; 19364 19365module.exports = Grid; 19366 19367 19368/***/ }), 19369 19370/***/ "./sources/core/ui/grid/grid_resize.gpl.js": 19371/*!*************************************************!*\ 19372 !*** ./sources/core/ui/grid/grid_resize.gpl.js ***! 19373 \*************************************************/ 19374/*! no static exports found */ 19375/***/ (function(module, exports) { 19376 19377function createResizer(gantt, grid){ 19378 return { 19379 init: function(){}, 19380 doOnRender: function(){} 19381 }; 19382} 19383 19384module.exports = createResizer; 19385 19386/***/ }), 19387 19388/***/ "./sources/core/ui/grid/main_grid_initializer.js": 19389/*!*******************************************************!*\ 19390 !*** ./sources/core/ui/grid/main_grid_initializer.js ***! 19391 \*******************************************************/ 19392/*! no static exports found */ 19393/***/ (function(module, exports, __webpack_require__) { 19394 19395var utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"); 19396var rowDnd = __webpack_require__(/*! ./tasks_grid_dnd */ "./sources/core/ui/grid/tasks_grid_dnd.js"); 19397var rowDndMarker = __webpack_require__(/*! ./tasks_grid_dnd_marker */ "./sources/core/ui/grid/tasks_grid_dnd_marker.js"); 19398 19399var initializer = (function(){ 19400 return function(gantt){ 19401 return { 19402 onCreated: function (grid) { 19403 grid.$config = utils.mixin(grid.$config, { 19404 bind: "task" 19405 }); 19406 if(grid.$config.id == "grid") { 19407 this.extendGantt(grid); 19408 gantt.ext.inlineEditors = gantt.ext._inlineEditors.createEditors(grid); 19409 gantt.ext.inlineEditors.init(); 19410 } 19411 19412 this._mouseDelegates = __webpack_require__(/*! ../mouse_event_container */ "./sources/core/ui/mouse_event_container.js")(gantt); 19413 }, 19414 onInitialized: function (grid) { 19415 var config = grid.$getConfig(); 19416 if (config.order_branch) { 19417 if(config.order_branch == "marker"){ 19418 rowDndMarker.init(grid.$gantt, grid); 19419 }else{ 19420 rowDnd.init(grid.$gantt, grid); 19421 } 19422 } 19423 19424 this.initEvents(grid, gantt); 19425 if(grid.$config.id == "grid") { 19426 this.extendDom(grid); 19427 } 19428 }, 19429 onDestroyed: function (grid) { 19430 if(grid.$config.id == "grid") { 19431 gantt.ext.inlineEditors.destructor(); 19432 } 19433 this.clearEvents(grid, gantt); 19434 }, 19435 19436 initEvents: function (grid, gantt) { 19437 this._mouseDelegates.delegate("click", "gantt_row", gantt.bind(function (e, id, trg) { 19438 var config = grid.$getConfig(); 19439 if (id !== null) { 19440 var task = this.getTask(id); 19441 if (config.scroll_on_click && !gantt._is_icon_open_click(e)) 19442 this.showDate(task.start_date); 19443 gantt.callEvent("onTaskRowClick", [id, trg]); 19444 } 19445 }, gantt), grid.$grid); 19446 19447 this._mouseDelegates.delegate("click", "gantt_grid_head_cell", gantt.bind(function (e, id, trg) { 19448 var column = trg.getAttribute("data-column-id"); 19449 19450 if (!gantt.callEvent("onGridHeaderClick", [column, e])) 19451 return; 19452 19453 var config = grid.$getConfig(); 19454 19455 if (column == "add") { 19456 var mouseEvents = gantt.$services.getService("mouseEvents"); 19457 mouseEvents.callHandler("click", "gantt_add", grid.$grid, [e, config.root_id]); 19458 return; 19459 } 19460 19461 if (config.sort) { 19462 var sorting_method = column, 19463 conf; 19464 19465 for (var i = 0; i < config.columns.length; i++) { 19466 if (config.columns[i].name == column) { 19467 conf = config.columns[i]; 19468 break; 19469 } 19470 } 19471 19472 if (conf && conf.sort !== undefined && conf.sort !== true) { 19473 sorting_method = conf.sort; 19474 19475 if (!sorting_method) { // column sort property 'false', no sorting 19476 return; 19477 } 19478 } 19479 19480 var sort = (this._sort && this._sort.direction && this._sort.name == column) ? this._sort.direction : "desc"; 19481 // invert sort direction 19482 sort = (sort == "desc") ? "asc" : "desc"; 19483 this._sort = { 19484 name: column, 19485 direction: sort 19486 }; 19487 this.sort(sorting_method, sort == "desc"); 19488 } 19489 }, gantt), grid.$grid); 19490 19491 this._mouseDelegates.delegate("click", "gantt_add", gantt.bind(function (e, id, trg) { 19492 var config = grid.$getConfig(); 19493 if (config.readonly) return; 19494 19495 var item = {}; 19496 this.createTask(item, id ? id : gantt.config.root_id); 19497 19498 return false; 19499 }, gantt), grid.$grid); 19500 19501 }, 19502 19503 clearEvents: function(grid, gantt){ 19504 this._mouseDelegates.destructor(); 19505 this._mouseDelegates = null; 19506 }, 19507 19508 extendDom: function(grid){ 19509 gantt.$grid = grid.$grid; 19510 gantt.$grid_scale = grid.$grid_scale; 19511 gantt.$grid_data = grid.$grid_data; 19512 }, 19513 extendGantt: function(grid){ 19514 gantt.getGridColumns = gantt.bind(grid.getGridColumns, grid); 19515 19516 grid.attachEvent("onColumnResizeStart", function(){ 19517 return gantt.callEvent("onColumnResizeStart", arguments); 19518 }); 19519 grid.attachEvent("onColumnResize", function(){ 19520 return gantt.callEvent("onColumnResize", arguments); 19521 }); 19522 grid.attachEvent("onColumnResizeEnd", function(){ 19523 return gantt.callEvent("onColumnResizeEnd", arguments); 19524 }); 19525 19526 grid.attachEvent("onColumnResizeComplete", function(columns, totalWidth){ 19527 gantt.config.grid_width = totalWidth; 19528 }); 19529 } 19530 }; 19531 }; 19532})(); 19533 19534module.exports = initializer; 19535 19536/***/ }), 19537 19538/***/ "./sources/core/ui/grid/tasks_grid_dnd.js": 19539/*!************************************************!*\ 19540 !*** ./sources/core/ui/grid/tasks_grid_dnd.js ***! 19541 \************************************************/ 19542/*! no static exports found */ 19543/***/ (function(module, exports, __webpack_require__) { 19544 19545var domHelpers = __webpack_require__(/*! ../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 19546 19547function _init_dnd(gantt, grid) { 19548 var DnD = gantt.$services.getService("dnd"); 19549 19550 if(!grid.$config.bind || !gantt.getDatastore(grid.$config.bind)){ 19551 return; 19552 } 19553 19554 function locate(e){ 19555 return domHelpers.locateAttribute(e, grid.$config.item_attribute); 19556 } 19557 19558 function getStore(){ 19559 return gantt.getDatastore(grid.$config.bind); 19560 } 19561 19562 var dnd = new DnD(grid.$grid_data, {updates_per_second: 60}); 19563 if (gantt.defined(grid.$getConfig().dnd_sensitivity)) 19564 dnd.config.sensitivity = grid.$getConfig().dnd_sensitivity; 19565 19566 dnd.attachEvent("onBeforeDragStart", gantt.bind(function (obj, e) { 19567 var el = locate(e); 19568 if (!el) return false; 19569 if (gantt.hideQuickInfo) gantt._hideQuickInfo(); 19570 19571 if (domHelpers.closest(e.target, ".gantt_grid_editor_placeholder")){ 19572 return false; 19573 } 19574 19575 var id = el.getAttribute(grid.$config.item_attribute); 19576 19577 var datastore = getStore(); 19578 19579 var task = datastore.getItem(id); 19580 19581 if (gantt.isReadonly(task)) 19582 return false; 19583 19584 dnd.config.initial_open_state = task.$open; 19585 if (!gantt.callEvent("onRowDragStart", [id, e.target || e.srcElement, e])) { 19586 return false; 19587 } 19588 19589 }, gantt)); 19590 19591 dnd.attachEvent("onAfterDragStart", gantt.bind(function (obj, e) { 19592 var el = locate(e); 19593 dnd.config.marker.innerHTML = el.outerHTML; 19594 var element = dnd.config.marker.firstChild; 19595 if(element){ 19596 element.style.position = "static"; 19597 } 19598 19599 dnd.config.id = el.getAttribute(grid.$config.item_attribute); 19600 19601 var store = getStore(); 19602 19603 var task = store.getItem(dnd.config.id); 19604 dnd.config.index = store.getBranchIndex(dnd.config.id); 19605 dnd.config.parent = task.parent; 19606 task.$open = false; 19607 task.$transparent = true; 19608 this.refreshData(); 19609 }, gantt)); 19610 19611 dnd.lastTaskOfLevel = function (level) { 19612 var last_item = null; 19613 var store = getStore(); 19614 var tasks = store.getItems(); 19615 for (var i = 0, len = tasks.length; i < len; i++) { 19616 if (tasks[i].$level == level) { 19617 last_item = tasks[i]; 19618 } 19619 } 19620 return last_item ? last_item.id : null; 19621 }; 19622 dnd._getGridPos = gantt.bind(function (e) { 19623 var pos = domHelpers.getNodePosition(grid.$grid_data); 19624 var store = getStore(); 19625 // row offset 19626 var x = pos.x; 19627 var y = e.pos.y - 10; 19628 19629 var config = grid.$getConfig(); 19630 // prevent moving row out of grid_data container 19631 if (y < pos.y) y = pos.y; 19632 var gridHeight = store.countVisible() * config.row_height; 19633 if (y > pos.y + gridHeight - config.row_height) y = pos.y + gridHeight - config.row_height; 19634 19635 pos.x = x; 19636 pos.y = y; 19637 return pos; 19638 }, gantt); 19639 dnd._getTargetY = gantt.bind(function (e) { 19640 var pos = domHelpers.getNodePosition(grid.$grid_data); 19641 19642 var y = e.pageY - pos.y + (grid.$state.scrollTop || 0); 19643 if (y < 0) 19644 y = 0; 19645 return y; 19646 }, gantt); 19647 dnd._getTaskByY = gantt.bind(function (y, dropIndex) { 19648 19649 var config = grid.$getConfig(), 19650 store = getStore(); 19651 19652 y = y || 0; 19653 19654 var index = Math.floor(y / config.row_height); 19655 index = dropIndex < index ? index - 1 : index; 19656 19657 if (index > store.countVisible() - 1) 19658 return null; 19659 19660 return store.getIdByIndex(index); 19661 }, gantt); 19662 dnd.attachEvent("onDragMove", gantt.bind(function (obj, e) { 19663 var dd = dnd.config; 19664 var pos = dnd._getGridPos(e); 19665 19666 var config = grid.$getConfig(), 19667 store = getStore(); 19668 19669 // setting position of row 19670 dd.marker.style.left = pos.x + 10 + "px"; 19671 dd.marker.style.top = pos.y + "px"; 19672 19673 // highlight row when mouseover 19674 var item = store.getItem(dnd.config.id); 19675 var targetY = dnd._getTargetY(e); 19676 var el = dnd._getTaskByY(targetY, store.getIndexById(item.id)); 19677 19678 if (!store.exists(el)) { 19679 el = dnd.lastTaskOfLevel(config.order_branch_free ? item.$level : 0); 19680 if (el == dnd.config.id) { 19681 el = null; 19682 } 19683 } 19684 19685 function allowedLevel(next, item) { 19686 return (!(store.isChildOf(over.id, item.id)) && (next.$level == item.$level || config.order_branch_free)); 19687 } 19688 19689 if (store.exists(el)) { 19690 var over = store.getItem(el); 19691 19692 if (store.getIndexById(over.id) * config.row_height + config.row_height / 2 < targetY) { 19693 //hovering over bottom part of item, check can be drop to bottom 19694 var index = store.getIndexById(over.id); 19695 var nextId = store.getNext(over.id);//adds +1 when hovering over placeholder 19696 var next = store.getItem(nextId); 19697 if (next) { 19698 if (next.id != item.id) { 19699 over = next; //there is a valid target 19700 } 19701 else { 19702 if (config.order_branch_free) { 19703 if (!(store.isChildOf(item.id, over.id) && store.getChildren(over.id).length == 1)) 19704 return; 19705 else { 19706 store.move(item.id, store.getBranchIndex(over.id) + 1, store.getParent(over.id)); 19707 return; 19708 } 19709 } 19710 else { 19711 return; 19712 } 19713 } 19714 } else { 19715 //we at end of the list, check and drop at the end of list 19716 nextId = store.getIdByIndex(index); 19717 next = store.getItem(nextId); 19718 19719 if (allowedLevel(next, item) && next.id != item.id) { 19720 store.move(item.id, -1, store.getParent(next.id)); 19721 return; 19722 } 19723 } 19724 } 19725 else if (config.order_branch_free) { 19726 if (over.id != item.id && allowedLevel(over, item)) { 19727 if (!store.hasChild(over.id)) { 19728 over.$open = true; 19729 store.move(item.id, -1, over.id); 19730 return; 19731 } 19732 if (store.getIndexById(over.id) || config.row_height / 3 < targetY) return; 19733 } 19734 } 19735 //if item is on different level, check the one before it 19736 var index = store.getIndexById(over.id), 19737 prevId = store.getIdByIndex(index - 1); 19738 19739 var prev = store.getItem(prevId); 19740 19741 var shift = 1; 19742 while ((!prev || prev.id == over.id) && index - shift >= 0) { 19743 19744 prevId = store.getIdByIndex(index - shift); 19745 prev = store.getItem(prevId); 19746 shift++; 19747 } 19748 19749 if (item.id == over.id) return; 19750 //replacing item under cursor 19751 if (allowedLevel(over, item) && item.id != over.id) { 19752 store.move(item.id, 0, 0, over.id); 19753 19754 } else if (over.$level == item.$level - 1 && !store.getChildren(over.id).length) { 19755 store.move(item.id, 0, over.id); 19756 19757 } else if (prev && (allowedLevel(prev, item)) && (item.id != prev.id)) { 19758 store.move(item.id, -1, store.getParent(prev.id)); 19759 19760 } 19761 } 19762 return true; 19763 }, gantt)); 19764 19765 dnd.attachEvent("onDragEnd", gantt.bind(function () { 19766 var store = getStore(); 19767 var task = store.getItem(dnd.config.id); 19768 task.$transparent = false; 19769 task.$open = dnd.config.initial_open_state; 19770 19771 if (this.callEvent("onBeforeRowDragEnd", [dnd.config.id, dnd.config.parent, dnd.config.index]) === false) { 19772 store.move(dnd.config.id, dnd.config.index, dnd.config.parent); 19773 task.$drop_target = null; 19774 } else { 19775 this.callEvent("onRowDragEnd", [dnd.config.id, task.$drop_target]); 19776 } 19777 19778 this.refreshData(); 19779 }, gantt)); 19780} 19781 19782module.exports = { 19783 init: _init_dnd 19784}; 19785 19786/***/ }), 19787 19788/***/ "./sources/core/ui/grid/tasks_grid_dnd_marker.js": 19789/*!*******************************************************!*\ 19790 !*** ./sources/core/ui/grid/tasks_grid_dnd_marker.js ***! 19791 \*******************************************************/ 19792/*! no static exports found */ 19793/***/ (function(module, exports, __webpack_require__) { 19794 19795var domHelpers = __webpack_require__(/*! ../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 19796var dropTarget = __webpack_require__(/*! ./tasks_grid_dnd_marker_helpers/drop_target */ "./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/drop_target.js"); 19797var getLockedLevelTarget = __webpack_require__(/*! ./tasks_grid_dnd_marker_helpers/locked_level */ "./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/locked_level.js"); 19798var getMultiLevelTarget = __webpack_require__(/*! ./tasks_grid_dnd_marker_helpers/multi_level */ "./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/multi_level.js"); 19799var higlighter = __webpack_require__(/*! ./tasks_grid_dnd_marker_helpers/highlight */ "./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/highlight.js"); 19800 19801function _init_dnd(gantt, grid) { 19802 var DnD = gantt.$services.getService("dnd"); 19803 19804 if(!grid.$config.bind || !gantt.getDatastore(grid.$config.bind)){ 19805 return; 19806 } 19807 19808 function locate(e){ 19809 return domHelpers.locateAttribute(e, grid.$config.item_attribute); 19810 } 19811 19812 var dnd = new DnD(grid.$grid_data, {updates_per_second: 60}); 19813 if (gantt.defined(grid.$getConfig().dnd_sensitivity)) 19814 dnd.config.sensitivity = grid.$getConfig().dnd_sensitivity; 19815 19816 dnd.attachEvent("onBeforeDragStart", gantt.bind(function (obj, e) { 19817 var el = locate(e); 19818 if (!el) return false; 19819 if (gantt.hideQuickInfo) gantt._hideQuickInfo(); 19820 if (domHelpers.closest(e.target, ".gantt_grid_editor_placeholder")){ 19821 return false; 19822 } 19823 19824 var id = el.getAttribute(grid.$config.item_attribute); 19825 var datastore = grid.$config.rowStore; 19826 var task = datastore.getItem(id); 19827 19828 if (gantt.isReadonly(task)) 19829 return false; 19830 19831 dnd.config.initial_open_state = task.$open; 19832 if (!gantt.callEvent("onRowDragStart", [id, e.target || e.srcElement, e])) { 19833 return false; 19834 } 19835 19836 }, gantt)); 19837 19838 dnd.attachEvent("onAfterDragStart", gantt.bind(function (obj, e) { 19839 var el = locate(e); 19840 19841 dnd.config.marker.innerHTML = el.outerHTML; 19842 var element = dnd.config.marker.firstChild; 19843 if(element){ 19844 dnd.config.marker.style.opacity = 0.4; 19845 element.style.position = "static"; 19846 element.style.pointerEvents = "none"; 19847 } 19848 19849 dnd.config.id = el.getAttribute(grid.$config.item_attribute); 19850 19851 var store = grid.$config.rowStore; 19852 19853 var task = store.getItem(dnd.config.id); 19854 dnd.config.level = store.calculateItemLevel(task); 19855 dnd.config.drop_target = dropTarget.createDropTargetObject({ 19856 targetParent: store.getParent(task.id), 19857 targetIndex: store.getBranchIndex(task.id), 19858 targetId: task.id, 19859 nextSibling: true 19860 }); 19861 19862 task.$open = false; 19863 task.$transparent = true; 19864 this.refreshData(); 19865 }, gantt)); 19866 19867 function getTargetTaskId(e){ 19868 var y = domHelpers.getRelativeEventPosition(e, grid.$grid_data).y; 19869 var store = grid.$config.rowStore; 19870 19871 y = y || 0; 19872 19873 if(y < 0){ 19874 return store.$getRootId(); 19875 } 19876 19877 var index = Math.floor(y / grid.getItemHeight()); 19878 19879 if (index > store.countVisible() - 1) 19880 return store.$getRootId(); 19881 19882 return store.getIdByIndex(index); 19883 } 19884 19885 function getDropPosition(e){ 19886 var targetTaskId = getTargetTaskId(e); 19887 var relTargetPos = null; 19888 var store = grid.$config.rowStore; 19889 var config = grid.$getConfig(); 19890 var lockLevel = !config.order_branch_free; 19891 19892 var eventTop = domHelpers.getRelativeEventPosition(e, grid.$grid_data).y; 19893 19894 if(targetTaskId !== store.$getRootId()) { 19895 var rowTop = grid.getItemTop(targetTaskId); 19896 var rowHeight = grid.getItemHeight(); 19897 relTargetPos = (eventTop - rowTop) / rowHeight; 19898 } 19899 19900 var result; 19901 if(!lockLevel){ 19902 result = getMultiLevelTarget(dnd.config.id, targetTaskId, relTargetPos, eventTop, store); 19903 }else{ 19904 result = getLockedLevelTarget(dnd.config.id, targetTaskId, relTargetPos, eventTop, store, dnd.config.level); 19905 } 19906 19907 return result; 19908 } 19909 19910 dnd.attachEvent("onDragMove", gantt.bind(function (obj, e) { 19911 var target = getDropPosition(e); 19912 19913 if(!target || 19914 gantt.callEvent("onBeforeRowDragMove", [dnd.config.id, target.targetParent, target.targetIndex]) === false){ 19915 target = dropTarget.createDropTargetObject(dnd.config.drop_target); 19916 } 19917 19918 higlighter.highlightPosition(target, dnd.config, grid); 19919 dnd.config.drop_target = target; 19920 19921 this.callEvent("onRowDragMove", [dnd.config.id, target.targetParent, target.targetIndex]); 19922 return true; 19923 }, gantt)); 19924 19925 dnd.attachEvent("onDragEnd", gantt.bind(function () { 19926 var store = grid.$config.rowStore; 19927 var task = store.getItem(dnd.config.id); 19928 19929 higlighter.removeLineHighlight(dnd.config); 19930 19931 task.$transparent = false; 19932 task.$open = dnd.config.initial_open_state; 19933 var target = dnd.config.drop_target; 19934 19935 if (this.callEvent("onBeforeRowDragEnd", [dnd.config.id, target.targetParent, target.targetIndex]) === false) { 19936 task.$drop_target = null; 19937 } else { 19938 store.move(dnd.config.id, target.targetIndex, target.targetParent); 19939 this.callEvent("onRowDragEnd", [dnd.config.id, target.targetParent, target.targetIndex]); 19940 } 19941 store.refresh(task.id); 19942 }, gantt)); 19943} 19944 19945module.exports = { 19946 init: _init_dnd 19947}; 19948 19949/***/ }), 19950 19951/***/ "./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/drop_target.js": 19952/*!***************************************************************************!*\ 19953 !*** ./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/drop_target.js ***! 19954 \***************************************************************************/ 19955/*! no static exports found */ 19956/***/ (function(module, exports, __webpack_require__) { 19957 19958/** 19959 * The state object for order branch drag and drop 19960 */ 19961 19962var utils = __webpack_require__(/*! ../../../../utils/utils */ "./sources/utils/utils.js"); 19963 19964module.exports = { 19965 createDropTargetObject: function createDropTargetObject(parent) { 19966 var res = { 19967 targetParent: null, 19968 targetIndex: 0, 19969 targetId: null, 19970 child: false, 19971 nextSibling: false, 19972 prevSibling: false 19973 }; 19974 19975 if (parent) { 19976 utils.mixin(res, parent, true); 19977 } 19978 return res; 19979 }, 19980 nextSiblingTarget: function nextSiblingTarget(dndTaskId, targetTaskId, store) { 19981 var result = this.createDropTargetObject(); 19982 result.targetId = targetTaskId; 19983 result.nextSibling = true; 19984 result.targetParent = store.getParent(result.targetId); 19985 result.targetIndex = store.getBranchIndex(result.targetId); 19986 if(store.getParent(dndTaskId) != result.targetParent || result.targetIndex < store.getBranchIndex(dndTaskId)){ 19987 result.targetIndex += 1; 19988 } 19989 return result; 19990 }, 19991 prevSiblingTarget: function prevSiblingTarget(dndTaskId, targetTaskId, store) { 19992 var result = this.createDropTargetObject(); 19993 result.targetId = targetTaskId; 19994 result.prevSibling = true; 19995 result.targetParent = store.getParent(result.targetId); 19996 result.targetIndex = store.getBranchIndex(result.targetId); 19997 if(store.getParent(dndTaskId) == result.targetParent && result.targetIndex > store.getBranchIndex(dndTaskId)){ 19998 result.targetIndex -= 1; 19999 } 20000 return result; 20001 }, 20002 firstChildTarget: function firstChildTarget(dndTaskId, targetTaskId, store) { 20003 var result = this.createDropTargetObject(); 20004 result.targetId = targetTaskId; 20005 result.targetParent = result.targetId; 20006 result.targetIndex = 0; 20007 result.child = true; 20008 return result; 20009 }, 20010 lastChildTarget: function lastChildTarget(dndTaskId, targetTaskId, store) { 20011 var children = store.getChildren(targetTaskId); 20012 var result = this.createDropTargetObject(); 20013 result.targetId = children[children.length - 1]; 20014 result.targetParent = targetTaskId; 20015 result.targetIndex = children.length; 20016 result.nextSibling = true; 20017 return result; 20018 } 20019}; 20020 20021/***/ }), 20022 20023/***/ "./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/highlight.js": 20024/*!*************************************************************************!*\ 20025 !*** ./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/highlight.js ***! 20026 \*************************************************************************/ 20027/*! no static exports found */ 20028/***/ (function(module, exports, __webpack_require__) { 20029 20030var domHelpers = __webpack_require__(/*! ../../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 20031 20032/** 20033 * methods for highlighting current drag and drop position 20034 */ 20035 20036function highlightPosition(target, root, grid){ 20037 var markerPos = getTaskMarkerPosition(target, grid); 20038 // setting position of row 20039 root.marker.style.left = markerPos.x + 9 + "px"; 20040 root.marker.style.top = markerPos.y + "px"; 20041 var markerLine = root.markerLine; 20042 if(!markerLine){ 20043 markerLine = document.createElement("div"); 20044 markerLine.className = "gantt_drag_marker gantt_grid_dnd_marker"; 20045 markerLine.innerHTML = "<div class='gantt_grid_dnd_marker_line'></div>"; 20046 markerLine.style.pointerEvents = "none"; 20047 document.body.appendChild(markerLine); 20048 root.markerLine = markerLine; 20049 } 20050 if(target.child){ 20051 highlightFolder(target, markerLine, grid); 20052 }else{ 20053 highlightRow(target, markerLine, grid); 20054 } 20055} 20056 20057function removeLineHighlight(root){ 20058 if(root.markerLine && root.markerLine.parentNode){ 20059 root.markerLine.parentNode.removeChild(root.markerLine); 20060 } 20061 root.markerLine = null; 20062} 20063 20064function highlightRow(target, markerLine, grid){ 20065 var linePos = getLineMarkerPosition(target, grid); 20066 20067 markerLine.innerHTML = "<div class='gantt_grid_dnd_marker_line'></div>"; 20068 markerLine.style.left = linePos.x + "px"; 20069 markerLine.style.height = "4px"; 20070 20071 markerLine.style.top = (linePos.y - 2) + "px"; 20072 markerLine.style.width = linePos.width + "px"; 20073 20074 return markerLine; 20075} 20076function highlightFolder(target, markerFolder, grid){ 20077 var id = target.targetParent; 20078 var pos = gridToPageCoordinates({x: 0, y: grid.getItemTop(id)}, grid); 20079 20080 markerFolder.innerHTML = "<div class='gantt_grid_dnd_marker_folder'></div>"; 20081 markerFolder.style.width = grid.$grid_data.offsetWidth + "px"; 20082 markerFolder.style.top = pos.y + "px"; 20083 markerFolder.style.left = pos.x + "px"; 20084 markerFolder.style.height = grid.getItemHeight(id) + "px"; 20085 return markerFolder; 20086} 20087 20088function getLineMarkerPosition(target, grid){ 20089 var store = grid.$config.rowStore; 20090 var pos = {x:0, y:0}; 20091 var indentNode = grid.$grid_data.querySelector(".gantt_tree_indent"); 20092 var indent = 15; 20093 var level = 0; 20094 if(indentNode){ 20095 indent = indentNode.offsetWidth; 20096 } 20097 var iconWidth = 40; 20098 if(target.targetId !== store.$getRootId()){ 20099 var itemTop = grid.getItemTop(target.targetId); 20100 var itemHeight = grid.getItemHeight(target.targetId); 20101 level = store.exists(target.targetId) ? store.calculateItemLevel(store.getItem(target.targetId)) : 0; 20102 20103 if(target.prevSibling){ 20104 pos.y = itemTop; 20105 }else if(target.nextSibling){ 20106 var childCount = 0; 20107 store.eachItem(function(child){ 20108 if(store.getIndexById(child.id) !== -1) 20109 childCount++; 20110 }, target.targetId); 20111 20112 pos.y = itemTop + itemHeight + childCount*itemHeight; 20113 }else { 20114 pos.y = itemTop + itemHeight; 20115 level += 1; 20116 } 20117 } 20118 pos.x = iconWidth + level * indent; 20119 pos.width = Math.max(grid.$grid_data.offsetWidth - pos.x, 0); 20120 return gridToPageCoordinates(pos, grid); 20121} 20122 20123function gridToPageCoordinates(pos, grid){ 20124 var gridPos = domHelpers.getNodePosition(grid.$grid_data); 20125 pos.x += gridPos.x - grid.$grid.scrollLeft; 20126 pos.y += gridPos.y - grid.$grid_data.scrollTop; 20127 return pos; 20128} 20129 20130function getTaskMarkerPosition(e, grid) { 20131 var pos = domHelpers.getNodePosition(grid.$grid_data); 20132 var ePos = domHelpers.getRelativeEventPosition(e, grid.$grid_data); 20133 var store = grid.$config.rowStore; 20134 // row offset 20135 var x = pos.x; 20136 var y = ePos.y - 10; 20137 20138 var config = grid.$getConfig(); 20139 // prevent moving row out of grid_data container 20140 if (y < pos.y) y = pos.y; 20141 var gridHeight = store.countVisible() * config.row_height; 20142 if (y > pos.y + gridHeight - config.row_height) y = pos.y + gridHeight - config.row_height; 20143 20144 pos.x = x; 20145 pos.y = y; 20146 return pos; 20147} 20148 20149module.exports = { 20150 removeLineHighlight: removeLineHighlight, 20151 highlightPosition: highlightPosition 20152}; 20153 20154 20155/***/ }), 20156 20157/***/ "./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/locked_level.js": 20158/*!****************************************************************************!*\ 20159 !*** ./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/locked_level.js ***! 20160 \****************************************************************************/ 20161/*! no static exports found */ 20162/***/ (function(module, exports, __webpack_require__) { 20163 20164/** 20165 * resolve dnd position of the task when gantt.config.order_branch_free = false 20166 */ 20167 20168var dropTarget = __webpack_require__(/*! ./drop_target */ "./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/drop_target.js"); 20169 20170function getLast(store){ 20171 var current = store.getNext(); 20172 while(store.exists(current)){ 20173 20174 var next = store.getNext(current); 20175 if(!store.exists(next)){ 20176 return current; 20177 }else{ 20178 current = next; 20179 } 20180 } 20181 return null; 20182} 20183 20184function findClosesTarget(dndTaskId, taskId, allowedLevel, store, up){ 20185 var prev = taskId; 20186 while(store.exists(prev)){ 20187 var targetLevel = store.calculateItemLevel(store.getItem(prev)); 20188 if((targetLevel === allowedLevel || targetLevel === (allowedLevel - 1)) && store.getBranchIndex(prev) > -1){ 20189 break; 20190 }else { 20191 prev = up ? store.getPrev(prev) : store.getNext(prev); 20192 } 20193 } 20194 20195 if(store.exists(prev)){ 20196 if(store.calculateItemLevel(store.getItem(prev)) === allowedLevel){ 20197 return up ? dropTarget.nextSiblingTarget(dndTaskId, prev, store) : dropTarget.prevSiblingTarget(dndTaskId, prev, store); 20198 }else{ 20199 return dropTarget.firstChildTarget(dndTaskId, prev, store); 20200 } 20201 } 20202 return null; 20203} 20204 20205function findTargetAbove(dndTaskId, taskId, allowedLevel, store){ 20206 return findClosesTarget(dndTaskId, taskId, allowedLevel, store, true); 20207} 20208function findTargetBelow(dndTaskId, taskId, allowedLevel, store){ 20209 return findClosesTarget(dndTaskId, taskId, allowedLevel, store, false); 20210} 20211 20212module.exports = function getSameLevelDropPosition(dndTaskId, targetTaskId, relTargetPos, eventTop, store, level){ 20213 var result; 20214 if(targetTaskId !== store.$getRootId()) { 20215 if (relTargetPos < 0.5) { 20216 if (store.calculateItemLevel(store.getItem(targetTaskId)) === level) { 20217 if(store.getPrevSibling(targetTaskId)){ 20218 result = dropTarget.nextSiblingTarget(dndTaskId, store.getPrevSibling(targetTaskId), store); 20219 }else{ 20220 result = dropTarget.prevSiblingTarget(dndTaskId, targetTaskId, store); 20221 } 20222 } else { 20223 result = findTargetAbove(dndTaskId, targetTaskId, level, store); 20224 if (result) { 20225 result = findTargetBelow(dndTaskId, targetTaskId, level, store); 20226 } 20227 } 20228 } else { 20229 if (store.calculateItemLevel(store.getItem(targetTaskId)) === level) { 20230 result = dropTarget.nextSiblingTarget(dndTaskId, targetTaskId, store); 20231 } else { 20232 result = findTargetBelow(dndTaskId, targetTaskId, level, store); 20233 if (result) { 20234 result = findTargetAbove(dndTaskId, targetTaskId, level, store); 20235 } 20236 } 20237 } 20238 }else{ 20239 var rootId = store.$getRootId(); 20240 var rootLevel = store.getChildren(rootId); 20241 result = dropTarget.createDropTargetObject(); 20242 if(rootLevel.length && eventTop >= 0){ 20243 result = findTargetAbove(dndTaskId, getLast(store), level, store); 20244 }else{ 20245 result = findTargetBelow(dndTaskId, rootId, level, store); 20246 } 20247 } 20248 20249 return result; 20250}; 20251 20252 20253/***/ }), 20254 20255/***/ "./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/multi_level.js": 20256/*!***************************************************************************!*\ 20257 !*** ./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/multi_level.js ***! 20258 \***************************************************************************/ 20259/*! no static exports found */ 20260/***/ (function(module, exports, __webpack_require__) { 20261 20262/** 20263 * resolve dnd position of the task when gantt.config.order_branch_free = true 20264 */ 20265 20266var dropTarget = __webpack_require__(/*! ./drop_target */ "./sources/core/ui/grid/tasks_grid_dnd_marker_helpers/drop_target.js"); 20267 20268module.exports = function getMultiLevelDropPosition(dndTaskId, targetTaskId, relTargetPos, eventTop, store){ 20269 var result; 20270 20271 if(targetTaskId !== store.$getRootId()){ 20272 if(relTargetPos < 0.25){ 20273 result = dropTarget.prevSiblingTarget(dndTaskId, targetTaskId, store); 20274 }else if(relTargetPos > 0.60 && !(store.hasChild(targetTaskId) && store.getItem(targetTaskId).$open)){ 20275 result = dropTarget.nextSiblingTarget(dndTaskId, targetTaskId, store); 20276 }else { 20277 result = dropTarget.firstChildTarget(dndTaskId, targetTaskId, store); 20278 } 20279 }else{ 20280 var rootId = store.$getRootId(); 20281 if(store.hasChild(rootId) && eventTop >= 0){ 20282 result = dropTarget.lastChildTarget(dndTaskId, rootId, store); 20283 }else{ 20284 result = dropTarget.firstChildTarget(dndTaskId, rootId, store); 20285 } 20286 } 20287 20288 return result; 20289}; 20290 20291/***/ }), 20292 20293/***/ "./sources/core/ui/index.js": 20294/*!**********************************!*\ 20295 !*** ./sources/core/ui/index.js ***! 20296 \**********************************/ 20297/*! no static exports found */ 20298/***/ (function(module, exports, __webpack_require__) { 20299 20300var uiFactory = __webpack_require__(/*! ./ui_factory */ "./sources/core/ui/ui_factory.js"), 20301 mouseEvents = __webpack_require__(/*! ./mouse */ "./sources/core/ui/mouse.js"), 20302 createLayers = __webpack_require__(/*! ./gantt_layers */ "./sources/core/ui/gantt_layers.js"), 20303 Cell = __webpack_require__(/*! ./layout/cell */ "./sources/core/ui/layout/cell.js"), 20304 Layout = __webpack_require__(/*! ./layout/layout */ "./sources/core/ui/layout/layout.js"), 20305 ViewLayout = __webpack_require__(/*! ./layout/view_layout */ "./sources/core/ui/layout/view_layout.js"), 20306 ViewCell = __webpack_require__(/*! ./layout/view_cell */ "./sources/core/ui/layout/view_cell.js"), 20307 Resizer = __webpack_require__(/*! ./layout/resizer_cell */ "./sources/core/ui/layout/resizer_cell.gpl.js"), 20308 Scrollbar = __webpack_require__(/*! ./layout/scrollbar_cell */ "./sources/core/ui/layout/scrollbar_cell.js"), 20309 Timeline = __webpack_require__(/*! ./timeline/timeline */ "./sources/core/ui/timeline/timeline.js"), 20310 Grid = __webpack_require__(/*! ./grid/grid */ "./sources/core/ui/grid/grid.js"), 20311 ResourceGrid = __webpack_require__(/*! ./grid/resource_grid */ "./sources/core/ui/grid/grid.js"), 20312 ResourceTimeline = __webpack_require__(/*! ./timeline/resource_timeline */ "./sources/core/ui/timeline/timeline.js"), 20313 ResourceHistogram = __webpack_require__(/*! ./timeline/resource_histogram */ "./sources/core/ui/timeline/timeline.js"); 20314 20315 20316var gridEditorsFactory = __webpack_require__(/*! ./grid/editors/controller */ "./sources/core/ui/grid/editors/controller.js"); 20317 20318 20319var renderTaskBar = __webpack_require__(/*! ./render/task_bar_smart_render */ "./sources/core/ui/render/task_bar_smart_render.js"), 20320 renderSplitTaskBar = __webpack_require__(/*! ./render/task_split_render */ "./sources/core/ui/render/task_split_render.js"), 20321 renderTaskBg = __webpack_require__(/*! ./render/task_bg_render */ "./sources/core/ui/render/task_bg_render.js"), 20322 renderLink = __webpack_require__(/*! ./render/link_render */ "./sources/core/ui/render/link_render.js"), 20323 gridRenderer = __webpack_require__(/*! ./render/task_grid_line_render */ "./sources/core/ui/render/task_grid_line_render.js"); 20324 20325var mainGridInitializer = __webpack_require__(/*! ./grid/main_grid_initializer */ "./sources/core/ui/grid/main_grid_initializer.js"); 20326var mainTimelineInitializer = __webpack_require__(/*! ./timeline/main_timeline_initializer */ "./sources/core/ui/timeline/main_timeline_initializer.js"); 20327var mainLayoutInitializer = __webpack_require__(/*! ./main_layout_initializer */ "./sources/core/ui/main_layout_initializer.js"); 20328 20329function initUI(gantt){ 20330 function attachInitializer(view, initializer){ 20331 var ext = initializer(gantt); 20332 if(ext.onCreated) 20333 ext.onCreated(view); 20334 view.attachEvent("onReady", function(){ 20335 if(ext.onInitialized) 20336 ext.onInitialized(view); 20337 }); 20338 view.attachEvent("onDestroy", function(){ 20339 if(ext.onDestroyed) 20340 ext.onDestroyed(view); 20341 }); 20342 } 20343 20344 var factory = uiFactory.createFactory(gantt); 20345 factory.registerView("cell", Cell); 20346 factory.registerView("resizer", Resizer); 20347 factory.registerView("scrollbar", Scrollbar); 20348 factory.registerView("layout", Layout, function(view){ 20349 var id = view.$config ? view.$config.id : null; 20350 if(id === "main"){ 20351 attachInitializer(view, mainLayoutInitializer); 20352 } 20353 }); 20354 factory.registerView("viewcell", ViewCell); 20355 factory.registerView("multiview", ViewLayout); 20356 factory.registerView("timeline", Timeline, function(view){ 20357 var id = view.$config ? view.$config.id : null; 20358 if(id === "timeline" || view.$config.bind == "task"){ 20359 attachInitializer(view, mainTimelineInitializer); 20360 } 20361 }); 20362 factory.registerView("grid", Grid, function(view){ 20363 var id = view.$config ? view.$config.id : null; 20364 if(id === "grid" || view.$config.bind == "task"){ 20365 attachInitializer(view, mainGridInitializer); 20366 } 20367 }); 20368 20369 factory.registerView("resourceGrid", ResourceGrid); 20370 factory.registerView("resourceTimeline", ResourceTimeline); 20371 factory.registerView("resourceHistogram", ResourceHistogram); 20372 20373 var layersEngine = createLayers(gantt); 20374 20375 var inlineEditors = gridEditorsFactory(gantt); 20376 20377 gantt.ext.inlineEditors = inlineEditors; 20378 gantt.ext._inlineEditors = inlineEditors; 20379 inlineEditors.init(gantt); 20380 20381 return { 20382 factory:factory, 20383 mouseEvents: mouseEvents.init(gantt), 20384 layersApi: layersEngine.init(), 20385 render:{ 20386 gridLine: function(){ 20387 return gridRenderer(gantt); 20388 }, 20389 taskBg: function(){ 20390 return renderTaskBg(gantt); 20391 }, 20392 taskBar: function(){ 20393 return renderTaskBar(gantt); 20394 }, 20395 taskSplitBar: function(){ 20396 return renderSplitTaskBar(gantt); 20397 }, 20398 link: function(){ 20399 return renderLink(gantt); 20400 } 20401 }, 20402 layersService: { 20403 getDataRender: function(name){ 20404 return layersEngine.getDataRender(name, gantt); 20405 }, 20406 createDataRender: function(config){ 20407 return layersEngine.createDataRender(config, gantt); 20408 } 20409 } 20410 }; 20411} 20412 20413module.exports = { 20414 init: initUI 20415}; 20416 20417/***/ }), 20418 20419/***/ "./sources/core/ui/layout/cell.js": 20420/*!****************************************!*\ 20421 !*** ./sources/core/ui/layout/cell.js ***! 20422 \****************************************/ 20423/*! no static exports found */ 20424/***/ (function(module, exports, __webpack_require__) { 20425 20426var utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"), 20427 eventable = __webpack_require__(/*! ../../../utils/eventable */ "./sources/utils/eventable.js"), 20428 domHelpers = __webpack_require__(/*! ../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 20429 20430var Cell = (function () { 20431 "use strict"; 20432 20433 function Cell(parent, config, factory, gantt) { 20434 if (parent) { 20435 this.$container = domHelpers.toNode(parent); 20436 this.$parent = parent; 20437 } 20438 // save config 20439 this.$config = utils.mixin(config, { 20440 headerHeight: 33 20441 }); 20442 this.$gantt = gantt; 20443 this.$domEvents = gantt._createDomEventScope(); 20444 // set id 20445 this.$id = config.id || "c" + utils.uid(); 20446 20447 this.$name = "cell"; 20448 this.$factory = factory; 20449 20450 eventable(this); 20451 20452 } 20453 20454 Cell.prototype.destructor = function () { 20455 this.$parent = this.$container = this.$view = null; 20456 var mouse = this.$gantt.$services.getService("mouseEvents"); 20457 mouse.detach("click", "gantt_header_arrow", this._headerClickHandler); 20458 this.$domEvents.detachAll(); 20459 this.callEvent("onDestroy", []); 20460 this.detachAllEvents(); 20461 }; 20462 Cell.prototype.cell = function (id) { 20463 return null; 20464 }; 20465 20466 Cell.prototype.scrollTo = function(left, top){ 20467 20468 if (left*1 == left){ 20469 this.$view.scrollLeft = left; 20470 } 20471 if(top*1 == top){ 20472 this.$view.scrollTop = top; 20473 } 20474 }; 20475 20476 Cell.prototype.clear = function(){ 20477 this.getNode().innerHTML = ""; 20478 this.getNode().className = "gantt_layout_content"; 20479 this.getNode().style.padding = "0"; 20480 }; 20481 20482 Cell.prototype.resize = function (final) { 20483 if (this.$parent) { 20484 return this.$parent.resize(final); 20485 } 20486 20487 if(final === false){ 20488 this.$preResize = true; 20489 } 20490 20491 var topCont = this.$container; 20492 var x = topCont.offsetWidth; 20493 var y = topCont.offsetHeight; 20494 var topSize = this.getSize(); 20495 if (topCont === document.body) { 20496 x = document.body.offsetWidth; 20497 y = document.body.offsetHeight; 20498 } 20499 if (x < topSize.minWidth) { 20500 x = topSize.minWidth; 20501 } 20502 if (x > topSize.maxWidth) { 20503 x = topSize.maxWidth; 20504 } 20505 if (y < topSize.minHeight) { 20506 y = topSize.minHeight; 20507 } 20508 if (y > topSize.maxHeight) { 20509 y = topSize.maxHeight; 20510 } 20511 this.setSize(x, y); 20512 20513 if(!this.$preResize){ 20514 // self.callEvent("onResize", [x, y]); 20515 } 20516 this.$preResize = false; 20517 }; 20518 20519 Cell.prototype.hide = function () { 20520 this._hide(true); 20521 this.resize(); 20522 }; 20523 Cell.prototype.show = function (force) { 20524 this._hide(false); 20525 if (force && this.$parent) { 20526 this.$parent.show(); 20527 } 20528 this.resize(); 20529 }; 20530 Cell.prototype._hide = function (mode) { 20531 if (mode === true && this.$view.parentNode) { 20532 this.$view.parentNode.removeChild(this.$view); 20533 } 20534 else if (mode === false && !this.$view.parentNode) { 20535 var index = this.$parent.cellIndex(this.$id); 20536 this.$parent.moveView(this, index); 20537 } 20538 this.$config.hidden = mode; 20539 }; 20540 Cell.prototype.$toHTML = function (content, css) { 20541 if (content === void 0) { content = ""; } 20542 css = [(css || ""), (this.$config.css || "")].join(" "); 20543 var obj = this.$config; 20544 var header = ""; 20545 if (obj.raw) { 20546 content = typeof obj.raw === "string" ? obj.raw : ""; 20547 } 20548 else { 20549 if (!content) { 20550 content = "<div class='gantt_layout_content' "+(css ? " class='"+css+"' " : "")+" >" + (obj.html || "") + "</div>"; 20551 } 20552 if (obj.header) { 20553 var collapseIcon = obj.canCollapse ? "<div class='gantt_layout_header_arrow'></div>" : ""; 20554 header = "<div class='gantt_layout_header'>" + collapseIcon + "<div class='gantt_layout_header_content'>" + obj.header + "</div></div>"; 20555 } 20556 } 20557 return "<div class='gantt_layout_cell " + css + "' data-cell-id='" + this.$id + "'>" + header + content + "</div>"; 20558 }; 20559 Cell.prototype.$fill = function (node, parent) { 20560 this.$view = node; 20561 this.$parent = parent; 20562 this.init(); 20563 }; 20564 Cell.prototype.getNode = function () { 20565 return (this.$view.querySelector("gantt_layout_cell") || this.$view); 20566 }; 20567 Cell.prototype.init = function () { 20568 // [NOT-GOOD] code is executed for each component, while it still has only one handler, it is no good 20569 20570 var self = this; 20571 20572 this._headerClickHandler = function(e){ 20573 var cellId = domHelpers.locateAttribute(e, "data-cell-id"); 20574 if(cellId == self.$id){ 20575 self.toggle(); 20576 } 20577 }; 20578 20579 var mouse = this.$gantt.$services.getService("mouseEvents"); 20580 mouse.delegate("click", "gantt_header_arrow", this._headerClickHandler); 20581 20582 this.callEvent("onReady", []); 20583 }; 20584 Cell.prototype.toggle = function () { 20585 this.$config.collapsed = !this.$config.collapsed; 20586 this.resize(); 20587 }; 20588 Cell.prototype.getSize = function () { 20589 var size = { 20590 height: this.$config.height || 0, 20591 width: this.$config.width || 0, 20592 gravity: this.$config.gravity || 1, 20593 minHeight: this.$config.minHeight || 0, 20594 minWidth: this.$config.minWidth || 0, 20595 maxHeight: this.$config.maxHeight || 100000, 20596 maxWidth: this.$config.maxWidth || 100000 20597 }; 20598 if (this.$config.collapsed) { 20599 var mode = this.$config.mode === "x"; 20600 size[mode ? "width" : "height"] = size[mode ? "maxWidth" : "maxHeight"] = this.$config.headerHeight; 20601 } 20602 return size; 20603 }; 20604 20605 Cell.prototype.getContentSize = function(){ 20606 20607 var width = this.$lastSize.contentX; 20608 if(width !== width*1){ 20609 width = this.$lastSize.width; 20610 } 20611 20612 var height = this.$lastSize.contentY; 20613 if(height !== height*1){ 20614 height = this.$lastSize.height; 20615 } 20616 20617 return { 20618 width: width, 20619 height: height 20620 }; 20621 }; 20622 20623 Cell.prototype._getBorderSizes = function(){ 20624 var borders = { 20625 top: 0, 20626 right: 0, 20627 bottom: 0, 20628 left: 0, 20629 horizontal: 0, 20630 vertical: 0 20631 }; 20632 if(this._currentBorders){ 20633 if(this._currentBorders[this._borders.left]){ 20634 borders.left = 1; 20635 borders.horizontal++; 20636 } 20637 20638 if(this._currentBorders[this._borders.right]){ 20639 borders.right = 1; 20640 borders.horizontal++; 20641 } 20642 20643 if(this._currentBorders[this._borders.top]){ 20644 borders.top = 1; 20645 borders.vertical++; 20646 } 20647 20648 if(this._currentBorders[this._borders.bottom]){ 20649 borders.bottom = 1; 20650 borders.vertical++; 20651 } 20652 } 20653 20654 return borders; 20655 20656 }; 20657 20658 Cell.prototype.setSize = function (x, y) { 20659 this.$view.style.width = x + "px"; 20660 this.$view.style.height = y + "px"; 20661 20662 var borders = this._getBorderSizes(); 20663 var contentY = y - borders.vertical; 20664 var contentX = x - borders.horizontal; 20665 20666 this.$lastSize = { x: x, y: y, contentX: contentX, contentY: contentY }; 20667 if (this.$config.header) { 20668 this._sizeHeader(); 20669 }else{ 20670 this._sizeContent(); 20671 } 20672 }; 20673 20674 Cell.prototype._borders = { 20675 "left":"gantt_layout_cell_border_left", 20676 "right":"gantt_layout_cell_border_right", 20677 "top":"gantt_layout_cell_border_top", 20678 "bottom":"gantt_layout_cell_border_bottom" 20679 }; 20680 20681 Cell.prototype._setBorders = function(css, view){ 20682 if(!view) { 20683 view = this; 20684 } 20685 var node = view.$view; 20686 20687 for( var i in this._borders){ 20688 domHelpers.removeClassName(node, this._borders[i]); 20689 } 20690 20691 if(typeof css == "string"){ 20692 css = [css]; 20693 } 20694 20695 var cssHash = {}; 20696 20697 for(var i = 0; i < css.length; i++){ 20698 domHelpers.addClassName(node, css[i]); 20699 cssHash[css[i]] = true; 20700 } 20701 20702 view._currentBorders = cssHash; 20703 }; 20704 20705 20706 Cell.prototype._sizeContent = function(){ 20707 var content = this.$view.childNodes[0]; 20708 if(content && content.className == "gantt_layout_content"){ 20709 content.style.height = this.$lastSize.contentY + "px"; 20710 } 20711 }; 20712 20713 Cell.prototype._sizeHeader = function () { 20714 var size = this.$lastSize; 20715 size.contentY -= this.$config.headerHeight; 20716 var header = this.$view.childNodes[0]; 20717 var content = this.$view.childNodes[1]; 20718 var xLayout = this.$config.mode === "x"; 20719 if (this.$config.collapsed) { 20720 content.style.display = "none"; 20721 if (xLayout) { 20722 header.className = "gantt_layout_header collapsed_x"; 20723 header.style.width = size.y + "px"; 20724 var d = Math.floor(size.y / 2 - size.x / 2); 20725 header.style.transform = "rotate(90deg) translate(" + d + "px, " + d + "px)"; 20726 content.style.display = "none"; 20727 } 20728 else { 20729 header.className = "gantt_layout_header collapsed_y"; 20730 } 20731 } 20732 else { 20733 if (xLayout) { 20734 header.className = "gantt_layout_header"; 20735 } 20736 else { 20737 header.className = "gantt_layout_header vertical"; 20738 } 20739 header.style.width = 'auto'; 20740 header.style.transform = ''; 20741 content.style.display = ""; 20742 content.style.height = size.contentY + "px"; 20743 } 20744 header.style.height = this.$config.headerHeight + "px"; 20745 }; 20746 return Cell; 20747}()); 20748 20749module.exports = Cell; 20750 20751 20752/***/ }), 20753 20754/***/ "./sources/core/ui/layout/layout.js": 20755/*!******************************************!*\ 20756 !*** ./sources/core/ui/layout/layout.js ***! 20757 \******************************************/ 20758/*! no static exports found */ 20759/***/ (function(module, exports, __webpack_require__) { 20760 20761var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"), 20762 domHelpers = __webpack_require__(/*! ../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"), 20763 Cell = __webpack_require__(/*! ./cell */ "./sources/core/ui/layout/cell.js"); 20764 20765var Layout = (function (_super) { 20766 "use strict"; 20767 20768 __extends(Layout, _super); 20769 function Layout(parent, config, factory) { 20770 var _this = _super.apply(this, arguments) || this; 20771 20772 if(parent) 20773 _this.$root = true; 20774 20775 _this._parseConfig(config); 20776 _this.$name = "layout"; 20777 return _this; 20778 } 20779 20780 Layout.prototype.destructor = function () { 20781 if (this.$container && this.$view) { 20782 domHelpers.removeNode(this.$view); 20783 } 20784 20785 for (var i = 0; i < this.$cells.length; i++) { 20786 var child = this.$cells[i]; 20787 child.destructor(); 20788 } 20789 this.$cells = []; 20790 20791 _super.prototype.destructor.call(this); 20792 }; 20793 20794 Layout.prototype._resizeScrollbars = function(autosize, scrollbars){ 20795 var scrollChanged = false; 20796 var visibleScrollbars = [], 20797 hiddenSrollbars = []; 20798 20799 function showScrollbar(scrollbar){ 20800 scrollbar.$parent.show(); 20801 scrollChanged = true; 20802 visibleScrollbars.push(scrollbar); 20803 } 20804 function hideScrollbar(scrollbar){ 20805 scrollbar.$parent.hide(); 20806 scrollChanged = true; 20807 hiddenSrollbars.push(scrollbar); 20808 } 20809 20810 var scrollbar; 20811 for(var i = 0; i < scrollbars.length; i++){ 20812 scrollbar = scrollbars[i]; 20813 20814 if(autosize[scrollbar.$config.scroll]) { 20815 hideScrollbar(scrollbar); 20816 }else if(scrollbar.shouldHide()){ 20817 hideScrollbar(scrollbar); 20818 }else if(scrollbar.shouldShow()){ 20819 showScrollbar(scrollbar); 20820 }else{ 20821 if(scrollbar.isVisible()){ 20822 visibleScrollbars.push(scrollbar); 20823 }else{ 20824 hiddenSrollbars.push(scrollbar); 20825 } 20826 } 20827 } 20828 20829 var visibleGroups = {}; 20830 for(var i = 0; i < visibleScrollbars.length; i++){ 20831 if(visibleScrollbars[i].$config.group){ 20832 visibleGroups[visibleScrollbars[i].$config.group] = true; 20833 } 20834 } 20835 20836 for(var i = 0; i < hiddenSrollbars.length; i++){ 20837 scrollbar = hiddenSrollbars[i]; 20838 20839 if(scrollbar.$config.group && visibleGroups[scrollbar.$config.group]){ 20840 showScrollbar(scrollbar); 20841 } 20842 } 20843 20844 return scrollChanged; 20845 }; 20846 20847 Layout.prototype._syncCellSizes = function(groupName, newSize){ 20848 if(!groupName) 20849 return; 20850 20851 var groups = {}; 20852 20853 this._eachChild(function(cell){ 20854 if(cell.$config.group && cell.$name != "scrollbar" && cell.$name != "resizer"){ 20855 if(!groups[cell.$config.group]){ 20856 groups[cell.$config.group] = []; 20857 } 20858 groups[cell.$config.group].push(cell); 20859 } 20860 }); 20861 20862 if(groups[groupName]){ 20863 this._syncGroupSize(groups[groupName], newSize); 20864 } 20865 return groups[groupName]; 20866 }; 20867 20868 Layout.prototype._syncGroupSize = function(cells, newSize){ 20869 if(!cells.length) return; 20870 20871 var property = cells[0].$parent._xLayout ? "width" : "height"; 20872 var direction = cells[0].$parent.getNextSibling(cells[0].$id) ? 1 : -1; 20873 20874 for(var i = 0; i < cells.length; i++){ 20875 var ownSize = cells[i].getSize(); 20876 20877 var resizeSibling = direction > 0 ? cells[i].$parent.getNextSibling(cells[i].$id) : cells[i].$parent.getPrevSibling(cells[i].$id); 20878 if(resizeSibling.$name == "resizer"){ 20879 resizeSibling = direction > 0 ? resizeSibling.$parent.getNextSibling(resizeSibling.$id) : resizeSibling.$parent.getPrevSibling(resizeSibling.$id); 20880 } 20881 var siblingSize = resizeSibling.getSize(); 20882 20883 if(resizeSibling[property]){ 20884 var totalGravity = ownSize.gravity + siblingSize.gravity; 20885 var totalSize = ownSize[property] + siblingSize[property]; 20886 var k = totalGravity / totalSize; 20887 cells[i].$config.gravity = k * newSize; 20888 20889 resizeSibling.$config[property] = totalSize - newSize; 20890 resizeSibling.$config.gravity = totalGravity - k * newSize; 20891 }else{ 20892 20893 20894 cells[i].$config[property] = newSize; 20895 } 20896 20897 var mainGrid = this.$gantt.$ui.getView("grid"); 20898 if(mainGrid && cells[i].$content === mainGrid && !mainGrid.$config.scrollable){ 20899 this.$gantt.config.grid_width = newSize; 20900 } 20901 } 20902 }; 20903 20904 Layout.prototype.resize = function(startStage){ 20905 var mainCall = false; 20906 if(this.$root && !this._resizeInProgress){ 20907 this.callEvent("onBeforeResize", []); 20908 mainCall = true; 20909 this._resizeInProgress = true; 20910 } 20911 20912 _super.prototype.resize.call(this, true); 20913 _super.prototype.resize.call(this, false); 20914 20915 if(mainCall){ 20916 20917 var contentViews = []; 20918 contentViews = contentViews.concat(this.getCellsByType("viewCell")); 20919 contentViews = contentViews.concat(this.getCellsByType("viewLayout")); 20920 contentViews = contentViews.concat(this.getCellsByType("hostCell")); 20921 20922 var scrollbars = this.getCellsByType("scroller"); 20923 20924 for(var i = 0; i < contentViews.length; i++){ 20925 if(!contentViews[i].$config.hidden) 20926 contentViews[i].setContentSize(); 20927 } 20928 20929 var autosize = this._getAutosizeMode(this.$config.autosize); 20930 20931 var scrollChanged = this._resizeScrollbars(autosize, scrollbars); 20932 20933 if(this.$config.autosize){ 20934 this.autosize(this.$config.autosize); 20935 scrollChanged = true; 20936 } 20937 20938 if(scrollChanged){ 20939 this.resize(); 20940 for(var i = 0; i < contentViews.length; i++){ 20941 if(!contentViews[i].$config.hidden) 20942 contentViews[i].setContentSize(); 20943 } 20944 } 20945 20946 this.callEvent("onResize", []); 20947 } 20948 if(mainCall){ 20949 this._resizeInProgress = false; 20950 } 20951 }; 20952 20953 Layout.prototype._eachChild = function(code, cell){ 20954 cell = cell || this; 20955 code(cell); 20956 if(cell.$cells){ 20957 for(var i = 0; i < cell.$cells.length; i++){ 20958 this._eachChild(code, cell.$cells[i]); 20959 } 20960 } 20961 }; 20962 20963 Layout.prototype.isChild = function(view){ 20964 var res = false; 20965 this._eachChild(function(child){ 20966 if(child === view || child.$content === view){ 20967 res = true; 20968 } 20969 }); 20970 return res; 20971 }; 20972 20973 Layout.prototype.getCellsByType = function(type){ 20974 var res = []; 20975 if(type === this.$name){ 20976 res.push(this); 20977 } 20978 20979 if(this.$content && this.$content.$name == type){ 20980 res.push(this.$content); 20981 } 20982 20983 if(this.$cells){ 20984 for(var i = 0; i < this.$cells.length; i++){ 20985 var children = Layout.prototype.getCellsByType.call(this.$cells[i], type); 20986 if(children.length){ 20987 res.push.apply(res, children); 20988 } 20989 } 20990 } 20991 return res; 20992 }; 20993 20994 Layout.prototype.getNextSibling = function(cellId){ 20995 var index = this.cellIndex(cellId); 20996 if(index >= 0 && this.$cells[index + 1]){ 20997 return this.$cells[index + 1]; 20998 }else{ 20999 return null; 21000 } 21001 }; 21002 21003 Layout.prototype.getPrevSibling = function(cellId){ 21004 var index = this.cellIndex(cellId); 21005 if(index >= 0 && this.$cells[index - 1]){ 21006 return this.$cells[index - 1]; 21007 }else{ 21008 return null; 21009 } 21010 }; 21011 21012 21013 Layout.prototype.cell = function (id) { 21014 for (var i = 0; i < this.$cells.length; i++) { 21015 var child = this.$cells[i]; 21016 if (child.$id === id) { 21017 return child; 21018 } 21019 var sub = child.cell(id); 21020 if (sub) { 21021 return sub; 21022 } 21023 } 21024 }; 21025 Layout.prototype.cellIndex = function (id) { 21026 for (var i = 0; i < this.$cells.length; i++) { 21027 if (this.$cells[i].$id === id) { 21028 return i; 21029 } 21030 } 21031 return -1; 21032 }; 21033 Layout.prototype.moveView = function (view, ind) { 21034 if (this.$cells[ind] !== view) { 21035 return window.alert("Not implemented"); 21036 } 21037 else { 21038 ind += this.$config.header ? 1 : 0; 21039 var node = this.$view; 21040 if (ind >= node.childNodes.length) { 21041 node.appendChild(view.$view); 21042 } 21043 else { 21044 node.insertBefore(view.$view, node.childNodes[ind]); 21045 } 21046 } 21047 }; 21048 Layout.prototype._parseConfig = function (config) { 21049 this.$cells = []; 21050 this._xLayout = !config.rows; 21051 var cells = config.rows || config.cols || config.views; 21052 for (var i = 0; i < cells.length; i++) { 21053 var cell = cells[i]; 21054 cell.mode = this._xLayout ? "x" : "y"; 21055 var $content = this.$factory.initUI(cell, this); 21056 if(!$content){ 21057 cells.splice(i, 1); 21058 i--; 21059 }else{ 21060 $content.$parent = this; 21061 this.$cells.push($content); 21062 } 21063 } 21064 }; 21065 Layout.prototype.getCells = function () { 21066 return this.$cells; 21067 }; 21068 Layout.prototype.render = function () { 21069 var view = domHelpers.insertNode(this.$container, this.$toHTML()); 21070 this.$fill(view, null); 21071 this.callEvent("onReady", []); 21072 this.resize(); 21073 21074 // do simple repaint after the first call 21075 this.render = this.resize; 21076 }; 21077 Layout.prototype.$fill = function (node, parent) { 21078 this.$view = node; 21079 this.$parent = parent; 21080 var cells = domHelpers.getChildNodes(node, "gantt_layout_cell"); 21081 for (var i = cells.length - 1; i >= 0; i--) { 21082 var sub = this.$cells[i]; 21083 sub.$fill(cells[i], this); 21084 // initially hidden cell 21085 if (sub.$config.hidden) { 21086 sub.$view.parentNode.removeChild(sub.$view); 21087 } 21088 } 21089 }; 21090 Layout.prototype.$toHTML = function () { 21091 var mode = this._xLayout ? "x" : "y"; 21092 var html = []; 21093 for (var i = 0; i < this.$cells.length; i++) { 21094 html.push(this.$cells[i].$toHTML()); 21095 } 21096 return _super.prototype.$toHTML.call(this, html.join(""), (this.$root ? "gantt_layout_root " : "") + "gantt_layout gantt_layout_" + mode); 21097 }; 21098 21099 Layout.prototype.getContentSize = function(mode){ 21100 var contentWidth = 0, 21101 contentHeight = 0; 21102 21103 var cellSize, cell, borders; 21104 for (var i = 0; i < this.$cells.length; i++) { 21105 cell = this.$cells[i]; 21106 if(cell.$config.hidden) 21107 continue; 21108 21109 cellSize = cell.getContentSize(mode); 21110 21111 if(cell.$config.view === "scrollbar" && mode[cell.$config.scroll]){ 21112 cellSize.height = 0; 21113 cellSize.width = 0; 21114 } 21115 21116 if(cell.$config.resizer){ 21117 if(this._xLayout){ 21118 cellSize.height = 0; 21119 }else{ 21120 cellSize.width = 0; 21121 } 21122 } 21123 21124 borders = cell._getBorderSizes(); 21125 21126 if(this._xLayout){ 21127 contentWidth += (cellSize.width + borders.horizontal); 21128 contentHeight = Math.max(contentHeight, (cellSize.height + borders.vertical)); 21129 }else{ 21130 contentWidth = Math.max(contentWidth, cellSize.width + borders.horizontal); 21131 contentHeight += cellSize.height + borders.vertical; 21132 } 21133 } 21134 21135 borders = this._getBorderSizes(); 21136 contentWidth += borders.horizontal; 21137 contentHeight += borders.vertical; 21138 21139 if(this.$root){ 21140 contentWidth += 1; 21141 contentHeight += 1; 21142 } 21143 21144 return { 21145 width: contentWidth, 21146 height: contentHeight 21147 }; 21148 }; 21149 21150 Layout.prototype._cleanElSize = function(value){ 21151 return ((value || "").toString().replace("px", "") * 1 || 0); 21152 }; 21153 Layout.prototype._getBoxStyles = function(div){ 21154 var computed = null; 21155 if(window.getComputedStyle){ 21156 computed = window.getComputedStyle(div, null); 21157 }else{ 21158 //IE with elem.currentStyle does not calculate sizes from %, so will use the default approach 21159 computed = { 21160 "width":div.clientWidth, 21161 "height":div.clientHeight 21162 }; 21163 } 21164 var properties = [ 21165 "width", 21166 "height", 21167 21168 "paddingTop", 21169 "paddingBottom", 21170 "paddingLeft", 21171 "paddingRight", 21172 21173 "borderLeftWidth", 21174 "borderRightWidth", 21175 "borderTopWidth", 21176 "borderBottomWidth" 21177 ]; 21178 var styles = { 21179 boxSizing:(computed.boxSizing == "border-box") 21180 }; 21181 21182 if(computed.MozBoxSizing){ 21183 styles.boxSizing = (computed.MozBoxSizing == "border-box"); 21184 } 21185 for(var i =0; i < properties.length; i++){ 21186 styles[properties[i]] = computed[properties[i]] ? this._cleanElSize(computed[properties[i]]) : 0; 21187 } 21188 21189 21190 var box = { 21191 horPaddings : (styles.paddingLeft + styles.paddingRight + styles.borderLeftWidth + styles.borderRightWidth), 21192 vertPaddings : (styles.paddingTop + styles.paddingBottom + styles.borderTopWidth + styles.borderBottomWidth), 21193 borderBox: styles.boxSizing, 21194 innerWidth : styles.width, 21195 innerHeight : styles.height, 21196 outerWidth : styles.width, 21197 outerHeight : styles.height 21198 }; 21199 21200 21201 if(box.borderBox){ 21202 box.innerWidth -= box.horPaddings; 21203 box.innerHeight -= box.vertPaddings; 21204 }else{ 21205 box.outerWidth += box.horPaddings; 21206 box.outerHeight += box.vertPaddings; 21207 } 21208 21209 return box; 21210 }; 21211 21212 Layout.prototype._getAutosizeMode = function(config){ 21213 var res = {x:false, y:false}; 21214 if(config === "xy"){ 21215 res.x = res.y = true; 21216 }else if(config === "y" || config === true){ 21217 res.y = true; 21218 }else if(config === "x"){ 21219 res.x = true; 21220 } 21221 return res; 21222 }; 21223 21224 Layout.prototype.autosize = function(mode) { 21225 var res = this._getAutosizeMode(mode); 21226 var boxSizes = this._getBoxStyles(this.$container); 21227 var contentSizes = this.getContentSize(mode); 21228 21229 var node = this.$container; 21230 if(res.x){ 21231 if(boxSizes.borderBox){ 21232 contentSizes.width += boxSizes.horPaddings; 21233 } 21234 node.style.width = contentSizes.width + "px"; 21235 } 21236 if(res.y){ 21237 if(boxSizes.borderBox){ 21238 contentSizes.height += boxSizes.vertPaddings; 21239 } 21240 node.style.height = contentSizes.height + "px"; 21241 } 21242 }; 21243 21244 Layout.prototype.getSize = function () { 21245 this._sizes = []; 21246 var width = 0; 21247 var minWidth = 0; 21248 var maxWidth = 100000; 21249 var height = 0; 21250 var maxHeight = 100000; 21251 var minHeight = 0; 21252 21253 for (var i = 0; i < this.$cells.length; i++) { 21254 21255 var size = this._sizes[i] = this.$cells[i].getSize(); 21256 if (this.$cells[i].$config.hidden) { 21257 continue; 21258 } 21259 if (this._xLayout) { 21260 if (!size.width && size.minWidth) { 21261 width += size.minWidth; 21262 } 21263 else { 21264 width += size.width; 21265 } 21266 maxWidth += size.maxWidth; 21267 minWidth += size.minWidth; 21268 height = Math.max(height, size.height); 21269 maxHeight = Math.min(maxHeight, size.maxHeight); // min of maxHeight 21270 minHeight = Math.max(minHeight, size.minHeight); // max of minHeight 21271 } 21272 else { 21273 if (!size.height && size.minHeight) { 21274 height += size.minHeight; 21275 } 21276 else { 21277 height += size.height; 21278 } 21279 maxHeight += size.maxHeight; 21280 minHeight += size.minHeight; 21281 width = Math.max(width, size.width); 21282 maxWidth = Math.min(maxWidth, size.maxWidth); // min of maxWidth 21283 minWidth = Math.max(minWidth, size.minWidth); // max of minWidth 21284 } 21285 } 21286 var self = _super.prototype.getSize.call(this); 21287 // maxWidth 21288 if (self.maxWidth >= 100000) { 21289 self.maxWidth = maxWidth; 21290 } 21291 // maxHeight 21292 if (self.maxHeight >= 100000) { 21293 self.maxHeight = maxHeight; 21294 } 21295 // minWidth 21296 self.minWidth = self.minWidth !== self.minWidth ? 0 : self.minWidth;// || self.width || Math.max(minWidth, width); 21297 // minHeight 21298 self.minHeight = self.minHeight !== self.minHeight ? 0 : self.minHeight;//self.minHeight || self.height || Math.max(minHeight, height); 21299 // sizes with paddings and margins 21300 if (this._xLayout) { 21301 self.minWidth += this.$config.margin * (this.$cells.length) || 0; 21302 self.minWidth += this.$config.padding * 2 || 0; 21303 self.minHeight += (this.$config.padding * 2) || 0; 21304 } 21305 else { 21306 self.minHeight += this.$config.margin * (this.$cells.length) || 0; 21307 self.minHeight += (this.$config.padding * 2) || 0; 21308 } 21309 21310 return self; 21311 }; 21312 // calc total gravity and free space 21313 Layout.prototype._calcFreeSpace = function (s, cell, xLayout) { 21314 var min = xLayout ? cell.minWidth : cell.minHeight; 21315 var max = xLayout ? cell.maxWidth : cell.maxWidth; 21316 var side = s; 21317 if (!side) { 21318 side = Math.floor(this._free / this._gravity * cell.gravity); 21319 if (side > max) { 21320 side = max; 21321 this._free -= side; 21322 this._gravity -= cell.gravity; 21323 } 21324 if (side < min) { 21325 side = min; 21326 this._free -= side; 21327 this._gravity -= cell.gravity; 21328 } 21329 } 21330 else { 21331 if (side > max) { 21332 side = max; 21333 } 21334 if (side < min) { 21335 side = min; 21336 } 21337 this._free -= side; 21338 } 21339 return side; 21340 }; 21341 Layout.prototype._calcSize = function (s, size, xLayout) { 21342 var side = s; 21343 var min = xLayout ? size.minWidth : size.minHeight; 21344 var max = xLayout ? size.maxWidth : size.maxHeight; 21345 if (!side) { 21346 side = Math.floor(this._free / this._gravity * size.gravity); 21347 } 21348 if (side > max) { 21349 side = max; 21350 } 21351 if (side < min) { 21352 side = min; 21353 } 21354 return side; 21355 }; 21356 21357 Layout.prototype._configureBorders = function(){ 21358 if(this.$root){ 21359 this._setBorders([ 21360 this._borders.left, 21361 this._borders.top, 21362 this._borders.right, 21363 this._borders.bottom 21364 ], 21365 this); 21366 } 21367 21368 var borderClass = this._xLayout ? this._borders.right : this._borders.bottom; 21369 21370 var cells = this.$cells; 21371 21372 var lastVisibleIndex = cells.length - 1; 21373 for(var i = lastVisibleIndex; i >= 0; i--){ 21374 if (!cells[i].$config.hidden) { 21375 lastVisibleIndex = i; 21376 break; 21377 } 21378 } 21379 21380 for (var i = 0; i < cells.length; i++) { 21381 if (cells[i].$config.hidden) { 21382 continue; 21383 } 21384 21385 var lastCell = i >= lastVisibleIndex; 21386 var borderColorClass = ""; 21387 if(!lastCell && cells[i + 1]){ 21388 if(cells[i + 1].$config.view == "scrollbar"){ 21389 if(this._xLayout){ 21390 lastCell = true; 21391 }else{ 21392 borderColorClass = "gantt_layout_cell_border_transparent"; 21393 } 21394 21395 } 21396 } 21397 21398 21399 this._setBorders(lastCell ? [] : [borderClass, borderColorClass], cells[i]); 21400 } 21401 }; 21402 21403 Layout.prototype._updateCellVisibility = function(){ 21404 var oldVisibleCells = this._visibleCells || {}; 21405 var firstCall = !this._visibleCells; 21406 var visibleCells = {}; 21407 var cell; 21408 for (var i = 0; i < this._sizes.length; i++) { 21409 cell = this.$cells[i]; 21410 21411 if (!firstCall && cell.$config.hidden && oldVisibleCells[cell.$id]) { 21412 cell._hide(true); 21413 }else if(!cell.$config.hidden && !oldVisibleCells[cell.$id]){ 21414 cell._hide(false); 21415 } 21416 21417 if(!cell.$config.hidden){ 21418 visibleCells[cell.$id] = true; 21419 } 21420 } 21421 this._visibleCells = visibleCells; 21422 }; 21423 21424 Layout.prototype.setSize = function (x, y) { 21425 this._configureBorders(); 21426 _super.prototype.setSize.call(this, x, y); 21427 y = this.$lastSize.contentY; 21428 x = this.$lastSize.contentX; 21429 21430 var padding = (this.$config.padding || 0); 21431 this.$view.style.padding = padding + "px"; 21432 this._gravity = 0; 21433 this._free = this._xLayout ? x : y; 21434 this._free -= padding * 2; 21435 // calc all gravity 21436 21437 var cell, 21438 size; 21439 21440 this._updateCellVisibility(); 21441 21442 for (var i = 0; i < this._sizes.length; i++) { 21443 cell = this.$cells[i]; 21444 21445 if (cell.$config.hidden) { 21446 continue; 21447 } 21448 var margin = (this.$config.margin || 0); 21449 if(cell.$name == "resizer" && !margin){ 21450 margin = -1; 21451 } 21452 21453 // set margins to child cell 21454 var cellView = cell.$view; 21455 21456 var marginSide = this._xLayout ? "marginRight" : "marginBottom"; 21457 if (i !== this.$cells.length - 1) { 21458 cellView.style[marginSide] = margin + "px"; 21459 this._free -= margin; // calc free space without margin 21460 } 21461 size = this._sizes[i]; 21462 if (this._xLayout) { 21463 if (!size.width) { 21464 this._gravity += size.gravity; 21465 } 21466 } 21467 else { 21468 if (!size.height) { 21469 this._gravity += size.gravity; 21470 } 21471 } 21472 } 21473 for (var i = 0; i < this._sizes.length; i++) { 21474 cell = this.$cells[i]; 21475 21476 if (cell.$config.hidden) { 21477 continue; 21478 } 21479 size = this._sizes[i]; 21480 var width = size.width; 21481 var height = size.height; 21482 if (this._xLayout) { 21483 this._calcFreeSpace(width, size, true); 21484 } 21485 else { 21486 this._calcFreeSpace(height, size, false); 21487 } 21488 } 21489 for (var i = 0; i < this.$cells.length; i++) { 21490 cell = this.$cells[i]; 21491 21492 if (cell.$config.hidden) { 21493 continue; 21494 } 21495 size = this._sizes[i]; 21496 var dx = void 0; 21497 var dy = void 0; 21498 if (this._xLayout) { 21499 dx = this._calcSize(size.width, size, true); 21500 dy = y - padding * 2; // layout height without paddings 21501 } 21502 else { 21503 dx = x - padding * 2; // layout width without paddings 21504 dy = this._calcSize(size.height, size, false); 21505 } 21506 21507 cell.setSize(dx, dy); 21508 } 21509 21510 }; 21511 21512 return Layout; 21513}(Cell)); 21514 21515module.exports = Layout; 21516 21517/***/ }), 21518 21519/***/ "./sources/core/ui/layout/resizer_cell.gpl.js": 21520/*!****************************************************!*\ 21521 !*** ./sources/core/ui/layout/resizer_cell.gpl.js ***! 21522 \****************************************************/ 21523/*! no static exports found */ 21524/***/ (function(module, exports) { 21525 21526module.exports = null; 21527 21528/***/ }), 21529 21530/***/ "./sources/core/ui/layout/scrollbar_cell.js": 21531/*!**************************************************!*\ 21532 !*** ./sources/core/ui/layout/scrollbar_cell.js ***! 21533 \**************************************************/ 21534/*! no static exports found */ 21535/***/ (function(module, exports, __webpack_require__) { 21536 21537var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"), 21538 domHelpers = __webpack_require__(/*! ../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"), 21539 utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"), 21540 env = __webpack_require__(/*! ../../../utils/env */ "./sources/utils/env.js"), 21541 Cell = __webpack_require__(/*! ./cell */ "./sources/core/ui/layout/cell.js"); 21542 21543var ScrollbarCell = (function (_super) { 21544 "use strict"; 21545 21546 var SCROLL_MODIFIER_KEYS = ["altKey", "shiftKey", "metaKey"]; // it's no way to disable ctrl+wheel 21547 __extends(ScrollbarCell, _super); 21548 function ScrollbarCell(parent, config, factory, gantt) { 21549 21550 var _this = _super.apply(this, arguments) || this; 21551 this.$config = utils.mixin(config, {scroll: "x"}); 21552 _this._scrollHorizontalHandler = utils.bind(_this._scrollHorizontalHandler, _this); 21553 _this._scrollVerticalHandler = utils.bind(_this._scrollVerticalHandler, _this); 21554 _this._outerScrollVerticalHandler = utils.bind(_this._outerScrollVerticalHandler, _this); 21555 _this._outerScrollHorizontalHandler = utils.bind(_this._outerScrollHorizontalHandler, _this); 21556 _this._mouseWheelHandler = utils.bind(_this._mouseWheelHandler, _this); 21557 21558 this.$config.hidden = true; 21559 var size = gantt.config.scroll_size; 21560 21561 if(gantt.env.isIE){ 21562 // full element height/width must be bigger than just a browser scrollbar, 21563 // otherwise the scrollbar element won't be scrolled on click 21564 size += 1; 21565 } 21566 21567 if(this._isHorizontal()){ 21568 _this.$config.height = size; 21569 _this.$parent.$config.height = size; 21570 }else{ 21571 _this.$config.width = size; 21572 _this.$parent.$config.width = size; 21573 } 21574 21575 this.$config.scrollPosition = 0; 21576 21577 _this.$name = "scroller"; 21578 return _this; 21579 } 21580 21581 ScrollbarCell.prototype.init = function(container){ 21582 container.innerHTML = this.$toHTML(); 21583 this.$view = container.firstChild; 21584 21585 if(!this.$view){ 21586 this.init(); 21587 } 21588 if(this._isVertical()){ 21589 this._initVertical(); 21590 }else{ 21591 this._initHorizontal(); 21592 } 21593 this._initMouseWheel(); 21594 this._initLinkedViews(); 21595 }; 21596 21597 ScrollbarCell.prototype.$toHTML = function () { 21598 var className = this._isHorizontal() ? "gantt_hor_scroll" : "gantt_ver_scroll"; 21599 return "<div class='gantt_layout_cell "+className+"'><div style='"+(this._isHorizontal() ? "width:2000px" : "height:2000px")+"'></div></div>"; 21600 }; 21601 21602 ScrollbarCell.prototype._getRootParent = function(){ 21603 var parent = this.$parent; 21604 while(parent && parent.$parent){ 21605 parent = parent.$parent; 21606 } 21607 if(parent){ 21608 return parent; 21609 } 21610 }; 21611 21612 21613 function eachCell(root, res){ 21614 res.push(root); 21615 if(root.$cells){ 21616 for(var i = 0; i < root.$cells.length; i++){ 21617 eachCell(root.$cells[i], res); 21618 } 21619 } 21620 } 21621 ScrollbarCell.prototype._eachView = function(){ 21622 var res = []; 21623 eachCell(this._getRootParent(), res); 21624 return res; 21625 }; 21626 21627 ScrollbarCell.prototype._getLinkedViews = function(){ 21628 var views = this._eachView(); 21629 var res = []; 21630 for(var i = 0; i < views.length; i++){ 21631 if(views[i].$config && ((this._isVertical() && views[i].$config.scrollY == this.$id) || (this._isHorizontal() && views[i].$config.scrollX == this.$id)) ){ 21632 res.push(views[i]); 21633 } 21634 } 21635 return res; 21636 }; 21637 21638 21639 ScrollbarCell.prototype._initHorizontal = function(){ 21640 this.$scroll_hor = this.$view; 21641 this.$domEvents.attach(this.$view, "scroll", this._scrollHorizontalHandler); 21642 21643 }; 21644 21645 ScrollbarCell.prototype._initLinkedViews = function(){ 21646 var views = this._getLinkedViews(); 21647 var css = this._isVertical() ?"gantt_layout_outer_scroll gantt_layout_outer_scroll_vertical" : "gantt_layout_outer_scroll gantt_layout_outer_scroll_horizontal"; 21648 for(var i = 0; i < views.length; i++){ 21649 //views[i].$config.css = [views[i].$config.css || "", css].join(" "); 21650 domHelpers.addClassName(views[i].$view || views[i].getNode(), css); 21651 } 21652 }; 21653 21654 ScrollbarCell.prototype._initVertical = function(){ 21655 this.$scroll_ver = this.$view; 21656 this.$domEvents.attach(this.$view, "scroll", this._scrollVerticalHandler); 21657 }; 21658 21659 ScrollbarCell.prototype._updateLinkedViews = function(){ 21660 }; 21661 21662 ScrollbarCell.prototype._initMouseWheel = function(){ 21663 var ff = env.isFF; 21664 if (ff) 21665 this.$domEvents.attach(this._getRootParent().$view, "wheel", this._mouseWheelHandler); 21666 else 21667 this.$domEvents.attach(this._getRootParent().$view, "mousewheel", this._mouseWheelHandler); 21668 }; 21669 21670 21671 21672 21673 ScrollbarCell.prototype.scrollHorizontally = function(left){ 21674 if(this._scrolling) return; 21675 this._scrolling = true; 21676 21677 this.$scroll_hor.scrollLeft = left; 21678 this.$config.codeScrollLeft = left; 21679 left = this.$scroll_hor.scrollLeft; 21680 21681 var views = this._getLinkedViews(); 21682 for(var i = 0; i < views.length; i++){ 21683 if(views[i].scrollTo){ 21684 views[i].scrollTo(left, undefined); 21685 } 21686 } 21687 var oldSize = this.$config.scrollPosition; 21688 this.$config.scrollPosition = left; 21689 this.callEvent("onScroll", [oldSize, left, this.$config.scroll]); 21690 this._scrolling = false; 21691 }; 21692 ScrollbarCell.prototype.scrollVertically = function(top){ 21693 if(this._scrolling) return; 21694 this._scrolling = true; 21695 21696 this.$scroll_ver.scrollTop = top; 21697 top = this.$scroll_ver.scrollTop; 21698 21699 var views = this._getLinkedViews(); 21700 21701 for(var i = 0; i < views.length; i++){ 21702 if(views[i].scrollTo){ 21703 views[i].scrollTo(undefined, top); 21704 } 21705 } 21706 var oldSize = this.$config.scrollPosition; 21707 this.$config.scrollPosition = top; 21708 this.callEvent("onScroll", [oldSize, top, this.$config.scroll]); 21709 this._scrolling = false; 21710 }; 21711 21712 ScrollbarCell.prototype._isVertical = function(){ 21713 return this.$config.scroll == "y"; 21714 }; 21715 ScrollbarCell.prototype._isHorizontal = function(){ 21716 return this.$config.scroll == "x"; 21717 }; 21718 ScrollbarCell.prototype._scrollHorizontalHandler = function (e) { 21719 if(this._isVertical() || this._scrolling){ 21720 return; 21721 } 21722 21723 //in safari we can catch previous onscroll after setting new value from mouse-wheel event 21724 //set delay to prevent value drifiting 21725 if ((new Date()) - ( this._wheel_time || 0 ) < 100) return true; 21726 if (this.$gantt._touch_scroll_active) return; 21727 var left = this.$scroll_hor.scrollLeft; 21728 21729 this.scrollHorizontally(left); 21730 21731 this._oldLeft = this.$scroll_hor.scrollLeft; 21732 }; 21733 ScrollbarCell.prototype._outerScrollHorizontalHandler = function(e){ 21734 if(this._isVertical()){ 21735 return; 21736 } 21737 }; 21738 21739 ScrollbarCell.prototype.show = function(){ 21740 this.$parent.show(); 21741 }; 21742 ScrollbarCell.prototype.hide = function(){ 21743 this.$parent.hide(); 21744 }; 21745 21746 ScrollbarCell.prototype._getScrollSize = function(){ 21747 var scrollSize = 0; 21748 var outerSize = 0; 21749 var isHorizontal = this._isHorizontal(); 21750 21751 var linked = this._getLinkedViews(); 21752 var view; 21753 var scrollProperty = isHorizontal ? "scrollWidth" : "scrollHeight", 21754 innerSizeProperty = isHorizontal ? "contentX" : "contentY"; 21755 var outerProperty = isHorizontal ? "x" : "y"; 21756 var offset = this._getScrollOffset(); 21757 21758 for(var i = 0; i < linked.length; i++){ 21759 view = linked[i]; 21760 if(!(view && view.$content && view.$content.getSize && !view.$config.hidden)) continue; 21761 21762 var sizes = view.$content.getSize(); 21763 var cellScrollSize; 21764 if(sizes.hasOwnProperty(scrollProperty)){ 21765 cellScrollSize = sizes[scrollProperty]; 21766 }else{ 21767 cellScrollSize = sizes[innerSizeProperty]; 21768 } 21769 21770 if(offset){ 21771 // precalculated vertical/horizontal offsets of scrollbar to emulate 4.x look 21772 if(sizes[innerSizeProperty] > sizes[outerProperty] && sizes[innerSizeProperty] > scrollSize && (cellScrollSize > (sizes[outerProperty] - offset + 2))){ 21773 scrollSize = cellScrollSize + (isHorizontal ? 0 : 2); 21774 outerSize = sizes[outerProperty]; 21775 } 21776 }else{ 21777 var nonScrollableSize = Math.max(sizes[innerSizeProperty] - cellScrollSize, 0); 21778 var scrollableViewPortSize = Math.max(sizes[outerProperty] - nonScrollableSize, 0); 21779 cellScrollSize = cellScrollSize + nonScrollableSize; 21780 21781 if(cellScrollSize > scrollableViewPortSize && (cellScrollSize > scrollSize) ){ 21782 //|| (cellScrollSize === scrollSize && sizes[outerProperty] < outerSize) // same scroll width but smaller scrollable view port 21783 21784 scrollSize = cellScrollSize; 21785 outerSize = sizes[outerProperty]; 21786 } 21787 } 21788 } 21789 21790 return { 21791 outerScroll: outerSize, 21792 innerScroll: scrollSize 21793 }; 21794 }; 21795 21796 ScrollbarCell.prototype.scroll = function(position){ 21797 if(this._isHorizontal()){ 21798 this.scrollHorizontally(position); 21799 }else{ 21800 this.scrollVertically(position); 21801 } 21802 }; 21803 21804 ScrollbarCell.prototype.getScrollState = function(){ 21805 return { 21806 visible: this.isVisible(), 21807 direction: this.$config.scroll, 21808 size: this.$config.outerSize, 21809 scrollSize: this.$config.scrollSize || 0, 21810 position: this.$config.scrollPosition || 0 21811 }; 21812 }; 21813 21814 ScrollbarCell.prototype.setSize = function(width, height){ 21815 _super.prototype.setSize.apply(this, arguments); 21816 21817 var scrollSizes = this._getScrollSize(); 21818 21819 var ownSize = (this._isVertical() ? height : width) - this._getScrollOffset() + (this._isHorizontal() ? 1 : 0); 21820 21821 if(scrollSizes.innerScroll && ownSize > scrollSizes.outerScroll){ 21822 scrollSizes.innerScroll += (ownSize - scrollSizes.outerScroll); 21823 } 21824 this.$config.scrollSize = scrollSizes.innerScroll; 21825 21826 this.$config.width = width; 21827 this.$config.height = height; 21828 this._setScrollSize(scrollSizes.innerScroll); 21829 }; 21830 21831 ScrollbarCell.prototype.isVisible = function(){ 21832 return !!(this.$parent && this.$parent.$view.parentNode); 21833 }; 21834 21835 ScrollbarCell.prototype.shouldShow = function(){ 21836 var scrollSizes = this._getScrollSize(); 21837 if(!scrollSizes.innerScroll && (this.$parent && this.$parent.$view.parentNode)){ 21838 return false; 21839 }else if(scrollSizes.innerScroll && !(this.$parent && this.$parent.$view.parentNode)){ 21840 return true; 21841 }else{ 21842 return false; 21843 } 21844 }; 21845 21846 ScrollbarCell.prototype.shouldHide = function(){ 21847 var scrollSizes = this._getScrollSize(); 21848 if(!scrollSizes.innerScroll && (this.$parent && this.$parent.$view.parentNode)){ 21849 return true; 21850 }else{ 21851 return false; 21852 } 21853 }; 21854 21855 21856 ScrollbarCell.prototype.toggleVisibility = function(){ 21857 if(this.shouldHide()){ 21858 this.hide(); 21859 }else if(this.shouldShow()){ 21860 this.show(); 21861 } 21862 }; 21863 21864 ScrollbarCell.prototype._getScaleOffset = function(view){ 21865 var offset = 0; 21866 if(view && (view.$config.view == "timeline" || view.$config.view == "grid")){ 21867 offset = view.$content.$getConfig().scale_height; 21868 } 21869 return offset; 21870 }; 21871 21872 ScrollbarCell.prototype._getScrollOffset = function(){ 21873 var offset = 0; 21874 if(this._isVertical()){ 21875 var parentLayout = this.$parent.$parent; 21876 offset = Math.max( 21877 this._getScaleOffset(parentLayout.getPrevSibling(this.$parent.$id)), 21878 this._getScaleOffset(parentLayout.getNextSibling(this.$parent.$id)) 21879 ); 21880 }else{ 21881 var linked = this._getLinkedViews(); 21882 21883 for (var i = 0; i < linked.length; i++) { 21884 var view = linked[i], 21885 vparent = view.$parent; 21886 var cells = vparent.$cells; 21887 21888 var last = cells[cells.length - 1]; 21889 21890 if (last && last.$config.view == "scrollbar" && last.$config.hidden === false) { 21891 offset = last.$config.width; 21892 break; 21893 } 21894 21895 } 21896 } 21897 return offset || 0; 21898 }; 21899 21900 ScrollbarCell.prototype._setScrollSize = function(size){ 21901 var property = this._isHorizontal() ? "width" : "height"; 21902 var scrollbar = this._isHorizontal() ? this.$scroll_hor : this.$scroll_ver; 21903 21904 var offset = this._getScrollOffset(); 21905 21906 var node = scrollbar.firstChild; 21907 21908 if(offset){ 21909 if(this._isVertical()){ 21910 21911 this.$config.outerSize = (this.$config.height - offset + 3); 21912 scrollbar.style.height = this.$config.outerSize + "px"; 21913 scrollbar.style.top = (offset-1) + "px"; 21914 domHelpers.addClassName(scrollbar, this.$parent._borders.top); 21915 domHelpers.addClassName(scrollbar.parentNode, "gantt_task_vscroll"); 21916 }else{ 21917 this.$config.outerSize = (this.$config.width - offset + 1); 21918 scrollbar.style.width = this.$config.outerSize + "px"; 21919 //domHelpers.addClassName(scrollbar, this.$parent._borders.right); 21920 } 21921 }else{ 21922 scrollbar.style.top = "auto"; 21923 domHelpers.removeClassName(scrollbar, this.$parent._borders.top); 21924 domHelpers.removeClassName(scrollbar.parentNode, "gantt_task_vscroll"); 21925 this.$config.outerSize = this.$config.height; 21926 } 21927 21928 node.style[property] = size + "px"; 21929 }; 21930 21931 ScrollbarCell.prototype._scrollVerticalHandler = function (e) { 21932 if(this._scrollHorizontalHandler() || this._scrolling){ 21933 return; 21934 } 21935 21936 if (this.$gantt._touch_scroll_active) return; 21937 var top = this.$scroll_ver.scrollTop; 21938 var prev = this._oldTop; 21939 if(top == prev) return; 21940 21941 this.scrollVertically(top); 21942 21943 this._oldTop = this.$scroll_ver.scrollTop; 21944 21945 }; 21946 ScrollbarCell.prototype._outerScrollVerticalHandler = function(e){ 21947 if(this._scrollHorizontalHandler()){ 21948 return; 21949 } 21950 }; 21951 21952 ScrollbarCell.prototype._checkWheelTarget = function(targetNode){ 21953 var connectedViews = this._getLinkedViews().concat(this); 21954 21955 for(var i = 0; i < connectedViews.length; i++){ 21956 var node = connectedViews[i].$view; 21957 if(domHelpers.isChildOf(targetNode, node)){ 21958 return true; 21959 } 21960 } 21961 21962 return false; 21963 }; 21964 21965 ScrollbarCell.prototype._mouseWheelHandler = function(e){ 21966 var target = e.target || e.srcElement; 21967 21968 if(!this._checkWheelTarget(target)) 21969 return; 21970 21971 this._wheel_time = new Date(); 21972 21973 var res = {}; 21974 var ff = env.isFF; 21975 var wx = ff ? (e.deltaX*-20) : e.wheelDeltaX*2; 21976 var wy = ff ? (e.deltaY*-40) : e.wheelDelta; 21977 21978 var horizontalScrollModifier = this.$gantt.config.horizontal_scroll_key; 21979 21980 if (horizontalScrollModifier !== false) { 21981 if (SCROLL_MODIFIER_KEYS.indexOf(horizontalScrollModifier) >= 0) { 21982 if(e[horizontalScrollModifier] && !(e.deltaX || e.wheelDeltaX)){ 21983 // shift+mousewheel for horizontal scroll 21984 wx = wy*2; 21985 wy = 0; 21986 } 21987 } 21988 } 21989 21990 21991 if (wx && Math.abs(wx) > Math.abs(wy)){ 21992 if(this._isVertical()){ 21993 return; 21994 } 21995 21996 if(res.x) return true;//no horisontal scroll, must not block scrolling 21997 if(!this.$scroll_hor || !this.$scroll_hor.offsetWidth) return true; 21998 21999 var dir = wx/-40; 22000 var oldLeft = this._oldLeft; 22001 var left = oldLeft+dir*30; 22002 this.scrollHorizontally(left); 22003 this.$scroll_hor.scrollLeft = left; 22004 // not block scroll if position hasn't changed 22005 if(oldLeft == this.$scroll_hor.scrollLeft){ 22006 return true; 22007 } 22008 22009 this._oldLeft = this.$scroll_hor.scrollLeft; 22010 } else { 22011 if(this._isHorizontal()){ 22012 return; 22013 } 22014 22015 if(res.y) return true;//no vertical scroll, must not block scrolling 22016 if(!this.$scroll_ver || !this.$scroll_ver.offsetHeight) return true; 22017 22018 var dir = wy/-40; 22019 if (typeof wy == "undefined") 22020 dir = e.detail; 22021 22022 var oldTop = this._oldTop; 22023 var top = this.$scroll_ver.scrollTop+dir*30; 22024 22025 //if(!this.$gantt.config.prevent_default_scroll && 22026 // (this.$gantt._cached_scroll_pos && ((this.$gantt._cached_scroll_pos.y == top) || (this.$gantt._cached_scroll_pos.y <= 0 && top <= 0)))) return true; 22027 22028 22029 this.scrollVertically(top); 22030 this.$scroll_ver.scrollTop = top; 22031 22032 // not block scroll if position hasn't changed 22033 if(oldTop == this.$scroll_ver.scrollTop){ 22034 return true; 22035 } 22036 this._oldTop = this.$scroll_ver.scrollTop; 22037 } 22038 22039 if (e.preventDefault) 22040 e.preventDefault(); 22041 e.cancelBubble=true; 22042 return false; 22043 }; 22044 22045 return ScrollbarCell; 22046})(Cell); 22047 22048module.exports = ScrollbarCell; 22049 22050/***/ }), 22051 22052/***/ "./sources/core/ui/layout/view_cell.js": 22053/*!*********************************************!*\ 22054 !*** ./sources/core/ui/layout/view_cell.js ***! 22055 \*********************************************/ 22056/*! no static exports found */ 22057/***/ (function(module, exports, __webpack_require__) { 22058 22059var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"), 22060 utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"), 22061 Cell = __webpack_require__(/*! ./cell */ "./sources/core/ui/layout/cell.js"); 22062 22063var ViewCell = (function (_super) { 22064 "use strict"; 22065 22066 __extends(ViewCell, _super); 22067 function ViewCell(parent, config, factory) { 22068 22069 var _this = _super.apply(this, arguments) || this; 22070 22071 if(config.view){ 22072 if(config.id){ 22073 // pass id to the nested view 22074 this.$id = utils.uid(); 22075 } 22076 var childConfig = utils.copy(config); 22077 delete childConfig.config; 22078 delete childConfig.templates; 22079 22080 this.$content = this.$factory.createView(config.view, this, childConfig, this); 22081 if(!this.$content) 22082 return false; 22083 } 22084 22085 _this.$name = "viewCell"; 22086 return _this; 22087 } 22088 22089 ViewCell.prototype.destructor = function(){ 22090 this.clear(); 22091 _super.prototype.destructor.call(this); 22092 }; 22093 22094 ViewCell.prototype.clear = function(){ 22095 22096 this.$initialized = false; 22097 22098 // call destructor 22099 if (this.$content){ 22100 var method = this.$content.unload || this.$content.destructor; 22101 if (method){ 22102 method.call(this.$content); 22103 } 22104 } 22105 22106 _super.prototype.clear.call(this); 22107 22108 }; 22109 22110 ViewCell.prototype.scrollTo = function(left, top){ 22111 22112 if(this.$content && this.$content.scrollTo){ 22113 this.$content.scrollTo(left, top); 22114 }else{ 22115 _super.prototype.scrollTo.call(this, left, top); 22116 } 22117 }; 22118 22119 ViewCell.prototype._setContentSize = function(x, y){ 22120 var borders = this._getBorderSizes(); 22121 if(typeof x === "number"){ 22122 var outerX = x + borders.horizontal; 22123 this.$config.width = outerX; 22124 } 22125 if(typeof y === "number"){ 22126 var outerY = y + borders.vertical; 22127 this.$config.height = outerY; 22128 } 22129 }; 22130 22131 ViewCell.prototype.setSize = function(x, y){ 22132 _super.prototype.setSize.call(this, x, y); 22133 22134 if(!this.$preResize && this.$content) { 22135 if (!this.$initialized) { 22136 this.$initialized = true; 22137 var header = this.$view.childNodes[0]; 22138 var content = this.$view.childNodes[1]; 22139 if(!content) content = header; 22140 22141 /*if(this.$content.$config){ 22142 this.$content.$config.width = this.$lastSize.contentX; 22143 this.$content.$config.height = this.$lastSize.contentY; 22144 }*/ 22145 this.$content.init(content); 22146 } 22147 } 22148 }; 22149 22150 ViewCell.prototype.setContentSize = function(){ 22151 if(!this.$preResize && this.$content) { 22152 if (this.$initialized) { 22153 this.$content.setSize(this.$lastSize.contentX, this.$lastSize.contentY); 22154 } 22155 } 22156 }; 22157 22158 22159 ViewCell.prototype.getContentSize = function(){ 22160 var size = _super.prototype.getContentSize.call(this); 22161 22162 if(this.$content && this.$initialized){ 22163 var childSize = this.$content.getSize(); 22164 size.width = childSize.contentX === undefined ? childSize.width : childSize.contentX; 22165 size.height = childSize.contentY === undefined ? childSize.height : childSize.contentY; 22166 } 22167 22168 var borders = this._getBorderSizes(); 22169 size.width += borders.horizontal; 22170 size.height += borders.vertical; 22171 22172 return size; 22173 }; 22174 22175 return ViewCell; 22176}(Cell)); 22177 22178module.exports = ViewCell; 22179 22180/***/ }), 22181 22182/***/ "./sources/core/ui/layout/view_layout.js": 22183/*!***********************************************!*\ 22184 !*** ./sources/core/ui/layout/view_layout.js ***! 22185 \***********************************************/ 22186/*! no static exports found */ 22187/***/ (function(module, exports, __webpack_require__) { 22188 22189var __extends = __webpack_require__(/*! ../../../utils/extends */ "./sources/utils/extends.js"), 22190 Layout = __webpack_require__(/*! ./layout */ "./sources/core/ui/layout/layout.js"), 22191 Cell = __webpack_require__(/*! ./cell */ "./sources/core/ui/layout/cell.js"); 22192 22193var ViewLayout = (function (_super) { 22194 "use strict"; 22195 22196 __extends(ViewLayout, _super); 22197 function ViewLayout(parent, config, factory) { 22198 var _this = _super.apply(this, arguments) || this; 22199 for (var i = 0; i < _this.$cells.length; i++) { 22200 _this.$cells[i].$config.hidden = (i !== 0); 22201 } 22202 _this.$cell = _this.$cells[0]; 22203 _this.$name = "viewLayout"; 22204 22205 return _this; 22206 } 22207 ViewLayout.prototype.cell = function (id) { 22208 var cell = _super.prototype.cell.call(this, id); 22209 if (!cell.$view) { 22210 this.$fill(null, this); 22211 } 22212 return cell; 22213 }; 22214 ViewLayout.prototype.moveView = function (view) { 22215 var body = this.$view; 22216 if (this.$cell) { 22217 this.$cell.$config.hidden = true; 22218 body.removeChild(this.$cell.$view); 22219 } 22220 this.$cell = view; 22221 body.appendChild(view.$view); 22222 }; 22223 ViewLayout.prototype.setSize = function (x, y) { 22224 Cell.prototype.setSize.call(this, x, y); 22225 }; 22226 22227 ViewLayout.prototype.setContentSize = function(){ 22228 var size = this.$lastSize; 22229 this.$cell.setSize(size.contentX, size.contentY); 22230 }; 22231 22232 ViewLayout.prototype.getSize = function () { 22233 var sizes = _super.prototype.getSize.call(this); 22234 if (this.$cell) { 22235 var cellSize = this.$cell.getSize(); 22236 if (this.$config.byMaxSize) { 22237 for (var i = 0; i < this.$cells.length; i++) { 22238 var otherCell = this.$cells[i].getSize(); 22239 for (var cell in cellSize) { 22240 cellSize[cell] = Math.max(cellSize[cell], otherCell[cell]); 22241 } 22242 } 22243 } 22244 for (var size in sizes) { 22245 sizes[size] = sizes[size] || cellSize[size]; 22246 } 22247 sizes.gravity = Math.max(sizes.gravity, cellSize.gravity); 22248 } 22249 return sizes; 22250 }; 22251 return ViewLayout; 22252}(Layout)); 22253 22254module.exports = ViewLayout; 22255 22256/***/ }), 22257 22258/***/ "./sources/core/ui/main_layout_initializer.js": 22259/*!****************************************************!*\ 22260 !*** ./sources/core/ui/main_layout_initializer.js ***! 22261 \****************************************************/ 22262/*! no static exports found */ 22263/***/ (function(module, exports, __webpack_require__) { 22264 22265var domHelpers = __webpack_require__(/*! ../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 22266 22267var initializer = (function() { 22268 return function (gantt) { 22269 return { 22270 22271 getVerticalScrollbar: function(){ 22272 return gantt.$ui.getView("scrollVer"); 22273 }, 22274 getHorizontalScrollbar: function(){ 22275 return gantt.$ui.getView("scrollHor"); 22276 }, 22277 22278 _legacyGridResizerClass: function(layout){ 22279 var resizers = layout.getCellsByType("resizer"); 22280 for(var i = 0; i < resizers.length; i++){ 22281 var r = resizers[i]; 22282 var gridResizer = false; 22283 22284 var prev = r.$parent.getPrevSibling(r.$id); 22285 if(prev && prev.$config && prev.$config.id === "grid"){ 22286 gridResizer= true; 22287 }else{ 22288 var next = r.$parent.getNextSibling(r.$id); 22289 if(next && next.$config && next.$config.id === "grid"){ 22290 gridResizer= true; 22291 } 22292 } 22293 22294 if(gridResizer){ 22295 r.$config.css = (r.$config.css ? r.$config.css + " " : "") + "gantt_grid_resize_wrap"; 22296 } 22297 } 22298 }, 22299 22300 onCreated: function(layout) { 22301 var first = true; 22302 22303 this._legacyGridResizerClass(layout); 22304 22305 layout.attachEvent("onBeforeResize", function() { 22306 var mainTimeline = gantt.$ui.getView("timeline"); 22307 if (mainTimeline) 22308 mainTimeline.$config.hidden = mainTimeline.$parent.$config.hidden = !gantt.config.show_chart; 22309 22310 var mainGrid = gantt.$ui.getView("grid"); 22311 22312 if(!mainGrid) 22313 return; 22314 22315 var showGrid = gantt.config.show_grid; 22316 if (first) { 22317 var colsWidth = mainGrid._getColsTotalWidth(); 22318 if (colsWidth !== false){ 22319 gantt.config.grid_width = colsWidth; 22320 } 22321 showGrid = showGrid && !!gantt.config.grid_width; 22322 gantt.config.show_grid = showGrid; 22323 } 22324 mainGrid.$config.hidden = mainGrid.$parent.$config.hidden = !showGrid; 22325 22326 if (!mainGrid.$config.hidden) { 22327 /* restrict grid width due to min_width, max_width, min_grid_column_width */ 22328 var grid_limits = mainGrid._getGridWidthLimits(); 22329 if (grid_limits[0] && gantt.config.grid_width < grid_limits[0]) 22330 gantt.config.grid_width = grid_limits[0]; 22331 if (grid_limits[1] && gantt.config.grid_width > grid_limits[1]) 22332 gantt.config.grid_width = grid_limits[1]; 22333 if (mainTimeline && gantt.config.show_chart){ 22334 22335 mainGrid.$config.width = gantt.config.grid_width - 1; 22336 if (!first) { 22337 if (mainTimeline && !domHelpers.isChildOf(mainTimeline.$task, layout.$view)) { 22338 // timeline is being displayed after being not visible, reset grid with from full screen 22339 if (!mainGrid.$config.original_grid_width) { 22340 var skinSettings = gantt.skins[gantt.skin]; 22341 if(skinSettings && skinSettings.config && skinSettings.config.grid_width){ 22342 mainGrid.$config.original_grid_width = skinSettings.config.grid_width; 22343 }else{ 22344 mainGrid.$config.original_grid_width = 0; 22345 } 22346 } 22347 gantt.config.grid_width = mainGrid.$config.original_grid_width; 22348 mainGrid.$parent.$config.width = gantt.config.grid_width; 22349 } else { 22350 mainGrid.$parent._setContentSize(mainGrid.$config.width, null); 22351 gantt.$layout._syncCellSizes(mainGrid.$parent.$config.group, gantt.config.grid_width); 22352 } 22353 } else { 22354 mainGrid.$parent.$config.width = gantt.config.grid_width; 22355 if (mainGrid.$parent.$config.group) { 22356 gantt.$layout._syncCellSizes(mainGrid.$parent.$config.group, mainGrid.$parent.$config.width); 22357 } 22358 } 22359 } else { 22360 if (mainTimeline && domHelpers.isChildOf(mainTimeline.$task, layout.$view)) { 22361 // hiding timeline, remember grid with to restore it when timeline is displayed again 22362 mainGrid.$config.original_grid_width = gantt.config.grid_width; 22363 } 22364 if (!first) { 22365 mainGrid.$parent.$config.width = 0; 22366 } 22367 } 22368 } 22369 22370 first = false; 22371 }); 22372 this._initScrollStateEvents(layout); 22373 }, 22374 22375 _initScrollStateEvents: function(layout) { 22376 gantt._getVerticalScrollbar = this.getVerticalScrollbar; 22377 gantt._getHorizontalScrollbar = this.getHorizontalScrollbar; 22378 22379 var vertical = this.getVerticalScrollbar(); 22380 var horizontal = this.getHorizontalScrollbar(); 22381 if (vertical) { 22382 vertical.attachEvent("onScroll", function(oldPos, newPos, dir){ 22383 var scrollState = gantt.getScrollState(); 22384 gantt.callEvent("onGanttScroll", [scrollState.x, oldPos, scrollState.x, newPos]); 22385 }); 22386 } 22387 if (horizontal) { 22388 horizontal.attachEvent("onScroll", function(oldPos, newPos, dir){ 22389 var scrollState = gantt.getScrollState(); 22390 gantt.callEvent("onGanttScroll", [oldPos, scrollState.y, newPos, scrollState.y]); 22391 }); 22392 } 22393 22394 layout.attachEvent("onResize", function(){ 22395 if (vertical && !gantt.$scroll_ver){ 22396 gantt.$scroll_ver = vertical.$scroll_ver; 22397 } 22398 22399 if (horizontal && !gantt.$scroll_hor){ 22400 gantt.$scroll_hor = horizontal.$scroll_hor; 22401 } 22402 }); 22403 }, 22404 22405 _findGridResizer: function(layout, grid){ 22406 var resizers = layout.getCellsByType("resizer"); 22407 22408 var gridFirst = true; 22409 var gridResizer; 22410 for(var i = 0; i < resizers.length; i++){ 22411 var res = resizers[i]; 22412 res._getSiblings(); 22413 var prev = res._behind; 22414 var next = res._front; 22415 if(prev && prev.$content === grid || (prev.isChild && prev.isChild(grid))){ 22416 gridResizer = res; 22417 gridFirst = true; 22418 break; 22419 }else if(next && next.$content === grid || (next.isChild && next.isChild(grid))){ 22420 gridResizer = res; 22421 gridFirst = false; 22422 break; 22423 } 22424 } 22425 return { 22426 resizer: gridResizer, 22427 gridFirst: gridFirst 22428 }; 22429 }, 22430 22431 onInitialized: function (layout) { 22432 var grid = gantt.$ui.getView("grid"); 22433 22434 var resizeInfo = this._findGridResizer(layout, grid); 22435 22436 // expose grid resize events 22437 if(resizeInfo.resizer){ 22438 var gridFirst = resizeInfo.gridFirst, 22439 next = resizeInfo.resizer; 22440 var initialWidth; 22441 next.attachEvent("onResizeStart", function(prevCellWidth, nextCellWidth){ 22442 22443 var grid = gantt.$ui.getView("grid"); 22444 var viewCell = grid ? grid.$parent : null; 22445 if(viewCell){ 22446 var limits = grid._getGridWidthLimits(); 22447 22448 // min grid width is defined by min widths of its columns, unless grid has horizontal scroll 22449 if(!grid.$config.scrollable) 22450 viewCell.$config.minWidth = limits[0]; 22451 22452 viewCell.$config.maxWidth = limits[1]; 22453 } 22454 initialWidth = gridFirst ? prevCellWidth : nextCellWidth; 22455 return gantt.callEvent("onGridResizeStart", [initialWidth]); 22456 }); 22457 next.attachEvent("onResize", function(newBehindSize, newFrontSize){ 22458 var newSize = gridFirst ? newBehindSize : newFrontSize; 22459 return gantt.callEvent("onGridResize", [initialWidth, newSize]); 22460 }); 22461 next.attachEvent("onResizeEnd", function(oldBackSize, oldFrontSize, newBackSize, newFrontSize){ 22462 22463 var oldSize = gridFirst ? oldBackSize : oldFrontSize; 22464 var newSize = gridFirst ? newBackSize : newFrontSize; 22465 var grid = gantt.$ui.getView("grid"); 22466 var viewCell = grid ? grid.$parent : null; 22467 if(viewCell){ 22468 viewCell.$config.minWidth = undefined; 22469 } 22470 var res = gantt.callEvent("onGridResizeEnd", [oldSize, newSize]); 22471 if(res){ 22472 gantt.config.grid_width = newSize; 22473 } 22474 22475 return res; 22476 }); 22477 } 22478 22479 }, 22480 onDestroyed: function (timeline) { 22481 22482 } 22483 }; 22484 22485 }; 22486})(); 22487 22488module.exports = initializer; 22489 22490/***/ }), 22491 22492/***/ "./sources/core/ui/mouse.js": 22493/*!**********************************!*\ 22494 !*** ./sources/core/ui/mouse.js ***! 22495 \**********************************/ 22496/*! no static exports found */ 22497/***/ (function(module, exports, __webpack_require__) { 22498 22499var domHelpers = __webpack_require__(/*! ../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 22500 22501var createMouseHandler = (function(domHelpers) { 22502 return function (gantt) { 22503 var eventHandlers = { 22504 "click": {}, 22505 "doubleclick": {}, 22506 "contextMenu": {} 22507 }; 22508 22509 function addEventTarget(event, className, handler, root) { 22510 if(!eventHandlers[event][className]){ 22511 eventHandlers[event][className] = []; 22512 } 22513 22514 eventHandlers[event][className].push({ 22515 handler: handler, 22516 root: root 22517 }); 22518 } 22519 22520 function callHandler(eventName, className, root, args) { 22521 var handlers = eventHandlers[eventName][className]; 22522 if(handlers){ 22523 for(var i = 0; i < handlers.length; i++){ 22524 if(!(root || handlers[i].root) || handlers[i].root === root){ 22525 handlers[i].handler.apply(this, args); 22526 } 22527 } 22528 } 22529 } 22530 22531 function onClick(e) { 22532 e = e || window.event; 22533 var id = gantt.locate(e); 22534 22535 var handlers = findEventHandlers(e, eventHandlers.click); 22536 var res = true; 22537 if (id !== null) { 22538 res = !gantt.checkEvent("onTaskClick") || gantt.callEvent("onTaskClick", [id, e]); 22539 } else { 22540 gantt.callEvent("onEmptyClick", [e]); 22541 } 22542 22543 if (res) { 22544 var default_action = callEventHandlers(handlers, e, id); 22545 if (!default_action) 22546 return; 22547 22548 if (id && gantt.getTask(id) && gantt.config.select_task && !gantt.config.multiselect) { 22549 gantt.selectTask(id); 22550 } 22551 } 22552 } 22553 22554 function onContextMenu(e) { 22555 e = e || window.event; 22556 var src = e.target || e.srcElement, 22557 taskId = gantt.locate(src), 22558 linkId = gantt.locate(src, gantt.config.link_attribute); 22559 22560 var res = !gantt.checkEvent("onContextMenu") || gantt.callEvent("onContextMenu", [taskId, linkId, e]); 22561 if (!res) { 22562 if (e.preventDefault) 22563 e.preventDefault(); 22564 else 22565 e.returnValue = false; 22566 } 22567 return res; 22568 } 22569 22570 function findEventHandlers(e, hash){ 22571 var trg = e.target || e.srcElement; 22572 var handlers = []; 22573 while (trg) { 22574 var css = domHelpers.getClassName(trg); 22575 if (css) { 22576 css = css.split(" "); 22577 for (var i = 0; i < css.length; i++) { 22578 if (!css[i]) continue; 22579 if (hash[css[i]]) { 22580 var delegateHandlers = hash[css[i]]; 22581 22582 for(var h = 0; h < delegateHandlers.length; h++){ 22583 if(delegateHandlers[h].root){ 22584 if(!domHelpers.isChildOf(trg, delegateHandlers[h].root)){ 22585 continue; 22586 } 22587 } 22588 handlers.push(delegateHandlers[h].handler); 22589 } 22590 } 22591 } 22592 } 22593 trg = trg.parentNode; 22594 } 22595 return handlers; 22596 } 22597 22598 function callEventHandlers(handlers, e, id){ 22599 var res = true; 22600 22601 for(var i = 0; i < handlers.length; i++){ 22602 var handlerResult = handlers[i].call(gantt, e, id, e.target || e.srcElement); 22603 res = res && !(typeof handlerResult != "undefined" && handlerResult !== true); 22604 } 22605 22606 return res; 22607 } 22608 22609 22610 function onDoubleClick(e) { 22611 e = e || window.event; 22612 var id = gantt.locate(e); 22613 22614 var handlers = findEventHandlers(e, eventHandlers.doubleclick); 22615 // when doubleclick fired not on task, id === null 22616 var res = !gantt.checkEvent("onTaskDblClick") || id === null || gantt.callEvent("onTaskDblClick", [id, e]); 22617 if (res) { 22618 var default_action = callEventHandlers(handlers, e, id); 22619 if (!default_action) 22620 return; 22621 22622 if (id !== null && gantt.getTask(id)) { 22623 if (res && gantt.config.details_on_dblclick && !gantt.isReadonly()) { 22624 gantt.showLightbox(id); 22625 } 22626 } 22627 } 22628 } 22629 22630 function onMouseMove(e) { 22631 if (gantt.checkEvent("onMouseMove")) { 22632 var id = gantt.locate(e); 22633 gantt._last_move_event = e; 22634 gantt.callEvent("onMouseMove", [id, e]); 22635 } 22636 } 22637 22638 function detach(eventName, className, handler, root) { 22639 if (eventHandlers[eventName] && eventHandlers[eventName][className]) { 22640 var handlers = eventHandlers[eventName]; 22641 var elementHandlers = handlers[className]; 22642 for(var i = 0; i < elementHandlers.length; i++){ 22643 if(elementHandlers[i].root == root){ 22644 elementHandlers.splice(i, 1); 22645 i--; 22646 } 22647 } 22648 if(!elementHandlers.length){ 22649 delete handlers[className]; 22650 } 22651 22652 } 22653 } 22654 22655 var domEvents = gantt._createDomEventScope(); 22656 22657 function reset(node){ 22658 22659 domEvents.detachAll(); 22660 22661 if(node){ 22662 domEvents.attach(node, "click", onClick); 22663 domEvents.attach(node, "dblclick", onDoubleClick); 22664 domEvents.attach(node, "mousemove", onMouseMove); 22665 domEvents.attach(node, "contextmenu", onContextMenu); 22666 } 22667 } 22668 22669 22670 22671 return { 22672 reset: reset, 22673 global: function(event, classname, handler){ 22674 addEventTarget(event, classname, handler, null); 22675 }, 22676 delegate: addEventTarget, 22677 detach: detach, 22678 callHandler: callHandler, 22679 onDoubleClick: onDoubleClick, 22680 onMouseMove: onMouseMove, 22681 onContextMenu: onContextMenu, 22682 onClick: onClick, 22683 destructor: function(){ 22684 reset(); 22685 eventHandlers = null; 22686 domEvents = null; 22687 } 22688 22689 }; 22690 }; 22691 22692})(domHelpers); 22693 22694 22695module.exports = { 22696 init:createMouseHandler 22697}; 22698 22699/***/ }), 22700 22701/***/ "./sources/core/ui/mouse_event_container.js": 22702/*!**************************************************!*\ 22703 !*** ./sources/core/ui/mouse_event_container.js ***! 22704 \**************************************************/ 22705/*! no static exports found */ 22706/***/ (function(module, exports) { 22707 22708function create(gantt){ 22709 var events = []; 22710 22711 return { 22712 delegate:function(event, className, handler, root) { 22713 events.push([event, className, handler, root]); 22714 22715 var helper = gantt.$services.getService("mouseEvents"); 22716 helper.delegate(event, className, handler, root); 22717 }, 22718 destructor: function(){ 22719 var mouseEvents = gantt.$services.getService("mouseEvents"); 22720 for(var i = 0; i < events.length; i++){ 22721 var h = events[i]; 22722 mouseEvents.detach(h[0], h[1], h[2], h[3]); 22723 } 22724 events = []; 22725 } 22726 }; 22727} 22728 22729module.exports = create; 22730 22731/***/ }), 22732 22733/***/ "./sources/core/ui/render/is_legacy_smart_render.js": 22734/*!**********************************************************!*\ 22735 !*** ./sources/core/ui/render/is_legacy_smart_render.js ***! 22736 \**********************************************************/ 22737/*! no static exports found */ 22738/***/ (function(module, exports) { 22739 22740module.exports = function(gantt){ 22741 return gantt.config.smart_rendering && gantt._smart_render; 22742}; 22743 22744/***/ }), 22745 22746/***/ "./sources/core/ui/render/layer_engine.js": 22747/*!************************************************!*\ 22748 !*** ./sources/core/ui/render/layer_engine.js ***! 22749 \************************************************/ 22750/*! no static exports found */ 22751/***/ (function(module, exports, __webpack_require__) { 22752 22753var renderFactoryProvider = __webpack_require__(/*! ./render_factory */ "./sources/core/ui/render/render_factory.js"); 22754var utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"), 22755 domHelpers = __webpack_require__(/*! ../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"), 22756 isLegacyRender = __webpack_require__(/*! ./is_legacy_smart_render */ "./sources/core/ui/render/is_legacy_smart_render.js"); 22757 22758var layerFactory = function(gantt){ 22759 22760 var renderFactory = renderFactoryProvider(gantt); 22761 return { 22762 createGroup: function (getContainer, relativeRoot, defaultFilters, initLayer) { 22763 22764 var renderGroup = { 22765 tempCollection: [], 22766 renderers: {}, 22767 container: getContainer, 22768 filters: [], 22769 getLayers: function () { 22770 this._add();// add pending layers 22771 22772 var res = []; 22773 for (var i in this.renderers) { 22774 res.push(this.renderers[i]); 22775 } 22776 return res; 22777 }, 22778 getLayer: function (id) { 22779 return this.renderers[id]; 22780 }, 22781 _add: function (layer) { 22782 if (layer) { 22783 layer.id = layer.id || utils.uid(); 22784 this.tempCollection.push(layer); 22785 } 22786 22787 var container = this.container(); 22788 22789 var pending = this.tempCollection; 22790 for (var i = 0; i < pending.length; i++) { 22791 layer = pending[i]; 22792 22793 if (!this.container() && !(layer && layer.container && domHelpers.isChildOf(layer.container, document.body))) continue; 22794 22795 var node = layer.container, 22796 id = layer.id, 22797 topmost = layer.topmost; 22798 if (!node.parentNode) { 22799 //insert on top or below the tasks 22800 if (topmost) { 22801 container.appendChild(node); 22802 } else { 22803 var rel = relativeRoot ? relativeRoot() : container.firstChild; 22804 if (rel) 22805 container.insertBefore(node, rel); 22806 else 22807 container.appendChild(node); 22808 } 22809 } 22810 this.renderers[id] = renderFactory.getRenderer( 22811 id, 22812 layer, 22813 node 22814 ); 22815 22816 if (initLayer) { 22817 initLayer(layer, gantt); 22818 } 22819 22820 this.tempCollection.splice(i, 1); 22821 i--; 22822 } 22823 }, 22824 addLayer: function (config) { 22825 if(config){ 22826 if(typeof config == "function"){ 22827 config = {renderer: config}; 22828 } 22829 22830 if(config.filter === undefined){ 22831 config.filter = mergeFilters(defaultFilters || []); 22832 }else if(config.filter instanceof Array){ 22833 config.filter.push(defaultFilters); 22834 config.filter = mergeFilters(config.filter); 22835 } 22836 22837 if(!config.container){ 22838 config.container = document.createElement("div"); 22839 } 22840 var self = this; 22841 config.requestUpdate = function(){ 22842 if(gantt.config.smart_rendering && !isLegacyRender(gantt)){ 22843 if(self.renderers[config.id]){ 22844 self.onUpdateRequest(self.renderers[config.id]); 22845 } 22846 } 22847 22848 }; 22849 } 22850 22851 this._add(config); 22852 return (config ? config.id : undefined); 22853 }, 22854 onUpdateRequest: function(layer){ 22855 22856 }, 22857 22858 eachLayer: function(code){ 22859 for (var i in this.renderers) { 22860 code(this.renderers[i]); 22861 } 22862 }, 22863 removeLayer: function (id) { 22864 if(!this.renderers[id]) 22865 return; 22866 this.renderers[id].destructor(); 22867 delete this.renderers[id]; 22868 }, 22869 clear: function () { 22870 for (var i in this.renderers) { 22871 this.renderers[i].destructor(); 22872 } 22873 this.renderers = {}; 22874 }//, 22875 //prepareConfig: prepareConfig 22876 }; 22877 22878 gantt.attachEvent("onDestroy", function(){ 22879 renderGroup.clear(); 22880 renderGroup = null; 22881 }); 22882 22883 return renderGroup; 22884 } 22885};}; 22886 22887 22888function mergeFilters(filter_methods){ 22889 if(!(filter_methods instanceof Array)){ 22890 filter_methods = Array.prototype.slice.call(arguments, 0); 22891 } 22892 22893 return function(obj){ 22894 var res = true; 22895 for(var i = 0, len = filter_methods.length; i < len; i++){ 22896 var filter_method = filter_methods[i]; 22897 if(filter_method){ 22898 res = res && (filter_method(obj.id, obj) !== false); 22899 } 22900 } 22901 22902 return res; 22903 }; 22904} 22905 22906 22907module.exports = layerFactory; 22908 22909 22910/***/ }), 22911 22912/***/ "./sources/core/ui/render/link_render.js": 22913/*!***********************************************!*\ 22914 !*** ./sources/core/ui/render/link_render.js ***! 22915 \***********************************************/ 22916/*! no static exports found */ 22917/***/ (function(module, exports, __webpack_require__) { 22918 22919var getLinkRectangle = __webpack_require__(/*! ./viewport/get_link_rectangle */ "./sources/core/ui/render/viewport/get_link_rectangle.js"); 22920 22921function createLinkRender(gantt){ 22922 22923function _render_link_element(link, view) { 22924 var config = view.$getConfig(); 22925 22926 var pt = path_builder.get_endpoint(link, view); 22927 var dy = pt.e_y - pt.y; 22928 var dx = pt.e_x - pt.x; 22929 if(!dx && !dy){ 22930 return null; 22931 } 22932 22933 22934 var dots = path_builder.get_points(link, view); 22935 var lines = drawer.get_lines(dots, view); 22936 22937 var div = document.createElement("div"); 22938 22939 var css = "gantt_task_link"; 22940 22941 if (link.color) { 22942 css += " gantt_link_inline_color"; 22943 } 22944 var cssTemplate = gantt.templates.link_class ? gantt.templates.link_class(link) : ""; 22945 if (cssTemplate) { 22946 css += " " + cssTemplate; 22947 } 22948 22949 if (config.highlight_critical_path && gantt.isCriticalLink) { 22950 if (gantt.isCriticalLink(link)) 22951 css += " gantt_critical_link"; 22952 } 22953 22954 div.className = css; 22955 22956 if(view.$config.link_attribute){ 22957 div.setAttribute(view.$config.link_attribute, link.id); 22958 } 22959 22960 for (var i = 0; i < lines.length; i++) { 22961 if (i == lines.length - 1) { 22962 lines[i].size -= config.link_arrow_size; 22963 } 22964 var el = drawer.render_line(lines[i], lines[i + 1], view); 22965 if (link.color) { 22966 el.firstChild.style.backgroundColor = link.color; 22967 } 22968 div.appendChild(el); 22969 } 22970 22971 var direction = lines[lines.length - 1].direction; 22972 var endpoint = _render_link_arrow(dots[dots.length - 1], direction, view); 22973 if (link.color) { 22974 endpoint.style.borderColor = link.color; 22975 } 22976 div.appendChild(endpoint); 22977 22978 gantt._waiAria.linkAttr(link, div); 22979 22980 return div; 22981} 22982 22983function _render_link_arrow(point, direction, view) { 22984 var config = view.$getConfig(); 22985 var div = document.createElement("div"); 22986 var top = point.y; 22987 var left = point.x; 22988 22989 var size = config.link_arrow_size; 22990 var line_width = config.row_height; 22991 var className = "gantt_link_arrow gantt_link_arrow_" + direction; 22992 switch (direction) { 22993 case drawer.dirs.right: 22994 top -= (size - line_width) / 2; 22995 left -= size; 22996 break; 22997 case drawer.dirs.left: 22998 top -= (size - line_width) / 2; 22999 break; 23000 case drawer.dirs.up: 23001 left -= size; 23002 break; 23003 case drawer.dirs.down: 23004 top += size * 2; 23005 left -= size; 23006 break; 23007 default: 23008 break; 23009 } 23010 div.style.cssText = [ 23011 "top:" + top + "px", 23012 "left:" + left + 'px'].join(';'); 23013 div.className = className; 23014 23015 return div; 23016} 23017 23018 23019var drawer = { 23020 current_pos: null, 23021 dirs: {"left": 'left', "right": 'right', "up": 'up', "down": 'down'}, 23022 path: [], 23023 clear: function () { 23024 this.current_pos = null; 23025 this.path = []; 23026 }, 23027 point: function (pos) { 23028 this.current_pos = gantt.copy(pos); 23029 }, 23030 get_lines: function (dots) { 23031 this.clear(); 23032 this.point(dots[0]); 23033 for (var i = 1; i < dots.length; i++) { 23034 this.line_to(dots[i]); 23035 } 23036 return this.get_path(); 23037 }, 23038 line_to: function (pos) { 23039 var next = gantt.copy(pos); 23040 var prev = this.current_pos; 23041 23042 var line = this._get_line(prev, next); 23043 this.path.push(line); 23044 this.current_pos = next; 23045 }, 23046 get_path: function () { 23047 return this.path; 23048 }, 23049 get_wrapper_sizes: function (v, view) { 23050 var config = view.$getConfig(); 23051 var res, 23052 wrapper_size = config.link_wrapper_width, 23053 y = v.y + (config.row_height - wrapper_size) / 2; 23054 switch (v.direction) { 23055 case this.dirs.left: 23056 res = { 23057 top: y, 23058 height: wrapper_size, 23059 lineHeight: wrapper_size, 23060 left: v.x - v.size - wrapper_size / 2, 23061 width: v.size + wrapper_size 23062 }; 23063 break; 23064 case this.dirs.right: 23065 res = { 23066 top: y, 23067 lineHeight: wrapper_size, 23068 height: wrapper_size, 23069 left: v.x - wrapper_size / 2, 23070 width: v.size + wrapper_size 23071 }; 23072 break; 23073 case this.dirs.up: 23074 res = { 23075 top: y - v.size, 23076 lineHeight: v.size + wrapper_size, 23077 height: v.size + wrapper_size, 23078 left: v.x - wrapper_size / 2, 23079 width: wrapper_size 23080 }; 23081 break; 23082 case this.dirs.down: 23083 res = { 23084 top: y /*- wrapper_size/2*/, 23085 lineHeight: v.size + wrapper_size, 23086 height: v.size + wrapper_size, 23087 left: v.x - wrapper_size / 2, 23088 width: wrapper_size 23089 }; 23090 break; 23091 default: 23092 break; 23093 } 23094 23095 return res; 23096 }, 23097 get_line_sizes: function (v, view) { 23098 var config = view.$getConfig(); 23099 var res, 23100 line_size = config.link_line_width, 23101 wrapper_size = config.link_wrapper_width, 23102 size = v.size + line_size; 23103 switch (v.direction) { 23104 case this.dirs.left: 23105 case this.dirs.right: 23106 res = { 23107 height: line_size, 23108 width: size, 23109 marginTop: (wrapper_size - line_size) / 2, 23110 marginLeft: (wrapper_size - line_size) / 2 23111 }; 23112 break; 23113 case this.dirs.up: 23114 case this.dirs.down: 23115 res = { 23116 height: size, 23117 width: line_size, 23118 marginTop: (wrapper_size - line_size) / 2, 23119 marginLeft: (wrapper_size - line_size) / 2 23120 }; 23121 break; 23122 default: 23123 break; 23124 } 23125 23126 23127 return res; 23128 }, 23129 render_line: function (v, end, view) { 23130 var pos = this.get_wrapper_sizes(v, view); 23131 var wrapper = document.createElement("div"); 23132 wrapper.style.cssText = [ 23133 "top:" + pos.top + "px", 23134 "left:" + pos.left + "px", 23135 "height:" + pos.height + "px", 23136 "width:" + pos.width + "px" 23137 ].join(';'); 23138 wrapper.className = "gantt_line_wrapper"; 23139 23140 var innerPos = this.get_line_sizes(v, view); 23141 var inner = document.createElement("div"); 23142 inner.style.cssText = [ 23143 "height:" + innerPos.height + "px", 23144 "width:" + innerPos.width + "px", 23145 "margin-top:" + innerPos.marginTop + "px", 23146 "margin-left:" + innerPos.marginLeft + "px" 23147 ].join(";"); 23148 23149 inner.className = "gantt_link_line_" + v.direction; 23150 wrapper.appendChild(inner); 23151 23152 return wrapper; 23153 }, 23154 _get_line: function (from, to) { 23155 var direction = this.get_direction(from, to); 23156 var vect = { 23157 x: from.x, 23158 y: from.y, 23159 direction: this.get_direction(from, to) 23160 }; 23161 if (direction == this.dirs.left || direction == this.dirs.right) { 23162 vect.size = Math.abs(from.x - to.x); 23163 } else { 23164 vect.size = Math.abs(from.y - to.y); 23165 } 23166 return vect; 23167 }, 23168 get_direction: function (from, to) { 23169 var direction = 0; 23170 if (to.x < from.x) { 23171 direction = this.dirs.left; 23172 } else if (to.x > from.x) { 23173 direction = this.dirs.right; 23174 } else if (to.y > from.y) { 23175 direction = this.dirs.down; 23176 } else { 23177 direction = this.dirs.up; 23178 } 23179 return direction; 23180 } 23181 23182}; 23183 23184var path_builder = { 23185 23186 path: [], 23187 clear: function () { 23188 this.path = []; 23189 }, 23190 current: function () { 23191 return this.path[this.path.length - 1]; 23192 }, 23193 point: function (next) { 23194 if (!next) 23195 return this.current(); 23196 23197 this.path.push(gantt.copy(next)); 23198 return next; 23199 }, 23200 point_to: function (direction, diff, point) { 23201 if (!point) 23202 point = gantt.copy(this.point()); 23203 else 23204 point = {x: point.x, y: point.y}; 23205 var dir = drawer.dirs; 23206 switch (direction) { 23207 case (dir.left): 23208 point.x -= diff; 23209 break; 23210 case (dir.right): 23211 point.x += diff; 23212 break; 23213 case (dir.up): 23214 point.y -= diff; 23215 break; 23216 case (dir.down): 23217 point.y += diff; 23218 break; 23219 default: 23220 break; 23221 } 23222 return this.point(point); 23223 }, 23224 get_points: function (link, view) { 23225 var pt = this.get_endpoint(link, view); 23226 var xy = gantt.config; 23227 23228 var dy = pt.e_y - pt.y; 23229 var dx = pt.e_x - pt.x; 23230 23231 var dir = drawer.dirs; 23232 23233 this.clear(); 23234 this.point({x: pt.x, y: pt.y}); 23235 23236 var shiftX = 2 * xy.link_arrow_size;//just random size for first line 23237 var lineType = this.get_line_type(link, view.$getConfig()); 23238 23239 var forward = (pt.e_x > pt.x); 23240 if (lineType.from_start && lineType.to_start) { 23241 this.point_to(dir.left, shiftX); 23242 if (forward) { 23243 this.point_to(dir.down, dy); 23244 this.point_to(dir.right, dx); 23245 } else { 23246 this.point_to(dir.right, dx); 23247 this.point_to(dir.down, dy); 23248 } 23249 this.point_to(dir.right, shiftX); 23250 23251 } else if (!lineType.from_start && lineType.to_start) { 23252 forward = (pt.e_x > (pt.x + 2 * shiftX)); 23253 this.point_to(dir.right, shiftX); 23254 if (forward) { 23255 dx -= shiftX; 23256 this.point_to(dir.down, dy); 23257 this.point_to(dir.right, dx); 23258 } else { 23259 dx -= 2 * shiftX; 23260 var sign = dy > 0 ? 1 : -1; 23261 23262 this.point_to(dir.down, sign * (xy.row_height / 2)); 23263 this.point_to(dir.right, dx); 23264 this.point_to(dir.down, sign * ( Math.abs(dy) - (xy.row_height / 2))); 23265 this.point_to(dir.right, shiftX); 23266 } 23267 23268 } else if (!lineType.from_start && !lineType.to_start) { 23269 this.point_to(dir.right, shiftX); 23270 if (forward) { 23271 this.point_to(dir.right, dx); 23272 this.point_to(dir.down, dy); 23273 } else { 23274 this.point_to(dir.down, dy); 23275 this.point_to(dir.right, dx); 23276 } 23277 this.point_to(dir.left, shiftX); 23278 } else if (lineType.from_start && !lineType.to_start) { 23279 23280 forward = (pt.e_x > (pt.x - 2 * shiftX)); 23281 this.point_to(dir.left, shiftX); 23282 23283 if (!forward) { 23284 dx += shiftX; 23285 this.point_to(dir.down, dy); 23286 this.point_to(dir.right, dx); 23287 } else { 23288 dx += 2 * shiftX; 23289 var sign = dy > 0 ? 1 : -1; 23290 this.point_to(dir.down, sign * (xy.row_height / 2)); 23291 this.point_to(dir.right, dx); 23292 this.point_to(dir.down, sign * ( Math.abs(dy) - (xy.row_height / 2))); 23293 this.point_to(dir.left, shiftX); 23294 } 23295 23296 } 23297 23298 return this.path; 23299 }, 23300 get_line_type: function(link, config){ 23301 var types = config.links; 23302 var from_start = false, to_start = false; 23303 if (link.type == types.start_to_start) { 23304 from_start = to_start = true; 23305 } else if (link.type == types.finish_to_finish) { 23306 from_start = to_start = false; 23307 } else if (link.type == types.finish_to_start) { 23308 from_start = false; 23309 to_start = true; 23310 } else if (link.type == types.start_to_finish) { 23311 from_start = true; 23312 to_start = false; 23313 } else { 23314 gantt.assert(false, "Invalid link type"); 23315 } 23316 23317 if(config.rtl){ 23318 from_start = !from_start; 23319 to_start = !to_start; 23320 } 23321 23322 return {from_start: from_start, to_start: to_start}; 23323 }, 23324 23325 get_endpoint: function (link, view) { 23326 var config = view.$getConfig(); 23327 23328 var lineType = this.get_line_type(link, config); 23329 var from_start = lineType.from_start, 23330 to_start = lineType.to_start; 23331 23332 var source = gantt.getTask(link.source); 23333 var target = gantt.getTask(link.target); 23334 23335 var from = getMilestonePosition(source, view), 23336 to = getMilestonePosition(target, view); 23337 23338 return { 23339 x: from_start ? from.left : (from.left + from.width), 23340 e_x: to_start ? to.left : (to.left + to.width), 23341 y: from.top, 23342 e_y: to.top 23343 }; 23344 } 23345}; 23346 23347function getMilestonePosition(task, view){ 23348 var config = view.$getConfig(); 23349 var pos = view.getItemPosition(task); 23350 if(gantt.getTaskType(task.type) == config.types.milestone){ 23351 var milestoneHeight = gantt.getTaskHeight(); 23352 var milestoneWidth = Math.sqrt(2*milestoneHeight*milestoneHeight); 23353 pos.left -= milestoneWidth / 2; 23354 pos.width = milestoneWidth; 23355 } 23356 return pos; 23357} 23358 23359 23360return { 23361 render: _render_link_element, 23362 update: null, 23363 getRectangle: getLinkRectangle 23364}; 23365} 23366 23367module.exports = createLinkRender; 23368 23369/***/ }), 23370 23371/***/ "./sources/core/ui/render/render_factory.js": 23372/*!**************************************************!*\ 23373 !*** ./sources/core/ui/render/render_factory.js ***! 23374 \**************************************************/ 23375/*! no static exports found */ 23376/***/ (function(module, exports, __webpack_require__) { 23377 23378var isInViewPort = __webpack_require__(/*! ./viewport/is_in_viewport */ "./sources/core/ui/render/viewport/is_in_viewport.js"); 23379var isLegacyRender = __webpack_require__(/*! ./is_legacy_smart_render */ "./sources/core/ui/render/is_legacy_smart_render.js"); 23380var basicGetRectangle = __webpack_require__(/*! ./viewport/get_grid_row_rectangle */ "./sources/core/ui/render/viewport/get_grid_row_rectangle.js"); 23381var rendererFactory = function(gantt){ 23382 var services = gantt.$services; 23383 23384 //hash of dom elements is needed to redraw single bar/link 23385 var task_area_pulls = {}, 23386 task_area_renderers = {}; 23387 23388 function getView(layer){ 23389 var view = null; 23390 if (typeof layer.view === "string") { 23391 view = gantt.$ui.getView(layer.view); 23392 } else if (layer.view) { 23393 view = layer.view; 23394 } 23395 return view; 23396 } 23397 23398 function getRenderer(id, layer, node) { 23399 23400 if (task_area_renderers[id]) 23401 return task_area_renderers[id]; 23402 23403 if (!layer.renderer) 23404 gantt.assert(false, "Invalid renderer call"); 23405 23406 var renderMethod = null; 23407 var updateMethod = null; 23408 var getRectangle = null; 23409 23410 if(typeof layer.renderer === "function"){ 23411 renderMethod = layer.renderer; 23412 getRectangle = basicGetRectangle; 23413 }else{ 23414 renderMethod = layer.renderer.render; 23415 updateMethod = layer.renderer.update; 23416 getRectangle = layer.renderer.getRectangle; 23417 if (!getRectangle && getRectangle !== null) { 23418 getRectangle = basicGetRectangle; 23419 } 23420 } 23421 23422 var filter = layer.filter; 23423 23424 if (node) 23425 node.setAttribute(services.config().layer_attribute, true); 23426 23427 task_area_renderers[id] = { 23428 render_item: function (item, container, viewPort) { 23429 container = container || node; 23430 23431 if (filter) { 23432 if (!filter(item)) { 23433 this.remove_item(item.id); 23434 return; 23435 } 23436 } 23437 23438 var view = getView(layer); 23439 var rendererViewPort = viewPort; 23440 if(!rendererViewPort && view && view.$getConfig().smart_rendering){ 23441 rendererViewPort = view.getViewPort(); 23442 } 23443 23444 var dom = null; 23445 if(!isLegacyRender(gantt) && getRectangle && rendererViewPort){ 23446 if(isInViewPort(rendererViewPort, getRectangle(item, view, gantt))){ 23447 dom = renderMethod.call(gantt, item, view, rendererViewPort); 23448 } 23449 }else{ 23450 dom = renderMethod.call(gantt, item, view, rendererViewPort); 23451 } 23452 this.append(item, dom, container); 23453 }, 23454 23455 clear: function (container) { 23456 23457 this.rendered = task_area_pulls[id] = {}; 23458 if(!layer.append) 23459 this.clear_container(container); 23460 }, 23461 clear_container: function (container) { 23462 container = container || node; 23463 if (container) 23464 container.innerHTML = ""; 23465 }, 23466 render_items: function (items, container) { 23467 container = container || node; 23468 23469 var buffer = document.createDocumentFragment(); 23470 this.clear(container); 23471 23472 var viewPort = null; 23473 var view = getView(layer); 23474 if(view && view.$getConfig().smart_rendering){ 23475 viewPort = view.getViewPort(); 23476 } 23477 23478 for (var i = 0, vis = items.length; i < vis; i++) { 23479 this.render_item(items[i], buffer, viewPort); 23480 } 23481 23482 container.appendChild(buffer, container); 23483 }, 23484 update_items: function (items, container) { 23485 var view = getView(layer); 23486 if(!view || !view.$getConfig().smart_rendering || isLegacyRender(gantt)){ 23487 return; 23488 } 23489 23490 if(!this.rendered){ 23491 return; 23492 } 23493 23494 if(!getRectangle){ 23495 return; 23496 } 23497 23498 container = container || node; 23499 23500 var buffer = document.createDocumentFragment(); 23501 23502 var viewPort = null; 23503 if(view){ 23504 viewPort = view.getViewPort(); 23505 } 23506 23507 for (var i = 0, vis = items.length; i < vis; i++) { 23508 var item = items[i]; 23509 var itemNode = this.rendered[item.id]; 23510 if (itemNode && itemNode.parentNode) { 23511 if (!isInViewPort(viewPort, getRectangle(item, view, gantt))) { 23512 this.hide(item.id); 23513 } else { 23514 if(updateMethod){ 23515 updateMethod.call(gantt, item, itemNode, view, viewPort); 23516 } 23517 this.restore(item); 23518 } 23519 } else { 23520 this.render_item(items[i], buffer, viewPort); 23521 } 23522 } 23523 if(buffer.childNodes.length){ 23524 container.appendChild(buffer, container); 23525 } 23526 }, 23527 append: function (item, node, container) { 23528 if(!this.rendered){ 23529 return; 23530 } 23531 23532 if (!node) { 23533 if (this.rendered[item.id]) { 23534 this.remove_item(item.id); 23535 } 23536 return; 23537 } 23538 23539 if (this.rendered[item.id] && this.rendered[item.id].parentNode) { 23540 this.replace_item(item.id, node); 23541 } else { 23542 container.appendChild(node); 23543 } 23544 this.rendered[item.id] = node; 23545 23546 }, 23547 replace_item: function (item_id, newNode) { 23548 var item = this.rendered[item_id]; 23549 if (item && item.parentNode) { 23550 item.parentNode.replaceChild(newNode, item); 23551 } 23552 this.rendered[item_id] = newNode; 23553 }, 23554 remove_item: function (item_id) { 23555 this.hide(item_id); 23556 delete this.rendered[item_id]; 23557 }, 23558 hide: function (item_id) { 23559 var item = this.rendered[item_id]; 23560 if (item && item.parentNode) { 23561 item.parentNode.removeChild(item); 23562 } 23563 }, 23564 restore: function (item) { 23565 var dom = this.rendered[item.id]; 23566 if (dom) { 23567 if (!dom.parentNode) { 23568 this.append(item, dom, node); 23569 } 23570 } else { 23571 this.render_item(item, node); 23572 } 23573 }, 23574 change_id: function (oldid, newid) { 23575 this.rendered[newid] = this.rendered[oldid]; 23576 delete this.rendered[oldid]; 23577 }, 23578 rendered: task_area_pulls[id], 23579 node: node, 23580 destructor: function () { 23581 this.clear(); 23582 delete task_area_renderers[id]; 23583 delete task_area_pulls[id]; 23584 } 23585 }; 23586 23587 return task_area_renderers[id]; 23588 } 23589 23590 23591 function clearRenderers() { 23592 for (var i in task_area_renderers) { 23593 getRenderer(i).destructor(); 23594 } 23595 } 23596 23597 return { 23598 getRenderer: getRenderer, 23599 clearRenderers: clearRenderers 23600 }; 23601 23602}; 23603 23604module.exports = rendererFactory; 23605 23606/***/ }), 23607 23608/***/ "./sources/core/ui/render/task_bar_render.js": 23609/*!***************************************************!*\ 23610 !*** ./sources/core/ui/render/task_bar_render.js ***! 23611 \***************************************************/ 23612/*! no static exports found */ 23613/***/ (function(module, exports) { 23614 23615function createTaskRenderer(gantt) { 23616 23617 function _render_task_element(task, view) { 23618 var config = view.$getConfig(); 23619 var painters = config.type_renderers; 23620 var renderer = painters[gantt.getTaskType(task.type)], 23621 defaultRenderer = _task_default_render; 23622 23623 if (!renderer) { 23624 return defaultRenderer.call(gantt, task, view); 23625 }else{ 23626 return renderer.call(gantt, task, function(task){ return defaultRenderer.call(gantt, task, view);}, view); 23627 } 23628 } 23629 23630 function _task_default_render(task, view) { 23631 if (gantt._isAllowedUnscheduledTask(task)) 23632 return; 23633 23634 if (!gantt._isTaskInTimelineLimits(task)) { 23635 return; 23636 } 23637 23638 var pos = view.getItemPosition(task); 23639 23640 var cfg = view.$getConfig(), 23641 templates = view.$getTemplates(); 23642 var height = view.getItemHeight(); 23643 23644 var taskType = gantt.getTaskType(task.type); 23645 23646 var padd = Math.floor((gantt.config.row_height - height) / 2); 23647 if (taskType == cfg.types.milestone && cfg.link_line_width > 1) { 23648 //little adjust milestone position, so horisontal corners would match link arrow when thickness of link line is more than 1px 23649 padd += 1; 23650 } 23651 23652 if (taskType == cfg.types.milestone) { 23653 pos.left -= Math.round(height / 2); 23654 pos.width = height; 23655 } 23656 23657 var div = document.createElement("div"); 23658 23659 var width = Math.round(pos.width); 23660 23661 if(view.$config.item_attribute) { 23662 div.setAttribute(view.$config.item_attribute, task.id); 23663 } 23664 23665 if (cfg.show_progress && taskType != cfg.types.milestone) { 23666 _render_task_progress(task, div, width, cfg, templates); 23667 } 23668 23669 //use separate div to display content above progress bar 23670 var content = _render_task_content(task, width, templates); 23671 if (task.textColor) { 23672 content.style.color = task.textColor; 23673 } 23674 div.appendChild(content); 23675 23676 var css = _combine_item_class("gantt_task_line", 23677 templates.task_class(task.start_date, task.end_date, task), 23678 task.id, 23679 view); 23680 if (task.color || task.progressColor || task.textColor) { 23681 css += " gantt_task_inline_color"; 23682 } 23683 div.className = css; 23684 23685 var styles = [ 23686 "left:" + pos.left + "px", 23687 "top:" + (padd + pos.top) + 'px', 23688 "height:" + height + 'px', 23689 "line-height:" + (Math.max(height < 30 ? height - 2 : height, 0)) + 'px', 23690 "width:" + width + 'px' 23691 ]; 23692 if (task.color) { 23693 styles.push("background-color:" + task.color); 23694 } 23695 if (task.textColor) { 23696 styles.push("color:" + task.textColor); 23697 } 23698 23699 div.style.cssText = styles.join(";"); 23700 var side = _render_leftside_content(task, cfg, templates); 23701 if (side) div.appendChild(side); 23702 23703 side = _render_rightside_content(task, cfg, templates); 23704 if (side) div.appendChild(side); 23705 23706 gantt._waiAria.setTaskBarAttr(task, div); 23707 23708 var state = gantt.getState(); 23709 23710 if (!gantt.isReadonly(task)) { 23711 if (cfg.drag_resize && !gantt.isSummaryTask(task) && taskType != cfg.types.milestone) { 23712 _render_pair(div, "gantt_task_drag", task, function (css) { 23713 var el = document.createElement("div"); 23714 el.className = css; 23715 return el; 23716 }, cfg); 23717 } 23718 if (cfg.drag_links && cfg.show_links) { 23719 _render_pair(div, "gantt_link_control", task, function (css) { 23720 var outer = document.createElement("div"); 23721 outer.className = css; 23722 outer.style.cssText = [ 23723 "height:" + height + 'px', 23724 "line-height:" + height + 'px' 23725 ].join(";"); 23726 var inner = document.createElement("div"); 23727 inner.className = "gantt_link_point"; 23728 23729 var showLinkPoints = false; 23730 if(state.link_source_id && cfg.touch){ 23731 showLinkPoints = true; 23732 } 23733 23734 inner.style.display = showLinkPoints ? "block" : ""; 23735 outer.appendChild(inner); 23736 return outer; 23737 }, cfg); 23738 } 23739 } 23740 return div; 23741 } 23742 23743 function _render_side_content(task, template, cssClass) { 23744 if (!template) return null; 23745 23746 var text = template(task.start_date, task.end_date, task); 23747 if (!text) return null; 23748 var content = document.createElement("div"); 23749 content.className = "gantt_side_content " + cssClass; 23750 content.innerHTML = text; 23751 return content; 23752 } 23753 23754 function _render_leftside_content(task, cfg, templates) { 23755 var css = "gantt_left " + _get_link_crossing_css(!cfg.rtl ? true : false, task, cfg); 23756 return _render_side_content(task, templates.leftside_text, css); 23757 } 23758 23759 function _render_rightside_content(task, cfg, templates) { 23760 var css = "gantt_right " + _get_link_crossing_css(!cfg.rtl ? false : true, task, cfg); 23761 return _render_side_content(task, templates.rightside_text, css); 23762 } 23763 23764 function _get_link_crossing_css(left, task) { 23765 var cond = _get_conditions(left); 23766 23767 for (var i in cond) { 23768 var links = task[i]; 23769 for (var ln = 0; ln < links.length; ln++) { 23770 var link = gantt.getLink(links[ln]); 23771 23772 for (var tp = 0; tp < cond[i].length; tp++) { 23773 if (link.type == cond[i][tp]) { 23774 return "gantt_link_crossing"; 23775 } 23776 } 23777 } 23778 } 23779 return ""; 23780 } 23781 23782 23783 function _render_task_content(task, width, templates) { 23784 var content = document.createElement("div"); 23785 if (gantt.getTaskType(task.type) != gantt.config.types.milestone) 23786 content.innerHTML = templates.task_text(task.start_date, task.end_date, task); 23787 content.className = "gantt_task_content"; 23788 //content.style.width = width + 'px'; 23789 return content; 23790 } 23791 23792 function _render_task_progress(task, element, maxWidth, cfg, templates) { 23793 var done = task.progress * 1 || 0; 23794 23795 maxWidth = Math.max(maxWidth - 2, 0);//2px for borders 23796 var pr = document.createElement("div"); 23797 var width = Math.round(maxWidth * done); 23798 23799 width = Math.min(maxWidth, width); 23800 if (task.progressColor) { 23801 pr.style.backgroundColor = task.progressColor; 23802 pr.style.opacity = 1; 23803 } 23804 pr.style.width = width + 'px'; 23805 pr.className = "gantt_task_progress"; 23806 pr.innerHTML = templates.progress_text(task.start_date, task.end_date, task); 23807 23808 if(cfg.rtl){ 23809 pr.style.position = "absolute"; 23810 pr.style.right = "0px"; 23811 } 23812 23813 var wrapper = document.createElement("div"); 23814 wrapper.className = "gantt_task_progress_wrapper"; 23815 wrapper.appendChild(pr); 23816 element.appendChild(wrapper); 23817 23818 if (gantt.config.drag_progress && !gantt.isReadonly(task)) { 23819 var drag = document.createElement("div"); 23820 23821 var markerPos = width; 23822 if(cfg.rtl){ 23823 markerPos = maxWidth - width; 23824 } 23825 23826 drag.style.left = markerPos + 'px'; 23827 drag.className = "gantt_task_progress_drag"; 23828 pr.appendChild(drag); 23829 element.appendChild(drag); 23830 } 23831 } 23832 23833 function _get_conditions(leftside) { 23834 if (leftside) { 23835 return { 23836 $source: [ 23837 gantt.config.links.start_to_start 23838 ], 23839 $target: [ 23840 gantt.config.links.start_to_start, 23841 gantt.config.links.finish_to_start 23842 ] 23843 }; 23844 } else { 23845 return { 23846 $source: [ 23847 gantt.config.links.finish_to_start, 23848 gantt.config.links.finish_to_finish 23849 ], 23850 $target: [ 23851 gantt.config.links.finish_to_finish 23852 ] 23853 }; 23854 } 23855 } 23856 23857 function _combine_item_class(basic, template, itemId, view) { 23858 var cfg = view.$getConfig(); 23859 var css = [basic]; 23860 if (template) 23861 css.push(template); 23862 23863 var state = gantt.getState(); 23864 23865 var task = gantt.getTask(itemId); 23866 23867 if (gantt.getTaskType(task.type) == cfg.types.milestone) { 23868 css.push("gantt_milestone"); 23869 }else if (gantt.getTaskType(task.type) == cfg.types.project) { 23870 css.push("gantt_project"); 23871 } 23872 23873 css.push("gantt_bar_" + gantt.getTaskType(task.type)); 23874 23875 23876 if (gantt.isSummaryTask(task)) 23877 css.push("gantt_dependent_task"); 23878 23879 if (gantt.isSplitTask(task) && ((cfg.open_split_tasks && !task.$open) || !cfg.open_split_tasks)) { 23880 css.push("gantt_split_parent"); 23881 } 23882 23883 if (cfg.select_task && gantt.isSelectedTask(itemId)) { 23884 css.push("gantt_selected"); 23885 } 23886 23887 if (itemId == state.drag_id) { 23888 css.push("gantt_drag_" + state.drag_mode); 23889 if (state.touch_drag) { 23890 css.push("gantt_touch_" + state.drag_mode); 23891 } 23892 } 23893 23894 if (state.link_source_id == itemId) 23895 css.push("gantt_link_source"); 23896 23897 if (state.link_target_id == itemId) 23898 css.push("gantt_link_target"); 23899 23900 23901 if (cfg.highlight_critical_path && gantt.isCriticalTask) { 23902 if (gantt.isCriticalTask(task)) 23903 css.push("gantt_critical_task"); 23904 } 23905 23906 if (state.link_landing_area && 23907 (state.link_target_id && state.link_source_id) && 23908 (state.link_target_id != state.link_source_id)) { 23909 23910 var from_id = state.link_source_id; 23911 var from_start = state.link_from_start; 23912 var to_start = state.link_to_start; 23913 23914 var allowDrag = gantt.isLinkAllowed(from_id, itemId, from_start, to_start); 23915 23916 var dragClass = ""; 23917 if (allowDrag) { 23918 if (to_start) 23919 dragClass = "link_start_allow"; 23920 else 23921 dragClass = "link_finish_allow"; 23922 } else { 23923 if (to_start) 23924 dragClass = "link_start_deny"; 23925 else 23926 dragClass = "link_finish_deny"; 23927 } 23928 css.push(dragClass); 23929 } 23930 return css.join(" "); 23931 } 23932 23933 function _render_pair(parent, css, task, content, config) { 23934 var state = gantt.getState(); 23935 var className, element; 23936 if (+task.start_date >= +state.min_date) { 23937 className = [css, config.rtl ? "task_right" : "task_left", "task_start_date"]; 23938 element = content(className.join(" ")); 23939 element.setAttribute("data-bind-property", "start_date"); 23940 parent.appendChild(element); 23941 } 23942 23943 if (+task.end_date <= +state.max_date){ 23944 className = [css, config.rtl ? "task_left" : "task_right", "task_end_date"]; 23945 element = content(className.join(" ")); 23946 element.setAttribute("data-bind-property", "end_date"); 23947 parent.appendChild(element); 23948 } 23949 23950 } 23951 23952 return _render_task_element; 23953} 23954 23955module.exports = createTaskRenderer; 23956 23957/***/ }), 23958 23959/***/ "./sources/core/ui/render/task_bar_smart_render.js": 23960/*!*********************************************************!*\ 23961 !*** ./sources/core/ui/render/task_bar_smart_render.js ***! 23962 \*********************************************************/ 23963/*! no static exports found */ 23964/***/ (function(module, exports, __webpack_require__) { 23965 23966var getBarRectangle = __webpack_require__(/*! ./viewport/get_bar_rectangle */ "./sources/core/ui/render/viewport/get_bar_rectangle.js"); 23967var createBaseBarRender = __webpack_require__(/*! ./task_bar_render */ "./sources/core/ui/render/task_bar_render.js"); 23968 23969module.exports = function createTaskRenderer(gantt){ 23970 var defaultRender = createBaseBarRender(gantt); 23971 return { 23972 render: defaultRender, 23973 update: null, 23974 getRectangle: getBarRectangle 23975 }; 23976}; 23977 23978/***/ }), 23979 23980/***/ "./sources/core/ui/render/task_bg_render.js": 23981/*!**************************************************!*\ 23982 !*** ./sources/core/ui/render/task_bg_render.js ***! 23983 \**************************************************/ 23984/*! no static exports found */ 23985/***/ (function(module, exports, __webpack_require__) { 23986 23987var getRowRectangle = __webpack_require__(/*! ./viewport/get_bg_row_rectangle */ "./sources/core/ui/render/viewport/get_bg_row_rectangle.js"); 23988var isLegacyRender = __webpack_require__(/*! ./is_legacy_smart_render */ "./sources/core/ui/render/is_legacy_smart_render.js"); 23989function getIndexRange(scale, viewportLeft, viewPortRight){ 23990 var firstCellIndex = 0; 23991 var lastCellIndex = scale.left.length - 1; 23992 for(var i = 0; i < scale.left.length; i++){ 23993 var left = scale.left[i]; 23994 if(left < viewportLeft){ 23995 firstCellIndex = i; 23996 } 23997 if(left > viewPortRight){ 23998 lastCellIndex = i; 23999 break; 24000 } 24001 } 24002 return { 24003 start: firstCellIndex, 24004 end: lastCellIndex 24005 }; 24006} 24007 24008function createTaskBgRender(gantt){ 24009 var renderedCells = {}; 24010 var visibleCells = {}; 24011 24012 function isRendered(item, columnIndex){ 24013 if(renderedCells[item.id][columnIndex] && renderedCells[item.id][columnIndex].parentNode){ 24014 return true; 24015 }else{ 24016 return false; 24017 } 24018 } 24019 24020 function detachRenderedCell(itemId, columnIndex){ 24021 if(renderedCells[itemId] && renderedCells[itemId][columnIndex] && 24022 renderedCells[itemId][columnIndex].parentNode 24023 ){ 24024 renderedCells[itemId][columnIndex].parentNode.removeChild(renderedCells[itemId][columnIndex]); 24025 } 24026 } 24027 24028 function getCellTemplate(view){ 24029 var templates = view.$getTemplates(); 24030 var cssTemplate; 24031 if (typeof templates.task_cell_class !== "undefined") { 24032 cssTemplate = templates.task_cell_class; 24033 // eslint-disable-next-line no-console 24034 var log = console.warn || console.log; 24035 log('gantt.templates.task_cell_class template is deprecated and will be removed soon. Please use gantt.templates.timeline_cell_class instead.'); 24036 } else { 24037 cssTemplate = templates.timeline_cell_class; 24038 } 24039 return cssTemplate; 24040 } 24041 24042 function renderCells(item, node, view, viewPort){ 24043 var config = view.$getConfig(); 24044 var cfg = view.getScale(); 24045 var count = cfg.count; 24046 var cssTemplate = getCellTemplate(view); 24047 24048 if (config.show_task_cells) { 24049 if(!renderedCells[item.id]){ 24050 renderedCells[item.id] = {}; 24051 } 24052 if(!visibleCells[item.id]){ 24053 visibleCells[item.id] = {}; 24054 } 24055 24056 var range = getIndexRange(cfg, viewPort.x, viewPort.x_end); 24057 24058 for(var i in visibleCells[item.id]){ 24059 var index = visibleCells[item.id][i]; 24060 24061 if(Number(index) < range.start || Number(index) > range.end){ 24062 detachRenderedCell(item.id, index); 24063 } 24064 } 24065 visibleCells[item.id] = {}; 24066 // TODO: do not iterate all cell, only ones in the viewport and once that are already rendered 24067 for (var columnIndex = range.start; columnIndex <= range.end; columnIndex++) { 24068 var cell = renderOneCell(cfg, columnIndex, item, viewPort, count, cssTemplate, config); 24069 if(!cell && isRendered(item, columnIndex)){ 24070 detachRenderedCell(item.id, columnIndex); 24071 }else if (cell && !cell.parentNode){ 24072 node.appendChild(cell); 24073 } 24074 } 24075 } 24076 } 24077 24078 function isColumnVisible(columnIndex, scale, viewPort){ 24079 var width = scale.width[columnIndex]; 24080 if(width <= 0){ 24081 return false; 24082 } 24083 if(!gantt.config.smart_rendering || isLegacyRender(gantt)){ 24084 return true; 24085 } 24086 var cellLeftCoord = scale.left[columnIndex] - width; 24087 var cellRightCoord = scale.left[columnIndex] + width; 24088 return (cellLeftCoord <= viewPort.x_end && cellRightCoord >= viewPort.x);//do not render skipped columns 24089 } 24090 24091 function renderOneCell(scale, columnIndex, item, viewPort, count, cssTemplate, config){ 24092 var width = scale.width[columnIndex], 24093 cssclass = ""; 24094 24095 if (isColumnVisible(columnIndex, scale, viewPort)) {//do not render skipped columns 24096 24097 var cssTemplateContent = cssTemplate(item, scale.trace_x[columnIndex]); 24098 24099 if(config.static_background){ 24100 // if cell render in static background is not allowed, or if it's a blank cell 24101 if(!(config.static_background_cells && cssTemplateContent)){ 24102 return null; 24103 } 24104 } 24105 24106 if(renderedCells[item.id][columnIndex]){ 24107 visibleCells[item.id][columnIndex] = columnIndex; 24108 return renderedCells[item.id][columnIndex]; 24109 } 24110 var cell = document.createElement("div"); 24111 cell.style.width = (width) + "px"; 24112 24113 cssclass = "gantt_task_cell" + (columnIndex == count - 1 ? " gantt_last_cell" : ""); 24114 if (cssTemplateContent) { 24115 cssclass += " " + cssTemplateContent; 24116 } 24117 cell.className = cssclass; 24118 24119 cell.style.position = "absolute"; 24120 cell.style.left = scale.left[columnIndex] + "px"; 24121 renderedCells[item.id][columnIndex] = cell; 24122 visibleCells[item.id][columnIndex] = columnIndex; 24123 24124 return cell; 24125 } 24126 return null; 24127 } 24128 24129 function _render_bg_line(item, view, viewPort) { 24130 var config = view.$getConfig(), 24131 templates = view.$getTemplates(); 24132 var cfg = view.getScale(); 24133 var count = cfg.count; 24134 24135 if(config.static_background && !config.static_background_cells){ 24136 return null; 24137 } 24138 24139 var row = document.createElement("div"); 24140 24141 var cellTemplate = getCellTemplate(view); 24142 24143 var range; 24144 24145 if(!viewPort || !config.smart_rendering || isLegacyRender(gantt)){ 24146 range = { 24147 start: 0, 24148 end: count - 1 24149 }; 24150 } else { 24151 range = getIndexRange(cfg, viewPort.x, viewPort.x_end); 24152 } 24153 if (config.show_task_cells) { 24154 renderedCells[item.id] = {}; 24155 visibleCells[item.id] = {}; 24156 for (var columnIndex = range.start; columnIndex <= range.end; columnIndex++) { 24157 var cell = renderOneCell(cfg, columnIndex, item, viewPort, count, cellTemplate, config); 24158 if(cell){ 24159 row.appendChild(cell); 24160 } 24161 } 24162 } 24163 var odd = gantt.getGlobalTaskIndex(item.id) % 2 !== 0; 24164 var cssTemplate = templates.task_row_class(item.start_date, item.end_date, item); 24165 var css = "gantt_task_row" + (odd ? " odd" : "") + (cssTemplate ? ' ' + cssTemplate : ''); 24166 24167 var store = view.$config.rowStore; 24168 if(store.isSelected(item.id)) { 24169 css += " gantt_selected"; 24170 } 24171 24172 row.className = css; 24173 24174 if (config.smart_rendering) { 24175 row.style.position = "absolute"; 24176 row.style.top = view.getItemTop(item.id) + "px"; 24177 row.style.width = "100%"; 24178 }else{ 24179 row.style.position = "relative"; 24180 } 24181 row.style.height = (config.row_height) + "px"; 24182 24183 if(view.$config.item_attribute){ 24184 row.setAttribute(view.$config.item_attribute, item.id); 24185 } 24186 24187 return row; 24188 } 24189 24190 return { 24191 render: _render_bg_line, 24192 update: renderCells, 24193 getRectangle: getRowRectangle 24194 }; 24195} 24196 24197module.exports = createTaskBgRender; 24198 24199 24200/***/ }), 24201 24202/***/ "./sources/core/ui/render/task_grid_line_render.js": 24203/*!*********************************************************!*\ 24204 !*** ./sources/core/ui/render/task_grid_line_render.js ***! 24205 \*********************************************************/ 24206/*! no static exports found */ 24207/***/ (function(module, exports, __webpack_require__) { 24208 24209var helpers = __webpack_require__(/*! ../../../utils/helpers */ "./sources/utils/helpers.js"); 24210var getRowRectangle = __webpack_require__(/*! ./viewport/get_grid_row_rectangle */ "./sources/core/ui/render/viewport/get_grid_row_rectangle.js"); 24211 24212function createGridLineRender(gantt){ 24213 24214 function _render_grid_item(item, view, viewport) { 24215 var columns = view.getGridColumns(); 24216 var config = view.$getConfig(), 24217 templates = view.$getTemplates(); 24218 24219 var store = view.$config.rowStore; 24220 24221 if(config.rtl){ 24222 columns = columns.reverse(); 24223 } 24224 24225 var cells = []; 24226 var has_child; 24227 for (var i = 0; i < columns.length; i++) { 24228 var last = i == columns.length - 1; 24229 var col = columns[i]; 24230 var cell; 24231 24232 var value; 24233 var textValue; 24234 if (col.name == "add") { 24235 var aria = gantt._waiAria.gridAddButtonAttrString(col); 24236 24237 value = "<div " + aria + " class='gantt_add'></div>"; 24238 textValue = ""; 24239 } else { 24240 if (col.template) 24241 value = col.template(item); 24242 else 24243 value = item[col.name]; 24244 24245 if (helpers.isDate(value)){ 24246 value = templates.date_grid(value, item, col.name); 24247 } 24248 24249 if (value === null || value === undefined) { 24250 value = ""; 24251 } 24252 24253 textValue = value; 24254 value = "<div class='gantt_tree_content'>" + value + "</div>"; 24255 } 24256 var css = "gantt_cell" + (last ? " gantt_last_cell" : ""); 24257 24258 var tree = []; 24259 if (col.tree) { 24260 for (var j = 0; j < item.$level; j++) 24261 tree.push(templates.grid_indent(item)); 24262 24263 has_child = store.hasChild(item.id) && !(gantt.isSplitTask(item) && !gantt.config.open_split_tasks); 24264 if (has_child) { 24265 tree.push(templates.grid_open(item)); 24266 tree.push(templates.grid_folder(item)); 24267 } else { 24268 tree.push(templates.grid_blank(item)); 24269 tree.push(templates.grid_file(item)); 24270 } 24271 } 24272 var style = "width:" + (col.width - (last ? 1 : 0)) + "px;"; 24273 if (this.defined(col.align)) 24274 style += "text-align:" + col.align + ";"; 24275 24276 var aria = gantt._waiAria.gridCellAttrString(col, textValue, item); 24277 24278 tree.push(value); 24279 if(config.rtl){ 24280 tree = tree.reverse(); 24281 } 24282 cell = "<div class='" + css + "' data-column-index='"+i+"' data-column-name='"+col.name+"' style='" + style + "' " + aria + ">" + tree.join("") + "</div>"; 24283 cells.push(cell); 24284 } 24285 var css = gantt.getGlobalTaskIndex(item.id) % 2 === 0 ? "" : " odd"; 24286 css += (item.$transparent) ? " gantt_transparent" : ""; 24287 24288 css += (item.$dataprocessor_class ? " " + item.$dataprocessor_class : ""); 24289 24290 if (templates.grid_row_class) { 24291 var css_template = templates.grid_row_class.call(gantt, item.start_date, item.end_date, item); 24292 if (css_template) 24293 css += " " + css_template; 24294 } 24295 24296 if(store.isSelected(item.id)) { 24297 css += " gantt_selected"; 24298 } 24299 24300 var el = document.createElement("div"); 24301 el.className = "gantt_row" + css + " gantt_row_" + gantt.getTaskType(item.type); 24302 var height = view.getItemHeight(); 24303 el.style.height = height + "px"; 24304 el.style.lineHeight = height + "px"; 24305 24306 if(config.smart_rendering){ 24307 el.style.position = "absolute"; 24308 el.style.left = "0px"; 24309 el.style.top = view.getItemTop(item.id) + "px"; 24310 } 24311 24312 if(view.$config.item_attribute){ 24313 el.setAttribute(view.$config.item_attribute, item.id); 24314 } 24315 24316 gantt._waiAria.taskRowAttr(item, el); 24317 24318 el.innerHTML = cells.join(""); 24319 return el; 24320 } 24321 24322 return { 24323 render: _render_grid_item, 24324 update: null, 24325 getRectangle: getRowRectangle 24326 }; 24327} 24328 24329module.exports = createGridLineRender; 24330 24331/***/ }), 24332 24333/***/ "./sources/core/ui/render/task_split_render.js": 24334/*!*****************************************************!*\ 24335 !*** ./sources/core/ui/render/task_split_render.js ***! 24336 \*****************************************************/ 24337/*! no static exports found */ 24338/***/ (function(module, exports, __webpack_require__) { 24339 24340var getBarRectangle = __webpack_require__(/*! ./viewport/get_bar_rectangle */ "./sources/core/ui/render/viewport/get_bar_rectangle.js"); 24341var createBaseBarRender = __webpack_require__(/*! ./task_bar_render */ "./sources/core/ui/render/task_bar_render.js"); 24342 24343function createTaskRenderer(gantt){ 24344 var defaultRender = createBaseBarRender(gantt); 24345 24346 function renderSplitTask(task, timeline) { 24347 if (gantt.isSplitTask(task) && ((gantt.config.open_split_tasks && !task.$open) || !gantt.config.open_split_tasks)) { 24348 var el = document.createElement('div'), 24349 sizes = gantt.getTaskPosition(task); 24350 24351 var sub_tasks = gantt.getChildren(task.id); 24352 24353 24354 for (var i = 0; i < sub_tasks.length; i++) { 24355 var child = gantt.getTask(sub_tasks[i]); 24356 24357 var element = defaultRender(child, timeline); 24358 if(!element) 24359 continue; 24360 24361 var padding = Math.floor((gantt.config.row_height - sizes.height) / 2); 24362 24363 element.style.top = (sizes.top + padding) + "px"; 24364 element.className += " gantt_split_child"; 24365 24366 el.appendChild(element); 24367 } 24368 return el; 24369 } 24370 return false; 24371 } 24372 return { 24373 render: renderSplitTask, 24374 update: null, 24375 getRectangle: getBarRectangle 24376 }; 24377} 24378 24379module.exports = createTaskRenderer; 24380 24381/***/ }), 24382 24383/***/ "./sources/core/ui/render/viewport/get_bar_rectangle.js": 24384/*!**************************************************************!*\ 24385 !*** ./sources/core/ui/render/viewport/get_bar_rectangle.js ***! 24386 \**************************************************************/ 24387/*! no static exports found */ 24388/***/ (function(module, exports) { 24389 24390module.exports = function(item, view){ 24391 if(!item.start_date || !item.end_date){ 24392 return null; 24393 } 24394 var padding = 200; 24395 var startCoord = view.posFromDate(item.start_date); 24396 var endCoord = view.posFromDate(item.end_date); 24397 var left = Math.min(startCoord, endCoord) - padding; 24398 var right = Math.max(startCoord, endCoord) + padding; 24399 var config = view.$getConfig(); 24400 return { 24401 top: view.getItemTop(item.id), 24402 height: config.row_height, 24403 left: left, 24404 width: right - left 24405 }; 24406}; 24407 24408/***/ }), 24409 24410/***/ "./sources/core/ui/render/viewport/get_bg_row_rectangle.js": 24411/*!*****************************************************************!*\ 24412 !*** ./sources/core/ui/render/viewport/get_bg_row_rectangle.js ***! 24413 \*****************************************************************/ 24414/*! no static exports found */ 24415/***/ (function(module, exports) { 24416 24417module.exports = function(item, view){ 24418 var config = view.$getConfig(); 24419 24420 return { 24421 top: view.getItemTop(item.id), 24422 height: config.row_height, 24423 left: 0, 24424 right: Infinity 24425 }; 24426}; 24427 24428/***/ }), 24429 24430/***/ "./sources/core/ui/render/viewport/get_grid_row_rectangle.js": 24431/*!*******************************************************************!*\ 24432 !*** ./sources/core/ui/render/viewport/get_grid_row_rectangle.js ***! 24433 \*******************************************************************/ 24434/*! no static exports found */ 24435/***/ (function(module, exports) { 24436 24437module.exports = function(item, view){ 24438 return { 24439 top: view.getItemTop(item.id), 24440 height: view.getItemHeight(item.id), 24441 left: 0, 24442 right: Infinity 24443 }; 24444}; 24445 24446/***/ }), 24447 24448/***/ "./sources/core/ui/render/viewport/get_link_rectangle.js": 24449/*!***************************************************************!*\ 24450 !*** ./sources/core/ui/render/viewport/get_link_rectangle.js ***! 24451 \***************************************************************/ 24452/*! no static exports found */ 24453/***/ (function(module, exports, __webpack_require__) { 24454 24455 24456 24457var barRectangle = __webpack_require__(/*! ./get_bar_rectangle */ "./sources/core/ui/render/viewport/get_bar_rectangle.js"); 24458 24459module.exports = function getLinkBox(item, view, gantt){ 24460 if(!gantt.isTaskExists(item.source)){ 24461 return null; 24462 } 24463 24464 if(!gantt.isTaskExists(item.target)){ 24465 return null; 24466 } 24467 var sourceBox = barRectangle(gantt.getTask(item.source), view, gantt); 24468 var targetBox = barRectangle(gantt.getTask(item.target), view, gantt); 24469 24470 if(!sourceBox || !targetBox){ 24471 return null; 24472 } 24473 24474 var padding = 100; 24475 var left = Math.min(sourceBox.left, targetBox.left) - padding; 24476 var right = Math.max(sourceBox.left + sourceBox.width, targetBox.left + targetBox.width) + padding; 24477 var top = Math.min(sourceBox.top, targetBox.top) - padding; 24478 var bottom = Math.max(sourceBox.top + sourceBox.height, targetBox.top + targetBox.height) + padding; 24479 24480 return { 24481 top: top, 24482 height: bottom - top, 24483 left: left, 24484 width: right - left 24485 }; 24486}; 24487 24488 24489/***/ }), 24490 24491/***/ "./sources/core/ui/render/viewport/is_in_viewport.js": 24492/*!***********************************************************!*\ 24493 !*** ./sources/core/ui/render/viewport/is_in_viewport.js ***! 24494 \***********************************************************/ 24495/*! no static exports found */ 24496/***/ (function(module, exports) { 24497 24498module.exports = function(viewport, box){ 24499 if(!box){ 24500 return false; 24501 } 24502 24503 if(box.left > viewport.x_end || box.left + box.width < viewport.x){ 24504 return false; 24505 } 24506 24507 if(box.top > viewport.y_end || box.top + box.height < viewport.y){ 24508 return false; 24509 } 24510 24511 return true; 24512}; 24513 24514/***/ }), 24515 24516/***/ "./sources/core/ui/row_position_mixin.js": 24517/*!***********************************************!*\ 24518 !*** ./sources/core/ui/row_position_mixin.js ***! 24519 \***********************************************/ 24520/*! no static exports found */ 24521/***/ (function(module, exports) { 24522 24523function createMixin(){ 24524 var topCache = {}; 24525 return { 24526 _resetTopPositionHeight: function(){ 24527 topCache = {}; 24528 }, 24529 24530 /** 24531 * Get top coordinate by row index (order) 24532 * @param {number} index 24533 */ 24534 getRowTop: function(index){ 24535 return index * this.$getConfig().row_height; 24536 }, 24537 24538 /** 24539 * Get top coordinate by item id 24540 * @param {*} task_id 24541 */ 24542 getItemTop: function (taskId) { 24543 if(this.$config.rowStore){ 24544 if(topCache[taskId] !== undefined){ 24545 return topCache[taskId]; 24546 } 24547 var store = this.$config.rowStore; 24548 if(!store) return 0; 24549 24550 var itemIndex = store.getIndexById(taskId); 24551 24552 if (itemIndex === -1 && store.getParent && store.exists(taskId)) { 24553 var parentId = store.getParent(taskId); 24554 if (store.exists(parentId)) { 24555 // if task is not found in list - maybe it's parent is a split task and we should use parents index instead 24556 var parent = store.getItem(parentId); 24557 if (this.$gantt.isSplitTask(parent)) { 24558 return this.getRowTop(store.getIndexById(parent.id)); 24559 } 24560 } 24561 } 24562 topCache[taskId] = this.getRowTop(itemIndex); 24563 return topCache[taskId]; 24564 }else{ 24565 return 0; 24566 } 24567 24568 } 24569 }; 24570} 24571 24572module.exports = createMixin; 24573 24574/***/ }), 24575 24576/***/ "./sources/core/ui/timeline/links_dnd.js": 24577/*!***********************************************!*\ 24578 !*** ./sources/core/ui/timeline/links_dnd.js ***! 24579 \***********************************************/ 24580/*! no static exports found */ 24581/***/ (function(module, exports, __webpack_require__) { 24582 24583var domHelpers = __webpack_require__(/*! ../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 24584 24585var initLinksDND = function(timeline, gantt) { 24586 var _link_landing, 24587 _link_target_task, 24588 _link_target_task_start, 24589 _link_source_task, 24590 _link_source_task_start, 24591 markerDefaultOffset = 10, 24592 scrollDefaultSize = 18; 24593 24594 24595 function getVisibleMilestoneWidth() { 24596 var origWidth = timeline.getItemHeight();//m-s have square shape 24597 return Math.round(Math.sqrt(2 * origWidth * origWidth)) - 2; 24598 } 24599 24600 function isMilestone(task) { 24601 return gantt.getTaskType(task.type) == gantt.config.types.milestone; 24602 } 24603 24604 function getDndState(){ 24605 return { 24606 link_source_id : _link_source_task, 24607 link_target_id : _link_target_task, 24608 link_from_start : _link_source_task_start, 24609 link_to_start : _link_target_task_start, 24610 link_landing_area : _link_landing 24611 }; 24612 } 24613 24614 var services = gantt.$services; 24615 24616 var state = services.getService("state"); 24617 var DnD = services.getService("dnd"); 24618 24619 state.registerProvider("linksDnD", getDndState); 24620 24621 var dnd = new DnD(timeline.$task_bars, { sensitivity : 0, updates_per_second : 60 }), 24622 start_marker = "task_start_date", 24623 end_marker = "task_end_date", 24624 link_edge_marker = "gantt_link_point", 24625 link_landing_hover_area = "gantt_link_control"; 24626 24627 dnd.attachEvent("onBeforeDragStart", gantt.bind(function(obj,e) { 24628 var target = (e.target||e.srcElement); 24629 resetDndState(); 24630 if(gantt.getState().drag_id) 24631 return false; 24632 24633 if(domHelpers.locateClassName(target, link_edge_marker)){ 24634 if(domHelpers.locateClassName(target, start_marker)) 24635 _link_source_task_start = true; 24636 24637 var sid = gantt.locate(e); 24638 _link_source_task = sid; 24639 24640 var t = gantt.getTask(sid); 24641 if(gantt.isReadonly(t)){ 24642 resetDndState(); 24643 return false; 24644 } 24645 24646 var shift = 0; 24647 24648 this._dir_start = getLinePos(t, !!_link_source_task_start, shift, timeline.$getConfig(), true); 24649 return true; 24650 }else{ 24651 return false; 24652 } 24653 24654 }, this)); 24655 24656 dnd.attachEvent("onAfterDragStart", gantt.bind(function(obj,e) { 24657 if(gantt.config.touch) { 24658 gantt.refreshData(); 24659 } 24660 updateMarkedHtml(dnd.config.marker); 24661 }, this)); 24662 24663 function getLinePos(task, to_start, shift, cfg, isStart){ 24664 var taskPos = getMilestonePosition(task, function(task){ return gantt.getTaskPosition(task);}, cfg); 24665 24666 var pos = {x: taskPos.x, y: taskPos.y}; 24667 if(!to_start){ 24668 pos.x = taskPos.xEnd; 24669 } 24670 24671 //var pos = gantt._get_task_pos(task, !!to_start); 24672 pos.y += gantt.config.row_height/2; 24673 24674 var offset = isMilestone(task) && isStart ? 2 : 0; 24675 24676 shift = shift || 0; 24677 if(cfg.rtl) 24678 shift = shift * -1; 24679 24680 pos.x += (to_start ? -1 : 1)*shift - offset; 24681 return pos; 24682 } 24683 24684 function getMilestonePosition(task, getTaskPosition, cfg){ 24685 var pos = getTaskPosition(task); 24686 24687 var res = { 24688 x: pos.left, 24689 y: pos.top, 24690 width: pos.width, 24691 height: pos.height 24692 }; 24693 24694 if(cfg.rtl){ 24695 res.xEnd = res.x; 24696 res.x = res.xEnd + res.width; 24697 }else{ 24698 res.xEnd = res.x + res.width; 24699 } 24700 res.yEnd = res.y + res.height; 24701 24702 if(gantt.getTaskType(task.type) == gantt.config.types.milestone){ 24703 var milestoneWidth = getVisibleMilestoneWidth(); 24704 24705 res.x += (!cfg.rtl ? -1 : 1)*(milestoneWidth / 2); 24706 res.xEnd += (!cfg.rtl ? 1 : -1)*(milestoneWidth / 2); 24707 24708 //pos.x -= milestoneWidth / 2; 24709 //pos.xEnd += milestoneWidth / 2; 24710 res.width = pos.xEnd - pos.x; 24711 } 24712 24713 24714 return res; 24715 } 24716 24717 function getVieportSize(){ 24718 var root = gantt.$root; 24719 return { right: root.offsetWidth, bottom: root.offsetHeight }; 24720 } 24721 function getMarkerSize (marker){ 24722 var width = 0, height = 0; 24723 if(marker){ 24724 width = marker.offsetWidth || 0; 24725 height = marker.offsetHeight || 0; 24726 } 24727 return { width: width, height: height }; 24728 } 24729 24730 function getPosition(e, marker){ 24731 var oldPos = dnd.getPosition(e); 24732 24733 var markerSize = getMarkerSize(marker); 24734 var viewportSize = getVieportSize(); 24735 24736 var offsetX = gantt.config.tooltip_offset_x || markerDefaultOffset; 24737 var offsetY = gantt.config.tooltip_offset_y || markerDefaultOffset; 24738 24739 var scrollSize = gantt.config.scroll_size || scrollDefaultSize; 24740 24741 var position = { 24742 y: oldPos.y + offsetY, 24743 x: oldPos.x + offsetX, 24744 bottom: oldPos.y + markerSize.height + offsetY + scrollSize, 24745 right: oldPos.x + markerSize.width + offsetX + scrollSize 24746 }; 24747 24748 if(position.bottom > viewportSize.bottom){ 24749 position.y = viewportSize.bottom - markerSize.height - offsetY; 24750 } 24751 24752 if(position.right > viewportSize.right){ 24753 position.x = viewportSize.right - markerSize.width - offsetX; 24754 } 24755 return position; 24756 } 24757 24758 dnd.attachEvent("onDragMove", gantt.bind(function(obj,e) { 24759 var dd = dnd.config; 24760 var pos = getPosition(e, dd.marker); 24761 advanceMarker(dd.marker, pos); 24762 var landing = !!domHelpers.locateClassName(e, link_landing_hover_area); 24763 24764 var prevTarget = _link_target_task; 24765 var prevLanding = _link_landing; 24766 var prevToStart = _link_target_task_start; 24767 24768 var targ = gantt.locate(e), 24769 to_start = true; 24770 24771 // can drag and drop link to another gantt on the page, such links are not supported 24772 var sameGantt = domHelpers.isChildOf(e.target || e.srcElement, gantt.$root); 24773 if(!sameGantt){ 24774 landing = false; 24775 targ = null; 24776 } 24777 24778 if(landing){ 24779 //refreshTask 24780 to_start = !domHelpers.locateClassName(e, end_marker); 24781 landing = !!targ; 24782 } 24783 24784 _link_target_task = targ; 24785 _link_landing = landing; 24786 _link_target_task_start = to_start; 24787 24788 if(landing){ 24789 var t = gantt.getTask(targ); 24790 24791 var config = timeline.$getConfig(); 24792 var node = domHelpers.locateClassName(e, link_landing_hover_area); 24793 var shift = 0; 24794 if(node){ 24795 shift = Math.floor(node.offsetWidth / 2); 24796 } 24797 24798 this._dir_end = getLinePos(t, !!_link_target_task_start,shift, config); 24799 }else{ 24800 this._dir_end = domHelpers.getRelativeEventPosition(e, timeline.$task_data); 24801 if(gantt.env.isEdge){ // to fix margin collapsing 24802 this._dir_end.y += window.scrollY; 24803 } 24804 } 24805 24806 var targetChanged = !(prevLanding == landing && prevTarget == targ && prevToStart == to_start); 24807 if(targetChanged){ 24808 if(prevTarget) 24809 gantt.refreshTask(prevTarget, false); 24810 if(targ) 24811 gantt.refreshTask(targ, false); 24812 } 24813 24814 if(targetChanged){ 24815 updateMarkedHtml(dd.marker); 24816 } 24817 24818 showDirectingLine(this._dir_start.x, this._dir_start.y, this._dir_end.x, this._dir_end.y); 24819 24820 return true; 24821 }, this)); 24822 24823 24824 dnd.attachEvent("onDragEnd", gantt.bind(function() { 24825 var drag = getDndState(); 24826 24827 if(drag.link_source_id && drag.link_target_id && drag.link_source_id != drag.link_target_id){ 24828 var type = gantt._get_link_type(drag.link_from_start, drag.link_to_start); 24829 24830 var link = {source : drag.link_source_id, target: drag.link_target_id, type:type}; 24831 if(link.type && gantt.isLinkAllowed(link)) { 24832 if(gantt.callEvent("onLinkCreated", [link])){ 24833 gantt.addLink(link); 24834 } 24835 } 24836 } 24837 24838 resetDndState(); 24839 24840 if(gantt.config.touch) { 24841 gantt.refreshData(); 24842 } 24843 else { 24844 if (drag.link_source_id) 24845 gantt.refreshTask(drag.link_source_id, false); 24846 if (drag.link_target_id) 24847 gantt.refreshTask(drag.link_target_id, false); 24848 } 24849 removeDirectionLine(); 24850 }, this)); 24851 24852 function updateMarkedHtml(marker){ 24853 var link = getDndState(); 24854 24855 var css = ["gantt_link_tooltip"]; 24856 if(link.link_source_id && link.link_target_id){ 24857 if(gantt.isLinkAllowed(link.link_source_id, link.link_target_id, link.link_from_start, link.link_to_start)){ 24858 css.push("gantt_allowed_link"); 24859 }else{ 24860 css.push("gantt_invalid_link"); 24861 } 24862 } 24863 24864 var className = gantt.templates.drag_link_class(link.link_source_id, link.link_from_start, link.link_target_id, link.link_to_start); 24865 if(className) 24866 css.push(className); 24867 24868 var html = "<div class='"+className+ "'>" + 24869 gantt.templates.drag_link(link.link_source_id, link.link_from_start, link.link_target_id, link.link_to_start) + 24870 "</div>"; 24871 marker.innerHTML = html; 24872 } 24873 24874 function advanceMarker(marker, pos){ 24875 marker.style.left = pos.x + "px"; 24876 marker.style.top = pos.y + "px"; 24877 } 24878 24879 function resetDndState(){ 24880 _link_source_task = 24881 _link_source_task_start = 24882 _link_target_task = null; 24883 _link_target_task_start = true; 24884 } 24885 function showDirectingLine(s_x, s_y, e_x, e_y){ 24886 var div = getDirectionLine(); 24887 24888 var link = getDndState(); 24889 24890 var css = ["gantt_link_direction"]; 24891 if(gantt.templates.link_direction_class){ 24892 css.push(gantt.templates.link_direction_class(link.link_source_id, link.link_from_start, link.link_target_id, link.link_to_start)); 24893 } 24894 24895 var dist =Math.sqrt( (Math.pow(e_x - s_x, 2)) + (Math.pow(e_y - s_y, 2)) ); 24896 dist = Math.max(0, dist - 3); 24897 if(!dist) 24898 return; 24899 24900 div.className = css.join(" "); 24901 var tan = (e_y - s_y)/(e_x - s_x), 24902 angle = Math.atan(tan); 24903 24904 if(coordinateCircleQuarter(s_x, e_x, s_y, e_y) == 2){ 24905 angle += Math.PI; 24906 }else if(coordinateCircleQuarter(s_x, e_x, s_y, e_y) == 3){ 24907 angle -= Math.PI; 24908 } 24909 24910 24911 24912 var sin = Math.sin(angle), 24913 cos = Math.cos(angle), 24914 top = Math.round(s_y), 24915 left = Math.round(s_x); 24916 24917 24918 var style = [ 24919 "-webkit-transform: rotate("+angle+"rad)", 24920 "-moz-transform: rotate("+angle+"rad)", 24921 "-ms-transform: rotate("+angle+"rad)", 24922 "-o-transform: rotate("+angle+"rad)", 24923 "transform: rotate("+angle+"rad)", 24924 "width:" + Math.round(dist) + "px" 24925 ]; 24926 24927 if(window.navigator.userAgent.indexOf("MSIE 8.0") != -1){ 24928 //ms-filter breaks styles in ie9, so add it only for 8th 24929 style.push("-ms-filter: \"" + ieTransform(sin, cos) + "\""); 24930 24931 var shiftLeft = Math.abs(Math.round(s_x - e_x)), 24932 shiftTop = Math.abs(Math.round(e_y - s_y)); 24933 //fix rotation axis 24934 switch(coordinateCircleQuarter(s_x, e_x, s_y, e_y)){ 24935 case 1: 24936 top -= shiftTop; 24937 break; 24938 case 2: 24939 left -= shiftLeft; 24940 top -= shiftTop; 24941 break; 24942 case 3: 24943 left -= shiftLeft; 24944 break; 24945 default: 24946 break; 24947 } 24948 24949 } 24950 24951 style.push("top:" + top + "px"); 24952 style.push("left:" + left + "px"); 24953 24954 div.style.cssText = style.join(";"); 24955 } 24956 24957 function ieTransform(sin, cos){ 24958 return "progid:DXImageTransform.Microsoft.Matrix("+ 24959 "M11 = "+cos+","+ 24960 "M12 = -"+sin+","+ 24961 "M21 = "+sin+","+ 24962 "M22 = "+cos+","+ 24963 "SizingMethod = 'auto expand'"+ 24964 ")"; 24965 } 24966 function coordinateCircleQuarter(sX, eX, sY, eY){ 24967 if(eX >= sX){ 24968 if(eY <= sY){ 24969 return 1; 24970 }else{ 24971 return 4; 24972 } 24973 }else{ 24974 if(eY <= sY){ 24975 return 2; 24976 }else{ 24977 return 3; 24978 } 24979 } 24980 24981 } 24982 function getDirectionLine(){ 24983 if(!dnd._direction || !dnd._direction.parentNode){ 24984 dnd._direction = document.createElement("div"); 24985 timeline.$task_links.appendChild(dnd._direction); 24986 } 24987 return dnd._direction; 24988 } 24989 function removeDirectionLine(){ 24990 if(dnd._direction){ 24991 if (dnd._direction.parentNode) //the event line can be detached because of data refresh 24992 dnd._direction.parentNode.removeChild(dnd._direction); 24993 24994 dnd._direction = null; 24995 } 24996 } 24997 gantt.attachEvent("onGanttRender", gantt.bind(function() { 24998 if(dnd._direction){ 24999 showDirectingLine(this._dir_start.x, this._dir_start.y, this._dir_end.x, this._dir_end.y); 25000 } 25001 }, this)); 25002}; 25003 25004module.exports = { 25005 createLinkDND: function(){ 25006 return { 25007 init: initLinksDND 25008 }; 25009 } 25010}; 25011 25012/***/ }), 25013 25014/***/ "./sources/core/ui/timeline/main_timeline_initializer.js": 25015/*!***************************************************************!*\ 25016 !*** ./sources/core/ui/timeline/main_timeline_initializer.js ***! 25017 \***************************************************************/ 25018/*! no static exports found */ 25019/***/ (function(module, exports, __webpack_require__) { 25020 25021var utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"), 25022 taskDnD = __webpack_require__(/*! ./tasks_dnd */ "./sources/core/ui/timeline/tasks_dnd.js"), 25023 linkDnD = __webpack_require__(/*! ./links_dnd */ "./sources/core/ui/timeline/links_dnd.js"), 25024 domHelpers = __webpack_require__(/*! ../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 25025 25026var initializer = (function(){ 25027 return function(gantt){ 25028 var services = gantt.$services; 25029 return { 25030 onCreated: function (timeline) { 25031 var config = timeline.$config; 25032 config.bind = utils.defined(config.bind) ? config.bind : "task"; 25033 config.bindLinks = utils.defined(config.bindLinks) ? config.bindLinks : "link"; 25034 25035 timeline._linksDnD = linkDnD.createLinkDND(); 25036 timeline._tasksDnD = taskDnD.createTaskDND(); 25037 timeline._tasksDnD.extend(timeline); 25038 25039 this._mouseDelegates = __webpack_require__(/*! ../mouse_event_container */ "./sources/core/ui/mouse_event_container.js")(gantt); 25040 }, 25041 onInitialized: function (timeline) { 25042 this._attachDomEvents(gantt); 25043 25044 this._attachStateProvider(gantt, timeline); 25045 25046 timeline._tasksDnD.init(timeline, gantt); 25047 timeline._linksDnD.init(timeline, gantt); 25048 25049 if(timeline.$config.id == "timeline"){ 25050 this.extendDom(timeline); 25051 } 25052 25053 }, 25054 onDestroyed: function (timeline) { 25055 this._clearDomEvents(gantt); 25056 this._clearStateProvider(gantt); 25057 if (timeline._tasksDnD) { 25058 timeline._tasksDnD.destructor(); 25059 } 25060 }, 25061 extendDom: function(timeline){ 25062 gantt.$task = timeline.$task; 25063 gantt.$task_scale = timeline.$task_scale; 25064 gantt.$task_data = timeline.$task_data; 25065 gantt.$task_bg = timeline.$task_bg; 25066 gantt.$task_links = timeline.$task_links; 25067 gantt.$task_bars = timeline.$task_bars; 25068 }, 25069 25070 _clearDomEvents: function(){ 25071 this._mouseDelegates.destructor(); 25072 this._mouseDelegates = null; 25073 }, 25074 25075 _attachDomEvents: function(gantt){ 25076 function _delete_link_handler(id, e) { 25077 if (id && this.callEvent("onLinkDblClick", [id, e])) { 25078 25079 var link = this.getLink(id); 25080 if (this.isReadonly(link)) return; 25081 25082 var title = ""; 25083 var question = this.locale.labels.link + " " + this.templates.link_description(this.getLink(id)) + " " + this.locale.labels.confirm_link_deleting; 25084 25085 window.setTimeout(function () { 25086 gantt._dhtmlx_confirm(question, title, function () { 25087 gantt.deleteLink(id); 25088 }); 25089 }, (this.config.touch ? 300 : 1)); 25090 } 25091 } 25092 25093 this._mouseDelegates.delegate("click", "gantt_task_link", gantt.bind(function (e, trg) { 25094 var id = this.locate(e, this.config.link_attribute); 25095 if (id) { 25096 this.callEvent("onLinkClick", [id, e]); 25097 } 25098 }, gantt), this.$task); 25099 25100 this._mouseDelegates.delegate("click", "gantt_scale_cell", gantt.bind(function (e, trg) { 25101 var pos = domHelpers.getRelativeEventPosition(e, gantt.$task_data); 25102 var date = gantt.dateFromPos(pos.x); 25103 var coll = Math.floor(gantt.columnIndexByDate(date)); 25104 25105 var coll_date = gantt.getScale().trace_x[coll]; 25106 25107 gantt.callEvent("onScaleClick", [e, coll_date]); 25108 }, gantt), this.$task); 25109 25110 this._mouseDelegates.delegate("doubleclick", "gantt_task_link", gantt.bind(function (e, id, trg) { 25111 var id = this.locate(e, gantt.config.link_attribute); 25112 _delete_link_handler.call(this, id, e); 25113 }, gantt), this.$task); 25114 25115 this._mouseDelegates.delegate("doubleclick", "gantt_link_point", gantt.bind(function (e, id, trg) { 25116 var id = this.locate(e), 25117 task = this.getTask(id); 25118 25119 var link = null; 25120 if (trg.parentNode && domHelpers.getClassName(trg.parentNode)) { 25121 if (domHelpers.getClassName(trg.parentNode).indexOf("_left") > -1) { 25122 link = task.$target[0]; 25123 } else { 25124 link = task.$source[0]; 25125 } 25126 } 25127 if (link) 25128 _delete_link_handler.call(this, link, e); 25129 return false; 25130 }, gantt), this.$task); 25131 }, 25132 25133 _attachStateProvider: function(gantt, timeline){ 25134 var self = timeline; 25135 var state = services.getService("state"); 25136 state.registerProvider("tasksTimeline", function(){ 25137 return { 25138 scale_unit: self._tasks ? self._tasks.unit : undefined, 25139 scale_step: self._tasks ? self._tasks.step : undefined 25140 }; 25141 }); 25142 }, 25143 25144 _clearStateProvider: function(){ 25145 var state = services.getService("state"); 25146 state.unregisterProvider("tasksTimeline"); 25147 } 25148 }; 25149 }; 25150 25151})(); 25152 25153module.exports = initializer; 25154 25155/***/ }), 25156 25157/***/ "./sources/core/ui/timeline/scales.js": 25158/*!********************************************!*\ 25159 !*** ./sources/core/ui/timeline/scales.js ***! 25160 \********************************************/ 25161/*! no static exports found */ 25162/***/ (function(module, exports, __webpack_require__) { 25163 25164var utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"); 25165 25166function ScaleHelper(gantt){ 25167 var dateHelper = gantt.date; 25168 var services = gantt.$services; 25169 25170 return { 25171 getSum: function (sizes, from, to) { 25172 if (to === undefined) 25173 to = sizes.length - 1; 25174 if (from === undefined) 25175 from = 0; 25176 25177 var summ = 0; 25178 for (var i = from; i <= to; i++) 25179 summ += sizes[i]; 25180 25181 return summ; 25182 }, 25183 setSumWidth: function (sum_width, scale, from, to) { 25184 var parts = scale.width; 25185 25186 if (to === undefined) 25187 to = parts.length - 1; 25188 if (from === undefined) 25189 from = 0; 25190 var length = to - from + 1; 25191 25192 if (from > parts.length - 1 || length <= 0 || to > parts.length - 1) 25193 return; 25194 25195 var oldWidth = this.getSum(parts, from, to); 25196 25197 var diff = sum_width - oldWidth; 25198 25199 this.adjustSize(diff, parts, from, to); 25200 this.adjustSize(-diff, parts, to + 1); 25201 25202 scale.full_width = this.getSum(parts); 25203 }, 25204 splitSize: function (width, count) { 25205 var arr = []; 25206 for (var i = 0; i < count; i++) arr[i] = 0; 25207 25208 this.adjustSize(width, arr); 25209 return arr; 25210 25211 }, 25212 adjustSize: function (width, parts, from, to) { 25213 if (!from) 25214 from = 0; 25215 if (to === undefined) 25216 to = parts.length - 1; 25217 25218 var length = to - from + 1; 25219 25220 var full = this.getSum(parts, from, to); 25221 25222 for (var i = from; i <= to; i++) { 25223 var share = Math.floor(width * (full ? (parts[i] / full) : (1 / length))); 25224 25225 full -= parts[i]; 25226 width -= share; 25227 length--; 25228 25229 parts[i] += share; 25230 } 25231 parts[parts.length - 1] += width; 25232 }, 25233 sortScales: function (scales) { 25234 function cellSize(unit, step) { 25235 var d = new Date(1970, 0, 1); 25236 return dateHelper.add(d, step, unit) - d; 25237 } 25238 25239 scales.sort(function (a, b) { 25240 if (cellSize(a.unit, a.step) < cellSize(b.unit, b.step)) { 25241 return 1; 25242 } else if (cellSize(a.unit, a.step) > cellSize(b.unit, b.step)) { 25243 return -1; 25244 } else { 25245 return 0; 25246 } 25247 }); 25248 25249 for (var i = 0; i < scales.length; i++) { 25250 scales[i].index = i; 25251 } 25252 }, 25253 _isLegacyMode: function(config){ 25254 var scaleConfig = config || services.config(); 25255 return scaleConfig.scale_unit || scaleConfig.date_scale || scaleConfig.subscales; 25256 }, 25257 _prepareScaleObject: function(scale){ 25258 var format = scale.format; 25259 if(!format){ 25260 format = scale.template || scale.date || "%d %M"; 25261 } 25262 25263 if(typeof format === "string"){ 25264 format = gantt.date.date_to_str(format); 25265 } 25266 return { 25267 unit: scale.unit || "day", 25268 step: scale.step || 1, 25269 format: format, 25270 css: scale.css 25271 }; 25272 }, 25273 primaryScale: function(config) { 25274 var templates = services.getService("templateLoader"); 25275 var legacyMode = this._isLegacyMode(config); 25276 25277 var scaleConfig = config || services.config(); 25278 25279 var result; 25280 if(legacyMode){ 25281 templates.initTemplate("date_scale", undefined, undefined, scaleConfig, services.templates()); 25282 result = { 25283 unit: services.config().scale_unit, 25284 step: services.config().step, 25285 template: services.templates().date_scale, 25286 date: services.config().date_scale, 25287 css: services.templates().scale_cell_class 25288 }; 25289 }else{ 25290 var primaryScale = scaleConfig.scales[0]; 25291 result = { 25292 unit: primaryScale.unit, 25293 step: primaryScale.step, 25294 template: primaryScale.template, 25295 format: primaryScale.format, 25296 date: primaryScale.date, 25297 css: primaryScale.css || services.templates().scale_cell_class 25298 }; 25299 } 25300 25301 return this._prepareScaleObject(result); 25302 }, 25303 getSubScales: function(config) { 25304 var legacyMode = this._isLegacyMode(config); 25305 var scaleConfig = config || services.config(); 25306 var scales; 25307 if(legacyMode){ 25308 scales = scaleConfig.subscales || []; 25309 }else{ 25310 scales = scaleConfig.scales.slice(1); 25311 } 25312 25313 return scales.map(function(scale){ 25314 return this._prepareScaleObject(scale); 25315 }.bind(this)); 25316 }, 25317 25318 prepareConfigs: function (scales, min_coll_width, container_width, scale_height, minDate, maxDate, rtl) { 25319 var heights = this.splitSize(scale_height, scales.length); 25320 var full_width = container_width; 25321 25322 var configs = []; 25323 for (var i = scales.length - 1; i >= 0; i--) { 25324 var main_scale = (i == scales.length - 1); 25325 var cfg = this.initScaleConfig(scales[i], minDate, maxDate); 25326 if (main_scale) { 25327 this.processIgnores(cfg); 25328 } 25329 25330 this.initColSizes(cfg, min_coll_width, full_width, heights[i]); 25331 this.limitVisibleRange(cfg); 25332 25333 if (main_scale) { 25334 full_width = cfg.full_width; 25335 } 25336 25337 configs.unshift(cfg); 25338 } 25339 25340 25341 for (var i = 0; i < configs.length - 1; i++) { 25342 this.alineScaleColumns(configs[configs.length - 1], configs[i]); 25343 } 25344 for (var i = 0; i < configs.length; i++) { 25345 25346 if(rtl){ 25347 this.reverseScale(configs[i]); 25348 } 25349 this.setPosSettings(configs[i]); 25350 } 25351 return configs; 25352 25353 }, 25354 25355 reverseScale: function(scale){ 25356 scale.width = scale.width.reverse(); 25357 scale.trace_x = scale.trace_x.reverse(); 25358 25359 var indexes = scale.trace_indexes; 25360 scale.trace_indexes = {}; 25361 scale.trace_index_transition = {}; 25362 scale.rtl = true; 25363 for(var i = 0; i < scale.trace_x.length; i++){ 25364 scale.trace_indexes[scale.trace_x[i].valueOf()] = i; 25365 scale.trace_index_transition[indexes[scale.trace_x[i].valueOf()]] = i; 25366 } 25367 return scale; 25368 }, 25369 25370 setPosSettings: function (config) { 25371 for (var i = 0, len = config.trace_x.length; i < len; i++) { 25372 config.left.push((config.width[i - 1] || 0) + (config.left[i - 1] || 0)); 25373 } 25374 }, 25375 25376 _ignore_time_config: function (date, scale) { 25377 25378 if (services.config().skip_off_time) { 25379 var skip = true; 25380 var probe = date; 25381 25382 // check dates in case custom scale unit, e.g. {unit: "month", step: 3} 25383 for (var i = 0; i < scale.step; i++) { 25384 if (i) { 25385 probe = dateHelper.add(date, i, scale.unit); 25386 } 25387 25388 skip = skip && !this.isWorkTime(probe, scale.unit); 25389 } 25390 25391 return skip; 25392 } 25393 return false; 25394 }, 25395 //defined in an extension 25396 processIgnores: function (config) { 25397 config.ignore_x = {}; 25398 config.display_count = config.count; 25399 }, 25400 initColSizes: function (config, min_col_width, full_width, line_height) { 25401 var cont_width = full_width; 25402 25403 config.height = line_height; 25404 25405 var column_count = config.display_count === undefined ? config.count : config.display_count; 25406 25407 if (!column_count) 25408 column_count = 1; 25409 25410 config.col_width = Math.floor(cont_width / column_count); 25411 25412 if (min_col_width) { 25413 if (config.col_width < min_col_width) { 25414 config.col_width = min_col_width; 25415 cont_width = config.col_width * column_count; 25416 } 25417 } 25418 config.width = []; 25419 var ignores = config.ignore_x || {}; 25420 for (var i = 0; i < config.trace_x.length; i++) { 25421 if (ignores[config.trace_x[i].valueOf()] || (config.display_count == config.count)) { 25422 config.width[i] = 0; 25423 } else { 25424 // width of month columns should be proportional month duration 25425 var width = 1; 25426 if (config.unit == "month") { 25427 var days = Math.round((dateHelper.add(config.trace_x[i], config.step, config.unit) - config.trace_x[i]) / (1000 * 60 * 60 * 24)); 25428 width = days; 25429 } 25430 config.width[i] = width; 25431 } 25432 } 25433 25434 this.adjustSize(cont_width - this.getSum(config.width)/* 1 width per column from the code above */, config.width); 25435 config.full_width = this.getSum(config.width); 25436 }, 25437 initScaleConfig: function (config, min_date, max_date) { 25438 var cfg = utils.mixin({ 25439 count: 0, 25440 col_width: 0, 25441 full_width: 0, 25442 height: 0, 25443 width: [], 25444 left: [], 25445 trace_x: [], 25446 trace_indexes: {}, 25447 min_date: new Date(min_date), 25448 max_date: new Date(max_date) 25449 }, config); 25450 25451 this.eachColumn(config.unit, config.step, min_date, max_date, function (date) { 25452 cfg.count++; 25453 cfg.trace_x.push(new Date(date)); 25454 cfg.trace_indexes[date.valueOf()] = cfg.trace_x.length - 1; 25455 }); 25456 25457 cfg.trace_x_ascending = cfg.trace_x.slice(); 25458 return cfg; 25459 }, 25460 iterateScales: function (lower_scale, upper_scale, from, to, callback) { 25461 var upper_dates = upper_scale.trace_x; 25462 var lower_dates = lower_scale.trace_x; 25463 25464 var prev = from || 0; 25465 var end = to || (lower_dates.length - 1); 25466 var prevUpper = 0; 25467 25468 25469 for (var up = 1; up < upper_dates.length; up++) { 25470 var target_index = (lower_scale.trace_indexes[+upper_dates[up]]); 25471 if (target_index !== undefined && target_index <= end) { 25472 if (callback) { 25473 callback.apply(this, [prevUpper, up, prev, target_index]); 25474 } 25475 prev = target_index; 25476 prevUpper = up; 25477 continue; 25478 } 25479 } 25480 }, 25481 alineScaleColumns: function (lower_scale, upper_scale, from, to) { 25482 this.iterateScales(lower_scale, upper_scale, from, to, function (upper_start, upper_end, lower_start, lower_end) { 25483 var targetWidth = this.getSum(lower_scale.width, lower_start, lower_end - 1); 25484 var actualWidth = this.getSum(upper_scale.width, upper_start, upper_end - 1); 25485 if (actualWidth != targetWidth) { 25486 this.setSumWidth(targetWidth, upper_scale, upper_start, upper_end - 1); 25487 } 25488 25489 }); 25490 }, 25491 25492 eachColumn: function (unit, step, min_date, max_date, callback) { 25493 var start = new Date(min_date), 25494 end = new Date(max_date); 25495 if (dateHelper[unit + "_start"]) { 25496 start = dateHelper[unit + "_start"](start); 25497 } 25498 25499 var curr = new Date(start); 25500 if (+curr >= +end) { 25501 end = dateHelper.add(curr, step, unit); 25502 } 25503 while (+curr < +end) { 25504 callback.call(this, new Date(curr)); 25505 var tzOffset = curr.getTimezoneOffset(); 25506 curr = dateHelper.add(curr, step, unit); 25507 curr = gantt._correct_dst_change(curr, tzOffset, step, unit); 25508 if (dateHelper[unit + '_start']) 25509 curr = dateHelper[unit + "_start"](curr); 25510 } 25511 }, 25512 limitVisibleRange: function (cfg) { 25513 var dates = cfg.trace_x; 25514 25515 var left = 0, right = cfg.width.length - 1; 25516 var diff = 0; 25517 if (+dates[0] < +cfg.min_date && left != right) { 25518 var width = Math.floor(cfg.width[0] * ((dates[1] - cfg.min_date) / (dates[1] - dates[0]))); 25519 diff += cfg.width[0] - width; 25520 cfg.width[0] = width; 25521 25522 dates[0] = new Date(cfg.min_date); 25523 } 25524 25525 var last = dates.length - 1; 25526 var lastDate = dates[last]; 25527 var outDate = dateHelper.add(lastDate, cfg.step, cfg.unit); 25528 if (+outDate > +cfg.max_date && last > 0) { 25529 var width = cfg.width[last] - Math.floor(cfg.width[last] * ((outDate - cfg.max_date) / (outDate - lastDate))); 25530 diff += cfg.width[last] - width; 25531 cfg.width[last] = width; 25532 } 25533 25534 if (diff) { 25535 var full = this.getSum(cfg.width); 25536 var shared = 0; 25537 for (var i = 0; i < cfg.width.length; i++) { 25538 var share = Math.floor(diff * (cfg.width[i] / full)); 25539 cfg.width[i] += share; 25540 shared += share; 25541 } 25542 this.adjustSize(diff - shared, cfg.width); 25543 } 25544 25545 } 25546 }; 25547} 25548 25549module.exports = ScaleHelper; 25550 25551 25552/***/ }), 25553 25554/***/ "./sources/core/ui/timeline/tasks_canvas_render.gpl.js": 25555/*!*************************************************************!*\ 25556 !*** ./sources/core/ui/timeline/tasks_canvas_render.gpl.js ***! 25557 \*************************************************************/ 25558/*! no static exports found */ 25559/***/ (function(module, exports) { 25560 25561var createStaticBgHelper = function(){ 25562 return { 25563 render: function () { }, 25564 destroy: function () { } 25565 }; 25566}; 25567 25568module.exports = { 25569 create: function(){ 25570 return createStaticBgHelper(); 25571 } 25572}; 25573 25574 25575 25576/***/ }), 25577 25578/***/ "./sources/core/ui/timeline/tasks_dnd.js": 25579/*!***********************************************!*\ 25580 !*** ./sources/core/ui/timeline/tasks_dnd.js ***! 25581 \***********************************************/ 25582/*! no static exports found */ 25583/***/ (function(module, exports, __webpack_require__) { 25584 25585var domHelpers = __webpack_require__(/*! ../../../utils/dom_helpers */ "./sources/utils/dom_helpers.js"); 25586var utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"); 25587var timeout = __webpack_require__(/*! ../../../utils/timeout */ "./sources/utils/timeout.js"); 25588var helpers = __webpack_require__(/*! ../../../utils/helpers */ "./sources/utils/helpers.js"); 25589 25590function createTaskDND(timeline, gantt) { 25591 var services = gantt.$services; 25592 return { 25593 drag: null, 25594 dragMultiple: {}, 25595 _events: { 25596 before_start: {}, 25597 before_finish: {}, 25598 after_finish: {} 25599 }, 25600 _handlers: {}, 25601 init: function() { 25602 this._domEvents = gantt._createDomEventScope(); 25603 this.clear_drag_state(); 25604 var drag = gantt.config.drag_mode; 25605 this.set_actions(); 25606 25607 var stateService = services.getService("state"); 25608 stateService.registerProvider("tasksDnd", utils.bind(function() { 25609 return { 25610 drag_id : this.drag ? this.drag.id : undefined, 25611 drag_mode : this.drag ? this.drag.mode : undefined, 25612 drag_from_start : this.drag ? this.drag.left : undefined 25613 }; 25614 }, this)); 25615 25616 var evs = { 25617 "before_start": "onBeforeTaskDrag", 25618 "before_finish": "onBeforeTaskChanged", 25619 "after_finish": "onAfterTaskDrag" 25620 }; 25621 //for now, all drag operations will trigger the same events 25622 for (var stage in this._events) { 25623 for (var mode in drag) { 25624 this._events[stage][mode] = evs[stage]; 25625 } 25626 } 25627 25628 this._handlers[drag.move] = this._move; 25629 this._handlers[drag.resize] = this._resize; 25630 this._handlers[drag.progress] = this._resize_progress; 25631 }, 25632 set_actions: function() { 25633 var data = timeline.$task_data; 25634 this._domEvents.attach(data, "mousemove", gantt.bind(function(e) { 25635 this.on_mouse_move(e || event); 25636 }, this)); 25637 this._domEvents.attach(data, "mousedown", gantt.bind(function(e) { 25638 this.on_mouse_down(e || event); 25639 }, this)); 25640 this._domEvents.attach(gantt.$root, "mouseup", gantt.bind(function(e) { 25641 this.on_mouse_up(e || event); 25642 }, this)); 25643 }, 25644 25645 clear_drag_state: function() { 25646 this.drag = { 25647 id: null, 25648 mode: null, 25649 pos: null, 25650 start_x: null, 25651 start_y: null, 25652 obj: null, 25653 left: null 25654 }; 25655 this.dragMultiple = {}; 25656 }, 25657 _resize: function(task, shift, drag) { 25658 var cfg = timeline.$getConfig(); 25659 var coords_x = this._drag_task_coords(task, drag); 25660 if (drag.left) { 25661 task.start_date = gantt.dateFromPos(coords_x.start + shift); 25662 if (!task.start_date) { 25663 task.start_date = new Date(gantt.getState().min_date); 25664 } 25665 } else { 25666 task.end_date = gantt.dateFromPos(coords_x.end + shift); 25667 if (!task.end_date) { 25668 task.end_date = new Date(gantt.getState().max_date); 25669 } 25670 } 25671 25672 var minDurationInUnits = this._calculateMinDuration(cfg.min_duration, cfg.duration_unit); 25673 if (task.end_date - task.start_date < cfg.min_duration) { 25674 if (drag.left) 25675 task.start_date = gantt.calculateEndDate(task.end_date, -minDurationInUnits, cfg.duration_unit, task); 25676 else 25677 task.end_date = gantt.calculateEndDate(task.start_date, minDurationInUnits, cfg.duration_unit, task); 25678 } 25679 gantt._init_task_timing(task); 25680 }, 25681 _calculateMinDuration: function(duration, unit) { 25682 var inMs = { 25683 "minute": 60000, 25684 "hour": 3600000, 25685 "day": 86400000, 25686 "week": 604800000, 25687 "month": 2419200000, 25688 "year": 31356000000 25689 }; 25690 return Math.ceil(duration / inMs[unit]); 25691 }, 25692 _resize_progress: function(task, shift, drag) { 25693 var coords_x = this._drag_task_coords(task, drag); 25694 25695 var config = timeline.$getConfig(); 25696 var diffValue = !config.rtl ? (drag.pos.x - coords_x.start) : (coords_x.start - drag.pos.x); 25697 25698 var diff = Math.max(0, diffValue); 25699 task.progress = Math.min(1, diff / Math.abs(coords_x.end - coords_x.start)); 25700 }, 25701 _find_max_shift: function(dragItems, shift) { 25702 var correctShift; 25703 for (var i in dragItems) { 25704 var drag = dragItems[i]; 25705 var task = gantt.getTask(drag.id); 25706 25707 var coords_x = this._drag_task_coords(task, drag); 25708 var minX = gantt.posFromDate(new Date(gantt.getState().min_date)); 25709 var maxX = gantt.posFromDate(new Date(gantt.getState().max_date)); 25710 25711 if (coords_x.end + shift > maxX) { 25712 var maxShift = maxX - coords_x.end; 25713 if (maxShift < correctShift || correctShift === undefined) { 25714 correctShift = maxShift; 25715 } 25716 } else if (coords_x.start + shift < minX) { 25717 var minShift = minX - coords_x.start; 25718 if (minShift > correctShift || correctShift === undefined) { 25719 correctShift = minShift; 25720 } 25721 } 25722 } 25723 return correctShift; 25724 }, 25725 _move: function(task, shift, drag) { 25726 var coords_x = this._drag_task_coords(task, drag); 25727 var new_start = gantt.dateFromPos(coords_x.start + shift), 25728 new_end = gantt.dateFromPos(coords_x.end + shift); 25729 if (!new_start) { 25730 task.start_date = new Date(gantt.getState().min_date); 25731 task.end_date = gantt.dateFromPos(gantt.posFromDate(task.start_date) + (coords_x.end - coords_x.start)); 25732 } else if (!new_end) { 25733 task.end_date = new Date(gantt.getState().max_date); 25734 task.start_date = gantt.dateFromPos(gantt.posFromDate(task.end_date) - (coords_x.end - coords_x.start)); 25735 } else { 25736 task.start_date = new_start; 25737 task.end_date = new_end; 25738 } 25739 }, 25740 _drag_task_coords: function(t, drag) { 25741 var start = drag.obj_s_x = drag.obj_s_x || gantt.posFromDate(t.start_date); 25742 var end = drag.obj_e_x = drag.obj_e_x || gantt.posFromDate(t.end_date); 25743 return { 25744 start: start, 25745 end: end 25746 }; 25747 }, 25748 _mouse_position_change: function(oldPos, newPos) { 25749 var dx = oldPos.x - newPos.x, 25750 dy = oldPos.y - newPos.y; 25751 return Math.sqrt(dx * dx + dy * dy); 25752 }, 25753 _is_number: function(n) { 25754 return !isNaN(parseFloat(n)) && isFinite(n); 25755 }, 25756 25757 on_mouse_move: function(e) { 25758 if (this.drag.start_drag) { 25759 var pos = domHelpers.getRelativeEventPosition(e, gantt.$task_data); 25760 25761 var sX = this.drag.start_drag.start_x, 25762 sY = this.drag.start_drag.start_y; 25763 25764 if ((Date.now() - this.drag.timestamp > 50) || 25765 (this._is_number(sX) && this._is_number(sY) && this._mouse_position_change({ 25766 x: sX, 25767 y: sY 25768 }, pos) > 20)) { 25769 this._start_dnd(e); 25770 } 25771 } 25772 25773 var drag = this.drag; 25774 25775 if (drag.mode) { 25776 if (!timeout(this, 40))//limit update frequency 25777 return; 25778 25779 this._update_on_move(e); 25780 25781 } 25782 }, 25783 25784 _update_item_on_move: function(shift, id, mode, drag, e) { 25785 var task = gantt.getTask(id); 25786 var original = gantt.mixin({}, task); 25787 var copy = gantt.mixin({}, task); 25788 this._handlers[mode].apply(this, [copy, shift, drag]); 25789 gantt.mixin(task, copy, true); 25790 //gantt._update_parents(drag.id, true); 25791 gantt.callEvent("onTaskDrag", [task.id, mode, copy, original, e]); 25792 gantt.mixin(task, copy, true); 25793 gantt.refreshTask(id); 25794 }, 25795 25796 _update_on_move: function(e) { 25797 var drag = this.drag; 25798 var config = timeline.$getConfig(); 25799 if (drag.mode) { 25800 var pos = domHelpers.getRelativeEventPosition(e, timeline.$task_data); 25801 if (drag.pos && drag.pos.x == pos.x) 25802 return; 25803 25804 drag.pos = pos; 25805 25806 var curr_date = gantt.dateFromPos(pos.x); 25807 if (!curr_date || isNaN(curr_date.getTime())) 25808 return; 25809 25810 25811 var shift = pos.x - drag.start_x; 25812 var task = gantt.getTask(drag.id); 25813 if (this._handlers[drag.mode]) { 25814 if (drag.mode === config.drag_mode.move) { 25815 var dragHash = {}; 25816 25817 if (this._isMultiselect()) { 25818 var selectedTasksIds = gantt.getSelectedTasks(); 25819 if (selectedTasksIds.indexOf(drag.id) >= 0) { 25820 dragHash = this.dragMultiple; 25821 } 25822 } 25823 if (gantt.isSummaryTask(task) && gantt.config.drag_project) { 25824 var initialDrag = {}; 25825 initialDrag[drag.id] = utils.copy(drag); 25826 dragHash = utils.mixin(initialDrag, this.dragMultiple); 25827 } 25828 25829 var maxShift = this._find_max_shift(dragHash, shift); 25830 if (maxShift !== undefined) { 25831 shift = maxShift; 25832 } 25833 this._update_item_on_move(shift, drag.id, drag.mode, drag, e); 25834 for (var i in dragHash) { 25835 var childDrag = dragHash[i]; 25836 this._update_item_on_move(shift, childDrag.id, childDrag.mode, childDrag, e); 25837 } 25838 } else { 25839 // for resize and progress 25840 this._update_item_on_move(shift, drag.id, drag.mode, drag, e); 25841 } 25842 gantt._update_parents(drag.id); 25843 } 25844 25845 } 25846 }, 25847 25848 on_mouse_down: function(e, src) { 25849 // on Mac we do not get onmouseup event when clicking right mouse button leaving us in dnd state 25850 // let's ignore right mouse button then 25851 if (e.button == 2 && e.button !== undefined) 25852 return; 25853 25854 var config = timeline.$getConfig(); 25855 var id = gantt.locate(e); 25856 var task = null; 25857 if (gantt.isTaskExists(id)) { 25858 task = gantt.getTask(id); 25859 } 25860 25861 if (gantt.isReadonly(task) || this.drag.mode) return; 25862 25863 this.clear_drag_state(); 25864 25865 src = src || (e.target || e.srcElement); 25866 25867 var className = domHelpers.getClassName(src); 25868 var drag = this._get_drag_mode(className, src); 25869 25870 if (!className || !drag) { 25871 if (src.parentNode) 25872 return this.on_mouse_down(e, src.parentNode); 25873 else 25874 return; 25875 } 25876 25877 if (!drag) { 25878 if (gantt.checkEvent("onMouseDown") && gantt.callEvent("onMouseDown", [className.split(" ")[0]])) { 25879 if (src.parentNode) 25880 return this.on_mouse_down(e, src.parentNode); 25881 25882 } 25883 } else { 25884 if (drag.mode && drag.mode != config.drag_mode.ignore && config["drag_" + drag.mode]) { 25885 id = gantt.locate(src); 25886 task = gantt.copy(gantt.getTask(id) || {}); 25887 25888 if (gantt.isReadonly(task)) { 25889 this.clear_drag_state(); 25890 return false; 25891 } 25892 25893 if ((gantt.isSummaryTask(task) && !config.drag_project) && drag.mode != config.drag_mode.progress) {//only progress drag is allowed for tasks with flexible duration 25894 this.clear_drag_state(); 25895 return; 25896 } 25897 25898 drag.id = id; 25899 var pos = domHelpers.getRelativeEventPosition(e, gantt.$task_data); 25900 25901 drag.start_x = pos.x; 25902 drag.start_y = pos.y; 25903 drag.obj = task; 25904 this.drag.start_drag = drag; 25905 this.drag.timestamp = Date.now(); 25906 25907 } else 25908 this.clear_drag_state(); 25909 } 25910 }, 25911 _fix_dnd_scale_time: function(task, drag) { 25912 var config = timeline.$getConfig(); 25913 var unit = gantt.getScale().unit, 25914 step = gantt.getScale().step; 25915 if (!config.round_dnd_dates) { 25916 unit = 'minute'; 25917 step = config.time_step; 25918 } 25919 25920 function fixStart(task) { 25921 if (!gantt.config.correct_work_time) 25922 return; 25923 var config = timeline.$getConfig(); 25924 if (!gantt.isWorkTime(task.start_date, undefined, task)) 25925 task.start_date = gantt.calculateEndDate({ 25926 start_date: task.start_date, 25927 duration: -1, 25928 unit: config.duration_unit, 25929 task: task 25930 }); 25931 } 25932 25933 function fixEnd(task) { 25934 if (!gantt.config.correct_work_time) 25935 return; 25936 var config = timeline.$getConfig(); 25937 if (!gantt.isWorkTime(new Date(task.end_date - 1), undefined, task)) 25938 task.end_date = gantt.calculateEndDate({ 25939 start_date: task.end_date, 25940 duration: 1, 25941 unit: config.duration_unit, 25942 task: task 25943 }); 25944 } 25945 25946 if (drag.mode == config.drag_mode.resize) { 25947 if (drag.left) { 25948 task.start_date = gantt.roundDate({date: task.start_date, unit: unit, step: step}); 25949 fixStart(task); 25950 } else { 25951 task.end_date = gantt.roundDate({date: task.end_date, unit: unit, step: step}); 25952 fixEnd(task); 25953 } 25954 } else if (drag.mode == config.drag_mode.move) { 25955 task.start_date = gantt.roundDate({date: task.start_date, unit: unit, step: step}); 25956 fixStart(task); 25957 task.end_date = gantt.calculateEndDate(task); 25958 } 25959 }, 25960 _fix_working_times: function(task, drag) { 25961 var config = timeline.$getConfig(); 25962 var drag = drag || {mode: config.drag_mode.move}; 25963 25964 if (drag.mode == config.drag_mode.resize) { 25965 if (drag.left) { 25966 task.start_date = gantt.getClosestWorkTime({date: task.start_date, dir: 'future', task: task}); 25967 } else { 25968 task.end_date = gantt.getClosestWorkTime({date: task.end_date, dir: 'past', task: task}); 25969 } 25970 } else if (drag.mode == config.drag_mode.move) { 25971 gantt.correctTaskWorkTime(task); 25972 } 25973 }, 25974 25975 _finalize_mouse_up: function(taskId, config, drag, e) { 25976 var task = gantt.getTask(taskId); 25977 25978 if (config.work_time && config.correct_work_time) { 25979 this._fix_working_times(task, drag); 25980 } 25981 25982 this._fix_dnd_scale_time(task, drag); 25983 25984 if (!this._fireEvent("before_finish", drag.mode, [taskId, drag.mode, gantt.copy(drag.obj), e])) { 25985 //drag.obj._dhx_changed = false; 25986 this.clear_drag_state(); 25987 if (taskId == drag.id) { 25988 drag.obj._dhx_changed = false; 25989 gantt.mixin(task, drag.obj, true); 25990 } 25991 25992 25993 gantt.refreshTask(task.id); 25994 } else { 25995 var drag_id = taskId; 25996 25997 gantt._init_task_timing(task); 25998 25999 this.clear_drag_state(); 26000 gantt.updateTask(task.id); 26001 this._fireEvent("after_finish", drag.mode, [drag_id, drag.mode, e]); 26002 } 26003 26004 }, 26005 26006 on_mouse_up: function(e) { 26007 26008 var drag = this.drag; 26009 if (drag.mode && drag.id) { 26010 var config = timeline.$getConfig(); 26011 //drop 26012 var task = gantt.getTask(drag.id); 26013 var dragMultiple = this.dragMultiple; 26014 26015 if (drag.mode === config.drag_mode.move) { 26016 if ((gantt.isSummaryTask(task) && config.drag_project) || (this._isMultiselect())) { 26017 for (var i in dragMultiple) { 26018 this._finalize_mouse_up(dragMultiple[i].id, config, dragMultiple[i], e); 26019 } 26020 } 26021 } 26022 this._finalize_mouse_up(drag.id, config, drag, e); 26023 } 26024 this.clear_drag_state(); 26025 }, 26026 _get_drag_mode: function(className, el) { 26027 var config = timeline.$getConfig(); 26028 var modes = config.drag_mode; 26029 var classes = (className || "").split(" "); 26030 var classname = classes[0]; 26031 var drag = {mode: null, left: null}; 26032 switch (classname) { 26033 case "gantt_task_line": 26034 case "gantt_task_content": 26035 drag.mode = modes.move; 26036 break; 26037 case "gantt_task_drag": 26038 drag.mode = modes.resize; 26039 26040 var dragProperty = el.getAttribute("data-bind-property"); 26041 26042 if (dragProperty == "start_date") { 26043 drag.left = true; 26044 } else { 26045 drag.left = false; 26046 } 26047 break; 26048 case "gantt_task_progress_drag": 26049 drag.mode = modes.progress; 26050 break; 26051 case "gantt_link_control": 26052 case "gantt_link_point": 26053 drag.mode = modes.ignore; 26054 break; 26055 default: 26056 drag = null; 26057 break; 26058 } 26059 return drag; 26060 26061 }, 26062 26063 _start_dnd: function(e) { 26064 var drag = this.drag = this.drag.start_drag; 26065 delete drag.start_drag; 26066 26067 var cfg = timeline.$getConfig(); 26068 var id = drag.id; 26069 26070 if (!cfg["drag_" + drag.mode] || !gantt.callEvent("onBeforeDrag", [id, drag.mode, e]) || !this._fireEvent("before_start", drag.mode, [id, drag.mode, e])) { 26071 this.clear_drag_state(); 26072 } else { 26073 delete drag.start_drag; 26074 var task = gantt.getTask(id); 26075 if (gantt.isReadonly(task)){ 26076 this.clear_drag_state(); 26077 return; 26078 } 26079 if (this._isMultiselect()) { 26080 // for don't move selected tasks when drag unselected task 26081 var selectedTasksIds = gantt.getSelectedTasks(); 26082 if (selectedTasksIds.indexOf(drag.id) >= 0) { 26083 helpers.forEach(selectedTasksIds, gantt.bind(function(taskId) { 26084 var selectedTask = gantt.getTask(taskId); 26085 if (gantt.isSummaryTask(selectedTask) && gantt.config.drag_project && drag.mode == cfg.drag_mode.move) { 26086 this._addSubtasksToDragMultiple(selectedTask.id); 26087 } 26088 this.dragMultiple[taskId] = gantt.mixin({ 26089 id: selectedTask.id, 26090 obj: gantt.copy(selectedTask) 26091 }, this.drag); 26092 }, this)); 26093 } 26094 } 26095 // for move unselected summary 26096 if (gantt.isSummaryTask(task) && gantt.config.drag_project && drag.mode == cfg.drag_mode.move) { 26097 this._addSubtasksToDragMultiple(task.id); 26098 } 26099 gantt.callEvent("onTaskDragStart", []); 26100 } 26101 26102 }, 26103 _fireEvent: function(stage, mode, params) { 26104 gantt.assert(this._events[stage], "Invalid stage:{" + stage + "}"); 26105 26106 var trigger = this._events[stage][mode]; 26107 26108 gantt.assert(trigger, "Unknown after drop mode:{" + mode + "}"); 26109 gantt.assert(params, "Invalid event arguments"); 26110 26111 26112 if (!gantt.checkEvent(trigger)) 26113 return true; 26114 26115 return gantt.callEvent(trigger, params); 26116 }, 26117 26118 round_task_dates: function(task) { 26119 var drag_state = this.drag; 26120 var config = timeline.$getConfig(); 26121 if (!drag_state) { 26122 drag_state = {mode: config.drag_mode.move}; 26123 } 26124 this._fix_dnd_scale_time(task, drag_state); 26125 }, 26126 destructor: function() { 26127 this._domEvents.detachAll(); 26128 }, 26129 _isMultiselect: function() { 26130 return gantt.config.drag_multiple && !!(gantt.getSelectedTasks && gantt.getSelectedTasks().length > 0); 26131 }, 26132 _addSubtasksToDragMultiple: function(summaryId) { 26133 gantt.eachTask(function(child) { 26134 this.dragMultiple[child.id] = gantt.mixin({ 26135 id: child.id, 26136 obj: gantt.copy(child) 26137 }, this.drag); 26138 }, summaryId, this); 26139 } 26140 }; 26141} 26142 26143function initTaskDND() { 26144 var _tasks_dnd; 26145 return { 26146 extend: function(timeline) { 26147 timeline.roundTaskDates = function(task) { 26148 _tasks_dnd.round_task_dates(task); 26149 }; 26150 26151 }, 26152 init: function(timeline, gantt) { 26153 _tasks_dnd = createTaskDND(timeline, gantt); 26154 // TODO: entry point for touch handlers, move touch to timeline 26155 timeline._tasks_dnd = _tasks_dnd; 26156 return _tasks_dnd.init(gantt); 26157 }, 26158 destructor: function() { 26159 if (_tasks_dnd) { 26160 _tasks_dnd.destructor(); 26161 _tasks_dnd = null; 26162 } 26163 } 26164 }; 26165} 26166 26167module.exports = { 26168 createTaskDND: initTaskDND 26169}; 26170 26171 26172/***/ }), 26173 26174/***/ "./sources/core/ui/timeline/timeline.js": 26175/*!**********************************************!*\ 26176 !*** ./sources/core/ui/timeline/timeline.js ***! 26177 \**********************************************/ 26178/*! no static exports found */ 26179/***/ (function(module, exports, __webpack_require__) { 26180 26181var ScaleHelper = __webpack_require__(/*! ./scales_ignore */ "./sources/core/ui/timeline/scales.js"); 26182var eventable = __webpack_require__(/*! ../../../utils/eventable */ "./sources/utils/eventable.js"); 26183var utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"); 26184var topPositionMixin = __webpack_require__(/*! ../row_position_mixin */ "./sources/core/ui/row_position_mixin.js"); 26185var canvasRender = __webpack_require__(/*! ./tasks_canvas_render */ "./sources/core/ui/timeline/tasks_canvas_render.gpl.js"); 26186 26187var Timeline = function(parent, config, factory, gantt){ 26188 this.$config = utils.mixin({}, config || {}); 26189 this.$scaleHelper = new ScaleHelper(gantt); 26190 this.$gantt = gantt; 26191 this._posFromDateCache = {}; 26192 this._timelineDragScroll = null; 26193 utils.mixin(this, topPositionMixin()); 26194 eventable(this); 26195}; 26196 26197Timeline.prototype = { 26198 init: function(container) { 26199 container.innerHTML += "<div class='gantt_task' style='width:inherit;height:inherit;'></div>"; 26200 this.$task = container.childNodes[0]; 26201 26202 this.$task.innerHTML = "<div class='gantt_task_scale'></div><div class='gantt_data_area'></div>"; 26203 this.$task_scale = this.$task.childNodes[0]; 26204 26205 this.$task_data = this.$task.childNodes[1]; 26206 this.$task_data.innerHTML = "<div class='gantt_task_bg'></div><div class='gantt_links_area'></div><div class='gantt_bars_area'></div>"; 26207 this.$task_bg = this.$task_data.childNodes[0]; 26208 this.$task_links = this.$task_data.childNodes[1]; 26209 this.$task_bars = this.$task_data.childNodes[2]; 26210 26211 this._tasks = { 26212 col_width: 0, 26213 width: [], // width of each column 26214 full_width: 0, // width of all columns 26215 trace_x: [], 26216 rendered: {} 26217 }; 26218 26219 var config = this.$getConfig(); 26220 var attr = config[this.$config.bind + "_attribute"]; 26221 var linksAttr = config[this.$config.bindLinks + "_attribute"]; 26222 if(!attr && this.$config.bind){ 26223 attr = this.$config.bind + "_id"; 26224 } 26225 if(!linksAttr && this.$config.bindLinks){ 26226 linksAttr = this.$config.bindLinks + "_id"; 26227 } 26228 this.$config.item_attribute = attr || null; 26229 this.$config.link_attribute = linksAttr || null; 26230 26231 var layers = this._createLayerConfig(); 26232 if(!this.$config.layers){ 26233 this.$config.layers = layers.tasks; 26234 } 26235 if(!this.$config.linkLayers){ 26236 this.$config.linkLayers = layers.links; 26237 } 26238 26239 this._attachLayers(this.$gantt); 26240 26241 this.callEvent("onReady", []); 26242 //this.refresh(); 26243 if (this.$gantt.ext.dragTimeline) { 26244 this._timelineDragScroll = this.$gantt.ext.dragTimeline.create(); 26245 this._timelineDragScroll.attach(this); 26246 } 26247 }, 26248 26249 setSize: function(width, height){ 26250 var config = this.$getConfig(); 26251 26252 if(width*1 === width){ 26253 this.$config.width = width; 26254 } 26255 if(height*1 === height){ 26256 26257 this.$config.height = height; 26258 var dataHeight = Math.max(this.$config.height - config.scale_height); 26259 this.$task_data.style.height = dataHeight + 'px'; 26260 } 26261 26262 this.refresh(); 26263 this.$task_bg.style.backgroundImage = ""; 26264 26265 if(config.smart_rendering && this.$config.rowStore){ 26266 var store = this.$config.rowStore; 26267 this.$task_bg.style.height = config.row_height * store.countVisible() +"px"; 26268 }else{ 26269 this.$task_bg.style.height = ""; 26270 } 26271 26272 var scale = this._tasks; 26273 //timeline area layers 26274 var data_els = this.$task_data.childNodes; 26275 for(var i= 0, len = data_els.length; i < len; i++){ 26276 var el = data_els[i]; 26277 if(el.hasAttribute("data-layer") && el.style) 26278 el.style.width = scale.full_width + "px"; 26279 } 26280 }, 26281 26282 isVisible: function(){ 26283 if(this.$parent && this.$parent.$config){ 26284 return !this.$parent.$config.hidden; 26285 }else{ 26286 return this.$task.offsetWidth; 26287 } 26288 }, 26289 26290 getSize: function(){ 26291 var config = this.$getConfig(); 26292 var store = this.$config.rowStore; 26293 26294 var contentHeight = store ? config.row_height * store.countVisible() : 0, 26295 contentWidth = this.isVisible() ? this._tasks.full_width : 0; 26296 26297 return { 26298 x: this.isVisible() ? this.$config.width : 0, 26299 y: this.isVisible() ? this.$config.height : 0, 26300 contentX: this.isVisible() ? contentWidth : 0, 26301 contentY: this.isVisible() ? (config.scale_height + contentHeight) : 0, 26302 scrollHeight: this.isVisible() ? contentHeight : 0, 26303 scrollWidth: this.isVisible() ? contentWidth : 0 26304 }; 26305 }, 26306 26307 scrollTo: function(left, top){ 26308 if(!this.isVisible()) 26309 return; 26310 26311 var scrolled = false; 26312 26313 this.$config.scrollTop = this.$config.scrollTop || 0; 26314 this.$config.scrollLeft = this.$config.scrollLeft || 0; 26315 if(top*1 === top){ 26316 this.$config.scrollTop = top; 26317 this.$task_data.scrollTop = this.$config.scrollTop; 26318 scrolled = true; 26319 } 26320 if (left*1 === left){ 26321 this.$task.scrollLeft = left; 26322 this.$config.scrollLeft = this.$task.scrollLeft; 26323 this._refreshScales(); 26324 scrolled = true; 26325 } 26326 26327 if(scrolled){ 26328 this.callEvent("onScroll", [this.$config.scrollLeft, this.$config.scrollTop]); 26329 } 26330 }, 26331 26332 _refreshScales: function _refreshScales() { 26333 if(!this.isVisible()) 26334 return; 26335 26336 var config = this.$getConfig(); 26337 if (!config.smart_scales) return; 26338 26339 var viewPort = this.getViewPort(); 26340 26341 var scales = this._scales; 26342 this.$task_scale.innerHTML = this._getScaleChunkHtml(scales, viewPort.x, viewPort.x_end); 26343 }, 26344 26345 getViewPort: function(){ 26346 var scrollLeft = this.$config.scrollLeft || 0; 26347 var scrollTop = this.$config.scrollTop || 0; 26348 var height = this.$config.height || 0; 26349 var width = this.$config.width || 0; 26350 return { 26351 y: scrollTop, 26352 y_end: scrollTop + height, 26353 x: scrollLeft, 26354 x_end: scrollLeft + width, 26355 height: height, 26356 width: width 26357 }; 26358 }, 26359 26360 _createLayerConfig: function(){ 26361 var self = this; 26362 var taskFilter = function(){ 26363 return self.isVisible(); 26364 }; 26365 26366 var taskLayers = [ 26367 { 26368 expose: true, 26369 renderer: this.$gantt.$ui.layers.taskBar(), 26370 container: this.$task_bars, 26371 filter: [taskFilter] 26372 }, 26373 { 26374 renderer: this.$gantt.$ui.layers.taskSplitBar(), 26375 filter: [taskFilter], 26376 container: this.$task_bars, 26377 append: true 26378 }, 26379 { 26380 renderer: this.$gantt.$ui.layers.taskBg(), 26381 container: this.$task_bg, 26382 filter: [ 26383 //function(){ 26384 // return !self.$getConfig().static_background; 26385 //}, 26386 taskFilter 26387 ] 26388 } 26389 ]; 26390 26391 var linkLayers = [ 26392 { 26393 expose: true, 26394 renderer: this.$gantt.$ui.layers.link(), 26395 container: this.$task_links, 26396 filter: [taskFilter] 26397 } 26398 ]; 26399 26400 return { 26401 tasks: taskLayers, 26402 links: linkLayers 26403 }; 26404 26405 }, 26406 26407 _attachLayers: function(gantt){ 26408 this._taskLayers = []; 26409 this._linkLayers = []; 26410 26411 var self = this; 26412 26413 var layers = this.$gantt.$services.getService("layers"); 26414 26415 if(this.$config.bind){ 26416 26417 this._bindStore(); 26418 var taskRenderer = layers.getDataRender(this.$config.bind); 26419 26420 if(!taskRenderer){ 26421 taskRenderer = layers.createDataRender({ 26422 name: this.$config.bind, 26423 defaultContainer: function(){ return self.$task_data;} 26424 }); 26425 } 26426 26427 taskRenderer.container = function(){ return self.$task_data;}; 26428 26429 var taskLayers = this.$config.layers; 26430 for(var i = 0; taskLayers && i < taskLayers.length; i++){ 26431 var layer = taskLayers[i]; 26432 26433 if(typeof layer == "string"){ 26434 layer = this.$gantt.$ui.layers[layer](); 26435 } 26436 26437 if(typeof layer == "function" || (layer && layer.render && layer.update)){ 26438 layer = {renderer: layer}; 26439 } 26440 26441 layer.view = this; 26442 26443 var bar_layer = taskRenderer.addLayer(layer); 26444 this._taskLayers.push(bar_layer); 26445 if(layer.expose){ 26446 this._taskRenderer = taskRenderer.getLayer(bar_layer); 26447 } 26448 } 26449 26450 this._initStaticBackgroundRender(); 26451 } 26452 26453 if(this.$config.bindLinks){ 26454 self.$config.linkStore = self.$gantt.getDatastore(self.$config.bindLinks); 26455 26456 var linkRenderer = layers.getDataRender(this.$config.bindLinks); 26457 26458 if(!linkRenderer){ 26459 linkRenderer = layers.createDataRender({ 26460 name: this.$config.bindLinks, 26461 defaultContainer: function(){ return self.$task_data;} 26462 }); 26463 } 26464 var linkLayers = this.$config.linkLayers; 26465 for(var i = 0; linkLayers && i < linkLayers.length; i++){ 26466 26467 if(typeof layer == "string"){ 26468 layer = this.$gantt.$ui.layers[layer](); 26469 } 26470 26471 var layer = linkLayers[i]; 26472 layer.view = this; 26473 // layer.getViewPort = getViewPort; 26474 // subscribeSmartRender(layer); 26475 var linkLayer = linkRenderer.addLayer(layer); 26476 this._taskLayers.push(linkLayer); 26477 if(linkLayers[i].expose){ 26478 this._linkRenderer = linkRenderer.getLayer(linkLayer); 26479 } 26480 } 26481 } 26482 }, 26483 26484 _initStaticBackgroundRender: function(){ 26485 var self = this; 26486 var staticRender = canvasRender.create(); 26487 var store = self.$config.rowStore; 26488 if(!store) return; 26489 26490 this._staticBgHandler = store.attachEvent("onStoreUpdated", function(id, item, mode){ 26491 if(id !== null) { 26492 return; 26493 } 26494 26495 if(!self.isVisible()) 26496 return; 26497 var config = self.$getConfig(); 26498 if(config.static_background) { 26499 var store = self.$gantt.getDatastore(self.$config.bind); 26500 var staticBgContainer = self.$task_bg_static; 26501 if(!staticBgContainer){ 26502 staticBgContainer = document.createElement("div"); 26503 staticBgContainer.className = "gantt_task_bg"; 26504 self.$task_bg_static = staticBgContainer; 26505 if(self.$task_bg.nextSibling){ 26506 self.$task_data.insertBefore(staticBgContainer, self.$task_bg.nextSibling); 26507 }else{ 26508 self.$task_data.appendChild(staticBgContainer); 26509 } 26510 } 26511 if (store) { 26512 staticRender.render(staticBgContainer, config, self.getScale(), config.row_height * store.countVisible()); 26513 } 26514 }else if(config.static_background){ 26515 if(self.$task_bg_static && self.$task_bg_static.parentNode){ 26516 self.$task_bg_static.parentNode.removeChild(self.$task_bg_static); 26517 } 26518 } 26519 }); 26520 this.attachEvent("onDestroy", function () { 26521 staticRender.destroy(); 26522 }); 26523 this._initStaticBackgroundRender = function(){};//init once 26524 }, 26525 26526 _clearLayers: function(gantt){ 26527 var layers = this.$gantt.$services.getService("layers"); 26528 var taskRenderer = layers.getDataRender(this.$config.bind); 26529 var linkRenderer = layers.getDataRender(this.$config.bindLinks); 26530 26531 if (this._taskLayers) { 26532 for(var i = 0; i < this._taskLayers.length; i++){ 26533 taskRenderer.removeLayer(this._taskLayers[i]); 26534 } 26535 } 26536 if (this._linkLayers) { 26537 for(var i = 0; i < this._linkLayers.length; i++){ 26538 linkRenderer.removeLayer(this._linkLayers[i]); 26539 } 26540 } 26541 26542 this._linkLayers = []; 26543 this._taskLayers = []; 26544 }, 26545 26546 _render_tasks_scales: function _render_tasks_scales() { 26547 var config = this.$getConfig(); 26548 26549 var scales_html = "", 26550 outer_width = 0, 26551 scale_height = 0; 26552 26553 var state = this.$gantt.getState(); 26554 26555 if (this.isVisible()) { 26556 var helpers = this.$scaleHelper; 26557 var scales = this._getScales(); 26558 scale_height = config.scale_height; 26559 26560 var availWidth = this.$config.width; 26561 if(config.autosize == "x" || config.autosize == "xy"){ 26562 availWidth = Math.max(config.autosize_min_width, 0); 26563 } 26564 26565 var cfgs = helpers.prepareConfigs(scales, config.min_column_width, availWidth, scale_height - 1, state.min_date, state.max_date, config.rtl); 26566 var cfg = this._tasks = cfgs[cfgs.length - 1]; 26567 this._scales = cfgs; 26568 this._posFromDateCache = {}; 26569 26570 scales_html = this._getScaleChunkHtml(cfgs, 0, this.$config.width); 26571 26572 outer_width = cfg.full_width + "px";//cfg.full_width + (this._scroll_sizes().y ? scrollSizes.scroll_size : 0) + "px"; 26573 scale_height += "px"; 26574 } 26575 26576 this.$task_scale.style.height = scale_height; 26577 26578 this.$task_data.style.width = 26579 this.$task_scale.style.width = outer_width; 26580 26581 this.$task_scale.innerHTML = scales_html; 26582 26583 }, 26584 26585 _getScaleChunkHtml: function _get_scale_chunk_html (scales, fromPos, toPos) { 26586 var templates = this.$gantt.$services.templates(); 26587 var html = []; 26588 26589 var css = templates.scale_row_class; 26590 for (var i = 0; i < scales.length; i++) { 26591 var cssClass = "gantt_scale_line"; 26592 var tplClass = css(scales[i]); 26593 if (tplClass) { 26594 cssClass += " " + tplClass; 26595 } 26596 26597 html.push("<div class=\"" + cssClass + "\" style=\"height:" + (scales[i].height) + 26598 "px;position:relative;line-height:" + (scales[i].height) + "px\">" + this._prepareScaleHtml(scales[i], fromPos, toPos) + "</div>"); 26599 } 26600 26601 return html.join(""); 26602 }, 26603 _prepareScaleHtml: function _prepare_scale_html(config, fromPos, toPos) { 26604 var globalConfig = this.$getConfig(); 26605 var globalTemplates = this.$gantt.$services.templates(); 26606 26607 var cells = []; 26608 var date = null, css = null; 26609 26610 var content = config.format || config.template || config.date; 26611 26612 if(typeof content === "string"){ 26613 content = this.$gantt.date.date_to_str(content); 26614 } 26615 26616 var startIndex = 0, 26617 endIndex = config.count; 26618 26619 if (globalConfig.smart_scales && (!isNaN(fromPos) && !isNaN(toPos))) { 26620 startIndex = _findBinary(config.left, fromPos); 26621 endIndex = _findBinary(config.left, toPos) + 1; 26622 } 26623 26624 css = config.css || function () { 26625 }; 26626 if (!config.css && globalConfig.inherit_scale_class) { 26627 css = globalTemplates.scale_cell_class; 26628 } 26629 26630 for (var i = startIndex; i < endIndex; i++) { 26631 if (!config.trace_x[i]) break; 26632 26633 date = new Date(config.trace_x[i]); 26634 var value = content.call(this, date), 26635 width = config.width[i], 26636 height = config.height, 26637 left = config.left[i], 26638 style = "", 26639 template = "", 26640 cssclass = ""; 26641 26642 if (width) { 26643 var position = globalConfig.smart_scales ? ("position:absolute;left:" + left + "px") : ""; 26644 26645 style = "width:" + (width) + "px;height:" + height + "px;" + position; 26646 cssclass = "gantt_scale_cell" + (i == config.count - 1 ? " gantt_last_cell" : ""); 26647 26648 template = css.call(this, date); 26649 if (template) cssclass += " " + template; 26650 26651 var ariaAttr = this.$gantt._waiAria.getTimelineCellAttr(value); 26652 var cell = "<div class='" + cssclass + "'" + ariaAttr + " style='" + style + "'>" + value + "</div>"; 26653 cells.push(cell); 26654 } else { 26655 //do not render ignored cells 26656 } 26657 26658 } 26659 return cells.join(""); 26660 }, 26661 dateFromPos: function dateFromPos(x) { 26662 var scale = this._tasks; 26663 if (x < 0 || x > scale.full_width || !scale.full_width) { 26664 return null; 26665 } 26666 26667 var ind = _findBinary(this._tasks.left, x); 26668 var summ = this._tasks.left[ind]; 26669 26670 var col_width = scale.width[ind] || scale.col_width; 26671 var part = 0; 26672 if (col_width) { 26673 part = (x - summ) / col_width; 26674 if(scale.rtl){ 26675 part = 1 - part; 26676 } 26677 26678 } 26679 26680 var unit = 0; 26681 if (part) { 26682 unit = this._getColumnDuration(scale, scale.trace_x[ind]); 26683 } 26684 26685 var date = new Date(scale.trace_x[ind].valueOf() + Math.round(part * unit)); 26686 return date; 26687 }, 26688 posFromDate: function posFromDate(date) { 26689 if (!this.isVisible()) 26690 return 0; 26691 26692 if(!date){ 26693 return 0; 26694 } 26695 26696 var dateValue = String(date.valueOf()); 26697 26698 if(this._posFromDateCache[dateValue] !== undefined){ 26699 return this._posFromDateCache[dateValue]; 26700 } 26701 var ind = this.columnIndexByDate(date); 26702 this.$gantt.assert(ind >= 0, "Invalid day index"); 26703 26704 var wholeCells = Math.floor(ind); 26705 var partCell = ind % 1; 26706 26707 var pos = this._tasks.left[Math.min(wholeCells, this._tasks.width.length - 1)]; 26708 if (wholeCells == this._tasks.width.length) 26709 pos += this._tasks.width[this._tasks.width.length - 1]; 26710 //for(var i=1; i <= wholeCells; i++) 26711 // pos += gantt._tasks.width[i-1]; 26712 26713 if (partCell) { 26714 if (wholeCells < this._tasks.width.length) { 26715 pos += this._tasks.width[wholeCells] * (partCell % 1); 26716 } else { 26717 pos += 1; 26718 } 26719 26720 } 26721 26722 var roundPos = Math.round(pos); 26723 this._posFromDateCache[dateValue] = roundPos; 26724 return Math.round(roundPos); 26725 }, 26726 26727 _getNextVisibleColumn: function (startIndex, columns, ignores) { 26728 // iterate columns to the right 26729 var date = +columns[startIndex]; 26730 var visibleDateIndex = startIndex; 26731 while (ignores[date]) { 26732 visibleDateIndex++; 26733 date = +columns[visibleDateIndex]; 26734 } 26735 26736 return visibleDateIndex; 26737 }, 26738 _getPrevVisibleColumn: function (startIndex, columns, ignores) { 26739 // iterate columns to the left 26740 var date = +columns[startIndex]; 26741 var visibleDateIndex = startIndex; 26742 while (ignores[date]) { 26743 visibleDateIndex--; 26744 date = +columns[visibleDateIndex]; 26745 } 26746 return visibleDateIndex; 26747 }, 26748 _getClosestVisibleColumn: function (startIndex, columns, ignores) { 26749 var visibleDateIndex = this._getNextVisibleColumn(startIndex, columns, ignores); 26750 if (!columns[visibleDateIndex]) { 26751 visibleDateIndex = this._getPrevVisibleColumn(startIndex, columns, ignores); 26752 } 26753 return visibleDateIndex; 26754 }, 26755 columnIndexByDate: function columnIndexByDate(date) { 26756 var pos = new Date(date).valueOf(); 26757 var days = this._tasks.trace_x_ascending, 26758 ignores = this._tasks.ignore_x; 26759 26760 var state = this.$gantt.getState(); 26761 26762 if (pos <= state.min_date) { 26763 if(this._tasks.rtl){ 26764 return days.length; 26765 }else{ 26766 return 0; 26767 } 26768 26769 } 26770 26771 if (pos >= state.max_date) { 26772 if(this._tasks.rtl){ 26773 return 0; 26774 }else{ 26775 return days.length; 26776 } 26777 } 26778 26779 var dateIndex = _findBinary(days, pos); 26780 26781 var visibleIndex = this._getClosestVisibleColumn(dateIndex, days, ignores); 26782 var visibleDate = days[visibleIndex]; 26783 var transition = this._tasks.trace_index_transition; 26784 26785 if(!visibleDate){ 26786 if(transition){ 26787 return transition[0]; 26788 }else{ 26789 return 0; 26790 } 26791 } 26792 26793 var part = ((date - days[visibleIndex]) / this._getColumnDuration(this._tasks, days[visibleIndex])); 26794 if(transition){ 26795 return transition[visibleIndex] + (1 - part); 26796 }else{ 26797 return visibleIndex + part; 26798 } 26799 }, 26800 getItemPosition:function (task, start_date, end_date) { 26801 var xLeft, xRight, width; 26802 if(this._tasks.rtl){ 26803 xRight = this.posFromDate(start_date || task.start_date); 26804 xLeft = this.posFromDate(end_date || task.end_date); 26805 }else{ 26806 xLeft = this.posFromDate(start_date || task.start_date); 26807 xRight = this.posFromDate(end_date || task.end_date); 26808 } 26809 width = Math.max((xRight - xLeft), 0); 26810 26811 var y = this.getItemTop(task.id); 26812 var height = this.getItemHeight(); 26813 return { 26814 left: xLeft, 26815 top: y, 26816 height: height, 26817 width: width 26818 }; 26819 }, 26820 26821 getItemHeight: function(){ 26822 var config = this.$getConfig(); 26823 26824 // height of the bar item 26825 var height = config.task_height; 26826 26827 if (height == "full") { 26828 var offset = config.task_height_offset || 5; 26829 height = config.row_height - offset; 26830 } 26831 //item height cannot be bigger than row height 26832 height = Math.min(height, config.row_height); 26833 return Math.max(height, 0); 26834 }, 26835 26836 getScale: function(){ 26837 return this._tasks; 26838 }, 26839 26840 _getScales: function _get_scales() { 26841 var config = this.$getConfig(); 26842 var helpers = this.$scaleHelper; 26843 var scales = [helpers.primaryScale(config)].concat(helpers.getSubScales(config)); 26844 26845 helpers.sortScales(scales); 26846 return scales; 26847 }, 26848 26849 _getColumnDuration: function _get_coll_duration(scale, date) { 26850 return this.$gantt.date.add(date, scale.step, scale.unit) - date; 26851 }, 26852 _bindStore: function () { 26853 if (this.$config.bind){ 26854 var rowStore = this.$gantt.getDatastore(this.$config.bind); 26855 this.$config.rowStore = rowStore; 26856 if(rowStore && !rowStore._timelineCacheAttached){ 26857 var self = this; 26858 rowStore._timelineCacheAttached = rowStore.attachEvent("onBeforeFilter", function(){ 26859 self._resetTopPositionHeight(); 26860 }); 26861 } 26862 } 26863 }, 26864 _unbindStore: function(){ 26865 if (this.$config.bind){ 26866 var rowStore = this.$gantt.getDatastore(this.$config.bind); 26867 if(rowStore._timelineCacheAttached){ 26868 rowStore.detachEvent(rowStore._timelineCacheAttached); 26869 rowStore._timelineCacheAttached = false; 26870 } 26871 } 26872 }, 26873 refresh: function(){ 26874 this._bindStore(); 26875 26876 if(this.$config.bindLinks) { 26877 this.$config.linkStore = this.$gantt.getDatastore(this.$config.bindLinks); 26878 } 26879 26880 this._resetTopPositionHeight(); 26881 this._initStaticBackgroundRender(); 26882 this._render_tasks_scales(); 26883 }, 26884 26885 destructor: function(){ 26886 var gantt = this.$gantt; 26887 this._clearLayers(gantt); 26888 this._unbindStore(); 26889 this.$task = null; 26890 this.$task_scale = null; 26891 this.$task_data = null; 26892 this.$task_bg = null; 26893 this.$task_links = null; 26894 this.$task_bars = null; 26895 26896 this.$gantt = null; 26897 26898 if(this.$config.rowStore){ 26899 this.$config.rowStore.detachEvent(this._staticBgHandler); 26900 this.$config.rowStore = null; 26901 } 26902 if(this.$config.linkStore){ 26903 this.$config.linkStore = null; 26904 } 26905 26906 if(this._timelineDragScroll) { 26907 this._timelineDragScroll.destructor(); 26908 this._timelineDragScroll = null; 26909 } 26910 26911 this.callEvent("onDestroy", []); 26912 this.detachAllEvents(); 26913 26914 } 26915}; 26916 26917module.exports = Timeline; 26918 26919function _findBinary(array, target) { 26920 // modified binary search, target value not exactly match array elements, looking for closest one 26921 26922 var low = 0, high = array.length - 1, i, item, prev; 26923 while (low <= high) { 26924 26925 i = Math.floor((low + high) / 2); 26926 item = +array[i]; 26927 prev = +array[i - 1]; 26928 if (item < target) { 26929 low = i + 1; 26930 continue; 26931 } 26932 if (item > target) { 26933 if (!(!isNaN(prev) && prev < target)) { 26934 high = i - 1; 26935 continue; 26936 } else { 26937 // if target is between 'i' and 'i-1' return 'i - 1' 26938 return i - 1; 26939 } 26940 26941 } 26942 while (+array[i] == +array[i + 1]) i++; 26943 26944 return i; 26945 } 26946 return array.length - 1; 26947} 26948 26949 26950 26951/***/ }), 26952 26953/***/ "./sources/core/ui/ui_factory.js": 26954/*!***************************************!*\ 26955 !*** ./sources/core/ui/ui_factory.js ***! 26956 \***************************************/ 26957/*! no static exports found */ 26958/***/ (function(module, exports, __webpack_require__) { 26959 26960var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"), 26961 configurable = __webpack_require__(/*! ./configurable */ "./sources/core/ui/configurable.js"); 26962 26963var uiFactory = function createFactory(gantt){ 26964 var views = {}; 26965 26966 function ui(cell, parentView) { 26967 var content; 26968 var view = "cell"; 26969 if (cell.view){ 26970 view = "viewcell"; 26971 }else if (cell.resizer) { 26972 view = "resizer"; 26973 } 26974 else if (cell.rows || cell.cols) { 26975 view = "layout"; 26976 } 26977 else if (cell.views) { 26978 view = "multiview"; 26979 } 26980 26981 content = createView.call(this, view, null, cell, parentView); 26982 return content; 26983 } 26984 26985 var createdViews = {}; 26986 26987 function createView(name, parent, config, parentView) { 26988 var creator = views[name]; 26989 26990 if(!creator || !creator.create) 26991 return false; 26992 26993 if(name == "resizer" && !config.mode){ 26994 if(parentView.$config.cols){ 26995 config.mode = "x"; 26996 }else{ 26997 config.mode = "y"; 26998 } 26999 } 27000 27001 if(name == "viewcell" && config.view == "scrollbar" && !config.scroll){ 27002 if(parentView.$config.cols){ 27003 config.scroll = "y"; 27004 }else{ 27005 config.scroll = "x"; 27006 } 27007 } 27008 27009 var config = utils.copy(config); 27010 27011 if(!config.id && !createdViews[config.view]){ 27012 config.id = config.view; 27013 } 27014 27015 if(config.id && !config.css){ 27016 config.css = config.id+"_cell"; 27017 } 27018 27019 var view = new creator.create(parent, config, this, gantt); 27020 27021 if(creator.configure){ 27022 creator.configure(view); 27023 } 27024 27025 configurable(view, parentView); 27026 if(!view.$id){ 27027 view.$id = config.id || gantt.uid(); 27028 } 27029 27030 if(!view.$parent && typeof parent == "object"){ 27031 view.$parent = parent; 27032 } 27033 if(!view.$config){ 27034 view.$config = config; 27035 } 27036 27037 if(createdViews[view.$id]){ 27038 view.$id = gantt.uid(); 27039 } 27040 27041 createdViews[view.$id] = view; 27042 27043 return view; 27044 } 27045 27046 function reset(){ 27047 createdViews = {}; 27048 } 27049 27050 function register(name, viewConstructor, configure){ 27051 views[name] = {create: viewConstructor, configure: configure}; 27052 } 27053 27054 function getView(id){ 27055 return createdViews[id]; 27056 } 27057 27058 var factory = { 27059 initUI:ui, 27060 reset: reset, 27061 registerView: register, 27062 createView: createView, 27063 getView: getView 27064 }; 27065 27066 return factory; 27067}; 27068 27069module.exports = { 27070 createFactory: uiFactory 27071}; 27072 27073 27074 27075/***/ }), 27076 27077/***/ "./sources/core/wai_aria.js": 27078/*!**********************************!*\ 27079 !*** ./sources/core/wai_aria.js ***! 27080 \**********************************/ 27081/*! no static exports found */ 27082/***/ (function(module, exports) { 27083 27084module.exports = function(gantt){ 27085 // TODO: why eslint fails on regexp? 27086 // eslint-disable-next-line no-control-regex 27087 var htmlTags = new RegExp("<(?:.|\n)*?>", "gm"); 27088 var extraSpaces = new RegExp(" +", "gm"); 27089 27090 function stripHTMLLite(htmlText){ 27091 return (htmlText + "") 27092 .replace(htmlTags, " "). 27093 replace(extraSpaces, " "); 27094 } 27095 27096 var singleQuotes = new RegExp("'", "gm"); 27097 function escapeQuotes(text){ 27098 return (text + "").replace(singleQuotes, "'"); 27099 } 27100 27101 gantt._waiAria = { 27102 getAttributeString: function(attr){ 27103 var attributes = [" "]; 27104 for(var i in attr){ 27105 var text = escapeQuotes(stripHTMLLite(attr[i])); 27106 attributes.push(i + "='" + text + "'"); 27107 } 27108 attributes.push(" "); 27109 return attributes.join(" "); 27110 27111 }, 27112 27113 getTimelineCellAttr:function(dateString){ 27114 27115 return gantt._waiAria.getAttributeString({"aria-label": dateString}); 27116 }, 27117 27118 _taskCommonAttr: function(task, div){ 27119 27120 if(!(task.start_date && task.end_date)) 27121 return; 27122 27123 div.setAttribute("aria-label", stripHTMLLite(gantt.templates.tooltip_text(task.start_date, task.end_date, task))); 27124 27125 if(task.$dataprocessor_class){ 27126 div.setAttribute("aria-busy", true); 27127 } 27128 27129 div.setAttribute("aria-selected", gantt.isSelectedTask(task.id) ? "true" : "false"); 27130 }, 27131 27132 setTaskBarAttr: function(task, div){ 27133 this._taskCommonAttr(task, div); 27134 27135 if(!gantt.isReadonly(task) && gantt.config.drag_move){ 27136 if(task.id != gantt.getState().drag_id){ 27137 div.setAttribute("aria-grabbed", false); 27138 }else{ 27139 div.setAttribute("aria-grabbed", true); 27140 } 27141 } 27142 }, 27143 27144 taskRowAttr: function(task, div){ 27145 27146 this._taskCommonAttr(task, div); 27147 27148 if(!gantt.isReadonly(task) && gantt.config.order_branch){ 27149 div.setAttribute("aria-grabbed", false); 27150 } 27151 27152 div.setAttribute("role", "row"); 27153 27154 div.setAttribute("aria-level", task.$level); 27155 27156 if(gantt.hasChild(task.id)){ 27157 div.setAttribute("aria-expanded", task.$open ? "true" : "false"); 27158 } 27159 }, 27160 27161 linkAttr: function(link, div){ 27162 27163 var linkTypes = gantt.config.links; 27164 27165 var toStart = link.type == linkTypes.finish_to_start || link.type == linkTypes.start_to_start; 27166 var fromStart = link.type == linkTypes.start_to_start || link.type == linkTypes.start_to_finish; 27167 27168 var content = gantt.locale.labels.link + " " + gantt.templates.drag_link(link.source, fromStart, link.target, toStart); 27169 27170 div.setAttribute("aria-label", stripHTMLLite(content)); 27171 if(gantt.isReadonly(link)){ 27172 div.setAttribute("aria-readonly", true); 27173 } 27174 }, 27175 27176 gridSeparatorAttr: function(div){ 27177 div.setAttribute("role", "separator"); 27178 }, 27179 27180 lightboxHiddenAttr: function(div){ 27181 div.setAttribute("aria-hidden", "true"); 27182 }, 27183 27184 lightboxVisibleAttr: function(div){ 27185 div.setAttribute("aria-hidden", "false"); 27186 }, 27187 27188 lightboxAttr: function(div){ 27189 div.setAttribute("role", "dialog"); 27190 div.setAttribute("aria-hidden", "true"); 27191 div.firstChild.setAttribute("role", "heading"); 27192 }, 27193 27194 lightboxButtonAttrString:function(buttonName){ 27195 return this.getAttributeString({"role":"button", "aria-label":gantt.locale.labels[buttonName], "tabindex":"0"}); 27196 }, 27197 27198 lightboxHeader: function(div, headerText){ 27199 div.setAttribute("aria-label", headerText); 27200 }, 27201 27202 lightboxSelectAttrString: function(time_option){ 27203 var label = ""; 27204 27205 switch (time_option) { 27206 case "%Y": 27207 label = gantt.locale.labels.years; 27208 break; 27209 case "%m": 27210 label = gantt.locale.labels.months; 27211 break; 27212 case "%d": 27213 label = gantt.locale.labels.days; 27214 break; 27215 case "%H:%i": 27216 label = gantt.locale.labels.hours + gantt.locale.labels.minutes; 27217 break; 27218 default: 27219 break; 27220 } 27221 27222 return gantt._waiAria.getAttributeString({"aria-label": label}); 27223 }, 27224 27225 lightboxDurationInputAttrString: function(section){ 27226 return this.getAttributeString({"aria-label": gantt.locale.labels.column_duration, "aria-valuemin": "0"}); 27227 }, 27228 27229 gridAttrString: function(){ 27230 return [" role='treegrid'", gantt.config.multiselect ? "aria-multiselectable='true'" : "aria-multiselectable='false'", " "].join(" "); 27231 }, 27232 27233 27234 gridScaleRowAttrString: function(){ 27235 return "role='row'"; 27236 }, 27237 27238 gridScaleCellAttrString: function(column, label){ 27239 var attrs = ""; 27240 if(column.name == "add"){ 27241 attrs = this.getAttributeString({"role":"button", "aria-label": gantt.locale.labels.new_task}); 27242 }else{ 27243 27244 var attributes = { 27245 "role":"columnheader", 27246 "aria-label": label 27247 }; 27248 27249 if(gantt._sort && gantt._sort.name == column.name){ 27250 if(gantt._sort.direction == "asc"){ 27251 attributes["aria-sort"] = "ascending"; 27252 }else{ 27253 attributes["aria-sort"] = "descending"; 27254 } 27255 } 27256 27257 attrs = this.getAttributeString(attributes); 27258 } 27259 return attrs; 27260 }, 27261 27262 gridDataAttrString: function(){ 27263 return "role='rowgroup'"; 27264 }, 27265 27266 gridCellAttrString: function(column, textValue, task){ 27267 var attributes = {"role":"gridcell", "aria-label": textValue}; 27268 if(!column.editor || gantt.isReadonly(task)){ 27269 attributes["aria-readonly"] = true; 27270 } 27271 27272 return this.getAttributeString(attributes); 27273 }, 27274 27275 gridAddButtonAttrString: function(column){ 27276 return this.getAttributeString({"role":"button", "aria-label": gantt.locale.labels.new_task}); 27277 }, 27278 27279 messageButtonAttrString: function(buttonLabel){ 27280 return "tabindex='0' role='button' aria-label='"+buttonLabel+"'"; 27281 }, 27282 27283 messageInfoAttr: function(div){ 27284 div.setAttribute("role", "alert"); 27285 //div.setAttribute("tabindex", "-1"); 27286 }, 27287 27288 messageModalAttr: function(div, uid){ 27289 div.setAttribute("role", "dialog"); 27290 if(uid){ 27291 div.setAttribute("aria-labelledby", uid); 27292 } 27293 27294 // div.setAttribute("tabindex", "-1"); 27295 }, 27296 27297 quickInfoAttr: function(div){ 27298 div.setAttribute("role", "dialog"); 27299 }, 27300 27301 quickInfoHeaderAttrString: function(){ 27302 return " role='heading' "; 27303 }, 27304 27305 quickInfoHeader: function(div, header){ 27306 div.setAttribute("aria-label", header); 27307 }, 27308 27309 quickInfoButtonAttrString: function(label){ 27310 return gantt._waiAria.getAttributeString({"role":"button", "aria-label":label, "tabindex":"0"}); 27311 }, 27312 27313 tooltipAttr: function(div){ 27314 div.setAttribute("role", "tooltip"); 27315 }, 27316 27317 tooltipVisibleAttr: function(div){ 27318 div.setAttribute("aria-hidden", "false"); 27319 }, 27320 27321 tooltipHiddenAttr: function(div){ 27322 div.setAttribute("aria-hidden", "true"); 27323 } 27324 }; 27325 27326 function isDisabled(){ 27327 return !gantt.config.wai_aria_attributes; 27328 } 27329 27330 for(var i in gantt._waiAria){ 27331 gantt._waiAria[i] = (function(payload){ 27332 return function(){ 27333 if(isDisabled()){ 27334 return ""; 27335 } 27336 return payload.apply(this, arguments); 27337 }; 27338 })(gantt._waiAria[i]); 27339 } 27340 27341 27342}; 27343 27344/***/ }), 27345 27346/***/ "./sources/core/worktime/calendar_arguments_helper.js": 27347/*!************************************************************!*\ 27348 !*** ./sources/core/worktime/calendar_arguments_helper.js ***! 27349 \************************************************************/ 27350/*! no static exports found */ 27351/***/ (function(module, exports, __webpack_require__) { 27352 27353var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 27354var helpers = __webpack_require__(/*! ../../utils/helpers */ "./sources/utils/helpers.js"); 27355 27356 27357function IsWorkTimeArgument(date, unit, task, id, calendar){ 27358 this.date = date; 27359 this.unit = unit; 27360 this.task = task; 27361 this.id = id; 27362 this.calendar = calendar; 27363 return this; 27364} 27365 27366function ClosestWorkTimeArgument(date, dir, unit, task, id, calendar){ 27367 this.date = date; 27368 this.dir = dir; 27369 this.unit = unit; 27370 this.task = task; 27371 this.id = id; 27372 this.calendar = calendar; 27373 return this; 27374} 27375 27376function CalculateEndDateArgument(start_date, duration, unit, step, task, id, calendar){ 27377 this.start_date = start_date; 27378 this.duration = duration; 27379 this.unit = unit; 27380 this.step = step; 27381 this.task = task; 27382 this.id = id; 27383 this.calendar = calendar; 27384 return this; 27385} 27386 27387function GetDurationArgument(start, end, task, calendar) { 27388 this.start_date = start; 27389 this.end_date = end; 27390 this.task = task; 27391 this.calendar = calendar; 27392 this.unit = null; 27393 this.step = null; 27394 return this; 27395} 27396 27397var calendarArgumentsHelper = function(gantt){ 27398 return { 27399 getWorkHoursArguments: function () { 27400 var config = arguments[0]; 27401 if (helpers.isDate(config)) { 27402 config = { 27403 date: config 27404 }; 27405 } else { 27406 config = utils.mixin({}, config); 27407 } 27408 27409 if(!helpers.isValidDate(config.date)){ 27410 gantt.assert(false, "Invalid date argument for getWorkHours method"); 27411 throw new Error("Invalid date argument for getWorkHours method"); 27412 } 27413 27414 return config; 27415 }, 27416 setWorkTimeArguments: function () { 27417 return arguments[0]; 27418 }, 27419 unsetWorkTimeArguments: function () { 27420 return arguments[0]; 27421 }, 27422 isWorkTimeArguments: function () { 27423 var config = arguments[0]; 27424 if(config instanceof IsWorkTimeArgument){ 27425 return config; 27426 } 27427 27428 var processedConfig; 27429 if (!config.date) { 27430 //IsWorkTimeArgument(date, unit, task, id, calendar) 27431 processedConfig = new IsWorkTimeArgument(arguments[0], arguments[1], arguments[2], null, arguments[3]); 27432 } else { 27433 processedConfig = new IsWorkTimeArgument(config.date, config.unit, config.task, null, config.calendar); 27434 } 27435 27436 processedConfig.unit = processedConfig.unit || gantt.config.duration_unit; 27437 27438 if(!helpers.isValidDate(processedConfig.date)){ 27439 gantt.assert(false, "Invalid date argument for isWorkTime method"); 27440 throw new Error("Invalid date argument for isWorkTime method"); 27441 } 27442 27443 return processedConfig; 27444 }, 27445 getClosestWorkTimeArguments: function (arg) { 27446 var config = arguments[0]; 27447 if (config instanceof ClosestWorkTimeArgument) 27448 return config; 27449 27450 var processedConfig; 27451 if (helpers.isDate(config)) { 27452 processedConfig = new ClosestWorkTimeArgument(config); 27453 27454 } else { 27455 processedConfig = new ClosestWorkTimeArgument( 27456 config.date, 27457 config.dir, 27458 config.unit, 27459 config.task, 27460 null,//config.id, 27461 config.calendar 27462 ); 27463 } 27464 27465 if(config.id){ 27466 processedConfig.task = config; 27467 } 27468 processedConfig.dir = config.dir || 'any'; 27469 processedConfig.unit = config.unit || gantt.config.duration_unit; 27470 27471 if(!helpers.isValidDate(processedConfig.date)){ 27472 gantt.assert(false, "Invalid date argument for getClosestWorkTime method"); 27473 throw new Error("Invalid date argument for getClosestWorkTime method"); 27474 } 27475 return processedConfig; 27476 }, 27477 27478 _getStartEndConfig: function (param) { 27479 var argumentType = GetDurationArgument; 27480 var config; 27481 if (param instanceof argumentType) 27482 return param; 27483 27484 if (helpers.isDate(param)) { 27485 config = new argumentType(arguments[0], arguments[1], arguments[2], arguments[3]); 27486 } else { 27487 config = new argumentType(param.start_date, param.end_date, param.task); 27488 if (param.id) { 27489 config.task = param; 27490 } 27491 } 27492 27493 config.unit = config.unit || gantt.config.duration_unit; 27494 config.step = config.step || gantt.config.duration_step; 27495 config.start_date = config.start_date || config.start || config.date; 27496 27497 if(!helpers.isValidDate(config.start_date)){ 27498 gantt.assert(false, "Invalid start_date argument for getDuration method"); 27499 throw new Error("Invalid start_date argument for getDuration method"); 27500 } 27501 27502 if(!helpers.isValidDate(config.end_date)){ 27503 gantt.assert(false, "Invalid end_date argument for getDuration method"); 27504 throw new Error("Invalid end_date argument for getDuration method"); 27505 } 27506 27507 return config; 27508 }, 27509 27510 getDurationArguments: function (start, end, unit, step) { 27511 return this._getStartEndConfig.apply(this, arguments); 27512 }, 27513 27514 hasDurationArguments: function (start, end, unit, step) { 27515 return this._getStartEndConfig.apply(this, arguments); 27516 }, 27517 27518 calculateEndDateArguments: function (start, duration, unit, step) { 27519 var config = arguments[0]; 27520 if (config instanceof CalculateEndDateArgument) 27521 return config; 27522 27523 var processedConfig; 27524 //CalculateEndDateArgument(start_date, duration, unit, step, task, id, calendar) 27525 if (helpers.isDate(config)) { 27526 processedConfig = new CalculateEndDateArgument( 27527 arguments[0], 27528 arguments[1], 27529 arguments[2], 27530 undefined, 27531 arguments[3], 27532 undefined, 27533 arguments[4] 27534 ); 27535 27536 } else { 27537 processedConfig = new CalculateEndDateArgument( 27538 config.start_date, 27539 config.duration, 27540 config.unit, 27541 config.step, 27542 config.task, 27543 null,//config.id, 27544 config.calendar 27545 ); 27546 } 27547 if(config.id){ 27548 processedConfig.task = config; 27549 27550 // received a task object as an argument 27551 // ignore 'unit' and 'step' properties in this case, since it's likely a part of data model of a task 27552 processedConfig.unit = null; 27553 processedConfig.step = null; 27554 } 27555 27556 processedConfig.unit = processedConfig.unit || gantt.config.duration_unit; 27557 processedConfig.step = processedConfig.step || gantt.config.duration_step; 27558 27559 if(!helpers.isValidDate(processedConfig.start_date)){ 27560 gantt.assert(false, "Invalid start_date argument for calculateEndDate method"); 27561 throw new Error("Invalid start_date argument for calculateEndDate method"); 27562 } 27563 27564 return processedConfig; 27565 } 27566 }; 27567}; 27568 27569 27570module.exports = calendarArgumentsHelper; 27571 27572/***/ }), 27573 27574/***/ "./sources/core/worktime/calendar_manager.js": 27575/*!***************************************************!*\ 27576 !*** ./sources/core/worktime/calendar_manager.js ***! 27577 \***************************************************/ 27578/*! no static exports found */ 27579/***/ (function(module, exports, __webpack_require__) { 27580 27581var utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 27582var createArgumentsHelper = __webpack_require__(/*! ./calendar_arguments_helper */ "./sources/core/worktime/calendar_arguments_helper.js"); 27583var CalendarWorktimeStrategy = __webpack_require__(/*! ./strategy/calendar_strategy */ "./sources/core/worktime/strategy/calendar_strategy.js"); 27584 27585function CalendarManager (gantt){ 27586 this.$gantt = gantt; 27587 this._calendars = {}; 27588} 27589 27590CalendarManager.prototype = { 27591 _calendars: {}, 27592 _getDayHoursForMultiple: function (calendars, date) { 27593 var units = [], 27594 tick = true, 27595 currPos = 0, 27596 is_work_hour = false, 27597 start = this.$gantt.date.day_start(new Date(date)); 27598 for (var hour = 0; hour < 24; hour++) { 27599 is_work_hour = calendars.reduce(function (acc, calendar) { 27600 return acc && calendar._is_work_hour(start); 27601 }, true); 27602 if (is_work_hour) { 27603 if (tick) { 27604 units[currPos] = hour; 27605 units[currPos + 1] = (hour + 1); 27606 currPos += 2; 27607 } else { 27608 units[currPos - 1] += 1; 27609 } 27610 tick = false; 27611 } else if (!tick) { 27612 tick = true; 27613 } 27614 start = this.$gantt.date.add(start, 1, "hour"); 27615 } 27616 if (!units.length) 27617 units = false; 27618 return units; 27619 }, 27620 mergeCalendars: function () { 27621 var newCalendar = this.createCalendar(), 27622 day, 27623 units = []; 27624 var calendars = Array.prototype.slice.call(arguments, 0); 27625 newCalendar.worktime.hours = [0, 24]; 27626 newCalendar.worktime.dates = {}; 27627 var start = this.$gantt.date.day_start(new Date(259200000)); // 1970 day=0 27628 for (day = 0; day < 7; day++) { 27629 units = this._getDayHoursForMultiple(calendars, start); 27630 newCalendar.worktime.dates[day] = units; 27631 start = this.$gantt.date.add(start, 1, "day"); 27632 } 27633 for (var i = 0; i < calendars.length; i++) { 27634 for (var value in calendars[i].worktime.dates) if (+value > 10000) { 27635 units = this._getDayHoursForMultiple(calendars, new Date(+value)); 27636 newCalendar.worktime.dates[value] = units; 27637 } 27638 } 27639 return newCalendar; 27640 }, 27641 27642 _convertWorktimeSettings: function (settings) { 27643 var days = settings.days; 27644 if (days) { 27645 settings.dates = settings.dates || {}; 27646 for (var i = 0; i < days.length; i++) { 27647 settings.dates[i] = days[i]; 27648 if (!(days[i] instanceof Array)) { 27649 settings.dates[i] = !!days[i]; 27650 } 27651 } 27652 delete settings.days; 27653 } 27654 return settings; 27655 }, 27656 27657 createCalendar: function (parentCalendar) { 27658 var settings; 27659 27660 if (!parentCalendar) { 27661 parentCalendar = {}; 27662 } 27663 27664 if (parentCalendar.worktime) { 27665 settings = utils.copy(parentCalendar.worktime); 27666 } else { 27667 settings = utils.copy(parentCalendar); 27668 } 27669 27670 var defaults = utils.copy(this.defaults.fulltime.worktime); 27671 utils.mixin(settings, defaults); 27672 27673 var id = utils.uid(); 27674 var calendar = { 27675 id: id + "", 27676 worktime: this._convertWorktimeSettings(settings) 27677 }; 27678 27679 var apiCore = new CalendarWorktimeStrategy(this.$gantt, createArgumentsHelper(this.$gantt)); 27680 utils.mixin(apiCore, calendar); 27681 27682 // validate/check if empty calendar 27683 if (!apiCore._tryChangeCalendarSettings(function () { 27684 })) { 27685 return null; 27686 } else { 27687 return apiCore; 27688 } 27689 }, 27690 27691 getCalendar: function (id) { 27692 id = id || "global"; 27693 this.createDefaultCalendars(); 27694 return this._calendars[id]; 27695 }, 27696 27697 getCalendars: function () { 27698 var res = []; 27699 for (var i in this._calendars) { 27700 res.push(this.getCalendar(i)); 27701 } 27702 return res; 27703 }, 27704 27705 _getOwnCalendar: function(task){ 27706 var config = this.$gantt.config; 27707 if (task[config.calendar_property]) { 27708 return this.getCalendar(task[config.calendar_property]); 27709 } 27710 27711 if (config.resource_calendars) { 27712 for (var field in config.resource_calendars) { 27713 var resource = config.resource_calendars[field]; 27714 if (task[field]) { 27715 var calendarId = resource[task[field]]; 27716 if (calendarId) { 27717 return this.getCalendar(calendarId); 27718 } 27719 } 27720 } 27721 } 27722 return null; 27723 }, 27724 27725 getTaskCalendar: function (task) { 27726 if (!task) { 27727 return this.getCalendar(); 27728 } 27729 27730 var calendar = this._getOwnCalendar(task); 27731 var gantt = this.$gantt; 27732 if (!calendar && gantt.config.inherit_calendar && gantt.isTaskExists(task.parent)){ 27733 var stop = false; 27734 gantt.eachParent(function(parent){ 27735 if(stop) return; 27736 if(gantt.isSummaryTask(parent)){ 27737 calendar = this._getOwnCalendar(parent); 27738 if(calendar){ 27739 stop = true; 27740 } 27741 } 27742 }, task.id, this); 27743 } 27744 27745 return calendar || this.getCalendar(); 27746 }, 27747 27748 addCalendar: function (calendar) { // puts new calendar to Global Storage - gantt.calendarManager._calendars {} 27749 if (!(calendar instanceof CalendarWorktimeStrategy)) { 27750 var id = calendar.id; 27751 calendar = this.createCalendar(calendar); 27752 calendar.id = id; 27753 } 27754 var config = this.$gantt.config; 27755 27756 calendar.id = calendar.id || utils.uid(); 27757 this._calendars[calendar.id] = calendar; 27758 if (!config.worktimes) 27759 config.worktimes = {}; 27760 config.worktimes[calendar.id] = calendar.worktime; 27761 return calendar.id; 27762 }, 27763 27764 deleteCalendar: function (calendar) { 27765 var config = this.$gantt.config; 27766 if (!calendar) return false; 27767 if (this._calendars[calendar]) { 27768 delete this._calendars[calendar]; 27769 if (config.worktimes && config.worktimes[calendar]) 27770 delete config.worktimes[calendar]; 27771 return true; 27772 } else { 27773 return false; 27774 } }, 27775 27776 restoreConfigCalendars: function (configs) { 27777 for (var i in configs) { 27778 if (this._calendars[i]) 27779 continue; 27780 27781 var settings = configs[i]; 27782 var calendar = this.createCalendar(settings); 27783 calendar.id = i; 27784 this.addCalendar(calendar); 27785 } 27786 }, 27787 27788 defaults: { 27789 global: { 27790 id: "global", 27791 worktime: { 27792 hours: [8, 17], 27793 days: [0, 1, 1, 1, 1, 1, 0] 27794 } 27795 }, 27796 fulltime: { 27797 id: "fulltime", 27798 worktime: { 27799 hours: [0, 24], 27800 days: [1, 1, 1, 1, 1, 1, 1] 27801 } 27802 } 27803 }, 27804 27805 createDefaultCalendars: function () { 27806 var config = this.$gantt.config; 27807 this.restoreConfigCalendars(this.defaults); 27808 this.restoreConfigCalendars(config.worktimes); 27809 } 27810}; 27811 27812module.exports = CalendarManager; 27813 27814/***/ }), 27815 27816/***/ "./sources/core/worktime/strategy/calendar_strategy.js": 27817/*!*************************************************************!*\ 27818 !*** ./sources/core/worktime/strategy/calendar_strategy.js ***! 27819 \*************************************************************/ 27820/*! no static exports found */ 27821/***/ (function(module, exports, __webpack_require__) { 27822 27823var cacheFactory = __webpack_require__(/*! ./work_unit_cache */ "./sources/core/worktime/strategy/work_unit_cache/index.ts"), 27824 utils = __webpack_require__(/*! ../../../utils/utils */ "./sources/utils/utils.js"); 27825 27826function CalendarWorkTimeStrategy(gantt, argumentsHelper){ 27827 this.argumentsHelper = argumentsHelper; 27828 this.$gantt = gantt; 27829 this._workingUnitsCache = cacheFactory.createCacheObject(); 27830} 27831 27832CalendarWorkTimeStrategy.prototype = { 27833 units: [ 27834 "year", 27835 "month", 27836 "week", 27837 "day", 27838 "hour", 27839 "minute" 27840 ], 27841 // cache previously calculated worktime 27842 _getUnitOrder: function (unit) { 27843 for (var i = 0, len = this.units.length; i < len; i++) { 27844 if (this.units[i] == unit) 27845 return i; 27846 } 27847 }, 27848 _timestamp: function (settings) { 27849 27850 var timestamp = null; 27851 if ((settings.day || settings.day === 0)) { 27852 timestamp = settings.day; 27853 } else if (settings.date) { 27854 // store worktime datestamp in utc so it could be recognized in different timezones (e.g. opened locally and sent to the export service in different timezone) 27855 timestamp = Date.UTC(settings.date.getFullYear(), settings.date.getMonth(), settings.date.getDate()); 27856 } 27857 return timestamp; 27858 }, 27859 _checkIfWorkingUnit: function (date, unit, order) { 27860 if (order === undefined) { 27861 order = this._getUnitOrder(unit); 27862 } 27863 27864 // disable worktime check for custom time units 27865 if (order === undefined) { 27866 return true; 27867 } 27868 if (order) { 27869 //check if bigger time unit is a work time (hour < day < month...) 27870 //i.e. don't check particular hour if the whole day is marked as not working 27871 if (!this._isWorkTime(date, this.units[order - 1], order - 1)) 27872 return false; 27873 } 27874 if (!this["_is_work_" + unit]) 27875 return true; 27876 return this["_is_work_" + unit](date); 27877 }, 27878 //checkings for particular time units 27879 //methods for month-year-week can be defined, otherwise always return 'true' 27880 _is_work_day: function (date) { 27881 var val = this._getWorkHours(date); 27882 27883 if (val instanceof Array) { 27884 return val.length > 0; 27885 } 27886 return false; 27887 }, 27888 _is_work_hour: function (date) { 27889 var hours = this._getWorkHours(date); // [7,12] or [] 27890 var hour = date.getHours(); 27891 for (var i = 0; i < hours.length; i += 2) { 27892 if (hours[i + 1] === undefined) { 27893 return hours[i] == hour; 27894 } else { 27895 if (hour >= hours[i] && hour < hours[i + 1]) 27896 return true; 27897 } 27898 } 27899 return false; 27900 }, 27901 _internDatesPull: {}, 27902 _nextDate: function (start, unit, step) { 27903 var dateHelper = this.$gantt.date; 27904 return dateHelper.add(start, step, unit); 27905 27906 /*var start_value = +start, 27907 key = unit + "_" + step; 27908 var interned = this._internDatesPull[key]; 27909 if(!interned){ 27910 interned = this._internDatesPull[key] = {}; 27911 } 27912 var calculated; 27913 if(!interned[start_value]){ 27914 interned[start_value] = calculated = dateHelper.add(start, step, unit); 27915 //interned[start_value] = dateHelper.add(start, step, unit); 27916 } 27917 return calculated || interned[start_value];*/ 27918 }, 27919 _getWorkUnitsBetweenGeneric: function (from, to, unit, step) { 27920 var dateHelper = this.$gantt.date; 27921 var start = new Date(from), 27922 end = new Date(to); 27923 step = step || 1; 27924 var units = 0; 27925 27926 27927 var next = null; 27928 var stepStart, 27929 stepEnd; 27930 27931 // calculating decimal durations, i.e. 2016-09-20 00:05:00 - 2016-09-20 01:00:00 ~ 0.95 instead of 1 27932 // and also 2016-09-20 00:00:00 - 2016-09-20 00:05:00 ~ 0.05 instead of 1 27933 // durations must be rounded later 27934 var checkFirst = false; 27935 stepStart = dateHelper[unit + "_start"](new Date(start)); 27936 if (stepStart.valueOf() != start.valueOf()) { 27937 checkFirst = true; 27938 } 27939 var checkLast = false; 27940 stepEnd = dateHelper[unit + "_start"](new Date(to)); 27941 if (stepEnd.valueOf() != to.valueOf()) { 27942 checkLast = true; 27943 } 27944 27945 var isLastStep = false; 27946 while (start.valueOf() < end.valueOf()) { 27947 next = this._nextDate(start, unit, step); 27948 isLastStep = (next.valueOf() > end.valueOf()); 27949 27950 if (this._isWorkTime(start, unit)) { 27951 if (checkFirst || (checkLast && isLastStep)) { 27952 stepStart = dateHelper[unit + "_start"](new Date(start)); 27953 stepEnd = dateHelper.add(stepStart, step, unit); 27954 } 27955 27956 if (checkFirst) { 27957 checkFirst = false; 27958 next = this._nextDate(stepStart, unit, step); 27959 units += ((stepEnd.valueOf() - start.valueOf()) / (stepEnd.valueOf() - stepStart.valueOf())); 27960 } else if (checkLast && isLastStep) { 27961 checkLast = false; 27962 units += ((end.valueOf() - start.valueOf()) / (stepEnd.valueOf() - stepStart.valueOf())); 27963 27964 } else { 27965 units++; 27966 } 27967 } 27968 start = next; 27969 } 27970 return units; 27971 }, 27972 27973 _getMinutesPerDay: function (date) { 27974 // current api doesn't allow setting working minutes, so use hardcoded 60 minutes per hour 27975 return this._getHoursPerDay(date) * 60; 27976 }, 27977 _getHoursPerDay: function (date) { 27978 var hours = this._getWorkHours(date); 27979 var res = 0; 27980 for (var i = 0; i < hours.length; i += 2) { 27981 res += ((hours[i + 1] - hours[i]) || 0); 27982 } 27983 return res; 27984 }, 27985 _getWorkUnitsForRange: function (from, to, unit, step) { 27986 var total = 0; 27987 var start = new Date(from), 27988 end = new Date(to); 27989 27990 var getUnitsPerDay; 27991 if (unit == "minute") { 27992 getUnitsPerDay = utils.bind(this._getMinutesPerDay, this); 27993 } else { 27994 getUnitsPerDay = utils.bind(this._getHoursPerDay, this); 27995 } 27996 27997 while (start.valueOf() < end.valueOf()) { 27998 if (this._isWorkTime(start, "day")) { 27999 total += getUnitsPerDay(start); 28000 } 28001 start = this._nextDate(start, "day", 1); 28002 } 28003 28004 return total / step; 28005 }, 28006 28007 // optimized method for calculating work units duration of large time spans 28008 // implemented for hours and minutes units, bigger time units don't benefit from the optimization so much 28009 _getWorkUnitsBetweenQuick: function (from, to, unit, step) { 28010 var start = new Date(from), 28011 end = new Date(to); 28012 step = step || 1; 28013 28014 var firstDayStart = new Date(start); 28015 var firstDayEnd = this.$gantt.date.add(this.$gantt.date.day_start(new Date(start)), 1, "day"); 28016 28017 if (end.valueOf() <= firstDayEnd.valueOf()) { 28018 return this._getWorkUnitsBetweenGeneric(from, to, unit, step); 28019 } else { 28020 28021 var lastDayStart = this.$gantt.date.day_start(new Date(end)); 28022 var lastDayEnd = end; 28023 28024 var startPart = this._getWorkUnitsBetweenGeneric(firstDayStart, firstDayEnd, unit, step); 28025 var endPart = this._getWorkUnitsBetweenGeneric(lastDayStart, lastDayEnd, unit, step); 28026 28027 var rangePart = this._getWorkUnitsForRange(firstDayEnd, lastDayStart, unit, step); 28028 var total = startPart + rangePart + endPart; 28029 28030 return total; 28031 } 28032 }, 28033 28034 _getCalendar: function () { 28035 return this.worktime; 28036 }, 28037 _setCalendar: function (settings) { 28038 this.worktime = settings; 28039 }, 28040 28041 _tryChangeCalendarSettings: function (payload) { 28042 var backup = JSON.stringify(this._getCalendar()); 28043 payload(); 28044 if (this._isEmptyCalendar(this._getCalendar())) { 28045 this.$gantt.assert(false, "Invalid calendar settings, no worktime available"); 28046 this._setCalendar(JSON.parse(backup)); 28047 this._workingUnitsCache.clear(); 28048 return false; 28049 } 28050 return true; 28051 28052 }, 28053 28054 _isEmptyCalendar: function (settings) { 28055 var result = false, 28056 datesArray = [], 28057 isFullWeekSet = true; 28058 for (var i in settings.dates) { 28059 result |= !!settings.dates[i]; 28060 datesArray.push(i); 28061 } 28062 28063 var checkFullArray = []; 28064 for (var i = 0; i < datesArray.length; i++) { 28065 if (datesArray[i] < 10) { 28066 checkFullArray.push(datesArray[i]); 28067 } 28068 } 28069 checkFullArray.sort(); 28070 28071 for (var i = 0; i < 7; i++) { 28072 if (checkFullArray[i] != i) 28073 isFullWeekSet = false; 28074 } 28075 if (isFullWeekSet) 28076 return !result; 28077 return !(result || !!settings.hours); // can still return false if separated dates are set to true 28078 }, 28079 28080 getWorkHours: function () { 28081 var config = this.argumentsHelper.getWorkHoursArguments.apply(this.argumentsHelper, arguments); 28082 return this._getWorkHours(config.date); 28083 }, 28084 _getWorkHours: function (date) { 28085 var t = this._timestamp({date: date}); 28086 var hours = true; 28087 var calendar = this._getCalendar(); 28088 if (calendar.dates[t] !== undefined) { 28089 hours = calendar.dates[t];//custom day 28090 } else if (calendar.dates[date.getDay()] !== undefined) { 28091 hours = calendar.dates[date.getDay()];//week day 28092 } 28093 if (hours === true) { 28094 return calendar.hours; 28095 } else if (hours) { 28096 return hours; 28097 } 28098 return []; 28099 }, 28100 28101 setWorkTime: function (settings) { 28102 return this._tryChangeCalendarSettings(utils.bind(function () { 28103 var hours = settings.hours !== undefined ? settings.hours : true; 28104 var timestamp = this._timestamp(settings); 28105 if (timestamp !== null) { 28106 this._getCalendar().dates[timestamp] = hours; 28107 } else { 28108 this._getCalendar().hours = hours; 28109 } 28110 this._workingUnitsCache.clear(); 28111 }, this)); 28112 }, 28113 28114 unsetWorkTime: function (settings) { 28115 return this._tryChangeCalendarSettings(utils.bind(function () { 28116 if (!settings) { 28117 this.reset_calendar(); 28118 } else { 28119 28120 var timestamp = this._timestamp(settings); 28121 28122 if (timestamp !== null) { 28123 delete this._getCalendar().dates[timestamp]; 28124 } 28125 } 28126 // Clear work units cache 28127 this._workingUnitsCache.clear(); 28128 }, this)); 28129 }, 28130 28131 _isWorkTime: function (date, unit, order) { 28132 // Check if this item has in the cache 28133 28134 // use string keys 28135 var dateKey = String(date.valueOf()); 28136 var is_work_unit = this._workingUnitsCache.getItem(unit, dateKey); 28137 28138 if (is_work_unit == -1) { 28139 // calculate if not cached 28140 is_work_unit = this._checkIfWorkingUnit(date, unit, order); 28141 this._workingUnitsCache.setItem(unit, dateKey, is_work_unit); 28142 } 28143 28144 return is_work_unit; 28145 }, 28146 28147 isWorkTime: function () { 28148 var config = this.argumentsHelper.isWorkTimeArguments.apply( this.argumentsHelper, arguments); 28149 return this._isWorkTime(config.date, config.unit); 28150 }, 28151 28152 calculateDuration: function () { 28153 var config = this.argumentsHelper.getDurationArguments.apply( this.argumentsHelper, arguments); 28154 28155 if (!config.unit) { 28156 return false; 28157 } 28158 return this._calculateDuration(config.start_date, config.end_date, config.unit, config.step); 28159 }, 28160 28161 _calculateDuration: function (from, to, unit, step) { 28162 var res = 0; 28163 if (unit == "hour" || unit == "minute") { 28164 res = this._getWorkUnitsBetweenQuick(from, to, unit, step); 28165 } else { 28166 res = this._getWorkUnitsBetweenGeneric(from, to, unit, step); 28167 } 28168 28169 // getWorkUnits.. returns decimal durations 28170 return Math.round(res); 28171 }, 28172 hasDuration: function () { 28173 var config = this.argumentsHelper.getDurationArguments.apply( this.argumentsHelper, arguments); 28174 28175 var from = config.start_date, 28176 to = config.end_date, 28177 unit = config.unit, 28178 step = config.step; 28179 28180 if (!unit) { 28181 return false; 28182 } 28183 var start = new Date(from), 28184 end = new Date(to); 28185 step = step || 1; 28186 28187 while (start.valueOf() < end.valueOf()) { 28188 if (this._isWorkTime(start, unit)) 28189 return true; 28190 start = this._nextDate(start, unit, step); 28191 } 28192 return false; 28193 }, 28194 28195 calculateEndDate: function () { 28196 var config = this.argumentsHelper.calculateEndDateArguments.apply( this.argumentsHelper, arguments); 28197 28198 var from = config.start_date, 28199 duration = config.duration, 28200 unit = config.unit, 28201 step = config.step; 28202 28203 if (!unit) 28204 return false; 28205 28206 var mult = (config.duration >= 0) ? 1 : -1; 28207 duration = Math.abs(duration * 1); 28208 return this._calculateEndDate(from, duration, unit, step * mult); 28209 }, 28210 28211 _calculateEndDate: function (from, duration, unit, step) { 28212 if (!unit) 28213 return false; 28214 28215 if (step == 1 && unit == "minute") { 28216 return this._calculateMinuteEndDate(from, duration, step); 28217 } else if (step == 1 && unit == "hour") { 28218 return this._calculateHourEndDate(from, duration, step); 28219 } else { 28220 var interval = this._addInterval(from, duration, unit, step, null); 28221 return interval.end; 28222 } 28223 }, 28224 28225 _addInterval: function (start, duration, unit, step, stopAction) { 28226 var added = 0; 28227 var current = start; 28228 while (added < duration && !(stopAction && stopAction(current))) { 28229 var next = this._nextDate(current, unit, step); 28230 if (this._isWorkTime(step > 0 ? new Date(next.valueOf() - 1) : new Date(next.valueOf() + 1), unit)) { 28231 added++; 28232 } 28233 current = next; 28234 } 28235 return { 28236 end: current, 28237 start: start, 28238 added: added 28239 }; 28240 }, 28241 28242 _calculateHourEndDate: function (from, duration, step) { 28243 var start = new Date(from), 28244 added = 0; 28245 step = step || 1; 28246 duration = Math.abs(duration * 1); 28247 28248 var interval = this._addInterval(start, duration, "hour", step, function (date) { 28249 // iterate until hour end 28250 if (!(date.getHours() || date.getMinutes() || date.getSeconds() || date.getMilliseconds())) { 28251 return true; 28252 } 28253 return false; 28254 }); 28255 28256 added = interval.added; 28257 start = interval.end; 28258 28259 var durationLeft = duration - added; 28260 28261 if (durationLeft && durationLeft > 24) { 28262 var current = start; 28263 while (added < duration) { 28264 var next = this._nextDate(current, "day", step); 28265 // reset to day start in case DST switch happens in the process 28266 next.setHours(0); 28267 next.setMinutes(0); 28268 next.setSeconds(0); 28269 if (this._isWorkTime(step > 0 ? new Date(next.valueOf() - 1) : new Date(next.valueOf() + 1), "day")) { 28270 var hours = this._getHoursPerDay(current); 28271 if (added + hours >= duration) { 28272 break; 28273 } else { 28274 added += hours; 28275 } 28276 } 28277 current = next; 28278 } 28279 start = current; 28280 } 28281 28282 if (added < duration) { 28283 var durationLeft = duration - added; 28284 interval = this._addInterval(start, durationLeft, "hour", step, null); 28285 start = interval.end; 28286 } 28287 28288 return start; 28289 }, 28290 28291 _calculateMinuteEndDate: function (from, duration, step) { 28292 28293 var start = new Date(from), 28294 added = 0; 28295 step = step || 1; 28296 duration = Math.abs(duration * 1); 28297 28298 var interval = this._addInterval(start, duration, "minute", step, function (date) { 28299 // iterate until hour end 28300 if (!(date.getMinutes() || date.getSeconds() || date.getMilliseconds())) { 28301 return true; 28302 } 28303 return false; 28304 }); 28305 28306 added = interval.added; 28307 start = interval.end; 28308 28309 if (added < duration) { 28310 var left = duration - added; 28311 var hours = Math.floor(left / 60); 28312 if (hours) { 28313 start = this._calculateEndDate(start, hours, "hour", step > 0 ? 1 : -1); 28314 added += hours * 60; 28315 } 28316 } 28317 28318 if (added < duration) { 28319 var durationLeft = duration - added; 28320 interval = this._addInterval(start, durationLeft, "minute", step, null); 28321 start = interval.end; 28322 } 28323 28324 return start; 28325 }, 28326 28327 getClosestWorkTime: function () { 28328 var settings = this.argumentsHelper.getClosestWorkTimeArguments.apply( this.argumentsHelper, arguments); 28329 return this._getClosestWorkTime(settings.date, settings.unit, settings.dir); 28330 }, 28331 28332 _getClosestWorkTime: function (inputDate, unit, direction) { 28333 var result = new Date(inputDate); 28334 28335 if (this._isWorkTime(result, unit)) { 28336 return result; 28337 } 28338 28339 result = this.$gantt.date[unit + '_start'](result); 28340 28341 if (direction == 'any' || !direction) { 28342 var closestFuture = this._getClosestWorkTimeFuture(result, unit); 28343 var closestPast = this._getClosestWorkTimePast(result, unit); 28344 if (Math.abs(closestFuture - inputDate) <= Math.abs(inputDate - closestPast)) { 28345 result = closestFuture; 28346 } else { 28347 result = closestPast; 28348 } 28349 } else if (direction == "past") { 28350 result = this._getClosestWorkTimePast(result, unit); 28351 } else { 28352 result = this._getClosestWorkTimeFuture(result, unit); 28353 } 28354 return result; 28355 }, 28356 28357 _getClosestWorkTimeFuture: function (date, unit) { 28358 return this._getClosestWorkTimeGeneric(date, unit, 1); 28359 }, 28360 28361 _getClosestWorkTimePast: function (date, unit) { 28362 var result = this._getClosestWorkTimeGeneric(date, unit, -1); 28363 // should return the end of the closest work interval 28364 return this.$gantt.date.add(result, 1, unit); 28365 }, 28366 28367 _getClosestWorkTimeGeneric: function (date, unit, increment) { 28368 var unitOrder = this._getUnitOrder(unit), 28369 biggerTimeUnit = this.units[unitOrder - 1]; 28370 28371 var result = date; 28372 28373 // be extra sure we won't fall into infinite loop, 3k seems big enough 28374 var maximumLoop = 3000, 28375 count = 0; 28376 28377 while (!this._isWorkTime(result, unit)) { 28378 if (biggerTimeUnit && !this._isWorkTime(result, biggerTimeUnit)) { 28379 // if we look for closest work hour and detect a week-end - first find the closest work day, 28380 // and continue iterations after that 28381 if (increment > 0) { 28382 result = this._getClosestWorkTimeFuture(result, biggerTimeUnit); 28383 } else { 28384 result = this._getClosestWorkTimePast(result, biggerTimeUnit); 28385 } 28386 28387 if (this._isWorkTime(result, unit)) { 28388 break; 28389 } 28390 } 28391 28392 count++; 28393 if (count > maximumLoop) { 28394 this.$gantt.assert(false, "Invalid working time check"); 28395 return false; 28396 } 28397 28398 var tzOffset = result.getTimezoneOffset(); 28399 result = this.$gantt.date.add(result, increment, unit); 28400 28401 result = this.$gantt._correct_dst_change(result, tzOffset, increment, unit); 28402 if (this.$gantt.date[unit + '_start']) { 28403 result = this.$gantt.date[unit + '_start'](result); 28404 } 28405 } 28406 return result; 28407 } 28408}; 28409 28410module.exports = CalendarWorkTimeStrategy; 28411 28412/***/ }), 28413 28414/***/ "./sources/core/worktime/strategy/no_work_time.js": 28415/*!********************************************************!*\ 28416 !*** ./sources/core/worktime/strategy/no_work_time.js ***! 28417 \********************************************************/ 28418/*! no static exports found */ 28419/***/ (function(module, exports) { 28420 28421function CalendarDisabledTimeStrategy(gantt, argumentsHelper){ 28422 this.argumentsHelper = argumentsHelper; 28423 this.$gantt = gantt; 28424} 28425 28426CalendarDisabledTimeStrategy.prototype = { 28427 getWorkHours: function () { 28428 return [0, 24]; 28429 }, 28430 setWorkTime: function () { 28431 return true; 28432 }, 28433 unsetWorkTime: function () { 28434 return true; 28435 }, 28436 isWorkTime: function () { 28437 return true; 28438 }, 28439 getClosestWorkTime: function (config) { 28440 var config = this.argumentsHelper.getClosestWorkTimeArguments.apply(this.argumentsHelper, arguments); 28441 return config.date; 28442 }, 28443 28444 calculateDuration: function () { 28445 var config = this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper, arguments); 28446 var from = config.start_date, 28447 to = config.end_date, 28448 unit = config.unit, 28449 step = config.step; 28450 28451 return this._calculateDuration(from, to, unit, step); 28452 }, 28453 _calculateDuration: function (start, end, unit, step) { 28454 var dateHelper = this.$gantt.date; 28455 var fixedUnits = { 28456 "week": 1000 * 60 * 60 * 24 * 7, 28457 "day": 1000 * 60 * 60 * 24, 28458 "hour": 1000 * 60 * 60, 28459 "minute": 1000 * 60 28460 }; 28461 28462 var res = 0; 28463 if (fixedUnits[unit]) { 28464 res = Math.round((end - start) / (step * fixedUnits[unit])); 28465 } else { 28466 var from = new Date(start), 28467 to = new Date(end); 28468 while (from.valueOf() < to.valueOf()) { 28469 res += 1; 28470 from = dateHelper.add(from, step, unit); 28471 } 28472 28473 if (from.valueOf() != end.valueOf()) { 28474 res += (to - from) / (dateHelper.add(from, step, unit) - from); 28475 } 28476 } 28477 28478 return Math.round(res); 28479 }, 28480 28481 hasDuration: function () { 28482 var config = this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper, arguments); 28483 var from = config.start_date, 28484 to = config.end_date, 28485 unit = config.unit; 28486 28487 if (!unit) { 28488 return false; 28489 } 28490 from = new Date(from); 28491 to = new Date(to); 28492 28493 return (from.valueOf() < to.valueOf()); 28494 }, 28495 28496 calculateEndDate: function () { 28497 var config = this.argumentsHelper.calculateEndDateArguments.apply(this.argumentsHelper, arguments); 28498 28499 var start = config.start_date, 28500 duration = config.duration, 28501 unit = config.unit, 28502 step = config.step; 28503 28504 return this.$gantt.date.add(start, step * duration, unit); 28505 } 28506}; 28507 28508module.exports = CalendarDisabledTimeStrategy; 28509 28510/***/ }), 28511 28512/***/ "./sources/core/worktime/strategy/work_unit_cache/index.ts": 28513/*!*****************************************************************!*\ 28514 !*** ./sources/core/worktime/strategy/work_unit_cache/index.ts ***! 28515 \*****************************************************************/ 28516/*! no static exports found */ 28517/***/ (function(module, exports, __webpack_require__) { 28518 28519"use strict"; 28520 28521Object.defineProperty(exports, "__esModule", { value: true }); 28522var workunit_map_cache_1 = __webpack_require__(/*! ./workunit_map_cache */ "./sources/core/worktime/strategy/work_unit_cache/workunit_map_cache.ts"); 28523var workunit_object_cache_1 = __webpack_require__(/*! ./workunit_object_cache */ "./sources/core/worktime/strategy/work_unit_cache/workunit_object_cache.ts"); 28524function createCacheObject() { 28525 // worktime hash is on the hot path, 28526 // Map seems to work faster than plain array, use it whenever possible 28527 if (typeof Map !== "undefined") { 28528 return new workunit_map_cache_1.WorkUnitsMapCache(); 28529 } 28530 else { 28531 return new workunit_object_cache_1.WorkUnitsObjectCache(); 28532 } 28533} 28534exports.createCacheObject = createCacheObject; 28535 28536 28537/***/ }), 28538 28539/***/ "./sources/core/worktime/strategy/work_unit_cache/workunit_map_cache.ts": 28540/*!******************************************************************************!*\ 28541 !*** ./sources/core/worktime/strategy/work_unit_cache/workunit_map_cache.ts ***! 28542 \******************************************************************************/ 28543/*! no static exports found */ 28544/***/ (function(module, exports, __webpack_require__) { 28545 28546"use strict"; 28547 28548Object.defineProperty(exports, "__esModule", { value: true }); 28549var WorkUnitsMapCache = /** @class */ (function () { 28550 function WorkUnitsMapCache() { 28551 this.clear(); 28552 } 28553 WorkUnitsMapCache.prototype.getItem = function (unit, timestamp) { 28554 if (this._cache.has(unit)) { 28555 var unitCache = this._cache.get(unit); 28556 if (unitCache.has(timestamp)) { 28557 return unitCache.get(timestamp); 28558 } 28559 } 28560 return -1; 28561 }; 28562 WorkUnitsMapCache.prototype.setItem = function (unit, timestamp, value) { 28563 if (!unit || !timestamp) { 28564 return; 28565 } 28566 var cache = this._cache; 28567 var unitCache; 28568 if (!cache.has(unit)) { 28569 unitCache = new Map(); 28570 cache.set(unit, unitCache); 28571 } 28572 else { 28573 unitCache = cache.get(unit); 28574 } 28575 unitCache.set(timestamp, value); 28576 }; 28577 WorkUnitsMapCache.prototype.clear = function () { 28578 this._cache = new Map(); 28579 }; 28580 return WorkUnitsMapCache; 28581}()); 28582exports.WorkUnitsMapCache = WorkUnitsMapCache; 28583 28584 28585/***/ }), 28586 28587/***/ "./sources/core/worktime/strategy/work_unit_cache/workunit_object_cache.ts": 28588/*!*********************************************************************************!*\ 28589 !*** ./sources/core/worktime/strategy/work_unit_cache/workunit_object_cache.ts ***! 28590 \*********************************************************************************/ 28591/*! no static exports found */ 28592/***/ (function(module, exports, __webpack_require__) { 28593 28594"use strict"; 28595 28596Object.defineProperty(exports, "__esModule", { value: true }); 28597var WorkUnitsObjectCache = /** @class */ (function () { 28598 function WorkUnitsObjectCache() { 28599 this.clear(); 28600 } 28601 WorkUnitsObjectCache.prototype.getItem = function (unit, timestamp) { 28602 var cache = this._cache; 28603 if (cache && cache[unit]) { 28604 var units = cache[unit]; 28605 if (units[timestamp] !== undefined) { 28606 return units[timestamp]; 28607 } 28608 } 28609 return -1; 28610 }; 28611 WorkUnitsObjectCache.prototype.setItem = function (unit, timestamp, value) { 28612 if (!unit || !timestamp) { 28613 return; 28614 } 28615 var cache = this._cache; 28616 if (!cache) { 28617 return; 28618 } 28619 if (!cache[unit]) { 28620 cache[unit] = {}; 28621 } 28622 cache[unit][timestamp] = value; 28623 }; 28624 WorkUnitsObjectCache.prototype.clear = function () { 28625 this._cache = {}; 28626 }; 28627 return WorkUnitsObjectCache; 28628}()); 28629exports.WorkUnitsObjectCache = WorkUnitsObjectCache; 28630 28631 28632/***/ }), 28633 28634/***/ "./sources/core/worktime/time_calculator.js": 28635/*!**************************************************!*\ 28636 !*** ./sources/core/worktime/time_calculator.js ***! 28637 \**************************************************/ 28638/*! no static exports found */ 28639/***/ (function(module, exports, __webpack_require__) { 28640 28641var createArgumentsHelper = __webpack_require__(/*! ./calendar_arguments_helper */ "./sources/core/worktime/calendar_arguments_helper.js"), 28642 NoWorkTimeCalendar = __webpack_require__(/*! ./strategy/no_work_time */ "./sources/core/worktime/strategy/no_work_time.js"); 28643 28644function TimeCalculator(calendarManager){ 28645 28646 this.$gantt = calendarManager.$gantt; 28647 this.argumentsHelper = createArgumentsHelper(this.$gantt); 28648 this.calendarManager = calendarManager; 28649 this.$disabledCalendar = new NoWorkTimeCalendar(this.$gantt, this.argumentsHelper); 28650} 28651 28652TimeCalculator.prototype = { 28653 _getCalendar: function (config) { 28654 var calendar; 28655 if (!this.$gantt.$services.config().work_time) { 28656 calendar = this.$disabledCalendar; 28657 } else { 28658 var manager = this.calendarManager; 28659 if (config.task) { 28660 calendar = manager.getTaskCalendar(config.task); 28661 } else if (config.id) { 28662 calendar = manager.getTaskCalendar(config); 28663 } else if (config.calendar) { 28664 calendar = config.calendar; 28665 } 28666 if (!calendar) { 28667 calendar = manager.getTaskCalendar(); 28668 } 28669 } 28670 return calendar; 28671 }, 28672 28673 getWorkHours: function (config) { 28674 config = this.argumentsHelper.getWorkHoursArguments.apply(this.argumentsHelper, arguments); 28675 28676 var calendar = this._getCalendar(config); 28677 28678 return calendar.getWorkHours(config.date); 28679 }, 28680 28681 setWorkTime: function (config, calendar) { 28682 config = this.argumentsHelper.setWorkTimeArguments.apply(this.argumentsHelper, arguments); 28683 28684 if (!calendar) 28685 calendar = this.calendarManager.getCalendar(); // Global 28686 return calendar.setWorkTime(config); 28687 }, 28688 28689 unsetWorkTime: function (config, calendar) { 28690 config = this.argumentsHelper.unsetWorkTimeArguments.apply(this.argumentsHelper, arguments); 28691 28692 if (!calendar) 28693 calendar = this.calendarManager.getCalendar(); // Global 28694 return calendar.unsetWorkTime(config); 28695 }, 28696 isWorkTime: function (date, unit, task, calendar) { 28697 var config = this.argumentsHelper.isWorkTimeArguments.apply(this.argumentsHelper, arguments); 28698 28699 calendar = this._getCalendar(config); 28700 return calendar.isWorkTime(config); 28701 }, 28702 getClosestWorkTime: function (config) { 28703 config = this.argumentsHelper.getClosestWorkTimeArguments.apply(this.argumentsHelper, arguments); 28704 28705 var calendar = this._getCalendar(config); 28706 28707 return calendar.getClosestWorkTime(config); 28708 }, 28709 28710 calculateDuration: function () { // start_date_date, end_date, task 28711 var config = this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper, arguments); 28712 28713 28714 var calendar = this._getCalendar(config); 28715 return calendar.calculateDuration(config); 28716 }, 28717 hasDuration: function () { 28718 var config = this.argumentsHelper.hasDurationArguments.apply(this.argumentsHelper, arguments); 28719 28720 var calendar = this._getCalendar(config); 28721 28722 return calendar.hasDuration(config); 28723 }, 28724 calculateEndDate: function (config) { // start_date, duration, unit, task 28725 var config = this.argumentsHelper.calculateEndDateArguments.apply(this.argumentsHelper, arguments); 28726 28727 var calendar = this._getCalendar(config); 28728 return calendar.calculateEndDate(config); 28729 } 28730}; 28731 28732module.exports = TimeCalculator; 28733 28734 28735 28736/***/ }), 28737 28738/***/ "./sources/core/worktime/work_time.js": 28739/*!********************************************!*\ 28740 !*** ./sources/core/worktime/work_time.js ***! 28741 \********************************************/ 28742/*! no static exports found */ 28743/***/ (function(module, exports, __webpack_require__) { 28744 28745var CalendarManager = __webpack_require__(/*! ./calendar_manager */ "./sources/core/worktime/calendar_manager.js"), 28746 TimeCalculator = __webpack_require__(/*! ./time_calculator */ "./sources/core/worktime/time_calculator.js"), 28747 worktimeFacadeFactory = __webpack_require__(/*! ../facades/worktime_calendars */ "./sources/core/facades/worktime_calendars.js"), 28748 utils = __webpack_require__(/*! ../../utils/utils */ "./sources/utils/utils.js"); 28749 28750module.exports = function (gantt) { 28751 var manager = new CalendarManager(gantt), 28752 timeCalculator = new TimeCalculator(manager); 28753 var facade = worktimeFacadeFactory.create(manager, timeCalculator); 28754 utils.mixin(gantt, facade); 28755}; 28756 28757 28758/***/ }), 28759 28760/***/ "./sources/css/skins/broadway.js": 28761/*!***************************************!*\ 28762 !*** ./sources/css/skins/broadway.js ***! 28763 \***************************************/ 28764/*! no static exports found */ 28765/***/ (function(module, exports) { 28766 28767module.exports = function(gantt) { 28768 gantt.skins.broadway = { 28769 config: { 28770 grid_width: 360, 28771 row_height: 35, 28772 scale_height: 35, 28773 link_line_width: 1, 28774 link_arrow_size: 7, 28775 lightbox_additional_height: 86 28776 }, 28777 _second_column_width: 90, 28778 _third_column_width: 80, 28779 28780 _lightbox_template: "<div class='gantt_cal_ltitle'><span class='gantt_mark'> </span><span class='gantt_time'></span><span class='gantt_title'></span><div class='gantt_cancel_btn'></div></div><div class='gantt_cal_larea'></div>", 28781 _config_buttons_left: {}, 28782 _config_buttons_right: { 28783 "gantt_delete_btn": "icon_delete", 28784 "gantt_save_btn": "icon_save" 28785 } 28786 }; 28787}; 28788 28789/***/ }), 28790 28791/***/ "./sources/css/skins/contrast_black.js": 28792/*!*********************************************!*\ 28793 !*** ./sources/css/skins/contrast_black.js ***! 28794 \*********************************************/ 28795/*! no static exports found */ 28796/***/ (function(module, exports) { 28797 28798module.exports = function(gantt) { 28799gantt.skins["contrast_black"] = { 28800 config:{ 28801 grid_width:360, 28802 row_height: 35, 28803 scale_height: 35, 28804 link_line_width:2, 28805 link_arrow_size:6, 28806 lightbox_additional_height:75 28807 }, 28808 _second_column_width:100, 28809 _third_column_width:80 28810}; 28811 28812}; 28813 28814/***/ }), 28815 28816/***/ "./sources/css/skins/contrast_white.js": 28817/*!*********************************************!*\ 28818 !*** ./sources/css/skins/contrast_white.js ***! 28819 \*********************************************/ 28820/*! no static exports found */ 28821/***/ (function(module, exports) { 28822 28823module.exports = function(gantt) { 28824gantt.skins["contrast_white"] = { 28825 config:{ 28826 grid_width:360, 28827 row_height: 35, 28828 scale_height: 35, 28829 link_line_width:2, 28830 link_arrow_size:6, 28831 lightbox_additional_height:75 28832 }, 28833 _second_column_width:100, 28834 _third_column_width:80 28835}; 28836 28837}; 28838 28839/***/ }), 28840 28841/***/ "./sources/css/skins/material.js": 28842/*!***************************************!*\ 28843 !*** ./sources/css/skins/material.js ***! 28844 \***************************************/ 28845/*! no static exports found */ 28846/***/ (function(module, exports) { 28847 28848module.exports = function(gantt) { 28849 gantt.skins.material = { 28850 config: { 28851 grid_width: 411, 28852 row_height: 34, 28853 task_height_offset: 6, 28854 scale_height: 36, 28855 link_line_width: 2, 28856 link_arrow_size: 6, 28857 lightbox_additional_height: 80 28858 }, 28859 _second_column_width: 110, 28860 _third_column_width: 75, 28861 _redefine_lightbox_buttons: { 28862 "buttons_left": ["dhx_delete_btn"], 28863 "buttons_right": ["dhx_save_btn", "dhx_cancel_btn"] 28864 } 28865 }; 28866 28867 gantt.attachEvent("onAfterTaskDrag", function (id) { 28868 var t = gantt.getTaskNode(id); 28869 if (t) { 28870 t.className += " gantt_drag_animation"; 28871 setTimeout(function () { 28872 var indx = t.className.indexOf(" gantt_drag_animation"); 28873 if (indx > -1) { 28874 t.className = t.className.slice(0, indx); 28875 } 28876 }, 200); 28877 } 28878 }); 28879 28880}; 28881 28882/***/ }), 28883 28884/***/ "./sources/css/skins/meadow.js": 28885/*!*************************************!*\ 28886 !*** ./sources/css/skins/meadow.js ***! 28887 \*************************************/ 28888/*! no static exports found */ 28889/***/ (function(module, exports) { 28890 28891module.exports = function(gantt) { 28892gantt.skins.meadow = { 28893 config:{ 28894 grid_width:350, 28895 row_height: 27, 28896 scale_height: 30, 28897 link_line_width:2, 28898 link_arrow_size:6, 28899 lightbox_additional_height:72 28900 }, 28901 _second_column_width:95, 28902 _third_column_width:80 28903}; 28904 28905}; 28906 28907/***/ }), 28908 28909/***/ "./sources/css/skins/skyblue.js": 28910/*!**************************************!*\ 28911 !*** ./sources/css/skins/skyblue.js ***! 28912 \**************************************/ 28913/*! no static exports found */ 28914/***/ (function(module, exports) { 28915 28916module.exports = function(gantt) { 28917gantt.skins.skyblue = { 28918 config:{ 28919 grid_width:350, 28920 row_height: 27, 28921 scale_height: 27, 28922 link_line_width:1, 28923 link_arrow_size:8, 28924 lightbox_additional_height:75 28925 }, 28926 _second_column_width:95, 28927 _third_column_width:80 28928}; 28929 28930}; 28931 28932/***/ }), 28933 28934/***/ "./sources/css/skins/terrace.js": 28935/*!**************************************!*\ 28936 !*** ./sources/css/skins/terrace.js ***! 28937 \**************************************/ 28938/*! no static exports found */ 28939/***/ (function(module, exports) { 28940 28941module.exports = function(gantt) { 28942gantt.skins.terrace = { 28943 config:{ 28944 grid_width:360, 28945 row_height: 35, 28946 scale_height: 35, 28947 link_line_width:2, 28948 link_arrow_size:6, 28949 lightbox_additional_height:75 28950 }, 28951 _second_column_width:90, 28952 _third_column_width:70 28953}; 28954 28955}; 28956 28957/***/ }), 28958 28959/***/ "./sources/css/skins/terrace.less": 28960/*!****************************************!*\ 28961 !*** ./sources/css/skins/terrace.less ***! 28962 \****************************************/ 28963/*! no static exports found */ 28964/***/ (function(module, exports, __webpack_require__) { 28965 28966// extracted by mini-css-extract-plugin 28967 28968/***/ }), 28969 28970/***/ "./sources/dhtmlxgantt.gpl.ts": 28971/*!************************************!*\ 28972 !*** ./sources/dhtmlxgantt.gpl.ts ***! 28973 \************************************/ 28974/*! no static exports found */ 28975/***/ (function(module, exports, __webpack_require__) { 28976 28977"use strict"; 28978 28979Object.defineProperty(exports, "__esModule", { value: true }); 28980var warnings = __webpack_require__(/*! ./core/deprecated_warnings */ "./sources/core/deprecated_warnings.js"); 28981var base = __webpack_require__(/*! ./core/gantt */ "./sources/core/gantt.js"); 28982var gantt = window.gantt = base(); 28983exports.gantt = gantt; 28984warnings(gantt); 28985exports.default = gantt; 28986 28987 28988/***/ }), 28989 28990/***/ "./sources/locale/index.js": 28991/*!*********************************!*\ 28992 !*** ./sources/locale/index.js ***! 28993 \*********************************/ 28994/*! no static exports found */ 28995/***/ (function(module, exports) { 28996 28997// default locale 28998// load locale definition and wrap it into module build-time 28999module.exports = function (gantt) { 29000 gantt.locale = { 29001 date: { 29002 month_full: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], 29003 month_short: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], 29004 day_full: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], 29005 day_short: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] 29006 }, 29007 labels: { 29008 new_task: "New task", 29009 icon_save: "Save", 29010 icon_cancel: "Cancel", 29011 icon_details: "Details", 29012 icon_edit: "Edit", 29013 icon_delete: "Delete", 29014 confirm_closing: "",//Your changes will be lost, are you sure? 29015 confirm_deleting: "Task will be deleted permanently, are you sure?", 29016 section_description: "Description", 29017 section_time: "Time period", 29018 section_type: "Type", 29019 29020 /* grid columns */ 29021 column_wbs: "WBS", 29022 column_text: "Task name", 29023 column_start_date: "Start time", 29024 column_duration: "Duration", 29025 column_add: "", 29026 29027 /* link confirmation */ 29028 link: "Link", 29029 confirm_link_deleting: "will be deleted", 29030 link_start: " (start)", 29031 link_end: " (end)", 29032 29033 type_task: "Task", 29034 type_project: "Project", 29035 type_milestone: "Milestone", 29036 29037 minutes: "Minutes", 29038 hours: "Hours", 29039 days: "Days", 29040 weeks: "Week", 29041 months: "Months", 29042 years: "Years", 29043 29044 /* message popup */ 29045 message_ok: "OK", 29046 message_cancel: "Cancel", 29047 29048 /* constraints */ 29049 section_constraint: "Constraint", 29050 constraint_type: "Constraint type", 29051 constraint_date: "Constraint date", 29052 asap: "As Soon As Possible", 29053 alap: "As Late As Possible", 29054 snet: "Start No Earlier Than", 29055 snlt: "Start No Later Than", 29056 fnet: "Finish No Earlier Than", 29057 fnlt: "Finish No Later Than", 29058 mso: "Must Start On", 29059 mfo: "Must Finish On", 29060 29061 /* resource control */ 29062 resources_filter_placeholder: "type to filter", 29063 resources_filter_label: "hide empty" 29064 } 29065}; 29066}; 29067 29068/***/ }), 29069 29070/***/ "./sources/publish_helpers/void_script_second.ts": 29071/*!*******************************************************!*\ 29072 !*** ./sources/publish_helpers/void_script_second.ts ***! 29073 \*******************************************************/ 29074/*! no static exports found */ 29075/***/ (function(module, exports, __webpack_require__) { 29076 29077"use strict"; 29078 29079Object.defineProperty(exports, "__esModule", { value: true }); 29080// all builds except for evaluation version get this mockup 29081// the evaluation build gets actual codes 29082exports.default = (function () { }); 29083 29084 29085/***/ }), 29086 29087/***/ "./sources/publish_helpers/void_script_third.ts": 29088/*!******************************************************!*\ 29089 !*** ./sources/publish_helpers/void_script_third.ts ***! 29090 \******************************************************/ 29091/*! no static exports found */ 29092/***/ (function(module, exports, __webpack_require__) { 29093 29094"use strict"; 29095 29096Object.defineProperty(exports, "__esModule", { value: true }); 29097// all builds except for evaluation version get this mockup 29098// the evaluation build gets actual codes 29099exports.default = (function () { }); 29100 29101 29102/***/ }), 29103 29104/***/ "./sources/utils/dom_event_scope.js": 29105/*!******************************************!*\ 29106 !*** ./sources/utils/dom_event_scope.js ***! 29107 \******************************************/ 29108/*! no static exports found */ 29109/***/ (function(module, exports, __webpack_require__) { 29110 29111var utils = __webpack_require__(/*! ./utils */ "./sources/utils/utils.js"); 29112 29113function createScope(addEvent, removeEvent) { 29114 addEvent = addEvent || utils.event; 29115 removeEvent = removeEvent || utils.eventRemove; 29116 29117 var handlers = []; 29118 29119 var eventScope = { 29120 attach: function(el, event, callback, capture){ 29121 handlers.push({element: el, event:event, callback: callback, capture: capture}); 29122 addEvent(el, event, callback, capture); 29123 }, 29124 detach: function(el, event, callback, capture){ 29125 removeEvent(el, event, callback, capture); 29126 for(var i = 0; i < handlers.length; i++){ 29127 var handler = handlers[i]; 29128 if (handler.element === el && handler.event === event && handler.callback === callback && handler.capture === capture) { 29129 handlers.splice(i, 1); 29130 i--; 29131 } 29132 } 29133 }, 29134 detachAll: function () { 29135 var staticArray = handlers.slice(); 29136 // original handlers array can be spliced on every iteration 29137 for (var i = 0; i < staticArray.length; i++){ 29138 var handler = staticArray[i]; 29139 eventScope.detach(handler.element, handler.event, handler.callback, handler.capture); 29140 eventScope.detach(handler.element, handler.event, handler.callback, undefined); 29141 eventScope.detach(handler.element, handler.event, handler.callback, false); 29142 eventScope.detach(handler.element, handler.event, handler.callback, true); 29143 } 29144 handlers.splice(0, handlers.length); 29145 }, 29146 extend: function(){ 29147 return createScope(this.event, this.eventRemove); 29148 } 29149 }; 29150 29151 if (!window.scopes) { 29152 window.scopes = []; 29153 } 29154 window.scopes.push(handlers); 29155 return eventScope; 29156} 29157 29158module.exports = createScope; 29159 29160/***/ }), 29161 29162/***/ "./sources/utils/dom_helpers.js": 29163/*!**************************************!*\ 29164 !*** ./sources/utils/dom_helpers.js ***! 29165 \**************************************/ 29166/*! no static exports found */ 29167/***/ (function(module, exports) { 29168 29169//returns position of html element on the page 29170function elementPosition(elem) { 29171 var top=0, left=0, right=0, bottom=0; 29172 if (elem.getBoundingClientRect) { //HTML5 method 29173 var box = elem.getBoundingClientRect(); 29174 var body = document.body; 29175 var docElem = (document.documentElement || 29176 document.body.parentNode || 29177 document.body); 29178 29179 var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop; 29180 var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft; 29181 var clientTop = docElem.clientTop || body.clientTop || 0; 29182 var clientLeft = docElem.clientLeft || body.clientLeft || 0; 29183 top = box.top + scrollTop - clientTop; 29184 left = box.left + scrollLeft - clientLeft; 29185 29186 right = document.body.offsetWidth - box.right; 29187 bottom = document.body.offsetHeight - box.bottom; 29188 } else { //fallback to naive approach 29189 while(elem) { 29190 top = top + parseInt(elem.offsetTop,10); 29191 left = left + parseInt(elem.offsetLeft,10); 29192 elem = elem.offsetParent; 29193 } 29194 29195 right = document.body.offsetWidth - elem.offsetWidth - left; 29196 bottom = document.body.offsetHeight - elem.offsetHeight - top; 29197 } 29198 return { y: Math.round(top), x: Math.round(left), width:elem.offsetWidth, height:elem.offsetHeight, right: Math.round(right), bottom: Math.round(bottom) }; 29199} 29200 29201function isVisible(node){ 29202 var display = false, 29203 visibility = false; 29204 if(window.getComputedStyle){ 29205 var style = window.getComputedStyle(node, null); 29206 display = style["display"]; 29207 visibility = style["visibility"]; 29208 }else if(node.currentStyle){ 29209 display = node.currentStyle["display"]; 29210 visibility = node.currentStyle["visibility"]; 29211 } 29212 return (display != "none" && visibility != "hidden"); 29213} 29214 29215function hasNonNegativeTabIndex(node){ 29216 return !isNaN(node.getAttribute("tabindex")) && (node.getAttribute("tabindex")*1 >= 0); 29217} 29218 29219function hasHref(node){ 29220 var canHaveHref = {"a": true, "area": true}; 29221 if(canHaveHref[node.nodeName.loLowerCase()]){ 29222 return !!node.getAttribute("href"); 29223 } 29224 return true; 29225} 29226 29227function isEnabled(node){ 29228 var canDisable = {"input":true, "select":true, "textarea":true, "button":true, "object":true}; 29229 if(canDisable[node.nodeName.toLowerCase()]){ 29230 return !node.hasAttribute("disabled"); 29231 } 29232 29233 return true; 29234} 29235 29236function getFocusableNodes(root){ 29237 var nodes = root.querySelectorAll([ 29238 "a[href]", 29239 "area[href]", 29240 "input", 29241 "select", 29242 "textarea", 29243 "button", 29244 "iframe", 29245 "object", 29246 "embed", 29247 "[tabindex]", 29248 "[contenteditable]" 29249 ].join(", ")); 29250 29251 var nodesArray = Array.prototype.slice.call(nodes, 0); 29252 for(var i = 0; i < nodesArray.length; i++){ 29253 var node = nodesArray[i]; 29254 var isValid = (hasNonNegativeTabIndex(node) || isEnabled(node) || hasHref(node)) && isVisible(node); 29255 if(!isValid){ 29256 nodesArray.splice(i, 1); 29257 i--; 29258 } 29259 } 29260 return nodesArray; 29261} 29262 29263function getScrollSize(){ 29264 var div = document.createElement("div"); 29265 div.style.cssText="visibility:hidden;position:absolute;left:-1000px;width:100px;padding:0px;margin:0px;height:110px;min-height:100px;overflow-y:scroll;"; 29266 29267 document.body.appendChild(div); 29268 var width = div.offsetWidth-div.clientWidth; 29269 document.body.removeChild(div); 29270 29271 return width; 29272} 29273 29274function getClassName(node){ 29275 if(!node) return ""; 29276 29277 var className = node.className || ""; 29278 if(className.baseVal)//'className' exist but not a string - IE svg element in DOM 29279 className = className.baseVal; 29280 29281 if(!className.indexOf) 29282 className = ""; 29283 29284 return _trimString(className); 29285} 29286 29287function addClassName(node, className){ 29288 if (className && node.className.indexOf(className) === -1) { 29289 node.className += " " + className; 29290 } 29291} 29292 29293function removeClassName(node, name) { 29294 name = name.split(" "); 29295 for (var i = 0; i < name.length; i++) { 29296 var regEx = new RegExp("\\s?\\b" + name[i] + "\\b(?![-_.])", ""); 29297 node.className = node.className.replace(regEx, ""); 29298 } 29299} 29300 29301function hasClass(element, className){ 29302 if ('classList' in element) { 29303 return element.classList.contains(className); 29304 } else { 29305 return new RegExp("\\b" + className + "\\b").test(element.className); 29306 } 29307} 29308 29309function toNode(node) { 29310 if (typeof node === "string") { 29311 return (document.getElementById(node) || document.querySelector(node) || document.body); 29312 } 29313 return node || document.body; 29314} 29315 29316var _slave = document.createElement("div"); 29317function insert(node, newone) { 29318 _slave.innerHTML = newone; 29319 var child = _slave.firstChild; 29320 node.appendChild(child); 29321 return child; 29322} 29323 29324function remove(node) { 29325 if (node && node.parentNode) { 29326 node.parentNode.removeChild(node); 29327 } 29328} 29329 29330function getChildren(node, css) { 29331 var ch = node.childNodes; 29332 var len = ch.length; 29333 var out = []; 29334 for (var i = 0; i < len; i++) { 29335 var obj = ch[i]; 29336 if (obj.className && obj.className.indexOf(css) !== -1) { 29337 out.push(obj); 29338 } 29339 } 29340 return out; 29341} 29342 29343function getTargetNode(e){ 29344 var trg; 29345 if (e.tagName) 29346 trg = e; 29347 else { 29348 e=e||window.event; 29349 trg=e.target||e.srcElement; 29350 } 29351 return trg; 29352} 29353 29354function locateAttribute(e, attribute) { 29355 if(!attribute) return; 29356 29357 var trg = getTargetNode(e); 29358 29359 while (trg){ 29360 if (trg.getAttribute){ //text nodes has not getAttribute 29361 var test = trg.getAttribute(attribute); 29362 if (test) return trg; 29363 } 29364 trg=trg.parentNode; 29365 } 29366 return null; 29367} 29368 29369function _trimString(str){ 29370 var func = String.prototype.trim || function(){ return this.replace(/^\s+|\s+$/g, ""); }; 29371 return func.apply(str); 29372} 29373 29374function locateClassName(e, classname, strict){ 29375 var trg = getTargetNode(e); 29376 var css = ""; 29377 29378 if(strict === undefined) 29379 strict = true; 29380 29381 while (trg){ 29382 css = getClassName(trg); 29383 if(css){ 29384 var ind = css.indexOf(classname); 29385 if (ind >= 0){ 29386 if (!strict) 29387 return trg; 29388 29389 //check that we have exact match 29390 var left = (ind === 0) || (!_trimString(css.charAt(ind - 1))); 29391 var right = ((ind + classname.length >= css.length)) || (!_trimString(css.charAt(ind + classname.length))); 29392 29393 if (left && right) 29394 return trg; 29395 } 29396 } 29397 trg=trg.parentNode; 29398 } 29399 return null; 29400} 29401 29402/* 29403event position relatively to DOM element 29404 */ 29405function getRelativeEventPosition(ev, node){ 29406 var d = document.documentElement; 29407 var box = elementPosition(node); 29408 29409 return { 29410 x: ev.clientX + d.scrollLeft - d.clientLeft - box.x + node.scrollLeft, 29411 y: ev.clientY + d.scrollTop - d.clientTop - box.y + node.scrollTop 29412 }; 29413} 29414 29415function isChildOf(child, parent){ 29416 if(!child || !parent){ 29417 return false; 29418 } 29419 29420 while(child && child != parent) { 29421 child = child.parentNode; 29422 } 29423 29424 return child === parent; 29425} 29426 29427function closest(element, selector){ 29428 if(element.closest){ 29429 return element.closest(selector); 29430 }else if(element.matches || element.msMatchesSelector || element.webkitMatchesSelector){ 29431 var el = element; 29432 if (!document.documentElement.contains(el)) return null; 29433 do { 29434 var method = el.matches || el.msMatchesSelector || el.webkitMatchesSelector; 29435 29436 if (method.call(el, selector)) return el; 29437 el = el.parentElement || el.parentNode; 29438 } while (el !== null && el.nodeType === 1); 29439 return null; 29440 }else{ 29441 // eslint-disable-next-line no-console 29442 console.error("Your browser is not supported"); 29443 return null; 29444 } 29445} 29446 29447module.exports = { 29448 getNodePosition: elementPosition, 29449 getFocusableNodes: getFocusableNodes, 29450 getScrollSize: getScrollSize, 29451 getClassName: getClassName, 29452 addClassName: addClassName, 29453 removeClassName: removeClassName, 29454 insertNode: insert, 29455 removeNode: remove, 29456 getChildNodes: getChildren, 29457 toNode: toNode, 29458 locateClassName:locateClassName, 29459 locateAttribute: locateAttribute, 29460 getTargetNode: getTargetNode, 29461 getRelativeEventPosition: getRelativeEventPosition, 29462 isChildOf: isChildOf, 29463 hasClass: hasClass, 29464 closest: closest 29465}; 29466 29467/***/ }), 29468 29469/***/ "./sources/utils/env.js": 29470/*!******************************!*\ 29471 !*** ./sources/utils/env.js ***! 29472 \******************************/ 29473/*! no static exports found */ 29474/***/ (function(module, exports) { 29475 29476var env = { 29477 isIE: (navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("Trident") >= 0), 29478 isIE6: (!window.XMLHttpRequest && navigator.userAgent.indexOf("MSIE") >= 0), 29479 isIE7: (navigator.userAgent.indexOf("MSIE 7.0") >= 0 && navigator.userAgent.indexOf("Trident") < 0), 29480 isIE8: (navigator.userAgent.indexOf("MSIE 8.0") >= 0 && navigator.userAgent.indexOf("Trident") >= 0), 29481 isOpera: (navigator.userAgent.indexOf("Opera") >= 0), 29482 isChrome: (navigator.userAgent.indexOf("Chrome") >= 0), 29483 isKHTML: (navigator.userAgent.indexOf("Safari") >= 0 || navigator.userAgent.indexOf("Konqueror") >= 0), 29484 isFF: (navigator.userAgent.indexOf("Firefox") >= 0), 29485 isIPad: (navigator.userAgent.search(/iPad/gi) >= 0), 29486 isEdge: (navigator.userAgent.indexOf("Edge")!=-1) 29487}; 29488 29489module.exports = env; 29490 29491/***/ }), 29492 29493/***/ "./sources/utils/eventable.js": 29494/*!************************************!*\ 29495 !*** ./sources/utils/eventable.js ***! 29496 \************************************/ 29497/*! no static exports found */ 29498/***/ (function(module, exports) { 29499 29500var EventHost = function(){ 29501 this._connected = []; 29502 this._silent_mode = false; 29503}; 29504 29505EventHost.prototype = { 29506 _silentStart: function() { 29507 this._silent_mode = true; 29508 }, 29509 _silentEnd: function() { 29510 this._silent_mode = false; 29511 } 29512}; 29513 29514var createEventStorage = function(obj) { 29515 var dhx_catch = []; 29516 var z = function(){ 29517 var res = true; 29518 for (var i = 0; i < dhx_catch.length; i++){ 29519 if (dhx_catch[i]){ 29520 var zr = dhx_catch[i].apply(obj, arguments); 29521 res=res&&zr; 29522 } 29523 } 29524 return res; 29525 }; 29526 z.addEvent=function(ev){ 29527 if (typeof (ev) == "function") 29528 return dhx_catch.push(ev)-1; 29529 return false; 29530 }; 29531 z.removeEvent=function(id){ 29532 dhx_catch[id]=null; 29533 }; 29534 return z; 29535}; 29536 29537function makeEventable(obj){ 29538 29539 var eventHost = new EventHost(); 29540 obj.attachEvent=function(name, catcher, callObj){ 29541 name='ev_'+name.toLowerCase(); 29542 if (!eventHost[name]) 29543 eventHost[name] = createEventStorage(callObj||this); 29544 29545 return(name+':'+eventHost[name].addEvent(catcher)); //return ID (event name & event ID) 29546 }; 29547 obj.attachAll = function(callback, callObj){ 29548 this.attachEvent('listen_all', callback, callObj); 29549 }; 29550 29551 obj.callEvent=function(name, arg0, callObj){ 29552 if (eventHost._silent_mode) return true; 29553 29554 var handlerName = 'ev_'+name.toLowerCase(); 29555 29556 if (eventHost['ev_listen_all']){ 29557 eventHost['ev_listen_all'].apply(callObj || this, [name].concat(arg0)); 29558 } 29559 29560 if (eventHost[handlerName]) 29561 return eventHost[handlerName].apply(callObj || this, arg0); 29562 return true; 29563 }; 29564 obj.checkEvent=function(name){ 29565 return (!!eventHost['ev_'+name.toLowerCase()]); 29566 }; 29567 obj.detachEvent=function(id){ 29568 if (id){ 29569 var list = id.split(':');//get EventName and ID 29570 var eventName = list[0]; 29571 var eventId = list[1]; 29572 29573 if(eventHost[eventName]){ 29574 eventHost[eventName].removeEvent(eventId); //remove event 29575 } 29576 } 29577 }; 29578 obj.detachAllEvents = function(){ 29579 for (var name in eventHost){ 29580 if (name.indexOf("ev_") === 0) 29581 delete eventHost[name]; 29582 } 29583 }; 29584 29585} 29586 29587module.exports = makeEventable; 29588 29589/***/ }), 29590 29591/***/ "./sources/utils/extends.js": 29592/*!**********************************!*\ 29593 !*** ./sources/utils/extends.js ***! 29594 \**********************************/ 29595/*! no static exports found */ 29596/***/ (function(module, exports) { 29597 29598module.exports = function (d, b) { 29599 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; 29600 function __() { this.constructor = d; } 29601 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 29602}; 29603 29604/***/ }), 29605 29606/***/ "./sources/utils/helpers.js": 29607/*!**********************************!*\ 29608 !*** ./sources/utils/helpers.js ***! 29609 \**********************************/ 29610/*! no static exports found */ 29611/***/ (function(module, exports) { 29612 29613var units = { 29614 "second": 1, 29615 "minute": 60, 29616 "hour": 60 * 60, 29617 "day": 60 * 60 * 24, 29618 "week": 60 * 60 * 24 * 7, 29619 "month": 60 * 60 * 24 * 30, 29620 "quarter": 60 * 60 * 24 * 30 * 3, 29621 "year": 60 * 60 * 24 * 365 29622}; 29623function getSecondsInUnit(unit){ 29624 return units[unit] || units.hour; 29625} 29626 29627function forEach(arr, callback) { 29628 if (arr.forEach) { 29629 arr.forEach(callback); 29630 } else { 29631 var workArray = arr.slice(); 29632 for (var i = 0; i < workArray.length; i++) { 29633 callback(workArray[i], i); 29634 } 29635 } 29636} 29637 29638function arrayMap(arr, callback) { 29639 if (arr.map) { 29640 return arr.map(callback); 29641 } else { 29642 var workArray = arr.slice(); 29643 var resArray = []; 29644 29645 for (var i = 0; i < workArray.length; i++) { 29646 resArray.push(callback(workArray[i], i)); 29647 } 29648 return resArray; 29649 } 29650} 29651 29652 29653function arrayFind(arr, callback) { 29654 if (arr.find) { 29655 return arr.find(callback); 29656 } else { 29657 for (var i = 0; i < arr.length; i++) { 29658 if (callback(arr[i], i)) { 29659 return arr[i]; 29660 } 29661 } 29662 } 29663} 29664 29665// iframe-safe array type check instead of using instanceof 29666function isArray(obj){ 29667 if(Array.isArray){ 29668 return Array.isArray(obj); 29669 }else{ 29670 // close enough 29671 return (obj && obj.length !== undefined && obj.pop && obj.push); 29672 } 29673} 29674 29675// non-primitive string object, e.g. new String("abc") 29676function isStringObject(obj){ 29677 return obj && typeof obj === "object" 29678 && Function.prototype.toString.call(obj.constructor) === "function String() { [native code] }"; 29679} 29680 29681// non-primitive number object, e.g. new Number(5) 29682function isNumberObject(obj){ 29683 return obj && typeof obj === "object" 29684 && Function.prototype.toString.call(obj.constructor) === "function Number() { [native code] }"; 29685} 29686 29687// non-primitive number object, e.g. new Boolean(true) 29688function isBooleanObject(obj){ 29689 return obj && typeof obj === "object" 29690 && Function.prototype.toString.call(obj.constructor) === "function Boolean() { [native code] }"; 29691} 29692 29693function isDate(obj) { 29694 if (obj && typeof obj === "object") { 29695 return !!(obj.getFullYear && obj.getMonth && obj.getDate); 29696 } else { 29697 return false; 29698 } 29699} 29700 29701function isValidDate(obj){ 29702 return isDate(obj) && !isNaN(obj.getTime()); 29703} 29704 29705function arrayFilter(arr, callback) { 29706 var result = []; 29707 29708 if (arr.filter) { 29709 return arr.filter(callback); 29710 } else { 29711 for (var i = 0; i < arr.length; i++) { 29712 if (callback(arr[i], i)) { 29713 result[result.length] = arr[i]; 29714 } 29715 } 29716 return result; 29717 } 29718} 29719 29720function hashToArray(hash) { 29721 var result = []; 29722 29723 for (var key in hash) { 29724 if (hash.hasOwnProperty(key)) { 29725 result.push(hash[key]); 29726 } 29727 } 29728 29729 return result; 29730} 29731 29732function arraySome(arr, callback) { 29733 if (arr.length === 0) return false; 29734 29735 for (var i = 0; i < arr.length; i++) { 29736 if (callback(arr[i], i, arr)) { 29737 return true; 29738 } 29739 } 29740 return false; 29741} 29742 29743function arrayDifference(arr, callback) { 29744 return arrayFilter(arr, function(item, i) { 29745 return !callback(item, i); 29746 }); 29747} 29748 29749function throttle (callback, timeout) { 29750 var wait = false; 29751 29752 return function () { 29753 if (!wait) { 29754 callback.apply(null, arguments); 29755 wait = true; 29756 setTimeout(function () { 29757 wait = false; 29758 }, timeout); 29759 } 29760 }; 29761} 29762 29763function delay (callback, timeout){ 29764 var timer; 29765 29766 var result = function() { 29767 result.$cancelTimeout(); 29768 callback.$pending = true; 29769 var args = Array.prototype.slice.call(arguments); 29770 timer = setTimeout(function(){ 29771 callback.apply(this, args); 29772 result.$pending = false; 29773 }, timeout); 29774 }; 29775 29776 result.$pending = false; 29777 result.$cancelTimeout = function(){ 29778 clearTimeout(timer); 29779 callback.$pending = false; 29780 }; 29781 result.$execute = function(){ 29782 callback(); 29783 callback.$cancelTimeout(); 29784 }; 29785 29786 return result; 29787} 29788 29789function sortArrayOfHash(arr, field, desc) { 29790 var compare = function(a, b) { 29791 return a < b; 29792 }; 29793 29794 arr.sort(function(a, b) { 29795 if (a[field] === b[field]) return 0; 29796 29797 return desc ? compare(a[field], b[field]) : compare(b[field], a[field]); 29798 }); 29799} 29800 29801function objectKeys(obj) { 29802 if (Object.keys) { 29803 return Object.keys(obj); 29804 } 29805 var result = []; 29806 var key; 29807 for (key in obj) { 29808 if (Object.prototype.hasOwnProperty.call(obj, key)) { 29809 result.push(key); 29810 } 29811 } 29812 return result; 29813} 29814 29815function requestAnimationFrame(callback) { 29816 var w = window; 29817 var foundRequestAnimationFrame = w.requestAnimationFrame 29818 || w.webkitRequestAnimationFrame 29819 || w.msRequestAnimationFrame 29820 || w.mozRequestAnimationFrame 29821 || w.oRequestAnimationFrame 29822 || function(cb) { setTimeout(cb, 1000/60); }; 29823 return foundRequestAnimationFrame(callback); 29824} 29825 29826function isEventable(obj) { 29827 return obj.attachEvent && obj.detachEvent; 29828} 29829 29830module.exports = { 29831 getSecondsInUnit: getSecondsInUnit, 29832 forEach: forEach, 29833 arrayMap: arrayMap, 29834 arrayFind: arrayFind, 29835 arrayFilter: arrayFilter, 29836 arrayDifference: arrayDifference, 29837 arraySome: arraySome, 29838 hashToArray: hashToArray, 29839 sortArrayOfHash: sortArrayOfHash, 29840 throttle: throttle, 29841 isArray: isArray, 29842 isDate: isDate, 29843 isValidDate: isValidDate, 29844 isStringObject: isStringObject, 29845 isNumberObject: isNumberObject, 29846 isBooleanObject: isBooleanObject, 29847 delay: delay, 29848 objectKeys: objectKeys, 29849 requestAnimationFrame: requestAnimationFrame, 29850 isEventable: isEventable 29851}; 29852 29853/***/ }), 29854 29855/***/ "./sources/utils/html_helpers.js": 29856/*!***************************************!*\ 29857 !*** ./sources/utils/html_helpers.js ***! 29858 \***************************************/ 29859/*! no static exports found */ 29860/***/ (function(module, exports, __webpack_require__) { 29861 29862var helpers = __webpack_require__(/*! ./helpers */ "./sources/utils/helpers.js"); 29863 29864var htmlHelpers = { 29865 getHtmlSelect: function(options, attributes, value) { 29866 var innerHTML = ""; 29867 var _this = this; 29868 29869 options = options || []; 29870 29871 helpers.forEach(options, function(entry) { 29872 var _attributes = [{ key: "value", value: entry.key }]; 29873 29874 if (value == entry.key) { 29875 _attributes[_attributes.length] = { key: "selected", value: "selected" }; 29876 } 29877 if (entry.attributes) { 29878 _attributes = _attributes.concat(entry.attributes); 29879 } 29880 innerHTML += _this.getHtmlOption({ innerHTML: entry.label }, _attributes); 29881 }); 29882 29883 return _getHtmlContainer("select", { innerHTML: innerHTML }, attributes); 29884 }, 29885 getHtmlOption: function(options, attributes) { return _getHtmlContainer("option", options, attributes); }, 29886 getHtmlButton: function(options, attributes) { return _getHtmlContainer("button", options, attributes); }, 29887 getHtmlDiv: function(options, attributes) { return _getHtmlContainer("div", options, attributes); }, 29888 getHtmlLabel: function(options, attributes) { return _getHtmlContainer("label", options, attributes); }, 29889 getHtmlInput: function(attributes) { 29890 return "<input" + _getHtmlAttributes(attributes || []) + ">"; 29891 } 29892}; 29893 29894function _getHtmlContainer(tag, options, attributes) { 29895 var html; 29896 29897 options = options || []; 29898 29899 html = "<" + tag + _getHtmlAttributes(attributes || []) + ">" + (options.innerHTML || "") + "</" + tag +">"; 29900 return html; 29901 29902} 29903 29904function _getHtmlAttributes(attributes) { 29905 var html = ""; 29906 29907 helpers.forEach(attributes, function(entry) { 29908 html += " " + entry.key + "='" + entry.value + "'"; 29909 }); 29910 return html; 29911} 29912 29913module.exports = htmlHelpers; 29914 29915/***/ }), 29916 29917/***/ "./sources/utils/promise.js": 29918/*!**********************************!*\ 29919 !*** ./sources/utils/promise.js ***! 29920 \**********************************/ 29921/*! no static exports found */ 29922/***/ (function(module, exports, __webpack_require__) { 29923 29924module.exports = __webpack_require__(/*! bluebird */ "./node_modules/bluebird/js/browser/bluebird.js"); 29925 29926/***/ }), 29927 29928/***/ "./sources/utils/task_tree_helpers.js": 29929/*!********************************************!*\ 29930 !*** ./sources/utils/task_tree_helpers.js ***! 29931 \********************************************/ 29932/*! no static exports found */ 29933/***/ (function(module, exports) { 29934 29935function copyLinkIdsArray(gantt, linkIds, targetHash){ 29936 for(var i = 0; i < linkIds.length; i++) { 29937 if(gantt.isLinkExists(linkIds[i])){ 29938 targetHash[linkIds[i]] = gantt.getLink(linkIds[i]); 29939 } 29940 } 29941} 29942 29943function copyLinkIds(gantt, task, targetHash){ 29944 copyLinkIdsArray(gantt, task.$source, targetHash); 29945 copyLinkIdsArray(gantt, task.$target, targetHash); 29946} 29947 29948function getSubtreeLinks(gantt, rootId){ 29949 var res = {}; 29950 29951 if(gantt.isTaskExists(rootId)){ 29952 copyLinkIds(gantt, gantt.getTask(rootId), res); 29953 } 29954 29955 gantt.eachTask(function(child){ 29956 copyLinkIds(gantt, child, res); 29957 }, rootId); 29958 29959 return res; 29960} 29961 29962function getSubtreeTasks(gantt, rootId){ 29963 var res = {}; 29964 29965 gantt.eachTask(function(child){ 29966 res[child.id] = child; 29967 }, rootId); 29968 29969 return res; 29970} 29971 29972module.exports = { 29973 getSubtreeLinks: getSubtreeLinks, 29974 getSubtreeTasks: getSubtreeTasks 29975}; 29976 29977/***/ }), 29978 29979/***/ "./sources/utils/timeout.js": 29980/*!**********************************!*\ 29981 !*** ./sources/utils/timeout.js ***! 29982 \**********************************/ 29983/*! no static exports found */ 29984/***/ (function(module, exports) { 29985 29986function checkTimeout(host, updPerSecond){ 29987 if (!updPerSecond) 29988 return true; 29989 29990 if (host._on_timeout) 29991 return false; 29992 29993 var timeout = Math.ceil(1000/updPerSecond); 29994 if (timeout < 2) return true; 29995 29996 setTimeout(function(){ 29997 delete host._on_timeout; 29998 }, timeout); 29999 30000 host._on_timeout = true; 30001 return true; 30002} 30003 30004module.exports = checkTimeout; 30005 30006/***/ }), 30007 30008/***/ "./sources/utils/utils.js": 30009/*!********************************!*\ 30010 !*** ./sources/utils/utils.js ***! 30011 \********************************/ 30012/*! no static exports found */ 30013/***/ (function(module, exports, __webpack_require__) { 30014 30015var helpers = __webpack_require__(/*! ./helpers */ "./sources/utils/helpers.js"); 30016 30017function isCustomType(object){ 30018 var constructorString = object.constructor.toString(); 30019 var plainObjectConstructor = ({}).constructor.toString(); 30020 30021 return constructorString !== plainObjectConstructor; 30022} 30023 30024function copy(object) { 30025 var i, result; // iterator, types array, result 30026 30027 if (object && typeof object == "object") { 30028 30029 switch (true){ 30030 case (helpers.isDate(object)): 30031 result = new Date(object); 30032 break; 30033 case (helpers.isArray(object)): 30034 result = new Array(object.length); 30035 for(i = 0; i < object.length; i++){ 30036 result[i] = copy(object[i]); 30037 } 30038 break; 30039 case (helpers.isStringObject(object)): 30040 result = new String(object); 30041 break; 30042 case (helpers.isNumberObject(object)): 30043 result = new Number(object); 30044 break; 30045 case (helpers.isBooleanObject(object)): 30046 result = new Boolean(object); 30047 break; 30048 default: 30049 if(isCustomType(object)){ 30050 result = Object.create(object); 30051 }else{ 30052 result = {}; 30053 } 30054 30055 for (i in object) { 30056 if (Object.prototype.hasOwnProperty.apply(object, [i])) 30057 result[i] = copy(object[i]); 30058 } 30059 break; 30060 } 30061 } 30062 return result || object; 30063} 30064 30065function mixin (target, source, force){ 30066 for (var f in source) 30067 if (((target[f] === undefined) || force)) target[f]=source[f]; 30068 return target; 30069} 30070 30071function defined(obj) { 30072 return typeof(obj) != "undefined"; 30073} 30074 30075var seed; 30076function uid() { 30077 if (!seed) 30078 seed = (new Date()).valueOf(); 30079 30080 seed++; 30081 return seed; 30082} 30083 30084//creates function with specified "this" pointer 30085function bind(functor, object){ 30086 if(functor.bind) 30087 return functor.bind(object); 30088 else 30089 return function(){ return functor.apply(object,arguments); }; 30090} 30091 30092function event(el, event, handler, capture){ 30093 if (el.addEventListener) 30094 el.addEventListener(event, handler, capture === undefined ? false : capture); 30095 30096 else if (el.attachEvent) 30097 el.attachEvent("on"+event, handler); 30098} 30099 30100function eventRemove(el, event, handler, capture){ 30101 if (el.removeEventListener) 30102 el.removeEventListener(event, handler, capture === undefined ? false : capture); 30103 30104 else if (el.detachEvent) 30105 el.detachEvent("on"+event, handler); 30106} 30107 30108module.exports = { 30109 copy: copy, 30110 defined: defined, 30111 mixin: mixin, 30112 uid: uid, 30113 bind: bind, 30114 event: event, 30115 eventRemove: eventRemove 30116}; 30117 30118/***/ }) 30119 30120/******/ }); 30121});