From efcca123817fda7d1cbd83923c4a957f636b74a1 Mon Sep 17 00:00:00 2001
From: Logaritmisk <Logaritmisk@855656.no-reply.drupal.org>
Date: Tue, 3 Jul 2012 13:13:56 -0400
Subject: [PATCH 1/2] add reorder functionality to feeds

---
 feeds_ui/feeds_ui.admin.inc |   36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/feeds_ui/feeds_ui.admin.inc b/feeds_ui/feeds_ui.admin.inc
index b66f963..53fc6c6 100644
--- a/feeds_ui/feeds_ui.admin.inc
+++ b/feeds_ui/feeds_ui.admin.inc
@@ -532,7 +532,7 @@ function feeds_ui_mapping_form($form, &$form_state, $importer) {
   $form['legendset']['legend'] = $legend;
 
   // Add unique and remove forms to mappings.
-  $form['unique_flags'] = $form['remove_flags'] = array(
+  $form['unique_flags'] = $form['remove_flags'] = $form['mapping_weight'] = array(
     '#tree' => TRUE,
   );
   if (is_array($mappings)) {
@@ -554,6 +554,17 @@ function feeds_ui_mapping_form($form, &$form_state, $importer) {
         '#prefix' => '<div class="feeds-ui-checkbox-link">',
         '#suffix' => '</div>',
       );
+      $form['mapping_weight'][$i] = array(
+        '#type' => 'weight',
+        '#title' => '',
+        '#default_value' => $i,
+        '#delta' => 10,
+        '#attributes' => array(
+          'class' => array(
+            'feeds-ui-mapping-weight'
+          ),
+        ),
+      );
     }
   }
 
@@ -632,6 +643,7 @@ function feeds_ui_mapping_form_submit($form, &$form_state) {
     // Keep our keys clean.
     $mappings = array_values($mappings);
   }
+  array_multisort($form_state['values']['mapping_weight'], $mappings);
   $processor->addConfig(array('mappings' => $mappings));
   $processor->save();
   drupal_set_message(t('Your changes have been saved.'));
@@ -803,6 +815,7 @@ function theme_feeds_ui_mapping_form($variables) {
     t('Target'),
     t('Unique target'),
     '&nbsp;',
+    t('Weight'),
   );
   $rows = array();
   if (is_array($form['#mappings'])) {
@@ -811,17 +824,21 @@ function theme_feeds_ui_mapping_form($variables) {
       $source = isset($form['source']['#options'][$mapping['source']]) ? $form['source']['#options'][$mapping['source']] : $mapping['source'];
       $target = isset($form['target']['#options'][$mapping['target']]) ? check_plain($form['target']['#options'][$mapping['target']]) : '<em>' . t('Missing') . '</em>';
       $rows[] = array(
-        check_plain($source),
-        $target,
-        drupal_render($form['unique_flags'][$i]),
-        drupal_render($form['remove_flags'][$i]),
+        'data' => array(
+          check_plain($source),
+          $target,
+          drupal_render($form['unique_flags'][$i]),
+          drupal_render($form['remove_flags'][$i]),
+          drupal_render($form['mapping_weight'][$i]),
+        ),
+        'class' => array('draggable', 'tabledrag-leaf'),
       );
     }
   }
   if (!count($rows)) {
     $rows[] = array(
       array(
-        'colspan' => 4,
+        'colspan' => 5,
         'data' => t('No mappings defined.'),
       ),
     );
@@ -831,9 +848,10 @@ function theme_feeds_ui_mapping_form($variables) {
     drupal_render($form['target']),
     '',
     drupal_render($form['add']),
+    '',
   );
   $output = '<div class="help feeds-admin-ui""' . drupal_render($form['help']) . '</div>';
-  $output .= theme('table', array('header' => $header, 'rows' => $rows));
+  $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'feeds-ui-mapping-overview')));
 
   // Build the help table that explains available sources.
   $legend = '';
@@ -866,7 +884,9 @@ function theme_feeds_ui_mapping_form($variables) {
   );
 
   $output .= drupal_render($form['legendset']);
-
   $output .= drupal_render_children($form);
+
+  drupal_add_tabledrag('feeds-ui-mapping-overview', 'order', 'sibling', 'feeds-ui-mapping-weight');
+
   return $output;
 }
-- 
1.7.10.3


From 175776047ae32f3d70669c915a2d918fb7c93e4d Mon Sep 17 00:00:00 2001
From: Vincent Massaro <vincent.massaro@yale.edu>
Date: Tue, 3 Jul 2012 13:17:09 -0400
Subject: [PATCH 2/2] added condition to array_multisort to fix error when
 saving feed importer without mappings

---
 feeds_ui/feeds_ui.admin.inc |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/feeds_ui/feeds_ui.admin.inc b/feeds_ui/feeds_ui.admin.inc
index 53fc6c6..33c3d43 100644
--- a/feeds_ui/feeds_ui.admin.inc
+++ b/feeds_ui/feeds_ui.admin.inc
@@ -643,7 +643,9 @@ function feeds_ui_mapping_form_submit($form, &$form_state) {
     // Keep our keys clean.
     $mappings = array_values($mappings);
   }
-  array_multisort($form_state['values']['mapping_weight'], $mappings);
+  if (!empty($mappings)) {
+    array_multisort($form_state['values']['mapping_weight'], $mappings);
+  }
   $processor->addConfig(array('mappings' => $mappings));
   $processor->save();
   drupal_set_message(t('Your changes have been saved.'));
-- 
1.7.10.3

