form.php 10 KB

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