PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/backend/modules/systemAdmin/Catalog/views/CatalogItemold/_form.php

https://gitlab.com/aintenebris/memoria
PHP | 221 lines | 177 code | 29 blank | 15 comment | 1 complexity | cab4eeb92acb02293f3f2c28769cd435 MD5 | raw file
  1. <?php
  2. use backend\modules\systemAdmin\Catalog\models\base\CatalogItem;
  3. use backend\modules\systemAdmin\Catalog\models\Section;
  4. use app\modules\systemAdmin\models\details\DetailTypes;
  5. use backend\modules\systemAdmin\Catalog\models\Size;
  6. use backend\modules\systemAdmin\Catalog\models\SystemCatalogs;
  7. use yii\helpers\ArrayHelper;
  8. use yii\helpers\Html;
  9. use yii\helpers\Url;
  10. use yii\widgets\ActiveForm;
  11. use wbraganca\dynamicform\DynamicFormWidget;
  12. //echo '<pre>';
  13. //print_r($model->name);
  14. //exit;
  15. /* @var $this yii\web\View */
  16. /* @var $model app\modules\systemAdmin\Catalog\models\CatalogItem */
  17. /* @var $form yii\widgets\ActiveForm */
  18. ?>
  19. <script>
  20. var img = '<img id="modelPreviewImg" height="70" width="40">';
  21. </script>
  22. <div class="catalog-item-form">
  23. <?php $form = ActiveForm::begin(['id' => 'dynamic-form']); ?>
  24. <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
  25. <?= $form->field($model, 'catalog')->dropDownList(
  26. ArrayHelper::map(SystemCatalogs::find()->all(), 'id', 'name'),
  27. [
  28. 'prompt' => Yii::t('app', 'Select catalog'),
  29. 'onchange' =>'
  30. $.post("' . Url::toRoute(['section/lists']) . '?id=" + $(this).val(), function(data){
  31. $("select#catalogitem-section_id").html(data);
  32. });',
  33. ]
  34. ) ?>
  35. <?= $form->field($model, 'section_id')->dropDownList(
  36. ArrayHelper::map(Section::find()->all(), 'id', 'name'),
  37. [
  38. 'prompt' => Yii::t('app', 'Select section'),
  39. 'onchange' =>'
  40. $.post("' . Url::toRoute(['catalogitem/lists']) . '?id=' . '" + $(this).val(), function(data){
  41. $("select#catalogitem-parent_id").html(data);
  42. });',
  43. ]
  44. ) ?>
  45. <?= $form->field($model, 'parent_id')->dropDownList(
  46. ArrayHelper::map(CatalogItem::find()->all(), 'id', 'name'),
  47. ['prompt' => Yii::t('app', 'Select item')]
  48. ) ?>
  49. <?= $form->field($model, 'type')->dropDownList(
  50. ArrayHelper::map(DetailTypes::find()->all(), 'id', 'name'),
  51. [
  52. 'prompt' => Yii::t('app', 'Select item'),
  53. 'onchange' =>'
  54. $.post("' . Url::toRoute(['catalogitem/modellists']) . '?id=' . '" + $(this).val(), function(data){
  55. console.log(data);
  56. $("#modalViewer").html("");
  57. $("#modalViewer").append(data);
  58. $(".iconItem").each(function(){
  59. var _this = $(this);
  60. $(this).click(function(){
  61. $(".iconItem").each(function(){
  62. $(this).children().removeClass("selected");
  63. });
  64. _this.children().addClass("selected");
  65. $("#catalogitem-detail_id").val(_this.attr("id"));
  66. $("#modelPreviewImg").remove();
  67. $("#currentModel").append(img);
  68. $("#currentModel").children().attr("src", _this.children().attr("src"));
  69. });
  70. });
  71. });',
  72. ]
  73. ) ?>
  74. <?php DynamicFormWidget::begin([
  75. 'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
  76. 'widgetBody' => '.container-items', // required: css class selector
  77. 'widgetItem' => '.item', // required: css class
  78. 'limit' => 50, // the maximum times, an element can be added (default 999)
  79. 'min' => 1, // 0 or 1 (default 1)
  80. 'insertButton' => '.add-item', // css class
  81. 'deleteButton' => '.remove-item', // css class
  82. 'model' => $modelsCatalogItemSize[0],
  83. 'formId' => 'dynamic-form',
  84. 'formFields' => [
  85. 'full_name',
  86. 'address_line1',
  87. 'address_line2',
  88. 'city',
  89. 'state',
  90. 'postal_code',
  91. ],
  92. ]); ?>
  93. <div class="panel panel-default">
  94. <div class="panel-heading">
  95. <h4>
  96. <i class="glyphicon glyphicon-resize-vertical"></i>
  97. <i class="glyphicon glyphicon-resize-horizontal"></i>
  98. Sizes
  99. <button type="button" class="add-item btn btn-success btn-sm pull-right"><i class="glyphicon glyphicon-plus"></i> Add</button>
  100. </h4>
  101. </div>
  102. <div class="panel-body">
  103. <div class="container-items"><!-- widgetBody -->
  104. <?php foreach ($modelsCatalogItemSize as $i => $modelsCatalogItemSize): ?>
  105. <div class="item panel panel-default"><!-- widgetItem -->
  106. <div class="panel-heading">
  107. <h3 class="panel-title pull-left">Sizes</h3>
  108. <div class="pull-right">
  109. <button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
  110. </div>
  111. <div class="clearfix"></div>
  112. </div>
  113. <div class="panel-body">
  114. <?php
  115. // necessary for update action.
  116. if (! $modelsCatalogItemSize->isNewRecord) {
  117. echo Html::activeHiddenInput($modelsCatalogItemSize, "[{$i}]id");
  118. }
  119. ?>
  120. <?= $form->field($modelsCatalogItemSize, "[$i]size_id")->dropDownList(
  121. ArrayHelper::map(Size::find()->all(), 'id', 'fullName'),
  122. [
  123. 'prompt' => Yii::t('app', 'Select size'),
  124. ]
  125. ) ?>
  126. </div>
  127. </div>
  128. <?php endforeach; ?>
  129. </div>
  130. </div>
  131. </div><!-- .panel -->
  132. <?php DynamicFormWidget::end(); ?>
  133. <?= $form->field($model, 'detail_id')->hiddenInput(
  134. [
  135. 'value' => $model->detail_id,
  136. ]
  137. // ArrayHelper::map(Models::find()->all(), 'id', 'model.id'),
  138. // ['prompt' => Yii::t('app', 'Select item')]
  139. ) ?>
  140. <div id="modalViewer" style="height: 100px; width: 100%; background: #00b3ee; overflow-x: scroll;"></div>
  141. <div id="currentModel" style="height: 80px;">
  142. <!-- <img height="70" width="40" src="/advanced/backend/web/">-->
  143. </div>
  144. <div class="form-group">
  145. <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
  146. </div>
  147. <?php ActiveForm::end(); ?>
  148. </div>
  149. <script>
  150. // window.onload = function(){
  151. <!-- $.get("getcurrentimage?id=--><?//= $model->detail_id ?><!--", function(data){-->
  152. // console.log(data);
  153. // $('#currentModel').children().attr('src', data);
  154. // $('#currentModel').append('<img height="70" width="40" src="' + data + '">');
  155. <!---->
  156. // });
  157. // }
  158. window.onload = function(){
  159. $.post("<?= Url::toRoute(['catalogitem/modellists']) ?>?id=<?= $model->type->id ?>",
  160. function(data){
  161. console.log(data);
  162. $("#modalViewer").html("");
  163. $("#modalViewer").append(data);
  164. var $elem = $("#<?= $model->model->id ?>");
  165. $elem.children().addClass("selected");
  166. $("#catalogitem-detail_id").val($elem.attr("id"));
  167. $("#currentModel").append(img);
  168. $("#currentModel").children().attr("src", $elem.children().attr("src"));
  169. $(".iconItem").each(function(){
  170. var _this = $(this);
  171. $(this).click(function(){
  172. $(".iconItem").each(function(){
  173. $(this).children().removeClass("selected");
  174. });
  175. _this.children().addClass("selected");
  176. $("#catalogitem-detail_id").val(_this.attr("id"));
  177. $("#modelPreviewImg").remove();
  178. $("#currentModel").append(img);
  179. $("#currentModel").children().attr("src", _this.children().attr("src"));
  180. });
  181. });
  182. });
  183. }
  184. </script>