f94682f9db8fac6e414731680f6a60d85f940436
[tine20] / tine20 / Calendar / js / Printer / DaysView.js
1 Tine.Calendar.Printer.DaysViewRenderer = Ext.extend(Tine.Calendar.Printer.BaseRenderer, {
2     paperHeight: 200, 
3     
4     printMode: 'sheet',
5     
6     generateBody: function(view) {
7         var mode = Ext.util.Format.capitalize(this.printMode),
8             method = 'generate' + mode + 'HTML';
9         
10         return this[method](view);
11     },
12     
13     /**
14      * Returns the HTML that will be placed into the <head> element of th print window.
15      * @param {Ext.Component} component The component to render
16      * @return {String} The HTML fragment to place inside the print window's <head> element
17      */
18     getAdditionalHeaders: function(component) {
19         var calendarCSS = Tine.clientVersion.buildType.match(/DEBUG|RELEASE/) ? 
20             '@import url(Calendar/css/Calendar-FAT.css);' : (
21             
22             '@import url(Calendar/css/daysviewpanel.css);' +
23             '@import url(Calendar/css/Calendar.css);'
24         );
25             
26         var head = 
27             '<style type="text/css" title="text/css" media="screen,print">' +
28                 '@import url(library/ExtJS/resources/css/ext-all.css);' +
29                 calendarCSS +
30             '</style>';
31         
32         return head;
33     },
34     
35     generateSheetHTML: function(view) {
36         var node = view.el.dom.cloneNode(true),
37             header = node.getElementsByClassName('cal-daysviewpanel-wholedayheader-scroller')[0],
38             scroller = node.getElementsByClassName('cal-daysviewpanel-scroller')[0];
39         
40         // resize header/scroller to fullsize
41         header.style.height = [header.firstChild.style.height, header.style.height].sort().pop();
42         scroller.style.height = view.dayEndPx - view.getTimeOffset(view.dayStart, false) + 20 + 'px';
43         scroller.style.width = null;
44         
45         return this.generateTitle(view) + node.innerHTML;
46     },
47     
48     generateGridHTML: function(view) {
49         var daysHtml = this.splitDays(view.store, view.startDate, view.numOfDays),
50             body = [];
51         
52         body.push(this.generateTitle(view));
53         
54         if (view.numOfDays === 1) {
55             body.push(String.format('<div class="cal-print-day-singleday">{0}</div>', daysHtml[0]));
56         } else if (view.numOfDays < 9) {
57             if (view.numOfDays == 7 && view.startDate.format('w') == 1) {
58                 // iso week
59                 body.push(this.generateIsoWeek(daysHtml));
60             } else {
61                 body.push(String.format('<table>{0}</table>', this.generateCalRows(daysHtml, 2)));
62             }
63         } else {
64             body.push(String.format('<table>{0}</table>', this.generateCalRows(daysHtml, 2, true)));
65         }
66         
67         return body.join("\n");
68     },
69     
70     getTitle: function(view) {
71         if (view.numOfDays == 1) {
72             return String.format(view.dayFormatString + ' {3}', view.startDate.format('l'), view.startDate.format('j'), view.startDate.format('F'), view.startDate.format('Y'));
73         } else {
74             var endDate = view.startDate.add(Date.DAY, view.numOfDays -1),
75                 startDayOfMonth = view.startDate.format('j. '),
76                 startMonth = view.startDate.format('F '),
77                 startYear = view.startDate.format('Y '),
78                 endDayOfMonth = endDate.format('j. '),
79                 endMonth = endDate.format('F '),
80                 endYear = endDate.format('Y '),
81                 week = view.numOfDays == 7 ? String.format(view.app.i18n._('Week {0} :'), view.startDate.add(Date.DAY, 1).getWeekOfYear()) + ' ' : '';
82                 
83                 if (startYear === endYear) startYear = '';
84                 if (startMonth === endMonth) startMonth = '';
85                 
86                 return week + startDayOfMonth + startMonth + startYear + ' - ' + endDayOfMonth + endMonth + endYear;
87         }
88     },
89   
90     generateIsoWeek: function(daysHtml) {
91         var height = this.paperHeight/4;
92         return ['<table>',
93             '<tr style="height: ' + height + 'mm;">',
94                 '<td class="cal-print-daycell" width="50%">', daysHtml[0], '</td>',
95                 '<td class="cal-print-daycell" width="50%">', daysHtml[3], '</td>',
96             '</tr>', 
97             '<tr style="height: ' + height + 'mm;">',
98                 '<td class="cal-print-daycell" width="50%">', daysHtml[1], '</td>',
99                 '<td class="cal-print-daycell" width="50%">', daysHtml[4], '</td>',
100             '</tr>', 
101             '<tr style="height: ' + height + 'mm;">',
102                 '<td class="cal-print-daycell" width="50%">', daysHtml[2], '</td>',
103                 '<td class="cal-print-daycell" width="50%">',
104                     '<table style="padding: 0;">',
105                         '<tr style="height: ' + height/2 + 'mm;">',
106                             '<td class="cal-print-daycell" width="100%" style="padding: 0;">', daysHtml[5], '</td>',
107                         '</tr>',
108                         '<tr style="height: ' + height/2 + 'mm;">',
109                             '<td class="cal-print-daycell" width="100%" style="padding: 0;">', daysHtml[6], '</td>',
110                         '</tr>', 
111                     '</table>',
112             '</tr>', 
113         '</table>'].join("\n");
114     }
115 });