Editing profile fields and some bugs

This commit is contained in:
Max Shinn 2011-01-01 16:06:14 -06:00
parent 6a44fba936
commit ac675c946d
2 changed files with 70 additions and 25 deletions

View File

@ -54,12 +54,28 @@ class ProfilefieldsAdminPanelAction extends AdminPanelAction
function saveSettings() function saveSettings()
{ {
$title = $this->trimmed('title'); $field = GNUsocialProfileExtensionField::staticGet('id', $this->trimmed('id'));
$description = $this->trimmed('description'); if (!$field)
$type = $this->trimmed('type'); $field = new GNUsocialProfileExtensionField();
$systemname = $this->trimmed('systemname'); $field->title = $this->trimmed('title');
$field->description = $this->trimmed('description');
$field = GNUsocialProfileExtensionField::newField($title, $description, $type, $systemname); $field->type = $this->trimmed('type');
$field->systemname = $this->trimmed('systemname');
if (!gnusocial_field_systemname_validate($field->systemname)) {
$this->clientError(_('Internal system name must be unique and consist of only alphanumeric characters!'));
return false;
}
if ($field->id) {
if ($field->validate())
$field->update();
else {
$this->clientError(_('There was an error with the field data.'));
return false;
}
}
else {
$field->insert();
}
return; return;
} }
@ -86,41 +102,63 @@ class ProfilefieldsAdminForm extends AdminForm
function formData() function formData()
{ {
//Listing all fields $title = null;
$this->out->elementStart('fieldset'); $description = null;
$this->out->element('legend', null, _('Existing Custom Profile Fields')); $type = null;
$this->out->elementStart('ul', 'form_data'); $systemname = null;
$fields = GNUsocialProfileExtensionField::allFields(); $id = null;
foreach ($fields as $field) { $fieldsettitle = _("New Profile Field");
$this->li(); //Edit a field
$this->out->element('div', array(), $field->title . ' (' . if ($this->out->trimmed('edit')) {
$field->type . '): ' . $field->description); $field = GNUsocialProfileExtensionField::staticGet('id', $this->out->trimmed('edit'));
$this->unli(); $title = $field->title;
$description = $field->description;
$type = $field->type;
$systemname = $field->systemname;
$this->out->hidden('id', $field->id, 'id');
$fieldsettitle = _("Edit Profile Field");
}
//Don't show the list of all fields when editing one
else {
$this->out->elementStart('fieldset');
$this->out->element('legend', null, _('Existing Custom Profile Fields'));
$this->out->elementStart('ul', 'form_data');
$fields = GNUsocialProfileExtensionField::allFields();
foreach ($fields as $field) {
$this->li();
$content =
$this->out->elementStart('div');
$this->out->element('a', array('href' => '/admin/profilefields?edit=' . $field->id),
$field->title);
$this->out->text(' (' . $field->type . '): ' . $field->description);
$this->out->elementEnd('div');
$this->unli();
}
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
} }
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
//New fields //New fields
$this->out->elementStart('fieldset'); $this->out->elementStart('fieldset');
$this->out->element('legend', null, _('New Profile Field')); $this->out->element('legend', null, $fieldsettitle);
$this->out->elementStart('ul', 'form_data'); $this->out->elementStart('ul', 'form_data');
$this->li(); $this->li();
$this->input('title', _('Title'), $this->out->input('title', _('Title'), $title,
_('The title of the field')); _('The title of the field'));
$this->unli(); $this->unli();
$this->li(); $this->li();
$this->input('systemname', _('Internal name'), $this->out->input('systemname', _('Internal name'), $systemname,
_('The name used internally for this field. Also the key used in OStatus user info. (optional)')); _('The alphanumeric name used internally for this field. Also the key used in OStatus user info. (optional)'));
$this->unli(); $this->unli();
$this->li(); $this->li();
$this->input('description', _('Description'), $this->out->input('description', _('Description'), $description,
_('An optional more detailed description of the field')); _('An optional more detailed description of the field'));
$this->unli(); $this->unli();
$this->li(); $this->li();
$this->out->dropdown('type', _('Type'), array('text' => _("Text"), $this->out->dropdown('type', _('Type'), array('text' => _("Text"),
'str' => _("String")), 'str' => _("String")),
_('The type of the datafield')); _('The type of the datafield'), false, $type);
$this->unli(); $this->unli();
$this->out->elementEnd('ul'); $this->out->elementEnd('ul');
$this->out->elementEnd('fieldset'); $this->out->elementEnd('fieldset');

View File

@ -37,4 +37,11 @@ function gnusocial_profile_merge(&$profile)
} }
} }
function gnusocial_field_systemname_validate($systemname)
{
$fields = GNUsocialProfileExtensionField::allFields();
foreach ($fields as $field)
if ($field->systemname == $systemname)
return false;
return ctype_alphanum($systemname);
}