1,322 → 1,3 |
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
<%@ page import="jomm.dao.impl.AbstractDao" %> |
<%@ page import="pt.estgp.estgweb.domain.CourseImpl" %> |
<%@ page import="pt.estgp.estgweb.domain.dao.DaoFactory" %> |
<%@ page import="pt.estgp.estgweb.utils.documentBuilder.TextComponent" %> |
<%@ page import="pt.estgp.estgweb.utils.documentBuilder.ImageComponent" %> |
<%@ page import="pt.estgp.estgweb.services.courses.CourseReportServices" %> |
<%@ page import="pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument" %> |
<%@ page import="org.json.JSONException" %> |
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %> |
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %> |
<%@ taglib uri="/WEB-INF/tlds/jomm.tld" prefix="jomm" %> |
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %> |
<%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested" %> |
<%@ taglib uri="/WEB-INF/tlds/baco.tld" prefix="baco" %> |
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %> |
|
<link rel="stylesheet" href="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.css"> |
<script src="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.min.js"></script> |
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/flora-commons/flora.resizable.css"> |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script> |
<script> |
function demoFromHTML() { |
var pdf = new jsPDF('p', 'pt', 'letter'); |
// source can be HTML-formatted string, or a reference |
// to an actual DOM element from which the text will be scraped. |
source = $('#courseReportApp')[0]; |
|
// we support special element handlers. Register them with jQuery-style |
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.) |
// There is no support for any other type of selectors |
// (class, of compound) at this time. |
specialElementHandlers = { |
// element with id of "bypass" - jQuery style selector |
'#bypassme': function (element, renderer) { |
// true = "handled elsewhere, bypass text extraction" |
return true |
} |
}; |
margins = { |
top: 80, |
bottom: 60, |
left: 40, |
width: 522 |
}; |
// all coords and widths are in jsPDF instance's declared units |
// 'inches' in this case |
pdf.fromHTML( |
source, // HTML string or DOM elem ref. |
margins.left, // x coord |
margins.top, { // y coord |
'width': margins.width, // max width of content on PDF |
'elementHandlers': specialElementHandlers |
}, |
|
function (dispose) { |
// dispose: object with X, Y of the last line add to the PDF |
// this allow the insertion of new lines after html |
//var pdfDocument = pdf.save('Test.pdf'); |
var pdfDocument = pdf.output(); |
|
var boundary = '---------------------------'; |
boundary += Math.floor(Math.random() * 32768); |
boundary += Math.floor(Math.random() * 32768); |
boundary += Math.floor(Math.random() * 32768); |
|
var body = ''; |
body += '--' + boundary + '\r\n' + |
'Content-Disposition: form-data; name="filesInputId-UPLOAD[]"; filename="20170530_210340.pdf"' + '\r\n'; |
body += 'Content-Type: application/pdf'; |
body += '\r\n\r\n'; |
body += pdfDocument; |
body += '\r\n' |
body += '--' + boundary + '--'; |
|
|
$.ajax({ |
type: "POST", |
cache: false, |
url: "<%=request.getContextPath()%>/filesUpload", |
data: body, |
processData: false, |
contentType: 'multipart/form-data; boundary=' + boundary, |
success: function (data) { |
alert('success'); |
return false; |
} |
}); |
}, margins |
); |
} |
</script> |
|
|
<%--<a href="javascript:demoFromHTML()" class="button">Run Code</a>--%> |
|
<div class="container-fluid"> |
|
<style> |
.separatorSection { |
border: 1px solid #ddd; |
} |
</style> |
|
|
<!-- Apresentacao da Unidade --> |
|
<div class="panel panel-default"> |
<div class="panel-heading"> |
Relatório Anual do curso: ${course.name} |
</div> |
<div class="panel-body"> |
|
<p><b class="label-info">Tipo de Curso:</b> <bean:message key="course.${course.degree}"/></p> |
<p><b class="label-info">Ano Lectivo:</b> ${course.importYear}</p> |
<p><b class="label-info">Departamento:</b> ${course.department.name}</p> |
<p><b class="label-info">Escola:</b> ${course.department.courseSchool.name}</p> |
|
|
<script> |
|
//Especifico da aplicacao |
var courseReportApp = angular.module('courseReportApp', ['ui.tree']); |
GLOBAL_BacoAngularAppDependencies.push('courseReportApp'); |
|
|
courseReportApp.directive('resizable', function () { |
return { |
restrict: 'A', |
scope: { |
callback: '&onResize' |
}, |
link: function postLink(scope, elem, attrs) { |
elem.resizable(); |
elem.on('resize', function (evt, ui, comp) { |
scope.$apply(function () { |
if (scope.callback) { |
scope.callback({$evt: evt, $ui: ui, $comp: comp}); |
} |
}) |
}); |
} |
}; |
}); |
|
|
courseReportApp.controller('courseReportAppController', function ($scope) { |
|
$scope.docAppSelector = "#courseReportApp"; |
$scope.report = ${courseDocumentJson} |
|
$scope.resize = function (evt, ui, comp) { |
//console.log (evt,ui); |
comp.width = ui.size.width; |
comp.height = ui.size.height; |
} |
|
/** |
* @classe class to match |
* @superClasses array of strings |
* */ |
$scope.contains = function (obj, classe) { |
if (obj['@class'] && obj['@class'] == classe) |
return true; |
if (obj.allSuperClasses) { |
for (var i in obj.allSuperClasses) { |
if (classe == obj.allSuperClasses[i]) |
return true; |
} |
} |
return false; |
} |
|
$scope.showSep = function (section, subSection) { |
var s; |
for (s in section.sections) { |
section.sections[s].active = false; |
} |
/*$(".separatorSectionNav").each(function() |
{ |
angular.element($(this)).scope().section.active = false; |
});*/ |
subSection.active = true; |
} |
|
/** |
* Este metodo devolve o template mais profundo na hierarquia de classes |
* permitindo emular o override, quanto mais especifica for a classe |
* e caso exista template é esse o template devolvido |
* procura um script com o id da classe e se nao existir |
* vai subindo nas super classes |
* @param obj |
* @returns {*} |
*/ |
$scope.class2id = function (obj) { |
var objClassId = obj["@class"].replaceAll(".", "_"); |
if ($("script#" + objClassId).length > 0) { |
return objClassId; |
} |
if (obj.allSuperClasses) { |
var s; |
for (s in obj.allSuperClasses) { |
var superClass = obj.allSuperClasses[s]; |
var superClassId = superClass.replaceAll(".", "_"); |
if ($("script#" + superClassId).length > 0) { |
return superClassId; |
} |
} |
} |
return obj["@class"].replaceAll(".", "_"); |
} |
|
$scope.addText = function (parentCustomPane) { |
$scope.addSimpleDocComponent(parentCustomPane, "pt.estgp.estgweb.utils.documentBuilder.TextComponent") |
} |
|
$scope.addImage = function (parentCustomPane) { |
$scope.addSimpleDocComponent(parentCustomPane, "pt.estgp.estgweb.utils.documentBuilder.ImageComponent") |
} |
|
$scope.addSimpleDocComponent = function (parentCustomPane, classComponent) { |
if (!parentCustomPane.components) { |
parentCustomPane.components = []; |
} |
parentCustomPane.components.push( |
{ |
"@class": classComponent |
} |
); |
} |
$scope.removeComponent = function (index, array) { |
array.splice(index, 1); |
} |
|
$scope.callbackUploadedFiles = function (filesUploadResult, token, targetElement) |
{ |
var modelObject = BacoAngularUtils.getAngularElementModel(targetElement); |
|
if (modelObject.image && modelObject.image.identifier) { |
widgetCallWithActionParameters( |
"<%=request.getContextPath()%>/user/json/repository.do", |
"replaceRepositoryFileFromTempPrivateDomain", |
{ |
"identifier": modelObject.image.identifier, |
"fileUploaded": BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0]) |
}, |
"#courseReportApp", |
function (repositoryFile4JsonView) { |
modelObject.image = repositoryFile4JsonView; |
//image URL is generated on reimport just to avoid caching |
modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime(); |
$scope.$apply(); |
}, |
function () { |
} |
); |
} |
else { |
widgetCallWithActionParameters( |
"<%=request.getContextPath()%>/user/json/repository.do", |
"saveRepositoryFileFromTempPrivateDomain", |
{ |
"fileUploaded": BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0]) |
}, |
"#courseReportApp", |
function (repositoryFile4JsonView) { |
modelObject.image = repositoryFile4JsonView; |
modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime(); |
angular.element($("#courseReportApp")).scope().$apply(); |
}, |
function () { |
} |
); |
} |
} |
|
$scope.save = function () { |
widgetCallWithActionParameters( |
"<%=request.getContextPath()%>/user/courseReport.do", |
"save", |
{ |
"courseReportDocument": BacoJS.stringifyOrdered($scope.report) |
}, |
"#courseReportApp", |
function (resposta) { |
$scope.$apply(); |
}, |
function () { |
} |
); |
} |
|
|
}); |
</script> |
|
<!--TEMPLATES FOR DOCUMENT BUILDER--> |
<jsp:include page="../utils/documentsBuilder.jsp"/> |
<jsp:include page="coursereport/templates.jsp"/> |
|
<div class="form-vertical"> |
<div id="courseReportApp" ng-app="courseReportApp" ng-controller="courseReportAppController"> |
<div class="web-messages"></div> |
<button ng-click="save()" class="btn btn-success">Salvar</button> |
<div ng-init="section=report;" |
ng-include="'pt_estgp_estgweb_utils_documentBuilder_DocumentSection'"> |
|
</div> |
|
<pre class="code">{{ report | json }}</pre> |
|
|
</div><!--App--> |
</div> <!--form--> |
|
</div><!--Panel Body--> |
|
</div><!--Panel--> |
|
</div> |
<!--container-fluid--> |
|
<jsp:include page="../utils/reportEdit.jsp"/> |
<jsp:include page="../courses/coursereport/templates.jsp"/> |
|