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 contact@x2engine.com.
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: Yii::import('zii.widgets.CListView');
37:
38: /**
39: * Renders a CListView
40: *
41: * @package application.components
42: */
43: class X2ListView extends CListView {
44:
45: protected $ajax = false;
46: private $afterGridViewUpdateJSString = "";
47: private $beforeGridViewUpdateJSString = "";
48:
49: public function __construct ($owner=null) {
50: parent::__construct ($owner);
51: $this->attachBehaviors ($this->behaviors ());
52: }
53:
54: public function behaviors () {
55: return array (
56: 'X2BaseListViewBehavior' => 'application.components.X2GridView.X2BaseListViewBehavior'
57: );
58: }
59:
60: public function init(){
61: if ($this->pager === array('class'=>'CLinkPager')) {
62: $this->pager = array (
63: 'header' => '',
64: 'firstPageCssClass' => '',
65: 'lastPageCssClass' => '',
66: 'prevPageLabel' => '<',
67: 'nextPageLabel' => '>',
68: 'firstPageLabel' => '<<',
69: 'lastPageLabel' => '>>',
70: );
71: }
72:
73: $this->asa ('X2BaseListViewBehavior')->setSummaryText ();
74:
75: $this->ajax = isset($_GET['ajax']) && $_GET['ajax'] === $this->id;
76:
77: if($this->ajax && ob_get_length ()) {
78: ob_clean();
79: }
80:
81: if($this->itemView === null)
82: throw new CException(Yii::t('app', 'The property "itemView" cannot be empty.'));
83: parent::init();
84:
85: if(!isset($this->htmlOptions['class']))
86: $this->htmlOptions['class'] = 'list-view';
87:
88: if($this->baseScriptUrl === null)
89: $this->baseScriptUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets')).'/listview';
90:
91: if($this->cssFile !== false){
92: if($this->cssFile === null)
93: $this->cssFile = $this->baseScriptUrl.'/styles.css';
94: Yii::app()->getClientScript()->registerCssFile($this->cssFile);
95: }
96: }
97:
98: public function run(){
99: $this->registerClientScript();
100:
101: echo CHtml::openTag($this->tagName, $this->htmlOptions)."\n";
102:
103: $this->renderContent();
104: $this->renderKeys();
105: if($this->ajax){
106: // remove any external JS and CSS files
107: Yii::app()->clientScript->scriptMap['*.css'] = false;
108: // remove JS for gridview checkboxes and delete buttons (these events use jQuery.on() and shouldn't be reapplied)
109: Yii::app()->clientScript->registerScript('CButtonColumn#C_gvControls', null);
110: Yii::app()->clientScript->registerScript('CCheckBoxColumn#C_gvCheckbox', null);
111:
112: $output = '';
113: Yii::app()->getClientScript()->renderBodyEnd($output);
114: echo $output;
115:
116: echo CHtml::closeTag($this->tagName);
117: ob_flush();
118:
119:
120: Yii::app()->end();
121: }
122: echo CHtml::closeTag($this->tagName);
123: }
124:
125: public function addToAfterAjaxUpdate ($str) {
126: $this->afterGridViewUpdateJSString .= $str;
127: if ($this->ajax) return;
128: $this->afterAjaxUpdate =
129: 'js: function(id, data) {'.
130: $this->afterGridViewUpdateJSString.
131: '}';
132: }
133:
134: public function addToBeforeAjaxUpdate ($str) {
135: $this->beforeGridViewUpdateJSString .= $str;
136: if ($this->ajax) return;
137: $this->beforeAjaxUpdate =
138: 'js: function(id, data) {'.
139: $this->beforeGridViewUpdateJSString .
140: '}';
141: }
142: }
143:
144: ?>
145: