From 398438af6a87d82c05f5e63d040685f39a91305b Mon Sep 17 00:00:00 2001 From: "j.goderbauer" <j.goderbauer@adito.de> Date: Tue, 6 Oct 2020 10:01:26 +0200 Subject: [PATCH] =?UTF-8?q?[Projekt:=20Entwicklung=20-=20Pool][TicketNr.:?= =?UTF-8?q?=201066739][Firma=20-=20Filter=20nach=20Englisch=20-=20Firmen,?= =?UTF-8?q?=20die=20noch=20nicht=20in=20Kampagne=20sind,=20werden=20nicht?= =?UTF-8?q?=20=C3=BCbernommen]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../addparticipants/onActionProcess.js | 12 +++---- .../addparticipants/stateProcess.js | 9 ++++- .../valueProcess.js | 6 ++-- process/Campaign_lib/process.js | 33 ++++++++++--------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/entity/CampaignAddParticipants_entity/entityfields/addparticipants/onActionProcess.js b/entity/CampaignAddParticipants_entity/entityfields/addparticipants/onActionProcess.js index 6d4c28eb34..b2c37dfa07 100644 --- a/entity/CampaignAddParticipants_entity/entityfields/addparticipants/onActionProcess.js +++ b/entity/CampaignAddParticipants_entity/entityfields/addparticipants/onActionProcess.js @@ -38,12 +38,12 @@ if (!vars.exists("$param.currentCampaignId_param") || !vars.get("$param.currentC function _handleCondition(pCampaignId, pTargetTableName, pCondition) { var contactIdsToHandle = []; + var contextComingFrom = "Person"; - var useRightJoinToGetOrgs = "false"; if(pTargetTableName == "ORGANISATION") { - useRightJoinToGetOrgs = "true"; - pCondition += " and PERSON.PERSONID is NULL" + pCondition += " and PERSON.PERSONID is NULL"; + contextComingFrom = "Organisation"; } /* @@ -55,10 +55,10 @@ function _handleCondition(pCampaignId, pTargetTableName, pCondition) */ if(isUpdate == "true") { - contactIdsToHandle = CampaignUtils.GetContactIdsInCampaignByCondition(pCampaignId, pCondition, useRightJoinToGetOrgs) + contactIdsToHandle = CampaignUtils.GetContactIdsInCampaignByCondition(pCampaignId, pCondition); } else - contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByCondition(pCampaignId, pCondition, useRightJoinToGetOrgs); + contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByCondition(pCampaignId, pCondition, contextComingFrom); _handleRowIds(contactIdsToHandle, pCampaignId); } @@ -169,6 +169,4 @@ function _handleRowIds(pParticipantRowIds, pCampaignId) if(logArray.length > 0) db.inserts(logArray); - - neon.refreshAll(); } \ No newline at end of file diff --git a/entity/CampaignAddParticipants_entity/entityfields/addparticipants/stateProcess.js b/entity/CampaignAddParticipants_entity/entityfields/addparticipants/stateProcess.js index be5aec2ba0..8271cfcda5 100644 --- a/entity/CampaignAddParticipants_entity/entityfields/addparticipants/stateProcess.js +++ b/entity/CampaignAddParticipants_entity/entityfields/addparticipants/stateProcess.js @@ -5,4 +5,11 @@ import("system.vars"); if (vars.get("$sys.validationerrors")) result.string(neon.COMPONENTSTATE_DISABLED); else - result.string(neon.COMPONENTSTATE_EDITABLE); \ No newline at end of file +{ + var contactCount = JSON.parse(vars.get("$field.campaignparticipantContactIds")).length; + if (contactCount == 0) + result.string(neon.COMPONENTSTATE_DISABLED); + else + result.string(neon.COMPONENTSTATE_EDITABLE); +} + \ No newline at end of file diff --git a/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantcontactids/valueProcess.js b/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantcontactids/valueProcess.js index cb25278a4a..ff279849ce 100644 --- a/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantcontactids/valueProcess.js +++ b/entity/CampaignAddParticipants_entity/entityfields/campaignparticipantcontactids/valueProcess.js @@ -22,14 +22,14 @@ if(vars.get("$field.CAMPAIGN_ID")) else if(comingfrom == "Person") filteredContactIds = FilterViewActionUtils.contactIdsFilter(selection) - contactIds = CampaignUtils.GetContactIdsNotInCampaignByCondition(vars.get("$field.CAMPAIGN_ID"), selection); + contactIds = CampaignUtils.GetContactIdsNotInCampaignByCondition(vars.get("$field.CAMPAIGN_ID"), selection, comingfrom); } else if(isUpdate) { - if (vars.get("$param.campaignParticipantsCondition_param")) { - contactIds = CampaignUtils.GetContactIdsNotInCampaignByCondition(vars.get("$field.CAMPAIGN_ID"), JSON.parse(vars.get("$param.campaignParticipantsCondition_param")).condition, false); + var contactFilterCondition = JSON.parse(vars.get("$param.campaignParticipantsCondition_param")).condition; + contactIds = CampaignUtils.GetContactIdsNotInCampaignByCondition(vars.get("$field.CAMPAIGN_ID"), contactFilterCondition, comingfrom); } else { diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js index be0fe84ca4..7c893948d7 100644 --- a/process/Campaign_lib/process.js +++ b/process/Campaign_lib/process.js @@ -521,30 +521,34 @@ CampaignUtils.GetContactIdsNotInCampaignByRowIds = function(pCampaignId, pPartic * The id of the campaign.<br> * @param {String} pCondition (optional) <p> * An condition which is used to limit the search contact results.<br> - * @param {Boolean} pRightJoinContacts <p> - * Case if its true, a prefix will used<br> - * to do a right join.<br> + * @param {String} [pOrigin=Organisation] <br/> + * id from which context we are coming from, e.g. "Person" * @return {String[]} <p> * The contact ids they arent in the campaign.<br> */ -CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCondition, pRightJoinContacts) +CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCondition, pOrigin) { - let query = newSelect("CONTACT.CONTACTID").from("PERSON"); + var origin = pOrigin || "Organisation"; + //subselect for excluding entries that are already in the campaign var subselect = newSelect("CAMPAIGNPARTICIPANT.CONTACT_ID") - .from("CAMPAIGNPARTICIPANT") - .where("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", pCampaignId); - - if (pRightJoinContacts == "true") - query.rightJoin("CONTACT", "CONTACT.PERSON_ID = PERSON.PERSONID"); - else - query.join("CONTACT", "CONTACT.PERSON_ID = PERSON.PERSONID"); + .from("CAMPAIGNPARTICIPANT") + .where("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", pCampaignId); + var query = newSelect("CONTACT.CONTACTID") + .from("CONTACT"); + + if (origin == "Person") + query.leftJoin("PERSON", "CONTACT.PERSON_ID = PERSON.PERSONID"); + query.join("ORGANISATION", "ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID") .leftJoin("ADDRESS", "ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID") .where("CONTACT.CONTACTID", subselect , SqlBuilder.NOT_IN() ); + + if (origin == "Organisation") + query.and("CONTACT.PERSON_ID is null"); //pCondition is always a contact related condition string and not a campaignparticipant related condition if(pCondition != "") @@ -562,14 +566,11 @@ CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCon * @param {String} pCondition <p> * The condition which shall be used, to<br> * limit the search result.<br> - * @param {Boolean} [pRightJoinContacts=false] <p> - * Currently not used.<br> - * <p> * @return {String[]} <p> * The contact ids which are in the given<br> * campaign.<br> */ -CampaignUtils.GetContactIdsInCampaignByCondition = function(pCampaignId, pCondition, pRightJoinContacts) +CampaignUtils.GetContactIdsInCampaignByCondition = function(pCampaignId, pCondition) { let query = newSelect("CONTACT.CONTACTID").from("CONTACT"); -- GitLab