diff --git a/vipra-ui/app/js/directives.js b/vipra-ui/app/js/directives.js index 3d7b93fc03c03ac32ae6580eb0583e54deb5c673..60b2b0c7c14546ed90a946b547acd917832126b7 100644 --- a/vipra-ui/app/js/directives.js +++ b/vipra-ui/app/js/directives.js @@ -218,4 +218,50 @@ }; }]); + app.directive('revolveSelect', function() { + return { + scope: { + ngModel: '=', + values: '=' + }, + require: 'ngModel', + template: '<a ng-bind="label" ng-click="next()"></a>', + link: function($scope, $elem, $attrs, $ctrl) { + var hasObjects = false; + if($scope.values && $scope.values.length) + hasObjects = angular.isObject($scope.values[0]); + + var index = function() { + if(hasObjects) { + for(var i = 0; i < $scope.values.length; i++) { + if($scope.values[i].value === $scope.ngModel) + return i; + } + return -1; + } else { + return $scope.values.indexOf($scope.ngModel); + } + }; + + var select = function(i) { + if(i < 0 || i >= $scope.values.length) return; + if(hasObjects) { + $scope.ngModel = $scope.values[i].value; + $scope.label = $scope.values[i].label; + } else { + $scope.ngModel = $scope.label = $scope.values[i]; + } + }; + + $scope.next = function() { + select((index() + 1) % $scope.values.length) + }; + + $scope.$watch('ngModel', function() { + select(index()); + }); + } + }; + }); + })(); \ No newline at end of file diff --git a/vipra-ui/app/less/app.less b/vipra-ui/app/less/app.less index 78a3d3586afd16087d8903c469e0a41c9e59c9e5..486a8fdcd93d6a65b5ecbb4b271486c05427fa6a 100644 --- a/vipra-ui/app/less/app.less +++ b/vipra-ui/app/less/app.less @@ -246,6 +246,11 @@ ul.dashed { padding-bottom: 10px; } +revolve-select, [revolve-select] { + .noselect; + cursor: pointer; +} + [sort-by] { .noselect; cursor: pointer;