Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kobedinho/9cd4059cd358be2fa8e31e1efda8089a to your computer and use it in GitHub Desktop.
Save Kobedinho/9cd4059cd358be2fa8e31e1efda8089a to your computer and use it in GitHub Desktop.
Custom button to download a PDF
// file: custom/modules/<module>/clients/base/views/supanel-list/supanel-list.php
<?php
$viewdefs['Calls']['base']['view']['subpanel-list'] = array(
'template' => 'flex-list',
'favorite' => true,
'rowactions' => array(
'actions' => array(
array(
'type' => 'rowaction',
'css_class' => 'btn',
'tooltip' => 'LBL_PREVIEW',
'event' => 'list:preview:fire',
'icon' => 'fa-eye',
'acl_action' => 'view',
),
array(
'type' => 'rowaction',
'name' => 'edit_button',
'icon' => 'fa-pencil',
'label' => 'LBL_EDIT_BUTTON',
'event' => 'list:editrow:fire',
'acl_action' => 'edit',
),
array(
'type' => 'unlink-action',
'icon' => 'fa-chain-broken',
'label' => 'LBL_UNLINK_BUTTON',
),
// custom option
array(
'type' => 'rowaction',
'icon' => 'fa-eye',
'event' => 'list:pdfbtn:fire',
'label' => 'LBL_PDF_BUTTON',
),
),
),
'last_state' => array(
'id' => 'subpanel-list',
),
);
// file: custom/Extension/modules/<module>/Ext/Language/en_us.customPdfButton.lang.php
<?php
$mod_strings['LBL_PDF_BUTTON'] = 'PDF';
// file: custom/modules/<module>/clients/base/views/supanel-list/supanel-list.js
({
extendsFrom: 'SubpanelListView',
// adding the listener to custom button event
contextEvents: {
"list:editall:fire": "toggleEdit",
"list:editrow:fire": "editClicked",
"list:unlinkrow:fire": "warnUnlink",
"list:pdfbtn:fire": "downloadPdf"
},
/**
* Handle click on custom button
*/
downloadPdf: function(model) {
// TO DO
console.log('Helo!!!');
},
})
@Kobedinho
Copy link
Author

I suggest to use the function: app.api.fileDownload.
Function definition:
/**
* Given a url, attempts to download a file.
*
* @param {string} url url to call
* @param {Object} [callbacks] Callback object
* @param {Object} [options] Options object
* - iframe: jquery element upon which to attach the iframe for download
* if not specified we must fall back to window.location.href
* @memberof Api
* @instance
*/
fileDownload: function(url, callbacks, options)

How to use it:
app.api.fileDownload(url, {
error: function(data) {
app.error.handleHttpError(data, {});
}
}, {
iframe: this.$el
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment