change the dynamic compile to a normal angular compile template

stable
Juanfran 2016-04-28 09:42:26 +02:00
parent 00b78eb65d
commit e4315246a1
5 changed files with 59 additions and 43 deletions

View File

@ -51,7 +51,12 @@ class LightboxService extends taiga.Service
@animationFrame.add -> @animationFrame.add ->
$el.addClass("open") $el.addClass("open")
$el.one "transitionend", => $el.one "transitionend", =>
firstField = $el.find('input,textarea').first()
if firstField.length
$el.find('input,textarea').first().focus() $el.find('input,textarea').first().focus()
else if document.activeElement
$(document.activeElement).blur()
@animationFrame.add => @animationFrame.add =>
lightboxContent.show() lightboxContent.show()

View File

@ -158,6 +158,10 @@ RelatedTaskStatusDirective = ($repo, $template) ->
$scope.$eval($attrs.onUpdate) $scope.$eval($attrs.onUpdate)
$scope.$emit("related-tasks:status-changed") $scope.$emit("related-tasks:status-changed")
$scope.$watch $attrs.tgRelatedTaskStatus, () ->
task = $scope.$eval($attrs.tgRelatedTaskStatus)
updateTaskStatus($el, task, $scope.taskStatusById)
taiga.bindOnce $scope, "project", (project) -> taiga.bindOnce $scope, "project", (project) ->
$el.append(selectionTemplate({ 'statuses': project.task_statuses })) $el.append(selectionTemplate({ 'statuses': project.task_statuses }))
updateTaskStatus($el, task, $scope.taskStatusById) updateTaskStatus($el, task, $scope.taskStatusById)

View File

@ -117,16 +117,14 @@ module.directive("tgRelatedTaskRow", ["$tgRepo", "$compile", "$tgConfirm", "$roo
"$tgTemplate", "$translate", RelatedTaskRowDirective]) "$tgTemplate", "$translate", RelatedTaskRowDirective])
RelatedTaskCreateFormDirective = ($repo, $compile, $confirm, $tgmodel, $loading, $analytics, $template) -> RelatedTaskCreateFormDirective = ($repo, $compile, $confirm, $tgmodel, $loading, $analytics) ->
template = $template.get("task/related-task-create-form.html", true)
newTask = { newTask = {
subject: "" subject: ""
assigned_to: null assigned_to: null
} }
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
createTask = debounce 2000, (task) -> createTask = (task) ->
task.subject = $el.find('input').val() task.subject = $el.find('input').val()
task.assigned_to = $scope.newTask.assigned_to task.assigned_to = $scope.newTask.assigned_to
task.status = $scope.newTask.status task.status = $scope.newTask.status
@ -151,50 +149,54 @@ RelatedTaskCreateFormDirective = ($repo, $compile, $confirm, $tgmodel, $loading,
return promise return promise
close = () -> close = () ->
$el.removeClass('active')
$el.off() $el.off()
$el.html("")
$scope.newRelatedTaskFormOpen = false $scope.openNewRelatedTask = false
reset = () ->
newTask = {
subject: ""
assigned_to: null
}
newTask["status"] = $scope.project.default_task_status
newTask["project"] = $scope.project.id
newTask["user_story"] = $scope.us.id
$scope.newTask = $tgmodel.make_model("tasks", newTask)
render = -> render = ->
$scope.newRelatedTaskFormOpen = true $scope.openNewRelatedTask = true
$el.html($compile(template())($scope))
$el.find('input').focus().select()
$el.addClass('active')
$el.on "keyup", "input", (event)-> $el.on "keyup", "input", (event)->
if event.keyCode == 13 if event.keyCode == 13
createTask(newTask).then -> createTask(newTask).then ->
render() reset()
$el.find('input').focus()
else if event.keyCode == 27 else if event.keyCode == 27
$scope.$apply () -> close() $scope.$apply () -> close()
$el.on "click", ".icon-close", (event)-> $scope.save = () ->
$scope.$apply () -> close()
$el.on "click", ".save-task", (event)->
createTask(newTask).then -> createTask(newTask).then ->
close() close()
taiga.bindOnce $scope, "us", (val) -> taiga.bindOnce $scope, "us", reset
newTask["status"] = $scope.project.default_task_status
newTask["project"] = $scope.project.id
newTask["user_story"] = $scope.us.id
$scope.newTask = $tgmodel.make_model("tasks", newTask)
$el.html("")
$scope.$on "related-tasks:show-form", -> $scope.$on "related-tasks:show-form", ->
render() $scope.$apply(render)
$scope.$on "$destroy", -> $scope.$on "$destroy", ->
$el.off() $el.off()
return {link: link} return {
scope: true,
link: link,
templateUrl: 'task/related-task-create-form.html'
}
module.directive("tgRelatedTaskCreateForm", ["$tgRepo", "$compile", "$tgConfirm", "$tgModel", "$tgLoading", module.directive("tgRelatedTaskCreateForm", ["$tgRepo", "$compile", "$tgConfirm", "$tgModel", "$tgLoading",
"$tgAnalytics", "$tgTemplate", RelatedTaskCreateFormDirective]) "$tgAnalytics", RelatedTaskCreateFormDirective])
RelatedTaskCreateButtonDirective = ($repo, $compile, $confirm, $tgmodel, $template) -> RelatedTaskCreateButtonDirective = ($repo, $compile, $confirm, $tgmodel, $template) ->
@ -288,6 +290,10 @@ RelatedTaskAssignedToInlineEditionDirective = ($repo, $rootscope, $translate) ->
notAutoSave = $scope.$eval($attrs.notAutoSave) notAutoSave = $scope.$eval($attrs.notAutoSave)
autoSave = !notAutoSave autoSave = !notAutoSave
$scope.$watch $attrs.tgRelatedTaskAssignedToInlineEdition, () ->
task = $scope.$eval($attrs.tgRelatedTaskAssignedToInlineEdition)
updateRelatedTask(task)
updateRelatedTask(task) updateRelatedTask(task)
$el.on "click", ".task-assignedto", (event) -> $el.on "click", ".task-assignedto", (event) ->

View File

@ -12,4 +12,4 @@ section.related-tasks(
tg-related-task-row tg-related-task-row
ng-model="task" ng-model="task"
) )
.row.single-related-task.related-task-create-form(tg-related-task-create-form) div(tg-related-task-create-form)

View File

@ -1,7 +1,8 @@
.row.single-related-task.related-task-create-form.active(ng-if="openNewRelatedTask")
.task-name .task-name
input(type='text', placeholder="{{'TASK.PLACEHOLDER_SUBJECT' | translate}}") input(type='text', autofocus, placeholder="{{'TASK.PLACEHOLDER_SUBJECT' | translate}}")
.task-settings .task-settings
a.save-task(title="{{'COMMON.SAVE' | translate}}") a.save-task(ng-click="save()" title="{{'COMMON.SAVE' | translate}}")
tg-svg(svg-icon="icon-save") tg-svg(svg-icon="icon-save")
.status(tg-related-task-status='newTask', ng-model='newTask', not-auto-save='true') .status(tg-related-task-status='newTask', ng-model='newTask', not-auto-save='true')