Bug 7563 - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference
Summary: Silent print slips using Firefox PlugIn jsPrintSetup and new staff client pre...
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: 3.10
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Marc Véron
QA Contact: Paul Poulain
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-20 23:50 UTC by Marc Véron
Modified: 2018-10-09 14:24 UTC (History)
9 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 7563 [ENH] - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (5.22 KB, text/plain)
2012-04-24 20:29 UTC, Marc Véron
Details
Bug 7563 [ENH] : Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (2.38 KB, text/plain)
2012-04-25 20:43 UTC, Marc Véron
Details
Bug 7563 [ENH] : Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (5.51 KB, patch)
2012-04-25 21:30 UTC, Marc Véron
Details | Diff | Splinter Review
Bug 7563 [ENH] - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (5.44 KB, patch)
2012-06-08 11:02 UTC, Marc Véron
Details | Diff | Splinter Review
Bug 7563 [ENH] - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (5.84 KB, patch)
2012-06-10 09:27 UTC, Marc Véron
Details | Diff | Splinter Review
Bug 7563 [ENH] - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (5.83 KB, patch)
2012-06-10 10:13 UTC, Chris Cormack
Details | Diff | Splinter Review
Bug 7563 [ENH] - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (6.10 KB, patch)
2012-06-10 10:32 UTC, Marc Véron
Details | Diff | Splinter Review
Bug 7563 [ENH] - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (6.15 KB, patch)
2012-06-10 10:39 UTC, Chris Cormack
Details | Diff | Splinter Review
Bug 7563 [ENH] - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (6.10 KB, patch)
2012-06-10 13:27 UTC, Chris Cormack
Details | Diff | Splinter Review
[REBASED] Bug 8272 - OPAC : date expiration format (6.16 KB, text/plain)
2012-06-22 10:11 UTC, Marc Véron
Details
[REBASED] Bug 7563 [ENH] - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (5.51 KB, patch)
2012-06-22 10:37 UTC, Marc Véron
Details | Diff | Splinter Review
[REBASED] Bug 7563 [ENH] - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (5.83 KB, patch)
2012-06-29 07:59 UTC, Marc Véron
Details | Diff | Splinter Review
[REBASED] Bug 7563 - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference (4.81 KB, patch)
2012-06-29 19:34 UTC, Marc Véron
Details | Diff | Splinter Review
Settings for Firefox Add-on JSPrintSetup (194.34 KB, image/jpeg)
2012-07-26 16:36 UTC, Marc Véron
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Véron 2012-02-20 23:50:29 UTC
This is a proposition to implement silent printing for slips. 

