Subversion Repositories bacoAlunos

Rev

Rev 1935 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1935 Rev 1936
Line 1... Line -...
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
<%@ 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" %>
-
 
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(
-
 
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
<%
-
 
96
    //Falta Chamar Serviço
-
 
97
 
-
 
98
 
-
 
99
    String courseCode = request.getParameter("courseCode");
-
 
100
    String year = request.getParameter("year");
-
 
101
    AbstractDao.getCurrentSession().beginTransaction();
-
 
102
    CourseImpl courseImpl = DaoFactory.getCourseDaoImpl().findCourseByCode(courseCode);
-
 
103
    request.setAttribute("course",courseImpl);
-
 
104
    CourseReportDocument courseReport = null;
-
 
105
    try {
-
 
106
        courseReport = new CourseReportServices().createNewCourseReportDocument(courseCode, year);
-
 
107
    } catch (Throwable e) {
-
 
108
        System.out.println(e);
-
 
109
        e.printStackTrace();
-
 
110
    }
-
 
111
    String courseReportJson = courseReport.toJson();
-
 
112
    request.setAttribute("courseDocumentJson",courseReportJson);
-
 
113
    request.setAttribute("courseDocument",courseReport);
-
 
114
 
-
 
115
%>
-
 
116
<%--<a href="javascript:demoFromHTML()" class="button">Run Code</a>--%>
-
 
117
 
-
 
118
<div class="container-fluid">
-
 
119
 
-
 
120
<style>
-
 
121
    .separatorSection
-
 
122
    {
-
 
123
        border: 1px solid #ddd;
-
 
124
    }
-
 
125
</style>
-
 
126
 
-
 
127
 
-
 
128
<!-- Apresentacao da Unidade -->
-
 
129
 
-
 
130
<div class="panel panel-default">
-
 
131
<div class="panel-heading">
-
 
132
    Relatório Anual do curso: ${course.name}
-
 
133
</div>
-
 
134
<div class="panel-body">
-
 
135
 
-
 
136
<p><b class="label-info">Tipo de Curso:</b> <bean:message key="course.${course.degree}"/></p>
-
 
137
<p><b class="label-info">Ano Lectivo:</b> ${course.importYear}</p>
-
 
138
<p><b class="label-info">Departamento:</b> ${course.department.name}</p>
-
 
139
<p><b class="label-info">Escola:</b> ${course.department.courseSchool.name}</p>
-
 
140
 
-
 
141
 
-
 
142
 
-
 
143
 
-
 
144
<script>
-
 
145
 
-
 
146
    //Especifico da aplicacao
-
 
147
    var courseReportApp = angular.module('courseReportApp', ['ui.tree']);
-
 
148
    GLOBAL_BacoAngularAppDependencies.push('courseReportApp');
-
 
149
 
-
 
150
 
-
 
151
    courseReportApp.directive('resizable', function () {
-
 
152
        return {
-
 
153
            restrict: 'A',
-
 
154
            scope: {
-
 
155
                callback: '&onResize'
-
 
156
            },
-
 
157
            link: function postLink(scope, elem, attrs) {
-
 
158
                elem.resizable();
-
 
159
                elem.on('resize', function (evt, ui, comp) {
-
 
160
                    scope.$apply(function() {
-
 
161
                        if (scope.callback) {
-
 
162
                            scope.callback({$evt: evt, $ui: ui, $comp: comp });
-
 
163
                        }
-
 
164
                    })
-
 
165
                });
-
 
166
            }
-
 
167
        };
-
 
168
    });
-
 
169
 
-
 
170
 
-
 
171
    courseReportApp.controller('courseReportAppController', function($scope)
-
 
172
    {
-
 
173
 
-
 
174
        $scope.docAppSelector = "#courseReportApp";
-
 
175
        $scope.report = <%=courseReportJson%>
-
 
176
 
-
 
177
                $scope.resize = function(evt,ui,comp) {
-
 
178
                    //console.log (evt,ui);
-
 
179
                    comp.width = ui.size.width;
-
 
180
                    comp.height = ui.size.height;
-
 
181
                }
-
 
182
 
-
 
183
        /**
-
 
184
         * @classe class to match
-
 
185
         * @superClasses array of strings
-
 
186
         * */
-
 
187
        $scope.contains = function(obj,classe)
-
 
188
        {
-
 
189
            if(obj['@class'] && obj['@class'] == classe)
-
 
190
                return true;
-
 
191
            if(obj.allSuperClasses)
-
 
192
            {
-
 
193
                for(var i in obj.allSuperClasses)
-
 
194
                {
-
 
195
                    if(classe == obj.allSuperClasses[i])
-
 
196
                        return true;
-
 
197
                }
-
 
198
            }
-
 
199
            return false;
-
 
200
        }
-
 
201
 
-
 
202
        $scope.showSep = function(section,subSection)
-
 
203
        {
-
 
204
            var s;
-
 
205
            for(s in section.sections)
-
 
206
            {
-
 
207
                section.sections[s].active = false;
-
 
208
            }
-
 
209
            /*$(".separatorSectionNav").each(function()
-
 
210
             {
-
 
211
             angular.element($(this)).scope().section.active = false;
-
 
212
             });*/
-
 
213
            subSection.active = true;
-
 
214
        }
-
 
215
 
-
 
216
        /**
-
 
217
         * Este metodo devolve o template mais profundo na hierarquia de classes
-
 
218
         * permitindo emular o override, quanto mais especifica for a classe
-
 
219
         * e caso exista template é esse o template devolvido
-
 
220
         * procura um script com o id da classe e se nao existir
-
 
221
         * vai subindo nas super classes
-
 
222
         * @param obj
-
 
223
         * @returns {*}
-
 
224
         */
-
 
225
        $scope.class2id = function(obj)
-
 
226
        {
-
 
227
            var objClassId = obj["@class"].replaceAll(".","_");
-
 
228
            if($("script#" + objClassId).length > 0)
-
 
229
            {
-
 
230
                return objClassId;
-
 
231
            }
-
 
232
            if(obj.allSuperClasses)
-
 
233
            {
-
 
234
                var s;
-
 
235
                for(s in obj.allSuperClasses)
-
 
236
                {
-
 
237
                    var superClass = obj.allSuperClasses[s];
-
 
238
                    var superClassId = superClass.replaceAll(".","_");
-
 
239
                    if($("script#" + superClassId).length > 0)
-
 
240
                    {
-
 
241
                        return superClassId;
-
 
242
                    }
-
 
243
                }
-
 
244
            }
-
 
245
            return obj["@class"].replaceAll(".","_");
-
 
246
        }
-
 
247
 
-
 
248
        $scope.addText = function(parentCustomPane)
-
 
249
        {
-
 
250
            $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.TextComponent")
-
 
251
        }
-
 
252
 
-
 
253
        $scope.addImage = function(parentCustomPane)
-
 
254
        {
-
 
255
            $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.ImageComponent")
-
 
256
        }
-
 
257
 
-
 
258
        $scope.addSimpleDocComponent = function(parentCustomPane,classComponent)
-
 
259
        {
-
 
260
            if(!parentCustomPane.components)
-
 
261
            {
-
 
262
                parentCustomPane.components = [];
-
 
263
            }
-
 
264
            parentCustomPane.components.push(
-
 
265
                    {
-
 
266
                        "@class" : classComponent
-
 
267
                    }
-
 
268
            );
-
 
269
        }
-
 
270
        $scope.removeComponent = function(index,array)
-
 
271
        {
-
 
272
            array.splice(index,1);
-
 
273
        }
-
 
274
 
-
 
275
        $scope.callbackUploadedFiles = function(filesUploadResult,token,targetElement)
-
 
276
        {
-
 
277
            var modelObject = BacoAngularUtils.getAngularElementModel(targetElement);
-
 
278
 
-
 
279
            if(modelObject.image && modelObject.image.identifier)
-
 
280
            {
-
 
281
                widgetCallWithActionParameters(
-
 
282
                        "<%=request.getContextPath()%>/user/json/repository.do",
-
 
283
                        "replaceRepositoryFileFromTempPrivateDomain",
-
 
284
                        {
-
 
285
                            "identifier" : modelObject.image.identifier,
-
 
286
                            "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0])
-
 
287
                        },
-
 
288
                        "#courseReportApp",
-
 
289
                        function(repositoryFile4JsonView)
-
 
290
                        {
-
 
291
                            modelObject.image = repositoryFile4JsonView;
-
 
292
                            //image URL is generated on reimport just to avoid caching
-
 
293
                            modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime();
-
 
294
                            angular.element($("#courseReportApp")).scope().$apply();
-
 
295
                        },
-
 
296
                        function(){}
-
 
297
                );
-
 
298
            }
-
 
299
            else
-
 
300
            {
-
 
301
                widgetCallWithActionParameters(
-
 
302
                        "<%=request.getContextPath()%>/user/json/repository.do",
-
 
303
                        "saveRepositoryFileFromTempPrivateDomain",
-
 
304
                        {
-
 
305
                            "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0])
-
 
306
                        },
-
 
307
                        "#courseReportApp",
-
 
308
                        function(repositoryFile4JsonView)
-
 
309
                        {
-
 
310
                            modelObject.image = repositoryFile4JsonView;
-
 
311
                            modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime();
-
 
312
                            angular.element($("#courseReportApp")).scope().$apply();
-
 
313
                        },
-
 
314
                        function(){}
-
 
315
                );
-
 
316
            }
-
 
317
        }
-
 
318
 
-
 
319
        $scope.Save = function () {
-
 
320
            widgetCallWithActionParameters(
-
 
321
                "<%=request.getContextPath()%>/user/courseReport.do",
-
 
322
                "SaveCourseReportDocument",
-
 
323
                {
-
 
324
                    "courseReportDocument":BacoJS.stringifyOrdered($scope.report)
-
 
325
                },
-
 
326
                "#courseReportApp",
-
 
327
                function(json)
-
 
328
                {
-
 
329
                    alert(BacoJS.stringifyOrdered(json));
-
 
330
                },
-
 
331
                function(){}
-
 
332
            );
-
 
333
        }
-
 
334
 
-
 
335
 
-
 
336
    });
-
 
337
</script>
-
 
338
 
-
 
339
<!--TEMPLATES FOR DOCUMENT BUILDER-->
-
 
340
<jsp:include page="../utils/documentsBuilder.jsp"/>
1
<jsp:include page="../utils/reportEdit.jsp"/>
341
<jsp:include page="coursereport/templates.jsp"/>
2
<jsp:include page="coursereport/templates.jsp"/>
342
 
-
 
343
 
-
 
344
<div class="form-vertical">
-
 
345
    <div id="courseReportApp" ng-app="courseReportApp" ng-controller="courseReportAppController">
-
 
346
        <div class="web-messages"> </div>
-
 
347
        <button ng-click="Save()">Click me</button>
-
 
348
        <div ng-init="section=report;" ng-include="'pt_estgp_estgweb_utils_documentBuilder_DocumentSection'">
-
 
349
 
-
 
350
        </div>
-
 
351
 
-
 
352
        <!-- <pre class="code">{{ report | json }}</pre>-->
-
 
353
 
-
 
354
 
-
 
355
 
-
 
356
    </div><!--App-->
-
 
357
</div> <!--form-->
-
 
358
 
-
 
359
</div><!--Panel Body-->
-
 
360
 
-
 
361
</div><!--Panel-->
-
 
362
 
-
 
363
</div><!--container-fluid-->
-
 
364
 
-
 
365
<%
-
 
366
    AbstractDao.getCurrentSession().getTransaction().commit();
-
 
367
%>
-