fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [10278] property: autocomplete as custom field


From: Sigurd Nes
Subject: [Fmsystem-commits] [10278] property: autocomplete as custom field
Date: Sat, 20 Oct 2012 13:40:37 +0000

Revision: 10278
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10278
Author:   sigurdne
Date:     2012-10-20 13:40:37 +0000 (Sat, 20 Oct 2012)
Log Message:
-----------
property:  autocomplete as custom field

Modified Paths:
--------------
    trunk/property/inc/class.custom_fields.inc.php
    trunk/property/inc/class.uientity.inc.php
    trunk/property/templates/base/attributes_form.xsl

Modified: trunk/property/inc/class.custom_fields.inc.php
===================================================================
--- trunk/property/inc/class.custom_fields.inc.php      2012-10-20 13:36:12 UTC 
(rev 10277)
+++ trunk/property/inc/class.custom_fields.inc.php      2012-10-20 13:40:37 UTC 
(rev 10278)
@@ -67,6 +67,8 @@
                 */
                public function prepare($values, $appname, $location, 
$view_only='')
                {
+                       $cache_custom_lookup = array();
+
                        $vendor                 = 
CreateObject('property.sogeneric');
                        $vendor->get_location_info('vendor',false);
 
@@ -236,10 +238,21 @@
                                else if($attributes['datatype'] == 'custom1') 
// select
                                {
                                        $attributes['choice'] = array();
+
                                        if($attributes['get_list_function'])
                                        {
-                                               $attributes['choice'] = 
execMethod($attributes['get_list_function'], 
$attributes['get_list_function_input']);
+                                               $_compare_key = 
$this->_get_compare_key($attributes['get_list_function'], 
$attributes['get_list_function_input']);
+                                               
if(isset($cache_custom_lookup[$_compare_key]))
+                                               {
+                                                       $attributes['choice'] = 
$cache_custom_lookup[$_compare_key];
+                                               }
+                                               else
+                                               {
+                                                       $attributes['choice'] = 
execMethod($attributes['get_list_function'], 
$attributes['get_list_function_input']);
+                                                       
$cache_custom_lookup[$_compare_key] = $attributes['choice'];
+                                               }
                                        }
+
                                        foreach ($attributes['choice'] as 
&$_choice)
                                        {
                                                $_choice['selected'] = 
$_choice['id'] == $attributes['value'] ? 1 : 0;
@@ -268,6 +281,48 @@
                                        $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","left=50,top=100,width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
                                        $m++;
                                }
+                               else if($attributes['datatype'] == 'custom3') 
//autocomplete
+                               {
+                                       if($attributes['value'] && 
$attributes['get_single_function'])
+                                       {
+                                               
if(!$attributes['get_single_function_input'])
+                                               {
+                                                       
$attributes['get_single_function_input'] = $attributes['value'];
+                                               }
+                                               $attributes['custom_name'] = 
execMethod($attributes['get_single_function'], 
$attributes['get_single_function_input']);
+                                       }
+
+                                       $insert_record_values[]                 
= $attributes['name'];
+                                       $lookup_link                            
        = $GLOBALS['phpgw']->link('/index.php',array(
+                                               'menuaction'                    
=> 'property.uilookup.custom',
+                                               'column'                        
        => $attributes['name'],
+                                               'get_list_function'             
=> $attributes['get_list_function'],
+                                               'get_list_function_input'       
=> urlencode(serialize($attributes['get_list_function_input']))
+                                       ));
+
+
+                                       $_append_url = '';
+                                       
if(isset($attributes['get_list_function_input']) && 
is_array($attributes['get_list_function_input']))
+                                       {
+                                               $_append_url = '&' . 
http_build_query($attributes['get_list_function_input']);
+                                       }
+
+                                       $_autocomplete = <<<JS
+
+                                       YAHOO.util.Event.addListener(window, 
"load", function()
+                                       {
+                                               var oArgs = 
{menuaction:'{$attributes['get_list_function']}'};
+                                               var strURL = 
phpGWLink('index.php', oArgs, true);
+                                               strURL += '{$_append_url}';
+
+                                           
YAHOO.portico.autocompleteHelper(strURL, 
+                               '{$attributes['name']}_name', 
'{$attributes['name']}_id', '{$attributes['name']}_container');
+
+                                       });
+JS;
+                                       $GLOBALS['phpgw']->js->add_code('', 
$_autocomplete);
+
+                               }
                                else if($attributes['datatype'] == 'user')
                                {
                                        if($attributes['value'])
@@ -412,6 +467,30 @@
                        return $values;
                }
 
+
+               protected function _get_compare_key($get_list_function, 
$get_list_function_input)
+               {
+                       $_compare_key = '';
+                       $_compare_key .= $get_list_function;
+                       if($get_list_function_input)
+                       {
+                               if (is_array($get_list_function_input))
+                               {
+                                       foreach($get_list_function_input as 
$_key => $_value)
+                                       {
+                                               $_compare_key .= $_key;
+                                               $_compare_key .= $_value;
+                                       }
+                               }
+                               else
+                               {
+                                               $_compare_key .= 
$get_list_function_input;
+                               }
+                       }
+                       return md5($_compare_key);
+               }
+
+
                function prepare_for_db($table, $values_attribute, $id = 0)
                {       
                        $id = (int)$id;

Modified: trunk/property/inc/class.uientity.inc.php
===================================================================
--- trunk/property/inc/class.uientity.inc.php   2012-10-20 13:36:12 UTC (rev 
10277)
+++ trunk/property/inc/class.uientity.inc.php   2012-10-20 13:40:37 UTC (rev 
10278)
@@ -2049,6 +2049,10 @@
                        phpgwapi_yui::load_widget('paginator');
                        phpgwapi_yui::load_widget('animation');
 
+                       phpgwapi_yui::load_widget('autocomplete');
+
+                       $GLOBALS['phpgw']->js->validate_file( 'yahoo', 
'common', 'phpgwapi' );
+
                        
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/examples/treeview/assets/css/folders/tree.css');
                        phpgwapi_yui::load_widget('treeview');
                        $appname        = $entity['name'];

Modified: trunk/property/templates/base/attributes_form.xsl
===================================================================
--- trunk/property/templates/base/attributes_form.xsl   2012-10-20 13:36:12 UTC 
(rev 10277)
+++ trunk/property/templates/base/attributes_form.xsl   2012-10-20 13:40:37 UTC 
(rev 10278)
@@ -313,6 +313,37 @@
                                                                        
</xsl:choose>
                                                                </input>
                                                        </xsl:when>
+                                                       <xsl:when 
test="datatype='custom3'">
+                                                               <xsl:variable 
name="custom_id">
+                                                                       
<xsl:value-of select="name"/>
+                                                                       
<xsl:text>_id</xsl:text>
+                                                               </xsl:variable>
+
+                                                               <xsl:variable 
name="custom_name">
+                                                                       
<xsl:value-of select="name"/>
+                                                                       
<xsl:text>_name</xsl:text>
+                                                               </xsl:variable>
+
+                                                               <xsl:variable 
name="custom_container">
+                                                                       
<xsl:value-of select="name"/>
+                                                                       
<xsl:text>_container</xsl:text>
+                                                               </xsl:variable>
+
+                                           <input id="{$custom_id}" 
name="{$custom_id}" type="hidden" value="{value}">
+                                           </input>
+                                           <input id="{$custom_name}" 
name="{$custom_name}" type="text" value="{custom_name}">
+                                                                       
<xsl:choose>
+                                                                               
<xsl:when test="disabled!=''">
+                                                                               
        <xsl:attribute name="disabled">
+                                                                               
                <xsl:text> disabled</xsl:text>
+                                                                               
        </xsl:attribute>
+                                                                               
</xsl:when>
+                                                                       
</xsl:choose>
+
+                                           </input>
+                                           <div id="{$custom_container}"/>
+
+                                                       </xsl:when>
                                                        <xsl:when 
test="datatype='user'">
                                                                <xsl:variable 
name="user_name">
                                                                        
<xsl:value-of select="name"/>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]