default-address.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'Magento_Ui/js/form/components/button',
  7. 'underscore'
  8. ], function (Button, _) {
  9. 'use strict';
  10. return Button.extend({
  11. defaults: {
  12. entityId: null,
  13. parentId: null,
  14. listens: {
  15. entity: 'changeVisibility'
  16. }
  17. },
  18. /**
  19. * Apply action on target component,
  20. * but previously create this component from template if it is not existed
  21. *
  22. * @param {Object} action - action configuration
  23. */
  24. applyAction: function (action) {
  25. if (action.params && action.params[0]) {
  26. action.params[0]['entity_id'] = this.entityId;
  27. action.params[0]['parent_id'] = this.parentId;
  28. } else {
  29. action.params = [{
  30. 'entity_id': this.entityId,
  31. 'parent_id': this.parentId
  32. }];
  33. }
  34. this._super();
  35. },
  36. /**
  37. * Change visibility of the default address shipping/billing blocks
  38. *
  39. * @param {Object} entity - customer address
  40. */
  41. changeVisibility: function (entity) {
  42. this.visible(!_.isEmpty(entity));
  43. }
  44. });
  45. });