mirror of
https://github.com/ansible/awx.git
synced 2026-03-11 06:29:31 -02:30
43 lines
1.6 KiB
JavaScript
43 lines
1.6 KiB
JavaScript
/*********************************************
|
|
* Copyright (c) 2014 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', 'PaginationHelpers'])
|
|
.factory('RefreshRelated', ['ProcessErrors', 'Rest', 'Wait', 'PageRangeSetup',
|
|
function(ProcessErrors, Rest, Wait, PageRangeSetup) {
|
|
return function(params) {
|
|
|
|
var scope = params.scope;
|
|
var set = params.set;
|
|
var iterator = params.iterator;
|
|
var url = params.url;
|
|
|
|
Rest.setUrl(url);
|
|
Rest.get()
|
|
.success( function(data, status, headers, config) {
|
|
PageRangeSetup({ scope: scope, count: data.count, next: data.next, previous: data.previous, iterator: iterator });
|
|
scope[set] = data['results'];
|
|
scope[iterator + 'Loading'] = false;
|
|
scope[iterator + 'HoldInput'] = false;
|
|
Wait('stop');
|
|
scope.$emit('related' + set);
|
|
|
|
})
|
|
.error ( function(data, status, headers, config) {
|
|
ProcessErrors(scope, data, status, null,
|
|
{ hdr: 'Error!', msg: 'Failed to retrieve ' + set + '. GET returned status: ' + status });
|
|
});
|
|
}
|
|
}]); |