Source: ui/DataTypeMenuWrapper.js

  1. const ContainerWrapper = require('./ContainerWrapper.js').ContainerWrapper;
  2. /**
  3. * This is a class to wrap anchor element with data-type menu
  4. */
  5. class DataTypeMenuWrapper extends ContainerWrapper {
  6. /**
  7. * The constructor
  8. * @param {View} view - The view class
  9. * @param {DocumentFragment} root - This view html fragment
  10. * @param {string} parentClass - Class name from parent element
  11. * @param {ElementFactory} factory - The factory for creating elements
  12. */
  13. constructor(view, root, parentClass, factory) {
  14. super(view, root, parentClass);
  15. root.querySelectorAll('a[data-type=menu]').forEach(element => {
  16. let elementWrapper = factory.make(view, element, this._class);
  17. this._elements.push(elementWrapper);
  18. });
  19. }
  20. /**
  21. * Populate the elements
  22. * @param {string} sender - The name of the sender
  23. * @param {Object} root - An object with method getByUid which returns and object
  24. */
  25. populate(sender, root) {
  26. if (root.getByUid == null) {
  27. return;
  28. }
  29. this._elements.each(elem => {
  30. let data = root.getByUid(elem.uid);
  31. elem.populate(sender, data);
  32. });
  33. }
  34. }
  35. exports.DataTypeMenuWrapper = DataTypeMenuWrapper;