From: Mike Rylander Date: Fri, 21 Aug 2015 02:17:20 +0000 (-0400) Subject: webstaff: improvements to core UI widgets X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6059f36449888a5c5604e92cea4e54da64f1c118;p=evergreen%2Fmasslnc.git webstaff: improvements to core UI widgets * Add enter-key-handler * improve basic combo box * teach org selector how to not have a default value Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- diff --git a/Open-ILS/web/js/ui/default/staff/services/ui.js b/Open-ILS/web/js/ui/default/staff/services/ui.js index 5291d9a257..966b3e3f15 100644 --- a/Open-ILS/web/js/ui/default/staff/services/ui.js +++ b/Open-ILS/web/js/ui/default/staff/services/ui.js @@ -218,10 +218,10 @@ function($modal, $interpolate) { template: '
'+ ''+ - '
'+ - ''+ - '
', @@ -246,8 +246,9 @@ function($modal, $interpolate) { transclude : true, replace : true, // makes styling easier scope : { - selected : '=', // defaults to workstation or root org - + selected : '=', // defaults to workstation or root org, + // unless the nodefault attibute exists + // Each org unit is passed into this function and, for // any org units where the response value is true, the // org unit will not be added to the selector. @@ -286,6 +287,9 @@ function($modal, $interpolate) { controller : ['$scope','$timeout','egOrg','egAuth', function($scope , $timeout , egOrg , egAuth) { + $scope.egOrg = egOrg; // for use in the link function + $scope.egAuth = egAuth; // for use in the link function + // avoid linking the full fleshed tree to the scope by // tossing in a flattened list. $scope.orgList = egOrg.list().map(function(org) { @@ -307,12 +311,41 @@ function($modal, $interpolate) { if ($scope.onchange) $scope.onchange($scope.selected); } - if (!$scope.selected) - $scope.selected = egOrg.get(egAuth.user().ws_ou()); - }] + }], + link : function(scope, element, attrs, egGridCtrl) { + + // boolean fields are presented as value-less attributes + angular.forEach( + ['nodefault'], + function(field) { + if (angular.isDefined(attrs[field])) + scope[field] = true; + else + scope[field] = false; + } + ); + + if (!scope.selected && !scope.nodefault) + scope.selected = scope.egOrg.get(scope.egAuth.user().ws_ou()); + } + } }) +/* http://eric.sau.pe/angularjs-detect-enter-key-ngenter/ */ +.directive('egEnter', function () { + return function (scope, element, attrs) { + element.bind("keydown keypress", function (event) { + if(event.which === 13) { + scope.$apply(function (){ + scope.$eval(attrs.egEnter); + }); + + event.preventDefault(); + } + }); + }; +}) /* http://stackoverflow.com/questions/18061757/angular-js-and-html5-date-input-value-how-to-get-firefox-to-show-a-readable-d