Active
Project:
Buddylist
Version:
master
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
30 Mar 2007 at 05:36 UTC
Updated:
3 Apr 2007 at 10:00 UTC
I've made a few improvements to the edit groups page and I would like it to be integrated to your code. These fall into two categories: how this page looks like and possibility to edit buddy groups even if you don't have any buddies yet (use case: pre-populated default buddy groups such as Friends, Scool Mates, ...). I hope you will forgive my negligence to not provide these as patches. I will provide the changed functions. I hope these changes will be useful. Please note that I did my best but I am not a Drupal UI expert, so if you think there is something you can do better don't hesitate to change it.
function buddylist_form_edit_groups_add() {
// Add group form
$form['add_group']['group_name'] = array(
'#type' => 'textfield',
'#title' => t('Group name'),
'#description' => t('Groups are a way to keep your @buddies organized. Groups can be named whatever you like.', buddylist_translation()),
);
$form['add_group']['submit'] = array(
'#type' => 'submit',
'#value' => t('Add'),
);
$form['add_group']['#type'] = 'fieldset';
$form['add_group']['#title'] = t('Add new group');
$form['add_group']['#collapsible'] = TRUE;
$form['add_group']['#collapsed'] = FALSE;
return $form;
}
function buddylist_form_edit_groups_remove($all_groups) {
// Make a form to remove groups
$form['remove']['groups'] = array(
'#type' => 'checkboxes',
'#return_value' => 1,
'#title' => '',
'#default_value' => null,
'#options' => array_map('check_plain', $all_groups),
);
$form['remove']['submit'] = array(
'#type' => 'submit',
'#value' => t('Remove'),
);
$form['remove']['#type'] = 'fieldset';
$form['remove']['#title'] = t('Remove group');
$form['remove']['#collapsible'] = TRUE;
$form['remove']['#collapsed'] = FALSE;
return $form;
}
/**
* Callback for the buddygroup editing page
*/
function buddylist_buddiesgroups_edit($uid) {
$thisuser = user_load(array('uid' => $uid));
drupal_set_title(t('%username\'s @buddy groups', array('%username' => $thisuser->name) + buddylist_translation()));
$output['add'] = drupal_get_form('buddylist_form_edit_groups_add');
$groups = buddylist_get_buddy_groups($uid);
if (count($groups) > 0) {
$output['remove'] = drupal_get_form('buddylist_form_edit_groups_remove', $groups);
if ($buddies = buddylist_get_buddies($thisuser->uid))
$output['table'] = drupal_get_form('buddylist_form_edit_groups_table', $buddies, $groups, $thisuser);
else {
// TODO: invent some informative message here
// drupal_set_message(t('Unable to edit @buddy groups. Add @buddies to your @buddylist before making groups.', buddylist_translation()));
return t('No @buddies found.', buddylist_translation()) . '<BR/><BR/>' . theme('buddylist_edit_groups', $output);
}
}
else {
drupal_set_message(t("You don't have any groups defined."));
}
return theme('buddylist_edit_groups', $output);
}
function theme_buddylist_form_edit_groups_table($form) {
$rows = array();
foreach ($form['table']['groups'] as $key => $value) {
if(is_numeric($key)) {
$rows[] = array(theme('username', user_load(array('uid' => $key))), drupal_render($form['table']['groups'][$key]));
}
}
$headers = array(t('buddy'), t('@buddy groups', buddylist_translation()));
$output .= theme('table', $headers, $rows);
$output .= drupal_render($form);
$fieldset['#type'] = 'fieldset';
$fieldset['#title'] = t('Add or remove buddies to @buddy groups', buddylist_translation());
$fieldset['#collapsible'] = TRUE;
$fieldset['#collapsed'] = FALSE;
$fieldset['#children'] = $output;
$output = theme_fieldset($fieldset);
return $output;
}
function buddylist_form_edit_groups_add_submit($form_id, $form_values) {
global $user;
$label_id = buddylist_buddygroup_new($user->uid, $form_values['group_name']);
}
Comments
Comment #1
attila75 commentedHere is the code to validate the group name. The define line of course goes after the other define lines.