aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts/selectable_table.coffee
diff options
context:
space:
mode:
authorjpl2017-03-07 12:17:17 +0100
committerjpl2017-03-07 12:17:17 +0100
commit54dd75a51b9e52f12e190f7166499df36196541a (patch)
tree6c4164b3bac274151cac961bf0d9606dc0fdf874 /app/assets/javascripts/selectable_table.coffee
parent6a05000eb7d371ef22bf1e91b7d23cca1e3f8e92 (diff)
downloadchouette-core-54dd75a51b9e52f12e190f7166499df36196541a.tar.bz2
Fix stuff
Diffstat (limited to 'app/assets/javascripts/selectable_table.coffee')
-rw-r--r--app/assets/javascripts/selectable_table.coffee56
1 files changed, 56 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..4d9f5122a
--- /dev/null
+++ b/app/assets/javascripts/selectable_table.coffee
@@ -0,0 +1,56 @@
+@selectTable = ->
+ $('.select_table').each ->
+ selection = []
+ toolbox = $(this).children('.select_toolbox')
+
+ $(this).on 'click', "[type='checkbox']", (e)->
+ if e.currentTarget.id == '0'
+ selection = []
+ if e.currentTarget.checked
+ $(this).closest('.table').find("[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
+ $(this).closest('.table').find("[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)
+
+ # console.log(selection)
+
+ # Updating toolbox, according to selection
+ if selection.length > 0
+ toolbox
+ .removeClass 'noselect'
+ .children('.info-msg').children('span').text(selection.length)
+
+ # Injecting selection into action urls
+ toolbox.find('.st_action').each ->
+ actionURL = $(this).children('a').attr('data-path')
+
+ newSelection = []
+ i = 0
+ while i < selection.length
+ newSelection[i] = 'referentials[]=' + selection[i] + ''
+ i++
+
+ $(this).children('a').attr('href', actionURL + '?' + newSelection.join('&'))
+
+ else
+ toolbox
+ .addClass 'noselect'
+ .children('.info-msg').children('span').text(selection.length)
+
+$(document).on 'ready page:load', selectTable