Subversion Repositories bacoAlunos

Rev

Rev 1928 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1928 grupo2 1
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
2
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
3
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
4
<%@ taglib uri="/WEB-INF/tlds/jomm.tld" prefix="jomm" %>
5
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
6
<%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested" %>
7
<%@ taglib uri="/WEB-INF/tlds/baco.tld" prefix="baco" %>
8
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
9
 
10
<%-- http://localhost:8080/baco/user/editCourseReport.do?courseCode=44&year=201617 --%>
11
 
12
<link rel="stylesheet" href="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.css">
13
<script src="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.min.js"></script>
14
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/flora-commons/flora.resizable.css">
15
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>-->
16
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.debug.js"></script>
1934 grupo2 17
 
18
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
19
<script src='http://cdnjs.cloudflare.com/ajax/libs/textAngular/1.5.0/textAngular-rangy.min.js'></script>
20
<script src='http://cdnjs.cloudflare.com/ajax/libs/textAngular/1.5.0/textAngular-sanitize.min.js'></script>
21
<script src='http://cdnjs.cloudflare.com/ajax/libs/textAngular/1.5.0/textAngular.min.js'></script>
22
 
23
 
1928 grupo2 24
<script>
25
    function demoFromHTML() {
26
        var pdf = new jsPDF('p', 'pt', 'letter');
27
        // source can be HTML-formatted string, or a reference
28
        // to an actual DOM element from which the text will be scraped.
29
        source = $('#courseReportApp')[0];
30
 
31
        // we support special element handlers. Register them with jQuery-style
32
        // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
33
        // There is no support for any other type of selectors
34
        // (class, of compound) at this time.
35
        specialElementHandlers = {
36
            // element with id of "bypass" - jQuery style selector
37
            '#bypassme': function (element, renderer) {
38
                // true = "handled elsewhere, bypass text extraction"
39
                return true
40
            }
41
        };
42
        margins = {
43
            top: 80,
44
            bottom: 60,
45
            left: 40,
46
            width: 522
47
        };
48
        // all coords and widths are in jsPDF instance's declared units
49
        // 'inches' in this case
50
        pdf.fromHTML(
51
            source, // HTML string or DOM elem ref.
52
            margins.left, // x coord
53
            margins.top, { // y coord
54
                'width': margins.width, // max width of content on PDF
55
                'elementHandlers': specialElementHandlers
56
            },
57
 
58
            function (dispose) {
59
                // dispose: object with X, Y of the last line add to the PDF
60
                //          this allow the insertion of new lines after html
61
                var pdfDocument =  pdf.save('Test.pdf');
62
                /*var pdfDocument = pdf.output();
63
 
64
                var boundary = '---------------------------';
65
                boundary += Math.floor(Math.random()*32768);
66
                boundary += Math.floor(Math.random()*32768);
67
                boundary += Math.floor(Math.random()*32768);
68
 
69
                var body = '';
70
                body += '--' + boundary + '\r\n' +
71
                    'Content-Disposition: form-data; name="filesInputId-UPLOAD[]"; filename="20170530_210340.pdf"' + '\r\n';
72
                body += 'Content-Type: application/pdf';
73
                body += '\r\n\r\n';
74
                body += pdfDocument;
75
                body += '\r\n'
76
                body += '--' + boundary + '--';
77
 
78
 
79
 
80
                $.ajax({
81
                    type: "POST",
82
                    cache: false,
83
                    url: "<%=request.getContextPath()%>/filesUpload",
84
                    data: body ,
85
                    processData: false,
86
                    contentType : 'multipart/form-data; boundary=' + boundary,
87
                    success: function (data) {
88
                        alert('success');
89
                        return false;
90
                    }
91
                });*/
92
            }, margins
93
        );
94
    }
95
</script>
96
 
97
<script>ping()</script>
98
 
99
<jsp:useBean id="courseReportJson" type="java.lang.String" scope="request"/>
100
<jsp:useBean id="course" type="pt.estgp.estgweb.domain.CourseImpl" scope="request"/>
101
 
102
<%--<a href="javascript:demoFromHTML()" class="button">Run Code</a>--%>
103
 
104
<div class="container-fluid">
105
 
106
    <style>
107
        .separatorSection
108
        {
109
            border: 1px solid #ddd;
110
        }
111
    </style>
112
 
113
 
114
    <!-- Apresentacao da Unidade -->
115
 
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">
121
 
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>
126
 
127
 
128
 
129
 
130
            <script>
131
 
132
                //Especifico da aplicacao
1934 grupo2 133
                var courseReportApp = angular.module('courseReportApp', ['textAngular', 'ngSanitize']);
1928 grupo2 134
                GLOBAL_BacoAngularAppDependencies.push('courseReportApp');
135
 
136
 
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
                            });
152
                        }
153
                    };
154
                });
155
 
156
 
157
                courseReportApp.controller('courseReportAppController', function($scope)
158
                {
159
 
160
                    $scope.docAppSelector = "#courseReportApp";
161
                    $scope.report = ${courseReportJson}
162
 
1934 grupo2 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
                    }
1928 grupo2 168
 
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
                    }
187
 
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
                    }
201
 
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)
212
                    {
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(".","_");
232
                    }
233
 
234
                    $scope.addText = function(parentCustomPane)
235
                    {
236
                        $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.TextComponent")
237
                    }
238
 
239
                    $scope.addImage = function(parentCustomPane)
240
                    {
241
                        $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.ImageComponent")
242
                    }
243
 
244
                    $scope.addSimpleDocComponent = function(parentCustomPane,classComponent)
245
                    {
246
                        if(!parentCustomPane.components)
247
                        {
248
                            parentCustomPane.components = [];
249
                        }
250
                        parentCustomPane.components.push(
251
                            {
252
                                "@class" : classComponent
253
                            }
254
                        );
255
                    }
256
                    $scope.removeComponent = function(index,array)
257
                    {
258
                        array.splice(index,1);
259
                    }
260
 
261
                    $scope.callbackUploadedFiles = function(filesUploadResult,token,targetElement)
262
                    {
263
                        var modelObject = BacoAngularUtils.getAngularElementModel(targetElement);
264
 
265
                        if(modelObject.image && modelObject.image.identifier)
266
                        {
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
286
                        {
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
                    }
304
 
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
                            {
1934 grupo2 315
                                //alert(BacoJS.stringifyOrdered(data));
1928 grupo2 316
                            },
317
                            function(){}
318
                        );
319
                    }
320
 
321
                });
322
            </script>
323
 
324
            <!--TEMPLATES FOR DOCUMENT BUILDER-->
325
            <jsp:include page="documentsBuilder.jsp"/>
326
 
327
            <div class="form-vertical">
328
                <div id="courseReportApp" ng-app="courseReportApp" ng-controller="courseReportAppController">
329
                    <div class="web-messages"></div>
330
 
331
                    <button class="btn btn-success" ng-click="saveCourseReportDocument()">Gravar</button>
1934 grupo2 332
                    <a class="btn btn-success" href="<%=request.getContextPath()%>/user/formattedCourseReport.do?courseCode={{report.courseCode}}&year={{report.year}}">PDF</a>
1928 grupo2 333
 
334
                    <div ng-init="section=report;" ng-include="'pt_estgp_estgweb_utils_documentBuilder_DocumentSection'">
335
 
336
                    </div>
337
 
338
                    <!--<pre class="code">{{ report | json }}</pre>-->
339
 
340
 
341
                </div><!--App-->
342
            </div> <!--form-->
343
 
344
        </div><!--Panel Body-->
345
 
346
    </div><!--Panel-->
347
 
348
</div><!--container-fluid-->