mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-13 03:21:49 -05:00
Moved UI into its own Django app.
This commit is contained in:
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);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
Reference in New Issue
Block a user