sum7/warehost-frontend
sum7
/
warehost-frontend
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost-frontend/public/app/user.js

46 lines
1.1 KiB
JavaScript

'use strict';
angular.module('warehost')
.controller('UserCtrl',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.obj = {};
$scope.invitor = {};
function resetObj(){
$scope.obj = {};
}
function load(){
$http.get(config.api+'/user').then(function(res){
session.set(res);
$scope.tableParams.settings({dataset: angular.copy(res.data.data),total: (res.data.data).length});
});
}
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.password = a.newPassword;
$http.put(config.api+'/user/'+a.ID,a).then(submitresult);
};
$scope.delete = function(a){
$http.delete(config.api+'/user/'+a.ID).then(submitresult);
};
$scope.add = function(){
$http.post(config.api+'/user',$scope.obj).then(submitresult);
};
});