AC-308 Added Remove button to Hosts list.

This commit is contained in:
chouseknecht 2013-07-30 11:07:47 -04:00
parent b904dd2ae5
commit e5aeefa43d
8 changed files with 60 additions and 34 deletions

View File

@ -31,7 +31,7 @@
/* Attempt to make button heights consistent. For some reason success, info, etc. are
taller than plain .btn */
.btn-success, .btn-danger, .btn-info, .btn-primary {
.btn-success, .btn-danger, .btn-info, .btn-primary, .btn-warning {
padding-top: 1px;
padding-bottom: 2px;
}

View File

@ -488,7 +488,13 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
}
scope.deleteHost = function(host_id, host_name) {
HostsDelete({ scope: scope, "inventory_id": id, group_id: scope.group_id, host_id: host_id, host_name: host_name });
HostsDelete({ scope: scope, "inventory_id": id, group_id: scope.group_id, host_id: host_id, host_name: host_name,
request: 'delete' });
}
scope.removeHost = function(host_id, host_name) {
HostsDelete({ scope: scope, "inventory_id": id, group_id: scope.group_id, host_id: host_id, host_name: host_name,
request: 'remove' });
}
scope.showEvents = function(host_name, last_job) {

View File

@ -156,12 +156,20 @@ angular.module('InventoryFormDefinition', [])
awToolTip: 'Edit host',
'class': 'btn-inventory-edit'
},
"remove": {
ngClick: "removeHost(\{\{ host.id \}\}, '\{\{ host.name \}\}')",
icon: 'icon-minus-sign',
label: 'Remove',
"class": 'btn-success',
ngHide: "group_id === null || group_id === undefined",
awToolTip: 'Remove this host from the group, but leave it as part of the inventory under All Hosts'
},
"delete": {
ngClick: "deleteHost(\{\{ host.id \}\}, '\{\{ host.name \}\}')",
icon: 'icon-remove',
label: 'Delete',
"class": 'btn-danger',
awToolTip: 'Remove host'
awToolTip: 'Permanently remove this host from the inventory'
}
}
}

View File

@ -345,53 +345,62 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, ProcessErrors, GetBasePath, HostsReload) {
return function(params) {
// Delete the selected host. Disassociates it from the group.
// Remove the selected host from the current group by dissaciating
var scope = params.scope;
var group_id = scope.group_id;
var inventory_id = params.inventory_id;
var host_id = params.host_id;
var host_name = params.host_name;
var url = (scope.group_id !== null) ? GetBasePath('groups') + scope.group_id + '/hosts/' :
GetBasePath('inventory') + inventory_id + '/hosts/';
var host_name = params.host_name;
var req = (params.request) ? params.request : null;
var url = (scope.group_id == null || req == 'delete') ? GetBasePath('inventory') + inventory_id + '/hosts/' :
GetBasePath('groups') + scope.group_id + '/hosts/';
var action_to_take = function() {
if (scope.removeHostsReload) {
scope.removeHostsReload();
}
scope.removeHostsReload = scope.$on('hostsReload', function() {
$('#prompt-modal').modal('hide');
HostsReload(params);
});
Rest.setUrl(url);
Rest.post({ id: host_id, disassociate: 1 })
.success( function(data, status, headers, config) {
$('#prompt-modal').modal('hide');
scope.$emit('hostsReload');
})
.error( function(data, status, headers, config) {
$('#prompt-modal').modal('hide');
scope.$emit('hostsReload');
ProcessErrors(scope, data, status, null,
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
});
};
.success( function(data, status, headers, config) {
scope.$emit('hostsReload');
})
.error( function(data, status, headers, config) {
scope.$emit('hostsReload');
ProcessErrors(scope, data, status, null,
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. POST returned status: ' + status });
});
}
//Force binds to work. Not working usual way.
if (scope.group_id !== null) {
$('#prompt-header').text('Remove Host from Group');
$('#prompt-body').text('Are you sure you want to remove host ' + host_name + ' from the group?');
if (scope.group_id == null || req == 'delete') {
scope['promptHeader'] = 'Delete Host';
scope['promptBody'] = 'Are you sure you want to permanently delete ' + host_name + ' from the inventory?';
scope['promptActionBtnClass'] = 'btn-danger';
}
else {
$('#prompt-header').text('Delete Host');
$('#prompt-body').text('Are you sure you want to permenantly remove host ' + host_name + '?');
scope['promptHeader'] = 'Remove Host from Group';
scope['promptBody'] = 'Are you sure you want to remove ' + host_name + ' from the group?';
scope['promptActionBtnClass'] = 'btn-success';
}
$('#prompt-action-btn').addClass('btn-danger');
scope.promptAction = action_to_take; // for some reason this binds?
scope.promptAction = action_to_take;
$('#prompt-modal').modal({
backdrop: 'static',
keyboard: true,
show: true
});
if (!scope.$$phase) {
scope.$digest();
}
}
}])
@ -401,8 +410,11 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
return function(params) {
// Rerfresh the Hosts view on right side of page
scope = params.scope;
scope['hosts'] = null;
var url = (scope.group_id !== null) ? GetBasePath('groups') + scope.group_id + '/all_hosts/' :
GetBasePath('inventory') + params.inventory_id + '/hosts/';
var relatedSets = { hosts: { url: url, iterator: 'host' } };
RelatedSearchInit({ scope: params.scope, form: InventoryForm, relatedSets: relatedSets });
RelatedPaginateInit({ scope: params.scope, relatedSets: relatedSets });

View File

@ -861,12 +861,12 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies'])
if (form.related[itm].type == 'tree') {
html += "<div class=\"span5\">";
html += "<div class=\"inventory-buttons\">";
html += "<button ng-click=\"editGroup()\" ng-hide=\"groupEditHide\" id=\"inv-group-edit\" class=\"btn btn-pad btn-mini\" " +
"aw-tool-tip=\"Edit the selected group\" data-placement=\"bottom\">" +
"<i class=\"icon-edit\"></i> Edit Group</button>";
html += "<button ng-click=\"addGroup()\" ng-hide=\"groupAddHide\" id=\"inv-group-add\" " +
"class=\"btn btn-mini btn-success\" aw-tool-tip=\"Add a new group\" " +
"data-placement=\"bottom\"><i class=\"icon-plus\"></i> Add Group</button>";
html += "<button ng-click=\"editGroup()\" ng-hide=\"groupEditHide\" id=\"inv-group-edit\" class=\"btn btn-mini btn-success\" " +
"aw-tool-tip=\"Edit the selected group\" data-placement=\"bottom\" " +
"<i class=\"icon-edit\"></i> Edit Group</button>";
html += "<button ng-click=\"deleteGroup()\" ng-hide=\"groupDeleteHide\" id=\"inv-group-delete\" " +
"aw-tool-tip=\"Delete the selected group\" data-placement=\"bottom\" " +
"class=\"btn btn-mini btn-danger\">" +
@ -952,6 +952,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies'])
" " + form.related[itm]['fieldActions'][action]['class'] : "";
html += "\" ";
html += (form.related[itm]['fieldActions'][action].awToolTip) ? this.attr(form.related[itm]['fieldActions'][action],'awToolTip') : "";
html += (form.related[itm]['fieldActions'][action].ngHide) ? this.attr(form.related[itm]['fieldActions'][action],'ngHide') : "";
html += this.attr(form.related[itm]['fieldActions'][action],'ngClick') +
">" + this.icon(form.related[itm]['fieldActions'][action].icon);
html += (form.related[itm].fieldActions[action].label) ? " " + form.related[itm].fieldActions[action].label : "";

View File

@ -55,9 +55,8 @@ angular.module('RestServices',['ngCookies','AuthService'])
},
destroy: function(data) {
var url = this.url;
return $http({method: 'DELETE',
url: url,
url: this.url,
headers: this.auth(),
data: data});
}

View File

@ -28,7 +28,7 @@
</form>
</div>
<div class="modal-footer">
<button ng-click="systemLogin(login_username, login_password)" id="login-button" class="btn btn-primary">Sign In</button>
<button ng-click="systemLogin(login_username, login_password)" id="login-button" class="btn btn-primary"><i class="icon-signin"></i> Sign In</button>
</div>
</div><!-- modal -->

View File

@ -209,7 +209,7 @@
</div>
<div class="modal-footer">
<a href="#" data-target="#prompt-modal" data-dismiss="modal" class="btn">No</a>
<a href="" ng-click="promptAction()" id="prompt-action-btn" class="btn">Yes</a>
<a href="" ng-class="promptActionBtnClass" ng-click="promptAction()" id="prompt-action-btn" class="btn">Yes</a>
</div>
</div>