ProjectReport.js (5371B)
1 /** 2 * Represents the project report view 3 */ 4 Ext.define('PartKeepr.ProjectReportView', { 5 extend: 'Ext.panel.Panel', 6 alias: 'widget.ProjectReportView', 7 8 bodyStyle: 'background:#DBDBDB;padding: 5px', 9 border: false, 10 11 layout: 'border', 12 13 reportedProjects: [], 14 15 viewModel: { 16 data: { 17 store: null, 18 parentRecord: null 19 } 20 }, 21 22 initComponent: function () { 23 this.createStores(); 24 25 this.projectList = Ext.create("PartKeepr.Components.Project.ProjectReportList", { 26 region: 'north', 27 title: i18n("Choose Projects to create a report for"), 28 height: 300, 29 maxHeight: 500, 30 split: true 31 32 33 }); 34 35 this.reportList = Ext.create("PartKeepr.Components.Project.ProjectReportGrid", { 36 title: i18n("Previous Project Reports"), 37 region: 'center' 38 }); 39 40 this.reportResult = Ext.create("PartKeepr.Components.Project.ProjectReportResultGrid", { 41 store: null, 42 itemId: "projectReportResult", 43 projectReportManager: this 44 }); 45 46 this.emptyReportPartStore = Ext.create("Ext.data.Store", { 47 model: "PartKeepr.ProjectBundle.Entity.ReportPart" 48 }); 49 50 51 this.items = [ 52 { 53 region: 'west', 54 layout: 'border', 55 collapsible: true, 56 split: true, 57 minWidth: 300, 58 width: 500, 59 items: [ 60 this.reportList, 61 this.projectList 62 ] 63 }, { 64 region: 'center', 65 layout: 'fit', 66 title: i18n("Project Report"), 67 items: this.reportResult 68 } 69 ]; 70 71 72 this.callParent(); 73 74 this.down("#createReportButton").on("click", this.onCreateReportClick, this); 75 this.down("#deleteReportButton").on("click", this.onDeleteReportClick, this); 76 this.down("#loadReportButton").on("click", this.onLoadReportClick, this); 77 }, 78 onLoadReportClick: function () { 79 this.reportResult.getView().mask(i18n("Loading…")); 80 var selection = this.reportList.getSelection(); 81 82 if (selection.length === 1) 83 { 84 this.projectReport = PartKeepr.ProjectBundle.Entity.Report.load( 85 selection[0].getId(), 86 { 87 success: this.onProjectReportLoaded, 88 scope: this 89 }); 90 } 91 }, 92 /** 93 * 94 */ 95 onCreateReportClick: function () { 96 this.reportResult.getView().mask(i18n("Loading…")); 97 this.reportResult.setProjectsToReport(this.projectList.getProjectsToReport()); 98 99 var projectsToReport = this.projectList.getProjectsToReport(); 100 101 this.projectReport = Ext.create("PartKeepr.ProjectBundle.Entity.Report"); 102 103 for (var i = 0; i < projectsToReport.length; i++) 104 { 105 this.projectReport.reportProjects().add( 106 Ext.create("PartKeepr.ProjectBundle.Entity.ReportProject", { 107 project: projectsToReport[i].project, 108 quantity: projectsToReport[i].quantity 109 })); 110 } 111 112 this.doSaveProjectReport(); 113 }, 114 /** 115 * 116 */ 117 onDeleteReportClick: function () { 118 var selection = this.reportList.getSelection(); 119 120 if (selection.length === 1) 121 { 122 123 Ext.Msg.confirm(i18n("Delete Report"), sprintf(i18n("Do you really wish to delete the report %s %s?"), selection[0].get("name"), selection[0].get("createDateTime")), 124 this.deleteReport, this); 125 } 126 127 }, 128 deleteReport: function (btn) { 129 if (btn === "yes") 130 { 131 this.reportResult.setProjectsToReport([]); 132 this.reportResult.setStore(new Ext.data.Store()); 133 134 var selection = this.reportList.getSelection(); 135 if (selection.length === 1) 136 { 137 selection[0].erase(); 138 } 139 } 140 }, 141 doSaveProjectReport: function () { 142 this.reportResult.getView().mask(i18n("Saving…")); 143 this.reportResult.reconfigure(this.emptyReportPartStore); 144 this.projectReport.save({ 145 success: this.onProjectReportSave, 146 scope: this 147 }); 148 }, 149 onProjectReportSave: function () { 150 this.projectReport.load({ 151 success: this.onProjectReportLoaded, 152 scope: this 153 }); 154 155 this.reportList.getStore().reload(); 156 }, 157 onProjectReportLoaded: function () { 158 this.reportResult.reconfigure(this.projectReport.reportParts()); 159 this.reportResult.projectReport = this.projectReport; 160 this.reportResult.getView().unmask(); 161 }, 162 /** 163 * Creates the store used in this view. 164 */ 165 createStores: function () { 166 this.projectReportStore = Ext.create('Ext.data.Store', { 167 model: "PartKeepr.ProjectBundle.Entity.ReportPart", 168 pageSize: -1, 169 proxy: { 170 type: "Hydra", 171 url: '/api/project_reports' 172 } 173 }); 174 }, 175 statics: { 176 iconCls: 'fugue-icon drill', 177 title: i18n('Project Reports'), 178 closable: true, 179 menuPath: [{text: i18n("View")}] 180 } 181 });