Changeset 13845

Show
Ignore:
Timestamp:
05/30/08 15:51:43 (6 months ago)
Author:
BryanForbes
Message:

refs #6546 !strict

Location:
dojox/trunk/grid
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • dojox/trunk/grid/DataGrid.js

    r13832 r13845  
    22 
    33dojo.require("dojox.grid._Grid"); 
     4dojo.require("dojox.grid.DataSelection"); 
    45 
    56dojo.declare("dojox.grid.DataGrid", dojox.grid._Grid, { 
     
    3031        }, 
    3132 
     33        createSelection: function(){ 
     34                this.selection = new dojox.grid.DataSelection(this); 
     35        }, 
     36 
    3237        get: function(inItem, inRowIndex){ 
    3338                return (!inItem ? this.defaultValue : (!this.field ? this.value : this.grid.store.getValue(inItem, this.field))); 
     
    7277                this._refresh(); 
    7378        }, 
    74          
     79 
    7580        _setStore: function(store){ 
    7681                if(this.store&&this._store_connects){ 
     
    8691 
    8792                        this._canEdit = !!f["dojo.data.api.Write"]; 
    88                          
     93 
    8994                        if(!!f["dojo.data.api.Notification"]){ 
    9095                                h.push(this.connect(this.store, "onSet", "_onSet")); 
     
    149154 
    150155        _clearData: function(){ 
     156                this.rowCount = 0; 
    151157                this._identity_map = {}; 
    152158                this._pages = []; 
     
    176182        }, 
    177183 
    178         filter: function(query){ 
     184        filter: function(query, reRender){ 
    179185                this.query = query; 
    180                 this._fetch(0, false); 
     186                if(reRender){ 
     187                        this._clearData(); 
     188                } 
     189                this._fetch(); 
    181190        }, 
    182191 
     
    348357        //                so it's no big deal, but it's something to be aware of. 
    349358        //              * I'm pretty sure that colgroup introspection is missing some of 
    350         //                the available settable properties.  
     359        //                the available settable properties. 
    351360        //              * No handling of cell formatting and content getting is done 
    352361        var d = dojo; 
     
    361370        // if a structure isn't referenced, do we have enough 
    362371        // data to try to build one automatically? 
    363         if(     !props.structure &&  
     372        if(     !props.structure && 
    364373                node.nodeName.toLowerCase() == "table"){ 
    365374 
     
    367376                props.structure = d.query("> colgroup", node).map(function(cg){ 
    368377                        var sv = d.attr(cg, "span"); 
    369                         var v = {  
     378                        var v = { 
    370379                                noscroll: (d.attr(cg, "noscroll") == "true") ? true : false, 
    371380                                __span: (!!sv ? parseInt(sv) : 1), 
     
    381390                                __span: Infinity, 
    382391                                cells: [] // catch-all view 
    383                         });  
     392                        }); 
    384393                } 
    385394                // check to see if we're gonna have more than one view 
    386                  
     395 
    387396                // for each tr in our th, create a row of cells 
    388397                d.query("thead > tr", node).forEach(function(tr, tr_idx){ 
  • dojox/trunk/grid/Selection.js

    r13588 r13845  
    33dojo.declare("dojox.grid.Selection", null, { 
    44        // summary: 
    5         //              Manages row selection for grid. Owned by grid and used internally  
     5        //              Manages row selection for grid. Owned by grid and used internally 
    66        //              for selection. Override to implement custom selection. 
    77 
     
    1010                this.selected = []; 
    1111        }, 
    12          
     12 
    1313        multiSelect: true, 
    1414        selected: null, 
  • dojox/trunk/grid/tests/test_yahoo_search.html

    r13832 r13845  
    2121        <script type="text/javascript"> 
    2222                dojo.require("dojox.grid.DataGrid"); 
     23                dojo.require("dojo.io.script"); 
     24                dojo.require("dojox.rpc.Service"); 
     25                dojo.require("dojox.data.ServiceStore"); 
    2326                dojo.require("dojo.parser"); 
    2427        </script> 
    25         <script type="text/javascript" src="yahooSearch.js"></script> 
    2628        <script type="text/javascript"> 
    27                 webFields = [ 
    28                         { name: 'Title', na: '' },  
    29                         { name: 'ModificationDate', na: ''}, 
    30                         { name: 'Summary', na: '&nbsp;' }, 
    31                         { name: 'Url', na: '' }, 
    32                         { name: 'MimeType', na: '&nbsp;'}, 
    33                         { name: 'DisplayUrl', na: '&nbsp;'} 
    34                 ]; 
    35                  
    36                 imageFields = [          
    37                         { name: 'Title', na: '' },  
    38                         { name: 'Thumbnail', na: ''}, 
    39                         { name: 'Summary', na: '' }, 
    40                         { name: 'Url', na: '' }, 
    41                         { name: 'FileSize', na: ''}, 
    42                         { name: 'Height', na: ''}, 
    43                         { name: 'Width', na: ''} 
    44                 ]; 
    45  
    46                 var model = new dojox.grid._data.yahooSearch(imageFields, null, "searchInput"); 
    47                 model.observer(this); 
    48                 // report some model send/receive status 
    49                 model.onSend = function(inParams) { 
    50                         dojo.byId('sendInfo').innerHTML = dojo.string.substitute('Request rows ${0} to ${1}.&nbsp&nbsp;', [inParams.start, inParams.start + inParams.results -1] ); 
    51                 } 
    52                 model.onReceive = function(inData) { 
    53                         dojo.byId('receiveInfo').innerHTML = dojo.string.substitute('Receive rows ${0} to ${1}.&nbsp&nbsp;', [inData.firstResultPosition, inData.firstResultPosition + inData.totalResultsReturned-1]); 
    54                 } 
    55  
    56                  
     29                dojo.declare("YahooStore", dojox.data.ServiceStore, { 
     30                        _processResults: function(results, def){ 
     31                                var totalCount = 0; 
     32                                if(results.ResultSet){ 
     33                                        totalCount = results.ResultSet.totalResultsAvailable; 
     34                                        results = results.ResultSet.Result; 
     35                                } 
     36                                var resultSet = this.inherited(arguments); 
     37                                resultSet.totalCount = totalCount > 1000 ? 1000 : totalCount; 
     38                                return resultSet; 
     39                        }, 
     40                        fetch: function(request){ 
     41                                if(request.query){ 
     42                                        if(request.count){ 
     43                                                request.query['results'] = request.count; 
     44                                        } 
     45                                        if(typeof request.start != "undefined"){ 
     46                                                request.query['start'] = request.start + 1; 
     47                                        } 
     48                                } 
     49 
     50                                return this.inherited(arguments); 
     51                        } 
     52                }); 
     53                var service = new dojox.rpc.Service(dojo.moduleUrl("dojox.rpc.SMDLibrary", "yahoo.smd")); 
     54                var store = new YahooStore({ service: service.webSearch }); 
     55 
     56                var getCellData = function(item, field){ 
     57                        return grid.store.getValue(item, field); 
     58                } 
     59 
     60                var getLink = function(inItem, inRowIndex){ 
     61                        if(!inItem){ return '&nbsp;'; } 
     62                        var text = getCellData(inItem, 'Title'); 
     63                        var link = getCellData(inItem, 'ClickUrl'); 
     64                        return dojo.string.substitute( 
     65                                '<a target="_blank" href="${href}">${text}</a>',  
     66                                { href: link, text: text } 
     67                        ); 
     68                }; 
     69 
     70                var formatDate = function(inDatum, inRowIndex){ 
     71                        if(!inDatum){ return '&nbsp;'; } 
     72                        var d = new Date(inDatum * 1000); 
     73                        return dojo.string.substitute( 
     74                                "${0}/${1}/${2}", 
     75                                [ d.getMonth()+1, d.getDate(), d.getFullYear() ] 
     76                        ); 
     77                }; 
     78 
     79                var getImage = function(inItem, inRowIndex){ 
     80                        if(!inItem){ return '&nbsp;'; } 
     81                        var thumb = getCellData(inItem, "Thumbnail"); 
     82                        var o = { 
     83                                href: getCellData(inItem, "ClickUrl"), 
     84                                src: thumb.Url, 
     85                                width: thumb.Width, 
     86                                height: thumb.Height 
     87                        } 
     88                        return dojo.string.substitute( 
     89                                '<a href="${href}" target="_blank"><img border=0 src="${src}" width="${width}" height="${height}"></a>', o); 
     90                }; 
     91 
     92 
     93                var getDimensions = function(inItem, inRowIndex){ 
     94                        if(!inItem){ return '&nbsp;'; } 
     95                        var w = getCellData(inItem, "Width"); 
     96                        var h = getCellData(inItem, "Height"); 
     97                        return w + ' x ' + h; 
     98                } 
     99 
    57100                var webLayout = [  
    58                         { type: 'dojox.grid._RowSelector', width: '20px' }, 
    59                         { noscroll: true, 
     101                        { 
     102                                noscroll: true, 
    60103                                cells: [ 
    61                                         [ { name: 'Row', width: 3, styles: 'text-align: center;', get: function(inRowIndex) { return inRowIndex + 1 } }] 
     104                                        { 
     105                                                name: 'Row', 
     106                                                width: 3, 
     107                                                styles: 'text-align: center;', 
     108                                                get: function(inItem, inRowIndex) { return inRowIndex + 1 } 
     109                                        } 
    62110                                ] 
    63111                        }, 
    64                         { cells: [ 
    65                                         [       { name: 'Site', width: 30, field: 3, extraField: 0, formatter: formatLink }, { name: 'Date', width: 10, field: 1, formatter: formatDate} ], 
    66                                         [       { name: 'Display Url', width: 30, field: 5, styles: 'color: green; size: small;' }, { name: 'Type', width: 10, field: 4, styles: ' font-style: italic; color: gray; size: small;'} ], 
    67                                         [ { name: 'Summary',  width: 40, colSpan: 2, field: 2 } ] 
    68                         ]} 
     112                        [ 
     113                                [ 
     114                                        { name: 'Site', width: 30, field: 'ClickUrl', get: getLink }, 
     115                                        { name: 'Date', width: 10, field: 'ModificationDate', formatter: formatDate} 
     116                                ],[ 
     117                                        { name: 'Display Url', width: 30, field: 'Url', styles: 'color: green; size: small;' }, 
     118                                        { name: 'Type', width: 10, field: 'MimeType', styles: ' font-style: italic; color: gray; size: small;'} 
     119                                ],[ 
     120                                        { name: 'Summary',  width: 40, colSpan: 2, field: 'Summary' } 
     121                                ] 
     122                        ] 
    69123                ]; 
    70124                 
     
    76130                 
    77131                var imageLayout = [  
    78                         { type: 'dojox.grid._RowSelector', width: '20px' }, 
    79                         { noscroll: true, 
     132                        { 
     133                                noscroll: true, 
    80134                                cells: [ 
    81                                         [ { name: 'Row', width: 3, styles: 'text-align: center;', get: function(inRowIndex) { return inRowIndex + 1 } }] 
     135                                        { 
     136                                                name: 'Row', 
     137                                                width: 3, 
     138                                                styles: 'text-align: center;', 
     139                                                get: function(inItem, inRowIndex) { return inRowIndex + 1 } 
     140                                        } 
    82141                                ] 
    83142                        }, 
    84                         { onBeforeRow: beforeImageRow, 
     143                        { 
     144                                onBeforeRow: beforeImageRow, 
    85145                                cells: [ 
    86                                         [       { name: 'Image', cellStyles: "height: 100px;", styles: "text-align: center;", width: 13, rowSpan: 2, field: 3, extraField: 1, formatter: formatImage }, 
    87                                                 { name: 'Title', cellStyles: "height: 10px;", width: 14, field: 3, extraField: 0, formatter: formatLink },  
    88                                                 { name: 'Size', width: 8, field: 4, styles: "font-style: italic; text-align: center;" }, 
    89                                                 { name: 'Dimensions', width: 8, field: 6, extraField: 5, styles: "text-align: center;", formatter: formatDimensions } 
     146                                        [ 
     147                                                { name: 'Image', cellStyles: "height: 100px;", styles: "text-align: center;", width: 13, rowSpan: 2, field: 'Url', get: getImage }, 
     148                                                { name: 'Title', cellStyles: "height: 10px;", width: 14, field: 'Title', get: getLink },  
     149                                                { name: 'Size', width: 8, field: 'FileSize', styles: "font-style: italic; text-align: center;" }, 
     150                                                { name: 'Dimensions', width: 8, styles: "text-align: center;", get: getDimensions } 
    90151                                        ], 
    91                                         [ { name: 'Summary',  cellStyles: "vertical-align: top; height: 75px;", colSpan: 3, field: 2 } ] 
    92                         ]} 
     152                                        [ 
     153                                                { name: 'Summary',  cellStyles: "vertical-align: top; height: 75px;", colSpan: 3, field: 'Summary' } 
     154                                        ] 
     155                                ] 
     156                        } 
    93157                ]; 
    94158                 
    95159                // execute search 
     160                var lastLayoutType = webLayout; 
    96161                doSearch = function() { 
     162                        var value = dojo.byId("searchInput").value; 
    97163                        var web = dojo.byId('webRb').checked; 
    98                         model.setRowCount(0); 
    99                         model.clear(); 
    100                         model.fields.set(web ? webFields : imageFields); 
    101                         model.url = 'http://search.yahooapis.com/' + (web ? 'WebSearchService/V1/webSearch' : 'ImageSearchService/V1/imageSearch'); 
    102                         grid.scrollToRow(0); 
    103                         grid.setStructure(web ? webLayout : imageLayout); 
    104                         model.requestRows(); 
     164                        store.service = (web ? service.webSearch : service.imageSearch); 
     165                        if(lastLayoutType != (web ? webLayout : imageLayout)){ 
     166                                grid.setStructure(web ? webLayout : imageLayout); 
     167                        } 
     168                        grid.filter({ query: value }, true); 
    105169                } 
    106170                 
     
    114178                        dojo.byId('webRb').checked = "checked"; 
    115179                        dojo.connect(dojo.byId("searchInput"), "keypress", keypress); 
    116                         doSearch(); 
    117180                }); 
    118181 
     
    127190<input id="searchInput" type="text" value="apple">&nbsp;&nbsp; 
    128191<button onclick="doSearch()">Search</button><br><br> 
    129 <div jsId="grid" class="grid" autoWidth="true" structure="webLayout" dojoType="dojox.grid.Grid" store="model" elasticView="1"></div> 
     192<div id="grid" jsId="grid" class="grid" autoWidth="true" structure="webLayout" dojoType="dojox.grid.DataGrid" store="store" elasticView="1" query="{ query: 'apple' }" rowSelector="20px"></div> 
    130193<br> 
    131194<div id="info"> 
  • dojox/trunk/grid/_Grid.js

    r13826 r13845  
    3838        }; 
    3939 
    40         dojo.declare('dojox.grid._Grid',  
    41                 [ dijit._Widget, dijit._Templated, dojox.grid._Events ],  
     40        dojo.declare('dojox.grid._Grid', 
     41                [ dijit._Widget, dijit._Templated, dojox.grid._Events ], 
    4242                { 
    4343                // summary: 
     
    5757                //      example: 
    5858                //              A quick sample: 
    59                 //               
     59                // 
    6060                //              define a get function 
    6161                //      |       function get(inRowIndex){ // called in cell context 
    6262                //      |               return [this.index, inRowIndex].join(', '); 
    6363                //      |       } 
    64                 //               
     64                // 
    6565                //              define the grid structure: 
    6666                //      |       var structure = [ // array of view objects 
    6767                //      |               { cells: [// array of rows, a row is an array of cells 
    6868                //      |                       [ 
    69                 //      |                               { name: "Alpha", width: 6 },  
    70                 //      |                               { name: "Beta" },  
     69                //      |                               { name: "Alpha", width: 6 }, 
     70                //      |                               { name: "Beta" }, 
    7171                //      |                               { name: "Gamma", get: get }] 
    7272                //      |               ]} 
    7373                //      |       ]; 
    74                 //               
    75                 //      |       <div id="grid"  
    76                 //      |               rowCount="100" get="get"  
    77                 //      |               structure="structure"  
     74                // 
     75                //      |       <div id="grid" 
     76                //      |               rowCount="100" get="get" 
     77                //      |               structure="structure" 
    7878                //      |               dojoType="dojox.grid._Grid"></div> 
    7979 
    8080                templatePath: dojo.moduleUrl("dojox.grid","resources/_Grid.html"), 
    81                  
     81 
    8282                // classTag: String 
    8383                //              CSS class applied to the grid's domNode 
     
    8585 
    8686                get: function(inRowIndex){ 
    87                         // summary: Default data getter.  
     87                        // summary: Default data getter. 
    8888                        // description: 
    8989                        //              Provides data to display in a grid cell. Called in grid cell context. 
     
    9494                        //              Data to display for a given grid cell. 
    9595                }, 
    96                  
     96 
    9797                // settings 
    9898                // rowCount: Integer 
    99                 //              Number of rows to display.  
     99                //              Number of rows to display. 
    100100                rowCount: 5, 
    101101 
     
    103103                //              Number of rows to keep in the rendering cache. 
    104104                keepRows: 75, 
    105                  
     105 
    106106                // rowsPerPage: Integer 
    107107                //              Number of rows to render at a time. 
     
    111111                //              If autoWidth is true, grid width is automatically set to fit the data. 
    112112                autoWidth: false, 
    113                  
     113 
    114114                // autoHeight: Boolean 
    115115                //              If autoHeight is true, grid height is automatically set to fit the data. 
    116116                autoHeight: false, 
    117                  
     117 
    118118                // autoRender: Boolean 
    119119                //              If autoRender is true, grid will render itself after initialization. 
     
    131131                //      Override defaults and make the indexed grid view elastic, thus filling available horizontal space. 
    132132                elasticView: -1, 
    133                  
     133 
    134134                // singleClickEdit: boolean 
    135135                //              Single-click starts editing. Default is double-click 
     
    143143                // Used to store the last two clicks, to ensure double-clicking occurs based on the intended row 
    144144                _click: null, 
    145                  
     145 
    146146                // private 
    147147                sortInfo: 0, 
     
    162162                        this.createViews(); 
    163163                        this.createManagers(); 
     164                        this.createSelection(); 
    164165                        dojox.html.metrics.initOnFontResize(); 
    165166                        this.connect(dojox.html.metrics, "onFontResize", "textSizeChanged"); 
     
    173174                        this._click = []; 
    174175                }, 
    175                  
     176 
    176177                destroy: function(){ 
    177178                        this.domNode.onReveal = null; 
     
    181182                        dijit._Widget.prototype.destroy.apply(this, arguments); 
    182183                }, 
    183                  
     184 
    184185                styleChanged: function(){ 
    185186                        this.setStyledClass(this.domNode, ''); 
    186187                }, 
    187                  
     188 
    188189                _styleChanged: function(){ 
    189190                        this.styleChanged(); 
    190191                        this.update(); 
    191192                }, 
    192                  
     193 
    193194                textSizeChanged: function(){ 
    194195                        setTimeout(dojo.hitch(this, "_textSizeChanged"), 1); 
    195196                }, 
    196                  
     197 
    197198                _textSizeChanged: function(){ 
    198199                        if(this.domNode){ 
     
    203204                        } 
    204205                }, 
    205                  
     206 
    206207                sizeChange: function(){ 
    207208                        jobs.job(this.id + 'SizeChange', 50, dojo.hitch(this, "update")); 
    208209                }, 
    209                  
     210 
    210211                renderOnIdle: function() { 
    211212                        setTimeout(dojo.hitch(this, "render"), 1); 
    212213                }, 
    213                  
     214 
    214215                createManagers: function(){ 
    215216                        // summary: 
    216217                        //              create grid managers for various tasks including rows, focus, selection, editing 
    217                          
     218 
    218219                        // row manager 
    219220                        this.rows = new dojox.grid._RowManager(this); 
    220221                        // focus manager 
    221222                        this.focus = new dojox.grid._FocusManager(this); 
     223                        // edit manager 
     224                        this.edit = new dojox.grid._EditManager(this); 
     225                }, 
     226 
     227                createSelection: function(){ 
    222228                        // selection manager 
    223229                        this.selection = new dojox.grid.Selection(this); 
    224                         // edit manager 
    225                         this.edit = new dojox.grid._EditManager(this); 
    226230                }, 
    227231 
     
    244248                        this.views.createView = dojo.hitch(this, "createView"); 
    245249                }, 
    246                  
     250 
    247251                createView: function(inClass){ 
    248252                        var c = dojo.getObject(inClass);