? views_reorder.patch Index: views_ui.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/views_ui.module,v retrieving revision 1.109 diff -r1.109 views_ui.module 122a123,126 > $items['admin/build/views/%views_ui_js/reorder-displays/%views_ui_cache'] = $callback + array( > 'page callback' => 'views_ui_reorder_view', > 'page arguments' => array(3, 5), > ); 210a215,219 > 'views_ui_reorder_displays_form' => array( > 'arguments' => array('form' => NULL), > 'file' => 'includes/admin.inc', > ), > Index: includes/admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/admin.inc,v retrieving revision 1.154.2.6 diff -r1.154.2.6 admin.inc 984c984,985 < $tabs->add_extra($display_button . $analyze_button); --- > $reorder_button = drupal_get_form('views_ui_reorder_displays_button', $view); > $tabs->add_extra($display_button . $analyze_button . $reorder_button); 1822a1824,2026 > * Page callback to display analysis information on a view. > */ > function views_ui_reorder_view($js, $view) { > views_include('ajax'); > $form_state = array( > 'view' => &$view, > 'ajax' => $js, > ); > > $output = views_ajax_form_wrapper('views_ui_reorder_displays_form', $form_state); > > if ($js) { > if(empty($output)) { > // Doesn't work yet, maybe we should reload the page dunno > return views_ui_regenerate_tabs($view); > } > return views_ajax_render($output); > } > > return $output; > } > > /** > * Form constructor callback to reorder displays on a view > */ > function views_ui_reorder_displays_form(&$form_state) { > $view = &$form_state['view']; > > $form['view'] = array('#type' => 'value', '#value' => $view); > > $form['#tree'] = TRUE; > > $last_display = end($view->display); > > foreach ($view->display as $display) { > $form[$display->id] = array( > 'title' => array('#value' => $display->display_title), > 'weight' => array( > '#type' => 'weight', > '#value' => $display->position, > '#delta' => $last_display->position, > ), > '#tree' => TRUE, > '#display' => $display, > 'removed' => array( > '#type' => 'checkbox', > '#id' => 'display-removed-' . $display->id, > '#attributes' => array('class' => 'views-remove-checkbox'), > '#default_value' => 0, > ), > ); > if ($display->id === 'default') { > unset($form[$display->id]['weight']); > unset($form[$display->id]['removed']); > } > > } > > $form['#title'] = t('Displays Reorder'); > $form['#section'] = 'reorder'; > > // Add javascript settings that will be added via $.extend for tabledragging > $form['#js']['tableDrag']['reorder']['weight'][0] = array( > 'target' => 'weight', > 'source' => NULL, > 'relationship' => 'sibling', > 'action' => 'order', > 'hidden' => TRUE, > 'limit' => 0, > ); > > > $form['#action'] = url('admin/build/views/nojs/reorder-display/'. $view->name); > > views_ui_standard_form_buttons($form, $form_state, 'views_ui_reorder_displays_form'); > > return $form; > } > > > /** > * Display position sorting function > */ > function _views_position_sort($a, $b) { > if ($a->position != $b->position) { > return $a->position < $b->position ? -1 : 1; > } > > return 0; > } > > /** > * Submit handler for rearranging display form > */ > function views_ui_reorder_displays_form_submit($form, &$form_state) { > foreach($form_state['input'] as $display => $info) { > // add each value that is a field with a weight to our list, but only if > // it has had its 'removed' checkbox checked. > if (is_array($info) && isset($info['weight']) && empty($info['removed'])) { > $order[$display] = $info['weight']; > } > } > > // Sort the order array > asort($order); > > // Fixing up positions > $position = 2; > > foreach(array_keys($order) as $display) { > $order[$display] = $position++; > } > > // Setting up position and removing deleted displays > $displays = $form_state['view']->display; > foreach($displays as $display_id => $display) { > // Don't touch the default !!! > if ($display_id === 'default') { > continue; > } > if (isset($order[$display_id])) { > $form_state['view']->display[$display_id]->position = $order[$display_id]; > } > else { > $form_state['view']->display[$display_id]->deleted = TRUE; > } > } > > // Sorting back the display array as the position is not enough > uasort($form_state['view']->display, '_views_position_sort'); > > // Store in cache > views_ui_cache_set($form_state['view']); > $form_state['redirect'] = array('admin/build/views/edit/' . $form_state['view']->name, NULL, 'views-tab-default'); > } > > /** > * Turn the reorder form into a proper table > */ > function theme_views_ui_reorder_displays_form($form) { > $rows = array(); > foreach (element_children($form) as $key) { > if (isset($form[$key]['#display'])) { > $display = &$form[$key]; > > $row = array(); > $row[] = drupal_render($display['title']); > $form[$key]['weight']['#attributes']['class'] = 'weight'; > $row[] = drupal_render($form[$key]['weight']); > if (isset($display['removed'])) { > $row[] = drupal_render($form[$id]['removed']) . > l('' . t('Remove') . '', > 'javascript:void()', > array( > 'attributes' => array( > 'id' => 'display-remove-link-' . $key, > 'class' => 'views-button-remove display-remove-link', > 'alt' => t('Remove this display'), > 'title' => t('Remove this display')), > 'html' => true)); > } > else { > $row[] = ''; > } > if (isset($form[$key]['weight']['#type'])) { > $rows[] = array('data' => $row, 'class' => 'draggable', 'id' => 'display-row-' . $key); > } > else { > $rows[] = array('data' => $row, 'id' => 'display-row-' . $key); > } > } > } > > $header = array('', t('Weight'), t('Remove')); > $output = ''; > drupal_add_tabledrag('reorder', 'order', 'sibling', 'weight'); > > $output = drupal_render($form['override']); > $output .= theme('table', $header, $rows, array('id' => 'reorder')); > $output .= drupal_render($form); > > return $output; > } > > /** > * This form doesn't particularly do much; it's really just providing a link > * but a button seems like it would be nicer here. > * > * It has no submit or anything, as we will never actually submit this form > * where the form is placed. > */ > function views_ui_reorder_displays_button(&$form_state, $view) { > $form['#action'] = url("admin/build/views/nojs/reorder-displays/$view->name"); > $form['#attributes'] = array('class' => 'views-ajax-form'); > $form['submit'] = array( > '#type' => 'submit', > '#value' => t('Reorder'), > ); > > return $form; > } > > /** Index: js/base.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/js/base.js,v retrieving revision 1.10.2.1 diff -r1.10.2.1 base.js 27a28,35 > $('a.display-remove-link') > .addClass('display-processed') > .click(function() { > var id = $(this).attr('id').replace('display-remove-link-', ''); > $('#display-row-' + id).hide(); > $('#display-removed-' + id).attr('checked', true); > return false; > });