Hi everyone!

I hope you help me!

I need that when I set up the Facebook profile in the employee's "CommunicationOptions", the profile photo will be uploaded to the Employee's Photo, which would implicitly be uploaded to the Contact's Photo. This functionallity only works when done from Contact. How could I replicate it in Employee? If the Employee's photo actually refers to the Contact's photo and in Contact works fine, it should appear, since the fields configured in Employee's "Communication Options" actually refer to the associated Contact.

I hope it was understood.

King regards,

Ezequiel

Like 0

Like

2 comments

Please use the following code on a replacing client module for an EmployeePage module

define("EmployeePage", [], function() {
	return {
		entitySchemaName: "Employee",
		messages: {
 
			"SearchResultBySocialNetworks": {
				mode: Terrasoft.MessageMode.BROADCAST,
				direction: Terrasoft.MessageDirectionType.SUBSCRIBE
			}
		},
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		methods: {
			subscribeSandboxEvents: function() {
				this.callParent(arguments);
				this.sandbox.subscribe("SearchResultBySocialNetworks", this.onSearchResultBySocialNetworks, this);
			},
			onSearchResultBySocialNetworks: function(config) {
				var collection = config.selectedItems;
				if (collection.isEmpty()) {
					return;
				}
				var socialContact = collection.getByIndex(0);
				this.setPhotoFromSocialNetworks(socialContact);
			},
			setPhotoFromSocialNetworks: function(socialContact) {
				var contactPhoto = this.get(this.primaryImageColumnName);
				if (!this.Ext.isEmpty(contactPhoto) || this.Ext.isEmpty(socialContact)) {
					return;
				}
				var isDefaultPhoto = socialContact.get("IsDefaultPhoto");
				var photoUrl = socialContact.get("Photo");
				if (isDefaultPhoto === true || this.Ext.isEmpty(photoUrl)) {
					return;
				}
				this.Terrasoft.ConfigurationFileApi.getImageFile(photoUrl, this.onPhotoChange, this);
			},
			onPhotoChange: function(photo) {
				if (!photo) {
					this.set(this.primaryImageColumnName, null);
					return;
				}
				this.Terrasoft.ImageApi.upload({
					file: photo,
					onComplete: this.onPhotoUploaded,
					onError: this.Terrasoft.emptyFn,
					scope: this
				});
			},
			onPhotoUploaded: function(imageId) {
				var imageData = {
					value: imageId,
					displayValue: "Photo"
				};
				this.set(this.primaryImageColumnName, imageData);
				var contactId = this.get("Contact") ? this.get("Contact").value : null;
				this.setContactPhoto(contactId, imageData);
			},
			setContactPhoto: function(contactId, imageData) {
				if (contactId) {
					var update = Ext.create("Terrasoft.UpdateQuery", {
						rootSchemaName: "Contact"
					});
					update.filters.addItem(update.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Id",
						contactId));
					update.setParameterValue("Photo", imageData.value, Terrasoft.DataValueType.IMAGELOOKUP);
					update.execute();
				}
			}
		},
		rules: {},
		businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
		diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/
	};
});

 

Hi Eugene! I appreciated your help! It was very useful form me. Regards!

Show all comments

Hi everyone!

How are you?

I hope you can help me!

I need that in EmployeePage the Photo are not ReadOnly and it has funcionallity as in Contact. I saw that in attributes Section of EmployeePage(Base), there a attribute called ContactPhoto that refers to Contact.Photo and in the Init Method, this attribute is assigned to "primaryImageColumnName".I don't understand why "primaryImageColumnName" not is a attribute of Employee. What is its source?

To replicate this functionally, I did the following on EmployeePage (Custom):

  • I changed the attribute "ReadOnly" to False in array values of photoProperty in Diff section
  • I add "OnPhotoChange" attribute in array values of photoProperty in Diff section
  • I add OnPhotoChange and onPhotoUploaded to methods section 
//diff
{
	"operation": "merge",
	"parentName": "PhotoContainer",
	"propertyName": "items",
	"name": "Photo",
	"values": {
		"getSrcMethod": "getSchemaImageUrl",
		"readonly": false,
		"onPhotoChange": "onPhotoChange",
		"defaultImage": Terrasoft.ImageUrlBuilder.getUrl(resources.localizableImages.DefaultPhoto),
		"generator": "ImageCustomGeneratorV2.generateCustomImageControl"
	}
},
 
...
//methods
onPhotoChange: function(photo) {
				if (!photo) {
 
					this.set(this.primaryImageColumnName, null);
					return;
				}
				this.Terrasoft.ImageApi.upload({
					file: photo,
					onComplete: this.onPhotoUploaded,
					onError: this.Terrasoft.emptyFn,
					scope: this
				});
			},
 
onPhotoUploaded: function(imageId) {
				debugger;
				var imageData = {
					value: imageId,
					displayValue: "Photo"
				};
				this.set(this.primaryImageColumnName, imageData);
			}

 

With this configuration, I can change the photo, but when I refresh or exit and return to the Page,the photo is reset with default image, I think it is not being recorded correctly in the contact photo column. What am I doing wrong? What is missing?

Thanks in advance.

King Regards,

 

Ezequiel

Like 0

Like

1 comments
Show all comments

Hi everyone!

How are you? I hope you can help me.

I need the default image of the employee to change dynamically depending if gender is Female O Male when the Photo not is set. I saw that the attribute Photo on Employee refers to Contact.Photo in attributes section of EmployeePage(Base)

How can I do this?

 

 

 

 

 

 

 

 

 

King Regards,

Ezequiel

 

Like 0

Like

2 comments

Dear Ezequiel,

 

You can achieve such task by applying some code modifications to the ContactPageV2. Please create or open ContactPageV2. Go to localizable strings (menu on the right) and add to Images your icon for female contacts.

Afterwards, please use this example to apply code modifications:

define("ContactPageV2", ["ContactPageV2Resources"],
	function(resources) {
		return {
			entitySchemaName: "Contact",
			attributes: {
				"DefaultImage": {
					dataValueType: Terrasoft.DataValueType.TEXT,
					type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN
				}
			},
			methods: {
				onEntityInitialized: function() {
					this.callParent(arguments);
					this.setPhoto();
				},
				setPhoto: function() {
					var primaryImageColumnValue = this.get(this.primaryImageColumnName);
					if (!primaryImageColumnValue) {
						var gender = this.get("Gender").value;
						if (gender === "fc2483f8-65b6-df11-831a-001d60e938c6") {
							document.getElementsByClassName("ts-image-edit-full-size-element ts-image-style-rectangular")[0]
								.setAttribute("src",
									Terrasoft.ImageUrlBuilder.getUrl(resources.localizableImages.DefaultPhotoFemale));
						} else {
							document.getElementsByClassName("ts-image-edit-full-size-element ts-image-style-rectangular")[0]
								.setAttribute("src",
									Terrasoft.ImageUrlBuilder.getUrl(resources.localizableImages.DefaultPhoto));
						}
					}
				}
			},
			diff: /**SCHEMA_DIFF*/[
			]/**SCHEMA_DIFF*/
		};
	}
);

Here you can see, that based on the gender of the contact, the icon is set. Also, you can improve the code by adding onChange statement, which can change the icon if gender changes in runtime. 

Regards,

Anastasia

Anastasia Botezat,

one question

How can set image when onentityinitialized event is not triggered?

Show all comments