SearchPart.js (5265B)
1 Ext.define("PartKeepr.BarcodeScanner.Actions.SearchPart", { 2 extend: "PartKeepr.BarcodeScanner.Action", 3 4 statics: { 5 actionName: i18n("Search Part"), 6 actionDescription: i18n("Searches for a part in the parts list"), 7 configure: function (configuration) 8 { 9 configuration = Ext.applyIf(configuration, { 10 searchFields: [], 11 searchMode: 'fixed' 12 }); 13 14 var modelFieldSelector = Ext.create({ 15 xtype: 'modelFieldSelector', 16 id: 'searchPartFieldSelector', 17 border: false, 18 sourceModel: PartKeepr.PartBundle.Entity.Part, 19 initiallyChecked: configuration.searchFields, 20 flex: 1 21 }); 22 23 var saveButton = Ext.create("Ext.button.Button", { 24 text: i18n("OK"), 25 iconCls: 'fugue-icon disk', 26 }); 27 28 var cancelButton = Ext.create("Ext.button.Button", { 29 text: i18n("Cancel"), 30 iconCls: 'web-icon cancel' 31 }); 32 33 var bottomToolbar = Ext.create("Ext.toolbar.Toolbar", { 34 enableOverflow: true, 35 margin: '10px', 36 defaults: {minWidth: 100}, 37 dock: 'bottom', 38 ui: 'footer', 39 items: [saveButton, cancelButton] 40 }); 41 42 var window = Ext.create('Ext.window.Window', { 43 title: i18n("Search Part Configuration"), 44 height: 400, 45 modal: true, 46 width: 600, 47 layout: { 48 type: 'vbox', 49 pack: 'start', 50 align: 'stretch' 51 }, 52 items: [ 53 { 54 html: i18n("Select all fields to be searched"), 55 border: false, 56 bodyStyle: 'padding: 5px; background:transparent;', 57 }, 58 modelFieldSelector, 59 { 60 xtype: 'radiogroup', 61 layout: 'vbox', 62 itemId: 'searchMode', 63 items: [ 64 { 65 boxLabel: i18n("Search string as-is"), 66 name: 'searchMode', 67 inputValue: "fixed", 68 checked: configuration.searchMode == "fixed" ? true : false 69 }, 70 { 71 boxLabel: i18n("Search beginning of string (string*)"), 72 name: 'searchMode', 73 inputValue: "beginning", 74 checked: configuration.searchMode == "beginning" ? true : false 75 }, { 76 boxLabel: i18n("Search middle of string (*string*)"), 77 name: 'searchMode', 78 inputValue: "any", 79 checked: configuration.searchMode == "any" ? true : false 80 81 } 82 ] 83 } 84 ], 85 dockedItems: bottomToolbar 86 } 87 ).show(); 88 89 saveButton.setHandler(function () 90 { 91 var selection = modelFieldSelector.getChecked(); 92 var fields = []; 93 94 for (var i = 0; i < selection.length; i++) { 95 fields.push(selection[i].data.data.name); 96 } 97 configuration.searchFields = fields; 98 configuration.searchMode = this.down("#searchMode").getValue().searchMode; 99 this.close(); 100 }, window); 101 102 cancelButton.setHandler(function () 103 { 104 this.close(); 105 106 }, window); 107 108 } 109 }, 110 111 execute: function () 112 { 113 var subFilters = []; 114 var searchValue; 115 116 switch (this.config.searchMode) { 117 case "beginning": 118 searchValue = this.data + "%"; 119 break; 120 case "any": 121 searchValue = "%" + this.data + "%"; 122 break; 123 default: 124 searchValue = this.data; 125 break; 126 } 127 128 for (var i = 0; i < this.config.searchFields.length; i++) { 129 subFilters.push(Ext.create("PartKeepr.util.Filter", { 130 property: this.config.searchFields[i], 131 operator: "LIKE", 132 value: searchValue 133 })); 134 } 135 136 this.filter = Ext.create("PartKeepr.util.Filter", { 137 type: "OR", 138 subfilters: subFilters 139 }); 140 141 var store = PartKeepr.getApplication().getPartManager().getStore(); 142 143 store.getFilters().clear(); 144 store.addFilter(this.filter, true); 145 store.currentPage = 1; 146 store.load({start: 0}); 147 148 } 149 });