Last active
June 20, 2017 07:59
-
-
Save esimonetti/6f37a44e0d39158946d2aa9f523844cb to your computer and use it in GitHub Desktop.
This is an example of how to have templates on sidecar modules, printable on either portrait or landscape based on user's choice. It excludes Reports, Quotes and Project as they do have a custom pdf generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Enrico Simonetti | |
// enricosimonetti.com | |
// | |
// 2017-06-20 on Sugar 7.9.0.0 | |
// filename: custom/Extension/application/Ext/Language/en_us.pdf_print.php | |
// | |
// Allow for landscape pdf template printing for all modules aside Quotes, Reports and Projects | |
$app_strings['LBL_PDF_LANDSCAPE'] = 'Landscape'; | |
$app_strings['LBL_PDF_PORTRAIT'] = 'Portrait'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enrico Simonetti | |
// enricosimonetti.com | |
// | |
// 2017-06-20 on Sugar 7.9.0.0 | |
// filename: custom/clients/base/fields/pdfaction/pdfaction.js | |
// | |
// Allow for landscape pdf template printing for all modules aside Quotes, Reports and Projects | |
({ | |
extendsFrom: 'PdfactionField', | |
isCustomPDFView: false, | |
disabledModules: ['Reports', 'Quotes', 'Project'], | |
initialize: function(options) { | |
this._super('initialize', [options]); | |
if($.inArray(this.module, this.disabledModules) == -1) { | |
this.isCustomPDFView = true; | |
} | |
}, | |
_buildDownloadLink: function(templateId, isLandscape) { | |
var urlParams = $.param({ | |
'action': 'sugarpdf', | |
'module': this.module, | |
'sugarpdf': 'pdfmanager', | |
'record': this.model.id, | |
'pdf_template_id': templateId, | |
'landscape': isLandscape | |
}); | |
return '?' + urlParams; | |
}, | |
_buildEmailLink: function(templateId, isLandscape) { | |
return '#' + app.bwc.buildRoute(this.module, null, 'sugarpdf', { | |
'sugarpdf': 'pdfmanager', | |
'record': this.model.id, | |
'pdf_template_id': templateId, | |
'to_email': '1', | |
'landscape': isLandscape | |
}); | |
}, | |
emailClicked: function(evt) { | |
var templateId = this.$(evt.currentTarget).data('id'); | |
var isLandscape = this.$(evt.currentTarget).data('landscape'); | |
app.router.navigate(this._buildEmailLink(templateId, isLandscape), { | |
trigger: true | |
}); | |
}, | |
downloadClicked: function(evt) { | |
var templateId = this.$(evt.currentTarget).data('id'); | |
var isLandscape = this.$(evt.currentTarget).data('landscape'); | |
app.bwc.login(null, _.bind(function() { | |
this._triggerDownload(this._buildDownloadLink(templateId, isLandscape)); | |
}, this)); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Enrico Simonetti | |
// enricosimonetti.com | |
// | |
// 2017-06-20 on Sugar 7.9.0.0 | |
// filename: custom/include/MVC/View/views/view.sugarpdf.php | |
// | |
// Allow for landscape pdf template printing for all modules aside Quotes, Reports and Projects | |
class CustomViewSugarpdf extends ViewSugarpdf | |
{ | |
public function preDisplay() | |
{ | |
parent::preDisplay(); | |
if(isset($_REQUEST['landscape']) && $_REQUEST['landscape'] == 1) { | |
$this->sugarpdfBean->setPageFormat(PDF_PAGE_FORMAT, 'L'); | |
} else { | |
$this->sugarpdfBean->setPageFormat(PDF_PAGE_FORMAT, 'P'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment