| OLD | NEW |
| (Empty) |
| 1 library company_info_loader; | |
| 2 | |
| 3 import 'dart:html'; | |
| 4 | |
| 5 import 'package:web_ui/web_ui.dart'; | |
| 6 import 'package:route_hierarchical/client.dart'; | |
| 7 | |
| 8 import 'data.dart' as data; | |
| 9 | |
| 10 | |
| 11 class CompanyInfoLoaderComponent extends WebComponent { | |
| 12 RouteHandle route; | |
| 13 @observable var company; | |
| 14 @observable Route companyRoute; | |
| 15 | |
| 16 inserted() { | |
| 17 companyRoute = route.getRoute('companyId'); | |
| 18 companyRoute.onRoute.listen(_showCompanyInfo); | |
| 19 } | |
| 20 | |
| 21 removed() { | |
| 22 route.discard(); | |
| 23 } | |
| 24 | |
| 25 _showCompanyInfo(RouteEvent e) { | |
| 26 var tokenInt = int.parse(e.parameters['companyId'], onError: (s) => -1); | |
| 27 if (tokenInt > -1) { | |
| 28 data.fetchCompany(tokenInt).then((result) { | |
| 29 if (result == null) { | |
| 30 window.alert('Unable to fetch company $tokenInt'); | |
| 31 } | |
| 32 company = result; | |
| 33 }); | |
| 34 } else { | |
| 35 // TODO: navigate to invalid company route... | |
| 36 window.alert('Invalid company id $tokenInt'); | |
| 37 } | |
| 38 } | |
| 39 } | |
| OLD | NEW |