defineImmutableProperty

stable
Juanfran 2015-04-24 10:59:09 +02:00
parent 37a0e59fd6
commit 3f34ed1412
3 changed files with 13 additions and 3 deletions

View File

@ -158,6 +158,15 @@ replaceTags = (str, tags, replace) ->
return str
defineImmutableProperty = (obj, name, variable) =>
Object.defineProperty obj, name, {
get: () =>
if _.isFunction(variable)
return variable.call(obj)
else
return variable
}
taiga = @.taiga
taiga.nl2br = nl2br
taiga.bindMethods = bindMethods
@ -179,3 +188,4 @@ taiga.startswith = startswith
taiga.sizeFormat = sizeFormat
taiga.stripTags = stripTags
taiga.replaceTags = replaceTags
taiga.defineImmutableProperty = defineImmutableProperty

View File

@ -1,10 +1,10 @@
DropdownProjectListDirective = (projectsService) ->
link = (scope, el, attrs, ctrl) ->
scope.vm = {}
scope.vm.projects = projectsService.projects
taiga.defineImmutableProperty(scope.vm, "projects", projectsService.projects)
scope.vm.newProject = ->
projectsService.newProject()
directive = {
templateUrl: "navigation-bar/dropdown-project-list/dropdown-project-list.html"
scope: {}

View File

@ -25,7 +25,7 @@ ProjectsListingDirective = (projectsService) ->
projectsService.bulkUpdateProjectsOrder(sortData)
scope.vm.projects = projectsService.projects
taiga.defineImmutableProperty(scope.vm, "projects", projectsService.projects)
scope.vm.newProject = ->
projectsService.newProject()