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: class WorkflowStageDetailsWidget extends SortableWidget {
43:
44: public $model;
45:
46: public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{workflowSelector}{closeButton}{minimizeButton}</div>{widgetContents}';
47:
48: public $viewFile = '_workflowStageDetailsWidget';
49:
50: protected $_module;
51:
52: private static $_JSONPropertiesStructure;
53:
54: private $_currentWorkflow;
55:
56: private $_associationType;
57:
58: public function getAssociationType () {
59: if (!isset ($this->_associationType)) {
60: $this->_associationType = X2Model::getAssociationType (get_class ($this->model));
61: }
62: return $this->_associationType;
63: }
64:
65: public function getModule () {
66: if (!isset ($this->_module)) {
67: $this->_module = Yii::app()->getModule ('workflow');
68: }
69: return $this->_module;
70: }
71:
72: public function getCurrentWorkflow () {
73: if (!isset ($this->_currentWorkflow)) {
74: $this->_currentWorkflow = $this->controller->getCurrentWorkflow(
75: $this->model->id, $this->getAssociationType ());
76: }
77: return $this->_currentWorkflow;
78: }
79:
80: public function renderWorkflowSelector () {
81: $workflowList = Workflow::getList();
82: echo CHtml::dropDownList('workflowId',$this->getCurrentWorkflow (),$workflowList,
83: array(
84: 'ajax' => array(
85: 'type'=>'GET',
86: 'url'=>CHtml::normalizeUrl(
87: array(
88: '/workflow/workflow/getWorkflow',
89: 'modelId'=>$this->model->id,
90: 'type'=>$this->getAssociationType ()
91: )
92: ),
93: 'update'=>'#workflow-diagram',
94: 'data'=>array('workflowId'=>'js:$(this).val()')
95:
96: ),
97: 'id'=>'workflowSelector',
98: 'class'=>'x2-select',
99: ));
100:
101: }
102:
103: public function getSetupScript () {
104: if (!isset ($this->_setupScript)) {
105: $widgetClass = get_called_class ();
106: $this->_setupScript = "
107: $(function () {
108: x2.".$widgetClass.$this->widgetUID." = new x2.WorkflowStageDetailsWidget ({
109: 'widgetClass': '".$widgetClass."',
110: 'setPropertyUrl': '".Yii::app()->controller->createUrl (
111: '/profile/setWidgetSetting')."',
112: 'cssSelectorPrefix': '".$this->widgetType."',
113: 'widgetType': '".$this->widgetType."',
114: 'widgetUID': '".$this->widgetUID."'
115: });
116: });
117: ";
118: }
119: return $this->_setupScript;
120: }
121:
122: public function getViewFileParams () {
123: if (!isset ($this->_viewFileParams)) {
124: $this->_viewFileParams = array_merge (
125: parent::getViewFileParams (),
126: array (
127: 'currentWorkflow'=> $this->getCurrentWorkflow (),
128: 'model' => $this->model,
129: )
130: );
131: }
132: return $this->_viewFileParams;
133: }
134:
135: public static function getJSONPropertiesStructure () {
136: if (!isset (self::$_JSONPropertiesStructure)) {
137: self::$_JSONPropertiesStructure = array_merge (
138: parent::getJSONPropertiesStructure (),
139: array (
140: 'label' => 'Process',
141: 'hidden' => false,
142: )
143: );
144: }
145: return self::$_JSONPropertiesStructure;
146: }
147:
148:
149: public function getPackages () {
150: if (!isset ($this->_packages)) {
151: $this->_packages = array_merge (
152: parent::getPackages (),
153: array (
154: 'WorkflowStageDetailsWorkflowJS' => array(
155: 'baseUrl' => $this->module->assetsUrl,
156: 'js' => array(
157: 'js/WorkflowManagerBase.js',
158: 'js/WorkflowManager.js',
159: ),
160: 'depends' => array ('auxlib')
161: ),
162: 'WorkflowStageDetailsWidgetJS' => array(
163: 'baseUrl' => Yii::app()->request->baseUrl,
164: 'js' => array(
165: 'js/sortableWidgets/WorkflowStageDetailsWidget.js',
166: ),
167: 'depends' => array ('SortableWidgetJS')
168: ),
169: 'WorkflowStageDetailsWidgetCSS' => array(
170: 'baseUrl' => Yii::app()->getTheme ()->getBaseUrl (),
171: 'css' => array(
172: 'css/workflowFunnel.css',
173: )
174: ),
175: )
176: );
177: if (AuxLib::isIE8 ()) {
178: $this->_packages['WorkflowExcanvas'] = array (
179: 'baseUrl' => Yii::app()->request->baseUrl,
180: 'js' => array(
181: 'js/jqplot/excanvas.js',
182: ),
183: );
184: }
185: }
186: return $this->_packages;
187: }
188:
189: public function init() {
190:
191: Yii::app()->clientScript->registerScriptFile(
192: $this->module->assetsUrl.'/js/WorkflowManagerBase.js');
193: Yii::app()->clientScript->registerScriptFile(
194: $this->module->assetsUrl.'/js/WorkflowManager.js');
195:
196: Yii::app()->clientScript->registerScript('workflowDialog_'.$this->id,'
197:
198: x2.workflowManager = new x2.WorkflowManager ({
199: translations: '.CJSON::encode (array (
200: 'Comment Required' => Yii::t('workflow', 'Comment Required'),
201: 'Stage {n}' => Yii::t('workflow', 'Stage {n}'),
202: 'Save' => Yii::t('app', 'Save'),
203: 'Edit' => Yii::t('app', 'Edit'),
204: 'Cancel' => Yii::t('app', 'Cancel'),
205: 'Close' => Yii::t('app', 'Close'),
206: 'Submit' => Yii::t('app', 'Submit'),
207: )).',
208: modelId: '.$this->model->id.',
209: modelName: "'.$this->getAssociationType ().'",
210: startStageUrl: "'.
211: CHtml::normalizeUrl(array('/workflow/workflow/startStage')).
212: '",
213: revertStageUrl: "'.
214: CHtml::normalizeUrl(array('/workflow/workflow/revertStage')).
215: '",
216: getStageDetailsUrl: "'.
217: CHtml::normalizeUrl(array('/workflow/workflow/getStageDetails')).
218: '",
219: completeStageUrl: "'.
220: CHtml::normalizeUrl(array('/workflow/workflow/completeStage')).
221: '"
222: });
223:
224: ',CClientScript::POS_END);
225:
226:
227: parent::init();
228: }
229:
230: protected function getCss () {
231: if (!isset ($this->_css)) {
232: $this->_css = array_merge (
233: parent::getCss (),
234: array (
235: 'WorkflowStageDetailsWidgetCSS' => "
236:
237: #workflowSelector {
238: margin-left: 13px;
239: }
240:
241: #funnel-container {
242: position: relative;
243: width: auto;
244: margin-left: 12px;
245: margin-top: 9px;
246: max-width: 500px;
247: }
248:
249: #funnel-container .interaction-buttons > a {
250: margin-right: 3px;
251: display: inline-block;
252: vertical-align: middle;
253: text-decoration: none;
254: }
255:
256: #funnel-container .interaction-buttons {
257: height: 17px;
258: }
259:
260:
261: #funnel-container img {
262: margin-right: 4px;
263: opacity: 0.8;
264: }
265:
266: #funnel-container img:hover {
267: opacity: 1;
268: }
269:
270: div.workflow-status {
271: overflow: hidden;
272: display: block;
273: line-height: 20px;
274: height: 24px;
275: max-width: 340px;
276: margin-right: 10px;
277: }
278:
279: div.workflow-status b {
280: float: left;
281: }
282:
283: div.workflow-status a {
284: float: right;
285: }
286: ")
287: );
288: }
289: return $this->_css;
290: }
291:
292:
293: }
294: