Browse Source

Refactoring getControllerUrlPath()

dev
Guillaume Bourgeois 5 years ago
parent
commit
d5d27ccdf1
5 changed files with 26 additions and 16 deletions
  1. +12
    -5
      backend/controllers/DocumentController.php
  2. +2
    -2
      backend/views/document/_form.php
  3. +6
    -1
      backend/views/invoice/index.php
  4. +6
    -1
      backend/views/quotation/index.php
  5. +0
    -7
      common/models/Document.php

+ 12
- 5
backend/controllers/DocumentController.php View File

@@ -86,7 +86,7 @@ class DocumentController extends BackendController
$this->processInvoiceViaDeliveryNotes($model) ;

Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('create', $model));
return $this->redirect(['/' . $model->getControllerUrlPath() . '/update', 'id' => $model->id]);
return $this->redirect(['/' . $this->getControllerUrl() . '/update', 'id' => $model->id]);
} else {
Yii::$app->getSession()->setFlash('error', 'Un problème est survenu lors de la création du document.');
}
@@ -161,7 +161,7 @@ class DocumentController extends BackendController
]);

Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('delete', $model));
$this->redirect([$model->getControllerUrlPath().'/index']);
$this->redirect([$this->getControllerUrl().'/index']);
}

public function actionDownload($id)
@@ -179,7 +179,7 @@ class DocumentController extends BackendController
else {
Yii::$app->getSession()->setFlash('danger', $this->getFlashMessage('send', $document));
}
$this->redirect([$document->getControllerUrlPath().'/index']);
$this->redirect([$this->getControllerUrl().'/index']);
}

public function actionAjaxUserInfos($typeAction, $idUser, $classDocument, $idDocument = false)
@@ -262,12 +262,12 @@ class DocumentController extends BackendController
$document->changeStatus(Document::STATUS_VALID);
$document->save();
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('validate', $document));
return $this->redirect(['delivery-note/index']);
return $this->redirect([$this->getControllerUrl().'/index']);
}
}

Yii::$app->getSession()->setFlash('danger', 'Une erreur est survenue lors de la validation du document.');
return $this->redirect(['delivery-note/index']);
return $this->redirect([$this->getControllerUrl().'/index']);
}

public function actionAjaxValidateDocument($idDocument, $classDocument)
@@ -522,6 +522,13 @@ class DocumentController extends BackendController
return $title;
}

public function getControllerUrl()
{
$path = strtolower($this->getClass());
$path = str_replace('deliverynote', 'delivery-note', $path);
return $path;
}

/**
* Recherche un Document en fonction de son ID.
*

+ 2
- 2
backend/views/document/_form.php View File

@@ -142,13 +142,13 @@ use common\models\Producer;
<div id="" class="info-box">
<span class="info-box-icon bg-blue"><i class="fa fa-download"></i></span>
<div class="info-box-content">
<a href="<?= Yii::$app->urlManager->createUrl([$model->getControllerUrlPath().'/download', 'id' => $model->id]) ?>" class="btn btn-default">Télécharger (PDF)</a>
<a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl().'/download', 'id' => $model->id]) ?>" class="btn btn-default"><span class="glyphicon glyphicon-download-alt"></span> Télécharger (PDF)</a>
</div>
</div>
<div id="" class="info-box">
<span class="info-box-icon bg-red"><i class="fa fa-flash"></i></span>
<div class="info-box-content">
<a v-if="document.status == 'draft'" class="btn btn-default" @click="validateDocument">Valider le document</a>
<a v-if="document.status == 'draft'" class="btn btn-default" @click="validateDocument"><span class="glyphicon glyphicon-ok"></span> Valider le document</a>
</div>
</div>
</div>

+ 6
- 1
backend/views/invoice/index.php View File

@@ -99,10 +99,15 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete} {send} {download}',
'template' => '{validate} {update} {delete} {send} {download}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'validate' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, [
'title' => Yii::t('app', 'Valider'), 'class' => 'btn btn-default'
]) : '');
},
'send' => function($url, $model) {
return (!$model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [
'title' => Yii::t('app', 'Envoyer'), 'class' => 'btn btn-default'

+ 6
- 1
backend/views/quotation/index.php View File

@@ -85,10 +85,15 @@ $this->addButton(['label' => 'Nouveau devis <span class="glyphicon glyphicon-plu
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete} {send} {download}',
'template' => '{validate} {update} {delete} {send} {download}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'validate' => function ($url, $model) {
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, [
'title' => Yii::t('app', 'Valider'), 'class' => 'btn btn-default'
]) : '');
},
'send' => function($url, $model) {
return (!$model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-send"></span>', $url, [
'title' => Yii::t('app', 'Envoyer'), 'class' => 'btn btn-default'

+ 0
- 7
common/models/Document.php View File

@@ -179,13 +179,6 @@ class Document extends ActiveRecordCommon
return '';
}

public function getControllerUrlPath()
{
$path = strtolower($this->getClass());
$path = str_replace('deliverynote', 'delivery-note', $path);
return $path;
}

public function isValidClass($typeDocument)
{
return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']);

Loading…
Cancel
Save