Commit 0a811f75 by Junaid Rahman pv

added file editor option

parent 16402987
...@@ -131,7 +131,6 @@ class ThemeController extends Controller ...@@ -131,7 +131,6 @@ class ThemeController extends Controller
} }
} }
public function actionFiles($id) public function actionFiles($id)
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
......
...@@ -14,23 +14,6 @@ class ThemeFileController extends \yii\web\Controller ...@@ -14,23 +14,6 @@ class ThemeFileController extends \yii\web\Controller
{ {
return $this->render('index'); return $this->render('index');
} }
/**
* Finds the Theme model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Theme the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = ThemeFiles::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
public function actionUpload() public function actionUpload()
{ {
$model = new ThemeFiles(); $model = new ThemeFiles();
...@@ -58,4 +41,24 @@ class ThemeFileController extends \yii\web\Controller ...@@ -58,4 +41,24 @@ class ThemeFileController extends \yii\web\Controller
return $this->redirect(['theme/index']); return $this->redirect(['theme/index']);
} }
public function actionEditor($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
}
return $this->render('editor',[
'model' => $model,
]);
}
protected function findModel($id)
{
if (($model = ThemeFiles::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
} }
...@@ -4,17 +4,15 @@ ...@@ -4,17 +4,15 @@
?> ?>
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\Modal; use yii\bootstrap\Modal;
use yii\helpers\Url;
?> ?>
<div class="customer-form"> <div class="customer-form">
<div class="col-md-6">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <table class="table">
<table>
<tr> <tr>
<th>File Name</th> <th>File Name</th>
<th>Options</th> <th>Options</th>
...@@ -30,22 +28,33 @@ use yii\helpers\Url; ...@@ -30,22 +28,33 @@ use yii\helpers\Url;
$fileCode = $value['code']; $fileCode = $value['code'];
$modelFiles[0]->theme_code = $themeCode; $modelFiles[0]->theme_code = $themeCode;
$modelFiles[0]->file_code = $fileCode; $modelFiles[0]->file_code = $fileCode;
if ($modelFiles[0]::isFileExist($themeCode, $fileCode)) { ?> if ($modelFiles[0]::isFileExist($themeCode, $fileCode)) {
$fileModel = $modelFiles[0]::findOne([
'theme_code' => $themeCode,
'file_code' => $fileCode
]);
?>
<td>
<td><?= 'edit' ?></td> <?= Html::a(' Edit ', ['theme-file/editor', 'id' => $fileModel->id], [
'class' => 'btn btn-primary fa fa-edit',
]) ?>
</td>
<?php } else { ?> <?php } else { ?>
<td> <td>
<?= Html::button('Upload File', [ <?= Html::button('Upload File', [
'class' => 'btn btn-default', 'class' => 'btn btn-primary',
'id' => 'modalButton' . $value['id'], 'id' => 'modalButton' . $value['id'],
'onclick' => 'uploadJquery.upload(' . $value['id'] . ');' 'onclick' => 'uploadJquery.upload(' . $value['id'] . ');'
]) ?> ]) ?>
<?php <?php
Modal::begin([ Modal::begin([
'header' => '<h3>Upload</h3>', 'header' => '',
'id' => 'modal' . $value['id'], 'id' => 'modal' . $value['id'],
'size' => 'modal-sm', 'size' => 'modal-sm',
//keeps from closing modal with esc key or by clicking out of the modal. //keeps from closing modal with esc key or by clicking out of the modal.
...@@ -54,18 +63,13 @@ use yii\helpers\Url; ...@@ -54,18 +63,13 @@ use yii\helpers\Url;
?> ?>
<div id='modalContent' .<?= $value['id'] ?> style="text-align: center"> <div id='modalContent'<?= $value['id'] ?> style="text-align: center">
<?= $this->render('upload', [ <?= $this->render('upload', ['model' => $modelFiles[0],]) ?>
'model' => $modelFiles[0],
]) ?>
</div> </div>
<?php <?php yii\bootstrap\Modal::end(); ?>
yii\bootstrap\Modal::end();
?>
</td> </td>
......
<?php
/**
* Created by PhpStorm.
* User: user50
* Date: 22-09-2016
* Time: 02:37 PM
*/
use yii\widgets\ActiveForm;
use yii\helpers\Html;
?>
<div class="text-block-form">
<?php $form = ActiveForm::begin(); ?>
<?php
$file = yii::getAlias('@storage/private/theme-assets/') .$model->theme_code . '/' .$model->file_code;
$model->fileContent = file_get_contents($file);
?>
?>
<?= $form->field($model, 'fileContent')->widget(
trntv\aceeditor\AceEditor::className(),
[
'mode' => 'html'
]
) ?>
<div class="form-group">
<?= Html::submitButton(
$model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'),
['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']
) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
...@@ -19,7 +19,7 @@ use yii\bootstrap\Html; ...@@ -19,7 +19,7 @@ use yii\bootstrap\Html;
'action' => '../theme-file/upload' 'action' => '../theme-file/upload'
]); ?> ]); ?>
<div class="conatiner"> <div class="panel">
<div class="row"> <div class="row">
<div class="col-md-11"> <div class="col-md-11">
...@@ -43,7 +43,7 @@ use yii\bootstrap\Html; ...@@ -43,7 +43,7 @@ use yii\bootstrap\Html;
</div> </div>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton(Yii::t('backend', 'Upload'), <?= Html::submitButton(Yii::t('backend', 'Save'),
['class' => 'btn btn-primary']) ?> ['class' => 'btn btn-primary']) ?>
</div> </div>
......
...@@ -22,4 +22,5 @@ body { ...@@ -22,4 +22,5 @@ body {
padding-left: 10px; padding-left: 10px;
} }
} }
\ No newline at end of file
...@@ -26,6 +26,10 @@ class ThemeFiles extends \yii\db\ActiveRecord ...@@ -26,6 +26,10 @@ class ThemeFiles extends \yii\db\ActiveRecord
* @var file upload * @var file upload
*/ */
public $file; public $file;
/*
* @var file upload
*/
public $fileContent;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -51,7 +55,7 @@ class ThemeFiles extends \yii\db\ActiveRecord ...@@ -51,7 +55,7 @@ class ThemeFiles extends \yii\db\ActiveRecord
{ {
return [ return [
[['theme_code', 'file_code','file'], 'required'], [['theme_code', 'file_code','file'], 'required'],
[['theme_code', 'file_code'], 'string'], [['theme_code', 'file_code','fileContent'], 'string'],
[['created_at', 'updated_at'], 'integer'], [['created_at', 'updated_at'], 'integer'],
[['file_code'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryFiles::className(), 'targetAttribute' => ['file_code' => 'id']], [['file_code'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryFiles::className(), 'targetAttribute' => ['file_code' => 'id']],
[['theme_code'], 'exist', 'skipOnError' => true, 'targetClass' => Theme::className(), 'targetAttribute' => ['theme_code' => 'id']], [['theme_code'], 'exist', 'skipOnError' => true, 'targetClass' => Theme::className(), 'targetAttribute' => ['theme_code' => 'id']],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment