BarcodeScannerConfiguration.js (9879B)
1 Ext.define('PartKeepr.Components.SystemPreferences.Preferences.BarcodeScannerConfiguration', { 2 extend: 'PartKeepr.Components.Preferences.PreferenceEditor', 3 4 initComponent: function () 5 { 6 var modifierItems = [ 7 { 8 xtype: 'checkbox', 9 boxLabel: "Ctrl", 10 itemId: 'barcodeScannerModifierCtrl' 11 }, 12 { 13 xtype: 'checkbox', 14 boxLabel: "Shift", 15 itemId: 'barcodeScannerModifierShift' 16 }, 17 { 18 xtype: 'checkbox', 19 boxLabel: "Alt", 20 itemId: 'barcodeScannerModifierAlt' 21 } 22 ]; 23 24 this.barcodeScannerActionsStore = Ext.create("Ext.data.Store", { 25 fields: ["code", "action", "configuration"], 26 data: [] 27 }); 28 29 this.deleteButton = Ext.create("Ext.button.Button", { 30 text: i18n("Delete"), 31 tooltip: i18n("Delete"), 32 iconCls: "web-icon delete", 33 handler: Ext.bind(function () 34 { 35 this.barcodeScannerActionsStore.remove( 36 this.barcodeScannerActionsGrid.getSelectionModel().getSelection()); 37 }, this), 38 disabled: true 39 }); 40 41 this.addButton = Ext.create("Ext.button.Button", { 42 text: i18n("Add"), 43 tooltip: i18n("Add"), 44 iconCls: "web-icon add", 45 handler: Ext.bind(function () 46 { 47 var rec = this.barcodeScannerActionsStore.add({}); 48 49 this.editing.startEdit(rec[0], 0); 50 }, this) 51 }); 52 53 this.topToolbar = Ext.create("Ext.toolbar.Toolbar", { 54 dock: 'top', 55 enableOverflow: true, 56 items: [this.addButton, this.deleteButton] 57 }); 58 59 this.editing = Ext.create('Ext.grid.plugin.RowEditing', { 60 clicksToEdit: 1 61 62 }); 63 64 this.barcodeScannerActionsGrid = Ext.create({ 65 height: 200, 66 plugins: [this.editing], 67 xtype: 'grid', 68 dockedItems: [this.topToolbar], 69 itemId: 'barcodeScannerActionsGrid', 70 store: this.barcodeScannerActionsStore, 71 columns: [ 72 { 73 text: i18n("Code"), dataIndex: 'code', flex: 1, 74 editor: { 75 xtype: 'textfield' 76 } 77 }, 78 { 79 text: i18n("Action"), dataIndex: 'action', flex: 1, 80 renderer: function (v) 81 { 82 if (v instanceof Ext.data.Model) { 83 return v.get("name"); 84 } else { 85 return i18n("No action selected"); 86 } 87 }, 88 editor: { 89 xtype: 'barcodescannerActions' 90 } 91 }, { 92 text: i18n("Description"), 93 flex: 3, 94 renderer: function (v, m, record) 95 { 96 if (record.get("action") instanceof Ext.data.Model) { 97 return record.get("action").get("description"); 98 } else { 99 return ""; 100 } 101 102 } 103 }, 104 { 105 xtype: 'actioncolumn', 106 items: [ 107 { 108 iconCls: 'fugue-icon pencil', 109 tooltip: i18n("Configure"), 110 handler: function (view, rowIndex, colIndex, item, e, record) 111 { 112 var config = record.get("configuration"); 113 114 if (typeof config === "undefined") { 115 config = {}; 116 record.set("configuration", config); 117 } 118 119 if (record.get("action") instanceof Ext.data.Model) { 120 121 122 Ext.ClassManager.get(record.get("action").get("action")).configure(config); 123 } 124 } 125 } 126 ] 127 } 128 ] 129 }); 130 131 this.barcodeScannerActionsGrid.getSelectionModel().on("select", this._onItemSelect, this); 132 this.barcodeScannerActionsGrid.getSelectionModel().on("deselect", this._onItemDeselect, this); 133 134 this.items = [ 135 { 136 fieldLabel: i18n("Modifier"), 137 xtype: 'checkboxgroup', 138 layout: { 139 type: 'vbox', 140 align: 'left' 141 }, 142 items: modifierItems 143 }, 144 { 145 fieldLabel: i18n("Key"), 146 xtype: 'textfield', 147 itemId: 'barcodeScannerKey', 148 minLength: 1, 149 maxLength: 1, 150 enforceMaxLength: true 151 }, { 152 fieldLabel: i18n("Timeout (ms)"), 153 xtype: 'numberfield', 154 minValue: 100, 155 maxValue: 3000, 156 itemId: 'barcodeScannerTimeout' 157 158 }, { 159 boxLabel: i18n("Use enter/return to indicate scan input end"), 160 xtype: 'checkbox', 161 hideEmptyLabel: false, 162 itemId: 'barcodeScannerEnter' 163 }, { 164 xtype: 'fieldcontainer', 165 fieldLabel: i18n("Actions"), 166 items: [this.barcodeScannerActionsGrid] 167 } 168 ]; 169 170 this.callParent(arguments); 171 172 this.down("#barcodeScannerKey").setValue( 173 PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.key", "")); 174 this.down("#barcodeScannerModifierAlt").setValue( 175 PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.modifierAlt", false)); 176 this.down("#barcodeScannerModifierShift").setValue( 177 PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.modifierShift", false)); 178 this.down("#barcodeScannerModifierCtrl").setValue( 179 PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.modifierCtrl", false)); 180 this.down("#barcodeScannerEnter").setValue( 181 PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.enter", true)); 182 this.down("#barcodeScannerTimeout").setValue( 183 PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.timeout", 500)); 184 185 var actions = PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.actions", []); 186 var actionStore = Ext.create("PartKeepr.Data.store.BarcodeScannerActionsStore"); 187 188 for (var i = 0; i < actions.length; i++) { 189 var item = actions[i]; 190 191 this.barcodeScannerActionsStore.add({ 192 code: item.code, 193 action: actionStore.findRecord("action", item.action), 194 configuration: item.config 195 }); 196 } 197 }, 198 onSave: function () 199 { 200 PartKeepr.getApplication().setSystemPreference("partkeepr.barcodeScanner.key", 201 this.down("#barcodeScannerKey").getValue()); 202 PartKeepr.getApplication().setSystemPreference("partkeepr.barcodeScanner.modifierAlt", 203 this.down("#barcodeScannerModifierAlt").getValue()); 204 PartKeepr.getApplication().setSystemPreference("partkeepr.barcodeScanner.modifierShift", 205 this.down("#barcodeScannerModifierShift").getValue()); 206 PartKeepr.getApplication().setSystemPreference("partkeepr.barcodeScanner.modifierCtrl", 207 this.down("#barcodeScannerModifierCtrl").getValue()); 208 PartKeepr.getApplication().setSystemPreference("partkeepr.barcodeScanner.enter", 209 this.down("#barcodeScannerEnter").getValue()); 210 PartKeepr.getApplication().setSystemPreference("partkeepr.barcodeScanner.timeout", 211 this.down("#barcodeScannerTimeout").getValue()); 212 213 var data = this.down("#barcodeScannerActionsGrid").getStore().getData(); 214 var actions = []; 215 216 for (var i = 0; i < data.length; i++) { 217 var item = data.getAt(i); 218 219 actions.push({ 220 code: item.get("code"), 221 action: item.get("action").get("action"), 222 config: item.get("configuration") 223 }); 224 } 225 226 PartKeepr.getApplication().setSystemPreference("partkeepr.barcodeScanner.actions", actions); 227 228 PartKeepr.getApplication().getBarcodeScannerManager().registerBarcodeScannerHotkey(); 229 230 }, 231 /** 232 * Called when an item was selected 233 */ 234 _onItemSelect: function (selectionModel, record) 235 { 236 this._updateDeleteButton(selectionModel, record); 237 this.fireEvent("itemSelect", record); 238 }, 239 /** 240 * Called when an item was deselected 241 */ 242 _onItemDeselect: function (selectionModel, record) 243 { 244 this._updateDeleteButton(selectionModel, record); 245 this.fireEvent("itemDeselect", record); 246 }, 247 /** 248 * Called when an item was selected. Enables/disables the delete button. 249 */ 250 _updateDeleteButton: function () 251 { 252 /* Right now, we support delete on a single record only */ 253 if (this.barcodeScannerActionsGrid.getSelectionModel().getCount() === 1) { 254 this.deleteButton.enable(); 255 } else { 256 this.deleteButton.disable(); 257 } 258 }, 259 statics: { 260 iconCls: 'fugue-icon barcode', 261 title: i18n('Barcode Scanner Configuration'), 262 menuPath: [] 263 } 264 });