aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts/selectable_table.coffee
diff options
context:
space:
mode:
authorjpl2017-02-06 18:13:30 +0100
committerjpl2017-02-06 18:13:30 +0100
commit045650481048cf957a0ef83ed9092a94bc20c904 (patch)
tree8154750b818bdb01868316e86f7fd8fa812bf75f /app/assets/javascripts/selectable_table.coffee
parent3567bbf39d65d55c3e49b647bac4bf4b5cbb6fc3 (diff)
downloadchouette-core-045650481048cf957a0ef83ed9092a94bc20c904.tar.bz2
Refs #2535: adding selectable feat. to table builder
Diffstat (limited to 'app/assets/javascripts/selectable_table.coffee')
-rw-r--r--app/assets/javascripts/selectable_table.coffee31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/assets/javascripts/selectable_table.coffee b/app/assets/javascripts/selectable_table.coffee
new file mode 100644
index 000000000..bb5fd6484
--- /dev/null
+++ b/app/assets/javascripts/selectable_table.coffee
@@ -0,0 +1,31 @@
+@selectTable = ->
+ $('.table').each ->
+ selection = []
+ $(this).on 'click', "[type='checkbox']", (e)->
+ if e.currentTarget.id == '0'
+ if e.currentTarget.checked
+ $("[type='checkbox']").each ->
+ $(this).prop('checked', true)
+ # Add each element to selection
+ selection.push($(this).attr('id'))
+
+ # Remove th checkbox from selection
+ selection.splice(0, 1)
+
+ else
+ $("[type='checkbox']").each ->
+ $(this).prop('checked', false)
+ # Empty selection
+ selection = []
+
+ else
+ if e.currentTarget.checked
+ selection.push(e.currentTarget.id)
+ else
+ elm = selection.indexOf(e.currentTarget.id)
+ selection.splice(elm, 1)
+
+ # We log the selection (for now)
+ console.log selection
+
+$(document).on 'ready page:load', selectTable