Subversion Repositories bacoAlunos

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1970 grupo8 1
<%--
2
  Created by IntelliJ IDEA.
3
  User: Pedro
4
  Date: 01/02/2018
5
  Time: 18:05
6
  To change this template use File | Settings | File Templates.
7
--%>
8
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
9
 
10
 
11
<link rel="stylesheet" href="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.css">
12
<script src="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.min.js"></script>
13
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/flora-commons/flora.resizable.css">
14
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
15
<script>
16
    function demoFromHTML() {
17
        var pdf = new jsPDF('p', 'pt', 'letter');
18
        // source can be HTML-formatted string, or a reference
19
        // to an actual DOM element from which the text will be scraped.
20
        source = $('#courseReportApp')[0];
21
 
22
        // we support special element handlers. Register them with jQuery-style
23
        // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
24
        // There is no support for any other type of selectors
25
        // (class, of compound) at this time.
26
        specialElementHandlers = {
27
            // element with id of "bypass" - jQuery style selector
28
            '#bypassme': function (element, renderer) {
29
                // true = "handled elsewhere, bypass text extraction"
30
                return true
31
            }
32
        };
33
        margins = {
34
            top: 80,
35
            bottom: 60,
36
            left: 40,
37
            width: 522
38
        };
39
        // all coords and widths are in jsPDF instance's declared units
40
        // 'inches' in this case
41
        pdf.fromHTML(
42
            source, // HTML string or DOM elem ref.
43
            margins.left, // x coord
44
            margins.top, { // y coord
45
                'width': margins.width, // max width of content on PDF
46
                'elementHandlers': specialElementHandlers
47
            },
48
 
49
            function (dispose) {
50
                // dispose: object with X, Y of the last line add to the PDF
51
                //          this allow the insertion of new lines after html
52
                //var pdfDocument =  pdf.save('Test.pdf');
53
                var pdfDocument = pdf.output();
54
 
55
                var boundary = '---------------------------';
56
                boundary += Math.floor(Math.random()*32768);
57
                boundary += Math.floor(Math.random()*32768);
58
                boundary += Math.floor(Math.random()*32768);
59
 
60
                var body = '';
61
                body += '--' + boundary + '\r\n' +
62
                    'Content-Disposition: form-data; name="filesInputId-UPLOAD[]"; filename="20170530_210340.pdf"' + '\r\n';
63
                body += 'Content-Type: application/pdf';
64
                body += '\r\n\r\n';
65
                body += pdfDocument;
66
                body += '\r\n'
67
                body += '--' + boundary + '--';
68
 
69
 
70
 
71
                $.ajax({
72
                    type: "POST",
73
                    cache: false,
74
                    url: "<%=request.getContextPath()%>/filesUpload",
75
                    data: body ,
76
                    processData: false,
77
                    contentType : 'multipart/form-data; boundary=' + boundary,
78
                    success: function (data) {
79
                        alert('success');
80
                        return false;
81
                    }
82
                });
83
            }, margins
84
        );
85
    }
86
</script>
87
 
88
 
89
<%--<a href="javascript:demoFromHTML()" class="button">Run Code</a>--%>
90
 
91
<div class="container-fluid">
92
 
93
    <style>
94
        .separatorSection
95
        {
96
            border: 1px solid #ddd;
97
        }
98
    </style>
99
 
100
 
101
    <!-- Apresentacao da Unidade -->
102
 
103
    <div class="panel panel-default">
104
        <div class="panel-heading">
105
            Relatório Anual do curso: ${course.name}
106
        </div>
107
        <div class="panel-body">
108
 
109
            <p><b class="label-info">Tipo de Curso:</b> <bean:message key="course.${course.degree}"/></p>
110
            <p><b class="label-info">Ano Lectivo:</b> ${course.importYear}</p>
111
            <p><b class="label-info">Departamento:</b> ${course.department.name}</p>
112
            <p><b class="label-info">Escola:</b> ${course.department.courseSchool.name}</p>
113
 
114
 
115
 
116
 
117
            <script>
118
 
119
                //Especifico da aplicacao
120
                var courseReportApp = angular.module('courseReportApp', ['ui.tree']);
121
                GLOBAL_BacoAngularAppDependencies.push('courseReportApp');
122
 
123
 
124
                courseReportApp.directive('resizable', function () {
125
                    return {
126
                        restrict: 'A',
127
                        scope: {
128
                            callback: '&onResize'
129
                        },
130
                        link: function postLink(scope, elem, attrs) {
131
                            elem.resizable();
132
                            elem.on('resize', function (evt, ui, comp) {
133
                                scope.$apply(function() {
134
                                    if (scope.callback) {
135
                                        scope.callback({$evt: evt, $ui: ui, $comp: comp });
136
                                    }
137
                                })
138
                            });
139
                        }
140
                    };
141
                });
142
 
143
 
144
                courseReportApp.controller('courseReportAppController', function($scope)
145
                {
146
 
147
                    $scope.docAppSelector = "#courseReportApp";
148
                    $scope.report = ${courseDocumentJson};
149
 
150
                        $scope.resize = function(evt,ui,comp) {
151
                            //console.log (evt,ui);
152
                            comp.width = ui.size.width;
153
                            comp.height = ui.size.height;
154
                        }
155
 
156
                    /**
157
                     * @classe class to match
158
                     * @superClasses array of strings
159
                     * */
160
                    $scope.contains = function(obj,classe)
161
                    {
162
                        if(obj['@class'] && obj['@class'] == classe)
163
                            return true;
164
                        if(obj.allSuperClasses)
165
                        {
166
                            for(var i in obj.allSuperClasses)
167
                            {
168
                                if(classe == obj.allSuperClasses[i])
169
                                    return true;
170
                            }
171
                        }
172
                        return false;
173
                    }
174
 
175
                    $scope.showSep = function(section,subSection)
176
                    {
177
                        var s;
178
                        for(s in section.sections)
179
                        {
180
                            section.sections[s].active = false;
181
                        }
182
                        /*$(".separatorSectionNav").each(function()
183
                         {
184
                         angular.element($(this)).scope().section.active = false;
185
                         });*/
186
                        subSection.active = true;
187
                    }
188
 
189
                    /**
190
                     * Este metodo devolve o template mais profundo na hierarquia de classes
191
                     * permitindo emular o override, quanto mais especifica for a classe
192
                     * e caso exista template é esse o template devolvido
193
                     * procura um script com o id da classe e se nao existir
194
                     * vai subindo nas super classes
195
                     * @param obj
196
                     * @returns {*}
197
                     */
198
                    $scope.class2id = function(obj)
199
                    {
200
                        var objClassId = obj["@class"].replaceAll(".","_");
201
                        if($("script#" + objClassId).length > 0)
202
                        {
203
                            return objClassId;
204
                        }
205
                        if(obj.allSuperClasses)
206
                        {
207
                            var s;
208
                            for(s in obj.allSuperClasses)
209
                            {
210
                                var superClass = obj.allSuperClasses[s];
211
                                var superClassId = superClass.replaceAll(".","_");
212
                                if($("script#" + superClassId).length > 0)
213
                                {
214
                                    return superClassId;
215
                                }
216
                            }
217
                        }
218
                        return obj["@class"].replaceAll(".","_");
219
                    }
220
 
221
                    $scope.addText = function(parentCustomPane)
222
                    {
223
                        $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.TextComponent")
224
                    }
225
 
226
                    $scope.addImage = function(parentCustomPane)
227
                    {
228
                        $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.ImageComponent")
229
                    }
230
 
231
                    $scope.addSimpleDocComponent = function(parentCustomPane,classComponent)
232
                    {
233
                        if(!parentCustomPane.components)
234
                        {
235
                            parentCustomPane.components = [];
236
                        }
237
                        parentCustomPane.components.push(
238
                            {
239
                                "@class" : classComponent
240
                            }
241
                        );
242
                    }
243
                    $scope.removeComponent = function(index,array)
244
                    {
245
                        array.splice(index,1);
246
                    }
247
 
248
                    $scope.callbackUploadedFiles = function(filesUploadResult,token,targetElement)
249
                    {
250
                        var modelObject = BacoAngularUtils.getAngularElementModel(targetElement);
251
 
252
                        if(modelObject.image && modelObject.image.identifier)
253
                        {
254
                            widgetCallWithActionParameters(
255
                                "<%=request.getContextPath()%>/user/json/repository.do",
256
                                "replaceRepositoryFileFromTempPrivateDomain",
257
                                {
258
                                    "identifier" : modelObject.image.identifier,
259
                                    "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0])
260
                                },
261
                                "#courseReportApp",
262
                                function(repositoryFile4JsonView)
263
                                {
264
                                    modelObject.image = repositoryFile4JsonView;
265
                                    //image URL is generated on reimport just to avoid caching
266
                                    modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime();
267
                                    angular.element($("#courseReportApp")).scope().$apply();
268
                                },
269
                                function(){}
270
                            );
271
                        }
272
                        else
273
                        {
274
                            widgetCallWithActionParameters(
275
                                "<%=request.getContextPath()%>/user/json/repository.do",
276
                                "saveRepositoryFileFromTempPrivateDomain",
277
                                {
278
                                    "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0])
279
                                },
280
                                "#courseReportApp",
281
                                function(repositoryFile4JsonView)
282
                                {
283
                                    modelObject.image = repositoryFile4JsonView;
284
                                    modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime();
285
                                    angular.element($("#courseReportApp")).scope().$apply();
286
                                },
287
                                function(){}
288
                            );
289
                        }
290
                    }
291
 
292
 
293
 
294
 
295
                });
296
            </script>
297
 
298
            <!--TEMPLATES FOR DOCUMENT BUILDER-->
299
            <jsp:include page="../utils/documentsBuilder.jsp"/>
300
 
301
 
302
            <div class="form-vertical">
303
                <div id="courseReportApp" ng-app="courseReportApp" ng-controller="courseReportAppController">
304
 
305
                    <div ng-init="section=report;" ng-include="'pt_estgp_estgweb_utils_documentBuilder_DocumentSection'">
306
 
307
                    </div>
308
 
309
                    <!-- <pre class="code">{{ report | json }}</pre>-->
310
 
311
 
312
 
313
                </div><!--App-->
314
            </div> <!--form-->
315
 
316
        </div><!--Panel Body-->
317
 
318
    </div><!--Panel-->
319
 
320
</div><!--container-fluid-->