mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-08-28 17:57:38 +00:00
(css,js) Dynamic CSS for printing calendars
Initial commit. Fixes #3768
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
CalendarController.$inject = ['$scope', '$rootScope', '$state', '$stateParams', 'sgHotkeys', 'Calendar', 'Component', 'Preferences', 'stateEventsBlocks'];
|
||||
function CalendarController($scope, $rootScope, $state, $stateParams, sgHotkeys, Calendar, Component, Preferences, stateEventsBlocks) {
|
||||
CalendarController.$inject = ['$scope', '$rootScope', '$state', '$stateParams', '$mdDialog', 'sgHotkeys', 'Calendar', 'Component', 'Preferences', 'stateEventsBlocks'];
|
||||
function CalendarController($scope, $rootScope, $state, $stateParams, $mdDialog ,sgHotkeys, Calendar, Component, Preferences, stateEventsBlocks) {
|
||||
var vm = this, deregisterCalendarsList, hotkeys = [];
|
||||
|
||||
this.$onInit = function() {
|
||||
@@ -184,11 +184,70 @@
|
||||
$state.go('calendars.view', { view: view });
|
||||
};
|
||||
|
||||
this.printView = function(centerIsClose, componentType) {
|
||||
$mdDialog.show({
|
||||
parent: angular.element(document.body),
|
||||
clickOutsideToClose: true,
|
||||
escapeToClose: true,
|
||||
templateUrl: 'UIxCalPrintDialog', // See UIxCalMainView.wox
|
||||
controller: PrintController,
|
||||
controllerAs: '$PrintDialogController',
|
||||
locals: {
|
||||
calendarView: $stateParams.view,
|
||||
visibleList: centerIsClose? undefined : componentType
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// Check if the week day should be visible/selectable
|
||||
this.isSelectableDay = function(date) {
|
||||
return _.includes(vm.selectableDays, date.getDay());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
PrintController.$inject = ['$rootScope', '$scope', '$window', '$stateParams', '$mdDialog', '$log', '$mdToast', 'Dialog', 'sgSettings', 'Preferences', 'Calendar', 'calendarView', 'visibleList'];
|
||||
function PrintController($rootScope, $scope, $window, $stateParams, $mdDialog, $log, $mdToast, Dialog, Settings, Preferences, Calendar, calendarView, visibleList) {
|
||||
var vm = this;
|
||||
var orientations = {
|
||||
day: 'portrait',
|
||||
week: 'landscape',
|
||||
month: 'landscape',
|
||||
multicolumnday: 'landscape'
|
||||
};
|
||||
|
||||
this.$onInit = function() {
|
||||
// Default values
|
||||
this.pageSize = 'letter';
|
||||
this.workingHoursOnly = true;
|
||||
this.calendarView = calendarView;
|
||||
this.orientation = orientations[this.calendarView];
|
||||
this.visibleList = visibleList;
|
||||
|
||||
angular.element(document.body).addClass(this.orientation);
|
||||
$scope.$watch(function() { return vm.pageSize; }, angular.bind(this, function(newSize, oldSize) {
|
||||
angular.element(document.body).removeClass(oldSize);
|
||||
angular.element(document.body).addClass(newSize);
|
||||
}));
|
||||
};
|
||||
|
||||
this.$onDestroy = function() {
|
||||
angular.element(document.body).removeClass(['portrait', 'landscape', 'letter', 'legal', 'a4']);
|
||||
};
|
||||
|
||||
this.print = function($event) {
|
||||
$window.print();
|
||||
$event.stopPropagation();
|
||||
return false;
|
||||
};
|
||||
|
||||
this.close = function () {
|
||||
$mdDialog.hide();
|
||||
};
|
||||
}
|
||||
|
||||
angular
|
||||
.module('SOGo.SchedulerUI')
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
(function() {
|
||||
/* jshint validthis: true */
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
* sgCalendarPrintStylesheet - Add CSS stylesheet to fix printing of calendars
|
||||
* @memberof SOGo.SchedulerUI
|
||||
* @restrict attribute
|
||||
* @param {string} sgCalendarView - the name of the calendar view
|
||||
* @param {string} sgPageSize - the desired page size (letter, legal, etc)
|
||||
* @param {string} sgOrientation - the page orientation
|
||||
* @param {boolean} sgWorkingHoursOnly - hide off-working hours
|
||||
* @example:
|
||||
|
||||
<sg-calendar-print-stylesheet
|
||||
sg-calendar-view="calendarView"
|
||||
sg-page-size="pageSize"
|
||||
sg-orientation="orientation"
|
||||
sg-working-hours-only="workingHoursOnly" />
|
||||
*/
|
||||
function sgCalendarPrintStylesheet() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
calendarView: '<sgCalendarView',
|
||||
pageSize: '<sgPageSize',
|
||||
orientation: '<sgOrientation',
|
||||
workingHoursOnly: '<sgWorkingHoursOnly',
|
||||
},
|
||||
replace: true,
|
||||
bindToController: true,
|
||||
controller: sgPrintStylesheetController,
|
||||
controllerAs: '$ctrl',
|
||||
template: [
|
||||
'<style type="text/css">',
|
||||
' @page {',
|
||||
' size: {{ $ctrl.pageSize }} {{ $ctrl.orientation }};',
|
||||
' margin: 0;',
|
||||
' }',
|
||||
' @media print {',
|
||||
' body {',
|
||||
' padding: {{ $ctrl.pageMargin }};',
|
||||
' }',
|
||||
' [ui-view=calendars] .view-list {',
|
||||
' height: {{ $ctrl.viewportHeight }};',
|
||||
' overflow: hidden;',
|
||||
' }',
|
||||
' [ui-view=calendars] .calendarView {',
|
||||
' transform: translateY(-{{ $ctrl.clipTop }});', // hide non-working hours at the top
|
||||
' height: {{ $ctrl.viewHeight }};',
|
||||
' position: relative;',
|
||||
' overflow: hidden;', // hide non-working hours at the bottom
|
||||
' }',
|
||||
' [ui-view=calendars] .allDaysView {',
|
||||
' max-height: {{ $ctrl.hourHeight }}{{ $ctrl.units }} !important;', // limit size of all-day cells
|
||||
' }',
|
||||
' [ui-view=calendars] .hours .hour,',
|
||||
' [ui-view=calendars] .days .day .clickableHourCell {',
|
||||
' min-height: {{ $ctrl.hourHeight }}{{ $ctrl.units }};',
|
||||
' max-height: {{ $ctrl.hourHeight }}{{ $ctrl.units }};',
|
||||
' }',
|
||||
' {{ $ctrl.eventsPositions() }}',
|
||||
' }',
|
||||
'</style>'
|
||||
].join('\n')
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
sgPrintStylesheetController.$inject = ['$scope', 'Preferences'];
|
||||
function sgPrintStylesheetController($scope, Preferences) {
|
||||
var vm = this;
|
||||
var sizes = {
|
||||
portrait: {
|
||||
letter: [8.5, 11, 'in'],
|
||||
legal: [8.5, 14, 'in'],
|
||||
a4: [210, 297, 'mm']
|
||||
},
|
||||
landscape: {
|
||||
letter: [11, 8.5, 'in'],
|
||||
legal: [14, 8.5, 'in'],
|
||||
a4: [297, 210, 'mm']
|
||||
}
|
||||
};
|
||||
var margins = {
|
||||
letter: [0.4, 2.1],
|
||||
legal: [0.4, 2.1],
|
||||
a4: [10, 30]
|
||||
};
|
||||
|
||||
this.$onInit = function() {
|
||||
$scope.$watchGroup([function() { return vm.pageSize; }, function() { return vm.workingHoursOnly; }], angular.bind(this, function() {
|
||||
var time;
|
||||
var size = sizes[this.orientation][this.pageSize];
|
||||
this.units = size[2];
|
||||
this.pageMargin = margins[this.pageSize][0] + this.units;
|
||||
this.viewportHeight = (size[1] - 2 * margins[this.pageSize][0]).toString() + this.units;
|
||||
this.hideHoursStart = 0;
|
||||
this.hideHoursEnd = 24;
|
||||
this.totalHours = 24;
|
||||
this.clipTop = 0;
|
||||
|
||||
if (this.calendarView === 'month') {
|
||||
this.viewHeight = (size[1] - (3 * margins[this.pageSize][0])).toString() + this.units;
|
||||
}
|
||||
else {
|
||||
// Day-based views
|
||||
if (this.workingHoursOnly) {
|
||||
if (Preferences.defaults.SOGoDayEndTime) {
|
||||
time = Preferences.defaults.SOGoDayEndTime.split(':');
|
||||
this.hideHoursEnd = parseInt(time[0]);
|
||||
this.totalHours = this.hideHoursEnd;
|
||||
}
|
||||
if (Preferences.defaults.SOGoDayStartTime) {
|
||||
time = Preferences.defaults.SOGoDayStartTime.split(':');
|
||||
this.hideHoursStart = parseInt(time[0]);
|
||||
this.totalHours -= this.hideHoursStart;
|
||||
}
|
||||
}
|
||||
this.hourHeight = (size[1] - 2 * margins[this.pageSize][0] - margins[this.pageSize][1]) / this.totalHours;
|
||||
this.clipTop = (this.hourHeight * this.hideHoursStart).toString() + this.units;
|
||||
this.viewHeight = (this.hideHoursEnd * this.hourHeight).toString() + this.units;
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
this.eventsPositions = function() {
|
||||
var i = 0, j;
|
||||
var css = [];
|
||||
|
||||
if (this.calendarView === 'month') {
|
||||
css.push('[ui-view=calendars] .monthView md-grid-list { min-height: ' + this.viewHeight + '; }');
|
||||
}
|
||||
else {
|
||||
while (i <= 96) { // number of 15-minutes blocks in a day
|
||||
if (i <= (4 * this.hideHoursStart)) {
|
||||
j = (4 * this.hideHoursStart) - i;
|
||||
css.push('[ui-view=calendars] .sg-event.starts' + i +
|
||||
' .text { margin-top: ' + (this.hourHeight/4*j) + this.units + '; }');
|
||||
}
|
||||
css.push('[ui-view=calendars] .sg-event.starts' + i + ' { top: ' + (this.hourHeight/4*i) + this.units + '; }');
|
||||
css.push('[ui-view=calendars] .sg-event.lasts' + i + ' { height: ' + (this.hourHeight/4*i) + this.units + '; }');
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return css.join('\n');
|
||||
};
|
||||
}
|
||||
|
||||
angular
|
||||
.module('SOGo.SchedulerUI')
|
||||
.directive('sgCalendarPrintStylesheet', sgCalendarPrintStylesheet);
|
||||
})();
|
||||
@@ -10,6 +10,37 @@
|
||||
min-height: auto !important;
|
||||
max-height: none !important;
|
||||
overflow: visible !important;
|
||||
|
||||
&.letter {
|
||||
width: 8.5in;
|
||||
height: 11in !important;
|
||||
&.landscape {
|
||||
width: 11in;
|
||||
height: 8.5in !important;
|
||||
}
|
||||
[ui-view=listView] {
|
||||
max-width: 3in;
|
||||
}
|
||||
}
|
||||
&.legal {
|
||||
width: 8.5in;
|
||||
height: 14in !important;
|
||||
&.landscape {
|
||||
width: 14in;
|
||||
height: 8.5in !important;
|
||||
}
|
||||
}
|
||||
&.a4 {
|
||||
width: 210mm;
|
||||
height: 297mm;
|
||||
&.landscape {
|
||||
width: 297mm;
|
||||
height: 210mm;
|
||||
}
|
||||
[ui-view=listView] {
|
||||
max-width: 80mm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't print some components
|
||||
@@ -17,10 +48,13 @@
|
||||
md-sidenav,
|
||||
md-card-actions,
|
||||
md-fab-speed-dial,
|
||||
md-backdrop,
|
||||
.md-scroll-mask,
|
||||
.md-dialog-container,
|
||||
.md-open-menu-container,
|
||||
.md-chip-remove-container,
|
||||
.toolbar-main,
|
||||
.view-list,
|
||||
.view-list--close,
|
||||
.view-detail .sg-reversible.sg-flip .sg-face,
|
||||
.view-detail .sg-reversible:not(.sg-flip) .sg-back,
|
||||
.sg-no-print
|
||||
@@ -29,8 +63,6 @@
|
||||
}
|
||||
|
||||
// Horizontal flex layout must be ignored for element that could spawn multiple pages
|
||||
.view[layout="row"],
|
||||
section > div[layout="row"],
|
||||
.msg-body > [layout="row"],
|
||||
.mailer_mailcontent[layout="row"] {
|
||||
display: block !important;
|
||||
@@ -50,7 +82,6 @@
|
||||
md-card,
|
||||
md-card-content,
|
||||
md-card-content pre,
|
||||
.view-detail,
|
||||
.view-detail .sg-reversible,
|
||||
.view-detail .sg-reversible:not(.sg-flip) .sg-face,
|
||||
.view-detail .sg-reversible.sg-flip .sg-back {
|
||||
@@ -59,7 +90,6 @@
|
||||
min-height: auto !important;
|
||||
overflow: visible !important;
|
||||
position: relative !important;
|
||||
min-width: 100%; // compensate for flex display
|
||||
}
|
||||
|
||||
// Remove shadow from Cards
|
||||
|
||||
@@ -798,3 +798,127 @@ $quarter_height: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print page preview
|
||||
*/
|
||||
$preview-size: 200px;
|
||||
$preview-letter-ratio: 8.5 / 11;
|
||||
$preview-legal-ratio: 8.5 / 14;
|
||||
$preview-a4-ratio: 210 / 297;
|
||||
|
||||
.sg-print-preview {
|
||||
.letter.portrait & {
|
||||
height: $preview-size;
|
||||
width: $preview-letter-ratio * $preview-size;
|
||||
}
|
||||
.letter.landscape & {
|
||||
height: $preview-letter-ratio * $preview-size;
|
||||
width: $preview-size;
|
||||
}
|
||||
.legal.portrait & {
|
||||
height: $preview-size;
|
||||
width: $preview-legal-ratio * $preview-size;
|
||||
}
|
||||
.legal.landscape & {
|
||||
height: $preview-legal-ratio * $preview-size;
|
||||
width: $preview-size;
|
||||
}
|
||||
.a4.portrait & {
|
||||
height: $preview-size;
|
||||
width: $preview-a4-ratio * $preview-size;
|
||||
}
|
||||
.a4.landscape & {
|
||||
height: $preview-a4-ratio * $preview-size;
|
||||
width: $preview-size;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print media
|
||||
*/
|
||||
@media print {
|
||||
[ui-view=calendars] {
|
||||
|
||||
.allDaysView,
|
||||
md-toolbar.daysView .days:not([sg-calendar-scroll-view$="allday"]),
|
||||
md-toolbar.monthView > div {
|
||||
overflow-y: hidden; // hide scrollbar
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[ui-view=calendars] {
|
||||
|
||||
/**
|
||||
* Events/tasks center list
|
||||
*/
|
||||
md-tab-data,
|
||||
md-tab-item:not(.md-active),
|
||||
md-ink-bar,
|
||||
// md-divider,
|
||||
// .md-subheader,
|
||||
md-list-item .md-secondary-container {
|
||||
display: none;
|
||||
}
|
||||
|
||||
[ui-view=listView]:not(.view-list--close) {
|
||||
// border-right: 1px solid $colorGrayLighter;
|
||||
padding-right: 2 * $layout-gutter-width;
|
||||
|
||||
.sg-tile-content .sg-md-subhead {
|
||||
font-size: $caption-font-size-base;
|
||||
}
|
||||
|
||||
md-list-item,
|
||||
md-list-item::before,
|
||||
md-list-item .md-list-item-inner::before {
|
||||
min-height: 6 * $baseline-grid;
|
||||
}
|
||||
}
|
||||
|
||||
.md-tab {
|
||||
font-size: $title-font-size-base;
|
||||
padding: $layout-gutter-width;
|
||||
color: $colorGrayDark;
|
||||
}
|
||||
|
||||
.sg-tile-icons {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calendar view
|
||||
*/
|
||||
.view-detail md-card {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.days .day {
|
||||
border-left-color: $colorGrayLight;
|
||||
}
|
||||
|
||||
.allDaysView,
|
||||
.allDaysView--sidenav,
|
||||
.hours .hour,
|
||||
.days .day .clickableHourCell {
|
||||
border-bottom-color: $colorGrayLight;
|
||||
}
|
||||
|
||||
.sg-event {
|
||||
&.sg-event--transparent:before {
|
||||
content: none;
|
||||
}
|
||||
&[class*=bg-folder],
|
||||
&[class*=bg-folder] md-icon {
|
||||
background: white !important;
|
||||
color: black !important;
|
||||
}
|
||||
&[class*=contrast-bdr-folder] {
|
||||
border-color: black !important;
|
||||
border-width: 1px !important;
|
||||
border-style: solid !important;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user