In opposition to the solution with an additional Firefox (Portable) installation (see: http://wiki.koha-community.org/wiki/Using_Portable_Firefox_as_a_Koha_Client), this solution works with the standard Firefox installation (+ PlugIn jsPrintSetup) .

jsPrintSetup e.g. allows to set printer, print silent, change header and footer, see: http://jsprintsetup.mozdev.org/

The overall concept is to have a new staff client preference where one can enter the necessary JavaScript. 

If this preference is empty, Koha falls back to te default behaviour.

I did a proof of concept with the following steps: 

--Step 1 --------------------------
Add somewhere to staff_client.pref, 
e.g. near intranetstylesheet:
----------------------------------
-
	- "Use the following JavaScript for printing slips. Define at least function printThenClose(). For use e.g. with Firefox PlugIn jsPrintSetup, see http://jsprintsetup.mozdev.org/:"
	- pref: intranetslipprinterjs
	  type: textarea
	  class: code		
----------------------------------
(Suppose this will be pootleized to have translations?)


--Step 2---------------------------
Add somewhere to moremember.pl:
----------------------------------
    $template->param( intranetslipprinterjs => C4::Context->preference('intranetslipprinterjs' ) );
----------------------------------

--Step 3----------------------------------------------
Replace hard coded JavaScript function printThenClose() 
in moremember-print.tt and moremember-receipt.tt with:
------------------------------------------------------
<script language="javascript">
[% IF ( intranetslipprinterjs ) %]
    [% intranetslipprinterjs %]
[% ELSE %] 
    function printThenClose() {
        window.print();
        window.close();
    }
[% END %] 
</script>	

--Step 4----------------------------------------------------------------------
Login to Koha, go to Home › Administration › System Preferences (Staff Client) 
and edit the new field intranetslipprinterjs to print silent, set printer etc.
------------------------------------------------------------------------------
function printThenClose() {
 try
  {
        //Try to print using jsPrintSetup Plug-In in Firefox
        //If it is not installed fall back to default prnting
        jsPrintSetup.clearSilentPrint();   
        jsPrintSetup.setOption('printSilent', 1);
		
	//Choose printer using one or more of the following functions
	//jsPrintSetup.getPrintersList...
	//jsPrintSetup.setPrinter...

	//Set Header and footer...
        jsPrintSetup.setOption('headerStrLeft', '');
        jsPrintSetup.setOption('headerStrCenter', '');
        jsPrintSetup.setOption('headerStrRight', '');
        jsPrintSetup.setOption('footerStrLeft', '');
        jsPrintSetup.setOption('footerStrCenter', '');
        jsPrintSetup.setOption('footerStrRight', '');   
		
        jsPrintSetup.print();     
        window.close();
  }
catch(err)
  {   
        //Default printing if jsPrint-setup is not available
        window.print();
        window.close();
  }
} 

--Step 5---------------------------------------------
...and install jsPrintSetup PlugIn in Firefox...
-----------------------------------------------
From now on, slips will print silently with Firefox and will show default behaviour
if jsPrintSetup is not installed or if you make use of an other browser. 
All other printing will behave like before.
Comment 1 Marc Véron 2012-04-24 20:29:13 UTC Comment hidden (obsolete)
Comment 2 Marc Véron 2012-04-25 09:34:08 UTC
Please do not use first patch (mistaked with files). New patch will follow.
Marc
Comment 3 Katrin Fischer 2012-04-25 10:06:03 UTC
Hi Marc,
you can obsolete the patch, so that noone uses it. It will still be accesssible.
Details > edit details (behind bug title) > obsolete checkbox
Comment 4 Marc Véron 2012-04-25 20:43:31 UTC Comment hidden (obsolete)
Comment 5 Marc Véron 2012-04-25 21:30:12 UTC Comment hidden (obsolete)
Comment 6 Marc Véron 2012-06-08 11:02:24 UTC Comment hidden (obsolete)
Comment 7 Marc Véron 2012-06-08 11:04:05 UTC
Did not longer apply. Remade patch, would be nice to get a signoff.
Comment 8 Marc Véron 2012-06-10 09:27:04 UTC Comment hidden (obsolete)
Comment 9 Marc Véron 2012-06-10 09:31:08 UTC
Did not longer apply, redone patch.

"Signed off by " in last comment by mistake.
Comment 10 Chris Cormack 2012-06-10 10:13:48 UTC Comment hidden (obsolete)
Comment 11 Marc Véron 2012-06-10 10:32:04 UTC Comment hidden (obsolete)
Comment 12 Chris Cormack 2012-06-10 10:39:48 UTC Comment hidden (obsolete)
Comment 13 Paul Poulain 2012-06-10 13:04:03 UTC
QA comment:
I think this change was not really wanted:

-    SetVersion($DBversion);
-}

as it result in updatedatabase not compiling:
Missing right curly or square bracket at installer/data/mysql/updatedatabase.pl line 5434, at end of line
syntax error at installer/data/mysql/updatedatabase.pl line 5434, at EOF
installer/data/mysql/updatedatabase.pl had compilation errors.
Comment 14 Chris Cormack 2012-06-10 13:24:07 UTC
Fixed, was a bad merge conflict fix
Comment 15 Chris Cormack 2012-06-10 13:27:01 UTC Comment hidden (obsolete)
Comment 16 Paul Poulain 2012-06-11 15:24:24 UTC
QA Comment: small new feature, introduced nicely through a systempreference, in a nice and extensible way I think.

