ProjectPartGrid.js (7687B)
1 /** 2 * Represents an editable list of project parts. 3 */ 4 Ext.define('PartKeepr.ProjectPartGrid', { 5 extend: 'PartKeepr.BaseGrid', 6 7 /* Column definitions */ 8 columns: [ 9 { 10 header: i18n("Quantity"), dataIndex: 'quantity', 11 wdith: 50, 12 editor: { 13 xtype: 'numberfield', 14 allowBlank: false, 15 minValue: 1 16 }, 17 renderer: function (v, m, rec) 18 { 19 if (rec.getPart() !== null) 20 { 21 return v + " " + rec.getPart().getPartUnit().get("shortName"); 22 } else { 23 return v; 24 } 25 } 26 }, { 27 header: i18n("Overage Type"), dataIndex: 'overageType', 28 wdith: 50, 29 editor: { 30 xtype: 'combobox', 31 store: { 32 fields: ["overageType", "description"], 33 data: [{overageType: 'percent', description: i18n("Percent")}, 34 {overageType: 'absolute', description: i18n("Absolute")}] 35 }, 36 displayField: 'description', 37 valueField: 'overageType', 38 queryMode: 'local', 39 editable: false, 40 forceSelection: true, 41 allowBlank: false 42 }, 43 renderer: function (v) 44 { 45 if (v === "percent") 46 { 47 return i18n("Percent"); 48 } else 49 { 50 return i18n("Absolute"); 51 } 52 } 53 }, { 54 header: i18n("Overage"), dataIndex: 'overage', 55 width: 50, 56 editor: { 57 xtype: 'numberfield', 58 allowBlank: false, 59 minValue: 0 60 }, 61 renderer: function (v, m, rec) 62 { 63 if (rec.get("overageType") === "percent") 64 { 65 return v + " %"; 66 } else 67 { 68 if (rec.getPart() !== null) 69 { 70 return v + " " + rec.getPart().getPartUnit().get("shortName"); 71 } 72 } 73 } 74 }, { 75 header: i18n("Part"), 76 dataIndex: 'part', 77 flex: 1, 78 editor: { 79 xtype: 'RemotePartComboBox' 80 }, 81 renderer: function (val, p, rec) 82 { 83 var part = rec.getPart(), icon; 84 85 if (part !== null) 86 { 87 if (part.get("metaPart")) 88 { 89 icon = "bricks"; 90 } else 91 { 92 icon = "brick"; 93 } 94 return '<span class="web-icon ' + icon + '"></span> ' + Ext.util.Format.htmlEncode( 95 part.get("name")); 96 } 97 } 98 }, { 99 header: i18n("Remarks"), dataIndex: 'remarks', 100 flex: 1, 101 editor: { 102 xtype: 'textfield' 103 } 104 }, { 105 header: i18n("Lot Number"), dataIndex: 'lotNumber', 106 flex: 1, 107 editor: { 108 xtype: 'textfield' 109 } 110 } 111 ], 112 113 /** 114 * Initializes the component 115 */ 116 initComponent: function () 117 { 118 119 this.editing = Ext.create('Ext.grid.plugin.CellEditing', { 120 clicksToEdit: 1 121 }); 122 123 this.plugins = [this.editing]; 124 125 this.deleteButton = Ext.create("Ext.button.Button", { 126 text: i18n('Delete'), 127 disabled: true, 128 itemId: 'delete', 129 scope: this, 130 iconCls: 'web-icon brick_delete', 131 handler: this.onDeleteClick 132 }); 133 134 this.viewButton = Ext.create("Ext.button.Button", { 135 text: i18n('View Part'), 136 disabled: true, 137 itemId: 'view', 138 scope: this, 139 iconCls: 'web-icon brick_go', 140 handler: this.onViewClick 141 }); 142 143 this.dockedItems = [ 144 { 145 xtype: 'toolbar', 146 items: [ 147 { 148 text: i18n('Add'), 149 scope: this, 150 iconCls: 'web-icon brick_add', 151 handler: this.onAddClick 152 }, { 153 text: i18n("Create new Part"), 154 scope: this, 155 iconCls: 'web-icon brick_add', 156 handler: this.onAddPartClick 157 }, 158 this.deleteButton, 159 this.viewButton 160 ] 161 } 162 ]; 163 164 this.bbar = [ 165 Ext.create("PartKeepr.Exporter.GridExporterButton", { 166 itemId: 'export', 167 genericExporter: true, 168 tooltip: i18n("Export"), 169 iconCls: "fugue-icon application-export", 170 disabled: this.store.isLoading() 171 }), 172 Ext.create("PartKeepr.Importer.GridImporterButton", { 173 itemId: 'import', 174 tooltip: i18n("Import"), 175 iconCls: "fugue-icon database-import", 176 disabled: this.store.isLoading() 177 }) 178 179 ]; 180 181 this.callParent(); 182 183 this.getSelectionModel().on('selectionchange', this.onSelectChange, this); 184 }, 185 /** 186 * Creates a new row and sets the default quantity to 1. 187 */ 188 onAddClick: function () 189 { 190 this.editing.cancelEdit(); 191 192 var rec = Ext.create("PartKeepr.ProjectBundle.Entity.ProjectPart", { 193 quantity: 1 194 }); 195 196 this.store.insert(this.store.count(), rec); 197 198 this.editing.startEdit(rec, this.columns[0]); 199 }, 200 /** 201 * Creates a new part, adds it to the list and sets the default quantity to 1. 202 */ 203 onAddPartClick: function () 204 { 205 var win = Ext.getCmp("partkeepr-partmanager").onItemAdd(); 206 win.editor.on("editorClose", function (context) 207 { 208 // End this if the record is a phatom and thus hasn't been saved yet 209 if (context.record.phantom) 210 { 211 return; 212 } 213 214 // Insert the new record 215 this.editing.cancelEdit(); 216 217 var rec = Ext.create("PartKeepr.ProjectBundle.Entity.ProjectPart", { 218 quantity: 1, 219 part_id: context.record.get("id"), 220 part_name: context.record.get("name") 221 }); 222 223 this.store.insert(this.store.count(), rec); 224 225 this.editing.startEdit(rec, this.columns[0]); 226 }, this); 227 }, 228 /** 229 * Removes the currently selected row 230 */ 231 onDeleteClick: function () 232 { 233 var selection = this.getView().getSelectionModel().getSelection()[0]; 234 if (selection) 235 { 236 this.store.remove(selection); 237 } 238 }, 239 /** 240 * Removes the currently selected row 241 */ 242 onViewClick: function () 243 { 244 var selection = this.getView().getSelectionModel().getSelection()[0]; 245 if (selection) 246 { 247 Ext.getCmp("partkeepr-partmanager").onEditPart(selection.getPart()); 248 } 249 }, 250 251 /** 252 * Enables or disables the delete button, depending on the row selection 253 */ 254 onSelectChange: function (selModel, selections) 255 { 256 this.deleteButton.setDisabled(selections.length === 0); 257 this.viewButton.setDisabled(selections.length === 0); 258 } 259 });