<commit_before>{% load humanize_date %}
<script type="text/javascript"> 
    // this script is totally dependant on jQuery, jQuery.blockUI, and jqModal scripts being loaded.
    // since it is called only in ajax requests they aren't loaded here
    
    $(document).ready(function() { 
        
        $('#fail_msg').click(function() { 
            $.unblockUI(); 
			location.reload(); //return false; 
        }); 
        
        $('#success_msg').click(function() { 
            $.unblockUI(); 
			location.reload(); //return false; 
        }); 
        
        $('#success').click(function() { 
            $.unblockUI(); 
			location.reload(); //return false; 
        }); 
        
        $('#fail').click(function() { 
            $.unblockUI(); 
            return false; 
        }); 
        $('#add_annotation').click(function() {
            // create a new annotation
            // extract parameters from the form
            attach_id = {{ attachment.id }};
            msg_area = $('#new_annotation');
            message = msg_area[0].value;
            
            var annotation_done = function(status) {
                // callback when an annotation is created 
                
                var sms_done = function(status) {
                    // callback when an sms is sent 
                    if (status == "success") {
                        $.blockUI({ message: $('#success_msg')});
                    } else {
                        $.blockUI({ message: $('#fail_msg')});
                    }
                }
                
                if (status == "success") {
                    send_sms = $('#send_sms')[0].checked;
                    if (send_sms) {
                        // this sends the message via the ajax/messaging app. 
                        reporter_id = $('#annotation_reporter_id')[0].value;
                        send_xhr = $.ajax({
                                "type": "POST",
                                "url":  "/ajax/messaging/send_message",
                                "data": {
                                    "uid":  reporter_id,
                                    "text": message,
                                },
                                "success": function() { sms_done("success"); location.reload(); },
                                "error":   function() { sms_done("error"); }
                        });
                    } else {
                        $.blockUI({ message: $('#success')});
                    }
                } else {
                    $.blockUI({ message: $('#fail')});
                }
            }

            // this creates the annotation object, and calls back to the above method
            // upon completion
            send_xhr = $.ajax({
                        "type": "POST",
                        "url":  "/receiver/annotations/new/",
                        "data": {
                            "attach_id":  attach_id,
                            "text": message,
                        },
                        "success": function() { annotation_done("success"); },
                        "error":   function() { annotation_done("error"); }
                    });
            
            
        });
    });
        
</script>

<!-- send/view UI -->
	{% if allow_add %}
		<div id="annotation-send">
		    <textarea id="new_annotation"></textarea>
		    <input type="hidden" id="annotation_reporter_id" value={{ attachment.get_linked_metadata.submitting_reporter.id }} /> 
		    {% if attachment.has_linked_schema and attachment.get_linked_metadata.submitting_reporter %}
		       <!-- <br /> <input type="checkbox" id="send_sms">Send as SMS to {{ attachment.get_linked_metadata.submitting_reporter }}</input> -->
		    {% else %}
		        {# we still need the input on the page, so just add a hidden one #}
		        <input type="hidden" id="send_sms" />
		    {% endif %}
		    
			<br/>

			
		    <input id="add_annotation" class="jqmClose" type="button" value="Send Message" />
		    <input id="close" class="jqmClose" type="button" value="Cancel" />
		</div>
		{% if annotations %}
			<br />
			<b><u>Previously Sent Messages</u></b>
		    {% for annotation in annotations reversed %}
		        <div class="annotation">
			        From <b>{{ annotation.user }}</b>, {{ annotation.date|timesince|human_date }} ago (<i>{{ annotation.date|date }}</i>):
					<blockquote>{{ annotation.text }}</blockquote>
		        </div>
		    {% endfor %}
		{% else %}<commit_msg>hide checkbox, checked<commit_after>{% load humanize_date %}
<script type="text/javascript"> 
    // this script is totally dependant on jQuery, jQuery.blockUI, and jqModal scripts being loaded.
    // since it is called only in ajax requests they aren't loaded here
    
    $(document).ready(function() { 
        
        $('#fail_msg').click(function() { 
            $.unblockUI(); 
			location.reload(); //return false; 
        }); 
        
        $('#success_msg').click(function() { 
            $.unblockUI(); 
			location.reload(); //return false; 
        }); 
        
        $('#success').click(function() { 
            $.unblockUI(); 
			location.reload(); //return false; 
        }); 
        
        $('#fail').click(function() { 
            $.unblockUI(); 
            return false; 
        }); 
        $('#add_annotation').click(function() {
            // create a new annotation
            // extract parameters from the form
            attach_id = {{ attachment.id }};
            msg_area = $('#new_annotation');
            message = msg_area[0].value;
            
            var annotation_done = function(status) {
                // callback when an annotation is created 
                
                var sms_done = function(status) {
                    // callback when an sms is sent 
                    if (status == "success") {
                        $.blockUI({ message: $('#success_msg')});
                    } else {
                        $.blockUI({ message: $('#fail_msg')});
                    }
                }
                
                if (status == "success") {
                    send_sms = $('#send_sms')[0].checked;
                    if (send_sms) {
                        // this sends the message via the ajax/messaging app. 
                        reporter_id = $('#annotation_reporter_id')[0].value;
                        send_xhr = $.ajax({
                                "type": "POST",
                                "url":  "/ajax/messaging/send_message",
                                "data": {
                                    "uid":  reporter_id,
                                    "text": message,
                                },
                                "success": function() { sms_done("success"); location.reload(); },
                                "error":   function() { sms_done("error"); }
                        });
                    } else {
                        $.blockUI({ message: $('#success')});
                    }
                } else {
                    $.blockUI({ message: $('#fail')});
                }
            }

            // this creates the annotation object, and calls back to the above method
            // upon completion
            send_xhr = $.ajax({
                        "type": "POST",
                        "url":  "/receiver/annotations/new/",
                        "data": {
                            "attach_id":  attach_id,
                            "text": message,
                        },
                        "success": function() { annotation_done("success"); },
                        "error":   function() { annotation_done("error"); }
                    });
            
            
        });
    });
        
</script>

<!-- send/view UI -->
	{% if allow_add %}
		<div id="annotation-send">
		    <textarea id="new_annotation"></textarea>
		    <input type="hidden" id="annotation_reporter_id" value={{ attachment.get_linked_metadata.submitting_reporter.id }} /> 
		    {% if attachment.has_linked_schema and attachment.get_linked_metadata.submitting_reporter %}
				<span style="display: none;">
					<input type="checkbox" id="send_sms" checked>Send as SMS to {{ attachment.get_linked_metadata.submitting_reporter }}</input>
				</span>
		    {% else %}
		        {# we still need the input on the page, so just add a hidden one #}
		        <input type="hidden" id="send_sms" />
		    {% endif %}
		    
			<br/>

			
		    <input id="add_annotation" class="jqmClose" type="button" value="Send Message" />
		    <input id="close" class="jqmClose" type="button" value="Cancel" />
		</div>
		{% if annotations %}
			<br />
			<b><u>Previously Sent Messages</u></b>
		    {% for annotation in annotations reversed %}
		        <div class="annotation">
			        From <b>{{ annotation.user }}</b>, {{ annotation.date|timesince|human_date }} ago (<i>{{ annotation.date|date }}</i>):
					<blockquote>{{ annotation.text }}</blockquote>
		        </div>
		    {% endfor %}
		{% else %}
{'fraction_non_alphanumeric': 0.1407602147004053, 'fraction_numerical': 0.0006572461386789353, 'mean_word_length': 1.318435754189944, 'pattern_counts': {'":': 28, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1887079', 'n_tokens_mistral': 2534, 'n_tokens_neox': 2219, 'n_words': 516}