Sort duplicates by modification date.
authorJan Schneider <jan@horde.org>
Mon, 5 Jul 2010 09:52:57 +0000 (11:52 +0200)
committerJan Schneider <jan@horde.org>
Mon, 5 Jul 2010 10:34:46 +0000 (12:34 +0200)
Show duplicates as inline-block.
Add merge button.

turba/lib/Object.php
turba/lib/View/Duplicates.php
turba/templates/search/duplicate/contact_header.html.php
turba/themes/ie6_or_less.css [new file with mode: 0644]
turba/themes/ie7.css [new file with mode: 0644]
turba/themes/screen.css

index c3a0663..f651afc 100644 (file)
@@ -188,6 +188,42 @@ class Turba_Object {
     }
 
     /**
+     * Returns the timestamp of the last modification, whether this was the
+     * creation or editing of the object and stores it as the attribute
+     * __modified. The value is cached for the lifetime of the object.
+     *
+     * @return integer  The timestamp of the last modification or zero.
+     */
+    function lastModification()
+    {
+        $time = $this->getValue('__modified');
+        if (!is_null($time)) {
+            return $time;
+        }
+
+        if (!$this->getValue('__uid')) {
+            $this->setValue('__modified', 0);
+            return 0;
+        }
+
+        $time = 0;
+        try {
+            $log = $GLOBALS['injector']
+                ->getInstance('Horde_History')
+                ->getHistory($this->getGuid());
+            foreach ($log as $entry) {
+                if ($entry['action'] == 'add' || $entry['action'] == 'modify') {
+
+                    $time = max($time, $entry['ts']);
+                }
+            }
+        } catch (Exception $e) {}
+        $this->setValue('__modified', $time);
+
+        return $time;
+    }
+
+    /**
      * Returns history information about this contact.
      *
      * @return array  A hash with the optional entries 'created' and 'modified'
index f9d3d3f..2f357f5 100644 (file)
@@ -81,8 +81,14 @@ class Turba_View_Duplicates
             echo $view->render('header');
 
             $view->contactUrl = Horde::applicationUrl('contact.php');
+            $view->first = true;
             $duplicate = $this->_duplicates[$this->_type][$this->_duplicate];
             while ($contact = $duplicate->next()) {
+                $contact->lastModification();
+            }
+            $duplicate->sort(array(array('field' => '__modified', 'ascending' => false)));
+            $view->mergeInto = $duplicate->reset()->getValue('__key');
+            while ($contact = $duplicate->next()) {
                 $view->source = $contact->getSource();
                 $view->id = $contact->getValue('__key');
                 $history = $contact->getHistory();
@@ -95,6 +101,7 @@ class Turba_View_Duplicates
                 $contactView = new Turba_Form_Contact($vars, $contact, false);
                 $contactView->renderInactive(new Horde_Form_Renderer(), $vars);
                 echo $view->render('contact_footer');
+                $view->first = false;
             }
 
             echo $view->render('footer');
index f50993b..65d8c4e 100644 (file)
@@ -1,13 +1,32 @@
 <div class="turba-duplicate-contact solidbox">
-  <form action="<?= $this->contactUrl ?>">
-    <p>
-      <? if ($this->changed): ?>
-      <?= _("Last change: ") . $this->changed ?>
-      <? endif; ?>
+  <? if ($this->changed): ?>
+  <p>
+    <?= _("Last change: ") . $this->changed ?>
+  </p>
+  <? endif; ?>
+  <div class="turba-duplicate-forms">
+    <? if (!$this->first): ?>
+    <form action="<?= $this->contactUrl ?>">
+      <input type="hidden" name="source" value="<?= $this->source ?>" />
+      <input type="hidden" name="key" value="<?= $this->h($this->id) ?>" />
+      <input type="hidden" name="url" value="<?= Horde::selfUrl(true) ?>" />
+      <input type="hidden" name="merge_into" value="<?= $this->h($this->mergeTarget) ?>" />
+      <input type="hidden" name="actionID" value="merge" />
+      <input type="submit" class="button" value="<?= _("<< Merge this into the first contact") ?>" />
+                                                           </form>
+    <? endif; ?>
+    <form action="<?= $this->contactUrl ?>">
+      <input type="hidden" name="source" value="<?= $this->source ?>" />
+      <input type="hidden" name="key" value="<?= $this->h($this->id) ?>" />
+      <input type="hidden" name="url" value="<?= Horde::selfUrl(true) ?>" />
       <input type="hidden" name="view" value="DeleteContact" />
+      <input type="submit" class="button" value="<?= _("Delete") ?>" />
+    </form>
+    <form action="<?= $this->contactUrl ?>">
       <input type="hidden" name="source" value="<?= $this->source ?>" />
-      <input type="hidden" name="key" value="<?= $this->id ?>" />
-      <input type="hidden" name="url" value="<?= Horde::selfUrl(true, true, true) ?>" />
-      <input type="submit" value="<?= _("Delete") ?>" class="button" />
-    </p>
-  </form>
+      <input type="hidden" name="key" value="<?= $this->h($this->id) ?>" />
+      <input type="hidden" name="url" value="<?= Horde::selfUrl(true) ?>" />
+      <input type="hidden" name="view" value="EditContact" />
+      <input type="submit" class="button" value="<?= _("Edit") ?>" />
+    </form>
+  </div>
diff --git a/turba/themes/ie6_or_less.css b/turba/themes/ie6_or_less.css
new file mode 100644 (file)
index 0000000..d20a095
--- /dev/null
@@ -0,0 +1,9 @@
+/**
+ * CSS corrections for IE 6 and below.
+ */
+
+/* Fixes broken inline-block. */
+.turba-duplicate-contact {
+    zoom: 1;
+    display: inline;
+}
diff --git a/turba/themes/ie7.css b/turba/themes/ie7.css
new file mode 100644 (file)
index 0000000..53a20d2
--- /dev/null
@@ -0,0 +1,9 @@
+/**
+ * CSS corrections for IE 7.
+ */
+
+/* Fixes broken inline-block. */
+.turba-duplicate-contact {
+    zoom: 1;
+    display: inline;
+}
index 8b14af7..f4edcf8 100644 (file)
@@ -71,16 +71,24 @@ table#addressbook-list th.sortdown {
 
 /* Duplicates */
 .turba-duplicate {
+    overflow-y: hidden;
     overflow-x: auto;
     white-space: nowrap;
+    vertical-align: top;
 }
 .turba-duplicate-contact {
-    float: left;
+    display: inline-block;
     margin-top: 8px;
     margin-right: 8px;
 }
 .turba-duplicate-contact p {
-    padding: 8px;
+    margin: 8px;
+}
+.turba-duplicate-contact form {
+    display: inline;
+}
+.turba-duplicate-forms {
+    margin: 8px;
 }
 
 /* Preferences pages */