Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 2.26 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /////////////////////////////////////////////
  2. // Build a contact widget in specified div
  3. /////////////////////////////////////////////
  4.  
  5.   FREIGHTR.contactList = function (div) {
  6.     var columnDefs = [
  7.       {key:"key[1]['company']", label: "Company", resizeable: true, width: 250},
  8.       {key:"key[1]['location']", label: "Location", resizeable: true, width: 100},
  9.     ];
  10.  
  11.     this.dataSource = new YAHOO.util.DataSource("_view/contacts?");
  12.     this.dataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
  13.     this.dataSource.connXhrMode = "queueRequests";
  14.     this.dataSource.responseSchema = {
  15.     resultsList: "rows",
  16.     fields: ["key[1]['id']","key[1]['company']","key[1]['location']"],
  17.   };
  18.  
  19.   this.dataTable = new YAHOO.widget.ScrollingDataTable(div, columnDefs,
  20.     this.dataSource, {    initialRequest:'?startkey=["a"]&endkey=["a\u9999"]&group=true'
  21.     , selectionMode:"single"
  22.     , height: "350px"
  23.     , width: "400px"
  24.     ,
  25.   });
  26.  
  27.   // Subscribe to events for row selection
  28.   this.dataTable.subscribe("rowMouseoverEvent", this.dataTable.onEventHighlightRow);
  29.   this.dataTable.subscribe("rowMouseoutEvent", this.dataTable.onEventUnhighlightRow);
  30.   this.dataTable.subscribe("rowClickEvent", this.dataTable.onEventSelectRow);
  31.                
  32.   this.dataTable.subscribe("rowClickEvent", FREIGHTR.showContact);
  33.  
  34.   // Programmatically select the first row
  35.   this.dataTable.selectRow(this.dataTable.getTrEl(0));
  36.  
  37.   this.callback = function() {
  38.     this.set("sortedBy", null);
  39.     this.onDataReturnInitializeTable.apply(this,arguments);
  40.     this.dataTable.selectRow(0);
  41.   };
  42.  
  43.   this.callback1 = {
  44.     success : this.callback,
  45.     failure : this.callback,
  46.     scope : this.dataTable
  47.   };
  48. };
  49.  
  50. /////////////////////////////////////////////
  51. // build contact widget
  52. /////////////////////////////////////////////
  53.  
  54. FREIGHTR.contacts.search.XHR_JSON = new FREIGHTR.contactList("contacts_results");
  55.  
  56. /////////////////////////////////////////////
  57. // submit search
  58. /////////////////////////////////////////////
  59.  
  60. FREIGHTR.contacts.search.submit = function(one, two, three) {
  61.   var search_term = YAHOO.util.Dom.get("contacts_q").value;
  62.   FREIGHTR.contacts.search.XHR_JSON.dataSource.sendRequest(search_term, FREIGHTR.contacts.search.XHR_JSON.callback1);
  63. };