1BX.namespace('BX.Sale.component.location.selector'); 2 3if(typeof BX.Sale.component.location.selector.search == 'undefined' && typeof BX.ui != 'undefined' && typeof BX.ui.widget != 'undefined'){ 4 5 BX.Sale.component.location.selector.search = function(opts, nf){ 6 7 this.parentConstruct(BX.Sale.component.location.selector.search, opts); 8 9 BX.merge(this, { 10 opts: { 11 12 usePagingOnScroll: true, 13 pageSize: 10, 14 //scrollThrottleTimeout: 100, 15 arrowScrollAdditional: 2, 16 pageUpWardOffset: 3, 17 provideLinkBy: 'id', 18 19 bindEvents: { 20 21 'after-input-value-modify': function(){ 22 23 this.ctrls.fullRoute.value = ''; 24 25 }, 26 'after-select-item': function(itemId){ 27 28 var so = this.opts; 29 var cItem = this.vars.cache.nodes[itemId]; 30 31 var path = cItem.DISPLAY; 32 if(typeof cItem.PATH == 'object'){ 33 for(var i = 0; i < cItem.PATH.length; i++){ 34 path += ', '+this.vars.cache.path[cItem.PATH[i]]; // deprecated 35 } 36 } 37 38 this.ctrls.inputs.fake.setAttribute('title', path); 39 this.ctrls.fullRoute.value = path; 40 41 if(typeof this.opts.callback == 'string' && this.opts.callback.length > 0 && this.opts.callback in window) 42 window[this.opts.callback].apply(this, [itemId, this]); 43 }, 44 'after-deselect-item': function(){ 45 this.ctrls.fullRoute.value = ''; 46 this.ctrls.inputs.fake.setAttribute('title', ''); 47 }, 48 'before-render-variant': function(itemData){ 49 50 if(itemData.PATH.length > 0){ 51 var path = ''; 52 for(var i = 0; i < itemData.PATH.length; i++) 53 path += ', '+this.vars.cache.path[itemData.PATH[i]]; 54 55 itemData.PATH = path; 56 }else 57 itemData.PATH = ''; 58 59 var query = ''; 60 61 if(this.vars && this.vars.lastQuery && this.vars.lastQuery.QUERY) 62 query = this.vars.lastQuery.QUERY; 63 64 if(BX.type.isNotEmptyString(query)){ 65 var chunks = []; 66 if(this.opts.wrapSeparate) 67 chunks = query.split(/\s+/); 68 else 69 chunks = [query]; 70 71 itemData['=display_wrapped'] = BX.util.wrapSubstring(itemData.DISPLAY+itemData.PATH, chunks, this.opts.wrapTagName, true); 72 }else 73 itemData['=display_wrapped'] = BX.util.htmlspecialchars(itemData.DISPLAY); 74 } 75 } 76 }, 77 vars: { 78 cache: { 79 path: {}, 80 nodesByCode: {} 81 } 82 }, 83 sys: { 84 code: 'sls' 85 } 86 }); 87 88 this.handleInitStack(nf, BX.Sale.component.location.selector.search, opts); 89 } 90 BX.extend(BX.Sale.component.location.selector.search, BX.ui.autoComplete); 91 BX.merge(BX.Sale.component.location.selector.search.prototype, { 92 93 // member of stack of initializers, must be defined even if do nothing 94 init: function(){ 95 96 // deprecated begin 97 if(typeof this.opts.pathNames == 'object') 98 BX.merge(this.vars.cache.path, this.opts.pathNames); 99 // deprecated end 100 101 this.pushFuncStack('buildUpDOM', BX.Sale.component.location.selector.search); 102 this.pushFuncStack('bindEvents', BX.Sale.component.location.selector.search); 103 }, 104 105 buildUpDOM: function(){ 106 107 var sc = this.ctrls, 108 so = this.opts, 109 sv = this.vars, 110 ctx = this, 111 code = this.sys.code; 112 113 // full route node 114 sc.fullRoute = BX.create('input', { 115 props: { 116 className: 'bx-ui-'+code+'-route' 117 }, 118 attrs: { 119 type: 'text', 120 disabled: 'disabled', 121 autocomplete: 'off' 122 } 123 }); 124 125 // todo: use metrics instead! 126 BX.style(sc.fullRoute, 'paddingTop', BX.style(sc.inputs.fake, 'paddingTop')); 127 BX.style(sc.fullRoute, 'paddingLeft', BX.style(sc.inputs.fake, 'paddingLeft')); 128 BX.style(sc.fullRoute, 'paddingRight', '0px'); 129 BX.style(sc.fullRoute, 'paddingBottom', '0px'); 130 131 BX.style(sc.fullRoute, 'marginTop', BX.style(sc.inputs.fake, 'marginTop')); 132 BX.style(sc.fullRoute, 'marginLeft', BX.style(sc.inputs.fake, 'marginLeft')); 133 BX.style(sc.fullRoute, 'marginRight', '0px'); 134 BX.style(sc.fullRoute, 'marginBottom', '0px'); 135 136 if(BX.style(sc.inputs.fake, 'borderTopStyle') != 'none'){ 137 BX.style(sc.fullRoute, 'borderTopStyle', 'solid'); 138 BX.style(sc.fullRoute, 'borderTopColor', 'transparent'); 139 BX.style(sc.fullRoute, 'borderTopWidth', BX.style(sc.inputs.fake, 'borderTopWidth')); 140 } 141 142 if(BX.style(sc.inputs.fake, 'borderLeftStyle') != 'none'){ 143 BX.style(sc.fullRoute, 'borderLeftStyle', 'solid'); 144 BX.style(sc.fullRoute, 'borderLeftColor', 'transparent'); 145 BX.style(sc.fullRoute, 'borderLeftWidth', BX.style(sc.inputs.fake, 'borderLeftWidth')); 146 } 147 148 BX.prepend(sc.fullRoute, sc.container); 149 150 sc.inputBlock = this.getControl('input-block'); 151 sc.loader = this.getControl('loader'); 152 }, 153 154 bindEvents: function(){ 155 156 var ctx = this; 157 158 // quick links 159 BX.bindDelegate(this.getControl('quick-locations', true), 'click', {tag: 'label'}, function(){ 160 ctx.setValueByLocationId(BX.data(this, 'id')); 161 }); 162 163 this.vars.outSideClickScope = this.ctrls.inputBlock; 164 }, 165 166 ////////// PUBLIC: free to use outside 167 168 // location id is just a value in terms of autocomplete 169 setValueByLocationId: function(id, autoSelect){ 170 BX.Sale.component.location.selector.search.superclass.setValue.apply(this, [id, autoSelect]); 171 }, 172 173 setValueByLocationIds: function(locationsData){ 174 if(locationsData.IDS) 175 { 176 this.displayPage( 177 { 178 'VALUE': locationsData.IDS, 179 'order': {'TYPE_ID': 'ASC', 'NAME.NAME': 'ASC'} 180 } 181 ); 182 } 183 }, 184 185 setValueByLocationCode: function(code, autoSelect){ 186 187 var sv = this.vars, 188 so = this.opts, 189 sc = this.ctrls, 190 ctx = this; 191 192 this.hideError(); 193 194 if(code == null || code == false || typeof code == 'undefined' || code.toString().length == 0){ // deselect 195 196 this.resetVariables(); 197 198 BX.cleanNode(sc.vars); 199 200 if(BX.type.isElementNode(sc.nothingFound)) 201 BX.hide(sc.nothingFound); 202 203 this.fireEvent('after-deselect-item'); 204 this.fireEvent('after-clear-selection'); 205 206 return; 207 }; 208 209 if(autoSelect !== false) 210 sv.forceSelectSingeOnce = true; 211 212 if(typeof sv.cache.nodesByCode[code] == 'undefined'){ 213 214 // lazyload it... 215 this.resetNavVariables(); 216 217 ctx.downloadBundle({CODE: code}, function(data){ 218 219 ctx.fillCache(data, false); // storing item in the cache 220 221 if(typeof sv.cache.nodesByCode[code] == 'undefined'){ // still not found 222 ctx.showNothingFound(); 223 }else{ 224 225 var value = sv.cache.nodesByCode[code].VALUE; 226
227 ////////////////// 228 if(so.autoSelectIfOneVariant || sv.forceSelectSingeOnce) 229 ctx.selectItem(value); 230 else 231 ctx.displayVariants([value]); 232 ////////////////// 233 } 234 }, function(){ 235 sv.forceSelectSingeOnce = false; 236 }); 237 238 }else{ 239 240 var value = sv.cache.nodesByCode[code].VALUE; 241 242 if(sv.forceSelectSingeOnce) 243 this.selectItem(value); 244 else 245 this.displayVariants([value]); 246 247 sv.forceSelectSingeOnce = false; 248 } 249 }, 250 251 getNodeByValue: function(value){ 252 if(this.opts.provideLinkBy == 'id') 253 return this.vars.cache.nodes[value]; 254 else 255 return this.vars.cache.nodesByCode[value]; 256 }, 257 258 getNodeByLocationId: function(value){ 259 return this.vars.cache.nodes[value]; 260 }, 261 262 setValue: function(value){ 263 264 if(this.opts.provideLinkBy == 'id') 265 BX.Sale.component.location.selector.search.superclass.setValue.apply(this, [value]); 266 else 267 this.setValueByLocationCode(value); 268 }, 269 270 getValue: function(){ 271 if(this.opts.provideLinkBy == 'id') 272 return this.vars.value === false ? '' : this.vars.value; 273 else{ 274 return this.vars.value ? this.vars.cache.nodes[this.vars.value].CODE : ''; 275 } 276 }, 277 278 getSelectedPath: function(){ 279 280 var sv = this.vars, 281 result = []; 282 283 if(typeof sv.value == 'undefined' || sv.value == false || sv.value == '') 284 return result; 285 286 if(typeof sv.cache.nodes[sv.value] != 'undefined'){ 287 var item = BX.clone(sv.cache.nodes[sv.value]); 288 if(typeof item.TYPE_ID != 'undefined' && typeof this.opts.types != 'undefined') 289 item.TYPE = this.opts.types[item.TYPE_ID].CODE; 290 291 var path = item.PATH; 292 delete(item.PATH); 293 result.push(item); 294 295 if(typeof path != 'undefined'){ 296 for(var k in path){ 297 var item = BX.clone(sv.cache.nodes[path[k]]); 298 if(typeof item.TYPE_ID != 'undefined' && typeof this.opts.types != 'undefined') 299 item.TYPE = this.opts.types[item.TYPE_ID].CODE; 300 301 delete(item.PATH); 302 303 result.push(item); 304 } 305 } 306 } 307 308 return result; 309 }, 310 311 ////////// PRIVATE: forbidden to use outside (for compatibility reasons) 312 313 setInitialValue: function(){ 314 315 if(this.opts.selectedItem !== false) // there will be always a value as ID, no matter what this.opts.provideLinkBy is equal to 316 this.setValueByLocationId(this.opts.selectedItem); 317 else if(this.ctrls.inputs.origin.value.length > 0) // there colud be eiter ID or CODE 318 { 319 if(this.opts.provideLinkBy == 'id') 320 this.setValueByLocationId(this.ctrls.inputs.origin.value); 321 else 322 this.setValueByLocationCode(this.ctrls.inputs.origin.value); 323 } 324 }, 325 326 addItem2Cache: function(item){ 327 this.vars.cache.nodes[item.VALUE] = item; 328 this.vars.cache.nodesByCode[item.CODE] = item; 329 }, 330 331 refineRequest: function(request){ 332 333 var filter = {}; 334 if(typeof request['QUERY'] != 'undefined') // search by words 335 filter['=PHRASE'] = request.QUERY; 336 337 if(typeof request['VALUE'] != 'undefined') // search by id 338 filter['=ID'] = request.VALUE; 339 340 if(typeof request['CODE'] != 'undefined') // search by code 341 filter['=CODE'] = request.CODE; 342 343 if(typeof this.opts.query.BEHAVIOUR.LANGUAGE_ID != 'undefined') 344 filter['=NAME.LANGUAGE_ID'] = this.opts.query.BEHAVIOUR.LANGUAGE_ID; 345 346 if(BX.type.isNotEmptyString(this.opts.query.FILTER.SITE_ID)) 347 filter['=SITE_ID'] = this.opts.query.FILTER.SITE_ID; 348 349 var result = { 350 'select': { 351 'VALUE': 'ID', 352 'DISPLAY': 'NAME.NAME', 353 '1': 'CODE', 354 '2': 'TYPE_ID' 355 }, 356 'additionals': { 357 '1': 'PATH' 358 }, 359 'filter': filter, 360 'version': '2' 361 }; 362 363 if(typeof request['order'] != 'undefined') 364 result['order'] = request.order; 365 366 return result; 367 }, 368 369 refineResponce: function(responce, request){ 370 371 if(typeof responce.ETC.PATH_ITEMS != 'undefined') 372 { 373 // deprecated begin 374 for(var k in responce.ETC.PATH_ITEMS){ 375 if(BX.type.isNotEmptyString(responce.ETC.PATH_ITEMS[k].DISPLAY)) 376 this.vars.cache.path[k] = responce.ETC.PATH_ITEMS[k].DISPLAY; 377 } 378 // deprecated end 379 380 for(var k in responce.ITEMS){ 381 382 var item = responce.ITEMS[k]; 383 384 if(typeof item.PATH != 'undefined') 385 { 386 var subPath = BX.clone(item.PATH); 387 for(var p in item.PATH) 388 { 389 var pItemId = item.PATH[p]; 390 391 subPath.shift(); 392 if(typeof this.vars.cache.nodes[pItemId] == 'undefined' && typeof responce.ETC.PATH_ITEMS[pItemId] != 'undefined'){ 393 394 var pItem = BX.clone(responce.ETC.PATH_ITEMS[pItemId]); 395 pItem.PATH = BX.clone(subPath); 396 this.vars.cache.nodes[pItemId] = pItem; 397 } 398 } 399 } 400 } 401 } 402 403 return responce.ITEMS; 404 }, 405 406 refineItems: function(items){ 407 return items; 408 }, 409 410 refineItemDataForTemplate: function(itemData){ 411 return itemData; 412 }, 413 414 // custom value getter (obsolete method) 415 getSelectorValue: function(value){ 416 417 if(this.opts.provideLinkBy == 'id') 418 return value; 419 420 if(typeof this.vars.cache.nodes[value] != 'undefined') 421 return this.vars.cache.nodes[value].CODE; 422 else 423 return ''; 424 }, 425 426 whenLoaderToggle: function(way){ 427 BX[way ? 'show' : 'hide'](this.ctrls.loader); 428 } 429 430 }); 431}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.