Skip to content

Instantly share code, notes, and snippets.

@frcake
Created November 12, 2018 16:01
Show Gist options
  • Save frcake/88fe5bc042f696f2c48f83751d708850 to your computer and use it in GitHub Desktop.
Save frcake/88fe5bc042f696f2c48f83751d708850 to your computer and use it in GitHub Desktop.
printit
import Ember from 'ember';
import layout from '../templates/components/print-this';
export default Ember.Component.extend({
layout,
printService: Ember.inject.service(''),
defaultPrintClass: 'content__printThis',
classNameBindings: ['defaultPrintClass'],
printSelector: null,
autoPrint: false,
options: null,
model:null,
deliveryReportDateAttribute:'',
deliveryReportValue:null,
actions: {
doPrint() {
this._print();
}
},
didInsertElement() {
if(this.get('autoPrint')) {
this._print();
}
},
_print() {
const printSelector = this.get('printSelector') || '';
this.get('printService').print(printSelector, this.get('options') || {}, this.$.bind(this));
},
});
{{yield (action "doPrint")}}
import Ember from 'ember';
export default Ember.Service.extend({
print(printSelector, options, jQuery = Ember.$) {
const environment = Ember.getOwner(this).resolveRegistration('config:environment');
const mergedOptions = this._constructPrintOptions(environment, options);
this._selectElement(printSelector, jQuery).printThis(mergedOptions);
},
_constructPrintOptions(environment = { rootURL: '/' }, userOptions = {}) {
const base = environment.rootURL || environment.baseURL;
const options = base === '/' ? { } : { base };
return Ember.merge(options, userOptions)
},
_selectElement: function(toSelect, jQuery) {
return jQuery(toSelect);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment