2017-06-14 12:59:14 +08:00
|
|
|
(function () {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular
|
|
|
|
|
.module('invitations')
|
|
|
|
|
.controller('InviteController', InviteController);
|
|
|
|
|
|
2017-06-14 17:28:40 +08:00
|
|
|
InviteController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', '$window', 'MeanTorrentConfig', 'NotifycationService',
|
2017-10-20 13:07:31 +08:00
|
|
|
'InvitationsService', '$rootScope', 'moment'];
|
2017-06-14 12:59:14 +08:00
|
|
|
|
2017-06-14 17:28:40 +08:00
|
|
|
function InviteController($scope, $state, $translate, $timeout, Authentication, $window, MeanTorrentConfig, NotifycationService,
|
2017-10-20 13:07:31 +08:00
|
|
|
InvitationsService, $rootScope, moment) {
|
2017-06-14 12:59:14 +08:00
|
|
|
var vm = this;
|
|
|
|
|
vm.inviteConfig = MeanTorrentConfig.meanTorrentConfig.invite;
|
|
|
|
|
vm.user = Authentication.user;
|
2017-08-14 12:46:55 +08:00
|
|
|
vm.announce = MeanTorrentConfig.meanTorrentConfig.announce;
|
2017-06-14 12:59:14 +08:00
|
|
|
|
2017-06-15 14:07:24 +08:00
|
|
|
vm.invitePopover = {
|
|
|
|
|
title: 'INVITATION.TITLE_SEND',
|
|
|
|
|
templateUrl: 'invite.html',
|
|
|
|
|
items: [],
|
|
|
|
|
sending: false
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-15 17:41:18 +08:00
|
|
|
vm.subuserPopover = {
|
|
|
|
|
templateUrl: 'userinfo.html'
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-16 10:04:52 +08:00
|
|
|
/**
|
|
|
|
|
* user-invitations-changed
|
|
|
|
|
*/
|
|
|
|
|
$scope.$on('user-invitations-changed', function (event, args) {
|
|
|
|
|
vm.getMyInvitations();
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-14 12:59:14 +08:00
|
|
|
/**
|
2017-06-14 17:28:40 +08:00
|
|
|
* getMyInvitations
|
2017-06-14 12:59:14 +08:00
|
|
|
*/
|
2017-06-14 17:28:40 +08:00
|
|
|
vm.getMyInvitations = function () {
|
|
|
|
|
InvitationsService.get({}, function (items) {
|
|
|
|
|
vm.my_invitations = items.my_invitations;
|
|
|
|
|
vm.used_invitations = items.used_invitations;
|
2017-06-15 14:07:24 +08:00
|
|
|
|
|
|
|
|
angular.forEach(vm.my_invitations, function (i) {
|
|
|
|
|
vm.invitePopover.items.push({isOpen: false});
|
|
|
|
|
});
|
2017-06-14 17:28:40 +08:00
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showErrorNotify('GET_INVITATIONS_ERROR');
|
|
|
|
|
});
|
2017-06-14 12:59:14 +08:00
|
|
|
};
|
2017-06-15 14:07:24 +08:00
|
|
|
|
2017-07-04 16:07:30 +08:00
|
|
|
/**
|
|
|
|
|
* sendClicked
|
|
|
|
|
* @param idx
|
|
|
|
|
*/
|
2017-06-15 14:07:24 +08:00
|
|
|
vm.sendClicked = function (idx) {
|
|
|
|
|
vm.invitePopover.email = undefined;
|
|
|
|
|
vm.invitePopover.items[idx].isOpen = true;
|
|
|
|
|
vm.invitePopover.selected = idx;
|
2017-06-15 16:18:07 +08:00
|
|
|
vm.invitePopover.sending = false;
|
2017-06-15 14:07:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* invite
|
|
|
|
|
* @param inx
|
|
|
|
|
*/
|
|
|
|
|
vm.invite = function (idx) {
|
|
|
|
|
if (vm.invitePopover.email) {
|
|
|
|
|
vm.invitePopover.sending = true;
|
|
|
|
|
var invitation = new InvitationsService(vm.my_invitations[idx]);
|
|
|
|
|
invitation.$update({
|
|
|
|
|
to_email: vm.invitePopover.email
|
|
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showSuccessNotify('SEND_INVITE_SUCCESSFULLY');
|
|
|
|
|
vm.invitePopover.items[idx].isOpen = false;
|
|
|
|
|
vm.invitePopover.sending = false;
|
2017-06-16 10:04:52 +08:00
|
|
|
$rootScope.$broadcast('user-invitations-changed');
|
2017-06-15 14:07:24 +08:00
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'SEND_INVITE_ERROR');
|
|
|
|
|
vm.invitePopover.sending = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-06-16 10:23:00 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getInvitationStatus
|
|
|
|
|
* @param invitation
|
|
|
|
|
*/
|
|
|
|
|
vm.getInvitationStatus = function (invitation) {
|
2017-06-16 17:15:38 +08:00
|
|
|
if (invitation.status === 2) {
|
2017-06-16 10:23:00 +08:00
|
|
|
return $translate.instant('INVITATION.TITLE_STATUS_REGED');
|
2017-06-16 17:15:38 +08:00
|
|
|
} else {
|
2017-10-20 13:07:31 +08:00
|
|
|
if (moment(invitation.expiresat) > moment(Date.now())) {
|
2017-06-16 10:23:00 +08:00
|
|
|
return $translate.instant('INVITATION.TITLE_STATUS_UNREGED');
|
2017-06-16 17:15:38 +08:00
|
|
|
} else {
|
2017-06-16 10:23:00 +08:00
|
|
|
return $translate.instant('INVITATION.TITLE_STATUS_EXPIRED');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-06-14 12:59:14 +08:00
|
|
|
}
|
|
|
|
|
}());
|