binding object content to layout items ...
[1/5] from: petr::krenzelok::trz::cz at: 24-May-2001 11:11
Hi,
can anyone suggest me how to bind object (database) items to layout
ones? I have following scenarion in mind:
inet-init: context [
name: ""
IP: "172.25."
]
Now I would like to create form, which should recognize init or edit
state:
1) Init state
------------
form items should be pre-initialised by inet-init object
2) Edit state
------------
form items should be initialised by stored object which we want to edit
...
What are possible ways to do so? There is also one other issue - there
are items we would like to represent by different than "field" item on
the screen - e.g. "rotary", but how to do it?
inet-obj: context [
name: ""
IP: "172.25."
email-type: ["POP3" "Lotus Notes"]
]
view layout [rotary inet-obj/email-type .... will not work, as we don't
expect block here, but two separate valuues ...
Is there also any easy way of how to auto-layout object to window?
Thanks,
-pekr-
[2/5] from: gjones05:mail:orion at: 24-May-2001 6:19
From: "Petr Krenzelok"
> can anyone suggest me how to bind object (database) items to layout
> ones? I have following scenarion in mind:
<<quoted lines omitted: 10>>
> ------------
> form items should be initialised by stored object which we want to
edit
> ...
>
> What are possible ways to do so?
The way I accomplished this a few months ago was to enclose the layout
within a function that contained a refinement. Called without the
refinement, the layout initialized to a standard default; with the
refinement, the layout initialized to that item. The code was too
lengthy to enclude here, but a very brief example would go something
like this:
default-item: [
field1: none
field2: "some default"
]
;versus the following set through database access
my-data: [
field1: "John Smith"
field2: "employee"
]
item-entry: func [/edit item-data] [
item-lo: layout [
across
txt "Field 1: "
f1: field [;validation, etc]
return
txt "Field 2: "
f2: field [;validation, etc]
do [
either edit [
f1/text: copy item-data/field1
f2/text: copy item-data/field2
][
f1/text: copy default-data/field1
f2/text: copy default-data/field2
]
show [f1 f2]
]
]
]
Then, from another portion of code, 'item-entry function can be called
alone to set up the layout with the dafault, or called with the
refinement to pass in data:
item-entry ;sets up form to default
view item-lo ;to show the form
;;;;;;versus
item-entry/edit my-data ;sets up form to a specific entry
view item-lo ;to show the form
It seems to work pretty well. As set up, most of the faces are
accessible directly from the global scope, which probably isn't such a
good idea, (as you well know better than I do!!). These could be made
local to the context to avoid namespace problems.
> There is also one other issue - there
> are items we would like to represent by different than "field" item on
<<quoted lines omitted: 5>>
> ]
> view layout [rotary inet-obj/email-type .... will not work, as we
don't
> expect block here, but two separate valuues ...
Try:
view layout [rotary data inet-obj/email-type]
> Is there also any easy way of how to auto-layout object to window?
I am sorry, Petr, I am not sure what you mean by this. Can you explain
it in different words?
Hope this helps, and I will be glad to try again on the last question.
--Scott Jones
[3/5] from: petr:krenzelok:trz:cz at: 24-May-2001 15:14
GS Jones wrote:
> > There is also one other issue - there
> > are items we would like to represent by different than "field" item on
<<quoted lines omitted: 12>>
> Try:
> view layout [rotary data inet-obj/email-type]
that's what I wrote above :-) It doesn't know, because in VID, you have to
provide arguments to 'rotary as space delimited strings ...,e.g.
rotary "A" "B"
but:
rotary ["A" "B"] <--- will not work ...
> > Is there also any easy way of how to auto-layout object to window?
>
> I am sorry, Petr, I am not sure what you mean by this. Can you explain
> it in different words?
>
Well, I had it almost done one day during some earlier beta View stage. I
mean - you take object (pairs of word-name + word-value) and will create
layout in such way, that word-name will serve you as description for field,
and word-value will be put into field ...
e.g.:
obj: context [
Name: "Petr Krenzelok"
Email: [petr--krenzelok--trz--cz]
]
should result in:
lo: layout [
across
text "Name:" name: field obj/name
text "Email:" email: field obj/email
]
... or something like that ..
Anyway - thanks :-)
Cheers,
-pekr-
[4/5] from: gjones05:mail:orion at: 24-May-2001 8:45
Hi, Petr, it is subtle, but I added the dialect word 'data.
Your version:
> > > view layout [rotary inet-obj/email-type .... will not work, as we
My version:
> > view layout [rotary data inet-obj/email-type]
This word allows a block to be accepted for the rotary choices. For
example:
d: ["by name" "by date"]
view layout [rotary data d]
I should have highlighted in my discussion that I added that word.
Sorry for the confusion.
--Scott Jones
[5/5] from: gjones05:mail:orion at: 24-May-2001 10:05
From: "Petr Krenzelok"
> Is there also any easy way of how to auto-layout object to window?
> >
GSJ> > I am sorry, Petr, I am not sure what you mean by this. Can you
explain
GSJ> > it in different words?
> >
>
> Well, I had it almost done one day during some earlier beta View
stage. I
> mean - you take object (pairs of word-name + word-value) and will
create
> layout in such way, that word-name will serve you as description for
field,
> and word-value will be put into field ...
> e.g.:
<<quoted lines omitted: 9>>
> ]
> ... or something like that ..
Hi, again, Petr,
Here is a very generic layout method. It generates labels, fields and
data from a data object:
obj: context [
Name: "Petr Krenzelok"
Email: to-string [petr--krenzelok--trz--cz]
]
lo-data: copy []
for idx 2 length? first obj 1 [
fn: pick first obj idx
fv: pick second obj idx
append lo-data reduce [
'text rejoin [fn ":"]
to-set-word fn 'field fv
]
]
view layout lo-data
Hope this is close to what you are looking for, or at least adaptable.
--Scott Jones
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted