mirror of
https://github.com/ansible/awx.git
synced 2026-04-11 13:09:21 -02:30
Major rename of package from lib to ansibleworks.
This commit is contained in:
56
ansibleworks/ui/static/lib/ansible/api-loader.js
Normal file
56
ansibleworks/ui/static/lib/ansible/api-loader.js
Normal file
@@ -0,0 +1,56 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* Read /api and /api/X to discover all the base paths needed
|
||||
* to access the primary model objects.
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('ApiLoader', ['ngCookies'])
|
||||
.factory('LoadBasePaths', ['$http', '$rootScope', '$cookieStore', 'ProcessErrors',
|
||||
function($http, $rootScope, $cookieStore, ProcessErrors) {
|
||||
return function() {
|
||||
$http.get('/api/')
|
||||
.success( function(data, status, headers, config) {
|
||||
var base = data.current_version;
|
||||
$http.get(base)
|
||||
.success( function(data, status, headers, config) {
|
||||
data['base'] = base;
|
||||
$rootScope['defaultUrls'] = data;
|
||||
$cookieStore.remove('api');
|
||||
$cookieStore.put('api',data); //Preserve in cookie to prevent against
|
||||
//loss during browser refresh
|
||||
})
|
||||
.error ( function(data, status, headers, config) {
|
||||
$rootScope['defaultUrls'] = { status: 'error' };
|
||||
ProcessErrors(null, data, status, null,
|
||||
{ hdr: 'Error', msg: 'Failed to read ' + base + '. GET status: ' + status });
|
||||
});
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$rootScope['defaultUrls'] = { status: 'error' };
|
||||
ProcessErrors(null, data, status, null,
|
||||
{ hdr: 'Error', msg: 'Failed to read /api. GET status: ' + status });
|
||||
});
|
||||
}
|
||||
}])
|
||||
|
||||
.factory('GetBasePath', ['$rootScope', '$cookieStore', 'LoadBasePaths',
|
||||
function($rootScope, $cookieStore, LoadBasePaths) {
|
||||
return function(set) {
|
||||
var answer;
|
||||
if ($rootScope['defaultUrls'] == null || $rootScope['defaultUrls'] == undefined) {
|
||||
// browser refresh must have occurred. use what's in session cookie and refresh
|
||||
answer = $cookieStore.get('api')[set];
|
||||
LoadBasePaths();
|
||||
}
|
||||
else {
|
||||
answer = $rootScope['defaultUrls'][set];
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
}]);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user