1
+ greenlistApp . controller ( "ShoppingListCtrl" ,
2
+ [ "CurrentAuth" , "$scope" , "UserInfo" , "DatabaseRef" , "$firebaseObject" , "$modal" , "$window" , "DatabaseQuery" ,
3
+ function ( CurrentAuth , $scope , UserInfo , DatabaseRef , $firebaseObject , $modal , $window , DatabaseQuery ) {
4
+
5
+ UserInfo . initUser ( CurrentAuth . displayName , CurrentAuth . uid , CurrentAuth . photoURL ) ;
6
+
7
+ // Setting shopping list page heading content and nav bar button style
8
+ $scope . heading = 'Shopping List' ;
9
+ $scope . listBtnColor = 'green' ;
10
+ $scope . histBtnColor = 'white' ;
11
+ $scope . reptBtnColor = 'white' ;
12
+ $scope . listColor = 'white' ;
13
+ $scope . histColor = 'black' ;
14
+ $scope . reptColor = 'black' ;
15
+ $scope . listBgImg = 'images/list-icon-on.png' ;
16
+ $scope . histBgImg = 'images/hist-icon-off.png' ;
17
+ $scope . reptBgImg = 'images/rept-icon-off.png' ;
18
+
19
+
20
+ var uncheckedItems = $firebaseObject ( DatabaseRef . getUncheckedItems ( ) ) ;
21
+ uncheckedItems . $bindTo ( $scope , "uncheckedItems" ) ;
22
+
23
+ var checkedItems = $firebaseObject ( DatabaseRef . getCheckedItems ( ) ) ;
24
+ checkedItems . $bindTo ( $scope , "checkedItems" ) ;
25
+
26
+ $scope . toggleCheck = function ( item , status ) {
27
+ DatabaseQuery . updateCheckedStatus ( item , status ) ;
28
+ }
29
+
30
+ $scope . addItem = function ( item ) {
31
+ DatabaseQuery . addItem ( item ) ;
32
+ $scope . newItemName = "" ;
33
+ }
34
+
35
+ $scope . deleteItem = function ( item ) {
36
+ if ( item . dataUpdated == undefined ) {
37
+ DatabaseQuery . deleteItem ( item ) ;
38
+ } else {
39
+ DatabaseQuery . setItemList ( item , "history" ) ;
40
+ }
41
+ }
42
+
43
+ $scope . archive = function ( ) {
44
+ DatabaseRef . getCheckedItems ( )
45
+ . once ( "value" )
46
+ . then ( function ( data ) {
47
+
48
+ data . forEach ( function ( item ) {
49
+ DatabaseQuery . updateWasteDataStatus ( item . val ( ) , false ) ;
50
+ DatabaseQuery . setItemList ( item . val ( ) , "history" ) ;
51
+ } ) ;
52
+
53
+ } ) ;
54
+
55
+ DatabaseRef . getUncheckedItems ( )
56
+ . once ( "value" )
57
+ . then ( function ( data ) {
58
+
59
+ data . forEach ( function ( item ) {
60
+
61
+ if ( item . val ( ) . dataUpdated == undefined ) {
62
+ DatabaseQuery . deleteItem ( item . val ( ) ) ;
63
+ } else {
64
+ DatabaseQuery . setItemList ( item . val ( ) , "history" ) ;
65
+ }
66
+
67
+ } ) ;
68
+
69
+ } ) ;
70
+ }
71
+
72
+ } ] ) ;
0 commit comments