All Downloads are FREE. Search and download functionalities are using the official Maven repository.

admin.mainpage_files.jsMain.js Maven / Gradle / Ivy

var client = null;
var selectedApp;
var permContentToSend = "";

$(function() {

	//creating dialog
	$("#webResourceDisplay").dialog({
		autoOpen : false,
		resizeable : true,
		draggable : true,
		close : function() {
			$('div#wrap').css('opacity', '1.0');
			$('div#footer').css('opacity', '1.0');
			$('div#header').css('opacity', '1.0');
		},
		open : function() {
			$('div#wrap').css('opacity', '0.3');
			$('div#footer').css('opacity', '0.3');
			$('div#header').css('opacity', '0.3');
		},
		minWidth : 300,
		minHeight : 100,
		width : $("div#wrap").width(),
		height : $(window).height() - 500
	});

	//creating dialog
	$("#editWebResources").dialog(
			{
				autoOpen : false,
				resizeable : true,
				draggable : true,
				buttons : [ {
					text : "Submit",
					click : function() { // POST settings to server
						var isReady = getPoliciesToSend();
						// wait until getPoliciesToSend() is done
						if (isReady == true) {
							var portletID = $(".selectedPortlet")[0].id;
							$.post(
									"/install/installedapps?action=setPermission&app="
											+ portletID, {
										settings : "" + permContentToSend
									}, function(data, status) { 
										// if successfull
										alert(status);
									}).fail(function(xhr) {
								alert(xhr);
							});
							$(this).dialog("close");
						}
					}
				} ],
				close : function() {
					$(this).html("");
					permContentToSend = "";
					$('div#wrap').css('opacity', '1.0');
					$('div#footer').css('opacity', '1.0');
					$('div#header').css('opacity', '1.0');
				},
				open : function() {
					$('div#wrap').css('opacity', '0.3');
					$('div#footer').css('opacity', '0.3');
					$('div#header').css('opacity', '0.3');
				},
				minWidth : 300,
				minHeight : 100,
				width : $("div#wrap").width(),
				height : $(window).height() - 500
			});

	//creating dialog
	$("#appDisplay").dialog({
		autoOpen : false,
		resizeable : true,
		draggable : true,
		close : function() {
			$(this).html("");
			$('div#wrap').css('opacity', '1.0');
			$('div#footer').css('opacity', '1.0');
			$('div#header').css('opacity', '1.0');
		},
		open : function() {
			$('div#wrap').css('opacity', '0.3');
			$('div#footer').css('opacity', '0.3');
			$('div#header').css('opacity', '0.3');
		},
		minWidth : 300,
		minHeight : 100,
		width : $("div#wrap").width(),
		height : $(window).height() - 300
	});

	//creating dialog
	$("#diaUpload").dialog({
		autoOpen : false,
		resizable : false,
		draggable : true,
		minWidth : 513,
		minHeight : 300,
		close : function() {
			$('div#wrap').css('opacity', '1.0');
			$('div#footer').css('opacity', '1.0');
			$('div#header').css('opacity', '1.0');
		},
		open : function() {
			$('div#wrap').css('opacity', '0.3');
			$('div#footer').css('opacity', '0.3');
			$('div#header').css('opacity', '0.3');
		}
	});
	
	//creating button
	$("button#done").button({
		icons : {
			primary : "ui-icon-check"
		},
		text : false,
		disabled : true
	});

	//creating button
	$("#initUp").button({
		icons : {
			primary : "ui-icon-arrowthickstop-1-n"
		}
	});
	//creating button
	$('input:text').button().css({
		'text-align' : 'left',
		'outline' : 'none',
		'cursor' : 'text',
		'padding' : '2.5px',
		'padding-left' : '10px',
		'margin-left' : '10px'
	});

	//creating button
	$('input[type="submit"]').each(function() {
		$(this).hide().after(' 
Actions


" + "
" + "
"); //button to delete permission //creating button $("#allowPerB" + i + j).button({ icons : { primary : "ui-icon-close" }, text : false }); } //if 0 actions if (countActions == 0) { $("#polPerm" + i) .append( "
Actions: none

" + "
" + "
"); //button to delete permission //creating button $("#allowPerB" + i + j).button({ icons : { primary : "ui-icon-close" }, text : false }); } //if more actions if (countActions == 2) { var actionsInput = ""; //creating action-part for (var x = 0; x < actionForThis.length; x++) { actionsInput = actionsInput + "
"; } //inserting action-part and do the rest like before $("#polPerm" + i) .append( "
Actions
" + actionsInput + "

" + "
" + "
"); //button to delete permission //creating button $("#allowPerB" + i + j).button({ icons : { primary : "ui-icon-close" }, text : false }); } } } //if the dialog has content afterwards open it if ($("#editWebResources").html() != "") { $("#editWebResources").dialog("open"); } } //delete permission in editing-mode function closePermission(i, j) { $("#wrapPolPerm" + i + j).remove(); } //if policy is checked/unchecked change style function policyChecked(num) { var idOfCheckbox = "slide" + num; if ($("#" + idOfCheckbox).prop("checked") == true) { $("#" + idOfCheckbox).parent().css("background", "#454545"); $("#wrapPolicy" + num).css("opacity", "1.0"); } else { $("#" + idOfCheckbox).parent().css("background", "#E8E8E8"); $("#wrapPolicy" + num).css("opacity", "0.8"); } } //extracts values in editing-mode of permissions //running after clicking submit-button function getPoliciesToSend() { var thisDia = $("div#editWebResources"); //count policies var countPolicies = $("div#editWebResources").find("div.wrapPols").length; var countPermsInOnePolicy; var countCondsInOnePolicy; var permString = ""; var condString = ""; var jsonString = ""; var allPolicies = ""; var jsonToSend = ""; // for each policy for (var x = 0; x < countPolicies; x++) { //boolean if current policy is checked var isChecked = thisDia.find("div#wrapPolicy" + x).find(".slide").find( ".slideCheck").prop("checked"); //count of permission in each policy countPermsInOnePolicy = thisDia.find("div#wrapPolicy" + x).find( ".polPermissions").find(".wrapOnePolPerm").length; //count of conditions in each policy countCondsInOnePolicy = thisDia.find("div#wrapPolicy" + x).find( ".polConditions").find(".wrapOnePolCond").length; //array containing permissions var polPerms = thisDia.find("div#wrapPolicy" + x).find( ".polPermissions").find(".wrapOnePolPerm"); //if there are permissions if (countPermsInOnePolicy != 0) { //for each permission for (var h = 0; h < countPermsInOnePolicy; h++) { //id of the current permissions in the current policy var idOfPolPerm = polPerms[h].attributes[0].value; var permType = $("#"+idOfPolPerm).find( ".permType").val(); var permFilter = $("#"+idOfPolPerm).find( ".permFilter").val(); var actionsAsArray = $("#"+idOfPolPerm).find( "input:checkbox:checked").map(function() { return $(this).next("label").text().split(' '); }); //transforms array to string var actionsAsString = ""; for (var a = 0; a < actionsAsArray.length; a++) { if (actionsAsString != "") { actionsAsString = actionsAsString + "," + actionsAsArray[a]; } else { actionsAsString = actionsAsArray[a]; } } //creates permission-string if (permString == "") { permString = permString + '{"type":"' + permType + '", "filter":"' + permFilter + '", "actions":"' + actionsAsString + '"}'; } else { permString = permString + ', {"type":"' + permType + '", "filter":"' + permFilter + '", "actions":"' + actionsAsString + '"}'; } //setting mode-type if (isChecked == true) { var modeType = "ALLOW"; } else { var modeType = "DENY"; } //adding mode and constant string-parts jsonString = '{"mode":"' + modeType + '", "permissions":[' + permString + '], "conditions":['; } } else { //if there are no permissions in the current policy if (isChecked == true) { var modeType = "ALLOW"; } else { var modeType = "DENY"; } //adding mode and constant string-parts //no permissions -> "permissions":[] jsonString = '{"mode":"' + modeType + '", "permissions":[], "conditions":['; } //for each condition for (var m = 0; m < countCondsInOnePolicy; m++) { var condType = thisDia.find("div#wrapPolicy" + x).find( ".polConditions").find("#wrapPolCond" + x + m).find( ".condType").val(); var condArg1 = thisDia.find("div#wrapPolicy" + x).find( ".polConditions").find("#wrapPolCond" + x + m).find( ".condArg1").val(); var condArg2 = thisDia.find("div#wrapPolicy" + x).find( ".polConditions").find("#wrapPolCond" + x + m).find( ".condArg2").val(); //creating condition-string if (condString == "") { condString = condString + '{"type":"' + condType + '", "arg1":"' + condArg1 + '", "arg2":"' + condArg2 + '"}'; } else { condString = condString + ', {"type":"' + condType + '", "arg1":"' + condArg1 + '", "arg2":"' + condArg2 + '"}'; } } //adding condition-string jsonString = jsonString + condString + ']}'; if (allPolicies == "") { allPolicies = allPolicies + jsonString; } else { allPolicies = allPolicies + ", " + jsonString; } //finally adding constant string-part jsonToSend = '{"policies":[' + allPolicies + ']}'; jsonString = ""; condString = ""; permString = ""; } //writing in variable permContentToSend permContentToSend = jsonToSend; //clearing variable jsonToSend jsonToSend = ""; return true; } //Information-Button clicked starts this function showAppInfo() { // Only if an appPortlet is selected if (selectedApp != "") { //get selected portlet-id var portletID = $(".selectedPortlet")[0].id; //get information for selected portlet $.getJSON("/install/installedapps?action=getInfo&app=" + portletID, function(json, xhr) { //open function fillAppDisplay for this json-data fillAppDisplay(selectedApp, json.policies); }).fail(function(xhr, textStatus, errorThrown) { console.log("FAIL : " + textStatus); console.log("FAIL : " + errorThrown); }); } else { //if no appPortlet is selected alert("Choose a bundle!"); } } //Update appPortlet function updateApp() { // Only if an appPortlet is selected if (selectedApp != "") { //get selected portlet-id var portletID = $(".selectedPortlet")[0].id; //update-url for selected portlet $.getJSON("/install/installedapps?action=update&app=" + portletID, function(json) { alert(json.statusInfo); }); } else { //if no appPortlet is selected alert("Choose a bundle!"); } } //Edit permissions of appPortlet function setPerms() { // Only if an appPortlet is selected if (selectedApp != "") { //get selected portlet-id var portletID = $(".selectedPortlet")[0].id; //get information for portlet-id $.getJSON("/install/installedapps?action=getInfo&app=" + portletID, function(json, xhr) { //open function fillEditDisplay for the json-data fillEditDisplay(selectedApp, json.policies); }).fail(function(xhr, textStatus, errorThrown) { console.log("FAIL : " + textStatus); console.log("FAIL : " + errorThrown); }); } else { //if no appPortlet is selected alert("Choose a bundle!"); } } //show the webresources for selected appPortlet function showWebResources() { // Only if an appPortlet is selected if ($(".selectedPortlet")[0]) { //get selected portlet-id var portletID = $(".selectedPortlet")[0].id; //destroy the last jsTree $("#treeWebRes").jstree("destroy"); //if #treeWebRes is no jsTree, transform into jsTree if (!($("#treeWebRes").hasClass("jstree"))) { $("#treeWebRes") .jstree( { "core" : { "animation" : 0, "check_callback" : true, "themes" : { "stripes" : true }, 'data' : { "url" : "/install/installedapps?action=webResources&app=" + portletID, 'data' : function(node) { return { 'id' : node.id, 'text' : node.text, 'alias' : node.alias }; } } }, "plugins" : [ "wholerow", "types" ] }).bind( "select_node.jstree", function(event, data) { if (!$("#treeWebRes").jstree("is_parent", data.node)) { window.open(data.node.text, "_blank"); } }); } //open dialog $("#webResourceDisplay").dialog("open"); } else { //if no portlet selected alert("Choose a bundle!"); } } //delete selected portlet function deleteApp() { // Only if an appPortlet is selected if ($(".selectedPortlet")[0]) { //get selected portlet-id var portletID = $(".selectedPortlet")[0].id; //delete selected portlet $.getJSON("/install/installedapps?action=delete&app=" + portletID, function(json) { var bundleName = $("#sortableApps") .find(".selectedPortlet").parent().find( ".portlet-content").text(); alert(bundleName + " deleted."); }); //list the apps again listSysApps(); } else { //if no portlet is selected alert("Choose a bundle!"); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy