"use strict";var connections;angular.module("connections.dataExport",["ngFileSaver","connections.common"]),function(t){var e,n,o;e=t.dataExport||(t.dataExport={}),(n=e.DataExportEvent||(e.DataExportEvent={})).Failure="DataExportFailure",n.Success="DataExportSuccess",(o=e.ExportType||(e.ExportType={})).Button="Button",o.Link="Link"}(connections||(connections={})),function(t){var r,e,n;r=t.dataExport||(t.dataExport={}),e=function(){function t(t,e,n,o,a){var i=this;this.$http=t,this.$log=e,this.$q=n,this.$scope=o,this.fileSaver=a,this.$onInit=function(){i.exporting=!1},this.exportData=function(){return i.exporting?i.$q.reject("A data export is already in progress."):(i.exporting=!0,i.$http({data:"POST"===i.method?i.data:void 0,method:i.method,url:i.url}).then(function(t){i.exporting=!1;var e={data:t.data,headers:t.headers(),status:t.status},n=new Blob([e.data],{type:"text/csv"});return i.fileSaver.saveAs(n,i.getFileName(e.headers["content-disposition"])||"exported-data.csv"),i.$scope.$emit(r.DataExportEvent.Success.toString()),e}).catch(function(t){i.exporting=!1;var e={data:t.data||"Request failed",headers:void 0,status:t.status};return i.$scope.$emit(r.DataExportEvent.Failure.toString()),e}))},this.getFileName=function(t){if(t)return-1!==t.indexOf("filename=")?t.substr(t.indexOf("filename=")+9,t.length):void i.$log.error("exportData.getFileName: filename prefix not found");i.$log.error("exportData.getFileName: contentDisposition is invalid")},this.method=this.method||"GET"}return t.$inject=["$http","$log","$q","$scope","FileSaver"],t}(),n=function(){var n=this;this.templateButton='\n \n ',this.templateLink='\n \n {{$ctrl.buttonTitle}}\n \n \n ',this.bindings={buttonTitle:"@",className:"@",data:"<",method:"@",type:"@?",url:"@"},this.controller=e,this.template=["$element","$attrs",function(t,e){return r.ExportType[e.type]===r.ExportType.Link?n.templateLink:n.templateButton}]},angular.module("connections.dataExport").component("cxDataExport",new n)}(connections||(connections={}));