Announcement

Collapse
No announcement yet.

passing data between two apps in a container

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • passing data between two apps in a container

    Ok, a question for the javascript guys I guess. I'm not very good at it. I created a container with two iframes. I put a control in container 1 and a form in container 2. I created a javascript button and added the following code to it:

    Code:
    parent.document.getElementById("id-iframe-widget1").src='../control/control.php?test=abc'
    I tested it and it works. The first IFrame shows the current time and it changes on every click.

    Now I want to do the same from php. My purpose is to refresh the first IFrame when the user changes the selection in the second IFrame application. So I added the following code to the oninit event:

    Code:
    echo '<script type="text/javascript">function disp_a(xfrm,xuri) { parent.document.getElementById("id-iframe-widget1").src="../control/control.php"; } </script>';
    Then I applied the following code to the PHP Button:

    Code:
      $javascript_function   = 'disp_a';  // Javascript function name
      $javascript_parameters = array( // Javascript function parameters, add as many as needed
    								'param1',
    								'param2');
     
    
    // Call javascript function
      sc_ajax_javascript($javascript_function, $javascript_parameters);
    ;

    But this has not the required effect. What am I doing wrong here?
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

  • #2
    Hi,
    first of all, sc_ajax_javascript() does not work in PHP buttons, you have to go a detour via a PHP method.

    I would suggest create a PHP method (php_disp_a) and a Javascript method (js_disp_a) for your form.

    php_disp_a()
    sc_ajax_javascript('js_disp_a');

    js_disp_a();
    parent.document.getElementById("id-iframe-widget1").src += '';

    PHP button:
    php_disp_a();
    sc_exit(sel);


    That should do it.

    jsb

    Comment


    • #3
      Originally posted by aducom View Post
      Ok, a question for the javascript guys I guess. I'm not very good at it. I created a container with two iframes. I put a control in container 1 and a form in container 2. I created a javascript button and added the following code to it:

      Code:
      parent.document.getElementById("id-iframe-widget1").src='../control/control.php?test=abc'
      I tested it and it works. The first IFrame shows the current time and it changes on every click.

      Now I want to do the same from php. My purpose is to refresh the first IFrame when the user changes the selection in the second IFrame application. So I added the following code to the oninit event:

      Code:
      echo '<script type="text/javascript">function disp_a(xfrm,xuri) { parent.document.getElementById("id-iframe-widget1").src="../control/control.php"; } </script>';
      Then I applied the following code to the PHP Button:

      Code:
        $javascript_function   = 'disp_a';  // Javascript function name
        $javascript_parameters = array( // Javascript function parameters, add as many as needed
      								'param1',
      								'param2');
       
      
      // Call javascript function
        sc_ajax_javascript($javascript_function, $javascript_parameters);
      ;

      But this has not the required effect. What am I doing wrong here?
      Did you tried calling JS function from JavaScript Console (F12) ? It's the JS function in the generated HTML (view source)?
      Did you tried with following code in onInit
      PHP Code:
      ?>
      <script type="text/javascript">function disp_a(xfrm,xuri) { parent.document.getElementById("id-iframe-widget1").src="../control/control.php"; } </script>
      <?PHP
      /Giuseppe

      Professional Scriptcase Services
      Some Customers opinions

      Comment


      • #4
        Thanks both of you! @JSB: I used a php button just for demo to see f it worked. In reality I want to do this within an event, ie. onload event. Do I need to adjust things or should my own approach work as far as you know?
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          Yesssss. Tnx jsb. The hint that you cannot use it within a button was a great one. If I move the code to the onvalidate events it works well. So now it's very easy to change a container content from another container and soooo easy....
          Albert Drent
          aducom software netherlands
          scriptcase partner, reseller, support and (turn-key) development
          www.scriptcase.eu / www.scriptcase.nl

          Comment


          • #6
            Now I want to go a step further. This I tried in SC8 and it didn't work.

            I need to change a container (iframe) on the press of a button. I created a php method 'showdyndos' and I applied

            Code:
             $javascript_function   = 'disp_widget2';  // Javascript function name
             $javascript_parameters = array( // Javascript function parameters, add as many as needed
            								'\main\main.php',
            								'a=b');
             
            
            // Call javascript function
              sc_ajax_javascript($javascript_function, $javascript_parameters);
              sc_exit(ref);
            At the button event I applied

            Code:
            showdyndos();
            in the onscriptinitevent I echo the javascript procedure, only a alert for now:

            Code:
             echo '<script type="text/javascript">function disp_widget2(xuri,xparm) { alert(xuri);  } </script>';
            It should change the iframe to a dynamic scriptcase module, but I want to display it first to see if the concept works.
            Afaik the iframe name is correct
            Code:
            <li class="scContainerWidget widget" id="widget2">
               <div class="widget-head scContainerTitle">
                <img src="/scriptcase/app/DOHMWeb/_lib/img/scriptcase__NM__widget_max.png" style="border: 0; float: left; margin-top: 3px" class="sc-widget-maximize" alt="widget2" />
                <h3 id="id-title-widget2">Dossier</h3>
               </div>
               <div class="widget-content" style="height: 1000px; padding: 0px">
                <iframe id="id-iframe-widget2" class="sc-iframe-widget" style="height: 100%; width: 100%; border: 0px" src="/scriptcase/app/DOHMWeb/form_medicaldossier_dyn/?script_case_session=ufa6cuun892m3qh7re4gvvjmq4"></iframe>
               </div>
              </li>
            But I must be doing something wrong here...
            Albert Drent
            aducom software netherlands
            scriptcase partner, reseller, support and (turn-key) development
            www.scriptcase.eu / www.scriptcase.nl

            Comment


            • #7
              Yeah, I too noticed that sometimes it doesn't work the way it's supposed to work. :-D

              Try it this way


              PHP-Button (put the whole kaboodle in here)
              Code:
              $new_app = '../main/main.php';
              ?>
                  <script type="text/javascript">
              	function disp_widget2(xuri,xparm) 
              	{ 
              		top.document.getElementById('id-iframe-widget2').contentWindow.document.location.href = xuri;
              	}
              	var newapp = '<?php echo $new_app; ?>';
              	disp_widget2(newapp);
                  </script>
              <?php
              sc_exit(sel);
              Oh, almost forgot. If you stick this block in a library (i.e. function change_widget($new_app)), all you have to do
              is call change_widget('../main/main.php'). It is of course open to further improvement (widget#, ..).

              Couldn't resist.
              Code:
              function change_widget($new_app)
              {
              	?>
              	<script type="text/javascript">
              		function disp_widget2(xuri,xparm) 
              		{ 
              			top.document.getElementById('id-iframe-widget2').contentWindow.document.location.href = xuri;
              		}
              		var newapp = '<?php echo $new_app; ?>';
              		disp_widget2(newapp);
              	</script>
              	<?php
              }
              jsb
              Last edited by jsbinca; 09-05-2014, 03:52 PM.

              Comment


              • #8
                Tnx jsb! I appreciate this very much. I'll try this asap. It looks simple enough, but I still try to understand what's happening here.
                Putting it into a library would be the best option I guess but I have some difficulties. Your solution does not use the sc macro's.


                function change_widget($new_app)
                {
                ?> // 'inject' javascript
                <script type="text/javascript">
                function disp_widget2(xuri,xparm)
                {
                // can I add the parameters here too?
                top.document.getElementById('id-iframe-widget2').contentWindow.document.location.href = xuri;
                }
                // newapp is a javascript var which will be filled with? Echo outputs to the screen

                var newapp = '<?php echo $new_app; ?>';
                disp_widget2(newapp);
                </script>
                <?php
                }
                Last edited by aducom; 09-05-2014, 04:06 PM.
                Albert Drent
                aducom software netherlands
                scriptcase partner, reseller, support and (turn-key) development
                www.scriptcase.eu / www.scriptcase.nl

                Comment


                • #9
                  I created the library function, applied it to the application and called the function from within the button. Unfortunately it didn't work. No errormessage at least:

                  change_widget('..\main\main.php');
                  Albert Drent
                  aducom software netherlands
                  scriptcase partner, reseller, support and (turn-key) development
                  www.scriptcase.eu / www.scriptcase.nl

                  Comment


                  • #10
                    Well, I can't see an error either.
                    Would you mind to create a quick and dirty project.
                    2 Controls (control_1, control_2) with different headers.
                    1 Container with two widgets (both widgets control_1)
                    1 library (with the above function) applied to control_1

                    Control_1: onValidate (or PHP-Button)
                    change_widget('..\control_2\control_2.php');

                    It should work.

                    jsb

                    Comment


                    • #11
                      Originally posted by aducom View Post

                      function disp_widget2(xuri,xparm)
                      {
                      // can I add the parameters here too?
                      }
                      No, it's the same as in php the parameters passed into the function have to declared in the header.

                      Originally posted by aducom View Post
                      // newapp is a javascript var which will be filled with? Echo outputs to the screen

                      var newapp = '<?php echo $new_app; ?>';
                      }
                      Correct. Newapp will be filled with the name of the application to run in the widget.
                      The echo command just passes the php varaiable $new_app to the javascript variable newapp.

                      I do not use SC macros here because, as you are well aware of, they don't work everywhere/always. :-)
                      Having those js functions 'hidden' behind a php function/library makes them a little bit more accessible, even in grids.

                      jsb
                      Last edited by jsbinca; 09-05-2014, 05:36 PM.

                      Comment


                      • #12
                        I will for sure test this out. Point is that I'm not a javascript guru and so far I tried to keep as far away as possible. But it's clear I need to put more time into this. I'll try to create a small concept, pehaps a demo app if it works. It will suit all then. I'll let you know the progress.
                        Albert Drent
                        aducom software netherlands
                        scriptcase partner, reseller, support and (turn-key) development
                        www.scriptcase.eu / www.scriptcase.nl

                        Comment


                        • #13
                          Originally posted by aducom View Post
                          I will for sure test this out. Point is that I'm not a javascript guru and so far I tried to keep as far away as possible. But it's clear I need to put more time into this. I'll try to create a small concept, pehaps a demo app if it works. It will suit all then. I'll let you know the progress.
                          Albert, when you decide to read something about javascript I recommend you to skip pure javascript.
                          Go for jQuery library. Why?

                          Scriptcase already import it in the generated applications.
                          Syntax is much easier.
                          If you do something wrong in javascript, it stops the execution of script, jquery validates most simple erros of javascript and let the script continue. (e.g. your script uses an id / object that don't exists).
                          Write less, do more.
                          Code:
                          parent.document.getElementById("id-iframe-widget1").src='../control/control.php?test=abc'
                           IS EQUAL TO 
                          parent.$('#id-iframe-widget1').attr('src', '../control/control.php?test=abc');
                          There are thousands of power users of the jQuery library and an immense community wich probably have the answer for every base thing you might need with JS.
                          Regards,
                          Cavadinha

                          Development Team
                          Netmake - IT Solutions

                          Comment


                          • #14
                            Hi Cavadina,

                            I don't want to dive into javascript, i try to avoid it as much as I can. To me the second line is as abstract as the first. I don't see the advantages (in this case) besides that jquery is a standard. But I still don't want to dive into the innerworkings of jquery. That's partly why I like to use SC. But the problem is that we miss a few essential macro's. It's very logical to have an easy way to control the content of one iframe (container) by another. I.e. I have left container containing some fixed data and a second container containing some form. I would like to have an easy way to change the content of the second container by i.e. a button in the first. Unfortunately you need to dive into the generated html, find the iframe name, then do some fiddling by injecting javascript procedure to find out that it sometimes work, but sometimes not. (In this case). If I can achieve it the easy way with jquery then please share. Or perhaps you have a better idea of achieving it.
                            Last edited by aducom; 09-08-2014, 05:17 PM.
                            Albert Drent
                            aducom software netherlands
                            scriptcase partner, reseller, support and (turn-key) development
                            www.scriptcase.eu / www.scriptcase.nl

                            Comment


                            • #15
                              Im not sure what your system does exacly, how you're building it... so its kinda hard to give you good suggestion. I would have to guess a lot.
                              But a easier/simpler way to send data to another container inside the iframe would be refresh with simple get parameters.
                              If you need to save any text inside the actual container, you could use ajax to save data into PHP globals and use some ternary operators to display those texts.

                              I don't know if you're following me neither if it will do the job for this specific system you're developing.
                              Regards,
                              Cavadinha

                              Development Team
                              Netmake - IT Solutions

                              Comment

                              Working...
                              X