2016-10-22 21:34:20 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('warehost')
|
2016-11-17 23:16:35 +01:00
|
|
|
.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;
|
|
|
|
};
|
|
|
|
})
|
2016-10-22 21:34:20 +02:00
|
|
|
.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 = {};
|
2016-11-17 23:16:35 +01:00
|
|
|
$scope.loginlist = [];
|
2016-10-22 21:34:20 +02:00
|
|
|
|
|
|
|
function resetObj(){
|
|
|
|
$scope.obj = {};
|
|
|
|
}
|
|
|
|
function load(){
|
2016-11-17 23:16:35 +01:00
|
|
|
$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});
|
|
|
|
});
|
2016-10-22 21:34:20 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
};
|
2016-11-17 23:16:35 +01:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2016-10-22 21:34:20 +02:00
|
|
|
|
|
|
|
});
|