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: abstract class TransactionalViewWidget extends GridViewWidget {
42:
43: 44: 45:
46: public $model;
47:
48: 49: 50:
51: public $widgetManager;
52: public $viewFile = '_transactionalViewWidget';
53: public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{createButton}{closeButton}{minimizeButton}{settingsMenu}</div>{widgetContents}';
54: public $sortableWidgetJSClass = 'x2.TransactionalViewWidget';
55:
56: protected $compactResultsPerPage = true;
57: protected $createButtonLabel = '';
58: protected $labelIconClass = '';
59: protected $historyType;
60: protected $_dataProvider;
61: protected $_gridViewConfig;
62: protected $_searchModel;
63: protected $containerClass = 'sortable-widget-container x2-layout-island transactional-view-widget';
64:
65:
66: private static $_JSONPropertiesStructure;
67:
68: protected function getSearchModel() {
69: if (!isset($this->_searchModel)) {
70: $this->_searchModel = new Actions('search', $this->widgetKey);
71: }
72: return $this->_searchModel;
73: }
74:
75: public static function getJSONPropertiesStructure() {
76: if (!isset(self::$_JSONPropertiesStructure)) {
77: self::$_JSONPropertiesStructure = array_merge(
78: parent::getJSONPropertiesStructure(), array(
79: 'showHeader' => false,
80: 'resultsPerPage' => 5,
81: 'hideFullHeader' => true,
82: )
83: );
84: }
85: return self::$_JSONPropertiesStructure;
86: }
87:
88: public function getPackages() {
89: if (!isset($this->_packages)) {
90: $this->_packages = array_merge(parent::getPackages(), array(
91: 'TransactionalViewWidgetJS' => array(
92: 'baseUrl' => Yii::app()->request->baseUrl,
93: 'js' => array(
94: 'js/sortableWidgets/TransactionalViewWidget.js',
95: ),
96: ),
97: ));
98: }
99: return $this->_packages;
100: }
101:
102: public function getSharedCssFileNames() {
103: if (!isset($this->_sharedCssFileNames)) {
104: $this->_sharedCssFileNames = array_merge(parent::getSharedCssFileNames(), array(
105: 'components/sortableWidget/recordViewWidgets/TransactionalViewWidget.css',
106: ));
107: }
108: return $this->_sharedCssFileNames;
109: }
110:
111: public function getIcon() {
112: return X2Html::fa($this->labelIconClass, array(
113: 'class' => 'widget-label-icon',
114: ));
115: }
116:
117: public function renderWidgetLabel() {
118: $label = $this->getWidgetLabel();
119: $count = $this->dataProvider->totalItemCount;
120: echo
121: "<div class='widget-title'>" .
122: $this->getIcon() .
123: htmlspecialchars($label) .
124: " (<span class='transaction-count'>" . $count . "</span>)
125: </div>";
126: }
127:
128: public function getCreateButtonTitle() {
129: return '';
130: }
131:
132: public function getCreateButtonText() {
133: return '';
134: }
135:
136: public function renderCreateButton() {
137: echo
138: "<button class='x2-button create-button'
139: title='" . CHtml::encode($this->createButtonTitle) . "'>
140: <span class='fa fa-plus'></span>" .
141: CHtml::encode($this->createButtonText) .
142: "</button>";
143: }
144:
145: 146: 147:
148: public function getDataProvider() {
149: if (!isset($this->_dataProvider)) {
150: $resultsPerPage = $this->getWidgetProperty(
151: 'resultsPerPage');
152: $historyCmd = History::getCriteria(
153: $this->model->id,
154: X2Model::getAssociationType(get_class($this->model)),
155: Yii::app()->params->profile->historyShowRels,
156: $this->historyType
157: );
158:
159: $this->_dataProvider = new CSqlDataProvider($historyCmd['cmd'], array(
160: 'totalItemCount' => $historyCmd['count'],
161: 'params' => $historyCmd['params'],
162: 'pagination' => array(
163: 'pageSize' => $resultsPerPage,
164: ),
165: ));
166:
167:
168:
169:
170:
171:
172: }
173: return $this->_dataProvider;
174: }
175:
176: protected function () {
177: return Yii::t(
178: 'actions',
179: '{action} Description',
180: array('{action}' => Modules::displayName(false, 'Actions')));
181: }
182:
183: public function getAjaxUpdateRouteAndParams() {
184: list ($updateRoute, $updateParams) = parent::getAjaxUpdateRouteAndParams();
185: $updateParams = array_merge($updateParams, array(
186: 'modelId' => $this->model->id,
187: 'modelType' => get_class($this->model),
188: ));
189: return array($updateRoute, $updateParams);
190: }
191:
192:
193: 194: 195: 196: 197: 198: 199:
200: public function getColumnWidths (array $collapse=array ()) {
201: if (!Yii::app()->params->profile->historyShowRels) {
202: $columnWidths = array (
203: '52%',
204: '22%',
205: '12%',
206: '106',
207: '60',
208: );
209: } else {
210: $columnWidths = array (
211: '42%',
212: '22%',
213: '22%',
214: '106',
215: '60',
216: );
217: }
218:
219: $addWidths = function ($widthA, $widthB) {
220: if (preg_match ('/%/', $widthA) && preg_match ('/%/', $widthB)) {
221: return $widthA + $widthB . '%';
222: } else if (!preg_match ('/%/', $widthA) && !preg_match ('/%/', $widthB)) {
223: return $widthA + $widthB;
224: } else {
225: throw new CException ('Type mismatch: widths cannot be added');
226: }
227: };
228:
229:
230: foreach ($collapse as $cols) {
231: $rest = $cols;
232: unset ($rest[0]);
233: $collapsedWidth = $columnWidths[$cols[0]];
234: foreach ($rest as $otherCol) {
235: $collapsedWidth = $addWidths ($collapsedWidth, $columnWidths[$otherCol]);
236: unset ($columnWidths[$otherCol]);
237: }
238: $columnWidths[$cols[0]] = $collapsedWidth;
239: }
240:
241: return $columnWidths;
242: }
243:
244: 245: 246:
247: public function buildDefaultGvSettings ($attributes, array $combine = array ()) {
248: return array_combine (
249: $attributes,
250: $this->getColumnWidths ($combine)
251: );
252: }
253:
254: 255: 256:
257: public function getGridViewConfig() {
258: if (!isset($this->_gridViewConfig)) {
259: $this->_gridViewConfig = array_merge(parent::getGridViewConfig(), array(
260: 'possibleResultsPerPage' => array(5, 10, 20, 30, 40, 50, 75, 100),
261: 'sortableWidget' => $this,
262: 'moduleName' => 'Actions',
263: 'sortableWidget' => $this,
264: 'id' => get_called_class() . '_' . $this->widgetUID,
265: 'fieldFormatter' => 'TransactionalViewFieldFormatter',
266: 'enableColDragging' => false,
267: 'evenPercentageWidthColumns' => true,
268: 'enableGridResizing' => false,
269: 'enableScrollOnPageChange' => false,
270: 'buttons' => array('clearFilters', 'columnSelector', 'autoResize'),
271: 'template' => '{summary}{items}{pager}',
272: 'fixedHeader' => false,
273: 'dataProvider' => $this->dataProvider,
274:
275: 'pager' => array('class' => 'CLinkPager', 'maxButtonCount' => 10),
276: 'modelName' => 'Actions',
277: 'viewName' => 'profile',
278: 'gvSettingsName' => get_called_class() . $this->widgetUID,
279: 'enableControls' => true,
280:
281: 'fullscreen' => false,
282: 'enableSelectAllOnAllPages' => false,
283: 'hideSummary' => true,
284: 'enableGvSettings' => false,
285: 'defaultGvSettings' => $this->buildDefaultGvSettings (
286: array (
287: 'actionDescription',
288: 'assignedTo',
289: 'createDate',
290: ), array (array (1, 2), array (3, 4))
291: ),
292: 'specialColumns' => array(
293: 'actionDescription' => array(
294: 'header' => $this->getActionDescriptionHeader(),
295: 'name' => 'actionDescription',
296: 'value' => 'Actions::model()->findByPk($data["id"])->frameLink ()',
297: 'type' => 'raw',
298: 'filter' => false,
299: 'htmlOptions' => array(
300: 'title' => 'php:CHtml::encode(Formatter::trimText(Actions::model()->findByPk($data["id"])->actionDescription))',
301: )
302: ),
303: ),
304: ));
305: $this->_gridViewConfig['specialColumns']['associationName'] = array(
306: 'header' => Yii::t('app', 'Association'),
307: 'name' => 'associationName',
308: 'value' => '$data->getAssociationLink ()',
309: 'type' => 'raw',
310: 'filter' => false,
311: );
312: if (Yii::app()->params->profile->historyShowRels) {
313: $this->_gridViewConfig['defaultGvSettings'] = $this->buildDefaultGvSettings (
314: array (
315: 'actionDescription',
316: 'assignedTo',
317: 'associationName',
318: 'createDate',
319: ), array (array (3, 4))
320: );
321: }
322: }
323: return $this->_gridViewConfig;
324: }
325:
326: public function run() {
327: $tabs = Yii::app()->settings->actionPublisherTabs;
328: $actionTypeToTab = Publisher::$actionTypeToTab;
329:
330: if (isset($this->widgetManager) && $this->widgetManager->layoutManager->staticLayout) {
331:
332:
333: return;
334: }
335:
336:
337: if ($tabs && isset($actionTypeToTab[$this->historyType]) &&
338: isset($tabs[$actionTypeToTab[$this->historyType]]) &&
339: !$tabs[$actionTypeToTab[$this->historyType]]) {
340:
341: return;
342: }
343:
344: if (!Yii::app()->params->profile->miscLayoutSettings['enableTransactionalView']) {
345: $this->registerSharedCss();
346: $this->render(
347: 'application.components.sortableWidget.views.' . $this->sharedViewFile,
348: array(
349: 'widgetClass' => get_called_class(),
350: 'profile' => $this->profile,
351: 'hidden' => true,
352: 'widgetUID' => $this->widgetUID,
353: ));
354: return;
355: }
356: parent::run();
357: }
358:
359: protected function getJSSortableWidgetParams() {
360: if (!isset($this->_JSSortableWidgetParams)) {
361: $this->_JSSortableWidgetParams = array_merge(
362: parent::getJSSortableWidgetParams(),
363: array(
364: 'actionType' => $this->historyType,
365: 'modelName' => get_class($this->model),
366: 'modelId' => $this->model->id,
367: )
368: );
369: }
370: return $this->_JSSortableWidgetParams;
371: }
372:
373: protected function getTranslations() {
374: if (!isset($this->_translations)) {
375: $this->_translations = array_merge(parent::getTranslations(), array(
376: 'dialogTitle' => ucwords($this->createButtonTitle),
377: ));
378: }
379: return $this->_translations;
380: }
381:
382: protected function () {
383: return
384: parent::getSettingsMenuContentEntries ().
385: '<li class="relationships-toggle x2-hint" title="'.
386: CHtml::encode (
387: Yii::t(
388: 'app',
389: 'Click to toggle showing actions associated with related records.')).
390: '">'.
391: X2Html::checkbox ('historyShowRels', Yii::app()->params->profile->historyShowRels).
392: '<span for="historyShowRels">'.
393: CHtml::encode (Yii::t('profile', 'Relationships')).'</span>'.
394: '</li>';
395: }
396:
397: }
398:
399: ?>
400: