feat(invitations): exchange an invitation with scores, the invitation can invite friend join us.

This commit is contained in:
OldHawk
2017-06-13 17:28:54 +08:00
parent 5090769c29
commit ddb9b05756
8 changed files with 93 additions and 16 deletions

View File

@@ -5,13 +5,14 @@
.module('users')
.controller('ScoreController', ScoreController);
ScoreController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', '$window', 'ScoreLevelService', 'getStorageLangService',
'MeanTorrentConfig'];
ScoreController.$inject = ['$rootScope', '$scope', '$state', '$translate', '$timeout', 'Authentication', '$window', 'ScoreLevelService', 'getStorageLangService',
'MeanTorrentConfig', 'ModalConfirmService', 'NotifycationService', 'InvitationsService'];
function ScoreController($scope, $state, $translate, $timeout, Authentication, $window, ScoreLevelService, getStorageLangService, MeanTorrentConfig) {
function ScoreController($rootScope, $scope, $state, $translate, $timeout, Authentication, $window, ScoreLevelService, getStorageLangService, MeanTorrentConfig,
ModalConfirmService, NotifycationService, InvitationsService) {
var vm = this;
vm.scoreConfig = MeanTorrentConfig.meanTorrentConfig.score;
vm.inviteConfig = MeanTorrentConfig.meanTorrentConfig.invite;
vm.lang = getStorageLangService.getLang();
vm.user = Authentication.user;
@@ -22,11 +23,51 @@
$state.go('authentication.signin');
}
$scope.$on('auth-user-score-changed', function(event, args) {
vm.user = Authentication.user;
vm.scoreLevelData = vm.user ? ScoreLevelService.getScoreLevelJson(vm.user.score) : undefined;
});
/**
* init
*/
vm.init = function () {
vm.scoreLevelData = ScoreLevelService.getScoreLevelJson(vm.user.score);
};
/**
* exchangeInvitation
*/
vm.exchangeInvitation = function () {
var modalOptions = {
closeButtonText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_CANCEL'),
actionButtonText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_OK'),
headerText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_HEADER_TEXT'),
bodyText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_BODY_TEXT', {score: vm.inviteConfig.score_exchange})
};
ModalConfirmService.showModal({}, modalOptions)
.then(function (result) {
var invitation = new InvitationsService();
invitation.$save(function (response) {
successCallback(response);
}, function (errorResponse) {
errorCallback(errorResponse);
});
function successCallback(res) {
if (res._id === vm.user._id) {
vm.user = Authentication.user = res;
$rootScope.$broadcast('auth-user-score-changed');
}
NotifycationService.showSuccessNotify('EXCHANGE_INVITATION_SUCCESSFULLY');
}
function errorCallback(res) {
NotifycationService.showErrorNotify(res.data.message, 'EXCHANGE_INVITATION_ERROR');
}
});
};
}
}());

View File

@@ -23,6 +23,15 @@
</div>
</div>
<div class="row margin-top-30">
<div class="col-sm-8 col-sm-offset-2 text-center">
<button class="btn btn-default" ng-disabled="vm.user.score < vm.inviteConfig.score_exchange"
translate="EXCHANGE_INVITATION" translate-values='{ score: vm.inviteConfig.score_exchange}'
ng-click="vm.exchangeInvitation();">
</button>
</div>
</div>
<div class="row margin-top-30 padding-top-30">
<div class="col-sm-8 col-sm-offset-2">
<legend class="small-legend" translate="SCORE.HOW_TO_GET_LEVEL"></legend>