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 ('application.components.sortableWidget.SortableWidget');
38: Yii::import('application.components.sortableWidget.SortableWidgetResizeBehavior');
39:
40: /**
41: * @package application.components
42: */
43: class IframeWidget extends SortableWidget {
44:
45: public $canBeDeleted = true;
46:
47: public $defaultTitle = 'Website Viewer';
48:
49: public $sortableWidgetJSClass = 'IframeWidget';
50:
51: public $relabelingEnabled = true;
52:
53: public $viewFile = '_iframeWidget';
54:
55: public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{closeButton}{minimizeButton}{settingsMenu}</div>{widgetContents}';
56:
57: private static $_JSONPropertiesStructure;
58:
59: public function getViewFileParams () {
60: if (!isset ($this->_viewFileParams)) {
61: $this->_viewFileParams = array_merge (
62: parent::getViewFileParams (),
63: array (
64: 'url' => self::getJSONProperty (
65: $this->profile, 'url', $this->widgetType, $this->widgetUID),
66: 'height' => self::getJSONProperty (
67: $this->profile, 'height', $this->widgetType, $this->widgetUID),
68: )
69: );
70: }
71: return $this->_viewFileParams;
72: }
73:
74: protected function getSettingsMenuContent () {
75: $htmlStr =
76: '<div class="widget-settings-menu-content" style="display:none;">
77: <ul>'.
78: ($this->relabelingEnabled ?
79: '<li class="relabel-widget-button">'.
80: Yii::t('app', 'Rename Widget').
81: '</li>' : '').
82: ($this->canBeDeleted ?
83: '<li class="delete-widget-button">'.
84: Yii::t('app', 'Delete Widget').
85: '</li>' : '').
86: '<li class="change-url-button">'.
87: Yii::t('profile', 'Change URL').
88: '</li>
89: </ul>
90: </div>';
91: if ($this->relabelingEnabled) {
92: $htmlStr .=
93: '<div id="relabel-widget-dialog-'.$this->widgetUID.'" style="display: none;">
94: <div>'.Yii::t('app', 'Enter a new name:').'</div>
95: <input class="new-widget-name">
96: </div>';
97: }
98: if ($this->canBeDeleted) {
99: $htmlStr .=
100: '<div id="delete-widget-dialog-'.$this->widgetUID.'" style="display: none;">
101: <div>'.
102: Yii::t('app', 'Performing this action will cause this widget\'s settings '.
103: 'to be lost. This action cannot be undone.').
104: '</div>
105: </div>';
106: }
107:
108: $htmlStr .=
109: '<div id="change-url-dialog-'.$this->widgetUID.'" class="change-url-dialog"
110: style="display: none;">'.
111: '<div>'.Yii::t('profile', 'Enter a URL:').'</div>'.
112: '<input class="iframe-url">'.
113: '</div>';
114: return $htmlStr;
115: }
116:
117:
118: /**
119: * overrides parent method
120: */
121: public static function getJSONPropertiesStructure () {
122: if (!isset (self::$_JSONPropertiesStructure)) {
123: self::$_JSONPropertiesStructure = array_merge (
124: parent::getJSONPropertiesStructure (),
125: array (
126: 'url' => '',
127: 'label' => Yii::t('app', 'Website Viewer'),
128: 'height' => '200',
129: 'hidden' => true
130: )
131: );
132: }
133: return self::$_JSONPropertiesStructure;
134: }
135:
136: protected function getJSSortableWidgetParams () {
137: if (!isset ($this->_JSSortableWidgetParams)) {
138: $this->_JSSortableWidgetParams = array_merge (parent::getJSSortableWidgetParams (),
139: array (
140: 'enableResizing' => true,
141: )
142: );
143: }
144: return $this->_JSSortableWidgetParams;
145: }
146:
147: /**
148: * @return array translations to pass to JS objects
149: */
150: protected function getTranslations () {
151: if (!isset ($this->_translations )) {
152: $this->_translations = array_merge (parent::getTranslations (), array (
153: 'dialogTitle'=> Yii::t('profile', 'Change URL'),
154: 'closeButton'=> Yii::t('profile', 'Close'),
155: 'selectButton'=> Yii::t('profile', 'Change'),
156: 'urlError'=> Yii::t('profile', 'URL cannot be blank'),
157: ));
158: }
159: return $this->_translations;
160: }
161:
162: /**
163: * overrides parent method. Adds JS file necessary to run the setup script.
164: */
165: public function getPackages () {
166: if (!isset ($this->_packages)) {
167: $this->_packages = array_merge (
168: parent::getPackages (),
169: array (
170: 'IframeWidgetJS' => array(
171: 'baseUrl' => Yii::app()->request->baseUrl,
172: 'js' => array(
173: 'js/sortableWidgets/IframeWidget.js',
174: ),
175: 'depends' => array ('SortableWidgetJS')
176: ),
177: )
178: );
179: }
180: return $this->_packages;
181: }
182:
183: /**
184: * Magic getter. Returns this widget's css
185: * @return array key is the proposed name of the css string which should be passed as the first
186: * argument to yii's registerCss. The value is the css string.
187: */
188: protected function getCss () {
189: if (!isset ($this->_css)) {
190: $this->_css = array_merge (
191: parent::getCss (),
192: array (
193: 'iframeWidgetCss' => "
194: #".get_called_class()."-widget-content-container {
195: padding-bottom: 1px;
196: }
197:
198: .change-url-dialog p {
199: display: inline;
200: margin-right: 5px;
201: }
202:
203: .default-text-container {
204: text-align: center;
205: position: absolute;
206: top: 0;
207: bottom: 0;
208: left: 0;
209: right: 0;
210: }
211:
212: .default-text-container a {
213: height: 17%;
214: text-decoration: none;
215: font-size: 16px;
216: margin: auto;
217: position: absolute;
218: left: 0;
219: top: 0;
220: right: 0;
221: bottom: 0;
222: }
223: "
224: )
225: );
226: }
227: return $this->_css;
228: }
229:
230: }
231: ?>
232: