LP#1511358 Patron Survey Interface
[evergreen-equinox.git] / Open-ILS / web / js / ui / default / staff / circ / patron / app.js
index 1dc380f..e075c4f 100644 (file)
@@ -214,6 +214,12 @@ angular.module('egPatronApp', ['ngRoute', 'ui.bootstrap',
         resolve : resolver
     });
 
+    $routeProvider.when('/circ/patron/:id/surveys', {
+        templateUrl: './circ/patron/t_surveys',
+        controller: 'PatronSurveyCtrl',
+        resolve : resolver
+    });
+
     $routeProvider.otherwise({redirectTo : '/circ/patron/search'});
 })
 
@@ -1633,6 +1639,33 @@ function($scope,  $routeParams , $q , egCore , patronSvc) {
     });
 }])
 
+.controller('PatronSurveyCtrl',
+       ['$scope','$routeParams','$location','egCore','patronSvc',
+function($scope,  $routeParams , $location , egCore , patronSvc) {
+    $scope.initTab('other', $routeParams.id);
+    var usr_id = $routeParams.id;
+    var org_ids = egCore.org.fullPath(egCore.auth.user().ws_ou(), true);
+    $scope.surveys = [];
+    // fetch the surveys
+    egCore.pcrud.search('asvr',
+        {usr : usr_id},
+        {flesh : 4, flesh_fields : {
+            asvr : ['question', 'survey', 'answer'],
+            asv : ['responses', 'questions'],
+            asvq : ['responses', 'question']
+    }},
+        {authoritative : true})
+    .then(null, null, function(survey) {
+        var sameSurveyId = false;
+        if (survey.survey().id() && $scope.surveys.length > 0) {
+            for (sid = 0; sid < $scope.surveys.length; sid++) {
+                if (survey.survey().id() == $scope.surveys[sid].id()) sameSurveyId = true; 
+            }
+        }
+        if (!sameSurveyId) $scope.surveys.push(survey.survey());
+    });
+}])
+
 .controller('PatronFetchLastCtrl',
        ['$scope','$location','egCore',
 function($scope , $location , egCore) {