angular-dual-listbox.umd.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/forms')) :
  3. typeof define === 'function' && define.amd ? define('angular-dual-listbox', ['exports', '@angular/core', '@angular/common', '@angular/forms'], factory) :
  4. (global = global || self, factory(global['angular-dual-listbox'] = {}, global.ng.core, global.ng.common, global.ng.forms));
  5. }(this, function (exports, core, common, forms) { 'use strict';
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  9. */
  10. var BasicList = /** @class */ (function () {
  11. function BasicList(name) {
  12. this._name = name;
  13. this.last = null;
  14. this.picker = '';
  15. this.dragStart = false;
  16. this.dragOver = false;
  17. // Arrays will contain objects of { _id, _name }.
  18. this.pick = [];
  19. this.list = [];
  20. this.sift = [];
  21. }
  22. Object.defineProperty(BasicList.prototype, "name", {
  23. get: /**
  24. * @return {?}
  25. */
  26. function () {
  27. return this._name;
  28. },
  29. enumerable: true,
  30. configurable: true
  31. });
  32. return BasicList;
  33. }());
  34. /**
  35. * @fileoverview added by tsickle
  36. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  37. */
  38. /** @type {?} */
  39. var nextId = 0;
  40. var DualListComponent = /** @class */ (function () {
  41. function DualListComponent(differs) {
  42. this.differs = differs;
  43. this.id = "dual-list-" + nextId++;
  44. this.key = '_id';
  45. this.display = '_name';
  46. this.height = '100px';
  47. this.filter = false;
  48. this.format = DualListComponent.DEFAULT_FORMAT;
  49. this.sort = false;
  50. this.disabled = false;
  51. this.destinationChange = new core.EventEmitter();
  52. this.sorter = (/**
  53. * @param {?} a
  54. * @param {?} b
  55. * @return {?}
  56. */
  57. function (a, b) { return (a._name < b._name) ? -1 : ((a._name > b._name) ? 1 : 0); });
  58. this.available = new BasicList(DualListComponent.AVAILABLE_LIST_NAME);
  59. this.confirmed = new BasicList(DualListComponent.CONFIRMED_LIST_NAME);
  60. }
  61. /**
  62. * @param {?} changeRecord
  63. * @return {?}
  64. */
  65. DualListComponent.prototype.ngOnChanges = /**
  66. * @param {?} changeRecord
  67. * @return {?}
  68. */
  69. function (changeRecord) {
  70. if (changeRecord['filter']) {
  71. if (changeRecord['filter'].currentValue === false) {
  72. this.clearFilter(this.available);
  73. this.clearFilter(this.confirmed);
  74. }
  75. }
  76. if (changeRecord['sort']) {
  77. if (changeRecord['sort'].currentValue === true && this.compare === undefined) {
  78. this.compare = this.sorter;
  79. }
  80. else if (changeRecord['sort'].currentValue === false) {
  81. this.compare = undefined;
  82. }
  83. }
  84. if (changeRecord['format']) {
  85. this.format = changeRecord['format'].currentValue;
  86. if (typeof (this.format.direction) === 'undefined') {
  87. this.format.direction = DualListComponent.LTR;
  88. }
  89. if (typeof (this.format.add) === 'undefined') {
  90. this.format.add = DualListComponent.DEFAULT_FORMAT.add;
  91. }
  92. if (typeof (this.format.remove) === 'undefined') {
  93. this.format.remove = DualListComponent.DEFAULT_FORMAT.remove;
  94. }
  95. if (typeof (this.format.all) === 'undefined') {
  96. this.format.all = DualListComponent.DEFAULT_FORMAT.all;
  97. }
  98. if (typeof (this.format.none) === 'undefined') {
  99. this.format.none = DualListComponent.DEFAULT_FORMAT.none;
  100. }
  101. if (typeof (this.format.draggable) === 'undefined') {
  102. this.format.draggable = DualListComponent.DEFAULT_FORMAT.draggable;
  103. }
  104. }
  105. if (changeRecord['source']) {
  106. this.available = new BasicList(DualListComponent.AVAILABLE_LIST_NAME);
  107. this.updatedSource();
  108. this.updatedDestination();
  109. }
  110. if (changeRecord['destination']) {
  111. this.confirmed = new BasicList(DualListComponent.CONFIRMED_LIST_NAME);
  112. this.updatedDestination();
  113. this.updatedSource();
  114. }
  115. };
  116. /**
  117. * @return {?}
  118. */
  119. DualListComponent.prototype.ngDoCheck = /**
  120. * @return {?}
  121. */
  122. function () {
  123. if (this.source && this.buildAvailable(this.source)) {
  124. this.onFilter(this.available);
  125. }
  126. if (this.destination && this.buildConfirmed(this.destination)) {
  127. this.onFilter(this.confirmed);
  128. }
  129. };
  130. /**
  131. * @param {?} source
  132. * @return {?}
  133. */
  134. DualListComponent.prototype.buildAvailable = /**
  135. * @param {?} source
  136. * @return {?}
  137. */
  138. function (source) {
  139. var _this = this;
  140. /** @type {?} */
  141. var sourceChanges = this.sourceDiffer.diff(source);
  142. if (sourceChanges) {
  143. sourceChanges.forEachRemovedItem((/**
  144. * @param {?} r
  145. * @return {?}
  146. */
  147. function (r) {
  148. /** @type {?} */
  149. var idx = _this.findItemIndex(_this.available.list, r.item, _this.key);
  150. if (idx !== -1) {
  151. _this.available.list.splice(idx, 1);
  152. }
  153. }));
  154. sourceChanges.forEachAddedItem((/**
  155. * @param {?} r
  156. * @return {?}
  157. */
  158. function (r) {
  159. // Do not add duplicates even if source has duplicates.
  160. if (_this.findItemIndex(_this.available.list, r.item, _this.key) === -1) {
  161. _this.available.list.push({ _id: _this.makeId(r.item), _name: _this.makeName(r.item) });
  162. }
  163. }));
  164. if (this.compare !== undefined) {
  165. this.available.list.sort(this.compare);
  166. }
  167. this.available.sift = this.available.list;
  168. return true;
  169. }
  170. return false;
  171. };
  172. /**
  173. * @param {?} destination
  174. * @return {?}
  175. */
  176. DualListComponent.prototype.buildConfirmed = /**
  177. * @param {?} destination
  178. * @return {?}
  179. */
  180. function (destination) {
  181. var _this = this;
  182. /** @type {?} */
  183. var moved = false;
  184. /** @type {?} */
  185. var destChanges = this.destinationDiffer.diff(destination);
  186. if (destChanges) {
  187. destChanges.forEachRemovedItem((/**
  188. * @param {?} r
  189. * @return {?}
  190. */
  191. function (r) {
  192. /** @type {?} */
  193. var idx = _this.findItemIndex(_this.confirmed.list, r.item, _this.key);
  194. if (idx !== -1) {
  195. if (!_this.isItemSelected(_this.confirmed.pick, _this.confirmed.list[idx])) {
  196. _this.selectItem(_this.confirmed.pick, _this.confirmed.list[idx]);
  197. }
  198. _this.moveItem(_this.confirmed, _this.available, _this.confirmed.list[idx], false);
  199. moved = true;
  200. }
  201. }));
  202. destChanges.forEachAddedItem((/**
  203. * @param {?} r
  204. * @return {?}
  205. */
  206. function (r) {
  207. /** @type {?} */
  208. var idx = _this.findItemIndex(_this.available.list, r.item, _this.key);
  209. if (idx !== -1) {
  210. if (!_this.isItemSelected(_this.available.pick, _this.available.list[idx])) {
  211. _this.selectItem(_this.available.pick, _this.available.list[idx]);
  212. }
  213. _this.moveItem(_this.available, _this.confirmed, _this.available.list[idx], false);
  214. moved = true;
  215. }
  216. }));
  217. if (this.compare !== undefined) {
  218. this.confirmed.list.sort(this.compare);
  219. }
  220. this.confirmed.sift = this.confirmed.list;
  221. if (moved) {
  222. this.trueUp();
  223. }
  224. return true;
  225. }
  226. return false;
  227. };
  228. /**
  229. * @return {?}
  230. */
  231. DualListComponent.prototype.updatedSource = /**
  232. * @return {?}
  233. */
  234. function () {
  235. this.available.list.length = 0;
  236. this.available.pick.length = 0;
  237. if (this.source !== undefined) {
  238. this.sourceDiffer = this.differs.find(this.source).create(null);
  239. }
  240. };
  241. /**
  242. * @return {?}
  243. */
  244. DualListComponent.prototype.updatedDestination = /**
  245. * @return {?}
  246. */
  247. function () {
  248. if (this.destination !== undefined) {
  249. this.destinationDiffer = this.differs.find(this.destination).create(null);
  250. }
  251. };
  252. /**
  253. * @return {?}
  254. */
  255. DualListComponent.prototype.direction = /**
  256. * @return {?}
  257. */
  258. function () {
  259. return this.format.direction === DualListComponent.LTR;
  260. };
  261. /**
  262. * @param {?=} list
  263. * @return {?}
  264. */
  265. DualListComponent.prototype.dragEnd = /**
  266. * @param {?=} list
  267. * @return {?}
  268. */
  269. function (list) {
  270. if (list === void 0) { list = null; }
  271. if (list) {
  272. list.dragStart = false;
  273. }
  274. else {
  275. this.available.dragStart = false;
  276. this.confirmed.dragStart = false;
  277. }
  278. return false;
  279. };
  280. /**
  281. * @param {?} event
  282. * @param {?} item
  283. * @param {?} list
  284. * @return {?}
  285. */
  286. DualListComponent.prototype.drag = /**
  287. * @param {?} event
  288. * @param {?} item
  289. * @param {?} list
  290. * @return {?}
  291. */
  292. function (event, item, list) {
  293. if (!this.isItemSelected(list.pick, item)) {
  294. this.selectItem(list.pick, item);
  295. }
  296. list.dragStart = true;
  297. // Set a custom type to be this dual-list's id.
  298. event.dataTransfer.setData(this.id, item['_id']);
  299. };
  300. /**
  301. * @param {?} event
  302. * @param {?} list
  303. * @return {?}
  304. */
  305. DualListComponent.prototype.allowDrop = /**
  306. * @param {?} event
  307. * @param {?} list
  308. * @return {?}
  309. */
  310. function (event, list) {
  311. if (event.dataTransfer.types.length && (event.dataTransfer.types[0] === this.id)) {
  312. event.preventDefault();
  313. if (!list.dragStart) {
  314. list.dragOver = true;
  315. }
  316. }
  317. return false;
  318. };
  319. /**
  320. * @return {?}
  321. */
  322. DualListComponent.prototype.dragLeave = /**
  323. * @return {?}
  324. */
  325. function () {
  326. this.available.dragOver = false;
  327. this.confirmed.dragOver = false;
  328. };
  329. /**
  330. * @param {?} event
  331. * @param {?} list
  332. * @return {?}
  333. */
  334. DualListComponent.prototype.drop = /**
  335. * @param {?} event
  336. * @param {?} list
  337. * @return {?}
  338. */
  339. function (event, list) {
  340. if (event.dataTransfer.types.length && (event.dataTransfer.types[0] === this.id)) {
  341. event.preventDefault();
  342. this.dragLeave();
  343. this.dragEnd();
  344. if (list === this.available) {
  345. this.moveItem(this.available, this.confirmed);
  346. }
  347. else {
  348. this.moveItem(this.confirmed, this.available);
  349. }
  350. }
  351. };
  352. /**
  353. * @private
  354. * @return {?}
  355. */
  356. DualListComponent.prototype.trueUp = /**
  357. * @private
  358. * @return {?}
  359. */
  360. function () {
  361. var _this = this;
  362. /** @type {?} */
  363. var changed = false;
  364. // Clear removed items.
  365. /** @type {?} */
  366. var pos = this.destination.length;
  367. while ((pos -= 1) >= 0) {
  368. /** @type {?} */
  369. var mv = this.confirmed.list.filter((/**
  370. * @param {?} conf
  371. * @return {?}
  372. */
  373. function (conf) {
  374. if (typeof _this.destination[pos] === 'object') {
  375. return conf._id === _this.destination[pos][_this.key];
  376. }
  377. else {
  378. return conf._id === _this.destination[pos];
  379. }
  380. }));
  381. if (mv.length === 0) {
  382. // Not found so remove.
  383. this.destination.splice(pos, 1);
  384. changed = true;
  385. }
  386. }
  387. var _loop_1 = function (i, len) {
  388. /** @type {?} */
  389. var mv = this_1.destination.filter((/**
  390. * @param {?} d
  391. * @return {?}
  392. */
  393. function (d) {
  394. if (typeof d === 'object') {
  395. return (d[_this.key] === _this.confirmed.list[i]._id);
  396. }
  397. else {
  398. return (d === _this.confirmed.list[i]._id);
  399. }
  400. }));
  401. if (mv.length === 0) {
  402. // Not found so add.
  403. mv = this_1.source.filter((/**
  404. * @param {?} o
  405. * @return {?}
  406. */
  407. function (o) {
  408. if (typeof o === 'object') {
  409. return (o[_this.key] === _this.confirmed.list[i]._id);
  410. }
  411. else {
  412. return (o === _this.confirmed.list[i]._id);
  413. }
  414. }));
  415. if (mv.length > 0) {
  416. this_1.destination.push(mv[0]);
  417. changed = true;
  418. }
  419. }
  420. };
  421. var this_1 = this;
  422. // Push added items.
  423. for (var i = 0, len = this.confirmed.list.length; i < len; i += 1) {
  424. _loop_1(i);
  425. }
  426. if (changed) {
  427. this.destinationChange.emit(this.destination);
  428. }
  429. };
  430. /**
  431. * @param {?} list
  432. * @param {?} item
  433. * @param {?=} key
  434. * @return {?}
  435. */
  436. DualListComponent.prototype.findItemIndex = /**
  437. * @param {?} list
  438. * @param {?} item
  439. * @param {?=} key
  440. * @return {?}
  441. */
  442. function (list, item, key) {
  443. if (key === void 0) { key = '_id'; }
  444. /** @type {?} */
  445. var idx = -1;
  446. /**
  447. * @param {?} e
  448. * @return {?}
  449. */
  450. function matchObject(e) {
  451. if (e._id === item[key]) {
  452. idx = list.indexOf(e);
  453. return true;
  454. }
  455. return false;
  456. }
  457. /**
  458. * @param {?} e
  459. * @return {?}
  460. */
  461. function match(e) {
  462. if (e._id === item) {
  463. idx = list.indexOf(e);
  464. return true;
  465. }
  466. return false;
  467. }
  468. // Assumption is that the arrays do not have duplicates.
  469. if (typeof item === 'object') {
  470. list.filter(matchObject);
  471. }
  472. else {
  473. list.filter(match);
  474. }
  475. return idx;
  476. };
  477. /**
  478. * @private
  479. * @param {?} source
  480. * @param {?} item
  481. * @return {?}
  482. */
  483. DualListComponent.prototype.makeUnavailable = /**
  484. * @private
  485. * @param {?} source
  486. * @param {?} item
  487. * @return {?}
  488. */
  489. function (source, item) {
  490. /** @type {?} */
  491. var idx = source.list.indexOf(item);
  492. if (idx !== -1) {
  493. source.list.splice(idx, 1);
  494. }
  495. };
  496. /**
  497. * @param {?} source
  498. * @param {?} target
  499. * @param {?=} item
  500. * @param {?=} trueup
  501. * @return {?}
  502. */
  503. DualListComponent.prototype.moveItem = /**
  504. * @param {?} source
  505. * @param {?} target
  506. * @param {?=} item
  507. * @param {?=} trueup
  508. * @return {?}
  509. */
  510. function (source, target, item, trueup) {
  511. var _this = this;
  512. if (item === void 0) { item = null; }
  513. if (trueup === void 0) { trueup = true; }
  514. /** @type {?} */
  515. var i = 0;
  516. /** @type {?} */
  517. var len = source.pick.length;
  518. if (item) {
  519. i = source.list.indexOf(item);
  520. len = i + 1;
  521. }
  522. var _loop_2 = function () {
  523. // Is the pick still in list?
  524. /** @type {?} */
  525. var mv = [];
  526. if (item) {
  527. /** @type {?} */
  528. var idx = this_2.findItemIndex(source.pick, item);
  529. if (idx !== -1) {
  530. mv[0] = source.pick[idx];
  531. }
  532. }
  533. else {
  534. mv = source.list.filter((/**
  535. * @param {?} src
  536. * @return {?}
  537. */
  538. function (src) {
  539. return (src._id === source.pick[i]._id);
  540. }));
  541. }
  542. // Should only ever be 1
  543. if (mv.length === 1) {
  544. // Add if not already in target.
  545. if (target.list.filter((/**
  546. * @param {?} trg
  547. * @return {?}
  548. */
  549. function (trg) { return trg._id === mv[0]._id; })).length === 0) {
  550. target.list.push(mv[0]);
  551. }
  552. this_2.makeUnavailable(source, mv[0]);
  553. }
  554. };
  555. var this_2 = this;
  556. for (; i < len; i += 1) {
  557. _loop_2();
  558. }
  559. if (this.compare !== undefined) {
  560. target.list.sort(this.compare);
  561. }
  562. source.pick.length = 0;
  563. // Update destination
  564. if (trueup) {
  565. this.trueUp();
  566. }
  567. // Delay ever-so-slightly to prevent race condition.
  568. setTimeout((/**
  569. * @return {?}
  570. */
  571. function () {
  572. _this.onFilter(source);
  573. _this.onFilter(target);
  574. }), 10);
  575. };
  576. /**
  577. * @param {?} list
  578. * @param {?} item
  579. * @return {?}
  580. */
  581. DualListComponent.prototype.isItemSelected = /**
  582. * @param {?} list
  583. * @param {?} item
  584. * @return {?}
  585. */
  586. function (list, item) {
  587. if (list.filter((/**
  588. * @param {?} e
  589. * @return {?}
  590. */
  591. function (e) { return Object.is(e, item); })).length > 0) {
  592. return true;
  593. }
  594. return false;
  595. };
  596. /**
  597. * @param {?} event
  598. * @param {?} index
  599. * @param {?} source
  600. * @param {?} item
  601. * @return {?}
  602. */
  603. DualListComponent.prototype.shiftClick = /**
  604. * @param {?} event
  605. * @param {?} index
  606. * @param {?} source
  607. * @param {?} item
  608. * @return {?}
  609. */
  610. function (event, index, source, item) {
  611. if (event.shiftKey && source.last && !Object.is(item, source.last)) {
  612. /** @type {?} */
  613. var idx = source.sift.indexOf(source.last);
  614. if (index > idx) {
  615. for (var i = (idx + 1); i < index; i += 1) {
  616. this.selectItem(source.pick, source.sift[i]);
  617. }
  618. }
  619. else if (idx !== -1) {
  620. for (var i = (index + 1); i < idx; i += 1) {
  621. this.selectItem(source.pick, source.sift[i]);
  622. }
  623. }
  624. }
  625. source.last = item;
  626. };
  627. /**
  628. * @param {?} list
  629. * @param {?} item
  630. * @return {?}
  631. */
  632. DualListComponent.prototype.selectItem = /**
  633. * @param {?} list
  634. * @param {?} item
  635. * @return {?}
  636. */
  637. function (list, item) {
  638. /** @type {?} */
  639. var pk = list.filter((/**
  640. * @param {?} e
  641. * @return {?}
  642. */
  643. function (e) {
  644. return Object.is(e, item);
  645. }));
  646. if (pk.length > 0) {
  647. // Already in list, so deselect.
  648. for (var i = 0, len = pk.length; i < len; i += 1) {
  649. /** @type {?} */
  650. var idx = list.indexOf(pk[i]);
  651. if (idx !== -1) {
  652. list.splice(idx, 1);
  653. }
  654. }
  655. }
  656. else {
  657. list.push(item);
  658. }
  659. };
  660. /**
  661. * @param {?} source
  662. * @return {?}
  663. */
  664. DualListComponent.prototype.selectAll = /**
  665. * @param {?} source
  666. * @return {?}
  667. */
  668. function (source) {
  669. source.pick.length = 0;
  670. source.pick = source.sift.slice(0);
  671. };
  672. /**
  673. * @param {?} source
  674. * @return {?}
  675. */
  676. DualListComponent.prototype.selectNone = /**
  677. * @param {?} source
  678. * @return {?}
  679. */
  680. function (source) {
  681. source.pick.length = 0;
  682. };
  683. /**
  684. * @param {?} source
  685. * @return {?}
  686. */
  687. DualListComponent.prototype.isAllSelected = /**
  688. * @param {?} source
  689. * @return {?}
  690. */
  691. function (source) {
  692. if (source.list.length === 0 || source.list.length === source.pick.length) {
  693. return true;
  694. }
  695. return false;
  696. };
  697. /**
  698. * @param {?} source
  699. * @return {?}
  700. */
  701. DualListComponent.prototype.isAnySelected = /**
  702. * @param {?} source
  703. * @return {?}
  704. */
  705. function (source) {
  706. if (source.pick.length > 0) {
  707. return true;
  708. }
  709. return false;
  710. };
  711. /**
  712. * @private
  713. * @param {?} source
  714. * @return {?}
  715. */
  716. DualListComponent.prototype.unpick = /**
  717. * @private
  718. * @param {?} source
  719. * @return {?}
  720. */
  721. function (source) {
  722. for (var i = source.pick.length - 1; i >= 0; i -= 1) {
  723. if (source.sift.indexOf(source.pick[i]) === -1) {
  724. source.pick.splice(i, 1);
  725. }
  726. }
  727. };
  728. /**
  729. * @param {?} source
  730. * @return {?}
  731. */
  732. DualListComponent.prototype.clearFilter = /**
  733. * @param {?} source
  734. * @return {?}
  735. */
  736. function (source) {
  737. if (source) {
  738. source.picker = '';
  739. this.onFilter(source);
  740. }
  741. };
  742. /**
  743. * @param {?} source
  744. * @return {?}
  745. */
  746. DualListComponent.prototype.onFilter = /**
  747. * @param {?} source
  748. * @return {?}
  749. */
  750. function (source) {
  751. var _this = this;
  752. if (source.picker.length > 0) {
  753. try {
  754. /** @type {?} */
  755. var filtered = source.list.filter((/**
  756. * @param {?} item
  757. * @return {?}
  758. */
  759. function (item) {
  760. if (Object.prototype.toString.call(item) === '[object Object]') {
  761. if (item._name !== undefined) {
  762. // @ts-ignore: remove when d.ts has locale as an argument.
  763. return item._name.toLocaleLowerCase(_this.format.locale).indexOf(source.picker.toLocaleLowerCase(_this.format.locale)) !== -1;
  764. }
  765. else {
  766. // @ts-ignore: remove when d.ts has locale as an argument.
  767. return JSON.stringify(item).toLocaleLowerCase(_this.format.locale).indexOf(source.picker.toLocaleLowerCase(_this.format.locale)) !== -1;
  768. }
  769. }
  770. else {
  771. // @ts-ignore: remove when d.ts has locale as an argument.
  772. return item.toLocaleLowerCase(_this.format.locale).indexOf(source.picker.toLocaleLowerCase(_this.format.locale)) !== -1;
  773. }
  774. }));
  775. source.sift = filtered;
  776. this.unpick(source);
  777. }
  778. catch (e) {
  779. if (e instanceof RangeError) {
  780. this.format.locale = undefined;
  781. }
  782. source.sift = source.list;
  783. }
  784. }
  785. else {
  786. source.sift = source.list;
  787. }
  788. };
  789. /**
  790. * @private
  791. * @param {?} item
  792. * @return {?}
  793. */
  794. DualListComponent.prototype.makeId = /**
  795. * @private
  796. * @param {?} item
  797. * @return {?}
  798. */
  799. function (item) {
  800. if (typeof item === 'object') {
  801. return item[this.key];
  802. }
  803. else {
  804. return item;
  805. }
  806. };
  807. // Allow for complex names by passing an array of strings.
  808. // Example: [display]="[ '_type.substring(0,1)', '_name' ]"
  809. // Allow for complex names by passing an array of strings.
  810. // Example: [display]="[ '_type.substring(0,1)', '_name' ]"
  811. /**
  812. * @protected
  813. * @param {?} item
  814. * @param {?=} separator
  815. * @return {?}
  816. */
  817. DualListComponent.prototype.makeName =
  818. // Allow for complex names by passing an array of strings.
  819. // Example: [display]="[ '_type.substring(0,1)', '_name' ]"
  820. /**
  821. * @protected
  822. * @param {?} item
  823. * @param {?=} separator
  824. * @return {?}
  825. */
  826. function (item, separator) {
  827. if (separator === void 0) { separator = '_'; }
  828. /** @type {?} */
  829. var display = this.display;
  830. /**
  831. * @param {?} itm
  832. * @return {?}
  833. */
  834. function fallback(itm) {
  835. switch (Object.prototype.toString.call(itm)) {
  836. case '[object Number]':
  837. return itm;
  838. case '[object String]':
  839. return itm;
  840. default:
  841. if (itm !== undefined) {
  842. return itm[display];
  843. }
  844. else {
  845. return 'undefined';
  846. }
  847. }
  848. }
  849. /** @type {?} */
  850. var str = '';
  851. if (this.display !== undefined) {
  852. switch (Object.prototype.toString.call(this.display)) {
  853. case '[object Function]':
  854. str = this.display(item);
  855. break;
  856. case '[object Array]':
  857. for (var i = 0, len = this.display.length; i < len; i += 1) {
  858. if (str.length > 0) {
  859. str = str + separator;
  860. }
  861. if (this.display[i].indexOf('.') === -1) {
  862. // Simple, just add to string.
  863. str = str + item[this.display[i]];
  864. }
  865. else {
  866. // Complex, some action needs to be performed
  867. /** @type {?} */
  868. var parts = this.display[i].split('.');
  869. /** @type {?} */
  870. var s = item[parts[0]];
  871. if (s) {
  872. // Use brute force
  873. if (parts[1].indexOf('substring') !== -1) {
  874. /** @type {?} */
  875. var nums = (parts[1].substring(parts[1].indexOf('(') + 1, parts[1].indexOf(')'))).split(',');
  876. switch (nums.length) {
  877. case 1:
  878. str = str + s.substring(parseInt(nums[0], 10));
  879. break;
  880. case 2:
  881. str = str + s.substring(parseInt(nums[0], 10), parseInt(nums[1], 10));
  882. break;
  883. default:
  884. str = str + s;
  885. break;
  886. }
  887. }
  888. else {
  889. // method not approved, so just add s.
  890. str = str + s;
  891. }
  892. }
  893. }
  894. }
  895. break;
  896. default:
  897. str = fallback(item);
  898. break;
  899. }
  900. }
  901. else {
  902. str = fallback(item);
  903. }
  904. return str;
  905. };
  906. DualListComponent.AVAILABLE_LIST_NAME = 'available';
  907. DualListComponent.CONFIRMED_LIST_NAME = 'confirmed';
  908. DualListComponent.LTR = 'left-to-right';
  909. DualListComponent.RTL = 'right-to-left';
  910. DualListComponent.DEFAULT_FORMAT = {
  911. add: 'Add',
  912. remove: 'Remove',
  913. all: 'All',
  914. none: 'None',
  915. direction: DualListComponent.LTR,
  916. draggable: true,
  917. locale: undefined
  918. };
  919. DualListComponent.decorators = [
  920. { type: core.Component, args: [{
  921. selector: 'dual-list',
  922. template: "<div class=\"dual-list\">\n\t<div class=\"listbox\" [ngStyle]=\"{ 'order' : direction() ? 1 : 2, 'margin-left' : direction() ? 0 : '10px' }\">\n\t\t<button type=\"button\" name=\"addBtn\" class=\"btn btn-primary btn-block\"\n\t\t\t(click)=\"moveItem(available, confirmed)\" [ngClass]=\"direction() ? 'point-right' : 'point-left'\"\n\t\t\t[disabled]=\"available.pick.length === 0\">{{format.add}}</button>\n\n\t\t<form *ngIf=\"filter\" class=\"filter\">\n\t\t\t<input class=\"form-control\" name=\"filterSource\" [(ngModel)]=\"available.picker\" (ngModelChange)=\"onFilter(available)\">\n\t\t</form>\n\n\t\t<div class=\"record-picker\">\n\t\t\t<ul [ngStyle]=\"{'max-height': height, 'min-height': height}\" [ngClass]=\"{over:available.dragOver}\"\n\t\t\t\t(drop)=\"drop($event, confirmed)\" (dragover)=\"allowDrop($event, available)\" (dragleave)=\"dragLeave()\">\n\t\t\t\t<li *ngFor=\"let item of available.sift; let idx=index;\"\n\t\t\t\t\t(click)=\"disabled ? null : selectItem(available.pick, item); shiftClick($event, idx, available, item)\"\n\t\t\t\t\t[ngClass]=\"{selected: isItemSelected(available.pick, item), disabled: disabled}\"\n\t\t\t\t\t[draggable]=\"!disabled && format.draggable\" (dragstart)=\"drag($event, item, available)\" (dragend)=\"dragEnd(available)\"\n\t\t\t\t><label>{{item._name}}</label></li>\n\t\t\t</ul>\n\t\t</div>\n\n\t\t<div class=\"button-bar\">\n\t\t\t<button type=\"button\" class=\"btn btn-primary pull-left\" (click)=\"selectAll(available)\"\n\t\t\t\t[disabled]=\"disabled || isAllSelected(available)\">{{format.all}}</button>\n\t\t\t<button type=\"button\" class=\"btn btn-default pull-right\" (click)=\"selectNone(available)\"\n\t\t\t\t[disabled]=\"!isAnySelected(available)\">{{format.none}}</button>\n\t\t</div>\n\t</div>\n\n\t<div class=\"listbox\" [ngStyle]=\"{ 'order' : direction() ? 2 : 1, 'margin-left' : direction() ? '10px' : 0 }\">\n\t\t<button type=\"button\" name=\"removeBtn\" class=\"btn btn-primary btn-block\"\n\t\t\t(click)=\"moveItem(confirmed, available)\" [ngClass]=\"direction() ? 'point-left' : 'point-right'\"\n\t\t\t[disabled]=\"confirmed.pick.length === 0\">{{format.remove}}</button>\n\n\t\t<form *ngIf=\"filter\" class=\"filter\">\n\t\t\t<input class=\"form-control\" name=\"filterDestination\" [(ngModel)]=\"confirmed.picker\" (ngModelChange)=\"onFilter(confirmed)\">\n\t\t</form>\n\n\t\t<div class=\"record-picker\">\n\t\t\t<ul [ngStyle]=\"{'max-height': height, 'min-height': height}\" [ngClass]=\"{over:confirmed.dragOver}\"\n\t\t\t\t(drop)=\"drop($event, available)\" (dragover)=\"allowDrop($event, confirmed)\" (dragleave)=\"dragLeave()\">\n\t\t\t\t<li #itmConf *ngFor=\"let item of confirmed.sift; let idx=index;\"\n\t\t\t\t\t(click)=\"disabled ? null : selectItem(confirmed.pick, item); shiftClick($event, idx, confirmed, item)\"\n\t\t\t\t\t[ngClass]=\"{selected: isItemSelected(confirmed.pick, item), disabled: disabled}\"\n\t\t\t\t\t[draggable]=\"!disabled && format.draggable\" (dragstart)=\"drag($event, item, confirmed)\" (dragend)=\"dragEnd(confirmed)\"\n\t\t\t\t><label>{{item._name}}</label></li>\n\t\t\t</ul>\n\t\t</div>\n\n\t\t<div class=\"button-bar\">\n\t\t\t<button type=\"button\" class=\"btn btn-primary pull-left\" (click)=\"selectAll(confirmed)\"\n\t\t\t\t[disabled]=\"disabled || isAllSelected(confirmed)\">{{format.all}}</button>\n\t\t\t<button type=\"button\" class=\"btn btn-default pull-right\" (click)=\"selectNone(confirmed)\"\n\t\t\t\t[disabled]=\"!isAnySelected(confirmed)\">{{format.none}}</button>\n\t\t</div>\n\t</div>\n</div>\n",
  923. styles: ["div.record-picker{overflow-x:hidden;overflow-y:auto;border:1px solid #ddd;border-radius:8px;position:relative;cursor:pointer;scrollbar-base-color:#337ab7;scrollbar-3dlight-color:#337ab7;scrollbar-highlight-color:#337ab7;scrollbar-track-color:#eee;scrollbar-arrow-color:gray;scrollbar-shadow-color:gray;scrollbar-dark-shadow-color:gray}div.record-picker::-webkit-scrollbar{width:12px}div.record-picker::-webkit-scrollbar-button{width:0;height:0}div.record-picker::-webkit-scrollbar-track{background:#eee;box-shadow:0 0 3px #dfdfdf inset;border-top-right-radius:8px;border-bottom-right-radius:8px}div.record-picker::-webkit-scrollbar-thumb{background:#337ab7;border:thin solid gray;border-top-right-radius:8px;border-bottom-right-radius:8px}div.record-picker::-webkit-scrollbar-thumb:hover{background:#286090}.record-picker ul{margin:0;padding:0 0 1px}.record-picker li{border-top:thin solid #ddd;border-bottom:1px solid #ddd;display:block;padding:2px 2px 2px 10px;margin-bottom:-1px;font-size:.85em;cursor:pointer;white-space:nowrap;min-height:16px}.record-picker li:hover{background-color:#f5f5f5}.record-picker li.selected{background-color:#d9edf7}.record-picker li.selected:hover{background-color:#c4e3f3}.record-picker li.disabled{opacity:.5;cursor:default;background-color:inherit}.record-picker li:first-child{border-top-left-radius:8px;border-top-right-radius:8px;border-top:none}.record-picker li:last-child{border-bottom-left-radius:8px;border-bottom-right-radius:8px;border-bottom:none}.record-picker label{cursor:pointer;font-weight:inherit;font-size:14px;padding:4px;margin-bottom:-1px;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.record-picker ul.over{background-color:#d3d3d3}.dual-list{display:flex;flex-direction:row;align-content:flex-start}.dual-list .listbox{width:50%;margin:0}.dual-list .button-bar{margin-top:8px}.point-right::after{content:\"\\25B6\";padding-left:1em}.point-left::before{content:\"\\25C0\";padding-right:1em}.dual-list .button-bar button{width:47%}button.btn-block{display:block;width:100%;margin-bottom:8px}.filter{margin-bottom:-2.2em}.filter::after{content:\"o\";width:40px;color:transparent;font-size:2em;background-image:url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 512 512\"><path d=\"M0 64l192 192v192l128-32V256L512 64H0z\"/></svg>');background-repeat:no-repeat;background-position:center center;opacity:.2;top:-36px;left:calc(100% - 21px);position:relative}"]
  924. }] }
  925. ];
  926. /** @nocollapse */
  927. DualListComponent.ctorParameters = function () { return [
  928. { type: core.IterableDiffers }
  929. ]; };
  930. DualListComponent.propDecorators = {
  931. id: [{ type: core.Input }],
  932. key: [{ type: core.Input }],
  933. display: [{ type: core.Input }],
  934. height: [{ type: core.Input }],
  935. filter: [{ type: core.Input }],
  936. format: [{ type: core.Input }],
  937. sort: [{ type: core.Input }],
  938. compare: [{ type: core.Input }],
  939. disabled: [{ type: core.Input }],
  940. source: [{ type: core.Input }],
  941. destination: [{ type: core.Input }],
  942. destinationChange: [{ type: core.Output }]
  943. };
  944. return DualListComponent;
  945. }());
  946. /**
  947. * @fileoverview added by tsickle
  948. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  949. */
  950. var AngularDualListBoxModule = /** @class */ (function () {
  951. function AngularDualListBoxModule() {
  952. }
  953. AngularDualListBoxModule.decorators = [
  954. { type: core.NgModule, args: [{
  955. imports: [
  956. common.CommonModule,
  957. forms.FormsModule
  958. ],
  959. declarations: [DualListComponent],
  960. exports: [DualListComponent]
  961. },] }
  962. ];
  963. return AngularDualListBoxModule;
  964. }());
  965. exports.AngularDualListBoxModule = AngularDualListBoxModule;
  966. exports.BasicList = BasicList;
  967. exports.DualListComponent = DualListComponent;
  968. Object.defineProperty(exports, '__esModule', { value: true });
  969. }));
  970. //# sourceMappingURL=angular-dual-listbox.umd.js.map