'use strict'; angular.module('warehost') .controller('InvitesCtrl',function(session,config,alert,NgTableParams,$scope,$http){ $scope.tableParams = new NgTableParams({ sorting: { 'invited.username': 'asc' }, total: 0, count: config.table.count }, { dataset: [] }); alert.set({}); $scope.list = {}; $scope.obj = {}; $scope.invitor = {}; 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}); }); $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; } } resetObj(); load(); $scope.edit = function(a){ a.invited.password = a.newPassword; $http.put(config.api+'/invite/'+a.invited.ID,a.invited).then(submitresult); }; $scope.delete = function(a){ $http.delete(config.api+'/invite/'+a.invited.ID).then(submitresult); }; $scope.add = function(){ $http.post(config.api+'/invite',$scope.obj).then(submitresult); }; $scope.toggleAdmin = function(){ $http.put(config.api+'/invitor').then(submitresult); }; });