Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1928 | grupo2 | 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.utl.ist.berserk.logic.serviceManager.IServiceManager" %> |
||
6 | <%@ page import="pt.utl.ist.berserk.logic.serviceManager.ServiceManager" %> |
||
7 | <%@ page import="pt.estgp.estgweb.web.utils.RequestUtils" %> |
||
8 | <%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %> |
||
9 | <%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %> |
||
10 | <%@ taglib uri="/WEB-INF/tlds/jomm.tld" prefix="jomm" %> |
||
11 | <%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %> |
||
12 | <%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested" %> |
||
13 | <%@ taglib uri="/WEB-INF/tlds/baco.tld" prefix="baco" %> |
||
14 | <%@ taglib prefix="t" tagdir="/WEB-INF/tags" %> |
||
15 | |||
16 | <%-- http://localhost:8080/baco/user/editCourseReport.do?courseCode=44&year=201617 --%> |
||
17 | |||
18 | <link rel="stylesheet" href="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.css"> |
||
19 | <script src="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.min.js"></script> |
||
20 | <link rel="stylesheet" href="<%=request.getContextPath()%>/css/flora-commons/flora.resizable.css"> |
||
21 | <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>--> |
||
22 | <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.debug.js"></script> |
||
23 | <script> |
||
24 | function demoFromHTML() { |
||
25 | var pdf = new jsPDF('p', 'pt', 'letter'); |
||
26 | // source can be HTML-formatted string, or a reference |
||
27 | // to an actual DOM element from which the text will be scraped. |
||
28 | source = $('#courseReportApp')[0]; |
||
29 | |||
30 | // we support special element handlers. Register them with jQuery-style |
||
31 | // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.) |
||
32 | // There is no support for any other type of selectors |
||
33 | // (class, of compound) at this time. |
||
34 | specialElementHandlers = { |
||
35 | // element with id of "bypass" - jQuery style selector |
||
36 | '#bypassme': function (element, renderer) { |
||
37 | // true = "handled elsewhere, bypass text extraction" |
||
38 | return true |
||
39 | } |
||
40 | }; |
||
41 | margins = { |
||
42 | top: 80, |
||
43 | bottom: 60, |
||
44 | left: 40, |
||
45 | width: 522 |
||
46 | }; |
||
47 | // all coords and widths are in jsPDF instance's declared units |
||
48 | // 'inches' in this case |
||
49 | pdf.fromHTML( |
||
50 | source, // HTML string or DOM elem ref. |
||
51 | margins.left, // x coord |
||
52 | margins.top, { // y coord |
||
53 | 'width': margins.width, // max width of content on PDF |
||
54 | 'elementHandlers': specialElementHandlers |
||
55 | }, |
||
56 | |||
57 | function (dispose) { |
||
58 | // dispose: object with X, Y of the last line add to the PDF |
||
59 | // this allow the insertion of new lines after html |
||
60 | var pdfDocument = pdf.save('Test.pdf'); |
||
61 | /*var pdfDocument = pdf.output(); |
||
62 | |||
63 | var boundary = '---------------------------'; |
||
64 | boundary += Math.floor(Math.random()*32768); |
||
65 | boundary += Math.floor(Math.random()*32768); |
||
66 | boundary += Math.floor(Math.random()*32768); |
||
67 | |||
68 | var body = ''; |
||
69 | body += '--' + boundary + '\r\n' + |
||
70 | 'Content-Disposition: form-data; name="filesInputId-UPLOAD[]"; filename="20170530_210340.pdf"' + '\r\n'; |
||
71 | body += 'Content-Type: application/pdf'; |
||
72 | body += '\r\n\r\n'; |
||
73 | body += pdfDocument; |
||
74 | body += '\r\n' |
||
75 | body += '--' + boundary + '--'; |
||
76 | |||
77 | |||
78 | |||
79 | $.ajax({ |
||
80 | type: "POST", |
||
81 | cache: false, |
||
82 | url: "<%=request.getContextPath()%>/filesUpload", |
||
83 | data: body , |
||
84 | processData: false, |
||
85 | contentType : 'multipart/form-data; boundary=' + boundary, |
||
86 | success: function (data) { |
||
87 | alert('success'); |
||
88 | return false; |
||
89 | } |
||
90 | });*/ |
||
91 | }, margins |
||
92 | ); |
||
93 | } |
||
94 | </script> |
||
95 | |||
96 | <script>ping()</script> |
||
97 | |||
98 | <jsp:useBean id="courseReportJson" type="java.lang.String" scope="request"/> |
||
99 | <jsp:useBean id="course" type="pt.estgp.estgweb.domain.CourseImpl" scope="request"/> |
||
100 | |||
101 | <% |
||
102 | //AbstractDao.getCurrentSession().beginTransaction(); |
||
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 | |||
131 | |||
132 | <script> |
||
133 | |||
134 | //Especifico da aplicacao |
||
135 | var courseReportApp = angular.module('courseReportApp', ['ui.tree']); |
||
136 | GLOBAL_BacoAngularAppDependencies.push('courseReportApp'); |
||
137 | |||
138 | |||
139 | courseReportApp.directive('resizable', function () { |
||
140 | return { |
||
141 | restrict: 'A', |
||
142 | scope: { |
||
143 | callback: '&onResize' |
||
144 | }, |
||
145 | link: function postLink(scope, elem, attrs) { |
||
146 | elem.resizable(); |
||
147 | elem.on('resize', function (evt, ui, comp) { |
||
148 | scope.$apply(function() { |
||
149 | if (scope.callback) { |
||
150 | scope.callback({$evt: evt, $ui: ui, $comp: comp }); |
||
151 | } |
||
152 | }) |
||
153 | }); |
||
154 | } |
||
155 | }; |
||
156 | }); |
||
157 | |||
158 | |||
159 | courseReportApp.controller('courseReportAppController', function($scope) |
||
160 | { |
||
161 | |||
162 | $scope.docAppSelector = "#courseReportApp"; |
||
163 | $scope.report = ${courseReportJson} |
||
164 | |||
165 | $scope.resize = function(evt,ui,comp) { |
||
166 | //console.log (evt,ui); |
||
167 | comp.width = ui.size.width; |
||
168 | comp.height = ui.size.height; |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @classe class to match |
||
173 | * @superClasses array of strings |
||
174 | * */ |
||
175 | $scope.contains = function(obj,classe) |
||
176 | { |
||
177 | if(obj['@class'] && obj['@class'] == classe) |
||
178 | return true; |
||
179 | if(obj.allSuperClasses) |
||
180 | { |
||
181 | for(var i in obj.allSuperClasses) |
||
182 | { |
||
183 | if(classe == obj.allSuperClasses[i]) |
||
184 | return true; |
||
185 | } |
||
186 | } |
||
187 | return false; |
||
188 | } |
||
189 | |||
190 | $scope.showSep = function(section,subSection) |
||
191 | { |
||
192 | var s; |
||
193 | for(s in section.sections) |
||
194 | { |
||
195 | section.sections[s].active = false; |
||
196 | } |
||
197 | /*$(".separatorSectionNav").each(function() |
||
198 | { |
||
199 | angular.element($(this)).scope().section.active = false; |
||
200 | });*/ |
||
201 | subSection.active = true; |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * Este metodo devolve o template mais profundo na hierarquia de classes |
||
206 | * permitindo emular o override, quanto mais especifica for a classe |
||
207 | * e caso exista template é esse o template devolvido |
||
208 | * procura um script com o id da classe e se nao existir |
||
209 | * vai subindo nas super classes |
||
210 | * @param obj |
||
211 | * @returns {*} |
||
212 | */ |
||
213 | $scope.class2id = function(obj) |
||
214 | { |
||
215 | var objClassId = obj["@class"].replaceAll(".","_"); |
||
216 | if($("script#" + objClassId).length > 0) |
||
217 | { |
||
218 | return objClassId; |
||
219 | } |
||
220 | if(obj.allSuperClasses) |
||
221 | { |
||
222 | var s; |
||
223 | for(s in obj.allSuperClasses) |
||
224 | { |
||
225 | var superClass = obj.allSuperClasses[s]; |
||
226 | var superClassId = superClass.replaceAll(".","_"); |
||
227 | if($("script#" + superClassId).length > 0) |
||
228 | { |
||
229 | return superClassId; |
||
230 | } |
||
231 | } |
||
232 | } |
||
233 | return obj["@class"].replaceAll(".","_"); |
||
234 | } |
||
235 | |||
236 | $scope.addText = function(parentCustomPane) |
||
237 | { |
||
238 | $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.TextComponent") |
||
239 | } |
||
240 | |||
241 | $scope.addImage = function(parentCustomPane) |
||
242 | { |
||
243 | $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.ImageComponent") |
||
244 | } |
||
245 | |||
246 | $scope.addSimpleDocComponent = function(parentCustomPane,classComponent) |
||
247 | { |
||
248 | if(!parentCustomPane.components) |
||
249 | { |
||
250 | parentCustomPane.components = []; |
||
251 | } |
||
252 | parentCustomPane.components.push( |
||
253 | { |
||
254 | "@class" : classComponent |
||
255 | } |
||
256 | ); |
||
257 | } |
||
258 | $scope.removeComponent = function(index,array) |
||
259 | { |
||
260 | array.splice(index,1); |
||
261 | } |
||
262 | |||
263 | $scope.callbackUploadedFiles = function(filesUploadResult,token,targetElement) |
||
264 | { |
||
265 | var modelObject = BacoAngularUtils.getAngularElementModel(targetElement); |
||
266 | |||
267 | if(modelObject.image && modelObject.image.identifier) |
||
268 | { |
||
269 | widgetCallWithActionParameters( |
||
270 | "<%=request.getContextPath()%>/user/json/repository.do", |
||
271 | "replaceRepositoryFileFromTempPrivateDomain", |
||
272 | { |
||
273 | "identifier" : modelObject.image.identifier, |
||
274 | "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0]) |
||
275 | }, |
||
276 | "#courseReportApp", |
||
277 | function(repositoryFile4JsonView) |
||
278 | { |
||
279 | modelObject.image = repositoryFile4JsonView; |
||
280 | //image URL is generated on reimport just to avoid caching |
||
281 | modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime(); |
||
282 | angular.element($("#courseReportApp")).scope().$apply(); |
||
283 | }, |
||
284 | function(){} |
||
285 | ); |
||
286 | } |
||
287 | else |
||
288 | { |
||
289 | widgetCallWithActionParameters( |
||
290 | "<%=request.getContextPath()%>/user/json/repository.do", |
||
291 | "saveRepositoryFileFromTempPrivateDomain", |
||
292 | { |
||
293 | "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0]) |
||
294 | }, |
||
295 | "#courseReportApp", |
||
296 | function(repositoryFile4JsonView) |
||
297 | { |
||
298 | modelObject.image = repositoryFile4JsonView; |
||
299 | modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime(); |
||
300 | angular.element($("#courseReportApp")).scope().$apply(); |
||
301 | }, |
||
302 | function(){} |
||
303 | ); |
||
304 | } |
||
305 | } |
||
306 | |||
307 | $scope.saveCourseReportDocument = function () { |
||
308 | widgetCallWithActionParameters( |
||
309 | "<%=request.getContextPath()%>/user/courseReport.do", |
||
310 | "saveCourseReportDocument", |
||
311 | { |
||
312 | "courseReportDocument" : BacoJS.stringifyOrdered($scope.report) |
||
313 | }, |
||
314 | "#courseReportApp", |
||
315 | function(data) |
||
316 | { |
||
317 | alert(BacoJS.stringifyOrdered(data)); |
||
318 | }, |
||
319 | function(){} |
||
320 | ); |
||
321 | } |
||
322 | |||
323 | |||
324 | |||
325 | }); |
||
326 | </script> |
||
327 | |||
328 | <!--TEMPLATES FOR DOCUMENT BUILDER--> |
||
329 | <jsp:include page="documentsBuilder.jsp"/> |
||
330 | |||
331 | <div class="form-vertical"> |
||
332 | <div id="courseReportApp" ng-app="courseReportApp" ng-controller="courseReportAppController"> |
||
333 | <div class="web-messages"></div> |
||
334 | |||
335 | <button class="btn btn-success" ng-click="saveCourseReportDocument()">Gravar</button> |
||
336 | <button class="btn btn-success" onclick="demoFromHTML()">PDF</button> |
||
337 | |||
338 | <div ng-init="section=report;" ng-include="'pt_estgp_estgweb_utils_documentBuilder_DocumentSection'"> |
||
339 | |||
340 | </div> |
||
341 | |||
342 | <!--<pre class="code">{{ report | json }}</pre>--> |
||
343 | |||
344 | |||
345 | |||
346 | </div><!--App--> |
||
347 | </div> <!--form--> |
||
348 | |||
349 | </div><!--Panel Body--> |
||
350 | |||
351 | </div><!--Panel--> |
||
352 | |||
353 | </div><!--container-fluid--> |
||
354 | |||
355 | <% |
||
356 | //AbstractDao.getCurrentSession().getTransaction().commit(); |
||
357 | %> |