<commit_before>define([
	"dojo/_base/declare", "dijit/layout/ContentPane", "./Base",
	"dojo/request/xhr", "../../util/PathJoin", "dojo/when","dojo/on",
	"dojo/_base/lang","dojo/dom-construct"
], function(declare, ContentPane, Base,
			Request, PathJoin, when, on,
			lang,domConstruct){
	return declare([Base], {
		dataModel: "genome_feature",
		limit: 25000,
		onSetState: function(attr, oldVal, state){
			var parts = state.pathname.split("/");
			var type = "dna";
			if(parts && (parts.length > 2) && parts[parts.length - 2]){
				type = parts[parts.length - 2];
			}

			if(!state.search){
				console.log("NO STATE");
				return;
			}
			var query = state.search;

			if(this.contentPanel){
				this.contentPanel.set("content", "Loading FASTA Data...");
			}
			var _self = this;

			when(this.getData(type, query), function(data){
				_self.contentPanel.set("content", data);
			}, function(err){
				_self.contentPanel.set("content", "There was an error retrieving the requested data: " + err);
			});
		},

		getData: function(type, query){

			query = query + "&limit(" + this.limit + ")";
			var url = PathJoin(this.apiServiceUrl, this.dataModel) + "/";

			return Request.post(url, {
				method: "post",
				headers: {
					"Content-Type": "application/rqlquery+x-www-form-urlencoded",
					"accept": "application/" + type + "+fasta",
					'authorization': (window.App.authorizationToken || ""),
					'X-Requested-With': null
				},
				'X-Requested-With': null,
				data: query
			});
		},

		startup: function(){
			// var query;
			if(this._started){
				return;
			}
			// if(this.state && this.state.search){
			// 	query = this.state.search;
			// 	var parts = this.state.pathname.split("/");
			// 	var type = "dna";
			// 	if(parts && (parts.length > 2) && parts[parts.length - 2]){
			// 		type = parts[parts.length - 2];
			// 	}
			// }

			this.header = new ContentPane({
				content: '<div style="padding: 4px;text-align:right;border:1px solid #ddd;"><i class="fa icon-download fa-2x"></i></div>',
				region: "top",
				style: "padding:4px;"
			});

			on(this.header.domNode, ".icon-download:click", lang.hitch(this,function(evt){
					console.log("Download FASTA Clicked",evt);

					var baseUrl = PathJoin(this.apiServiceUrl, this.dataModel) + "/";

					var query = this.state.search + "&limit(" + this.limit + ")"; 

					baseUrl = baseUrl + "?" + query;


					if(window.App.authorizationToken){
						baseUrl = baseUrl + "&http_authorization=" + encodeURIComponent(window.App.authorizationToken) 
					}

					baseUrl = baseUrl + "&http_accept=application/dna+fasta";


					window.open(baseUrl);

					return;

					var form = domConstruct.create("form", {
						style: "display: none;",
						id: "downloadForm",
						enctype: 'application/x-www-form-urlencoded',
						name: "downloadForm",
						method: "post",
						action: baseUrl
					}, this.domNode);
					domConstruct.create('input', {type: "hidden", value: encodeURIComponent(query), name: "rql"}, form);
					form.submit();
			}))



			this.contentPanel = new ContentPane({<commit_msg>addressed issue #1717: fixed download bug in FASTA viewer.<commit_after>define([
	"dojo/_base/declare", "dijit/layout/ContentPane", "./Base",
	"dojo/request/xhr", "../../util/PathJoin", "dojo/when","dojo/on",
	"dojo/_base/lang","dojo/dom-construct"
], function(declare, ContentPane, Base,
			Request, PathJoin, when, on,
			lang,domConstruct){
	return declare([Base], {
		dataModel: "genome_feature",
		primaryKey: "feature_id",
		limit: 25000,
		type: "dna",
		onSetState: function(attr, oldVal, state){
			var parts = state.pathname.split("/");
			var type = "dna";
			if(parts && (parts.length > 2) && parts[parts.length - 2]){
				type = parts[parts.length - 2];
			}

			if(!state.search){
				console.log("NO STATE");
				return;
			}
			var query = state.search;

			if(this.contentPanel){
				this.contentPanel.set("content", "Loading FASTA Data...");
			}
			var _self = this;

			when(this.getData(type, query), function(data){
				_self.contentPanel.set("content", data);
			}, function(err){
				_self.contentPanel.set("content", "There was an error retrieving the requested data: " + err);
			});
		},

		getData: function(type, query){

			query = query + "&limit(" + this.limit + ")";
			var url = PathJoin(this.apiServiceUrl, this.dataModel) + "/";

			return Request.post(url, {
				method: "post",
				headers: {
					"Content-Type": "application/rqlquery+x-www-form-urlencoded",
					"accept": "application/" + type + "+fasta",
					'authorization': (window.App.authorizationToken || ""),
					'X-Requested-With': null
				},
				'X-Requested-With': null,
				data: query
			});
		},

		startup: function(){
			if(this._started){
				return;
			}
			var parts = this.state.pathname.split("/");
			if(parts && (parts.length > 2) && parts[parts.length - 2]){
				this.type = parts[parts.length - 2];
			}
      this.header = new ContentPane({
				content: '<div style="padding: 4px;text-align:right;border:1px solid #ddd;"><i class="fa icon-download fa-2x"></i></div>',
				region: "top",
				style: "padding:4px;"
			});

			on(this.header.domNode, ".icon-download:click", lang.hitch(this,function(evt){
					//console.log("Download FASTA Clicked",evt);
					var query = this.state.search + "&sort(+" + this.primaryKey + ")&limit(" + this.limit + ")";
					var baseUrl = PathJoin(this.apiServiceUrl, this.dataModel) + "/";
					baseUrl = baseUrl + "?http_download=true&http_accept=application/" + this.type +"+fasta";
					if(window.App.authorizationToken){
						baseUrl = baseUrl + "&http_authorization=" + encodeURIComponent(window.App.authorizationToken)
					}
					var form = domConstruct.create("form", {
						style: "display: none;",
						id: "downloadForm",
						enctype: 'application/x-www-form-urlencoded',
						name: "downloadForm",
						method: "post",
						action: baseUrl
					}, this.domNode);
					domConstruct.create('input', {type: "hidden", value: encodeURIComponent(query), name: "rql"}, form);
					form.submit();
			}))



			this.contentPanel = new ContentPane({
{'fraction_non_alphanumeric': 0.1834892499589693, 'fraction_numerical': 0.005580173970129657, 'mean_word_length': 3.2764912280701752, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1062994', 'n_tokens_mistral': 2534, 'n_tokens_neox': 2048, 'n_words': 397}