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; 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() function getExperiences()
{ {
$companies = (isset($this->fields['company'])) ? $this->fields['company'] : null; $companies = (isset($this->fields['company'])) ? $this->fields['company'] : null;
@ -248,11 +274,7 @@ class ExtendedProfile
'label' => _m('Contact'), 'label' => _m('Contact'),
'fields' => array( 'fields' => array(
'phone' => $this->getPhones(), 'phone' => $this->getPhones(),
'im' => array( 'im' => $this->getIms(),
'label' => _m('IM'),
'type' => 'im',
'multi' => true,
),
'website' => array( 'website' => array(
'label' => _m('Websites'), 'label' => _m('Websites'),
'type' => 'website', 'type' => 'website',

View File

@ -106,6 +106,7 @@ class ExtendedProfileWidget extends Form
switch($fieldName) { switch($fieldName) {
case 'phone': case 'phone':
case 'im':
case 'experience': case 'experience':
case 'education': case 'education':
$this->showMultiple($fieldName, $field); $this->showMultiple($fieldName, $field);
@ -156,6 +157,53 @@ class ExtendedProfileWidget extends Form
$this->out->elementEnd('div'); $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) protected function showEditablePhone($name, $field)
{ {
$index = isset($field['index']) ? $field['index'] : 0; $index = isset($field['index']) ? $field['index'] : 0;
@ -373,6 +421,9 @@ class ExtendedProfileWidget extends Form
case 'phone': case 'phone':
$this->showPhone($name, $field); $this->showPhone($name, $field);
break; break;
case 'im':
$this->showIm($name, $field);
break;
case 'experience': case 'experience':
$this->showExperience($name, $field); $this->showExperience($name, $field);
break; break;
@ -413,6 +464,9 @@ class ExtendedProfileWidget extends Form
case 'phone': case 'phone':
$this->showEditablePhone($name, $field); $this->showEditablePhone($name, $field);
break; break;
case 'im':
$this->showEditableIm($name, $field);
break;
case 'experience': case 'experience':
$this->showEditableExperience($name, $field); $this->showEditableExperience($name, $field);
break; break;

View File

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

View File

@ -109,6 +109,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
} }
$this->savePhoneNumbers($user); $this->savePhoneNumbers($user);
$this->saveIms($user);
$this->saveExperiences($user); $this->saveExperiences($user);
$this->saveEducations($user); $this->saveEducations($user);
@ -159,6 +160,44 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
return $phoneArray; 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() { function findExperiences() {
// Form vals look like this: // Form vals look like this: