PageRenderTime 43ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/backend/modules/systemAdmin/Catalog/views/catalog-item/_form.php

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