Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PrintUtils |
|
| 2.0;2 |
1 | package org.kuali.student.common.ui.client.util; | |
2 | ||
3 | import com.google.gwt.dom.client.Document; | |
4 | import com.google.gwt.dom.client.NodeList; | |
5 | import com.google.gwt.user.client.Window; | |
6 | import com.google.gwt.user.client.ui.UIObject; | |
7 | ||
8 | 0 | public class PrintUtils { |
9 | 0 | private static int num = 0; |
10 | public static void print(UIObject uiObject){ | |
11 | 0 | String headTag = ""; |
12 | 0 | String styleTags = ""; |
13 | 0 | NodeList<com.google.gwt.dom.client.Element> head = Document.get().getElementsByTagName("head"); |
14 | 0 | if(head.getItem(0) != null){ |
15 | 0 | com.google.gwt.dom.client.Element e = head.getItem(0); |
16 | 0 | NodeList<com.google.gwt.dom.client.Element> styles = e.getElementsByTagName("style"); |
17 | 0 | for(int i = 0; i < styles.getLength(); i++){ |
18 | 0 | styleTags = styleTags + styles.getItem(i).getString(); |
19 | ||
20 | } | |
21 | } | |
22 | 0 | headTag = "<HEAD><TITLE>Print - " + Window.getTitle() + "</TITLE>" + styleTags + "</HEAD>"; |
23 | 0 | openPrintWindow(uiObject.getElement().getString(), headTag, num); |
24 | 0 | num++; |
25 | 0 | } |
26 | ||
27 | private static native void openPrintWindow(String html, String headTag, int num)/*-{ | |
28 | var win = $wnd.open("", num, "width=900,height=600"); | |
29 | var doc = win.document; | |
30 | doc.open("text/html", "replace"); | |
31 | doc.write("<HTML>"); | |
32 | doc.write(headTag); | |
33 | doc.write("<BODY style='overflow: auto;'>"); | |
34 | doc.write("<a class='ks-button-primary' style='cursor: pointer;' onClick='print();'>Print</a>"); | |
35 | doc.write("<DIV class='printPage'>"); | |
36 | doc.write(html); | |
37 | doc.write("</DIV></BODY></HTML>"); | |
38 | doc.close(); | |
39 | var inputs = $doc.getElementsByTagName('input'); | |
40 | for(i = 0; i < inputs.length; i++){ | |
41 | var v = inputs[i].value; | |
42 | doc.getElementById(inputs[i].id).value = v; | |
43 | } | |
44 | inputs = $doc.getElementsByTagName('textarea'); | |
45 | for(i = 0; i < inputs.length; i++){ | |
46 | var v = inputs[i].value; | |
47 | doc.getElementById(inputs[i].id).value = v; | |
48 | } | |
49 | win.print(); | |
50 | }-*/; | |
51 | } |