Files
Plataforma-de-desarrolladores/SIG.Web/Scripts/CatalogosTramites.js
Jorge Luis caudillo esparza c6cb8d5cce --
2026-08-28 06:36:39 -07:00

134 lines
3.9 KiB
JavaScript

(function (window, $) {
"use strict";
window.SIGTramiteCatalog = window.SIGTramiteCatalog || {};
window.SIGTramiteCatalog.show = function (id) {
var modal = $("#" + id);
modal.modal("show");
if (window.App && App.initAjax) {
App.initAjax();
}
};
window.SIGTramiteCatalog.hide = function (id) {
$("#" + id).modal("hide");
};
function preserveCellWidths(event, row) {
var cells = row.children();
cells.each(function () {
$(this).width($(this).width());
});
return row;
}
function sendOrderMove(grid, row) {
var movedId = row.find(".tra-order-handle").attr("data-sig-order-id");
var referenceRow = row.prev("tr:has(.tra-order-handle)");
var placeAfter = true;
if (referenceRow.length === 0) {
referenceRow = row.next("tr:has(.tra-order-handle)");
placeAfter = false;
}
if (!movedId || referenceRow.length === 0) {
return;
}
var movedGroup = row
.find(".tra-order-handle")
.attr("data-sig-order-group") || "";
var referenceHandle = referenceRow.find(".tra-order-handle");
var referenceGroup = referenceHandle.attr("data-sig-order-group") || "";
if (movedGroup !== referenceGroup) {
grid.find("tbody").sortable("cancel");
return;
}
var referenceId = referenceHandle.attr("data-sig-order-id");
var payload = document.getElementById(
grid.attr("data-sig-order-payload"));
var postBackButton = document.getElementById(
grid.attr("data-sig-order-postback"));
if (!referenceId || !payload || !postBackButton) {
return;
}
payload.value = movedId + "|" + referenceId + "|" + (placeAfter ? "1" : "0");
grid.find("tbody").sortable("disable");
postBackButton.click();
}
function initializeOrderGrids(root) {
var container = $(root || document);
var grids = container
.find('[data-sig-order-grid="1"]:not([data-sig-order-initialized="1"])')
.addBack('[data-sig-order-grid="1"]:not([data-sig-order-initialized="1"])');
grids.each(function () {
var grid = $(this);
var body = grid.find("tbody");
if (body.length === 0 ||
body.find(".tra-order-handle").length < 2 ||
!$.fn.sortable) {
return;
}
body.sortable({
axis: "y",
cursor: "move",
handle: ".tra-order-handle",
helper: preserveCellWidths,
items: "> tr:has(.tra-order-handle)",
placeholder: "tra-order-placeholder",
update: function (event, ui) {
sendOrderMove(grid, ui.item);
}
});
grid.attr("data-sig-order-initialized", "1");
});
}
window.SIGTramiteCatalog.initializeOrderGrids = initializeOrderGrids;
if (window.SIG_TRAMITE_CATALOG_EVENTS_REGISTERED === true) {
initializeOrderGrids(document);
return;
}
window.SIG_TRAMITE_CATALOG_EVENTS_REGISTERED = true;
$(document).on(
"click.sigTramiteCatalog",
"[data-sig-options-toggle]",
function () {
var target = $($(this).attr("data-sig-options-toggle"));
target.toggleClass("is-collapsed");
$(this).find(".js-toggle-label").text(
target.hasClass("is-collapsed")
? "Mostrar respuestas"
: "Ocultar respuestas");
});
if (window.Sys && Sys.Application) {
Sys.Application.add_load(function () {
initializeOrderGrids(document);
});
} else {
$(function () {
initializeOrderGrids(document);
});
}
}(window, window.jQuery));