Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Open Java Poppup for printing
    text
    copied!<p>Here is the problem.</p> <p>Code in My Partial / Modal <code>_form.html.erb</code></p> <pre><code>&lt;div class="modal-footer"&gt; &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt; &lt;%= f.submit 'Store Ticket', :class =&gt; 'btn btn-primary' %&gt; &lt;%= f.submit 'Print Ticket', :name =&gt;'Print Ticket ', :class =&gt; 'btn btn-primary', :id =&gt; 'print', :onclick =&gt; "$.print_page(#{@ticket.id});" %&gt; </code></pre> <p></p> <p>This call my function in <code>tickets.js.erb</code></p> <pre><code>$(document).ready(function() { $.print_page = function(val) { var val, left = ($(window).width() / 2) - (900 / 2), top = ($(window).height() / 2) - (600 / 2); window.open("tickets/print?id=" + val, null, "height=600,width=800,top=" + top + ",left=" + left + ",status=yes,toolbar=no,menubar=no,location=no"); }; $.reprint_page = function(val) { var val, left = ($(window).width() / 2) - (900 / 2), top = ($(window).height() / 2) - (600 / 2); window.open("./print?id=" + val, null, "height=600,width=800,top=" + top + ",left=" + left + ",status=yes,toolbar=no,menubar=no,location=no"); }; }); </code></pre> <p>In turn this opens my /print that has a on open pop up a print box in embedded java</p> <p>The problem is that when this opens it seems to pop up before the controller has stored the fields. All fields are getting stored but in the print window are still showing pre-update values.</p> <p>I need to ensure the database has been updated then call the page for printing the ticket?</p> <p>I thought about balling it on <code>if @ticket.save</code> but you cant seem to render twice i.e redirect to the main app screen with a popup that has focus.</p> <p>Any idea on how best to implement this function. At the moment it is hit and miss sometimes it has the updated values in /print/html.erb and other times it has the pre update values so i think it fires too fast i.e before the .save has completed in the controller.</p> <p>If I call <code>$.print_page(15)</code> from the console everything works like a dream.</p> <p>Also tried wrapping in a <code>setTimeout()</code> with a 2 second delay but this does not fire at all from the onclick event but files ok from the console manually ???</p> <p>Any help is appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload