Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VTreeviewNode.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.VTreeviewNodeProps = undefined;
  6. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; // Components
  7. // Mixins
  8. // Utils
  9. var _transitions = require('../transitions');
  10. var _VIcon = require('../VIcon');
  11. var _VTreeviewNode = require('./VTreeviewNode');
  12. var _VTreeviewNode2 = _interopRequireDefault(_VTreeviewNode);
  13. var _registrable = require('../../mixins/registrable');
  14. var _mixins = require('../../util/mixins');
  15. var _mixins2 = _interopRequireDefault(_mixins);
  16. var _helpers = require('../../util/helpers');
  17. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  18. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  19. var VTreeviewNodeProps = exports.VTreeviewNodeProps = {
  20. activatable: Boolean,
  21. activeClass: {
  22. type: String,
  23. default: 'v-treeview-node--active'
  24. },
  25. selectable: Boolean,
  26. selectedColor: {
  27. type: String,
  28. default: 'accent'
  29. },
  30. indeterminateIcon: {
  31. type: String,
  32. default: '$vuetify.icons.checkboxIndeterminate'
  33. },
  34. onIcon: {
  35. type: String,
  36. default: '$vuetify.icons.checkboxOn'
  37. },
  38. offIcon: {
  39. type: String,
  40. default: '$vuetify.icons.checkboxOff'
  41. },
  42. expandIcon: {
  43. type: String,
  44. default: '$vuetify.icons.subgroup'
  45. },
  46. loadingIcon: {
  47. type: String,
  48. default: '$vuetify.icons.loading'
  49. },
  50. itemKey: {
  51. type: String,
  52. default: 'id'
  53. },
  54. itemText: {
  55. type: String,
  56. default: 'name'
  57. },
  58. itemChildren: {
  59. type: String,
  60. default: 'children'
  61. },
  62. loadChildren: Function,
  63. openOnClick: Boolean,
  64. transition: Boolean
  65. };
  66. exports.default = (0, _mixins2.default)((0, _registrable.inject)('treeview')
  67. /* @vue/component */
  68. ).extend({
  69. name: 'v-treeview-node',
  70. inject: {
  71. treeview: {
  72. default: null
  73. }
  74. },
  75. props: _extends({
  76. item: {
  77. type: Object,
  78. default: function _default() {
  79. return null;
  80. }
  81. }
  82. }, VTreeviewNodeProps),
  83. data: function data() {
  84. return {
  85. isOpen: false,
  86. isSelected: false,
  87. isIndeterminate: false,
  88. isActive: false,
  89. isLoading: false,
  90. hasLoaded: false
  91. };
  92. },
  93. computed: {
  94. key: function key() {
  95. return (0, _helpers.getObjectValueByPath)(this.item, this.itemKey);
  96. },
  97. children: function children() {
  98. return (0, _helpers.getObjectValueByPath)(this.item, this.itemChildren);
  99. },
  100. text: function text() {
  101. return (0, _helpers.getObjectValueByPath)(this.item, this.itemText);
  102. },
  103. scopedProps: function scopedProps() {
  104. return {
  105. item: this.item,
  106. leaf: !this.children,
  107. selected: this.isSelected,
  108. indeterminate: this.isIndeterminate,
  109. active: this.isActive,
  110. open: this.isOpen
  111. };
  112. },
  113. computedIcon: function computedIcon() {
  114. if (this.isIndeterminate) return this.indeterminateIcon;else if (this.isSelected) return this.onIcon;else return this.offIcon;
  115. },
  116. hasChildren: function hasChildren() {
  117. return !!this.children && (!!this.children.length || !!this.loadChildren);
  118. }
  119. },
  120. created: function created() {
  121. this.treeview.register(this);
  122. },
  123. beforeDestroy: function beforeDestroy() {
  124. this.treeview.unregister(this);
  125. },
  126. methods: {
  127. checkChildren: function checkChildren() {
  128. var _this = this;
  129. return new Promise(function (resolve) {
  130. // TODO: Potential issue with always trying
  131. // to load children if response is empty?
  132. if (!_this.children || _this.children.length || !_this.loadChildren || _this.hasLoaded) return resolve();
  133. _this.isLoading = true;
  134. resolve(_this.loadChildren(_this.item));
  135. }).then(function () {
  136. _this.isLoading = false;
  137. _this.hasLoaded = true;
  138. });
  139. },
  140. open: function open() {
  141. this.isOpen = !this.isOpen;
  142. this.treeview.updateOpen(this.key, this.isOpen);
  143. this.treeview.emitOpen();
  144. },
  145. genLabel: function genLabel() {
  146. var children = [];
  147. if (this.$scopedSlots.label) children.push(this.$scopedSlots.label(this.scopedProps));else children.push(this.text);
  148. return this.$createElement('div', {
  149. slot: 'label',
  150. staticClass: 'v-treeview-node__label'
  151. }, children);
  152. },
  153. genContent: function genContent() {
  154. var children = [this.$scopedSlots.prepend && this.$scopedSlots.prepend(this.scopedProps), this.genLabel(), this.$scopedSlots.append && this.$scopedSlots.append(this.scopedProps)];
  155. return this.$createElement('div', {
  156. staticClass: 'v-treeview-node__content'
  157. }, children);
  158. },
  159. genToggle: function genToggle() {
  160. var _this2 = this;
  161. return this.$createElement(_VIcon.VIcon, {
  162. staticClass: 'v-treeview-node__toggle',
  163. class: {
  164. 'v-treeview-node__toggle--open': this.isOpen,
  165. 'v-treeview-node__toggle--loading': this.isLoading
  166. },
  167. slot: 'prepend',
  168. on: {
  169. click: function click(e) {
  170. e.stopPropagation();
  171. if (_this2.isLoading) return;
  172. _this2.checkChildren().then(function () {
  173. return _this2.open();
  174. });
  175. }
  176. }
  177. }, [this.isLoading ? this.loadingIcon : this.expandIcon]);
  178. },
  179. genCheckbox: function genCheckbox() {
  180. var _this3 = this;
  181. return this.$createElement(_VIcon.VIcon, {
  182. staticClass: 'v-treeview-node__checkbox',
  183. props: {
  184. color: this.isSelected ? this.selectedColor : undefined
  185. },
  186. on: {
  187. click: function click(e) {
  188. e.stopPropagation();
  189. if (_this3.isLoading) return;
  190. _this3.checkChildren().then(function () {
  191. // We nextTick here so that items watch in VTreeview has a chance to run first
  192. _this3.$nextTick(function () {
  193. _this3.isSelected = !_this3.isSelected;
  194. _this3.isIndeterminate = false;
  195. _this3.treeview.updateSelected(_this3.key, _this3.isSelected);
  196. _this3.treeview.emitSelected();
  197. });
  198. });
  199. }
  200. }
  201. }, [this.computedIcon]);
  202. },
  203. genNode: function genNode() {
  204. var _this4 = this;
  205. var children = [this.genContent()];
  206. if (this.selectable) children.unshift(this.genCheckbox());
  207. if (this.hasChildren) children.unshift(this.genToggle());
  208. return this.$createElement('div', {
  209. staticClass: 'v-treeview-node__root',
  210. class: _defineProperty({}, this.activeClass, this.isActive),
  211. on: {
  212. click: function click() {
  213. if (_this4.openOnClick && _this4.children) {
  214. _this4.open();
  215. } else if (_this4.activatable) {
  216. _this4.isActive = !_this4.isActive;
  217. _this4.treeview.updateActive(_this4.key, _this4.isActive);
  218. _this4.treeview.emitActive();
  219. }
  220. }
  221. }
  222. }, children);
  223. },
  224. genChild: function genChild(item) {
  225. return this.$createElement(_VTreeviewNode2.default, {
  226. key: (0, _helpers.getObjectValueByPath)(item, this.itemKey),
  227. props: {
  228. activatable: this.activatable,
  229. activeClass: this.activeClass,
  230. item: item,
  231. selectable: this.selectable,
  232. selectedColor: this.selectedColor,
  233. expandIcon: this.expandIcon,
  234. indeterminateIcon: this.indeterminateIcon,
  235. offIcon: this.offIcon,
  236. onIcon: this.onIcon,
  237. loadingIcon: this.loadingIcon,
  238. itemKey: this.itemKey,
  239. itemText: this.itemText,
  240. itemChildren: this.itemChildren,
  241. loadChildren: this.loadChildren,
  242. transition: this.transition,
  243. openOnClick: this.openOnClick
  244. },
  245. scopedSlots: this.$scopedSlots
  246. });
  247. },
  248. genChildrenWrapper: function genChildrenWrapper() {
  249. if (!this.isOpen || !this.children) return null;
  250. var children = [this.children.map(this.genChild)];
  251. return this.$createElement('div', {
  252. staticClass: 'v-treeview-node__children'
  253. }, children);
  254. },
  255. genTransition: function genTransition() {
  256. return this.$createElement(_transitions.VExpandTransition, [this.genChildrenWrapper()]);
  257. }
  258. },
  259. render: function render(h) {
  260. var children = [this.genNode()];
  261. if (this.transition) children.push(this.genTransition());else children.push(this.genChildrenWrapper());
  262. return h('div', {
  263. staticClass: 'v-treeview-node',
  264. class: {
  265. 'v-treeview-node--leaf': !this.hasChildren,
  266. 'v-treeview-node--click': this.openOnClick,
  267. 'v-treeview-node--selected': this.isSelected,
  268. 'v-treeview-node--excluded': this.treeview.isExcluded(this.key)
  269. }
  270. }, children);
  271. }
  272. });
  273. //# sourceMappingURL=VTreeviewNode.js.map