<commit_before>kd = require 'kd'
_  = require 'lodash'
present = require './present-binding'
facade = require('./actions-facade')
EventType = require './event-type'

DUP_CLASS_NAME = 'collides'

module.exports =

class Item extends kd.View

  constructor: (options, @model, @_dup) ->

    @_enabled = @model.enabled
    @_handlers = null

    super _.extend cssClass: 'row', options


  viewAppended: ->

    if @_dup then @setClass DUP_CLASS_NAME
    delete @_dup

    toggle = new kd.View
      cssClass : 'col'
      tagName  : 'div'
      partial: '<div class=toggle><span class=icon>'

    if @model.enabled then toggle.setClass 'enabled'

    description = new kd.View
      cssClass : 'col'
      partial  : _.escape @model.description

    binding = new kd.View
      cssClass : 'col'
      partial  : present _.first @model.binding

    toggleClickHandler = (e, silent=no) =>
      @_enabled = if _.isBoolean e then e else not @_enabled
      if @_enabled then toggle.setClass 'enabled' else toggle.unsetClass 'enabled'
      unless silent
        @emit EventType.Item.TOGGLED, @_enabled

    bindingClickHandler = =>
      @setClass 'active'
      binding.updatePartial ''
      @emit EventType.Item.SELECTED,
        (res) =>
          partial = if res then present res else present _.first @model.binding<commit_msg>shortcuts/item: do not add subviews on viewAppended (see: https://github.com/koding/koding/pull/3396#discussion_r28393016)<commit_after>kd = require 'kd'
_  = require 'lodash'
present = require './present-binding'
facade = require('./actions-facade')
EventType = require './event-type'

DUP_CLASS_NAME = 'collides'

module.exports =

class Item extends kd.View

  constructor: (options, @model, @_dup) ->

    @_enabled = @model.enabled
    @_handlers = null

    super _.extend cssClass: 'row', options

    @addSubViews()


  addSubViews: ->

    if @_dup then @setClass DUP_CLASS_NAME
    delete @_dup

    toggle = new kd.View
      cssClass : 'col'
      tagName  : 'div'
      partial: '<div class=toggle><span class=icon>'

    if @model.enabled then toggle.setClass 'enabled'

    description = new kd.View
      cssClass : 'col'
      partial  : _.escape @model.description

    binding = new kd.View
      cssClass : 'col'
      partial  : present _.first @model.binding

    toggleClickHandler = (e, silent=no) =>
      @_enabled = if _.isBoolean e then e else not @_enabled
      if @_enabled then toggle.setClass 'enabled' else toggle.unsetClass 'enabled'
      unless silent
        @emit EventType.Item.TOGGLED, @_enabled

    bindingClickHandler = =>
      @setClass 'active'
      binding.updatePartial ''
      @emit EventType.Item.SELECTED,
        (res) =>
          partial = if res then present res else present _.first @model.binding
{'fraction_non_alphanumeric': 0.11027298850574713, 'fraction_numerical': 0.004310344827586207, 'mean_word_length': 2.8626907073509016, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 1, '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': '4874654', 'n_tokens_mistral': 888, 'n_tokens_neox': 852, 'n_words': 240}