NetTalk Central

Author Topic: Using new p_web.script - 7.12  (Read 5067 times)

CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Using new p_web.script - 7.12
« on: June 21, 2013, 04:40:12 PM »
From the Docs:

Cannot Call Procedure as Function
Your code likely looks something like this;
    packet = clip(packet) & p_web.script(something)
Alter it to make it a simple procedure call. For example;
  p_web.script(something)

OK, but that doesn't give the same result, does it?   I looked through the source code and it didn't jump out at me.  Do we use   DO SendPacket ;  p_web.script(something)?

If the SendPacket routine is not available,  such as in an added NetWebServerWorker method do we use self.ParseHTML ?  My particular situation is NetWebServerWorker method that uses p_web.jQuery to create a timepicker entry:

NetWebServerWorker.CreateTimeInput PROCEDURE  (string p_Id,string p_Value,<string p_class>,long p_Readonly=0,long p_disabled=0,<string p_picture>,<string p_Javascript>,<string p_Options>,<string p_extra>,<String p_tip>,Long p_size=0,Long p_MinDate=0,Long p_MaxDate=0,<String p_placeholder>)
.
.
.
If p_Readonly <> 0
.
.
Else               
    returnValue = |
 '<input type="text" name="'&clip(loc:id)&'" id="'&clip(loc:id)&loc:randomid&'" '&clip(loc:value)& clip(loc:class) & clip(loc:javascript) & clip(loc:tip) & clip(loc:readonly) & clip(loc:disabled) & clip(loc:extra) & clip(loc:placeholder) & '/>' |
 & self.jQuery(clip(loc:id)&loc:randomid,'clockpick',loc:options)
End
Return clip(Returnvalue)

Any advice would be greatly appreciated.    Thanks.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Using new p_web.script - 7.12
« Reply #1 on: June 23, 2013, 11:44:30 PM »
Hi Casey,

>> OK, but that doesn't give the same result, does it?

yes, and no. In the old way the script was returned by the method, you put it in Packet, and did a SendPacket. Nothing wrong with that, but the new way is"cleaner" (for reasons I'll explain in a moment.)

In the new way, the Script is internally added into a thing called the "Response Queue" which is really just a collection of stuff that gets added to the packet before it is sent. So instead of your script being "embedded" into the HTML at that point, all the scripts are collected together and included at the end of the page/ajax response.

There are a couple advantages to this;
a) it's a bit smaller because only one set of <script> </script> tags are used. Smaller is faster, so that's good.
b) the HTML code is easier to read because the HTML part, and the Script parts are not mingled together.
c) the Clarion code is easier to read because "packet" ends up being just HTML, and not HTML and Script mixed together.

>> Do we use   DO SendPacket ;  p_web.script(something)?

the "Do SendPacket" part is now disconnected from the Script part. ie you'll still use it for the "packet" (which is the HTML part) but the script is going down a different path.

regarding your example I'd probably do something like this;
    returnValue = |
 '<input type="text" name="'&clip(loc:id)&'" id="'&clip(loc:id)&loc:randomid&'" '&clip(loc:value)& clip(loc:class) & clip(loc:javascript) & clip(loc:tip) & clip(loc:readonly) & clip(loc:disabled) & clip(loc:extra) & clip(loc:placeholder) & '/>'

self.jQuery(clip(loc:id)&loc:randomid,'clockpick',loc:options)


ie the jQuery bit becomes a separate line of code.

cheers
Bruce








CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Re: Using new p_web.script - 7.12
« Reply #2 on: June 24, 2013, 05:14:39 PM »
Thanks, Bruce.  That is much clearer.

Stu

  • Hero Member
  • *****
  • Posts: 510
    • View Profile
    • Email
Re: Using new p_web.script - 7.12
« Reply #3 on: August 27, 2013, 04:01:51 PM »
Hi Bruce,

What if I'm using p_web.jQuery within a contained procedure that returns a STRING.

IE

I have a procedure called g_Get_Internet_Page(...) which returns a great honking string of a page.

In the code I call p_web.jQuery() for the Gallery:

Code: [Select]
loc:PageString = clip(loc:PageString)&p_web.CreateGalleryEnd()
loc:PageString = clip(loc:PageString)&p_web.jQuery('#beauty-propertypage-gallery_div','adGallery','width: false, height: false, slideshow: {{ speed: 3000 }')

Anyway I can replicate this now?
Cheers,

Stu Andrews

Stu

  • Hero Member
  • *****
  • Posts: 510
    • View Profile
    • Email
Re: Using new p_web.script - 7.12
« Reply #4 on: August 27, 2013, 04:04:21 PM »
Obvious answer.

Am going to hardcode it. DUH!
Cheers,

Stu Andrews

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Using new p_web.script - 7.12
« Reply #5 on: August 28, 2013, 02:32:27 AM »
the second line is just

p_web.jQuery('#beauty-propertypage-gallery_div','adGallery','width: false, height: false, slideshow: {{ speed: 3000 }')

the rest happens by magic.

Bruce