initial import
[roojs1] / examples / form / forum-search.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11 \r
12 \r
13 Roo.onReady(function(){
14
15     var ds = new Roo.data.Store({
16         
17       
18          
19         proxy: new Roo.data.ScriptTagProxy({
20             url: 'http://www.roojs.com/forum/topics-remote.php'
21         }),
22         reader: new Roo.data.JsonReader({
23             root: 'topics',
24             totalProperty: 'totalCount',
25             id: 'post_id'
26         }, [
27             {name: 'title', mapping: 'topic_title'},
28             {name: 'topicId', mapping: 'topic_id'},
29             {name: 'author', mapping: 'author'},
30             {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
31             {name: 'excerpt', mapping: 'post_text'}
32         ])
33         */
34     });
35
36     // Custom rendering Template
37     var resultTpl = new Roo.Template(
38         '<div class="search-item">',
39             '<h3><span>{lastPost:date("M j, Y")}<br />by {author}</span>{title}</h3>',
40             '{excerpt}',
41         '</div>'
42     );
43     
44     var search = new Roo.form.ComboBox({
45         store: ds,
46         displayField:'title',
47         typeAhead: false,
48         loadingText: 'Searching...',
49         width: 570,
50         pageSize:10,
51         hideTrigger:true,
52         tpl: resultTpl,
53         onSelect: function(record){ // override default onSelect to do redirect
54             window.location =
55                String.format('http://www.roojs.com/forum/showthread.php?t={0}&p={1}', record.data.topicId, record.id);
56         }
57     });
58     // apply it to the exsting input element
59     search.applyTo('search');
60 });