form.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. use yii\helpers\Html;
  3. use yii\widgets\ActiveForm;
  4. use \app\models\base\Story;
  5. use \app\models\base\NewsTopic;
  6. use \app\models\base\Tags;
  7. $this->title = 'Добавить новый блок';
  8. $this->params['breadcrumbs'][] = ['label' => 'Блоки', 'url' => ['blocks']];
  9. $this->params['breadcrumbs'][] = $this->title;
  10. $form = ActiveForm::begin([
  11. 'id' => 'design-form',
  12. 'options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data']]);
  13. ?>
  14. <input type="hidden" name="Design[id]" value="<?=$model->id?>">
  15. <div class="row">
  16. <div class="col-sm-7">
  17. <div class="input-group">
  18. <label class="control-label col-form-label mr-3" >Источник</label>
  19. <select class="custom-select custom-select-sm" name="Design[type]" id="design-type">
  20. <option value="0" disabled selected hidden>Источник модуля</option>
  21. <option value="story" <?=($model->type == 'story')?'selected':''?> data-toggle="collapse" data-target="#collapseStory" aria-expanded="true" aria-controls="collapseStory">Сюжет</option>
  22. <option value="topic" <?=($model->type == 'topic')?'selected':''?> data-toggle="collapse" data-target="#collapseTopic" aria-expanded="false" aria-controls="collapseTopic">Рубрика</option>
  23. <option value="tag" <?=($model->type == 'tag')?'selected':''?> data-toggle="collapse" data-target="#collapseTag" aria-expanded="false" aria-controls="collapseTag">Тэг</option>
  24. </select>
  25. </div>
  26. </div>
  27. </div>
  28. <!-- Тэги --->
  29. <div class="card-body col-sm-7">
  30. <div class="collapse <?=($model->type == 'tag')?'show':''?>" id="collapseTag">
  31. <div class="input-group">
  32. <label class="control-label col-form-label mr-3" for="tag">Тэг</label>
  33. <div class="input-group-prepend">
  34. <span class="btn btn-primary" id="validatedInputGroupPrepend"><i class="fas fa-search"></i></span>
  35. </div>
  36. <input type="text" class="form-control" aria-describedby="validatedInputGroupPrepend" id="tag">
  37. </div>
  38. <?
  39. $smodel = new Tags();
  40. if( $model->type == 'tag' && $model->parent_id > 0 ){
  41. $s = $smodel->findOne(['id' => $model->parent_id]);
  42. }
  43. ?>
  44. <div class="custom-control custom-checkbox">
  45. <div id="tag_items">
  46. <?
  47. if( isset($s) && $s )
  48. {
  49. echo '<div class="custom-control custom-checkbox"><input class="custom-control-input" type="checkbox" name="Design[Tag]" value="'.$s->id.'" checked id="tagi'.$s->id.'"><label class="custom-control-label" for="tagi'.$s->id.'">'.$s->title."</label></div>";
  50. }
  51. ?>
  52. </div>
  53. </div>
  54. </div>
  55. <!-- #################### --->
  56. <!-- сюжеты --->
  57. <div class="card-body col-sm-7">
  58. <div class="collapse <?=($model->type == 'story')?'show':''?>" id="collapseStory">
  59. <div class="input-group">
  60. <label class="control-label col-form-label mr-3" for="story">Сюжет</label>
  61. <div class="input-group-prepend">
  62. <span class="btn btn-primary" id="validatedInputGroupPrepend"><i class="fas fa-search"></i></span>
  63. </div>
  64. <input type="text" class="form-control" aria-describedby="validatedInputGroupPrepend" id="story">
  65. </div>
  66. <?
  67. $smodel = new Story();
  68. if( $model->type == 'story' && $model->parent_id > 0 ){
  69. $s = $smodel->findOne(['id' => $model->parent_id]);
  70. }
  71. ?>
  72. <div class="custom-control custom-checkbox">
  73. <div id="story_items">
  74. <?
  75. if( isset($s) && $s )
  76. {
  77. echo '<div class="custom-control custom-checkbox"><input class="custom-control-input" type="checkbox" name="Design[Story]" value="'.$s->id.'" checked id="storyi'.$s->id.'"><label class="custom-control-label" for="storyi'.$s->id.'">'.$s->title."</label></div>";
  78. }
  79. ?>
  80. </div>
  81. </div>
  82. </div>
  83. <!-- #################### --->
  84. <!-- Рубрики --->
  85. <div class="collapse <?=($model->type == 'topic')?'show':''?>" id="collapseTopic">
  86. <div class="input-group">
  87. <label class="control-label col-form-label mr-3" for="design-topic">Рубрика</label>
  88. <select class="custom-select custom-select-sm" name="Design[Topic]" id="design-topic">
  89. <?
  90. $topics = new \yii\data\ActiveDataProvider(
  91. [
  92. "query"=>\app\models\base\NewsTopic::find()->where(['active'=>1])->orderBy(["topic_id"=>SORT_ASC,"order"=>SORT_ASC]),
  93. "pagination" => false
  94. ]
  95. );
  96. foreach( $topics->getModels() as $item ){
  97. ?>
  98. <option value="<?=$item->id?>" <?=($model->parent_id == $item->id)?'selected':''?>><?=$item->title?></option>
  99. <?
  100. }
  101. ?>
  102. </select>
  103. </div>
  104. </div>
  105. </div>
  106. <div class="row">
  107. <div class="col-sm-7">
  108. <div class="input-group">
  109. <label class="control-label col-form-label mr-3" >Дизайн блока</label>
  110. <select class="custom-select custom-select-sm" name="Design[design]" id="design-type">
  111. <option value="0" disabled selected hidden>Вариант вывода</option>
  112. <option value="1" <?=($model->design == 1)?'selected':''?>>1 большой+реклама</option>
  113. <option value="2" <?=($model->design == 2)?'selected':''?>>только текст</option>
  114. <option value="3" <?=($model->design == 3)?'selected':''?>>Стандартный сюжет</option>
  115. <option value="4" <?=($model->design == 4)?'selected':''?>>3 с фото</option>
  116. <option value="5" <?=($model->design == 5)?'selected':''?>>Радужная</option>
  117. <option value="6" <?=($model->design == 6)?'selected':''?>>9may</option>
  118. </select>
  119. </div>
  120. </div>
  121. </div>
  122. <div class="row">
  123. <div class="col-sm-7">
  124. <div class="position-relative p-3 my-4 bg-gray ">
  125. <div class="ribbon-wrapper">
  126. <div class="ribbon bg-primary">Подмена</div>
  127. </div>
  128. <div class="form-group field-news-title required">
  129. <label class="control-label col-form-label" for="news-title">Заголовок</label>
  130. <input type="text" id="news-title" class="form-control col-sm-9" name="Design[title]" placeholder="Заголовок блока" aria-required="true" value='<?=str_replace("'", '&apos;', $model->title)?>'>
  131. </div>
  132. <div class="form-group">
  133. <label class="control-label" for="news-link">Прямой переход на URL</label>
  134. <input type="text" class="form-control col-sm-9" name="Design[url]" id="news-link" value="<?=$model->url?>">
  135. </div>
  136. <small class="form-text my-0">Если нужны индивидуальные настройки, если не заполнить берётся автоматом из сюжета или другого источника</small>
  137. </div>
  138. </div>
  139. </div>
  140. <div class="form-group form-check">
  141. <div class="btn-group">
  142. <label class="btn btn-primary active">
  143. <input type="checkbox" name="Design[active]" id="active" style="width:3vw;height:3vh;top: 3px;position: relative;" class="active"<?=($model->active == 'Y')?' checked':''?> value="Y"><i class="far fa-play-circle"></i> Показывать</label>
  144. </label>
  145. </div>
  146. </div>
  147. <div class="form-group"><?
  148. echo Html::submitButton('Send', ['class' => 'btn btn-success']);
  149. ?>
  150. </div>
  151. <script>
  152. $(function() {
  153. var cache = {};
  154. var cache2 = {};
  155. $( "#story" ).autocomplete({
  156. source: function( request, response ) {
  157. var term = request.term;
  158. if ( term in cache ) {
  159. response( cache[ term ] );
  160. return;
  161. }
  162. $.getJSON( "/manager/news/ajaxstory", {'q':request.term}, function( data, status, xhr ) {
  163. if( data.status == 'ok' ){
  164. cache[ term ] = data.item;
  165. response( data.item );
  166. }
  167. });
  168. },
  169. minLength: 3,
  170. select: function( event, ui ) {
  171. if( $( "#story_items :input[value='"+ui.item.id+"']" ).val() != ui.item.id ){
  172. $( "#story_items" ).html('<div class="custom-control custom-checkbox"><input class="custom-control-input" type="checkbox" name="Design[Story]" value="'+ui.item.id+'" checked id="storyi'+ui.item.id+'"><label class="custom-control-label" for="storyi'+ui.item.id+'">'+ ui.item.label +"</label></div>");
  173. }
  174. },
  175. });
  176. $( "#tag" ).autocomplete({
  177. source: function( request, response ) {
  178. var term = request.term;
  179. if ( term in cache2 ) {
  180. response( cache2[ term ] );
  181. return;
  182. }
  183. $.getJSON( "/manager/tags/ajaxtag", {'q':request.term}, function( data, status, xhr ) {
  184. if( data.status == 'ok' ){
  185. cache2[ term ] = data.item;
  186. response( data.item );
  187. }
  188. });
  189. },
  190. minLength: 3,
  191. select: function( event, ui ) {
  192. if( $( "#tag_items :input[value='"+ui.item.id+"']" ).val() != ui.item.id ){
  193. $( "#tag_items" ).html('<div class="custom-control custom-checkbox"><input class="custom-control-input" type="checkbox" name="Design[Tag]" value="'+ui.item.id+'" checked id="tagi'+ui.item.id+'"><label class="custom-control-label" for="tagi'+ui.item.id+'">'+ ui.item.label +"</label></div>");
  194. }
  195. },
  196. });
  197. $('.collapse').on('show.bs.collapse', function () {
  198. $('.collapse').collapse('hide');
  199. });
  200. });
  201. </script>
  202. <?
  203. ActiveForm::end();