Skip to content

Instantly share code, notes, and snippets.

@AlexanderKozhevin
Created April 16, 2016 11:38
Show Gist options
  • Save AlexanderKozhevin/7cd11ec913ab568db09e3b59920c0438 to your computer and use it in GitHub Desktop.
Save AlexanderKozhevin/7cd11ec913ab568db09e3b59920c0438 to your computer and use it in GitHub Desktop.
angular.module('eagle').factory 'second_angular', (Restangular) ->
return Restangular.withConfig (RestangularConfigurer) ->
RestangularConfigurer.setBaseUrl('http://eagletest.media.test.eagleplatform.com/api/');
RestangularConfigurer.setRequestSuffix('.json');
RestangularConfigurer.setDefaultHeaders({'Content-Type': 'application/json'});
RestangularConfigurer.setDefaultHttpFields({withCredentials: true});
RestangularConfigurer.addResponseInterceptor (data, operation, what, url, response, deferred) ->
if (data.data)
if_records = url.length - url.lastIndexOf('records')
if (if_records == 7) or (url.lastIndexOf('records/search')!=-1)
data.data.total_pages = data.total_pages
data.data.total_records = data.total_records
return data.data
else
return false
RestangularConfigurer.addRequestInterceptor (elem, operation, what, url) ->
retElem = elem;
if operation == 'post' or operation == 'put'
wrapper = {};
wrapper[what.substring(0, what.length - 1)] = elem;
retElem = wrapper;
return retElem;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment