<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">angular.module("CMS")
    .directive('cmsSampleKitList', ['$timeout', '$q', '$uibModal', '$state', 'auth', 'Confirmer', '$sce', '$http', 'SampleKit', function ($timeout, $q, $uibModal, $state, auth, Confirmer, $sce, $http, SampleKit) {
        return {
            restrict: 'E',
            scope: {
                inspectionId: "=",
                readOnly: "=?",
                onLoaded: "=?",
                showDeleted: "="
            },
            templateUrl: "/templates/directives/cms-sample-kit-list.html",
            controller: function ($scope, $element, $state, $window) {
                var self = $scope;
                $scope.loading = false;
                $scope.sampleKits = null;

                $scope.loadTimer = null;

                $scope.load = function () {
                    if ($scope.loadTimer) $timeout.cancel($scope.loadTimer);
                    $scope.loadTimer = $timeout(function () {
                        if ($scope.inspectionId) {
                            let deletedFilter = "Deleted eq 0 and ";
                            if ($scope.showDeleted) deletedFilter = "";
                            SampleKit.get({ $filter: deletedFilter + "ParentID eq " + $scope.inspectionId, $select: "ID,ParentID,ShippedToLabDate,ShippedToLabTrackingNumber,LabBoxIdentifier,Deleted,LabDeliveryDate,LabDeliveryStatus,LabDeliveryDetails,ShippedFromLabMethod" }).then(function (data) {
                                $scope.sampleKits = data.value;
                                if ($scope.onLoaded) $scope.onLoaded(data.value);
                                $scope.loading = false;
                            });
                        }
                        else {
                            $scope.sampleKits = null;
                            if ($scope.onLoaded) $scope.onLoaded(null);
                            $scope.loading = false;
                        }
                    }, 10);
                }


                $scope.$watch("inspectionId", function (newVal, oldVal) {
                    $scope.load();
                });

                $scope.$watch("showDeleted", function (newVal, oldVal) {
                    $scope.load();
                });


                $scope.addSampleKit = function () {
                    SampleKit.new().then(function (data) {
                        data.Deleted = 0;
                        data.ParentID = $scope.inspectionId;
                        data.ShippedToLabDate = new Date();
                        data.LabID = "ACA93561-4C26-4C89-8B91-58239AC14A2E";
                        data.ShippedToLab = true;
                        data.persist().then(function (data) {
                            $scope.sampleKits.push(data);
                        });
                    });
                }

                $scope.updateSampleKit = function (sk) {
                    SampleKit.patchObject(sk.ID, { ShippedToLabTrackingNumber: sk.ShippedToLabTrackingNumber, LabDeliveryDate: null, LabDeliveryStatus: null, LabDeliveryDetails: null, LabBoxIdentifier: sk.LabBoxIdentifier, ShippedToLabDate: sk.ShippedToLabDate });
                }
                $scope.deleteSampleKit = function (sk) {
                    Confirmer.confirm("Are you sure you want to delete this sample kit?").then(function (answer) {
                        if (answer) {
                            SampleKit.patchObject(sk.ID, { Deleted: 1 }).then(function (data) {
                                sk.Deleted = true;
                            });
                        }
                    });
                }
            }
        }
    }]);</pre></body></html>