+++ /dev/null
-/**
- * Service for communicating with the Evergreen flattener
- * web service.
- *
- * egFlattener.load({
- * hint : aou,
- * map : {shortname : shortname, parent_ou : parent_ou.shortname},
- * where : {id : {'<>' : null}}
- * slo : {offset : 0, limit : 20, order_by : ['shortname']}
- * }).then( function(data) { console.log(data) } );
- */
-angular.module('egFlattenerMod', ['egCoreMod'])
-
-.factory('egFlattener',
- ['$q','$http','egAuth',
-function($q, $http, egAuth) {
-
- var url = '/opac/extras/flattener';
-
- return {
- load : function(args) {
- args.ses = egAuth.token();
- args.format = args.format || 'application/json';
-
- angular.forEach(['map', 'where', 'slo'], function(key) {
- args[key] = js2JSON(args[key]);
- });
-
- /** angular $http uses content type application/json natively.
- * flattener / mod_perl (?) does not extract that data, so
- * we have to encode it ourselves as x-www-form-urlencoded
- * http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/
- */
- var query = 'ses=' + args.ses;
- angular.forEach(args, function(val, key) {
- if (key == 'ses' || !val) return;
- query += '&' + key + '=' + encodeURIComponent(val);
- });
-
- return $http({
- url : url,
- data : query,
- method : 'POST',
- headers : {
- 'Content-Type':
- 'application/x-www-form-urlencoded; charset=UTF-8'
- }
- });
- }
- };
-}])