mirror of
https://github.com/ansible/awx.git
synced 2026-02-02 01:58:09 -03:30
Moved UI into its own Django app.
This commit is contained in:
148
lib/ui/static/js/app.js
Normal file
148
lib/ui/static/js/app.js
Normal file
@@ -0,0 +1,148 @@
|
||||
/************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Our main application mdoule. Declare application routes and perform initialization chores.
|
||||
*
|
||||
*/
|
||||
angular.module('ansible', [
|
||||
'RestServices',
|
||||
'AuthService',
|
||||
'Utilities',
|
||||
'OrganizationFormDefinition',
|
||||
'UserFormDefinition',
|
||||
'FormGenerator',
|
||||
'OrganizationListDefinition',
|
||||
'UserListDefinition',
|
||||
'ListGenerator',
|
||||
'AWToolTip',
|
||||
'PromptDialog',
|
||||
'APIDefaults',
|
||||
'RelatedSearchHelper',
|
||||
'RelatedPaginateHelper',
|
||||
'SearchHelper',
|
||||
'PaginateHelper',
|
||||
'RefreshHelper',
|
||||
'AdminListDefinition',
|
||||
'AWDirectives',
|
||||
'InventoriesListDefinition',
|
||||
'InventoryFormDefinition',
|
||||
'InventoryHelper',
|
||||
'AWFilters',
|
||||
'HostFormDefinition',
|
||||
'HostListDefinition',
|
||||
'HostHelper',
|
||||
'GroupFormDefinition',
|
||||
'GroupListDefinition',
|
||||
'TeamsListDefinition',
|
||||
'TeamFormDefinition',
|
||||
'TeamHelper'
|
||||
])
|
||||
.config(['$routeProvider', function($routeProvider) {
|
||||
$routeProvider.
|
||||
when('/inventories', { templateUrl: 'partials/inventories.html',
|
||||
controller: InventoriesList }).
|
||||
|
||||
when('/inventories/add', { templateUrl: 'partials/inventories.html',
|
||||
controller: InventoriesAdd }).
|
||||
|
||||
when('/inventories/:id', { templateUrl: 'partials/inventories.html',
|
||||
controller: InventoriesEdit }).
|
||||
|
||||
when('/inventories/:id/hosts', { templateUrl: 'partials/inventories.html',
|
||||
controller: HostsList }).
|
||||
|
||||
when('/inventories/:id/hosts/add', { templateUrl: 'partials/inventories.html',
|
||||
controller: HostsAdd }).
|
||||
|
||||
when('/inventories/:inventory_id/hosts/:id', { templateUrl: 'partials/inventories.html',
|
||||
controller: HostsEdit }).
|
||||
|
||||
when('/inventories/:id/groups', { templateUrl: 'partials/inventories.html',
|
||||
controller: GroupsList }).
|
||||
|
||||
when('/inventories/:id/groups/add', { templateUrl: 'partials/inventories.html',
|
||||
controller: GroupsAdd }).
|
||||
|
||||
when('/inventories/:inventory_id/groups/:id', { templateUrl: 'partials/inventories.html',
|
||||
controller: GroupsEdit }).
|
||||
|
||||
when('/organizations', { templateUrl: 'partials/organizations.html',
|
||||
controller: OrganizationsList }).
|
||||
|
||||
when('/organizations/add', { templateUrl: 'partials/organizations.html',
|
||||
controller: OrganizationsAdd }).
|
||||
|
||||
when('/organizations/:id', { templateUrl: 'partials/organizations.html',
|
||||
controller: OrganizationsEdit }).
|
||||
|
||||
when('/organizations/:id/admins', { templateUrl: 'partials/organizations.html',
|
||||
controller: AdminsList }).
|
||||
|
||||
when('/organizations/:id/users', { templateUrl: 'partials/users.html',
|
||||
controller: UsersList }).
|
||||
|
||||
when('/organizations/:id/users/add', { templateUrl: 'partials/users.html',
|
||||
controller: UsersAdd }).
|
||||
|
||||
when('/organizations/:organization_id/users/:id', { templateUrl: 'partials/users.html',
|
||||
controller: UsersEdit }).
|
||||
|
||||
when('/teams', { templateUrl: 'partials/teams.html',
|
||||
controller: TeamsList }).
|
||||
|
||||
when('/teams/add', { templateUrl: 'partials/teams.html',
|
||||
controller: TeamsAdd }).
|
||||
|
||||
when('/teams/:id', { templateUrl: 'partials/teams.html',
|
||||
controller: TeamsEdit }).
|
||||
|
||||
when('/users', { templateUrl: 'partials/users.html',
|
||||
controller: UsersList }).
|
||||
|
||||
when('/users/add', { templateUrl: 'partials/users.html',
|
||||
controller: UsersAdd }).
|
||||
|
||||
when('/users/:id', { templateUrl: 'partials/users.html',
|
||||
controller: UsersEdit }).
|
||||
|
||||
when('/login', { templateUrl: 'partials/login-dialog.html', controller: Authenticate }).
|
||||
|
||||
when('/logout', { templateUrl: 'partials/login-dialog.html', controller: Authenticate }).
|
||||
|
||||
otherwise({redirectTo: '/'});
|
||||
}])
|
||||
.run(function($rootScope, $location, Authorization) {
|
||||
|
||||
$rootScope.breadcrumbs = new Array();
|
||||
$rootScope.crumbCache = new Array();
|
||||
|
||||
$rootScope.$on("$routeChangeStart", function(event, next, current) {
|
||||
// Evaluate the token on each navigation request. Redirect to login page when not valid
|
||||
if (Authorization.isTokenValid() == false) {
|
||||
if ( next.templateUrl != 'partials/login.html' ) {
|
||||
$location.path('/login');
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($rootScope.current_user == undefined || $rootScope.current_user == null) {
|
||||
Authorization.restoreUserInfo(); //user must have hit browser refresh
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (! Authorization.isTokenValid() ) {
|
||||
// When the app first loads, redirect to login page
|
||||
$location.path('/login');
|
||||
}
|
||||
|
||||
// If browser refresh, activate the correct tab
|
||||
var base = ($location.path().replace(/^\//,'').split('/')[0]);
|
||||
if (base == '') {
|
||||
console.log(base);
|
||||
base = 'organizations';
|
||||
$location.path('/organizations');
|
||||
}
|
||||
else {
|
||||
$('.nav-tabs a[href="#' + base + '"]').tab('show');
|
||||
}
|
||||
});
|
||||
19
lib/ui/static/js/config.js
Normal file
19
lib/ui/static/js/config.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/************************************
|
||||
*
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* config.js
|
||||
*
|
||||
* Gobal configuration variables for controlling application behavior.
|
||||
*
|
||||
*/
|
||||
|
||||
var $AnsibleConfig =
|
||||
{
|
||||
session_timeout: 3600, // cookie expiration in seconds. session will expire after this many
|
||||
// seconds of inactivity.
|
||||
|
||||
tooltip_delay: 2000, // Default number of milliseconds to delay displaying/hiding tooltips
|
||||
|
||||
debug_mode: true // Enable console logging messages
|
||||
}
|
||||
104
lib/ui/static/js/controllers/Admins.js
Normal file
104
lib/ui/static/js/controllers/Admins.js
Normal file
@@ -0,0 +1,104 @@
|
||||
/************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* Admins.js
|
||||
*
|
||||
* Controller functions for ading Admins to an Organization.
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
function AdminsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
Alert, AdminList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit,
|
||||
ReturnToCaller)
|
||||
{
|
||||
var list = AdminList;
|
||||
var defaultUrl = '/api/v1' + '/organizations/' + $routeParams.id + '/users/' ;
|
||||
var view = GenerateList;
|
||||
//var paths = $location.path().replace(/^\//,'').split('/');
|
||||
var mode = 'select';
|
||||
var scope = view.inject(AdminList, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
SearchInit({ scope: scope, set: 'admins', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl('/api/v1' + $location.path() + '/'); // We're assuming the path matches the api path.
|
||||
// Will this always be true??
|
||||
scope.queue = [];
|
||||
|
||||
scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
scope.selected = [];
|
||||
var errors = 0;
|
||||
for (var i=0; i < scope.queue.length; i++) {
|
||||
if (scope.queue[i].result == 'error') {
|
||||
errors++;
|
||||
// there is no way to know which user raised the error. no data comes
|
||||
// back from the api call.
|
||||
// $('td.username-column').each(function(index) {
|
||||
// if ($(this).text() == scope.queue[i].username) {
|
||||
// $(this).addClass("error");
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
if (errors > 0) {
|
||||
Alert('Error', 'There was an error while adding one or more of the selected users.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var user;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
user = null;
|
||||
for (var j=0; j < scope.admins.length; j++) {
|
||||
if (scope.admins[j].id == scope.selected[i]) {
|
||||
user = scope.admins[j];
|
||||
}
|
||||
}
|
||||
if (user !== null) {
|
||||
Rest.post(user)
|
||||
.success( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'success', data: data, status: status });
|
||||
scope.$emit('callFinished');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'error', data: data, status: status, headers: headers });
|
||||
scope.$emit('callFinished');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
returnToCaller();
|
||||
}
|
||||
}
|
||||
|
||||
scope.toggle_admin = function(idx) {
|
||||
if (scope.selected.indexOf(idx) > -1) {
|
||||
scope.selected.splice(scope.selected.indexOf(idx),1);
|
||||
}
|
||||
else {
|
||||
scope.selected.push(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AdminsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'AdminList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller' ];
|
||||
|
||||
74
lib/ui/static/js/controllers/Authentication.js
Normal file
74
lib/ui/static/js/controllers/Authentication.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* Authentication.js
|
||||
*
|
||||
* Controller functions for user authentication.
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
function Authenticate($scope, $rootScope, $location, Authorization, ToggleClass, Alert)
|
||||
{
|
||||
// Authorization is injected from AuthService found in services.js
|
||||
|
||||
if ($location.path() == '/logout') {
|
||||
//if logout request, clear AuthToken and user session data
|
||||
Authorization.logout();
|
||||
}
|
||||
|
||||
$rootScope.userLoggedIn = false; //hide the logout link. if you got here, your logged out.
|
||||
//gets set back to true by Authorization.setToken().
|
||||
|
||||
$scope.sessionExpired = Authorization.didSessionExpire(); //Display session timeout message
|
||||
$scope.sessionTimeout = ($AnsibleConfig.session_timeout / 60).toFixed(2)
|
||||
|
||||
// Display the login dialog
|
||||
$('#login-modal').modal({ show: true, keyboard: false, backdrop: false });
|
||||
|
||||
$scope.reset = function() {
|
||||
$('#login-form input').each( function(index) { $(this).val(''); });
|
||||
};
|
||||
|
||||
// Call the API to get an auth token
|
||||
$scope.systemLogin = function(username, password) {
|
||||
$('.api-error').empty();
|
||||
Authorization.retrieveToken(username, password)
|
||||
.success( function(data, status, headers, config) {
|
||||
Authorization.setToken(data.token);
|
||||
$scope.reset();
|
||||
// Get all the profile/access info regarding the logged in user
|
||||
Authorization.getUser()
|
||||
.success(function(data, status, headers, config) {
|
||||
$('#login-modal').modal('hide');
|
||||
Authorization.setUserInfo(data);
|
||||
$location.path('/organizations');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
Alert('Error', 'Failed to get user data from /api/v1/me. GET status: ' + status);
|
||||
});
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
if ( data.non_field_errors && data.non_field_errors.length == 0 ) {
|
||||
// show field specific errors returned by the API
|
||||
for (var key in data) {
|
||||
$scope[key + 'Error'] = data[key][0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( data.non_field_errors && data.non_field_errors.length > 0 ) {
|
||||
$rootScope.alertHeader = 'Error!';
|
||||
$rootScope.alertBody = data.non_field_errors[0];
|
||||
}
|
||||
else {
|
||||
$rootScope.alertHeader = 'Error!';
|
||||
$rootScope.alertBody = 'The login attempt failed with a status of: ' + status;
|
||||
}
|
||||
$scope.reset();
|
||||
$('#alert-modal').modal({ show: true, keyboard: true, backdrop: 'static' });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
227
lib/ui/static/js/controllers/Groups.js
Normal file
227
lib/ui/static/js/controllers/Groups.js
Normal file
@@ -0,0 +1,227 @@
|
||||
/************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* Groups.js
|
||||
*
|
||||
* Controller functions for Group model.
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
function GroupsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
Alert, GroupList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit,
|
||||
PaginateInit, ReturnToCaller, ClearScope, ProcessErrors)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var list = GroupList;
|
||||
var defaultUrl = '/api/v1/inventories/' + $routeParams.id + '/groups/';
|
||||
var view = GenerateList;
|
||||
var paths = $location.path().replace(/^\//,'').split('/');
|
||||
var scope = view.inject(GroupList, { mode: 'edit' }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
SearchInit({ scope: scope, set: 'groups', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
scope.addGroup = function() {
|
||||
$location.path($location.path() + '/add');
|
||||
}
|
||||
|
||||
scope.editGroup = function(id) {
|
||||
$location.path($location.path() + '/' + id);
|
||||
}
|
||||
|
||||
scope.deleteGroup = function(id, name) {
|
||||
|
||||
var action = function() {
|
||||
var url = defaultUrl;
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ id: id, disassociate: 1 })
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(list.iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete group' + name + '?',
|
||||
action: action
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GroupsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GroupList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInventoryInit'];
|
||||
|
||||
|
||||
function GroupsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, GroupForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller,
|
||||
ClearScope, LookUpInventoryInit)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
// Inject dynamic view
|
||||
var defaultUrl = '/api/v1/inventories/';
|
||||
var form = GroupForm;
|
||||
var generator = GenerateForm;
|
||||
var scope = generator.inject(form, {mode: 'add', related: false});
|
||||
generator.reset();
|
||||
var master={};
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
LookUpInventoryInit({ scope: scope });
|
||||
|
||||
// Load inventory lookup value
|
||||
var url = defaultUrl + $routeParams.id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
scope['inventory'] = data.id;
|
||||
master['inventory'] = data.id;
|
||||
scope['inventory_name'] = data.name;
|
||||
master['inventory_name'] = data.name;
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve: ' + url + '. GET status: ' + status });
|
||||
});
|
||||
|
||||
// Save
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl + $routeParams.id + '/groups/');
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.post(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
ReturnToCaller(1);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to add new group. Post returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Cancel
|
||||
scope.formReset = function() {
|
||||
// Defaults
|
||||
generator.reset();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
GroupsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'GroupForm', 'GenerateForm',
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'LookUpInventoryInit' ];
|
||||
|
||||
|
||||
function GroupsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, GroupForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInventoryInit)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var defaultUrl='/api/v1/groups/';
|
||||
var generator = GenerateForm;
|
||||
var form = GroupForm;
|
||||
var scope = generator.inject(form, {mode: 'edit', related: true});
|
||||
generator.reset();
|
||||
var master = {};
|
||||
var id = $routeParams.id;
|
||||
var relatedSets = {};
|
||||
|
||||
LookUpInventoryInit({ scope: scope });
|
||||
|
||||
// After the Organization is loaded, retrieve each related set
|
||||
scope.$on('groupLoaded', function() {
|
||||
Rest.setUrl(scope['inventory_url']);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
scope['inventory_name'] = data.name;
|
||||
master['inventory_name'] = data.name;
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve: ' + scope.orgnization_url + '. GET status: ' + status });
|
||||
});
|
||||
for (var set in relatedSets) {
|
||||
scope.search(relatedSets[set].iterator);
|
||||
}
|
||||
});
|
||||
|
||||
// Retrieve detail record and prepopulate the form
|
||||
Rest.setUrl(defaultUrl + ':id/');
|
||||
Rest.get({ params: {id: id} })
|
||||
.success( function(data, status, headers, config) {
|
||||
LoadBreadCrumbs();
|
||||
for (var fld in form.fields) {
|
||||
if (data[fld]) {
|
||||
scope[fld] = data[fld];
|
||||
master[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
var related = data.related;
|
||||
for (var set in form.related) {
|
||||
if (related[set]) {
|
||||
relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
|
||||
}
|
||||
}
|
||||
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
||||
RelatedPaginateInit({ scope: scope, relatedSets: relatedSets });
|
||||
scope['inventory_url'] = data.related.inventory;
|
||||
scope.$emit('groupLoaded');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve group: ' + $routeParams.id + '. GET status: ' + status });
|
||||
});
|
||||
|
||||
// Save changes to the parent
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl + id + '/');
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.put(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
(base == 'inventories') ? ReturnToCaller() : ReturnToCaller(1);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to update host: ' + $routeParams.id + '. PUT status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Cancel
|
||||
scope.formReset = function() {
|
||||
generator.reset();
|
||||
for (var fld in master) {
|
||||
scope[fld] = master[fld];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
HostsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'HostForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInventoryInit' ];
|
||||
|
||||
228
lib/ui/static/js/controllers/Hosts.js
Normal file
228
lib/ui/static/js/controllers/Hosts.js
Normal file
@@ -0,0 +1,228 @@
|
||||
/************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* Hosts.js
|
||||
*
|
||||
* Controller functions for Host model.
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
function HostsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
Alert, HostList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit,
|
||||
ReturnToCaller, ClearScope, ProcessErrors)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var list = HostList;
|
||||
var defaultUrl = '/api/v1/inventories/' + $routeParams.id + '/hosts/';
|
||||
var view = GenerateList;
|
||||
var paths = $location.path().replace(/^\//,'').split('/');
|
||||
var scope = view.inject(HostList, { mode: 'edit' }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
SearchInit({ scope: scope, set: 'hosts', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
scope.addHost = function() {
|
||||
$location.path($location.path() + '/add');
|
||||
}
|
||||
|
||||
scope.editHost = function(id) {
|
||||
$location.path($location.path() + '/' + id);
|
||||
}
|
||||
|
||||
scope.deleteHost = function(id, name) {
|
||||
|
||||
var action = function() {
|
||||
var url = defaultUrl;
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ id: id, disassociate: 1 })
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(list.iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete host ' + name + '?',
|
||||
action: action
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HostsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors' ];
|
||||
|
||||
|
||||
function HostsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, HostForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller,
|
||||
ClearScope, LookUpInventoryInit)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
// Inject dynamic view
|
||||
var defaultUrl = '/api/v1/inventories/';
|
||||
var form = HostForm;
|
||||
var generator = GenerateForm;
|
||||
var scope = generator.inject(form, {mode: 'add', related: false});
|
||||
generator.reset();
|
||||
var master = {};
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
LookUpInventoryInit({ scope: scope });
|
||||
|
||||
// Load inventory lookup value
|
||||
var url = defaultUrl + $routeParams.id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
scope['inventory'] = data.id;
|
||||
master['inventory'] = data.id;
|
||||
scope['inventory_name'] = data.name;
|
||||
master['inventory_name'] = data.name;
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve: ' + url + '. GET status: ' + status });
|
||||
});
|
||||
|
||||
// Save
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl + $routeParams.id + '/hosts/');
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.post(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
ReturnToCaller(1);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to add new host. Post returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Cancel
|
||||
scope.formReset = function() {
|
||||
// Defaults
|
||||
generator.reset();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
HostsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'HostForm', 'GenerateForm',
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'LookUpInventoryInit' ];
|
||||
|
||||
|
||||
function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInventoryInit)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var defaultUrl='/api/v1/hosts/';
|
||||
var generator = GenerateForm;
|
||||
var form = UserForm;
|
||||
var scope = generator.inject(form, {mode: 'edit', related: true});
|
||||
generator.reset();
|
||||
var master = {};
|
||||
var id = $routeParams.id;
|
||||
var relatedSets = {};
|
||||
|
||||
LookUpInventoryInit({ scope: scope });
|
||||
|
||||
// After form data loads, load related sets and lookups
|
||||
scope.$on('hostLoaded', function() {
|
||||
Rest.setUrl(scope['inventory_url']);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
scope['inventory_name'] = data.name;
|
||||
master['inventory_name'] = data.name;
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve: ' + scope.inventory_url + '. GET status: ' + status });
|
||||
});
|
||||
for (var set in relatedSets) {
|
||||
scope.search(relatedSets[set].iterator);
|
||||
}
|
||||
});
|
||||
|
||||
// Retrieve detail record and prepopulate the form
|
||||
Rest.setUrl(defaultUrl + ':id/');
|
||||
Rest.get({ params: {id: id} })
|
||||
.success( function(data, status, headers, config) {
|
||||
LoadBreadCrumbs();
|
||||
for (var fld in form.fields) {
|
||||
if (data[fld]) {
|
||||
scope[fld] = data[fld];
|
||||
master[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
var related = data.related;
|
||||
for (var set in form.related) {
|
||||
if (related[set]) {
|
||||
relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
|
||||
}
|
||||
}
|
||||
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
||||
RelatedPaginateInit({ scope: scope, relatedSets: relatedSets });
|
||||
scope['inventory_url'] = data.related.inventory;
|
||||
scope.$emit('hostLoaded');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve host: ' + $routeParams.id + '. GET status: ' + status });
|
||||
});
|
||||
|
||||
// Save changes to the parent
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl + id + '/');
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.put(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
(base == 'inventories') ? ReturnToCaller() : ReturnToCaller(1);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to update host: ' + $routeParams.id + '. PUT status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Cancel
|
||||
scope.formReset = function() {
|
||||
generator.reset();
|
||||
for (var fld in master) {
|
||||
scope[fld] = master[fld];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
HostsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'HostForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInventoryInit' ];
|
||||
|
||||
332
lib/ui/static/js/controllers/Inventories.js
Normal file
332
lib/ui/static/js/controllers/Inventories.js
Normal file
@@ -0,0 +1,332 @@
|
||||
/************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* Inventories.js
|
||||
*
|
||||
* Controller functions for the Inventory model.
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, InventoryList,
|
||||
GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller,
|
||||
ClearScope, ProcessErrors, SetListeners)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
var list = InventoryList;
|
||||
var defaultUrl = '/api/v1/inventories/';
|
||||
var view = GenerateList;
|
||||
var paths = $location.path().replace(/^\//,'').split('/');
|
||||
var mode = (paths[0] == 'inventories') ? 'edit' : 'select'; // if base path 'users', we're here to add/edit users
|
||||
var scope = view.inject(InventoryList, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
SetListeners({ scope: scope, set: 'inventories', iterator: list.iterator });
|
||||
SearchInit({ scope: scope, set: 'inventories', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
scope.addInventory = function() {
|
||||
$location.path($location.path() + '/add');
|
||||
}
|
||||
|
||||
scope.editInventory = function(id) {
|
||||
$location.path($location.path() + '/' + id);
|
||||
}
|
||||
|
||||
scope.deleteInventory = function(id, name) {
|
||||
|
||||
var action = function() {
|
||||
var url = defaultUrl + id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.delete()
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(list.iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete ' + name + '?',
|
||||
action: action
|
||||
});
|
||||
}
|
||||
|
||||
scope.lookupOrganization = function(organization_id) {
|
||||
Rest.setUrl('/api/v1/organization/' + organization_id + '/');
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
return data.name;
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl('/api/v1' + $location.path() + '/'); // We're assuming the path matches the api path.
|
||||
// Will this always be true??
|
||||
scope.queue = [];
|
||||
|
||||
scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
scope.selected = [];
|
||||
var errors = 0;
|
||||
for (var i=0; i < scope.queue.length; i++) {
|
||||
if (scope.queue[i].result == 'error') {
|
||||
errors++;
|
||||
// there is no way to know which user raised the error. no data comes
|
||||
// back from the api call.
|
||||
// $('td.username-column').each(function(index) {
|
||||
// if ($(this).text() == scope.queue[i].username) {
|
||||
// $(this).addClass("error");
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
if (errors > 0) {
|
||||
Alert('Error', 'There was an error while adding one or more of the selected inventories.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var inventory = null;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
for (var j=0; j < scope.inventories.length; j++) {
|
||||
if (scope.inventories[j].id == scope.selected[i]) {
|
||||
inventory = scope.inventories[j];
|
||||
}
|
||||
}
|
||||
if (inventory !== null) {
|
||||
Rest.post(inventory)
|
||||
.success( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'success', data: data, status: status });
|
||||
scope.$emit('callFinished');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'error', data: data, status: status, headers: headers });
|
||||
scope.$emit('callFinished');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReturnToCaller();
|
||||
}
|
||||
}
|
||||
|
||||
scope.toggle_inventory = function(idx) {
|
||||
if (scope.selected.indexOf(idx) > -1) {
|
||||
scope.selected.splice(scope.selected.indexOf(idx),1);
|
||||
}
|
||||
else {
|
||||
scope.selected.push(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InventoriesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'InventoryList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors',
|
||||
'SetListeners' ];
|
||||
|
||||
|
||||
function InventoriesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, InventoryForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
|
||||
GenerateList, OrganizationList, SearchInit, PaginateInit, LookUpOrganizationInit)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
// Inject dynamic view
|
||||
var defaultUrl = '/api/v1/inventories/';
|
||||
var form = InventoryForm;
|
||||
var generator = GenerateForm;
|
||||
var scope = generator.inject(form, {mode: 'add', related: false});
|
||||
generator.reset();
|
||||
LoadBreadCrumbs();
|
||||
LookUpOrganizationInit({ scope: scope });
|
||||
|
||||
// Save
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl);
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.post(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
ReturnToCaller();
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to add new inventory. Post returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Reset
|
||||
scope.formReset = function() {
|
||||
// Defaults
|
||||
generator.reset();
|
||||
};
|
||||
}
|
||||
|
||||
InventoriesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'InventoryForm', 'GenerateForm',
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GenerateList',
|
||||
'OrganizationList', 'SearchInit', 'PaginateInit', 'LookUpOrganizationInit' ];
|
||||
|
||||
|
||||
function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, InventoryForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpOrganizationInit, Prompt,
|
||||
TreeInit)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var defaultUrl='/api/v1/inventories/';
|
||||
var generator = GenerateForm;
|
||||
var form = InventoryForm;
|
||||
var scope = generator.inject(form, {mode: 'edit', related: true});
|
||||
generator.reset();
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
var master = {};
|
||||
var id = $routeParams.id;
|
||||
var relatedSets = {};
|
||||
|
||||
LookUpOrganizationInit({ scope: scope });
|
||||
|
||||
// After inventory is loaded, retrieve each related set and any lookups
|
||||
scope.$on('inventoryLoaded', function() {
|
||||
Rest.setUrl(scope['organization_url']);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
scope['organization_name'] = data.name;
|
||||
master['organization_name'] = data.name;
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve: ' + scope.orgnization_url + '. GET status: ' + status });
|
||||
});
|
||||
for (var set in relatedSets) {
|
||||
scope.search(relatedSets[set].iterator);
|
||||
}
|
||||
});
|
||||
|
||||
// Retrieve detail record and prepopulate the form
|
||||
Rest.setUrl(defaultUrl + ':id/');
|
||||
Rest.get({ params: {id: id} })
|
||||
.success( function(data, status, headers, config) {
|
||||
LoadBreadCrumbs({ path: '/inventories/' + id, title: data.name });
|
||||
for (var fld in form.fields) {
|
||||
if (data[fld]) {
|
||||
scope[fld] = data[fld];
|
||||
master[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
var related = data.related;
|
||||
for (var set in form.related) {
|
||||
if (related[set]) {
|
||||
relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
|
||||
}
|
||||
}
|
||||
|
||||
// Load the tree view
|
||||
TreeInit(related.groups);
|
||||
|
||||
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
||||
RelatedPaginateInit({ scope: scope, relatedSets: relatedSets });
|
||||
scope['organization_url'] = data.related.organization;
|
||||
scope.$emit('inventoryLoaded');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve inventory: ' + $routeParams.id + '. GET status: ' + status });
|
||||
});
|
||||
|
||||
// Save changes to the parent
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl + $routeParams.id);
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.put(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
(base == 'inventories') ? ReturnToCaller() : ReturnToCaller(1);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to update inventory: ' + $routeParams.id + '. PUT status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Cancel
|
||||
scope.formReset = function() {
|
||||
generator.reset();
|
||||
for (var fld in master) {
|
||||
scope[fld] = master[fld];
|
||||
}
|
||||
};
|
||||
|
||||
// Related set: Add button
|
||||
scope.add = function(set) {
|
||||
$rootScope.flashMessage = null;
|
||||
$location.path('/' + base + '/' + $routeParams.id + '/' + set + '/add');
|
||||
};
|
||||
|
||||
// Related set: Edit button
|
||||
scope.edit = function(set, id, name) {
|
||||
$rootScope.flashMessage = null;
|
||||
$location.path('/' + base + '/' + $routeParams.id + '/' + set + '/' + id);
|
||||
};
|
||||
|
||||
// Related set: Delete button
|
||||
scope.delete = function(set, itm_id, name, title) {
|
||||
$rootScope.flashMessage = null;
|
||||
|
||||
var action = function() {
|
||||
var url = defaultUrl + id + '/' + set + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ id: itm_id, disassociate: 1 })
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(form.related[set].iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. POST returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to remove ' + name + ' from ' + scope.name + ' ' + title + '?',
|
||||
action: action
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
InventoriesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'InventoryForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpOrganizationInit', 'Prompt',
|
||||
'TreeInit' ];
|
||||
|
||||
234
lib/ui/static/js/controllers/Organizations.js
Normal file
234
lib/ui/static/js/controllers/Organizations.js
Normal file
@@ -0,0 +1,234 @@
|
||||
/************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* Organizations.js
|
||||
*
|
||||
* Controller functions for Organization model.
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
function OrganizationsList ($scope, $rootScope, $location, $log, Rest, Alert, LoadBreadCrumbs, Prompt, GetAPIDefaults,
|
||||
GenerateList, OrganizationList, SearchInit, PaginateInit, ClearScope, ProcessErrors)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var list = OrganizationList;
|
||||
var generate = GenerateList;
|
||||
var paths = $location.path().replace(/^\//,'').split('/');
|
||||
var mode = (paths[0] == 'organizations') ? 'edit' : 'select'; // if base path 'users', we're here to add/edit users
|
||||
var scope = generate.inject(OrganizationList, { mode: mode }); // Inject our view
|
||||
var defaultUrl = '/api/v1/organizations/';
|
||||
var iterator = list.iterator;
|
||||
$rootScope.flashMessage = null;
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
// Initialize search and paginate pieces and load data
|
||||
SearchInit({ scope: scope, set: list.name, list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
|
||||
//getData();
|
||||
|
||||
scope.addOrganization = function() {
|
||||
$location.path($location.path() + '/add');
|
||||
}
|
||||
|
||||
scope.editOrganization = function(id) {
|
||||
$location.path($location.path() + '/' + id);
|
||||
}
|
||||
|
||||
scope.deleteOrganization = function(id, name) {
|
||||
|
||||
var action = function() {
|
||||
var url = defaultUrl + id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.delete()
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(list.iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete ' + name + '?',
|
||||
action: action
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
OrganizationsList.$inject=[ '$scope', '$rootScope', '$location', '$log', 'Rest', 'Alert', 'LoadBreadCrumbs', 'Prompt', 'GetAPIDefaults',
|
||||
'GenerateList', 'OrganizationList', 'SearchInit', 'PaginateInit', 'ClearScope', 'ProcessErrors'];
|
||||
|
||||
|
||||
function OrganizationsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, OrganizationForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
// Inject dynamic view
|
||||
var form = GenerateForm;
|
||||
var scope = form.inject(OrganizationForm, {mode: 'add', related: false});
|
||||
form.reset();
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
// Save
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl('/api/v1/organizations/');
|
||||
Rest.post({ name: $scope.name,
|
||||
description: $scope.description })
|
||||
.success( function(data, status, headers, config) {
|
||||
$rootScope.flashMessage = "Your changes were successfully saved!";
|
||||
$location.path('/organizations/' + data.id + '/');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, OrganizationForm,
|
||||
{ hdr: 'Error!', msg: 'Failed to add new location. Post returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Cancel
|
||||
scope.formReset = function() {
|
||||
$rootScope.flashMessage = null;
|
||||
form.reset();
|
||||
};
|
||||
}
|
||||
|
||||
OrganizationsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'OrganizationForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope' ];
|
||||
|
||||
|
||||
function OrganizationsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, OrganizationForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, GetAPIDefaults,
|
||||
RelatedSearchInit, RelatedPaginateInit, Prompt, ClearScope)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
// Inject dynamic view
|
||||
var form = OrganizationForm;
|
||||
var generator = GenerateForm;
|
||||
var scope = GenerateForm.inject(form, {mode: 'edit', related: true});
|
||||
generator.reset();
|
||||
|
||||
var defaultUrl = '/api/v1/organizations/';
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
var master = {};
|
||||
var id = $routeParams.id;
|
||||
var relatedSets = {};
|
||||
|
||||
// After the Organization is loaded, retrieve each related set
|
||||
scope.$on('organizationLoaded', function() {
|
||||
for (var set in relatedSets) {
|
||||
scope.search(relatedSets[set].iterator);
|
||||
}
|
||||
});
|
||||
|
||||
// Retrieve detail record and prepopulate the form
|
||||
Rest.setUrl(defaultUrl + ':id/');
|
||||
Rest.get({ params: {id: id} })
|
||||
.success( function(data, status, headers, config) {
|
||||
LoadBreadCrumbs({ path: '/organizations/' + id, title: data.name });
|
||||
for (var fld in form.fields) {
|
||||
if (data[fld]) {
|
||||
scope[fld] = data[fld];
|
||||
master[fld] = data[fld];
|
||||
}
|
||||
}
|
||||
var related = data.related;
|
||||
for (var set in form.related) {
|
||||
if (related[set]) {
|
||||
relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
|
||||
}
|
||||
}
|
||||
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
||||
RelatedPaginateInit({ scope: scope, relatedSets: relatedSets });
|
||||
scope.$emit('organizationLoaded');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve organization: ' + $routeParams.id + '. GET status: ' + status });
|
||||
});
|
||||
|
||||
|
||||
// Save changes to the parent
|
||||
scope.formSave = function() {
|
||||
var params = {};
|
||||
for (var fld in form.fields) {
|
||||
params[fld] = scope[fld];
|
||||
}
|
||||
Rest.setUrl('/api/v1/organizations/' + $routeParams.id + '/');
|
||||
Rest.put(params)
|
||||
.success( function(data, status, headers, config) {
|
||||
master = params;
|
||||
$rootScope.flashMessage = "Your changes were successfully saved!";
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, OrganizationForm,
|
||||
{ hdr: 'Error!', msg: 'Failed to update organization: ' + id + '. PUT status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Reset the form
|
||||
scope.formReset = function() {
|
||||
$rootScope.flashMessage = null;
|
||||
form.reset();
|
||||
for (var fld in master) {
|
||||
scope[fld] = master[fld];
|
||||
}
|
||||
};
|
||||
|
||||
// Related set: Add button
|
||||
scope.add = function(set) {
|
||||
$rootScope.flashMessage = null;
|
||||
$location.path('/' + base + '/' + $routeParams.id + '/' + set);
|
||||
};
|
||||
|
||||
// Related set: Edit button
|
||||
scope.edit = function(set, id, name) {
|
||||
$rootScope.flashMessage = null;
|
||||
$location.path('/' + base + '/' + $routeParams.id + '/' + set + '/' + id);
|
||||
};
|
||||
|
||||
// Related set: Delete button
|
||||
scope.delete = function(set, itm_id, name, title) {
|
||||
$rootScope.flashMessage = null;
|
||||
|
||||
var action = function() {
|
||||
var url = defaultUrl + id + '/' + set + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ id: itm_id, disassociate: 1 })
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(form.related[set].iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. POST returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to remove ' + name + ' from ' + scope.name + ' ' + title + '?',
|
||||
action: action
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
OrganizationsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'OrganizationForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'GetAPIDefaults',
|
||||
'RelatedSearchInit', 'RelatedPaginateInit', 'Prompt', 'ClearScope'];
|
||||
328
lib/ui/static/js/controllers/Teams.js
Normal file
328
lib/ui/static/js/controllers/Teams.js
Normal file
@@ -0,0 +1,328 @@
|
||||
/************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* Teams.js
|
||||
*
|
||||
* Controller functions for the Team model.
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
function TeamsList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, TeamList,
|
||||
GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller,
|
||||
ClearScope, ProcessErrors, SetTeamListeners)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
var list = TeamList;
|
||||
var defaultUrl = '/api/v1/teams/';
|
||||
var view = GenerateList;
|
||||
var paths = $location.path().replace(/^\//,'').split('/');
|
||||
var mode = (paths[0] == 'teams') ? 'edit' : 'select'; // if base path 'teams', we're here to add/edit teams
|
||||
var scope = view.inject(list, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
SetTeamListeners({ scope: scope, set: 'teams', iterator: list.iterator });
|
||||
SearchInit({ scope: scope, set: 'teams', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
scope.addTeam = function() {
|
||||
$location.path($location.path() + '/add');
|
||||
}
|
||||
|
||||
scope.editTeam = function(id) {
|
||||
$location.path($location.path() + '/' + id);
|
||||
}
|
||||
|
||||
scope.deleteTeam = function(id, name) {
|
||||
|
||||
var action = function() {
|
||||
var url = defaultUrl + id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.delete()
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(list.iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete ' + name + '?',
|
||||
action: action
|
||||
});
|
||||
}
|
||||
|
||||
scope.lookupOrganization = function(organization_id) {
|
||||
Rest.setUrl('/api/v1/organization/' + organization_id + '/');
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
return data.name;
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl('/api/v1' + $location.path() + '/'); // We're assuming the path matches the api path.
|
||||
// Will this always be true??
|
||||
scope.queue = [];
|
||||
|
||||
scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
scope.selected = [];
|
||||
var errors = 0;
|
||||
for (var i=0; i < scope.queue.length; i++) {
|
||||
if (scope.queue[i].result == 'error') {
|
||||
errors++;
|
||||
// there is no way to know which user raised the error. no data comes
|
||||
// back from the api call.
|
||||
// $('td.username-column').each(function(index) {
|
||||
// if ($(this).text() == scope.queue[i].username) {
|
||||
// $(this).addClass("error");
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
if (errors > 0) {
|
||||
Alert('Error', 'There was an error while adding one or more of the selected teams.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var team = null;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
for (var j=0; j < scope.teams.length; j++) {
|
||||
if (scope.teams[j].id == scope.selected[i]) {
|
||||
team = scope.teams[j];
|
||||
}
|
||||
}
|
||||
if (team !== null) {
|
||||
Rest.post(team)
|
||||
.success( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'success', data: data, status: status });
|
||||
scope.$emit('callFinished');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'error', data: data, status: status, headers: headers });
|
||||
scope.$emit('callFinished');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReturnToCaller();
|
||||
}
|
||||
}
|
||||
|
||||
scope.toggle_team = function(idx) {
|
||||
if (scope.selected.indexOf(idx) > -1) {
|
||||
scope.selected.splice(scope.selected.indexOf(idx),1);
|
||||
}
|
||||
else {
|
||||
scope.selected.push(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TeamsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'TeamList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors',
|
||||
'SetTeamListeners' ];
|
||||
|
||||
|
||||
function TeamsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
|
||||
GenerateList, OrganizationList, SearchInit, PaginateInit, TeamLookUpOrganizationInit)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
// Inject dynamic view
|
||||
var defaultUrl = '/api/v1/teams/';
|
||||
var form = TeamForm;
|
||||
var generator = GenerateForm;
|
||||
var scope = generator.inject(form, {mode: 'add', related: false});
|
||||
generator.reset();
|
||||
LoadBreadCrumbs();
|
||||
TeamLookUpOrganizationInit({ scope: scope });
|
||||
|
||||
// Save
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl);
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.post(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
ReturnToCaller();
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to add new inventory. Post returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Reset
|
||||
scope.formReset = function() {
|
||||
// Defaults
|
||||
generator.reset();
|
||||
};
|
||||
}
|
||||
|
||||
TeamsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm', 'GenerateForm',
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GenerateList',
|
||||
'OrganizationList', 'SearchInit', 'PaginateInit', 'TeamLookUpOrganizationInit' ];
|
||||
|
||||
|
||||
function TeamsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, TeamLookUpOrganizationInit, Prompt)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var defaultUrl='/api/v1/teams/';
|
||||
var generator = GenerateForm;
|
||||
var form = InventoryForm;
|
||||
var scope = generator.inject(form, {mode: 'edit', related: true});
|
||||
generator.reset();
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
var master = {};
|
||||
var id = $routeParams.id;
|
||||
var relatedSets = {};
|
||||
|
||||
TeamLookUpOrganizationInit({ scope: scope });
|
||||
|
||||
// After inventory is loaded, retrieve each related set and any lookups
|
||||
scope.$on('teamLoaded', function() {
|
||||
Rest.setUrl(scope['organization_url']);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
scope['organization_name'] = data.name;
|
||||
master['organization_name'] = data.name;
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve: ' + scope.orgnization_url + '. GET status: ' + status });
|
||||
});
|
||||
for (var set in relatedSets) {
|
||||
scope.search(relatedSets[set].iterator);
|
||||
}
|
||||
});
|
||||
|
||||
// Retrieve detail record and prepopulate the form
|
||||
Rest.setUrl(defaultUrl + ':id/');
|
||||
Rest.get({ params: {id: id} })
|
||||
.success( function(data, status, headers, config) {
|
||||
LoadBreadCrumbs({ path: '/teams/' + id, title: data.name });
|
||||
for (var fld in form.fields) {
|
||||
if (data[fld]) {
|
||||
scope[fld] = data[fld];
|
||||
master[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
var related = data.related;
|
||||
for (var set in form.related) {
|
||||
if (related[set]) {
|
||||
relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
||||
RelatedPaginateInit({ scope: scope, relatedSets: relatedSets });
|
||||
scope['organization_url'] = data.related.organization;
|
||||
scope.$emit('teamLoaded');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve team: ' + $routeParams.id + '. GET status: ' + status });
|
||||
});
|
||||
|
||||
// Save changes to the parent
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl + $routeParams.id);
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.put(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
(base == 'inventories') ? ReturnToCaller() : ReturnToCaller(1);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to update team: ' + $routeParams.id + '. PUT status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Cancel
|
||||
scope.formReset = function() {
|
||||
generator.reset();
|
||||
for (var fld in master) {
|
||||
scope[fld] = master[fld];
|
||||
}
|
||||
};
|
||||
|
||||
// Related set: Add button
|
||||
scope.add = function(set) {
|
||||
$rootScope.flashMessage = null;
|
||||
$location.path('/' + base + '/' + $routeParams.id + '/' + set + '/add');
|
||||
};
|
||||
|
||||
// Related set: Edit button
|
||||
scope.edit = function(set, id, name) {
|
||||
$rootScope.flashMessage = null;
|
||||
$location.path('/' + base + '/' + $routeParams.id + '/' + set + '/' + id);
|
||||
};
|
||||
|
||||
// Related set: Delete button
|
||||
scope.delete = function(set, itm_id, name, title) {
|
||||
$rootScope.flashMessage = null;
|
||||
|
||||
var action = function() {
|
||||
var url = defaultUrl + id + '/' + set + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ id: itm_id, disassociate: 1 })
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(form.related[set].iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. POST returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to remove ' + name + ' from ' + scope.name + ' ' + title + '?',
|
||||
action: action
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TeamsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'TeamLookUpOrganizationInit', 'Prompt'
|
||||
];
|
||||
|
||||
284
lib/ui/static/js/controllers/Users.js
Normal file
284
lib/ui/static/js/controllers/Users.js
Normal file
@@ -0,0 +1,284 @@
|
||||
/************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* Users.js
|
||||
*
|
||||
* Controller functions for User model.
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
function UsersList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
Alert, UserList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit,
|
||||
ReturnToCaller, ClearScope, ProcessErrors)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var list = UserList;
|
||||
var defaultUrl = '/api/v1/users/';
|
||||
var view = GenerateList;
|
||||
var paths = $location.path().replace(/^\//,'').split('/');
|
||||
var mode = (paths[0] == 'users') ? 'edit' : 'select'; // if base path 'users', we're here to add/edit users
|
||||
var scope = view.inject(UserList, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
SearchInit({ scope: scope, set: 'users', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
scope.addUser = function() {
|
||||
$location.path($location.path() + '/add');
|
||||
}
|
||||
|
||||
scope.editUser = function(id) {
|
||||
$location.path($location.path() + '/' + id);
|
||||
}
|
||||
|
||||
scope.deleteUser = function(id, name) {
|
||||
|
||||
var action = function() {
|
||||
var url = defaultUrl + id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.delete()
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(list.iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete ' + name + '?',
|
||||
action: action
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl('/api/v1' + $location.path() + '/'); // We're assuming the path matches the api path.
|
||||
// Will this always be true??
|
||||
scope.queue = [];
|
||||
|
||||
scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
scope.selected = [];
|
||||
var errors = 0;
|
||||
for (var i=0; i < scope.queue.length; i++) {
|
||||
if (scope.queue[i].result == 'error') {
|
||||
errors++;
|
||||
// there is no way to know which user raised the error. no data comes
|
||||
// back from the api call.
|
||||
// $('td.username-column').each(function(index) {
|
||||
// if ($(this).text() == scope.queue[i].username) {
|
||||
// $(this).addClass("error");
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
if (errors > 0) {
|
||||
Alert('Error', 'There was an error while adding one or more of the selected users.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var user;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
user = null;
|
||||
for (var j=0; j < scope.users.length; j++) {
|
||||
if (scope.users[j].id == scope.selected[i]) {
|
||||
user = scope.users[j];
|
||||
}
|
||||
}
|
||||
if (user !== null) {
|
||||
Rest.post(user)
|
||||
.success( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'success', data: data, status: status });
|
||||
scope.$emit('callFinished');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'error', data: data, status: status, headers: headers });
|
||||
scope.$emit('callFinished');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReturnToCaller();
|
||||
}
|
||||
}
|
||||
|
||||
scope.toggle_user = function(idx) {
|
||||
if (scope.selected.indexOf(idx) > -1) {
|
||||
scope.selected.splice(scope.selected.indexOf(idx),1);
|
||||
}
|
||||
else {
|
||||
scope.selected.push(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UsersList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'UserList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors' ];
|
||||
|
||||
|
||||
function UsersAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
// Inject dynamic view
|
||||
var defaultUrl = '/api/v1/organizations/';
|
||||
var form = UserForm;
|
||||
var generator = GenerateForm;
|
||||
var scope = generator.inject(form, {mode: 'add', related: false});
|
||||
generator.reset();
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
// Save
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl + $routeParams.id + '/users/');
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.post(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
ReturnToCaller(1);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to add new user. Post returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Cancel
|
||||
scope.formReset = function() {
|
||||
// Defaults
|
||||
generator.reset();
|
||||
};
|
||||
|
||||
// Password change
|
||||
scope.clearPWConfirm = function() {
|
||||
// If password value changes, make sure password_confirm must be re-entered
|
||||
scope.password_confirm = '';
|
||||
scope[form.name]['password_confirm'].$setValidity('awpassmatch', false);
|
||||
}
|
||||
}
|
||||
|
||||
UsersAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'UserForm', 'GenerateForm',
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope'];
|
||||
|
||||
|
||||
function UsersEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var defaultUrl='/api/v1/users/';
|
||||
var generator = GenerateForm;
|
||||
var form = UserForm;
|
||||
var scope = generator.inject(form, {mode: 'edit', related: true});
|
||||
generator.reset();
|
||||
var master = {};
|
||||
var id = $routeParams.id;
|
||||
var relatedSets = {};
|
||||
|
||||
// After the Organization is loaded, retrieve each related set
|
||||
scope.$on('userLoaded', function() {
|
||||
for (var set in relatedSets) {
|
||||
scope.search(relatedSets[set].iterator);
|
||||
}
|
||||
});
|
||||
|
||||
// Retrieve detail record and prepopulate the form
|
||||
Rest.setUrl(defaultUrl + ':id/');
|
||||
Rest.get({ params: {id: id} })
|
||||
.success( function(data, status, headers, config) {
|
||||
LoadBreadCrumbs({ path: '/users/' + id, title: data.username });
|
||||
for (var fld in form.fields) {
|
||||
if (data[fld]) {
|
||||
if (fld == 'is_superuser') {
|
||||
scope[fld] = (data[fld] == 'true' || data[fld] == true) ? 'true' : 'false';
|
||||
}
|
||||
else {
|
||||
scope[fld] = data[fld];
|
||||
}
|
||||
master[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
var related = data.related;
|
||||
for (var set in form.related) {
|
||||
if (related[set]) {
|
||||
relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
|
||||
}
|
||||
}
|
||||
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
||||
RelatedPaginateInit({ scope: scope, relatedSets: relatedSets });
|
||||
scope.$emit('userLoaded');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve user: ' + $routeParams.id + '. GET status: ' + status });
|
||||
});
|
||||
|
||||
// Save changes to the parent
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl + $routeParams.id);
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.put(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
(base == 'users') ? ReturnToCaller() : ReturnToCaller(1);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to update users: ' + $routeParams.id + '. PUT status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Cancel
|
||||
scope.formReset = function() {
|
||||
generator.reset();
|
||||
for (var fld in master) {
|
||||
scope[fld] = master[fld];
|
||||
}
|
||||
};
|
||||
|
||||
// Password change
|
||||
scope.clearPWConfirm = function() {
|
||||
// If password value changes, make sure password_confirm must be re-entered
|
||||
scope.password_confirm = '';
|
||||
scope[form.name]['password_confirm'].$setValidity('awpassmatch', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UsersEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'UserForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope'];
|
||||
|
||||
64
lib/ui/static/js/forms/Groups.js
Normal file
64
lib/ui/static/js/forms/Groups.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Groups.js
|
||||
* Form definition for Group model
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('GroupFormDefinition', [])
|
||||
.value(
|
||||
'GroupForm', {
|
||||
|
||||
addTitle: 'Create Group', //Legend in add mode
|
||||
editTitle: '{{ name }}', //Legend in edit mode
|
||||
name: 'group', //Form name attribute
|
||||
well: true, //Wrap the form with TB well
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
label: 'Name',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
},
|
||||
description: {
|
||||
label: 'Description',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
},
|
||||
inventory: {
|
||||
label: 'Inventory',
|
||||
type: 'lookup',
|
||||
sourceModel: 'inventory',
|
||||
sourceField: 'name',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
ngClick: 'lookUpInventory()'
|
||||
}
|
||||
},
|
||||
|
||||
buttons: { //for now always generates <button> tags
|
||||
save: {
|
||||
label: 'Save',
|
||||
icon: 'icon-ok',
|
||||
class: 'btn btn-success',
|
||||
ngClick: 'formSave()', //$scope.function to call on click, optional
|
||||
ngDisabled: true //Disable when $pristine or $invalid, optional
|
||||
},
|
||||
reset: {
|
||||
ngClick: 'formReset()',
|
||||
label: 'Reset',
|
||||
icon: 'icon-remove',
|
||||
class: 'btn',
|
||||
ngDisabled: true //Disabled when $pristine
|
||||
}
|
||||
},
|
||||
|
||||
related: { //related colletions (and maybe items?)
|
||||
|
||||
}
|
||||
|
||||
}); //UserForm
|
||||
|
||||
64
lib/ui/static/js/forms/Hosts.js
Normal file
64
lib/ui/static/js/forms/Hosts.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Hosts.js
|
||||
* Form definition for Host model
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('HostFormDefinition', [])
|
||||
.value(
|
||||
'HostForm', {
|
||||
|
||||
addTitle: 'Create Host', //Legend in add mode
|
||||
editTitle: '{{ name }}', //Legend in edit mode
|
||||
name: 'host', //Form name attribute
|
||||
well: true, //Wrap the form with TB well
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
label: 'Name',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
},
|
||||
description: {
|
||||
label: 'Description',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
},
|
||||
inventory: {
|
||||
label: 'Inventory',
|
||||
type: 'lookup',
|
||||
sourceModel: 'inventory',
|
||||
sourceField: 'name',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
ngClick: 'lookUpInventory()'
|
||||
}
|
||||
},
|
||||
|
||||
buttons: { //for now always generates <button> tags
|
||||
save: {
|
||||
label: 'Save',
|
||||
icon: 'icon-ok',
|
||||
class: 'btn btn-success',
|
||||
ngClick: 'formSave()', //$scope.function to call on click, optional
|
||||
ngDisabled: true //Disable when $pristine or $invalid, optional
|
||||
},
|
||||
reset: {
|
||||
ngClick: 'formReset()',
|
||||
label: 'Reset',
|
||||
icon: 'icon-remove',
|
||||
class: 'btn',
|
||||
ngDisabled: true //Disabled when $pristine
|
||||
}
|
||||
},
|
||||
|
||||
related: { //related colletions (and maybe items?)
|
||||
|
||||
}
|
||||
|
||||
}); //UserForm
|
||||
|
||||
108
lib/ui/static/js/forms/Inventories.js
Normal file
108
lib/ui/static/js/forms/Inventories.js
Normal file
@@ -0,0 +1,108 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Inventories.js
|
||||
* Form definition for User model
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('InventoryFormDefinition', [])
|
||||
.value(
|
||||
'InventoryForm', {
|
||||
|
||||
addTitle: 'Create Inventory', //Legend in add mode
|
||||
editTitle: '{{ name }}', //Legend in edit mode
|
||||
name: 'inventory',
|
||||
well: true,
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
label: 'Name',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
capitalize: true
|
||||
},
|
||||
description: {
|
||||
label: 'Description',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
},
|
||||
organization: {
|
||||
label: 'Organization',
|
||||
type: 'lookup',
|
||||
sourceModel: 'organization',
|
||||
sourceField: 'name',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
ngClick: 'lookUpOrganization()'
|
||||
}
|
||||
},
|
||||
|
||||
buttons: { //for now always generates <button> tags
|
||||
save: {
|
||||
label: 'Save',
|
||||
icon: 'icon-ok',
|
||||
class: 'btn btn-success',
|
||||
ngClick: 'formSave()', //$scope.function to call on click, optional
|
||||
ngDisabled: true //Disable when $pristine or $invalid, optional
|
||||
},
|
||||
reset: {
|
||||
ngClick: 'formReset()',
|
||||
label: 'Reset',
|
||||
icon: 'icon-remove',
|
||||
class: 'btn',
|
||||
ngDisabled: true //Disabled when $pristine
|
||||
}
|
||||
},
|
||||
|
||||
related: { //related colletions (and maybe items?)
|
||||
|
||||
hosts: {
|
||||
type: 'collection',
|
||||
title: 'Hosts',
|
||||
iterator: 'host',
|
||||
open: false,
|
||||
|
||||
actions: {
|
||||
add: {
|
||||
ngClick: "add('hosts')",
|
||||
icon: 'icon-plus',
|
||||
awToolTip: 'Create a new host'
|
||||
},
|
||||
},
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Description'
|
||||
}
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
edit: {
|
||||
ngClick: "edit('hosts', \{\{ host.id \}\}, '\{\{ host.name \}\}')",
|
||||
icon: 'icon-edit',
|
||||
awToolTip: 'Edit host'
|
||||
},
|
||||
delete: {
|
||||
ngClick: "delete('hosts', \{\{ host.id \}\}, '\{\{ host.name \}\}', 'hosts')",
|
||||
icon: 'icon-remove',
|
||||
class: 'btn-danger',
|
||||
awToolTip: 'Create a new host'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
groups: {
|
||||
type: 'tree',
|
||||
title: 'Groups',
|
||||
open: true
|
||||
}
|
||||
}
|
||||
}); //InventoryForm
|
||||
|
||||
128
lib/ui/static/js/forms/Organizations.js
Normal file
128
lib/ui/static/js/forms/Organizations.js
Normal file
@@ -0,0 +1,128 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Organization.js
|
||||
* Form definition for Organization model
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('OrganizationFormDefinition', [])
|
||||
.value(
|
||||
'OrganizationForm', {
|
||||
|
||||
addTitle: 'Create Organization', //Title in add mode
|
||||
editTitle: '{{ name }}', //Title in edit mode
|
||||
name: 'organization', //entity or model name in singular form
|
||||
well: true, //Wrap the form with TB well/
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
label: 'Name',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
capitalize: true
|
||||
},
|
||||
description: {
|
||||
label: 'Description',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
}
|
||||
},
|
||||
|
||||
buttons: { //for now always generates <button> tags
|
||||
save: {
|
||||
label: 'Save',
|
||||
icon: 'icon-ok',
|
||||
class: 'btn btn-success',
|
||||
ngClick: 'formSave()', //$scope.function to call on click, optional
|
||||
ngDisabled: true //Disable when $pristine or $invalid, optional
|
||||
},
|
||||
reset: {
|
||||
ngClick: 'formReset()',
|
||||
label: 'Reset',
|
||||
icon: 'icon-remove',
|
||||
class: 'btn',
|
||||
ngDisabled: true //Disabled when $pristine
|
||||
}
|
||||
},
|
||||
|
||||
related: { //related colletions (and maybe items?)
|
||||
|
||||
users: {
|
||||
type: 'collection',
|
||||
title: 'Users',
|
||||
iterator: 'user',
|
||||
open: false,
|
||||
|
||||
actions: {
|
||||
add: {
|
||||
ngClick: "add('users')",
|
||||
icon: 'icon-plus'
|
||||
},
|
||||
},
|
||||
|
||||
fields: {
|
||||
username: {
|
||||
key: true,
|
||||
label: 'Username'
|
||||
},
|
||||
first_name: {
|
||||
label: 'First Name'
|
||||
},
|
||||
last_name: {
|
||||
label: 'Last Name'
|
||||
}
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
edit: {
|
||||
ngClick: "edit('users', \{\{ user.id \}\}, '\{\{ user.username \}\}')",
|
||||
icon: 'icon-edit'
|
||||
},
|
||||
delete: {
|
||||
ngClick: "delete('users', \{\{ user.id \}\}, '\{\{ user.username \}\}', 'users')",
|
||||
icon: 'icon-remove',
|
||||
class: 'btn-danger'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
admins: { // Assumes a plural name (e.g. things)
|
||||
type: 'collection',
|
||||
title: 'Administrators',
|
||||
iterator: 'admin', // Singular form of name (e.g. thing)
|
||||
open: false, // Open accordion on load?
|
||||
actions: { // Actions displayed top right of list
|
||||
add: {
|
||||
ngClick: "add('admins')",
|
||||
icon: 'icon-plus'
|
||||
}
|
||||
},
|
||||
fields: {
|
||||
username: {
|
||||
key: true,
|
||||
label: 'Username'
|
||||
},
|
||||
first_name: {
|
||||
label: 'First Name'
|
||||
},
|
||||
last_name: {
|
||||
label: 'Last Name'
|
||||
}
|
||||
},
|
||||
fieldActions: { // Actions available on each row
|
||||
delete: {
|
||||
ngClick: "delete('admins', \{\{ admin.id \}\}, '\{\{ admin.username \}\}', 'administrators')",
|
||||
icon: 'icon-remove',
|
||||
class: 'btn-danger'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}); //OrganizationForm
|
||||
|
||||
|
||||
65
lib/ui/static/js/forms/Teams.js
Normal file
65
lib/ui/static/js/forms/Teams.js
Normal file
@@ -0,0 +1,65 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Teams.js
|
||||
* Form definition for Team model
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('TeamFormDefinition', [])
|
||||
.value(
|
||||
'TeamForm', {
|
||||
|
||||
addTitle: 'Create Team', //Legend in add mode
|
||||
editTitle: '{{ name }}', //Legend in edit mode
|
||||
name: 'team',
|
||||
well: true,
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
label: 'Name',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
capitalize: true
|
||||
},
|
||||
description: {
|
||||
label: 'Description',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
},
|
||||
organization: {
|
||||
label: 'Organization',
|
||||
type: 'lookup',
|
||||
sourceModel: 'organization',
|
||||
sourceField: 'name',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
ngClick: 'lookUpOrganization()'
|
||||
}
|
||||
},
|
||||
|
||||
buttons: { //for now always generates <button> tags
|
||||
save: {
|
||||
label: 'Save',
|
||||
icon: 'icon-ok',
|
||||
class: 'btn btn-success',
|
||||
ngClick: 'formSave()', //$scope.function to call on click, optional
|
||||
ngDisabled: true //Disable when $pristine or $invalid, optional
|
||||
},
|
||||
reset: {
|
||||
ngClick: 'formReset()',
|
||||
label: 'Reset',
|
||||
icon: 'icon-remove',
|
||||
class: 'btn',
|
||||
ngDisabled: true //Disabled when $pristine
|
||||
}
|
||||
},
|
||||
|
||||
related: { //related colletions (and maybe items?)
|
||||
|
||||
}
|
||||
|
||||
}); //InventoryForm
|
||||
|
||||
175
lib/ui/static/js/forms/Users.js
Normal file
175
lib/ui/static/js/forms/Users.js
Normal file
@@ -0,0 +1,175 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Users.js
|
||||
* Form definition for User model
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('UserFormDefinition', [])
|
||||
.value(
|
||||
'UserForm', {
|
||||
|
||||
addTitle: 'Create User', //Legend in add mode
|
||||
editTitle: '{{ username }}', //Legend in edit mode
|
||||
name: 'user', //Form name attribute
|
||||
well: true, //Wrap the form with TB well
|
||||
|
||||
fields: {
|
||||
username: {
|
||||
label: 'Username',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
},
|
||||
first_name: {
|
||||
label: 'First Name',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
capitalize: true
|
||||
},
|
||||
last_name: {
|
||||
label: 'Last Name',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
capitalize: true
|
||||
},
|
||||
email: {
|
||||
label: 'Email',
|
||||
type: 'email',
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
},
|
||||
password: {
|
||||
label: 'Password',
|
||||
type: 'password',
|
||||
addRequired: true,
|
||||
editRequired: false,
|
||||
ngChange: 'clearPWConfirm()'
|
||||
},
|
||||
password_confirm: {
|
||||
label: 'Confirm Password',
|
||||
type: 'password',
|
||||
addRequired: false,
|
||||
editRequired: false,
|
||||
awPassMatch: true
|
||||
},
|
||||
is_superuser: {
|
||||
label: 'Superuser?',
|
||||
type: 'checkbox',
|
||||
trueValue: 'true',
|
||||
falseValue: 'false',
|
||||
default: 'false',
|
||||
ngShow: "current_user['is_superuser'] == true"
|
||||
}
|
||||
},
|
||||
|
||||
buttons: { //for now always generates <button> tags
|
||||
save: {
|
||||
label: 'Save',
|
||||
icon: 'icon-ok',
|
||||
class: 'btn btn-success',
|
||||
ngClick: 'formSave()', //$scope.function to call on click, optional
|
||||
ngDisabled: true //Disable when $pristine or $invalid, optional
|
||||
},
|
||||
reset: {
|
||||
ngClick: 'formReset()',
|
||||
label: 'Reset',
|
||||
icon: 'icon-remove',
|
||||
class: 'btn',
|
||||
ngDisabled: true //Disabled when $pristine
|
||||
}
|
||||
},
|
||||
|
||||
related: { //related colletions (and maybe items?)
|
||||
admin_of_organizations: { // Assumes a plural name (e.g. things)
|
||||
type: 'collection',
|
||||
title: 'Admin of Organizations',
|
||||
iterator: 'adminof', // Singular form of name (e.g. thing)
|
||||
open: false, // Open accordion on load?
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Description'
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
organizations: {
|
||||
type: 'collection',
|
||||
title: 'Organizations',
|
||||
iterator: 'organization',
|
||||
open: false,
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Description'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
teams: {
|
||||
type: 'collection',
|
||||
title: 'Teams',
|
||||
iterator: 'team',
|
||||
open: false,
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Description'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
projects: {
|
||||
type: 'collection',
|
||||
title: 'Projects',
|
||||
iterator: 'project',
|
||||
open: false,
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Description'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
credentials: {
|
||||
type: 'collection',
|
||||
title: 'Credentials',
|
||||
iterator: 'credential',
|
||||
open: false,
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Description'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
}); //UserForm
|
||||
|
||||
89
lib/ui/static/js/helpers/api-defaults.js
Normal file
89
lib/ui/static/js/helpers/api-defaults.js
Normal file
@@ -0,0 +1,89 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* APIDefaults
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('APIDefaults', ['RestServices', 'Utilities'])
|
||||
.factory('GetAPIDefaults', ['Alert', 'Rest', '$rootScope', function(Alert, Rest, $rootScope) {
|
||||
return function(key) {
|
||||
|
||||
//Reload a related collection on pagination or search change
|
||||
|
||||
var answer;
|
||||
var result = {};
|
||||
var cnt=0;
|
||||
|
||||
function lookup(key) {
|
||||
var result = {};
|
||||
for (id in $rootScope.apiDefaults) {
|
||||
if (id == key || id.iterator == key) {
|
||||
result[id] = defaults[id];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function wait() {
|
||||
var answer;
|
||||
if ( result == {} && cnt < 5) {
|
||||
cnt++;
|
||||
setTimeout(1000, wait());
|
||||
}
|
||||
else {
|
||||
if (result.status == 'success') {
|
||||
return lookup(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($rootScope.apiDefaults == null || $rootScope.apiDefaults == undefined) {
|
||||
var result = {};
|
||||
var url = '/api/v1';
|
||||
Rest.setUrl(url);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
defaults = data;
|
||||
for (var id in defaults) {
|
||||
switch (id) {
|
||||
case 'organizations':
|
||||
dafaults[id].iterator = 'organization';
|
||||
break;
|
||||
case 'jobs':
|
||||
defaults[id].iterator = 'job';
|
||||
break;
|
||||
case 'users':
|
||||
defaults[id].iterator = 'user';
|
||||
break;
|
||||
case 'teams':
|
||||
defaults[id].iterator = 'team';
|
||||
break;
|
||||
case 'hosts':
|
||||
defaults[id].iterator = 'host';
|
||||
break;
|
||||
case 'groups':
|
||||
defaults[id].iterator = 'group';
|
||||
break;
|
||||
case 'projects':
|
||||
defaults[id].iterator = 'project';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$rootScope.apiDefaults = defaults;
|
||||
result = {status: 'success'};
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
result = {status: 'error', msg: 'Call to ' + url + ' failed. GET returned status: ' + status};
|
||||
});
|
||||
return wait();
|
||||
}
|
||||
else {
|
||||
return lookup(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}]);
|
||||
58
lib/ui/static/js/helpers/hosts.js
Normal file
58
lib/ui/static/js/helpers/hosts.js
Normal file
@@ -0,0 +1,58 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Helper
|
||||
* Routines shared amongst the hosts controllers
|
||||
*/
|
||||
|
||||
angular.module('HostHelper', [ 'RestServices', 'Utilities', 'OrganizationListDefinition',
|
||||
'SearchHelper', 'PaginateHelper', 'ListGenerator' ])
|
||||
|
||||
.factory('LookUpInventoryInit', ['Alert', 'Rest', 'InventoryList', 'GenerateList', 'SearchInit', 'PaginateInit',
|
||||
function(Alert, Rest, InventoryList, GenerateList, SearchInit, PaginateInit) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
|
||||
// Show pop-up to select organization
|
||||
scope.lookUpInventory = function() {
|
||||
var list = InventoryList;
|
||||
var listGenerator = GenerateList;
|
||||
var listScope = listGenerator.inject(list, { mode: 'lookup', hdr: 'Select Inventory' });
|
||||
var defaultUrl = '/api/v1/inventories';
|
||||
|
||||
listScope.selectAction = function() {
|
||||
var found = false;
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
if (listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] == "success") {
|
||||
found = true;
|
||||
scope['inventory'] = listScope[list.name][i].id;
|
||||
scope['inventory_name'] = listScope[list.name][i].name;
|
||||
scope['host_form'].$setDirty();
|
||||
listGenerator.hide();
|
||||
}
|
||||
}
|
||||
if (found == false) {
|
||||
Alert('No Selection', 'Click on a row to select an Inventory before clicking the Select button.');
|
||||
}
|
||||
}
|
||||
|
||||
listScope.toggle_inventory = function(id) {
|
||||
// when user clicks a row, remove 'success' class from all rows except clicked-on row
|
||||
if (listScope[list.name]) {
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] = "";
|
||||
}
|
||||
}
|
||||
if (id != null && id != undefined) {
|
||||
listScope[list.iterator + "_" + id + "_class"] = "success";
|
||||
}
|
||||
}
|
||||
|
||||
SearchInit({ scope: listScope, set: list.name, list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: listScope, list: list, url: defaultUrl, mode: 'lookup' });
|
||||
scope.search(list.iterator);
|
||||
listScope.toggle_inventory(scope.inventory);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
129
lib/ui/static/js/helpers/inventory.js
Normal file
129
lib/ui/static/js/helpers/inventory.js
Normal file
@@ -0,0 +1,129 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* InventoryHelper
|
||||
* Routines shared amongst the inventory controllers
|
||||
*/
|
||||
|
||||
angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationListDefinition',
|
||||
'SearchHelper', 'PaginateHelper', 'ListGenerator' ])
|
||||
.factory('SetListeners', ['Alert', 'Rest', function(Alert, Rest) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var set = params.set;
|
||||
var iterator = params.iterator;
|
||||
|
||||
// Listeners to perform lookups after main inventory list loads
|
||||
|
||||
scope.$on('resultFound', function(e, results, lookup_results) {
|
||||
if ( lookup_results.length == results.length ) {
|
||||
key = 'organization';
|
||||
property = 'organization_name';
|
||||
for (var i=0; i < results.length; i++) {
|
||||
for (var j=0; j < lookup_results.length; j++) {
|
||||
if (results[i][key] == lookup_results[j].id) {
|
||||
results[i][property] = lookup_results[j].value;
|
||||
}
|
||||
}
|
||||
}
|
||||
scope[iterator + 'SearchSpin'] = false;
|
||||
scope[set] = results;
|
||||
}
|
||||
});
|
||||
|
||||
scope.$on('refreshFinished', function(e, results) {
|
||||
// Loop through the result set (sent to us by the search helper) and
|
||||
// lookup the id and name of each organization. After each lookup
|
||||
// completes, call resultFound.
|
||||
|
||||
var lookup_results = [];
|
||||
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
Rest.setUrl('/api/v1/organizations/' + results[i].organization + '/');
|
||||
Rest.get()
|
||||
.success( function( data, status, headers, config) {
|
||||
lookup_results.push({ id: data.id, value: data.name });
|
||||
scope.$emit('resultFound', results, lookup_results);
|
||||
})
|
||||
.error( function( data, status, headers, config) {
|
||||
lookup_results.push({ id: 'error' });
|
||||
scope.$emit('resultFound', results, lookup_results);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}])
|
||||
|
||||
.factory('LookUpOrganizationInit', ['Alert', 'Rest', 'OrganizationList', 'GenerateList', 'SearchInit', 'PaginateInit',
|
||||
function(Alert, Rest, OrganizationList, GenerateList, SearchInit, PaginateInit) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
|
||||
// Show pop-up to select organization
|
||||
scope.lookUpOrganization = function() {
|
||||
var list = OrganizationList;
|
||||
var listGenerator = GenerateList;
|
||||
var listScope = listGenerator.inject(list, { mode: 'lookup', hdr: 'Select Organization' });
|
||||
var defaultUrl = '/api/v1/organizations';
|
||||
|
||||
listScope.selectAction = function() {
|
||||
var found = false;
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
if (listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] == "success") {
|
||||
found = true;
|
||||
scope['organization'] = listScope[list.name][i].id;
|
||||
scope['organization_name'] = listScope[list.name][i].name;
|
||||
scope['inventory_form'].$setDirty();
|
||||
listGenerator.hide();
|
||||
}
|
||||
}
|
||||
if (found == false) {
|
||||
Alert('No Selection', 'Click on a row to select an Organization before clicking the Select button.');
|
||||
}
|
||||
}
|
||||
|
||||
listScope.toggle_organization = function(id) {
|
||||
// when user clicks a row, remove 'success' class from all rows except clicked-on row
|
||||
if (listScope[list.name]) {
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] = "";
|
||||
}
|
||||
}
|
||||
if (id != null && id != undefined) {
|
||||
listScope[list.iterator + "_" + id + "_class"] = "success";
|
||||
}
|
||||
}
|
||||
|
||||
SearchInit({ scope: listScope, set: list.name, list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: listScope, list: list, url: defaultUrl, mode: 'lookup' });
|
||||
scope.search(list.iterator);
|
||||
listScope.toggle_organization(scope.organization);
|
||||
}
|
||||
}
|
||||
}])
|
||||
|
||||
.factory('TreeInit', ['Alert', 'Rest', function(Alert, Rest) {
|
||||
return function(groups) {
|
||||
Rest.setUrl(groups);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
var treeData = [];
|
||||
for (var i=0; i < data.results.length; i++) {
|
||||
treeData.push({
|
||||
data: data.results[i].name,
|
||||
state: 'closed',
|
||||
attr: { id: data.results[i] }
|
||||
});
|
||||
}
|
||||
$('#tree-view').jstree({ "json_data": { data: treeData },
|
||||
plugins: ['themes', 'json_data', 'ui'] });
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
Alert('Error', 'Failed to laod tree data. Url: ' + groups + ' GET status: ' + status);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
|
||||
51
lib/ui/static/js/helpers/paginate.js
Normal file
51
lib/ui/static/js/helpers/paginate.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* PaginateHelper
|
||||
*
|
||||
* All the parts for controlling the search widget on
|
||||
* related collections.
|
||||
*
|
||||
* PaginateInit({
|
||||
* scope: <scope>,
|
||||
* list: <form object used by FormGenerator>
|
||||
* url: <
|
||||
* });
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('PaginateHelper', ['RefreshHelper'])
|
||||
.factory('PaginateInit', [ 'Refresh', function(Refresh) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var list = params.list;
|
||||
var defaultUrl = params.url;
|
||||
var mode = (params.mode) ? params.mode : null;
|
||||
|
||||
scope[list.iterator + 'Page'] = 0;
|
||||
|
||||
if (mode == 'lookup') {
|
||||
scope[list.iterator + 'PageSize'] = 5;
|
||||
}
|
||||
else {
|
||||
scope[list.iterator + 'PageSize'] = 20;
|
||||
}
|
||||
|
||||
scope.nextSet = function(set, iterator) {
|
||||
scope[iterator + 'Page']++;
|
||||
Refresh({ scope: scope, set: set, iterator: iterator, url: scope[iterator + 'NextUrl'] });
|
||||
};
|
||||
|
||||
scope.prevSet = function(set, iterator) {
|
||||
scope[iterator + 'Page']--;
|
||||
Refresh({ scope: scope, set: set, iterator: iterator, url: scope[iterator + 'PrevUrl'] });
|
||||
};
|
||||
|
||||
scope.changePageSize = function(set, iterator) {
|
||||
// Called when a new page size is selected
|
||||
scope[iterator + 'Page'] = 0;
|
||||
Refresh({ scope: scope, set: set, iterator: iterator, url: defaultUrl });
|
||||
}
|
||||
}
|
||||
}]);
|
||||
43
lib/ui/static/js/helpers/refresh-related.js
Normal file
43
lib/ui/static/js/helpers/refresh-related.js
Normal file
@@ -0,0 +1,43 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* RefreshRelatedHelper
|
||||
*
|
||||
* Used to refresh a related set whenever pagination or filter options change.
|
||||
*
|
||||
* RefreshRelated({
|
||||
* scope: <current scope>,
|
||||
* set: <model>,
|
||||
* iterator: <model name in singular form (i.e. organization),
|
||||
* url: <the api url to call>
|
||||
* });
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('RefreshRelatedHelper', ['RestServices', 'Utilities'])
|
||||
.factory('RefreshRelated', ['Alert', 'Rest', function(Alert, Rest) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var set = params.set;
|
||||
var iterator = params.iterator;
|
||||
var url = params.url;
|
||||
|
||||
url.replace(/page_size\=\d+/,''); //stop repeatedly appending page_size
|
||||
|
||||
Rest.setUrl(url);
|
||||
Rest.get({ params: { page_size: scope[iterator + 'PageSize'] }})
|
||||
.success( function(data, status, headers, config) {
|
||||
scope[set] = data['results'];
|
||||
scope[iterator + 'NextUrl'] = data.next;
|
||||
scope[iterator + 'PrevUrl'] = data.previous;
|
||||
scope[iterator + 'Count'] = data.count;
|
||||
scope[iterator + 'PageCount'] = Math.ceil((data.count / scope[iterator + 'PageSize']));
|
||||
scope[iterator + 'SearchSpin'] = false;
|
||||
})
|
||||
.error ( function(data, status, headers, config) {
|
||||
scope[iterator + 'SearchSpin'] = true;
|
||||
Alert('Error!', 'Failed to retrieve related set: ' + set + '. GET returned status: ' + status);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
53
lib/ui/static/js/helpers/refresh.js
Normal file
53
lib/ui/static/js/helpers/refresh.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* RefreshHelper
|
||||
*
|
||||
* Used to refresh a related set whenever pagination or filter options change.
|
||||
*
|
||||
* RefreshRelated({
|
||||
* scope: <current scope>,
|
||||
* set: <model>,
|
||||
* iterator: <model name in singular form (i.e. organization),
|
||||
* url: <the api url to call>
|
||||
* });
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('RefreshHelper', ['RestServices', 'Utilities'])
|
||||
.factory('Refresh', ['Alert', 'Rest', function(Alert, Rest) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var set = params.set;
|
||||
var iterator = params.iterator;
|
||||
var url = params.url;
|
||||
|
||||
url.replace(/page_size\=\d+/,''); //stop repeatedly appending page_size
|
||||
url += scope[iterator + 'SearchParams'];
|
||||
Rest.setUrl(url);
|
||||
Rest.get({ params: { page_size: scope[iterator + 'PageSize'] }})
|
||||
.success( function(data, status, headers, config) {
|
||||
scope[iterator + 'NextUrl'] = data.next;
|
||||
scope[iterator + 'PrevUrl'] = data.previous;
|
||||
scope[iterator + 'Count'] = data.count;
|
||||
scope[iterator + 'PageCount'] = Math.ceil((data.count / scope[iterator + 'PageSize']));
|
||||
if (set == 'inventories') {
|
||||
lookup_results = [];
|
||||
scope.$emit('refreshFinished', data['results']);
|
||||
}
|
||||
else if (set == 'teams') {
|
||||
lookup_results = [];
|
||||
scope.$emit('TeamRefreshFinished', data['results']);
|
||||
}
|
||||
else {
|
||||
scope[iterator + 'SearchSpin'] = false;
|
||||
scope[set] = data['results'];
|
||||
}
|
||||
})
|
||||
.error ( function(data, status, headers, config) {
|
||||
scope[iterator + 'SearchSpin'] = true;
|
||||
Alert('Error!', 'Failed to retrieve ' + set + '. GET returned status: ' + status);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
52
lib/ui/static/js/helpers/related-paginate.js
Normal file
52
lib/ui/static/js/helpers/related-paginate.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* RelatedPaginateHelper
|
||||
*
|
||||
* All the parts for controlling the search widget on
|
||||
* related collections.
|
||||
*
|
||||
* RelatedPaginateInit({
|
||||
* scope: <scope>,
|
||||
* relatedSets: <array of related collections {model_name, url, iterator}>,
|
||||
* form: <form object used by FormGenerator>
|
||||
* });
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('RelatedPaginateHelper', ['RefreshRelatedHelper'])
|
||||
.factory('RelatedPaginateInit', [ 'RefreshRelated', function(RefreshRelated) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var relatedSets = params.relatedSets;
|
||||
|
||||
for (var key in relatedSets){
|
||||
scope[relatedSets[key].iterator + 'Page'] = 0;
|
||||
scope[relatedSets[key].iterator + 'PageSize'] = 20;
|
||||
}
|
||||
|
||||
scope.nextSet = function(set, iterator) {
|
||||
scope[iterator + 'Page']++;
|
||||
RefreshRelated({ scope: scope, set: set, iterator: iterator, url: scope[iterator + 'NextUrl'] });
|
||||
};
|
||||
|
||||
scope.prevSet = function(set, iterator) {
|
||||
scope[iterator + 'Page']--;
|
||||
RefreshRelated({ scope: scope, set: set, iterator: iterator, url: scope[iterator + 'PrevUrl'] });
|
||||
};
|
||||
|
||||
scope.changePageSize = function(set, iterator) {
|
||||
// Called when a new page size is selected
|
||||
var defaultUrl;
|
||||
scope[iterator + 'Page'] = 0;
|
||||
for (var key in relatedSets) {
|
||||
if (key == set) {
|
||||
defaultUrl = relatedSets[key].url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RefreshRelated({ scope: scope, set: set, iterator: iterator, url: defaultUrl });
|
||||
}
|
||||
}
|
||||
}]);
|
||||
80
lib/ui/static/js/helpers/related-search.js
Normal file
80
lib/ui/static/js/helpers/related-search.js
Normal file
@@ -0,0 +1,80 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* RelatedSearchHelper
|
||||
*
|
||||
* All the parts for controlling the search widget on
|
||||
* related collections.
|
||||
*
|
||||
* SearchInit({
|
||||
* scope: <scope>,
|
||||
* relatedSets: <array of related collections {model_name, url, iterator}>,
|
||||
* form: <form object used by FormGenerator>
|
||||
* });
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('RelatedSearchHelper', ['RestServices', 'Utilities','RefreshRelatedHelper'])
|
||||
.factory('RelatedSearchInit', ['Alert', 'Rest', 'RefreshRelated', function(Alert, Rest, RefreshRelated) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var relatedSets = params.relatedSets;
|
||||
var form = params.form;
|
||||
|
||||
// Set default values
|
||||
for (var set in form.related) {
|
||||
for (var fld in form.related[set].fields) {
|
||||
if (form.related[set].fields[fld].key) {
|
||||
scope[form.related[set].iterator + 'SearchField'] = fld
|
||||
scope[form.related[set].iterator + 'SearchFieldLabel'] = form.related[set].fields[fld].label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
scope[form.related[set].iterator + 'SearchType'] = 'contains';
|
||||
scope[form.related[set].iterator + 'SearchTypeLabel'] = 'Contains';
|
||||
}
|
||||
|
||||
// Functions to handle search widget changes
|
||||
scope.setSearchField = function(model, fld, label) {
|
||||
scope[model + 'SearchFieldLabel'] = label;
|
||||
scope[model + 'SearchField'] = fld;
|
||||
scope.search(model);
|
||||
}
|
||||
|
||||
scope.setSearchType = function(model, type, label) {
|
||||
scope[model + 'SearchTypeLabel'] = label;
|
||||
scope[model + 'SearchType'] = type;
|
||||
scope.search(model);
|
||||
}
|
||||
|
||||
scope.search = function(model) {
|
||||
scope[model + 'SearchSpin'] = true;
|
||||
var set, url, iterator, default_order;
|
||||
for (var key in relatedSets) {
|
||||
if (relatedSets[key].iterator == model) {
|
||||
set = key;
|
||||
iterator = relatedSets[key].iterator;
|
||||
url = relatedSets[key].url;
|
||||
|
||||
for (var fld in form.related[key].fields) {
|
||||
if (form.related[key].fields[fld].key) {
|
||||
default_order = fld;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (scope[model + 'SearchValue'] != '' && scope[model + 'SearchValue'] != undefined) {
|
||||
url += '?' + scope[model + 'SearchField'] +
|
||||
'__' + scope[model + 'SearchType'] + '=' + escape(scope[model + 'SearchValue']);
|
||||
url += (default_order) ? '&order_by=' + escape(default_order) : '';
|
||||
}
|
||||
else {
|
||||
url += (default_order) ? '?order_by=' + escape(default_order) : '';
|
||||
}
|
||||
RefreshRelated({ scope: scope, set: set, iterator: iterator, url: url });
|
||||
}
|
||||
}
|
||||
}]);
|
||||
84
lib/ui/static/js/helpers/search.js
Normal file
84
lib/ui/static/js/helpers/search.js
Normal file
@@ -0,0 +1,84 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* SearchHelper
|
||||
*
|
||||
* All the parts for controlling the search widget on
|
||||
* related collections.
|
||||
*
|
||||
* SearchInit({
|
||||
* scope: <scope>,
|
||||
* set: <model name (i.e. organizations),
|
||||
* name was given in ng-repeat>
|
||||
* url: <default api url used to load data>
|
||||
* list: <list object used by ListGenerator>
|
||||
* });
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('SearchHelper', ['RestServices', 'Utilities', 'RefreshHelper'])
|
||||
.factory('SearchInit', ['Alert', 'Rest', 'Refresh', function(Alert, Rest, Refresh) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var set = params.set;
|
||||
var defaultUrl = params.url;
|
||||
var list = params.list;
|
||||
var iterator = list.iterator;
|
||||
var default_order;
|
||||
|
||||
// Set default values
|
||||
for (fld in list.fields) {
|
||||
if (list.fields[fld].key) {
|
||||
default_order = fld;
|
||||
scope[iterator + 'SearchField'] = fld
|
||||
scope[iterator + 'SearchFieldLabel'] = list.fields[fld].label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
scope[iterator + 'SearchType'] = 'icontains';
|
||||
scope[iterator + 'SearchTypeLabel'] = 'Contains';
|
||||
scope[iterator + 'SearchParams'] = '';
|
||||
scope[iterator + 'SearchValue'] = '';
|
||||
|
||||
// Functions to handle search widget changes
|
||||
scope.setSearchField = function(iterator, fld, label) {
|
||||
scope[iterator + 'SearchFieldLabel'] = label;
|
||||
scope[iterator + 'SearchField'] = fld;
|
||||
scope.search(iterator);
|
||||
}
|
||||
|
||||
scope.setSearchType = function(iterator, type, label) {
|
||||
scope[iterator + 'SearchTypeLabel'] = label;
|
||||
scope[iterator + 'SearchType'] = type;
|
||||
scope.search(iterator);
|
||||
}
|
||||
|
||||
scope.search = function(iterator) {
|
||||
//
|
||||
// need to be able to search by related set. Ex: /api/v1/inventories/?organization__name__icontains=
|
||||
//
|
||||
scope[iterator + 'SearchSpin'] = true;
|
||||
var url = defaultUrl;
|
||||
if (scope[iterator + 'SearchValue'] != '' && scope[iterator + 'SearchValue'] != undefined) {
|
||||
if (list.fields[scope[iterator + 'SearchField']].sourceModel) {
|
||||
// handle fields whose source is a related model e.g. inventories.organization
|
||||
scope[iterator + 'SearchParams'] = '?' + list.fields[scope[iterator + 'SearchField']].sourceModel + '__' +
|
||||
list.fields[scope[iterator + 'SearchField']].sourceField + '__' +
|
||||
scope[iterator + 'SearchType'] + '=' + escape(scope[iterator + 'SearchValue']);
|
||||
scope[iterator + 'SearchParams'] += (default_order) ? '&order_by=' + escape(default_order) : '';
|
||||
}
|
||||
else {
|
||||
scope[iterator + 'SearchParams'] = '?' + scope[iterator + 'SearchField'] + '__' +
|
||||
scope[iterator + 'SearchType'] + '=' + escape(scope[iterator + 'SearchValue']);
|
||||
scope[iterator + 'SearchParams'] += (default_order) ? '&order_by=' + escape(default_order) : '';
|
||||
}
|
||||
}
|
||||
else {
|
||||
scope[iterator + 'SearchParams'] = '';
|
||||
scope[iterator + 'SearchParams'] += (default_order) ? '?order_by=' + escape(default_order) : '';
|
||||
}
|
||||
Refresh({ scope: scope, set: set, iterator: iterator, url: url });
|
||||
}
|
||||
}
|
||||
}]);
|
||||
109
lib/ui/static/js/helpers/teams.js
Normal file
109
lib/ui/static/js/helpers/teams.js
Normal file
@@ -0,0 +1,109 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* TeamHelper
|
||||
* Routines shared amongst the team controllers
|
||||
*/
|
||||
|
||||
angular.module('TeamHelper', [ 'RestServices', 'Utilities', 'OrganizationListDefinition',
|
||||
'SearchHelper', 'PaginateHelper', 'ListGenerator' ])
|
||||
.factory('SetTeamListeners', ['Alert', 'Rest', function(Alert, Rest) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var set = params.set;
|
||||
var iterator = params.iterator;
|
||||
|
||||
// Listeners to perform lookups after main inventory list loads
|
||||
|
||||
scope.$on('TeamResultFound', function(e, results, lookup_results) {
|
||||
if ( lookup_results.length == results.length ) {
|
||||
key = 'organization';
|
||||
property = 'organization_name';
|
||||
for (var i=0; i < results.length; i++) {
|
||||
for (var j=0; j < lookup_results.length; j++) {
|
||||
if (results[i][key] == lookup_results[j].id) {
|
||||
results[i][property] = lookup_results[j].value;
|
||||
}
|
||||
}
|
||||
}
|
||||
scope[iterator + 'SearchSpin'] = false;
|
||||
scope[set] = results;
|
||||
}
|
||||
});
|
||||
|
||||
scope.$on('TeamRefreshFinished', function(e, results) {
|
||||
// Loop through the result set (sent to us by the search helper) and
|
||||
// lookup the id and name of each organization. After each lookup
|
||||
// completes, call resultFound.
|
||||
|
||||
var lookup_results = [];
|
||||
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
Rest.setUrl('/api/v1/organizations/' + results[i].organization + '/');
|
||||
Rest.get()
|
||||
.success( function( data, status, headers, config) {
|
||||
console.log('here!');
|
||||
console.log(data);
|
||||
lookup_results.push({ id: data.id, value: data.name });
|
||||
scope.$emit('TeamResultFound', results, lookup_results);
|
||||
})
|
||||
.error( function( data, status, headers, config) {
|
||||
lookup_results.push({ id: 'error' });
|
||||
scope.$emit('TeamResultFound', results, lookup_results);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}])
|
||||
|
||||
.factory('TeamLookUpOrganizationInit', ['Alert', 'Rest', 'OrganizationList', 'GenerateList', 'SearchInit', 'PaginateInit',
|
||||
function(Alert, Rest, OrganizationList, GenerateList, SearchInit, PaginateInit) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
|
||||
// Show pop-up to select organization
|
||||
scope.lookUpOrganization = function() {
|
||||
var list = OrganizationList;
|
||||
var listGenerator = GenerateList;
|
||||
var listScope = listGenerator.inject(list, { mode: 'lookup', hdr: 'Select Organization' });
|
||||
var defaultUrl = '/api/v1/organizations';
|
||||
|
||||
listScope.selectAction = function() {
|
||||
var found = false;
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
if (listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] == "success") {
|
||||
found = true;
|
||||
scope['organization'] = listScope[list.name][i].id;
|
||||
scope['organization_name'] = listScope[list.name][i].name;
|
||||
scope['team_form'].$setDirty();
|
||||
listGenerator.hide();
|
||||
}
|
||||
}
|
||||
if (found == false) {
|
||||
Alert('No Selection', 'Click on a row to select an Organization before clicking the Select button.');
|
||||
}
|
||||
}
|
||||
|
||||
listScope.toggle_organization = function(id) {
|
||||
// when user clicks a row, remove 'success' class from all rows except clicked-on row
|
||||
if (listScope[list.name]) {
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] = "";
|
||||
}
|
||||
}
|
||||
if (id != null && id != undefined) {
|
||||
listScope[list.iterator + "_" + id + "_class"] = "success";
|
||||
}
|
||||
}
|
||||
|
||||
SearchInit({ scope: listScope, set: list.name, list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: listScope, list: list, url: defaultUrl, mode: 'lookup' });
|
||||
scope.search(list.iterator);
|
||||
listScope.toggle_organization(scope.organization);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
|
||||
37
lib/ui/static/js/lists/Admins.js
Normal file
37
lib/ui/static/js/lists/Admins.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Admins.js
|
||||
* List view object for Admins data model.
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('AdminListDefinition', [])
|
||||
.value(
|
||||
'AdminList', {
|
||||
|
||||
name: 'admins',
|
||||
iterator: 'admin',
|
||||
selectTitle: 'Add Administrators',
|
||||
editTitle: 'Admins',
|
||||
selectInstructions: 'Click the Select checkbox next to each user to be added. Click the Finished button when done.',
|
||||
|
||||
fields: {
|
||||
username: {
|
||||
key: true,
|
||||
label: 'Username'
|
||||
},
|
||||
first_name: {
|
||||
label: 'First Name'
|
||||
},
|
||||
last_name: {
|
||||
label: 'Last Name'
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
}
|
||||
});
|
||||
52
lib/ui/static/js/lists/Groups.js
Normal file
52
lib/ui/static/js/lists/Groups.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Groups.js
|
||||
* List view object for Group data model.
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('GroupListDefinition', [])
|
||||
.value(
|
||||
'GroupList', {
|
||||
|
||||
name: 'groups',
|
||||
iterator: 'group',
|
||||
selectTitle: 'Add Group',
|
||||
editTitle: 'Groups',
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Description'
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
add: {
|
||||
icon: 'icon-plus',
|
||||
mode: 'all', // One of: edit, select, all
|
||||
ngClick: 'addGroup()',
|
||||
class: 'btn btn-mini btn-success',
|
||||
awToolTip: 'Create a new group'
|
||||
}
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
edit: {
|
||||
ngClick: "editGroup(\{\{ group.id \}\})",
|
||||
icon: 'icon-edit',
|
||||
awToolTip: 'Edit group'
|
||||
},
|
||||
|
||||
delete: {
|
||||
ngClick: "deleteGroup(\{\{ group.id \}\},'\{\{ group.name \}\}')",
|
||||
icon: 'icon-remove',
|
||||
class: 'btn-danger',
|
||||
awToolTip: 'Delete group'
|
||||
}
|
||||
}
|
||||
});
|
||||
52
lib/ui/static/js/lists/Hosts.js
Normal file
52
lib/ui/static/js/lists/Hosts.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Hosts.js
|
||||
* List view object for Users data model.
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('HostListDefinition', [])
|
||||
.value(
|
||||
'HostList', {
|
||||
|
||||
name: 'hosts',
|
||||
iterator: 'host',
|
||||
selectTitle: 'Add Host',
|
||||
editTitle: 'Hosts',
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Description'
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
add: {
|
||||
icon: 'icon-plus',
|
||||
mode: 'all', // One of: edit, select, all
|
||||
ngClick: 'addHost()',
|
||||
class: 'btn btn-mini btn-success',
|
||||
awToolTip: 'Create a new host'
|
||||
}
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
edit: {
|
||||
ngClick: "editHost(\{\{ host.id \}\})",
|
||||
icon: 'icon-edit',
|
||||
awToolTip: 'Edit host'
|
||||
},
|
||||
|
||||
delete: {
|
||||
ngClick: "deleteHost(\{\{ host.id \}\},'\{\{ host.name \}\}')",
|
||||
icon: 'icon-remove',
|
||||
class: 'btn-danger',
|
||||
awToolTip: 'Delete host'
|
||||
}
|
||||
}
|
||||
});
|
||||
59
lib/ui/static/js/lists/Inventories.js
Normal file
59
lib/ui/static/js/lists/Inventories.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Inventories.js
|
||||
* List view object for Inventories data model.
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('InventoriesListDefinition', [])
|
||||
.value(
|
||||
'InventoryList', {
|
||||
|
||||
name: 'inventories',
|
||||
iterator: 'inventory',
|
||||
selectTitle: 'Add Inventories',
|
||||
editTitle: 'Inventories',
|
||||
selectInstructions: 'Check the Select checkbox next to each inventory to be added, and click Finished when done. Use the green <i class=\"icon-plus\"></i> button to create a new inventory.',
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Descriptions'
|
||||
},
|
||||
organization: {
|
||||
label: 'Organization',
|
||||
ngBind: 'inventory.organization_name',
|
||||
sourceModel: 'organization',
|
||||
sourceField: 'name'
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
add: {
|
||||
icon: 'icon-plus',
|
||||
mode: 'all', // One of: edit, select, all
|
||||
ngClick: 'addInventory()',
|
||||
class: 'btn btn-mini btn-success',
|
||||
awToolTip: 'Create a new row'
|
||||
}
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
edit: {
|
||||
ngClick: "editInventory(\{\{ inventory.id \}\})",
|
||||
icon: 'icon-edit',
|
||||
awToolTip: 'Edit'
|
||||
},
|
||||
|
||||
delete: {
|
||||
ngClick: "deleteInventory(\{\{ inventory.id \}\},'\{\{ inventory.name \}\}')",
|
||||
icon: 'icon-remove',
|
||||
class: 'btn-danger',
|
||||
awToolTip: 'Delete'
|
||||
}
|
||||
}
|
||||
});
|
||||
52
lib/ui/static/js/lists/Organizations.js
Normal file
52
lib/ui/static/js/lists/Organizations.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Organizations.js
|
||||
* List view object for Organizations data model.
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('OrganizationListDefinition', [])
|
||||
.value(
|
||||
'OrganizationList', {
|
||||
|
||||
name: 'organizations',
|
||||
iterator: 'organization',
|
||||
selectTitle: 'Add Organizations',
|
||||
editTitle: 'Organizations',
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Description'
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
add: {
|
||||
icon: 'icon-plus',
|
||||
mode: 'all', // One of: edit, select, all
|
||||
ngClick: 'addOrganization()',
|
||||
class: 'btn btn-mini btn-success',
|
||||
awToolTip: 'Create a new row'
|
||||
}
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
edit: {
|
||||
ngClick: "editOrganization(\{\{ organization.id \}\})",
|
||||
icon: 'icon-edit',
|
||||
awToolTip: 'Edit'
|
||||
},
|
||||
|
||||
delete: {
|
||||
ngClick: "deleteOrganization(\{\{ organization.id \}\},'\{\{ organization.name \}\}')",
|
||||
icon: 'icon-remove',
|
||||
class: 'btn-danger',
|
||||
awToolTip: 'Delete'
|
||||
}
|
||||
}
|
||||
});
|
||||
59
lib/ui/static/js/lists/Teams.js
Normal file
59
lib/ui/static/js/lists/Teams.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Teams.js
|
||||
* List view object for Team data model.
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('TeamsListDefinition', [])
|
||||
.value(
|
||||
'TeamList', {
|
||||
|
||||
name: 'teams',
|
||||
iterator: 'team',
|
||||
selectTitle: 'Add Team',
|
||||
editTitle: 'Teams',
|
||||
selectInstructions: 'Check the Select checkbox next to each team to be added, and click Finished when done. Use the green <i class=\"icon-plus\"></i> button to create a new team.',
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Descriptions'
|
||||
},
|
||||
organization: {
|
||||
label: 'Organization',
|
||||
ngBind: 'team.organization_name',
|
||||
sourceModel: 'organization',
|
||||
sourceField: 'name'
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
add: {
|
||||
icon: 'icon-plus',
|
||||
mode: 'all', // One of: edit, select, all
|
||||
ngClick: 'addTeam()',
|
||||
class: 'btn btn-mini btn-success',
|
||||
awToolTip: 'Create a new team'
|
||||
}
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
edit: {
|
||||
ngClick: "editTeam(\{\{ team.id \}\})",
|
||||
icon: 'icon-edit',
|
||||
awToolTip: 'Edit team'
|
||||
},
|
||||
|
||||
delete: {
|
||||
ngClick: "deleteTeam(\{\{ team.id \}\},'\{\{ team.name \}\}')",
|
||||
icon: 'icon-remove',
|
||||
class: 'btn-danger',
|
||||
awToolTip: 'Delete team'
|
||||
}
|
||||
}
|
||||
});
|
||||
57
lib/ui/static/js/lists/Users.js
Normal file
57
lib/ui/static/js/lists/Users.js
Normal file
@@ -0,0 +1,57 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Users.js
|
||||
* List view object for Users data model.
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('UserListDefinition', [])
|
||||
.value(
|
||||
'UserList', {
|
||||
|
||||
name: 'users',
|
||||
iterator: 'user',
|
||||
selectTitle: 'Add Users',
|
||||
editTitle: 'Users',
|
||||
selectInstructions: 'Check the Select checkbox next to each user to be added, and click Finished when done. Use the green <i class=\"icon-plus\"></i> button to create a new user.',
|
||||
editInstructions: 'Create new users from the Organizations tab. Each Organizaton has an associated list of Users.',
|
||||
|
||||
fields: {
|
||||
username: {
|
||||
key: true,
|
||||
label: 'Username'
|
||||
},
|
||||
first_name: {
|
||||
label: 'First Name'
|
||||
},
|
||||
last_name: {
|
||||
label: 'Last Name'
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
add: {
|
||||
icon: 'icon-plus',
|
||||
mode: 'select', // One of: edit, select, all
|
||||
ngClick: 'addUser()',
|
||||
class: 'btn btn-mini btn-success',
|
||||
awToolTip: 'Create a new row'
|
||||
}
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
edit: {
|
||||
ngClick: "editUser(\{\{ user.id \}\})",
|
||||
icon: 'icon-edit',
|
||||
awToolTip: 'Edit'
|
||||
},
|
||||
|
||||
delete: {
|
||||
ngClick: "deleteUser(\{\{ user.id \}\},'\{\{ user.username \}\}')",
|
||||
icon: 'icon-remove',
|
||||
class: 'btn-danger',
|
||||
awToolTip: 'Delete'
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user