PageRenderTime 192ms CodeModel.GetById 42ms RepoModel.GetById 9ms app.codeStats 0ms

/client/app/views/form/chosen_view/index.coffee

https://bitbucket.org/lutashi/node12306
CoffeeScript | 48 lines | 41 code | 7 blank | 0 comment | 2 complexity | ad4a64a9d1b395249347f5c4c395e1d1 MD5 | raw file
  1. require './lib/chosen.jquery'
  2. module.exports = class ChosenView extends Backbone.View
  3. template: require './templates/chosen'
  4. defaults:
  5. name: null
  6. placeholder: null
  7. multiple: null
  8. defaultValue: null
  9. span: null
  10. value: null
  11. text: null
  12. groupBy: null
  13. subText: null
  14. selected: null
  15. disabled: false
  16. allowDeselect: true
  17. events:
  18. 'change select': 'saveSelected'
  19. initialize: ->
  20. @options = _.extend @defaults, @options
  21. @selected = @options.defaultValue
  22. @collection.bind 'reset', @render
  23. @render()
  24. render: =>
  25. @$el.html @template
  26. collection: @collection?.toJSON()
  27. multiple: @options.multiple
  28. placeholder: @options.placeholder
  29. span: @options.span ? 'span4'
  30. name: @options.name
  31. value: @options.value
  32. text: @options.text
  33. groupBy: @options.groupBy
  34. subText: @options.subText
  35. selected: if _.isArray(@selected) then @selected else [@selected]
  36. disabled: @options.disabled
  37. @$('select').chosen
  38. allow_single_deselect: @options.allowDeselect
  39. this
  40. saveSelected: =>
  41. @selected = @$('select').val()