/**
  * Render a hidden input, a text input with an auto-complete
  * event, and a select button. These three items together
  * form the Opportunity Editable Element
  * @return The element's content as a string.
  */
 protected function renderControlEditable()
 {
     $content = null;
     $content .= ZurmoHtml::textField('stageToProbabilityMapping_notUsed', null, array('id' => $this->getEditableInputId(), 'style' => "display:none;"));
     $fieldData = CustomFieldData::getByName('SalesStages');
     if ($fieldData->serializedData != null) {
         $values = unserialize($fieldData->serializedData);
         if (!is_array($values)) {
             $values = array();
         }
     } else {
         $values = array();
     }
     $stagesToProbabilities = OpportunitiesModule::getStageToProbabilityMappingData();
     foreach ($values as $value) {
         if (isset($stagesToProbabilities[$value])) {
             $probability = $stagesToProbabilities[$value];
         } else {
             $probability = 0;
         }
         $htmlOptions = array('name' => $this->getNameForInputField($value), 'value' => $probability);
         $element = $this->form->textField($this->model, $this->attribute, $htmlOptions);
         $element .= ZurmoHtml::tag('span', array(), $value);
         $content .= ZurmoHtml::tag('div', array('class' => 'has-lang-label'), $element);
     }
     return $content;
 }
 protected function registerStageToProbabilityMappingScript($form)
 {
     $stageInputId = Element::resolveInputIdPrefixIntoString(array(get_class($this->model), 'stage', 'value'));
     $probabilityInputId = Element::resolveInputIdPrefixIntoString(array(get_class($this->model), 'probability'));
     $mappingData = OpportunitiesModule::getStageToProbabilityMappingData();
     if (count($mappingData) > 0) {
         $jsonEncodedMapping = CJSON::encode($mappingData);
         Yii::app()->clientScript->registerScript('stageToProbabilityMapping', "\n                \$('#" . $stageInputId . "').unbind('change');\n                \$('#" . $stageInputId . "').bind('change', function()\n                    {\n                        stageToProbabilityMapping(\$(this));\n                    }\n                );\n                function stageToProbabilityMapping(stageInput)\n                {\n                    var value  = stageInput.val();\n                    var result = \$.parseJSON('" . $jsonEncodedMapping . "');\n                    \$('#" . $probabilityInputId . "').val(0);\n                    \$.each(result, function(stage, probability)\n                    {\n                        if (value == stage)\n                        {\n                            \$('#" . $probabilityInputId . "').val(probability);\n                            return false;\n                        }\n                    });\n                 }\n                 stageToProbabilityMapping(\$('#" . $stageInputId . "'));\n                ");
     }
 }
예제 #3
0
 /**
  * @depends testCreateStageValues
  */
 public function testGetStageToProbabilityMappingData()
 {
     $this->assertEquals(6, count(OpportunitiesModule::getStageToProbabilityMappingData()));
 }