factory Organizations changed View
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 12 Mar 2013 20:52:18 +0000 (21:52 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 12 Mar 2013 20:52:45 +0000 (21:52 +0100)
This allows it to use any CouchDB view_url to populate data

app/js/controllers.js
app/js/services.js.ep

index 7958b69..c7a043c 100644 (file)
@@ -2,12 +2,12 @@
 
 /* Controllers */
 
 
 /* Controllers */
 
-function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, Organizations, ValidStates) {
+function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, View, ValidStates) {
 
        $scope.$routeParams = $routeParams;
        $scope.$location = $location;
        $scope.organizations = [];
 
        $scope.$routeParams = $routeParams;
        $scope.$location = $location;
        $scope.organizations = [];
-       Organizations.getArrayPromise().then(function(data) {
+       View.getArrayPromise('organizations?group=true;format=key_array').then(function(data) {
                $scope.organizations = data;
                $log.info('organizations promise ', $scope.organizations);
        });
                $scope.organizations = data;
                $log.info('organizations promise ', $scope.organizations);
        });
@@ -187,7 +187,7 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
 
        $scope.reset();
 }
 
        $scope.reset();
 }
-RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'Organizations', 'ValidStates' ];
+RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'View', 'ValidStates' ];
 
 function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidStates ) {
 
 
 function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidStates ) {
 
index 23c58ca..0a94ae2 100644 (file)
@@ -43,30 +43,30 @@ angular.module('myApp.services', [ 'ngResource' ]).
                        query: {method:'GET', params:{registrationId:'@id'}, isArray:true}
                });
        }).
                        query: {method:'GET', params:{registrationId:'@id'}, isArray:true}
                });
        }).
+
 /* http://jsfiddle.net/asgoth/7bNAd/ */
 /* http://jsfiddle.net/asgoth/7bNAd/ */
-       factory('Organizations', function($q, $http, $log) {
-               var url = '/<%= $couchdb_database %>/_design/registration/_view/organizations?group=true;format=key_array;callback=JSON_CALLBACK';
+       factory('View', function($q, $http, $log) {
+               return {
+                       getArrayPromise: function(view_url) {
+                               var url = '/<%= $couchdb_database %>/_design/registration/_view/'+view_url+';callback=JSON_CALLBACK';
 
 
-               var deferred = $q.defer();
+                               var deferred = $q.defer();
 
 
-               $log.info('defer', url);
+                               $log.info('defer', url);
 
 
-               $http.jsonp(url).success(function(json) {
-                       $log.info('success', url);
-                       deferred.resolve(json.rows);
-               }).error(function(error) {
-                       $log.error('error', url, error );
-                       deferred.reject(error);
-               });
+                               $http.jsonp(url).success(function(json) {
+                                       $log.info('success', url);
+                                       deferred.resolve(json.rows);
+                               }).error(function(error) {
+                                       $log.error('error', url, error );
+                                       deferred.reject(error);
+                               });
 
 
-               return {
-                       getArrayPromise: function() {
                                return deferred.promise;
                        }
                };
                                return deferred.promise;
                        }
                };
-
-               return $scope.organizations;
        }).
        }).
+
 /* http://jsfiddle.net/asgoth/7bNAd/ */
        value('ValidStates', function() {
                return [ 'draft', 'confirmation', 'verified', 'review' ];
 /* http://jsfiddle.net/asgoth/7bNAd/ */
        value('ValidStates', function() {
                return [ 'draft', 'confirmation', 'verified', 'review' ];