<commit_before>package im.mange.jetboot.input

import im.mange.jetboot.{Event, Js}
import im.mange.jetboot.widget.form.FormInput
import net.liftweb.http.SHtml
import net.liftweb.http.js.JsCmd
import org.joda.time.LocalDate
import net.liftweb.http.SHtml
import net.liftweb.http.js.JE.JsRaw
import net.liftweb.http.js.{JsCmd, JsExp}
import net.liftweb.util.Helpers._

//TIP: this depends on https://eonasdan.github.io/bootstrap-datetimepicker/
case class DatePicker(field: Field, default: Option[LocalDate], allowWeekends: Boolean = true) extends FormInput {
  private val defaultStr = default.map(_.toString("dd/MM/yyyy")).getOrElse("")
  var value = defaultStr
  private def widgetId = s"datepicker-$id"
  private val daysOfWeekDisabled = if (allowWeekends) "" -> "" else "daysOfWeekDisabled" -> "[0,6]"
  private val options = Seq("format" -> "\"DD/MM/YYYY\"", "showTodayButton" -> "false", daysOfWeekDisabled).map(x => s"${x._1}:${x._2}")

  //TIP: https://github.com/Eonasdan/bootstrap-datetimepicker/issues/983
  private def js = s"""$$(function () {
      |$$('#$widgetId').datetimepicker({${options.mkString(",")}})
      |.on('dp.hide',function (e) {
      |$$('#$id').trigger('change');
      |});
      |});""".stripMargin

  //TIP: this font-size 7px is a nasty layout hack to support input-xs
  //TODO: remove the script and override init instead ....
  //TODO: this is all a bit nasty, it's because EventHandlers is broken
  override def render = <div>
    <div class='input-group date' id={widgetId}>
      {attachHandlersToBase(baseElement)}
      <span class="input-group-addon" style="font-size: 7px;">
        <span class="glyphicon glyphicon-calendar"/><commit_msg>touch<commit_after>package im.mange.jetboot.input

import im.mange.jetboot.{Event, Js}
import im.mange.jetboot.widget.form.FormInput
import net.liftweb.http.SHtml
import net.liftweb.http.js.JsCmd
import org.joda.time.LocalDate
import net.liftweb.http.SHtml
import net.liftweb.http.js.JE.JsRaw
import net.liftweb.http.js.{JsCmd, JsExp}
import net.liftweb.util.Helpers._

//TIP: this depends on https://eonasdan.github.io/bootstrap-datetimepicker/
case class DatePicker(field: Field, default: Option[LocalDate], allowWeekends: Boolean = true) extends FormInput {
  private val defaultStr = default.map(_.toString("dd/MM/yyyy")).getOrElse("")
  var value = defaultStr
  private def widgetId = s"datepicker-$id"
  private val daysOfWeekDisabled = if (allowWeekends) "" -> "" else "daysOfWeekDisabled" -> "[0,6]"
  private val options = Seq("format" -> "\"DD/MM/YYYY\"", "showTodayButton" -> "false", daysOfWeekDisabled).map(x => s"${x._1}:${x._2}")

  //TIP: we have to simulate onchange - https://github.com/Eonasdan/bootstrap-datetimepicker/issues/983
  private def js = s"""$$(function () {
      |$$('#$widgetId').datetimepicker({${options.mkString(",")}})
      |.on('dp.hide',function (e) {
      |$$('#$id').trigger('change');
      |});
      |});""".stripMargin

  //TIP: this font-size 7px is a nasty layout hack to support input-xs
  //TODO: this is all a bit nasty, it's because EventHandlers is broken
  override def render = <div>
    <div class='input-group date' id={widgetId}>
      {attachHandlersToBase(baseElement)}
      <span class="input-group-addon" style="font-size: 7px;">
        <span class="glyphicon glyphicon-calendar"/>
{'fraction_non_alphanumeric': 0.16756756756756758, 'fraction_numerical': 0.005405405405405406, 'mean_word_length': 4.245669291338583, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 4, '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': '2009913', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1101, 'n_words': 246}