ui.collection_widget.edit.strategy.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * DevExtreme (ui/collection/ui.collection_widget.edit.strategy.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. var $ = require("../../core/renderer");
  11. var Class = require("../../core/class");
  12. var commonUtils = require("../../core/utils/common");
  13. var abstract = Class.abstract;
  14. var EditStrategy = Class.inherit({
  15. ctor: function(collectionWidget) {
  16. this._collectionWidget = collectionWidget
  17. },
  18. getIndexByItemData: abstract,
  19. getItemDataByIndex: abstract,
  20. getKeysByItems: abstract,
  21. getItemsByKeys: abstract,
  22. itemsGetter: abstract,
  23. getKeyByIndex: function(index) {
  24. var resultIndex = this._denormalizeItemIndex(index);
  25. return this.getKeysByItems([this.getItemDataByIndex(resultIndex)])[0]
  26. },
  27. _equalKeys: function(key1, key2) {
  28. if (this._collectionWidget._isKeySpecified()) {
  29. return commonUtils.equalByValue(key1, key2)
  30. } else {
  31. return key1 === key2
  32. }
  33. },
  34. beginCache: function() {
  35. this._cache = {}
  36. },
  37. endCache: function() {
  38. this._cache = null
  39. },
  40. getIndexByKey: abstract,
  41. getNormalizedIndex: function(value) {
  42. if (this._isNormalizedItemIndex(value)) {
  43. return value
  44. }
  45. if (this._isItemIndex(value)) {
  46. return this._normalizeItemIndex(value)
  47. }
  48. if (this._isDOMNode(value)) {
  49. return this._getNormalizedItemIndex(value)
  50. }
  51. return this._normalizeItemIndex(this.getIndexByItemData(value))
  52. },
  53. getIndex: function(value) {
  54. if (this._isNormalizedItemIndex(value)) {
  55. return this._denormalizeItemIndex(value)
  56. }
  57. if (this._isItemIndex(value)) {
  58. return value
  59. }
  60. if (this._isDOMNode(value)) {
  61. return this._denormalizeItemIndex(this._getNormalizedItemIndex(value))
  62. }
  63. return this.getIndexByItemData(value)
  64. },
  65. getItemElement: function(value) {
  66. if (this._isNormalizedItemIndex(value)) {
  67. return this._getItemByNormalizedIndex(value)
  68. }
  69. if (this._isItemIndex(value)) {
  70. return this._getItemByNormalizedIndex(this._normalizeItemIndex(value))
  71. }
  72. if (this._isDOMNode(value)) {
  73. return $(value)
  74. }
  75. var normalizedItemIndex = this._normalizeItemIndex(this.getIndexByItemData(value));
  76. return this._getItemByNormalizedIndex(normalizedItemIndex)
  77. },
  78. deleteItemAtIndex: abstract,
  79. itemPlacementFunc: function(movingIndex, destinationIndex) {
  80. return this._itemsFromSameParent(movingIndex, destinationIndex) && movingIndex < destinationIndex ? "after" : "before"
  81. },
  82. moveItemAtIndexToIndex: abstract,
  83. _isNormalizedItemIndex: function(index) {
  84. return "number" === typeof index && Math.round(index) === index
  85. },
  86. _isDOMNode: function(value) {
  87. var $value;
  88. try {
  89. $value = $(value)
  90. } catch (error) {
  91. return false
  92. }
  93. return $value && $value.length && $value.get(0).nodeType
  94. },
  95. _isItemIndex: abstract,
  96. _getNormalizedItemIndex: abstract,
  97. _normalizeItemIndex: abstract,
  98. _denormalizeItemIndex: abstract,
  99. _getItemByNormalizedIndex: abstract,
  100. _itemsFromSameParent: abstract
  101. });
  102. module.exports = EditStrategy;