Announcement

Collapse
No announcement yet.

passing data between two apps in a container

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

  • aducom
    started a topic passing data between two apps in a container

    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?

  • Giu
    replied
    Originally posted by aducom View Post
    Simple sample: I have a container with two columns. In the left i have static data about a patient and two buttons: static dossier and dynamic dossier. Depending on the press of the button I want the second column to feed with the selected application. I also need to send some parameters to this dossier like the patient id. I found out that just using [] variables not always do the job and sometimes you need to pass them directly using the url or within the sc_redir. So press static, i show the static dossier of the selected patient, press dynamic, i show the dynamic dossier of the selected patient. What's the most easy approach for this?

    In general I would expect that I could use sc_redir where I could use the iframe like : sc_redir(myapp,mypars,'id-iframe-widget1'); It still has the disadvantage I have to find out the iframe name in the generated form but...
    This is a wish, it doesn't work and I need to put _parent etc. in it.
    Adding to your suggestion...names for widgets, and events and macros to interact with this widgets.

    Leave a comment:


  • aducom
    replied
    Simple sample: I have a container with two columns. In the left i have static data about a patient and two buttons: static dossier and dynamic dossier. Depending on the press of the button I want the second column to feed with the selected application. I also need to send some parameters to this dossier like the patient id. I found out that just using [] variables not always do the job and sometimes you need to pass them directly using the url or within the sc_redir. So press static, i show the static dossier of the selected patient, press dynamic, i show the dynamic dossier of the selected patient. What's the most easy approach for this?

    In general I would expect that I could use sc_redir where I could use the iframe like : sc_redir(myapp,mypars,'id-iframe-widget1'); It still has the disadvantage I have to find out the iframe name in the generated form but...
    This is a wish, it doesn't work and I need to put _parent etc. in it.

    Leave a comment:


  • Cavadinha
    replied
    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.

    Leave a comment:


  • aducom
    replied
    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.

    Leave a comment:


  • Cavadinha
    replied
    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.

    Leave a comment:


  • aducom
    replied
    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.

    Leave a comment:


  • jsbinca
    replied
    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.

    Leave a comment:


  • jsbinca
    replied
    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

    Leave a comment:


  • aducom
    replied
    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');

    Leave a comment:


  • aducom
    replied
    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.

    Leave a comment:


  • jsbinca
    replied
    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.

    Leave a comment:


  • aducom
    replied
    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...

    Leave a comment:


  • aducom
    replied
    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....

    Leave a comment:


  • aducom
    replied
    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?

    Leave a comment:

Working...
X