<commit_before>var channelXml,skinXml;

// Initialization tasks for non-focused mode
function initportal() {

	// initialize dialog menus
	$("#contentAddingDialog").channelbrowser({handles: new Array("#contentDialogLink")});
	$("#layoutDialogLink").click(initializeLayoutMenu);
	$("#skinDialogLink").click(initializeSkinMenu);

	// initialize portlet drag and drop
    $('div[@id*=inner-column_]').each(function(i){
		$(this).Sortable({
			accept : 'movable',
			helperclass : 'dropborder',
			opacity : 0.5,
			handle : 'div.portlet-toolbar',
			onStop : movePortlet
		});
    });
    
    // add onclick events for portlet delete buttons
	$('a[@id*=removePortlet_]').each(function(i){$(this).click(function(){deletePortlet(this.id.split("_")[1]);return false;});});	

	$("#addTabLink").click(function(){addTab()});
	$("#deletePageLink").click(function(){deleteTab(this.id.split("_")[1])});
	$("#editPageLink").click(initializeLayoutMenu);
	$("#movePageLeftLink").click(function(){ moveTab('left')});
	$("#movePageRightLink").click(function(){moveTab('right')});
	initTabEditLinks();

}

// Initialization tasks for focus mode
function initfocusedportal() {
	$("#focusedContentDialogLink").click(initializeFocusedContentMenu);
}
function initializeFocusedContentMenu() {
	$("#focusedContentAddingDialog").dialog({height:450, width:500});
	$("#focusedContentDialogLink")
		.unbind('click', initializeFocusedContentMenu)
		.click(function(){$("#focusedContentAddingDialog").dialog('open');});
}

function initializeLayoutMenu() {
	$("#changeColumns").find("img")
		.click(function(){$(this).prev().attr("checked", true)})
		.end().find("input[value=" + getCurrentLayoutString() + "]").attr("checked", true);
	$("#pageLayoutDialog").dialog({height:300, width:400});

	$("#layoutDialogLink")
		.unbind('click', initializeLayoutMenu)
		.click(function(){$("#pageLayoutDialog").dialog('open');});
	$("#editPageLink")
		.unbind('click', initializeLayoutMenu)
		.click(function(){$("#pageLayoutDialog").dialog('open');});

}
function getCurrentLayoutString() {
	var str = "";
	$('#portalPageBodyColumns > td[@id*=column_]').each(function(){
		if (str != '')
			str += '-';
		str += parseInt($(this).attr("width"));
	});
	return str;
}
function updatePage(form) {
	var name = form.pageName.value;
	var layout = $(form.layoutChoice).filter(":checked").val();
	var columns = layout.split("-");
	if (name != $("#portalPageBodyTitle").text())
		updatePageName(name);
	if (layout != getCurrentLayoutString())
		changeColumns(columns);
	$("#pageLayoutDialog").dialog('close');
	return false;
}
function updatePageName(name) {
	$("#tabLink_" + tabId + " > span").text(name);
	$("#portalPageBodyTitle").text(name);
	$.post(preferencesUrl, {action: 'renameTab', tabId: tabId, tabName: name}, function(xml){});
	return false;
}
// Column editing persistence functions
function changeColumns(newcolumns) {
	$.post(preferencesUrl, {action: 'changeColumns', tabId: tabId, columns: newcolumns}, 
		function(xml) { 
		    var columns = $('#portalPageBodyColumns > td[@id*=column_]');
		    if (columns.length < newcolumns.length) {
		    	$("newColumns > id", xml).each(function(){
		    		$("#portalPageBodyColumns")
		    			.append(
		    				$(document.createElement('td')).attr("id", 'column_' + $(this).text())
		    					.addClass("portal-page-column")
		    					.append(
		    						$(document.createElement('div'))
		    							.attr("id", 'inner-column_' + $(this).text())
		    							.addClass("portal-page-column-inner")
		    							.Sortable({
											accept : 'movable',
											helperclass : 'dropborder',
											opacity : 0.5,
											handle : 'div.portlet-toolbar',
											onStop : movePortlet
										})
								)
		    			);
		    	});
		    	
		    } else if(columns.length > newcolumns.length) {
		    	for (var i = newcolumns.length; i < columns.length; i++) {
		    		var lastColumn = $("#inner-column_" + $(columns[newcolumns.length-1]).attr("id").split("_")[1]);
		    		var portlets = $(columns[i]).find("div[@id*=portlet_]")
			    		.each(function(){
			    			$(this).appendTo(lastColumn);
			    			lastColumn.SortableAddItem($(this));
			    		})
		    			.end().remove();
		    	}
		    	
		    }

		    $("#portalPageBodyTitleRow").attr("colspan", newcolumns.length);
		    $('#portalPageBodyColumns > td[@id*=column_]').each(function(i){
		    	$(this).attr("width", newcolumns[i] + "%")
		    	.removeClass("right").removeClass("left").removeClass("single");
		    	if (newcolumns.length == 1) $(this).addClass("single");
		    	else if (i == 0) $(this).addClass("left");
		    	else if (i == newcolumns.length - 1) $(this).addClass("right");
		    });
			
		}
	);
}

// Portlet editing persistence functions
function addPortlet(chandId) {
	$.post(preferencesUrl, {action: 'addChannel', elementID: tabId, channelID: $("#addChannelId").attr("value")}, function(xml) { window.location = portalUrl; });
}
function deletePortlet(id) {
	if (!confirm("Are you sure you want to remove this portlet?")) return false;
	$('#portlet_'+id).remove();
	$.post(preferencesUrl, {action: 'removeElement', elementID: id}, function(xml) { });
}


// Tab editing persistence functions
function addTab() {
	$.post(preferencesUrl, {action: 'addTab'}, function(xml) {
		window.location = portalUrl + "?uP_root=root&uP_sparam=activeTab&activeTab=" + 
			($("#portalNavigationList > li").length + 1);
	});
}
function deleteTab(tabId) {
	if (!confirm("Are you sure you want to remove this tab and all its content?")) return false;
	$.post(preferencesUrl, {action: 'removeElement', elementID: id}, function(xml) { window.location = portalUrl + "?uP_root=root&uP_sparam=activeTab&activeTab=1"; });
}
function moveTab(direction) {
	var tab = $("#portalNavigation_" + tabId);
	var method = 'insertBefore';<commit_msg>NOJIRA Fixed bug preventing the AJAX interface from successfully deleting tabs.<commit_after>var channelXml,skinXml;

// Initialization tasks for non-focused mode
function initportal() {

	// initialize dialog menus
	$("#contentAddingDialog").channelbrowser({handles: new Array("#contentDialogLink")});
	$("#layoutDialogLink").click(initializeLayoutMenu);
	$("#skinDialogLink").click(initializeSkinMenu);

	// initialize portlet drag and drop
    $('div[@id*=inner-column_]').each(function(i){
		$(this).Sortable({
			accept : 'movable',
			helperclass : 'dropborder',
			opacity : 0.5,
			handle : 'div.portlet-toolbar',
			onStop : movePortlet
		});
    });
    
    // add onclick events for portlet delete buttons
	$('a[@id*=removePortlet_]').each(function(i){$(this).click(function(){deletePortlet(this.id.split("_")[1]);return false;});});	

	$("#addTabLink").click(function(){addTab()});
	$("#deletePageLink").click(deleteTab);
	$("#editPageLink").click(initializeLayoutMenu);
	$("#movePageLeftLink").click(function(){ moveTab('left')});
	$("#movePageRightLink").click(function(){moveTab('right')});
	initTabEditLinks();

}

// Initialization tasks for focus mode
function initfocusedportal() {
	$("#focusedContentDialogLink").click(initializeFocusedContentMenu);
}
function initializeFocusedContentMenu() {
	$("#focusedContentAddingDialog").dialog({height:450, width:500});
	$("#focusedContentDialogLink")
		.unbind('click', initializeFocusedContentMenu)
		.click(function(){$("#focusedContentAddingDialog").dialog('open');});
}

function initializeLayoutMenu() {
	$("#changeColumns").find("img")
		.click(function(){$(this).prev().attr("checked", true)})
		.end().find("input[value=" + getCurrentLayoutString() + "]").attr("checked", true);
	$("#pageLayoutDialog").dialog({height:300, width:400});

	$("#layoutDialogLink")
		.unbind('click', initializeLayoutMenu)
		.click(function(){$("#pageLayoutDialog").dialog('open');});
	$("#editPageLink")
		.unbind('click', initializeLayoutMenu)
		.click(function(){$("#pageLayoutDialog").dialog('open');});

}
function getCurrentLayoutString() {
	var str = "";
	$('#portalPageBodyColumns > td[@id*=column_]').each(function(){
		if (str != '')
			str += '-';
		str += parseInt($(this).attr("width"));
	});
	return str;
}
function updatePage(form) {
	var name = form.pageName.value;
	var layout = $(form.layoutChoice).filter(":checked").val();
	var columns = layout.split("-");
	if (name != $("#portalPageBodyTitle").text())
		updatePageName(name);
	if (layout != getCurrentLayoutString())
		changeColumns(columns);
	$("#pageLayoutDialog").dialog('close');
	return false;
}
function updatePageName(name) {
	$("#tabLink_" + tabId + " > span").text(name);
	$("#portalPageBodyTitle").text(name);
	$.post(preferencesUrl, {action: 'renameTab', tabId: tabId, tabName: name}, function(xml){});
	return false;
}
// Column editing persistence functions
function changeColumns(newcolumns) {
	$.post(preferencesUrl, {action: 'changeColumns', tabId: tabId, columns: newcolumns}, 
		function(xml) { 
		    var columns = $('#portalPageBodyColumns > td[@id*=column_]');
		    if (columns.length < newcolumns.length) {
		    	$("newColumns > id", xml).each(function(){
		    		$("#portalPageBodyColumns")
		    			.append(
		    				$(document.createElement('td')).attr("id", 'column_' + $(this).text())
		    					.addClass("portal-page-column")
		    					.append(
		    						$(document.createElement('div'))
		    							.attr("id", 'inner-column_' + $(this).text())
		    							.addClass("portal-page-column-inner")
		    							.Sortable({
											accept : 'movable',
											helperclass : 'dropborder',
											opacity : 0.5,
											handle : 'div.portlet-toolbar',
											onStop : movePortlet
										})
								)
		    			);
		    	});
		    	
		    } else if(columns.length > newcolumns.length) {
		    	for (var i = newcolumns.length; i < columns.length; i++) {
		    		var lastColumn = $("#inner-column_" + $(columns[newcolumns.length-1]).attr("id").split("_")[1]);
		    		var portlets = $(columns[i]).find("div[@id*=portlet_]")
			    		.each(function(){
			    			$(this).appendTo(lastColumn);
			    			lastColumn.SortableAddItem($(this));
			    		})
		    			.end().remove();
		    	}
		    	
		    }

		    $("#portalPageBodyTitleRow").attr("colspan", newcolumns.length);
		    $('#portalPageBodyColumns > td[@id*=column_]').each(function(i){
		    	$(this).attr("width", newcolumns[i] + "%")
		    	.removeClass("right").removeClass("left").removeClass("single");
		    	if (newcolumns.length == 1) $(this).addClass("single");
		    	else if (i == 0) $(this).addClass("left");
		    	else if (i == newcolumns.length - 1) $(this).addClass("right");
		    });
			
		}
	);
}

// Portlet editing persistence functions
function addPortlet(chandId) {
	$.post(preferencesUrl, {action: 'addChannel', elementID: tabId, channelID: $("#addChannelId").attr("value")}, function(xml) { window.location = portalUrl; });
}
function deletePortlet(id) {
	if (!confirm("Are you sure you want to remove this portlet?")) return false;
	$('#portlet_'+id).remove();
	$.post(preferencesUrl, {action: 'removeElement', elementID: id}, function(xml) { });
}


// Tab editing persistence functions
function addTab() {
	$.post(preferencesUrl, {action: 'addTab'}, function(xml) {
		window.location = portalUrl + "?uP_root=root&uP_sparam=activeTab&activeTab=" + 
			($("#portalNavigationList > li").length + 1);
	});
}
function deleteTab() {
	if (!confirm("Are you sure you want to remove this tab and all its content?")) return false;
	$.post(preferencesUrl, {action: 'removeElement', elementID: tabId}, function(xml) { 
		window.location = portalUrl + "?uP_root=root&uP_sparam=activeTab&activeTab=1"; 
	});
}
function moveTab(direction) {
	var tab = $("#portalNavigation_" + tabId);
	var method = 'insertBefore';
{'fraction_non_alphanumeric': 0.19672833162041795, 'fraction_numerical': 0.004196642685851319, 'mean_word_length': 4.4185614849187935, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '4159408', 'n_tokens_mistral': 4060, 'n_tokens_neox': 3659, 'n_words': 639}