sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Web Dialogs -Get string from Ruby before Body loads?

    Scheduled Pinned Locked Moved Developers' Forum
    35 Posts 5 Posters 1.0k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      @dan rathbun said:

      Also, it occurs to me that you may be able to use the DEFER attribute for a <SCRIPT> element to have it wait, until the page loads, or some event, rather than run immediately.

      Does DEFER work for anything other than IE?

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        You first 'make' your dialog and all its 'callbacks' etc...
        Then use @dlg.show{ self.populate() }
        This 'shows' the dialog - i.e. it displays all of its 'fields' with their default values, then when it's all 'showing' the Ruby side runs the code in the {} block - in this example it's a method called '.populate()', which sets any custom values; of course the '.populate()' method can then in turn call up any other methods etc as needed...
        I prefer this as the more reliable method, rather that trying with <script> window.location="skp:populate@"; </script> inserted at the end of the html file's 'body', where it's a callback to the Ruby's '.populate()' method...

        TIG

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          Well, the Body doesn't like to be processed until it has the path. If I hardcode the path into the js, then all works fine. But when I attempt to pass the path in, it all breaks because it is not retrieveing the path until after the body begins to load. In my example, the line I show in the body is a typical line of this html doc. It refers to the "ds1" variable, which is set based on the path.

          We are using dojo. Could I maybe remove all references to "ds1" from the body and then add them after the page is loaded completely and I"ve been able to retrieve the path using some dojo trickery?

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            Could you use an external .js file? If so, maybe you can write the .js file before the dialog, and reference it in the HEAD element of the html.

            <head> <script src="external.js"></script> </head>

            Hi

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              I have all of my fields set to '' in the html, and then 'populated' [using callbacks] in the '{}' block after the dialog has 'shown'...
              The dialog opens and is very very briefly 'empty' before the data fields appear... BUT it is hardly noticeable unless you are looking for it...

              TIG

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @chris fullmer said:

                In my example, the line I show in the body is a typical line of this html doc. It refers to the "ds1" variable, which is set based on the path.

                Except that index_path is local to the passFromRubyToJavascript() function, and won't be accessible globally.

                You need to declare it outside the function first as an empty string value.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @chris fullmer said:

                  Dan, I think your first example looks good, I'm not quite getting it implemented correctly yet, but I'm still plugging away at it.

                  You may need to wrap the <INPUT> element within a <FORM> element:

                  <!DOCTYPE html>
                  <HTML>
                    <HEAD>
                    <SCRIPT>
                      // globals
                      var index_path = "";
                      var ds1;
                  
                      function init_path(patharg){
                        index_path = patharg;
                        ds1 = new Spry.Data.XMLDataSet(index_path,"tag",{sortOnLoad; "@file", sortOrderOnLoad; "ascending", distinctOnLoad; true});
                      }
                    </SCRIPT>
                    </HEAD>
                    <BODY>
                      <FORM onload="init_path(IndexPath.value);">
                        <INPUT type="hidden" id=IndexPath name="IndexPath" value="" />
                      </FORM>
                      <DIV>
                        <TABLE name="DataTable">
                        </TABLE>
                      </DIV>
                    </BODY>
                  </HTML>
                  

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • Chris FullmerC Offline
                    Chris Fullmer
                    last edited by

                    Ahh, or the ds1 variable points to a spry xmldataset. What if when the page loads, I point it to a temp xml file that I provide with the install, swo that the ds1 variable can be set correctly. Then once the page loads, I re-set the ds1 variable to point to the real path.

                    Maybe I'll poke around with that idea.

                    -oh, TIG just posted -
                    @TIG

                    I like that way of doing it just fine. I'm not sure what I would need to tell my html developer guy to do to make that work on his end. Right now he is using spry to be able to dynamically change the values shown in the boxes. I'm not sure how to leave the fields blank until the page loads. The spry thingy seems to want to populate as it loads, I guess?

                    @Dan - yes, that is the way I showed it in what I posted. I am actually declaring it first outside the method, thanks for checking that. I've also been writing it to a blank field in the html just to verify it does come in right. And it does, I think, its just coming in too late for the ds1 declaration.

                    Lately you've been tan, suspicious for the winter.
                    All my Plugins I've written

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      Anyway Chris ... back to basics: Are you just wanting to display a table of data ??

                      Does the applet need to be cross-platform ??

                      If so there's a better way to do this.

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • Chris FullmerC Offline
                        Chris Fullmer
                        last edited by

                        Yes please, back to basics πŸ˜„

                        I have a file that contains a list of xml files. Those xml files have the data that I want to display in the webpage. The wbpage has a dropdown box and a table. The dropdown box lets you select which xml file to view, the xml file has the data that populates the table.

                        The file with the list of xml files is my index_path I'm trying to pass in. When I hardcode it in, all the fields populate correctly, the dropwdown box works great, I can switch between all the listed xml files.

                        So, a simpler cross-platform solution might be great.

                        Lately you've been tan, suspicious for the winter.
                        All my Plugins I've written

                        1 Reply Last reply Reply Quote 0
                        • Dan RathbunD Offline
                          Dan Rathbun
                          last edited by

                          Ok...

                          Is the index file always the same.. or does it change from session to session, or within the session ?

                          Does the data in the individual XML files change and therefore need to change the cell values in the tables dynamically while the table is displayed, or do the XML tables just represent "post operation" data displayed "after the fact." ??

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • Chris FullmerC Offline
                            Chris Fullmer
                            last edited by

                            The index file is written to a temp_folder, and that path is always different on different user's systems. But other than that, the name and location will not change during the SketchUp session, or while the window is open.

                            The xml files will not change either while the window is open. The window is setup to be the system where the user can enter data, press submit, and it will then update the xml files with the newly entered data.

                            Lately you've been tan, suspicious for the winter.
                            All my Plugins I've written

                            1 Reply Last reply Reply Quote 0
                            • Chris FullmerC Offline
                              Chris Fullmer
                              last edited by

                              I should add I'm not the one developing the webdialogs either. It is a guy who has done a lot of html development. So he is pretty good with it, but definitely in a more typical scenario. So I keep throing him curveballs about how I can and can't interact with his dialogs, etc.

                              His webpage works great, and I'd love to be able to work within his framework if possible.

                              Lately you've been tan, suspicious for the winter.
                              All my Plugins I've written

                              1 Reply Last reply Reply Quote 0
                              • Chris FullmerC Offline
                                Chris Fullmer
                                last edited by

                                Could I do something like create a temp webpage that opens, gets (or is given) the path. Then that window opens a child window that has access to the path?

                                Lately you've been tan, suspicious for the winter.
                                All my Plugins I've written

                                1 Reply Last reply Reply Quote 0
                                • Chris FullmerC Offline
                                  Chris Fullmer
                                  last edited by

                                  Oh!, I think I'm on to something really good from Dan's original comment. More to come once (if) I get it working.

                                  Lately you've been tan, suspicious for the winter.
                                  All my Plugins I've written

                                  1 Reply Last reply Reply Quote 0
                                  • Chris FullmerC Offline
                                    Chris Fullmer
                                    last edited by

                                    WOOOOOHOOOOO!!!!!!! I got it! At least it is working very smoothly on my PC. I'll have to do some Mac testing later today <frightened!>. This is what is working great for me. In ruby, I set the path to the webdialog as a few parts - 'path' + 'filename.html' + '?' + 'index_path' + 'index_filename' so it looks something like this:

                                    @@webdialog.set_file(html_path + "?" + index_path)

                                    Then I grab it really easy in the <head> because the path is included in the url. I parse the document.URL like this:

                                    q_mark_index = document.URL.indexOf("?")
                                    var index_path = document.URL.substring(q_mark_index+1)

                                    Is that an ok way to parse it? I am not an expert string parser, that's for sure. But that seems to be working well.

                                    Thanks so far to everyone who has chimed in and read along. I've been working on this little tidbit for too many hours. Dan I would not have got this without your example at the beginning.

                                    Lately you've been tan, suspicious for the winter.
                                    All my Plugins I've written

                                    1 Reply Last reply Reply Quote 0
                                    • thomthomT Offline
                                      thomthom
                                      last edited by

                                      AH - nice. Query strings, that's a nice way to feed small amounts of data. I like that.

                                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                                      List of my plugins and link to the CookieWare fund

                                      1 Reply Last reply Reply Quote 0
                                      • thomthomT Offline
                                        thomthom
                                        last edited by

                                        @chris fullmer said:

                                        q_mark_index = document.URL.indexOf("?")
                                        var index_path = document.URL.substring(q_mark_index+1)

                                        How about:

                                        var index_path = document.URL.split('?')[1]

                                        Thomas Thomassen β€” SketchUp Monkey & Coding addict
                                        List of my plugins and link to the CookieWare fund

                                        1 Reply Last reply Reply Quote 0
                                        • Dan RathbunD Offline
                                          Dan Rathbun
                                          last edited by

                                          @chris fullmer said:

                                          Is that an ok way to parse it? I am not an expert string parser, that's for sure. But that seems to be working well.

                                          You don't need to parse it, the location object has methods that return all the various parts.
                                          document.url just returns the location object.
                                          see:
                                          http://msdn.microsoft.com/en-us/library/ms535866(v=VS.85).aspx

                                          @chris fullmer said:

                                          Thanks so far to everyone who has chimed in and read along. I've been working on this little tidbit for too many hours. Dan I would not have got this without your example at the beginning.

                                          πŸ˜‰

                                          I'm not here much anymore.

                                          1 Reply Last reply Reply Quote 0
                                          • Chris FullmerC Offline
                                            Chris Fullmer
                                            last edited by

                                            Very Cool Dan, thanks for that hint. Using *string*.search still returns the question mark at the front, so I had to split that off. But I was able to simplify my js to this,

                                            var index_path = document.location.search.slice(1)

                                            And that is so nice compared to all the callbacks and timing issues I was trying to fight with.

                                            Lately you've been tan, suspicious for the winter.
                                            All my Plugins I've written

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement