partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

SummaryStatisticsPanel.js (3739B)


      1 Ext.define('PartKeepr.SummaryStatisticsPanel', {
      2     extend: 'Ext.panel.Panel',
      3     width: 400,
      4     height: 250,
      5     title: i18n("Current Statistics"),
      6     bodyStyle: {
      7         padding: "5px"
      8     },
      9     layout: 'fit',
     10     /**
     11      * Initializes the component and adds a template
     12      */
     13     initComponent: function ()
     14     {
     15         /**
     16          * Create the template
     17          */
     18         this.tpl = new Ext.XTemplate(
     19             '<h1>' + i18n("Current Statistics") + '</h1>',
     20             '<table>',
     21                 '<tr>',
     22                     '<td style="width: 200px;" class="o">' + i18n("Different Parts") + ':</td>',
     23                     '<td style="width: 200px;" class="o">{partCount}</td>',
     24                 '</tr>',
     25                 '<tr>',
     26                     '<td style="width: 200px;" class="e">' + i18n("Total Part Value") + ':</td>',
     27                     '<td style="width: 200px;" class="e">{[PartKeepr.getApplication().formatCurrency(values.totalPrice)]}</td>',
     28                 '</tr>',
     29                 '<tr>',
     30                     '<td style="width: 200px;" class="o">' + i18n("Average Part Value") + ':</td>',
     31                     '<td style="width: 200px;" class="o">{[PartKeepr.getApplication().formatCurrency(values.averagePrice)]}</td>',
     32                 '</tr>',
     33                 '<tr>',
     34                     '<td style="width: 200px;" class="e">' + i18n("Parts with price") + ':</td>',
     35                     '<td style="width: 200px;" class="e">{partsWithPrice}</td>',
     36                 '</tr>',
     37                 '<tr>',
     38                     '<td style="width: 200px;" class="o">' + i18n("Parts without price") + ':</td>',
     39                     '<td style="width: 200px;" class="o">{partsWithoutPrice}</td>',
     40                 '</tr>',
     41                 '<tr>',
     42                     '<td class="e">' + i18n("Categories") + ':</td>',
     43                 '<td class="e">{partCategoryCount}</td>',
     44                 '</tr>',
     45             '</table>',
     46             '<h1>' + i18n("Counts per Unit") + '</h1>',
     47             '<table>',
     48                 '<tpl for="units">',
     49                 '<tr>',
     50                     '<td style="width: 200px;" class="{[xindex % 2 === 0 ? "e" : "o"]}">{partMeasurementUnit.name}</td>',
     51                     '<td style="width: 200px;" class="{[xindex % 2 === 0 ? "e" : "o"]}">{stockLevel}</td>',
     52                 '</tr>',
     53                 '</tpl>',
     54             '</table>');
     55 
     56         this.tbButtons = [
     57             {
     58                 text: i18n("Refresh"),
     59                 handler: this.loadStats,
     60                 scope: this
     61             }, {
     62                 text: i18n("Close"),
     63                 handler: this.close,
     64                 scope: this
     65             }
     66         ];
     67 
     68         this.dockedItems = [
     69             {
     70                 xtype: 'toolbar',
     71                 dock: 'bottom',
     72                 ui: 'footer',
     73                 items: this.tbButtons
     74             }
     75         ];
     76 
     77         this.view = Ext.create("Ext.panel.Panel", {
     78             autoScroll: true
     79         });
     80 
     81         this.items = this.view;
     82         this.callParent();
     83 
     84         this.loadStats();
     85     },
     86     loadStats: function ()
     87     {
     88         var options = {
     89             url: PartKeepr.getBasePath() + "/api/statistics/current",
     90             method: "GET",
     91             callback: Ext.bind(this.onStatsLoaded, this)
     92         };
     93 
     94         Ext.Ajax.request(options);
     95     },
     96     onStatsLoaded: function (options, success, response)
     97     {
     98         var data = Ext.decode(response.responseText);
     99         this.tpl.overwrite(this.view.getTargetEl(), data);
    100     },
    101     statics: {
    102         iconCls: 'web-icon chart_bar',
    103         title: i18n('Summary'),
    104         closable: true,
    105         menuPath: [{text: i18n("View")}, {text: i18n("Statistics"), iconCls: "web-icon chart_bar"}]
    106     }
    107 });