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: /**
38: * @package application.components
39: */
40: abstract class PublisherTab extends X2Widget {
41:
42: public $id = '';
43:
44: public $viewFile = 'application.components.views.publisher._tab';
45:
46: /**
47: * @var String
48: */
49: public $title;
50:
51: /**
52: * @var Publisher $publisher
53: */
54: public $publisher;
55:
56: /**
57: * @var bool If true, tab content container will be rendered with contents shown
58: */
59: public $startVisible = false;
60:
61: /**
62: * Id of tab content container
63: * @var String
64: */
65: public $tabId;
66:
67: /**
68: * Name of tab JS prototype
69: * @var String
70: */
71: public $JSClass = 'PublisherTab';
72:
73: protected $_innerViewFile;
74: public function getInnerViewFile () {
75: if (!isset ($this->_innerViewFile)) {
76:
77: $this->_innerViewFile = 'application.modules.actions.views.actions._'.
78: ($this->type ? $this->type : 'action').'Form';
79: }
80: return $this->_innerViewFile;
81: }
82:
83: /**
84: * Packages which will be registered when the widget content gets rendered.
85: */
86: protected $_packages;
87:
88: /**
89: * @var string This script gets registered when the widget content gets rendered.
90: */
91: protected $_setupScript;
92:
93: /**
94: * @param bool $onReady whether or not JS class should be instantiated after page is ready
95: */
96: public function instantiateJSClass ($onReady=true) {
97: parent::instantiateJSClass ($onReady);
98: if (isset ($this->publisher)) {
99: Yii::app()->clientScript->registerScript (
100: $this->namespace.get_class ($this).'AddTabJS',
101: ($onReady ? "$(function () {" : "").
102: $this->publisher->getJSObjectName ().".addTab (".
103: $this->getJSObjectName ().");".
104: ($onReady ? "});" : ""), CClientScript::POS_END);
105: }
106: }
107:
108:
109: public function getJSClassParams () {
110: if (!isset ($this->_JSClassParams)) {
111: $this->_JSClassParams = array_merge (parent::getJSClassParams (), array (
112: 'tabId' => $this->tabId,
113: 'translations' => array (
114: 'beforeSubmit' => Yii::t('actions', 'Please enter a description.'),
115: 'startDateError' => Yii::t('actions', 'Please enter a start date.'),
116: 'endDateError' => Yii::t('actions', 'Please enter an end date.'),
117: ),
118: ));
119: }
120: return $this->_JSClassParams;
121: }
122:
123:
124: /**
125: * Magic getter. Returns this widget's packages.
126: */
127: public function getPackages () {
128: if (!isset ($this->_packages)) {
129: $this->_packages = array_merge (parent::getPackages (), array (
130: 'PublisherTabJS' => array(
131: 'baseUrl' => Yii::app()->request->baseUrl,
132: 'js' => array(
133: 'js/publisher/PublisherTab.js',
134: ),
135: 'depends' => array ('auxlib')
136: ),
137: ));
138: }
139: return $this->_packages;
140: }
141:
142: protected $_modelType;
143: public function getModelType () {
144: if (!isset ($this->_modelType)) {
145: $this->_modelType = ucfirst ($this->type ? $this->type : 'Action').'FormModel';
146: }
147: return $this->_modelType;
148: }
149:
150: public function renderTab ($viewParams) {
151: $this->registerPackages ();
152: $this->instantiateJSClass (false);
153: $modelType = $this->getModelType ();
154: $model = new $modelType;
155: $model->associationType = $this->publisher->model->associationType;
156: $model->associationId = $this->publisher->model->associationId;
157: $model->assignedTo = $this->publisher->model->assignedTo;
158: $viewParams['model'] = $model;
159: $viewParams['htmlOptions'] = array (
160: );
161: $this->render ($this->viewFile, array_merge (
162: $viewParams, array ('startVisible' => $this->startVisible)));
163: }
164:
165: public function renderTitle () {
166: echo '<a href="#'.$this->resolveId ($this->tabId).'">'.Yii::t('actions',$this->title).'</a>';
167: }
168:
169: }
170: