diff options
author | Vinnie Okada <vokada@mrvinn.com> | 2014-10-07 04:19:12 +0400 |
---|---|---|
committer | Vinnie Okada <vokada@mrvinn.com> | 2014-10-07 04:19:12 +0400 |
commit | 40263a06c196e0c99cc13d187228bd62bbcf4a6a (patch) | |
tree | 37bce0ef915874dfe215ba78e2fe4964b879571e /app | |
parent | 31bc42de57b3cfd7bf068df06d15372307b8661b (diff) |
Refactor task list tests and coffeescript
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/behaviors/taskable_behavior.js.coffee | 21 | ||||
-rw-r--r-- | app/assets/javascripts/issue.js.coffee | 26 | ||||
-rw-r--r-- | app/assets/javascripts/merge_request.js.coffee | 28 |
3 files changed, 34 insertions, 41 deletions
diff --git a/app/assets/javascripts/behaviors/taskable_behavior.js.coffee b/app/assets/javascripts/behaviors/taskable_behavior.js.coffee new file mode 100644 index 00000000000..ddce71c1886 --- /dev/null +++ b/app/assets/javascripts/behaviors/taskable_behavior.js.coffee @@ -0,0 +1,21 @@ +window.updateTaskState = (taskableType) -> + objType = taskableType.data + isChecked = $(this).prop("checked") + if $(this).is(":checked") + stateEvent = "task_check" + else + stateEvent = "task_uncheck" + + taskableUrl = $("form.edit-" + objType).first().attr("action") + taskableNum = taskableUrl.match(/\d+$/) + taskNum = 0 + $("li.task-list-item input:checkbox").each( (index, e) => + if e == this + taskNum = index + 1 + ) + + $.ajax + type: "PATCH" + url: taskableUrl + data: objType + "[state_event]=" + stateEvent + + "&" + objType + "[task_num]=" + taskNum diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee index f2b531fb2b1..0e2a2fa792a 100644 --- a/app/assets/javascripts/issue.js.coffee +++ b/app/assets/javascripts/issue.js.coffee @@ -9,25 +9,11 @@ class Issue if $("a.btn-close").length $("li.task-list-item input:checkbox").prop("disabled", false) - $(".task-list-item input:checkbox").on "click", -> - is_checked = $(this).prop("checked") - if $(this).is(":checked") - state_event = "task_check" - else - state_event = "task_uncheck" - - mr_url = $("form.edit-issue").first().attr("action") - mr_num = mr_url.match(/\d+$/) - task_num = 0 - $("li.task-list-item input:checkbox").each( (index, e) => - if e == this - task_num = index + 1 - ) - - $.ajax - type: "PATCH" - url: mr_url - data: "issue[state_event]=" + state_event + - "&issue[task_num]=" + task_num + $(".task-list-item input:checkbox").on( + "click" + null + "issue" + updateTaskState + ) @Issue = Issue diff --git a/app/assets/javascripts/merge_request.js.coffee b/app/assets/javascripts/merge_request.js.coffee index 203c721c30c..3c78e4b5f0e 100644 --- a/app/assets/javascripts/merge_request.js.coffee +++ b/app/assets/javascripts/merge_request.js.coffee @@ -17,7 +17,7 @@ class MergeRequest disableButtonIfEmptyField '#commit_message', '.accept_merge_request' - if $("a.close-mr-link").length + if $("a.btn-close").length $("li.task-list-item input:checkbox").prop("disabled", false) # Local jQuery finder @@ -74,26 +74,12 @@ class MergeRequest this.$('.remove_source_branch_in_progress').hide() this.$('.remove_source_branch_widget.failed').show() - this.$(".task-list-item input:checkbox").on "click", -> - is_checked = $(this).prop("checked") - if $(this).is(":checked") - state_event = "task_check" - else - state_event = "task_uncheck" - - mr_url = $("form.edit-merge_request").first().attr("action") - mr_num = mr_url.match(/\d+$/) - task_num = 0 - $("li.task-list-item input:checkbox").each( (index, e) => - if e == this - task_num = index + 1 - ) - - $.ajax - type: "PATCH" - url: mr_url - data: "merge_request[state_event]=" + state_event + - "&merge_request[task_num]=" + task_num + $(".task-list-item input:checkbox").on( + "click" + null + "merge_request" + updateTaskState + ) activateTab: (action) -> this.$('.merge-request-tabs li').removeClass 'active' |