diff options
Diffstat (limited to 'acf2/model/field.lua')
-rw-r--r-- | acf2/model/field.lua | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/acf2/model/field.lua b/acf2/model/field.lua index 31dc5ee..f668b90 100644 --- a/acf2/model/field.lua +++ b/acf2/model/field.lua @@ -68,7 +68,7 @@ function M.Field:init(params) super(self, M.Field):init(params) if type(self.editable) ~= 'function' then - function self.editable(context) return params.editable end + function self.editable(obj) return params.editable end end self.condition = M.conv_filter(self.condition) @@ -98,6 +98,8 @@ function M.Field:init(params) end end +function M.Field:_editable(context) return self:editable(context.parent) end + function M.Field:_choice(context) return self.choice end function M.Field:meta(context) @@ -107,7 +109,7 @@ function M.Field:meta(context) { type=self.dtype, visible=self.visible, - editable=self:editable(context), + editable=self:_editable(context), condition=self.condition, required=self.required, default=self.default, @@ -126,7 +128,7 @@ end function M.Field:load(context) if not context.txn then return setmetatable({}, context) end local value - if self.compute then value = self:compute(context) end + if self.compute then value = self:compute(context.parent, context.txn) end if value == nil then value = self:_load(context) end if value == nil then return self.default end return value @@ -162,7 +164,7 @@ function M.Field:_validate(context, value) end function M.Field:check_editable(context) - if not self:editable(context) then + if not self:_editable(context) then raise(context.path, 'Is not editable') end end @@ -177,14 +179,14 @@ function M.Field:validate(context, value) end function M.Field:save(context, value) self:check_editable(context) - if self.store then self:store(context, value) + if self.store then self:store(context.parent, value, context.txn) else self:_save(context, self:_validate(context, value)) end end function M.Field:_save(context, value) context.txn:set(context.addr, value) end function M.Field:validate_saved(context) - if self:editable(context) then self:save(context, self:load(context)) end + if self:_editable(context) then self:save(context, self:load(context)) end end |