Skip to content

Commit

Permalink
Merge pull request #10 from justin-davisibm/lock_objects
Browse files Browse the repository at this point in the history
Lock objects- Walls, Area, Racks
  • Loading branch information
tbotnz authored Sep 22, 2023
2 parents d97fdad + ba98879 commit 58096fa
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 58 additions & 1 deletion netbox_floorplan/static/netbox_floorplan/floorplan/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ function add_wall() {
maxHeight: canvasHeight,
centeredRotation: true,
angle: 90,
custom_meta: {
"object_type": "wall",
},
});

var group = new fabric.Group([wall]);
Expand Down Expand Up @@ -153,8 +156,10 @@ function add_area() {
maxHeight: canvasHeight,
centeredRotation: true,
angle: 90,
custom_meta: {
"object_type": "area",
},
});

var group = new fabric.Group([wall]);

group.setControlsVisibility({
Expand All @@ -172,6 +177,58 @@ function add_area() {
}
window.add_area = add_area;

/*
* lock_floorplan_object: Toggle function to enable/disable movement and resize of objects
* Uses object.custom_meta.object_type to determine which controls to enable/disable
* for walls/area, mtr, mt, mb, ml, mr and movement/rotation are all enabled/disabled.
* for racks, only mtr and movement/roatation are enabled/disabled.
*/
function lock_floorplan_object() {
var object = canvas.getActiveObject();
if (object) {
if (object.lockMovementX) {
object.set({
'lockMovementX': false,
'lockMovementY': false,
'lockRotation': false
});
object.setControlsVisibility({
mtr: true,
});
if ( object._objects[0].custom_meta.object_type === "wall" ||
object._objects[0].custom_meta.object_type === "area" ) {
object.setControlsVisibility({
mt: true,
mb: true,
ml: true,
mr: true,
});
};
} else {
object.set({
'lockMovementX': true,
'lockMovementY': true,
'lockRotation': true
});
object.setControlsVisibility({
mtr: false,
});
if ( object._objects[0].custom_meta.object_type === "wall" ||
object._objects[0].custom_meta.object_type === "area" ) {
object.setControlsVisibility({
mt: false,
mb: false,
ml: false,
mr: false,
});
};
};
};
canvas.renderAll();
return;
}
window.lock_floorplan_object = lock_floorplan_object;

function bring_forward() {
var object = canvas.getActiveObject();
if (object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ <h5 class="card-header">Controls</h5>
<a class="btn btn-sm btn-outline-success" onclick="add_text()">
Add label
</a>
<a class="btn btn-sm btn-outline-info tools disabled" onclick="lock_floorplan_object()" id="lock_button">Lock/Unlock Object
</a>
<a class="btn btn-sm btn-outline-danger tools disabled"
onclick="delete_floorplan_object()" id="remove_button">
Delete
Expand Down

0 comments on commit 58096fa

Please sign in to comment.