Last active
August 29, 2015 14:05
-
-
Save Igosuki/bcee512038f4bc31297f to your computer and use it in GitHub Desktop.
Berk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module 'wat' | |
.directive 'bindServerErrors', ($compile, $timeout) -> | |
errorTemplate = """ | |
<div><ul><li ng-repeat='(k,v) in errors'>{{k}}: {{v.join(',')}}</li></ul></div> | |
""" | |
restrict: 'A' | |
template: """ | |
<span tooltip-html-unsafe='{{errorsHtml}}' tooltip-placement="top" tooltip-append-to-body="true"> | |
<span ng-transclude></span> | |
</span> | |
""" | |
scope: | |
errors: '=bindServerErrors' | |
transclude: true | |
compile: (element, attrs, transclude) -> | |
element.addClass 'hidden' | |
compileErrors = $compile(angular.element(errorTemplate).contents()) | |
post:(scope, elm, attrs) -> | |
errorsScope = scope.$new() | |
scope.$watch 'errors', (errors, oldErrors) -> | |
if errors != oldErrors | |
if !errors || Object.keys(errors).length <= 0 | |
elm.addClass('hidden') | |
else | |
elm.removeClass('hidden') | |
errorsScope.errors = errors | |
$timeout () -> | |
compileErrors(errorsScope) | |
scope.$digest() | |
scope.errorsHtml = compileErrors(errorsScope).html() | |
return | |
return | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.7.1 | |
(function() { | |
angular.module('finexkap').directive('bindServerErrors', function($compile, $timeout) { | |
var errorTemplate; | |
errorTemplate = "<div><ul><li ng-repeat='(k,v) in errors'>{{k}}: {{v.join(',')}}</li></ul></div>"; | |
return { | |
restrict: 'A', | |
template: "<span tooltip-html-unsafe='{{errorsHtml}}' tooltip-placement=\"top\" tooltip-append-to-body=\"true\">\n <span ng-transclude></span>\n</span>", | |
scope: { | |
errors: '=bindServerErrors' | |
}, | |
transclude: true, | |
compile: function(element, attrs, transclude) { | |
var compileErrors; | |
element.addClass('hidden'); | |
compileErrors = $compile(angular.element(errorTemplate).contents()); | |
return { | |
post: function(scope, elm, attrs) { | |
var errorsScope; | |
errorsScope = scope.$new(); | |
scope.$watch('errors', function(errors, oldErrors) { | |
if (errors !== oldErrors) { | |
if (!errors || Object.keys(errors).length <= 0) { | |
elm.addClass('hidden'); | |
} else { | |
elm.removeClass('hidden'); | |
errorsScope.errors = errors; | |
$timeout(function() { | |
compileErrors(errorsScope); | |
scope.$digest(); | |
return scope.errorsHtml = compileErrors(errorsScope).html(); | |
}); | |
} | |
} | |
}); | |
} | |
}; | |
} | |
}; | |
}); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment