Refactored the isiocaine and block buttons

stable
Jesús Espino 2014-10-21 09:40:55 +02:00 committed by David Barragán Merino
parent c4c439d305
commit 0ec7e2dc25
5 changed files with 15 additions and 25 deletions

View File

@ -346,28 +346,22 @@ module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgLoa
#############################################################################
BlockButtonDirective = ($rootscope, $loading) ->
template = _.template("""
template = """
<a class="button button-gray item-block">Block</a>
<a class="button button-red item-unblock">Unblock</a>
""")
"""
link = ($scope, $el, $attrs, $model) ->
render = _.once (item) ->
$el.html(template())
$scope.$watch $attrs.ngModel, (item) ->
return if not item
refresh = (item) ->
if item?.is_blocked
if item.is_blocked
$el.find('.item-block').hide()
$el.find('.item-unblock').show()
else
$el.find('.item-block').show()
$el.find('.item-unblock').hide()
$scope.$watch $attrs.ngModel, (item) ->
return if not item
render(item)
refresh(item)
$el.on "click", ".item-block", (event) ->
$rootscope.$broadcast("block", $model.$modelValue)
@ -385,6 +379,7 @@ BlockButtonDirective = ($rootscope, $loading) ->
link: link
restrict: "EA"
require: "ngModel"
template: template
}
module.directive("tgBlockButton", ["$rootScope", "$tgLoading", BlockButtonDirective])

View File

@ -270,28 +270,22 @@ module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "
TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) ->
template = _.template("""
template = """
<fieldset title="Feeling a bit overwhelmed by a task? Make sure others know about it by clicking on Iocaine when editing a task. It's possible to become immune to this (fictional) deadly poison by consuming small amounts over time just as it's possible to get better at what you do by occasionally taking on extra challenges!">
<label for="is-iocaine" class="clickable button button-gray is-iocaine">Iocaine</label>
<input type="checkbox" id="is-iocaine" name="is-iocaine"/>
</fieldset>
""")
"""
link = ($scope, $el, $attrs, $model) ->
render = _.once (task) ->
$el.html(template())
$scope.$watch $attrs.ngModel, (task) ->
return if not task
refresh = (task) ->
if task?.is_iocaine
if task.is_iocaine
$el.find('.is-iocaine').addClass('active')
else
$el.find('.is-iocaine').removeClass('active')
$scope.$watch $attrs.ngModel, (task) ->
return if not task
render(task)
refresh(task)
$scope.$on "$destroy", ->
$el.off()
@ -316,6 +310,7 @@ TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) ->
link: link
restrict: "EA"
require: "ngModel"
template: tempalte
}
module.directive("tgTaskIsIocaineButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", TaskIsIocaineButtonDirective])

View File

@ -54,7 +54,7 @@ block content
section.us-detail-settings
tg-promote-issue-to-us-button(tg-check-permission="add_us", ng-model="issue")
div(tg-check-permission="modify_issue", tg-block-button, ng-model="issue")
tg-block-button(tg-check-permission="modify_issue", ng-model="issue")
tg-delete-button(tg-check-permission="delete_issue",
on-delete-go-to-url="project-issues",
project-slug="{{ project.slug }}",

View File

@ -53,7 +53,7 @@ block content
section.us-detail-settings
fieldset(tg-task-is-iocaine-button, tg-check-permission="modify_task", ng-model="task")
div(tg-check-permission="modify_task", tg-block-button, ng-model="task")
tg-block-button(tg-check-permission="modify_task", ng-model="task")
tg-delete-button(tg-check-permission="delete_task",
on-delete-go-to-url="project-backlog",
project-slug="{{ project.slug }}",

View File

@ -60,7 +60,7 @@ block content
section.us-detail-settings
tg-us-team-requirement-button(ng-model="us")
tg-us-client-requirement-button(ng-model="us")
div(tg-check-permission="modify_us", tg-block-button, ng-model="us")
tg-block-button(tg-check-permission="modify_us", ng-model="us")
tg-delete-button(tg-check-permission="delete_us",
on-delete-go-to-url="project-backlog",
project-slug="{{ project.slug }}",