1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36:
37:
38: 39: 40: 41: 42:
43: class ProfileDashboardManager extends CWidget {
44:
45: 46: 47:
48: public $model;
49:
50: 51: 52:
53: public $viewFile = 'profileDashboard';
54:
55: 56: 57:
58: public $columnWidth = 52;
59:
60: 61: 62: 63:
64: public $columnMargin = 0.0;
65:
66: public function init() {
67: Yii::app()->clientScript->registerPackages($this->getPackages(), true);
68:
69: $miscLayoutSettings = Yii::app()->params->profile->miscLayoutSettings;
70: if (isset($miscLayoutSettings['columnWidth'])) {
71: $this->columnWidth = $miscLayoutSettings['columnWidth'];
72: }
73:
74: $this->instantiateJS();
75:
76: parent::init ();
77: }
78:
79: public function run() {
80: $this->render('layoutEditor', array ('namespace' => 'profile'));
81: parent::run ();
82: }
83:
84: public function renderContainer ($container) {
85: $this->render('profileDashboard', array('container' => $container));
86: }
87:
88: public function getPackages () {
89: $baseUrl = Yii::app()->getBaseUrl ();
90: $packages = array(
91: 'layoutEditorCss' => array(
92: 'baseUrl' => Yii::app()->theme->getBaseUrl (),
93: 'css' => array(
94: '/css/components/views/layoutEditor.css',
95: )
96: ),
97: 'X2WidgetJS' => array (
98: 'baseUrl' => $baseUrl.'/js',
99: 'js' => array(
100: 'X2Widget.js',
101: ),
102: 'depends' => array('auxlib')
103: ),
104: 'sortableWidgetJS' => array(
105: 'baseUrl' => $baseUrl.'/js/sortableWidgets/',
106: 'js' => array(
107: 'SortableWidget.js',
108: 'SortableWidgetManager.js',
109: 'TwoColumnSortableWidgetManager.js',
110: 'ProfileWidgetManager.js',
111: ),
112: 'depends' => array('auxlib', 'X2WidgetJS')
113: ),
114: 'layoutEditorJS' => array(
115: 'baseUrl' => $baseUrl.'/js/',
116: 'js' => array(
117: 'LayoutEditor.js',
118: 'ProfileLayoutEditor.js',
119: )
120: )
121: );
122:
123: return $packages;
124: }
125:
126: 127: 128: 129:
130: public function displayWidgets ($containerNumber){
131: $layout = $this->model->profileWidgetLayout;
132:
133: foreach ($layout as $widgetClass => $settings) {
134: if ($settings['containerNumber'] == $containerNumber) {
135: SortableWidget::instantiateWidget ($widgetClass, $this->model);
136: }
137:
138: }
139: }
140:
141: 142: 143:
144: public function instantiateJS () {
145: $miscSettings = Yii::app()->params->profile->miscLayoutSettings;
146: $layoutEditorParams = array (
147: 'miscSettingsUrl' => Yii::app()->controller->createUrl('saveMiscLayoutSetting'),
148: 'margin' => $this->columnMargin
149: );
150:
151: $columnWidth = $this->columnWidth;
152: if ($columnWidth) {
153: $layoutEditorParams['columnWidth'] = $columnWidth;
154: }
155:
156: $layoutEditorParams = CJSON::encode($layoutEditorParams);
157:
158: $widgetManagerParams = CJSON::encode (array(
159: 'setSortOrderUrl' => Yii::app()->controller->createUrl ('/profile/setWidgetOrder'),
160: 'showWidgetContentsUrl' =>
161: Yii::app()->controller->createUrl ('/profile/view', array ('id' => 1)),
162: 'connectedContainerSelector' => '.connected-sortable-profile-container',
163: 'translations' => $this->getTranslations(),
164: 'createProfileWidgetUrl' =>
165: Yii::app()->controller->createUrl ('/profile/createProfileWidget'),
166:
167: ));
168:
169: $script = "
170: x2.profileWidgetManager = new ProfileWidgetManager ($widgetManagerParams);
171: x2.profileLayoutManager = new x2.ProfileLayoutEditor ($layoutEditorParams);
172:
173: new PopupDropdownMenu ({
174: containerElemSelector: '#x2-hidden-profile-widgets-menu-container',
175: openButtonSelector: '#show-profile-widget-button',
176: defaultOrientation: 'left'
177: });
178:
179: ";
180:
181: Yii::app()->clientScript->registerScript(
182: 'profilePageInitScript', $script, CClientScript::POS_END);
183:
184: }
185:
186:
187:
188: 189: 190: 191:
192: public function getColumnWidths () {
193:
194: if(!$this->columnWidth) {
195: return array('', '');
196: }
197:
198: $column1 = $this->columnWidth;
199: $column2 = 100 - $column1;
200:
201: $column1 = ($column1 - $this->columnMargin).'%';
202: $column2 = ($column2 - $this->columnMargin).'%';
203:
204: return array(
205: $column1,
206: $column2
207: );
208: }
209:
210:
211: public function getTranslations () {
212: return array(
213: 'createProfileWidgetDialogTitle' => Yii::t('profile', 'Create Profile Widget'),
214: 'Create' => Yii::t('app', 'Create'),
215: 'Cancel' => Yii::t('app', 'Cancel'),
216: );
217: }
218:
219: }
220:
221: ?>
222: