1: <?php
2: /*****************************************************************************************
3: * X2Engine Open Source Edition is a customer relationship management program developed by
4: * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
5: *
6: * This program 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 X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
11: * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12: *
13: * This program 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 X2Engine, Inc. P.O. Box 66752, Scotts Valley,
24: * California 95067, USA. or at email address [email protected].
25: *
26: * The interactive user interfaces in modified source and object code 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 "Powered by
32: * X2Engine" logo. If the display of the logo is not reasonably feasible for
33: * technical reasons, the Appropriate Legal Notices must display the words
34: * "Powered by X2Engine".
35: *****************************************************************************************/
36:
37: Yii::import('zii.widgets.CPortlet');
38:
39:
40: /**
41: * Gives a utility function to derived classes which sets up this left widgets title bar.
42: * @package application.components
43: */
44: class LeftWidget extends CPortlet {
45:
46: /**
47: * The name of the widget. This should match the name used in the layout stored in
48: * the user's profile.
49: * @var string
50: */
51: public $widgetName;
52:
53: /**
54: * The label used in this widgets title bar
55: * @var string
56: */
57: public $widgetLabel;
58:
59: protected $isCollapsed = false;
60:
61: private $_openTag;
62:
63: /**
64: * @var string The prefix used on the id of the container
65: */
66: public static $idPrefix = 'x2widget_';
67:
68:
69: /**
70: * @var string The class of the container
71: */
72: public static $class = 'sidebar-left';
73:
74: /**
75: * Class added to the porlet decoration to indicate that the widget is collapsed
76: * @var string
77: */
78: public static $leftWidgetCollapsedClass = 'left-widget-collapsed';
79:
80: public static function registerScript () {
81: // collapse or expand left widget and save setting to user profile
82: Yii::app()->clientScript->registerScript('leftWidgets','
83: $(".left-widget-min-max").click(function(e){
84: e.preventDefault();
85: var link=this;
86: var action = $(this).attr ("value");
87: $.ajax({
88: url:"'.Yii::app()->request->getScriptUrl ().'/site/minMaxLeftWidget'.'",
89: data:{
90: action: action,
91: widgetName: $(link).attr ("name")
92: },
93: success:function(data){
94: if (data === "failure") return;
95: if(action === "expand"){
96: $(link).removeClass("fa-caret-left");
97: $(link).addClass("fa-caret-down");
98: $("ggads").html("<img src=\'"+yii.themeBaseUrl+"/images/icons/'.
99: 'Collapse_Widget.png\' />");
100: $(link).parents(".portlet-decoration").next().slideDown();
101: $(link).attr ("value", "collapse");
102: $(link).parents (".portlet-decoration").parent ().
103: removeClass ("'.self::$leftWidgetCollapsedClass.'")
104: }else if(action === "collapse"){
105: $(link).removeClass("fa-caret-down");
106: $(link).addClass("fa-caret-left");
107: $("ggads").html("<img src=\'"+yii.themeBaseUrl+"/images/icons/'.
108: 'Expand_Widget.png\' />");
109: $(link).parents(".portlet-decoration").next().slideUp();
110: $(link).attr ("value", "expand");
111: $(link).parents (".portlet-decoration").parent ().
112: addClass ("'.self::$leftWidgetCollapsedClass.'")
113: }
114: }
115: });
116: });
117: ');
118: }
119:
120: /**
121: * Sets the label in the widget title and determines whether this left widget should
122: * be hidden or shown on page load.
123: */
124: protected function initTitleBar () {
125: $profile = Yii::app()->params->profile;
126: if(isset($profile)){
127: $layout = $profile->getLayout ();
128: if (in_array ($this->widgetName, array_keys ($layout['left']))) {
129: $this->isCollapsed = $layout['left'][$this->widgetName]['minimize'];
130: }
131: }
132: $themeURL = Yii::app()->theme->getBaseUrl();
133: $this->title =
134: Yii::t('app', $this->widgetLabel).
135: CHtml::tag( 'i',
136: array(
137: 'title'=>Yii::t('app', $this->widgetLabel),
138: 'name'=>$this->widgetName,
139: 'class'=>'fa fa-lg right left-widget-min-max '.($this->isCollapsed ? 'fa-caret-left' : 'fa-caret-down'),
140: 'value'=>($this->isCollapsed ? 'expand' : 'collapse'),
141: ), ' '
142: );
143: $this->htmlOptions = array(
144: 'class' => (!$this->isCollapsed ? "" : "hidden-filter")
145: );
146:
147: }
148:
149: /**
150: * overrides parent method so that content gets hidden/shown depending on value
151: * of isCollapsed
152: *
153: * This method is Copyright (c) 2008-2014 by Yii Software LLC
154: * http://www.yiiframework.com/license/
155: */
156: public function init()
157: {
158: if (!$this->widgetName) {
159: $this->widgetName = get_called_class();
160: }
161: /* x2modstart */
162: $this->initTitleBar ();
163: /* x2modend */
164:
165: ob_start();
166: ob_implicit_flush(false);
167:
168: if(isset($this->htmlOptions['id']))
169: $this->id=$this->htmlOptions['id'];
170: else
171: $this->htmlOptions['id']=$this->id;
172:
173: /* x2modstart */
174: if ($this->isCollapsed)
175: $this->htmlOptions['class'] = self::$leftWidgetCollapsedClass;
176: /* x2modend */
177:
178: echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
179: $this->renderDecoration();
180: /* x2modstart */
181: echo "<div class=\"{$this->contentCssClass}\" ".
182: ($this->isCollapsed ? "style='display: none;'" : '').">\n";
183: /* x2modend */
184:
185: $this->_openTag=ob_get_contents();
186: ob_clean();
187: }
188:
189: /**
190: * Overrides parent method since private property _openTag gets set in init ().
191: * This is identical to the parent method.
192: *
193: * This method is Copyright (c) 2008-2014 by Yii Software LLC
194: * http://www.yiiframework.com/license/
195: */
196: public function run()
197: {
198: $this->renderContent();
199: $content=ob_get_clean();
200: if($this->hideOnEmpty && trim($content)==='')
201: return;
202: echo $this->_openTag;
203: echo $content;
204: echo "</div>\n";
205: echo CHtml::closeTag($this->tagName);
206: }
207:
208:
209: /**
210: * Instantiates a left Widget with the specified settings
211: * @param array $settings the array of settings to be passed to the widget
212: */
213: public static function instantiateWidget ($settings=array()) {
214: $class = get_called_class();
215: echo CHtml::openTag('div', array(
216: 'id' => self::$idPrefix.$class,
217: 'class' => self::$class ));
218:
219: Yii::app()->controller->widget($class, $settings);
220:
221: echo "</div>";
222: }
223: }
224: ?>
225: