includes/clientside/static/SpryJSONDataSet.js
author Dan
Tue, 19 Aug 2008 20:57:57 -0400
changeset 698 40f9528b6348
parent 581 5e8fd89c02ea
permissions -rw-r--r--
Merge? o_O
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
581
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
     1
// SpryJSONDataSet.js - version 0.6 - Spry Pre-Release 1.6.1
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
     2
//
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
     3
// Copyright (c) 2007. Adobe Systems Incorporated.
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
     4
// All rights reserved.
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
     5
//
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
     6
// Redistribution and use in source and binary forms, with or without
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
     7
// modification, are permitted provided that the following conditions are met:
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
     8
//
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
     9
//   * Redistributions of source code must retain the above copyright notice,
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    10
//     this list of conditions and the following disclaimer.
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    11
//   * Redistributions in binary form must reproduce the above copyright notice,
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    12
//     this list of conditions and the following disclaimer in the documentation
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    13
//     and/or other materials provided with the distribution.
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    14
//   * Neither the name of Adobe Systems Incorporated nor the names of its
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    15
//     contributors may be used to endorse or promote products derived from this
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    16
//     software without specific prior written permission.
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    17
//
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    19
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    20
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    21
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    22
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    23
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    24
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    25
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    26
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    27
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    28
// POSSIBILITY OF SUCH DAMAGE.
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    29
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    30
Spry.Data.JSONDataSet=function(dataSetURL,dataSetOptions)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    31
{this.path="";this.pathIsObjectOfArrays=false;this.doc=null;this.subPaths=[];this.useParser=false;this.preparseFunc=null;Spry.Data.HTTPSourceDataSet.call(this,dataSetURL,dataSetOptions);var jwType=typeof this.subPaths;if(jwType=="string"||(jwType=="object"&&this.subPaths.constructor!=Array))
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    32
this.subPaths=[this.subPaths];};Spry.Data.JSONDataSet.prototype=new Spry.Data.HTTPSourceDataSet();Spry.Data.JSONDataSet.prototype.constructor=Spry.Data.JSONDataSet;Spry.Data.JSONDataSet.prototype.getDataRefStrings=function()
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    33
{var strArr=[];if(this.url)strArr.push(this.url);if(this.path)strArr.push(this.path);if(this.requestInfo&&this.requestInfo.postData)strArr.push(this.requestInfo.postData);return strArr;};Spry.Data.JSONDataSet.prototype.getDocument=function(){return this.doc;};Spry.Data.JSONDataSet.prototype.getPath=function(){return this.path;};Spry.Data.JSONDataSet.prototype.setPath=function(path)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    34
{if(this.path!=path)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    35
{this.path=path;if(this.dataWasLoaded&&this.doc)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    36
{this.notifyObservers("onPreLoad");this.setDataFromDoc(this.doc);}}};Spry.Data.JSONDataSet.getMatchingObjects=function(path,jsonObj)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    37
{var results=[];if(path&&jsonObj)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    38
{var prop="";var leftOverPath="";var offset=path.search(/\./);if(offset!=-1)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    39
{prop=path.substring(0,offset);leftOverPath=path.substring(offset+1);}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    40
else
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    41
prop=path;var matches=[];if(prop&&typeof jsonObj=="object")
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    42
{var obj=jsonObj[prop];var objType=typeof obj;if(objType!=undefined&&objType!=null)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    43
{if(obj&&objType=="object"&&obj.constructor==Array)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    44
matches=matches.concat(obj);else
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    45
matches.push(obj);}}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    46
var numMatches=matches.length;if(leftOverPath)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    47
{for(var i=0;i<numMatches;i++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    48
results=results.concat(Spry.Data.JSONDataSet.getMatchingObjects(leftOverPath,matches[i]));}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    49
else
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    50
results=matches;}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    51
return results;};Spry.Data.JSONDataSet.flattenObject=function(obj,basicColumnName)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    52
{var basicName=basicColumnName?basicColumnName:"column0";var row=new Object;var objType=typeof obj;if(objType=="object")
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    53
Spry.Data.JSONDataSet.copyProps(row,obj);else
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    54
row[basicName]=obj;row.ds_JSONObject=obj;return row;};Spry.Data.JSONDataSet.copyProps=function(dstObj,srcObj,suppressObjProps)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    55
{if(srcObj&&dstObj)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    56
{for(var prop in srcObj)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    57
{if(suppressObjProps&&typeof srcObj[prop]=="object")
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    58
continue;dstObj[prop]=srcObj[prop];}}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    59
return dstObj;};Spry.Data.JSONDataSet.flattenDataIntoRecordSet=function(jsonObj,path,pathIsObjectOfArrays)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    60
{var rs=new Object;rs.data=[];rs.dataHash={};if(!path)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    61
path="";var obj=jsonObj;var objType=typeof obj;var basicColName="";if(objType!="object"||!obj)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    62
{if(obj!=null)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    63
{var row=new Object;row.column0=obj;row.ds_RowID=0;rs.data.push(row);rs.dataHash[row.ds_RowID]=row;}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    64
return rs;}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    65
var matches=[];if(obj.constructor==Array)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    66
{var arrLen=obj.length;if(arrLen<1)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    67
return rs;var eleType=typeof obj[0];if(eleType!="object")
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    68
{for(var i=0;i<arrLen;i++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    69
{var row=new Object;row.column0=obj[i];row.ds_RowID=i;rs.data.push(row);rs.dataHash[row.ds_RowID]=row;}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    70
return rs;}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    71
if(obj[0].constructor==Array)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    72
return rs;if(path)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    73
{for(var i=0;i<arrLen;i++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    74
matches=matches.concat(Spry.Data.JSONDataSet.getMatchingObjects(path,obj[i]));}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    75
else
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    76
{for(var i=0;i<arrLen;i++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    77
matches.push(obj[i]);}}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    78
else
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    79
{if(path)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    80
matches=Spry.Data.JSONDataSet.getMatchingObjects(path,obj);else
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    81
matches.push(obj);}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    82
var numMatches=matches.length;if(path&&numMatches>=1&&typeof matches[0]!="object")
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    83
basicColName=path.replace(/.*\./,"");if(!pathIsObjectOfArrays)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    84
{for(var i=0;i<numMatches;i++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    85
{var row=Spry.Data.JSONDataSet.flattenObject(matches[i],basicColName,pathIsObjectOfArrays);row.ds_RowID=i;rs.dataHash[i]=row;rs.data.push(row);}}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    86
else
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    87
{var rowID=0;for(var i=0;i<numMatches;i++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    88
{var obj=matches[i];var colNames=[];var maxNumRows=0;for(var propName in obj)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    89
{var prop=obj[propName];var propyType=typeof prop;if(propyType=='object'&&prop.constructor==Array)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    90
{colNames.push(propName);maxNumRows=Math.max(maxNumRows,obj[propName].length);}}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    91
var numColNames=colNames.length;for(var j=0;j<maxNumRows;j++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    92
{var row=new Object;for(var k=0;k<numColNames;k++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    93
{var colName=colNames[k];row[colName]=obj[colName][j];}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    94
row.ds_RowID=rowID++;rs.dataHash[row.ds_RowID]=row;rs.data.push(row);}}}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    95
return rs;};Spry.Data.JSONDataSet.prototype.flattenSubPaths=function(rs,subPaths)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    96
{if(!rs||!subPaths)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    97
return;var numSubPaths=subPaths.length;if(numSubPaths<1)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    98
return;var data=rs.data;var dataHash={};var pathArray=[];var cleanedPathArray=[];var isObjectOfArraysArr=[];for(var i=0;i<numSubPaths;i++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
    99
{var subPath=subPaths[i];if(typeof subPath=="object")
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   100
{isObjectOfArraysArr[i]=subPath.pathIsObjectOfArrays;subPath=subPath.path;}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   101
if(!subPath)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   102
subPath="";pathArray[i]=Spry.Data.Region.processDataRefString(null,subPath,this.dataSetsForDataRefStrings);cleanedPathArray[i]=pathArray[i].replace(/\[.*\]/g,"");}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   103
var row;var numRows=data.length;var newData=[];for(var i=0;i<numRows;i++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   104
{row=data[i];var newRows=[row];for(var j=0;j<numSubPaths;j++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   105
{var newRS=Spry.Data.JSONDataSet.flattenDataIntoRecordSet(row.ds_JSONObject,pathArray[j],isObjectOfArraysArr[j]);if(newRS&&newRS.data&&newRS.data.length)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   106
{if(typeof subPaths[j]=="object"&&subPaths[j].subPaths)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   107
{var sp=subPaths[j].subPaths;spType=typeof sp;if(spType=="string")
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   108
sp=[sp];else if(spType=="object"&&spType.constructor==Object)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   109
sp=[sp];this.flattenSubPaths(newRS,sp);}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   110
var newRSData=newRS.data;var numRSRows=newRSData.length;var cleanedPath=cleanedPathArray[j]+".";var numNewRows=newRows.length;var joinedRows=[];for(var k=0;k<numNewRows;k++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   111
{var newRow=newRows[k];for(var l=0;l<numRSRows;l++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   112
{var newRowObj=new Object;var newRSRow=newRSData[l];for(var prop in newRSRow)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   113
{var newPropName=cleanedPath+prop;if(cleanedPath==prop||cleanedPath.search(new RegExp("\\."+prop+"\\.$"))!=-1)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   114
newPropName=cleanedPathArray[j];newRowObj[newPropName]=newRSRow[prop];}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   115
Spry.Data.JSONDataSet.copyProps(newRowObj,newRow);joinedRows.push(newRowObj);}}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   116
newRows=joinedRows;}}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   117
newData=newData.concat(newRows);}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   118
data=newData;numRows=data.length;for(i=0;i<numRows;i++)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   119
{row=data[i];row.ds_RowID=i;dataHash[row.ds_RowID]=row;}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   120
rs.data=data;rs.dataHash=dataHash;};Spry.Data.JSONDataSet.prototype.parseJSON=function(str,filter)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   121
{try
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   122
{if(/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(str))
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   123
{var j=eval('('+str+')');if(typeof filter==='function')
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   124
{function walk(k,v)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   125
{if(v&&typeof v==='object')
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   126
{for(var i in v)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   127
{if(v.hasOwnProperty(i))
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   128
{v[i]=walk(i,v[i]);}}}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   129
return filter(k,v);}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   130
j=walk('',j);}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   131
return j;}}catch(e){}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   132
throw new Error("Failed to parse JSON string.");};Spry.Data.JSONDataSet.prototype.syncColumnTypesToData=function()
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   133
{var row=this.getData()[0];for(var colName in row)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   134
{if(!this.columnTypes[colName])
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   135
{var type=typeof row[colName];if(type=="number")
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   136
this.setColumnType(colName,type);}}};Spry.Data.JSONDataSet.prototype.loadDataIntoDataSet=function(rawDataDoc)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   137
{if(this.preparseFunc)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   138
rawDataDoc=this.preparseFunc(this,rawDataDoc);var jsonObj;try{jsonObj=this.useParser?this.parseJSON(rawDataDoc):eval("("+rawDataDoc+")");}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   139
catch(e)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   140
{Spry.Debug.reportError("Caught exception in JSONDataSet.loadDataIntoDataSet: "+e);jsonObj={};}
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   141
if(jsonObj==null)
5e8fd89c02ea Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
parents:
diff changeset
   142
jsonObj="null";var rs=Spry.Data.JSONDataSet.flattenDataIntoRecordSet(jsonObj,Spry.Data.Region.processDataRefString(null,this.path,this.dataSetsForDataRefStrings),this.pathIsObjectOfArrays);this.flattenSubPaths(rs,this.subPaths);this.doc=rawDataDoc;this.docObj=jsonObj;this.data=rs.data;this.dataHash=rs.dataHash;this.dataWasLoaded=(this.doc!=null);this.syncColumnTypesToData();};