diff --git a/controllers/frame.js b/controllers/frame.js index e7cd60d63..8dc8d8281 100644 --- a/controllers/frame.js +++ b/controllers/frame.js @@ -355,6 +355,25 @@ const setGroup = function(objectID, frameID, body, callback) { callback(404, {success: false, error: 'Couldn\'t find frame ' + frameID + ' to set groupID'}); }; +const setPinned = function(objectID, frameID, body, callback) { + var frame = utilities.getFrame(objects, objectID, frameID); + if (frame) { + var newPinned = body.isPinned; + if (newPinned !== frame.pinned) { + frame.pinned = newPinned; + utilities.writeObjectToFile(objects, objectID, objectsPath, globalVariables.saveToDisk); + utilities.actionSender({ + reloadFrame: {object: objectID, frame: frameID}, + lastEditor: body.lastEditor + }); + callback(200, {success: true}); + return; + } + } + + callback(404, {success: false, error: 'Couldn\'t find frame ' + frameID + ' to set pinned'}); +}; + /** * Updates the x, y, scale, and/or matrix for the specified frame or node * @todo this function is a mess, fix it up @@ -514,6 +533,7 @@ module.exports = { updateFrame: updateFrame, deleteFrame: deleteFrame, setGroup: setGroup, + setPinned: setPinned, changeSize: changeSize, changeVisualization: changeVisualization, resetPositioning: resetPositioning, diff --git a/libraries/objectDefaultFiles/object.js b/libraries/objectDefaultFiles/object.js index 730509a54..b53dbcb54 100755 --- a/libraries/objectDefaultFiles/object.js +++ b/libraries/objectDefaultFiles/object.js @@ -45,6 +45,7 @@ isFullScreenExclusive: false, attachesTo: null, wasToolJustCreated: null, + isPinned: true, height: '100%', width: '100%', socketIoScript: {}, @@ -604,6 +605,7 @@ this.getPositionInWorld = makeSendStub('getPositionInWorld'); this.useWebGlWorker = makeSendStub('useWebGlWorker'); this.wasToolJustCreated = makeSendStub('wasToolJustCreated'); + this.setPinned = makeSendStub('setPinned'); // deprecated methods this.sendToBackground = makeSendStub('sendToBackground'); } @@ -1607,6 +1609,13 @@ // return spatialObject.wasToolJustCreated; }; + this.setPinned = function(isPinned) { + spatialObject.isPinned = isPinned; + postDataToParent({ + setPinned: isPinned + }); + }; + /** * Stubbed here for backwards compatibility of API. In previous versions: * Hides the frame itself and instead populates a background context within the editor with this frame's contents diff --git a/models/Frame.js b/models/Frame.js index e99506e0b..5ba300c5c 100644 --- a/models/Frame.js +++ b/models/Frame.js @@ -60,6 +60,8 @@ function Frame(objectId, frameId) { this.distanceScale = 1.0; // Indicates what group the frame belongs to; null if none this.groupID = null; + // "Pinned" frames are by default loaded and visible with the object they belong to. Unpinned must be asked for. + this.pinned = true; } /** diff --git a/routers/object.js b/routers/object.js index fc7e286ee..a4163480e 100644 --- a/routers/object.js +++ b/routers/object.js @@ -376,6 +376,16 @@ router.post('/:objectName/frame/:frameName/group/', function (req, res) { }); }); +router.post('/:objectName/frame/:frameName/pinned/', function (req, res) { + if (!utilities.isValidId(req.params.objectName) || !utilities.isValidId(req.params.frameName)) { + res.status(400).send('Invalid object or frame name. Must be alphanumeric.'); + return; + } + frameController.setPinned(req.params.objectName, req.params.frameName, req.body, function(statusCode, responseContents) { + res.status(statusCode).json(responseContents).end(); + }); +}); + const setupDeveloperRoutes = function() { // normal nodes router.post('/:objectName/frame/:frameName/node/:nodeName/size/', function (req, res) {