diff options
author | Eric Guzman | 2012-04-23 11:55:55 -0700 |
---|---|---|
committer | Eric Guzman | 2012-04-23 11:55:55 -0700 |
commit | cdd1189e349e2974681e2c451e861e5b0db570e4 (patch) | |
tree | d8823c3d050e011032c563d20c1a5f61e67ae740 /js/components/tree.reel/tree.js | |
parent | c0fce534c255ef1e25779e2f0e8de95bb4e160cf (diff) | |
parent | 5a0331fc26fcc2cdc6200086109e34440a2dec6a (diff) | |
download | ninja-cdd1189e349e2974681e2c451e861e5b0db570e4.tar.gz |
Merge branch 'refs/heads/master' into CSSPanelUpdates
Diffstat (limited to 'js/components/tree.reel/tree.js')
-rwxr-xr-x | js/components/tree.reel/tree.js | 789 |
1 files changed, 0 insertions, 789 deletions
diff --git a/js/components/tree.reel/tree.js b/js/components/tree.reel/tree.js deleted file mode 100755 index 7084ba99..00000000 --- a/js/components/tree.reel/tree.js +++ /dev/null | |||
@@ -1,789 +0,0 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage/core/core").Montage; | ||
8 | var Component = require("montage/ui/component").Component; | ||
9 | var nj = require("js/lib/NJUtils").NJUtils; | ||
10 | |||
11 | exports.Tree = Montage.create(Component, { | ||
12 | |||
13 | _treeDepth: { | ||
14 | value: 1 | ||
15 | }, | ||
16 | treeDepth: { | ||
17 | get: function() { | ||
18 | return this._treeDepth; | ||
19 | }, | ||
20 | set: function(value) { | ||
21 | this._treeDepth = value; | ||
22 | } | ||
23 | }, | ||
24 | _depthHash: { | ||
25 | value: "" | ||
26 | }, | ||
27 | depthHash: { | ||
28 | get: function() { | ||
29 | return this._depthHash; | ||
30 | }, | ||
31 | set: function(strValue) { | ||
32 | this._depthHash = strValue; | ||
33 | } | ||
34 | }, | ||
35 | _firstLevel: { | ||
36 | value: true | ||
37 | }, | ||
38 | firstLevel: { | ||
39 | get: function() { | ||
40 | return this._firstLevel; | ||
41 | }, | ||
42 | set: function(value) { | ||
43 | this._firstLevel = value; | ||
44 | } | ||
45 | }, | ||
46 | |||
47 | _hasFocus: { | ||
48 | enumerable: false, | ||
49 | value: false | ||
50 | }, | ||
51 | |||
52 | _selectedNode: { | ||
53 | enumerable: false, | ||
54 | value: null | ||
55 | }, | ||
56 | |||
57 | _selectedNodes: { | ||
58 | enumerable: false, | ||
59 | value: null | ||
60 | }, | ||
61 | |||
62 | _dataProvider: { | ||
63 | enumerable: false, | ||
64 | value: null | ||
65 | }, | ||
66 | |||
67 | dataProvider: { | ||
68 | enumerable: true, | ||
69 | get: function() { | ||
70 | return this._dataProvider; | ||
71 | }, | ||
72 | set: function(dp) { | ||
73 | this._dataProvider = dp.documentElement; | ||
74 | this.needsDraw = true; | ||
75 | } | ||
76 | }, | ||
77 | |||
78 | _jsonData: { | ||
79 | enumerable: false, | ||
80 | value: null | ||
81 | }, | ||
82 | |||
83 | jsonData: { | ||
84 | enumerable: true, | ||
85 | get: function() { | ||
86 | return this._jsonData; | ||
87 | }, | ||
88 | set: function(jsonObject) { | ||
89 | this._jsonData = jsonObject; | ||
90 | this.needsDraw = true; | ||
91 | } | ||
92 | }, | ||
93 | |||
94 | _traverseJson: { | ||
95 | value: function(jsonObject, parentElement, intCounter) { | ||
96 | var newLi = document.createElement("li"), | ||
97 | fileSpan = document.createElement("span"), | ||
98 | spaceSpan = document.createElement("span"), | ||
99 | nameSpan = document.createElement("span"), | ||
100 | sizeSpan = document.createElement("span"), | ||
101 | dateSpan = document.createElement("span"), | ||
102 | clearSpan = document.createElement("span"), | ||
103 | containerSpan = document.createElement("span"), | ||
104 | textName = document.createTextNode(jsonObject.name), | ||
105 | textSize = "", | ||
106 | textDate = "", | ||
107 | textSpace = document.createTextNode("\u00A0"), | ||
108 | indent = this.treeDepth * 18, | ||
109 | strIndent = indent + "px", | ||
110 | extension = jsonObject.name.split(".").pop(), | ||
111 | makeFriendlySize = function(intSize) { | ||
112 | var strSize = false, | ||
113 | intRoundedSize = Math.round(intSize/1000); | ||
114 | strSize = intRoundedSize + " K"; | ||
115 | return strSize; | ||
116 | }, | ||
117 | makeFriendlyDate = function(intSeconds) { | ||
118 | // TODO: Localization. | ||
119 | var myDate = new Date(intSeconds), | ||
120 | strDate = ""; | ||
121 | strDate = (myDate.getMonth() + 1) + "/" | ||
122 | + myDate.getDate() + "/" | ||
123 | + myDate.getFullYear() + " " | ||
124 | + myDate.toLocaleTimeString(); | ||
125 | return strDate; | ||
126 | } | ||
127 | |||
128 | // File or directory? | ||
129 | if (jsonObject.type === "file") { | ||
130 | // Build file item: | ||
131 | // Create li, give it attributes and event listeners | ||
132 | // and then append it to the DOM | ||
133 | // Markup is a little complex in order to handle indention and columns. | ||
134 | |||
135 | |||
136 | textSize = document.createTextNode(makeFriendlySize(jsonObject.size)); | ||
137 | fileSpan.setAttribute("class", "pp-col-files"); | ||
138 | sizeSpan.setAttribute("class", "pp-col-size"); | ||
139 | sizeSpan.appendChild(textSize); | ||
140 | spaceSpan.setAttribute("class", "span-space"); | ||
141 | spaceSpan.appendChild(textSpace); | ||
142 | spaceSpan.style.width = strIndent; | ||
143 | clearSpan.setAttribute("class", "clear"); | ||
144 | fileSpan.appendChild(spaceSpan); | ||
145 | fileSpan.appendChild(textName); | ||
146 | |||
147 | dateSpan.setAttribute("class", "pp-col-date"); | ||
148 | textDate = document.createTextNode(makeFriendlyDate(parseInt(jsonObject.modifiedDate))); | ||
149 | dateSpan.appendChild(textDate); | ||
150 | |||
151 | // Append elements in order | ||
152 | containerSpan.appendChild(fileSpan); | ||
153 | containerSpan.appendChild(dateSpan); | ||
154 | containerSpan.appendChild(sizeSpan); | ||
155 | |||
156 | containerSpan.appendChild(clearSpan); | ||
157 | containerSpan.setAttribute("tabindex", 0); | ||
158 | containerSpan.setAttribute("class", "pp-span-all"); | ||
159 | newLi.appendChild(containerSpan); | ||
160 | |||
161 | // Loop through the JSON properties and set them as data attributes on the element | ||
162 | for (var property in jsonObject) { | ||
163 | var newAttribute = "data-" + property; | ||
164 | newLi.setAttribute(newAttribute, jsonObject[property]); | ||
165 | } | ||
166 | |||
167 | // Set depth hash data | ||
168 | newLi.setAttribute("data-depthhash", this.depthHash + "" + intCounter); | ||
169 | |||
170 | // We also need to set the class of the element | ||
171 | newLi.setAttribute("class", jsonObject.type); | ||
172 | |||
173 | |||
174 | // Get the file extension | ||
175 | newLi.classList.add(extension.toLowerCase()); | ||
176 | |||
177 | // Add event listeners. Use the nifty identifier feature. | ||
178 | newLi.identifier="jsontree"; | ||
179 | newLi.addEventListener("click", this, false); | ||
180 | newLi.addEventListener("keydown", this, false); | ||
181 | |||
182 | // Add element to the DOM. | ||
183 | parentElement.appendChild(newLi); | ||
184 | |||
185 | } else { | ||
186 | // If it's not a file, it's a directory, so build directory item: | ||
187 | // Create li for directory entry, give it properties | ||
188 | // If it has children, create a UL for it and recurse. | ||
189 | // Markup is a little complex in order to handle indention and columns. | ||
190 | |||
191 | fileSpan.setAttribute("class", "pp-col-files"); | ||
192 | if (this.firstLevel) { | ||
193 | fileSpan.setAttribute("title", jsonObject.uri); | ||
194 | fileSpan.classList.add("bold"); | ||
195 | this.firstLevel = false; | ||
196 | } | ||
197 | sizeSpan.setAttribute("class", "pp-col-size"); | ||
198 | dateSpan.setAttribute("class", "pp-col-date"); | ||
199 | spaceSpan.setAttribute("class", "span-space"); | ||
200 | spaceSpan.appendChild(textSpace); | ||
201 | spaceSpan.style.width = strIndent; | ||
202 | clearSpan.setAttribute("class", "clear"); | ||
203 | fileSpan.appendChild(spaceSpan); | ||
204 | fileSpan.appendChild(textName); | ||
205 | |||
206 | containerSpan.appendChild(fileSpan); | ||
207 | containerSpan.appendChild(dateSpan); | ||
208 | containerSpan.appendChild(sizeSpan); | ||
209 | containerSpan.appendChild(clearSpan); | ||
210 | containerSpan.setAttribute("tabindex", 0); | ||
211 | containerSpan.setAttribute("class", "pp-span-all"); | ||
212 | |||
213 | newLi.appendChild(containerSpan); | ||
214 | |||
215 | // Loop through the JSON properties and set them as data attributes on the element | ||
216 | for (var property in jsonObject) { | ||
217 | if (property !== "children") { | ||
218 | var newAttribute = "data-" + property; | ||
219 | newLi.setAttribute(newAttribute, jsonObject[property]); | ||
220 | } | ||
221 | } | ||
222 | |||
223 | |||
224 | // Set element classes | ||
225 | newLi.setAtt |