<commit_before>{#
   The big question is, do we check if the user is logged in here, or should that be done in the twig templatye including this?
   For now, I vote the including template.
 #}
<script type="text/javascript">
function createPmMessage() {
    $( "#createpm" ).dialog("open");
    return false;
}

function checkUnread() {
    $.ajax({
        beforeSend: function(req) {
          req.setRequestHeader("Accept", "application/json");
        },
        type: "GET",
        url: "{{ path('check_unread', { 'access': 'ajax' }) }}",
        dataType: "json",
        async: true,
      }).done( function( cont, textStatus, xhr ) {
          if (cont['amount'] > 0) {
              $( "#message_menu" ).children().css("color","red");
              $( "#message_menu .dropdown-toggle" ).append("("+cont['amount']+")");
              $( "#menu_unread" ).show();
          } else {
            setTimeout ( "checkUnread()", 60000 );
          }
      });
    return false;
}

function submitPmMessageForm(pmform, in_reply_to) {
    pmform = "#" + pmform;
    formdata = $( pmform ).serialize();
    url = "{{ path('pm_create', { 'access': 'ajax' }) }}";
    if (in_reply_to) {
        url = url + "?in_reply_to=" + in_reply_to;
    }
    $.ajax({
        beforeSend: function(req) {
          req.setRequestHeader("Accept", "application/json");
        },
        type: "POST",
        url: url,
        data: formdata,
        dataType: "text",
        async: true,
      }).done( function( cont, textStatus, xhr ) {
            $( "#createpm" ).dialog("close");
            $( ".pm_reply" ).hide();
      }).fail(function(xhr, status, error) {
            errmsg = "Message sending failed\n";
            errmsg = errmsg + xhr.responseText + "\n";
            alert(errmsg);
    });
    return false;
}

jQuery(document).ready(function() {
    $( "#createpm" ).dialog({
      autoOpen: false,
      height: 370,
      width: 500,
      modal: true
    });
    $( "#createpmform #to" ).val("");
    $( "#createpmform #to_userid" ).val("");
    $( "#createpmform #body" ).val("");
    checkUnread();
});

</script>

<script>
{# TODO: Gotta make this optional or configurable. Right now it uses my commonbundle, which kinda is OK since I use it for more here, but not everyone wants to use if for user stuff.#}
$( function() {
$( "#createpmform #to" ).autocomplete({
  source: "{{ path('user_search', {'access': 'ajax'}) }}",
  minlength: 4,
  select: function( event, ui ) {
    $( "#createpmform #to" ).val(ui.item.value);
    $( "#createpmform #to_userid" ).val(ui.item.userid);
    $( "#createpmform #body" ).focus();
  }
 });
} );
</script>

<div id="createpm" title="Write a PM">
 {# Gotta remember to add some way to send "in_reply_to" here. #}
 {% set pmform = sakonnin.getCreatePmForm({'create_view': true}) %}
 <form id="createpmform" method="POST" action="{{ path('pm_create', { 'access': 'ajax' }) }}" onSubmit="return submitPmMessageForm('createpmform', null);"><commit_msg>Minimum 2 letters, now with a correct option case.<commit_after>{#
   The big question is, do we check if the user is logged in here, or should that be done in the twig templatye including this?
   For now, I vote the including template.
 #}
<script type="text/javascript">
function createPmMessage() {
    $( "#createpm" ).dialog("open");
    return false;
}

function checkUnread() {
    $.ajax({
        beforeSend: function(req) {
          req.setRequestHeader("Accept", "application/json");
        },
        type: "GET",
        url: "{{ path('check_unread', { 'access': 'ajax' }) }}",
        dataType: "json",
        async: true,
      }).done( function( cont, textStatus, xhr ) {
          if (cont['amount'] > 0) {
              $( "#message_menu" ).children().css("color","red");
              $( "#message_menu .dropdown-toggle" ).append("("+cont['amount']+")");
              $( "#menu_unread" ).show();
          } else {
            setTimeout ( "checkUnread()", 60000 );
          }
      });
    return false;
}

function submitPmMessageForm(pmform, in_reply_to) {
    pmform = "#" + pmform;
    formdata = $( pmform ).serialize();
    url = "{{ path('pm_create', { 'access': 'ajax' }) }}";
    if (in_reply_to) {
        url = url + "?in_reply_to=" + in_reply_to;
    }
    $.ajax({
        beforeSend: function(req) {
          req.setRequestHeader("Accept", "application/json");
        },
        type: "POST",
        url: url,
        data: formdata,
        dataType: "text",
        async: true,
      }).done( function( cont, textStatus, xhr ) {
            $( "#createpm" ).dialog("close");
            $( ".pm_reply" ).hide();
      }).fail(function(xhr, status, error) {
            errmsg = "Message sending failed\n";
            errmsg = errmsg + xhr.responseText + "\n";
            alert(errmsg);
    });
    return false;
}

jQuery(document).ready(function() {
    $( "#createpm" ).dialog({
      autoOpen: false,
      height: 370,
      width: 500,
      modal: true
    });
    $( "#createpmform #to" ).val("");
    $( "#createpmform #to_userid" ).val("");
    $( "#createpmform #body" ).val("");
    checkUnread();
});

</script>

<script>
{# TODO: Gotta make this optional or configurable. Right now it uses my commonbundle, which kinda is OK since I use it for more here, but not everyone wants to use if for user stuff.#}
$( function() {
$( "#createpmform #to" ).autocomplete({
  source: "{{ path('user_search', {'access': 'ajax'}) }}",
  minLength: 2,
  select: function( event, ui ) {
    $( "#createpmform #to" ).val(ui.item.value);
    $( "#createpmform #to_userid" ).val(ui.item.userid);
    $( "#createpmform #body" ).focus();
  }
 });
} );
</script>

<div id="createpm" title="Write a PM">
 {# Gotta remember to add some way to send "in_reply_to" here. #}
 {% set pmform = sakonnin.getCreatePmForm({'create_view': true}) %}
 <form id="createpmform" method="POST" action="{{ path('pm_create', { 'access': 'ajax' }) }}" onSubmit="return submitPmMessageForm('createpmform', null);">
{'fraction_non_alphanumeric': 0.18489626556016597, 'fraction_numerical': 0.004481327800829876, 'mean_word_length': 2.719753086419753, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '1665007', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1906, 'n_words': 501}