fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [7614] controller: XSLT alternative


From: Sigurd Nes
Subject: [Fmsystem-commits] [7614] controller: XSLT alternative
Date: Thu, 15 Sep 2011 19:18:19 +0000

Revision: 7614
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7614
Author:   sigurdne
Date:     2011-09-15 19:18:18 +0000 (Thu, 15 Sep 2011)
Log Message:
-----------
controller: XSLT alternative

Modified Paths:
--------------
    trunk/controller/inc/class.menu.inc.php
    trunk/controller/inc/class.uicommon.inc.php
    trunk/controller/inc/class.uicontrol_item2.inc.php

Added Paths:
-----------
    trunk/controller/js/yahoo/datatable.js
    trunk/controller/templates/base/datatable.xsl

Modified: trunk/controller/inc/class.menu.inc.php
===================================================================
--- trunk/controller/inc/class.menu.inc.php     2011-09-15 13:16:47 UTC (rev 
7613)
+++ trunk/controller/inc/class.menu.inc.php     2011-09-15 19:18:18 UTC (rev 
7614)
@@ -46,6 +46,15 @@
                                        'text'  => lang('Control_item') . 2,
                                        'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'controller.uicontrol_item2.index') ),
                            'image'     => array('property', 'location_1'),
+                                       'children'      => array(
+                                                               
'control_item_list2' => array
+
+                                                               (
+                                                                       'text'  
=> lang('control_item_list') . 2,
+                                                                       'url'   
=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol_item2.display_control_items', 'appname' => 'controller') 
),
+                                                                       'image' 
=> array('rental', 'x-office-spreadsheet')
+                                                               )
+                                                       )
                        ),
                                'procedure' => array
                                (

Modified: trunk/controller/inc/class.uicommon.inc.php
===================================================================
--- trunk/controller/inc/class.uicommon.inc.php 2011-09-15 13:16:47 UTC (rev 
7613)
+++ trunk/controller/inc/class.uicommon.inc.php 2011-09-15 19:18:18 UTC (rev 
7614)
@@ -131,13 +131,16 @@
                        array_push($this->tmpl_search_path, PHPGW_SERVER_ROOT . 
'/phpgwapi/templates/' . $GLOBALS['phpgw_info']['server']['template_set']);
                        array_push($this->tmpl_search_path, PHPGW_SERVER_ROOT . 
'/' . $GLOBALS['phpgw_info']['flags']['currentapp'] . '/templates/base');
                        phpgwapi_yui::load_widget('datatable');
+                       phpgwapi_yui::load_widget('history');
                        phpgwapi_yui::load_widget('paginator');
                        phpgwapi_yui::load_widget('menu');
                        phpgwapi_yui::load_widget('calendar');
                        phpgwapi_yui::load_widget('autocomplete');
                        phpgwapi_yui::load_widget('animation');
                        
-                       $dateFormat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $this->url_prefix = str_replace('_', '.', 
get_class($this));
+
+                       $this->dateFormat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
                        
                        $this->acl = & $GLOBALS['phpgw']->acl;
                        $this->locations = & $GLOBALS['phpgw']->locations;
@@ -426,19 +429,46 @@
                        }
                }
 
-               /**
-                * Build a YUI result of the data
-                * 
-                * @param $data the data
-                * @return YUI result { ResultSet => { totalRecords => ?, 
Result => ?}
-                */
-               public function yui_results($data,$field_total = 
'total_records', $field_results = 'results')
+               // Add link key to a result array
+               public function _add_links(&$value, $key, $menuaction)
                {
-             return array
-                       (   
+                       $unset = 0;
+                       // FIXME: Fugly workaround
+                       // I cannot figure out why this variable isn't set, but 
it is needed 
+                       // by the ->link() method, otherwise we wind up in the 
phpgroupware 
+                       // errorhandler which does lot of weird things and 
breaks the output
+                       if 
(!isset($GLOBALS['phpgw_info']['server']['webserver_url'])) {
+                               
$GLOBALS['phpgw_info']['server']['webserver_url'] = "/";
+                               $unset = 1;
+                       }
+
+                       $value['link'] = self::link(array('menuaction' => 
$menuaction, 'id' => $value['id']));
+
+                       // FIXME: Fugly workaround
+                       // I kid you not my friend. There is something very 
wonky going on 
+                       // in phpgroupware which I cannot figure out.
+                       // If this variable isn't unset() (if it wasn't set 
before that is) 
+                       // then it will contain extra slashes and break URLs
+                       if ($unset) {
+                               
unset($GLOBALS['phpgw_info']['server']['webserver_url']);
+                       }
+               }
+
+               // Build a YUI result style array
+               public function yui_results($results)
+               {
+                       if (!$results) {
+                               $results['total_records'] = 0;
+                               $result['results'] = array();
+                       }
+                       
+                       return array(   
                                'ResultSet' => array(
-                                       'totalRecords' => $data[$field_total], 
-                                       'Result' => $data[$field_results]
+                                       'totalResultsAvailable' => 
$results['total_records'], 
+                                       'startIndex' => $results['start'], 
+                                       'sortKey' => $results['sort'], 
+                                       'sortDir' => $results['dir'], 
+                                       'Result' => $results['results']
                                )   
                        );  
                }

