_form.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. use yii\helpers\Html;
  3. use yii\jui\DatePicker;
  4. use kartik\datetime\DateTimePicker;
  5. use yii\web\JsExpression;
  6. use yii\web\View;
  7. use yii\widgets\ActiveForm;
  8. /* @var $this yii\web\View */
  9. /* @var $model app\models\base\TopSlider */
  10. /* @var $form yii\widgets\ActiveForm */
  11. $formatJs = <<< 'JS'
  12. var formatRepo = function (repo) {
  13. if (repo.loading) {
  14. return repo.text;
  15. }
  16. var markup =
  17. '<div class="row">' +
  18. '<div class="col-sm-5">' +
  19. '<img src="' + repo.picture + '" class="img-rounded" style="width:160px;height:90px;" />' +
  20. '<b style="margin-left:5px">' + repo.title + '</b>' +
  21. '</div>' +
  22. '</div>';
  23. return '<div style="overflow:hidden;">' + markup + '</div>';
  24. };
  25. var formatRepoSelection = function (repo) {
  26. return repo.title;
  27. }
  28. JS;
  29. $this->registerJs($formatJs, View::POS_HEAD);
  30. $resultsJs = <<< JS
  31. function (data, params) {
  32. params.page = params.page || 1;
  33. return {
  34. results: data.items,
  35. pagination: {
  36. more: (params.page * 30) < data.total_count
  37. }
  38. };
  39. }
  40. JS;
  41. ?>
  42. <div class="top-slider-form">
  43. <?php $form = ActiveForm::begin(); ?>
  44. <?= $form->field($model, 'post_id')->widget( \kartik\select2\Select2::class,[
  45. "value"=>$model->post_id,
  46. 'initValueText' => !is_null($model->post)?$model->post->title:"asdasd",
  47. "options"=>["value"=>$model->post_id],
  48. 'pluginOptions' => [
  49. //'allowClear' => true,
  50. 'selectOnClose' => true,
  51. 'ajax' => [
  52. 'url' => \yii\helpers\Url::to(['/manager/top-slider/find-news']),
  53. 'dataType' => 'json',
  54. 'data' => new JsExpression('function(params) { return {q:params.term, page: params.page}; }'),
  55. 'processResults' => new JsExpression($resultsJs),
  56. 'cache' => true,
  57. 'delay' => 1000,
  58. ],
  59. 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
  60. 'templateResult' => new JsExpression('formatRepo'),
  61. 'templateSelection' => new JsExpression('formatRepoSelection'),
  62. ]
  63. ])->label('Новость')?>
  64. <div class="row">
  65. <div class="col-md-6">
  66. <?= $form->field($model, 'published_from')->widget(DateTimePicker::classname(), [
  67. 'name' => 'published_from',
  68. 'options' => ['class' => 'form-control'],
  69. 'convertFormat' => true,
  70. 'type' => DateTimePicker::TYPE_COMPONENT_PREPEND,
  71. 'pluginOptions' => [
  72. 'format' => 'yyyy-MM-dd hh:i:s',
  73. 'startDate' => '2023-01-01 12:00',
  74. 'todayHighlight' => true,
  75. 'autoclose'=>true
  76. ]
  77. ])?>
  78. </div>
  79. <div class="col-md-6">
  80. <?= $form->field($model, 'published_to')->widget(DateTimePicker::classname(), [
  81. 'name' => 'published_to',
  82. 'options' => ['class' => 'form-control'],
  83. 'convertFormat' => true,
  84. 'type' => DateTimePicker::TYPE_COMPONENT_PREPEND,
  85. 'pluginOptions' => [
  86. 'format' => 'yyyy-MM-dd hh:i:s',
  87. 'startDate' => '2023-01-01 12:00',
  88. 'todayHighlight' => true,
  89. 'autoclose'=>true
  90. ]
  91. ])?>
  92. </div>
  93. </div>
  94. <?= $form->field($model, 'is_active')->checkbox() ?>
  95. <div class="form-group">
  96. <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
  97. </div>
  98. <?php ActiveForm::end(); ?>
  99. </div>