<commit_before>/*
 * Copyright (C) 2013-2014 by <NAME> Brinkmann
 */

package twibs.form.bootstrap3

import org.threeten.bp.format.DateTimeFormatter
import org.threeten.bp.{LocalDate, LocalDateTime}
import twibs.form.base._
import twibs.util.JavaScript._
import twibs.util.{InfoDisplayType, DangerDisplayType, Message, Translator}
import twibs.web.Upload
import xml._

trait ReadOnlyField extends Field {
  override def inputAsEnrichedHtml(input: Input, index: Int) =
    HiddenInputRenderer(name, input.string) ++ <p class="form-control-static">{input.title}</p>

  override def inputAsElem(input: Input) = <span></span>
}

trait Emptiable extends Field {
  override def inputAsEnrichedHtml(input: Input, index: Int): NodeSeq =
    <span class="emptiable">{super.inputAsEnrichedHtml(input, index)}<span class="input-clear glyphicon glyphicon-remove"></span></span>
}

trait FieldWithSuffixes extends Field {
  def suffixes: List[NodeSeq] = suffix :: Nil

  def suffix: NodeSeq = NodeSeq.Empty

  def surroundWithInputGroup(input: Input, nodeSeq: NodeSeq) = <div class="input-group">{nodeSeq}</div>

  override def inputAsEnrichedHtml(input: Input, index: Int): NodeSeq = {
    (suffixes.filterNot(_.isEmpty).map(s => <span class="input-group-addon">{ s }</span>), infoHtml) match {
      case (Nil, NodeSeq.Empty) => super.inputAsEnrichedHtml(input, index)
      case (suffixes, infoHtml) => surroundWithInputGroup(input, super.inputAsEnrichedHtml(input, index) ++ suffixes ++ infoHtml)
    }
  }

  protected override def infoHtml: NodeSeq = super.infoHtml match {
    case NodeSeq.Empty => NodeSeq.Empty
    case x => <span class="input-group-btn field-info">{x}</span>
  }
}

trait TextField extends FieldWithSuffixes {
  def placeholder = t"placeholder: Please enter text"
}

trait SingleLineField extends TextField {
  override def inputAsElem(input: Input) = <input type="text" placeholder={placeholder} value={input.string} />
}

trait AbstractDateTimeField extends SingleLineField with JavascriptItem {
  def datePickerOptions = Map("autoclose" -> autoClose, "pickerPosition" -> "bottom-left", "language" -> "de")

  def autoClose = true

  override def javascript = if (submitOnChange) initDateTimeJs.call("on", "changeDate", JsCmd("$(this).reloadForm()")) else initDateTimeJs

  private def initDateTimeJs = jQuery(inputGroupId).call("datetimepicker", datePickerOptions)

  private def inputGroupId = id + "_input_group"

  override def suffixes: List[NodeSeq] =
    if (isEnabled) <span class="glyphicon glyphicon-calendar"></span> :: super.suffixes
    else super.suffixes


  override def surroundWithInputGroup(input: Input, nodeSeq: NodeSeq): Elem =
    <div class="input-group date" id={inputGroupId} data-date={input.string} data-link-field={id} data-link-format={formatPatternForBrowser} data-date-format={formatPatternForBrowser} data-date-today-btn={todayButton} data-date-today-highlight={"" + todayHighlight}>{nodeSeq}</div>
      .add(!minimumFormattedForBrowser.isEmpty, "data-date-startdate", minimumFormattedForBrowser)
      .add(!maximumFormattedForBrowser.isEmpty, "data-date-enddate", maximumFormattedForBrowser)

  override def inputAsEnrichedHtml(input: Input, index: Int) =
    if (isDisabled)
      super.inputAsEnrichedHtml(input, index)
    else
      super.inputAsEnrichedHtml(input, index) ++ clearButton<commit_msg>- show datepicker only for enabled fields<commit_after>/*
 * Copyright (C) 2013-2014 by <NAME>
 */

package twibs.form.bootstrap3

import org.threeten.bp.format.DateTimeFormatter
import org.threeten.bp.{LocalDate, LocalDateTime}
import twibs.form.base._
import twibs.util.JavaScript._
import twibs.util.{InfoDisplayType, DangerDisplayType, Message, Translator}
import twibs.web.Upload
import xml._

trait ReadOnlyField extends Field {
  override def inputAsEnrichedHtml(input: Input, index: Int) =
    HiddenInputRenderer(name, input.string) ++ <p class="form-control-static">{input.title}</p>

  override def inputAsElem(input: Input) = <span></span>
}

trait Emptiable extends Field {
  override def inputAsEnrichedHtml(input: Input, index: Int): NodeSeq =
    <span class="emptiable">{super.inputAsEnrichedHtml(input, index)}<span class="input-clear glyphicon glyphicon-remove"></span></span>
}

trait FieldWithSuffixes extends Field {
  def suffixes: List[NodeSeq] = suffix :: Nil

  def suffix: NodeSeq = NodeSeq.Empty

  def surroundWithInputGroup(input: Input, nodeSeq: NodeSeq) = <div class="input-group">{nodeSeq}</div>

  override def inputAsEnrichedHtml(input: Input, index: Int): NodeSeq = {
    (suffixes.filterNot(_.isEmpty).map(s => <span class="input-group-addon">{ s }</span>), infoHtml) match {
      case (Nil, NodeSeq.Empty) => super.inputAsEnrichedHtml(input, index)
      case (suffixes, infoHtml) => surroundWithInputGroup(input, super.inputAsEnrichedHtml(input, index) ++ suffixes ++ infoHtml)
    }
  }

  protected override def infoHtml: NodeSeq = super.infoHtml match {
    case NodeSeq.Empty => NodeSeq.Empty
    case x => <span class="input-group-btn field-info">{x}</span>
  }
}

trait TextField extends FieldWithSuffixes {
  def placeholder = t"placeholder: Please enter text"
}

trait SingleLineField extends TextField {
  override def inputAsElem(input: Input) = <input type="text" placeholder={placeholder} value={input.string} />
}

trait AbstractDateTimeField extends SingleLineField with JavascriptItem {
  def datePickerOptions = Map("autoclose" -> autoClose, "pickerPosition" -> "bottom-left", "language" -> "de")

  def autoClose = true

  override def javascript =
    if (isEnabled)
      if (submitOnChange) initDateTimeJs.call("on", "changeDate", JsCmd("$(this).reloadForm()")) else initDateTimeJs
    else JsEmpty

  private def initDateTimeJs = jQuery(inputGroupId).call("datetimepicker", datePickerOptions)

  private def inputGroupId = id + "_input_group"

  override def suffixes: List[NodeSeq] =
    if (isEnabled) <span class="glyphicon glyphicon-calendar"></span> :: super.suffixes
    else super.suffixes

  override def surroundWithInputGroup(input: Input, nodeSeq: NodeSeq): Elem =
    <div class="input-group date" id={inputGroupId} data-date={input.string} data-link-field={id} data-link-format={formatPatternForBrowser} data-date-format={formatPatternForBrowser} data-date-today-btn={todayButton} data-date-today-highlight={"" + todayHighlight}>{nodeSeq}</div>
      .add(!minimumFormattedForBrowser.isEmpty, "data-date-startdate", minimumFormattedForBrowser)
      .add(!maximumFormattedForBrowser.isEmpty, "data-date-enddate", maximumFormattedForBrowser)

  override def inputAsEnrichedHtml(input: Input, index: Int) =
    if (isDisabled)
      super.inputAsEnrichedHtml(input, index)
    else
      super.inputAsEnrichedHtml(input, index) ++ clearButton
{'fraction_non_alphanumeric': 0.125129265770424, 'fraction_numerical': 0.0026591815630078296, 'mean_word_length': 5.3389513108614235, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '13656', 'n_tokens_mistral': 2123, 'n_tokens_neox': 2026, 'n_words': 476}