Load Facebook Profile Photo in Employee

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