
app.controller("teamSubmit",
               
               function($scope, $firebaseArray){
                
                $scope.input = {
		event:"",
                    name:"",
                    intro:"",
                    holder:"",
                    state:false,
                    teamleader:"",
                    member:""
                };
                
                var ref=firebase.database().ref("events");
                
                $scope.submit = function() {
                    
                    if($scope.input.name!==""&&$scope.input.intro!==""){
                        $scope.input.state=true;
                        $scope.input.holder=1;
                        $scope.team = {
                              name:"",
			intro:"",
            			teamleader:"",
                        openness:true	,
                        member:""				
			};
                        $scope.team.teamleader=firebase.auth().currentUser.uid;
                              $scope.team.name=$scope.input.name;
                              $scope.team.intro=$scope.input.intro;
                              childRef=ref.child($scope.input.event);
                              if(firebase.auth().currentUser){
                                        ref.orderByChild("name").equalTo($scope.input.event).once("child_added",function(location){
                                                  location.child("Team").ref.push().set($scope.team);
                                        });
				}
                              else{
                                        window.alert("Please sign in first!");
                              }
                              $scope.input.event= "";
                              $scope.input.intro= "";
                              $scope.input.name= "";
								                    

                    
                    }
                    
                    
                    
                };
                
                
               }
               
               
);
@@ -138,18 +138,36 @@
 put = %7B%0A
-%09%09
+                    
 event:%22%22
@@ -763,34 +763,32 @@
                 
-  
 name:%22%22,%0A%09%09%09intr
@@ -784,21 +784,57 @@
 %22%22,%0A
-%09%09%09intro:%22%22,%0A
+                            intro:%22%22,%0A           
     
@@ -841,19 +841,21 @@
         
-%09%09%09
+     
 teamlead
@@ -853,32 +853,36 @@
  teamleader:%22%22,%0A
+    
                 
@@ -921,32 +921,36 @@
                 
+    
 member:%22%22%09%09%09%09%0A%09%09
@@ -946,18 +946,292 @@
 r:%22%22
-%09%09%09%09%0A%09%09%09%7D;
+,%0A                            numberOfmember:0%0A                        %7D;%0A                        %0A                        var eventRef=firebase.database().ref(%22events%22);%0A                        var memberNoTeamRef=firebase.database().ref(%22memberWithNoTeam%22);%0A                        
 %0A   
@@ -1808,16 +1808,1254 @@
 .team);%0A
+                                    %0A////%0A                                                  memberNoTeamRef.orderByChild(%22uid%22).equalTo(firebase.auth().currentUser.uid).once(%22child_added%22,%0A                                                      function(oldLocation)%7B%0A                                                        movingMember=oldLocation.val();%0A                                                        location.ref.child(%22Team%22).orderByChild(%22name%22).equalTo($scope.team.name).once(%22child_added%22,function(newLocation)%7B%0A                                                            newLocation.child(%22member%22).ref.push().set(movingMember);%0A                                                            newLocation.ref.update(%7BnumberOfmember: newLocation.val().numberOfmember+1%7D);%0A                                                            oldLocation.ref.remove();%0A                                                            window.alert(%22Create team success!%22);%0A                                                          %0A                                                        %7D);%0A                            %0A                                                  %7D);     %0A////         %0A                                                  %0A
         
@@ -3090,20 +3090,47 @@
     %7D);%0A
-%09%09%09%09
+%0A                              
 %7D%0A      

Add teamleader into team>member, and remove teamleader form memberWithNoTeam