partkeepr

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

QuantityRenderer.js (2188B)


      1 Ext.define("PartKeepr.Components.ProjectReport.Renderers.QuantityRenderer", {
      2     extend: "PartKeepr.Components.Grid.Renderers.AbstractRenderer",
      3 
      4     alias: 'columnRenderer.projectReportQuantity',
      5 
      6     renderer: function (value, metaData, record, rowIndex, colIndex, store, view, renderObj)
      7     {
      8         var quantityField = renderObj.getRendererConfigItem(renderObj, "quantityField", false);
      9 
     10         if (record.get("metaPart"))
     11         {
     12             total = 0;
     13             for (i = 0; i < record.subParts().getCount(); i++)
     14             {
     15                 if (record.subParts().getAt(i).get("use"))
     16                 {
     17                     total += record.subParts().getAt(i).get("stockToUse");
     18                 }
     19             }
     20 
     21             return total + " / " + value;
     22         } else
     23         {
     24             title = renderObj.getProjectParts(record);
     25             return '<span class="web-icon fugue-icon information-small-white" title="' + title + '"></span> '+ record.get(quantityField) + " " + record.getPart().getPartUnit().get("shortName");
     26         }
     27     },
     28     getProjectParts: function (rec) {
     29         var report = rec.getReport(),
     30             i,j, project, projectPart, projectPartQuantities = [];
     31 
     32         for (i=0;i<report.reportProjects().getCount();i++) {
     33             project = report.reportProjects().getAt(i).getProject();
     34 
     35             for (j=0;j<project.parts().getCount();j++) {
     36                 projectPart = project.parts().getAt(j);
     37 
     38                 if (projectPart.getPart().getId() === rec.getPart().getId() ) {
     39                     projectPartQuantities.push(project.get("name")+ ": "+projectPart.get("totalQuantity"));
     40                 }
     41             }
     42         }
     43 
     44         return projectPartQuantities.join("&#013;&#010;")
     45     },
     46 
     47     statics: {
     48         rendererName: i18n("Project Report Quantity Renderer"),
     49         rendererDescription: i18n("Renders the amount of required metadata quantities"),
     50         rendererConfigs: {
     51             parameterName: {
     52                 type: 'quantityField',
     53                 title: i18n("Field name which denotes the quantity")
     54             }
     55         },
     56 
     57         restrictToEntity: ["PartKeepr.ProjectBundle.Entity.ProjectReport"]
     58     }
     59 });