<commit_before>var AIRTIME = (function(AIRTIME){
	var mod;
	
	if (AIRTIME.library === undefined) {
		AIRTIME.library = {};
	}
	mod = AIRTIME.library;
	
	mod.fnDeleteItems = function(aMedia) {
		var oLibTT = TableTools.fnGetInstance('library_display'),
			oLibTable = $("#library_display").dataTable();
		
		$.post("/library/delete", 
			{"format": "json", "media": aMedia}, 
			function(json){
				oLibTT.fnSelectNone();
				oLibTable.fnDraw();
			});
	};
	
	mod.fnDeleteSelectedItems = function() {
		var oLibTT = TableTools.fnGetInstance('library_display'),
			aData = oLibTT.fnGetSelectedData(),
			item,
			temp,
			aMedia = [];
		
		//process selected files/playlists.
		for (item in aData) {
			temp = aData[item];
			if (temp !== null && temp.hasOwnProperty('id') ) {
				aMedia.push({"id": temp.id, "type": temp.ftype});
			} 	
		}
	
		AIRTIME.library.fnDeleteItems(aMedia);
	};
	
	return AIRTIME;
	
}(AIRTIME || {}));

function addToolBarButtonsLibrary(aButtons) {
	var i,
		length = aButtons.length,
		libToolBar,
		html,
		buttonClass = '',
		DEFAULT_CLASS = 'ui-button ui-state-default',
		DISABLED_CLASS = 'ui-state-disabled';
	
	libToolBar = $(".library_toolbar");
	
	for ( i=0; i < length; i+=1 ) {
		buttonClass = '';
		
		//add disabled class if not enabled.
		if (aButtons[i][2] === false) {
			buttonClass+=DISABLED_CLASS;
		}
		
		html = '<div id="'+aButtons[i][1]+'" class="ColVis TableTools"><button class="'+DEFAULT_CLASS+' '+buttonClass+'"><span>'+aButtons[i][0]+'</span></button></div>';	
		libToolBar.append(html);
		libToolBar.find("#"+aButtons[i][1]).click(aButtons[i][3]);
	}
}

function enableGroupBtn(btnId, func) {
    btnId = '#' + btnId;
    if ($(btnId).hasClass('ui-state-disabled')) {
        $(btnId).removeClass('ui-state-disabled');
    }
}

function disableGroupBtn(btnId) {
    btnId = '#' + btnId;
    if (!$(btnId).hasClass('ui-state-disabled')) {
        $(btnId).addClass('ui-state-disabled');
    }
}

function checkImportStatus(){
    $.getJSON('/Preference/is-import-in-progress', function(data){
        var div = $('#import_status');
        if (data == true){
            div.show();
        }
        else{
            div.hide();
        }
    });
}

function addProgressIcon(id) {
	var tr = $("#au_"+id),
		span;
	
	span = tr.find("td.library_title").find("span");
	
    if (span.length > 0){	
        span.removeClass()
        	.addClass("small-icon progress");
    }
    else{
        tr.find("td.library_title")
        	.append('<span class="small-icon progress"></span>');
    }
}

function checkSCUploadStatus(){
	
    var url = '/Library/get-upload-to-soundcloud-status';
    
    $("span[class*=progress]").each(function(){
    	var span, id;
    	
        span = $(this);
        id = span.parent().parent().data("aData").id;
       
        $.post(url, {format: "json", id: id, type:"file"}, function(json){
            if (json.sc_id > 0) {
                span.removeClass("progress")
                	.addClass("soundcloud");
                
            }
            else if (json.sc_id == "-3") {
                span.removeClass("progress")
                	.addClass("sc-error");
            }
        });
    });
}

