<commit_before>B = require \backbone
F = require \fs # inlined by brfs
T = require \transparency
_ = require \underscore
H = require \./helper
S = require \./session

const CLASS-EDITING = \editing

module.exports =
  DocuView: B.View.extend do
    initialize: -> @document = it.document
    render: -> @$el.html @document .show!

  EditView: B.View.extend do
    events:
      'click .cancel': \cancel
      'click .delete': \delete
      'submit form'  : \save
    initialize: ->
      @template = it.template
      _.extend this, B.Events
    cancel: -> @trigger \cancelled
    delete: ->
      #TODO: reinstate dialog when Marionette is capable of testing it
      #return unless confirm 'Are you sure you want to delete this item ?'
      @coll.destroy @model, error:H.on-err, success: ~> @trigger \destroyed, @model
    render: (@model, @coll, opts) ->
      @delegateEvents!
      $ \.view .addClass CLASS-EDITING
      B.Validation.bind this
      ($tem = $ @template).addClass if is-new = @model.isNew! then \create else \update
      return render @model if is-new or opts?fetch is no
      @model.fetch error:H.on-err, success: -> render it
      ~function render model then
        @$el.html $tem.render model.toJSON-T! .set-access S .show!
        @$el.find 'input[type=text],textarea,select' .filter \:visible:first .focus!
        @trigger \rendered, model
    save: ->
      unless @model then alert "ERROR! @model is void. Check $el isn't used by other edit views!"
      is-new = @model.isNew!
      (m = @model).attributes = $ it.currentTarget .serializeObject!
      @coll.create m, { +merge, +wait, error:H.on-err, success: ~> @trigger \saved, @model, is-new }
      false
  ResetEditView: -> $ \.view .removeClass CLASS-EDITING

  InfoView: B.View.extend do
    initialize: -> @template = it.template
    render: (model, directive) ->
      data = if model then model.toJSON-T! else {}
      # NOTE: transparency won't process directive if data is void, hence {}
      ($tem = $ @template).render data, directive
      @$el.html $tem .set-access S .show!

  ListView: B.View.extend do
    initialize: -> @template = it.template
    # For fast ui render happens in 2 passes:
    # 1. render current content immediately
    # 2. render async-fetched content
    render: (coll, directive, opts) ->
      @$el.attr \data-loc, B.history.fragment # to detemine if navigated away
      render coll, 0
      return unless coll.url # filtered collection won't have url
      coll.fetch error:H.on-err, success: -> render it, 1
      ~function render c, pass then
        return unless B.history.fragment is @$el.attr \data-loc # bail if user has navigated away
        c = c.find f if f = opts?filter
        return opts?void-view.render! if c.length is 0
        ($tem = $ @template).filter \.items .render c.toJSON-T!, directive
        @$el.html $tem
        @$el.set-access S .show! if pass is 0

  SelectView: B.View.extend do
    get-selected-id: -> @dropdown.val!
    initialize: -> @sel = it.sel
    render: (coll, fname, sel-id = '') ->
      H.insert-css F.readFileSync __dirname + \/lib-3p/bootstrap-combobox.css
      T-Sel = F.readFileSync __dirname + \/view/select.html
      $T-Sel = ($T = $ T-Sel) .filter \select .render coll.toJSON!, item:
        html : -> @[fname]
        value: -> @_id
      if coll.findWhere _id:sel-id .length is 0 then $T-Sel.prepend ($T.filter \.prompt .find \option)
      log @sel
      @dropdown = $ @sel
        ..html $T-Sel.children! # children! prevents duplicate nested select
        ..val sel-id
        ..combobox!
        ..change ~> @trigger \selected<commit_msg>remove logging<commit_after>B = require \backbone
F = require \fs # inlined by brfs
T = require \transparency
_ = require \underscore
H = require \./helper
S = require \./session

const CLASS-EDITING = \editing

module.exports =
  DocuView: B.View.extend do
    initialize: -> @document = it.document
    render: -> @$el.html @document .show!

  EditView: B.View.extend do
    events:
      'click .cancel': \cancel
      'click .delete': \delete
      'submit form'  : \save
    initialize: ->
      @template = it.template
      _.extend this, B.Events
    cancel: -> @trigger \cancelled
    delete: ->
      #TODO: reinstate dialog when Marionette is capable of testing it
      #return unless confirm 'Are you sure you want to delete this item ?'
      @coll.destroy @model, error:H.on-err, success: ~> @trigger \destroyed, @model
    render: (@model, @coll, opts) ->
      @delegateEvents!
      $ \.view .addClass CLASS-EDITING
      B.Validation.bind this
      ($tem = $ @template).addClass if is-new = @model.isNew! then \create else \update
      return render @model if is-new or opts?fetch is no
      @model.fetch error:H.on-err, success: -> render it
      ~function render model then
        @$el.html $tem.render model.toJSON-T! .set-access S .show!
        @$el.find 'input[type=text],textarea,select' .filter \:visible:first .focus!
        @trigger \rendered, model
    save: ->
      unless @model then alert "ERROR! @model is void. Check $el isn't used by other edit views!"
      is-new = @model.isNew!
      (m = @model).attributes = $ it.currentTarget .serializeObject!
      @coll.create m, { +merge, +wait, error:H.on-err, success: ~> @trigger \saved, @model, is-new }
      false
  ResetEditView: -> $ \.view .removeClass CLASS-EDITING

  InfoView: B.View.extend do
    initialize: -> @template = it.template
    render: (model, directive) ->
      data = if model then model.toJSON-T! else {}
      # NOTE: transparency won't process directive if data is void, hence {}
      ($tem = $ @template).render data, directive
      @$el.html $tem .set-access S .show!

  ListView: B.View.extend do
    initialize: -> @template = it.template
    # For fast ui render happens in 2 passes:
    # 1. render current content immediately
    # 2. render async-fetched content
    render: (coll, directive, opts) ->
      @$el.attr \data-loc, B.history.fragment # to detemine if navigated away
      render coll, 0
      return unless coll.url # filtered collection won't have url
      coll.fetch error:H.on-err, success: -> render it, 1
      ~function render c, pass then
        return unless B.history.fragment is @$el.attr \data-loc # bail if user has navigated away
        c = c.find f if f = opts?filter
        return opts?void-view.render! if c.length is 0
        ($tem = $ @template).filter \.items .render c.toJSON-T!, directive
        @$el.html $tem
        @$el.set-access S .show! if pass is 0

  SelectView: B.View.extend do
    get-selected-id: -> @dropdown.val!
    initialize: -> @sel = it.sel
    render: (coll, fname, sel-id = '') ->
      H.insert-css F.readFileSync __dirname + \/lib-3p/bootstrap-combobox.css
      T-Sel = F.readFileSync __dirname + \/view/select.html
      $T-Sel = ($T = $ T-Sel) .filter \select .render coll.toJSON!, item:
        html : -> @[fname]
        value: -> @_id
      if coll.findWhere _id:sel-id .length is 0 then $T-Sel.prepend ($T.filter \.prompt .find \option)
      @dropdown = $ @sel
        ..html $T-Sel.children! # children! prevents duplicate nested select
        ..val sel-id
        ..combobox!
        ..change ~> @trigger \selected
{'fraction_non_alphanumeric': 0.13089655172413794, 'fraction_numerical': 0.0024827586206896553, 'mean_word_length': 2.456148713060057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, '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': '4476809', 'n_tokens_mistral': 2327, 'n_tokens_neox': 2248, 'n_words': 730}