MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mtabbedbasegroup.class
Ir para a documentação deste ficheiro.
1
<?php
2
31
$MIOLO
=
MIOLO::getInstance
();
32
$MIOLO
->page->addScript(
'm_tabbedbasegroup.js'
);
33
34
class
MTabbedBaseGroup
extends
MBaseGroup
35
{
36
private
$tabs;
37
44
public
function
__construct
(
$name
, $tabs = array(), $scrollToTop =
true
)
45
{
46
$controls
[] =
new
MDiv
(
"{$name}DivResponse"
);
47
parent::__construct(
$name
);
48
$this->tabs = $tabs;
49
$this->
setBoxClass
(
'm-tabbed-base-group'
);
50
51
if
( !$scrollToTop )
52
{
53
$MIOLO
=
MIOLO::getInstance
();
54
self::AddJsCode(
"scrollToTop = false"
);
55
}
56
}
57
67
public
function
createTab
(
$id
,
$label
,
$controls
= array(), $disabled =
false
)
68
{
69
$tab =
new
MTab
(
$id
,
$label
,
$controls
, $disabled);
70
if
( strpos(
MIOLO::getInstance
()->getTheme()->
id
,
"sbootstrap"
) ===
false
)
71
{
72
$tab->addBoxStyle(
'width'
,
'100%'
);
73
$tab->addBoxStyle(
'display'
,
'none'
);
74
}
75
76
$this->tabs[
$id
] = $tab;
77
}
78
93
public
static
function
createStaticTab
($tabbedBaseGroupId,
$id
,
$label
,
$controls
= array(), $disabled =
false
)
94
{
95
$tab =
new
MTab
(
$id
,
$label
,
$controls
, $disabled);
96
$tab->addBoxStyle(
'width'
,
'100%'
);
97
$tab->addBoxStyle(
'display'
,
'none'
);
98
99
list($button, $tabJs) =
self::getTabButton
($tab, $tabbedBaseGroupId);
100
$bGenerate = $button->generate();
101
$bGenerate = str_replace(
"\n"
,
'\n'
, $bGenerate);
102
$bGenerate = str_replace(
"'"
,
"\'"
, $bGenerate);
103
104
$dGenerate = $tab->generate();
105
$dGenerate = str_replace(
"\n"
,
'\n'
, $dGenerate);
106
$dGenerate = str_replace(
"'"
,
"\'"
, $dGenerate);
107
108
$js =
"MIOLO_GetElementById('buttons{$tabbedBaseGroupId}').innerHTML += '$bGenerate'; "
;
109
$js .=
"MIOLO_GetElementById('{$tabbedBaseGroupId}').innerHTML += '$dGenerate';"
;
110
$js .=
"{$tabbedBaseGroupId}Tabs[{$tabbedBaseGroupId}Tabs.length] = '{$id}';"
;
111
$js .=
"mtabbedbasegroup.changeTab('{$id}','{$tabbedBaseGroupId}');"
;
112
$js .= $tabJs;
113
114
self::addJsCode($js);
115
//$MIOLO->ajax->setResponse(NULL, "{$tabbedBaseGroupId}DivResponse");
116
}
117
121
public
function
getTabs
()
122
{
123
return
$this->tabs;
124
}
125
129
public
function
setTabs
($tabs = array())
130
{
131
$this->tabs = $tabs;
132
}
133
137
public
function
addTab
($tab)
138
{
139
$this->tabs[$tab->id] = $tab;
140
}
141
145
public
function
getTab
($tabId)
146
{
147
return
$this->tabs[$tabId];
148
}
149
155
protected
function
getTabButton
($tab, $tabbedBaseGroupId, $selected =
false
)
156
{
157
$MIOLO
=
MIOLO::getInstance
();
158
159
$tempDiv =
new
MDiv
($tab->id .
'Button'
, $tab->label);
160
161
if
( !$tab->disabled )
162
{
163
$tempDiv->setBoxClass(!$selected ?
'm-tab m-tab-idle'
:
'm-tab m-tab-active'
);
164
165
$changeTabJs =
"mtabbedbasegroup.changeTab('{$tab->id}', '$tabbedBaseGroupId');"
;
166
167
$tempDiv->getBox()->addAttribute(
'onclick'
, $changeTabJs);
168
169
if
( $selected )
170
{
171
$tab->addBoxStyle(
'display'
,
'block'
);
172
$jsCode = $changeTabJs;
173
}
174
}
175
else
176
{
177
$tempDiv->setBoxClass(
'm-tab m-tab-disabled'
);
178
}
179
180
return
array($tempDiv, $jsCode);
181
}
182
188
public
function
generate
()
189
{
190
$MIOLO
=
MIOLO::getInstance
();
191
192
if
( strpos(
MIOLO::getInstance
()->getTheme()->
id
,
"sbootstrap"
) !==
false
)
193
{
194
return
$this->
generateBootstrap
();
195
}
196
197
$jsCode =
"{$this->name}Tabs = new Array(); \n"
;
198
$index = 0;
199
200
$tabButtons = array();
201
202
foreach
( $this->tabs as $tab )
203
{
204
$this->
addControl
($tab);
205
$jsCode .=
"{$this->name}Tabs[{$index}] = '{$tab->id}';\n"
;
206
207
list($tabButtons[$tab->id], $tabJs) = $this->
getTabButton
($tab, $this->name, $index == 0 ?
true
:
false
);
208
209
$jsCode .= $tabJs;
210
211
$index++;
212
}
213
214
$divButtons =
new
MDiv
(
"buttons{$this->name}"
, $tabButtons);
215
$divButtons->setBoxClass(
'm-tab-buttons'
);
216
217
// Shows only the current tab
218
self::addJsCode($jsCode);
219
220
$buttonContainer =
new
MHContainer
(
"tabButtonContainer{$this->name}"
, array($divButtons));
221
222
return
$buttonContainer->generate() . parent::generate();
223
}
224
225
public
function
generateBootstrap
()
226
{
227
$first =
true
;
228
$htmlHead =
""
;
229
$htmlBody =
""
;
230
foreach
( $this->tabs as $tab )
231
{
232
$tabBtn =
'tab'
. trim($tab->name,
'tab'
) .
'Button'
;
233
234
$label
= $tab->label;
235
if
(
$label
instanceof
MControl
)
236
{
237
$label
=
$label
->generate();
238
}
239
240
if
($first)
241
{
242
$htmlHead .=
"<li class='m-tab nav-item'>
243
<a href='#"
. $tabBtn .
"' data-toggle='tab' data-bs-target='#{$tabBtn}' data-bs-toggle='tab' class='nav-link active'>"
.
$label
.
"</a>
244
</li>"
;
245
246
$htmlBody .=
"<div class='tab-pane active' id='"
. $tabBtn .
"'>
247
"
. $tab->generate() .
"
248
</div>"
;
249
250
$first =
false
;
251
}
252
else
253
{
254
$htmlHead .=
"<li class='m-tab nav-item'>
255
<a href='#"
. str_replace(
' '
,
'_'
, $tabBtn) .
"' data-toggle='tab' data-bs-target='#"
. str_replace(
' '
,
'_'
, $tabBtn) .
"' data-bs-toggle='tab' class='nav-link'>"
.
$label
.
"</a>
256
</li>"
;
257
258
$htmlBody .=
"<div class='tab-pane' id='"
. str_replace(
' '
,
'_'
, $tabBtn) .
"'>
259
"
. $tab->generate() .
"
260
</div>"
;
261
}
262
}
263
264
$return =
"<div class='m-new-container' style='width: 100%'>
265
<ul class='nav nav-tabs'>"
.
266
$htmlHead .
"
267
</ul>
268
<div class='tab-content m-tab-content'>"
. $htmlBody .
"</div>
269
</div>"
;
270
271
return
$return;
272
}
273
274
/* Static methods to use on ajax requests */
275
282
public
static
function
enableTab
($tabId, $tabbedBaseGroupId)
283
{
284
$jsCode =
"mtabbedbasegroup.enableTab('{$tabId}', '{$tabbedBaseGroupId}');"
;
285
286
self::addJsCode($jsCode);
287
}
288
295
public
static
function
disableTab
($tabId, $tabbedBaseGroupId)
296
{
297
$jsCode =
"mtabbedbasegroup.disableTab('{$tabId}', '{$tabbedBaseGroupId}');"
;
298
299
self::addJsCode($jsCode);
300
}
301
308
public
static
function
removeTab
($tabId, $tabbedBaseGroupId)
309
{
310
self::addJsCode(
"mtabbedbasegroup.removeTab('{$tabId}','{$tabbedBaseGroupId}');"
);
311
}
312
319
public
static
function
updateTab
($tabId,
$controls
)
320
{
321
$MIOLO
=
MIOLO::getInstance
();
322
$container =
new
MVContainer
(
"ajaxFields$tabId"
,
$controls
,
MFormControl::FORM_MODE_SHOW_SIDE
);
323
}
324
330
private
static
function
addJsCode($jsCode)
331
{
332
$MIOLO
=
MIOLO::getInstance
();
333
334
if
(
$MIOLO
->page->request(
'cpaint_function'
) !=
''
)
335
{
336
$MIOLO
->page->addAJAXJsCode($jsCode);
337
}
338
else
339
{
340
$MIOLO
->page->onload($jsCode);
341
}
342
}
343
}
344
372
class
MTab
extends
MFormContainer
373
{
374
public
$label
;
375
public
$disabled
;
376
386
public
function
__construct
(
$id
,
$label
,
$controls
,
$disabled
=
false
)
387
{
388
parent::__construct(
$id
,
$controls
);
389
$this->label =
$label
;
390
$this->disabled =
$disabled
;
391
$this->
getBox
()->setClass(
'm-new-tab-content'
);
392
}
393
397
public
function
setEnabled
()
398
{
399
$this->disabled =
false
;
400
}
401
405
public
function
setDisabled
()
406
{
407
$this->disabled =
true
;
408
}
409
}
410
?>
MBaseGroup
Definição
groupcontrols.class:4
MComponent\$name
$name
Definição
mcomponent.class:17
MControl
Definição
mcontrol.class:35
MControl\addControl
addControl($control)
Definição
mcontrol.class:652
MControl\getBox
getBox()
Definição
mcontrol.class:778
MControl\setBoxClass
setBoxClass( $cssClass, $add=true)
Definição
mcontrol.class:797
MControl\$controls
$controls
Definição
mcontrol.class:163
MControl\FORM_MODE_SHOW_SIDE
const FORM_MODE_SHOW_SIDE
Definição
mcontrol.class:42
MControl\$id
$id
Definição
mcontrol.class:69
MDiv
Definição
blockcontrols.class:23
MFormContainer
Definição
mcontainer.class:237
MFormControl\$label
$label
Definição
mformcontrol.class:5
MHContainer
Definição
mcontainer.class:193
MIOLO\getInstance
static getInstance()
Definição
miolo.class:134
MTab
Definição
mtabbedbasegroup.class:373
MTab\$label
$label
Definição
mtabbedbasegroup.class:374
MTab\$disabled
$disabled
Definição
mtabbedbasegroup.class:375
MTab\__construct
__construct($id, $label, $controls, $disabled=false)
Definição
mtabbedbasegroup.class:386
MTab\setEnabled
setEnabled()
Definição
mtabbedbasegroup.class:397
MTab\setDisabled
setDisabled()
Definição
mtabbedbasegroup.class:405
MTabbedBaseGroup
Definição
mtabbedbasegroup.class:35
MTabbedBaseGroup\createStaticTab
static createStaticTab($tabbedBaseGroupId, $id, $label, $controls=array(), $disabled=false)
Definição
mtabbedbasegroup.class:93
MTabbedBaseGroup\getTab
getTab($tabId)
Definição
mtabbedbasegroup.class:145
MTabbedBaseGroup\getTabs
getTabs()
Definição
mtabbedbasegroup.class:121
MTabbedBaseGroup\setTabs
setTabs($tabs=array())
Definição
mtabbedbasegroup.class:129
MTabbedBaseGroup\enableTab
static enableTab($tabId, $tabbedBaseGroupId)
Definição
mtabbedbasegroup.class:282
MTabbedBaseGroup\generate
generate()
Definição
mtabbedbasegroup.class:188
MTabbedBaseGroup\getTabButton
getTabButton($tab, $tabbedBaseGroupId, $selected=false)
Definição
mtabbedbasegroup.class:155
MTabbedBaseGroup\createTab
createTab($id, $label, $controls=array(), $disabled=false)
Definição
mtabbedbasegroup.class:67
MTabbedBaseGroup\removeTab
static removeTab($tabId, $tabbedBaseGroupId)
Definição
mtabbedbasegroup.class:308
MTabbedBaseGroup\disableTab
static disableTab($tabId, $tabbedBaseGroupId)
Definição
mtabbedbasegroup.class:295
MTabbedBaseGroup\__construct
__construct($name, $tabs=array(), $scrollToTop=true)
Definição
mtabbedbasegroup.class:44
MTabbedBaseGroup\addTab
addTab($tab)
Definição
mtabbedbasegroup.class:137
MTabbedBaseGroup\updateTab
static updateTab($tabId, $controls)
Definição
mtabbedbasegroup.class:319
MTabbedBaseGroup\generateBootstrap
generateBootstrap()
Definição
mtabbedbasegroup.class:225
MVContainer
Definição
mcontainer.class:185
$MIOLO
$MIOLO
Definição
mtabbedbasegroup.class:31
classes
ui
controls
mtabbedbasegroup.class
Gerado por
1.10.0