<commit_before>{% extends "dashboard_base.html" %}

{% load pipeline %}
{% load static %}
{% load siteFrames %}
{% load jsonify %}

{% block sitemenu-content-secondary %}
{% include "xgds_planner2/planner2_subnav.html" %}
{% endblock %}

{% block cssExtras %}
{{ block.super }}
{% if 'xgds_notes2' in settings.INSTALLED_APPS %}
{% include "xgds_notes2/NoteCSS.html" %}
{% endif %}
{% endblock cssExtras %}

{% block siteSection %}{{ group_flight.name }}{% endblock %}

{% block buttonrowLeft %}
    <h4>{{ group_flight.name }}</h4>
{% endblock buttonrowLeft %}

{% if 'xgds_notes2' in settings.INSTALLED_APPS %}
{% block buttonrowRight %}
<div id="full_notesDiv">
	<div id="notes_content" class="notes_content mb-2">
		{% include 'xgds_notes2/notes_input_include_full.html' %}
 	</div>
 </div>
{% endblock buttonrowRight %}
{% endif %}

{% block pretemplate %}
    <script type="x-template/underscore" id="plot_contents">
		<div id="plotDiv" class="plot-div"></div>
		<div id="plotLegend" class="row ml-2"></div>
    </script>
{% endblock pretemplate %}

{% block preDashboard %}
    <div id="controllers" >
    	{% include "xgds_core/playback_controller.html" %}
    </div>
    <div id="masterSlider" class="masterSlider" >
    </div>
    <div id="plot-container" class="plot-container">
	</div>
{% endblock preDashboard %}


{% block map %}
    <div id="map-gridstack-item" class="grid-stack-item"
    data-gs-x="0" data-gs-y="0"
    data-gs-width="2" data-gs-height="4" >
        <div class="grid-stack-item-content" id="map-gridstack-item-content" >
            {% siteframe_form %}
            <ul class="nav justify-content-end">
                <i class="fa fa-lock pinDiv gray-light"></i>
            </ul>
            <div id="map"></div>
        </div>
    </div>
    {% endblock map %}

    {% block layers %}
    <div id="layers-gridstack-item" class="grid-stack-item"
        data-gs-x="2" data-gs-y="0"
        data-gs-width="1" data-gs-height="3" >
        <div class="grid-stack-item-content" id="layers-gridstack-item-content">
        <ul class="nav justify-content-end">
            <i class="fa fa-lock gray-light pinDiv mr-1"></i>
            <i class="fa fa-window-close gray-light fa-lg"></i>
        </ul>
        <div id="layers" class="mt-negative-1rem"></div>
        </div>
    </div>
    {% endblock layers %}

{% block postMap %}
    <div id="tabs-gridstack-item" class="grid-stack-item"  data-gs-x="4" data-gs-y="4" data-gs-width="3" data-gs-height="4" >
    		<div id="tabs-gridstack-item-content" class="grid-stack-item-content" >
			<ul class="nav justify-content-end">
				<i class="fa fa-lock pinDiv gray-light"></i>
			</ul>
	        <div id="tabs" class="mt-negative-1rem"></div>
	    </div>
{% endblock postMap %}


{% block scripts %}
{{block.super}}
    <script type="text/javascript" src="{{ EXTERNAL_URL }}flot/jquery.flot.js" ></script>
	<script type="text/javascript" src="{{ EXTERNAL_URL }}flot/jquery.flot.time.js" ></script>
	<script type="text/javascript" src="{{ EXTERNAL_URL }}flot/jquery.flot.resize.js" ></script>
	<script type="text/javascript" src="{{ EXTERNAL_URL }}timezone-js/src/date.js" ></script>

{% if 'xgds_notes2' in settings.INSTALLED_APPS %}
	{% include "xgds_notes2/NoteJS.html" %}
    <script type="text/javascript" src="{% static 'xgds_notes2/js/note_create_form.js' %}"></script>

{% else %}
    {% include "xgds_core/timeJS.html" %}
    <script type="text/javascript" src="{{ EXTERNAL_URL }}datatables.net-plugins/sorting/datetime-moment.js"></script>
{% endif %}
    <script type="text/javascript">
   		DEFAULT_PLOT_TIME_FORMAT = '%H:%M';
   	</script>
    {% include "xgds_core/playbackJS.html" %}
    <script type="text/javascript" src="{% static 'xgds_timeseries/js/timeseriesUtils.js' %}"></script>
    <script type="text/javascript" src="{% static 'geocamTrack/js/trackBackbone.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/mapReplayModels.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/replayPlots.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/conditionPlots.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/replayLinksViews.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/replayDataPlotsViews.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/mapReplayViews.js' %}"></script>


    <script type="x-template/underscore" id="plot_contents">
        <div id="plotTitle" class="row mt-2"></div>
        <div id="plotDiv" class="plot-div" style="height:150px;"></div>
        <div id="plotLegend" class="row ml-2 mb-2"></div>
        <div id="timeseries_message"></div>
    </script>

	{% for template_name, template in templates.items %}
	<script type="text/handlebars" id="template-{{template_name}}">
		{{template|safe}}
	</script>
    {% endfor %}

    {% include "xgds_map_server/SearchForms.html" with searchForms=searchForms %}

{% endblock scripts %}


{% block preMapJS %}
    <script type="text/javascript">
	var siteFrames = {% siteframes_dict %};

	getTimeZone = function() {
	    if ("{{ group_flight.timezone }}" === "Etc/UTC") {
	        return "utc";
        }
	    return "{{ group_flight.timezone }}";
    }

    var conditions = [];
    {% for c in group_flight.conditions %}
        conditions.push({{ c.toJson|safe }});
    {% endfor %}

    var group_flight_links = {};
    {% for u in group_flight.links.all %}
        group_flight_links['{{ u.name }}'] ='{{ u.url }}';
    {% endfor %}

    var appOptions = {
        	BODY_RADIUS_METERS: {{ settings.XGDS_MAP_SERVER_BODY_RADIUS_METERS }},
        	DEFAULT_COORD_SYSTEM: '{{ settings.XGDS_MAP_SERVER_DEFAULT_COORD_SYSTEM }}',
        	SETUP_COORD_SYSTEM: {{ settings.XGDS_MAP_SERVER_MAP_SETUP_COORD_SYSTEM }},
            DEFAULT_COORD_SYSTEM_CENTER: {{ settings.XGDS_MAP_SERVER_DEFAULT_COORD_SYSTEM_CENTER }},
    		DEFAULT_ZOOM: {{ settings.XGDS_MAP_SERVER_DEFAULT_ZOOM }},
    		DEFAULT_ROTATION: {{ settings.XGDS_MAP_SERVER_DEFAULT_ROTATION }},
    		SHOW_COMPASS: {{ settings.XGDS_MAP_SERVER_SHOW_COMPASS}},
    		offline: {{ settings.XGDS_PLANNER_OFFLINE|yesno:'true,false'}},
       	    selectedLayerUrl: '{{ settings.XGDS_MAP_SERVER_SELECTED_LAYER_URL }}',
            layerFeedUrl: '{{ settings.XGDS_PLANNER_LAYER_FEED_URL }}',
            dataUrl: '{{ settings.DATA_URL }}',
            simulator: '{{ simulator }}',
            siteFrame: {% siteframe settings.XGDS_CURRENT_SITEFRAME_ID %},
            XGDS_MAP_SERVER_MAP_LOADED_CALLBACK: '{{ settings.XGDS_MAP_SERVER_MAP_LOADED_CALLBACK }}',
            searchModels: {{ settings.XGDS_MAP_SERVER_JS_MAP|safe }},
            settingsLive: {{ settings.GEOCAM_UTIL_LIVE_MODE|yesno:'true,false' }},
            track_urls: [],
            flight_ids: [],
            timeseries_config: [],
            group_flight: {{ group_flight.toJson|safe }},
            group_flight_links: group_flight_links,
            conditions: conditions
     };

        {% if extras %}
            var extras = {{ extras|safe }};
            for (var key in extras) {
            	appOptions[key] = extras[key];
            }
        {% endif %}
    </script>
{% endblock preMapJS %}


{% block jsInit %}

	{% block jsInitPreApp %}
        moment.tz.setDefault(getTimeZone());

        // flot currently depends on timezoneJS.
        timezoneJS.timezone.zoneFileBasePath = "{% static 'tz' %}";
		timezoneJS.timezone.defaultZoneFile = [];
		timezoneJS.timezone.init({async: false});

        appOptions.track_urls = [];
        appOptions.track_metadata = [];
        {% for flight in group_flight.flights %}
            {% if flight.track %}
                appOptions.track_urls.push("{% url 'geocamTrack_mapJsonTrack_downsample' flight.track.uuid %}");
                appOptions.track_metadata.push({{flight.track.get_tree_json|jsonify }});
            {% endif %}
            appOptions.flight_ids.push({{ flight.id }});
        {% endfor %}

	{% endblock jsInitPreApp %}

    // get the timeseries configs to know what timeseries data to load on the data plots tab
    _.each(appOptions.flight_ids, function(flight_id) {
            var jsonData = {'flight_ids':[flight_id]};
            $.ajax({
                url : '/timeseries/classes/metadata/json',
                type: "POST",
                data: jsonData,
                dataType: "json",
                success: function(data) {
                    _.each(data, function(d) {
                        d.flight_ids = [flight_id];
                        appOptions.timeseries_config.push(d);
                    });
                }
            });
    });

	$(function(){
		app.start(appOptions);
    	app.vent.on("mapSearch:drewFeatures", function(e) {
        	app.vent.trigger('mapSearch:fit');
        });

        app.vent.on('searchDiv:visible', function(){
		 	if (!searchDiv_initialized){
		        addDateTimePickers();
		        searchDiv_initialized = true;
		 	}
		 });

        {% block preLayout %}
		{% endblock preLayout %}

    	xgds_gridstack.initializeGridstack();

        // right here the map is the right height and when we exit this method it is not.

        {% block otherJSInit %}
        group_flight_start = {% if group_flight.start_time %}new moment('{{ group_flight.start_time.isoformat }}'){% else %}null{% endif %};
        group_flight_end = {% if group_flight.end_time %}new moment('{{ group_flight.end_time.isoformat }}'){% else %}null{% endif %};
        playback.initialize({getStartTime: function(){return group_flight_start;},
                             getEndTime: function(){return group_flight_end;},
                             displayTZ: getTimeZone(),
                             slider: true
                            });

            {% block initializeNotes %}
            var container = $("#full_notes_input");
            xgds_notes.setupNotesUI(container);
            xgds_notes.initializeNotesForm(false);

            // add a playback listener to set the time
            timePlaybackListener =  {
		        lastUpdate: undefined,
		        invalid: false,
		        initialize: function() {
                    this.event_time_input = $("#id_event_time");
		        },
		        doSetTime: function(currentTime){
			        if (currentTime === undefined){
				        return;
			        }
			        this.lastUpdate = moment(currentTime);
                    this.event_time_input.val(this.lastUpdate.format('MM/DD/YY HH:mm:ss zz'));
		        },
		        start: function(currentTime){
			        this.doSetTime(currentTime);
		        },
		        update: function(currentTime){
			        if (this.lastUpdate === undefined){
				        this.doSetTime(currentTime);
				        return;
			        }
			        var delta = currentTime.diff(this.lastUpdate);
			        if (Math.abs(delta) >= 100) {
				        this.doSetTime(currentTime);
			        }
		        },
		        pause: function() {
		        }
            };
                playback.addListener(timePlaybackListener);

            {% endblock initializeNotes %}

            {% block eventTimeFunction %}
            xgds_notes.getEventTime = function(context) {
                    var dataString = "";
                    var parent = $(context).closest('.notes_input_container');
                    var event_hidden = parent.find('#id_event_time');
                    if (event_hidden.length == 0){
                        event_hidden = $("#id_event_time");

                    }
                    var event_timestring = event_hidden.val();

                    try {
                        if (event_timestring !== undefined && event_timestring !== ""){
                            if (!event_hidden.is(':visible')){ // in a form
                                dataString = dataString + '&event_time=' + event_timestring;
                                try {
                                    var timezone_hidden = parent.find('#id_event_timezone');
                                    dataString = dataString + "&event_timezone=" + timezone_hidden.val();
                                } catch(err){
                                    // no timezone
                                }
                            } else {
                                var tzified = getUTCTime(event_timestring.substring(0, event_timestring.length-4), serverTimezone);
                                var theUtc = tzified.utc().format('YYYY/MM/DD HH:mm:ss') + ' UTC';
                                dataString = dataString + '&event_time=' + theUtc;
                                try {
                                    dataString = dataString + "&event_timezone=" + serverTimezone;
                                } catch(err){
                                    // no timezone
                                }
                            }
                        } else {
                            if (event_hidden.is(':visible')){
                                dataString = dataString + "&serverNow=true";
                            }
                        }
                    }
                    catch(err) {
                        dataString = dataString + "&serverNow=true";
                    }
                    return dataString;

                };
            xgds_notes.postSubmit = function(data) {
               xgds_notes.clear_event_time();
            };
            {% endblock eventTimeFunction %}

            xgds_notes.updateRole = function(stuff) {
	var theForm = $("#edit_user_session_form");
	var content = theForm.find("#id_location option:selected").text();
	if (content == '---------'){
		theForm.find("#id_location option[value='{{request.session.notes_user_session.location}}']").attr('selected', 'selected');
		theForm.find("#id_vehicle option[value='{{request.session.notes_user_session.vehicle}}']").attr('selected', 'selected');
		theForm.find("#id_role option[value='{{request.session.notes_user_session.role}}']").attr('selected', 'selected');
		var content = theForm.find("#id_location option:selected").text();
	}
	content += ', ' + theForm.find("#id_vehicle option:selected").text();
	content += ', ' + theForm.find("#id_role option:selected").text();
	$("#roleLocationVehicle").text(content);
	if (content.indexOf('--') == -1){
		user_session_exists = true;
	}
}

    xgds_notes.set_event_time = function() {
            timePlaybackListener.doSetTime(playback.getCurrentTime());

	};
    xgds_notes.postSubmit = function(data) {
            timePlaybackListener.doSetTime(playback.getCurrentTime());

	};


$("#changeRole").click(function(e){
	xgds_notes.editUserSession('xgds_notes.updateRole');
});

xgds_notes.updateRole();

            var input_initialized = false;
 		var formNote = $("#form-Note");
 		var input = formNote.find('.taginput');
        xgds_notes.initializeInput(input);
        var role = formNote.find("#id_role");
        role.val(role.find("option:first").val());
        var location = formNote.find("#id_location");
        location.val(location.find("option:first").val());
        input_initialized = true;
                timePlaybackListener.doSetTime(playback.getCurrentTime());

		{% endblock otherJSInit %}

	});

    {% endblock jsInit%}

