PDA

View Full Version : Working with non-DD values



Anders Ohrt
5-Jun-2007, 02:34 AM
I have found a couple of things we often do in VDF that I need to do in my
WebApp too, and would like some advice as to how they are best done using
the Ajax library:

1) Adding a custom column in a grid. We often put (SomeFunction(self)) as
Entry_Item in a dbGrid or dbList, and then in SomeFunction accesses the
record buffer to create the value.

2) Adding custom <input>'s (disabled) on a page. We often hook into Refresh
of the main dbForm and do things like finding descriptions for fields that
are not in the DD structure (like soft relates).

The cleanest approach that I can see would be to declare a "virtual" field
somehow, like a vdfFunctionBinding="SomeFunction" and then adding the code
to the .wo to pass the values automatically just like the normal data
tables, would this be possible?

// Anders

Edwin van der Velden
5-Jun-2007, 04:05 AM
I'm not totally sure what Entry_Item does, so it's hard to say for me. Am
reading the help file but either my english fails or my brain does at the
moment, as it's still not completely clear. But some things that might help
is the fact that input fields that are not recognized are also sent on
requests as user data. You can then use the OnAjaxRequestStart and
OnAjaxRequestEnd functions to add custom code which bases actions to do on
the user data sent with the request.

--Edwin


"Anders Öhrt" <Anders.Ohrt@berendsen.se> wrote in message
news:CDRC0P0pHHA.5572@dacmail.dataaccess.com...
>
> I have found a couple of things we often do in VDF that I need to do in my
> WebApp too, and would like some advice as to how they are best done using
> the Ajax library:
>
> 1) Adding a custom column in a grid. We often put (SomeFunction(self)) as
> Entry_Item in a dbGrid or dbList, and then in SomeFunction accesses the
> record buffer to create the value.
>
> 2) Adding custom <input>'s (disabled) on a page. We often hook into
> Refresh of the main dbForm and do things like finding descriptions for
> fields that are not in the DD structure (like soft relates).
>
> The cleanest approach that I can see would be to declare a "virtual" field
> somehow, like a vdfFunctionBinding="SomeFunction" and then adding the code
> to the .wo to pass the values automatically just like the normal data
> tables, would this be possible?
>
> // Anders
>
>

Edwin van der Velden
5-Jun-2007, 04:06 AM
btw, basically if you give an input a name which does not contain "__" it
should not be recognized and added as user data.

-Edwin


"Edwin van der Velden" <edwin.van.der.velden@dataaccess.nl> wrote in message
news:WTcT2C1pHHA.3152@dacmail.dataaccess.com...
> I'm not totally sure what Entry_Item does, so it's hard to say for me. Am
> reading the help file but either my english fails or my brain does at the
> moment, as it's still not completely clear. But some things that might
> help is the fact that input fields that are not recognized are also sent
> on requests as user data. You can then use the OnAjaxRequestStart and
> OnAjaxRequestEnd functions to add custom code which bases actions to do on
> the user data sent with the request.
>
> --Edwin
>
>
> "Anders Öhrt" <Anders.Ohrt@berendsen.se> wrote in message
> news:CDRC0P0pHHA.5572@dacmail.dataaccess.com...
>>
>> I have found a couple of things we often do in VDF that I need to do in
>> my WebApp too, and would like some advice as to how they are best done
>> using the Ajax library:
>>
>> 1) Adding a custom column in a grid. We often put (SomeFunction(self)) as
>> Entry_Item in a dbGrid or dbList, and then in SomeFunction accesses the
>> record buffer to create the value.
>>
>> 2) Adding custom <input>'s (disabled) on a page. We often hook into
>> Refresh of the main dbForm and do things like finding descriptions for
>> fields that are not in the DD structure (like soft relates).
>>
>> The cleanest approach that I can see would be to declare a "virtual"
>> field somehow, like a vdfFunctionBinding="SomeFunction" and then adding
>> the code to the .wo to pass the values automatically just like the normal
>> data tables, would this be possible?
>>
>> // Anders
>>
>>
>
>

Anders Ohrt
5-Jun-2007, 07:13 AM
> I'm not totally sure what Entry_Item does, so it's hard to say for me. Am
> reading the help file but either my english fails or my brain does at the
> moment, as it's still not completely clear. But some things that might
> help is the fact that input fields that are not recognized are also sent
> on requests as user data. You can then use the OnAjaxRequestStart and
> OnAjaxRequestEnd functions to add custom code which bases actions to do on
> the user data sent with the request.
>
> --Edwin
>
>
> "Anders Öhrt" <Anders.Ohrt@berendsen.se> wrote in message
> news:CDRC0P0pHHA.5572@dacmail.dataaccess.com...
>>
>> I have found a couple of things we often do in VDF that I need to do in
>> my WebApp too, and would like some advice as to how they are best done
>> using the Ajax library:
>>
>> 1) Adding a custom column in a grid. We often put (SomeFunction(self)) as
>> Entry_Item in a dbGrid or dbList, and then in SomeFunction accesses the
>> record buffer to create the value.
>>
>> 2) Adding custom <input>'s (disabled) on a page. We often hook into
>> Refresh of the main dbForm and do things like finding descriptions for
>> fields that are not in the DD structure (like soft relates).
>>
>> The cleanest approach that I can see would be to declare a "virtual"
>> field somehow, like a vdfFunctionBinding="SomeFunction" and then adding
>> the code to the .wo to pass the values automatically just like the normal
>> data tables, would this be possible?
>>
>> // Anders
>>
>>
>
>

Anders Ohrt
5-Jun-2007, 07:15 AM
(Somehow pressed send too fast, disregard the other post)


> I'm not totally sure what Entry_Item does, so it's hard to say for me. Am
> reading the help file but either my english fails or my brain does at the
> moment, as it's still not completely clear. But some things that might
> help is the fact that input fields that are not recognized are also sent
> on requests as user data. You can then use the OnAjaxRequestStart and
> OnAjaxRequestEnd functions to add custom code which bases actions to do on
> the user data sent with the request.

Great, that's basically what I was after. I'm satisfied for the moment. =)

// Anders

Anders Ohrt
5-Jun-2007, 09:46 AM
> I'm not totally sure what Entry_Item does, so it's hard to say for me. Am
> reading the help file but either my english fails or my brain does at the
> moment, as it's still not completely clear. But some things that might
> help is the fact that input fields that are not recognized are also sent
> on requests as user data. You can then use the OnAjaxRequestStart and
> OnAjaxRequestEnd functions to add custom code which bases actions to do on
> the user data sent with the request.

It was a bit messier that it sounded at first, but I got it working. Since I
have a list on the page, I get two Requests (the first for the main_dd and
another dd, and the second for the top and bottom of the list buffer). The
second Request kept wiping the user data that I setup in the first Response,
but the code below will do what I wanted. I need to make sure I don't return
any user data if it's not the find for the main DD that is asking:

Property Boolean pbReturnUserData Public False
Property String psSomeUserData Public ""

Procedure OnAjaxRequestStart TAjaxRequestData ByRef tRequestData
Forward Send OnAjaxRequestStart (&tRequestData)

Set pbReturnUserData to False
Set psSomeUserData to ""
End_Procedure // OnAjaxRequestStart

Procedure OnAjaxRequestSetEnd TAjaxResponseSet ByRef tResponseSet
Integer iRecnum

Forward Send OnAjaxRequestSetEnd (&tResponseSet)

If (tResponseSet.sMainTableName <> "table") Begin
Procedure_Return
End

Set pbReturnUserData to True

Get Current_Record of Table_DD to iRecnum

If (iRecnum <> 0) Begin
Set psSomeUserData to "Some Value..."
End
End_Procedure // OnAjaxRequestSetEnd

Procedure OnAjaxRequestEnd TAjaxResponseData ByRef tResponseData
TAjaxUserData[] taData

Forward Send OnAjaxRequestEnd (&tResponseData)

If (not(pbReturnUserData(Self))) Begin
Set ptaRequestUserData to taData
End
Else Begin
Send SetAjaxResponseUserData "custom_user_data"
(psSomeUserData(Self))
End
End_Procedure // OnAjaxRequestEnd

// Anders

Edwin van der Velden
6-Jun-2007, 03:35 AM
You mention the second request wipes user data setup in the first request.
There is however more to that as well, the second request can be attached to
a completely differnt process as the first request so any data set in the
first request might be completely differnt. You should always assume each
request as starting from scratch and make sure they contain all the
information needed for that process themselves. Looking at the code I can't
exactly determine if you still rely on the first request at the second
request, I guess that all depends on how you determine the "Some value..."
that is being set. If the second request gets the data it needs to determine
the value itself it should be fine.

-Edwin


"Anders Öhrt" <Anders.Ohrt@berendsen.se> wrote in message
news:9bYwJB4pHHA.1556@dacmail.dataaccess.com...
>
>> I'm not totally sure what Entry_Item does, so it's hard to say for me. Am
>> reading the help file but either my english fails or my brain does at the
>> moment, as it's still not completely clear. But some things that might
>> help is the fact that input fields that are not recognized are also sent
>> on requests as user data. You can then use the OnAjaxRequestStart and
>> OnAjaxRequestEnd functions to add custom code which bases actions to do
>> on the user data sent with the request.
>
> It was a bit messier that it sounded at first, but I got it working. Since
> I have a list on the page, I get two Requests (the first for the main_dd
> and another dd, and the second for the top and bottom of the list buffer).
> The second Request kept wiping the user data that I setup in the first
> Response, but the code below will do what I wanted. I need to make sure I
> don't return any user data if it's not the find for the main DD that is
> asking:
>
> Property Boolean pbReturnUserData Public False
> Property String psSomeUserData Public ""
>
> Procedure OnAjaxRequestStart TAjaxRequestData ByRef tRequestData
> Forward Send OnAjaxRequestStart (&tRequestData)
>
> Set pbReturnUserData to False
> Set psSomeUserData to ""
> End_Procedure // OnAjaxRequestStart
>
> Procedure OnAjaxRequestSetEnd TAjaxResponseSet ByRef tResponseSet
> Integer iRecnum
>
> Forward Send OnAjaxRequestSetEnd (&tResponseSet)
>
> If (tResponseSet.sMainTableName <> "table") Begin
> Procedure_Return
> End
>
> Set pbReturnUserData to True
>
> Get Current_Record of Table_DD to iRecnum
>
> If (iRecnum <> 0) Begin
> Set psSomeUserData to "Some Value..."
> End
> End_Procedure // OnAjaxRequestSetEnd
>
> Procedure OnAjaxRequestEnd TAjaxResponseData ByRef tResponseData
> TAjaxUserData[] taData
>
> Forward Send OnAjaxRequestEnd (&tResponseData)
>
> If (not(pbReturnUserData(Self))) Begin
> Set ptaRequestUserData to taData
> End
> Else Begin
> Send SetAjaxResponseUserData "custom_user_data"
> (psSomeUserData(Self))
> End
> End_Procedure // OnAjaxRequestEnd
>
> // Anders
>

Vincent Oorsprong
6-Jun-2007, 03:54 AM
Anders,

Two tips about the properties;
1. You can drop the use of PUBLIC (it is the default)
2. You do not need the initialisation values (False and "") because - in
this case - these are the defaults.

--
Regards,
Vincent Oorsprong
Data Access Europe B.V.
http://www.dataaccess.nl

Hans van de Laar
6-Jun-2007, 08:08 AM
Hi Anders and the Ajax-team,

I'm running into the same problem as Anders. Anders, did you manage to
add some custom data for every row in a vdfgrid or vdflookup?

Let me try to explain with 2 different simple examples:

1. I want to be able to combine 2 or more database columns and show the
data is one column like the windows entry_item allows:
Entry_Item (Customer.Zip * "-" * Customer.State) or
Entry_Item (Gebruiker.voornaam * "," * Gebruiker.Tussenvoegsel)

2. I want to be able to call a custom function for every main record in
the grid and display the return value in a separated column e.g. the
total amount of not paid invoices for every debtor in the list. This
would force a custom function to lookup one or more records in a debtor
child table, total the amount and return the result for displaying,

Is this already possible with the current AJAX-library?

Regards,
Hans


Anders Vhrt wrote:

>
> I have found a couple of things we often do in VDF that I need to do
> in my WebApp too, and would like some advice as to how they are best
> done using the Ajax library:
>
> 1) Adding a custom column in a grid. We often put
> (SomeFunction(self)) as Entry_Item in a dbGrid or dbList, and then in
> SomeFunction accesses the record buffer to create the value.
>
> 2) Adding custom <input>'s (disabled) on a page. We often hook into
> Refresh of the main dbForm and do things like finding descriptions
> for fields that are not in the DD structure (like soft relates).
>
> The cleanest approach that I can see would be to declare a "virtual"
> field somehow, like a vdfFunctionBinding="SomeFunction" and then
> adding the code to the .wo to pass the values automatically just like
> the normal data tables, would this be possible?
>
> // Anders

Anders Ohrt
7-Jun-2007, 01:35 AM
> You mention the second request wipes user data setup in the first request.
> There is however more to that as well, the second request can be attached
> to a completely differnt process as the first request so any data set in
> the first request might be completely differnt. You should always assume
> each request as starting from scratch and make sure they contain all the
> information needed for that process themselves. Looking at the code I
> can't exactly determine if you still rely on the first request at the
> second request, I guess that all depends on how you determine the "Some
> value..." that is being set. If the second request gets the data it needs
> to determine the value itself it should be fine.

I don't depend on any values between the requests, so it should work ok.
What I'm doing is in OnAjaxRequestStart resetting the properties, then in
OnAjaxRequestSetEnd I set pbReturnUserData to true only when I've seen the
request I was expecting ("table" is the Main_DD), so I know I should give
the user data back filled in. Then in OnAjaxRequestEnd, if I have seen the
request I was expecting pbReturnUserData will be True and psSomeUserData
will contain something I want to pass back, so I add the user data. If
pbReturnUserData if false, I set ptaRequestUserData to an empty array and
thereby no user data will be returned. A bit messy, but necessary.

// Anders

Anders Ohrt
7-Jun-2007, 01:45 AM
> Two tips about the properties;
> 1. You can drop the use of PUBLIC (it is the default)

It's only there to keep the code consistent with older VDF code we have (old
habits die hard, and it was mandatory in earlier VDF if I remember
correctly). I don't think we even use private properties, so one day when I
have nothing better to do I will be though all our code and remove the
Public key word. =)


> 2. You do not need the initialisation values (False and "") because - in
> this case - these are the defaults.

That is on purpose, so when I add a property that should have a different
default values it matches the ones around it. But, since I always
re-initialized the values due to process pooling, I could just drop it
anyway.

// Anders

Anders Ohrt
7-Jun-2007, 01:52 AM
> I'm running into the same problem as Anders. Anders, did you manage to
> add some custom data for every row in a vdfgrid or vdflookup?

Hacking lists is the next task in line, since I need to emulate checkboxes
with <img> in a list (CSS doesn't allow enough customization here). I'll
give it a try and post back...

// Anders

Anders Ohrt
7-Jun-2007, 04:20 AM
>> I'm running into the same problem as Anders. Anders, did you manage to
>> add some custom data for every row in a vdfgrid or vdflookup?
>
> Hacking lists is the next task in line, since I need to emulate checkboxes
> with <img> in a list (CSS doesn't allow enough customization here). I'll
> give it a try and post back...

I've checked a bit, and I see a couple of issues.

First, we need some events in vdfList. The obvious is an event for each row
displayed, like an onDisplayRow at the end of VdfList.prototype.displayRow.

Second, user data is per form, and we want per row user data. The library
should somehow figure out that the user data is within a list-control and
work with the data in the list request, not the form request. We can then
use the above event to get a hold of the per row data.

Of course, this is just my naive solution; there might be cleaner and easier
ways to accomplish this.

// Anders

Hans van de Laar
7-Jun-2007, 05:58 AM
Anders,

Let's hope this will be picked up by the AJAX team.

--
Regards,

Hans van de Laar
Micros b.v.
The Netherlands
www.micros.nl

Anders Vhrt wrote:

>
> > > I'm running into the same problem as Anders. Anders, did you
> > > manage to add some custom data for every row in a vdfgrid or
> > > vdflookup?
> >
> > Hacking lists is the next task in line, since I need to emulate
> > checkboxes
> >with <img> in a list (CSS doesn't allow enough customization here).
> I'll
> > give it a try and post back...
>
> I've checked a bit, and I see a couple of issues.
>
> First, we need some events in vdfList. The obvious is an event for
> each row displayed, like an onDisplayRow at the end of
> VdfList.prototype.displayRow.
>
> Second, user data is per form, and we want per row user data. The
> library should somehow figure out that the user data is within a
> list-control and work with the data in the list request, not the form
> request. We can then use the above event to get a hold of the per row
> data.
>
> Of course, this is just my naive solution; there might be cleaner and
> easier ways to accomplish this.
>
> // Anders

Edwin van der Velden
7-Jun-2007, 06:23 AM
I have made a note of this on our todo list, so we shall at least have a
look at it at some point.

-Edwin

"Hans van de Laar" <hansvandelaar@micros.nl> wrote in message
news:xn0f7662z7wiu5000@news.dataaccess.com...
> Anders,
>
> Let's hope this will be picked up by the AJAX team.
>
> --
> Regards,
>
> Hans van de Laar
> Micros b.v.
> The Netherlands
> www.micros.nl
>
> Anders Vhrt wrote:
>
>>
>> > > I'm running into the same problem as Anders. Anders, did you
>> > > manage to add some custom data for every row in a vdfgrid or
>> > > vdflookup?
>> >
>> > Hacking lists is the next task in line, since I need to emulate
>> > checkboxes
>> >with <img> in a list (CSS doesn't allow enough customization here).
>> I'll
>> > give it a try and post back...
>>
>> I've checked a bit, and I see a couple of issues.
>>
>> First, we need some events in vdfList. The obvious is an event for
>> each row displayed, like an onDisplayRow at the end of
>> VdfList.prototype.displayRow.
>>
>> Second, user data is per form, and we want per row user data. The
>> library should somehow figure out that the user data is within a
>> list-control and work with the data in the list request, not the form
>> request. We can then use the above event to get a hold of the per row
>> data.
>>
>> Of course, this is just my naive solution; there might be cleaner and
>> easier ways to accomplish this.
>>
>> // Anders