Main.js
3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Ext.define('KitchenSink.controller.Main', {
extend: 'Ext.app.Controller',
stores: [
'Examples',
'Companies',
'Restaurants',
'States',
'TreeStore'
],
views: [
'Viewport',
'Header'
],
refs: [
{
ref: 'examplePanel',
selector: '#examplePanel'
},
{
ref: 'exampleList',
selector: 'exampleList'
}
],
init: function() {
this.control({
'viewport exampleList': {
'select': function(me, record, item, index, e) {
if (!record.isLeaf()) {
return;
}
this.setActiveExample(this.classNameFromRecord(record), record.get('text'));
},
afterrender: function(){
var me = this,
className, exampleList, name, record;
setTimeout(function(){
className = location.hash.substring(1);
exampleList = me.getExampleList();
if (className) {
name = className.replace('-', ' ');
record = exampleList.view.store.find('text', name);
} else {
record = exampleList.view.store.find('text', 'grouped header grid');
}
exampleList.view.select(record);
}, 0);
}
}
});
},
setActiveExample: function(className, title) {
var examplePanel = this.getExamplePanel(),
path, example, className;
if (!title) {
title = className.split('.').reverse()[0];
}
//update the title on the panel
examplePanel.setTitle(title);
//remember the className so we can load up this example next time
location.hash = title.toLowerCase().replace(' ', '-');
//set the browser window title
document.title = document.title.split(' - ')[0] + ' - ' + title;
//create the example
example = Ext.create(className);
//remove all items from the example panel and add new example
examplePanel.removeAll();
examplePanel.add(example);
},
// Will be used for source file code
// loadExample: function(path) {
// Ext.Ajax.request({
// url: path,
// success: function() {
// console.log(Ext.htmlEncode(response.responseText));
// }
// });
// },
filePathFromRecord: function(record) {
var parentNode = record.parentNode,
path = record.get('text');
while (parentNode && parentNode.get('text') != "Root") {
path = parentNode.get('text') + '/' + Ext.String.capitalize(path);
parentNode = parentNode.parentNode;
}
return this.formatPath(path);
},
classNameFromRecord: function(record) {
var path = this.filePathFromRecord(record);
path = 'KitchenSink.view.examples.' + path.replace('/', '.');
return path;
},
formatPath: function(string) {
var result = string.split(' ')[0].charAt(0).toLowerCase() + string.split(' ')[0].substr(1),
paths = string.split(' '),
ln = paths.length,
i;
for (i = 1; i < ln; i++) {
result = result + Ext.String.capitalize(paths[i]);
}
return result;
}
});