Skip to content

Commit

Permalink
json default
Browse files Browse the repository at this point in the history
  • Loading branch information
shancarter committed May 28, 2013
1 parent ffe58b2 commit 1e70b1b
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions js/converter.js
@@ -1,9 +1,9 @@
//
//
// converter.js
// Mr-Data-Converter
//
//
// Created by Shan Carter on 2010-09-01.
//
//



Expand All @@ -12,11 +12,11 @@ function DataConverter(nodeId) {
//---------------------------------------
// PUBLIC PROPERTIES
//---------------------------------------

this.nodeId = nodeId;
this.node = $("#"+nodeId);
this.outputDataTypes = [

this.outputDataTypes = [
{"text":"Actionscript", "id":"as", "notes":""},
{"text":"ASP/VBScript", "id":"asp", "notes":""},
{"text":"HTML", "id":"html", "notes":""},
Expand All @@ -30,35 +30,35 @@ function DataConverter(nodeId) {
{"text":"XML - Properties", "id":"xmlProperties", "notes":""},
{"text":"XML - Nodes", "id":"xml", "notes":""},
{"text":"XML - Illustrator", "id":"xmlIllustrator", "notes":""}];
this.outputDataType = "xml";
this.outputDataType = "json";

this.columnDelimiter = "\t";
this.rowDelimiter = "\n";

this.inputTextArea = {};
this.outputTextArea = {};

this.inputHeader = {};
this.outputHeader = {};
this.dataSelect = {};

this.inputText = "";
this.outputText = "";

this.newLine = "\n";
this.indent = " ";

this.commentLine = "//";
this.commentLineEnd = "";
this.tableName = "MrDataConverter"

this.useUnderscores = true;
this.headersProvided = true;
this.downcaseHeaders = true;
this.upcaseHeaders = false;
this.includeWhiteSpace = true;
this.useTabsForIndent = false;

}

//---------------------------------------
Expand All @@ -67,13 +67,13 @@ function DataConverter(nodeId) {

DataConverter.prototype.create = function(w,h) {
var self = this;

//build HTML for converter
this.inputHeader = $('<div class="groupHeader" id="inputHeader"><p class="groupHeadline">Input CSV or tab-delimited data. <span class="subhead"> Using Excel? Simply copy and paste. No data on hand? <a href="#" id="insertSample">Use sample</a></span></p></div>');
this.inputTextArea = $('<textarea class="textInputs" id="dataInput"></textarea>');
var outputHeaderText = '<div class="groupHeader" id="inputHeader"><p class="groupHeadline">Output as <select name="Data Types" id="dataSelector" >';
for (var i=0; i < this.outputDataTypes.length; i++) {

outputHeaderText += '<option value="'+this.outputDataTypes[i]["id"]+'" '
+ (this.outputDataTypes[i]["id"] == this.outputDataType ? 'selected="selected"' : '')
+ '>'
Expand All @@ -82,66 +82,66 @@ DataConverter.prototype.create = function(w,h) {
outputHeaderText += '</select><span class="subhead" id="outputNotes"></span></p></div>';
this.outputHeader = $(outputHeaderText);
this.outputTextArea = $('<textarea class="textInputs" id="dataOutput"></textarea>');

this.node.append(this.inputHeader);
this.node.append(this.inputTextArea);
this.node.append(this.outputHeader);
this.node.append(this.outputTextArea);

this.dataSelect = this.outputHeader.find("#dataSelector");


//add event listeners

// $("#convertButton").bind('click',function(evt){
// evt.preventDefault();
// self.convert();
// });

this.outputTextArea.click(function(evt){this.select();});


$("#insertSample").bind('click',function(evt){
evt.preventDefault();
self.insertSampleData();
self.convert();
_gaq.push(['_trackEvent', 'SampleData','InsertGeneric']);
});

$("#dataInput").keyup(function() {self.convert()});
$("#dataInput").change(function() {
self.convert();
_gaq.push(['_trackEvent', 'DataType',self.outputDataType]);
});

$("#dataSelector").bind('change',function(evt){
self.outputDataType = $(this).val();
self.convert();
});

this.resize(w,h);
}

DataConverter.prototype.resize = function(w,h) {

var paneWidth = w;
var paneHeight = (h-90)/2-20;

this.node.css({width:paneWidth});
this.inputTextArea.css({width:paneWidth-20,height:paneHeight});
this.outputTextArea.css({width: paneWidth-20, height:paneHeight});

}

DataConverter.prototype.convert = function() {

this.inputText = this.inputTextArea.val();
this.outputText = "";


//make sure there is input data before converting...
if (this.inputText.length > 0) {

if (this.includeWhiteSpace) {
this.newLine = "\n";
// console.log("yes")
Expand All @@ -150,20 +150,20 @@ DataConverter.prototype.convert = function() {
this.newLine = "";
// console.log("no")
}

CSVParser.resetLog();
var parseOutput = CSVParser.parse(this.inputText, this.headersProvided, this.delimiter, this.downcaseHeaders, this.upcaseHeaders);

var dataGrid = parseOutput.dataGrid;
var headerNames = parseOutput.headerNames;
var headerTypes = parseOutput.headerTypes;
var errors = parseOutput.errors;

this.outputText = DataGridRenderer[this.outputDataType](dataGrid, headerNames, headerTypes, this.indent, this.newLine);


this.outputTextArea.val(errors + this.outputText);

}; //end test for existence of input text
}

Expand Down

0 comments on commit 1e70b1b

Please sign in to comment.