123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /**
- * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
- */
- define([
- 'ko',
- 'Temando_Shipping/js/model/collection-points',
- 'Temando_Shipping/js/model/pickup-locations'
- ], function (ko, collectionPoints, pickupLocations) {
- 'use strict';
- var userValue = ko.observable('');
- var selected = ko.pureComputed({
- read: function() {
- if (userValue() === '') {
- if (collectionPoints.getSearchRequest()) {
- return 'toCollectionPoint';
- }
- if (pickupLocations.getSearchRequest()) {
- return 'clickAndCollect';
- }
- return 'toAddress';
- } else {
- return userValue();
- }
- },
- write: function(value) {
- userValue(value);
- }
- });
- var collectionPointSelected = ko.computed(function () {
- return (selected() === 'toCollectionPoint');
- });
- var toAddressSelected = ko.computed(function () {
- return (selected() === 'toAddress');
- });
- var clickAndCollectSelected = ko.computed(function () {
- return (selected() === 'clickAndCollect');
- });
- return {
- selected: selected,
- isCollectionPointSelected: collectionPointSelected,
- isToAddressSelected: toAddressSelected
- };
- });
|