Skip to content

Instantly share code, notes, and snippets.

@mehulsbhandari
Forked from dmulvi/fullname.js
Created November 26, 2016 04:13
Show Gist options
  • Save mehulsbhandari/43943f0b426a23cc986c859ff7255b14 to your computer and use it in GitHub Desktop.
Save mehulsbhandari/43943f0b426a23cc986c859ff7255b14 to your computer and use it in GitHub Desktop.
SugarCRM 7 - add fields to Full Name headerpane display (middle name, nick name, preferred name etc)
/*
* I only wanted to apply this change to the Contacts modules so I put this file in:
* custom/modules/Contacts/clients/base/fields/fullname/
*/
({
extendsFrom: 'FullnameField',
formatMap: {
'f': 'first_name',
'l': 'last_name',
's': 'salutation',
'p': 'preferred_name_c',
'm': 'middle_name_c'
},
initialize: function(options) {
// override the name format for this module
app.user.setPreference('default_locale_name_format', 's f p m l');
this._super('initialize', [options]);
},
format: function() {
var fullname = this.model.attributes.salutation +' '+ this.model.attributes.first_name +' ';
fullname += (!_.isEmpty(this.model.attributes.preferred_name_c)) ? '"'+ this.model.attributes.preferred_name_c +'" ': ' ';
fullname += this.model.attributes.middle_name_c +' '+ this.model.attributes.last_name;
return fullname;
},
})
<?php
/*
* This is the custom record file for Contacts.
* custom/modules/Contacts/clients/base/views/record/record.php
*/
<?php
$viewdefs['Contacts'] =
array (
'base' =>
array (
'view' =>
array (
'record' =>
array (
'buttons' =>
array (
// ....
),
'panels' =>
array (
0 =>
array (
'name' => 'panel_header',
'header' => true,
'fields' =>
array (
0 =>
array (
'name' => 'picture',
'type' => 'avatar',
'size' => 'large',
'dismiss_label' => true,
),
// THIS IS THE IMPORTANT PART
1 =>
array (
'name' => 'full_name',
'label' => 'LBL_NAME',
'dismiss_label' => true,
'type' => 'fullname',
'fields' =>
array (
0 => 'salutation',
1 => 'first_name',
2 => 'preferred_name_c',
3 => 'middle_name_c',
4 => 'last_name',
),
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment