ui.collection_widget.edit.strategy.plain.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * DevExtreme (ui/collection/ui.collection_widget.edit.strategy.plain.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. function _typeof(obj) {
  11. "@babel/helpers - typeof";
  12. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
  13. return typeof obj
  14. } : function(obj) {
  15. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
  16. }, _typeof(obj)
  17. }
  18. var inArray = require("../../core/utils/array").inArray;
  19. var EditStrategy = require("./ui.collection_widget.edit.strategy");
  20. var PlainEditStrategy = EditStrategy.inherit({
  21. _getPlainItems: function() {
  22. return this._collectionWidget.option("items") || []
  23. },
  24. getIndexByItemData: function(itemData) {
  25. var keyOf = this._collectionWidget.keyOf.bind(this._collectionWidget);
  26. if (keyOf) {
  27. return this.getIndexByKey(keyOf(itemData))
  28. } else {
  29. return inArray(itemData, this._getPlainItems())
  30. }
  31. },
  32. getItemDataByIndex: function(index) {
  33. return this._getPlainItems()[index]
  34. },
  35. deleteItemAtIndex: function(index) {
  36. this._getPlainItems().splice(index, 1)
  37. },
  38. itemsGetter: function() {
  39. return this._getPlainItems()
  40. },
  41. getKeysByItems: function(items) {
  42. var keyOf = this._collectionWidget.keyOf.bind(this._collectionWidget);
  43. var result = items;
  44. if (keyOf) {
  45. result = [];
  46. for (var i = 0; i < items.length; i++) {
  47. result.push(keyOf(items[i]))
  48. }
  49. }
  50. return result
  51. },
  52. getIndexByKey: function(key) {
  53. var cache = this._cache;
  54. var keys = cache && cache.keys || this.getKeysByItems(this._getPlainItems());
  55. if (cache && !cache.keys) {
  56. cache.keys = keys
  57. }
  58. if ("object" === _typeof(key)) {
  59. for (var i = 0, length = keys.length; i < length; i++) {
  60. if (this._equalKeys(key, keys[i])) {
  61. return i
  62. }
  63. }
  64. } else {
  65. return keys.indexOf(key)
  66. }
  67. return -1
  68. },
  69. getItemsByKeys: function(keys, items) {
  70. return (items || keys).slice()
  71. },
  72. moveItemAtIndexToIndex: function(movingIndex, destinationIndex) {
  73. var items = this._getPlainItems();
  74. var movedItemData = items[movingIndex];
  75. items.splice(movingIndex, 1);
  76. items.splice(destinationIndex, 0, movedItemData)
  77. },
  78. _isItemIndex: function(index) {
  79. return "number" === typeof index && Math.round(index) === index
  80. },
  81. _getNormalizedItemIndex: function(itemElement) {
  82. return this._collectionWidget._itemElements().index(itemElement)
  83. },
  84. _normalizeItemIndex: function(index) {
  85. return index
  86. },
  87. _denormalizeItemIndex: function(index) {
  88. return index
  89. },
  90. _getItemByNormalizedIndex: function(index) {
  91. return index > -1 ? this._collectionWidget._itemElements().eq(index) : null
  92. },
  93. _itemsFromSameParent: function() {
  94. return true
  95. }
  96. });
  97. module.exports = PlainEditStrategy;