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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
var Data =
{
assets : new Item,
folderList : [],
};
Data.reset = function() {
this.assets = null;
this.assets = new Item;
this.folderList = [];
this.folderList.push({item : this.assets, id: 0});
};
Data.completed= function(sort) {
if (sort == true)
this.assets.sortPayload();
this.folderList.push({item : this.assets, id: 0});
alert ("Data.completed()= " +this.folderList.length);
};
Data.selectFolder = function (idx) {
this.folderList.push({item : this.getCurrentItem().childs[idx], id: idx});
};
Data.isRootFolder = function() {
if (this.folderList.length == 1)
return true;
else
return false;
};
Data.folderUp = function () {
itm = this.folderList.pop();
return itm.id;
};
Data.addItem = function(t_list, pyld) {
this.assets.addChild(t_list, pyld, 0);
};
Data.dumpFolderStruct = function(){
alert("---------- dumpFolderStruct ------------");
this.assets.print(0);
alert("---------- dumpFolderStruct Done -------");
};
Data.getCurrentItem = function () {
return this.folderList[this.folderList.length-1].item;
};
Data.getVideoCount = function()
{
return this.folderList[this.folderList.length-1].item.childs.length;
};
//-----------------------------------------
function Item() {
this.title = "root";
this.isFolder = true;
this.childs = [];
this.payload = ""; // only set, if (isFolder == false)
}
Item.prototype.isFolder = function() {
return this.isFolder;
};
Item.prototype.getTitle = function () {
return this.title;
};
Item.prototype.getPayload = function () {
if (this.isFolder == true) {
alert("WARNING: getting payload on a folder title=" +this.title);
}
return this.payload;
};
Item.prototype.getItem = function (title) {
for (var i = 0; i < this.childs.length; i++) {
if (this.childs[i].title == title) {
return this.childs[i];
}
}
return 0;
};
Item.prototype.addChild = function (key, pyld, level) {
if (key.length == 1) {
var folder = new Item;
// folder.title = pyld.startstr + " - " + key;
folder.title = key[0];
folder.payload = pyld;
folder.isFolder = false;
this.childs.push(folder);
// this.titles.push({title: pyld.startstr + " - " + key , pyld : pyld});
}
else {
if (level > 10) {
alert(" too many levels");
return;
}
var t = key.shift();
var found = false;
for (var i = 0; i < this.childs.length; i++) {
if (this.childs[i].title == t) {
this.childs[i].addChild(key, pyld, level +1);
found = true;
break;
}
}
if (found == false) {
var folder = new Item;
folder.title = t;
folder.addChild(key, pyld, level+1);
this.childs.push(folder);
}
}
};
Item.prototype.print = function(level) {
var prefix= "";
for (var i = 0; i < level; i++)
prefix += " ";
for (var i = 0; i < this.childs.length; i++) {
alert(prefix + this.childs[i].title);
if (this.childs[i].isFolder == true) {
alert(prefix+"Childs:");
this.childs[i].print(level +1);
}
}
};
Item.prototype.sortPayload = function() {
for (var i = 0; i < this.childs.length; i++) {
if (this.childs[i].isFolder == true) {
this.childs[i].sortPayload();
}
}
this.childs.sort(function(a,b) {
if (a.title == b.title) {
return (b.payload.start - a.payload.start);
}
else {
return ((a.title < b.title) ? -1 : 1);
}
});
};
|