| @@ -10,12 +10,15 @@ | ||
| 10 | 10 | clipboard.on('success', function(e) { |
| 11 | 11 | window.alert(v.i10n['copied']); |
| 12 | 12 | }); |
| 13 | 13 | } |
| 14 | - $('a.visualizer-action[data-visualizer-type!=copy]').on('click', function(e) { | |
| 14 | + $('a.visualizer-action[data-visualizer-type!=copy]').off('click').on('click', function(e) { | |
| 15 | 15 | var type = $(this).attr( 'data-visualizer-type' ); |
| 16 | 16 | var chart = $(this).attr( 'data-visualizer-chart-id' ); |
| 17 | + var container = $(this).attr( 'data-visualizer-container-id' ); | |
| 17 | 18 | var lock = $('.visualizer-front.visualizer-front-' + chart); |
| 19 | + var mime = $(this).attr( 'data-visualizer-mime' ); | |
| 20 | + console.log(mime); | |
| 18 | 21 | lock.lock(); |
| 19 | 22 | e.preventDefault(); |
| 20 | 23 | $.ajax({ |
| 21 | 24 | url : v.rest_url.replace('#id#', chart).replace('#type#', type), |
| @@ -22,40 +25,39 @@ | ||
| 22 | 25 | success: function(data) { |
| 23 | 26 | if (data && data.data) { |
| 24 | 27 | switch(type){ |
| 25 | 28 | case 'csv': |
| 26 | - var a = document.createElement("a"); | |
| 27 | - document.body.appendChild(a); | |
| 28 | - a.style = "display: none"; | |
| 29 | - var blob = new Blob([data.data.csv], {type: $(this).attr( 'data-visualizer-mime' ) }), | |
| 30 | - url = window.URL.createObjectURL(blob); | |
| 31 | - a.href = url; | |
| 32 | - a.download = data.data.name; | |
| 33 | - a.click(); | |
| 34 | - setTimeout(function () { | |
| 35 | - window.URL.revokeObjectURL(url); | |
| 36 | - }, 100); | |
| 29 | + var blob = new Blob([data.data.csv], {type: mime }); | |
| 30 | + if(window.navigator.msSaveOrOpenBlob){ | |
| 31 | + window.navigator.msSaveOrOpenBlob(blob, data.data.name); | |
| 32 | + } else { | |
| 33 | + var url = window.URL.createObjectURL(blob); | |
| 34 | + var $a = $("<a>"); | |
| 35 | + $a.attr("href", url); | |
| 36 | + $("body").append($a); | |
| 37 | + $a.attr("download", data.data.name); | |
| 38 | + $a[0].click(); | |
| 39 | + setTimeout(function () { | |
| 40 | + window.URL.revokeObjectURL(url); | |
| 41 | + $a.remove(); | |
| 42 | + }, 100); | |
| 43 | + } | |
| 37 | 44 | break; |
| 38 | 45 | case 'xls': |
| 39 | - var $a = $("<a>"); | |
| 40 | - $a.attr("href",data.data.csv); | |
| 41 | - $("body").append($a); | |
| 42 | - $a.attr("download",data.data.name); | |
| 43 | - $a[0].click(); | |
| 44 | - $a.remove(); | |
| 46 | + if(window.navigator.msSaveOrOpenBlob){ | |
| 47 | + blob = new Blob([s2ab(atob(data.data.raw))], {type: '' }); | |
| 48 | + window.navigator.msSaveOrOpenBlob(blob, data.data.name); | |
| 49 | + } else { | |
| 50 | + var $a = $("<a>"); // jshint ignore:line | |
| 51 | + $a.attr("href", data.data.csv); | |
| 52 | + $("body").append($a); | |
| 53 | + $a.attr("download", data.data.name); | |
| 54 | + $a[0].click(); | |
| 55 | + $a.remove(); | |
| 56 | + } | |
| 45 | 57 | break; |
| 46 | 58 | case 'print': |
| 47 | - var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute"); | |
| 48 | - iframe.appendTo($('body')); | |
| 49 | - var iframe_doc = iframe.get(0).contentWindow || iframe.get(0).contentDocument.document || iframe.get(0).contentDocument; | |
| 50 | - iframe_doc.document.open(); | |
| 51 | - iframe_doc.document.write(data.data.csv); | |
| 52 | - iframe_doc.document.close(); | |
| 53 | - setTimeout(function(){ | |
| 54 | - window.frames['print-visualization'].focus(); | |
| 55 | - window.frames['print-visualization'].print(); | |
| 56 | - iframe.remove(); | |
| 57 | - }, 500); | |
| 59 | + $('body').trigger('visualizer:action:specificchart', {action: 'print', id: container, data: data.data.csv}); | |
| 58 | 60 | break; |
| 59 | 61 | default: |
| 60 | 62 | if(window.visualizer_perform_action) { |
| 61 | 63 | window.visualizer_perform_action(type, chart, data.data); |
| @@ -68,12 +70,38 @@ | ||
| 68 | 70 | }); |
| 69 | 71 | }); |
| 70 | 72 | } |
| 71 | 73 | |
| 74 | + function s2ab(s) { | |
| 75 | + var buf = new ArrayBuffer(s.length); | |
| 76 | + var view = new Uint8Array(buf); | |
| 77 | + for (var i=0; i !== s.length; ++i) { | |
| 78 | + view[i] = s.charCodeAt(i) & 0xFF; | |
| 79 | + } | |
| 80 | + return buf; | |
| 81 | + } | |
| 82 | + | |
| 72 | 83 | $(document).ready(function(){ |
| 73 | 84 | $('body').trigger('visualizer:render:chart:start', visualizer); |
| 74 | 85 | initActionsButtons(visualizer); |
| 86 | + registerDefaultActions(); | |
| 75 | 87 | }); |
| 88 | + | |
| 89 | + function registerDefaultActions(){ | |
| 90 | + $('body').off('visualizer:action:specificchart:defaultprint').on('visualizer:action:specificchart:defaultprint', function(event, v){ | |
| 91 | + var iframe = $('<iframe>').attr("name", "print-visualization").attr("id", "print-visualization").css("position", "absolute"); | |
| 92 | + iframe.appendTo($('body')); | |
| 93 | + var iframe_doc = iframe.get(0).contentWindow || iframe.get(0).contentDocument.document || iframe.get(0).contentDocument; | |
| 94 | + iframe_doc.document.open(); | |
| 95 | + iframe_doc.document.write(v.data); | |
| 96 | + iframe_doc.document.close(); | |
| 97 | + setTimeout(function(){ | |
| 98 | + window.frames['print-visualization'].focus(); | |
| 99 | + window.frames['print-visualization'].print(); | |
| 100 | + iframe.remove(); | |
| 101 | + }, 500); | |
| 102 | + }); | |
| 103 | + } | |
| 76 | 104 | })(jQuery, visualizer); |
| 77 | 105 | |
| 78 | 106 | (function ($) { |
| 79 | 107 | $.fn.lock = function () { |