This repository was archived by the owner on Jun 20, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathjquery.jasperreader.js
More file actions
147 lines (114 loc) · 3.54 KB
/
Copy pathjquery.jasperreader.js
File metadata and controls
147 lines (114 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
(function($) {
$.fn.JasperReader = function(url, sections) {
if(typeof url == 'undefined') {
console.error('Please specify a JasperReports XML file.');
return;
}
var container = $(this);
var report = {};
var canvas = {};
var fetchPage = function(url, callback) {
$.ajax({
type: 'GET',
url: url,
dataType: 'xml',
complete: function(response) {
callback($.xml2json(response.responseText));
}
});
};
var createPage = function() {
container.css({
width: report.pageWidth,
height: report.pageHeight,
padding: report.topMargin + 'px ' +
report.rightMargin + 'px ' +
report.bottomMargin + 'px ' +
report.leftMargin + 'px'
});
canvas = Raphael(container.attr('id'));
Draw.draw();
container.before('<h1>' + report.name + '</h1>');
};
var Draw = {
sections: [],
setSections: function(obj) {
if(typeof obj == 'undefined') {
var obj = [];
for(i in report) {
if(typeof report[i] == 'object') {
obj.push(i);
}
}
}
this.sections = obj;
},
exists: function(str) {
if(typeof this[str] != 'undefined') {
return true;
}
return false;
},
draw: function() {
var currentTop = parseInt(report.topMargin);
var currentLeft = parseInt(report.leftMargin);
for(i in this.sections) {
var section = this.sections[i];
for(band in report[section]) {
for(name in report[section][band]) {
if(this.exists(name)) {
if(report[section][band][name].length > 0) {
for(i in report[section][band][name]) {
report[section][band][name][i].reportElement.x = parseInt(report[section][band][name][i].reportElement.x) + currentLeft;
report[section][band][name][i].reportElement.y = parseInt(report[section][band][name][i].reportElement.y) + currentTop;
this[name](report[section][band][name][i]);
}
} else {
report[section][band][name].reportElement.x = parseInt(report[section][band][name].reportElement.x) + currentLeft;
report[section][band][name].reportElement.y = parseInt(report[section][band][name].reportElement.y) + currentTop;
this[name](report[section][band][name]);
}
}
}
currentTop += parseInt(report[section][band].height);
}
}
},
rectangle: function(e) {
var rect = canvas.rect(
e.reportElement.x,
e.reportElement.y,
e.reportElement.width,
e.reportElement.height
);
rect.attr("fill", e.reportElement.backcolor);
rect.attr("stroke", "#CCC");
},
line: function(e) {
this.rectangle(e);
},
staticText: function(e) {
var text = canvas.text(e.reportElement.x, e.reportElement.y, e.text[0]);
text.attr("fill", e.forecolor);
text.attr("textAlign", e.textElement.textAlignment);
text.attr("font", e.textElement.font.size + "px Arial");
text.attr("text-anchor", "start");
if(e.textElement.font.isBold) {
text.attr("font-weight", "bold");
}
},
textField: function(e) {
var text = canvas.text(e.reportElement.x, e.reportElement.y, e.textFieldExpression);
text.attr("fill", "#DDD");
text.attr("text-anchor", "start");
text.attr("textAlign", e.textElement.textAlignment);
text.attr("font", e.textElement.font.size + "px Arial");
}
};
fetchPage(url, function(xml) {
report = xml;
Draw.setSections(sections);
createPage();
});
};
})(jQuery);