-
Notifications
You must be signed in to change notification settings - Fork 3
/
ShowProfile.js
143 lines (129 loc) · 6.37 KB
/
ShowProfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Ext.ns('Talho');
Talho.ShowProfile = Ext.extend(Ext.util.Observable, {
constructor: function(config){
Ext.apply(this, config);
Talho.ShowProfile.superclass.constructor.call(this, config);
Ext.Ajax.request({
url: '/users/' + this.user_id + '/profile.json',
scope: this,
success: function(response, options) {
var record = Ext.decode(response.responseText);
this.userdata = record.userdata;
this.renderProfile();
}
});
this.inner_panel = new Ext.Panel({
layout: 'column',
cls: 'inner-panel',
layoutConfig: {defaultMargins:'5'}
});
this.primary_panel = new Ext.Panel({
layout: 'column',
autoScroll: true,
padding: 5,
itemId: config.id,
cls: 'primary-panel',
closable: true,
title: this.title,
items: [{xtype: 'container', html: ' ', columnWidth:0.5}, this.inner_panel, {xtype: 'container', html: ' ', columnWidth:0.5}]
});
this.getPanel = function(){
return this.primary_panel;
};
},
buildLeftColumn: function(){
var singleDataBox = Ext.extend(Ext.BoxComponent, {
tpl: '<tpl if="dataPoint"><fieldset style="margin-bottom: 20px; border: none; border-top: 1px solid #EEEEEE;"><legend style="color: #999999;">{label}</legend>' +
'<span style="font-size: 130%;"> {dataPoint} </span></fieldset></tpl>'
});
var assembledItems = [ {xtype: 'box', data: this.userdata, tpl: '<span style="font-weight: bold; font-size: 300%; line-height: 100%;"> {display_name} </span>'} ];
if (this.userdata.can_edit){
assembledItems.push([
new Ext.Container({
layout: 'hbox',
items: [
new Ext.Container({
flex: 2,
items:[{xtype: "box", data: this.userdata, tpl: '<tpl if="(first_name +\' \' + last_name) != display_name"><span style="font-weight: bold; margin-bottom: 10px; padding-left: 5px;> ({first_name} {last_name}) </span></tpl>'}]
}),
new Ext.Container({
flex: 1,
items: [
new Ext.Container({
layout: 'hbox',
layoutConfig: { pack: 'end' },
items: [ new Ext.Button({ scope: this, handler: this.openEditUserTab, text: "Edit This Account" }) ]
})
]
})
]
})
]);
} else {
assembledItems.push({xtype: "box", data: this.userdata, tpl: '<tpl if="(first_name +\' \' + last_name) != display_name"><span style="font-weight: bold; margin-bottom: 10px; padding-left: 5px;> ({first_name} {last_name}) </span></tpl>'});
}
if (this.userdata.privateProfile){
assembledItems.push({ xtype: 'box', tpl: '<span style="font-size: 150%;">This profile information is private.</span>' });
} else {
assembledItems.push([
{xtype: 'box', data: this.userdata, tpl: '<fieldset style="margin-bottom: 20px; margin-top: 20px; border:none; border-top: 1px solid #EEEEEE;"><legend style="color: #999999;">Roles</legend><tpl for="role_memberships"><p style="font-size: 130%;">{role} in {jurisdiction}</p></tpl></fieldset>'},
new singleDataBox({data:{ label: "Employer", dataPoint: this.userdata.employer} }),
new singleDataBox({data:{ label: "Occupation", dataPoint: this.userdata.occupation} }),
new singleDataBox({data:{ label: "Job Description", dataPoint: this.userdata.job_description} }),
new singleDataBox({data:{ label: "Bio", dataPoint: this.userdata.bio} }),
new singleDataBox({data:{ label: "Credentials", dataPoint: this.userdata.credentials} }),
new singleDataBox({data:{ label: "Experience", dataPoint: this.userdata.experience} })
]);
}
return assembledItems;
},
buildRightColumn: function(){
var deviceMap = {'email': 'E-Mail', 'office_phone': 'Office Phone', 'home_phone': 'Home Phone', 'mobile_phone': 'Mobile Phone', 'fax': 'Fax' };
for (var i=0; i < this.userdata.contacts.length; i++ ) { // create nicer labels for display
this.userdata.contacts[i]['label'] = deviceMap[this.userdata.contacts[i]['type']];
}
return [{xtype: 'box', data: this.userdata, tpl: '<img src="{photo}" />', height: 200},
{xtype: 'box', data: this.userdata, tpl: '<fieldset style="margin-bottom: 20px; margin-top: 20px; border:none; border-top: 1px solid #EEEEEE;">'+
'<legend style="color: #999999;">Contact Information</legend><tpl for="contacts">'+
'<tpl if="address"><div style="margin-bottom: 10px;"><span style="color: #555555">{label}:</span>'+
'<p style="font-size: 130%; ">{address}</p></div></tpl></tpl></fieldset>'},
{xtype: 'box', data: this.userdata, tpl: '<tpl if="!Ext.isEmpty(organizations)"><fieldset style="margin-bottom: 20px; border: none; border-top: 1px solid #EEEEEE;">' +
'<legend style="color: #999999;">Organizations</legend><tpl for="organizations"><p style="font-size: 130%;">{name}</p></tpl></fieldset></tpl>'}];
},
renderProfile: function(){
var leftColumn = new Ext.Panel({
width: 500,
padding: 5,
border: false,
items: this.buildLeftColumn()
});
var rightColumn = new Ext.Panel({
width: 250,
padding: 5,
border: false,
items: this.buildRightColumn()
});
this.inner_panel.add(
leftColumn,
rightColumn
);
this.inner_panel.doLayout();
this.primary_panel.doLayout();
},
openEditUserTab: function(){
Application.fireEvent('opentab', {
title: 'Edit Account: ' + this.userdata.first_name + ' ' + this.userdata.last_name,
url: '/users/' + this.userdata.user_id + '/profile',
user_id: this.userdata.user_id,
id: 'edit_user_for_' + this.userdata.user_id, initializer: 'Talho.EditProfile'
});
}
});
/**
* Initializer for the ShowProfile object. Returns a panel
*/
Talho.ShowProfile.initialize = function(config){
var show_profile_panel = new Talho.ShowProfile(config);
return show_profile_panel.getPanel();
};
Talho.ScriptManager.reg('Talho.ShowProfile', Talho.ShowProfile, Talho.ShowProfile.initialize);