caixaDeFerramentas.js
6.1 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
if (typeof (i3GEO) === 'undefined') {
var i3GEO = {};
}
i3GEO.caixaDeFerramentas = {
MIGALHA: [],
config: {
"idOndeFolder": "listaFerramentas",
"idOndeLinks": "listaFerramentasLinks",
"idOndeMigalha": "migalhaFerramentas",
"templateFolder" : "templates/ferramentasFolder.html",
"templateMigalha" : "templates/ferramentasMigalha.html",
"templateLinks" : "templates/ferramentasLink.html"
},
carregaTemplates: function(){
var t1 = i3GEO.caixaDeFerramentas.config.templateFolder,
t2 = i3GEO.caixaDeFerramentas.config.templateLinks,
t3 = i3GEO.caixaDeFerramentas.config.templateMigalha;
$.when( $.get(t1),$.get(t2),$.get(t3) ).done(function(r1,r2,r3) {
i3GEO.template.ferramentasFolder = r1[0];
i3GEO.template.ferramentasLinks = r2[0];
i3GEO.template.ferramentasMigalha = r3[0];
i3GEO.caixaDeFerramentas.inicia();
}).fail(function() {
i3GEO.janela.closeMsg($trad("erroTpl"));
return;
});
},
aguarde: function(){
//$("#" + i3GEO.caixaDeFerramentas.config.idFolder).html($trad("o1"));
},
inicia : function(config){
if(config){
$.each( config, function( i,v ) {
i3GEO.caixaDeFerramentas.config[i] = v;
});
}
i3GEO.caixaDeFerramentas.aguarde();
if(!i3GEO.template.ferramentasFolder || !i3GEO.template.ferramentasLinks || !i3GEO.template.ferramentasMigalha){
i3GEO.caixaDeFerramentas.carregaTemplates();
return;
} else {
i3GEO.caixaDeFerramentas.nivel0();
}
},
migalha: function (data){
var f = i3GEO.caixaDeFerramentas.config;
var t = Mustache.to_html(
i3GEO.template.ferramentasMigalha,
{"nome":data.nome}
);
$("#" + f.idOndeMigalha)
.data(data)
.html(t)
.click(function(event){
var f = i3GEO.caixaDeFerramentas.config;
event.stopImmediatePropagation();
$("#" + f.idOndeMigalha).off("click");
var data = $(this).data();
if((data.nivel - 1) == 0){
f.idOndeFolder.fadeOut( "fast", function(){
i3GEO.caixaDeFerramentas.nivel0();
i3GEO.caixaDeFerramentas.config.idOndeFolder.show();
});
}
if((data.nivel - 1) == 1){
f.idOndeFolder.fadeOut( "fast", function(){
i3GEO.caixaDeFerramentas.nivel1(data);
i3GEO.caixaDeFerramentas.config.idOndeFolder.show();
});
}
if((data.nivel - 1) == 2){
f.idOndeFolder.fadeOut( "fast", function(){
i3GEO.caixaDeFerramentas.nivel2(data);
i3GEO.caixaDeFerramentas.config.idOndeFolder.show();
});
}
});
},
nivel0 : function(){
var confm = i3GEO.listaDeFerramentas,
subs = i3GEO.listaDeFerramentas.submenus,
menu = confm.menu,
n = menu.length,
f = i3GEO.caixaDeFerramentas.config,
i,t,data;
$("#" + f.idOndeMigalha).html(" ");
f.idOndeFolder.html("");
f.idOndeLinks.html("");
for (i = 0; i < n; i += 1) {
if(subs[menu[i].id].length > 0){
t = Mustache.to_html(
i3GEO.template.ferramentasFolder,
{"nome":menu[i].nome,"descricao":menu[i].descricao}
);
t = $(t);
//quando clica, abre o nivel 1 e muda a migalha
data = {"nivel":1,"nome":menu[i].nome,"id":i,"n0": i, "n1":"", "n2": "", "n3": ""};
t.find("a")
.data(data)
.click(function(){
$(this).find("a").off("click");
var data = $(this).data();
//texto da migalha e evento click
i3GEO.caixaDeFerramentas.config.idOndeFolder.fadeOut( "fast", function(){
i3GEO.caixaDeFerramentas.nivel1(data);
i3GEO.caixaDeFerramentas.config.idOndeFolder.show();
});
});
i3GEO.caixaDeFerramentas.config.idOndeFolder
.append(t);
}
}
},
nivel1 : function(data){
var confm = i3GEO.listaDeFerramentas,
menu = confm.submenus[confm.menu[data.n0].id],
n = menu.length,
f = i3GEO.caixaDeFerramentas.config,
i,t,datan;
f.idOndeFolder.html("");
f.idOndeLinks.html("");
for (i = 0; i < n; i += 1) {
datan = {"nivel":2,"nome":menu[i].text,"id":menu[i].id,"n0": data.n0, "n1":i, "n2": "", "n3": ""};
if(menu[i].url){
t = Mustache.to_html(
i3GEO.template.ferramentasLinks,
{"nome":menu[i].text,"target": menu[i].target,"url": menu[i].url,"opcional": menu[i].opcional}
);
t = $(t);
f.idOndeLinks
.append(t);
} else {
t = Mustache.to_html(
i3GEO.template.ferramentasFolder,
{"nome":menu[i].text}
);
t = $(t);
t.find("a")
.data(datan)
.click(function(){
$(this).find("a").off("click");
var data = $(this).data();
var f = i3GEO.caixaDeFerramentas.config;
var t = Mustache.to_html(
i3GEO.template.ferramentasMigalha,
data
);
//texto da migalha e evento click
//nivel2(data);
f.idOndeFolder.fadeOut( "fast", function(){i3GEO.caixaDeFerramentas.nivel2(data);f.idOndeFolder.show();});
});
f.idOndeFolder
.append(t);
}
}
data.nivel = 1;
data.nome = confm.menu[data.id].nome;
data.n0 = data.id;
i3GEO.caixaDeFerramentas.migalha(data);
},
nivel2 : function(data){
var confm = i3GEO.listaDeFerramentas,
menu = confm.submenus[confm.menu[data.n0].id][data.n1].submenu.itemdata[0],
n = menu.length,
f = i3GEO.caixaDeFerramentas.config,
i,t,datan;
f.idOndeFolder.html("");
f.idOndeLinks.html("");
for (i = 0; i < n; i += 1) {
datan = {"nivel":3,"nome":menu[i].text,"id":menu[i].id,"n0": data.n0, "n1":data.n1, "n2": i, "n3": ""};
if(menu[i].url){
t = Mustache.to_html(
i3GEO.template.ferramentasLinks,
{"nome":menu[i].text,"target": menu[i].target,"url": menu[i].url,"opcional": menu[i].opcional}
);
t = $(t);
f.idOndeLinks
.append(t);
} else {
t = Mustache.to_html(
i3GEO.template.ferramentasFolder,
{"nome":menu[i].text}
);
t = $(t);
t.find("a")
.data(datan)
.click(function(){
$(this).find("a").off("click");
var data = $(this).data();
var t = Mustache.to_html(
i3GEO.caixaDeFerramentas.config.templateMigalha,
data
);
});
f.idOndeFolder
.append(t);
}
}
data.nivel = 2;
data.id = data.n0;
i3GEO.caixaDeFerramentas.migalha(data);
}
};