this.element.dialog('close');
}
},
- _formatUrl: function(url) {
+ _formatUrl: function(url, snippetType) {
// Strip hash
url = url.split('#')[0];
// Add snippet argument to url
- if (url.search(/[&?]snippet=/) < 0) {
- url += (url.indexOf('?') < 0 ? '?' : '&') + 'snippet=json';
- } else {
- url = url.replace(/snippet=[^&]*/, 'snippet=json');
+ if (snippetType) {
+ if (url.search(/[&?]snippet=/) < 0) {
+ url += (url.indexOf('?') < 0 ? '?' : '&') + 'snippet=' + snippetType;
+ } else {
+ url = url.replace(/snippet=[^&]*/, 'snippet=' + snippetType);
+ }
}
return url;
},
var that = this;
$('a.crm-weight-arrow', that.element).click(function(e) {
if (that.options.block) that.element.block();
- $.getJSON(that._formatUrl(this.href)).done(function() {
+ $.getJSON(that._formatUrl(this.href, 'json')).done(function() {
that.refresh();
});
e.stopImmediatePropagation();
},
refresh: function() {
var that = this;
- var url = this._formatUrl(this.options.url);
+ var url = this._formatUrl(this.options.url, 'json');
if (this.options.crmForm) $('form', this.element).ajaxFormUnbind();
if (this.options.block) this.element.block();
$.getJSON(url, function(data) {
// Create new dialog
if (settings.dialog) {
settings.dialog = CRM.utils.adjustDialogDefaults(settings.dialog);
- $('<div id="' + settings.target.substring(1) + '"></div>').dialog(settings.dialog);
+ $('<div id="' + settings.target.substring(1) + '"></div>')
+ .dialog(settings.dialog)
+ .parent().find('.ui-dialog-titlebar')
+ .append($('<a class="crm-dialog-titlebar-print ui-dialog-titlebar-close" title="'+ts('Print window')+'" target="_blank" style="right:3.8em;"/>')
+ .button({icons: {primary: 'ui-icon-print'}, text: false}));
}
+ // Add handlers to new or existing dialog
if ($(settings.target).data('uiDialog')) {
$(settings.target)
.on('dialogclose', function() {
if (e.target === $(settings.target)[0] && data && !settings.dialog.title && data.title) {
$(this).dialog('option', 'title', data.title);
}
+ // Update print url
+ $(this).parent().find('a.crm-dialog-titlebar-print').attr('href', $(this).data('civiCrmSnippet')._formatUrl($(this).crmSnippet('option', 'url'), '2'));
});
}
$(settings.target).crmSnippet(settings).crmSnippet('refresh');