directives.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. /* Directives for DOM manipulation and interaction. */
  3. /* Directive that can be used to make an input field react to the press of Enter. */
  4. eventManApp.directive('eventmanPressEnter', function () {
  5. return function (scope, element, attrs) {
  6. element.bind("keydown keypress", function (event) {
  7. if(event.which === 13) {
  8. scope.$apply(function (){
  9. scope.$eval(attrs.ngEnter);
  10. });
  11. event.preventDefault();
  12. }
  13. });
  14. };
  15. });
  16. eventManApp.directive('eventmanFocus', function () {
  17. function link(scope, element, attrs) {
  18. element[0].focus();
  19. };
  20. return {
  21. link: link
  22. };
  23. });
  24. eventManApp.directive('resetFocus', function () {
  25. function link(scope, element, attrs) {
  26. element.on('click', function() {
  27. // FIXME: that's so wrong! We need to make the new directive communicate.
  28. var el = angular.element(document.querySelector('#query-persons'));
  29. el.length && el[0].focus();
  30. });
  31. };
  32. return {
  33. link: link
  34. };
  35. });
  36. eventManApp.directive('eventmanMessage', ['$timeout',
  37. function($timeout) {
  38. function link(scope, element, attrs) {
  39. scope.dControl = scope.control || {};
  40. scope.dControl.isVisible = false;
  41. scope.dControl.show = function(cfg) {
  42. cfg = cfg || {};
  43. scope.dControl.isVisible = true;
  44. scope.dControl.message = cfg.message;
  45. scope.dControl.isError = cfg.isError;
  46. $timeout(function () {
  47. scope.dControl.isVisible = false;
  48. }, cfg.timeout || 2000);
  49. };
  50. };
  51. return {
  52. scope: {
  53. control: '='
  54. },
  55. link: link,
  56. replace: true,
  57. template: '<div ng-if="dControl.isVisible">{{dControl.message}}</div>'
  58. };
  59. }]
  60. );