disable category create button
[outofuni/tavern2.git] / lib / product_category_component.dart
1 // Copyright (c) 2016, hackbard. All rights reserved. Use of this source code
2 // is governed by a BSD-style license that can be found in the LICENSE file.
3
4 import 'dart:async';
5
6 import 'package:angular2/core.dart';
7 import 'package:angular2/router.dart';
8
9 import 'product_category.dart';
10 import 'product_category_service.dart';
11
12 import 'package:angular2_rbi/directives.dart';
13
14 @Component(
15         selector: 'my-product-categories',
16         templateUrl: 'product_category_component.html',
17         styleUrls: const ['product_category_component.css'],
18         directives: const [MaterialTextfield,MaterialButton],
19         providers: const [ProductCategoryService]
20 )
21
22 class ProductCategoryComponent implements OnInit {
23         List<ProductCategory> product_categories;
24         ProductCategory selected_prod_category;
25         String new_prod_category_name;
26         String new_prod_category_id;
27         final ProductCategoryService _prodcatSrv;
28         final Router _router;
29         var docreate=false;
30
31         ProductCategoryComponent(this._prodcatSrv,this._router);
32
33         Future<Null> getProductCategories() async {
34                 product_categories = await _prodcatSrv.getAll();
35         }
36
37         Future<Null> createProductCategory() async {
38                 await _prodcatSrv.createProdCategory(
39                         new_prod_category_name,
40                         new_prod_category_id
41                 );
42         }
43
44         void ngOnInit() {
45                 getProductCategories();
46         }
47
48         void checkInput() {
49                 if(new_prod_category_name=='' || new_prod_category_id=='') {
50                         docreate=false;
51                 }
52                 else {
53                         docreate=true;
54                         for(var cat in product_categories) {
55                                 if(cat.id==new_prod_category_id) {
56                                         docreate=false;
57                                         break;
58                                 }
59                         }
60                 }
61         }
62
63         choose(ProductCategory pt) {
64                 selected_prod_category=pt;
65                 goto_products(pt);
66         }
67
68         Future<Null> goto_products(ProductCategory pt) => _router.navigate([
69                 'Products',
70                 {'id': pt.id.toString()}
71         ]);
72 }
73