Index: filefield.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.install,v retrieving revision 1.18 diff -u -r1.18 filefield.install --- filefield.install 16 Nov 2008 06:57:21 -0000 1.18 +++ filefield.install 2 Mar 2009 05:09:24 -0000 @@ -192,6 +192,28 @@ } /** + * Migrate field settings from 'force_list_default' and 'show_description'. + */ +function filefield_update_6100() { + $ret = array(); + + module_load_include('inc', 'content', 'includes/content.crud'); + + $fields = content_fields(); + foreach ($fields as $field) { + if ($field['type'] == 'filefield') { + $field['list_field'] = empty($field['force_list_default']); + $field['description_field'] = $field['show_description']; + _content_field_write($field); + $ret[] = array('success' => TRUE, 'query' => t('The File field %field has been updated with new settings.', array('%field' => $field['field_name']))); + } + } + + return $ret; +} + + +/** * Move the list and descriptions column into the serialized data column. */ function _filefield_update_6001_move_operation($field, &$context) { Index: filefield_field.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield_field.inc,v retrieving revision 1.13 diff -u -r1.13 filefield_field.inc --- filefield_field.inc 27 Feb 2009 16:54:53 -0000 1.13 +++ filefield_field.inc 2 Mar 2009 05:09:24 -0000 @@ -7,26 +7,27 @@ function filefield_field_settings_form($field) { + drupal_add_js(drupal_get_path('module', 'filefield') .'/filefield.js'); + $form = array(); - $form['list_default'] = array( + + $form['list_field'] = array( '#type' => 'radios', - '#title' => t('Default list value'), - '#options' => array(1 => t('Listed'), 0 => t('Hidden')), - '#default_value' => $field['list_default'] === '' ? 1 : (int) $field['list_default'], - '#required' => true, - '#description' => t('The list option determines whether files are visible on node views. This will be used as the default value for the list option.'), + '#title' => t('List field'), + '#options' => array(0 => t('Disabled'), 1 => t('Enabled')), + '#default_value' => $field['list_field'] === '' ? 0 : (int) $field['list_field'], + '#description' => t('The "list" option lets a user choose if a file should shown in a list when viewing the content after creation.'), + '#attributes' => array('class' => 'filefield-list-field'), ); - $form['force_list_default'] = array( - '#type' => 'radios', - '#title' => t('How should the list value be handled?'), - '#options' => array(0 => t('User Configurable. (Users will be able to set the list value per file.)'), 1 => t('Enforce Default. (The default list value will be used for all files, and the list checkbox will not be displayed to users.)')), - '#default_value' => $field['force_list_default'] === '' ? 0 : (int) $field['force_list_default'], - '#required' => true, + $form['list_default'] = array( + '#type' => 'checkbox', + '#title' => t('Files listed by default'), + '#default_value' => $field['list_default'] === '' ? 1 : (int) $field['list_default'], ); - $form['show_description'] = array( + $form['description_field'] = array( '#type' => 'radios', '#title' => t('Description field'), - '#default_value' => $field['show_description'] === '' ? 1 : (int) $field['show_description'], + '#default_value' => $field['description_field'] === '' ? 0 : (int) $field['description_field'], '#options' => array(0 => t('Disabled'), 1 => t('Enabled')), '#description' => t('When enabled, will display a text field where users may enter a description about the uploaded file.'), ); @@ -38,7 +39,7 @@ } function filefield_field_settings_save($field) { - return array('force_list_default', 'list_default', 'show_description', 'file_formatters'); + return array('list_field', 'list_default', 'description_field'); } function filefield_field_settings_database_columns($field) { Index: filefield_formatter.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield_formatter.inc,v retrieving revision 1.7 diff -u -r1.7 filefield_formatter.inc --- filefield_formatter.inc 4 Feb 2009 02:18:27 -0000 1.7 +++ filefield_formatter.inc 2 Mar 2009 05:09:24 -0000 @@ -41,20 +41,20 @@ } /** - * return whether a file is set to listed taking into consideration - * widget default value settings. + * Return whether a file should be listed when viewing the node. * - * @param $file a populated filefield item. - * @param $field a cck field instance array. + * @param $file + * A populated FileField item. + * @param $field + * A CCK field instance array. */ function filefield_file_listed($file, $field) { - if ($field['force_list_default']) return (bool)$field['list_default']; - return (bool)$file['list']; + if ($field['list_field']) { + return (bool)$file['list']; + } + return TRUE; } - - - /** * Theme function for the 'generic' single file formatter. */ Index: filefield.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.js,v retrieving revision 1.13 diff -u -r1.13 filefield.js --- filefield.js 31 Jan 2009 17:56:22 -0000 1.13 +++ filefield.js 2 Mar 2009 05:09:24 -0000 @@ -30,4 +30,24 @@ */ /* @todo */ }); -} +}; + +/** + * Admin enhancement: only show the "Files listed by default" when needed. + */ +Drupal.behaviors.filefieldAdmin = function(context) { + var $listField = $('div.filefield-list-field', context); + if ($listField.size()) { + $listField.find('input').change(function() { + if (this.checked) { + if (this.value == 0) { + $('#edit-list-default-wrapper').css('display', 'none'); + } + else { + $('#edit-list-default-wrapper').css('display', 'block'); + } + } + }).change(); + } +}; + Index: filefield_widget.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield_widget.inc,v retrieving revision 1.55 diff -u -r1.55 filefield_widget.inc --- filefield_widget.inc 1 Mar 2009 05:17:37 -0000 1.55 +++ filefield_widget.inc 2 Mar 2009 05:09:24 -0000 @@ -209,7 +209,7 @@ // to put additional data. $element['data'] = array('#tree' => 'true'); - if ($field['show_description']) { + if ($field['description_field']) { $element['data']['description'] = array( '#type' => 'textfield', '#title' => t('Description'), @@ -218,13 +218,7 @@ ); } - if ($field['force_list_default']) { - $element['list'] = array( - '#type' => 'hidden', - '#value' => $field['list_default'], - ); - } - else { + if ($field['list_field']) { $element['list'] = array( '#type' => 'checkbox', '#title' => t('List'), @@ -233,6 +227,12 @@ '#access' => !empty($item['fid']), ); } + else { + $element['list'] = array( + '#type' => 'hidden', + '#value' => '1', + ); + } foreach ($element['#upload_validators'] as $callback => $arguments) { $help_func = $callback .'_help';