⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 territoryedit.jsp

📁 国外的一套开源CRM
💻 JSP
📖 第 1 页 / 共 2 页
字号:
%>
	<p>Are you sure you want to delete the <b><%=selectedRole.getString("roleName")%></b> territory?
	<br><br>All sub-territories will be deleted as well, and all users will be unassigned from those territories.
	<br><br><i>Note: This action cannot be undone</i>
	<CENTER>
	<FORM ACTION=territoryEdit TARGET=contentFrame>
	    <INPUT TYPE=hidden NAME=roleId value=<%=selectedRoleId%>>
	    <INPUT TYPE=hidden NAME=action value=delete>
	    <INPUT TYPE=SUBMIT CLASS=button value="Delete this Territory">
	</FORM>
	</CENTER>
<%
  }
  else if (action.equals(UIScreenSection.ACTION_UPDATE))
  {

	if ( selectedRole == null )
		out.write("Error:  you must select an existing territory first.  No territory specified");
	else
	{

		out.write("<body onload=parent.diagramFrame.location.reload()>");

		selectedRole.set("roleName", request.getParameter("roleName"));

		List storeGVL = new LinkedList();
		storeGVL.add(selectedRole);

		String unassignedRoles = request.getParameter("inpUnassigned");
		String assignedRoles   = request.getParameter("inpAssigned");

		if ( unassignedRoles != null )
		{
			StringTokenizer st = new StringTokenizer(unassignedRoles, ";");
			while (st.hasMoreTokens())
			{
				String contactId = st.nextToken();

				ModelEntity contactEntity = delegator.getModelEntity("Contact");
				HashMap hashMap = new HashMap();
				hashMap.put("contactId", contactId);
				GenericPK genericPk = new GenericPK(contactEntity, hashMap);
				GenericValue contact = delegator.findByPrimaryKey(genericPk);

				contact.set("roleId", null);
				storeGVL.add(contact);

			}
		}

		if ( assignedRoles != null )
		{
			StringTokenizer st = new StringTokenizer(assignedRoles, ";");
			while (st.hasMoreTokens())
			{
				String contactId = st.nextToken();

				ModelEntity contactEntity = delegator.getModelEntity("Contact");
				HashMap hashMap = new HashMap();
				hashMap.put("contactId", contactId);
				GenericPK genericPk = new GenericPK(contactEntity, hashMap);
				GenericValue contact = delegator.findByPrimaryKey(genericPk);

				contact.set("roleId", selectedRoleId);
				storeGVL.add(contact);
			}
		}
		delegator.storeAll(storeGVL);
		roleChanged = true;
	}
  }
  else if (action.equals(UIScreenSection.ACTION_INSERT))
  {

	if ( selectedRole == null )
		out.write("Error:  you must select an existing territory first.  No territory specified");
	else
	{

		out.write("<body onload=parent.diagramFrame.location.reload()>");

		String newRoleId = GenericReplicator.getNextSeqId("Party", delegator);
		ModelEntity entity = delegator.getModelEntity("Party");
		GenericValue party = new GenericValue(entity);
		party.setDelegator(delegator);
		party.set("partyId", newRoleId);

		String roleName = request.getParameter("roleName");

		if ( ( roleName == null ) || ( roleName.length() < 1 ) )
			roleName = "Territory-" + newRoleId;

		entity = delegator.getModelEntity(ENTITY);
		GenericValue role = new GenericValue(entity);
		role.setDelegator(delegator);
		role.set("roleId", newRoleId );
		role.set("roleName", roleName);
		role.set("roleParentId", selectedRoleId);
		role.set("accountId", userInfo.getAccountId());

		String parentPath = selectedRole.getString("rolePath");
		String rolePath = parentPath + ", " + newRoleId;
		role.set("rolePath", rolePath );

		List storeGVL = new LinkedList();
		storeGVL.add(role);
		storeGVL.add(party);

		String unassignedRoles = request.getParameter("inpUnassigned");
		String assignedRoles   = request.getParameter("inpAssigned");

		if ( unassignedRoles != null )
		{
			StringTokenizer st = new StringTokenizer(unassignedRoles, ";");
			while (st.hasMoreTokens())
			{
				String contactId = st.nextToken();

				ModelEntity contactEntity = delegator.getModelEntity("Contact");
				HashMap hashMap = new HashMap();
				hashMap.put("contactId", contactId);
				GenericPK genericPk = new GenericPK(contactEntity, hashMap);
				GenericValue contact = delegator.findByPrimaryKey(genericPk);

				contact.set("roleId", null);
				storeGVL.add(contact);
			}
		}

		if ( assignedRoles != null )
		{
			StringTokenizer st = new StringTokenizer(assignedRoles, ";");
			while (st.hasMoreTokens())
			{
				String contactId = st.nextToken();

				ModelEntity contactEntity = delegator.getModelEntity("Contact");
				HashMap hashMap = new HashMap();
				hashMap.put("contactId", contactId);
				GenericPK genericPk = new GenericPK(contactEntity, hashMap);
				GenericValue contact = delegator.findByPrimaryKey(genericPk);

				contact.set("roleId", newRoleId);
				storeGVL.add(contact);

			}
		}
		delegator.storeAll(storeGVL);
		roleChanged = true;
	}

  }

  else if(action.equals(UIScreenSection.ACTION_DELETE))
  {
	if ( selectedRole == null )
		out.write("Error:  you must select an existing territory first.  No territory specified");
	else
	{

		out.write("<body onload=parent.diagramFrame.location.reload()>");

		ModelEntity entity = delegator.getModelEntity(ENTITY);
		Vector roleFields = new Vector();
		String rolePath = selectedRole.getString("rolePath");
		if ( (rolePath == null ) || ( rolePath.length() == 0 ) )
			rolePath = "ERROR:";
		roleFields.add( new EntityExpr("rolePath", EntityOperator.LIKE, rolePath + "%"));
		List roles = delegator.findByAnd("Role", roleFields, null);

		Iterator ir = roles.iterator();
		try{
			while(ir.hasNext())
			{
				GenericValue roleToDelete = (GenericValue)ir.next();
				String deleteRoleId = roleToDelete.getString("roleId");
				out.write("deleting Territory " + roleToDelete.getString("roleName"));
				HashMap hm = new HashMap();
				hm.put("roleId", deleteRoleId);
				GenericPK pk = new GenericPK(entity, hm);
				delegator.removeByPrimaryKey(pk);
				roleChanged = true;

				/* unassign any contacts from this role */
				Vector contactFields = new Vector();
 			    contactFields.add(new EntityExpr("roleId", EntityOperator.EQUALS, deleteRoleId));

				List contacts = delegator.findByAnd("Contact", contactFields, null);
				Iterator ic = contacts.iterator();
				while(ic.hasNext())
				{
				  GenericValue contact = (GenericValue) ic.next();
				  contact.set("roleId", null);
				  delegator.store(contact);
				}
			}
		} catch (Exception e){ e.printStackTrace(); out.write(e.toString()); }
	}
  }

  if(action.equals("assignUsersToRole")){
    Enumeration enum = request.getParameterNames();
    while(enum.hasMoreElements()){
      String param = (String)enum.nextElement();

      if(param.startsWith("contactId-")){
        ModelEntity contactEntity = delegator.getModelEntity("Contact");
        HashMap hashMap = new HashMap();
        hashMap.put("contactId", request.getParameter(param));
        GenericPK genericPk = new GenericPK(contactEntity, hashMap);
        GenericValue contact = delegator.findByPrimaryKey(genericPk);
        contact.set("roleId", request.getParameter("roleId"));
        delegator.store(contact);
      }
    }
  }

  /* clear any Role based cache if the role has been modified */
  if ( roleChanged )
  {
	delegator.clearCacheLine("Role", null );
  }
%>

<!-- Display the Section and process events. -->
<%
/*
try {
	out.write(
		contactWebEventProcessor.processEvents(
			"NEW_USER",
			"UserQuickCreate",
			userInfo,
			request,
			response,
			delegator,
			contactEventProcessor,
			uiCache,
			false)
		);
} catch (Exception e) {
	e.printStackTrace();
}
*/
%>

<%@ include file="/includes/footer.jsp" %>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -