$self->render( $self->stash('template') , lang => $self->stash('lang') );
};
+get '/lang/:lang/template/*template' => sub { # angular-ui templates
+ my $self = shift;
+ my $path = '/lib/angular-ui/bootstrap/template/' . $self->stash('template');
+ warn "# render_static $path";
+ $self->render_static( $path );
+};
get '/data/' => sub {
my $self = shift;
-->
<script src="/lib/angular/angular.js"></script>
<script src="/lib/angular/angular-resource.js"></script>
+
+ <script src="/js/pagination.js"></script>
+
<script src="/js/app.js"></script>
<script src="/js/services.js"></script>
<script src="/js/controllers.js"></script>
// Declare app level module which depends on filters, and services
-angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives' ]).
+angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'ui.bootstrap.pagination' ]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/registration/:registrationId', {templateUrl: 'partials/registration.html', controller: RegistrationCtrl});
$routeProvider.when('/confirmation/:registrationId', {templateUrl: 'partials/confirmation.html', controller: RegistrationCtrl});
$scope.pager = {
page: 1,
limit: 10,
- results: 0,
- last_page: 0
+ results: 1,
+ last_page: 1
};
$scope.search = {};
$scope.ready = false;
$scope.filters = [ 'student', 'hpd_member', 'reception', 'dinner' ];
+ $scope.show = {
+ registration_type: true,
+ filters: true,
+ search: true,
+ states: true,
+ pager_numeric: false
+ };
$scope.all_registrations = Registration.query( function() {
var Counts = {};
$log.info('Counts', Counts);
$scope.Counts = Counts;
-// $scope.list = $scope.all_registrations; // FIXME show all registrations on page loadyy
$scope.ready = true;
+ $scope.reset();
+
});
$scope.filter_list = function(newVal, oldVal) {
var filtered =
$filter('filter')($scope.all_registrations, $scope.search);
-// $scope.pager.page = 1;
+ $log.info('pager before apply', $scope.pager);
+
$scope.pager.results = filtered.length;
$scope.pager.last_page = Math.ceil( $scope.pager.results / $scope.pager.limit );
- if ( $scope.pager.page > $scope.pager.last_page ) {
- $scope.pager.page = 1;
- }
$log.info('pager', $scope.pager);
var from = ( $scope.pager.page - 1 ) * $scope.pager.limit;
}, $scope.list );
$log.info('list length=', $scope.list.length, "offset=", from);
};
- angular.forEach( $scope.filters, function(f) {
- $scope.$watch('search.'+f, $scope.filter_list);
- $log.info('watch search.'+f);
- });
- $scope.$watch('search.registration_type', $scope.filter_list);
- $scope.$watch('search.$', $scope.filter_list);
- $scope.$watch('pager.page', $scope.filter_list);
- $scope.$watch('pager.limit', $scope.filter_list);
+ $scope.$watch('search', $scope.filter_list, true);
+ $scope.$watch('pager', $scope.filter_list, true);
$scope.RegistrationTypes = RegistrationTypes;
$log.info( "RegistrationTypes", RegistrationTypes );
+
+ $scope.reset = function() {
+ $scope.search = { registration_type: '' };
+ $log.info('reset', $scope.search );
+ }
}
}
};
}])
+.directive('myPagination', function() { // modified ui.bootstrap.pagination
+ return {
+ restrict: 'E',
+ scope: {
+ numPages: '=',
+ currentPage: '=',
+ maxSize: '=',
+ 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);
+ }
+ };
+ }
+ };
+})
;
--- /dev/null
+../lib/angular-ui/bootstrap/src/pagination/pagination.js
\ No newline at end of file
-<div ng-show="! ready">
+
+<div ng-show="! ready" class="alert alert-important">
Loading data...
</div>
-
<form ng-controller="ListCtrl" class="form-search" ng-show="ready">
-<div class="controls-row">
-<h2>Odaberite tip registracije</h2>
+<fieldset ng-show="show.registration_type">
+<legend>
+Odaberite tip registracije
+</legend>
<label class="radio input-block-level" ng-repeat="type in RegistrationTypes" ng-switch on="type.code" ng-show="Counts[type.code] > 0">
<hr ng-switch-when="false">
</span>
</label>
-</div>
+</fieldset>
+
+<fieldset ng-show="show.filters">
+<legend>
+Filters
+</legend>
-<div class="controls-row">
-Filters:
<label class="badge filter-{{search[filter]}}" ng-repeat="filter in filters">
<input ng-model="search[filter]" type="checkbox">
{{Counts[filter]}}
{{filter}}
</label>
-</div>
+</fieldset>
-<div class="controls-row">
+<fieldset>
+<legend>
+Search
+</legend>
-<label>
-Search:
-<input class="search-query" ng-model="search.$">
-</label>
+<input class="my-lebel-input search-query" ng-model="search.$" label="Search">
-<a class="btn btn-invert" href="" ng-click="search = {}">
+<a class="btn btn-invert" href="" ng-click="reset()">
<i class="icon-remove"></i></a>
+
<b>{{pager.results}} results</b>
<tt>{{search}}</tt>
-<br>
+</fieldset>
+
+<fieldset ng-show="show.states">
+
<button ng-click="search.$ = 'draft'" class="btn draft">draft</button>
<button ng-click="search.$ = 'confirmation'" class="btn confirmation">confirmation</button>
<button ng-click="search.$ = 'verified'" class="btn verified">verified</button>
-<input type="number" ng-model="pager.page" min="1" max="{{pager.last_page}}">
-<input type="number" ng-model="pager.limit">
-</div>
+</fieldset>
+<fieldset ng-show="show.pager_numeric">
+<input type="number" ng-model="pager.page" size="3" min="1" max="{{pager.last_page}}">
+<input type="number" ng-model="pager.limit">
+</fieldset>
-<div ng-show="list.length">
-
-<h2>Prijavljenje registracije {{search.registration_type}}</h2>
+<div ng-show="list.length" class="content">
-<ul>
+<pagination class="pagination-large" max-size="12"
+ num-pages="pager.last_page"
+ current-page="pager.page"
+></pagination>
-<li ng-repeat="registration in list">
+<dl ng-repeat="registration in list">
+%= include 'registration/view', before => begin
{{registration.nr}}
<a class="btn btn-primary" href="#/verified/{{registration.id}}" target="{{registration.id}}">change status</a>
-%= include 'registration/view'
-</li>
+% end
+</dl>
-</ul>
+<pagination class="pagination-large" max-size="12"
+ num-pages="pager.last_page"
+ current-page="pager.page"
+></pagination>
</div><!-- ng-show="list.length"-->
% if ( $lang =~ m/-dev/ ) {
<pre class="controls-row">
+{{pager}}
+
{{Counts}}
</pre>
% }
-
+<dt>
+%= $before->()
<a id="edit-registration" class="btn" href="#/registration/{{registration.id}}">edit</a>
{{registration.user.registration_type}}
{{registration._id | registration_date_time}}
% if ( $lang =~ m/-dev/ ) {
<a class="btn" href="<%= $couchdb_view %>/{{registration._id}}" target="couchdb">couchdb</a>
% }
+</dt>
+
+<dd>
- <p>
+ <p class="well">
{{registration.user.firstname}}
{{registration.user.surname}}
<em>{{registration.user.organization}}</em>,
<p class="abstract">{{work.abstract}}</p>
+</dd>
beforeEach(module('myApp.services'));
it('div+label+input', function() {
inject(function($compile, $rootScope, RegistrationState) {
- dump( 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);
- dump(element.html());
+ //dump(element.html());
expect(element.html()).toMatch(/div.*label.*label.*div.*select.*select.*div.*div/i);
});
});