--- attachment.module Thu Aug 2 17:37:32 2007 +++ attachment.module Tue Sep 9 11:43:09 2008 @@ -58,6 +58,7 @@ $form['attachments'][$key]['hidden'] = array('#type'=>'checkbox', '#return_value'=>1, '#default_value'=>$attachment['hidden']); $form['attachments'][$key]['title'] = array('#type'=>'textfield', '#size'=>30, '#maxlength'=>255, '#default_value'=>$attachment['title']); $form['attachments'][$key]['description'] = array('#type'=>'textfield', '#size'=>100, '#maxlength'=>255, '#default_value'=>$attachment['description']); + $form['attachments'][$key]['weight'] = array('#type'=>'weight','#default_value'=>$attachment['weight']); $form['attachments'][$key]['display'] = array('#type'=>'markup', '#value'=> 'Filename:'. $attachment['filename'] .'
URL:'. module_invoke('filemanager', 'url', $attachment['fid'], FALSE, TRUE) .'
Size:' . format_size($attachment['size']) . '
'); } @@ -126,11 +127,11 @@ if (!$attachment['deleted']) { module_invoke('filemanager', 'promote_working', $attachment['fid']); if ($attachment['aid']) { - db_query("UPDATE {attachment} SET title='%s', description = '%s', size=%d, hidden='%s' WHERE aid=%d", $attachment['title'], $attachment['description'], $attachment['size'], $attachment['hidden'], $attachment['aid']); + db_query("UPDATE {attachment} SET title='%s', description = '%s', size=%d, hidden='%s', weight='%d' WHERE aid=%d", $attachment['title'], $attachment['description'], $attachment['size'], $attachment['hidden'], $attachment['weight'], $attachment['aid']); } else { $aid = db_next_id('{attachment}_aid'); - db_query("INSERT INTO {attachment} (aid,title,description,nid,fid,filename,size,hidden) VALUES (%d,'%s','%s',%d,%d,'%s',%d,'%s')", $aid, $attachment['title'],$attachment['description'],$node->nid, $attachment['fid'], $attachment['filename'], $attachment['size'], $attachment['hidden']); + db_query("INSERT INTO {attachment} (aid,title,description,nid,fid,filename,size,hidden,weight) VALUES (%d,'%s','%s',%d,%d,'%s',%d,'%s',%d)", $aid, $attachment['title'],$attachment['description'],$node->nid, $attachment['fid'], $attachment['filename'], $attachment['size'], $attachment['hidden'], $attachment['weight']); } } else { @@ -269,35 +270,36 @@ * Theme the attachment form */ function theme_attachment_form($form) { + _attachments_enable_dragdrop(); $output = ''; $header = array( t('Delete'), t('Hidden'), + t('Weight'), t('Title'), t('Description'), ); $rows = array(); + + $output .= "
"; $output .= drupal_render($form); return $output; @@ -381,7 +383,7 @@ * Load the attachments for the given node */ function attachment_load($node) { - $result = db_query("SELECT aid, title, description, fid, filename, size, hidden FROM {attachment} WHERE nid = %d", $node->nid); + $result = db_query("SELECT aid, title, description, fid, filename, size, hidden,weight FROM {attachment} WHERE nid = %d ORDER BY weight ASC,title", $node->nid); while ($attachment = db_fetch_array($result)) { $attachment['deleted'] = FALSE; $attachment['working'] = FALSE; @@ -450,4 +452,38 @@ /** * @} end of addtogroup themeable */ + +/** + * includes javascript to enable drag and drop of attachment list to + * rearrange the order of the attachments. requires jquery interface + * module which if absent will fall back on letting user reorder list + * via the weights. + */ +function _attachments_enable_dragdrop() { + if(module_exists('jquery_interface')) { + jquery_interface_add(); + drupal_add_js( <<