FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour mod harbour session js session object
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
mod harbour session js session object
Posted: Sun Jul 28, 2019 07:28 PM
Dear Antonio,
I am try to use the session object from javascript.
Can you show me how I could substitude generateUUID() - javascript function for example date() and time() as GUID with harbour and then pass harbour variable to javascript.
Thank you in advance
Otto




Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: mod harbour session js session object
Posted: Sun Jul 28, 2019 07:41 PM
Dear Otto
Function in harbour is
win_UuidCreateString( [@<nStatus>] )


contrib/hbwin/win_rpc.c
contrib/hbwin/tests/testrpc.prg
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: mod harbour session js session object
Posted: Sun Jul 28, 2019 08:50 PM

Dear Cristobal,
thank you.
Can you show me how to pass harbour variable to javascript.
Also a little sample how to show harbour variables inside html code would be great.
Best regards
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod harbour session js session object
Posted: Sun Jul 28, 2019 08:56 PM

Otto,

Your code is fine. The only observation is that you are generating it on the client side.

On a next example lets see how to generate it on the server side

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod harbour session js session object
Posted: Sun Jul 28, 2019 08:59 PM

Otto,

Using fields values in HTML code:

use < and > in both extremes, can't write them here:
input id="builder" name="builder" type="text" class="form-control" value="{{_Value('builder')}}"

Where function _Value( cFieldName ) is:

function _Value( cFieldName )

return FieldGet( FieldPos( cFieldName ) )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod harbour session js session object
Posted: Sun Jul 28, 2019 09:22 PM
This is an example of an UUID generated from the server side using mod_harbour:

C5843854-4DB4-1DB9-CCDB08473109
UUID generated on the server


Code (fw): Select all Collapse
function Main()

   BLOCKS
      ... begins the script
         var value = sessionStorage.getItem( "MyId" );
       
         if( value == null )
         {
            value = "{{generateUUID()}}"; 
            sessionStorage.setItem( "MyId", value );
         }

         d ocument.write( value );
      ... ends the script
   ENDTEXT

   ? "UUID generated on the server"

return nil

function GenerateUUID()

   local cChars := "0123456789ABCDEF"
   local cUUID  := ""

   for n = 1 to 8
      cUUID += SubStr( cChars, hb_Random( 1, 16 ), 1 )
   next
   
   cUUID += "-4"

   for n = 1 to 3
      cUUID += SubStr( cChars, hb_Random( 1, 16 ), 1 )
   next

   cUUID += "-"

   for n = 1 to 4
      cUUID += SubStr( cChars, hb_Random( 1, 16 ), 1 )
   next

   cUUID += "-"

   for n = 1 to 12
      cUUID += SubStr( cChars, hb_Random( 1, 16 ), 1 )
   next
 
return cUUID
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: mod harbour session js session object
Posted: Mon Jul 29, 2019 01:31 PM
Dear Antonio,
thank you so much.


Best regards
Otto

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: mod harbour session js session object
Posted: Mon Jul 29, 2019 01:33 PM

Dear Antonio,
would you please be so kind to make me a screenshot of the code insite the post.
Best regards
Otto

Otto,

Using fields values in HTML code:

use < and > in both extremes, can't write them here:
input id="builder" name="builder" type="text" class="form-control" value="{{_Value('builder')}}"

Where function _Value( cFieldName ) is:

function _Value( cFieldName )

return FieldGet( FieldPos( cFieldName ) )

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod harbour session js session object
Posted: Mon Jul 29, 2019 05:16 PM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: mod harbour session js session object
Posted: Mon Jul 29, 2019 05:54 PM

Dear Antonio,
thank you.
can you make me a sceenshot of this code too.
Thank you and best regards
Otto

Using fields values in HTML code:

use < and > in both extremes, can't write them here:
input id="builder" name="builder" type="text" class="form-control" value="{{_Value('builder')}}"

Where function _Value( cFieldName ) is:

function _Value( cFieldName )

return FieldGet( FieldPos( cFieldName ) )

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod harbour session js session object
Posted: Mon Jul 29, 2019 06:22 PM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: mod harbour session js session object
Posted: Tue Jul 30, 2019 05:59 AM

Dear Antonio,
thank you.
Is it possible to change "{{_Value('builder')}}" with xZTranslate.
to HB2HTML('builder').
input id="builder" name="builder" type="text" class="form-control" value=" & HB2HTML('builder').
Thank you in advance
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod harbour session js session object
Posted: Tue Jul 30, 2019 07:12 AM

Otto,

We need to use {{ ... }} so mod_harbour knows what to replace in the view.

You can use ANY function from inside it :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: mod harbour session js session object
Posted: Tue Jul 30, 2019 07:38 AM

Dear Antonio,
I mean hb_htlm() {{ ... }} would be more familiar to us CLIPPER heads.
Does xTranslate also translate code inside BLOCKS ?
Thank you in advance
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: mod harbour session js session object
Posted: Tue Jul 30, 2019 07:43 AM
Otto,

BLOCKS
...
ENDTEXT

search for {{ ... }} and whatever is inside {{ ... }} is "macro expanded" and replaced there and sent to Apache

{{ ... }} is a standard from many "templates" systems, thats why mod_harbour use them too

mod_harbour also supports {% ... %} to receive "instructions" from the user. In example:

// {% hb_SetEnv( "HB_INCLUDE", "c:\harbour\include" ) %}

this code will be processed by mod_harbour PREVIOUS to the execution of the PRG code
regards, saludos

Antonio Linares
www.fivetechsoft.com