{% block footer %}
{% endblock footer %}<commit_msg>corrected event time javascript stuff, now the flight and time are correct from recording event from replay group flight page<commit_after>{% extends "dashboard_base.html" %}

{% load pipeline %}
{% load static %}
{% load siteFrames %}
{% load jsonify %}

{% block sitemenu-content-secondary %}
{% include "xgds_planner2/planner2_subnav.html" %}
{% endblock %}

{% block cssExtras %}
{{ block.super }}
{% if 'xgds_notes2' in settings.INSTALLED_APPS %}
{% include "xgds_notes2/NoteCSS.html" %}
{% endif %}
{% endblock cssExtras %}

{% block siteSection %}{{ group_flight.name }}{% endblock %}

{% block buttonrowLeft %}
    <h4>{{ group_flight.name }}</h4>
{% endblock buttonrowLeft %}

{% if 'xgds_notes2' in settings.INSTALLED_APPS %}
{% block buttonrowRight %}
<div id="full_notesDiv">
	<div id="notes_content" class="notes_content mb-2">
		{% include 'xgds_notes2/notes_input_include_full.html' %}
 	</div>
 </div>
{% endblock buttonrowRight %}
{% endif %}

{% block pretemplate %}
    <script type="x-template/underscore" id="plot_contents">
		<div id="plotDiv" class="plot-div"></div>
		<div id="plotLegend" class="row ml-2"></div>
    </script>
{% endblock pretemplate %}

