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/assets/javascripts/behaviors | |
parent | 31bc42de57b3cfd7bf068df06d15372307b8661b (diff) |
Refactor task list tests and coffeescript
Diffstat (limited to 'app/assets/javascripts/behaviors')
-rw-r--r-- | app/assets/javascripts/behaviors/taskable_behavior.js.coffee | 21 |
1 files changed, 21 insertions, 0 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 |