"use strict";
appCore.controller("projectTypeMasterCtrl", ["$state", "$scope", "$http", "$timeout", "vServices", function ($state, $scope, $http, $timeout, vServices) {
    $scope.params = $state.params;
    $scope.$root.page.title = "Project Type";
    $scope.dataList = [];
    
    $scope.edit = (dl) => {
        $scope.data = JSON.parse(JSON.stringify(dl));
        $scope.page.type = "Edit";
        $(document).find("#tag").focus();
        window.screen.width < 768 ? window.scrollTo(0, 0) : null;
        setTimeout(() => {
            $(document).find("#formCard").addClass("highlightme");
            setTimeout(() => {
                $(document).find("#formCard").removeClass("highlightme");
            }, 800);
        }, (window.screen.width < 768 ? 500 : 0));
    };

    $scope.delete = (d) => {
        console.log(d.id);
        vServices.callApi("project/deleteProjectType/" + d.id , "DELETE" , {}).then(function (res) {
            if (res) toastr.success(res, "Success!", {timeOut: 5000});
            $state.go($state.current, {}, {reload: true});
        });
    };
    $scope.add = (d) => {
        vServices.callApi("project/addOrEditProjectTypeMaster/" + (d.id ? "edit" : "add"), d.id ? "PUT" : "POST", d).then(function (res) {
            if (res) toastr.success(res, "Success!", {timeOut: 5000});
            $state.go($state.current, {}, {reload: true});
        });
    };
    const init = function () {
            $scope.dataList = [];
            vServices.callApi("project/projectType_master", "GET", {}).then((res) => {
                $scope.dataList = res;
            });
        }
    ;
    init();

}
]);



