_form.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Author: lf
  4. * Blog: https://blog.feehi.com
  5. * Email: job@feehi.com
  6. * Created at: 2017-12-05 13:00
  7. */
  8. /**
  9. * @var $this yii\web\View
  10. * @var $model common\models\User
  11. */
  12. use backend\widgets\ActiveForm;
  13. use common\libs\Constants;
  14. use common\widgets\JsBlock;
  15. $this->title = 'Ad';
  16. ?>
  17. <div class="col-sm-12">
  18. <div class="ibox">
  19. <?= $this->render('/widgets/_ibox-title') ?>
  20. <div class="ibox-content">
  21. <?php $form = ActiveForm::begin([
  22. 'options' => [
  23. 'enctype' => 'multipart/form-data',
  24. 'class' => 'form-horizontal'
  25. ]
  26. ]); ?>
  27. <?= $form->field($model, 'name')->textInput(); ?>
  28. <div class="hr-line-dashed"></div>
  29. <?= $form->field($model, 'tips')->textInput(); ?>
  30. <div class="hr-line-dashed"></div>
  31. <?= $form->field($model, 'input_type')->dropDownList(Constants::getAdTypeItems()); ?>
  32. <div class="hr-line-dashed"></div>
  33. <?php
  34. foreach (Constants::getAdTypeItems() as $type => $name){
  35. $options = ['options'=>['class'=>"form-group input_$type"]];
  36. switch ($type){
  37. case Constants::AD_TEXT:
  38. echo $form->field($model, "ad", $options)
  39. ->textarea();
  40. break;
  41. case Constants::AD_IMG:
  42. echo $form->field($model,"ad", $options)
  43. ->imgInput();
  44. break;
  45. case Constants::AD_VIDEO:
  46. echo $form->field($model, "ad", $options)
  47. ->fileInput();
  48. break;
  49. }
  50. }
  51. ?>
  52. <div class="hr-line-dashed"></div>
  53. <?= $form->field($model, 'link')->textInput(); ?>
  54. <div class="hr-line-dashed"></div>
  55. <?= $form->field($model, 'desc')->textInput(); ?>
  56. <div class="hr-line-dashed"></div>
  57. <?= $form->field($model, 'target')->radioList(Constants::getTargetOpenMethod()); ?>
  58. <div class="hr-line-dashed"></div>
  59. <?= $form->field($model, 'sort')->textInput(); ?>
  60. <div class="hr-line-dashed"></div>
  61. <?= $form->field($model, 'autoload')->radioList(Constants::getStatusItems()); ?>
  62. <div class="hr-line-dashed"></div>
  63. <?= $form->defaultButtons() ?>
  64. <?php ActiveForm::end(); ?>
  65. </div>
  66. </div>
  67. </div>
  68. <?php JsBlock::begin() ?>
  69. <script>
  70. $(document).ready(function () {
  71. var defaultType = $("select#adform-input_type :selected").val();
  72. $(".form-group.field-adform-ad").not(".input_"+defaultType).hide().find("input[name=AdForm\\[ad\\]], textarea[name=AdForm\\[ad\\]]").attr('disabled', true);
  73. $("select#adform-input_type").change(function () {
  74. var type = parseInt( $(this).val() );
  75. $(".form-group.field-adform-ad").hide().find("input[name=AdForm\\[ad\\]], textarea[name=AdForm\\[ad\\]]").attr('disabled', true);
  76. $(".form-group.field-adform-ad.input_"+type).show().attr('name', 'AdForm[value]').find("input[name=AdForm\\[ad\\]], textarea[name=AdForm\\[ad\\]]").attr('disabled', false);
  77. })
  78. })
  79. </script>
  80. <?php JsBlock::end() ?>