update for creation of policy and destinations.

This commit is contained in:
kunw 2016-06-17 18:07:33 +08:00
parent 3b2b0d8849
commit 7ae5b39407
2 changed files with 40 additions and 27 deletions

View File

@ -23,16 +23,19 @@
vm.selectDestination = selectDestination;
vm.projectId = getParameterByName('project_id', $location.absUrl());
$scope.$on('$locationChangeSuccess', function() {
vm.projectId = getParameterByName('project_id', $location.absUrl());
});
vm.addNew = addNew;
vm.edit = edit;
vm.prepareDestination = prepareDestination;
vm.createPolicy = createPolicy;
vm.updatePolicy = updatePolicy;
vm.create = create;
vm.update = update;
vm.pingDestination = pingDestination;
$scope.$watch('vm.destinations', function(current) {
if(current) {
console.log('destination:' + angular.toJson(current));
vm1.selection = current[0];
vm1.endpoint = vm1.selection.endpoint;
vm1.username = vm1.selection.username;
@ -48,9 +51,11 @@
vm.policyId = Number(parts[1]);
switch(parts[0]) {
case 'ADD_NEW':
vm.addNew(); break;
vm.addNew();
break;
case 'EDIT':
vm.edit(vm.policyId); break;
vm.edit(vm.policyId);
break;
}
}
});
@ -81,13 +86,13 @@
.error(listReplicationPolicyFailed);
}
function createPolicy(policy) {
function create(policy) {
CreateReplicationPolicyService(policy)
.success(createReplicationPolicySuccess)
.error(createReplicationPolicyFailed);
}
function updatePolicy(policy) {
function update(policy) {
console.log('Update policy ID:' + vm.policyId);
UpdateReplicationPolicyService(vm.policyId, policy)
.success(updateReplicationPolicySuccess)
@ -119,7 +124,7 @@
}
function listDestinationSuccess(data, status) {
vm.destinations = data;
vm.destinations = data || [];
}
function listDestinationFailed(data, status) {
console.log('Failed list destination:' + data);
@ -136,12 +141,17 @@
}
function createReplicationPolicySuccess(data, status) {
console.log('Successful create replication policy.');
vm.reload();
}
function createReplicationPolicyFailed(data, status) {
if(status === 409) {
alert('Policy name already exists.');
}
console.log('Failed create replication policy.');
}
function updateReplicationPolicySuccess(data, status) {
console.log('Successful update replication policy.');
vm.reload();
}
function updateReplicationPolicyFailed(data, status) {
console.log('Failed update replication policy.');
@ -179,14 +189,15 @@
function link(scope, element, attr, ctrl) {
element.find('#createPolicyModal').on('shown.bs.modal', function() {
element.find('#createPolicyModal').on('show.bs.modal', function() {
ctrl.prepareDestination();
scope.form.$setPristine();
scope.form.$setUntouched();
});
ctrl.save = save;
function save(form) {
console.log(angular.toJson(form));
var postPayload = {
'projectId': Number(ctrl.projectId),
'targetId': form.destination.selection.id,
@ -198,14 +209,14 @@
};
switch(ctrl.action) {
case 'ADD_NEW':
ctrl.createPolicy(postPayload); break;
ctrl.create(postPayload);
break;
case 'EDIT':
ctrl.updatePolicy(postPayload); break;
ctrl.update(postPayload);
break;
}
element.find('#createPolicyModal').modal('hide');
ctrl.reload();
}
}
}

View File

@ -20,7 +20,7 @@
vm.update = update;
vm.pingDestination = pingDestination;
$scope.$watch('vm.action + "," + vm.targetId', function(current) {
$scope.$watch('vm.action+","+vm.targetId', function(current) {
if(current) {
var parts = current.split(',');
vm.action = parts[0];
@ -62,6 +62,9 @@
}
function createDestinationFailed(data, status) {
if(status === 409) {
alert('Destination already exists.');
}
console.log('Failed create destination:' + data);
}
@ -105,7 +108,6 @@
'username': vm0.username,
'password': vm0.password
};
console.log('Ping target:' + angular.toJson(target));
PingDestinationService(target)
.success(pingDestinationSuccess)
.error(pingDestinationFailed);
@ -136,24 +138,24 @@
function link(scope, element, attrs, ctrl) {
element.find('#createDestinationModal').on('hidden.bs.modal', function() {
element.find('#createDestinationModal').on('show.bs.modal', function() {
scope.form.$setPristine();
scope.form.$setUntouched();
});
ctrl.save = save;
function save(destination) {
if(destination) {
console.log('destination:' + angular.toJson(destination));
switch(ctrl.action) {
case 'ADD_NEW':
ctrl.create(destination);
break;
case 'EDIT':
ctrl.update(destination);
break;
}
element.find('#createDestinationModal').modal('hide');
ctrl.reload();
}
}
}