fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [9597] controller: serverbased pagination


From: Sigurd Nes
Subject: [Fmsystem-commits] [9597] controller: serverbased pagination
Date: Thu, 14 Jun 2012 13:27:19 +0000

Revision: 9597
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9597
Author:   sigurdne
Date:     2012-06-14 13:27:19 +0000 (Thu, 14 Jun 2012)
Log Message:
-----------
controller: serverbased pagination

Modified Paths:
--------------
    trunk/controller/inc/class.uicontrol_location.inc.php
    trunk/controller/js/controller/ajax_control_to_component.js
    
trunk/controller/templates/base/control_location/register_control_to_component.xsl

Added Paths:
-----------
    trunk/controller/js/yahoo/register_control_to_component2.js

Modified: trunk/controller/inc/class.uicontrol_location.inc.php
===================================================================
--- trunk/controller/inc/class.uicontrol_location.inc.php       2012-06-14 
13:26:04 UTC (rev 9596)
+++ trunk/controller/inc/class.uicontrol_location.inc.php       2012-06-14 
13:27:19 UTC (rev 9597)
@@ -689,7 +689,8 @@
                        phpgwapi_jquery::load_widget('core');
 
                        self::add_javascript('controller', 'controller', 
'ajax_control_to_component.js');
-                       self::add_javascript('controller', 'yahoo', 
'register_control_to_component.js');
+       //              self::add_javascript('controller', 'yahoo', 
'register_control_to_component.js');
+                       self::add_javascript('controller', 'yahoo', 
'register_control_to_component2.js');
 
                        
$GLOBALS['phpgw']->xslttpl->add_file(array('control_location/register_control_to_component'));
                        
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('data' => $data));
@@ -803,10 +804,11 @@
 
                        $location_id = 
$GLOBALS['phpgw']->locations->get_id('property', 
".entity.{$entity_id}.{$cat_id}");
                        $boentity       = 
CreateObject('property.boentity',false, 'entity');
-                       $boentity->allrows = true;
+//                     $boentity->allrows = true;
                        
                        $values = $boentity->read();
 
+                       $results = array();
                        foreach($values as &$entry)
                        {
                                $checked = '';
@@ -816,9 +818,17 @@
                                        $entry['delete'] = "<input class 
=\"mychecks_delete\" type =\"checkbox\" name=\"values[delete][]\" 
value=\"{$control_id}_{$location_id}_{$entry['id']}\">";
                                }
                                $entry['select'] = "<input class 
=\"mychecks_add\" type =\"checkbox\" $checked 
name=\"values[register_component][]\" 
value=\"{$control_id}_{$location_id}_{$entry['id']}\">";
+                               $results['records'][]= $entry;
                        }
 
-                       return json_encode($values);
+                       $results['recordsReturned'] = count($values);
+                       $results['totalRecords'] = $boentity->total_records;
+                       $results['startIndex'] = $this->start;
+                       $results['sort'] = 'location_code';
+                       $results['dir'] = "ASC";
+                       $results['pageSize'] = 10;
+
+                       return $results;
                }
 
                public function edit_component()

Modified: trunk/controller/js/controller/ajax_control_to_component.js
===================================================================
--- trunk/controller/js/controller/ajax_control_to_component.js 2012-06-14 
13:26:04 UTC (rev 9596)
+++ trunk/controller/js/controller/ajax_control_to_component.js 2012-06-14 
13:27:19 UTC (rev 9597)
@@ -401,8 +401,8 @@
                        {               
                                myColumnDefs = [];
                        myColumnDefs.push(data);
-                               update_component_table_def();
-//                             update_component_table();
+//                             update_component_table_def();
+                               update_component_table2();
                        }
                        else
                        {
@@ -413,6 +413,24 @@
 
 }
 
+
+function update_component_table2()
+{
+       var oArgs = {
+               menuaction:'controller.uicontrol_location.query2',
+               entity_id:$("#entity_id").val(),
+               cat_id:$("#cat_id").val(),
+               district_id:$("#district_id").val(),
+               part_of_town_id:$("#part_of_town_id").val(),
+               location_code:$("#loc1").val() != null ? $("#loc1").val():'',
+               control_id:$("#control_id").val() != null ? 
$("#control_id").val():''
+       };
+       var requestUrl = phpGWLink('index.php', oArgs, true);
+
+       YAHOO.example.DynamicData(myColumnDefs[0],requestUrl);
+}
+
+
 function update_component_table_def()
 {
        pager = YAHOO.util.Dom.get("paging_0");

Added: trunk/controller/js/yahoo/register_control_to_component2.js
===================================================================
--- trunk/controller/js/yahoo/register_control_to_component2.js                 
        (rev 0)
+++ trunk/controller/js/yahoo/register_control_to_component2.js 2012-06-14 
13:27:19 UTC (rev 9597)
@@ -0,0 +1,81 @@
+YAHOO.example.DynamicData = function(myColumnDefs,requestUrl) {
+
+     // Custom parser
+    var timestampToDate = function(oData) {
+        // timestamp comes from server in seconds
+        // JS needs it in milliseconds
+        return new Date(oData*1000);
+    };
+
+
+       fields = new Array();
+       for(i=0; i < myColumnDefs.length;i++)
+       {
+               fields[i] = myColumnDefs[i].key;
+       }
+
+    // DataSource instance
+    var myDataSource = new YAHOO.util.DataSource( requestUrl );
+    myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
+    myDataSource.responseSchema = {
+        resultsList: "records",
+        fields: fields,
+        // Access to values in the server response
+        metaFields: {
+            totalRecords: "totalRecords",
+            startIndex: "startIndex"
+        }
+    };
+    
+    // Customize request sent to server to be able to set total # of records
+    var generateRequest = function(oState, oSelf) {
+        // Get states or use defaults
+        oState = oState || { pagination: null, sortedBy: null };
+        var sort = (oState.sortedBy) ? oState.sortedBy.key : "id";
+        var dir = (oState.sortedBy && oState.sortedBy.dir === 
YAHOO.widget.DataTable.CLASS_DESC) ? "desc" : "asc";
+        var startIndex = (oState.pagination) ? oState.pagination.recordOffset 
: 0;
+        var results = (oState.pagination) ? oState.pagination.rowsPerPage : 25;
+
+        var total = YAHOO.util.Dom.get("total").value *1;
+        // Validate input
+        if(!YAHOO.lang.isNumber(total) || total < 0 || total > 1000) {
+            YAHOO.util.Dom.get("total").value = 0;
+            total = 0;
+            alert("Total must be between 0 and 1000.");
+        }
+
+        // Build custom request
+        return  "&order=" + sort +
+                "&sort=" + dir +
+                "&start=" + startIndex +
+                "&results=" + (startIndex + results) +
+                "&total=" + total;
+    };
+
+    // DataTable configuration
+    var myConfigs = {
+        generateRequest: generateRequest,
+        initialRequest: generateRequest(), // Initial request for first page 
of data
+        dynamicData: true, // Enables dynamic server-driven data
+        sortedBy : {key:"id", dir:YAHOO.widget.DataTable.CLASS_ASC}, // Sets 
UI initial sort arrow
+        paginator: new YAHOO.widget.Paginator({ rowsPerPage:25 }) // Enables 
pagination 
+    };
+    
+    // DataTable instance
+    var myDataTable = new YAHOO.widget.DataTable("dynamicdata", myColumnDefs, 
myDataSource, myConfigs);
+    // Update totalRecords on the fly with values from server
+    myDataTable.doBeforeLoadData = function(oRequest, oResponse, oPayload) {
+        oPayload.totalRecords = oResponse.meta.totalRecords;
+        oPayload.pagination.recordOffset = oResponse.meta.startIndex;
+        return oPayload;
+    };
+
+    return {
+        ds: myDataSource,
+        dt: myDataTable
+    };
+        
+};
+//YAHOO.util.Event.onDOMReady( YAHOO.example.DynamicData );
+
+

Modified: 
trunk/controller/templates/base/control_location/register_control_to_component.xsl
===================================================================
--- 
trunk/controller/templates/base/control_location/register_control_to_component.xsl
  2012-06-14 13:26:04 UTC (rev 9596)
+++ 
trunk/controller/templates/base/control_location/register_control_to_component.xsl
  2012-06-14 13:27:19 UTC (rev 9597)
@@ -64,6 +64,8 @@
                                                                        <td 
colspan = '6'>
                                                                                
<xsl:apply-templates select="paging"/>
                                                                                
<xsl:apply-templates select="datatable"/>
+                                                                               
<p>Total records (between 0 and 1000): <input type="text" id="total" 
value="1000"/> <input type="button" id="update" value="Update"/></p>
+                                                                               
<div id="dynamicdata"></div>
                                                                        </td>
                                                                </tr>
                                                        </table>




reply via email to

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