formTopic.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. use yii\helpers\Html;
  3. use yii\widgets\ActiveForm;
  4. use kartik\datetime\DateTimePicker;
  5. use app\widgets\CropperjsWidget;
  6. $form = ActiveForm::begin([
  7. 'id' => 'topic-form',
  8. 'options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data']]);
  9. $brightness = 60;
  10. if( trim($model->ext) != ''){
  11. $ext = json_decode(trim($model->ext));
  12. if( isset($ext->brightness) ){
  13. $brightness = $ext->brightness;
  14. }
  15. }
  16. ?>
  17. <input type="hidden" name="NewsTopic[id]" value="<?=$model->id?>">
  18. <input type="hidden" name="NewsTopic[ext]" id="ext" value='<?=$model->ext?>'>
  19. <style>
  20. #image {
  21. width: 100%;
  22. height: 56%;
  23. background: URL(/img/image.svg) no-repeat 50% 50%;
  24. background-size: contain;
  25. background-color: #fff;
  26. cursor: pointer;
  27. padding: 0px 100px 8px 0px;
  28. filter: brightness(<?=$brightness?>%);
  29. }
  30. .cont {
  31. position: relative;
  32. overflow: hidden;
  33. }
  34. .itext {
  35. position: absolute;
  36. bottom: 0;
  37. left: 0;
  38. padding: 30px;
  39. max-width: 608px;
  40. font: 36px/43px "Golos Text",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Ubuntu,Arial,sans-serif;
  41. color: #fff;
  42. margin-bottom: 50px;
  43. }
  44. .itext p{
  45. font: 700 16px/19px "Golos Text",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Ubuntu,Arial,sans-serif;
  46. color: #fff;
  47. line-height: 23px;
  48. }
  49. </style>
  50. <?
  51. if($model->id){
  52. $imageSrc = "/topic-images/".$model->id."_sizehd.jpg?r=".rand();
  53. }else{
  54. $imageSrc = '/img/e.gif';
  55. }
  56. ?>
  57. <img id="image" src="<?=$imageSrc?>" onClick="$('#modal').modal('show');document.getElementById('inputImage').click();" >
  58. <?
  59. echo CropperjsWidget::widget(['image' => 'image', 'file' => 'NewsTopic[photo]', 'post' => 'cropping', 'aspectRatio' => '13 / 5']);
  60. ?>
  61. <div class="form-group">
  62. <label for="formControlRange">Затенение</label>
  63. <input type="range" class="form-control-range" id="formControlRange" name="NewsTopic[brightness]" min="10" max="100" value="<?=$brightness?>" step="1" oninput="test(this)">
  64. </div>
  65. <?
  66. echo $form->field($model, 'url')->textInput([
  67. 'maxlength' => true,
  68. 'class' => 'form-control js-word-count-input',
  69. 'placeholder' => 'URL'
  70. ])->label('URL часть адреса рездела');
  71. echo $form->field($model, 'title')->textInput([
  72. 'maxlength' => true,
  73. 'class' => 'form-control js-word-count-input',
  74. 'placeholder' => 'Заголовок',
  75. // 'id' => 'js-news-content'
  76. ])->label('Заголовок рубрики');
  77. echo $form->field($model, 'meta_title')->textInput([
  78. 'maxlength' => true,
  79. 'class' => 'form-control js-word-count-input',
  80. 'placeholder' => 'Заголовок SEO'
  81. ])->label('Заголовок SEO');
  82. echo $form->field($model, 'description')->textarea([
  83. 'maxlength' => true,
  84. 'class' => 'form-control js-word-count-input',
  85. 'placeholder' => 'description'
  86. ])->label('Описание раздела кратко');
  87. echo $form->field($model, 'keywords')->textarea([
  88. 'maxlength' => true,
  89. 'class' => 'form-control js-word-count-input',
  90. 'placeholder' => 'ключевые слова'
  91. ])->label('ключевые слова через запятую');
  92. ?>
  93. <div class="form-group form-check">
  94. <?
  95. echo $form->field($model, 'active')->checkbox([
  96. 'class' => 'form-check-input',
  97. 'label' => 'Активный'
  98. ]);
  99. //($model->show == 'Y')?true:false,
  100. echo $form->field($model, 'show')->checkbox([
  101. 'class' => 'form-check-input',
  102. 'label' => 'Показывать везде',
  103. 'uncheck' => 'N',
  104. 'checked' => ($model->show == 'Y')?true:false
  105. ]);
  106. ?></div><div class="form-group"><?
  107. echo Html::submitButton('Send', ['class' => 'btn btn-success']);
  108. ?>
  109. </div>
  110. <script>
  111. var ext ='';
  112. var extx='<?=json_decode(trim($model->ext))?trim($model->ext):""?>';
  113. if( extx != '' ){
  114. var ext = JSON.parse(extx);
  115. }
  116. $('#topic-form').on('beforeValidate',
  117. function (event){
  118. console.log(JSON.stringify(ext));
  119. if( ext != '' ){
  120. $('#ext').val(JSON.stringify(ext));
  121. }
  122. return;
  123. }
  124. );
  125. function test(e){
  126. $('#image').css( "filter", "brightness("+$(e).val()+"%)" );
  127. if( ext == '' ){
  128. ext = new Object();
  129. }
  130. ext.brightness = $(e).val();
  131. }
  132. </script>
  133. <?
  134. ActiveForm::end();