Merge branch 'testacular' of mjesec.ffzg.hr:/git/angular-drzb into testacular
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 28 Jan 2013 22:59:14 +0000 (23:59 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 28 Jan 2013 22:59:14 +0000 (23:59 +0100)
app/js/controllers.js
app/js/pagination.js [changed from symlink to file mode: 0644]
app/js/services.js.ep
app/partials/list.html.ep
app/partials/verified.html.ep
test/unit/controllersSpec.js
test/unit/directivesSpec.js
test/unit/servicesSpec.js

index 3561aff..3c43f53 100644 (file)
@@ -2,7 +2,7 @@
 
 /* Controllers */
 
-function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, Organizations, RegistrationState) {
+function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, Organizations, ValidStates) {
 
        $scope.$routeParams = $routeParams;
        $scope.$location = $location;
@@ -11,7 +11,7 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
                $scope.organizations = data;
                $log.info('organizations promise ', $scope.organizations);
        });
-       $scope.RegistrationState = RegistrationState();
+       $scope.ValidStates = ValidStates();
 
        $scope.info = { message: '', css_class: '' } ; // alert box
 
@@ -173,9 +173,9 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
 
        $scope.reset();
 }
-RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'Organizations', 'RegistrationState' ];
+RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'Organizations', 'ValidStates' ];
 
-function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, RegistrationState ) {
+function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidStates ) {
 
        $scope.list = [];
        $scope.list_results = 0;
@@ -196,7 +196,7 @@ function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, Regist
                states: true,
                pager_numeric: false
        };
-       $scope.RegistrationState = RegistrationState();
+       $scope.ValidStates = ValidStates();
 
        $scope.create_counts = function( array ) {
                $log.info('create_counts', array.length );
@@ -289,5 +289,5 @@ function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, Regist
        }
 }
 
-ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter', 'RegistrationState' ];
+ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter', 'ValidStates' ];
 
deleted file mode 120000 (symlink)
index cfd2d8c17600e263cd2c1f9bdbb7647f7beea801..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1 +0,0 @@
-../lib/angular-ui/bootstrap/src/pagination/pagination.js
\ No newline at end of file
new file mode 100644 (file)
index 0000000000000000000000000000000000000000..0accf494c2993bdf0d2cc9b28c1820cc21db3783
--- /dev/null
@@ -0,0 +1,67 @@
+angular.module('ui.bootstrap.pagination', [])
+
+.directive('pagination', function() {
+  return {
+    restrict: 'E',
+    scope: {
+      numPages: '=',
+      currentPage: '=',
+      maxSize: '=',
+      hidePagination: '=',
+      onSelectPage: '&'
+    },
+    templateUrl: 'template/pagination/pagination.html',
+    replace: true,
+    link: function(scope) {
+      scope.$watch('numPages + currentPage + maxSize', function() {
+        scope.pages = [];
+        
+        //set the default maxSize to numPages
+        var maxSize = ( scope.maxSize && scope.maxSize < scope.numPages ) ? scope.maxSize : scope.numPages;
+        var startPage = scope.currentPage - Math.floor(maxSize/2);
+        
+        //adjust the startPage within boundary
+        if(startPage < 1) {
+            startPage = 1;
+        }
+        if ((startPage + maxSize - 1) > scope.numPages) {
+            startPage = startPage - ((startPage + maxSize - 1) - scope.numPages );
+        }
+
+        for(var i=0; i < maxSize && i < scope.numPages ;i++) {
+          scope.pages.push(startPage + i);
+        }
+        if ( scope.currentPage > scope.numPages ) {
+          scope.selectPage(scope.numPages);
+        }
+      });
+      scope.noPrevious = function() {
+        return scope.currentPage === 1;
+      };
+      scope.noNext = function() {
+        return scope.currentPage === scope.numPages;
+      };
+      scope.isActive = function(page) {
+        return scope.currentPage === page;
+      };
+
+      scope.selectPage = function(page) {
+        if ( ! scope.isActive(page) ) {
+          scope.currentPage = page;
+          scope.onSelectPage({ page: page });
+        }
+      };
+
+      scope.selectPrevious = function() {
+        if ( !scope.noPrevious() ) {
+          scope.selectPage(scope.currentPage-1);
+        }
+      };
+      scope.selectNext = function() {
+        if ( !scope.noNext() ) {
+          scope.selectPage(scope.currentPage+1);
+        }
+      };
+    }
+  };
+});
\ No newline at end of file
index 9149a3f..62578ed 100644 (file)
@@ -67,6 +67,6 @@ angular.module('myApp.services', [ 'ngResource' ]).
                return $scope.organizations;
        }).
 /* http://jsfiddle.net/asgoth/7bNAd/ */
-       value('RegistrationState', function() {
+       value('ValidStates', function() {
                return [ 'draft', 'confirmation', 'verified', 'review' ];
        });
index 0faca67..1a7927b 100644 (file)
@@ -62,7 +62,7 @@ All results on single page <b>(can be slow!)</b>
 </fieldset>
 
 <fieldset ng-show="show.states">
-<button ng-repeat="state in RegistrationState" ng-click="search.$ = state" class="btn {{state}}">
+<button ng-repeat="state in ValidStates" ng-click="search.$ = state" class="btn {{state}}">
 <span class="badge">{{Counts['state+'+state]}}</span>
 {{state}}
 </button>
index a5a541b..55381a7 100644 (file)
@@ -13,7 +13,7 @@
 
 <select
        ng-model="registration.state"
-       ng-options="state for state in RegistrationState"
+       ng-options="state for state in ValidStates"
        class="my-label-select"
        label="<%= locale en => 'State', hr => 'Stanje' %>"
 >
index a8b34e7..de7a63d 100644 (file)
@@ -68,8 +68,8 @@ describe('ListCtrl', function(){
        expect( scope.ready ).toBe( true );
   });
 
-  it('RegistrationState', function() {
+  it('ValidStates', function() {
        $httpBackend.flush();
-       expect( scope.RegistrationState ).toBeTruthy();
+       expect( scope.ValidStates ).toBeTruthy();
   });
 });
index 32c0ae3..fe2d390 100644 (file)
@@ -40,9 +40,9 @@ describe('directives', function() {
   describe('my-label-select', function() {
     beforeEach(module('myApp.services'));
     it('div+label+input', function() {
-      inject(function($compile, $rootScope, RegistrationState) {
-               //dump( RegistrationState() );
-        var element = $compile('<div><select class="my-label-select" ng-model="m" label="label" ng-options="value for value in RegistrationState()"></select></div>')($rootScope);
+      inject(function($compile, $rootScope, ValidStates) {
+               //dump( ValidStates() );
+        var element = $compile('<div><select class="my-label-select" ng-model="m" label="label" ng-options="value for value in ValidStates()"></select></div>')($rootScope);
                //dump(element.html());
         expect(element.html()).toMatch(/div.*label.*label.*div.*select.*select.*div.*div/i);
       });
index 138ffec..bb06cee 100644 (file)
@@ -19,9 +19,9 @@ describe('service', function() {
     }));
   });
 
-       describe('RegistrationState', function() {
-               it('have status', inject(function(RegistrationState) {
-                       expect(RegistrationState().length).toBe(4);
+       describe('ValidStates', function() {
+               it('have status', inject(function(ValidStates) {
+                       expect(ValidStates().length).toBe(4);
                }));
        });