84 lines
2.2 KiB
JavaScript
84 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
angular.module('warehost')
|
|
.filter('afterKeyID',function(){
|
|
return function(collection,list,key){
|
|
var output = [],
|
|
keys = [];
|
|
angular.forEach(list, function(item) {
|
|
if(item[key] !== undefined){
|
|
keys.push(item[key].ID);
|
|
}
|
|
});
|
|
angular.forEach(collection, function(item) {
|
|
if(keys.indexOf(item.ID)){
|
|
output.push(item);
|
|
}
|
|
});
|
|
return output;
|
|
};
|
|
})
|
|
.controller('WebDomainHostCtrl',function(session,config,alert,NgTableParams,$rootScope,$scope,$http,$stateParams){
|
|
$scope.tableParams = new NgTableParams({
|
|
sorting: { 'subdomain': 'asc' },
|
|
total: 0,
|
|
count: config.table.count
|
|
}, { dataset: [] });
|
|
alert.set({});
|
|
$scope.obj = {};
|
|
$scope.domain = {};
|
|
$scope.loginlist = [];
|
|
|
|
function resetObj(){
|
|
$scope.obj = {};
|
|
}
|
|
function load(){
|
|
$http.get(config.api+'/user').then(function(res){
|
|
$scope.loginlist = res.data.data;
|
|
$http.get(config.api+'/host/domain/'+$stateParams.domainid).then(function(res){
|
|
$scope.domain = res.data.data;
|
|
$http.get(config.api+'/host/domain/'+$stateParams.domainid+'/web').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){
|
|
resetObj();
|
|
$scope.isAdding = false;
|
|
load();
|
|
}
|
|
}
|
|
resetObj();
|
|
load();
|
|
$rootScope.$on('warehost.session',load);
|
|
|
|
$scope.edit = function(a){
|
|
$http.patch(config.api+'/host/domain/'+$stateParams.domainid+'/web/'+a.ID,a).then(submitresult);
|
|
};
|
|
$scope.delete = function(a){
|
|
$http.delete(config.api+'/host/domain/'+$stateParams.domainid+'/web/'+a.ID).then(submitresult);
|
|
};
|
|
$scope.add = function(){
|
|
$http.post(config.api+'/host/domain/'+$stateParams.domainid+'/web',$scope.obj).then(submitresult);
|
|
};
|
|
$scope.newUser = function(list, $model){
|
|
var ids= [];
|
|
list.forEach(function(item, i) {
|
|
if(item.login === undefined){
|
|
list[i] = {login: $model};
|
|
}
|
|
if(ids.indexOf(list[i].login.ID) < 0){
|
|
ids.push(list[i].login.ID);
|
|
}else{
|
|
list.splice(i);
|
|
}
|
|
});
|
|
};
|
|
|
|
});
|