/* Controllers */
-
-function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, View) {
+function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, Organizations) {
$scope.$routeParams = $routeParams;
$scope.$location = $location;
$scope.organizations = [];
+ Organizations.getArrayPromise().then(function(data) {
+ $scope.organizations = data;
+ $log.info('organizations promise ', $scope.organizations);
+ });
$scope.update = function(registration, state) {
$log.info( $routeParams.registrationId );
- $scope.view = new View();
-if(0){//FIXME
- $scope.view.$get({ view: 'organizations' }, function(result) {
- $log.info('View organizations', result);
- angular.forEach( result.rows, function(value, key) {
- this.push( value.key ); // name of organization
- }, $scope.organizations );
- $log.info('organizations', $scope.organizations);
- });
-}else{//FIXME
- $scope.view.$key_array({ view: 'organizations' }, function(result) {
- $log.info('key_array', result);
-// $scope.organizations = result.rows; // FIXME doesn't refresh bs-typeahead
- angular.forEach( result.rows, function(o) {
- this.push( o );
- }, $scope.organizations );
- $log.info('organizations', $scope.organizations);
- });
}
-}//FIXME
$scope.$watch('user.registration_type', function( oldValue, newValue ) {
$log.info("registration_type watch", oldValue, newValue );
$scope.reset();
}
-//RegistrationCtrl.$inject = [ '$scope', '$log' ];
+RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'Organizations' ];
function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter) {
}
-function MyCtrl2() {
-}
-MyCtrl2.$inject = [];
+ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter' ];
query: {method:'GET', params:{registraionId:'@id'}, isArray:true}
});
}).
- factory('View', function($resource) {
- return $resource('/:database/_design/registration/_view/:view?group=true;format=:format', { database: '<%= $couchdb_database %>' }, {
- key_array: {method:'GET', params:{ format:'key_array' }, isArray:false}
- });
+/* 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';
+
+ return {
+ getArrayPromise: function() {
+ var deferred = $q.defer();
+
+ $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);
+ });
+ return deferred.promise;
+ }
+ };
+ return $scope.organizations;
});