Permalink
Browse files

Bugfixes

  • Loading branch information...
1 parent 9829267 commit 41850dac9c18dc3d1949a4a6539fc13c1a8924ad @Zerogiven Zerogiven committed Feb 6, 2011
Showing with 253 additions and 115 deletions.
  1. +1 −0 .gitignore
  2. +17 −0 .project
  3. +1 −1 JSONpad-web.html
  4. +7 −0 TODO.txt
  5. +1 −1 css/style.css
  6. +1 −5 index.html
  7. +108 −15 js/jp.ActionPanel.IconBar.js
  8. +24 −2 js/jp.TabPanel.Tab.TreePanel.js
  9. +1 −1 js/jp.TabPanel.js
  10. +92 −90 js/jp.util.js
View
@@ -1 +1,2 @@
nbproject/
+.project/
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>JSONpad</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.aptana.ide.core.unifiedBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.aptana.ide.project.nature.web</nature>
+ </natures>
+</projectDescription>
View
@@ -138,7 +138,7 @@
<body>
<div id="loading-mask"></div>
<div id="loading">
- <span id="loading-message">Starting JSONpad...</span>
+ <span id="loading-message">Starting JSONpad222...</span>
</div>
<script type="text/javascript">
View
@@ -0,0 +1,7 @@
+* Save nodes in tree if they are not selected but opened in the editor
+* Validation for datatype. Number for number value for example.
+* Change form input for boolean datatype (just true/false)
+* Drag and drop order is buggy
+* Add Treepath
+* Add JSONxPath Filter method inside tree
+* Making Adobe Air version ready
View
@@ -7,7 +7,7 @@ HTML, BODY { height: 100%; }
width: 100%;
height: 100%;
background: #FFFFFF;
- z-index: 9;
+ z-index: 999;
}
#loading {
position: absolute;
View
@@ -1,7 +1,3 @@
-<!--
-To change this template, choose Tools | Templates
-and open the template in the editor.
--->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
@@ -19,4 +15,4 @@
<body>
<a href="javascript:openJSONpad();">Starte JSONpad</a>
</body>
-</html>
+</html>
@@ -35,7 +35,8 @@ jp.ActionPanel.IconBar = Ext.extend(Ext.Toolbar, {
{
iconCls: 'icon_loadFromTree',
tooltip: 'Load data from tree as JSON string',
- scale: 'medium'
+ scale: 'medium',
+ handler: this.actionLoadTreeToJson
}
]
};
@@ -167,33 +168,125 @@ jp.ActionPanel.IconBar = Ext.extend(Ext.Toolbar, {
var json = jp.json.parse(value);
if ( codeMirror.validateJson(json, true, false) ) {
-
- //var buildObjectForTree = ;
-
treepanel.setNodesByJson(json);
statuspanel.setStatus({
text: 'Tree succesfully build from JSON data',
iconCls: 'x-status-valid',
clear: true
});
- /*
+ }
+ }
+ },
-
+ actionLoadTreeToJson: function () {
- var editKeyForm = this.findParentByType("viewport").findByType("jp_main_center_ediTreeForm_tabs_edit")[0];
- editKeyForm.formUnsaved = false;
+ var tabpanel = this.findParentByType("jp.Editor").tabPanel;
+ var treepanel = tabpanel.getActiveTab().treePanel;
+ var codeMirror = tabpanel.getCodemirror();
+ var value = codeMirror.getValue().trim();
+ var statuspanel = this.findParentByType("jp.Editor").statusPanel;
- tree.getSelectionModel().select( tree.getRootNode() );
- JP.util.setJPStatus({
- text: 'Made succesfully a tree with the JSON string',
- iconCls: 'x-status-valid',
- clear: true
- }, 'left');*/
- }
+ var rootNode = treepanel.getRootNode();
+ var jsonString = "", lb = "", spacer = "", pt = ":";
+ var compress = false;
+
+ if (!compress) {
+ lb = "\n";
+ spacer = "\t";
+ pt = " : ";
}
+
+ var buildJSONString = function ( node, jsonString, lvl, compress ) {
+ lvl++;
+
+ var tab = "";
+ for (var i = 1; i < lvl; i++)
+ tab += spacer;
+
+ var collapseNode = false;
+ if (node.isExpandable() && !node.isExpanded()) {
+ node.expand();
+ collapseNode = true;
+ }
+
+ node.eachChild(function (child) {
+ var childText = child.attributes.text;
+ childText = unescape(escape(childText).replace(/\%0A/g, "\\n"));
+ childText = childText.replace(/\\n|\\r/g, "\\n").replace(/\"/g, '\\"');
+
+ if ( child.hasChildNodes() ) {
+ if ( child.attributes.type == "array" && node.attributes.type != "array" )
+ jsonString += tab + spacer + '"' + childText + '"' + pt + '[' + lb;
+ else
+ {
+ jsonString += tab + spacer;
+
+ if ( node.attributes.type != "array" )
+ jsonString += '"' + childText + '"' + pt;
+
+ jsonString += (child.attributes.type == "array" ? '[' : "{") + lb;
+ }
+
+ jsonString = tab + buildJSONString ( child, jsonString, lvl, compress );
+
+ jsonString += tab + spacer + (child.attributes.type == "array" ? ']' : '}');
+ }
+ else
+ {
+ var nodeValue = child.attributes.value;
+ nodeValue = unescape(escape(nodeValue).replace(/\%0A/g, "\\n"));
+ nodeValue = nodeValue.replace(/\\n|\\r/g, "\\n").replace(/\"/g, '\\"');
+
+ if ( child.attributes.type == "string" )
+ nodeValue = '"' + nodeValue + '"';
+
+ jsonString += tab + spacer;
+
+ if ( node.attributes.type == "array" )
+ jsonString += nodeValue;
+ else
+ jsonString += '"' + childText + '"' + pt + nodeValue;
+ }
+
+ jsonString += ( !child.isLast() ? "," : "" ) + lb;
+ });
+
+ if (collapseNode) {
+ node.collapse();
+ collapseNode = false;
+ }
+
+ return jsonString;
+ };
+
+
+ if ( rootNode.attributes.type == "array" )
+ jsonString += "[" + lb;
+ else
+ jsonString += "{" + lb;
+
+ jsonString = buildJSONString ( rootNode, jsonString, 0, compress );
+
+ if ( rootNode.attributes.isArray )
+ jsonString += "]" + lb;
+ else
+ jsonString += "}" + lb;
+
+ codeMirror.setValue( jsonString.trim() );
+
+ statuspanel.setStatus({
+ text: 'JSON data succesfully build from tree',
+ iconCls: 'x-status-valid',
+ clear: true
+ });
+ /*JP.util.setJPStatus({
+ text: 'Tree built to JSON string',
+ iconCls: 'x-status-valid',
+ clear: true
+ }, 'left');*/
},
actionFormatIndentJson: function () {
@@ -29,6 +29,7 @@ jp.TabPanel.Tab.TreePanel = Ext.extend(Ext.tree.TreePanel, {
this.contextMenu = new jp.TabPanel.Tab.TreePanel.contextMenu();
this.listeners = {
+ 'movenode': this.onNodeMove,
'mouseover': this.onNodeMouseover,
'mouseout': this.onNodeMouseout,
'contextmenu': this.showContextMenu,
@@ -100,6 +101,27 @@ jp.TabPanel.Tab.TreePanel = Ext.extend(Ext.tree.TreePanel, {
event.stopEvent();
},
+ onNodeMove: function (tree, node, oldParent, newParent, index) {
+ debug.trace("**move node**");
+ if ( newParent.attributes.type == "array" ) {
+ debug.trace("DROP INTO ARRAY");
+
+ debug.trace("***"+node.attributes.type+"***");
+ if (node.attributes.type == "null") {
+ node.setText( "<NULL>" );
+ } else {
+ node.setText( node.attributes.value );
+ }
+ } else {
+ debug.trace("DROP NOT INTO ARRAY");
+ }
+
+ var sm = tree.getSelectionModel();
+ sm.fireEvent('beforeselect', sm, node, null);
+
+ node.select();
+ },
+
onBeforeSelectNode: function (sel, node, obj) {
var topBar = this.getTopToolbar();
//var treeEditPanel = this.findParentByType("jp.Editor").tabPanel.getTreeEditPanel();
@@ -127,8 +149,8 @@ jp.TabPanel.Tab.TreePanel = Ext.extend(Ext.tree.TreePanel, {
this.treeEditPanel.form.jsonkey.disable();
if ( node.attributes.type == "null" ) {
+ this.treeEditPanel.form.jsonvalue.setValue("null");
this.treeEditPanel.form.jsonvalue.disable();
- this.treeEditPanel.form.jsonvalue.value("null");
}
} else {
this.treeEditPanel.form.datatype.disable();
@@ -419,4 +441,4 @@ jp.TabPanel.Tab.TreePanel = Ext.extend(Ext.tree.TreePanel, {
}
});
-Ext.reg('jp.TabPanel.Tab.TreePanel', jp.TabPanel.Tab.TreePanel);
+Ext.reg('jp.TabPanel.Tab.TreePanel', jp.TabPanel.Tab.TreePanel);
View
@@ -17,7 +17,7 @@ jp.TabPanel = Ext.extend(Ext.TabPanel, {
getTabPlugins: function () {
return [
- new Ext.ux.TabCloseMenu(),
+ //new Ext.ux.TabCloseMenu(),
new Ext.ux.TabTitleEdit()
];
},
Oops, something went wrong.

0 comments on commit 41850da

Please sign in to comment.