It would be worth to add it also on other places where we do a window.print() for consistency. grep -R "window.print()" * shows that we print in the following pages:
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detailprint.tt:    	window.print();
koha-tmpl/intranet-tmpl/prog/en/modules/members/printinvoice.tt:        window.print();
koha-tmpl/intranet-tmpl/prog/en/modules/members/printfeercpt.tt:        window.print();
koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-receipt.tt:        window.print();
koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-print.tt:        window.print();
koha-tmpl/intranet-tmpl/prog/en/modules/labels/spinelabel-print.tt:			<body id="labels_spinelabel-print" class="tools labels" onLoad="window.print()">
koha-tmpl/intranet-tmpl/prog/en/modules/labels/spinelabel-print.tt:<button onclick="window.print()">Print this label</button>
koha-tmpl/intranet-tmpl/prog/en/modules/circ/transfer-slip.tt:window.print();
koha-tmpl/intranet-tmpl/prog/en/modules/circ/printslip.tt:window.print();
koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview-slip.tt:   <a class="button" href="javascript:window.print();self.close()">Print</a> &nbsp; <a class="button" href="javascript:self.close()">Close</a>
koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt:<p class="noprint"><a href="#" onclick="window.print(); return false;">Print</a> &nbsp; <a href="#" class="close">Close</a></p>
koha-tmpl/intranet-tmpl/prog/en/xslt/oilsMARC21slim2HTML.xsl:<div><button onclick='window.print();'>Print Page</button></div>

I hesitate failing QA because of this non consistent behaviour, I won't mark it passed QA nor failed QA, to get another QA team opinion.
Comment 17 Jonathan Druart 2012-06-12 09:40:13 UTC
Paul, I agree with you, this feature must be used for all occurrences of "window.print". But it is not blocking.
I think this patch could be pushed though a followup is required asap.
I let you make the decision ;-)
Comment 18 Marc Véron 2012-06-13 09:21:42 UTC
Paul and Jonathan,

Thank you for your comments. When I introduced this feature, I was aware that it could be used at other places as well. This version is just for the use case where a lot of printing occurs, and it was made by advice of the librarians in our group who often work at the front desk and who told me that not having this feature could be a killer argument against Koha.

I really would appreciate if you could push it, and I will be happy to deliver follow ups for the other use cases as well.

Thanks again
Marc
Comment 19 Marc Véron 2012-06-22 10:11:04 UTC Comment hidden (obsolete)
Comment 20 Marc Véron 2012-06-22 10:20:43 UTC
Comment on attachment 10427 [details]
[REBASED] Bug 8272 - OPAC : date expiration format

Something went wrong with teh attachment...
Comment 21 Marc Véron 2012-06-22 10:21:33 UTC
Comment on attachment 10104 [details] [review]
Bug 7563 [ENH] - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference

REstoring previous attachment...
Comment 22 Marc Véron 2012-06-22 10:37:11 UTC Comment hidden (obsolete)
Comment 23 Marc Véron 2012-06-29 07:59:26 UTC Comment hidden (obsolete)
Comment 24 Marc Véron 2012-06-29 19:34:36 UTC
Created attachment 10570 [details] [review]
[REBASED] Bug 7563 - Silent print slips using Firefox PlugIn jsPrintSetup and new staff client preference

...to version 3.09.00.021
Comment 25 Paul Poulain 2012-07-06 16:22:50 UTC
QA comment, my concern has been answered in comment #18
> Paul and Jonathan,
> 
> Thank you for your comments. When I introduced this feature, I was aware
> that it could be used at other places as well. This version is just for the
> use case where a lot of printing occurs, and it was made by advice of the
> librarians in our group who often work at the front desk and who told me
> that not having this feature could be a killer argument against Koha.
> 
> I really would appreciate if you could push it, and I will be happy to
> deliver follow ups for the other use cases as well.


Passed QA then
Comment 26 Marc Véron 2012-07-08 05:09:42 UTC
Thanks for QA-ing, Paul. 

I will work on the follow-ups you suggested after my vacation.

Marc
Comment 27 Nicole C. Engard 2012-07-26 14:32:17 UTC
I'm trying to document this and am having trouble.  The preference says "Define at least function printThenClose()." which makes me think that this preference must have that function in there for Koha to work.  We might need to make it clearer.


Can someone write  a short description of this preference in librarianese (aka not developer talk) so that I can edit it and put it in the manual?

Nicole
Comment 28 Nicole C. Engard 2012-07-26 14:40:51 UTC
via IRC:


