Major rename of package from lib to ansibleworks.

This commit is contained in:
Chris Church
2013-05-21 18:20:26 -04:00
parent 5133b9a30e
commit aeac739735
264 changed files with 230 additions and 316 deletions

View 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;
}
}]);