From 060308d6c24f24231d6739236a02e1642584e332 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 30 Jul 2010 10:02:16 -0600 Subject: [PATCH] Convert browse javascript to a static js file --- .../browse/javascript.inc => js/browse.js} | 28 ++++++++++++---------- turba/lib/Turba.php | 23 ++++++++++++++++++ turba/lib/View/Browse.php | 4 ++-- turba/search.php | 5 +++- 4 files changed, 45 insertions(+), 15 deletions(-) rename turba/{templates/browse/javascript.inc => js/browse.js} (64%) diff --git a/turba/templates/browse/javascript.inc b/turba/js/browse.js similarity index 64% rename from turba/templates/browse/javascript.inc rename to turba/js/browse.js index 9f536ac56..23f69c216 100644 --- a/turba/templates/browse/javascript.inc +++ b/turba/js/browse.js @@ -1,4 +1,11 @@ - diff --git a/turba/lib/Turba.php b/turba/lib/Turba.php index 46d95b749..fc53c6ba5 100644 --- a/turba/lib/Turba.php +++ b/turba/lib/Turba.php @@ -621,4 +621,27 @@ class Turba { return $menu; } + /** + * Add browse.js javascript to page. + */ + public function addBrowseJs() + { + $js = array(); + $js_text = array( + 'confirmdelete' => _("Are you sure that you want to delete %s?"), + 'contact1' => _("You must select at least one contact first."), + 'contact2' => ("You must select a target contact list."), + 'contact3' => _("Please name the new contact list:"), + 'copymove' => _("You must select a target address book."), + 'submit' => _("Are you sure that you want to delete the selected contacts?"), + ); + + foreach ($js_text as $key => $val) { + $js[] = 'TurbaBrowse.' . $key . ' = ' . Horde_Serialize::serialize($val, Horde_Serialize::JSON, $GLOBALS['registry']->getCharset()); + } + + Horde::addScriptFile('browse.js', 'turba'); + Horde::addInlineScript($js); + } + } diff --git a/turba/lib/View/Browse.php b/turba/lib/View/Browse.php index a82af2c72..3bf8c33a9 100644 --- a/turba/lib/View/Browse.php +++ b/turba/lib/View/Browse.php @@ -192,7 +192,7 @@ class Turba_View_Browse { if (!is_array($targetDriver->map[$info_key]) || isset($targetDriver->map[$info_key]['attribute'])) { $objectValue = $object->getValue($info_key); - + // Get 'data' value if object type is image, the // direct value in other case. $objAttributes[$info_key] = isset($GLOBALS['attributes'][$info_key]) && $GLOBALS['attributes'][$info_key]['type'] == 'image' ? $objectValue['load']['data'] : $objectValue; @@ -338,7 +338,7 @@ class Turba_View_Browse { $templates = array(); if (isset($driver)) { - $templates[] = '/browse/javascript.inc'; + Turba::addBrowseJs(); // Read the columns to display from the preferences. $sources = Turba::getColumns(); diff --git a/turba/search.php b/turba/search.php index b1c65c706..8bbb8c8e2 100644 --- a/turba/search.php +++ b/turba/search.php @@ -269,6 +269,10 @@ Horde::addScriptFile('quickfinder.js', 'horde'); Horde::addScriptFile('effects.js', 'horde'); Horde::addScriptFile('redbox.js', 'horde'); Horde::addScriptFile('search.js', 'turba'); +if (isset($view) && is_object($view)) { + Turba::addBrowseJs(); +} + require TURBA_TEMPLATES . '/common-header.inc'; require TURBA_TEMPLATES . '/menu.inc'; echo $tabs->render($_SESSION['turba']['search_mode']); @@ -278,7 +282,6 @@ if ($_SESSION['turba']['search_mode'] != 'duplicate') { echo $vbookView->render('vbook'); } if (isset($view) && is_object($view)) { - require TURBA_TEMPLATES . '/browse/javascript.inc'; require TURBA_TEMPLATES . '/browse/header.inc'; $view->display(); } -- 2.11.0