OLD | NEW |
(Empty) | |
| 1 #import('dart:html'); |
| 2 #source('realviews.dart'); |
| 3 |
| 4 class Division { |
| 5 String name; |
| 6 int id; |
| 7 List<Product> products; |
| 8 |
| 9 Division(this.name, this.id, this.products); |
| 10 } |
| 11 |
| 12 class Product { |
| 13 int id; |
| 14 String name; |
| 15 int users; |
| 16 List<YTD_Sales> sales; |
| 17 |
| 18 Product(this.id, this.name, this.users, this.sales); |
| 19 } |
| 20 |
| 21 class YTD_Sales { |
| 22 int yearly; |
| 23 String country; |
| 24 |
| 25 YTD_Sales(this.yearly, this.country); |
| 26 } |
| 27 |
| 28 // TODO(terry): Remove use for debug only. |
| 29 void debug() { |
| 30 try { |
| 31 throw "DEBUG"; |
| 32 } catch (var e) { |
| 33 print("DEBUGBREAK"); |
| 34 } |
| 35 } |
| 36 |
| 37 void main() { |
| 38 List<Division> divisions = []; |
| 39 List<Product> products; |
| 40 List<YTD_Sales> sales; |
| 41 |
| 42 products = []; |
| 43 sales = []; |
| 44 sales.add(new YTD_Sales(52000000, "USA")); |
| 45 sales.add(new YTD_Sales(550000, "China")); |
| 46 sales.add(new YTD_Sales(56000000, "EU")); |
| 47 sales.add(new YTD_Sales(510000, "Canada")); |
| 48 sales.add(new YTD_Sales(58700028, "Mexico")); |
| 49 products.add(new Product(100, "Gmail", 75000000, sales)); |
| 50 |
| 51 sales = []; |
| 52 sales.add(new YTD_Sales(12000000, "USA")); |
| 53 sales.add(new YTD_Sales(50000, "China")); |
| 54 sales.add(new YTD_Sales(6000000, "EU")); |
| 55 sales.add(new YTD_Sales(10000, "Canada")); |
| 56 sales.add(new YTD_Sales(8700028, "Mexico")); |
| 57 products.add(new Product(101, "Talk", 5000000, sales)); |
| 58 divisions.add(new Division("Apps", 1, products)); |
| 59 |
| 60 products = []; |
| 61 sales = []; |
| 62 sales.add(new YTD_Sales(200000, "USA")); |
| 63 sales.add(new YTD_Sales(20000, "China")); |
| 64 sales.add(new YTD_Sales(2200000, "EU")); |
| 65 sales.add(new YTD_Sales(10000, "Canada")); |
| 66 sales.add(new YTD_Sales(100, "Mexico")); |
| 67 products.add(new Product(200, "iGoogle", 2000000, sales)); |
| 68 divisions.add(new Division("Misc", 3, products)); |
| 69 |
| 70 products = []; |
| 71 sales = []; |
| 72 sales.add(new YTD_Sales(1200, "USA")); |
| 73 sales.add(new YTD_Sales(50, "China")); |
| 74 sales.add(new YTD_Sales(600, "EU")); |
| 75 sales.add(new YTD_Sales(10, "Canada")); |
| 76 sales.add(new YTD_Sales(8, "Mexico")); |
| 77 products.add(new Product(300, "Dart", 2000, sales)); |
| 78 divisions.add(new Division("Chrome", 2, products)); |
| 79 |
| 80 products = []; |
| 81 sales = []; |
| 82 divisions.add(new Division("Search", 4, products)); |
| 83 |
| 84 var header = new Header("Google World Wide", new Date.now()); |
| 85 var listView = new DivisionSales(divisions); |
| 86 |
| 87 document.body.elements.add(header.root); // Add top view. |
| 88 document.body.elements.add(listView.root); // Add list view. |
| 89 |
| 90 // Hookup events. |
| 91 for (var elem in listView.productZippy) { |
| 92 elem.on.click.add((MouseEvent e) { |
| 93 var expandCollapseElem = e.toElement; |
| 94 |
| 95 DivElement salesDiv = expandCollapseElem.parent.elements.last(); |
| 96 |
| 97 bool showSales = (salesDiv.classes.contains(DivisionSales.showSales)); |
| 98 |
| 99 expandCollapseElem.innerHTML = showSales ? "▶": "▼"; |
| 100 expandCollapseElem.classes.remove(showSales ? DivisionSales.expand : Divis
ionSales.collapse); |
| 101 expandCollapseElem.classes.add(showSales ? DivisionSales.collapse : Divisi
onSales.expand); |
| 102 |
| 103 salesDiv.classes.clear(); |
| 104 salesDiv.classes.add(showSales ? DivisionSales.hideSales : DivisionSales.s
howSales); |
| 105 }); |
| 106 } |
| 107 } |
| 108 |
OLD | NEW |