Commit a679569431d6e10eb7e9562b88e09d3ee681525a
1 parent
740e8bee
feedback calculator almost
Showing
5 changed files
with
122 additions
and
158 deletions
Show diff stats
| 1 | +<?php | |
| 2 | + use common\models\Feedback; | |
| 3 | + use yii\web\View; | |
| 4 | + | |
| 5 | + /** | |
| 6 | + * @var View $this | |
| 7 | + * @var Feedback $model | |
| 8 | + */ | |
| 9 | + | |
| 10 | +?> | |
| 11 | + | |
| 12 | +<table> | |
| 13 | + <tbody> | |
| 14 | + <tr> | |
| 15 | + <td><b><?= \Yii::t('app', 'Name: ') ?></b></td> | |
| 16 | + <td><?= $model->name ?></td> | |
| 17 | + </tr> | |
| 18 | + <tr> | |
| 19 | + <td><b><?= \Yii::t('app', 'Topic: ') ?></b></td> | |
| 20 | + <td><?= $model->topic ?></td> | |
| 21 | + </tr> | |
| 22 | + <tr> | |
| 23 | + <td><b><?= \Yii::t('app', 'Phone: ') ?></b></td> | |
| 24 | + <td><?= $model->phone ?></td> | |
| 25 | + </tr> | |
| 26 | + <tr> | |
| 27 | + <td><b><?= \Yii::t('app', 'Email: ') ?></b></td> | |
| 28 | + <td><?= $model->email ?></td> | |
| 29 | + </tr> | |
| 30 | + <tr> | |
| 31 | + <td><b><?= \Yii::t('app', 'JSON string: ') ?></b></td> | |
| 32 | + <td><?= $model->calc_json_info ?></td> | |
| 33 | + </tr> | |
| 34 | + </tbody> | |
| 35 | +</table> | ... | ... |
common/models/Feedback.php
| ... | ... | @@ -24,16 +24,18 @@ |
| 24 | 24 | const calculator_attributes = [ |
| 25 | 25 | 'adress', 'module_install_angle', 'latitude', 'longitude', |
| 26 | 26 | 'south_deviation', 'power_station_type', 'area', 'power', |
| 27 | - 'budget', 'day_consumption', 'month_consumption', 'consumptors_total_power', | |
| 28 | - 'autonomous_days' | |
| 27 | + 'budget', 'auth_day', 'auth_month', 'auth_pwr_all', | |
| 28 | + 'auth_pwr_days' | |
| 29 | 29 | ]; |
| 30 | - | |
| 31 | - private $attributeValues = []; | |
| 30 | + | |
| 31 | + public $attributeValues = []; | |
| 32 | 32 | |
| 33 | 33 | public function __set($name, $value) |
| 34 | 34 | { |
| 35 | 35 | if(in_array($name, self::calculator_attributes)){ |
| 36 | - $this->attributeValues[$name] = $value; | |
| 36 | + if(isset($value) && !empty($value)){ | |
| 37 | + $this->attributeValues[$name] = $value; | |
| 38 | + } | |
| 37 | 39 | } |
| 38 | 40 | else{ |
| 39 | 41 | parent::__set($name, $value); |
| ... | ... | @@ -111,7 +113,6 @@ |
| 111 | 113 | 'name', |
| 112 | 114 | 'phone', |
| 113 | 115 | 'email', |
| 114 | - 'returnUrl', | |
| 115 | 116 | 'topic', |
| 116 | 117 | 'calc_json_info', |
| 117 | 118 | |
| ... | ... | @@ -125,9 +126,9 @@ |
| 125 | 126 | ); |
| 126 | 127 | } |
| 127 | 128 | |
| 128 | - public function setCalcJsonInfo( array $value) | |
| 129 | + public function setCalcJsonInfo() | |
| 129 | 130 | { |
| 130 | - $this->calc_json_info = json_encode($value); | |
| 131 | + $this->calc_json_info = json_encode($this->attributeValues); | |
| 131 | 132 | } |
| 132 | 133 | |
| 133 | 134 | public function getCalcJsonInfo() : array | ... | ... |
frontend/controllers/SiteController.php
| ... | ... | @@ -160,8 +160,8 @@ |
| 160 | 160 | if (empty(Yii::$app->request->post())) { |
| 161 | 161 | throw new BadRequestHttpException(); |
| 162 | 162 | } else { |
| 163 | - | |
| 164 | - switch (Yii::$app->request->post('topic')){ | |
| 163 | + $post = Yii::$app->request->post('Feedback'); | |
| 164 | + switch ($post['topic']){ | |
| 165 | 165 | case Feedback::SCENARIO_FEEDBACK : |
| 166 | 166 | $model = new Feedback(['scenario' => Feedback::SCENARIO_FEEDBACK]); |
| 167 | 167 | $view = 'feedback'; |
| ... | ... | @@ -178,14 +178,7 @@ |
| 178 | 178 | $model = new Feedback(['scenario' => Feedback::SCENARIO_CALCULATOR]); |
| 179 | 179 | $view = 'calculator'; |
| 180 | 180 | $isLoaded = $model->load(Yii::$app->request->post()); |
| 181 | - $newPost = []; | |
| 182 | - foreach (Feedback::calculator_attributes as $calculator_attribute_name){ | |
| 183 | - $calculator_attribute_value = Yii::$app->request->post($calculator_attribute_name); | |
| 184 | - if( isset($calculator_attribute_value) && !empty($calculator_attribute_value) ){ | |
| 185 | - $newPost[$calculator_attribute_name] = $calculator_attribute_value; | |
| 186 | - } | |
| 187 | - } | |
| 188 | - $model->setCalcJsonInfo($newPost); | |
| 181 | + $model->setCalcJsonInfo(); | |
| 189 | 182 | break; |
| 190 | 183 | |
| 191 | 184 | default: |
| ... | ... | @@ -216,6 +209,8 @@ |
| 216 | 209 | return [ |
| 217 | 210 | 'success' => true, |
| 218 | 211 | 'message' => 'Success message', |
| 212 | + 'view' => $view, | |
| 213 | + 'model' => $model->attributeValues, | |
| 219 | 214 | 'alert' => $this->renderPartial('success_alert'), |
| 220 | 215 | ]; |
| 221 | 216 | } else { | ... | ... |
frontend/views/layouts/main.php
| ... | ... | @@ -565,165 +565,98 @@ |
| 565 | 565 | <div class="col-md-12"> |
| 566 | 566 | <div class="row"> |
| 567 | 567 | <div class="col-md-4"> |
| 568 | - <div class="form-group field-calculate-email"> | |
| 569 | - <label class="control-label"><?= \Yii::t( | |
| 570 | - 'app', | |
| 571 | - 'info_area' | |
| 572 | - ) ?></label> | |
| 573 | - <input type="text" class="form-control"> | |
| 574 | - | |
| 575 | - <p class="help-block help-block-error"></p> | |
| 576 | - </div> | |
| 568 | + <?= $form->field($feedback, "area") | |
| 569 | + ->textInput() | |
| 570 | + ->label( | |
| 571 | + \Yii::t( | |
| 572 | + 'app', | |
| 573 | + 'info_area' | |
| 574 | + ) | |
| 575 | + )?> | |
| 577 | 576 | </div> |
| 578 | 577 | <div class="col-md-4"> |
| 579 | - <div class="form-group field-calculate-email"> | |
| 580 | - <label class="control-label"><?= \Yii::t( | |
| 581 | - 'app', | |
| 582 | - 'info_power' | |
| 583 | - ) ?></label> | |
| 584 | - <input type="text" class="form-control"> | |
| 585 | - | |
| 586 | - <p class="help-block help-block-error"></p> | |
| 587 | - </div> | |
| 578 | + <?= $form->field($feedback, "power") | |
| 579 | + ->textInput() | |
| 580 | + ->label( | |
| 581 | + \Yii::t( | |
| 582 | + 'app', | |
| 583 | + 'info_power' | |
| 584 | + ) | |
| 585 | + )?> | |
| 588 | 586 | </div> |
| 589 | 587 | <div class="col-md-4"> |
| 590 | - <div class="form-group field-calculate-email"> | |
| 591 | - <label class="control-label"><?= \Yii::t( | |
| 592 | - 'app', | |
| 593 | - 'info_budget' | |
| 594 | - ) ?></label> | |
| 595 | - <input type="text" class="form-control"> | |
| 596 | - | |
| 597 | - <p class="help-block help-block-error"></p> | |
| 598 | - </div> | |
| 588 | + <?= $form->field($feedback, "budget") | |
| 589 | + ->textInput() | |
| 590 | + ->label( | |
| 591 | + \Yii::t( | |
| 592 | + 'app', | |
| 593 | + 'info_budget' | |
| 594 | + ) | |
| 595 | + )?> | |
| 599 | 596 | </div> |
| 600 | 597 | </div> |
| 601 | 598 | </div> |
| 602 | 599 | </div> |
| 603 | 600 | </div> |
| 604 | 601 | </div> |
| 605 | - | |
| 606 | - <?php $form::end()?> | |
| 607 | 602 | |
| 608 | - <form action="" id="calculate-form"> | |
| 609 | - | |
| 610 | - <div class="row"> | |
| 611 | - <div class="col-md-12"> | |
| 612 | - <p style="font-weight:bold;"><?= \Yii::t('app', 'info_power_ses') ?></p> | |
| 613 | - <div class="row"> | |
| 614 | - <div class="col-md-12"> | |
| 615 | - <div class="row" style="margin-bottom: 15px;"> | |
| 616 | - <div class="col-md-3 col-sm-12 col-xs-12"> | |
| 617 | - <input class="custom-radio" id="custom-radio-Автономная" type="radio" name="Calculate[mode]" value="Автономная"><label for="custom-radio-Автономная"></label><span style="margin-left:5px;"><?= \Yii::t( | |
| 618 | - 'app', | |
| 619 | - 'authonomous' | |
| 620 | - ) ?></span></div> | |
| 621 | - <div class="col-md-3 col-sm-12 col-xs-12"> | |
| 622 | - <input class="custom-radio" id="custom-radio-Сетевая" type="radio" name="Calculate[mode]" value="Сетевая"><label for="custom-radio-Сетевая"></label><span style="margin-left:5px;"><?= \Yii::t( | |
| 623 | - 'app', | |
| 624 | - 'ses_network' | |
| 625 | - ) ?></span></div> | |
| 626 | - </div> | |
| 627 | - </div> | |
| 628 | - <div class="col-md-12"> | |
| 629 | - <div class="row"> | |
| 630 | - <div class="col-md-4"> | |
| 631 | - <div class="form-group field-calculate-email"> | |
| 632 | - <label class="control-label"><?= \Yii::t( | |
| 633 | - 'app', | |
| 634 | - 'info_area' | |
| 635 | - ) ?></label> | |
| 636 | - <input type="text" class="form-control"> | |
| 637 | - | |
| 638 | - <p class="help-block help-block-error"></p> | |
| 639 | - </div> | |
| 640 | - </div> | |
| 641 | - <div class="col-md-4"> | |
| 642 | - <div class="form-group field-calculate-email"> | |
| 643 | - <label class="control-label"><?= \Yii::t( | |
| 644 | - 'app', | |
| 645 | - 'info_power' | |
| 646 | - ) ?></label> | |
| 647 | - <input type="text" class="form-control"> | |
| 648 | - | |
| 649 | - <p class="help-block help-block-error"></p> | |
| 650 | - </div> | |
| 651 | - </div> | |
| 652 | - <div class="col-md-4"> | |
| 653 | - <div class="form-group field-calculate-email"> | |
| 654 | - <label class="control-label"><?= \Yii::t( | |
| 655 | - 'app', | |
| 656 | - 'info_budget' | |
| 657 | - ) ?></label> | |
| 658 | - <input type="text" class="form-control"> | |
| 659 | - | |
| 660 | - <p class="help-block help-block-error"></p> | |
| 661 | - </div> | |
| 662 | - </div> | |
| 663 | - </div> | |
| 664 | - </div> | |
| 665 | - </div> | |
| 666 | - </div> | |
| 667 | - </div> | |
| 668 | - | |
| 669 | - <div class="row"> | |
| 670 | - <div class="col-md-12"> | |
| 671 | - <p style="font-weight:bold;"><?= \Yii::t( | |
| 672 | - 'app', | |
| 673 | - 'info_power_ses_auth' | |
| 674 | - ) ?></p> | |
| 675 | - <div class="row"> | |
| 676 | - <div class="col-md-6"> | |
| 677 | - <div class="form-group field-calculate-email"> | |
| 678 | - <label class="control-label"><?= \Yii::t( | |
| 603 | + <div class="row"> | |
| 604 | + <div class="col-md-12"> | |
| 605 | + <p style="font-weight:bold;"><?= \Yii::t( | |
| 606 | + 'app', | |
| 607 | + 'info_power_ses_auth' | |
| 608 | + ) ?></p> | |
| 609 | + <div class="row"> | |
| 610 | + <div class="col-md-6"> | |
| 611 | + <?=$form->field($feedback, "auth_day") | |
| 612 | + ->textInput() | |
| 613 | + ->label( | |
| 614 | + \Yii::t( | |
| 679 | 615 | 'app', |
| 680 | 616 | 'info_auth_day' |
| 681 | - ) ?></label> | |
| 682 | - <input type="text" class="form-control"> | |
| 683 | - | |
| 684 | - <p class="help-block help-block-error"></p> | |
| 685 | - </div> | |
| 686 | - <div class="form-group field-calculate-email"> | |
| 687 | - <label class="control-label"><?= \Yii::t( | |
| 617 | + ) | |
| 618 | + )?> | |
| 619 | + | |
| 620 | + <?=$form->field($feedback, "auth_month") | |
| 621 | + ->textInput() | |
| 622 | + ->label( | |
| 623 | + \Yii::t( | |
| 688 | 624 | 'app', |
| 689 | 625 | 'info_auth_month' |
| 690 | - ) ?></label> | |
| 691 | - <input type="text" class="form-control"> | |
| 692 | - | |
| 693 | - <p class="help-block help-block-error"></p> | |
| 694 | - </div> | |
| 695 | - </div> | |
| 696 | - <div class="col-md-6"> | |
| 697 | - <div class="form-group field-calculate-email"> | |
| 698 | - <label class="control-label"><?= \Yii::t( | |
| 626 | + ) | |
| 627 | + )?> | |
| 628 | + </div> | |
| 629 | + | |
| 630 | + <div class="col-md-6"> | |
| 631 | + <?=$form->field($feedback, "auth_pwr_all") | |
| 632 | + ->textInput() | |
| 633 | + ->label( | |
| 634 | + \Yii::t( | |
| 699 | 635 | 'app', |
| 700 | 636 | 'info_auth_pwr_all' |
| 701 | - ) ?></label> | |
| 702 | - <input type="text" class="form-control"> | |
| 703 | - | |
| 704 | - <p class="help-block help-block-error"></p> | |
| 705 | - </div> | |
| 706 | - <div class="form-group field-calculate-email"> | |
| 707 | - <label class="control-label"><?= \Yii::t( | |
| 637 | + ) | |
| 638 | + )?> | |
| 639 | + <?=$form->field($feedback, "auth_pwr_days") | |
| 640 | + ->textInput() | |
| 641 | + ->label( | |
| 642 | + \Yii::t( | |
| 708 | 643 | 'app', |
| 709 | 644 | 'info_auth_pwr_days' |
| 710 | - ) ?></label> | |
| 711 | - <input type="text" class="form-control"> | |
| 712 | - | |
| 713 | - <p class="help-block help-block-error"></p> | |
| 714 | - </div> | |
| 715 | - </div> | |
| 645 | + ) | |
| 646 | + )?> | |
| 716 | 647 | </div> |
| 717 | 648 | </div> |
| 718 | 649 | </div> |
| 719 | - | |
| 720 | - <p class="text-center submit-wr"> | |
| 721 | - <button type="submit" class="send-form btn btn-lg btn-template-primary"><?= \Yii::t( | |
| 722 | - 'app', | |
| 723 | - 'info_calculate' | |
| 724 | - ) ?></button> | |
| 725 | - </p> | |
| 726 | - </form> | |
| 650 | + </div> | |
| 651 | + | |
| 652 | + <p class="text-center submit-wr"> | |
| 653 | + <button type="submit" class="send-form btn btn-lg btn-template-primary"><?= \Yii::t( | |
| 654 | + 'app', | |
| 655 | + 'info_calculate' | |
| 656 | + ) ?></button> | |
| 657 | + </p> | |
| 658 | + | |
| 659 | + <?php $form::end()?> | |
| 727 | 660 | |
| 728 | 661 | </div> |
| 729 | 662 | </div> | ... | ... |
frontend/web/js/script.js
| ... | ... | @@ -6,7 +6,7 @@ $( |
| 6 | 6 | */ |
| 7 | 7 | $(document) |
| 8 | 8 | .on( |
| 9 | - 'beforeSubmit', '#feedback-form', function(e) { | |
| 9 | + 'beforeSubmit', '#calculate-form, #feedback-form', function(e) { | |
| 10 | 10 | var f = this; |
| 11 | 11 | var form = $(this); |
| 12 | 12 | var formData = form.serialize(); |
| ... | ... | @@ -17,7 +17,7 @@ $( |
| 17 | 17 | data: formData, |
| 18 | 18 | success: function(data) { |
| 19 | 19 | f.reset(); |
| 20 | - $('#feedback-modal') | |
| 20 | + $('#feedback-modal,#calculate-modal') | |
| 21 | 21 | .modal('hide'); |
| 22 | 22 | form.data('yiiActiveForm').validated = false; |
| 23 | 23 | $('#success-modal') |
| ... | ... | @@ -32,7 +32,7 @@ $( |
| 32 | 32 | } |
| 33 | 33 | ) |
| 34 | 34 | .on( |
| 35 | - 'submit', '#feedback-form', function(e) { | |
| 35 | + 'submit', '#calculate-form, #feedback-form', function(e) { | |
| 36 | 36 | e.preventDefault(); |
| 37 | 37 | } |
| 38 | 38 | ); | ... | ... |