"""
constructor: (@$el) ->
$uploadedFile = @$el.parent().find('a, img').addClass('uploaded-file').remove()
unless @$el.data("file-upload")
$container = @$el.parent().html(@template)
# Append input to file buttons
$container.find(".btn-file").append(@$el)
# Add preview link if existing
$container.prepend($uploadedFile) if $uploadedFile.length
# Store object in "file-upload" data key on dom element
@$el.data("file-upload", this)
class CheckboxBuilder
constructor: (@$el) ->
unless @$el.data("checkbox")
@$el.wrap('')
@$el.closest('.checkbox').prepend("")
@$el.closest(".checkbox").on 'click', ->
setupLabel()
setupLabel()
# Store object in "checkbox" data key on dom element
@$el.data("checkbox", this)
class SpinnerBuilder
template:
"""
"""
# input custom constructor
constructor: (@$el) ->
unless @$el.data("spinner")
@$el.addClass "spinner-input"
$spinner_wrapper = @$el.wrap("")
$(@template).insertAfter @$el
# @$el.closest(".spinner").spinner('value')
# Store object in "spinner" data key on dom element
@$el.data("spinner", this)
class SelectBuilder
# input custom constructor
constructor: (@$el) ->
$jquerySelect = @$el.closest('.controls').find('.filtering-select')
if $jquerySelect.length
else
unless @$el.data("select")
$jqueryMultiSelect = @$el.closest('.controls').find('.ra-multiselect').remove()
@$el.closest('select').selectpicker(
title: '-- Selectionnez --'
)
# Store object in "spinner" data key on dom element
@$el.data("select", this)
class FormInputs
fieldTypes:
'input[type="file"]': FileUploadBuilder
'input[type="number"]': SpinnerBuilder
'input[type="checkbox"]:visible': CheckboxBuilder
'select': SelectBuilder
constructor: (@selector, options = {}) ->
# # Constructor when page is loaded by pjax
$(document).on "ready pjax:end nested:fieldAdded", =>
@$el = $(@selector)
@processFields()
processFields: ->
$.each @fieldTypes, (selector, klass) =>
@$el.find(selector).each ->
new klass($(this))
$ ->
# Hack for Ipad
$("body").on "touchstart.dropdown", ".dropdown-menu", (e) ->
e.stopPropagation()
# Add class
$("body.rails_admin").addClass 'glyph-theme-js'
# Form Inputs constructor
new FormInputs("form")
# Toggle checkbox list & export
$(document).on "click", "#list input.toggle", ->
$("#list [name='bulk_ids[]']").prop("checked", $(this).is(":checked")).closest('.checkbox').toggleClass('checked')
$(document).on "click", "#fields_to_export label input#check_all", ->
elems = $("#fields_to_export label input")
$checbox_checked = $("#fields_to_export label input#check_all").is(":checked")
if $checbox_checked
$(elems).closest('.checkbox').addClass 'checked'
$(elems).prop "checked", true
else
$(elems).closest('.checkbox').removeClass 'checked'
$(elems).prop "checked", false