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: class RecordViewLayoutManager extends X2Widget {
38:
39: public $miscLayoutSettingsKey = 'recordViewColumnWidth';
40:
41: public $namespace = 'recordView';
42:
43: public $mainColumnSelector = '#main-column';
44:
45: 46: 47:
48: public $staticLayout = true;
49:
50: public $JSClass = 'RecordViewLayoutEditor';
51:
52: private static $editLayoutButtonId = 'edit-record-view-layout';
53:
54: public $columnWidthPercentage = 65;
55:
56: private $responsiveCssId = 'main-column-responsive-css';
57:
58: public static function () {
59: return array(
60: 'name'=>'editLayout',
61: 'linkOptions' => array (
62: 'id' => self::$editLayoutButtonId,
63: ),
64: 'label'=>Yii::t('app', 'Edit Layout'),
65: 'url'=>array('#')
66: );
67: }
68:
69: public static function ($modelId) {
70: if (Yii::app()->controller->action->getId () === 'view') {
71: return array(
72: 'name'=>'view',
73: 'label' =>
74: Yii::t('app', 'View').X2Html::minimizeButton (array (
75: 'class' => 'record-view-type-menu-toggle',
76: ), '#record-view-type-menu', true,
77: Yii::app()->params->profile->miscLayoutSettings['viewModeActionSubmenuOpen']),
78: 'encodeLabel' => false,
79: 'url' => array('view', 'id' => $modelId),
80: 'linkOptions' => array (
81:
82: 'onClick' => '$(this).find ("i:visible").click ();',
83: ),
84: 'itemOptions' => array (
85: 'id' => 'view-record-action-menu-item',
86: ),
87: 'submenuOptions' => array (
88: 'id' => 'record-view-type-menu',
89: 'style' =>
90: Yii::app()->params->profile->miscLayoutSettings
91: ['viewModeActionSubmenuOpen'] ? '' : 'display: none;',
92: ),
93: 'items' => array (
94: array (
95: 'encodeLabel' => false,
96: 'name'=>'journalView',
97: 'label' => CHtml::checkBox (
98: 'journalView',
99: Yii::app()->params->profile->miscLayoutSettings
100: ['enableJournalView'],
101: array (
102: 'class' => 'journal-view-checkbox',
103: )).CHtml::label (Yii::t('app', 'Journal View'), 'journalView'),
104: ),
105: array (
106: 'encodeLabel' => false,
107: 'name'=>'transactionalView',
108: 'label' => CHtml::checkBox (
109: 'transactionalView',
110: Yii::app()->params->profile->miscLayoutSettings[
111: 'enableTransactionalView'],
112: array (
113: 'class' => 'transactional-view-checkbox',
114: )).CHtml::label (
115: Yii::t('app', 'List View'), 'transactionalView'),
116: ),
117: ),
118: );
119: } else {
120: return array(
121: 'name'=>'view',
122: 'label' => Yii::t('app', 'View'),
123: 'encodeLabel' => true,
124: 'url' => array('view', 'id' => $modelId),
125: );
126: }
127: }
128:
129: public function getPackages () {
130: if (!isset ($this->_packages)) {
131: $baseUrl = Yii::app()->getBaseUrl ();
132: $this->_packages = array_merge (parent::getPackages (), array (
133: 'layoutEditorJS' => array(
134: 'baseUrl' => $baseUrl.'/js/',
135: 'js' => array(
136: 'LayoutEditor.js',
137: 'RecordViewLayoutEditor.js',
138: ),
139: 'depends' => array ('auxlib'),
140: ),
141: 'layoutEditorCss' => array(
142: 'baseUrl' => Yii::app()->theme->getBaseUrl (),
143: 'css' => array(
144: '/css/components/views/layoutEditor.css',
145: )
146: ),
147: ));
148: }
149: return $this->_packages;
150: }
151:
152: public function getJSClassParams () {
153: if (!isset ($this->_JSClassParams)) {
154: $this->_JSClassParams = array_merge (parent::getJSClassParams (), array (
155: 'defaultWidth' => '65',
156: 'columnWidth' => $this->columnWidthPercentage,
157: 'editLayoutButton' => '#'.self::$editLayoutButtonId,
158: 'container' => '#'.$this->namespace.'-layout-editor',
159: 'draggable' => '#'.$this->namespace.'-section-1',
160: 'mainColumnSelector' => $this->mainColumnSelector,
161: 'responsiveCssSelector' => '#'.$this->responsiveCssId,
162: 'minWidths' => array (50, 35),
163: 'column1' => array (
164: '#RecordViewWidgetManagerwidgets-container-2',
165: '#main-column',
166: '#'.$this->namespace.'-section-1',
167: ),
168: 'column2' => array (
169: '#RecordViewWidgetManagerwidgets-container',
170: ),
171: 'miscSettingsUrl' =>
172: Yii::app()->controller->createUrl('/profile/saveMiscLayoutSetting'),
173: 'settingName' => $this->miscLayoutSettingsKey,
174: 'dimensions' => array (
175: 'singleColumnThresholdNoWidgets' => $this->singleColumnThresholdNoWidgets,
176: 'singleColumnThreshold' => $this->singleColumnThreshold,
177: 'extraContentWidth' => $this->extraContentWidth,
178: 'rightWidgetWidth' => $this->rightWidgetWidth,
179: 'formLayoutWidthThreshold' => $this->formLayoutWidthThreshold ,
180: ),
181: ));
182: }
183: return $this->_JSClassParams;
184: }
185:
186: public function init() {
187: $miscLayoutSettings = Yii::app()->params->profile->miscLayoutSettings;
188: if (!$this->staticLayout &&
189: isset($miscLayoutSettings[$this->miscLayoutSettingsKey])) {
190:
191: $this->columnWidthPercentage = $miscLayoutSettings[$this->miscLayoutSettingsKey];
192: }
193: if (!$this->staticLayout) {
194: $this->registerPackages ();
195: $this->instantiateJSClass ();
196: }
197:
198: parent::init ();
199: }
200:
201: public function columnWidthStyleAttr ($columnNumber) {
202: $columnWidth = $this->getColumnWidth (1);
203: return "style='width: {$columnWidth};'";
204: }
205:
206: public function getColumnWidth ($columnNumber) {
207: $columnWidths = $this->getColumnWidths ($columnNumber);
208: return $columnWidths[$columnNumber - 1];
209: }
210:
211: public function responsiveCss ($parentSelector) {
212: return "
213: $parentSelector .formSectionRow td {
214: // display: block;
215: // width: 100% !important;
216: }
217: $parentSelector .formSectionRow td > div{
218: // width: 100% !important;
219: }
220: $parentSelector .formItem.leftLabel > .formInputBox {
221: // width: 200px !important;
222: }";
223: }
224:
225: private $singleColumnThresholdNoWidgets = 1130;
226: private $singleColumnThreshold = 1407;
227: private = 160;
228: private $rightWidgetWidth = 280;
229: private $formLayoutWidthThreshold = 630;
230:
231: public function registerResponsiveCss () {
232:
233: $columnWidthPercentage = $this->columnWidthPercentage / 100;
234:
235:
236: Yii::app()->clientScript->registerCss('RecordViewLayoutManager::registerResponsiveCss',
237: array (
238: 'text' => "
239: @media (min-width:{$this->singleColumnThreshold}px) and (max-width: {$this->getFormLayoutResponsiveThreshold (true)}px) {
240: {$this->responsiveCss ('body.show-widgets')}
241: }
242: @media (min-width:{$this->singleColumnThresholdNoWidgets}px) and (max-width: {$this->getFormLayoutResponsiveThreshold (false)}px) {
243: {$this->responsiveCss ('body.no-widgets')}
244: }",
245: 'htmlOptions' => array (
246: 'id' => $this->responsiveCssId,
247: ),
248: ));
249:
250: Yii::app()->clientScript->registerCss('RecordViewLayoutManager::registerResponsiveCss2',
251: $this->responsiveCss ($this->mainColumnSelector . '.force-single-column'));
252: }
253:
254: public function run () {
255: $layoutEditor = $this->render ('layoutEditor', array (
256: 'namespace' => $this->namespace,
257: ), true);
258: $this->registerResponsiveCss ();
259: Yii::app()->clientScript->registerScript('RecordViewLayoutManager::run',"
260: $('#main-column').before (".CJSON::encode ($layoutEditor).");
261: ", CClientScript::POS_END);
262: }
263:
264: private $_columnWidths;
265: public function getColumnWidths () {
266: if ($this->staticLayout) return array ('100%', '100%');
267: if (!isset ($this->_columnWidths)) {
268: if(!$this->columnWidthPercentage) {
269: $this->_columnWidths = array('', '');
270: } else {
271: $column1 = $this->columnWidthPercentage;
272: $column2 = 100 - $column1;
273:
274: $column1 = $column1.'%';
275: $column2 = $column2.'%';
276:
277: $this->_columnWidths = array(
278: $column1,
279: $column2
280: );
281: }
282: }
283: return $this->_columnWidths;
284: }
285:
286: private function getFormLayoutResponsiveThreshold ($rightWidgets=true) {
287: $columnWidthRatio = $this->columnWidthPercentage / 100;
288: $extraContentWidth = $this->extraContentWidth;
289: if ($rightWidgets) {
290: $extraContentWidth += $this->rightWidgetWidth;
291: }
292: return $extraContentWidth + $this->formLayoutWidthThreshold +
293: ($this->formLayoutWidthThreshold * ( 1 - $columnWidthRatio)) / $columnWidthRatio;
294: }
295:
296: }
297:
298: ?>
299: