-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathpdf.js
117 lines (102 loc) · 4.98 KB
/
pdf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
Termination of Transfer - tool to help in returning authors rights.
Copyright (C) 2016 Creative Commons Corporation.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// PDF Generation
// (browser-side data preparation and call to server)
////////////////////////////////////////////////////////////////////////////////
var PDF = {};
PDF.url = jQuery("script[src*='/termination-of-transfer/js/pdf.js']")
.attr('src').replace(/js\/pdf\.js.*$/, '')
+ 'result-pdf.php';
PDF.appendProperty = function (details, key, value) {
var mapping = {key: key,
value: value};
details.push(mapping);
};
PDF.append203Windows = function (details) {
var notice = '';
var termination = '';
if (Values.notice_begin != undefined) {
notice += Values.notice_begin + '-' + Values.notice_end;
termination += Values.term_begin + '-' + Values.term_end
}
if (Values.p_term_begin != undefined) {
if (notice != '') {
notice += ' or ';
termination += ' or ';
}
notice += Values.p_notice_begin + '-' + Values.p_notice_end;
termination += Values.p_term_begin + '-' + Values.p_term_end;
}
PDF.appendProperty(details, '§ 203 <a href="https://rightsback.org/glossary/#notice_window" target="_blank">notice window</a>', notice);
PDF.appendProperty(details, '§ 203 <a href="https://rightsback.org/glossary/#termination_window" target="_blank">termination window</a>', termination);
};
PDF.append304Windows = function (details) {
PDF.appendProperty(details, '§ 304(c) <a href="https://rightsback.org/glossary/#notice_window" target="_blank">notice window</a> begins',
Values.notice_begin);
PDF.appendProperty(details, '§ 304(c) <a href="https://rightsback.org/glossary/#notice_window" target="_blank">notice window</a> ends',
Values.notice_end);
PDF.appendProperty(details, '§ 304(c) <a href="https://rightsback.org/glossary/#termination_window" target="_blank">termination window</a> begins',
Values.term_begin);
PDF.appendProperty(details, '§ 304(c) <a href="https://rightsback.org/glossary/#termination_window" target="_blank">termination window</a> ends',
Values.term_end);
if (Values.d_notice_begin != undefined) {
PDF.appendProperty(details, '§ 304(d) <a href="https://rightsback.org/glossary/#notice_window" target="_blank">notice window</a> begins',
Values.d_notice_begin);
PDF.appendProperty(details, '§ 304(d) <a href="https://rightsback.org/glossary/#notice_window" target="_blank">notice window</a> ends',
Values.d_notice_end);
PDF.appendProperty(details, '§ 304(d) <a href="https://rightsback.org/glossary/#termination_window" target="_blank">termination window</a> begins',
Values.d_term_begin);
PDF.appendProperty(details, '§ 304(d) <a href="https://rightsback.org/glossary/#termination_window" target="_blank">termination window</a> ends',
Values.d_term_end);
}
};
PDF.appendWindows = function (details) {
if (Rules.is203()) {
PDF.append203Windows(details);
} else if (Rules.is304()) {
PDF.append304Windows(details);
}
};
PDF.details = function () {
var details = [];
Object.getOwnPropertyNames(varsToTitles).forEach(function (key) {
if ((Values[key] != undefined)
&& (Values[key] != '')) {
PDF.appendProperty(details, varsToTitles[key], Values[key]);
}
});
PDF.appendWindows(details);
return details;
};
PDF.request = function () {
var data = {report_timestamp: Values.current_date.getTime()/1000,
flags: Values.flags.sort(), // Sorts inline & returns, so OK here
conclusion: Values.conclusion,
details: PDF.details(),
};
var totform = document.createElement("FORM");
totform.setAttribute("action", PDF.url);
totform.setAttribute("method", "post");
totform.setAttribute("enctype", "multipart/form-data");
totform.setAttribute("target", "_blank");
var data_field = document.createElement("INPUT");
data_field.setAttribute("type", "hidden");
data_field.setAttribute("name", "data");
data_field.setAttribute("value", JSON.stringify(data));
totform.appendChild(data_field);
jQuery('body').append(totform);
totform.submit();
};