{% block preDashboard %}
    <div id="controllers" >
    	{% include "xgds_core/playback_controller.html" %}
    </div>
    <div id="masterSlider" class="masterSlider" >
    </div>
    <div id="plot-container" class="plot-container">
	</div>
{% endblock preDashboard %}


{% block map %}
    <div id="map-gridstack-item" class="grid-stack-item"
    data-gs-x="0" data-gs-y="0"
    data-gs-width="2" data-gs-height="4" >
        <div class="grid-stack-item-content" id="map-gridstack-item-content" >
            {% siteframe_form %}
            <ul class="nav justify-content-end">
                <i class="fa fa-lock pinDiv gray-light"></i>
            </ul>
            <div id="map"></div>
        </div>
    </div>
    {% endblock map %}

    {% block layers %}
    <div id="layers-gridstack-item" class="grid-stack-item"
        data-gs-x="2" data-gs-y="0"
        data-gs-width="1" data-gs-height="3" >
        <div class="grid-stack-item-content" id="layers-gridstack-item-content">
        <ul class="nav justify-content-end">
            <i class="fa fa-lock gray-light pinDiv mr-1"></i>
            <i class="fa fa-window-close gray-light fa-lg"></i>
        </ul>
        <div id="layers" class="mt-negative-1rem"></div>
        </div>
    </div>
    {% endblock layers %}

{% block postMap %}
    <div id="tabs-gridstack-item" class="grid-stack-item"  data-gs-x="4" data-gs-y="4" data-gs-width="3" data-gs-height="4" >
    		<div id="tabs-gridstack-item-content" class="grid-stack-item-content" >
			<ul class="nav justify-content-end">
				<i class="fa fa-lock pinDiv gray-light"></i>
			</ul>
	        <div id="tabs" class="mt-negative-1rem"></div>
	    </div>
{% endblock postMap %}


{% block scripts %}
{{block.super}}
    <script type="text/javascript" src="{{ EXTERNAL_URL }}flot/jquery.flot.js" ></script>
	<script type="text/javascript" src="{{ EXTERNAL_URL }}flot/jquery.flot.time.js" ></script>
	<script type="text/javascript" src="{{ EXTERNAL_URL }}flot/jquery.flot.resize.js" ></script>
	<script type="text/javascript" src="{{ EXTERNAL_URL }}timezone-js/src/date.js" ></script>

{% if 'xgds_notes2' in settings.INSTALLED_APPS %}
	{% include "xgds_notes2/NoteJS.html" %}
    <script type="text/javascript" src="{% static 'xgds_notes2/js/note_create_form.js' %}"></script>

{% else %}
    {% include "xgds_core/timeJS.html" %}
    <script type="text/javascript" src="{{ EXTERNAL_URL }}datatables.net-plugins/sorting/datetime-moment.js"></script>
{% endif %}
    <script type="text/javascript">
   		DEFAULT_PLOT_TIME_FORMAT = '%H:%M';
   	</script>
    {% include "xgds_core/playbackJS.html" %}
    <script type="text/javascript" src="{% static 'xgds_timeseries/js/timeseriesUtils.js' %}"></script>
    <script type="text/javascript" src="{% static 'geocamTrack/js/trackBackbone.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/mapReplayModels.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/replayPlots.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/conditionPlots.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/replayLinksViews.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/replayDataPlotsViews.js' %}"></script>
    <script type="text/javascript" src="{% static 'xgds_map_server/js/replay/mapReplayViews.js' %}"></script>


    <script type="x-template/underscore" id="plot_contents">
        <div id="plotTitle" class="row mt-2"></div>
        <div id="plotDiv" class="plot-div" style="height:150px;"></div>
        <div id="plotLegend" class="row ml-2 mb-2"></div>
        <div id="timeseries_message"></div>
    </script>

	{% for template_name, template in templates.items %}
	<script type="text/handlebars" id="template-{{template_name}}">
		{{template|safe}}
	</script>
    {% endfor %}

    {% include "xgds_map_server/SearchForms.html" with searchForms=searchForms %}

{% endblock scripts %}


{% block preMapJS %}
    <script type="text/javascript">
	var siteFrames = {% siteframes_dict %};

	getTimeZone = function() {
	    if ("{{ group_flight.timezone }}" === "Etc/UTC") {
	        return "utc";
        }
	    return "{{ group_flight.timezone }}";
    }

    var conditions = [];
    {% for c in group_flight.conditions %}
        conditions.push({{ c.toJson|safe }});
    {% endfor %}

    var group_flight_links = {};
    {% for u in group_flight.links.all %}
        group_flight_links['{{ u.name }}'] ='{{ u.url }}';
    {% endfor %}

    var appOptions = {
        	BODY_RADIUS_METERS: {{ settings.XGDS_MAP_SERVER_BODY_RADIUS_METERS }},
        	DEFAULT_COORD_SYSTEM: '{{ settings.XGDS_MAP_SERVER_DEFAULT_COORD_SYSTEM }}',
        	SETUP_COORD_SYSTEM: {{ settings.XGDS_MAP_SERVER_MAP_SETUP_COORD_SYSTEM }},
            DEFAULT_COORD_SYSTEM_CENTER: {{ settings.XGDS_MAP_SERVER_DEFAULT_COORD_SYSTEM_CENTER }},
    		DEFAULT_ZOOM: {{ settings.XGDS_MAP_SERVER_DEFAULT_ZOOM }},
    		DEFAULT_ROTATION: {{ settings.XGDS_MAP_SERVER_DEFAULT_ROTATION }},
    		SHOW_COMPASS: {{ settings.XGDS_MAP_SERVER_SHOW_COMPASS}},
    		offline: {{ settings.XGDS_PLANNER_OFFLINE|yesno:'true,false'}},
       	    selectedLayerUrl: '{{ settings.XGDS_MAP_SERVER_SELECTED_LAYER_URL }}',
            layerFeedUrl: '{{ settings.XGDS_PLANNER_LAYER_FEED_URL }}',
            dataUrl: '{{ settings.DATA_URL }}',
            simulator: '{{ simulator }}',
            siteFrame: {% siteframe settings.XGDS_CURRENT_SITEFRAME_ID %},
            XGDS_MAP_SERVER_MAP_LOADED_CALLBACK: '{{ settings.XGDS_MAP_SERVER_MAP_LOADED_CALLBACK }}',
            searchModels: {{ settings.XGDS_MAP_SERVER_JS_MAP|safe }},
            settingsLive: {{ settings.GEOCAM_UTIL_LIVE_MODE|yesno:'true,false' }},
            track_urls: [],
            flight_ids: [],
            timeseries_config: [],
            group_flight: {{ group_flight.toJson|safe }},
            group_flight_links: group_flight_links,
            conditions: conditions
     };

        {% if extras %}
            var extras = {{ extras|safe }};
            for (var key in extras) {
            	appOptions[key] = extras[key];
            }
        {% endif %}
    </script>
{% endblock preMapJS %}


