Rev 1848 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1830 | jmachado | 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> |
2 | <%@ page import="jomm.dao.impl.AbstractDao" %> |
||
3 | <%@ page import="pt.estgp.estgweb.domain.CourseImpl" %> |
||
4 | <%@ page import="pt.estgp.estgweb.domain.dao.DaoFactory" %> |
||
5 | <%@ page import="pt.estgp.estgweb.utils.documentBuilder.TextComponent" %> |
||
6 | <%@ page import="pt.estgp.estgweb.utils.documentBuilder.ImageComponent" %> |
||
7 | <%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %> |
||
8 | <%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %> |
||
9 | <%@ taglib uri="/WEB-INF/tlds/jomm.tld" prefix="jomm" %> |
||
10 | <%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %> |
||
11 | <%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested" %> |
||
12 | <%@ taglib uri="/WEB-INF/tlds/baco.tld" prefix="baco" %> |
||
13 | <%@taglib prefix="t" tagdir="/WEB-INF/tags" %> |
||
14 | |||
15 | <link rel="stylesheet" href="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.css"> |
||
16 | <script src="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.min.js"></script> |
||
17 | <link rel="stylesheet" href="<%=request.getContextPath()%>/css/flora-commons/flora.resizable.css"> |
||
18 | <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script> |
||
19 | <script> |
||
20 | function demoFromHTML() { |
||
21 | var pdf = new jsPDF('p', 'pt', 'letter'); |
||
22 | // source can be HTML-formatted string, or a reference |
||
23 | // to an actual DOM element from which the text will be scraped. |
||
24 | source = $('#courseReportApp')[0]; |
||
25 | |||
26 | // we support special element handlers. Register them with jQuery-style |
||
27 | // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.) |
||
28 | // There is no support for any other type of selectors |
||
29 | // (class, of compound) at this time. |
||
30 | specialElementHandlers = { |
||
31 | // element with id of "bypass" - jQuery style selector |
||
32 | '#bypassme': function (element, renderer) { |
||
33 | // true = "handled elsewhere, bypass text extraction" |
||
34 | return true |
||
35 | } |
||
36 | }; |
||
37 | margins = { |
||
38 | top: 80, |
||
39 | bottom: 60, |
||
40 | left: 40, |
||
41 | width: 522 |
||
42 | }; |
||
43 | // all coords and widths are in jsPDF instance's declared units |
||
44 | // 'inches' in this case |
||
45 | pdf.fromHTML( |
||
46 | source, // HTML string or DOM elem ref. |
||
47 | margins.left, // x coord |
||
48 | margins.top, { // y coord |
||
49 | 'width': margins.width, // max width of content on PDF |
||
50 | 'elementHandlers': specialElementHandlers |
||
51 | }, |
||
52 | |||
53 | function (dispose) { |
||
54 | // dispose: object with X, Y of the last line add to the PDF |
||
55 | // this allow the insertion of new lines after html |
||
56 | //var pdfDocument = pdf.save('Test.pdf'); |
||
57 | var pdfDocument = pdf.output(); |
||
58 | |||
59 | var boundary = '---------------------------'; |
||
60 | boundary += Math.floor(Math.random()*32768); |
||
61 | boundary += Math.floor(Math.random()*32768); |
||
62 | boundary += Math.floor(Math.random()*32768); |
||
63 | |||
64 | var body = ''; |
||
65 | body += '--' + boundary + '\r\n' + |
||
66 | 'Content-Disposition: form-data; name="filesInputId-UPLOAD[]"; filename="20170530_210340.pdf"' + '\r\n'; |
||
67 | body += 'Content-Type: application/pdf'; |
||
68 | body += '\r\n\r\n'; |
||
69 | body += pdfDocument; |
||
70 | body += '\r\n' |
||
71 | body += '--' + boundary + '--'; |
||
72 | |||
73 | |||
74 | |||
75 | $.ajax({ |
||
76 | type: "POST", |
||
77 | cache: false, |
||
78 | url: "<%=request.getContextPath()%>/filesUpload", |
||
79 | data: body , |
||
80 | processData: false, |
||
81 | contentType : 'multipart/form-data; boundary=' + boundary, |
||
82 | success: function (data) { |
||
83 | alert('success'); |
||
84 | return false; |
||
85 | } |
||
86 | }); |
||
87 | }, margins |
||
88 | ); |
||
89 | } |
||
90 | </script> |
||
91 | |||
92 | <% |
||
93 | |||
94 | Long courseId = Long.parseLong(request.getParameter("courseId")); |
||
95 | AbstractDao.getCurrentSession().beginTransaction(); |
||
96 | CourseImpl courseImpl = (CourseImpl) DaoFactory.getCourseDaoImpl().get(courseId); |
||
97 | request.setAttribute("course",courseImpl); |
||
98 | |||
99 | String classTextComponent = TextComponent.class.getName(); |
||
100 | String classImageComponent = ImageComponent.class.getName(); |
||
101 | request.setAttribute("classTextComponent",classTextComponent); |
||
102 | request.setAttribute("classImageComponent",classImageComponent); |
||
103 | %> |
||
104 | <a href="javascript:demoFromHTML()" class="button">Run Code</a> |
||
105 | |||
106 | <div class="container-fluid"> |
||
107 | |||
108 | <style> |
||
109 | .separatorSection |
||
110 | { |
||
111 | border: 1px solid #ddd; |
||
112 | } |
||
113 | </style> |
||
114 | |||
115 | |||
116 | <!-- Apresentacao da Unidade --> |
||
117 | |||
118 | <div class="panel panel-default"> |
||
119 | <div class="panel-heading"> |
||
120 | Relatório Anual do curso: ${course.name} |
||
121 | </div> |
||
122 | <div class="panel-body"> |
||
123 | |||
124 | <p><b class="label-info">Tipo de Curso:</b> <bean:message key="course.${course.degree}"/></p> |
||
125 | <p><b class="label-info">Ano Lectivo:</b> ${course.importYear}</p> |
||
126 | <p><b class="label-info">Departamento:</b> ${course.department.name}</p> |
||
127 | <p><b class="label-info">Escola:</b> ${course.department.courseSchool.name}</p> |
||
128 | |||
129 | |||
130 | <script> |
||
131 | function showSep(id) |
||
132 | { |
||
133 | $(".separatorSectionNav").removeClass("active"); |
||
134 | $(".separatorSection").hide(); |
||
135 | $("#separatorSectionNav_" + id).addClass("active"); |
||
136 | $("#separatorSection_" + id).show(); |
||
137 | } |
||
138 | </script> |
||
139 | |||
140 | <ul class="nav nav-tabs"> |
||
141 | <li id="separatorSectionNav_introducao" class="active separatorSectionNav"><a href="javascript:showSep('introducao')">1 - Introdução</a></li> |
||
142 | <li id="separatorSectionNav_mapaUnidades" class="separatorSectionNav"><a href="javascript:showSep('mapaUnidades')">2 - Mapa Síntese </a></li> |
||
143 | <li id="separatorSectionNav_resultados" class="separatorSectionNav"><a href="javascript:showSep('resultados')">3 - Resultados </a></li> |
||
144 | <li id="separatorSectionNav_inqueritos" class="separatorSectionNav"><a href="javascript:showSep('inqueritos')">4 - Inquéritos </a></li> |
||
145 | <li id="separatorSectionNav_conclusoes" class="separatorSectionNav"><a href="javascript:showSep('conclusoes')">4 - Conclusões </a></li> |
||
146 | |||
147 | </ul> |
||
148 | |||
149 | |||
150 | |||
151 | <script> |
||
152 | //Especifico da aplicacao |
||
153 | var courseReportApp = angular.module('courseReportApp', []); |
||
154 | GLOBAL_BacoAngularAppDependencies.push('courseReportApp'); |
||
155 | |||
156 | |||
157 | courseReportApp.directive('resizable', function () { |
||
158 | return { |
||
159 | restrict: 'A', |
||
160 | scope: { |
||
161 | callback: '&onResize' |
||
162 | }, |
||
163 | link: function postLink(scope, elem, attrs) { |
||
164 | elem.resizable(); |
||
165 | elem.on('resize', function (evt, ui, comp) { |
||
166 | scope.$apply(function() { |
||
167 | if (scope.callback) { |
||
168 | scope.callback({$evt: evt, $ui: ui, $comp: comp }); |
||
169 | } |
||
170 | }) |
||
171 | }); |
||
172 | } |
||
173 | }; |
||
174 | }); |
||
175 | |||
176 | |||
177 | courseReportApp.controller('courseReportAppController', function($scope) |
||
178 | { |
||
179 | |||
180 | $scope.report = |
||
181 | { |
||
182 | |||
183 | } |
||
184 | |||
185 | $scope.resize = function(evt,ui,comp) { |
||
186 | //console.log (evt,ui); |
||
187 | comp.width = ui.size.width; |
||
188 | comp.height = ui.size.height; |
||
189 | } |
||
190 | |||
191 | $scope.addText = function(parentCustomPane) |
||
192 | { |
||
193 | $scope.addSimpleDocComponent(parentCustomPane,"${classTextComponent}") |
||
194 | } |
||
195 | |||
196 | $scope.addImage = function(parentCustomPane) |
||
197 | { |
||
198 | $scope.addSimpleDocComponent(parentCustomPane,"${classImageComponent}") |
||
199 | } |
||
200 | |||
201 | $scope.addSimpleDocComponent = function(parentCustomPane,classComponent) |
||
202 | { |
||
203 | if(!parentCustomPane.components) |
||
204 | { |
||
205 | parentCustomPane.components = []; |
||
206 | } |
||
207 | parentCustomPane.components.push( |
||
208 | { |
||
209 | "@class" : classComponent, |
||
210 | "text" : "", |
||
211 | "title" : "" |
||
212 | } |
||
213 | ); |
||
214 | } |
||
215 | $scope.removeComponent = function(index,array) |
||
216 | { |
||
217 | array.splice(index,1); |
||
218 | |||
219 | |||
220 | } |
||
221 | $scope.callbackUploadedFiles = function(filesUploadResult,token,targetElement) |
||
222 | { |
||
223 | var modelObject = BacoAngularUtils.getAngularElementModel(targetElement); |
||
224 | modelObject.filesUploadResult = filesUploadResult; |
||
225 | if(modelObject.image && modelObject.image.identifier) |
||
226 | { |
||
227 | widgetCallWithActionParameters( |
||
228 | "<%=request.getContextPath()%>/user/json/repository.do", |
||
229 | "replaceRepositoryFileFromTempPrivateDomain", |
||
230 | { |
||
231 | "identifier" : modelObject.image.identifier, |
||
232 | "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0]) |
||
233 | }, |
||
234 | "#courseReportApp", |
||
235 | function(repositoryFile4JsonView) |
||
236 | { |
||
237 | modelObject.image = repositoryFile4JsonView; |
||
238 | modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime(); |
||
239 | delete modelObject.filesUploadResult; |
||
240 | angular.element($("#courseReportApp")).scope().$apply(); |
||
241 | }, |
||
242 | function(){} |
||
243 | ); |
||
244 | } |
||
245 | else |
||
246 | { |
||
247 | widgetCallWithActionParameters( |
||
248 | "<%=request.getContextPath()%>/user/json/repository.do", |
||
249 | "saveRepositoryFileFromTempPrivateDomain", |
||
250 | { |
||
251 | "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0]) |
||
252 | }, |
||
253 | "#courseReportApp", |
||
254 | function(repositoryFile4JsonView) |
||
255 | { |
||
256 | modelObject.image = repositoryFile4JsonView; |
||
257 | modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime(); |
||
258 | delete modelObject.filesUploadResult; |
||
259 | angular.element($("#courseReportApp")).scope().$apply(); |
||
260 | }, |
||
261 | function(){} |
||
262 | ); |
||
263 | } |
||
264 | } |
||
265 | |||
266 | |||
267 | }); |
||
268 | </script> |
||
269 | <jsp:include page="../utils/documentsBuilder.jsp"/> |
||
270 | |||
271 | |||
272 | <div id="courseReportApp" ng-app="courseReportApp" ng-controller="courseReportAppController" class="form-vertical"> |
||
273 | |||
274 | |||
275 | <!--Introducao--> |
||
276 | <div id="separatorSection_introducao" class="separatorSection clearfix"> |
||
277 | |||
278 | <div class="documentSimpleComponent form-group clearfix"> |
||
279 | <label class="col-md-2 control-label">Texto</label> |
||
280 | <div class="col-md-10"> |
||
281 | <textarea class="form-control" rows="10" ng-model="report.introSection.textComponent.text"> |
||
282 | |||
283 | </textarea> |
||
284 | </div> |
||
285 | </div> |
||
286 | <div ng-include="'customPane_renderer.html'" |
||
287 | ng-init="report.introSection.customPane = {};customPane = report.introSection.customPane;docAppSelector='#courseReportApp'"> |
||
288 | </div> |
||
289 | |||
290 | |||
291 | </div> |
||
292 | <!--/Introducao--> |
||
293 | |||
294 | <!--Mapa Unidades--> |
||
295 | <div id="separatorSection_mapaUnidades" class="separatorSection"> |
||
296 | |||
297 | </div> |
||
298 | <!--/Mapa Unidades--> |
||
299 | |||
300 | <!--Resultados--> |
||
301 | <div id="separatorSection_resultados" class="separatorSection"> |
||
302 | |||
303 | </div> |
||
304 | <!--/Resultados--> |
||
305 | |||
306 | <!--Inqueritos--> |
||
307 | <div id="separatorSection_inqueritos" class="separatorSection"> |
||
308 | |||
309 | </div> |
||
310 | <!--/Inqueritos--> |
||
311 | |||
312 | <!--Conclusoes--> |
||
313 | <div id="separatorSection_conclusoes" class="separatorSection"> |
||
314 | |||
315 | </div> |
||
316 | <!--/Conclusoes--> |
||
317 | |||
318 | <pre class="code">{{ report | json }}</pre> |
||
319 | |||
320 | </div><!--App--> |
||
321 | |||
322 | </div><!--Panel Body--> |
||
323 | |||
324 | </div><!--Panel--> |
||
325 | |||
326 | </div><!--container-fluid--> |
||
327 | |||
328 | <% |
||
329 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
330 | %> |