<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.emframe.dev.MContext,
                 com.novell.emframe.dev.eMFrameFactory,
                 com.novell.emframe.dev.DirUtils,
                 com.novell.emframe.base.DGUtilities,
                 java.util.List,
                 com.novell.emframe.dev.dataTable.TableCell,
                 java.util.Iterator,
                 com.novell.application.console.snapin.ObjectType,
                 com.novell.application.console.snapin.ObjectEntry,
                 com.novell.emframe.dev.dataTable.IconTableCell,
                 com.novell.emframe.dev.dataTable.TextTableCell,
                                                                             com.novell.admin.ns.AdminNamespace"%>
<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<iman:stringtable bundle="DevResources"/>
<iman:stringtable bundle="BaseResources"/>


<html>
	<head>
		<title></title>
		<style media="screen" type="text/css">
	   	<!--
			-->
		</style>
		<iman:stylesheet/>
      <iman:dataTableScripts/>
      <iman:eMFrameScripts/>

		<script language="JavaScript">

			function pageInit()
			{
			}

			function handleModifyObject( groupDN )
			{
				var dnArray = new Array( groupDN );
				document.Form.elements['eDir$target'].value = pack( dnArray );
				<%/*--document.Form.elements["initialPageId"].value = "";  don"t need to go to a specific page -- */%>
				document.Form.elements['delegate'].value = "base.ModifyGroup";
				document.Form.submit();
			}


         function handleMenu(menuItemId, selectedIndices, tableData)
         {
            if(menuItemId=="New")
            {
               window.location = "frameservice?NPService=fw.LaunchService&NPAction=Delegate&delegate=base.CreateGroup&launcher=<c:out value="${taskId}"/>";
            }
            else if(menuItemId=="Edit")
            {
               if(selectedIndices==null || selectedIndices.length==0)
               {
                  alert("<iman:string key="Groups.noGroupSelected"/>");
                  return;
               }

               var dnArray = new Array();
               for(var i=0; i<selectedIndices.length; i++)
               {
                  dnArray[dnArray.length] = tableData[selectedIndices[i]][1];
               }
	   			var dnList = pack(dnArray);

               window.location = "frameservice?NPService=fw.LaunchService&NPAction=Delegate&delegate=base.ModifyGroup&launcher=<c:out value="${taskId}"/>&eDir$target=" + urlEncode( dnList );
            }
            else if(menuItemId=="Delete")
            {
               if(selectedIndices==null || selectedIndices.length==0)
               {
                  alert("<iman:string key="Groups.noGroupSelected"/>");
                  return;
               }

               var dnArray = new Array();
               for(var i=0; i<selectedIndices.length; i++)
               {
                  dnArray[dnArray.length] = tableData[selectedIndices[i]][1];
               }
	   			var dnList = pack(dnArray);

               window.location = "frameservice?NPService=fw.LaunchService&NPAction=Delegate&delegate=base.DeleteGroup&launcher=<c:out value="${taskId}"/>&targetNames=" + urlEncode( dnList );
            }

            return;
         }
	 	</script>
	</head>

	<body onLoad="pageInit()">
		<form name="Form" method="post" action="webacc" onSubmit="return false">
			<input type="hidden" name="eDir$target" value="">
			<input type="hidden" name="error" value="dev.GenMsg">
			<input type="hidden" name="nextState" value="initialState">

			<input type="hidden" name="NPService" value="fw.LaunchService">
			<input type="hidden" name="NPAction" value="Delegate">
			<input type="hidden" name="delegate" value="">
			<input type="hidden" name="launcher" value="fw.HomePage">
			<input type="hidden" name="lifecycle" value="Recreate">

			<p class="head3b">
            <iman:string key="DynamicGroup.ViewMyGroupsTaskName"/>
			</p>

      <br>



         <%
         // localized strings
         MContext context = eMFrameFactory.getMContext(request);
         DirUtils dirUtils = context.getDirUtils();

         List groupList = (List)request.getAttribute("groups");
         AdminNamespace namespace = (AdminNamespace)request.getAttribute("namespace");
         TableCell[][] data = new TableCell[groupList.size()][];
         int i=0;
         for(Iterator iter = groupList.iterator(); iter.hasNext();)
         {
            ObjectEntry objectEntry = (ObjectEntry) iter.next();
            String objectName = namespace.getUnrootedName( objectEntry );

            ObjectType objectType = objectEntry.getObjectType();
            boolean isDynamicGroup =  ( DirUtils.isOfType(objectType, DGUtilities.DYNAMIC_GROUP_CLASS, true ) || dirUtils.isOfAuxClass( objectEntry, DGUtilities.DYNAMIC_GROUP_AUX_CLASS ));

            String iconUrl = isDynamicGroup ? "dev/dir/dynamicGroup.gif" : "dev/dir/Group.gif";
            data[i] = new TableCell[2];
            data[i][0] = new IconTableCell(context.getDirUtils().getObjectTypeDisplayName(objectType.getName(), context), iconUrl, objectType.getName());
            data[i][1] = new TextTableCell(objectName, objectName);

            i++;
         }

         request.setAttribute("data", data);
         %>

         <iman:dataTable id="myTable" tableData="${data}" menuActionHandler="handleMenu" titleKey="DynamicGroup.ViewMyGroupsTitle">
            <iman:menuItem textKey="General.New" id="New"/>
            <iman:menuItem textKey="General.Edit" id="Edit"/>
            <iman:menuItem textKey="General.Delete" id="Delete"/>
            <iman:columnHeader textKey="Groups.typeHeader"/>
            <iman:columnHeader textKey="Groups.nameHeader"/>
         </iman:dataTable>
		</form>

   <iman:bar/>
   <iman:button key="Close" onClick="window.location='webacc?NPService=fw.LaunchService&NPAction=Return&returnID=${taskId}'"/>
	</body>
</html>
