From: Jan Schneider Date: Fri, 2 Jul 2010 22:18:29 +0000 (+0200) Subject: Display selected set of duplicates and allow to delete them. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7ab2b244936de50db86beeeb9ec729d2b0d6a760;p=horde.git Display selected set of duplicates and allow to delete them. --- diff --git a/turba/lib/Form/Contact.php b/turba/lib/Form/Contact.php index a66c1a9c0..5021e1023 100644 --- a/turba/lib/Form/Contact.php +++ b/turba/lib/Form/Contact.php @@ -4,7 +4,7 @@ */ class Turba_Form_Contact extends Horde_Form { - public function __construct(&$vars, &$contact) + public function __construct(&$vars, &$contact, $tabs = true) { global $conf, $notification; @@ -17,7 +17,7 @@ class Turba_Form_Contact extends Horde_Form } $vars->set('object', $object); - $this->_addFields($contact); + $this->_addFields($contact, $tabs); /* List files. */ $v_params = $GLOBALS['injector']->getInstance('Horde_Vfs')->getConfig('documents'); @@ -35,7 +35,7 @@ class Turba_Form_Contact extends Horde_Form /** * Set up the Horde_Form fields for $contact's attributes. */ - function _addFields($contact) + function _addFields($contact, $useTabs = true) { global $attributes; @@ -64,7 +64,11 @@ class Turba_Form_Contact extends Horde_Form } foreach ($tabs as $tab => $tab_fields) { if (!empty($tab)) { - $this->setSection($tab, $tab); + if ($useTabs) { + $this->setSection($tab, $tab); + } else { + $this->addVariable($tab, '', 'header', false); + } } foreach ($tab_fields as $field) { if (!in_array($field, $fields) || diff --git a/turba/lib/View/DeleteContact.php b/turba/lib/View/DeleteContact.php index 7b5490a7d..5268f8ecd 100644 --- a/turba/lib/View/DeleteContact.php +++ b/turba/lib/View/DeleteContact.php @@ -48,6 +48,7 @@ class Turba_View_DeleteContact { ?>
+
diff --git a/turba/lib/View/Duplicates.php b/turba/lib/View/Duplicates.php index 2a01e6b29..f9d3d3f87 100644 --- a/turba/lib/View/Duplicates.php +++ b/turba/lib/View/Duplicates.php @@ -21,6 +21,20 @@ class Turba_View_Duplicates protected $_duplicates; /** + * A field name. + * + * @var string + */ + protected $_type; + + /** + * A duplicate value. + * + * @var string + */ + protected $_duplicate; + + /** * A Turba_Driver instance. * * @var Turba_Driver @@ -30,27 +44,69 @@ class Turba_View_Duplicates /** * Constructor. * + * If the $type and $duplicate parameters are specified, they are used to + * lookup a single Turba_List from $duplicates with a list of duplicate + * contacts. The resolution interface for those duplicates is rendered + * above the overview tables then. + * * @param array $duplicates Hash of Turba_List objects. * @param Turba_Driver $driver A Turba_Driver instance. + * @param string $type A field name. + * @param string $duplicate A duplicate value. */ - public function __construct(array $duplicates, Turba_Driver $driver) + public function __construct(array $duplicates, Turba_Driver $driver, + $type = null, $duplicate = null) { $this->_duplicates = $duplicates; $this->_driver = $driver; + $this->_type = $type; + $this->_duplicate = $duplicate; } + /** + * Renders this view. + */ public function display() { require TURBA_BASE . '/config/attributes.php'; - $view = new Horde_View(array('templatePath' => TURBA_TEMPLATES . '/search')); + + $view = new Horde_View(array('templatePath' => TURBA_TEMPLATES . '/search/duplicate')); new Horde_View_Helper_Text($view); + + $hasDuplicate = $this->_type && $this->_duplicate; + if ($hasDuplicate) { + $vars = new Horde_Variables(); + $view->type = $attributes[$this->_type]['label']; + $view->value = $this->_duplicate; + echo $view->render('header'); + + $view->contactUrl = Horde::applicationUrl('contact.php'); + $duplicate = $this->_duplicates[$this->_type][$this->_duplicate]; + while ($contact = $duplicate->next()) { + $view->source = $contact->getSource(); + $view->id = $contact->getValue('__key'); + $history = $contact->getHistory(); + if (isset($history['modified'])) { + $view->changed = $history['modified']; + } elseif (isset($history['created'])) { + $view->changed = $history['created']; + } + echo $view->render('contact_header'); + $contactView = new Turba_Form_Contact($vars, $contact, false); + $contactView->renderInactive(new Horde_Form_Renderer(), $vars); + echo $view->render('contact_footer'); + } + + echo $view->render('footer'); + } + $view->duplicates = $this->_duplicates; + $view->hasDuplicate = (bool)$hasDuplicate; $view->attributes = $attributes; $view->link = Horde::applicationUrl('search.php') ->add(array('source' => $this->_driver->name, - 'search_mode' => 'duplicate', - 'search' => 1)); + 'search_mode' => 'duplicate')); - echo $view->render('duplicate_list'); + echo $view->render('list'); } } diff --git a/turba/search.php b/turba/search.php index ff54d653b..fd924036c 100644 --- a/turba/search.php +++ b/turba/search.php @@ -131,7 +131,9 @@ if (is_a($driver, 'PEAR_Error')) { if ((is_array($criteria) && count($criteria)) || !empty($val) || ($_SESSION['turba']['search_mode'] == 'duplicate' && - (Horde_Util::getFormData('search') || count($addressBooks) == 1))) { + (Horde_Util::getFormData('search') || + Horde_Util::getFormData('dupe') || + count($addressBooks) == 1))) { if (Horde_Util::getFormData('save_vbook')) { /* We create the vbook and redirect before we try to search * since we are not displaying the search results on this page @@ -165,9 +167,15 @@ if (is_a($driver, 'PEAR_Error')) { /* Perform a search. */ if ($_SESSION['turba']['search_mode'] == 'duplicate') { - $duplicates = $driver->searchDuplicates(); - $view = new Turba_View_Duplicates($duplicates, $driver); - Horde::addScriptFile('tables.js', 'horde'); + try { + $duplicates = $driver->searchDuplicates(); + $dupe = Horde_Util::getFormData('dupe'); + $type = Horde_Util::getFormData('type'); + $view = new Turba_View_Duplicates($duplicates, $driver, $type, $dupe); + Horde::addScriptFile('tables.js', 'horde'); + } catch (Exception $e) { + $notification->push($e); + } } elseif (($_SESSION['turba']['search_mode'] == 'basic' && is_object($results = $driver->search(array($criteria => $val)))) || ($_SESSION['turba']['search_mode'] == 'advanced' && diff --git a/turba/templates/search/duplicate/contact_footer.html.php b/turba/templates/search/duplicate/contact_footer.html.php new file mode 100644 index 000000000..04f5b8449 --- /dev/null +++ b/turba/templates/search/duplicate/contact_footer.html.php @@ -0,0 +1 @@ +
diff --git a/turba/templates/search/duplicate/contact_header.html.php b/turba/templates/search/duplicate/contact_header.html.php new file mode 100644 index 000000000..f50993bd0 --- /dev/null +++ b/turba/templates/search/duplicate/contact_header.html.php @@ -0,0 +1,13 @@ +
+ +

+ changed): ?> + changed ?> + + + + + + " class="button" /> +

+ diff --git a/turba/templates/search/duplicate/footer.html.php b/turba/templates/search/duplicate/footer.html.php new file mode 100644 index 000000000..04f5b8449 --- /dev/null +++ b/turba/templates/search/duplicate/footer.html.php @@ -0,0 +1 @@ +
diff --git a/turba/templates/search/duplicate/header.html.php b/turba/templates/search/duplicate/header.html.php new file mode 100644 index 000000000..1933bd9a0 --- /dev/null +++ b/turba/templates/search/duplicate/header.html.php @@ -0,0 +1,3 @@ +
+

h(sprintf(_("Duplicates of %s \"%s\""), $this->type, $this->value)) ?>

+
diff --git a/turba/templates/search/duplicate/list.html.php b/turba/templates/search/duplicate/list.html.php new file mode 100644 index 000000000..a81c7d564 --- /dev/null +++ b/turba/templates/search/duplicate/list.html.php @@ -0,0 +1,23 @@ +hasDuplicate): ?> +
+ +
+duplicates as $field => $duplicates): ?> +

h(sprintf(_("Duplicates of %s"), $this->attributes[$field]['label'])) ?>

+ + + + + + + + + $list): ?> + + + + + + + + diff --git a/turba/templates/search/duplicate_list.html.php b/turba/templates/search/duplicate_list.html.php deleted file mode 100644 index 878af1f1a..000000000 --- a/turba/templates/search/duplicate_list.html.php +++ /dev/null @@ -1,20 +0,0 @@ -
-duplicates as $field => $duplicates): ?> -

h($this->attributes[$field]['label'])) ?>

- - - - - - - - - $list): ?> - - - - - - - - diff --git a/turba/themes/screen.css b/turba/themes/screen.css index 1c722081f..8b14af7eb 100644 --- a/turba/themes/screen.css +++ b/turba/themes/screen.css @@ -69,6 +69,20 @@ table#addressbook-list th.sortdown { width: 1%; } +/* Duplicates */ +.turba-duplicate { + overflow-x: auto; + white-space: nowrap; +} +.turba-duplicate-contact { + float: left; + margin-top: 8px; + margin-right: 8px; +} +.turba-duplicate-contact p { + padding: 8px; +} + /* Preferences pages */ #turba-prefs-cols-list { float: left;