/* 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 = [];
- 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.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 ) {
query: {method:'GET', params:{registrationId:'@id'}, isArray:true}
});
}).
+
/* 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 $scope.organizations;
}).
+
/* http://jsfiddle.net/asgoth/7bNAd/ */
value('ValidStates', function() {
return [ 'draft', 'confirmation', 'verified', 'review' ];