Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
StateToggleElement.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 
37  abstract class StateToggleElement extends Element implements DerivedElementInterface
38  {
39  abstract protected function assertAttributeName();
40 
41  abstract protected function assertModelClass();
42 
43  protected function renderEditable()
44  {
45  throw new NotSupportedException();
46  }
47 
48  protected function renderControlEditable()
49  {
50  throw new NotSupportedException();
51  }
52 
53  public static function getDropDownArray()
54  {
55  throw new NotImplementedException();
56  }
57 
58  protected static function resolveSelectedRadioButtonListOption(RedBeanModel $model)
59  {
60  throw new NotImplementedException();
61  }
62 
63  protected static function resolveStatusChangeUrl(RedBeanModel $model)
64  {
65  throw new NotImplementedException();
66  }
67 
68  protected static function resolveSuccessMessage()
69  {
70  throw new NotImplementedException();
71  }
72 
73  protected function renderLabel()
74  {
75  return null;
76  }
77 
78  protected static function resolvePostNotificationSuccessScript()
79  {
80  return null;
81  }
82 
83  public static function getDisplayName()
84  {
85  return Zurmo::t('ZurmoModule', 'Status');
86  }
87 
88  protected function renderControlNonEditable()
89  {
90  $this->assertAttributeName();
91  $this->assertModelClass();
92  static::renderAjaxStatusChange($this->model);
93  return static::renderStatusChangeArea($this->model);
94  }
95 
96  protected static function renderAjaxStatusChange(RedBeanModel $model)
97  {
98  $url = static::resolveStatusChangeUrl($model);
99  $name = static::getRadioButtonListName($model->id);
100  $successScript = static::resolveOnSuccessScript();
101  $script = "
102  $('input[name=${name}]').change(function()
103  {
104  $.ajax(
105  {
106  url: '{$url}',
107  type: 'GET',
108  success: ${successScript},
109  });
110  });
111  ";
112  Yii::app()->clientScript->registerScript('ConversationStatusChange', $script);
113  }
114 
115  protected static function resolveOnSuccessScript()
116  {
117  $message = static::resolveSuccessMessage();
118  $postNotificationSuccessScript = static::resolvePostNotificationSuccessScript();
119  // Begin Not Coding Standard
120  $script = "
121  function(data)
122  {
123  $('#FlashMessageBar').jnotifyAddMessage(
124  {
125  text: '${message}',
126  permanent: false,
127  showIcon: true,
128  type: 'ConversationsChangeStatusMessage'
129  }
130  );
131  ${postNotificationSuccessScript}
132  }";
133  // End Not Coding Standard
134  return $script;
135  }
136 
137  public static function renderStatusChangeArea(RedBeanModel $model)
138  {
139  $content = static::renderStatusAreaLabel();
140  $content .= static::renderStatusButtonsContent($model);
141  $content = ZurmoHtml::tag('div', static::getStatusChangeHtmlOptions($model), $content);
142  return $content;
143  }
144 
145  public static function renderStatusButtonsContent(RedBeanModel $model)
146  {
147  $content = ZurmoHtml::radioButtonList(
148  static::getRadioButtonListName($model->id),
149  static::resolveSelectedRadioButtonListOption($model),
150  static::getDropDownArray(),
151  static::getRadioButtonListHtmlOptions($model)
152  );
153  return ZurmoHtml::tag('div', array('class' => 'switch'), $content);
154  }
155 
156  protected static function getRadioButtonListHtmlOptions(RedBeanModel $model)
157  {
158  return array('separator' => '', 'template' => '<div class="switch-state clearfix">{input}{label}</div>');
159  }
160 
161  protected static function getStatusChangeHtmlOptions(RedBeanModel $model)
162  {
163  $id = static::getStatusChangeDivId($model);
164  $class = static::getStatusChangeDivClassNames($model);
165  $class[] = 'clearfix';
166  $class = implode(' ', $class);
167  $options = compact('id', 'class');
168  return $options;
169  }
170 
171  public static function getStatusChangeDivId(RedBeanModel $model)
172  {
173  $classNames = static::getStatusChangeDivClassNames($model);
174  return ucfirst($classNames[0]) . '-' . $model->id;
175  }
176 
177  private static function getRadioButtonListName($modelId)
178  {
179  return 'statusChange-' . $modelId;
180  }
181 
182  protected static function renderStatusAreaLabel()
183  {
184  return ZurmoHtml::tag('span', array(), Zurmo::t('ZurmoModule', 'Status'));
185  }
186 
187  protected static function getStatusChangeDivClassNames(RedBeanModel $model)
188  {
189  $modelClassName = get_class($model);
190  $modelClassName = lcfirst($modelClassName);
191  $modelClassName .= 'StatusChangeArea';
192  return array($modelClassName);
193  }
194  }
195 ?>
static radioButtonList($name, $select, $data, $htmlOptions=array(), $dataSelectOptions=array(), $dataHtmlOptions=array())
Definition: ZurmoHtml.php:170
Generated on Wed Jul 8 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.