Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
systems:yii2:examples [2018/05/29 16:25] smayr [Modal called from GridView] |
systems:yii2:examples [2018/10/04 17:05] (current) ajdavis [Copy to Clipboard using Javascript] |
||
---|---|---|---|
Line 989: | Line 989: | ||
<code php> | <code php> | ||
<? | <? | ||
- | use yii\helpers\Url; | + | // Method 1: Button |
- | ... | + | \yii\helpers\Html:: |
- | // Method | + | ' |
- | echo Html:: | + | ' |
+ | ]); | ||
+ | |||
+ | // Method | ||
+ | echo \yii\helpers\Html:: | ||
- | // Method | + | // Method |
- | $url = urldecode(Url:: | + | $url = urldecode(\yii\helpers\Url:: |
- | echo Html:: | + | echo \yii\helpers\Html:: |
| | ||
- | // Method | + | // Method |
- | echo Url:: | + | echo \yii\helpers\Url:: |
?> | ?> | ||
</ | </ | ||
Line 1526: | Line 1530: | ||
=== Modal Window === | === Modal Window === | ||
+ | * See: [[systems: | ||
- | <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 called from GridView ==== | ||
- | 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 confirmation called from GridView ==== | ||
- | Example of confirmation dialog in a view: | ||
- | <code php> | ||
- | <?php | ||
- | <?= yii\grid\GridView:: | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | // record number column | ||
- | [' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | [' | ||
- | [ // Checkboxes to delete selection | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | ], | ||
- | ' | ||
- | ]) ?> | ||
- | |||
- | <?php | ||
- | // Add Javascript code to perform AJAX call (using JQuery) | ||
- | $this-> | ||
- | " | ||
- | | ||
- | $('# | ||
- | var activeElement = $(document.activeElement); | ||
- | if (activeElement.is(' | ||
- | console.log(activeElement); | ||
- | console.log(' | ||
- | var action = activeElement[0].textContent; | ||
- | switch(action) { | ||
- | case ' | ||
- | case ' | ||
- | default: | ||
- | } | ||
- | } | ||
- | }); | ||
- | | ||
- | }); | ||
- | | ||
- | function delSelected() | ||
- | { | ||
- | if ( $( '# | ||
- | var keys = $('# | ||
- | console.log(' | ||
- | $.post({ | ||
- | url:'" | ||
- | dataType: ' | ||
- | data: {keylist: keys}, | ||
- | success: function( data ) { | ||
- | console.log(' | ||
- | console.log(data.status); | ||
- | console.log(data.details); | ||
- | console.log(data.data_post); | ||
- | console.log(data.data_get); | ||
- | } | ||
- | }); | ||
- | } else { | ||
- | alert(' | ||
- | } | ||
- | } | ||
- | ", \yii\web\View:: | ||
- | ?> | ||
- | |||
- | <?php | ||
- | function getDeleteConfirmationDialog() | ||
- | { | ||
- | $str = ''; | ||
- | $str .= '< | ||
- | $str .= '< | ||
- | $str .= ' | ||
- | $str .= '</ | ||
- | $str .= ''; | ||
- | | ||
- | $str .= '< | ||
- | $str .= '< | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= ' | ||
- | $str .= '</ | ||
- | |||
- | return $str; | ||
- | } | ||
- | ?> | ||
- | </ | ||
- | |||
- | In controller, add the action to call. Eg: '' | ||
- | <code php> | ||
- | //... | ||
- | class PriceController extends Controller | ||
- | { | ||
- | public function behaviors() | ||
- | { | ||
- | return [ | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | [ | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | //... | ||
- | ], | ||
- | ], | ||
- | //... | ||
- | ]; | ||
- | } | ||
- | | ||
- | //... | ||
- | | ||
- | /** | ||
- | * Deletes selected Price models for specified customer. | ||
- | * @return mixed | ||
- | */ | ||
- | public function actionDeleteSelected() | ||
- | { | ||
- | if (Yii:: | ||
- | $keys = Yii:: | ||
- | if (!is_array($keys)) { | ||
- | return \yii\helpers\Json:: | ||
- | ' | ||
- | ' | ||
- | ]); | ||
- | } | ||
- | | ||
- | if (count($keys) > 0) { | ||
- | $model = $this-> | ||
- | $customer_id = $model-> | ||
- | | ||
- | // Method 1: Delete each record (using a loop) | ||
- | //foreach ($keys as $key => $id) { | ||
- | // $model = $this-> | ||
- | // $model-> | ||
- | //} | ||
- | | ||
- | // Method 2: Delete each record (using single query) | ||
- | $result = (new \yii\db\Query) | ||
- | -> | ||
- | -> | ||
- | -> | ||
- | | ||
- | // Return Method 1: JSON | ||
- | //return \yii\helpers\Json:: | ||
- | // ' | ||
- | // ' | ||
- | //]); | ||
- | | ||
- | // Return Method 2: Redirect | ||
- | return $this-> | ||
- | } | ||
- | } | ||
- | return \yii\helpers\Json:: | ||
- | ' | ||
- | ' | ||
- | ]); | ||
- | } | ||
- | </ | ||
== Events == | == Events == | ||
Line 1957: | Line 1658: | ||
' | ' | ||
' | ' | ||
- | ' | + | ' |
+ | //' | ||
], | ], | ||
[ | [ | ||
Line 3257: | Line 2959: | ||
$dataProviderPrice-> | $dataProviderPrice-> | ||
</ | </ | ||
+ | |||
+ | == Copy to Clipboard using Javascript == | ||
+ | |||
+ | # Add a reference to the // | ||
+ | # Add javascript to your page that creates an instance of ClipboardJS: | ||
+ | <code php> | ||
+ | # Add a button that follows this logic: | ||
+ | <code html> | ||
+ | <i class=" | ||
+ | </ |