eventman/angular_app/js/directives.js

71 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-04-18 15:50:27 +02:00
'use strict';
/* Directives for DOM manipulation and interaction. */
/* Directive that can be used to make an input field react to the press of Enter. */
eventManApp.directive('eventmanPressEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
});
2015-04-18 15:50:27 +02:00
eventManApp.directive('eventmanFocus', function () {
function link(scope, element, attrs) {
element[0].focus();
};
return {
link: link
};
});
eventManApp.directive('resetFocus', function () {
function link(scope, element, attrs) {
element.on('click', function() {
2015-04-19 22:05:04 +02:00
// FIXME: that's so wrong! We need to make the new directive communicate.
var el = angular.element(document.querySelector('#query-persons'));
el.length && el[0].focus();
});
};
return {
link: link
};
});
eventManApp.directive('eventmanMessage', ['$timeout',
function($timeout) {
function link(scope, element, attrs) {
scope.dControl = scope.control || {};
scope.dControl.isVisible = false;
scope.dControl.show = function(cfg) {
cfg = cfg || {};
scope.dControl.isVisible = true;
scope.dControl.message = cfg.message;
scope.dControl.isError = cfg.isError;
$timeout(function () {
scope.dControl.isVisible = false;
2015-05-16 20:12:42 +02:00
}, cfg.timeout || 4000);
};
};
return {
scope: {
control: '='
},
link: link,
template: '<div ng-if="dControl.isVisible" ng-class="{\'eventman-message\': true, clearfix: true, \'alert\': true, \'alert-success\': !dControl.isError, \'alert-danger\': dControl.isError}">{{dControl.message}}</div>'
};
}]
);