PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/modules/opportunities/views/OpportunityConvertToView.php

https://bitbucket.org/zurmo/zurmo/
PHP | 219 lines | 160 code | 8 blank | 51 comment | 9 complexity | 76678a1f6d60e33a06bcacf4ae1b9297 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2015 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * Zurmo is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
  24. * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
  25. *
  26. * The interactive user interfaces in original and modified versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the Zurmo
  32. * logo and Zurmo copyright notice. If the display of the logo is not reasonably
  33. * feasible for technical reasons, the Appropriate Legal Notices must display the words
  34. * "Copyright Zurmo Inc. 2015. All rights reserved".
  35. ********************************************************************************/
  36. class OpportunityConvertToView extends EditView
  37. {
  38. protected $wrapContentInWrapperDiv = false;
  39. /**
  40. * Override to pass in the relation Id as the modelId. In the case of lead conversion, the lead->id is the
  41. * $modelId. This can then be used for a cancel button to return to the lead detailview.
  42. * @param string $controllerId
  43. * @param string $moduleId
  44. * @param RedsBeanModel $model
  45. * @param integer $modelId
  46. */
  47. public function __construct($controllerId, $moduleId, $model, $modelId)
  48. {
  49. assert('is_int($modelId)');
  50. parent::__construct($controllerId, $moduleId, $model);
  51. $this->modelId = $modelId;
  52. }
  53. public static function getDefaultMetadata()
  54. {
  55. $metadata = array(
  56. 'global' => array(
  57. 'toolbar' => array(
  58. 'elements' => array(
  59. array('type' => 'BackConvertLink'),
  60. array('type' => 'SaveButton', 'label' => "eval:Zurmo::t('ZurmoModule', 'Complete Conversion')"),
  61. array('type' => 'CancelConvertLink'),
  62. ),
  63. ),
  64. 'panelsDisplayType' => FormLayout::PANELS_DISPLAY_TYPE_ALL,
  65. 'panels' => array(
  66. array(
  67. 'rows' => array(
  68. array('cells' =>
  69. array(
  70. array(
  71. 'elements' => array(
  72. array('attributeName' => 'name', 'type' => 'Text'),
  73. ),
  74. ),
  75. )
  76. ),
  77. array('cells' =>
  78. array(
  79. array(
  80. 'elements' => array(
  81. array('attributeName' => 'amount', 'type' => 'CurrencyValue'),
  82. ),
  83. ),
  84. )
  85. ),
  86. array('cells' =>
  87. array(
  88. array(
  89. 'elements' => array(
  90. array('attributeName' => 'closeDate', 'type' => 'Date'),
  91. ),
  92. ),
  93. )
  94. ),
  95. array('cells' =>
  96. array(
  97. array(
  98. 'elements' => array(
  99. array('attributeName' => 'stage', 'type' => 'DropDown', 'addBlank' => true),
  100. ),
  101. ),
  102. )
  103. ),
  104. array('cells' =>
  105. array(
  106. array(
  107. 'elements' => array(
  108. array('attributeName' => 'probability', 'type' => 'Integer'),
  109. ),
  110. ),
  111. )
  112. ),
  113. ),
  114. ),
  115. ),
  116. ),
  117. );
  118. return $metadata;
  119. }
  120. public static function getDesignerRulesType()
  121. {
  122. return 'OpportunityConvertToView';
  123. }
  124. /**
  125. * Override to remove unused float-bar div
  126. * @param string $content
  127. * @return string
  128. */
  129. protected function resolveAndWrapDockableViewToolbarContent($content)
  130. {
  131. assert('is_string($content)');
  132. if ($this->disableFloatOnToolbar)
  133. {
  134. $disableFloatContent = ' disable-float-bar';
  135. }
  136. else
  137. {
  138. $disableFloatContent = null;
  139. }
  140. $content = ZurmoHtml::tag('div', array('class' => 'form-toolbar'), $content);
  141. $content = ZurmoHtml::tag('div', array('class' => 'view-toolbar-container clearfix dock' . $disableFloatContent), $content);
  142. return $content;
  143. }
  144. /**
  145. * Override to disabling probability attribute.
  146. */
  147. protected function resolveElementInformationDuringFormLayoutRender(& $elementInformation)
  148. {
  149. parent::resolveElementInformationDuringFormLayoutRender($elementInformation);
  150. $automaticMappingDisabled = OpportunitiesModule::isAutomaticProbabilityMappingDisabled();
  151. if ($automaticMappingDisabled === false)
  152. {
  153. if ($elementInformation['attributeName'] == 'probability')
  154. {
  155. $elementInformation['disabled'] = true;
  156. }
  157. }
  158. }
  159. protected function renderAfterFormLayout($form)
  160. {
  161. parent::renderAfterFormLayout($form);
  162. $automaticMappingDisabled = OpportunitiesModule::isAutomaticProbabilityMappingDisabled();
  163. if ($automaticMappingDisabled === false)
  164. {
  165. $this->registerStageToProbabilityMappingScript($form);
  166. }
  167. }
  168. protected function registerStageToProbabilityMappingScript($form)
  169. {
  170. $stageInputId = Element::resolveInputIdPrefixIntoString(array(get_class($this->model), 'stage', 'value'));
  171. $probabilityInputId = Element::resolveInputIdPrefixIntoString(array(get_class($this->model), 'probability'));
  172. $mappingData = OpportunitiesModule::getStageToProbabilityMappingData();
  173. if (count($mappingData) > 0)
  174. {
  175. $jsonEncodedMapping = CJSON::encode($mappingData);
  176. // In case of edit, we need the exact value from db
  177. if ($this->model->id > 0)
  178. {
  179. $initialCallToFunction = "";
  180. }
  181. else
  182. {
  183. $initialCallToFunction = " stageToProbabilityMapping($('#" . $stageInputId . "'));";
  184. }
  185. Yii::app()->clientScript->registerScript('stageToProbabilityMapping', "
  186. $('#" . $stageInputId . "').unbind('change.probabilityMapping');
  187. $('#" . $stageInputId . "').bind('change.probabilityMapping', function()
  188. {
  189. stageToProbabilityMapping($(this));
  190. }
  191. );
  192. function stageToProbabilityMapping(stageInput)
  193. {
  194. var value = stageInput.val();
  195. var result = $.parseJSON('" . $jsonEncodedMapping . "');
  196. $('#" . $probabilityInputId . "').val(0);
  197. $.each(result, function(stage, probability)
  198. {
  199. if (value == stage)
  200. {
  201. $('#" . $probabilityInputId . "').val(probability);
  202. return false;
  203. }
  204. });
  205. }
  206. ".$initialCallToFunction // Not Coding Standard
  207. );
  208. }
  209. }
  210. }
  211. ?>