function DetalheDemanda() {
    const mSelf = this;
    mSelf.Demanda = ko.observable(null);
    mSelf.DemandaSelecionada = null;

    mSelf.CarregarDemanda = function (demandaSelecionada, grid) {
        $.ajax({
            url: urlGlobal + "DemandaTarefa/Demanda/CarregarDetalheDemanda",
            contentType: 'application/json; charset=utf-8',
            dataType: "json",
            type: "GET",
            data: { codigoDemanda: demandaSelecionada.Codigo() },
            success: function (ret) {
                mSelf.DemandaSelecionada = demandaSelecionada;
                const data = ko.mapping.fromJS(ret);

                data.Latitude(data.Latitude() / 1000000);
                data.Longitude(data.Longitude() / 1000000);

                mSelf.Demanda(data);
                mSelf.Registrar();

                vm.Perspectiva.SetoresMapa
                    .SelecionarMarker(demandaSelecionada.Codigo(), grid);

                $(".sb_demanda").fadeIn("fast");
                vm.currentMap.fitBoundsMarkers('demandas', (item) => item.Codigo === demandaSelecionada.Codigo());
            }
        });
    };

    mSelf.EditarDemanda = () => vm.Perspectiva.DemandaViewModel().ModalEditarDemanda(mSelf.DemandaSelecionada)

    mSelf.Registrar = function () {
        $('.flexslider-shotbox').removeData("flexslider");

        $('.flexslider-shotbox').flexslider({
            animation: "slide",
            animationLoop: false,
            slideshow: false,
            itemWidth: 130,
            itemMargin: 10,
            minItems: 3,
            maxItems: 3,
            controlNav: false
        });

        $(".flexslider-shotbox .slides > li, .count-photos").unbind();

        $(".flexslider-shotbox .slides > li, .count-photos").on("click", function (e) {
            e.stopPropagation();
            vm.Perspectiva.GaleriaDemanda.CarregarGaleria(mSelf.DemandaSelecionada.Codigo(), $(this).index())
        });
    }

    mSelf.FecharModalDetalhes = () => $(".sb_demanda").fadeOut("fast");
}