📄 viewactivity.bsh
字号:
/* * Copyright (C) 2006 Open Source Strategies, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *//* Copyright (c) 2005-2006 Open Source Strategies, Inc. */import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.entity.util.EntityUtil;import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;import com.opensourcestrategies.crmsfa.activities.UtilActivity;import com.opensourcestrategies.crmsfa.party.PartyHelper;import com.opensourcestrategies.crmsfa.util.UtilCommon;// find the work effort and the association IDs, used by both viewActivity and updateTaskForm/updateEventFormworkEffortId = parameters.get("workEffortId");if (workEffortId == null) return;workEffort = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId));if (workEffort == null) return;// make sure it is a TASK or EVENTworkEffortTypeId = workEffort.getString("workEffortTypeId");if (!(workEffortTypeId.equals("TASK") || workEffortTypeId.equals("EVENT"))) { return;}// make a new map with all the workEffort fields (because we might add more later)context.put("workEffort", workEffort.getAllFields());// some helper parameters for the menusactivityValueParams = "workEffortId=" + workEffortId;context.put("activityValueParams", activityValueParams);if (workEffort.getString("workEffortTypeId").equals("EVENT")) { context.put("cancelActivityParams", "currentStatusId=EVENT_CANCELLED");} else if (workEffort.getString("workEffortTypeId").equals("TASK")) { context.put("cancelActivityParams", "currentStatusId=TASK_CANCELLED");}// put the association IDs in the workEffort context map (for forms) and in the context (for security, etc.)List parties = UtilActivity.getActivityParties(delegator, workEffort.getString("workEffortId"));if (parties.size() > 0) { internalPartyId = parties.get(0).getString("partyId"); context.get("workEffort").put("internalPartyId", internalPartyId); // also get the role and set the view page target for it viewPage = null; roleTypeId = PartyHelper.getFirstValidInternalPartyRoleTypeId(internalPartyId, delegator); if (roleTypeId.equals("ACCOUNT")) viewPage = "viewAccount"; else if (roleTypeId.equals("CONTACT")) viewPage = "viewContact"; else if (roleTypeId.equals("PROSPECT")) viewPage = "viewLead"; context.put("internalPartyRoleTypeId", roleTypeId); context.put("viewPage", viewPage); context.put("internalPartyId", internalPartyId);}opportunities = workEffort.getRelated("SalesOpportunityWorkEffort");if (opportunities.size() > 0) { id = opportunities.get(0).getString("salesOpportunityId"); context.get("workEffort").put("salesOpportunityId", id); context.put("salesOpportunityId", id);}cases = workEffort.getRelated("CustRequestWorkEffort");if (cases.size() > 0) { id = cases.get(0).getString("custRequestId"); context.get("workEffort").put("custRequestId", id); context.put("custRequestId", id);}// check for update permission hasUpdatePermission = false;if (CrmsfaSecurity.hasActivityPermission(security, "_UPDATE", userLogin, workEffortId)) { hasUpdatePermission = true;}context.put("hasUpdatePermission", hasUpdatePermission);// if the current login is CAL_OWNER of this work effort, then allow updating partiesif (hasUpdatePermission) { userAssignments = EntityUtil.filterByDate(workEffort.getRelatedByAnd("WorkEffortPartyAssignment", UtilMisc.toMap("partyId", userLogin.getString("partyId"), "roleTypeId", "CAL_OWNER"))); if (userAssignments.size() > 0) { context.put("hasUpdatePartiesPermission", true); }}// stausstatusId = workEffort.getString("currentStatusId");// notify screen widget if the activity is scheduledcontext.put("isScheduled", false);if (statusId.equals("TASK_SCHEDULED") || statusId.equals("EVENT_SCHEDULED")) { context.put("isScheduled", true);}// notify screen widget if the activity is startedcontext.put("isStarted", false);if (statusId.equals("TASK_STARTED") || statusId.equals("EVENT_STARTED")) { context.put("isStarted", true);}// Do things when the work effort is a Task// isCrmEmail tells the system whether communication events associated with task are to be viewed as email or generic communication events// isPending tells the system whether that email should be editableif (workEffort.get("workEffortTypeId").equals("TASK")) { context.put("isCrmEmail", false); // get the first related comm event (we're supposed to have only one but the data model is too flexible) candidates = workEffort.getRelated("CommunicationEventWorkEff"); if (candidates.size() > 0) { communicationEvent = candidates.get(0).getRelatedOne("CommunicationEvent"); context.put("communicationEvent", communicationEvent); // check for emails if (communicationEvent.getString("communicationEventTypeId").equals("EMAIL_COMMUNICATION")) { // ignore logged emails or those without contact mech info context.put("isCrmEmail", true); // If we have a pending email, tell the screen to include writeEmail.ftl context.put("pendingEmail", false); if (communicationEvent.getString("statusId").equals("COM_PENDING")) { context.put("pendingEmail", true); context.put("isStarted", false); // also disable the "finish" form because the finish time is taken care of by the service } } // auto-received emails are to be viewed as email but are never to be editable else if(communicationEvent.getString("communicationEventTypeId").equals("AUTO_EMAIL_COMM")) { // ignore logged emails or those without contact mech info context.put("isCrmEmail", true); context.put("pendingEmail", false); } }}// put in the availability status of the userLogininput = UtilMisc.toMap("workEffortId", workEffortId, "partyId", userLogin.getString("partyId"));assocs = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortPartyAssignment", input));if ((assocs != null) && (assocs.size() > 0)) { context.get("workEffort").put("availabilityStatusId", assocs.get(0).getString("availabilityStatusId"));}// put the duration if the work effort has start and end timesstart = workEffort.getTimestamp("estimatedStartDate");end = workEffort.getTimestamp("estimatedCompletionDate");if (start != null && end != null) { context.get("workEffort").put("duration", UtilCommon.getDuration(start, end));}// default times for the start/finish mini form in viewActivity (note these won't override the ones in workEffort)context.put("actualStartDate", UtilDateTime.nowTimestamp());context.put("actualCompletionDate", UtilDateTime.nowTimestamp());// list of associated partiesparties = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortAndPartyAssign", UtilMisc.toMap("workEffortId", workEffortId)));context.put("associatedParties", parties);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -