#set ($layout = "grid.vm" )
#if($params.profile)
#set($profile_name=$params.profile)
#set($title = "Attribute $profile_name")
#set($r = $profile.load($profile_name))
#else
#set($title = "Attribute $params.computer")
#end
#set ($module = "properties")
#set($disablebuttons=false)
#if($request.isUserInRole("packageadmin"))
#set($isAdmin=true)
#else
#set($disablebuttons=true)
#end
#if($profile_name)
#set($r=$property.fetchByProfileName($profile_name))
#else
#set($r=$property.fetchByComputerName($params.computer))
#end
	<SCRIPT type="text/javascript">

	var grid;
	var dataView;
  	var columns = [
		{id: "key", name: "Name", field: "name", cssClass: "mycell"},
		{id: "value", name: "Wert",  field: "value", cssClass: "mycell" },
	];

	function enable_buttons(row) {
		var o=dataView.getItem(row);
		if(!o) return;
#if(!$disablebuttons)
		$('#button-edit').button("option","disabled",false);
		$('#button-delete').button("option","disabled",false);
#end
	};


	function post_error_handler(jqXHR, textStatus, errorThrown) {
		alert("AJAX POST Error:"+errorThrown);
	}

	function updateFilter(search) {
		dataView.setFilterArgs({
			searchString: search });
		dataView.refresh();
	}

	function myFilter(item, args) {
		if (args.searchString != "" && item["name"].indexOf(args.searchString) == -1) {
			return false;
		}
		return true;
	}

	$(document).ready(function () {

#js_create_grid("columns")

		grid.onSelectedRowsChanged.subscribe(function() {
	   		row_ids = grid.getSelectedRows();
			i=row_ids[0];
			o=dataView.getItem(i);
			if(!o) return;
			enable_buttons(i);
 	  		console.log(row_ids);
		});
		grid.onDblClick.subscribe(function() { $("#button-edit").click(); });

#js_dialog_form("new" "Neues Attribut" "ui-icon-plus" $disablebuttons false)
#js_dialog_form("edit" "Speichern" "ui-icon-pencil" true false)
#js_dialog_form("delete" "Entfernen" "ui-icon-minus" true false)
#js_searchbox()
#if($profile_name)
#js_load_data_key("properties","id","profile=${profile_name}")
#else
#js_load_data_key("properties","id","computer=${params.computer}")
#end
		
	});

	</SCRIPT>
<DIV class="ui-layout-center">
</DIV>
<DIV class="ui-layout-north">#parse("menu.vm")&nbsp;
#searchbox()
<div id="ajaxBusy" class="ajaxBusy"><img class="ajaxBusy" src="$root/images/loading.gif"></div>
#parse("properties/assistant.inc")
</DIV>
<DIV class="ui-layout-south">
<div class="buttons">
<button id="button-new">Neu</button>
<button id="button-edit">Bearbeiten</button>
<button id="button-delete">Entfernen</button>
<span>&nbsp;</span>
</div>
</DIV>
#parse("$module/new.inc")
#parse("$module/edit.inc")
#parse("$module/delete.inc")

