Skip to content

Instantly share code, notes, and snippets.

@Loschcode
Created April 30, 2014 12:40
Show Gist options
  • Save Loschcode/f057ebe9cc9caee65c30 to your computer and use it in GitHub Desktop.
Save Loschcode/f057ebe9cc9caee65c30 to your computer and use it in GitHub Desktop.
# request_manager.coffee
load_request_manager = ->
this.daterange_picker_datatable('#client_request_daterangepicker')
$(document).ready(load_request_manager)
$(document).on('page:load', load_request_manager)
# shared/je_sais_plus_quoi (chargé avant)
daterange_picker_datatable: (element_id) ->
#
# We configure the daterangepicker
#
configObj = {
format: 'MMM D, YYYY',
separator: ' - ',
language: 'auto'
}
#
# We set the timestamps
#
timestamp_start = 0
timestamp_end = 0
# We load the date rangepicker and manage the changes in the datatable
$(element_id).dateRangePicker(configObj).bind('datepicker-apply', (event, datepicker) ->
# We select the data_table
datatable_entity = $('#data_table').dataTable()
# Datas we can take :
#
# - datepicker.date1
# - datepicker.date2
#
timestamp_start = Date.parse(datepicker.date1)
timestamp_end = Date.parse(datepicker.date2)
datatable_entity.fnDraw()
)
$.fn.dataTableExt.afnFiltering.push (oSettings, aData, iDataIndex) ->
#
# We got all the dates into timestamp format to compare it as integers
#
row = 1 # Don't forget it starts with 0, from the left
iMin = timestamp_start # We get our date from the date range picker (start)
iMax = timestamp_end # We get our date from the date range picker (end)
#console.log('aData '+aData[row])
#console.log('iMin '+iMin)
#console.log('iMax '+iMax)
timestamp_date = new Date(aData[row]).getTime()
#console.log('iDate before '+timestamp_date)
iDate = (if timestamp_date is "-" then 0 else timestamp_date * 1)
#console.log('iDate after '+iDate)
if iMin is "" and iMax is ""
#console.log('true 1')
return true
else if iMin is "" and iDate < iMax
#console.log('true 2')
return true
else if iMin < iDate and "" is iMax
#console.log('true 3')
return true
else if iMin < iDate and iDate < iMax
#console.log('true 4')
return true
#console.log('false')
return false
#return false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment