2016-08-20 01:17:28 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('warehost')
|
2016-10-17 23:43:14 +02:00
|
|
|
.controller('InviteCtrl',function(session,config,alert,NgTableParams,$scope,$rootScope,$http){
|
2016-08-20 01:17:28 +02:00
|
|
|
$scope.tableParams = new NgTableParams({
|
|
|
|
sorting: { 'invited.username': 'asc' },
|
|
|
|
total: 0,
|
|
|
|
count: config.table.count
|
|
|
|
}, { dataset: [] });
|
|
|
|
alert.set({});
|
2016-08-24 23:11:57 +02:00
|
|
|
$scope.obj = {};
|
2016-08-27 02:13:16 +02:00
|
|
|
$scope.invitor = {};
|
2016-08-24 23:11:57 +02:00
|
|
|
|
2016-08-23 22:57:35 +02:00
|
|
|
function resetObj(){
|
|
|
|
$scope.obj = {};
|
|
|
|
var username = session.get().login.username;
|
|
|
|
if(username.indexOf('@')<0){
|
|
|
|
$scope.obj.username = username+'@';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function load(){
|
|
|
|
$http.get(config.api+'/invite').then(function(res){
|
|
|
|
session.set(res);
|
|
|
|
$scope.tableParams.settings({dataset: angular.copy(res.data.data),total: (res.data.data).length});
|
|
|
|
});
|
2016-08-24 23:11:57 +02:00
|
|
|
$http.get(config.api+'/invitor').then(function(res){
|
|
|
|
session.set(res);
|
|
|
|
$scope.invitor = res.data.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function submitresult(res){
|
|
|
|
session.set(res);
|
|
|
|
alert.set(res);
|
|
|
|
if(res.data.data){
|
|
|
|
load();
|
|
|
|
resetObj();
|
|
|
|
$scope.isAdding = false;
|
|
|
|
}
|
2016-08-23 22:57:35 +02:00
|
|
|
}
|
|
|
|
resetObj();
|
|
|
|
load();
|
2016-10-17 23:43:14 +02:00
|
|
|
$rootScope.$on('warehost.session',load);
|
2016-08-23 22:57:35 +02:00
|
|
|
|
2016-08-24 23:11:57 +02:00
|
|
|
$scope.edit = function(a){
|
|
|
|
a.invited.password = a.newPassword;
|
2016-10-17 23:43:14 +02:00
|
|
|
$http.patch(config.api+'/user/'+a.invited.ID,a.invited).then(submitresult);
|
2016-08-24 23:11:57 +02:00
|
|
|
};
|
|
|
|
$scope.delete = function(a){
|
2016-09-11 18:40:03 +02:00
|
|
|
$http.delete(config.api+'/user/'+a.invited.ID).then(submitresult);
|
2016-08-23 22:57:35 +02:00
|
|
|
};
|
|
|
|
$scope.add = function(){
|
2016-08-24 23:11:57 +02:00
|
|
|
$http.post(config.api+'/invite',$scope.obj).then(submitresult);
|
|
|
|
};
|
2016-08-27 02:13:16 +02:00
|
|
|
$scope.toggleAdmin = function(){
|
2016-10-17 23:43:14 +02:00
|
|
|
$http.patch(config.api+'/invitor').then(submitresult);
|
2016-08-23 22:57:35 +02:00
|
|
|
};
|
2016-08-20 01:17:28 +02:00
|
|
|
});
|