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 DocViewerProfileWidget extends SortableWidget {
44:
45: public $canBeDeleted = true;
46:
47: public $defaultTitle = 'Doc Viewer';
48:
49: public $sortableWidgetJSClass = 'DocViewerProfileWidget';
50:
51: public $viewFile = '_docViewerProfileWidget';
52:
53: public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{closeButton}{minimizeButton}{settingsMenu}</div>{widgetContents}';
54:
55: private static $_JSONPropertiesStructure;
56:
57: public function getViewFileParams () {
58: if (!isset ($this->_viewFileParams)) {
59: $this->_viewFileParams = array_merge (
60: parent::getViewFileParams (),
61: array (
62: 'docId' => self::getJSONProperty (
63: $this->profile, 'docId', $this->widgetType, $this->widgetUID),
64: 'height' => self::getJSONProperty (
65: $this->profile, 'height', $this->widgetType, $this->widgetUID),
66: )
67: );
68: }
69: return $this->_viewFileParams;
70: }
71:
72: /**
73: * overrides parent method
74: */
75: public static function getJSONPropertiesStructure () {
76: if (!isset (self::$_JSONPropertiesStructure)) {
77: self::$_JSONPropertiesStructure = array_merge (
78: parent::getJSONPropertiesStructure (),
79: array (
80: 'docId' => '', // id of the doc record to be displayed
81: 'label' => Yii::t('app', 'Doc Viewer'),
82: 'height' => '200',
83: 'hidden' => true
84: )
85: );
86: }
87: return self::$_JSONPropertiesStructure;
88: }
89:
90: /**
91: * @return array translations to pass to JS objects
92: */
93: protected function getTranslations () {
94: if (!isset ($this->_translations )) {
95: $this->_translations = array_merge (parent::getTranslations (), array (
96: 'dialogTitle'=> Yii::t('profile', 'Select a {Doc}', array(
97: '{Doc}' => Modules::displayName(false, 'Docs')
98: )),
99: 'closeButton'=> Yii::t('profile', 'Close'),
100: 'selectButton'=> Yii::t('profile', 'Select'),
101: 'docError'=> Yii::t('profile', 'Please select an existing {Doc}', array(
102: '{Doc}' => Modules::displayName(false, 'Docs')
103: )),
104: ));
105: }
106: return $this->_translations;
107: }
108:
109: protected function getJSSortableWidgetParams () {
110: if (!isset ($this->_JSSortableWidgetParams)) {
111: $docId = self::getJSONProperty (
112: $this->profile, 'docId', $this->widgetType, $this->widgetUID);
113: $this->_JSSortableWidgetParams = array_merge (parent::getJSSortableWidgetParams (),
114: array (
115: 'getItemsUrl' => Yii::app()->createUrl ("/docs/docs/getItems"),
116: 'getDocUrl' => Yii::app()->createUrl("/docs/docs/getItem"),
117: 'enableResizing' => true,
118: 'docId' => $docId,
119: )
120: );
121: }
122: return $this->_JSSortableWidgetParams;
123: }
124:
125: /**
126: * overrides parent method. Adds JS file necessary to run the setup script.
127: */
128: public function getPackages () {
129: if (!isset ($this->_packages)) {
130: $this->_packages = array_merge (
131: parent::getPackages (),
132: array (
133: 'DocViewerProfileWidgetJS' => array(
134: 'baseUrl' => Yii::app()->request->baseUrl,
135: 'js' => array(
136: 'js/sortableWidgets/IframeWidget.js',
137: 'js/sortableWidgets/DocViewerProfileWidget.js',
138: ),
139: 'depends' => array ('SortableWidgetJS')
140: ),
141: )
142: );
143: }
144: return $this->_packages;
145: }
146:
147: /**
148: * Magic getter. Returns this widget's css
149: * @return array key is the proposed name of the css string which should be passed as the first
150: * argument to yii's registerCss. The value is the css string.
151: */
152: protected function getCss () {
153: if (!isset ($this->_css)) {
154: $this->_css = array_merge (
155: parent::getCss (),
156: array (
157: 'docViewerProfileWidgetCss' => "
158: #".get_called_class()."-widget-content-container {
159: padding-bottom: 1px;
160: }
161:
162: #select-a-document-dialog p {
163: display: inline;
164: margin-right: 5px;
165: }
166:
167: .default-text-container {
168: text-align: center;
169: position: absolute;
170: top: 0;
171: bottom: 0;
172: left: 0;
173: right: 0;
174: }
175:
176: .default-text-container a {
177: height: 17%;
178: text-decoration: none;
179: font-size: 16px;
180: margin: auto;
181: position: absolute;
182: left: 0;
183: top: 0;
184: right: 0;
185: bottom: 0;
186: color: #222222 !important;
187: }
188: "
189: )
190: );
191: }
192: return $this->_css;
193: }
194:
195: protected function getSettingsMenuContentEntries () {
196: return
197: '<li class="select-a-document-button">'.
198: Yii::t('profile', 'Select a Document').'
199: </li>'.parent::getSettingsMenuContentEntries ();
200: }
201:
202: protected function getSettingsMenuContentDialogs () {
203: return
204: '<div id="select-a-document-dialog-'.$this->widgetUID.'"
205: style="display: none;">'.
206: '<div>'.Yii::t('profile', 'Enter the name of a {Doc}:', array(
207: '{Doc}' => Modules::displayName(false, 'Docs')
208: )).'</div>'.
209: '<input class="selected-doc">'.
210: '</div>'.parent::getSettingsMenuContentDialogs ();
211: }
212:
213: }
214: ?>
215: