En uPortal 3.2
On peut travailler sans modifier de XSL uniquement au niveau javascript et jquery.
Pour se faire au niveau du (ou des skins) dans le fichier skin.xml ajouter :
| Bloc de code |
|---|
<js>javascript/print-plugins.js</js>
|
Mettre le fichier print-plugins.js dans le dossier "javascript" du skin
| Bloc de code |
|---|
/*********************************************
Ajout de la fonctionnalité d'impression
*********************************************/
(function($){
$(".up-portlet-controls").ready(function() {
var portletControls = $(".up-portlet-controls");
$('.up-portlet-controls').each(function(i){
var parentNode = $(this).parent();
var chanId = $(parentNode).attr('id').split('_')[1]
$('<a href="javascript:void(0);" title="Pour imprimer le canal" id="printPortlet_'+chanId+' "class="up-portlet-control print"><span>Imprimer</span></a>').appendTo($(this));
});
$('a[id*=printPortlet_]').each(function(i){$(this).click(function(){printPortlet(this.id.split("_")[1]);return false;});});
var printPortlet = function(id) {
var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,";
sOption+="scrollbars=yes,width=750,height=600,left=100,top=25,resizable=yes";
var iFrame = $('#portletContent_'+id).find('iframe')[0];
if(typeof(iFrame) == 'object') {
var printWindows = window.open(iFrame.src,'',sOption);
printWindows.focus();
printWindows.print();
return false;
}
var printWindows = window.open('','',sOption);
var html = '<html><head><title>Impression</title>';
$('link[rel=stylesheet]').each(function () {
html += '<link href="'+this.href+'" rel="'+this.rel+'" type="'+this.type+'"/>\n';
});
html += '</head>';
var htmlTree = '';
$('#portletContent_'+id).parents().each(function () {
if(this.tagName.toLowerCase() != "head" && this.tagName.toLowerCase() != 'html') {
var oneElement = '<'+this.tagName ;
if(this.id != 'undefined' && this.id != '') oneElement += ' id="'+this.id+'"' ;
if(this.className != 'undefined' && this.className != '') {
var className = this.className.toLowerCase();
className = className.replace(new RegExp("layout-.-columns","gi"),"layout-1-columns");
className = className.replace(new RegExp("fl-col-flex.","gi"),"fl-col-flex1");
className = className.replace(new RegExp("left","gi"),"single");
className = className.replace(new RegExp("fl-col-flex..","gi"),"fl-col-flex");
oneElement += '' ;
}
oneElement += ' >' ;
htmlTree = oneElement + '\n' + htmlTree
}
});
html += htmlTree;
html +='<div id="portletContent_' + id + '">';
//
html += $('#portletContent_'+id).clone().html();
html +='</div>';
$('#portletContent_'+id).parents().each(function () {
html += '</'+this.tagName+'>\n' ;
});
printWindows.document.write(html);
printWindows.document.close();
printWindows.focus();
printWindows.print();
return false;
};
});
})(jQuery);
|
Ce code Javascript va :
- trouver toutes les div dequi ont la class : .up-portlet-controls
- Ajouter dans celle ci un lien avec l'id "printPortlet_chanIdXXX"
- Attache la fonction printPortlet à tout les liens de type printPortlet_*
- la fonction printPortlet va ouvrir une nouvelle fenêtre
- si le canal est un iframe il ouvre carrément une fenêtr eavec l'url de l'iframe et imprime
- si c'est un canal on recupére le contenu et imprime
Antérieur à uPortal 3.2
Ajouter un lien dans les controls
Fichier : custom/uportal-war/src/main/resources/layout/theme/universality/content.xsl
...