PartDisplay.js (6024B)
1 /** 2 * @class PartKeepr.PartDisplay 3 * <p>This component displays information about a specific part.</p> 4 */ 5 Ext.define('PartKeepr.PartDisplay', { 6 extend: 'Ext.panel.Panel', 7 bodyCls: 'partdisplay', 8 9 overflowY: 'auto', 10 11 /** 12 * Initializes the component and adds a template as well as the add/remove stock and edit part buttons. 13 */ 14 initComponent: function () 15 { 16 /** 17 * Create the "add stock" button 18 */ 19 this.addButton = new Ext.Button({ 20 text: i18n("Add Stock"), 21 iconCls: 'web-icon brick_add', 22 handler: Ext.bind(this.addPartStockPrompt, this) 23 }); 24 25 /** 26 * Create the "remove stock" button 27 */ 28 this.deleteButton = new Ext.Button({ 29 text: i18n("Remove Stock"), 30 iconCls: 'web-icon brick_delete', 31 handler: Ext.bind(this.removePartStockPrompt, this) 32 }); 33 34 /** 35 * Create the "edit part" button 36 */ 37 this.editButton = new Ext.Button({ 38 text: i18n("Edit Part"), 39 iconCls: 'web-icon brick_edit', 40 handler: Ext.bind(function () 41 { 42 this.fireEvent("editPart", this.record); 43 }, this) 44 }); 45 46 /** 47 * Create the toolbar which holds our buttons 48 */ 49 this.tbar = Ext.create("Ext.toolbar.Toolbar", { 50 enableOverflow: true, 51 items: [ 52 this.addButton, 53 this.deleteButton, 54 this.editButton 55 ] 56 }); 57 58 /** 59 * Add the event "editPart". This event is fired as soon as the "edit" button is clicked. 60 * 61 * @todo Add the events "addStock" and "removeStock" and manage these events from the PartManager. 62 */ 63 64 this.attachmentDisplay = Ext.create("Ext.view.View", { 65 title: "Foobar", 66 store: null, 67 itemSelector: 'div.foobar', 68 selectedItemCls: "", 69 focusCls: "", 70 margin: 5, 71 emptyText: i18n("No attachments"), 72 tpl: [ 73 '<tpl for=".">', 74 '<div class="foobar"><a href="{[values["@id"]]}/getFile" target="_blank">{[values.originalFilename]}</a></div>', 75 '</tpl>' 76 ] 77 }); 78 79 this.imageDisplay = Ext.create("PartKeepr.PartImageDisplay", { 80 title: i18n("Images"), 81 }); 82 83 this.infoGrid = Ext.create("PartKeepr.Components.Part.PartInfoGrid", { 84 title: { 85 height: 'auto', 86 cls: 'x-title-wrappable-text' 87 } 88 }); 89 90 this.partParameterGrid = Ext.create("Ext.grid.Panel", { 91 title: i18n("Part Parameters"), 92 emptyText: i18n("No Parameters"), 93 columns: [ 94 { 95 header: i18n("Parameter"), 96 dataIndex: "name", 97 flex: 1 98 }, { 99 header: i18n("Value"), 100 renderer: function (v, m, rec) 101 { 102 return PartKeepr.PartManager.formatParameter(rec); 103 }, 104 flex: 1 105 } 106 ] 107 }); 108 109 this.items = [ 110 this.infoGrid, this.partParameterGrid, { 111 xtype: 'panel', 112 title: i18n("Attachments"), 113 items: this.attachmentDisplay 114 }, this.imageDisplay 115 ]; 116 this.callParent(); 117 }, 118 clear: function () 119 { 120 this.attachmentDisplay.bindStore(null); 121 this.imageDisplay.setStore(null); 122 this.partParameterGrid.setStore(null); 123 124 }, 125 /** 126 * Sets the values for the template. 127 * 128 * Note that the data of the record is applied with htmlentities(), i.e. <b>Test</b> will be 129 * displayed as such and not in bold. 130 */ 131 setValues: function (r) 132 { 133 this.record = r; 134 135 this.attachmentDisplay.bindStore(this.record.attachments()); 136 this.partParameterGrid.bindStore(this.record.parameters()); 137 this.infoGrid.applyFromPart(this.record); 138 this.infoGrid.setTitle( 139 "<div>" + this.record.get("name") + "</div><small>" + this.record.get("description") + "</small>"); 140 this.imageDisplay.setStore(this.record.attachments()); 141 142 // Scroll the container to top in case the user scrolled the part, then switched to another part 143 this.scrollTo(0, 0); 144 145 }, 146 /** 147 * Prompt the user for the stock level he wishes to add. 148 */ 149 addPartStockPrompt: function () 150 { 151 var j = new PartKeepr.PartStockWindow({partUnitName: this.record.get("partUnitName")}); 152 j.addStock(this.addStockHandler, this); 153 }, 154 /** 155 * Callback after the "add stock" dialog is complete. 156 */ 157 addStockHandler: function (quantity, price, comment) 158 { 159 this.record.callPutAction("addStock", { 160 quantity: quantity, 161 price: price, 162 comment: comment 163 }, null, true); 164 }, 165 /** 166 * Prompts the user for the stock level to decrease for the item. 167 */ 168 removePartStockPrompt: function () 169 { 170 var j = new PartKeepr.PartStockWindow({partUnitName: this.record.get("partUnitName")}); 171 j.removeStock(this.removeStockHandler, this); 172 }, 173 /** 174 * Callback after the "delete stock" dialog is complete. 175 */ 176 removeStockHandler: function (quantity, unused_price, comment) 177 { 178 this.record.callPutAction("removeStock", { 179 quantity: quantity, 180 comment: comment, 181 }, null, true); 182 }, 183 /** 184 * Load the part from the database. 185 */ 186 loadPart: function () 187 { 188 this.record.load({ 189 scope: this, 190 success: this.onPartLoaded 191 }); 192 }, 193 /** 194 * Callback after the part is loaded 195 */ 196 onPartLoaded: function () 197 { 198 this.setValues(this.record); 199 } 200 });