index.html 3.11 KB
Newer Older
1
{{
2
    #--------------------------------------------------------------------------
legac's avatar
legac committed
3
    #
4 5 6 7
    # The python controller return:
    #    - cfg_store, the configuration of the Ext.data.Array
    #    - team_project string
    #    - selector object
legac's avatar
legac committed
8
    #
9 10 11 12 13
    # prepare the data
    #    - build unique DIV identifier
    #    - Title and DIV block
    #
    #--------------------------------------------------------------------------
14

legac's avatar
legac committed
15
    #
16
    # unique identifier for the DIV block associated to the grid
legac's avatar
legac committed
17
    #
18 19 20 21 22 23 24 25
    divgrid = "grid-%s" % id(cfg_store)

    #
    # The title and the DIV block for the Ext.grid.Panel
    #
    title = "%s %s" % (T("Publications"), team_project)
    response.write(H2(title, _class="dbui-h2 dbui-small-cap"))
    response.write(DIV(_id=divgrid))
26

legac's avatar
legac committed
27
    #
28
    # The footer
legac's avatar
legac committed
29 30 31 32
    #
    # Add the URL providing a direct access to this list.
    # The application use the POST method will a user will use the GET one.
    # Display the URL only in the first case.
33
    #
legac's avatar
Polish  
legac committed
34
    if request.env.request_method == 'POST':
35 36 37
        html_url = A("url", _href=selector.repr_url(), _target='_blank')
        =P(T("Direct access to the table: "), html_url, _class="dbui-p")
        =P(request.now.strftime("%d %b %Y %H:%M"), _class="dbui-p")
legac's avatar
Polish  
legac committed
38 39
        =BR()
    pass
40 41 42 43 44 45 46 47 48 49 50

    #
    # Export python variables to the javascript
    #
    jsvars = ["cfgStore = %s" % cfg_store,
              "columns = []",
              "divgrid = '%s'" % divgrid,
              "i"]

    jsvars = "    var %s;" % ',\n'.join(jsvars)
    response.write(SCRIPT(jsvars), escape=False)
51
}}
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
<script>

    /**
     * Renderer functions
     *
     * @param {Object} value
     * @param {Object} metadata
     * @param {Ext.data.Model} record
     * @param {Number} rowIndex
     * @param {Number} colIndex
     * @param {Ext.data.Store} store
     * @param {Ext.view.view} view
     *
     */
    function rTotal() {
        return 'Total';
    }

    //
    // check that the Ext JS library is loaded
    //
    if (typeof Ext === "undefined") {
        alert("The javascript library Ext JS is missing !");
    }

    //
    // The first column contains labels for the vertical axis
    //
    columns.push({
        text: cfgStore.fields[0].name,
        dataIndex: cfgStore.fields[0].name,
        summaryRenderer: rTotal,
        flex: 1.5
    });

    //
    // the others columns contains publication count
    //
    for (i = 1; i < cfgStore.fields.length; i += 1) {
        columns.push({
            text: cfgStore.fields[i].name,
            dataIndex: cfgStore.fields[i].name,
            align: 'right',
            summaryType: 'sum',
            flex: 0.8
        });
    }

    //
    // instantiate the grid with a summary row.
    // data can be extracted via the plugin pGridExport
    //
104 105 106 107 108
    var grid = Ext.create('App.grid.Panel', {
        plugins: [{
            fileRoot: 'metrics',
            ptype:'pGridExport'
        }],
109 110 111 112 113 114 115 116 117 118 119
        store: Ext.create('Ext.data.ArrayStore', cfgStore),
        columns: columns,
        features: [{ftype:'summary'}],
        forceFit: true,
        hideHeaders: false,
        padding: "10 40 20 60",
        renderTo: divgrid
    });

</script>