function addQtipToSCIcons(){
    $(".progress, .soundcloud, .sc-error").live('mouseover', function(){
    	
        var id = $(this).parent().parent().data("aData").id;
        
        if ($(this).hasClass("progress")){
            $(this).qtip({
                content: {
                    text: "Uploading in progress..."
                },
                position:{
                    adjust: {
                    resize: true,
                    method: "flip flip"
                    },
                    at: "right center",
                    my: "left top",
                    viewport: $(window)
                },
                show: {
                    ready: true // Needed to make it show on first mouseover event
                }
            });
        }
        else if($(this).hasClass("soundcloud")){
            $(this).qtip({
                content: {
                    text: "Retreiving data from the server...",
                    ajax: {
                        url: "/Library/get-upload-to-soundcloud-status",
                        type: "post",
                        data: ({format: "json", id : id, type: "file"}),
                        success: function(json, status){
                            this.set('content.text', "The soundcloud id for this file is: "+json.sc_id);
                        }
                    }
                },
                position:{
                    adjust: {
                    resize: true,
                    method: "flip flip"
                    },
                    at: "right center",
                    my: "left top",
                    viewport: $(window)
                },
                show: {
                    ready: true // Needed to make it show on first mouseover event
                }
            });
        }else if($(this).hasClass("sc-error")){
            $(this).qtip({
                content: {
                    text: "Retreiving data from the server...",
                    ajax: {
                        url: "/Library/get-upload-to-soundcloud-status",
                        type: "post",
                        data: ({format: "json", id : id, type: "file"}),
                        success: function(json, status){
                            this.set('content.text', "There was error while uploading to soundcloud.<br>"+"Error code: "+json.error_code+
                                    "<br>"+"Error msg: "+json.error_msg+"<br>");
                        }
                    }
                },
                position:{
                    adjust: {
                    resize: true,
                    method: "flip flip"
                    },
                    at: "right center",
                    my: "left top",
                    viewport: $(window)
                },
                show: {
                    ready: true // Needed to make it show on first mouseover event
                }
            });
        }
    });
}

$(document).ready(function() {
    var oTable;
    
    oTable = $('#library_display').dataTable( {
    	
    	"aoColumns": [
          /* Checkbox */      {"sTitle": "<input type='checkbox' name='pl_cb_all'>", "mDataProp": "checkbox", "bSortable": false, "bSearchable": false, "sWidth": "25px", "sClass": "library_checkbox"},
          /* Type */          {"sTitle": "", "mDataProp": "image", "bSearchable": false, "sWidth": "25px", "sClass": "library_type", "iDataSort": 2},
          /* ftype */         {"sTitle": "", "mDataProp": "ftype", "bSearchable": false, "bVisible": false},
          /* Title */         {"sTitle": "Title", "mDataProp": "track_title", "sClass": "library_title"},
          /* Creator */       {"sTitle": "Creator", "mDataProp": "artist_name", "sClass": "library_creator"},
          /* Album */         {"sTitle": "Album", "mDataProp": "album_title", "sClass": "library_album"},
          /* Genre */         {"sTitle": "Genre", "mDataProp": "genre", "sClass": "library_genre"},
          /* Year */          {"sTitle": "Year", "mDataProp": "year", "sClass": "library_year", "sWidth": "60px"},
          /* Length */        {"sTitle": "Length", "mDataProp": "length", "sClass": "library_length", "sWidth": "80px"},
          /* Upload Time */   {"sTitle": "Uploaded", "mDataProp": "utime", "sClass": "library_upload_time"},
          /* Last Modified */ {"sTitle": "Last Modified", "mDataProp": "mtime", "bVisible": false, "sClass": "library_modified_time"},
          /* Track Number */  {"sTitle": "Track", "mDataProp": "track_number", "bSearchable": false, "bVisible": false, "sClass": "library_track"},
          /* Mood */  		  {"sTitle": "Mood", "mDataProp": "mood", "bSearchable": false, "bVisible": false, "sClass": "library_mood"},
          /* BPM */  {"sTitle": "BPM", "mDataProp": "bpm", "bSearchable": false, "bVisible": false, "sClass": "library_bpm"},
          /* Composer */  {"sTitle": "Composer", "mDataProp": "composer", "bSearchable": false, "bVisible": false, "sClass": "library_composer"},
          /* Website */  {"sTitle": "Website", "mDataProp": "info_url", "bSearchable": false, "bVisible": false, "sClass": "library_url"},
          /* Bit Rate */  {"sTitle": "Bit Rate", "mDataProp": "bit_rate", "bSearchable": false, "bVisible": false, "sClass": "library_bitrate"},
          /* Sameple Rate */  {"sTitle": "Sample Rate", "mDataProp": "sample_rate", "bSearchable": false, "bVisible": false, "sClass": "library_sr"},
          /* ISRC Number */  {"sTitle": "ISRC", "mDataProp": "isrc_number", "bSearchable": false, "bVisible": false, "sClass": "library_isrc"},
          /* Encoded */  {"sTitle": "Encoded", "mDataProp": "encoded_by", "bSearchable": false, "bVisible": false, "sClass": "library_encoded"},
          /* Label */  {"sTitle": "Label", "mDataProp": "label", "bSearchable": false, "bVisible": false, "sClass": "library_label"},
          /* Copyright */  {"sTitle": "Copyright", "mDataProp": "copyright", "bSearchable": false, "bVisible": false, "sClass": "library_copyright"},
          /* Mime */  {"sTitle": "Mime", "mDataProp": "mime", "bSearchable": false, "bVisible": false, "sClass": "library_mime"},
          /* Language */  {"sTitle": "Language", "mDataProp": "language", "bSearchable": false, "bVisible": false, "sClass": "library_language"}
          ],
    	              
		"bProcessing": true,
		"bServerSide": true,
		
		"bStateSave": true,
		"fnStateSaveParams": function (oSettings, oData) {
    		//remove oData components we don't want to save.
    		delete oData.oSearch;
    		delete oData.aoSearchCols;
	    },
        "fnStateSave": function (oSettings, oData) {
           
    		$.ajax({
			  url: "/usersettings/set-library-datatable",
			  type: "POST",
			  data: {settings : oData, format: "json"},
			  dataType: "json",
			  success: function(){},
			  error: function (jqXHR, textStatus, errorThrown) {
				  var x;
			  }
			});
        },
        "fnStateLoad": function (oSettings) {
        	var o;

        	$.ajax({
  			  url: "/usersettings/get-library-datatable",
  			  type: "GET",
  			  data: {format: "json"},
  			  dataType: "json",
  			  async: false,
  			  success: function(json){
  				  o = json.settings;
  			  },
  			  error: function (jqXHR, textStatus, errorThrown) {
				  var x;
			  }
  			});
        	
        	return o;
        },
        "fnStateLoadParams": function (oSettings, oData) {
        	var i,
				length,
				a = oData.abVisCols;
		
        	//putting serialized data back into the correct js type to make
        	//sure everything works properly.
	        for (i = 0, length = a.length; i < length; i++) {	
	        	a[i] = (a[i] === "true") ? true : false;
	        }
	        
	        a = oData.ColReorder;
	        for (i = 0, length = a.length; i < length; i++) {	
	        	a[i] = parseInt(a[i], 10);
	        }
	       
	        oData.iCreate = parseInt(oData.iCreate, 10);
        },
		
		"sAjaxSource": "/Library/contents",
		"fnServerData": function ( sSource, aoData, fnCallback ) {
        	var type;
        	
    		aoData.push( { name: "format", value: "json"} );
    		
    		//push whether to search files/playlists or all.
    		type = $("#library_display_type").find("select").val();
    		type = (type === undefined) ? 0 : type;
    		aoData.push( { name: "type", value: type} );
    		
			$.ajax( {
				"dataType": 'json',
				"type": "GET",
				"url": sSource,
				"data": aoData,
				"success": fnCallback
			} );
		},
		"fnRowCallback": AIRTIME.library.events.fnRowCallback,
		"fnCreatedRow": function( nRow, aData, iDataIndex ) {
			
			//call the context menu so we can prevent the event from propagating.
			$(nRow).find('td:not(.library_checkbox)').click(function(e){
				<commit_msg>CC-3356 : Library & Timeline : remove zero prefixes from numbers<commit_after>var AIRTIME = (function(AIRTIME){
	var mod;
	
	if (AIRTIME.library === undefined) {
		AIRTIME.library = {};
	}
	mod = AIRTIME.library;
	
	mod.fnDeleteItems = function(aMedia) {
		var oLibTT = TableTools.fnGetInstance('library_display'),
			oLibTable = $("#library_display").dataTable();
		
		$.post("/library/delete", 
			{"format": "json", "media": aMedia}, 
			function(json){
				oLibTT.fnSelectNone();
				oLibTable.fnDraw();
			});
	};
	
	mod.fnDeleteSelectedItems = function() {
		var oLibTT = TableTools.fnGetInstance('library_display'),
			aData = oLibTT.fnGetSelectedData(),
			item,
			temp,
			aMedia = [];
		
		//process selected files/playlists.
		for (item in aData) {
			temp = aData[item];
			if (temp !== null && temp.hasOwnProperty('id') ) {
				aMedia.push({"id": temp.id, "type": temp.ftype});
			} 	
		}
	
		AIRTIME.library.fnDeleteItems(aMedia);
	};
	
	return AIRTIME;
	
}(AIRTIME || {}));

function addToolBarButtonsLibrary(aButtons) {
	var i,
		length = aButtons.length,
		libToolBar,
		html,
		buttonClass = '',
		DEFAULT_CLASS = 'ui-button ui-state-default',
		DISABLED_CLASS = 'ui-state-disabled';
	
	libToolBar = $(".library_toolbar");
	
	for ( i=0; i < length; i+=1 ) {
		buttonClass = '';
		
		//add disabled class if not enabled.
		if (aButtons[i][2] === false) {
			buttonClass+=DISABLED_CLASS;
		}
		
		html = '<div id="'+aButtons[i][1]+'" class="ColVis TableTools"><button class="'+DEFAULT_CLASS+' '+buttonClass+'"><span>'+aButtons[i][0]+'</span></button></div>';	
		libToolBar.append(html);
		libToolBar.find("#"+aButtons[i][1]).click(aButtons[i][3]);
	}
}

function enableGroupBtn(btnId, func) {
    btnId = '#' + btnId;
    if ($(btnId).hasClass('ui-state-disabled')) {
        $(btnId).removeClass('ui-state-disabled');
    }
}

function disableGroupBtn(btnId) {
    btnId = '#' + btnId;
    if (!$(btnId).hasClass('ui-state-disabled')) {
        $(btnId).addClass('ui-state-disabled');
    }
}

function checkImportStatus(){
    $.getJSON('/Preference/is-import-in-progress', function(data){
        var div = $('#import_status');
        if (data == true){
            div.show();
        }
        else{
            div.hide();
        }
    });
}

function addProgressIcon(id) {
	var tr = $("#au_"+id),
		span;
	
	span = tr.find("td.library_title").find("span");
	
    if (span.length > 0){	
        span.removeClass()
        	.addClass("small-icon progress");
    }
    else{
        tr.find("td.library_title")
        	.append('<span class="small-icon progress"></span>');
    }
}

function checkSCUploadStatus(){
	
    var url = '/Library/get-upload-to-soundcloud-status';
    
    $("span[class*=progress]").each(function(){
    	var span, id;
    	
        span = $(this);
        id = span.parent().parent().data("aData").id;
       
        $.post(url, {format: "json", id: id, type:"file"}, function(json){
            if (json.sc_id > 0) {
                span.removeClass("progress")
                	.addClass("soundcloud");
                
            }
            else if (json.sc_id == "-3") {
                span.removeClass("progress")
                	.addClass("sc-error");
            }
        });
    });
}

function addQtipToSCIcons(){
    $(".progress, .soundcloud, .sc-error").live('mouseover', function(){
    	
        var id = $(this).parent().parent().data("aData").id;
        
        if ($(this).hasClass("progress")){
            $(this).qtip({
                content: {
                    text: "Uploading in progress..."
                },
                position:{
                    adjust: {
                    resize: true,
                    method: "flip flip"
                    },
                    at: "right center",
                    my: "left top",
                    viewport: $(window)
                },
                show: {
                    ready: true // Needed to make it show on first mouseover event
                }
            });
        }
        else if($(this).hasClass("soundcloud")){
            $(this).qtip({
                content: {
                    text: "Retreiving data from the server...",
                    ajax: {
                        url: "/Library/get-upload-to-soundcloud-status",
                        type: "post",
                        data: ({format: "json", id : id, type: "file"}),
                        success: function(json, status){
                            this.set('content.text', "The soundcloud id for this file is: "+json.sc_id);
                        }
                    }
                },
                position:{
                    adjust: {
                    resize: true,
                    method: "flip flip"
                    },
                    at: "right center",
                    my: "left top",
                    viewport: $(window)
                },
                show: {
                    ready: true // Needed to make it show on first mouseover event
                }
            });
        }else if($(this).hasClass("sc-error")){
            $(this).qtip({
                content: {
                    text: "Retreiving data from the server...",
                    ajax: {
                        url: "/Library/get-upload-to-soundcloud-status",
                        type: "post",
                        data: ({format: "json", id : id, type: "file"}),
                        success: function(json, status){
                            this.set('content.text', "There was error while uploading to soundcloud.<br>"+"Error code: "+json.error_code+
                                    "<br>"+"Error msg: "+json.error_msg+"<br>");
                        }
                    }
                },
                position:{
                    adjust: {
                    resize: true,
                    method: "flip flip"
                    },
                    at: "right center",
                    my: "left top",
                    viewport: $(window)
                },
                show: {
                    ready: true // Needed to make it show on first mouseover event
                }
            });
        }
    });
}

$(document).ready(function() {
    var oTable;
    
    oTable = $('#library_display').dataTable( {
    	
    	"aoColumns": [
          /* Checkbox */      {"sTitle": "<input type='checkbox' name='pl_cb_all'>", "mDataProp": "checkbox", "bSortable": false, "bSearchable": false, "sWidth": "25px", "sClass": "library_checkbox"},
          /* Type */          {"sTitle": "", "mDataProp": "image", "bSearchable": false, "sWidth": "25px", "sClass": "library_type", "iDataSort": 2},
          /* ftype */         {"sTitle": "", "mDataProp": "ftype", "bSearchable": false, "bVisible": false},
          /* Title */         {"sTitle": "Title", "mDataProp": "track_title", "sClass": "library_title"},
          /* Creator */       {"sTitle": "Creator", "mDataProp": "artist_name", "sClass": "library_creator"},
          /* Album */         {"sTitle": "Album", "mDataProp": "album_title", "sClass": "library_album"},
          /* Genre */         {"sTitle": "Genre", "mDataProp": "genre", "sClass": "library_genre"},
          /* Year */          {"sTitle": "Year", "mDataProp": "year", "sClass": "library_year", "sWidth": "60px"},
          /* Length */        {"sTitle": "Length", "mDataProp": "length", "sClass": "library_length", "sWidth": "80px"},
          /* Upload Time */   {"sTitle": "Uploaded", "mDataProp": "utime", "sClass": "library_upload_time"},
          /* Last Modified */ {"sTitle": "Last Modified", "mDataProp": "mtime", "bVisible": false, "sClass": "library_modified_time"},
          /* Track Number */  {"sTitle": "Track", "mDataProp": "track_number", "bSearchable": false, "bVisible": false, "sClass": "library_track"},
          /* Mood */  		  {"sTitle": "Mood", "mDataProp": "mood", "bSearchable": false, "bVisible": false, "sClass": "library_mood"},
          /* BPM */  {"sTitle": "BPM", "mDataProp": "bpm", "bSearchable": false, "bVisible": false, "sClass": "library_bpm"},
          /* Composer */  {"sTitle": "Composer", "mDataProp": "composer", "bSearchable": false, "bVisible": false, "sClass": "library_composer"},
          /* Website */  {"sTitle": "Website", "mDataProp": "info_url", "bSearchable": false, "bVisible": false, "sClass": "library_url"},
          /* Bit Rate */  {"sTitle": "Bit Rate", "mDataProp": "bit_rate", "bSearchable": false, "bVisible": false, "sClass": "library_bitrate"},
          /* Sameple Rate */  {"sTitle": "Sample Rate", "mDataProp": "sample_rate", "bSearchable": false, "bVisible": false, "sClass": "library_sr"},
          /* ISRC Number */  {"sTitle": "ISRC", "mDataProp": "isrc_number", "bSearchable": false, "bVisible": false, "sClass": "library_isrc"},
          /* Encoded */  {"sTitle": "Encoded", "mDataProp": "encoded_by", "bSearchable": false, "bVisible": false, "sClass": "library_encoded"},
          /* Label */  {"sTitle": "Label", "mDataProp": "label", "bSearchable": false, "bVisible": false, "sClass": "library_label"},
          /* Copyright */  {"sTitle": "Copyright", "mDataProp": "copyright", "bSearchable": false, "bVisible": false, "sClass": "library_copyright"},
          /* Mime */  {"sTitle": "Mime", "mDataProp": "mime", "bSearchable": false, "bVisible": false, "sClass": "library_mime"},
          /* Language */  {"sTitle": "Language", "mDataProp": "language", "bSearchable": false, "bVisible": false, "sClass": "library_language"}
          ],
    	              
		"bProcessing": true,
		"bServerSide": true,
		
		"bStateSave": true,
		"fnStateSaveParams": function (oSettings, oData) {
    		//remove oData components we don't want to save.
    		delete oData.oSearch;
    		delete oData.aoSearchCols;
	    },
        "fnStateSave": function (oSettings, oData) {
           
    		$.ajax({
			  url: "/usersettings/set-library-datatable",
			  type: "POST",
			  data: {settings : oData, format: "json"},
			  dataType: "json",
			  success: function(){},
			  error: function (jqXHR, textStatus, errorThrown) {
				  var x;
			  }
			});
        },
        "fnStateLoad": function (oSettings) {
        	var o;

        	$.ajax({
  			  url: "/usersettings/get-library-datatable",
  			  type: "GET",
  			  data: {format: "json"},
  			  dataType: "json",
  			  async: false,
  			  success: function(json){
  				  o = json.settings;
  			  },
  			  error: function (jqXHR, textStatus, errorThrown) {
				  var x;
			  }
  			});
        	
        	return o;
        },
        "fnStateLoadParams": function (oSettings, oData) {
        	var i,
				length,
				a = oData.abVisCols;
		
        	//putting serialized data back into the correct js type to make
        	//sure everything works properly.
	        for (i = 0, length = a.length; i < length; i++) {	
	        	a[i] = (a[i] === "true") ? true : false;
	        }
	        
	        a = oData.ColReorder;
	        for (i = 0, length = a.length; i < length; i++) {	
	        	a[i] = parseInt(a[i], 10);
	        }
	       
	        oData.iEnd = parseInt(oData.iEnd, 10);
	        oData.iLength = parseInt(oData.iLength, 10);
	        oData.iStart = parseInt(oData.iStart, 10);
	        oData.iCreate = parseInt(oData.iCreate, 10);
        },
		
		"sAjaxSource": "/Library/contents",
		"fnServerData": function ( sSource, aoData, fnCallback ) {
        	var type;
        	
    		aoData.push( { name: "format", value: "json"} );
    		
    		//push whether to search files/playlists or all.
    		type = $("#library_display_type").find("select").val();
    		type = (type === undefined) ? 0 : type;
    		aoData.push( { name: "type", value: type} );
    		
			$.ajax( {
				"dataType": 'json',
				"type": "GET",
				"url": sSource,
				"data": aoData,
				"success": fnCallback
			} );
		},
		"fnRowCallback": AIRTIME.library.events.fnRowCallback,
		"fnCreatedRow": function( nRow, aData, iDataIndex ) {
			
			//call the context menu so we can prevent the event from propagating.
			$(nRow).find('td:not(.library_checkbox)').click(function(e){
				
{'fraction_non_alphanumeric': 0.17315747998838704, 'fraction_numerical': 0.0025714404213844303, 'mean_word_length': 1.947316953917614, 'pattern_counts': {'":': 258, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2487324', 'n_tokens_mistral': 7925, 'n_tokens_neox': 7319, 'n_words': 1606}