public function registerScripts()
 {
     parent::registerScripts();
     $chartTypesRequiringSecondInputs = ChartRules::getChartTypesRequiringSecondInputs();
     $script = '
             if ($(".chart-selector:checked").val() != "")
             {
                 $("#series-and-range-areas").detach().insertAfter( $(".chart-selector:checked").parent()).removeClass("hidden-element");
             }
             $(".chart-selector").live("change", function()
                 {
                     onChangeChartType(this);
                 }
             );
             function onChangeChartType(changedChartObject)
             {
                 $("#series-and-range-areas").detach().insertAfter( $(changedChartObject).parent()  ).removeClass("hidden-element");
                 arr = ' . CJSON::encode($chartTypesRequiringSecondInputs) . ';
                 if ($(changedChartObject).val() == "")
                 {
                     $("#series-and-range-areas").addClass("hidden-element")
                     $(".first-series-and-range-area").hide();
                     $(".first-series-and-range-area").find("select option:selected").removeAttr("selected");
                     $(".first-series-and-range-area").find("select").prop("disabled", true);
                 }
                 else
                 {
                     $(".first-series-and-range-area").show();
                     $(".first-series-and-range-area").find("select").prop("disabled", false);
                 }
                 if ($.inArray($(changedChartObject).val(), arr) != -1)
                 {
                     $(".second-series-and-range-area").show();
                     $(".second-series-and-range-area").find("select").prop("disabled", false);
                 }
                 else
                 {
                     $(".second-series-and-range-area").hide();
                     $(".second-series-and-range-area").find("select option:selected").removeAttr("selected");
                     $(".second-series-and-range-area").find("select").prop("disabled", true);
                 }
             }
         ';
     Yii::app()->getClientScript()->registerScript('ChartChangingScript', $script);
 }
Пример #2
0
 /**
  * Validates that the first and second series/ranges are properly formed.
  * @return bool
  */
 public function validateSeriesAndRange()
 {
     $passedValidation = true;
     if ($this->type != null) {
         if ($this->firstSeries == null) {
             $this->addError('firstSeries', Zurmo::t('ReportsModule', 'First Series cannot be blank.'));
             $passedValidation = false;
         }
         if ($this->firstRange == null) {
             $this->addError('firstRange', Zurmo::t('ReportsModule', 'First Range cannot be blank.'));
             $passedValidation = false;
         }
         if (in_array($this->type, ChartRules::getChartTypesRequiringSecondInputs()) && $this->secondSeries == null) {
             $this->addError('secondSeries', Zurmo::t('ReportsModule', 'Second Series cannot be blank.'));
             $passedValidation = false;
         }
         if (in_array($this->type, ChartRules::getChartTypesRequiringSecondInputs()) && $this->secondRange == null) {
             $this->addError('secondRange', Zurmo::t('ReportsModule', 'Second Range cannot be blank.'));
             $passedValidation = false;
         }
         if ($this->firstSeries != null && $this->secondSeries != null && $this->firstSeries == $this->secondSeries) {
             $this->addError('secondSeries', Zurmo::t('ReportsModule', 'Second Series must be unique.'));
             $passedValidation = false;
         }
         if ($this->firstRange != null && $this->secondRange != null && $this->firstRange == $this->secondRange) {
             $this->addError('secondRange', Zurmo::t('ReportsModule', 'Second Range must be unique.'));
             $passedValidation = false;
         }
     }
     return $passedValidation;
 }