|
75 | 75 | console.info('init success result:', result); |
76 | 76 | ContentHome.data = result; |
77 | 77 | if (!ContentHome.data) |
78 | | - ContentHome.data = angular.copy(_data); |
| 78 | + ContentHome.data = angular.copy(_data); |
79 | 79 |
|
80 | 80 | //make sure to assign to the right appId |
81 | 81 | ContentHome.data.appId = _data.appId; |
|
84 | 84 | if (tmrDelay) clearTimeout(tmrDelay); |
85 | 85 |
|
86 | 86 | buildfire.datastore.get(TAG_NAMES.LOYALTY_INFO,function(err,data){ |
87 | | - ContentHome.settings = data.data.settings; |
88 | | - if (!ContentHome.settings || !ContentHome.settings.redemptionPasscode){ |
89 | | - ContentHome.showRedemptionPasscodeHint = true; |
90 | | - } else { |
91 | | - ContentHome.showRedemptionPasscodeHint = false; |
92 | | - } |
93 | | - if (!$scope.$$phase) $scope.$digest(); |
94 | | - updateMasterItem(ContentHome.data); |
95 | | - if(Number(ContentHome.data.pointsPerDollar) <= 0) { |
96 | | - ContentHome.data.pointsPerDollar = 1; |
| 87 | + ContentHome.settings = data.data.settings; |
| 88 | + if (!ContentHome.settings || !ContentHome.settings.redemptionPasscode){ |
| 89 | + ContentHome.showRedemptionPasscodeHint = true; |
| 90 | + } else { |
| 91 | + ContentHome.showRedemptionPasscodeHint = false; |
| 92 | + } |
| 93 | + ContentHome.initializeSettings(); |
| 94 | + if (!$scope.$$phase) $scope.$digest(); |
| 95 | + updateMasterItem(ContentHome.data); |
| 96 | + if(Number(ContentHome.data.pointsPerDollar) <= 0) { |
| 97 | + ContentHome.data.pointsPerDollar = 1; |
97 | 98 | saveData(JSON.parse(angular.toJson(ContentHome.data))); |
98 | | - } |
| 99 | + } |
99 | 100 | }); |
100 | 101 | }; |
101 | 102 | ContentHome.error = function (err) { |
102 | | - ContentHome.showRedemptionPasscodeHint = true; |
| 103 | + ContentHome.showRedemptionPasscodeHint = true; |
103 | 104 | if (err && err.code == 2100) { |
104 | 105 | console.error('Error while getting application:', err); |
105 | 106 | var success = function (result) { |
|
110 | 111 | type: 'AppCreated' |
111 | 112 | }); |
112 | 113 | } |
113 | | - , error = function (err) { |
| 114 | + , error = function (err) { |
114 | 115 | console.log('Error while saving data : ', err); |
115 | 116 | if(err && err.code == 2000) { |
116 | | - ContentHome.data = angular.copy(_data); |
117 | | - buildfire.messaging.sendMessageToWidget({ |
118 | | - type: 'AppCreated' |
119 | | - }); |
| 117 | + ContentHome.data = angular.copy(_data); |
| 118 | + buildfire.messaging.sendMessageToWidget({ |
| 119 | + type: 'AppCreated' |
| 120 | + }); |
120 | 121 | } |
121 | 122 | }; |
122 | 123 | if (ContentHome.currentLoggedInUser) { |
123 | 124 | _data.userToken = ContentHome.currentLoggedInUser.userToken; |
124 | 125 | _data.auth = ContentHome.currentLoggedInUser.auth; |
125 | 126 | LoyaltyAPI.addEditApplication(_data).then(success, error); |
126 | 127 | } else { |
127 | | - buildfire.dialog.toast({ |
128 | | - message: "Please make sure you are logged In", |
129 | | - type: "danger", |
130 | | - }); |
| 128 | + buildfire.dialog.toast({ |
| 129 | + message: "Please make sure you are logged In", |
| 130 | + type: "danger", |
| 131 | + }); |
131 | 132 | } |
132 | 133 | } |
133 | 134 | }; |
134 | 135 | ContentHome.successloyaltyRewards = function (result) { |
135 | 136 | ContentHome.loyaltyRewards = result; |
136 | 137 | if (!ContentHome.loyaltyRewards) { |
137 | | - ContentHome.loyaltyRewards = []; |
138 | | - $rootScope.showEmptyState = true; |
| 138 | + ContentHome.loyaltyRewards = []; |
| 139 | + $rootScope.showEmptyState = true; |
139 | 140 | } else { |
140 | | - $rootScope.showEmptyState = false; |
| 141 | + $rootScope.showEmptyState = false; |
141 | 142 | } |
142 | 143 | ContentHome.loyaltyRewardsCloned = ContentHome.loyaltyRewards |
143 | 144 | ContentHome.addDeepLinks(result); |
|
154 | 155 | ContentHome.loyaltyRewards = []; |
155 | 156 | LoyaltyAPI.getApplication(`${context.appId}_${context.instanceId}`).then(ContentHome.success, ContentHome.error); |
156 | 157 | buildfire.auth.getCurrentUser(function (err, user) { |
157 | | - console.log("!!!!!!!!!!User!!!!!!!!!!!!", user); |
158 | 158 | if (user && user._cpUser) { |
159 | 159 | ContentHome.currentLoggedInUser = user._cpUser; |
160 | 160 | if (!$scope.$$phase) $scope.$digest(); |
|
163 | 163 | }); |
164 | 164 | }; |
165 | 165 |
|
| 166 | + ContentHome.initializeSettings = function() { |
| 167 | + if (!ContentHome.settings || Object.keys(ContentHome.settings).length === 0) { |
| 168 | + ContentHome.settings = { |
| 169 | + purchaseOption: { |
| 170 | + name: "Per Money Spent", |
| 171 | + value: "perMoneySpent" |
| 172 | + } |
| 173 | + }; |
| 174 | + buildfire.datastore.save({settings: ContentHome.settings}, TAG_NAMES.LOYALTY_INFO, function (err, data) { |
| 175 | + if (err) { |
| 176 | + console.error('Error while saving data:', err); |
| 177 | + } |
| 178 | + else { |
| 179 | + Buildfire.analytics.registerEvent( |
| 180 | + { title: "Reward redeemed", key: 'reward-redeemed', description: "User has redeemed a reward" }, |
| 181 | + { silentNotification: true } |
| 182 | + ); |
| 183 | + Buildfire.analytics.registerEvent( |
| 184 | + { title: "Points earned", key: 'points-earned', description: "User has earned points" }, |
| 185 | + { silentNotification: true } |
| 186 | + ); |
| 187 | + } |
| 188 | + }); |
| 189 | + |
| 190 | + } |
| 191 | + }; |
| 192 | + |
166 | 193 | ContentHome.search = function() { |
167 | 194 | if(ContentHome.title != ""){ |
168 | 195 | ContentHome.loyaltyRewards = ContentHome.loyaltyRewardsCloned.filter(x=>x.title.includes(ContentHome.title)) |
|
0 commit comments