[10:34]  <oleonard> nengard it looks like there's two basic steps: Install the jsPrintSetup addon, and populate the pref
[10:35]  <oleonard> That first comment gives you an example for what to populate the pref with in Step 4
[10:35]  <nengard> THANK YOU
[10:35]  <nengard> :)
[10:35]  <nengard> I was missing the whole install the add on part
[10:35]  <nengard> we should update the description on that preference to make it clearer
[10:35]  <oleonard> Hmmm... not sure about the "Choose printer using one or more of the following functions" step
Comment 29 Owen Leonard 2012-07-26 14:59:19 UTC
Yeah, this part is cryptic:

  //Choose printer using one or more of the following functions
  //jsPrintSetup.getPrintersList...
  //jsPrintSetup.setPrinter...

Is this something I must configure in order for this feature to work? 

I installed the Firefox addon (https://addons.mozilla.org/en-US/firefox/addon/js-print-setup/) and populated the system preference with the JS code exactly as it appears in Step four of comment 0. Then I went to a patron record and chose "Print quick slip." A new tab appeared for a split second and disappeared, but no print job started.
Comment 30 Marc Véron 2012-07-26 16:36:31 UTC
Created attachment 11149 [details]
Settings for Firefox Add-on JSPrintSetup

Screenshot with settings to make work Firefox add-on jsprintsetup with a specific web site.

For security reasons, the website must be in a list of allowed sites.

The pre-installed JavaScript in the system preference should then work with the default printer.

To create more sophisticated solutions you find the function reference of jsprintsetup at:
http://jsprintsetup.mozdev.org/reference.html

I will set up a Wiki page for this as soon as possible.

Marc
Comment 31 Owen Leonard 2012-07-26 16:41:27 UTC
(In reply to comment #30)
> The pre-installed JavaScript in the system preference should then work 
> with the default printer.

By this do mean that the getPrintersList and setPrinter settings are not required?
Comment 32 Marc Véron 2012-07-26 16:54:47 UTC
Regarding:
//Choose printer using one or more of the following functions
//jsPrintSetup.getPrintersList...
//jsPrintSetup.setPrinter...

Here I wanted to indicate where a more sophisticated solution can be implemented. The lines are commented out (//) and ar ignored by the JavaScript. You can savely remove them.

The function jsPrintSetup.getPrintersList retuns a list of installed printers. One could then check if e.g. a printer with the name "Slipprinter" is available and if yes print on this printer using jsPrintSetup.setPrinter('Slipprinter), otherwise print on the default printer.
For full reference see:
http://jsprintsetup.mozdev.org/reference.html
Comment 33 Marc Véron 2012-07-26 19:29:15 UTC
Please refer to the following wiki page for setup and usage instructions:
http://wiki.koha-community.org/wiki/Setting_up_slip_printer_to_print_silently
Comment 34 Marc Véron 2017-04-09 08:28:02 UTC
(In reply to Marc Véron from comment #33)
> Please refer to the following wiki page for setup and usage instructions:
> http://wiki.koha-community.org/wiki/Setting_up_slip_printer_to_print_silently

For the records: Wiki page updated after testing for Koha 16.11 an Firefox 52.02
with new example JavaScript:

-----------------------------
$( window ).load(function() {
 try
 {
    //Try to print using jsPrintSetup Plug-In in Firefox
    //If it is not installed fall back to default printing
    jsPrintSetup.clearSilentPrint();   
    jsPrintSetup.setOption('printSilent', 1);
 
    //Choose printer using one or more of the following functions
    //jsPrintSetup.getPrintersList...
    jsPrintSetup.setPrinter("PUT HERE YOUR PRINTER NAME");
 
    //Set Header and footer...
    jsPrintSetup.setOption('headerStrLeft', '');
    jsPrintSetup.setOption('headerStrCenter', '');
    jsPrintSetup.setOption('headerStrRight', '');
    jsPrintSetup.setOption('footerStrLeft', '');
    jsPrintSetup.setOption('footerStrCenter', '');
    jsPrintSetup.setOption('footerStrRight', '');
 
    jsPrintSetup.print();     
    window.close();
 }
 catch(err)
 {   
    //Default printing if jsPrintsetup is not available
    window.print();
    window.close();
 }
});
-----------------------------