text: 'use strict';
  
  angular.module('webApp.welcome', ['ngRoute', 'firebase'])
  
  .config(['$routeProvider', function($routeProvider){
  	$routeProvider.when('/welcome',{
  		templateUrl: 'welcome/welcome.html',
  		controller: 'WelcomeCtrl'
  	});
  }])
  
  .controller('WelcomeCtrl', ['$scope', 'CommonProp', '$firebaseArray', '$firebaseObject', '$location', function($scope, CommonProp, $firebaseArray, $firebaseObject, $location){
  	$scope.username = CommonProp.getUser();
  
  	if(!$scope.username){
  		$location.path('/home');
  	}
  
  	var ref = firebase.database().ref().child('Articles');
  	$scope.articles = $firebaseArray(ref);	
  
  	$scope.editPost = function(id){
  		var ref = firebase.database().ref().child('Articles/' + id);
  		$scope.editPostData = $firebaseObject(ref);
  	};
  
  	$scope.updatePost = function(id){
  		var ref = firebase.database().ref().child('Articles/' + id);
  		ref.update({
  			title: $scope.editPostData.title,
  			post: $scope.editPostData.post
  		}).then(function(ref){
  			$scope.$apply(function(){
  				$("#editModal").modal('hide');
  				$("#editModal").removeClass('show');
  				$('.modal-backdrop').remove();
  				
  			});
  		}, function(error){
  			console.log(error);
  		});
  	};
  
  	$scope.deleteCnf = function(article){
  		$scope.deleteArticle = article;
  	};
  
  	$scope.deletePost = function(deleteArticle){
  		$scope.articles.$remove(deleteArticle);
  		$("#deleteModal").modal('hide');
  		$("#deleteModal").removeClass('show');
  		$(".modal-backdrop").remove();
  	};
  
  	$scope.logout = function(){
  		CommonProp.logoutUser();
  	}
  }])