- /////////////////////////////////////////////
- // Build a contact widget in specified div
- /////////////////////////////////////////////
- FREIGHTR.contactList = function (div) {
- var columnDefs = [
- {key:"key[1]['company']", label: "Company", resizeable: true, width: 250},
- {key:"key[1]['location']", label: "Location", resizeable: true, width: 100},
- ];
- this.dataSource = new YAHOO.util.DataSource("_view/contacts?");
- this.dataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
- this.dataSource.connXhrMode = "queueRequests";
- this.dataSource.responseSchema = {
- resultsList: "rows",
- fields: ["key[1]['id']","key[1]['company']","key[1]['location']"],
- };
- this.dataTable = new YAHOO.widget.ScrollingDataTable(div, columnDefs,
- this.dataSource, { initialRequest:'?startkey=["a"]&endkey=["a\u9999"]&group=true'
- , selectionMode:"single"
- , height: "350px"
- , width: "400px"
- ,
- });
- // Subscribe to events for row selection
- this.dataTable.subscribe("rowMouseoverEvent", this.dataTable.onEventHighlightRow);
- this.dataTable.subscribe("rowMouseoutEvent", this.dataTable.onEventUnhighlightRow);
- this.dataTable.subscribe("rowClickEvent", this.dataTable.onEventSelectRow);
- this.dataTable.subscribe("rowClickEvent", FREIGHTR.showContact);
- // Programmatically select the first row
- this.dataTable.selectRow(this.dataTable.getTrEl(0));
- this.callback = function() {
- this.set("sortedBy", null);
- this.onDataReturnInitializeTable.apply(this,arguments);
- this.dataTable.selectRow(0);
- };
- this.callback1 = {
- success : this.callback,
- failure : this.callback,
- scope : this.dataTable
- };
- };
- /////////////////////////////////////////////
- // build contact widget
- /////////////////////////////////////////////
- FREIGHTR.contacts.search.XHR_JSON = new FREIGHTR.contactList("contacts_results");
- /////////////////////////////////////////////
- // submit search
- /////////////////////////////////////////////
- FREIGHTR.contacts.search.submit = function(one, two, three) {
- var search_term = YAHOO.util.Dom.get("contacts_q").value;
- FREIGHTR.contacts.search.XHR_JSON.dataSource.sendRequest(search_term, FREIGHTR.contacts.search.XHR_JSON.callback1);
- };