1 |
Module("JooseX.IDE", function () { |
2 |
Class("ClassBrowser", { |
3 |
classMethods: { |
4 |
test: function () { return "I am just a test" } |
5 |
}, |
6 |
methods: { |
7 |
|
8 |
$: function (id) { |
9 |
return document.getElementById(id) |
10 |
}, |
11 |
|
12 |
initialize: function () { |
13 |
this.fillSelect( |
14 |
this.moduleSelect(), |
15 |
Joose.A.grep(Joose.Module.getAllModules(), function (m) { return !m.meta.isEmpty() }), |
16 |
true |
17 |
) |
18 |
}, |
19 |
|
20 |
getNames: function (array) { |
21 |
var names = []; |
22 |
Joose.A.each(array, function (ele) { names.push(ele.meta.getName()) }); |
23 |
return names |
24 |
}, |
25 |
|
26 |
fillSelect: function (select, array, useMeta) { |
27 |
|
28 |
select.innerHTML = "" |
29 |
|
30 |
var options = [] |
31 |
|
32 |
Joose.O.each(array, function (thing) { |
33 |
var option = document.createElement("option"); |
34 |
var name = thing.name; |
35 |
if(thing.getName) { |
36 |
name = thing.getName() |
37 |
} |
38 |
if(useMeta) { |
39 |
name = thing.meta.getName() |
40 |
} |
41 |
option.innerHTML = name |
42 |
option.valueObject = thing |
43 |
options.push(option) |
44 |
}) |
45 |
Joose.A.each(options, function (option) { select.appendChild(option) }) |
46 |
}, |
47 |
|
48 |
clearSelect: function (select) { |
49 |
select.innerHTML = ""; |
50 |
}, |
51 |
|
52 |
selectedModule: function (select) { |
53 |
var module = this.selectedValueObject(select); |
54 |
this.fillSelect(this.classSelect(), module.meta.getElements(), true) |
55 |
this.clearBody() |
56 |
this.clearSelect(this.categoriesSelect()) |
57 |
this.clearSelect(this.elementsSelect()) |
58 |
}, |
59 |
|
60 |
selectedClass: function (select) { |
61 |
var c = this.selectedValueObject(select); |
62 |
this.fillSelect(this.categoriesSelect(), [ |
63 |
{c: c, name: "Instance Methods"}, |
64 |
{c: c, name: "Class Methods"}, |
65 |
{c: c, name: "Attributes"} |
66 |
]) |
67 |
|
68 |
var html = "<p><strong>"+c.meta.className()+"</strong></p>" |
69 |
html += "<ul>" |
70 |
html += "<li>Super Classes: "+c.meta.getSuperClasses()+"</li>" |
71 |
html += "<li>Roles: "+c.meta.getRoles()+"</li>" |
72 |
html += "</ul>" |
73 |
|
74 |
if(c.meta.renderHTML) { |
75 |
html += "<p>"+c.meta.renderHTML()+"</p>" |
76 |
} |
77 |
|
78 |
this.$('JooseCBBody').innerHTML = html |
79 |
}, |
80 |
|
81 |
clearBody: function () { |
82 |
this.$('JooseCBBody').innerHTML = "" |
83 |
}, |
84 |
|
85 |
selectedCategory: function (select) { |
86 |
var cat = this.selectedValueObject(select); |
87 |
var c = cat.c |
88 |
if(cat.name == "Instance Methods") { |
89 |
this.fillSelect(this.elementsSelect(), c.meta.getInstanceMethods()) |
90 |
} |
91 |
if(cat.name == "Class Methods") { |
92 |
this.fillSelect(this.elementsSelect(), c.meta.getClassMethods()) |
93 |
} |
94 |
if(cat.name == "Attributes") { |
95 |
this.fillSelect(this.elementsSelect(), c.meta.getAttributes()) |
96 |
} |
97 |
}, |
98 |
|
99 |
selectedElement: function (select) { |
100 |
var ele = this.selectedValueObject(select); |
101 |
var html = ""; |
102 |
|
103 |
html += "<p><strong>"+ele.getName()+"</strong></p>" |
104 |
|
105 |
if(ele.meta.isa(Joose.Method)) { |
106 |
html += "<pre>"+ele.getBody().toString()+"</pre>" |
107 |
} |
108 |
else if(ele.meta.isa(Joose.Attribute)) { |
109 |
html += "<ul>" |
110 |
Joose.O.each(ele.getProps(), function (value, name) { |
111 |
html += "<li>"+name+": "+value+"</li>" |
112 |
}) |
113 |
html += "</ul>" |
114 |
} |
115 |
|
116 |
|
117 |
this.$('JooseCBBody').innerHTML = html |
118 |
}, |
119 |
|
120 |
selectedValueObject: function (select) { |
121 |
return select.options[select.selectedIndex].valueObject |
122 |
}, |
123 |
|
124 |
elementsSelect: function () { |
125 |
return this.$('JooseCBElementsSelect') |
126 |
}, |
127 |
|
128 |
categoriesSelect: function () { |
129 |
return this.$('JooseCBCategoriesSelect') |
130 |
}, |
131 |
|
132 |
classSelect: function () { |
133 |
return this.$('JooseCBClassesSelect') |
134 |
}, |
135 |
|
136 |
moduleSelect: function () { |
137 |
return this.$('JooseCBModulesSelect') |
138 |
} |
139 |
} |
140 |
}) |
141 |
}) |