Skip to content
Snippets Groups Projects
Commit d3ff2a2b authored by Andre Loreth's avatar Andre Loreth
Browse files

#1035771 Standard address/communication

parent 5f3daf0d
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import("system.vars");
import("Person_lib");
import("Communication_lib");
import("Entity_lib");
import("StandardObject_lib");
// TODO: this is a workaround for missing possibility to react on changes of fields not connected to record Contqainer #1030023
FieldChanges.assimilateChangeAndDispose("$field.IMAGE", function(state, value){
......@@ -20,3 +21,6 @@ FieldChanges.assimilateChangeAndDispose("$field.STANDARD_EMAIL_COMMUNICATION", f
FieldChanges.assimilateChangeAndDispose("$field.STANDARD_PHONE_COMMUNICATION", function(state, value){
CommUtil.setStandardPhone(uid, value);
});
new StandardObject("Address", vars.get("$field.ADDRESS_ID"), "Person", vars.get("$field.CONTACTID"))
.onPersonUpdate(vars.get("$field.ORGANISATION_ID"));
\ No newline at end of file
......@@ -2,6 +2,7 @@ import("system.logging");
import("system.db");
import("Keyword_lib");
import("KeywordRegistry_basic");
import("Contact_lib");
function StandardObject (pObjectType, pObjectID, pScopeType, pScopeID) {
if (!this._isValidType("object", pObjectType))
......@@ -114,9 +115,9 @@ StandardObject.prototype.onObjectInsert = function () {
this._assertScopeIdNotNull();
if (this.objectType === StandardObject.CONST_OBJECT_ADDRESS()) {
this._onAddressInsert()
this._onAddressInsert();
} else if (this.objectType === StandardObject.CONST_OBJECT_COMMUNICATION) {
this._onCommunicationInsert()
this._onCommunicationInsert();
}
}
......@@ -130,7 +131,21 @@ StandardObject.prototype._onAddressInsert = function () {
this._assertObjectType(StandardObject.CONST_OBJECT_ADDRESS());
if (!this._hasContactStandardAddress(this.scopeID)) {
this._setContactStandardAddress(this.objectID, this.scopeID)
this._setContactStandardAddress(this.objectID, this.scopeID);
}
}
StandardObject.prototype.onPersonUpdate = function (pOrganisationID) {
// Assert
this._assertScopeType(StandardObject.CONST_SCOPE_PERSON());
var isOrganisationAddress = this._isOrganisationAddress(this.scopeID);
if (isOrganisationAddress) {
// Update to new address of org
var addressID = this._getCompanyStandardAddress(pOrganisationID);
this._setContactStandardAddress(addressID, this.scopeID);
}
}
......@@ -199,7 +214,7 @@ StandardObject.prototype._setContactStandardAddress = function (pAddressID, pCon
["ADDRESS_ID"],
db.getColumnTypes("CONTACT", ["ADDRESS_ID"]),
[pAddressID],
"CONTACTID = '" + pContactID + "'")
"CONTACTID = '" + pContactID + "'");
}
/**
......@@ -231,7 +246,7 @@ StandardObject.prototype._hasStandardCommunicationByMedium = function (pContactI
var dbResult = db.array(db.COLUMN, "select CHAR_VALUE from COMMUNICATION"
+ " left join AB_KEYWORD_ENTRY on KEYID = MEDIUM_ID"
+ " left join AB_KEYWORD_ATTRIBUTERELATION on AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRYID and AB_KEYWORD_ATTRIBUTE_ID = '7250ff28-1d48-41cc-bb36-8c33ace341bb'"
+ " where STANDARD = 1 and CONTACT_ID = '" + pContactID + "'")
+ " where STANDARD = 1 and CONTACT_ID = '" + pContactID + "'");
return dbResult.indexOf(pMediumCategory) !== -1;
}
......@@ -265,7 +280,7 @@ StandardObject.prototype._setStandardCommunication = function (pCommunicationID,
["STANDARD"],
db.getColumnTypes("COMMUNICATION", ["STANDARD"]),
[pValue],
"COMMUNICATIONID = '" + pCommunicationID + "'")
"COMMUNICATIONID = '" + pCommunicationID + "'");
}
/**
......@@ -275,5 +290,16 @@ StandardObject.prototype._setStandardCommunication = function (pCommunicationID,
* @return The contact ID.
*/
StandardObject.prototype._getContactIdByCommunication = function (pCommunicationID) {
return db.cell("select CONTACT_ID from COMMUNICATION where COMMUNICATIONID = '" + pCommunicationID + "'")
return db.cell("select CONTACT_ID from COMMUNICATION where COMMUNICATIONID = '" + pCommunicationID + "'");
}
StandardObject.prototype._isOrganisationAddress = function (pAddressID) {
var contactID = db.cell("select CONTACTID from CONTACT where ADDRESS_ID = '" + pAddressID + "'");
if (contactID === "")
return false;
var contactType = ContactUtils.getContactTypeByContactId(contactID);
return contactType === 1;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment