poconsole.controller('fluidShotCtrl', function($scope, Page, FluidShot) {
	Page.setTitle('Fluid Shots');
    Page.setPage('fluidshot');

    $scope.loadFluidShotData = function(page_number){
        var getData = FluidShot.getFluidShotPage(page_number);
        getData.then(function(d){
            for(var j = 0; j < d.objects.length; j++){
                d.objects[j].created_on = Date.create(d.objects[j].created_on + "Z", { fromUTC: true });
            }
            $scope.fluid_shots = d.objects;
            $scope.num_pages = d.total_pages;
            $scope.page_list = [];
            $scope.page_num = d.page;
            $scope.total = d.total;
        });
    };

    $scope.loadFluidShotData(1);

    $scope.startCreateFluidShot = function(){
        $scope.newFluidShot = {
            'pump_intake_pressure': 1000,
            'created_on': Date.create()
        };
    };

    $scope.submitNewFluidShot = function(){
        var temp_date = Date.create($scope.newFluidShot.created_on);
        $scope.newFluidShot.created_on = temp_date.utc().format('{yyyy}-{MM}-{dd}T{HH}:{mm}:00.00000');
        var createFluidShot = FluidShot.createFluidShot($scope.newFluidShot);
        createFluidShot.then(function(response_data){
            console.log("Response from API");
            console.log(response_data);
            $scope.loadFluidShotData(1);
        });
    };

    $scope.startEditFluidShot = function(id){
        var getEditFluidShotData = FluidShot.getFluidShot(id);
        getEditFluidShotData.then(function(d){
            $scope.editFluidShot = d;
            $scope.editFluidShot.created_on = Date.utc.create($scope.editFluidShot.created_on);
        });
    };

    $scope.submitEditFluidShot = function(){
        var temp_date = Date.create($scope.editFluidShot.created_on);
        $scope.editFluidShot.created_on = temp_date.utc().format('{yyyy}-{MM}-{dd}T{HH}:{mm}:00.00000');
        var updateFluidShot = FluidShot.updateFluidShot($scope.editFluidShot);
        updateFluidShot.then(function(response_data){
            console.log("Response from API");
            console.log(response_data);
            $scope.loadFluidShotData(1);
        });
    };

    $scope.openDeleteFluidShot = function(id){
        var getDeleteFluidShotData = FluidShot.getFluidShot(id);
        getDeleteFluidShotData.then(function(d){
            $scope.deleteFluidShot = d;
        });
    };

    $scope.submitDeleteFluidShot = function(){
        var deleteSelectedFluidShot = FluidShot.deleteFluidShot($scope.deleteFluidShot._id);
        deleteSelectedFluidShot.then(function(data){
            $scope.loadFluidShotData(1);
        });
    };
});