{% block jsInit %}

	{% block jsInitPreApp %}
        moment.tz.setDefault(getTimeZone());

        // flot currently depends on timezoneJS.
        timezoneJS.timezone.zoneFileBasePath = "{% static 'tz' %}";
		timezoneJS.timezone.defaultZoneFile = [];
		timezoneJS.timezone.init({async: false});

        appOptions.track_urls = [];
        appOptions.track_metadata = [];
        {% for flight in group_flight.flights %}
            {% if flight.track %}
                appOptions.track_urls.push("{% url 'geocamTrack_mapJsonTrack_downsample' flight.track.uuid %}");
                appOptions.track_metadata.push({{flight.track.get_tree_json|jsonify }});
            {% endif %}
            appOptions.flight_ids.push({{ flight.id }});
        {% endfor %}

	{% endblock jsInitPreApp %}

    // get the timeseries configs to know what timeseries data to load on the data plots tab
    _.each(appOptions.flight_ids, function(flight_id) {
            var jsonData = {'flight_ids':[flight_id]};
            $.ajax({
                url : '/timeseries/classes/metadata/json',
                type: "POST",
                data: jsonData,
                dataType: "json",
                success: function(data) {
                    _.each(data, function(d) {
                        d.flight_ids = [flight_id];
                        appOptions.timeseries_config.push(d);
                    });
                }
            });
    });

	$(function(){
		app.start(appOptions);
    	app.vent.on("mapSearch:drewFeatures", function(e) {
        	app.vent.trigger('mapSearch:fit');
        });

        app.vent.on('searchDiv:visible', function(){
		 	if (!searchDiv_initialized){
		        addDateTimePickers();
		        searchDiv_initialized = true;
		 	}
		 });

        {% block preLayout %}
		{% endblock preLayout %}

    	xgds_gridstack.initializeGridstack();

        // right here the map is the right height and when we exit this method it is not.

        {% block otherJSInit %}
        server_time_url = "{% url 'server_time' %}";
        serverTimezone = "{{TIME_ZONE}}";
        group_flight_start = {% if group_flight.start_time %}new moment('{{ group_flight.start_time.isoformat }}'){% else %}null{% endif %};
        group_flight_end = {% if group_flight.end_time %}new moment('{{ group_flight.end_time.isoformat }}'){% else %}null{% endif %};
        playback.initialize({getStartTime: function(){return group_flight_start;},
                             getEndTime: function(){return group_flight_end;},
                             displayTZ: getTimeZone(),
                             slider: true
                            });

            {% block initializeNotes %}
            var container = $("#full_notes_input");
            xgds_notes.setupNotesUI(container);
            xgds_notes.initializeNotesForm(false);

            // add a playback listener to set the time
            timePlaybackListener =  {
		        lastUpdate: undefined,
		        invalid: false,
		        initialize: function() {
                    this.event_time_input = $("#id_event_time");
		        },
		        doSetTime: function(currentTime){
			        if (currentTime === undefined){
				        return;
			        }
			        this.lastUpdate = moment(currentTime);
                    this.event_time_input.val(this.lastUpdate.format('MM/DD/YY HH:mm:ss zz'));
		        },
		        start: function(currentTime){
			        this.doSetTime(currentTime);
		        },
		        update: function(currentTime){
			        if (this.lastUpdate === undefined){
				        this.doSetTime(currentTime);
				        return;
			        }
			        var delta = currentTime.diff(this.lastUpdate);
			        if (Math.abs(delta) >= 100) {
				        this.doSetTime(currentTime);
			        }
		        },
		        pause: function() {
		        }
            };
                playback.addListener(timePlaybackListener);

            {% endblock initializeNotes %}

            {% block eventTimeFunction %}
            xgds_notes.getEventTime = function(context) {
                var parent = $(context).closest('.notes_input_container');
                var event_hidden = parent.find('#id_event_time');
                var dataString = "";

                if (event_hidden.length == 0){
                    event_hidden = $("#id_event_time");
                }
                var event_timestring = event_hidden.val();

                try {
                    if (event_timestring !== undefined && event_timestring !== ""){
                        if (!event_hidden.is(':visible')){ // in a form
                            dataString = dataString + '&event_time=' + event_timestring;
                            try {
                                var timezone_hidden = parent.find('#id_event_timezone');
                                dataString = dataString + "&event_timezone=" + timezone_hidden.val();
                            } catch(err){
                                // no timezone
                            }
                        } else {
                            var tzified = getUTCTime(event_timestring.substring(0, event_timestring.length-4), serverTimezone);
                            var theUtc = tzified.utc().format('YYYY/MM/DD HH:mm:ss') + ' UTC';
                            dataString = dataString + '&event_time=' + theUtc;
                            try {
                                dataString = dataString + "&event_timezone=" + serverTimezone;
                            } catch(err){
                                // no timezone
                            }
                        }
                    } else {
                        if (event_hidden.is(':visible')){
                            dataString = dataString + "&serverNow=true";
                        }
                    }
                }
                catch(err) {
                    dataString = dataString + "&serverNow=true";
                }
                return dataString;

            };
            xgds_notes.postSubmit = function(data) {
               xgds_notes.clear_event_time();
            };
            {% endblock eventTimeFunction %}

            xgds_notes.updateRole = function(stuff) {
	var theForm = $("#edit_user_session_form");
	var content = theForm.find("#id_location option:selected").text();
	if (content == '---------'){
		theForm.find("#id_location option[value='{{request.session.notes_user_session.location}}']").attr('selected', 'selected');
		theForm.find("#id_vehicle option[value='{{request.session.notes_user_session.vehicle}}']").attr('selected', 'selected');
		theForm.find("#id_role option[value='{{request.session.notes_user_session.role}}']").attr('selected', 'selected');
		var content = theForm.find("#id_location option:selected").text();
	}
	content += ', ' + theForm.find("#id_vehicle option:selected").text();
	content += ', ' + theForm.find("#id_role option:selected").text();
	$("#roleLocationVehicle").text(content);
	if (content.indexOf('--') == -1){
		user_session_exists = true;
	}
}

    xgds_notes.set_event_time = function() {
            timePlaybackListener.doSetTime(playback.getCurrentTime());

	};
    xgds_notes.postSubmit = function(data) {
            timePlaybackListener.doSetTime(playback.getCurrentTime());

	};


$("#changeRole").click(function(e){
	xgds_notes.editUserSession('xgds_notes.updateRole');
});

xgds_notes.updateRole();

            var input_initialized = false;
 		var formNote = $("#form-Note");
 		var input = formNote.find('.taginput');
        xgds_notes.initializeInput(input);
        var role = formNote.find("#id_role");
        role.val(role.find("option:first").val());
        var location = formNote.find("#id_location");
        location.val(location.find("option:first").val());
        input_initialized = true;
                timePlaybackListener.doSetTime(playback.getCurrentTime());

		{% endblock otherJSInit %}

	});

    {% endblock jsInit%}

{% block footer %}
{% endblock footer %}
{'fraction_non_alphanumeric': 0.15095009194438172, 'fraction_numerical': 0.0026454172984482368, 'mean_word_length': 2.352222342381313, 'pattern_counts': {'":': 0, '<': 189, '<?xml version=': 0, '>': 191, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4266274', 'n_tokens_mistral': 10167, 'n_tokens_neox': 9299, 'n_words': 1554}