// you need to define javascript variables in your base jsp, which value is dynamic generated // shopRestAirport - airport for the portlet // when terminal changed, call method terminalChanged // shoplocation changed, call method shopLocationChanged // category changed, call method categoryChanged // // call chain: updateShopLocations --> updateShopLocationsResult --> // updateCategories --> updateCategoriesResult --> // updateShops --> updateShopsResult // function terminalChanged(targetForm) { shopRestAjaxSearchForm = targetForm; var terminalValue = shopRestAirport; if(shopRestAjaxSearchForm.terminal) { terminalValue = shopRestAjaxSearchForm.terminal.value; } updateShopLocations(shopRestAirport, terminalValue); } function shopLocationChanged(targetForm) { shopRestAjaxSearchForm = targetForm; var terminalValue = shopRestAirport; if(shopRestAjaxSearchForm.terminal) { terminalValue = shopRestAjaxSearchForm.terminal.value; } updateCategories(shopRestAjaxSearchForm.shoptype.value, shopRestAirport, terminalValue, shopRestAjaxSearchForm.shoplocation.value); } function categoryChanged(targetForm) { shopRestAjaxSearchForm = targetForm; var terminalValue = shopRestAirport; if(shopRestAjaxSearchForm.terminal) { terminalValue = shopRestAjaxSearchForm.terminal.value; } updateShops(shopRestAjaxSearchForm.shoptype.value, shopRestAirport, terminalValue, shopRestAjaxSearchForm.shoplocation.value, shopRestAjaxSearchForm.category.value); } var shopRestAjaxshopRestAjaxSearchForm; var shopRestLocation = 'All'; function updateShopLocations(airport, terminal) { dwr.engine.setHttpMethod("GET"); shopRestLocation = dwr.util.getValue(shopRestAjaxSearchForm.shoplocation); shopRestAjaxSearchForm.shoplocation.disabled = true; shopRestAjaxSearchForm.category.disabled = true; shopRestAjaxSearchForm.shop.disabled = true; AjaxShopRestSearchHelper.getLocations(airport, terminal, updateShopLocationsResult); } function updateShopLocationsResult(locationList) { shopRestAjaxSearchForm.shoplocation.disabled = false; dwr.util.removeAllOptions(shopRestAjaxSearchForm.shoplocation); dwr.util.addOptions(shopRestAjaxSearchForm.shoplocation, [ { name:"Choose a location", value:"All" } ], 'value', 'name'); dwr.util.addOptions(shopRestAjaxSearchForm.shoplocation, locationList, 'location'); dwr.util.setValue(shopRestAjaxSearchForm.shoplocation,shopRestLocation); var terminalValue = shopRestAirport; if(shopRestAjaxSearchForm.terminal) { terminalValue = shopRestAjaxSearchForm.terminal.value; } updateCategories(shopRestAjaxSearchForm.shoptype.value, shopRestAirport, terminalValue, shopRestAjaxSearchForm.shoplocation.value); } var shopRestCategory = ''; function updateCategories(shoptype, airport, terminal, shoplocation) { dwr.engine.setHttpMethod("GET"); shopRestCategory = dwr.util.getValue(shopRestAjaxSearchForm.category); shopRestAjaxSearchForm.category.disabled = true; shopRestAjaxSearchForm.shop.disabled = true; AjaxShopRestSearchHelper.getCategories(shoptype, airport, terminal, shoplocation, updateCategoriesResult); } function updateCategoriesResult(categoryList) { shopRestAjaxSearchForm.category.disabled = false; dwr.util.removeAllOptions(shopRestAjaxSearchForm.category); dwr.util.addOptions(shopRestAjaxSearchForm.category, [ { name:"Choose a category", value:"" } ], 'value', 'name'); dwr.util.addOptions(shopRestAjaxSearchForm.category, categoryList, 'id', 'category'); dwr.util.setValue(shopRestAjaxSearchForm.category,shopRestCategory); var terminalValue = shopRestAirport; if(shopRestAjaxSearchForm.terminal) { terminalValue = shopRestAjaxSearchForm.terminal.value; } updateShops(shopRestAjaxSearchForm.shoptype.value, shopRestAirport, terminalValue, shopRestAjaxSearchForm.shoplocation.value, shopRestAjaxSearchForm.category.value); } var shopRestShop = ''; function updateShops(shoptype, airport, terminal, shoplocation, category) { dwr.engine.setHttpMethod("GET"); shopRestShop = dwr.util.getValue(shopRestAjaxSearchForm.shop); shopRestAjaxSearchForm.shop.disabled = true; AjaxShopRestSearchHelper.getShops(shoptype, airport, terminal, shoplocation, category, updateShopsResult); } function updateShopsResult(shopList) { shopRestAjaxSearchForm.shop.disabled = false; dwr.util.removeAllOptions(shopRestAjaxSearchForm.shop); dwr.util.addOptions(shopRestAjaxSearchForm.shop, [ { name:getShopRestChoosePhrase(), value:"" } ], 'value', 'name'); dwr.util.addOptions(shopRestAjaxSearchForm.shop, shopList, 'name'); dwr.util.setValue(shopRestAjaxSearchForm.shop,shopRestShop); } function getShopRestChoosePhrase() { if( shopRestAjaxSearchForm.shoptype.value == 'Shop') { return 'Choose a shop'; } else { return 'Choose a restaurant/bar'; } }