? translations/.svn
Index: weight-view-weight-form.tpl.php
===================================================================
RCS file: weight-view-weight-form.tpl.php
diff -N weight-view-weight-form.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ weight-view-weight-form.tpl.php	10 Oct 2008 17:57:00 -0000
@@ -0,0 +1,23 @@
+<table class="<?php print $class; ?>" id="<?php print $id; ?>">
+  <thead>
+    <tr>
+      <?php foreach ($header as $field => $label): ?>
+        <th class="views-field views-field-<?php print $fields[$field]; ?>">
+          <?php print $label; ?>
+        </th>
+      <?php endforeach; ?>
+    </tr>
+  </thead>
+  <tbody>
+    <?php  foreach ($rows as $count => $row): ?>
+      <tr class="<?php print ($count % 2 == 0) ? 'even' : 'odd';?> draggable">
+        <?php foreach ($row as $field => $content): ?>
+          <td class="views-field views-field-<?php print isset($fields[$field]) ? $fields[$field] : '' ?>">
+            <?php print $content; ?>
+          </td>
+        <?php endforeach; ?>
+      </tr>
+    <?php endforeach;  ?>
+  </tbody>
+</table>
+<?php print $submit; ?>
Index: weight_handler_sort.inc
===================================================================
RCS file: weight_handler_sort.inc
diff -N weight_handler_sort.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ handlers/weight_handler_sort.inc	10 Oct 2008 17:57:00 -0000
@@ -0,0 +1,16 @@
+<?php
+
+class weight_handler_sort extends views_handler_sort {
+
+ 	function query() {
+   $this->ensure_my_table();
+   // Reverse ASC and DESC for weight order so that the sticky weights are ordered like real weights.
+   if ($this->options['order'] == 'ASC') {
+	   $this->options['order'] = 'DESC';
+   }
+   elseif ($this->options['order'] == 'DESC') {
+	   $this->options['order'] = 'ASC';
+   }
+   $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
+ }
+}
\ No newline at end of file
Index: weight_handler_field_sticky.inc
===================================================================
RCS file: weight_handler_field_sticky.inc
diff -N weight_handler_field_sticky.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ handlers/weight_handler_field_sticky.inc	10 Oct 2008 17:57:00 -0000
@@ -0,0 +1,25 @@
+<?php
+
+class weight_handler_field_sticky extends views_handler_field_numeric {
+	function render($values) {
+    $value = $values->{$this->field_alias};
+    // convert sticky values to corresponding weights.
+		if ($value > 0) {
+		  $value = $value == 1 ? 0 : (100 - $value);
+		}
+		else {
+		  $value = $value == 0 ? 0 : -($value + 100);
+		}
+    if (!empty($this->options['set_precision'])) {
+      $value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']);
+    }
+    else {
+      $remainder = abs($value) - intval(abs($value));
+      $value = number_format($value, 0, '', $this->options['separator']);
+      if ($remainder) {
+        $value .= $this->options['decimal'] . $remainder;
+      }
+    }
+    return check_plain($this->options['prefix'] . $value . $this->options['suffix']);
+  } 	
+}
\ No newline at end of file
Index: INSTALL.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weight/INSTALL.txt,v
retrieving revision 1.1
diff -u -p -r1.1 INSTALL.txt
--- INSTALL.txt	1 Nov 2005 19:07:34 -0000	1.1
+++ INSTALL.txt	10 Oct 2008 17:57:00 -0000
@@ -19,4 +19,10 @@ UNINSTALL:
 
 Go to admin/settings/weight/setup/disable
   and click "Remove Weights".
-Disable the module.
\ No newline at end of file
+Disable the module.
+
+TO CREATE AN ORDERABLE VIEW:
+
+Create a views as normal with a "page" display
+Change the view style to "weight changer"
+Load up the view, reorder, and save!
Index: weight.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weight/weight.module,v
retrieving revision 1.23
diff -u -p -r1.23 weight.module
--- weight.module	27 Sep 2008 00:05:46 -0000	1.23
+++ weight.module	10 Oct 2008 17:57:01 -0000
@@ -384,3 +384,13 @@ function _encoded_sticky2weight(&$node) 
   }
 // drupal_set_message("For node $node->nid, $x becomes sticky: $node->sticky and weight: $node->node_weight.");
 }
+
+/**
+ * Implementation of hook_views_api().
+ */
+function weight_views_api() {
+  return array(
+    'api' => 2,
+    'path' => drupal_get_path('module', 'weight'),
+  );
+}
\ No newline at end of file
Index: weight.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weight/weight.views.inc,v
retrieving revision 1.2
diff -u -p -r1.2 weight.views.inc
--- weight.views.inc	27 Sep 2008 00:05:46 -0000	1.2
+++ weight.views.inc	10 Oct 2008 17:57:01 -0000
@@ -1,25 +1,266 @@
 <?php
-function weight_views_tables() {
-  $tables['node_by_weight'] = array(
-    'name' => 'node',
-    'join' => array(
-      'left' => array(
-        'table' => 'node',
-        'field' => 'nid',
-      ),
-      'right' => array(
-        'field' => 'nid',
+/**
+ * Implementation of hook_views_data()
+ */
+function weight_views_data() {
+	$data['node_weight'] = array(
+		'table' => array(
+		  'group' => t('Weight'),
+		  'join' => array(
+			  'node' => array(
+				  'table' => 'node',
+				  'left_field' => 'nid',
+					'field' => 'nid',
+				),
+			),
+		),
+		'weight' => array(
+			'real field' => 'sticky',
+			'title' => t('Weight'), // The item it appears as on the UI,
+	    'help' => t('The node weight.'), // The help that appears on the UI,
+	    'field' => array(
+	      'handler' => 'weight_handler_field_sticky',
+	      'click sortable' => TRUE,
+	    ),
+	    'sort' => array(
+	      'handler' => 'weight_handler_sort',
+	    ),
+		),
+  );
+
+  return $data;
+}
+
+
+/**
+ * Implementation of hook_views_plugins();
+ */
+function weight_views_plugins() {
+	return array(
+		'style' => array(
+			'weight' => array(
+        'title' => t('Weight Changer'),
+        'help' => t('Displays rows in a table which allows weight change.  Be sure to add the Weight field and Sort by Weight.'),
+        'handler' => 'views_plugin_style_table',
+        'parent' => 'table',
+        'path' => drupal_get_path('module', 'weight') . '/handlers',
+        'theme' => 'weight_view_weight',
+        'uses row plugin' => FALSE,
+        'uses fields' => TRUE,
+        'uses options' => TRUE,
+        'type' => 'normal',
       ),
+		),
+	);
+}
+
+/**
+ * Implementation of hook_views_handlers().
+ */
+function weight_views_handlers() {
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'weight') . '/handlers',
     ),
-    'filters' => array(
-      'sticky' => array(
-        'name' => t('Weight: Sticky'),
-        'operator' => array('>' => t('Yes'), '<=' => t('No')),
-        'value' => array('#type' => 'value', '#value' => '0'),
-        'help' => t('Filter by whether or not the node is set sticky.') .' '. t('Use "Weight: Sticky" as a replacement for "Node: Sticky" when the weight module is enabled.'),
+    'handlers' => array(
+	    'weight_handler_field_sticky' => array(
+		    'parent' => 'views_handler_field_numeric',
+		  ),
+      'weight_handler_sort' => array(
+        'parent' => 'views_handler_sort',
       ),
     ),
   );
+}
+
+/**
+ * Display a view as a weight changing table.
+ */
+function theme_weight_view_weight($view, $rows, $type) {
+  $result = $view->result;
+  $rows = array();
+
+  $options  = $view->style_plugin->options;
+  $handler  = $view->style_plugin;
+
+  $fields   = &$view->field;
+  $columns  = $handler->sanitize_columns($options['columns'], $fields);
+
+  $active   = !empty($handler->active) ? $handler->active : '';
+  $order    = !empty($handler->order) ? $handler->order : 'asc';
+
+  $query    = tablesort_get_querystring();
+  if ($query) {
+    $query = '&' . $query;
+  }
+  foreach ($columns as $field => $column) {
+    // render the header labels
+    if ($field == $column && empty($fields[$field]->options['exclude'])) {
+      $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : '');
+      if (empty($options['info'][$field]['sortable'])) {
+        $header[$field] = $label;
+      }
+      else {
+        // @todo -- make this a setting
+        $initial = 'asc';
+
+        if ($active == $field && $order == 'asc') {
+          $initial = 'desc';
+        }
+
+        $image = theme('tablesort_indicator', $initial);
+        $title = t('sort by @s', array('@s' => $label));
+        $link_options = array(
+          'html' => true,
+          'attributes' => array('title' => $title),
+          'query' => 'order=' . urlencode($field) . '&sort=' . $initial . $query,
+        );
+        $header[$field] = l($label . $image, $_GET['q'], $link_options);
+      }
+    }
 
-  return $tables;
-}
\ No newline at end of file
+    // Create a second variable so we can easily find what fields we have and what the
+    // CSS classes should be.
+    $weight_fields[$field] = views_css_safe($field);
+    if ($active == $field) {
+      $weight_fields[$field] .= ' active';
+    }
+
+    // Render each field into its appropriate column.
+    foreach ($result as $num => $row) {
+      if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) {
+		    $field_output = $fields[$field]->theme($row);
+
+        // Don't bother with separators and stuff if the field does not show up.
+        if (!isset($field_output) && isset($rows[$num][$column])) {
+          continue;
+        }
+        // Place the field into the column, along with an optional separator.
+        if (isset($rows[$num][$column])) {
+          if (!empty($options['info'][$column]['separator'])) {
+            $rows[$num][$column] .= filter_xss_admin($options['info'][$column]['separator']);
+          }
+        }
+        else {
+          $rows[$num][$column] = '';
+        }
+
+        $rows[$num][$column] .= $field_output;
+      }
+    }
+  }
+
+  $class = 'views-table-weight';
+  if (!empty($options['sticky'])) {
+    drupal_add_js('misc/tableheader.js');
+    $class .= " sticky-enabled";
+  }
+  
+  // Pass along the nid.
+
+  foreach($view->result as $count => $item) {
+	  $rows[$count]['nid_hidden'] = $item->nid;
+  } 
+  $id = $view->name .'_drag';
+  return drupal_get_form('weight_view_weight_form', $header, $rows, $weight_fields, $class, $id);
+}
+/**
+ * Display a view as a weight changing table.
+ */
+function weight_view_weight_form(&$form_state, $header, $rows, $fields, $class, $id) {
+  // Make this form draggable
+  drupal_add_tabledrag($id, 'order', 'sibling', 'weight_dragger');
+
+	$form = array('#tree' => TRUE);
+	$form['#variables'] = array(
+		'header' => $header,
+		'class' => $class,
+		'fields' => $fields,
+		'id'=> $id,
+		);
+	foreach ($rows as $count => $row) {
+		if (is_numeric($count)) {
+			foreach ($row as $field => $content) {
+				$nid = $row['nid_hidden'];
+				if (substr($field, 0, 6) == 'weight') {
+					$form['rows'][$count][$field] = array(
+						'#default_value' => $content,
+						'#type' => 'weight',
+						'#delta' => variable_get('weight_range', 20),
+						);
+				}
+				elseif($field != 'nid_hidden') {
+					$form['rows'][$count][$field] = array(
+						'#value' => $content,
+						);
+				}
+				else {
+					$form['rows'][$count][$field] = array(
+						'#type' => 'hidden',
+						'#value' => $content,
+						);
+				}
+			}
+		}	
+	}
+	$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
+	return $form;
+}
+
+/**
+ * Save the changed weights.
+ */
+function weight_view_weight_form_submit($form, &$form_state) {
+	foreach ($form_state['values']['rows'] as $count => $value) {
+		$weight = $value['weight'];
+		$nid = $value['nid_hidden'];
+		$node = node_load($nid);
+	  if ($node->sticky) {
+	    $node->sticky = (-1 * $weight) + 100;
+	  }
+	  // Unweighted non-sticky nodes will have a value of -100.
+	  else {
+	    $node->sticky = (-1 * $weight) - 100;
+	  }
+	  db_query("UPDATE {node} SET sticky = %d WHERE nid = %d", $node->sticky, $nid);
+	}
+	drupal_set_message('Your weight changes have been saved.');
+}
+
+/** 
+ * Prepare the weight form for its template file.
+ */
+function template_preprocess_weight_view_weight_form(&$vars) {
+	$vars['header'] = $vars['form']['#variables']['header'];
+	$vars['class'] = $vars['form']['#variables']['class'];
+	$vars['id'] = $vars['form']['#variables']['id'];
+	$vars['fields'] = $vars['form']['#variables']['fields'];
+	foreach ($vars['form']['rows'] as $count => $item) {
+		if (is_numeric($count)) {
+			foreach ($item as $field => $value) {
+				if (substr($field, 0, 1) != '#') {
+					if (substr($field, 0, 6) == 'weight') {
+						$value['#attributes']['class'] = 'weight_dragger';
+					}
+					$vars['rows'][$count][$field] = drupal_render($value);
+				}
+			}
+		}
+	}
+	unset($vars['form']['rows']);
+	$vars['submit'] = drupal_render($vars['form']);
+}
+
+
+
+/**
+ * Implementation of hook_theme()
+ */
+function weight_theme() {
+  return array(
+    'weight_view_weight_form' => array(
+      'arguments' => array('form' => NULL),
+      'template' => 'weight-view-weight-form',
+    ),
+  );
+}
