PageRenderTime 37ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/modules/contacts/views/attributetypes/ModelAttributeElementPreContentView.php

https://bitbucket.org/zurmo/zurmo/
PHP | 153 lines | 79 code | 8 blank | 66 comment | 4 complexity | 65d003f9243a79415444c2643dfeb95d 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. /**
  37. * Renders content before the element.
  38. */
  39. class ModelAttributeElementPreContentView extends ZurmoWidget
  40. {
  41. /**
  42. * Models selected for merge.
  43. * @var array
  44. */
  45. public $selectedModels;
  46. /**
  47. * Attributes associated to the element. This would include multiple attributes in case
  48. * of derived ones.
  49. * @var array
  50. */
  51. public $attributes;
  52. /**
  53. * Primary model associated to the merged item.
  54. * @var RedBeanModel
  55. */
  56. public $primaryModel;
  57. /**
  58. * Element associated to the merged item.
  59. * @var string
  60. */
  61. public $element;
  62. /**
  63. * @var ModelAttributeAndElementDataToMergeItem
  64. */
  65. public $modelAttributeAndElementDataToMergeItemClass;
  66. /**
  67. * Runs the widget
  68. */
  69. public function run()
  70. {
  71. $attributes = $this->attributes;
  72. $content = null;
  73. if ($this->modelAttributeAndElementDataToMergeItemClass == null)
  74. {
  75. $modelAttributeAndElementDataToMergeItemClass = 'ModelAttributeAndElementDataToMergeItem';
  76. }
  77. else
  78. {
  79. $modelAttributeAndElementDataToMergeItemClass = $this->modelAttributeAndElementDataToMergeItemClass;
  80. }
  81. foreach ($attributes as $attribute)
  82. {
  83. $attributeContent = null;
  84. $position = 1;
  85. foreach ($this->selectedModels as $model)
  86. {
  87. $modelAttributeAndElementDataToMergeItem = new $modelAttributeAndElementDataToMergeItemClass(
  88. $model, $attribute, $this->element, $this->primaryModel, $position++);
  89. $attributeContent .= $modelAttributeAndElementDataToMergeItem->getAttributeRenderedContent();
  90. }
  91. $content .= ZurmoHtml::tag('div', array('class' => 'hasPossibles'), $attributeContent);
  92. }
  93. Yii::app()->clientScript->registerScript('preContentSelectScript', $this->registerScriptForAttributeReplacement());
  94. echo $content;
  95. }
  96. /**
  97. * Registers script for attribute replacement
  98. * @return string
  99. */
  100. protected function registerScriptForAttributeReplacement()
  101. {
  102. // Begin Not Coding Standard
  103. $script = "$('.attributePreElementContent').click(function(){
  104. $('#' + $(this).data('id')).val($(this).data('value'));
  105. $('#' + $(this).data('id')).focus();
  106. $(this).siblings('a').removeClass('selected');
  107. $(this).addClass('selected');
  108. return false;
  109. });";
  110. $script .= "$('.attributePreTagCloudElementContent').click(function(){
  111. var dataArray = $.map($(this).data('value').split(','), $.trim);
  112. $('#' + $(this).data('id')).val($(this).data('value'));
  113. $('#' + $(this).data('id')).tokenInput('clear');
  114. for (index = 0; index < dataArray.length; ++index) {
  115. if (dataArray[index].length)
  116. {
  117. var tokenData = {id: dataArray[index], name: dataArray[index]};
  118. $('#' + $(this).data('id')).tokenInput('add', tokenData);
  119. }
  120. }
  121. $('#' + $(this).data('id')).focus();
  122. $(this).siblings('a').removeClass('selected');
  123. $(this).addClass('selected');
  124. return false;
  125. });";
  126. $script .= "$('.attributePreMultiSelectDropDownElementContent').click(function(){
  127. var dataArray = $.map($(this).data('value').split(','), $.trim);
  128. $('#' + $(this).data('id') + '_values').val(dataArray);
  129. $('#' + $(this).data('id') + '_values').focus();
  130. $(this).siblings('a').removeClass('selected');
  131. $(this).addClass('selected');
  132. return false;
  133. });";
  134. $script .= "$('.attributePreElementContentModelElement').click(function(){
  135. $('#' + $(this).data('id')).val($(this).data('value'));
  136. $('#' + $(this).data('hiddenid')).val($(this).data('hiddenvalue'));
  137. $(this).siblings('a').removeClass('selected');
  138. $(this).addClass('selected');
  139. return false;
  140. });";
  141. // End Not Coding Standard
  142. return $script;
  143. }
  144. }
  145. ?>