/*!
 * SAP UI development toolkit for HTML5 (SAPUI5/OpenUI5)
 * (c) Copyright 2009-2015 SAP SE or an SAP affiliate company.
 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
 */
sap.ui.define(['jquery.sap.global','sap/ui/core/Control','./ExportColumn','./ExportRow','./ExportType','./File'],function(q,C,E,a,b,F){'use strict';function w(f,o){if(f){return function(){return f.apply(o,arguments);};}else{return f;}}function p(m){q.sap.log.warning("Usage of deprecated jQuery Promise method: '"+m+"'. "+"Please use the standard Promise methods 'then' / 'catch' instead!","","sap.ui.core.util.Export");}function c(P,o){var O=new Promise(P);o=o||O;var r=false,R=false;O.then(function(v){r=true;return v;},function(e){R=true;throw e;});var m={then:O.then,"catch":O["catch"]};function f(e){e.then=function(s,g){var A=[w(s,o),w(g,o)];return f(m.then.apply(e,A),o);};e["catch"]=function(g){var A=[w(g,o)];return f(m["catch"].apply(e,A),o);};q.each([{jq:"done",es6:"then"},{jq:"fail",es6:"catch"},{jq:"always",es6:"then"}],function(i,g){e[g.jq]=function(){p(g.jq);var h=null;q.each(Array.prototype.concat.apply([],arguments),function(i,j){var W=w(j,o);var k=function(v){W.apply(this,arguments);return v;};var A=[k];if(g.jq==="always"){A.push(k);}if(!h){h=m[g.es6].apply(e,A);}else{h=h[g.es6].apply(h,A);}});return f(h,o);};});e.pipe=function(D,g){p("pipe");return e.then(D,g);};e.state=function(){p("state");if(r){return"resolved";}else if(R){return"rejected";}else{return"pending";}};return e;}return f(O);}var d=C.extend('sap.ui.core.util.Export',{metadata:{publicMethods:["generate","saveFile"],library:"sap.ui.core",aggregations:{exportType:{type:'sap.ui.core.util.ExportType',multiple:false},columns:{type:'sap.ui.core.util.ExportColumn',multiple:true,bindable:'bindable'},rows:{type:'sap.ui.core.util.ExportRow',multiple:true,bindable:'bindable'},_template:{type:'sap.ui.core.util.ExportRow',multiple:false,visibility:'hidden'}}}});d.getMetadata().getAggregation("rows")._doesNotRequireFactory=true;d.prototype.init=function(){this._oPromise=null;this._fnResolvePromise=null;this._oRowBindingArgs=null;};d.prototype.exit=function(){delete this._oPromise;delete this._fnResolvePromise;delete this._oRowBindingArgs;};d.prototype._createRowTemplate=function(){var t=new a(this.getId()+"-row"),e=this.getColumns();for(var i=0,l=e.length;i<l;i++){var o=e[i].getTemplate();if(o){t.addCell(o.clone("col"+i));}}return t;};d.prototype.bindAggregation=function(n,B){if(n==='rows'){this._oRowBindingArgs=arguments;return this;}return C.prototype.bindAggregation.apply(this,arguments);};d.prototype.updateRows=function(r){if(r==='change'&&this._fnResolvePromise){var s=this.getExportType()._generate(this);this.destroyAggregation('_template');this.unbindAggregation('rows');this._fnResolvePromise(s);this._oPromise=null;this._fnResolvePromise=null;}};d.prototype.generate=function(){var t=this;if(!this._oPromise){this._oPromise=c(function(r,e){t._fnResolvePromise=r;if(!t.hasModel()){e("Generate is not possible beause no model was set.");}else{var T=t._createRowTemplate();t.setAggregation('_template',T,true);C.prototype.bindAggregation.apply(t,t._oRowBindingArgs);if(t.getBinding("rows")){t.getBinding("rows").getContexts(0,t.getBinding("rows").getLength());}}},this);}return this._oPromise;};d.prototype.saveFile=function(f){return this.generate().then(function(s){var e=this.getExportType();F.save(s,f||"data",e.getFileExtension(),e.getMimeType(),e.getCharset());});};return d;},true);
