Skip to content

Commit

Permalink
Merge pull request #37 from sakshityagi/master
Browse files Browse the repository at this point in the history
Disabled done button until item not saved on CP, #129155733
  • Loading branch information
DanielHindi authored Aug 26, 2016
2 parents f326996 + 09d2df2 commit 462d5ad
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
10 changes: 8 additions & 2 deletions control/content/controllers/content.reward.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
};
ContentReward.isInserted = false;
ContentReward.masterData = null;
ContentReward.itemSaved = false;
updateMasterItem(ContentReward.item);
ContentReward.bodyWYSIWYGOptions = {
plugins: 'advlist autolink link image lists charmap print preview',
Expand Down Expand Up @@ -129,11 +130,12 @@
var data = newObj;
data.appId = context.appId;
data.loyaltyUnqiueId = context.instanceId;
data.userToken = ContentReward.currentLoggedInUser.userToken;
data.auth = ContentReward.currentLoggedInUser.auth;
data.userToken = ContentReward.currentLoggedInUser && ContentReward.currentLoggedInUser.userToken;
data.auth = ContentReward.currentLoggedInUser && ContentReward.currentLoggedInUser.auth;
var success = function (result) {
console.info('Saved data result: ', result);
updateMasterItem(newObj);
ContentReward.itemSaved = true;
ContentReward.item.deepLinkUrl = Buildfire.deeplink.createLink({id: result._id});
ContentReward.item = Object.assign(ContentReward.item, result);
ContentReward.isInserted = true;
Expand All @@ -148,6 +150,7 @@
}
, error = function (err) {
ContentReward.isInserted = false;
ContentReward.itemSaved = true;
console.error('Error while saving data : ', err);
};
LoyaltyAPI.addReward(data).then(success, error);
Expand All @@ -173,9 +176,11 @@
$scope.$digest();
var success = function (result) {
console.info('Saved data result: ', result);
ContentReward.itemSaved = true;
}
, error = function (err) {
console.error('Error while saving data : ', err);
ContentReward.itemSaved = true;
};
LoyaltyAPI.updateReward(data).then(success, error);
};
Expand Down Expand Up @@ -229,6 +234,7 @@
if (isUnchanged(newObj)) {
return;
}
ContentReward.itemSaved = false;
if (tmrDelay) {
clearTimeout(tmrDelay);
}
Expand Down
2 changes: 1 addition & 1 deletion control/content/templates/reward.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<div class="main col-md-9 pull-right">
<div class="col-md-6 pull-right padding-right-zero padding-left-ten">
<button class="btn btn-primary pull-right stretch"
ng-click="ContentReward.gotToHome()">
ng-click="ContentReward.gotToHome()" ng-disabled="!ContentReward.itemSaved">
Done
</button>
</div>
Expand Down
3 changes: 3 additions & 0 deletions test/widget/widget.home.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ describe('Unit : loyaltyPluginWidget Plugin widget.home.controller.js', function
var points = 5, callback = function(e, data){
}
WidgetHome.loyaltyRewards = [1,2,3];
WidgetHome.context = {
instanceId : 'abcde1234'
};
$rootScope.$broadcast('REWARD_ADDED', callback);
});
it('should invoke GOTO_HOME when point have some values', function () {
Expand Down
22 changes: 18 additions & 4 deletions widget/controllers/widget.home.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,17 @@
* This event listener is bound for "REWARD_ADDED" event broadcast
*/
WidgetHome.listeners['REWARD_ADDED'] = $rootScope.$on('REWARD_ADDED', function (e, item) {
WidgetHome.loyaltyRewards.unshift(item);
var successLoyaltyRewards = function (result) {
WidgetHome.loyaltyRewards = result;
if (!WidgetHome.loyaltyRewards)
WidgetHome.loyaltyRewards = [];
}
, errorLoyaltyRewards = function (err) {
if (err && err.code !== STATUS_CODE.NOT_FOUND) {
console.error('Error while getting data loyaltyRewards--------------------------------------', err);
}
};
LoyaltyAPI.getRewards(WidgetHome.context.instanceId).then(successLoyaltyRewards, errorLoyaltyRewards);
});

/**
Expand Down Expand Up @@ -368,9 +378,13 @@
});

WidgetHome.listeners['REWARD_UPDATED'] = $rootScope.$on('REWARD_UPDATED', function (e, item, index) {
if (index == 0 || index) {
WidgetHome.loyaltyRewards[index] = item;
if($scope.$$phase) $scope.$digest();
if (item && WidgetHome.loyaltyRewards && WidgetHome.loyaltyRewards.length) {
WidgetHome.loyaltyRewards.some(function (reward, index) {
if (reward._id == item._id) {
WidgetHome.loyaltyRewards[index] = item;
return true;
}
})
}
});

Expand Down

0 comments on commit 462d5ad

Please sign in to comment.