2 * Copyright (c) 2008,2009 Tobias Sarnowski <sarnowski@new-thoughts.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 function FM_fillTree(searchTerm
)
20 var tree
= document
.getElementById("ManualPageTree");
21 var treec
= document
.getElementById("ManualPageTreeContent");
23 var data
= FM_getList(searchTerm
);
25 if (data
.length
== 0) {
26 FM_showError("nothing found!");
30 for (var n
= 0; n
< data
.length
; n
++) {
31 FM_addManual(data
[n
]["title"], data
[n
]["category"], data
[n
]["description"], data
[n
]["machines"], data
[n
]["aliases"]);
34 treec
= document
.getElementById("ManualPageTreeContent");
36 // if there are only a few results, open alle categories
37 if (data
.length
< 25) {
38 for (var n
= 0; n
< treec
.childNodes
.length
; n
++) {
39 treec
.childNodes
[n
].setAttribute("open", "true");
43 // if it is only 1 category, open it
44 if (treec
.childNodes
.length
== 1) {
45 treec
.childNodes
[0].setAttribute("open", "true");
49 dump("FireMan Exception:\n" + ex
);
53 function FM_clearManualTree()
55 var tree
= document
.getElementById("ManualPageTreeContent");
56 while (tree
.childNodes
.length
> 0) {
57 tree
.removeChild(tree
.childNodes
[0]);
61 function FM_showError(msg
)
65 var tc
= document
.createElement("treecell");
66 tc
.setAttribute("id", "FM-treecell-error");
67 tc
.setAttribute("label", msg
);
68 tc
.setAttribute("src", "chrome://fireman/skin/images/error.png");
70 var tr
= document
.createElement("treerow");
71 tr
.setAttribute("id", "FM-treerow-error");
74 var ti
= document
.createElement("treeitem");
75 ti
.setAttribute("id", "FM-treeitem-error");
78 var tree
= window
.document
.getElementById("ManualPageTreeContent");
82 function FM_addCategory(category
)
89 // prepare the category
90 categorydesc
= FM_getOSCategoryDescription(category
);
92 categorydesc
= category
;
94 categorydesc
= categorydesc
; // + " [" + category + "]";
97 tc
= document
.createElement("treecell");
98 tc
.setAttribute("id", "FM-category-" + category
+ "-treecell");
99 tc
.setAttribute("label", categorydesc
);
100 tc
.setAttribute("src", "chrome://fireman/skin/images/book.png");
102 tr
= document
.createElement("treerow");
103 tr
.setAttribute("id", "FM-category-" + category
+ "-treerow");
106 tch
= document
.createElement("treechildren");
107 tch
.setAttribute("id", "FM-category-" + category
+ "-children");
109 ti
= document
.createElement("treeitem");
110 ti
.setAttribute("id", "FM-category-" + category
);
111 ti
.setAttribute("container", "true");
112 ti
.setAttribute("fm_type", "category");
113 ti
.setAttribute("fm_category", category
);
117 // search the right place to insert
118 var tree
= document
.getElementById("ManualPageTreeContent");
120 var categories
= FM_getOSCategories();
121 var catsToReappend
= new Array();
123 for (var ci
= 0; ci
< tree
.childNodes
.length
; ci
++) {
127 for (ca
in categories
) {
128 if (ca
== category
) {
132 if ("FM-category-" + ca
== tree
.childNodes
[ci
].getAttribute("id")) {
138 catsToReappend
[catsToReappend
.length
] = tree
.childNodes
[ci
];
142 for (ci
= 0; ci
< catsToReappend
.length
; ci
++) {
143 tree
.removeChild(catsToReappend
[ci
]);
145 tree
.appendChild(ti
);
146 for (ci
= 0; ci
< catsToReappend
.length
; ci
++) {
147 tree
.appendChild(catsToReappend
[ci
]);
153 function FM_addManual(title
, category
, description
, machines
, aliases
)
159 // aliases resolution
160 var aliascategory
= FM_getOSCategoryAlias(category
);
162 var tch
= document
.getElementById("FM-category-" + aliascategory
+ "-children");
164 tch
= FM_addCategory(aliascategory
);
167 // add manual to the category
168 tc
= document
.createElement("treecell");
169 tc
.setAttribute("id", "FM-page-" + category
+ "-" + title
+ "-treecell");
170 tc
.setAttribute("label", title
+ " - " + description
);
171 tc
.setAttribute("src", "chrome://fireman/skin/images/page_white_text.png");
173 tr
= document
.createElement("treerow");
174 tr
.setAttribute("id", "FM-page-" + category
+ "-" + title
+ "-treerow");
177 ti
= document
.createElement("treeitem");
178 ti
.setAttribute("id", "FM-page-" + category
+ "-" + title
);
179 ti
.setAttribute("fm_type", "page");
180 ti
.setAttribute("fm_title", title
);
181 ti
.setAttribute("fm_category", category
);
182 ti
.setAttribute("fm_machine", '');
188 if (machines
.length
+ aliases
.length
> 0) {
189 tch
= document
.createElement("treechildren");
190 tch
.setAttribute("id", "FM-page-" + category
+ "-" + title
+ "-children");
192 ti
.setAttribute("container", "true");
195 // add machine specific pages if available
196 for (var n
= 0; n
< machines
.length
; n
++) {
197 tc
= document
.createElement("treecell");
198 tc
.setAttribute("id", "FM-page-" + category
+ "-" + machines
[n
] + "-" + title
+ "-treecell");
199 tc
.setAttribute("label", machines
[n
]);
200 tc
.setAttribute("src", "chrome://fireman/skin/images/page_white_gear.png");
202 tr
= document
.createElement("treerow");
203 tr
.setAttribute("id", "FM-page-" + category
+ "-" + machines
[n
] + "-" + title
+ "-treerow");
206 ti
= document
.createElement("treeitem");
207 ti
.setAttribute("id", "FM-page-" + category
+ "-" + machines
[n
] + "-" + title
);
208 ti
.setAttribute("fm_type", "page");
209 ti
.setAttribute("fm_title", title
);
210 ti
.setAttribute("fm_category", category
);
211 ti
.setAttribute("fm_machine", machines
[n
]);
217 // add aliases if available
218 for (var n
= 0; n
< aliases
.length
; n
++) {
219 tc
= document
.createElement("treecell");
220 tc
.setAttribute("id", "FM-page-" + category
+ "-" + aliases
[n
] + "-" + title
+ "-treecell");
221 tc
.setAttribute("label", aliases
[n
]);
222 tc
.setAttribute("src", "chrome://fireman/skin/images/page_white_get.png");
224 tr
= document
.createElement("treerow");
225 tr
.setAttribute("id", "FM-page-" + category
+ "-" + aliases
[n
] + "-" + title
+ "-treerow");
228 ti
= document
.createElement("treeitem");
229 ti
.setAttribute("id", "FM-page-" + category
+ "-" + aliases
[n
] + "-" + title
);
230 ti
.setAttribute("fm_type", "page");
231 ti
.setAttribute("fm_title", title
);
232 ti
.setAttribute("fm_category", category
);
233 ti
.setAttribute("fm_machine", '');
242 function FM_showMan(tree
)
244 var item
= tree
.view
.getItemAtIndex(tree
.currentIndex
);
246 if (item
.getAttribute("fm_type") != "page") {
247 // categories aren't handled atm
251 var title
= item
.getAttribute("fm_title");
252 var category
= item
.getAttribute("fm_category");
253 var machine
= item
.getAttribute("fm_machine");
256 category
= category
+ "/" + machine
.toLowerCase();
258 var manurl
= "man://" + category
+ "/" + title
;
260 var browser
= top
.document
.getElementById("content");
261 browser
.webNavigation
.loadURI(manurl
, Components
.interfaces
.nsIWebNavigation
,null,null,null);