Subversion Repositories bacoAlunos

Rev

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