<commit_before>define 'cs!xlform/view.row', [
        'backbone',
        'jquery',
        'cs!xlform/view.rowSelector',
        'cs!xlform/model.row',
        'cs!xlform/view.templates',
        'cs!xlform/view.utils',
        'cs!xlform/model.choices',
        'cs!xlform/view.choices',
        'cs!xlform/view.rowDetail',
        ], (
            Backbone,
            $,
            $rowSelector,
            $row,
            $viewTemplates,
            $viewUtils,
            $choices,
            $viewChoices,
            $viewRowDetail,
            )->

  class RowView extends Backbone.View
    tagName: "li"
    className: "xlf-row-view"
    events:
     "click": "select"
     "click .js-expand-row-selector": "expandRowSelector"
     "drop": "drop"
     "click .js-advanced-toggle": "expandCog"
     "click .js-expand-multioptions": "expandMultiOptions"
     "click .row-extras__add-to-question-library": "add_row_to_question_library"

    initialize: (opts)->
      @options = opts
      typeDetail = @model.get("type")
      @$el.attr("data-row-id", @model.cid)
      @ngScope = opts.ngScope
      # @model.on "change", @render, @
      # typeDetail.on "change:value", _.bind(@render, @)
      # typeDetail.on "change:listName", _.bind(@render, @)
      @surveyView = @options.surveyView
      @model.on "detail-change", (key, value, ctxt)=>
        customEventName = "row-detail-change-#{key}"
        @$(".on-#{customEventName}").trigger(customEventName, key, value, ctxt)

      @$el.on "xlf-blur", =>
        @$el.removeClass("xlf-selected")

    drop: (evt, index)->
      @$el.trigger("update-sort", [@model, index])

    select: ->
      unless @$el.hasClass("xlf-selected")
        $(".xlf-selected").trigger("xlf-blur")
        @$el.addClass("xlf-selected")
    expandRowSelector: ->
      new $rowSelector.RowSelector(el: @$el.find(".expanding-spacer-between-rows").get(0), ngScope: @ngScope, spawnedFromView: @).expand()

    render: ->
      if @model instanceof $row.RowError
        @_renderError()
      else
        @_renderRow()
      @$el.data("row-index", @model.getSurvey().rows.indexOf @model)
      @
    _renderError: ->
      @$el.addClass("xlf-row-view-error")
      atts = $viewUtils.cleanStringify(@model.attributes)
      @$el.html $viewTemplates.$$render('row.rowErrorView', atts)
      @
    _renderRow: ->
      @$el.html $viewTemplates.$$render('row.xlfRowView')
      @listView = new $viewChoices.ListView(el: @$(".list-view"), model: cl, rowView: @).render()
      @multiOptions = @$(".row__multioptions")
      @multiOptions.addClass("hidden")
      @rowExtras = @$(".row-extras")
      @rowExtrasSummary = @$(".row-extras-summary")
      for [key, val] in @model.attributesArray()
        new $viewRowDetail.DetailView(model: val, rowView: @).renderInRowView(@)
      @

    expandCog: (evt)->
      evt.stopPropagation()
      @rowExtras.parent().toggleClass("activated")
      @$(evt.currentTarget).toggleClass("activated")
      @rowExtrasSummary.toggleClass("hidden")
      @rowExtras.toggleClass("hidden")

    expandMultiOptions: (evt)->
      evt.stopPropagation()
      @$(evt.currentTarget).parent().toggleClass("activated")
      @$(evt.currentTarget).children("i").toggleClass("fa-caret-right").toggleClass("fa-caret-down")
      @multiOptions.toggleClass("hidden")

    add_row_to_question_library: (evt) ->
      evt.stopPropagation()
      @ngScope.add_row_to_question_library @model

  RowView: RowView
