| Current Path : /var/www/html/dosmv2/backend/modules/contentApplication/views/content-application/ |
| Current File : /var/www/html/dosmv2/backend/modules/contentApplication/views/content-application/index.php |
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use backend\modules\contentApplication\models\ContentApplicationTranslation;
$this->title = Yii::t('app', 'Pautan');
$this->params['breadcrumbs'][] = $this->title;
$this->registerJs('$(\'[data-toggle="tooltip"]\').tooltip();');
if (!empty($searchModel->application_cat)) {
$this->registerCssFile('@web/plugins/jquery-ui.css');
$this->registerJsFile('@web/plugins/jquery-ui.js', ['depends' => [\yii\web\JqueryAsset::className()]]);
$this->registerJs('$(document).ready(function() {
var fixHelper = function fixWidthHelper(e, ui){
ui.children().each(function() {
$(this).width($(this).width());
});
return ui;
}
$(".table-custom tbody").sortable({
helper: fixHelper,
update: function (event, ui) {
var output = "";
$(".table-custom tbody tr").each(function (i) {
var data = $(this).attr("data-key");
output += data + ",";
});
$.ajax({
url: "sorting?data=" + output,
method: "GET",
success: function (response) {
location.reload();
}
});
}
});
});');
}
?>
<div class="wrapper wrapper-content">
<p>
<?= Html::a('Tambah Baru', ['create'], ['class' => 'btn btn-primary']) ?>
</p>
<div class="ibox animated fadeInRightx">
<div class="mail-box b-r-md">
<?=
GridView::widget([
'summary' => "Paparan <b>{begin} - {end}</b> daripada <b>{totalCount}</b> rekod.",
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'tableOptions' => ['class' => 'table table-hover table-mail table-custom',],
'layout' => "<div class='gridview-top-wrapper'><div class='row'><div class='col-sm-6'>{summary}</div><div class='col-sm-6'>{pager}</div></div></div>\n{items}\n{pager}",
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'class' => 'yii\grid\ActionColumn',
'header' => 'Tindakan',
'template' => '{sort}{update}{delete}',
'headerOptions' => ['style' => 'text-align:center;width:1%;'],
'contentOptions' => ['style' => 'text-align:center;'],
'buttons' => [
'sort' => function ($url, $model) use ($searchModel) {
if (!empty($searchModel->application_cat)) {
return Html::a('<i class="fa fa-arrows"></i> Susunan', ['#'], ['class' => 'label label-warning label-button']);
} else {
return '<span data-toggle="tooltip" data-placement="top" title="Please specify category to use sorting function" class="label label-default label-button"><i class="fa fa-arrows"></i> Sort</span>';
}
},
'update' => function($url, $model, $key) {
return Html::a('<span class="fa fa-pencil"></span> Kemaskini', ['update', 'id' => $model->application_id], ['class' => 'label label-info label-button']);
},
'delete' => function ($url, $model) {
return '<span class="label label-danger label-button" onclick="deletedata(\'' . $model->application_id . '\')">
<i class="fa fa-trash"></i> Hapus
</span>';
},
],
],
[
'attribute' => 'application_title',
'value' => function ($model) {
if (($modelText = ContentApplicationTranslation::findOne(['application_translation_parent_id' => $model->application_id, 'application_translation_main' => 1])) !== null) {
return $modelText->application_translation_title;
}
}
],
[
'attribute' => 'application_cat',
'filter' => ArrayHelper::map(
(new \yii\db\Query())
->from('ref')
->where(['=', 'cat', 'APP_CAT'])
->orderBy(['descr' => SORT_ASC])
->all(), 'code', 'descr'),
'value' => function ($model) {
$ref = (new \yii\db\Query())
->from('ref')
->where(['=', 'cat', 'APP_CAT'])
->andwhere(['=', 'code', $model->application_cat])
->one();
if (!empty($ref))
return $ref['descr'];
}
],
[
'attribute' => 'application_status',
'filter' => ArrayHelper::map(
(new \yii\db\Query())->select(['code', 'descr'])
->from('ref')
->where(['=', 'cat', 'CONTENT_STATUS'])
->orderBy(['sort' => SORT_ASC])
->all(), 'code', 'descr'),
'value' => function ($model) {
$ref = (new \yii\db\Query())->select(['descr'])
->from('ref')
->where(['=', 'cat', 'CONTENT_STATUS'])
->andwhere(['=', 'code', $model->application_status])
->one();
if (!empty($ref))
return $ref['descr'];
}
],
'application_url',
'application_sort',
[
'header' => 'Terjemahan',
'format' => 'raw',
'headerOptions' => ['style' => 'width:10%'],
'value' => function ($model) {
$output = '';
$arr = ArrayHelper::map(
(new \yii\db\Query())->select(['*'])
->from('content_application_translation')
->orderBy(['application_translation_language' => SORT_ASC])
->groupby(['application_translation_language'])
->all(), 'application_translation_language', 'application_translation_language');
if (!empty($arr)) {
foreach ($arr as $code) {
$ref = (new \yii\db\Query())->select(['descr'])
->from('ref')
->where(['=', 'cat', 'CONTENT_LANGUAGE'])
->andwhere(['=', 'code', $code])
->one();
if (!empty($ref)) {
$label_class = 'label-dark';
if (($modeltranslation = ContentApplicationTranslation::findOne(['application_translation_parent_id' => $model->application_id, 'application_translation_language' => $code])) !== null) {
$label_class = 'label-primary';
}
$output .= '<span class="label label-button ' . $label_class . '">' . $ref['descr'] . '</span>';
}
}
}
return $output . Html::a('<i class="fa fa-plus" aria-hidden="true"></i> Terjemahan', ['addtranslation', 'id' => $model->application_id], ['class' => 'label label-warning label-button']);
}
],
],
]);
?>
</div>
</div>
</div>
<script>
function deletedata(id) {
Swal.fire({
title: 'Anda pasti untuk hapuskan data ini?',
text: "Data tidak boleh dikembalikan!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ya, teruskan!',
cancelButtonText: 'Batal',
}).then((result) => {
if (result.value) {
$.ajax({
url: "delete",
method: "POST",
data: {"id": id},
success: function (response) {
if (response === 'success') {
swal.fire({
title: 'Berjaya',
icon: 'success',
text: 'Data telah dihapuskan',
}).then(function (result) {
location.reload();
});
}
},
});
}
});
}
</script>