moving from localhost to www

Workarounds and usability notes.

Re: moving from localhost to www

Postby John Robin Dove » Sun Jun 02, 2019 12:18 pm

Yes, I agree. I had thought about this myself. I still do not exactly which part of the loading process fails to execute. The fact that there has never been a problem with XAMPP makes it more complicated.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby John Robin Dove » Fri Jun 07, 2019 8:54 am

Hi Clifton,

I've just been re-reading this long conversation. I think my last reply completely missed the point you made when you wrote 'that doesn't mean you don't have a server issue'. If I understand you correctly you mean that there is no problem with the code that I have written but that probably my webserver is not capable of executing it. Right? I have always thought that, if by some miracle the program were finished and people wanted to use it, I would have to migrate from my current budget priced server to something more substantial. Only then would I need to worry if the loading process failed to complete?

I am trying to rationalize my code but it's a laborious process. The program is basically a huge mess! The problem has always been Toolbook's limited capacity which means that there are bits of code all over the place in JS files and XML files in addition to the TBK file which only just manages to survive the export process and takes several minutes to complete it.

I am currently trying to create a loading system like the example you sent but including some parts of the loading process in an XML file doesn't seem to be possible. Two questions:
- Is it possible to modify variables using code in an XML file?
- Is it possible to execute shared actions using code in an XML file?

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Fri Jun 07, 2019 11:59 am

Is it possible to modify variables using code in an XML file?
    YES. Global variables and local variable are accessible. However, a global set in ToolBook actions is difficult to determine it's encoded name. I would set globals using XML instead. And better yet make your global variable properties of objects that are created with the <make> tag. That way they will always be available no mater what page you are on. You can see this in the examples in the next section.
Is it possible to execute shared actions using code in an XML file?
    YES. But if you build your sharedActions in ToolBook, you easiest approach is to use an object to access them via a user event. A better approach using XML is to re-create your sharedActions entirely in the XML file. I have been doing this by creating a level 0 <make> element and assign all my shared actions to functions of the <make> element. Because it is level 0, it is accessible everywhere in your application and you can call the functions from any other object using pgTBObjSet() as this PowerPac function allows you to directly execute functions. (To understand <make> tags in PowerPac's XML files, see this link.)

    Example:
    <make id="sharedActions" type="div" level="0" dims="-50,-50,20,20" class="" refObj="sysbootstrap" autoAlign="" replace="">
    <style>
    { "display" : "none" }
    </style>
    <function name="convertDate" event="" params="date,mask,isMillisec,utc">
    <![CDATA[
    /* CLIFTON: Converts a date string from the database to new format.
    Params: (date and mask are required)
    date = string as date from database in format 'YYYYMMDDHHMMSS'
    HHMMSS parts are optional but when provided, at least
    HHMM should be included.
    Alternatively, you can submit result from pgCurrentTime().
    mask = string mask to use for new date format.
    Uses same mask methods as pgDateFormat()
    isMillisec = (optional) boolean true | false (default)
    Indicates whether [date] is in milliseconds format
    as a result of calling pgCurrentTime()
    utc = boolean true | false (default)
    (uses UTC/GMT time when converting date)
    ***/
    if (!date || !mask) return '';
    utc = typeof utc == 'boolean' ? utc : false;
    isMillisec = typeof isMillisec == 'boolean' ? isMillisec : false; //Ensure type default
    if (!isMillisec) {
    date = date.toString();
    var m = date.match(/^\d{4}|\d{2}/g);
    if (date.length > 3) {
    m = m.slice(0, 3).join('-') + ' ' + m.slice(3).join(':');
    } else {
    m = m.join('-');
    }
    }
    return tbfunction_pgDateFormat(m, mask, utc);
    ]]>
    </function>

    <function name="myUser" event="user" params="e">
    <![CDATA[
    /* CLIFTON: You can even make a user event on the sharedAction object.
    To access the [value] parameter of the shared action:
    var value = e.data OR use e.value
    This example simply checks if the [value] submitted is a number
    and returns true or false.
    ***/
    return pgIsNumber( e.data );
    ]]>
    </function>

    <function name="myLoad" event="load" params="e">
    <![CDATA[
    /* CLIFTON: Set a global variable/property which we can call from anywhere.
    ***/
    this.myGlobal = "Some value"; //Set as property of the sharedActions object
    myUsername = "Clifton"; /Top level global accessible anywhere (not always be preferred as its not too secure.)
    ]]>
    </function>
    </make>
     

    To call this sharedAction/function:
    var args = [ tbfunction_pgCurrentTime(), "longDate" ];
    var myDate = tbfunction_pgTBObjSet( "sharedActions", "convertDate", args );
    //To retrieve a previous set global that is set as a property of the sharedActions object:
    var myGlobal = gTBo( "sharedActions", "objRef" ).myGlobal;
    OR
    var myGlobal = tbfunction_userProperty( "sharedActions", "myGlobal", "", "get");
     

    Save your sharedActions into a file and call it "sharedActions.xml". Then load it using ToolBook Actions like this:
    on load background
    XMLHttpRequest( "GET", "../xml/sharedActions.xml", "", "nouser"); discard return value

    NOTE: You could also just load it with each new page as the xml files are cached and will not be reloaded
    as the Engine detects if they are already loaded.
You won't find much you can't do with the current XML capabilities of the PowerPac XML Engine.
Plus you can organize your code in many XML files and just edit the ones necessary without having to pour over lots of irrelevant code.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby John Robin Dove » Sat Jun 08, 2019 2:34 am

Thanks for your reply. I should have paid more attention to your XML development earlier. In theory it could solve all my problems. In practice I find its complexity daunting. I'll have a go. :)

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby John Robin Dove » Sun Jun 09, 2019 9:07 am

Hi Clifton,

Code: Select all
<make id="sharedActions" type="div" level="0" dims="-50,-50,20,20" class="" refObj="sysbootstrap" autoAlign="" replace="">
    <style>
        { "display" : "none" }
    </style>
   
     
    <function name="myUser" event="user" params="e">
        <![CDATA[
            /*   CLIFTON:  You can even make a user event on the sharedAction object.
                    To access the [value] parameter of the shared action:
                        var value = e.data OR use e.value
            ***/
            alert (e.data);
        ]]>
    </function>

    <function name="myLoad" event="load" params="e">
        <![CDATA[
            /* CLIFTON:  Set a global variable/property which we can call from anywhere.
            ***/
            this.myGlobal = "Some value"; //Set as property of the sharedActions object!!
            //myUsername = "Clifton"; Top level global accessible anywhere (not always be preferred as its not too secure.)!!
        ]]>
    </function>
</make>


I am exploring the possibilities of creating a 'sharedActions' object and using it to modify variables stored as its user properties. So far, so good. Very good in fact!

Is it possible to have more than one function based on the user event like this:

<function name="myUser" event="user" params="e">
[do something]
</function>

<function name="myUser2" event="user" params="e">
[do something different]
</function>

and, if so, how would I call it? In your explanation of the <make> tag you wrote that this type of function is an object method and can be called thus [name of object].method name. How would this work? Using exeJavaScriptDirect maybe?

If more than one user event function is not possible then I have thought of a (clunky?) solution. Use pgTBObjSet to send something like "1,xyz", splitToArray, and then
if (myArray [0] == 1) do this with xyz else if (myArray [0] == 2} do that etc. but probably this level of complication is not necessary?

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Sun Jun 09, 2019 9:45 am

You can add custom functions as needed:
<make id="sharedActions" type="div" level="0" dims="-50,-50,20,20" class="" refObj="sysbootstrap" autoAlign="" replace="">
<style>
{ "display" : "none" }
</style>


<function name="myUser" event="user" params="e">
<![CDATA[
/* CLIFTON: You can even make a user event on the sharedAction object.
To access the [value] parameter of the shared action:
var value = e.data OR use e.value
***/
alert (e.data);
]]>
</function>

<function name="myCustom1" event="" params="p1,p2,p3">
<![CDATA[
/* CLIFTON: Make sure to leave event="" or the function will bound to an event.
Params:
p1 to ... pX are values of any type that can be sent to the function
You can name them any way you want, but they must be named according JavaScript conventions.
***/
if ( p1 == "Clifton" ) {
//Do something based on this condition
}
//Other code ...
]]>
</function>
</make>

To call your custom function:
var args = [ "Clifton", [ 1, 2, 3 ], { a : "candy", b: "popcorn" } ];
tbfunction_pgTBObjSet( "sharedActions", "myCustom1", args );

NOTES:
  • args is an array of parameters to send to myCustom1(). They must ordered as expected (p1, p2, p3) for predictable results.
  • The args array can contain complex variables (not just strings) as shown in the example above.
    args[0] = "Clifton" (becomes parameter p1)
    args[1] = array of integers (becomes parameter p2)
    args[2] = object with properties a and b and values "candy" and "popcorn" respectively (parameter p3)
  • You can use the [delay] property in pgTBObjSet() to delay your function execution.
  • As your functions grow, consider making additional elements to group your functions to make your work easier.
    Example call one "sharedActions"
    Call another one "videoActions"
    Call another one "audioActions" ... etc.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby John Robin Dove » Sun Jun 09, 2019 11:03 am

Thanks Clifton. I had vaguely understood a lot of this but your answer makes it much clearer. I should now be able to reduce some of my overweight tbk files to a more manageable format.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Sun Jun 09, 2019 8:05 pm

For sake of continued discussion on XML-related topics, I think future conversations should be short topics in the XML section of the forum.
That way other developers can benefit and this will make these discussions more easily searched on the forum.
https://pgsoftwaretools.com/forum/viewforum.php?f=16
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron