<commit_before>class App.SettingsArea extends App.Controller
  constructor: ->
    super

    # check authentication
    return if !@authenticate()

    App.Setting.bind 'refresh change', @render
    App.Setting.fetch()

  render: =>
    settings = App.Setting.all()
    
    html = $('<div></div>')
    for setting in settings
      if setting.area is @area
        item = new App.SettingsAreaItem( setting: setting ) 
        html.append( item.el )

    @html html

class App.SettingsAreaItem extends App.Controller
  events:
    'submit form': 'update'

  constructor: ->
    super
    @render()

  render: =>
    # defaults
    for item in @setting.options['form']
      if typeof @setting.state.value is 'object'
        item['default'] = @setting.state.value[item.name]
      else
        item['default'] = @setting.state.value

    # form
    @configure_attributes = @setting.options['form']

    # item
    @html App.view('settings/item')(
      setting: @setting,
    )

    new App.ControllerForm(
      el: @el.find('#form-item'),
      model: { configure_attributes: @configure_attributes, className: '' },
      autofocus: false,
    )

  update: (e) =>
    e.preventDefault()
    params = @formParam(e.target)
    @log 'submit', @setting, params, e.target, typeof @setting.state.value
    if typeof @setting.state.value is 'object'
      state = {
        value: params
      }
    else<commit_msg>Improved generic setting widget.<commit_after>class App.SettingsArea extends App.Controller
  constructor: ->
    super

    # check authentication
    return if !@authenticate()

    App.Setting.bind 'refresh change', @render
    App.Setting.fetch()

  render: =>
    settings = App.Setting.all()
    
    html = $('<div></div>')
    for setting in settings
      if setting.area is @area
        item = new App.SettingsAreaItem( setting: setting ) 
        html.append( item.el )

    @html html

class App.SettingsAreaItem extends App.Controller
  events:
    'submit form': 'update'

  constructor: ->
    super
    @render()

  render: =>
    # defaults
    directValue = 0
    for item in @setting.options['form']
      directValue = +1

    if directValue > 1
      item['default'] = @setting.state.value[item.name]
    else
      item['default'] = @setting.state.value

    # form
    @configure_attributes = @setting.options['form']

    # item
    @html App.view('settings/item')(
      setting: @setting,
    )

    new App.ControllerForm(
      el: @el.find('#form-item'),
      model: { configure_attributes: @configure_attributes, className: '' },
      autofocus: false,
    )

  update: (e) =>
    e.preventDefault()
    params = @formParam(e.target)
    @log 'submit', @setting, params, e.target, typeof @setting.state.value
    directValue = 0
    for item in @setting.options['form']
      directValue = +1

    if directValue > 1
      state = {
        value: params
      }
    else
{'fraction_non_alphanumeric': 0.12722908093278465, 'fraction_numerical': 0.00205761316872428, 'mean_word_length': 2.548661800486618, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3521654', 'n_tokens_mistral': 888, 'n_tokens_neox': 860, 'n_words': 218}