delivery-options.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  3. */
  4. define([
  5. 'ko',
  6. 'Temando_Shipping/js/model/collection-points',
  7. 'Temando_Shipping/js/model/pickup-locations'
  8. ], function (ko, collectionPoints, pickupLocations) {
  9. 'use strict';
  10. var userValue = ko.observable('');
  11. var selected = ko.pureComputed({
  12. read: function() {
  13. if (userValue() === '') {
  14. if (collectionPoints.getSearchRequest()) {
  15. return 'toCollectionPoint';
  16. }
  17. if (pickupLocations.getSearchRequest()) {
  18. return 'clickAndCollect';
  19. }
  20. return 'toAddress';
  21. } else {
  22. return userValue();
  23. }
  24. },
  25. write: function(value) {
  26. userValue(value);
  27. }
  28. });
  29. var collectionPointSelected = ko.computed(function () {
  30. return (selected() === 'toCollectionPoint');
  31. });
  32. var toAddressSelected = ko.computed(function () {
  33. return (selected() === 'toAddress');
  34. });
  35. var clickAndCollectSelected = ko.computed(function () {
  36. return (selected() === 'clickAndCollect');
  37. });
  38. return {
  39. selected: selected,
  40. isCollectionPointSelected: collectionPointSelected,
  41. isToAddressSelected: toAddressSelected
  42. };
  43. });