<commit_msg>trying out a cleaner way of toggling expanded choice lists and settings with just a className change on the parent '.card'<commit_after>define 'cs!xlform/view.row', [
        'backbone',
        'jquery',
        'cs!xlform/view.rowSelector',
        'cs!xlform/model.row',
        'cs!xlform/view.templates',
        'cs!xlform/view.utils',
        'cs!xlform/view.choices',
        'cs!xlform/view.rowDetail',
        ], (
            Backbone,
            $,
            $rowSelector,
            $row,
            $viewTemplates,
            $viewUtils,
            $viewChoices,
            $viewRowDetail,
            )->

  class RowView extends Backbone.View
    tagName: "li"
    className: "xlf-row-view"
    events:
     "click": "select"
     "click .js-expand-row-selector": "expandRowSelector"
     "drop": "drop"
     "click .js-advanced-toggle": "toggleSettings"
     "click .js-expand-multioptions": "toggleMultiOptions"
     "click .row-extras__add-to-question-library": "add_row_to_question_library"

    initialize: (opts)->
      @options = opts
      typeDetail = @model.get("type")
      @$el.attr("data-row-id", @model.cid)
      @ngScope = opts.ngScope
      # @model.on "change", @render, @
      # typeDetail.on "change:value", _.bind(@render, @)
      # typeDetail.on "change:listName", _.bind(@render, @)
      @surveyView = @options.surveyView
      @model.on "detail-change", (key, value, ctxt)=>
        customEventName = "row-detail-change-#{key}"
        @$(".on-#{customEventName}").trigger(customEventName, key, value, ctxt)

      @$el.on "xlf-blur", =>
        @$el.removeClass("xlf-selected")

    drop: (evt, index)->
      @$el.trigger("update-sort", [@model, index])

    select: ->
      unless @$el.hasClass("xlf-selected")
        $(".xlf-selected").trigger("xlf-blur")
        @$el.addClass("xlf-selected")
    expandRowSelector: ->
      new $rowSelector.RowSelector(el: @$el.find(".expanding-spacer-between-rows").get(0), ngScope: @ngScope, spawnedFromView: @).expand()

    render: ->
      if @model instanceof $row.RowError
        @_renderError()
      else
        @_renderRow()
      @$el.data("row-index", @model.getSurvey().rows.indexOf @model)
      @
    _renderError: ->
      @$el.addClass("xlf-row-view-error")
      atts = $viewUtils.cleanStringify(@model.attributes)
      @$el.html $viewTemplates.$$render('row.rowErrorView', atts)
      @
    _renderRow: ->
      @$el.html $viewTemplates.$$render('row.xlfRowView')
      @$card = @$el.find('.card')
      if (cl = @model.getList())
        @$card.addClass('card--selectquestion')
        @listView = new $viewChoices.ListView(el: @$(".list-view"), model: cl, rowView: @).render()

      # @multiOptions = @$(".row__multioptions")
      # @multiOptions.addClass("hidden")

      @rowExtras = @$(".row-extras")
      @rowExtrasSummary = @$(".row-extras-summary")
      for [key, val] in @model.attributesArray()
        new $viewRowDetail.DetailView(model: val, rowView: @).renderInRowView(@)
      @

    toggleSettings: (evt)->
      evt.stopPropagation()

      # cannot be expandsettings and expandchoices at the same time
      @$card.removeClass('card--expandedchoices')
      @$card.toggleClass('card--expandsettings')

      # @rowExtras.parent().toggleClass("activated")
      # @$(evt.currentTarget).toggleClass("activated")
      # @rowExtrasSummary.toggleClass("hidden")
      # @rowExtras.toggleClass("hidden")

    toggleMultiOptions: (evt)->
      evt.stopPropagation()

      # cannot be expandsettings and expandchoices at the same time
      @$card.removeClass('card--expandsettings')
      @$card.toggleClass('card--expandedchoices')

      # @$(evt.currentTarget).parent().toggleClass("activated")
      # @$(evt.currentTarget).children("i").toggleClass("fa-caret-right").toggleClass("fa-caret-down")
      # @multiOptions.toggleClass("hidden")

    add_row_to_question_library: (evt) ->
      evt.stopPropagation()
      @ngScope.add_row_to_question_library @model

  RowView: RowView

{'fraction_non_alphanumeric': 0.16859922697587632, 'fraction_numerical': 0.0002665600426496068, 'mean_word_length': 2.765178123432012, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 29, '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': '4655190', 'n_tokens_mistral': 2461, 'n_tokens_neox': 2442, 'n_words': 376}