From 3a999ad92a5d15566d20bb03acc9da5909de5f39 Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Tue, 9 Dec 2014 15:09:31 -0800 Subject: [PATCH] fix(panel/scopes): disallow editing special scope properties --- panel/components/json-tree/json-tree.js | 39 +++++++++++++++++++------ 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/panel/components/json-tree/json-tree.js b/panel/components/json-tree/json-tree.js index 3f6e583..994d965 100644 --- a/panel/components/json-tree/json-tree.js +++ b/panel/components/json-tree/json-tree.js @@ -3,6 +3,17 @@ angular.module('batarang.json-tree', []). var BAT_JSON_TREE_TEMPLATE = '
'; +var BAT_JSON_TREE_UNEDITABLE = [ + '$id', + + // managed by ngRepeat + '$first', + '$last', + '$index', + '$even', + '$odd' +]; + /* * TODO: remove dependency on inspectedApp service */ @@ -89,18 +100,28 @@ function batJsonTreeDirective() { if (typeof val === 'string') { val = '"' + val + '"'; } - childElt = angular.element( - '' + - val + - ''); // TODO: test this - childElt.on('blur', function () { - scope.batAssign({ - path: fullPath, - value: childElt.text() + // some properties (like $id) shouldn't be edited + if (BAT_JSON_TREE_UNEDITABLE.indexOf(fullPath) > -1) { + childElt = angular.element( + '' + + val + + ''); + } else { + childElt = angular.element( + '' + + val + + ''); + + // TODO: test this + childElt.on('blur', function () { + scope.batAssign({ + path: fullPath, + value: childElt.text() + }); }); - }) + } } parentElt.append(childElt);