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