Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SelectBaseTemplateElement.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 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. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  const FILTER_BY_PREDEFINED_TEMPLATES = 1;
40 
41  const FILTER_BY_PREVIOUSLY_CREATED_TEMPLATES = 2;
42 
43  const CLOSE_LINK_CLASS_NAME = 'closeme';
44 
45  const MODEL_CLASS_NAME_ATTRIBUTE = 'modelClassName';
46 
47  const ITEMS_LIST_CLASS_NAME = 'template-list';
48 
49  const ITEMS_TAG_NAME = 'ul';
50 
51  protected function renderControlEditable()
52  {
53  $dataProvider = $this->getDataProviderByGet();
54  $cClipWidget = new CClipWidget();
55  $cClipWidget->beginClip("ListView");
56  $cClipWidget->widget('application.core.widgets.ZurmoListView', array(
57  'id' => $this->getListViewId(),
58  'dataProvider' => $dataProvider,
59  'itemView' => 'BaseEmailTemplateItemForListView',
60  'itemsTagName' => static::ITEMS_TAG_NAME,
61  'itemsCssClass' => static::ITEMS_LIST_CLASS_NAME . ' clearfix',
62  'pager' => $this->getCGridViewPagerParams(),
63  'htmlOptions' => array('class' => 'templates-chooser-list clearfix'),
64  'beforeAjaxUpdate' => $this->getCGridViewBeforeAjaxUpdate(),
65  'afterAjaxUpdate' => $this->getCGridViewAfterAjaxUpdate(),
66  'template' => static::getGridTemplate(),
67  ));
68  $cClipWidget->endClip();
69  $content = $this->renderActionBar();
70  $content .= $cClipWidget->getController()->clips['ListView'];
71  $content .= $this->renderHiddenInput();
72  $this->registerScripts($cClipWidget->id);
73  return $content;
74  }
75 
76  protected static function getGridTemplate()
77  {
78  $preloader = '<div class="list-preloader"><span class="z-spinner"></span></div>';
79  return "{summary}{sorter}{items}" . $preloader . "{pager}";
80  }
81 
82  protected function getCGridViewBeforeAjaxUpdate()
83  {
84  return "js:function(id, options) {
85  cacheListItems = $('" . static::getItemsListJQuerySelector() . "').html()
86  }";
87  }
88 
89  public static function getItemsListJQuerySelector()
90  {
91  return static::ITEMS_TAG_NAME . '.' . static::ITEMS_LIST_CLASS_NAME;
92  }
93 
94  protected function getCGridViewAfterAjaxUpdate()
95  {
96  // Begin Not Coding Standard
97  return "js:function(id, data) {
98  var html = $('" . static::getItemsListJQuerySelector() . "').html();
99  $('" . static::getItemsListJQuerySelector() . "').html(cacheListItems + html);
100  }";
101  // End Not Coding Standard
102  }
103 
104  protected function getDataProviderByGet()
105  {
106  $modelClassName = $this->resolveModelClassName();
107  $filterBy = ArrayUtil::getArrayValue(GetUtil::getData(), 'filterBy');
108  $sortAttribute = null;
109  $sortDescending = false;
110  if ($filterBy == static::FILTER_BY_PREVIOUSLY_CREATED_TEMPLATES)
111  {
112  $searchAttributeData = EmailTemplate::getPreviouslyCreatedBuilderTemplateSearchAttributeData($modelClassName, false);
113  $sortAttribute = 'isFeatured';
114  $sortDescending = true;
115  }
116  else
117  {
119  $sortAttribute = 'id';
120  }
121  $dataProvider = RedBeanModelDataProviderUtil::makeDataProvider($searchAttributeData, 'EmailTemplate', 'RedBeanModelDataProvider', $sortAttribute, $sortDescending, 10);
122  return $dataProvider;
123  }
124 
125  protected function renderActionBar()
126  {
127  $modelClassName = $this->resolveModelClassName();
128  $content = '
129  <div class="pills">
130  <a href="#" class="filter-link active" data-filter="' . static::FILTER_BY_PREDEFINED_TEMPLATES . '">' .
131  Zurmo::t('DesignerModule', 'Layouts') . '</a>
132  <a href="#" id="saved-templates-link" class="filter-link" data-filter="' . static::FILTER_BY_PREVIOUSLY_CREATED_TEMPLATES . '">' .
133  Zurmo::t('EmailTemplatesModule', 'Saved Templates') . '</a>
134  </div>
135  ';
136  $content .= $this->renderCloseSelectTemplatesButton();
137  $content = ZurmoHtml::tag('div', array('class' => 'mini-pillbox'), $content);
138  return $content;
139  }
140 
141  protected function renderCloseSelectTemplatesButton()
142  {
143  $linkText = ZurmoHtml::icon('icon-x');
144  $linkText .= Zurmo::t('Core', 'cancel');
145  return ZurmoHtml::link($linkText, '#', array('class' => 'simple-link ' . static::CLOSE_LINK_CLASS_NAME));
146  }
147 
148  protected function getCGridViewPagerParams()
149  {
150  $pagerParams = array(
151  'class' => 'BottomLinkPager',
152  'nextPageLabel' => '<span>' . Zurmo::t('Core', 'next') . '</span>',
153  'header' => '<div class="list-preloader"><span class="z-spinner"></span></div>',
154  'htmlOptions' => array('class' => 'endless-list-pager')
155  );
156  return $pagerParams;
157  }
158 
159  protected function renderHiddenInput()
160  {
161  $attribute = $this->attribute;
162  return ZurmoHtml::hiddenField($this->getEditableInputName(),
163  $this->model->$attribute,
164  array('id' => $this->getEditableInputId()));
165  }
166 
167  protected function renderControlNonEditable()
168  {
169  throw new NotSupportedException();
170  }
171 
172  protected function registerScripts($listViewId)
173  {
174  $script = $this->renderOnClickUseLinkScript();
175  $script .= $this->renderOnClickPreviewLinkScript();
176  $script .= $this->renderOnClickFilterLinksScript($listViewId);
177  Yii::app()->getClientScript()->registerScript(__CLASS__, $script);
178  }
179 
180  protected function renderOnClickUseLinkScript()
181  {
183  $script = "
184  $('body').off('click', '.use-template');
185  $('body').on('click', '.use-template', function (event) {
186  var currentSelectedValue = $(this).closest('li').data('value');
187  originalBaseTemplateId = $('" . SelectBaseTemplateForEmailTemplateWizardView::resolveOriginalBaseTemplateIdHiddenInputJQuerySelector() . "').val();
188  // show warning only on edit when a user has already been to canvas once.
189  if (originalBaseTemplateId != '' && currentSelectedValue != originalBaseTemplateId)
190  {
191  if (!confirm('" . Zurmo::t('EmailTemplatesModule', 'Changing base template would trash any existing design made on canvas.') ."'))
192  {
193  return false;
194  }
195  }
196  $('#{$this->getEditableInputId()}').val(currentSelectedValue);
197  updateBaseTemplateIdHiddenInputValue(currentSelectedValue);
198  updateSelectedLayout($(this).closest('li'));
199  $('#BuilderEmailTemplateWizardView .float-bar').show();
200  $('#" . SelectBaseTemplateForEmailTemplateWizardView::CHOSEN_DIV_ID . "').show();
201  $('#" . SelectBaseTemplateForEmailTemplateWizardView::TEMPLATES_DIV_ID . "').hide();
202  event.preventDefault();
203  return true;
204  });
205  ";
206  return $script;
207  }
208 
209  protected function renderOnClickPreviewLinkScript()
210  {
211  $url = Yii::app()->createUrl('emailTemplates/default/renderPreview', array('id' => null));
212  $ajaxOptions['cache'] = 'false';
213  $ajaxOptions['url'] = "js:(function(){
214  return '{$url}' + templateId;
215  })()";
216  $ajaxOptions['success'] = "js:function (html){
217  $('#" . BuilderCanvasWizardView::PREVIEW_IFRAME_ID . "').contents().find('html').html(html);
218  $('#" . BuilderCanvasWizardView::PREVIEW_IFRAME_CONTAINER_ID . "').show();
219  $('body').addClass('previewing-builder');
220  }";
221  $ajax = ZurmoHtml::ajax($ajaxOptions);
222 
223  $script = "
224  $('body').off('click', '.preview-template');
225  $('body').on('click', '.preview-template', function (event) {
226  var templateId = $(this).closest('li').data('value');
227  {$ajax}
228  event.preventDefault();
229  return true;
230  });
231  ";
232 
233  return $script;
234  }
235 
236  protected function renderOnClickFilterLinksScript()
237  {
238  // Begin Not Coding Standard
239  $script = "
240  $('body').off('click', '.filter-link');
241  $('body').on('click', '.filter-link', function (event) {
242  $('.filter-link.active').removeClass('active');
243  $(this).addClass('active');
244  $('#" . $this->getListViewId() . "').addClass('attachLoadingTarget');
245  $('#" . $this->getListViewId() . "').addClass('loading');
246  $('#" . $this->getListViewId() . " > .pager').hide();
247  $(this).makeSmallLoadingSpinner(true, '#" . $this->getListViewId() . "');
248  $('ul.template-list').html('');
249  $.fn.yiiListView.update('{$this->getListViewId()}', {
250  url: location.href.replace(/&?.*filterBy=([^&]$|[^&]*)/i, ''),
251  data: {filterBy: $(this).data('filter'), modelClassName: $('#{$this->getModelClassNameId()}').val()}
252  });
253  event.preventDefault();
254  return true;
255  });
256  ";
257  // End Not Coding Standard
258  return $script;
259  }
260 
261  protected function getModelClassNameId()
262  {
263  return $this->getEditableInputId(static::MODEL_CLASS_NAME_ATTRIBUTE, 'value');
264  }
265 
266  protected function getListViewId()
267  {
268  return $this->getEditableInputId() . '_list_view';
269  }
270 
271  protected function resolveModelClassName()
272  {
273  $modelClassName = ArrayUtil::getArrayValue(GetUtil::getData(), 'modelClassName');
274  if (isset($modelClassName))
275  {
276  return $modelClassName;
277  }
278 
279  if (isset($this->model->modelClassName))
280  {
281  return $this->model->modelClassName;
282  }
283  return 'Contact';
284  }
285  }
286 ?>
static getPredefinedBuilderTemplatesSearchAttributeData()
static getPreviouslyCreatedBuilderTemplateSearchAttributeData($modelClassName=null, $includeDrafts=false)
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
getEditableInputName($attributeName=null, $relationAttributeName=null)
Definition: Element.php:303
static makeDataProvider(array $metadata, $listModelClassName, $dataProviderClassName, $sortAttribute, $sortDescending, $pageSize, $stateMetadataAdapterClassName=null)
getEditableInputId($attributeName=null, $relationAttributeName=null)
Definition: Element.php:277
Generated on Sun Oct 25 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.