<commit_before>class StoryBoardAJax
{

    
    constructor()
    {
	this._sw_utils = new SWDjangoUtils();
	
    }

    ajax_scene_search_from_elem(elem, handler_func)
    {
	var r_url = elem.data('url');
	this.ajax_scene_search( r_url, handler_func);
		
    }

    ajax_scene_search( s_url,  handler_func )
    {
	var csrftoken = this._sw_utils.getCsrfToken();
	$.ajax(
	    {
		url : s_url, // the endpoint,commonly same url
		type : "GET", // http method
		data : { csrfmiddlewaretoken : csrftoken, 
     		       },
		success: handler_func,
		error: this.handle_error
	    }
	);
    }

    ajax_list_scenes(service_url, handler_func)
    {
	var csrftoken = this._sw_utils.getCsrfToken();
	var err_func = this.handle_error;
	$.ajax(
	    {
		url : service_url, // the endpoint,commonly same url
		type : "GET", // http method
		data : { csrfmiddlewaretoken : csrftoken, 
     		       },
		success: handler_func,
		error: err_func
	    }
	);

    }

  
    ajax_update_scene(scene, handler_func)
    {
	var csrftoken = this._sw_utils.getCsrfToken();
	var err_func = this._handle_error;
	$.ajax(
	    {
		url : scene.url, // the endpoint,commonly same url
		type : "PUT", // http method
		dataType   : 'json',
		contentType: 'application/json; charset=UTF-8',
		data : JSON.stringify(scene),
		success: handler_func,
		error: err_func
	    }
	);

    }

    _handle_error(xhr,errmsg,err) {
	console.log(xhr.status + ": " + xhr.responseText);
	// provide a bit more info about the error to the console
    }


}


class StoryBoardManager {


    constructor(service_url, s_time_url){
	// PUBLIC
	this.ajax = new StoryBoardAJax();
	// private
	this._tl_manager = new TimeLineManager(s_time_url);
	this.filter_field = null;
	this._sw_utils = new SWDjangoUtils();
	this.url = service_url;
	HandlebarsIntl.registerWith(Handlebars);

    }
    
    
    
    

    filter_list( element )
    {
	this.filter_field = element;
	var value = $(element).val().toLowerCase();

	$(".sw_scene_item").each(function() {
            if ($(this).find('h4').text().toLowerCase().search(value) > -1) {
            $(this).show();
        }
        else {
            $(this).hide();
        }
	});
    }

    
    
    redraw_scene(json)
    {
	var temp_sc_panel = ScriptusTemplates.sw_sc_main_pannel
	var html = temp_sc_panel(json);
	var timeline = this.timeline
	$('#sc_main_panel').html(html);

	if(json['start']) {
	    this._tl_manager.timeline.fit(json['id']);
	    this._tl_manager.timeline.setSelection(json['id']);
	    this._tl_manager.timeline.setWindow(json['dt_start'],json['dt_end']);
	    this._tl_manager.timeline.setCurrentTime(json.start);
	   
	}
	else{
	    // picker.data("DateTimePicker").date(d_time);
	    this.__setup_dt_picker(json);
	}

    }

    __setup_dt_picker(json) {
	var d_time = this._tl_manager.timeline.getCurrentTime();
	var __this = this;
	var picker = $('#sc_datetimepicker').datetimepicker({
	    sideBySide: true,
	    defaultDate: d_time
	});
	picker.on('dp.change', function(e) {
	    // e.date is a moment object
	    json.timeframe.tf_start = e.date.toJSON();
	    __this.ajax.ajax_update_scene(json,
					  __this.init.bind(__this))
	}
		 )

    }

    _tl_update_hook(event, properties) {
	var dt = properties.data[0];
	dt.timeframe.tf_start = dt.start;
	dt.timeframe.tf_end = dt.end;
	this.ajax.ajax_update_scene(dt,
				    this.init.bind(this));
    }


    redraw_scene_list(json)
    {
	var scene_item_tmpl = ScriptusTemplates.sw_sc_li;
	var container = $('#scene_list');
	var __this = this;
	var ajax = this.ajax;
	
	$('.sw_scene_item').each(<commit_msg>Added navigator locale to datetime picker<commit_after>class StoryBoardAJax
{

    
    constructor()
    {
	this._sw_utils = new SWDjangoUtils();
	
    }

    ajax_scene_search_from_elem(elem, handler_func)
    {
	var r_url = elem.data('url');
	this.ajax_scene_search( r_url, handler_func);
		
    }

    ajax_scene_search( s_url,  handler_func )
    {
	var csrftoken = this._sw_utils.getCsrfToken();
	$.ajax(
	    {
		url : s_url, // the endpoint,commonly same url
		type : "GET", // http method
		data : { csrfmiddlewaretoken : csrftoken, 
     		       },
		success: handler_func,
		error: this.handle_error
	    }
	);
    }

    ajax_list_scenes(service_url, handler_func)
    {
	var csrftoken = this._sw_utils.getCsrfToken();
	var err_func = this.handle_error;
	$.ajax(
	    {
		url : service_url, // the endpoint,commonly same url
		type : "GET", // http method
		data : { csrfmiddlewaretoken : csrftoken, 
     		       },
		success: handler_func,
		error: err_func
	    }
	);

    }

  
    ajax_update_scene(scene, handler_func)
    {
	var csrftoken = this._sw_utils.getCsrfToken();
	var err_func = this._handle_error;
	$.ajax(
	    {
		url : scene.url, // the endpoint,commonly same url
		type : "PUT", // http method
		dataType   : 'json',
		contentType: 'application/json; charset=UTF-8',
		data : JSON.stringify(scene),
		success: handler_func,
		error: err_func
	    }
	);

    }

    _handle_error(xhr,errmsg,err) {
	console.log(xhr.status + ": " + xhr.responseText);
	// provide a bit more info about the error to the console
    }


}


class StoryBoardManager {


    constructor(service_url, s_time_url){
	// PUBLIC
	this.ajax = new StoryBoardAJax();
	// private
	this._tl_manager = new TimeLineManager(s_time_url);
	this.filter_field = null;
	this._sw_utils = new SWDjangoUtils();
	this.url = service_url;
	HandlebarsIntl.registerWith(Handlebars);

    }
    
    
    
    

    filter_list( element )
    {
	this.filter_field = element;
	var value = $(element).val().toLowerCase();

	$(".sw_scene_item").each(function() {
            if ($(this).find('h4').text().toLowerCase().search(value) > -1) {
            $(this).show();
        }
        else {
            $(this).hide();
        }
	});
    }

    
    
    redraw_scene(json)
    {
	var temp_sc_panel = ScriptusTemplates.sw_sc_main_pannel
	var html = temp_sc_panel(json);
	var timeline = this.timeline
	$('#sc_main_panel').html(html);

	if(json['start']) {
	    this._tl_manager.timeline.fit(json['id']);
	    this._tl_manager.timeline.setSelection(json['id']);
	    this._tl_manager.timeline.setWindow(json['dt_start'],json['dt_end']);
	    this._tl_manager.timeline.setCurrentTime(json.start);
	   
	}
	else{
	    // picker.data("DateTimePicker").date(d_time);
	    this.__setup_dt_picker(json);
	}

    }

    __setup_dt_picker(json) {
	var d_time = this._tl_manager.timeline.getCurrentTime();
	var __this = this;
	var picker = $('#sc_datetimepicker').datetimepicker({
	    sideBySide: true,
	    defaultDate: d_time,
	    locale: navigator.language
	});
	picker.on('dp.change', function(e) {
	    // e.date is a moment object
	    json.timeframe.tf_start = e.date.toJSON();
	    __this.ajax.ajax_update_scene(json,
					  __this.init.bind(__this))
	}
		 )

    }

    _tl_update_hook(event, properties) {
	var dt = properties.data[0];
	dt.timeframe.tf_start = dt.start;
	dt.timeframe.tf_end = dt.end;
	this.ajax.ajax_update_scene(dt,
				    this.init.bind(this));
    }


    redraw_scene_list(json)
    {
	var scene_item_tmpl = ScriptusTemplates.sw_sc_li;
	var container = $('#scene_list');
	var __this = this;
	var ajax = this.ajax;
	
	$('.sw_scene_item').each(
{'fraction_non_alphanumeric': 0.13713575473000966, 'fraction_numerical': 0.0011048197762739953, 'mean_word_length': 2.948745910577972, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '4536300', 'n_tokens_mistral': 2760, 'n_tokens_neox': 2591, 'n_words': 428}