Subversion Repositories bacoAlunos

Rev

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