Rev 1907 | 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" %> |
||
5 | <%@ page import="pt.estgp.estgweb.utils.documentBuilder.TextComponent" %> |
||
6 | <%@ page import="pt.estgp.estgweb.utils.documentBuilder.ImageComponent" %> |
||
1848 | jmachado | 7 | <%@ page import="pt.estgp.estgweb.services.courses.CourseReportServices" %> |
8 | <%@ page import="pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument" %> |
||
9 | <%@ page import="org.json.JSONException" %> |
||
1830 | jmachado | 10 | <%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %> |
11 | <%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %> |
||
12 | <%@ taglib uri="/WEB-INF/tlds/jomm.tld" prefix="jomm" %> |
||
13 | <%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %> |
||
14 | <%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested" %> |
||
15 | <%@ taglib uri="/WEB-INF/tlds/baco.tld" prefix="baco" %> |
||
16 | <%@taglib prefix="t" tagdir="/WEB-INF/tags" %> |
||
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> |
||
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( |
||
1905 | grupo7 | 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 | }, |
||
1830 | jmachado | 55 | |
1905 | grupo7 | 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(); |
||
1830 | jmachado | 61 | |
1905 | grupo7 | 62 | var boundary = '---------------------------'; |
63 | boundary += Math.floor(Math.random() * 32768); |
||
64 | boundary += Math.floor(Math.random() * 32768); |
||
65 | boundary += Math.floor(Math.random() * 32768); |
||
1830 | jmachado | 66 | |
1905 | grupo7 | 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 + '--'; |
||
1830 | jmachado | 75 | |
76 | |||
1905 | grupo7 | 77 | $.ajax({ |
78 | type: "POST", |
||
79 | cache: false, |
||
80 | url: "<%=request.getContextPath()%>/filesUpload", |
||
81 | data: body, |
||
82 | processData: false, |
||
83 | contentType: 'multipart/form-data; boundary=' + boundary, |
||
84 | success: function (data) { |
||
85 | alert('success'); |
||
86 | return false; |
||
87 | } |
||
88 | }); |
||
89 | }, margins |
||
1830 | jmachado | 90 | ); |
91 | } |
||
92 | </script> |
||
93 | |||
94 | |||
1848 | jmachado | 95 | <%--<a href="javascript:demoFromHTML()" class="button">Run Code</a>--%> |
1830 | jmachado | 96 | |
97 | <div class="container-fluid"> |
||
98 | |||
1905 | grupo7 | 99 | <style> |
100 | .separatorSection { |
||
101 | border: 1px solid #ddd; |
||
102 | } |
||
103 | </style> |
||
1830 | jmachado | 104 | |
105 | |||
1905 | grupo7 | 106 | <!-- Apresentacao da Unidade --> |
1830 | jmachado | 107 | |
1905 | grupo7 | 108 | <div class="panel panel-default"> |
109 | <div class="panel-heading"> |
||
110 | Relatório Anual do curso: ${course.name} |
||
111 | </div> |
||
112 | <div class="panel-body"> |
||
1830 | jmachado | 113 | |
1905 | grupo7 | 114 | <p><b class="label-info">Tipo de Curso:</b> <bean:message key="course.${course.degree}"/></p> |
115 | <p><b class="label-info">Ano Lectivo:</b> ${course.importYear}</p> |
||
116 | <p><b class="label-info">Departamento:</b> ${course.department.name}</p> |
||
117 | <p><b class="label-info">Escola:</b> ${course.department.courseSchool.name}</p> |
||
1830 | jmachado | 118 | |
119 | |||
1905 | grupo7 | 120 | <script> |
1830 | jmachado | 121 | |
1905 | grupo7 | 122 | //Especifico da aplicacao |
123 | var courseReportApp = angular.module('courseReportApp', ['ui.tree']); |
||
124 | GLOBAL_BacoAngularAppDependencies.push('courseReportApp'); |
||
1830 | jmachado | 125 | |
126 | |||
1905 | grupo7 | 127 | courseReportApp.directive('resizable', function () { |
128 | return { |
||
129 | restrict: 'A', |
||
130 | scope: { |
||
131 | callback: '&onResize' |
||
132 | }, |
||
133 | link: function postLink(scope, elem, attrs) { |
||
134 | elem.resizable(); |
||
135 | elem.on('resize', function (evt, ui, comp) { |
||
136 | scope.$apply(function () { |
||
137 | if (scope.callback) { |
||
138 | scope.callback({$evt: evt, $ui: ui, $comp: comp}); |
||
139 | } |
||
140 | }) |
||
141 | }); |
||
1830 | jmachado | 142 | } |
1905 | grupo7 | 143 | }; |
1830 | jmachado | 144 | }); |
145 | |||
146 | |||
1905 | grupo7 | 147 | courseReportApp.controller('courseReportAppController', function ($scope) { |
1830 | jmachado | 148 | |
1905 | grupo7 | 149 | $scope.docAppSelector = "#courseReportApp"; |
1919 | grupo6 | 150 | $scope.report = ${courseDocumentJson} |
1830 | jmachado | 151 | |
1905 | grupo7 | 152 | $scope.resize = function (evt, ui, comp) { |
153 | //console.log (evt,ui); |
||
154 | comp.width = ui.size.width; |
||
155 | comp.height = ui.size.height; |
||
156 | } |
||
1830 | jmachado | 157 | |
1905 | grupo7 | 158 | /** |
159 | * @classe class to match |
||
160 | * @superClasses array of strings |
||
161 | * */ |
||
162 | $scope.contains = function (obj, classe) { |
||
163 | if (obj['@class'] && obj['@class'] == classe) |
||
164 | return true; |
||
165 | if (obj.allSuperClasses) { |
||
166 | for (var i in obj.allSuperClasses) { |
||
167 | if (classe == obj.allSuperClasses[i]) |
||
168 | return true; |
||
169 | } |
||
170 | } |
||
171 | return false; |
||
172 | } |
||
1848 | jmachado | 173 | |
1905 | grupo7 | 174 | $scope.showSep = function (section, subSection) { |
175 | var s; |
||
176 | for (s in section.sections) { |
||
177 | section.sections[s].active = false; |
||
178 | } |
||
179 | /*$(".separatorSectionNav").each(function() |
||
180 | { |
||
181 | angular.element($(this)).scope().section.active = false; |
||
182 | });*/ |
||
183 | subSection.active = true; |
||
184 | } |
||
1848 | jmachado | 185 | |
1905 | grupo7 | 186 | /** |
187 | * Este metodo devolve o template mais profundo na hierarquia de classes |
||
188 | * permitindo emular o override, quanto mais especifica for a classe |
||
189 | * e caso exista template é esse o template devolvido |
||
190 | * procura um script com o id da classe e se nao existir |
||
191 | * vai subindo nas super classes |
||
192 | * @param obj |
||
193 | * @returns {*} |
||
194 | */ |
||
195 | $scope.class2id = function (obj) { |
||
196 | var objClassId = obj["@class"].replaceAll(".", "_"); |
||
197 | if ($("script#" + objClassId).length > 0) { |
||
198 | return objClassId; |
||
199 | } |
||
200 | if (obj.allSuperClasses) { |
||
201 | var s; |
||
202 | for (s in obj.allSuperClasses) { |
||
203 | var superClass = obj.allSuperClasses[s]; |
||
204 | var superClassId = superClass.replaceAll(".", "_"); |
||
205 | if ($("script#" + superClassId).length > 0) { |
||
206 | return superClassId; |
||
207 | } |
||
208 | } |
||
209 | } |
||
210 | return obj["@class"].replaceAll(".", "_"); |
||
1848 | jmachado | 211 | } |
212 | |||
1905 | grupo7 | 213 | $scope.addText = function (parentCustomPane) { |
214 | $scope.addSimpleDocComponent(parentCustomPane, "pt.estgp.estgweb.utils.documentBuilder.TextComponent") |
||
215 | } |
||
1830 | jmachado | 216 | |
1905 | grupo7 | 217 | $scope.addImage = function (parentCustomPane) { |
218 | $scope.addSimpleDocComponent(parentCustomPane, "pt.estgp.estgweb.utils.documentBuilder.ImageComponent") |
||
219 | } |
||
1830 | jmachado | 220 | |
1905 | grupo7 | 221 | $scope.addSimpleDocComponent = function (parentCustomPane, classComponent) { |
222 | if (!parentCustomPane.components) { |
||
223 | parentCustomPane.components = []; |
||
224 | } |
||
225 | parentCustomPane.components.push( |
||
226 | { |
||
227 | "@class": classComponent |
||
228 | } |
||
229 | ); |
||
1830 | jmachado | 230 | } |
1905 | grupo7 | 231 | $scope.removeComponent = function (index, array) { |
232 | array.splice(index, 1); |
||
233 | } |
||
1830 | jmachado | 234 | |
1906 | grupo6 | 235 | $scope.callbackUploadedFiles = function (filesUploadResult, token, targetElement) |
236 | { |
||
1905 | grupo7 | 237 | var modelObject = BacoAngularUtils.getAngularElementModel(targetElement); |
1830 | jmachado | 238 | |
1905 | grupo7 | 239 | if (modelObject.image && modelObject.image.identifier) { |
240 | widgetCallWithActionParameters( |
||
241 | "<%=request.getContextPath()%>/user/json/repository.do", |
||
242 | "replaceRepositoryFileFromTempPrivateDomain", |
||
243 | { |
||
244 | "identifier": modelObject.image.identifier, |
||
245 | "fileUploaded": BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0]) |
||
246 | }, |
||
247 | "#courseReportApp", |
||
248 | function (repositoryFile4JsonView) { |
||
249 | modelObject.image = repositoryFile4JsonView; |
||
250 | //image URL is generated on reimport just to avoid caching |
||
251 | modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime(); |
||
1906 | grupo6 | 252 | $scope.$apply(); |
1905 | grupo7 | 253 | }, |
254 | function () { |
||
255 | } |
||
256 | ); |
||
257 | } |
||
258 | else { |
||
259 | widgetCallWithActionParameters( |
||
260 | "<%=request.getContextPath()%>/user/json/repository.do", |
||
261 | "saveRepositoryFileFromTempPrivateDomain", |
||
262 | { |
||
263 | "fileUploaded": BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0]) |
||
264 | }, |
||
265 | "#courseReportApp", |
||
266 | function (repositoryFile4JsonView) { |
||
267 | modelObject.image = repositoryFile4JsonView; |
||
268 | modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime(); |
||
269 | angular.element($("#courseReportApp")).scope().$apply(); |
||
270 | }, |
||
271 | function () { |
||
272 | } |
||
273 | ); |
||
274 | } |
||
275 | } |
||
1830 | jmachado | 276 | |
1905 | grupo7 | 277 | $scope.save = function () { |
278 | widgetCallWithActionParameters( |
||
279 | "<%=request.getContextPath()%>/user/courseReport.do", |
||
280 | "save", |
||
281 | { |
||
282 | "courseReportDocument": BacoJS.stringifyOrdered($scope.report) |
||
283 | }, |
||
284 | "#courseReportApp", |
||
285 | function (resposta) { |
||
286 | $scope.$apply(); |
||
287 | }, |
||
288 | function () { |
||
289 | } |
||
290 | ); |
||
291 | } |
||
1848 | jmachado | 292 | |
1830 | jmachado | 293 | |
1905 | grupo7 | 294 | }); |
295 | </script> |
||
1830 | jmachado | 296 | |
1905 | grupo7 | 297 | <!--TEMPLATES FOR DOCUMENT BUILDER--> |
298 | <jsp:include page="../utils/documentsBuilder.jsp"/> |
||
299 | <jsp:include page="coursereport/templates.jsp"/> |
||
1830 | jmachado | 300 | |
1905 | grupo7 | 301 | <div class="form-vertical"> |
302 | <div id="courseReportApp" ng-app="courseReportApp" ng-controller="courseReportAppController"> |
||
303 | <div class="web-messages"></div> |
||
304 | <button ng-click="save()" class="btn btn-success">Salvar</button> |
||
305 | <div ng-init="section=report;" |
||
306 | ng-include="'pt_estgp_estgweb_utils_documentBuilder_DocumentSection'"> |
||
1830 | jmachado | 307 | |
1905 | grupo7 | 308 | </div> |
1830 | jmachado | 309 | |
1906 | grupo6 | 310 | <pre class="code">{{ report | json }}</pre> |
1830 | jmachado | 311 | |
312 | |||
1905 | grupo7 | 313 | </div><!--App--> |
314 | </div> <!--form--> |
||
1830 | jmachado | 315 | |
1905 | grupo7 | 316 | </div><!--Panel Body--> |
1830 | jmachado | 317 | |
1905 | grupo7 | 318 | </div><!--Panel--> |
1830 | jmachado | 319 | |
1905 | grupo7 | 320 | </div> |
321 | <!--container-fluid--> |
||
1830 | jmachado | 322 |