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
21 changes: 17 additions & 4 deletions allcount-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,16 @@ function fieldDirective(directiveName) {
})
}

function renderField(fieldDescription, isEditor) {
function callReadOnly(fieldDescription, entity, isEditor) {
var expression = fieldDescription.isReadOnlyExpression;
if (expression && entity && isEditor) {
var entityCopy = JSON.parse(JSON.stringify(entity));
return !eval("(" + expression+ ")(entityCopy)");
}
return undefined;
}

function renderField(fieldDescription, isEditor, entity) {
if (!fieldDescription || fieldRenderingService.readOnlyFieldRenderer(fieldDescription) === false && fieldScope) {
if (fieldScope) {
fieldScope.isEditor = isEditor;
Expand All @@ -580,7 +589,9 @@ function fieldDirective(directiveName) {
}
if (fieldScope) fieldScope.$destroy();
if (!fieldDescription) return;
isEditor = fieldDescription.isReadOnly ? false : isEditor;
var readOnlyExp = callReadOnly(fieldDescription, entity, isEditor);
isEditor = readOnlyExp != undefined ? readOnlyExp : (fieldDescription.isReadOnly ? false : isEditor);

fieldScope = scope.$new();
if (isEditor || fieldRenderingService.readOnlyFieldRenderer(fieldDescription) === false) {
fieldScope.isEditor = isEditor;
Expand All @@ -599,10 +610,12 @@ function fieldDirective(directiveName) {
}

scope.$watch(attrs.isEditor, function (isEditor) {
renderField(scope.$eval(attrs[directiveName]), isEditor);
var entity = scope.entity || scope.$eval("item");
renderField(scope.$eval(attrs[directiveName]), isEditor, entity);
});
scope.$watch(attrs[directiveName], function (fd) {
renderField(fd, scope.$eval(attrs.isEditor));
var entity = scope.entity;
renderField(fd, scope.$eval(attrs.isEditor), entity);
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allcountjs-angular-base",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "http://allcountjs.com",
"authors": [
"Pavel Tiunov <pavel.tiunov@gmail.com>"
Expand Down Expand Up @@ -28,6 +28,6 @@
},
"repository": {
"type": "git",
"url": "git://github.com/allcount/allcountjs-angular-base.git"
"url": "file:///Users/alexx/projects/allcount-base-fork/.git"
}
}