From 708f5780e3e0ed172e968f06f21c11d2aaa6c83c Mon Sep 17 00:00:00 2001
From: bugrain <bugrain@e107.org>
Date: Sat, 15 Aug 2009 01:00:38 +0000
Subject: [PATCH] Some updates to start making filter list code more generic

---
 e107_admin/ad_links.php                       | 18 ++++++++++++-----
 e107_files/jslib/core/admin.js                | 20 ++++++++++++-------
 e107_plugins/download/admin_download.php      |  6 +++---
 .../download/handlers/adminDownload_class.php | 15 ++++++--------
 4 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/e107_admin/ad_links.php b/e107_admin/ad_links.php
index fdedb0e49..673b94607 100644
--- a/e107_admin/ad_links.php
+++ b/e107_admin/ad_links.php
@@ -9,9 +9,9 @@
  * Admin Navigation
  *
  * $Source: /cvs_backup/e107_0.8/e107_admin/ad_links.php,v $
- * $Revision: 1.15 $
- * $Date: 2009-08-05 20:05:48 $
- * $Author: e107coders $
+ * $Revision: 1.16 $
+ * $Date: 2009-08-15 01:00:38 $
+ * $Author: bugrain $
 */
 
 if (!defined('e107_INIT')) { exit; }
@@ -145,6 +145,9 @@ if (!defined('E_16_CRON')) {
 if (!defined('E_16_CUST')) {
 	define('E_16_CUST', "<img class='icon S16' src='".e_IMAGE."admin_images/custom_16.png' alt='' />");
 }
+if (!defined('E_16_CUSTOMFIELD')) {
+	define('E_16_CUSTOMFIELD', "<img class='icon S16' src='".e_IMAGE."admin_images/custom_field_16.png' alt='' />");
+}
 if (!defined('E_16_DATAB')) {
 	define('E_16_DATAB', "<img class='icon S16' src='".e_IMAGE."admin_images/database_16.png' alt='' />");
 }
@@ -294,6 +297,9 @@ if (!defined('E_32_CRON')) {
 if (!defined('E_32_CUST')) {
 	define('E_32_CUST', "<img class='icon S32' src='".e_IMAGE."admin_images/custom_32.png' alt='' />");
 }
+if (!defined('E_32_CUSTOMFIELD')) {
+	define('E_32_CUSTOMFIELD', "<img class='icon S16' src='".e_IMAGE."admin_images/custom_field_32.png' alt='' />");
+}
 if (!defined('E_32_DATAB')) {
 	define('E_32_DATAB', "<img class='icon S32' src='".e_IMAGE."admin_images/database_32.png' alt='' />");
 }
@@ -430,6 +436,7 @@ $e_icon_array = array(
 	'credits' => E_32_CREDITS,
 	'cron'	=> E_32_CRON,
 	'custom' => E_32_CUST,
+	'custom_field' => E_32_CUSTOMFIELD,
 	'database' => E_32_DATAB,
 	'docs' => E_32_DOCS,
 	'download' => E_32_DOWNL,
@@ -581,8 +588,9 @@ $array_functions = array(
 	32 => array(e_ADMIN.'eurl.php', ADLAN_159, ADLAN_160, 'L', 1, E_16_EURL, E_32_EURL),
 	33 => array(e_ADMIN.'plugin.php', ADLAN_98, ADLAN_99, 'Z', 5 , E_16_PLUGMANAGER, E_32_PLUGMANAGER),
 	34 => array(e_ADMIN.'docs.php', ADLAN_12, ADLAN_13, '', 20, E_16_DOCS, E_32_DOCS),
-	35 => array('#TODO', 'System Info', 'System Information', '', 20, E_16_SYSINFO, E_32_SYSINFO),
-	36 => array(e_ADMIN.'credits.php', LAN_CREDITS, LAN_CREDITS, '', 20, E_16_CREDITS, E_32_CREDITS)
+	35 => array('#TODO', 'System Info', 'System Information', '', 20, '', ''),
+	36 => array(e_ADMIN.'credits.php', LAN_CREDITS, LAN_CREDITS, '', 20, '', ''),
+	37 => array(e_ADMIN.'custom_field.php', ADLAN_161, ADLAN_162, 'U', 4, E_16_CUSTOMFIELD, E_32_CUSTOMFIELD)
 );
 
 //FIXME  array structure suitable for e_admin_menu - see shortcodes/admin_navigation.php
diff --git a/e107_files/jslib/core/admin.js b/e107_files/jslib/core/admin.js
index be5dd1975..819fde79d 100644
--- a/e107_files/jslib/core/admin.js
+++ b/e107_files/jslib/core/admin.js
@@ -8,8 +8,8 @@
  * e107 Admin Helper
  *
  * $Source: /cvs_backup/e107_0.8/e107_files/jslib/core/admin.js,v $
- * $Revision: 1.19 $
- * $Date: 2009-08-15 00:03:05 $
+ * $Revision: 1.20 $
+ * $Date: 2009-08-15 01:00:38 $
  * $Author: bugrain $
  *
 */
@@ -307,6 +307,15 @@ if(e107Admin.initRules.AdminMenu)
 
 
 //TODO find the right place for this and make generic - wanted it out of download plugin for now
+// Current use:
+// - filter text field must be in a form
+// - form tag must have a class of e-filter-form
+// - form must have an id of jstarget-xxx where xxx is the ID of the element to be replaced by the Ajax response
+// - form action must be the URL to submit the Ajax request to
+// - ajax requests posts 3 values:
+//    - ajax_used = 1 - because of a current issue with e107Ajax.Updater
+//    - filter_list=1 - to indicate to called URL that this is a filter list request
+//    - the name/value of the st input field in the form, i.e. the one with the text to be searched for
 e107.runOnLoad(function(){
    $$('form.e-filter-form').each(function(f) {
       var el = f.select('input')[0];
@@ -320,12 +329,9 @@ e107.runOnLoad(function(){
    		   }
    		   el.e107PreviousValue = el.getValue();
    		   el.e107Timeout = window.setTimeout(function () {
-   				new e107Ajax.Updater('downloads-list', f.action, {
+   				new e107Ajax.Updater(f.id.replace(/jstarget-/, '').strip(), f.action, {
    					method: 'post',
-   					parameters: { //send query parameters here
-   						'download_filter_list': 1,
-   						'download-search-text': el.getValue()
-   					},
+   					parameters: 'ajax_used=1&filter_list=1&'+el.name+'='+el.getValue(),
    					overlayPage: $(document.body)
    				});
    	      }, 500);
diff --git a/e107_plugins/download/admin_download.php b/e107_plugins/download/admin_download.php
index 0c5bdf151..e6b784dca 100644
--- a/e107_plugins/download/admin_download.php
+++ b/e107_plugins/download/admin_download.php
@@ -11,8 +11,8 @@
 |     GNU General Public License (http://gnu.org).
 |
 |     $Source: /cvs_backup/e107_0.8/e107_plugins/download/admin_download.php,v $
-|     $Revision: 1.11 $
-|     $Date: 2009-08-14 23:22:37 $
+|     $Revision: 1.12 $
+|     $Date: 2009-08-15 01:00:38 $
 |     $Author: bugrain $
 +----------------------------------------------------------------------------+
 */
@@ -88,7 +88,7 @@ require_once (e_HANDLER.'message_handler.php');
 $emessage = &eMessage::getInstance();
 
 
-if(isset($_POST['download_filter_list']))
+if(isset($_POST['filter_list']))
 {
 	echo $adminDownload->show_existing_items($action, $subAction, $id, 0, 10);
 	exit;
diff --git a/e107_plugins/download/handlers/adminDownload_class.php b/e107_plugins/download/handlers/adminDownload_class.php
index 362ae1106..38fb1f89b 100644
--- a/e107_plugins/download/handlers/adminDownload_class.php
+++ b/e107_plugins/download/handlers/adminDownload_class.php
@@ -11,8 +11,8 @@
 |     GNU General Public License (http://gnu.org).
 |
 |     $Source: /cvs_backup/e107_0.8/e107_plugins/download/handlers/adminDownload_class.php,v $
-|     $Revision: 1.16 $
-|     $Date: 2009-08-14 23:22:37 $
+|     $Revision: 1.17 $
+|     $Date: 2009-08-15 01:00:38 $
 |     $Author: bugrain $
 |
 +----------------------------------------------------------------------------+
@@ -51,23 +51,20 @@ class adminDownload extends download
       $frm = new e_form();
 
       $filterColumns = ($user_pref['admin_download_disp'] ? $user_pref['admin_download_disp'] : array("download_name","download_class"));
-      $jsfunc = $ajax
-         ? "e107Ajax.toggleUpdate('{$id}-iconpicker', '{$id}-iconpicker-cn', 'sc:iconpicker=".urlencode($sc_parameters)."', '{$id}-iconpicker-ajax', { overlayElement: '{$id}-iconpicker-button' })"
-         : "e107Helper.toggle('{$id}-iconpicker')";
-	$url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => 123));
-	$url = "admin_download.php";
+	   $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => 123));
+	   $url = "admin_download.php";
 
       // Search field
       $text .= "
 		   <script type='text/javascript'>
 		   </script>
-         <form method='post' action='".e_SELF."' class='e-show-if-js'>
+         <form method='post' action='".e_SELF."' class='e-show-if-js e-filter-form' id='jstarget-downloads-list'>
             <div id='download_search'>
             <fieldset>
                <legend class='e-hideme'>".DOWLAN_194."</legend>
                <table class='adminlist'>
                   <tr>
-                     <td>".DOWLAN_198." ".$frm->text('download-search-text', $this->searchField, 50, array('size'=>50, 'other' => "onkeyup=\"{$jsfunc}\""))."&nbsp;<a href='#download_search#download_advanced_search' class='e-swapit'>Switch to Advanced-Search</a></td>
+                     <td>".DOWLAN_198." ".$frm->text('download-search-text', $this->searchField, 50, array('size'=>50, 'class' => 'someclass'))."&nbsp;<a href='#download_search#download_advanced_search' class='e-swapit'>Switch to Advanced-Search</a></td>
                   </tr>
                </table>