Jump to content

MoaP calendar needs Javascript?


Quistess Alpha
 Share

You are about to reply to a thread that has been inactive for 737 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

So, I'm not at all a web-developer, but I've been playing around a bit with MoaP things lately.

I have this weekly calendar/organizer working, but the problem I have with it is that if I write in more than one box, only the box in which I press 'enter' is used in the query string.

Is there a clever way to reorganize this or use javascript to make the browser's query string contain information on all the boxes that have user-entered text in them? (ignoring all empty boxes to save on LSL memory & data limits)

key ghRequestURL;
string gsURL;

string gsHead = 
"<!DOCTYPE xhtml>
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head><style>
table { width: 100%; }
</style></head><body>
<table>";
list glItems;
string gsFoot = 
"</table>
</body></html>";

integer gCount;

default
{
    state_entry()
    {   ghRequestURL = llRequestURL();
        
        list days = 
        [   "[TIME]","Monday Plan","Monday Real",
            "[TIME]","Tuesday Plan","Tuesday Real",
            "[TIME]","Wednesday Plan","Wednesday Real",
            "[TIME]","Thursday Plan","Thursday Real",
            "[TIME]","Friday Plan","Friday Real",
            "[TIME]","Saturday Plan","Saturday Real",
            "[TIME]","Sunday Plan","Sunday Real"];
        glItems += "<tr><th>"+llDumpList2String(days,"</th>\n<th>")+"</th>";
        integer lld = llGetListLength(days);
        integer index_items = 1;
        integer index_time = 8;
        for(;index_time<22;++index_time)
        {   integer iTime = index_time%12;
            iTime+=12*(!iTime); // 12 not 0.
            string sTime = (string)iTime +llChar(65+(15*(index_time>=12)))+"M";
            glItems+="</tr><tr>";
            ++index_items;
            
            integer index_day;
            for(;index_day<lld;++index_day)
            {   string sDay = llList2String(days,index_day);
                if(sDay=="[TIME]")
                {   glItems+="<th>"+sTime+"</th>";
                    ++index_items;
                }else
                {   glItems+="\n<td>"+"<form action=\"./add\">"+sDay+" "+sTime+
                    "<input type=\"text\" name=\""+(string)index_items+"item\"/>"+
                    "</form></td>";
                    ++index_items;
                }
            }
        }
        glItems+="</tr>";
        llOwnerSay((string)llGetFreeMemory());
    }
    on_rez(integer i)
    {   llResetScript();
    }
    changed(integer c)
    {   
        if(c&(CHANGED_REGION_START|CHANGED_REGION))
        {   llReleaseURL(gsURL);
            ghRequestURL = llRequestURL();
        }
    }
    http_request(key ID, string Method, string Body)
    {   if(ID==ghRequestURL)
        {   gsURL=Body;
            llSetLinkMedia(LINK_THIS,2,
                [   PRIM_MEDIA_HOME_URL, gsURL+"/home",
                    PRIM_MEDIA_CURRENT_URL, gsURL+"/home",
                    PRIM_MEDIA_AUTO_PLAY, TRUE,
                    PRIM_MEDIA_PERMS_CONTROL, PRIM_MEDIA_PERM_OWNER, // don't show nav-bar.
                    PRIM_MEDIA_PERMS_INTERACT, PRIM_MEDIA_PERM_NONE // do not change curent URL via navigation.
                ]);
        }else
        {   
            string path = llGetHTTPHeader(ID,"x-path-info");
            // Debug:
            llOwnerSay(path+"::"+llGetHTTPHeader(ID,"x-remote-ip"));
            if(llGetSubString(path,0,4)=="/home")
            {   llSetContentType(ID,CONTENT_TYPE_XHTML);
                llHTTPResponse(ID,200,gsHead+(string)glItems+gsFoot);
            }else if(path=="/add")
            {   string query = llGetHTTPHeader(ID,"x-query-string");
                // Debug:
                llOwnerSay(query);
                //
                // if the query had more than one element, we'd loop over them here.
                //
                list parsed = llParseString2List(query,["=","&"],[]);
                string text = llDumpList2String(llParseStringKeepNulls(
                    llList2String(parsed,1),["+"], [])," ");
                text = llUnescapeURL(text);
                integer index = (integer)llList2String(parsed,0);
                glItems=llListReplaceList(glItems,
                [   "\n<td>"+"<form action=\"./add\">"+text+" "+
                    "<input type=\"text\" name=\""+(string)index+"item\"/>"+
                    "</form></td>"
                ],index,index);
                /*glItems=llListReplaceList(glItems,
                [   "<td>"+text+"</td>"
                ],index,index);*/
                llSetLinkMedia(LINK_THIS,2,
                [   PRIM_MEDIA_CURRENT_URL, gsURL+"/home"+(string)(++gCount) ]);
                //llSleep(0.2);
                llSetContentType(ID,CONTENT_TYPE_XHTML);
                llHTTPResponse(ID,200,gsHead+(string)glItems+gsFoot);
            }
        }
    }
}
// SL forums syntax highlighting doesn't like multi-line strings

 

  • Thanks 1
Link to comment
Share on other sites

37 minutes ago, panterapolnocy said:

Try to encase the whole table in the form tag instead of doing that for every single field separately.

I tried that (briefly) but then pressing enter didn't cause the form to submit at all (probably needed to add an extra button) and if it did, wouldn't that send all of the empty inputs in the query string as well?

Link to comment
Share on other sites

40 minutes ago, panterapolnocy said:

Try to encase the whole table in the form tag instead of doing that for every single field separately.

I tried that. <I had a longer reply but it got flagged for moderation>.

Link to comment
Share on other sites

Test.

Edited by Quistess Alpha
I had some perfectly normal replies flagged for moderation, and now I'm just kinda curious how much text I can shove into this box that may or may not be unmoderated.
Link to comment
Share on other sites

On 7/1/2022 at 12:20 PM, Quistess Alpha said:

I tried that (briefly) but then pressing enter didn't cause the form to submit at all (probably needed to add an extra button)

You can try to add an invisible submit button that looks like this, anywhere in the form, and it should work:

<input type="submit" hidden />

About this:

Quote

and if it did, wouldn't that send all of the empty inputs in the query string as well?

You can try to exclude empty inputs in JavaScript with 'disabled' attribute before the form is sent with, for example, onsubmit="return yourFunctionThatWillReturnTrueOrFalse()" which would do the validation and processing. Take a peek here:

https://stackoverflow.com/questions/59829278/how-to-disable-a-button-if-one-of-the-inputs-is-empty-pure-javascript
https://stackoverflow.com/questions/2417928/delete-empty-values-from-forms-params-before-submitting-it
https://stackoverflow.com/questions/63858583/listen-for-blank-inputs-and-add-a-disabled-attribute-to-a-button-until-an-inpu

Edited by panterapolnocy
  • Thanks 1
Link to comment
Share on other sites

I tried some of those solutions but couldn't get them to work correctly (I'm not a web dev). What I ended up doing was changing the 'formmethod' to 'submit' rather than get, which makes the querystring go into the body of the request (which has a much higher data-limit) rather than appended to the url.

<input type=\"submit\" hidden=\"true\" formmethod=\"post\" />

and no javascript :D

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 737 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...