Web viewer Javascript making FMP URL call back to same file (not hosted, non-iOS)

208 views
Skip to first unread message

Justin Close

unread,
Apr 7, 2015, 5:57:43 PM4/7/15
to modular-...@googlegroups.com
In FMP 13.02 FileMaker apparently fixed the FMP URL for the desktop client, such that it could be used to make a call to the same/local/self file.  So I would have a web viewer in a solution and it would use an "fmp://web.address/dbname..." URL that would reference itself, the file that was currently open.

I found some references to how to do this, but for some reason things aren't working for me.  Apparently, if you are on a non-mobile platform, you need to use "$" as the IP address to reference the local file.  E.g. "fmp://web.address/dbname.fmp12?script=AScriptName&$var1=1234&$var2=abcd".  This would make the database essentially accept AJAX calls.  (Although an unanswered question for me is how does the response or data get back to the web viewer.  But for now, I just want to register event that trigger sending new data into the DB.)

Here's the code I am using for my web viewer definition.  The short description is that I am trying to integrate Full Calendar into a web viewer in a solution.  I am trying to configure the onDrag event so that when an event is modified it sends the new date range back to the DB.
-----------------------------
Let ( [
    _IPDestination = If ( Left(Get(FilePath);7) = "fmnet:/"; Get ( HostIPAddress ) ; "$" ) ;
    _fmpURLString = "fmp://" & _IPDestination & "/" & Get(FileName) & ".fmp12" ;
    _fmScript1 = "?script=FullCalendarChangeDate";
    $CurrDate = "2015/7/01"         //hardcoding for testing purposes
];

"data:text/html,
<!DOCTYPE html>
<html><head><meta charset='utf-8' />
<link rel='stylesheet' type='text/css' href='http://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.3.1/fullcalendar.min.css' />
<script src='http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.3.1/fullcalendar.min.js'></script>
<script>
    $(document).ready(function() {
        var   httpXHR, fmpurl ;

        $('#calendar').fullCalendar({
            defaultDate: '" & $CurrDate & "',
            editable: true,
            allDayDefault: true,
            eventStartEditable: true,
            eventDurationEditable: true,

            dayClick: function() {
                alert('a day has been clicked!');
            },

            eventDrop: function(event, delta, revertFunc) {
                if (!confirm(event.title + ' was dropped on ' + event.start.format() + '.\nAre you sure?')) {
                    revertFunc();
                }
            },

            eventResize: function(event, delta, revertFunc) {
                if (!confirm(event.title + ' end is now ' + ( event.end.format() ) + '.\n\nIs this okay?')) {
                    revertFunc();
                } else {
                    fmpurl = '" & _fmpURLString & _fmScript1 & "&$eventid=' + event.id + '&$newEndDate=' + event.end ;
                    httpXHR = new XMLHttpRequest();            
                    httpXHR.open(\"GET\", fmpurl, true);
                }
            },

            events:  [
                {
                    id: 1,
                    title: "Project 1",
                    start: "7/1/2015",
                    end: "7/3/2015"
                },
                {
                    id: 2,
                    title: "Project 2",
                    start: "7/3/2015",
                    end: "7/7/2015"
                },
                {
                    id: 3,
                    title: "Project 3",
                    start: "7/7/2015",
                    end: "7/7/2015"
                },
                {
                    id: 4,
                    title: "Project 4",
                    start: "7/7/2015",
                    end: "7/11/2015"
                },
                {
                    id: 5,
                    title: "Project 5",
                    start: "7/14/2015",
                    end: "7/16/2015"
                },
                {
                    id: 6,
                    title: "Project 6",
                    start: "6/18/2015",
                    end: "7/3/2015"
                },
                {
                    id: 7,
                    title: "Project 7",
                    start: "7/30/2015",
                    end: "8/15/2015"
                },
                {
                    id: 15,
                    title: "Project 15",
                    start: "6/08/2015",
                    end: "6/19/2015"
                }
            ]

        });
       
    });
</script>

<style>

    body {
        margin: 0;
        padding: 0;
        font-family: \"Lucida Grande\",Helvetica,Arial,Verdana,sans-serif;
        font-size: 14px;
    }

    #calendar {
        width: 900px;
        margin: 40px auto;
    }

</style></head>
<body>
    <div id='calendar'></div>
</body>
</html>
"
)
-----------------------------

In the middle of that you will see these three lines, where I am trying to make that call back to the local file from the webviewer:

            fmpurl = '" & _fmpURLString & _fmScript1 & "&$eventid=' + event.id + '&$newEndDate=' + event.end ;
            httpXHR = new XMLHttpRequest();            
            httpXHR.open(\"GET\", fmpurl, true);

Any one have experience achieving this?  Todd Geist's Watermark module uses this technique but I can't seem to extract that functionality for my own purposes here.  :)

Thanks,

-- Justin


Justin Close

unread,
Apr 9, 2015, 6:56:18 PM4/9/15
to modular-...@googlegroups.com
Oops, missed a step in my original code.  Unfortunately, adding the 'send' step didn't fix it.

                    fmpurl = '" & _fmpURLString & _fmScript1 & "&$eventid=' + event.id + '&$newEndDate=' + event.end ;
                    httpXHR = new XMLHttpRequest();            
                    httpXHR.open(\"GET\", fmpurl, true);
                    httpXHR.send();

I did some more testing, and even a simplified URL isn't triggering anything.  (Usually, the FM app gets launched and the file starts to open.)

Can anyone comment to the fact that I at least have the code and structure looking correct?

Thanks,
Justin

Todd Geist

unread,
Apr 9, 2015, 7:17:06 PM4/9/15
to modular-...@googlegroups.com
Hey Justin,

I thought the use of an XMLHTTPRequest looked funny, but when I looked at my watermark code I thought I had used one there. But actually I didn't.  The code I saw in there was for using the reactor plugin.

So why is it funny, you might ask?  Because I was pretty sure it doesn't work. Making an HTTPRequest is NOT the same as opening a URL in the browser.  Even if you use GET.  You need to trigger the browser to load a URL

There are two ways to do that, that I am aware of.  One is to use window.location = fmpurl and the other is to use an iframe with the src=fmpurl.  I don't believe that anything else works consistently across platforms.

Thats your problem, sorry I didn't catch that earlier.

Todd




--
You received this message because you are subscribed to the Google Groups "Modular FileMaker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modular-filema...@googlegroups.com.
To post to this group, send email to modular-...@googlegroups.com.
Visit this group at http://groups.google.com/group/modular-filemaker.
To view this discussion on the web visit https://groups.google.com/d/msgid/modular-filemaker/e915a0b4-b196-418c-8b3e-f53cab1c5e0b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Todd Geist

Justin Close

unread,
Apr 9, 2015, 7:41:43 PM4/9/15
to modular-...@googlegroups.com
Well, that could explain it.  So when I saw this block in your code, and was taking it out of context to try it in my own...

 if (isWebViewer)                    
     
var http = null                    
     http
= new XMLHttpRequest();¶                    
     http
.open(\"POST\", url, true);¶                    
     http.send(postData)¶                
     ...

...it's the Reactor plugin that makes that work?  (Which I wasn't including in my context.)  That the clause that is wrapped around that code (i.e. the original context) has a lot to do with why it works and why mine didn't?   Darn context.  :)

There's a note on the Watermark page that you don't need Reactor anymore (on Windows); is it still required on a Mac?

And now that I read the rest of it more closely, I see this a bit further down (but again, pulled out of context):
            
            if (isWebViewer)                    
                window
.location = url                
           
} ...


Well that's a bummer.  Why can't it just work?  :)

Thanks for following up on this.

--  Justin



On Thursday, April 9, 2015 at 4:17:06 PM UTC-7, Todd Geist wrote:
Hey Justin,

I thought the use of an XMLHTTPRequest looked funny, but when I looked at my watermark code I thought I had used one there. But actually I didn't.  The code I saw in there was for using the reactor plugin.

So why is it funny, you might ask?  Because I was pretty sure it doesn't work. Making an HTTPRequest is NOT the same as opening a URL in the browser.  Even if you use GET.  You need to trigger the browser to load a URL

There are two ways to do that, that I am aware of.  One is to use window.location = fmpurl and the other is to use an iframe with the src=fmpurl.  I don't believe that anything else works consistently across platforms.

Thats your problem, sorry I didn't catch that earlier.

Todd



On Thu, Apr 9, 2015 at 3:56 PM, Justin Close <jus...@mazamadw.com> wrote:
Oops, missed a step in my original code.  Unfortunately, adding the 'send' step didn't fix it.

                    fmpurl = '" & _fmpURLString & _fmScript1 & "&$eventid=' + event.id + '&$newEndDate=' + event.end ;
                    httpXHR = new XMLHttpRequest();            
                    httpXHR.open(\"GET\", fmpurl, true);
                    httpXHR.send();

I did some more testing, and even a simplified URL isn't triggering anything.  (Usually, the FM app gets launched and the file starts to open.)

Can anyone comment to the fact that I at least have the code and structure looking correct?

Thanks,
Justin



--

Todd Geist

unread,
Apr 9, 2015, 7:46:54 PM4/9/15
to modular-...@googlegroups.com
Reactor is no longer required at all.  The code you are looking at is in a JavaScript library I wrote to abstract away the differences between using the various methods of calling scripts from web viewers. Back before 13.v2 you needed several different ways to get the scripts to run if you wanted to cover all the platform and deployment options.  Now you can just use the simple method.  It works most of the time :-)

Todd

--
You received this message because you are subscribed to the Google Groups "Modular FileMaker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modular-filema...@googlegroups.com.
To post to this group, send email to modular-...@googlegroups.com.
Visit this group at http://groups.google.com/group/modular-filemaker.

For more options, visit https://groups.google.com/d/optout.

Justin Close

unread,
Apr 9, 2015, 8:03:06 PM4/9/15
to modular-...@googlegroups.com
Ah, I think I am catching on.  Except...what is the simple method?  :)

Is it just the 'window.location = url' form?

Todd Geist

unread,
Apr 9, 2015, 8:22:53 PM4/9/15
to modular-...@googlegroups.com
yes :-)

--
You received this message because you are subscribed to the Google Groups "Modular FileMaker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modular-filema...@googlegroups.com.
To post to this group, send email to modular-...@googlegroups.com.
Visit this group at http://groups.google.com/group/modular-filemaker.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages