Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Add Pjax to ProductController.
Browse files Browse the repository at this point in the history
Remove Bootstrap from ProductAsset.
  • Loading branch information
Albert committed May 6, 2017
1 parent 4d441d7 commit afe3a88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion backend/assets/ProductAsset.php
Expand Up @@ -16,6 +16,5 @@ class ProductAsset extends AssetBundle

public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
4 changes: 4 additions & 0 deletions backend/controllers/ProductController.php
Expand Up @@ -694,6 +694,7 @@ public function actionUp($id)
$product->movePrev();
$this->trigger(self::EVENT_AFTER_EDIT_PRODUCT, new ProductEvent(['id' => $id]));
}
if (\Yii::$app->request->isPjax) return $this->actionIndex();
return $this->redirect(\Yii::$app->request->referrer);
} else throw new ForbiddenHttpException(\Yii::t('shop', 'You have not permission to do this action.'));
}
Expand All @@ -720,6 +721,7 @@ public function actionDown($id)
$product->moveNext();
$this->trigger(self::EVENT_AFTER_EDIT_PRODUCT, new ProductEvent(['id' => $id]));
}
if (\Yii::$app->request->isPjax) return $this->actionIndex();
return $this->redirect(\Yii::$app->request->referrer);
} else throw new ForbiddenHttpException(\Yii::t('shop', 'You have not permission to do this action.'));
}
Expand Down Expand Up @@ -751,6 +753,8 @@ public function actionDelete($id)
$product->delete();

$this->trigger(self::EVENT_AFTER_DELETE_PRODUCT, new ProductEvent(['id' => $id]));

if (\Yii::$app->request->isPjax) return $this->actionIndex();
return $this->redirect('index');
} else throw new ForbiddenHttpException(\Yii::t('shop', 'You have not permission to delete this product.'));
}
Expand Down
11 changes: 8 additions & 3 deletions backend/views/product/index.php
Expand Up @@ -34,7 +34,11 @@
Yii::t('shop', 'Products')
];
?>

<?php Pjax::begin([
'id' => 'p-products',
'linkSelector' => '.pjax',
'enablePushState' => false
]); ?>
<div class="box">

<!--TITLE-->
Expand Down Expand Up @@ -79,14 +83,14 @@ class="btn btn-primary btn-xs">
'',
Url::toRoute(['up', 'id' => $model->id]),
[
'class' => 'fa fa-chevron-up'
'class' => 'fa fa-chevron-up pjax'
]
);
$buttonDown = Html::a(
'',
Url::toRoute(['down', 'id' => $model->id]),
[
'class' => 'fa fa-chevron-down'
'class' => 'fa fa-chevron-down pjax'
]
);
return $buttonUp . '<div>' . $model->position . '</div>' . $buttonDown;
Expand Down Expand Up @@ -229,3 +233,4 @@ class="btn btn-primary btn-xs pull-right">
</a>
</div>
</div>
<?php Pjax::end(); ?>

0 comments on commit afe3a88

Please sign in to comment.