Extended profile - make IMs display and save

This commit is contained in:
Zach Copley 2011-03-14 22:38:34 -07:00
parent 6d34818b5d
commit cd82ff2dcf
4 changed files with 121 additions and 5 deletions

View File

@ -129,6 +129,32 @@ class ExtendedProfile
return $pArrays;
}
function getIms()
{
$ims = (isset($this->fields['im'])) ? $this->fields['im'] : null;
$iArrays = array();
if (empty($ims)) {
$iArrays[] = array(
'label' => _m('IM'),
'type' => 'im'
);
} else {
for ($i = 0; $i < sizeof($ims); $i++) {
$ia = array(
'label' => _m('IM'),
'type' => 'im',
'index' => intval($ims[$i]->value_index),
'rel' => $ims[$i]->rel,
'value' => $ims[$i]->field_value,
);
$iArrays[] = $ia;
}
}
return $iArrays;
}
function getExperiences()
{
$companies = (isset($this->fields['company'])) ? $this->fields['company'] : null;
@ -248,11 +274,7 @@ class ExtendedProfile
'label' => _m('Contact'),
'fields' => array(
'phone' => $this->getPhones(),
'im' => array(
'label' => _m('IM'),
'type' => 'im',
'multi' => true,
),
'im' => $this->getIms(),
'website' => array(
'label' => _m('Websites'),
'type' => 'website',

View File

@ -106,6 +106,7 @@ class ExtendedProfileWidget extends Form
switch($fieldName) {
case 'phone':
case 'im':
case 'experience':
case 'education':
$this->showMultiple($fieldName, $field);
@ -156,6 +157,53 @@ class ExtendedProfileWidget extends Form
$this->out->elementEnd('div');
}
protected function showIm($name, $field)
{
$this->out->elementStart('div', array('class' => 'im-display'));
$this->out->text($field['value']);
if (!empty($field['rel'])) {
$this->out->text(' (' . $field['rel'] . ')');
}
$this->out->elementEnd('div');
}
protected function showEditableIm($name, $field)
{
$index = isset($field['index']) ? $field['index'] : 0;
$id = "extprofile-$name-$index";
$rel = $id . '-rel';
$this->out->elementStart(
'div', array(
'id' => $id . '-edit',
'class' => 'im-edit'
)
);
$this->out->input(
$id,
null,
isset($field['value']) ? $field['value'] : null
);
$this->out->dropdown(
$id . '-rel',
'Type',
array(
'jabber' => 'Jabber',
'gtalk' => 'GTalk',
'aim' => 'AIM',
'yahoo' => 'Yahoo! Messenger',
'msn' => 'MSN',
'skype' => 'Skype',
'other' => 'Other'
),
null,
false,
isset($field['rel']) ? $field['rel'] : null
);
$this->showMultiControls();
$this->out->elementEnd('div');
}
protected function showEditablePhone($name, $field)
{
$index = isset($field['index']) ? $field['index'] : 0;
@ -373,6 +421,9 @@ class ExtendedProfileWidget extends Form
case 'phone':
$this->showPhone($name, $field);
break;
case 'im':
$this->showIm($name, $field);
break;
case 'experience':
$this->showExperience($name, $field);
break;
@ -413,6 +464,9 @@ class ExtendedProfileWidget extends Form
case 'phone':
$this->showEditablePhone($name, $field);
break;
case 'im':
$this->showEditableIm($name, $field);
break;
case 'experience':
$this->showEditableExperience($name, $field);
break;

View File

@ -84,6 +84,7 @@ var init = function() {
reorder('phone-edit');
reorder('experience-edit');
reorder('education-edit');
reorder('im-edit');
}
$(document).ready(

View File

@ -109,6 +109,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
}
$this->savePhoneNumbers($user);
$this->saveIms($user);
$this->saveExperiences($user);
$this->saveEducations($user);
@ -159,6 +160,44 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
return $phoneArray;
}
function findIms() {
// Form vals look like this:
// 'extprofile-im-0' => 'jed',
// 'extprofile-im-0-rel' => 'yahoo',
$ims = $this->sliceParams('im', 2);
$imArray = array();
foreach ($ims as $im) {
list($id, $rel) = array_values($im);
$imArray[] = array(
'value' => $id,
'rel' => $rel
);
}
return $imArray;
}
function saveIms($user) {
$ims = $this->findIms();
$this->removeAll($user, 'im');
$i = 0;
foreach($ims as $im) {
if (!empty($im['value'])) {
++$i;
$this->saveField(
$user,
'im',
$im['value'],
$im['rel'],
$i
);
}
}
}
function findExperiences() {
// Form vals look like this: