MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mpopup.class
Ir para a documentação deste ficheiro.
1
<?php
2
27
$MIOLO
=
MIOLO::getInstance
();
28
$MIOLO
->page->addScript(
'm_popup_control.js'
);
29
$MIOLO
->page->addScript(
'm_lookup.js'
);
30
31
class
MPopup
extends
MDiv
32
{
33
const
CONTAINER_ID
=
'mPopupResponse'
;
34
const
PROMPT_FIELD_ID
=
'mPopupPromptField'
;
35
const
POPUP_GRANDE
=
'modal-lg'
;
36
const
POPUP_MEIDA
=
'modal-md'
;
37
const
POPUP_PEQUENA
=
'modal-sm'
;
38
39
43
public
$content
;
44
48
public
$title
;
49
53
private
$showCloseButton =
true
;
54
55
private
$modalSize =
self::POPUP_GRANDE
;
56
64
public
function
__construct
(
$name
,
$content
,
$title
, $closeBtn =
true
)
65
{
66
parent::__construct(
'mPopup'
, NULL,
'm-popup-inner'
);
67
68
$this->name =
$name
;
69
$this->content =
$content
;
70
$this->title =
$title
;
71
$this->showCloseButton = $closeBtn;
72
}
73
80
public
static
function
getPopupContainer
()
81
{
82
return
new
MDiv
(self::CONTAINER_ID, NULL);
83
}
84
92
private
static
function
getTitle(
$title
, $closeButton =
true
)
93
{
94
$fields[] =
new
MDiv
(
''
,
$title
,
'm-popup-title'
);
95
96
if
( $closeButton )
97
{
98
$attributes
[
'onclick'
] =
'mpopup.remove();'
;
99
$fields[] =
new
MDiv
(
'mPopupClose'
, NULL,
'm-popup-close'
,
$attributes
);
100
}
101
return
new
MDiv
(
'popupTitle'
, $fields,
'm-box-title m-popup-title-div'
);
102
}
103
113
private
static
function
getFields(
$name
,
$content
, $label, $closeButton=
true
)
114
{
115
$body =
new
MContainer
(
$name
,
$content
,
'vertical'
,
MFormControl::FORM_MODE_SHOW_NBSP
);
116
$body->setClass(
'm-popup-body'
);
117
$container =
new
MContainer
(NULL, array( self::getTitle($label, $closeButton), $body ),
'vertical'
,
MFormControl::FORM_MODE_SHOW_SIDE
);
118
$container->addBoxStyle(
'width'
,
'100%'
);
119
120
return
$container;
121
}
122
131
protected
static
function
getPromptFields
($message,
$action
, $defaultValue)
132
{
133
$fields[] =
new
MLabel
($message);
134
$fields[] =
new
MTextField
(self::PROMPT_FIELD_ID, $defaultValue,
null
);
135
136
$buttons[] =
new
MButton
(
'btnConfirm'
, _M(
'OK'
),
$action
);
137
$fields[] =
new
MDiv
(NULL, $buttons,
'm-popup-buttons-div'
);
138
139
return
$fields;
140
}
141
149
protected
static
function
getAlertFields
($message,
$action
)
150
{
151
$fields[] =
new
MLabel
($message);
152
$buttons[] =
new
MButton
(
'btnConfirm'
, _M(
'OK'
),
$action
);
153
$fields[] =
new
MDiv
(NULL, $buttons,
'm-popup-buttons-div'
);
154
return
$fields;
155
}
156
165
protected
static
function
getConfirmFields
($message =
null
, $actionYes =
null
, $actionNo =
null
, $field =
null
)
166
{
167
$fields[] =
new
MLabel
($message);
168
$fields[] = $field;
169
$buttons[] =
new
MButton
(
'btnRefuse'
, _M(
'No'
), $actionNo);
170
$buttons[] =
new
MButton
(
'btnConfirm'
, _M(
'Yes'
), $actionYes);
171
$fields[] =
new
MDiv
(NULL, $buttons,
'm-popup-buttons-div'
);
172
return
$fields;
173
}
174
181
private
static
function
getRendered(
$inner
)
182
{
183
$background =
new
MDiv
(
'mPopupBackground'
);
184
185
$div =
new
MDiv
(
'mPopupAnchor'
,
$inner
);
186
//$table = '<table id="mPopup"><tr><td>' . $inner . '</td></tr></table>';
187
return
$background->generate() . $div->generate();
// . $table;
188
}
189
198
public
static
function
prompt
($message, $label = NULL,
$action
=
':promptConfirmation'
, $defaultValue = NULL)
199
{
200
self::show
(
'mPopupPrompt'
, self::getPromptFields($message,
$action
, $defaultValue), $label);
201
}
202
210
public
static
function
alert
($message, $label = NULL,
$action
=
'javascript:mpopup.remove();'
)
211
{
212
self::show
(
'mPopupAlert'
, self::getAlertFields($message,
$action
), $label);
213
}
214
223
public
static
function
confirm
($message, $label = NULL, $actionYes = NULL, $actionNo =
'javascript:mpopup.remove();'
)
224
{
225
self::show
(
'mPopupConfirm'
, self::getConfirmFields($message, $actionYes, $actionNo), $label);
226
}
227
236
public
static
function
show
(
$name
,
$content
, $label, $closeButton=
true
, $focusField = NULL, $ajax =
true
, $class =
""
, $modalSize = self::POPUP_GRANDE)
237
{
238
if
( strpos(
MIOLO::getInstance
()->getTheme()->
id
,
"sbootstrap"
) !==
false
)
239
{
240
$popup =
self::generateBootstrap
(
$name
,
$content
, $label, $closeButton, $class, $modalSize);
241
}
242
else
243
{
244
$inner
=
new
MDiv
(
'mPopup'
, self::getFields(
$name
,
$content
, $label, $closeButton),
'm-popup-inner'
);
245
$popup = self::getRendered(
$inner
->generate());
246
}
247
248
$functionJs = ($ajax) ?
'addAjaxJSCode'
:
'addJsCode'
;
249
250
$MIOLO
=
MIOLO::getInstance
();
251
$focusField = $focusField == NULL ?
'null'
:
"'$focusField'"
;
252
253
if
( strpos(
MIOLO::getInstance
()->getTheme()->
id
,
"sbootstrap"
) ===
false
)
254
{
255
$MIOLO
->page->$functionJs(
" setTimeout(function() { mpopup.configureClose(); mpopup.show($focusField); }, 0);"
);
256
}
257
258
echo $popup;
259
}
260
261
public
static
function
generateBootstrap
(
$name
,
$content
, $label, $closeButton, $class, $modalSize = self::POPUP_GRANDE)
262
{
263
$innerDiv =
new
MContainer
(
$name
,
$content
,
'vertical'
,
MFormControl::FORM_MODE_SHOW_NBSP
);
264
$innerDiv->setClass(
'm-modal-bootstrap'
);
265
266
// Criei um interval, para garantir que popups que abrem sozinhos sejam abertos automaticamente, nem que demore um pouco
267
MIOLO::getInstance
()->getPage()->addAJAXJsCode(
"
268
setTimeout(showPopupBootstrap, 500);
269
270
document.addEventListener('DOMContentLoaded', function(e) {
271
setTimeout(showPopupBootstrap, 500);
272
$('#modalCloseButton_{$name}').click(function() {
273
$('#divSaguMessages').attr('style', 'display: none');
274
});
275
});
276
277
function showPopupBootstrap() {
278
$('#modal_{$name}').modal({
279
backdrop: 'static',
280
keyboard: false
281
});
282
$('#modal_{$name}').modal('show');
283
$('#modal_{$name}').css('display', 'block');
284
$('#modal_{$name}').on('hidden.bs.modal', function () {
285
$('#modal_{$name}').html('');
286
});
287
ajustarVisualizacaoDoTema();
288
}
289
"
);
290
291
return
292
'<div class="modal fade '
.$class.
'" id="modal_'
.
$name
.
'" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
293
<div class="modal-dialog modal-lg '
.$modalSize.
'">
294
<div class="modal-content">
295
<div class="modal-header">
296
<h4 class="modal-title" id="modalTitle_'
.
$name
.
'">'
. $label .
'</h4>
297
<button id="modalCloseButton_'
.$name.
'" type="button" class="close btn-close" data-bs-dismiss="modal" aria-label="Fechar" title="Fechar" onclick="mpopup.remove(); $(\'#divSaguMessages\').hide();"><span aria-hidden="true">×</span></button>
298
</div>
299
<div class="modal-content modal-body">
300
'
. $innerDiv->generate() .
'
301
</div>
302
</div>
303
</div>
304
</div>'
;
305
306
}
307
311
public
static
function
remove
()
312
{
313
$MIOLO
=
MIOLO::getInstance
();
314
if
( (
$MIOLO
->page->request(
'cpaint_function'
) ) !=
""
)
315
{
316
$MIOLO
->page->addAJAXJsCode(
"mpopup.remove();"
);
317
}
318
else
319
{
320
$MIOLO
->page->onload(
"mpopup.remove();"
);
321
}
322
}
323
327
public
function
setShowCloseButton
($showCloseButton)
328
{
329
$this->showCloseButton = $showCloseButton;
330
}
331
335
public
function
getShowCloseButton
()
336
{
337
return
$this->showCloseButton;
338
}
339
340
public
function
generate
()
341
{
342
$fields = self::getFields($this->name, $this->content, $this->title, $this->showCloseButton);
343
$this->
setInner
($fields);
344
345
$jsCode =
"mpopup.configureClose();"
;
346
if
($this->showCloseButton ===
false
)
347
{
348
$jsCode =
""
;
349
}
350
351
if
( strpos(
MIOLO::getInstance
()->getTheme()->
id
,
"sbootstrap"
) !==
false
)
352
{
353
return
self::generateBootstrap
($this->name, $this->content, $this->title, $this->showCloseButton,
''
, $this->modalSize);
354
}
355
else
356
{
357
// Check if it is AJAX
358
if
(
MIOLO::_REQUEST
(
'cpaint_function'
) )
359
{
360
$this->page->addAjaxJSCode(
" setTimeout(function() { "
.$jsCode.
" mpopup.show(); }, 0); "
);
361
}
362
else
363
{
364
$this->page->onload(
" "
.$jsCode.
" mpopup.show(); "
);
365
}
366
367
return
self::getRendered(parent::generate());
368
}
369
}
370
371
public
function
getModalSize
()
372
{
373
return
$this->modalSize;
374
}
375
376
public
function
setModalSize
($modalSize)
377
{
378
$this->modalSize = $modalSize;
379
}
380
}
381
382
387
class
MPopupPrompt
extends
MPopup
388
{
397
public
function
__construct
($message, $label = NULL,
$action
= NULL, $defaultValue = NULL)
398
{
399
$fields = parent::getPromptFields($message,
$action
, $defaultValue);
400
parent::__construct(
'mPopupPrompt'
, $fields, $label);
401
}
402
}
403
404
409
class
MPopupAlert
extends
MPopup
410
{
418
public
function
__construct
($message, $label = NULL,
$action
=
'javascript:mpopup.remove();'
)
419
{
420
$fields = parent::getAlertFields($message,
$action
);
421
parent::__construct(
'mPopupAlert'
, $fields, $label);
422
}
423
}
424
425
430
class
MPopupConfirm
extends
MPopup
431
{
440
public
function
__construct
($message, $label = NULL, $actionYes=
':confirmAction'
, $actionNo =
'javascript:mpopup.remove();'
, $field =
null
)
441
{
442
$fields = parent::getConfirmFields($message, $actionYes, $actionNo, $field);
443
parent::__construct(
'mPopupConfirm'
, $fields, $label);
444
}
445
}
446
447
?>
MButton
Definição
buttoncontrols.class:4
MComponent\$name
$name
Definição
mcomponent.class:17
MContainer
Definição
mcontainer.class:4
MControl\FORM_MODE_SHOW_NBSP
const FORM_MODE_SHOW_NBSP
Definição
mcontrol.class:44
MControl\setInner
setInner($inner)
Definição
mcontrol.class:598
MControl\$inner
$inner
Definição
mcontrol.class:141
MControl\$attributes
$attributes
Definição
mcontrol.class:106
MControl\FORM_MODE_SHOW_SIDE
const FORM_MODE_SHOW_SIDE
Definição
mcontrol.class:42
MDiv
Definição
blockcontrols.class:23
MIOLO\_REQUEST
static _REQUEST( $vars, $from='ALL')
Definição
miolo.class:1109
MIOLO\getInstance
static getInstance()
Definição
miolo.class:134
MLabel
Definição
labelcontrols.class:79
MPopupAlert
Definição
mpopup.class:410
MPopupAlert\__construct
__construct($message, $label=NULL, $action='javascript:mpopup.remove();')
Definição
mpopup.class:418
MPopupConfirm
Definição
mpopup.class:431
MPopupConfirm\__construct
__construct($message, $label=NULL, $actionYes=':confirmAction', $actionNo='javascript:mpopup.remove();', $field=null)
Definição
mpopup.class:440
MPopupPrompt
Definição
mpopup.class:388
MPopupPrompt\__construct
__construct($message, $label=NULL, $action=NULL, $defaultValue=NULL)
Definição
mpopup.class:397
MPopup
Definição
mpopup.class:32
MPopup\PROMPT_FIELD_ID
const PROMPT_FIELD_ID
Definição
mpopup.class:34
MPopup\generateBootstrap
static generateBootstrap($name, $content, $label, $closeButton, $class, $modalSize=self::POPUP_GRANDE)
Definição
mpopup.class:261
MPopup\POPUP_GRANDE
const POPUP_GRANDE
Definição
mpopup.class:35
MPopup\alert
static alert($message, $label=NULL, $action='javascript:mpopup.remove();')
Definição
mpopup.class:210
MPopup\getPromptFields
static getPromptFields($message, $action, $defaultValue)
Definição
mpopup.class:131
MPopup\confirm
static confirm($message, $label=NULL, $actionYes=NULL, $actionNo='javascript:mpopup.remove();')
Definição
mpopup.class:223
MPopup\$content
$content
Definição
mpopup.class:43
MPopup\setShowCloseButton
setShowCloseButton($showCloseButton)
Definição
mpopup.class:327
MPopup\__construct
__construct($name, $content, $title, $closeBtn=true)
Definição
mpopup.class:64
MPopup\generate
generate()
Definição
mpopup.class:340
MPopup\getModalSize
getModalSize()
Definição
mpopup.class:371
MPopup\setModalSize
setModalSize($modalSize)
Definição
mpopup.class:376
MPopup\getConfirmFields
static getConfirmFields($message=null, $actionYes=null, $actionNo=null, $field=null)
Definição
mpopup.class:165
MPopup\getPopupContainer
static getPopupContainer()
Definição
mpopup.class:80
MPopup\getShowCloseButton
getShowCloseButton()
Definição
mpopup.class:335
MPopup\getAlertFields
static getAlertFields($message, $action)
Definição
mpopup.class:149
MPopup\CONTAINER_ID
const CONTAINER_ID
Definição
mpopup.class:33
MPopup\show
static show($name, $content, $label, $closeButton=true, $focusField=NULL, $ajax=true, $class="", $modalSize=self::POPUP_GRANDE)
Definição
mpopup.class:236
MPopup\$title
$title
Definição
mpopup.class:48
MPopup\POPUP_MEIDA
const POPUP_MEIDA
Definição
mpopup.class:36
MPopup\POPUP_PEQUENA
const POPUP_PEQUENA
Definição
mpopup.class:37
MPopup\prompt
static prompt($message, $label=NULL, $action=':promptConfirmation', $defaultValue=NULL)
Definição
mpopup.class:198
MTextField
Definição
inputcontrols.class:4
$MIOLO
$MIOLO
Definição
mpopup.class:27
$action
$action
Definição
base.php:4
classes
ui
controls
mpopup.class
Gerado por
1.10.0