var connPointActivity = {
init: function () {
var me = this;
accordionFunc();
initUI();
$(".switch").bootstrapSwitch();
var connPointId = $("#connpoint-id").val();
me.connPointId = connPointId;
this.baCladdr = $("#ba").cofUltimateCladdr();
this.cpCladdr = $("#cp").cofUltimateCladdr();
this.cpSewerCladdr = $("#cp_sewer").cofUltimateCladdr();
this.loadFromCookies();
// $("form").valid();
$("#btn-copy").click(function () {
$("#cpParams").find("input,select").each(function () {
var name = $(this).attr("name");
if (!!name) {
var value = $(this).val();
var id2 = name.replace(/'cp_/g, "'cp_sewer_");
id2 = id2.replace(/'/g, "\\'");
$("[name='" + id2 + "']").val(value);
}
});
});
$("#CPResource").change(function () {
var id = $("#CPResource").val();
$("#CPSource").foo("t" + id);
$("#CPType").foo("t" + id);
});
var id = $("#CPResource").val();
$("#CPSource option:not(.t" + id + ")").appendTo($("#CPSource").siblings("div.hiddenOptions"));
$("#CPType option:not(.t" + id + ")").appendTo($("#CPType").siblings("div.hiddenOptions"));
$("#CPSewerResource").change(function () {
var id = $("#CPSewerResource").val();
$("#CPSewerSource").foo("t" + id);
$("#CPSewerType").foo("t" + id);
});
var id = $("#CPSewerResource").val();
$("#CPSewerSource option:not(.t" + id + ")").appendTo($("#CPSewerSource").siblings("div.hiddenOptions"));
$("#CPSewerType option:not(.t" + id + ")").appendTo($("#CPSewerType").siblings("div.hiddenOptions"));
var cpnamechanged = false;
$("#connection-union-name").keyup(function () {
if (!cpnamechanged) {
var name = $(this).val();
$("#CPName").val(name);
}
});
$("#CPName").change(function () {
var name = $(this).val();
if (!name || name == "") {
cpnamechanged = false;
} else {
cpnamechanged = true;
}
})
if (!!connPointId) {
this.loadContractObjectCalcPointsList([
{field: "connectionPoint.id", value: connPointId, filterType: "EQ"}
]);
}
if (true || USER_GROUP == "JUR_GROUP") {
$("#btn-add-accDevice").click(function () {
if (!$(this).hasClass("disabled")) {
$.cookie("data['connpoint_id']", me.connPointId);
goto("/accdevice", null);
}
});
$("#btn-add-accDevice-del").click(function () {
if (!$(this).hasClass("disabled"))
$.ajax({
type: "post",
data: "id=" + $("#cp-accDevices-list")[0].selected,
url: "/app/contract/connectionpoint/accdevice/delete",
success: function (result) {
$("#btn-add-accDevice-del").addClass("disabled");
me.loadAccountDevicesList([
{field: "connectionPoint.id", value: connPointId, filterType: "EQ"},
{field: "accountingDevice", filterType: "NOT_NULL"}
]);
},
error: function (e) {
showError('Ошибка: ' + e.statusText);
}
})
});
if (!!connPointId) {
this.loadAccountDevicesList([
{field: "connectionPoint.id", value: connPointId, filterType: "EQ"},
{field: "accountingDevice", filterType: "NOT_NULL"}
]);
}
this.loadSubabonentsList([
{field: "parent.id", value: connPointId, filterType: "EQ"}
]);
this.loadAccountChangeList([
{field: "connectionPoint.id", value: connPointId, filterType: "EQ"}
]);
}
if (!!connPointId) {
this.loadPlombs1List([
{field: "connectionPoint.id", value: connPointId, filterType: "EQ"}
]);
}
this.loadChargesList([
{field: "connectionPoint.id", value: connPointId, filterType: "EQ"}
]);
$("#btn-add-norm").click(function () {
// if ($("#btn-add-norm").hasClass("disabled"))
// return;
if (connPointId)
$.cookie("data['connpoint_id']", connPointId);
goto("/connpointnorms", null);
});
$("#btn-add-charge").click(function () {
if (connPointId)
$.cookie("data['connpoint_id']", connPointId);
goto("/charge", null);
});
$("#btn-add-loopline").click(function () {
if (connPointId)
$.cookie("data['connpoint_id']", connPointId);
goto("/loopline", null);
});
$("#btn-add-looplinevalveseal").click(function () {
var looplineId = $("#cp-plombs-list")[0].selected;
if (looplineId)
$.cookie("data['loopline_id']", looplineId);
goto("/looplinevalveseal", null);
});
var toggleLoading = function (elem) {
return elem.toggleLoading({addClass: "loading-combobox"});
}
$("#CPIngeneerDep").change(function () {
var id = $("#CPIngeneerDep").val();
if (id == null)
return;
$("#CPIngeneer").find("option").removeAttr("selected");
$("#CPController").find("option").removeAttr("selected");
$("#CPIngeneer").val(null);
$("#CPController").val(null);
if (id == "") {
$("#CPIngeneer").attr("disabled", "");
$("#CPController").attr("disabled", "");
return;
}
toggleLoading($("#CPIngeneer"));
toggleLoading($("#CPController"));
$.ajax({
type: "post",
data: "id=" + id,
url: "/app/employee/ingeneer_controller",
success: function (result) {
result = $.parseJSON(result);
var ingeneers = result.ingeneers;
var controllers = result.controllers;
$("#CPIngeneer").empty();
if (ingeneers.length > 0) {
$("#CPIngeneer").append("<option></option>");
for (var i = 0; i < ingeneers.length; i++) {
$("#CPIngeneer").append("<option value='" + ingeneers[i].id + "'>" + ingeneers[i].name + "</option>");
}
$("#CPIngeneer").loaded = true;
$("#CPIngeneer").removeAttr("disabled");
$("#CPIngeneer").change();
} else {
$("#CPIngeneer").attr("disabled", "");
}
$("#CPController").empty();
if (controllers.length > 0) {
$("#CPController").append("<option></option>");
for (var i = 0; i < controllers.length; i++) {
$("#CPController").append("<option value='" + controllers[i].id + "'>" + controllers[i].name + "</option>");
}
$("#CPController").loaded = true;
$("#CPController").removeAttr("disabled");
$("#CPController").change();
} else {
$("#CPController").attr("disabled", "");
}
toggleLoading($("#CPIngeneer"));
toggleLoading($("#CPController"));
},
error: function (e) {
showError('Ошибка: ' + e.statusText);
}
});
});
$("#btn-submit").click(function () {
var valid = $("form").valid();
if (!valid) {
if (!$("#connpoint-union-id").val() && !$("#creatingUnion").prop("checked")) {
showInfo("Выберите объект на предыдущей форме или поставьте переключатель на создание нового объекта");
return;
}