From 5254441c14ef13af9fbd8e0c76a0b12735b0f8ea Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 12 Jun 2017 14:13:51 -0400 Subject: [PATCH] Bug 18791: Add the ability for librarians to easily copy, download or print DataTables based tables in Koha There are many tables in Koha where it would be useful for librarians to easily copy, download or print the table for various purposes. These functions are available via DataTables button plugins. Test Plan: 1) Clear your browser cache ( just in case ) 2) Apply this patch 3) Browse to boraccount.pl ( or another page using DataTabes ) 4) Note the new Excel, CSV, Copy and Print buttons 5) Test each button to ensure they work Signed-off-by: Claire Gravely Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- .../lib/jquery/plugins/buttons.colVis.min.js | 11 +-- .../lib/jquery/plugins/buttons.html5.min.js | 26 +++++++ .../lib/jquery/plugins/buttons.print.min.js | 4 ++ .../jquery/plugins/dataTables.buttons.min.js | 68 ++++++++++--------- .../lib/jquery/plugins/jszip.min.js | 15 ++++ .../prog/en/includes/columns_settings.inc | 6 +- .../prog/en/includes/datatables.inc | 3 + .../intranet-tmpl/prog/en/modules/about.tt | 3 + 8 files changed, 97 insertions(+), 39 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.html5.min.js create mode 100644 koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.print.min.js create mode 100644 koha-tmpl/intranet-tmpl/lib/jquery/plugins/jszip.min.js diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.colVis.min.js b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.colVis.min.js index f4aaff6ae6..1e59b8bd77 100644 --- a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.colVis.min.js +++ b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.colVis.min.js @@ -1,5 +1,6 @@ -(function(g){"function"===typeof define&&define.amd?define(["jquery","datatables.net","datatables.net-buttons"],function(d){return g(d,window,document)}):"object"===typeof exports?module.exports=function(d,e){d||(d=window);if(!e||!e.fn.dataTable)e=require("datatables.net")(d,e).$;e.fn.dataTable.Buttons||require("datatables.net-buttons")(d,e);return g(e,d,d.document)}:g(jQuery,window,document)})(function(g,d,e,h){d=g.fn.dataTable;g.extend(d.ext.buttons,{colvis:function(a,b){return{extend:"collection", -text:function(c){return c.i18n("buttons.colvis","Column visibility")},className:"buttons-colvis",buttons:[{extend:"columnsToggle",columns:b.columns}]}},columnsToggle:function(a,b){return a.columns(b.columns).indexes().map(function(c){return{extend:"columnToggle",columns:c}}).toArray()},columnToggle:function(a,b){return{extend:"columnVisibility",columns:b.columns}},columnsVisibility:function(a,b){return a.columns(b.columns).indexes().map(function(c){return{extend:"columnVisibility",columns:c,visibility:b.visibility}}).toArray()}, -columnVisibility:{columns:h,text:function(a,b,c){return c._columnText(a,c.columns)},className:"buttons-columnVisibility",action:function(a,b,c,f){a=b.columns(f.columns);b=a.visible();a.visible(f.visibility!==h?f.visibility:!(b.length&&b[0]))},init:function(a,b,c){var f=this,b=a.column(c.columns);a.on("column-visibility.dt"+c.namespace,function(a,b,d,e){d===c.columns&&f.active(e)}).on("column-reorder.dt"+c.namespace,function(b,d,e){1===a.columns(c.columns).count()&&("number"===typeof c.columns&&(c.columns= -e.mapping[c.columns]),b=a.column(c.columns),f.text(c._columnText(a,c.columns)),f.active(b.visible()))});this.active(b.visible())},destroy:function(a,b,c){a.off("column-visibility.dt"+c.namespace).off("column-reorder.dt"+c.namespace)},_columnText:function(a,b){var c=a.column(b).index();return a.settings()[0].aoColumns[c].sTitle.replace(/\n/g," ").replace(/<.*?>/g,"").replace(/^\s+|\s+$/g,"")}},colvisRestore:{className:"buttons-colvisRestore",text:function(a){return a.i18n("buttons.colvisRestore","Restore visibility")}, -init:function(a,b,c){c._visOriginal=a.columns().indexes().map(function(b){return a.column(b).visible()}).toArray()},action:function(a,b,c,d){b.columns().every(function(a){a=b.colReorder&&b.colReorder.transpose?b.colReorder.transpose(a,"toOriginal"):a;this.visible(d._visOriginal[a])})}},colvisGroup:{className:"buttons-colvisGroup",action:function(a,b,c,d){b.columns(d.show).visible(!0);b.columns(d.hide).visible(!1)},show:[],hide:[]}});return d.Buttons}); +(function(g){"function"===typeof define&&define.amd?define(["jquery","datatables.net","datatables.net-buttons"],function(d){return g(d,window,document)}):"object"===typeof exports?module.exports=function(d,e){d||(d=window);if(!e||!e.fn.dataTable)e=require("datatables.net")(d,e).$;e.fn.dataTable.Buttons||require("datatables.net-buttons")(d,e);return g(e,d,d.document)}:g(jQuery,window,document)})(function(g,d,e,h){d=g.fn.dataTable;g.extend(d.ext.buttons,{colvis:function(b,a){return{extend:"collection", +text:function(a){return a.i18n("buttons.colvis","Column visibility")},className:"buttons-colvis",buttons:[{extend:"columnsToggle",columns:a.columns,columnText:a.columnText}]}},columnsToggle:function(b,a){return b.columns(a.columns).indexes().map(function(b){return{extend:"columnToggle",columns:b,columnText:a.columnText}}).toArray()},columnToggle:function(b,a){return{extend:"columnVisibility",columns:a.columns,columnText:a.columnText}},columnsVisibility:function(b,a){return b.columns(a.columns).indexes().map(function(b){return{extend:"columnVisibility", +columns:b,visibility:a.visibility,columnText:a.columnText}}).toArray()},columnVisibility:{columns:h,text:function(b,a,c){return c._columnText(b,c)},className:"buttons-columnVisibility",action:function(b,a,c,f){b=a.columns(f.columns);a=b.visible();b.visible(f.visibility!==h?f.visibility:!(a.length&&a[0]))},init:function(b,a,c){var f=this;b.on("column-visibility.dt"+c.namespace,function(a,d){d.bDestroying||f.active(b.column(c.columns).visible())}).on("column-reorder.dt"+c.namespace,function(a,d,e){1=== +b.columns(c.columns).count()&&("number"===typeof c.columns&&(c.columns=e.mapping[c.columns]),a=b.column(c.columns),f.text(c._columnText(b,c)),f.active(a.visible()))});this.active(b.column(c.columns).visible())},destroy:function(b,a,c){b.off("column-visibility.dt"+c.namespace).off("column-reorder.dt"+c.namespace)},_columnText:function(b,a){var c=b.column(a.columns).index(),f=b.settings()[0].aoColumns[c].sTitle.replace(/\n/g," ").replace(/<.*?>/g,"").replace(/^\s+|\s+$/g,"");return a.columnText?a.columnText(b, +c,f):f}},colvisRestore:{className:"buttons-colvisRestore",text:function(b){return b.i18n("buttons.colvisRestore","Restore visibility")},init:function(b,a,c){c._visOriginal=b.columns().indexes().map(function(a){return b.column(a).visible()}).toArray()},action:function(b,a,c,d){a.columns().every(function(b){b=a.colReorder&&a.colReorder.transpose?a.colReorder.transpose(b,"toOriginal"):b;this.visible(d._visOriginal[b])})}},colvisGroup:{className:"buttons-colvisGroup",action:function(b,a,c,d){a.columns(d.show).visible(!0, +!1);a.columns(d.hide).visible(!1,!1);a.columns.adjust()},show:[],hide:[]}});return d.Buttons}); diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.html5.min.js b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.html5.min.js new file mode 100644 index 0000000000..9cd4cee6a7 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/buttons.html5.min.js @@ -0,0 +1,26 @@ +(function(i){"function"===typeof define&&define.amd?define(["jquery","datatables.net","datatables.net-buttons"],function(g){return i(g,window,document)}):"object"===typeof exports?module.exports=function(g,l,r,s){g||(g=window);if(!l||!l.fn.dataTable)l=require("datatables.net")(g,l).$;l.fn.dataTable.Buttons||require("datatables.net-buttons")(g,l);return i(l,g,g.document,r,s)}:i(jQuery,window,document)})(function(i,g,l,r,s,o){function z(a,c){t===o&&(t=-1===x.serializeToString(i.parseXML(A["xl/worksheets/sheet1.xml"])).indexOf("xmlns:r")); +i.each(c,function(c,b){if(i.isPlainObject(b)){var e=a.folder(c);z(e,b)}else{if(t){var e=b.childNodes[0],h,f,u=[];for(h=e.attributes.length-1;0<=h;h--){f=e.attributes[h].nodeName;var m=e.attributes[h].nodeValue;-1!==f.indexOf(":")&&(u.push({name:f,value:m}),e.removeAttribute(f))}h=0;for(f=u.length;h'+ +e),e=e.replace(/_dt_b_namespace_token_/g,":"));e=e.replace(/<([^<>]*?) xmlns=""([^<>]*?)>/g,"<$1 $2>");a.file(c,e)}})}function p(a,c,d){var b=a.createElement(c);d&&(d.attr&&i(b).attr(d.attr),d.children&&i.each(d.children,function(a,c){b.appendChild(c)}),d.text&&b.appendChild(a.createTextNode(d.text)));return b}function I(a,c){var d=a.header[c].length,b;a.footer&&a.footer[c].length>d&&(d=a.footer[c].length);for(var e=0,h=a.body.length;ed&&(d=b),401*a[1]?!0:!1};try{var x=new XMLSerializer,t}catch(P){}var A={"_rels/.rels":'', +"xl/_rels/workbook.xml.rels":'',"[Content_Types].xml":'', +"xl/workbook.xml":'', +"xl/worksheets/sheet1.xml":'',"xl/styles.xml":''}, +H=[{match:/^\-?\d+\.\d%$/,style:60,fmt:function(a){return a/100}},{match:/^\-?\d+\.?\d*%$/,style:56,fmt:function(a){return a/100}},{match:/^\-?\$[\d,]+.?\d*$/,style:57},{match:/^\-?£[\d,]+.?\d*$/,style:58},{match:/^\-?€[\d,]+.?\d*$/,style:59},{match:/^\-?\d+$/,style:65},{match:/^\-?\d+\.\d{2}$/,style:66},{match:/^\([\d,]+\)$/,style:61,fmt:function(a){return-1*a.replace(/[\(\)]/g,"")}},{match:/^\([\d,]+\.\d{2}\)$/,style:62,fmt:function(a){return-1*a.replace(/[\(\)]/g,"")}},{match:/^\-?[\d,]+$/,style:63}, +{match:/^\-?[\d,]+\.\d{2}$/,style:64}];n.ext.buttons.copyHtml5={className:"buttons-copy buttons-html5",text:function(a){return a.i18n("buttons.copy","Copy")},action:function(a,c,d,b){this.processing(!0);var e=this,a=F(c,b),h=a.str,d=i("
").css({height:1,width:1,overflow:"hidden",position:"fixed",top:0,left:0});b.customize&&(h=b.customize(h,b));b=i("