Modified: trunk/controller/inc/class.uicontrol_item2.inc.php
===================================================================
--- trunk/controller/inc/class.uicontrol_item2.inc.php  2011-09-15 13:16:47 UTC 
(rev 7613)
+++ trunk/controller/inc/class.uicontrol_item2.inc.php  2011-09-15 19:18:18 UTC 
(rev 7614)
@@ -15,7 +15,8 @@
                
                public $public_functions = array
                (
-                       'index' =>      true
+                       'index'                                 => true,
+                       'display_control_items' => true
                );
 
                public function __construct()
@@ -29,8 +30,7 @@
                
                public function index()
                {
-                       $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
"controller::control_item2";
-                       
+                       self::set_active_menu('controller::control_item2');     
                
                        $repeat_type = $this->bo->get_rpt_type_list();
                        $repeat_day = $this->bo->get_rpt_day_list();
 
@@ -119,6 +119,242 @@
 
                        self::render_template_xsl('control_item', $data);
                }
+
+
+               public function display_control_items()
+               {
+                       
self::set_active_menu('controller::control_item2::control_item_list2');
+                       if(phpgw::get_var('phpgw_return_as') == 'json') {
+                               return $this->display_control_items_json();
+                       }
+                       $this->bo = CreateObject('booking.boapplication');
+                       $GLOBALS['phpgw_info']['apps']['manual']['section'] = 
'booking_manual';
+                       self::add_javascript('controller', 'yahoo', 
'datatable.js');
+                       phpgwapi_yui::load_widget('datatable');
+                       phpgwapi_yui::load_widget('paginator');
+
+                       $data = array(
+                               'form' => array(
+                                       'toolbar' => array(
+                                               'item' => array(
+                                                       array(
+                                                               'type' => 
'link',
+                                                               'value' => 
lang('New application'),
+                                                               'href' => 
self::link(array('menuaction' => 'controller.uicontrol_item2.index'))
+                                                       ),
+                                                       array('type' => 
'filter', 
+                                                               'name' => 
'status',
+                                'text' => lang('Status').':',
+                                'list' => array(
+                                    array(
+                                        'id' => 'none',
+                                        'name' => lang('Not selected')
+                                    ), 
+                                    array(
+                                        'id' => 'NEW',
+                                        'name' => lang('NEW')
+                                    ), 
+                                    array(
+                                        'id' => 'PENDING',
+                                        'name' =>  lang('PENDING')
+                                    ), 
+                                    array(
+                                        'id' => 'REJECTED',
+                                        'name' => lang('REJECTED')
+                                    ), 
+                                    array(
+                                        'id' => 'ACCEPTED',
+                                        'name' => lang('ACCEPTED')
+                                    )
+                                )
+                            ),
+                                                       array('type' => 
'filter', 
+                                                               'name' => 
'buildings',
+                                'text' => lang('Building').':',
+                                'list' => $this->bo->so->get_buildings(),
+                                                       ),
+                                                       array('type' => 
'filter', 
+                                                               'name' => 
'activities',
+                                'text' => lang('Activity').':',
+                                'list' => 
$this->bo->so->get_activities_main_level(),
+                                                       ),
+                                                       array('type' => 'text', 
+                                'text' => lang('searchfield'),
+                                                               'name' => 
'query'
+                                                       ),
+                                                       array(
+                                                               'type' => 
'submit',
+                                                               'name' => 
'search',
+                                                               'value' => 
lang('Search')
+                                                       ),
+                                                       array(
+                                                               'type' => 
'link',
+                                                               'value' => 
$_SESSION['showall'] ? lang('Show only active') : lang('Show all'),
+                                                               'href' => 
self::link(array('menuaction' => $this->url_prefix.'.toggle_show_inactive'))
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                               'datatable' => array(
+                                       'source' => 
self::link(array('menuaction' => 
'controller.uicontrol_item2.display_control_items', 'phpgw_return_as' => 
'json')),
+                                       'field' => array(
+                                               array(
+                                                       'key' => 'id',
+                                                       'label' => lang('ID'),
+                                                       'sortable'      => true,
+                                                       'formatter' => 
'YAHOO.portico.formatLink'
+                                               ),
+                                               array(
+                                                       'key' => 'status',
+                                                       'label' => 
lang('Status'),
+                                                       'sortable'      => false
+                                               ),
+                                               array(
+                                                       'key' => 
'building_name',
+                                                       'label' => 
lang('Building'),
+                                                       'sortable'      => true
+                                               ),
+                                               array(
+                                                       'key' => 'what',
+                                                       'label' => lang('What'),
+                                                       'sortable'      => false
+                                               ),
+                                               array(
+                                                       'key' => 'created',
+                                                       'label' => 
lang('Created'),
+                                                       'sortable'      => true
+                                               ),
+                                               array(
+                                                       'key' => 'modified',
+                                                       'label' => lang('last 
modified'),
+                                                       'sortable'      => true
+                                               ),
+                                               array(
+                                                       'key' => 
'activity_name',
+                                                       'label' => 
lang('Activity'),
+                                                       'sortable'      => true
+                                               ),
+                                               array(
+                                                       'key' => 'contact_name',
+                                                       'label' => 
lang('Contact'),
+                                                       'sortable'      => true
+                                               ),
+                                               array(
+                                                       'key' => 'link',
+                                                       'hidden' => true
+                                               )
+                                       )
+                               ),
+                       );
+//_debug_array($data);
+
+                       self::render_template_xsl('datatable', $data);
+               }
+
+               public function display_control_items_json()
+               {
+                       $this->bo = CreateObject('booking.boapplication');
+                       $this->resource_bo = CreateObject('booking.boresource');
+
+                       if ( 
!isset($GLOBALS['phpgw_info']['user']['apps']['admin']) &&
+                            $GLOBALS['phpgw']->acl->check('admin', 
phpgwapi_acl::ADD, 'controller') )
+                       {
+                               $filters['id'] = 
$this->bo->accessable_applications($GLOBALS['phpgw_info']['user']['id']);
+                       }
+                       $filters['status'] = 'NEW';
+                       if(isset($_SESSION['showall']))
+                       {
+                               $filters['status'] = array('NEW', 
'PENDING','REJECTED', 'ACCEPTED');
+                $testdata =  phpgw::get_var('buildings', 'int', 'REQUEST', 
null);
+                if ($testdata != 0)
+                {
+                    $filters['building_name'] = 
$this->bo->so->get_building(phpgw::get_var('buildings', 'int', 'REQUEST', 
null));        
+                }
+                else
+                {
+                    unset($filters['building_name']);                
+                }
+                $testdata2 =  phpgw::get_var('activities', 'int', 'REQUEST', 
null);
+                if ($testdata2 != 0)
+                {
+                    $filters['activity_id'] = 
$this->bo->so->get_activities(phpgw::get_var('activities', 'int', 'REQUEST', 
null));        
+                }
+                else
+                {
+                    unset($filters['activity_id']);                
+                }
+                
+                       }
+                       else
+                       {
+                               if (phpgw::get_var('status') == 'none')
+                               {
+                                       $filters['status'] = array('NEW', 
'PENDING', 'REJECTED', 'ACCEPTED');
+                               } 
+                               else
+                               {
+                       $filters['status'] = phpgw::get_var('status');
+                               }
+                $testdata =  phpgw::get_var('buildings', 'int', 'REQUEST', 
null);
+                if ($testdata != 0)
+                {
+                    $filters['building_name'] = 
$this->bo->so->get_building(phpgw::get_var('buildings', 'int', 'REQUEST', 
null));        
+                }
+                else
+                {
+                    unset($filters['building_name']);                
+                }
+                $testdata2 =  phpgw::get_var('activities', 'int', 'REQUEST', 
null);
+                if ($testdata2 != 0)
+                {
+                    $filters['activity_id'] = 
$this->bo->so->get_activities(phpgw::get_var('activities', 'int', 'REQUEST', 
null));        
+                }
+                else
+                {
+                    unset($filters['activity_id']);                
+                }
+            }
+
+                       $params = array(
+                               'start' => phpgw::get_var('startIndex', 'int', 
'REQUEST', 0),
+                               'results' => phpgw::get_var('results', 'int', 
'REQUEST', null),
+                               'query' => phpgw::get_var('query'),
+                               'sort'  => phpgw::get_var('sort'),
+                               'dir'   => phpgw::get_var('dir'),
+                               'filters' => $filters
+                       );
+
+                       $applications = $this->bo->so->read($params);
+
+                       foreach($applications['results'] as &$application)
+                       {
+                               if (strstr($application['building_name'],"%"))
+                               {
+                                       $search = array('%2C','%C3%85', 
'%C3%A5', '%C3%98', '%C3%B8', '%C3%86', '%C3%A6');
+                                       $replace = array 
(',','Å','å','Ø','ø','Æ','æ');
+                                       $application['building_name'] = 
str_replace($search, $replace, $application['building_name']);
+                               }
+
+                               $application['status'] = 
lang($application['status']);
+                               $application['created'] = 
pretty_timestamp($application['created']);
+                               $application['modified'] = 
pretty_timestamp($application['modified']);
+                               $application['frontend_modified'] = 
pretty_timestamp($application['frontend_modified']);
+                               $application['resources'] = 
$this->resource_bo->so->read(array('filters'=>array('id'=>$application['resources'])));
+                               $application['resources'] = 
$application['resources']['results'];
+                               if($application['resources'])
+                               {
+                                       $names = array();
+                                       foreach($application['resources'] as 
$res)
+                                       {
+                                               $names[] = $res['name'];
+                                       }
+                                       $application['what'] = 
$application['resources'][0]['building_name']. ' ('.join(', ', $names).')';
+                               }
+                       }
+                       array_walk($applications["results"], array($this, 
"_add_links"), "controller.uicontrol_item2.index");
+
+                       return $this->yui_results($applications);
+               }
                                        
 
                public function query()

Added: trunk/controller/js/yahoo/datatable.js
===================================================================
--- trunk/controller/js/yahoo/datatable.js                              (rev 0)
+++ trunk/controller/js/yahoo/datatable.js      2011-09-15 19:18:18 UTC (rev 
7614)
@@ -0,0 +1,170 @@
+YAHOO.portico.setupToolbar = function() {
+       YAHOO.portico.renderUiFormItems('toolbar');
+};
+
+YAHOO.portico.setupListActions = function() {
+       YAHOO.portico.renderUiFormItems('list_actions');
+};
+
+YAHOO.portico.renderUiFormItems = function(container) {
+       var items = YAHOO.util.Dom.getElementsBy(function(){return true;}, 
'input', container);
+   for(var i=0; i < items.length; i++) {
+       var type = items[i].getAttribute('type');
+       if(type == 'link') {
+           new YAHOO.widget.Button(items[i], 
+                                   {type: 'link', 
+                                    href: items[i].getAttribute('href')});
+       }
+       else if(type == 'submit') {
+           new YAHOO.widget.Button(items[i], {type: 'submit'});
+       }
+   }
+};
+
+YAHOO.portico.setupPaginator = function() {
+       var paginatorConfig = {
+        rowsPerPage: 10,
+        alwaysVisible: false,
+        template: "{PreviousPageLink} <strong>{CurrentPageReport}</strong> 
{NextPageLink}",
+        pageReportTemplate: "Showing items {startRecord} - {endRecord} of 
{totalRecords}",
+        containers: ['paginator']
+    };
+       
+       YAHOO.portico.lang('setupPaginator', paginatorConfig);
+       var pag = new YAHOO.widget.Paginator(paginatorConfig);
+    pag.render();
+       return pag;
+};
+
+YAHOO.portico.preSerializeQueryFormListeners = new Array();
+
+       YAHOO.portico.addPreSerializeQueryFormListener = function(func) {
+       YAHOO.portico.preSerializeQueryFormListeners.push(func);
+}
+
+YAHOO.portico.preSerializeQueryForm = function(form) {
+       for (var key in YAHOO.portico.preSerializeQueryFormListeners) {
+               YAHOO.portico.preSerializeQueryFormListeners[key](form);
+       }
+}
+
+YAHOO.portico.initializeDataTable = function()
+{
+       YAHOO.portico.setupToolbar();
+       YAHOO.portico.setupListActions();
+       YAHOO.portico.setupDatasource();
+       var pag = YAHOO.portico.setupPaginator();
+
+    var fields = [];
+    for(var i=0; i < YAHOO.portico.columnDefs.length; i++) {
+        fields.push(YAHOO.portico.columnDefs[i].key);
+    }
+    var baseUrl = YAHOO.portico.dataSourceUrl;
+    if(baseUrl[baseUrl.length - 1] != '&') {
+        baseUrl += '&';
+    }
+    
+    if (YAHOO.portico.initialSortedBy) {
+      baseUrl += 'sort=' + YAHOO.portico.initialSortedBy.key + '&dir=' + 
YAHOO.portico.initialSortedBy.dir;
+    } else {
+      baseUrl += 'sort=' + fields[0];
+    }
+       
+         baseUrl += '&results=' + pag.getRowsPerPage() + '&';
+    var myDataSource = new YAHOO.util.DataSource(baseUrl);
+
+    myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
+    myDataSource.connXhrMode = "queueRequests";
+    myDataSource.responseSchema = {
+        resultsList: "ResultSet.Result",
+        fields: fields,
+        metaFields : {
+            totalResultsAvailable: "ResultSet.totalResultsAvailable",
+                       startIndex: 'ResultSet.startIndex',
+                       sortKey: 'ResultSet.sortKey',
+                       sortDir: 'ResultSet.sortDir'
+        }
+    };
+    var myDataTable = new YAHOO.widget.DataTable("datatable-container", 
+        YAHOO.portico.columnDefs, myDataSource, {
+            paginator: pag,
+            dynamicData: true,
+            sortedBy: YAHOO.portico.initialSortedBy || {key: fields[0], dir: 
YAHOO.widget.DataTable.CLASS_ASC}
+    });
+    var handleSorting = function (oColumn) {
+        var sDir = this.getColumnSortDir(oColumn);
+        var newState = getState(oColumn.key, sDir);
+        History.navigate("state", newState);
+    };
+    myDataTable.sortColumn = handleSorting;
+
+    var handlePagination = function(state) {
+        var sortedBy  = this.get("sortedBy");
+        var newState = getState(sortedBy.key, sortedBy.dir, 
state.recordOffset);
+        History.navigate("state", newState);
+     };
+    pag.unsubscribe("changeRequest", myDataTable.onPaginatorChangeRequest);
+    pag.subscribe("changeRequest", handlePagination, myDataTable, true);
+    myDataTable.doBeforeLoadData = function(oRequest, oResponse, oPayload) {
+        oPayload.totalRecords = oResponse.meta.totalResultsAvailable;
+               oPayload.pagination = { 
+                       rowsPerPage: oResponse.meta.paginationRowsPerPage || 
10, 
+                       recordOffset: oResponse.meta.startIndex || 0 
+           }
+               oPayload.sortedBy = { 
+                       key: oResponse.meta.sortKey || "id", 
+                       dir: (oResponse.meta.sortDir) ? "yui-dt-" + 
oResponse.meta.sortDir : "yui-dt-asc" 
+               };
+               return true;
+    }
+        
+    YAHOO.util.Event.addListener('queryForm', "submit", function(e){
+        YAHOO.util.Event.stopEvent(e);
+               var state = getState();
+               YAHOO.util.Dom.setStyle('list_flash', 'display', 'none');
+               History.navigate('state', state);
+    });
+
+       YAHOO.util.Event.addListener('list_actions_form', "submit", function(e){
+               YAHOO.util.Event.stopEvent(e);
+               window.setTimeout(function() {
+                       var state = getState();
+                       var action = myDataSource.liveData + '&' + state;
+                       action = action.replace('&phpgw_return_as=json', '');
+                       
YAHOO.util.Dom.setAttribute(document.getElementById('list_actions_form'), 
'action', action);
+                  document.getElementById('list_actions_form').submit();
+               }, 0);
+       });
+
+       var History = YAHOO.util.History; 
+       var getState = function(skey, sdir, start) {
+               var state = YAHOO.portico.serializeForm('queryForm');
+               var sortedBy  = myDataTable.get("sortedBy");
+               skey = skey ? skey : sortedBy.key;
+               sdir = sdir ? sdir : sortedBy.dir; 
+               sdir = sdir == 'yui-dt-asc' ? 'asc' : 'desc';
+               start = start ? start : 0;
+               state += '&sort=' + skey;
+               state += '&dir=' + sdir;
+               state += '&startIndex=' + start;
+               return state;
+       }
+
+       var handleHistoryNavigation = function (state) {
+               var params = YAHOO.portico.parseQS(state);
+               YAHOO.portico.fillForm('queryForm', params);
+               myDataSource.sendRequest(state, {success: function(sRequest, 
oResponse, oPayload) {
+                       myDataTable.onDataReturnInitializeTable(sRequest, 
oResponse, pag);
+               }});
+       };
+       
+       var initialRequest = History.getBookmarkedState("state") || getState();
+       History.register("state", initialRequest, handleHistoryNavigation);
+       History.onReady(function() {
+               var state = YAHOO.util.History.getCurrentState('state');
+               handleHistoryNavigation(state);
+       });
+       History.initialize("yui-history-field", "yui-history-iframe");
+};
+
+YAHOO.util.Event.addListener(window, "load", 
YAHOO.portico.initializeDataTable);

Added: trunk/controller/templates/base/datatable.xsl
===================================================================
--- trunk/controller/templates/base/datatable.xsl                               
(rev 0)
+++ trunk/controller/templates/base/datatable.xsl       2011-09-15 19:18:18 UTC 
(rev 7614)
@@ -0,0 +1,239 @@
+<func:function name="phpgw:conditional">
+       <xsl:param name="test"/>
+       <xsl:param name="true"/>
+       <xsl:param name="false"/>
+
+       <func:result>
+               <xsl:choose>
+                       <xsl:when test="$test">
+                       <xsl:value-of select="$true"/>
+                       </xsl:when>
+                       <xsl:otherwise>
+                               <xsl:value-of select="$false"/>
+                       </xsl:otherwise>
+               </xsl:choose>
+       </func:result>
+</func:function>
+
+<xsl:template match="data">
+       <iframe id="yui-history-iframe" 
src="phpgwapi/js/yahoo/history/assets/blank.html" 
style="position:absolute;top:0; left:0;width:1px; 
height:1px;visibility:hidden;"></iframe>
+       <input id="yui-history-field" type="hidden"/>
+       <xsl:call-template name="yui_booking_i18n"/>
+       <xsl:apply-templates select="form" />
+       <xsl:apply-templates select="paging"/>
+       <div id="list_flash">
+               <xsl:call-template name="msgbox"/>
+       </div>
+       <xsl:apply-templates select="datatable"/> 
+       <xsl:apply-templates select="form/list_actions"/>
+</xsl:template>
+
+<xsl:template match="toolbar">
+    <div id="toolbar">
+                 <table class='yui-skin-sam' border="0" cellspacing="0" 
cellpadding="0" style="padding:0px; margin:0px;">
+                       <tr>
+        <xsl:for-each select="item">
+                       <xsl:variable name="filter_key" 
select="concat('filter_', name)"/>
+                       <xsl:variable name="filter_key_name" 
select="concat(concat('filter_', name), '_name')"/>
+                       <xsl:variable name="filter_key_id" 
select="concat(concat('filter_', name), '_id')"/>
+               
+                       <xsl:choose>
+                               <xsl:when test="type = 'date-picker'">
+                                       <td valign="top">
+                                       <div class="date-picker">
+                       <input id="filter_{name}" name="filter_{name}" 
type="text">
+                                                       <xsl:attribute 
name="value"><xsl:value-of select="../../../filters/*[local-name() = 
$filter_key]"/></xsl:attribute>
+                                               </input>
+                </div>
+                                       </td>
+                               </xsl:when>
+                               <xsl:when test="type = 'autocomplete'">
+                                       <td valign="top" width="160px">
+                                               <div style="width:140px">
+                                                       <input 
id="filter_{name}_name" name="filter_{name}_name" type="text">
+                                                               <xsl:attribute 
name="value"><xsl:value-of select="../../../filters/*[local-name() = 
$filter_key_name]"/></xsl:attribute>
+                                                       </input>
+                                                       <input 
id="filter_{name}_id" name="filter_{name}_id" type="hidden">
+                                                               <xsl:attribute 
name="value"><xsl:value-of select="../../../filters/*[local-name() = 
$filter_key_id]"/></xsl:attribute>
+                                                       </input>
+                                                       <div 
id="filter_{name}_container"/>
+                                               </div>
+                                               <script type="text/javascript"> 
+                                               
YAHOO.util.Event.onDOMReady(function() {
+                                                  var name = "<xsl:value-of 
select="name"/>";
+                                                       var ui = "<xsl:value-of 
select="ui"/>";
+
+                                                       var itemSelectCallback 
= false;
+                                                       <xsl:if 
test="onItemSelect">
+                                                               
itemSelectCallback = <xsl:value-of select="onItemSelect"/>;
+                                                       </xsl:if>
+
+                                                       var 
onClearSelectionCallback = false;
+                                                       <xsl:if 
test="onClearSelection">
+                                                               
onClearSelectionCallback = <xsl:value-of select="onClearSelection"/>;
+                                                       </xsl:if>
+
+                                                       var requestGenerator = 
false;
+                                                       <xsl:if 
test="requestGenerator">
+                                                               
requestGenerator = <xsl:value-of select="requestGenerator"/>;
+                                                       </xsl:if>
+
+                                                       <![CDATA[
+                                                       var oAC = 
YAHOO.portico.autocompleteHelper('index.php?menuaction=booking.ui'+ui+'.index&phpgw_return_as=json&',
 
+                                                                               
 'filter_'+name+'_name', 'filter_'+name+'_id', 'filter_'+name+'_container');
+
+                                                       if (requestGenerator) {
+                                                               
oAC.generateRequest = requestGenerator;
+                                                       }
+
+                                                       if (itemSelectCallback) 
{
+                                                               
oAC.itemSelectEvent.subscribe(itemSelectCallback);
+                                                       }
+
+                                                       
YAHOO.util.Event.addBlurListener('filter_'+name+'_name', function() {
+                                                               if 
(YAHOO.util.Dom.get('filter_'+name+'_name').value == "") {
+                                                                       
YAHOO.util.Dom.get('filter_'+name+'_id').value = "";
+                                                                       if 
(onClearSelectionCallback) {
+                                                                               
onClearSelectionCallback();
+                                                                       }
+                                                               }
+                                                       });
+
+                                                       
YAHOO.portico.addPreSerializeQueryFormListener(function(form) {
+                                                               if 
(YAHOO.util.Dom.get('filter_'+name+'_name').value == "") {
+                                                                       
YAHOO.util.Dom.get('filter_'+name+'_id').value = "";
+                                                               } 
+                                                       });
+                                                       ]]>
+                                               });
+                                               </script>
+                                       </td>
+                               </xsl:when>
+                               <xsl:when test="type = 'filter'">
+                                       <td valign="top">
+                    <xsl:variable name="name"><xsl:value-of 
select="name"/></xsl:variable>
+                       <select name="{$name}" 
onMouseout="window.status='';return true;">
+                        <xsl:for-each select="list">
+                               <xsl:variable name="id"><xsl:value-of 
select="id"/></xsl:variable>
+                                                       <xsl:if test="id = 
'NEW'">
+                                       <option value="{$id}" 
selected="selected">
+                                                                       
<xsl:value-of select="name"/>
+                                                               </option>
+                                                       </xsl:if>
+                                                       <xsl:if test="id != 
'NEW'">
+                                       <option value="{$id}">
+                                                                       
<xsl:value-of select="name"/>
+                                                               </option>
+                                                       </xsl:if>
+                        </xsl:for-each>
+                       </select>
+                    </td>
+                               </xsl:when>
+                               <xsl:otherwise>
+                                       <td valign="top">
+                                       <input id="innertoolbar">
+                                               <xsl:attribute 
name="type"><xsl:value-of select="phpgw:conditional(not(type), '', 
type)"/></xsl:attribute>
+                                               <xsl:attribute 
name="name"><xsl:value-of select="phpgw:conditional(not(name), '', 
name)"/></xsl:attribute>
+                                               <xsl:attribute 
name="onclick"><xsl:value-of select="phpgw:conditional(not(onClick), '', 
onClick)"/></xsl:attribute>
+                                               <xsl:attribute 
name="value"><xsl:value-of select="phpgw:conditional(not(value), '', 
value)"/></xsl:attribute>
+                                               <xsl:attribute 
name="href"><xsl:value-of select="phpgw:conditional(not(href), '', 
href)"/></xsl:attribute>
+                                       </input>
+                                       </td>
+                               </xsl:otherwise>
+                       </xsl:choose>
+        </xsl:for-each>
+                 </tr>
+                       <xsl:if test="item/text and normalize-space(item/text)">
+                               <thead style="background:none">
+                                       <tr>
+                                               <xsl:for-each select="item">
+                                                       <td>
+                                                               <xsl:if 
test="name">
+                                                                       <label 
style='margin:auto 0.25em'>
+                                                                               
<xsl:attribute name="for"><xsl:value-of select="phpgw:conditional(not(name), 
'', name)"/></xsl:attribute>
+                                                                               
<xsl:value-of select="phpgw:conditional(not(text), '', text)"/>
+                                                                       </label>
+                                                               </xsl:if>
+                                                       </td>
+                                               </xsl:for-each>
+                                       </tr>
+                               </thead>
+                       </xsl:if>
+               </table>
+    </div>
+</xsl:template>
+
+<xsl:template match="form/list_actions">
+       <form id="list_actions_form" method="POST">
+               <!-- Form action is set by javascript listener -->
+               <div id="list_actions" class='yui-skin-sam'>
+                       <table cellpadding="0" cellspacing="0">
+                               <tr>
+                                       <xsl:for-each select="item">
+                                               <td valign="top">
+                                                       <input 
id="innertoolbar">
+                                                               <xsl:attribute 
name="type"><xsl:value-of select="phpgw:conditional(not(type), '', 
type)"/></xsl:attribute>
+                                                               <xsl:attribute 
name="name"><xsl:value-of select="phpgw:conditional(not(name), '', 
name)"/></xsl:attribute>
+                                                               <xsl:attribute 
name="onclick"><xsl:value-of select="phpgw:conditional(not(onClick), '', 
onClick)"/></xsl:attribute>
+                                                               <xsl:attribute 
name="value"><xsl:value-of select="phpgw:conditional(not(value), '', 
value)"/></xsl:attribute>
+                                                               <xsl:attribute 
name="href"><xsl:value-of select="phpgw:conditional(not(href), '', 
href)"/></xsl:attribute>
+                                                       </input>
+                                               </td>
+                                       </xsl:for-each>
+                               </tr>
+                       </table>
+               </div>
+       </form>
+</xsl:template>
+<xsl:template match="form">
+       <form id="queryForm">
+               <xsl:attribute name="method">
+                       <xsl:value-of select="phpgw:conditional(not(method), 
'GET', method)"/>
+               </xsl:attribute>
+
+               <xsl:attribute name="action">
+                       <xsl:value-of select="phpgw:conditional(not(action), 
'', action)"/>
+               </xsl:attribute>
+        <xsl:apply-templates select="toolbar"/>
+       </form>
+</xsl:template>
+
+<xsl:template match="datatable">
+    <div id="paginator"/>
+    <div id="datatable-container"/>
+       <xsl:call-template name="datasource-definition" />
+</xsl:template>
+
+<xsl:template name="datasource-definition">
+       <script>
+               YAHOO.portico.setupDatasource = function() {
+                       <xsl:if test="source">
+                   YAHOO.portico.dataSourceUrl = '<xsl:value-of 
select="source"/>';
+                                       YAHOO.portico.initialSortedBy = false;
+                                       YAHOO.portico.initialFilters = false;
+                                       <xsl:if test="sorted_by">
+                                               YAHOO.portico.initialSortedBy = 
{key: '<xsl:value-of select="sorted_by/key"/>', dir: '<xsl:value-of 
select="sorted_by/dir"/>'};
+                                       </xsl:if>
+               </xsl:if>
+
+                       YAHOO.portico.columnDefs = [
+                               <xsl:for-each select="//datatable/field">
+                                       {
+                                               key: "<xsl:value-of 
select="key"/>",
+                                               <xsl:if test="label">
+                                               label: "<xsl:value-of 
select="label"/>",
+                                           </xsl:if>
+                                               sortable: <xsl:value-of 
select="phpgw:conditional(not(sortable = 0), 'true', 'false')"/>,
+                                               <xsl:if test="hidden">
+                                               hidden: true,
+                                           </xsl:if>
+                                               <xsl:if test="formatter">
+                                               formatter: <xsl:value-of 
select="formatter"/>,
+                                           </xsl:if>
+                                               className: "<xsl:value-of 
select="className"/>"
+                                       }<xsl:value-of 
select="phpgw:conditional(not(position() = last()), ',', '')"/>
+                               </xsl:for-each>
+                       ];
+               }
+       </script>
+</xsl:template>




reply via email to

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