newsNew.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <?php
  2. use yii\helpers\Html;
  3. use yii\widgets\ActiveForm;
  4. use kartik\datetime\DateTimePicker;
  5. use \app\models\base\Story;
  6. use \app\models\base\NewsTopic;
  7. $request = Yii::$app->request;
  8. $id = $request->get('id');
  9. if( $id ){
  10. $this->title="Редактирование статьи";
  11. $news = \app\models\News::find()->andWhere(['id'=>$id])->one();
  12. // print_a( $news );
  13. }else{
  14. $this->title="Новая статья";
  15. $anews = [
  16. 'title' => ''
  17. ];
  18. $news = new \app\models\News();;
  19. $news->title = '';
  20. }
  21. ?>
  22. <?
  23. $form = ActiveForm::begin([
  24. 'id' => 'news-form',
  25. 'options' => ['class' => 'form-horizontal','enctype' => 'multipart/form-data'],]);
  26. //иничиализация
  27. DateTimePicker::widget([
  28. 'name' => 'dt_pub',
  29. 'options' => [],
  30. 'convertFormat' => true,
  31. 'pluginOptions' => [
  32. 'format' => 'd-M-Y g:i A',
  33. 'startDate' => '01-Mar-2014 12:00 AM',
  34. 'todayHighlight' => true
  35. ]
  36. ]);
  37. ?>
  38. <div class="row"><div class="col">
  39. <div class="input-group mb-3">
  40. <div class="input-group-prepend">
  41. <span class="input-group-text" id="basic-addon1" onclick="jQuery('#dt_pub').datetimepicker('show')"><i class="fa fa-calendar"></i></span>
  42. </div>
  43. <input type="text" id="dt_pub" class="col-auto" placeholder="Дата публикации" aria-label="Дата публикации" aria-describedby="basic-addon1" value="<?=$news->dt_pub?>" name="news['dt_pub']">
  44. </div>
  45. <?
  46. /*
  47. echo $form->field($news, 'title')->textInput([
  48. 'maxlength' => true,
  49. 'class' => 'form-control js-word-count-input',
  50. 'placeholder' => 'Заголовок новости'
  51. ])->label('Заголовок');
  52. */
  53. ?>
  54. <div class="form-group field-news-title required">
  55. <label class="control-label col-form-label" for="news-title">Заголовок</label>
  56. <div class="row">
  57. <input type="text" id="news-title" class="form-control js-word-count-input col-sm-6" name="News[title]" value="Преподаватель МГУ вспомнил, как Горбачёва избила букетом роз старушка в Сибири" placeholder="Заголовок новости" aria-required="true" value="<?=$news->meta_title?>">
  58. <div class="help-block px-lg-2"><div class="news__input-word-count"><span class="count">0</span> из 80</div></div>
  59. <a class="btn btn-primary px-lg-2" data-toggle="collapse" href="#collapseSEOTitle" role="button" aria-expanded="false" aria-controls="collapseSEOTitle">SEO title</a>
  60. </div>
  61. </div>
  62. <div class="collapse" id="collapseSEOTitle">
  63. <div class="card card-body">
  64. <input type="text" name="news[meta_title]" value="<?=$news->meta_title?>">
  65. </div>
  66. </div>
  67. <div class="form-group field-news-lid required">
  68. <label class="control-label" for="news-lid">Новость кратко</label>
  69. <textarea id="news-lid" class="form-control js-word-count-input" name="News[lid]" placeholder="Лид" aria-required="true"><?=$news->lid?></textarea>
  70. <div class="help-block">Краткое содержание статьи</div>
  71. </div>
  72. <div class="form-group">
  73. <label class="control-label" for="news-link">Прямой переход на URL</label>
  74. <div class="row">
  75. <input type="text" class="form-control" name="news[link]" id="news-link" value="<?=$news->link?>">
  76. </div>
  77. </div>
  78. <div class="form-group">
  79. <label class="control-label" for="news-embed">вставка медиа URL</label>
  80. <div class="row">
  81. <input type="text" class="form-control" name="news[embed_url]" id="news-embed" value="<?=$news->embed_url?>">
  82. </div>
  83. </div>
  84. <div class="form-group field-js-news-content required">
  85. <label class="control-label" for="js-news-content">Контент</label>
  86. <textarea id="js-news-content" class="form-control" name="News[text]" rows="12" aria-required="true"><?=$news->text?></textarea>
  87. </div>
  88. <blockquote class="quote-info mt-0">
  89. <h5 id="tip">Новость подготовили</h5>
  90. <p><?=$news->editors?></p>
  91. </blockquote>
  92. <div class="input-group">
  93. <label class="control-label col-form-label mr-3" >Автор</label>
  94. <select class="custom-select custom-select-sm" name="news[author]" id="news-author">
  95. <option selected>Откройте это меню выбора</option>
  96. <option value="1">Вася</option>
  97. <option value="2">Гоша</option>
  98. <option value="3">Саша</option>
  99. </select>
  100. <label class="input-group-append btn btn-primary" title="показывать автора" for="news-author">
  101. <input type="checkbox" autocomplete="off" name="News[show_author]"><i class="fa fa-eye ml-2"></i>
  102. </label>
  103. </div>
  104. <div class="card card-outline card-primary">
  105. <div class="card-body">
  106. <div class="custom-control custom-checkbox custom-control-inline">
  107. <input type="checkbox" id="customRadioInline1" name="customRadioInline" class="custom-control-input">
  108. <label class="custom-control-label" for="customRadioInline1"><i class="fas fa-spell-check"></i>Корректор</label>
  109. </div>
  110. <div class="custom-control custom-checkbox custom-control-inline">
  111. <input type="checkbox" id="customRadioInline2" name="customRadioInline" class="custom-control-input">
  112. <label class="custom-control-label" for="customRadioInline2"><s><i class="fas fa-search"></i></s>Не отдавать в поиск</label>
  113. </div>
  114. <div class="custom-control custom-checkbox custom-control-inline">
  115. <input type="checkbox" id="customRadioInline4" name="customRadioInline" class="custom-control-input">
  116. <label class="custom-control-label" for="customRadioInline4"><i class="fas fa-yin-yang"></i>Не отдавать в <strong class="text-indigo">DZEN</strong> новости</label>
  117. </div>
  118. <div class="custom-control custom-checkbox custom-control-inline">
  119. <input type="checkbox" id="customRadioInline3" name="customRadioInline" class="custom-control-input">
  120. <label class="custom-control-label" for="customRadioInline3"><i class="fas fa-comment-slash"></i>Без коментариев</label>
  121. </div>
  122. </div>
  123. </div>
  124. <div class="card card-outline card-teal">
  125. <div class="card-body">
  126. <div class="custom-control custom-checkbox custom-control-inline">
  127. <input type="checkbox" name="iphoto_status" value="ON" id="fcont1" class="custom-control-input">
  128. <label class="custom-control-label" for="fcont1"><i class="fa fa-camera"></i> C фото материалом</label>
  129. </div>
  130. <div class="custom-control custom-checkbox custom-control-inline">
  131. <input type="checkbox" name="ivideo_status" value="ON" id="fcont2" class="custom-control-input">
  132. <label class="custom-control-label" for="fcont2"><i class="fa fa-video"></i> C видео материалом</label>
  133. </div>
  134. <div class="custom-control custom-checkbox custom-control-inline">
  135. <input type="checkbox" name="iaudio_status" value="ON" id="fcont3" class="custom-control-input">
  136. <label class="custom-control-label" for="fcont3"><i class="fa fa-headphones"></i> C аудио материалом</label>
  137. </div>
  138. </div>
  139. </div>
  140. <div class="card card-outline card-olive">
  141. <div class="card-body">
  142. <div class="custom-control custom-checkbox custom-control-inline">
  143. <input type="checkbox" name="iphoto_status" value="ON" id="fcont4" class="custom-control-input">
  144. <label class="custom-control-label" for="fcont4"><i class="fas fa-comment-dollar"></i> Простая коммерческая</label>
  145. </div>
  146. <div class="custom-control custom-checkbox custom-control-inline">
  147. <input type="checkbox" name="ivideo_status" value="ON" id="fcont5" class="custom-control-input">
  148. <label class="custom-control-label" for="fcont5"><i class="fas fa-comment-dollar"></i> Медицинская коммерческая</label>
  149. </div>
  150. </div>
  151. </div>
  152. <div class="card card-outline card-maroon">
  153. <div class="card-body">
  154. <div class="custom-control custom-checkbox custom-control-inline">
  155. <input type="checkbox" name="top" value="ON" id="fcont6" class="custom-control-input">
  156. <label class="custom-control-label" for="fcont6"><i class="fas fa-comment-dollar"></i> В топ</label>
  157. </div>
  158. <div class="custom-control custom-checkbox custom-control-inline">
  159. <input type="checkbox" name="NH" value="ON" id="fcont7" class="custom-control-input">
  160. <label class="custom-control-label" for="fcont7"><i class="fas fa-comment-dollar"></i> В НЧ</label>
  161. </div>
  162. </div>
  163. </div>
  164. <div class="custom-control custom-checkbox custom-control-inline">
  165. <input type="checkbox" name="active" value="ON" id="active" class="custom-control-input">
  166. <label class="custom-control-label" for="active"><i class="far fa-play-circle"></i> Опубликовать</label>
  167. </div>
  168. <script>
  169. window.datetimepicker_conf = {"bootcssVer":4,"icontype":"glyphicon","fontAwesome":true,"icons":{"leftArrow":"glyphicon-arrow-left","rightArrow":"glyphicon-arrow-right"},"format":"dd-mm-yyyy hh:ii","type":3,"startDate":"11-Oct-2022 04:35","todayHighlight":true,"language":"ru","autoclose":true,"timezone":"UTC"};
  170. jQuery(function ($) {
  171. if (jQuery('#dt_pub').data('datetimepicker')) { jQuery('#dt_pub').datetimepicker('destroy'); }
  172. $('#dt_pub').datetimepicker(datetimepicker_conf);
  173. });
  174. </script>
  175. <a href="#preview" class="btn btn-info" target="_blank"><i class="fas fa-cat"></i> Предпросмотр</a>
  176. <?
  177. echo Html::submitButton('Send', ['class' => 'btn btn-success']);
  178. echo Html::submitButton('Save', ['class' => 'btn btn-success']);
  179. ?>
  180. </div>
  181. <!-- правая колонка --->
  182. <div class="col-3">
  183. <div class="card card-primary">
  184. <div class="card-header">
  185. <h3 class="card-title">Фото</h3>
  186. </div>
  187. <div class="card-body">
  188. <?
  189. if($news->id){
  190. $imageSrc = "/images/news/news/".$news->id."_size4.jpg";
  191. }
  192. echo @app\components\admin\uploadcrop\UploadCrop::widget(
  193. [
  194. 'form' => $form,
  195. 'model' => $news,
  196. 'attribute' => 'photo',
  197. 'maxSize' => 3000,
  198. 'imageSrc' => (isset($imageSrc)) ? $imageSrc : '',
  199. 'title' => 'Фото',
  200. 'changePhotoTitle' => 'Фото',
  201. 'jcropOptions' => [
  202. 'center' => true,
  203. 'rotatable' => true,
  204. 'autoCrop' => true,
  205. 'autoCropArea' => false,
  206. 'checkOrientation' => true,
  207. 'aspectRatio' => 16 / 9,
  208. 'dragMode' => 'move',
  209. 'viewMode' => 1,
  210. 'autoCropArea' => '0.1',
  211. 'restore' => true,
  212. 'guides' => true,
  213. 'center' => true,
  214. 'movable' => false,
  215. 'highlight' => true,
  216. 'cropBoxMovable' => true,
  217. 'cropBoxResizable' => true,
  218. 'background' => false,
  219. 'minContainerHeight' => 500,
  220. 'minCanvasHeight' => 400,
  221. 'minCropBoxWidth' => 600,
  222. 'minCropBoxHeight' => 200,
  223. 'responsive' => true,
  224. 'toggleDragModeOnDblclick' => false,
  225. 'crop' => 'crq'
  226. ]
  227. ]
  228. );
  229. ?>
  230. <label class="control-label" for="status-photo">Статусы для фото</label>
  231. <div class="btn-group" data-toggle="buttons" id="status-photo">
  232. <label class="btn btn-primary active btn-sm px-3" title="показывать фото">
  233. <input type="checkbox" autocomplete="off" name="News[photo_include]"><i class="fa fa-eye ml-2"></i>
  234. </label>
  235. <label class="btn btn-info active btn-sm px-3" title="фото в пр. ленте">
  236. <input type="checkbox" autocomplete="off" name="News[photo_rcol]"><i class="fa fa-list-alt ml-2"></i>
  237. </label>
  238. <label class="btn btn-dark active btn-sm px-3" title="удалить фото">
  239. <input type="checkbox" autocomplete="off" name="News[del_photo]"><i class="fa fa-trash ml-2"></i>
  240. </label>
  241. </div>
  242. <div class="form-group field-title-photo required">
  243. <label class="control-label" for="title-photo">Подпись фото</label>
  244. <textarea id="title-photo" class="form-control" name="News[photo_title]" rows="1" aria-required="true"><?=$news->photo_title?></textarea>
  245. </div>
  246. </div>
  247. </div>
  248. <div class="card card-primary">
  249. <div class="ribbon-wrapper">
  250. <div class="ribbon bg-primary">
  251. Рубрики
  252. </div>
  253. </div>
  254. <div class="card-body">
  255. <?
  256. $model = new NewsTopic();
  257. $Titems = $model->getForNews($news->id);
  258. $atopic = array();
  259. foreach( $Titems as $item ){
  260. $atopic[$item->id] = $item->id;
  261. }
  262. foreach( NewsTopic::findActive()->getModels() as $item ){
  263. ?>
  264. <div class="custom-control <?=($item->show == 'Y')?'custom-checkbox':'custom-switch bg-purple'?>">
  265. <input class="custom-control-input" type="checkbox" value="" id="flexCheck<?=$item->id?>" name="Topics[<?=$item->id?>]"<?=(in_array($item->id, $atopic, true))?' checked':''?>>
  266. <label class="custom-control-label" for="flexCheck<?=$item->id?>">
  267. <?=$item->title?>
  268. </label>
  269. </div>
  270. <?
  271. }
  272. ?>
  273. </div>
  274. </div>
  275. <div class="card card-primary">
  276. <div class="ribbon-wrapper">
  277. <div class="ribbon bg-primary">
  278. сюжеты
  279. </div>
  280. </div>
  281. <div class="card-body">
  282. <div class="input-group">
  283. <div class="input-group-prepend">
  284. <span class="btn btn-primary" id="validatedInputGroupPrepend"><i class="fas fa-search"></i></span>
  285. </div>
  286. <input type="text" class="form-control" aria-describedby="validatedInputGroupPrepend" id="story">
  287. </div>
  288. <?
  289. $model = new Story();
  290. $Sitems = $model->getForNews($news->id);
  291. ?>
  292. <div class="custom-control custom-checkbox">
  293. <?
  294. foreach($Sitems as $item){
  295. ?>
  296. <div class="custom-control custom-checkbox">
  297. <input class="custom-control-input" type="checkbox" value="" id="Story<?=$item->id?>" name="Story[<?=$item->id?>]" checked>
  298. <label class="custom-control-label" for="Story<?=$item->id?>">
  299. <?=$item->title?>
  300. </label>
  301. </div>
  302. <?
  303. }
  304. ?>
  305. <div id="story_items"></div>
  306. </div>
  307. </div>
  308. </div>
  309. <!-- end col r-->
  310. </div></div>
  311. <?
  312. ActiveForm::end();
  313. ?>
  314. <script>
  315. $(function() {
  316. var cache = {};
  317. $( "#story" ).autocomplete({
  318. source: function( request, response ) {
  319. var term = request.term;
  320. if ( term in cache ) {
  321. response( cache[ term ] );
  322. return;
  323. }
  324. $.getJSON( "ajaxstory", {'q':request.term}, function( data, status, xhr ) {
  325. if( data.status == 'ok' ){
  326. cache[ term ] = data.item;
  327. response( data.item );
  328. }
  329. });
  330. },
  331. minLength: 3,
  332. select: function( event, ui ) {
  333. if( $( "#story_items :input[value='"+ui.item.id+"']" ).val() != ui.item.id ){
  334. $( "#story_items" ).append('<div class="custom-control custom-checkbox"><input class="custom-control-input" type="checkbox" name="Story[]" value="'+ui.item.id+'" checked ><label class="custom-control-label" >'+ ui.item.label +"</label></div>");
  335. }
  336. },
  337. open: function() {
  338. $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
  339. },
  340. close: function() {
  341. $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
  342. }
  343. });
  344. });
  345. </script>