Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
systems:yii2:modal_window [2018/05/31 15:16] smayr [Confirmation Dialog] |
systems:yii2:modal_window [2018/05/31 16:04] (current) smayr [Modal Confirmation (called from GridView action)] |
||
---|---|---|---|
Line 26: | Line 26: | ||
</ | </ | ||
- | == In View '' | + | == Modal with Image == |
+ | <code php> | ||
+ | <?php | ||
+ | // | ||
+ | // Image | ||
+ | // | ||
+ | $itemImage = (!empty($model-> | ||
+ | Yii:: | ||
+ | '' | ||
+ | ); | ||
+ | |||
+ | // | ||
+ | // Image Thumbnail | ||
+ | // | ||
+ | if(!empty($itemImage)) { | ||
+ | echo "< | ||
+ | } else { | ||
+ | echo "< | ||
+ | base64_encode(\app\models\Tool:: | ||
+ | } | ||
+ | |||
+ | |||
+ | echo Html:: | ||
+ | [' | ||
+ | ); | ||
+ | |||
+ | // | ||
+ | // Modal to view image | ||
+ | // | ||
+ | yii\bootstrap\Modal:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | | ||
+ | ], | ||
+ | ]); | ||
+ | |||
+ | if(!empty($itemImage)) { | ||
+ | echo "< | ||
+ | } else { | ||
+ | echo "< | ||
+ | base64_encode(\app\models\Tool:: | ||
+ | } | ||
+ | echo '< | ||
+ | echo ' | ||
+ | echo '</ | ||
+ | |||
+ | yii\bootstrap\Modal:: | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | |||
+ | == Modal Content (called from GridView field) == | ||
+ | |||
+ | <code php> | ||
+ | <?php Pjax:: | ||
+ | <?= GridView:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | [' | ||
+ | |||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | // | ||
+ | [ // use Modal window to display Notes | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | if (!empty($data[" | ||
+ | $str = ' | ||
+ | <!-- Button trigger modal --> | ||
+ | <button type=" | ||
+ | | ||
+ | data-toggle=" | ||
+ | data-target="# | ||
+ | <span class=" | ||
+ | </ | ||
+ | |||
+ | <!-- Modal --> | ||
+ | <div class=" | ||
+ | | ||
+ | | ||
+ | | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <button type=" | ||
+ | <span aria-hidden=" | ||
+ | </ | ||
+ | <h4 class=" | ||
+ | </ | ||
+ | <div class=" | ||
+ | < | ||
+ | </ | ||
+ | <div class=" | ||
+ | <button type=" | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | } else { | ||
+ | $str = ""; | ||
+ | } | ||
+ | |||
+ | return ($str); | ||
+ | }, | ||
+ | //' | ||
+ | ], | ||
+ | |||
+ | [' | ||
+ | ], | ||
+ | ]); ?> | ||
+ | <?php Pjax:: | ||
+ | </ | ||
+ | |||
+ | |||
+ | == Modal View (called from GridView action) == | ||
+ | Modal to view or update a record, called from a '' | ||
+ | <code php> | ||
+ | <?= yii\grid\GridView:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | // record number column | ||
+ | [' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | // | ||
+ | [ | ||
+ | ' | ||
+ | //' | ||
+ | | ||
+ | ' | ||
+ | | ||
+ | }, | ||
+ | ' | ||
+ | | ||
+ | }, | ||
+ | ], | ||
+ | ], | ||
+ | ], | ||
+ | ]) ?> | ||
+ | |||
+ | <?php | ||
+ | // Attach click events to buttons ' | ||
+ | $this-> | ||
+ | " | ||
+ | $(' | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | }); | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | }); | ||
+ | }); | ||
+ | "); | ||
+ | ?> | ||
+ | |||
+ | <?php | ||
+ | // Modal for VIEW | ||
+ | yii\bootstrap\Modal:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | //' | ||
+ | ' | ||
+ | ]); | ||
+ | echo "< | ||
+ | yii\bootstrap\Modal:: | ||
+ | ?> | ||
+ | |||
+ | <?php | ||
+ | // Modal for UPDATE | ||
+ | yii\bootstrap\Modal:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | //' | ||
+ | ' | ||
+ | ]); | ||
+ | echo "< | ||
+ | yii\bootstrap\Modal:: | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | See also: [[http:// | ||
+ | |||
+ | === Modal View (called from GridView action) using AJAX === | ||
To add a modal window (popup) from the '' | To add a modal window (popup) from the '' | ||
Line 125: | Line 326: | ||
' | ' | ||
]); | ]); | ||
+ | echo "< | ||
yii\bootstrap\Modal:: | yii\bootstrap\Modal:: | ||
| | ||
Line 135: | Line 337: | ||
// ' | // ' | ||
//], | //], | ||
+ | echo "< | ||
' | ' | ||
]); | ]); | ||
Line 147: | Line 350: | ||
- | == GridView | + | == Modal Confirmation (called from GridView |
- | <code php> | ||
- | <?php Pjax:: | ||
- | <?= GridView:: | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | [' | ||
- | |||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | //... | ||
- | [ // use Modal window to display Notes | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | if (!empty($data[" | ||
- | $str = ' | ||
- | <!-- Button trigger modal --> | ||
- | <button type=" | ||
- | | ||
- | data-toggle=" | ||
- | data-target="# | ||
- | <span class=" | ||
- | </ | ||
- | |||
- | <!-- Modal --> | ||
- | <div class=" | ||
- | | ||
- | | ||
- | | ||
- | <div class=" | ||
- | <div class=" | ||
- | <div class=" | ||
- | <button type=" | ||
- | <span aria-hidden=" | ||
- | </ | ||
- | <h4 class=" | ||
- | </ | ||
- | <div class=" | ||
- | < | ||
- | </ | ||
- | <div class=" | ||
- | <button type=" | ||
- | | ||
- | </ | ||
- | </ | ||
- | </ | ||
- | </ | ||
- | } else { | ||
- | $str = ""; | ||
- | } | ||
- | |||
- | return ($str); | ||
- | }, | ||
- | //' | ||
- | ], | ||
- | |||
- | [' | ||
- | ], | ||
- | ]); ?> | ||
- | <?php Pjax:: | ||
- | </ | ||
- | |||
- | == Confirmation Dialog == | ||
Example of confirmation dialog in a view: | Example of confirmation dialog in a view: | ||
<code php> | <code php> | ||
Line 267: | Line 402: | ||
$.post({ | $.post({ | ||
url:'" | url:'" | ||
- | dataType: ' | ||
data: {keylist: keys}, | data: {keylist: keys}, | ||
success: function( data ) { | success: function( data ) { | ||
Line 275: | Line 409: | ||
console.log(data.data_post); | console.log(data.data_post); | ||
console.log(data.data_get); | console.log(data.data_get); | ||
- | } | + | }, |
+ | dataType: ' | ||
}); | }); | ||
} else { | } else { | ||
Line 344: | Line 479: | ||
' | ' | ||
]) ?> | ]) ?> | ||
+ | |||
+ | <?php | ||
+ | // Modal for Delete | ||
+ | yii\bootstrap\Modal:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | Html:: | ||
+ | ' | ||
+ | ]) . " " . | ||
+ | Html:: | ||
+ | ' | ||
+ | ]), | ||
+ | //' | ||
+ | ' | ||
+ | ]); | ||
+ | echo "< | ||
+ | echo " | ||
+ | echo "</ | ||
+ | yii\bootstrap\Modal:: | ||
+ | ?> | ||
<?php | <?php | ||
Line 373: | Line 529: | ||
$.post({ | $.post({ | ||
url:'" | url:'" | ||
- | dataType: ' | ||
data: {keylist: keys}, | data: {keylist: keys}, | ||
success: function( data ) { | success: function( data ) { | ||
Line 381: | Line 536: | ||
console.log(data.data_post); | console.log(data.data_post); | ||
console.log(data.data_get); | console.log(data.data_get); | ||
- | } | + | }, |
+ | dataType: ' | ||
}); | }); | ||
} else { | } else { | ||
Line 388: | Line 544: | ||
} | } | ||
", \yii\web\View:: | ", \yii\web\View:: | ||
- | ?> | ||
- | |||
- | <?php | ||
- | // Modal for Delete | ||
- | yii\bootstrap\Modal:: | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | Html:: | ||
- | ' | ||
- | ]) . " " . | ||
- | Html:: | ||
- | ' | ||
- | ]), | ||
- | //' | ||
- | ' | ||
- | ]); | ||
- | echo "< | ||
- | echo " | ||
- | echo "</ | ||
- | yii\bootstrap\Modal:: | ||
?> | ?> | ||
</ | </ |