Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions client/modules/addresses/houses.js
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,11 @@
pathFirst = false;
}

function validVisibleForFlats(value) {
value = $.trim(value);
return !value || /^\d+\s*(?:-\s*\d+\s*)?(?:,\s*\d+\s*(?:-\s*\d+\s*)?)*$/.test(value);
}

cardForm({
title: i18n("addresses.path"),
footer: true,
Expand All @@ -2438,12 +2443,14 @@
addRoot: function (instance) {
POST("houses", "path", treeName, {
text: i18n("addresses.newNode"),
visibleForFlats: "",
}).done(result => {
if (result && result.nodeId) {
let node = {
id: result.nodeId,
text: i18n("addresses.newNode"),
viewType: "list",
visibleForFlats: "",
};
instance.jstree().create_node("#", node, 'last', newNode => {
setTimeout(() => {
Expand All @@ -2461,12 +2468,14 @@
parent = parent.length ? parent[0] : "#";
POST("houses", "path", (parent === "#") ? treeName : parent, {
text: i18n("addresses.newNode"),
visibleForFlats: "",
}).done(result => {
if (result && result.nodeId) {
let node = {
id: result.nodeId,
text: i18n("addresses.newNode"),
viewType: "list",
visibleForFlats: "",
};
modules.addresses.houses.pathNodes[result.nodeId] = i18n("addresses.newNode");
instance.jstree().create_node(parent, node, 'last', newNode => {
Expand Down Expand Up @@ -2563,6 +2572,14 @@
{ value: "map", text: i18n("addresses.pathViewTypeMap") },
],
},
{
id: "pathVisibleForFlats",
type: "text",
title: i18n("addresses.pathVisibleForFlats"),
placeholder: "1,3,10-20",
hint: i18n("addresses.pathVisibleForFlatsHint"),
validate: validVisibleForFlats,
},
{
id: "pathOrder",
type: "text",
Expand All @@ -2581,16 +2598,18 @@
return false;
}

function syncPathViewType() {
function syncPathSettings() {
let node = selectedPathNode();
if (node) {
$(`#${prefix}pathViewType`).prop("disabled", false).val(node.original && node.original.viewType ? node.original.viewType : "list");
$(`#${prefix}pathVisibleForFlats`).prop("disabled", false).val(node.original && node.original.visibleForFlats !== null && typeof node.original.visibleForFlats !== "undefined" ? node.original.visibleForFlats : "");
} else {
$(`#${prefix}pathViewType`).prop("disabled", true).val("list");
$(`#${prefix}pathVisibleForFlats`).prop("disabled", true).val("");
}
}

$(`#${prefix}path`).off("select_node.jstree.cctvType deselect_node.jstree.cctvType changed.jstree.cctvType ready.jstree.cctvType").on("select_node.jstree.cctvType deselect_node.jstree.cctvType changed.jstree.cctvType ready.jstree.cctvType", syncPathViewType);
$(`#${prefix}path`).off("select_node.jstree.cctvPathSettings deselect_node.jstree.cctvPathSettings changed.jstree.cctvPathSettings ready.jstree.cctvPathSettings").on("select_node.jstree.cctvPathSettings deselect_node.jstree.cctvPathSettings changed.jstree.cctvPathSettings ready.jstree.cctvPathSettings", syncPathSettings);
$(`#${prefix}pathViewType`).off("change.cctvType").on("change.cctvType", () => {
let node = selectedPathNode();
if (!node) {
Expand All @@ -2608,7 +2627,29 @@
}).
fail(FAIL);
});
syncPathViewType();
$(`#${prefix}pathVisibleForFlats`).off("change.cctvVisibleForFlats").on("change.cctvVisibleForFlats", () => {
let node = selectedPathNode();
if (!node) {
return;
}

let visibleForFlats = $.trim($(`#${prefix}pathVisibleForFlats`).val());
if (!validVisibleForFlats(visibleForFlats)) {
return;
}

PUT("houses", "path", node.id, {
text: node.text,
type: node.original && node.original.viewType ? node.original.viewType : "list",
visibleForFlats: visibleForFlats,
}).
done(() => {
node.original = node.original || {};
node.original.visibleForFlats = visibleForFlats;
}).
fail(FAIL);
});
syncPathSettings();
},
callback: result => {
let pathOrder = $.trim(`${result.pathOrder}`);
Expand Down
2 changes: 2 additions & 0 deletions client/modules/addresses/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@
"pathViewType": "Group view mode",
"pathViewTypeList": "List",
"pathViewTypeMap": "Map",
"pathVisibleForFlats": "Visible for flats",
"pathVisibleForFlatsHint": "Empty inherits from parent",
"pathOrder": "Order in group",
"confirmDeleteNode": "Delete node \"%s\"?",
"deleteNode": "Delete node",
Expand Down
2 changes: 2 additions & 0 deletions client/modules/addresses/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@
"pathViewType": "Режим отображения группы",
"pathViewTypeList": "Список",
"pathViewTypeMap": "Карта",
"pathVisibleForFlats": "Видна квартирам",
"pathVisibleForFlatsHint": "Пусто — наследовать от родителя",
"pathOrder": "Порядок в группе",
"confirmDeleteNode": "Удалить элемент \"%s\"?",
"deleteNode": "Удалить элемент",
Expand Down
10 changes: 7 additions & 3 deletions server/api/houses/path.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @apiBody {String} text
* @apiBody {String} icon
* @apiBody {String="list","map"} [type=list]
* @apiBody {String} [visibleForFlats] comma-separated flat numbers and ranges, e.g. "1,3,10-20"; empty inherits from parent
*
* @apiSuccess {Number} nodeId
*/
Expand All @@ -51,6 +52,7 @@
* @apiBody {String} text
* @apiBody {String} icon
* @apiBody {String="list","map"} [type]
* @apiBody {String} [visibleForFlats] comma-separated flat numbers and ranges, e.g. "1,3,10-20"; empty inherits from parent
*
* @apiSuccess {Boolean} oprationResult
*/
Expand Down Expand Up @@ -109,9 +111,9 @@ public static function POST($params) {
return api::ERROR();
} else {
if ((int)$params["_id"]) {
return api::ANSWER($households->addPathNode($params["_id"], @$params["text"], @$params["icon"], @$params["type"] ?: "list"), "nodeId");
return api::ANSWER($households->addPathNode($params["_id"], @$params["text"], @$params["icon"], @$params["type"] ?: "list", @$params["visibleForFlats"]), "nodeId");
} else {
return api::ANSWER($households->addRootPathNode($params["_id"], @$params["text"], @$params["icon"], @$params["type"] ?: "list"), "nodeId");
return api::ANSWER($households->addRootPathNode($params["_id"], @$params["text"], @$params["icon"], @$params["type"] ?: "list", @$params["visibleForFlats"]), "nodeId");
}
}
}
Expand All @@ -122,7 +124,9 @@ public static function PUT($params) {
if (!$households) {
return api::ERROR();
} else {
return api::ANSWER($households->modifyPathNode($params["_id"], @$params["text"], @$params["icon"], @$params["type"]));
$visibleForFlats = array_key_exists("visibleForFlats", $params) ? $params["visibleForFlats"] : false;

return api::ANSWER($households->modifyPathNode($params["_id"], @$params["text"], @$params["icon"], @$params["type"], $visibleForFlats));
}
}

Expand Down
14 changes: 11 additions & 3 deletions server/backends/households/households.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ abstract function getPath($treeOrFrom, $withParents = false);
* @return mixed
*/

abstract function addRootPathNode($tree, $text, $icon, $type = "list");
abstract function addRootPathNode($tree, $text, $icon, $type = "list", $visibleForFlats = null);

/**
* @param string parentId
Expand All @@ -589,7 +589,7 @@ abstract function addRootPathNode($tree, $text, $icon, $type = "list");
* @return mixed
*/

abstract function addPathNode($parentId, $text, $icon, $type = "list");
abstract function addPathNode($parentId, $text, $icon, $type = "list", $visibleForFlats = null);

/**
* @param string nodeId
Expand All @@ -599,7 +599,15 @@ abstract function addPathNode($parentId, $text, $icon, $type = "list");
* @return mixed
*/

abstract function modifyPathNode($nodeId, $text, $icon, $type = null);
abstract function modifyPathNode($nodeId, $text, $icon, $type = null, $visibleForFlats = false);

/**
* @param string nodeId
*
* @return mixed
*/

abstract function getPathVisibleForFlats($nodeId);

/**
* @param string deviceToken
Expand Down
Loading