public function addAction($attributes = array())
 {
     if (!isset($this->attributes['actions'])) {
         $this->attributes['actions'] = array();
     }
     /** Check Credential ***/
     if (isset($attributes['url']) && !ComponentCredential::urlHasCredential($attributes['url'])) {
         return;
     }
     $count_actions = count($this->attributes['actions']);
     $attributes['urlIndex'] = 'action' . ($count_actions + 1);
     $attributes['hideIndex'] = 'hide' . ($count_actions + 1);
     if (isset($attributes['script'])) {
         $attributes['script'] = $attributes['script'];
     }
     if (isset($attributes['popup'])) {
         $attributes['popup'] = $attributes['popup'];
     }
     if (isset($attributes['popupSettings'])) {
         $attributes['popupSettings'] = $attributes['popupSettings'];
     } else {
         $attributes['popupSettings'] = '';
     }
     if (isset($attributes['loadas'])) {
         $attributes['load'] = $attributes['loadas'];
         unset($attributes['loadas']);
     }
     array_push($this->actions, $attributes);
     array_push($this->attributes['actions'], $this->afExtjs->asAnonymousClass($attributes));
 }
Пример #2
0
    public static function getButtonParams(&$action, $type, $iteration = '', $select = "false", $grid = null)
    {
        if ($type == "moreactions") {
            if (!isset($action['attributes']['confirmMsg'])) {
                $action['attributes']['confirmMsg'] = "";
            }
            if (!isset($action['attributes']['forceSelection'])) {
                $action['attributes']['forceSelection'] = "true";
            }
            if (!isset($action['attributes']['confirm'])) {
                $action['attributes']['confirm'] = "true";
            }
            if (!isset($action['attributes']['post'])) {
                $action['attributes']['post'] = "true";
            }
        } else {
            if (!isset($action['attributes']['confirmMsg'])) {
                $action['attributes']['confirmMsg'] = "";
            }
            if (!isset($action['attributes']['forceSelection'])) {
                $action['attributes']['forceSelection'] = "false";
            }
            if (!isset($action['attributes']['confirm'])) {
                $action['attributes']['confirm'] = "false";
            }
            if (!isset($action['attributes']['post'])) {
                $action['attributes']['post'] = "false";
            }
        }
        if (!isset($action['attributes']['icon'])) {
            $action['attributes']['icon'] = "";
        }
        if (!isset($action['attributes']['iconCls'])) {
            $action['attributes']['iconCls'] = "";
        }
        if (!isset($action['attributes']['url'])) {
            $action['attributes']['url'] = "#";
        }
        if (!isset($action["attributes"]["label"])) {
            $action["attributes"]["label"] = isset($action["attributes"]["text"]) ? $action["attributes"]["text"] : ucfirst($action["attributes"]["name"]);
        }
        $action["attributes"]["name"] = $iteration . "_" . $action["attributes"]["name"];
        //Evaluate real script
        if (isset($action['attributes']['script'])) {
            $action['attributes']['script'] = self::getRealScript($action['attributes']['script']);
        }
        $confirmMsg = $action["attributes"]["confirmMsg"] == "" ? "Are you sure to perform this operation?" : $action["attributes"]["confirmMsg"];
        $noItemsSelectedFunction = '';
        $noDataInGridFunction = '';
        $requestParams = '"';
        $params = '';
        $functionForUpdater = '';
        $successFunction = '';
        if ($grid) {
            if ($action["attributes"]["updater"] === "true") {
                $action["attributes"]["post"] = "true";
                $updater = new afExtjsUpdater(array('url' => $action["attributes"]["url"], 'width' => 500));
                $functionForUpdater = $updater->privateName . '.start();';
            }
            if ($action["attributes"]["forceSelection"] != "false") {
                $noDataInGridFunction = '
					if(!' . $grid->privateName . '.getStore().getCount()){
						Ext.Msg.alert("No Data In Grid","There is no data on grid.");
						return;
					}
				';
                $noItemsSelectedFunction = '								
					if(!' . $grid->privateName . '.getSelectionModel().getCount()){
						Ext.Msg.alert("No items selected","Please select at least one item");
						return;
					}
				';
                if ($select == "true") {
                    $requestParams = '/selections/"+' . $grid->privateName . '.getSelectionModel().getSelectionsJSON()';
                    $params = 'params:{"selections":' . $grid->privateName . '.getSelectionModel().getSelectionsJSON()}, ';
                }
            }
        }
        if ($action["attributes"]["updater"] != "true") {
            if ($action["attributes"]["post"] != "false") {
                $successFunction = '
					Ext.Ajax.request({ 
						url: "' . $action["attributes"]["url"] . '",
						method:"post", 
						' . $params . '
						success:function(response, options){
							response=Ext.decode(response.responseText);
							if(response.message){								
								var win = Ext.Msg.show({
								   title:"Success",
								   msg: response.message,
								   buttons: Ext.Msg.OK,
								   fn: function(){
									   	if(response.redirect){
											win.getDialog().suspendEvents();										
											afApp.load(response.redirect,response.load);
										}
								   },
								   icon: Ext.MessageBox.INFO
								});															
							}
							else
							{
								if(response.redirect){
									afApp.load(response.redirect,response.load);
								}
							}
						},
						failure: function(response,options) {
							if(response.message){
								Ext.Msg.alert("Failure",response.message);
							}
						}
					});
				';
            } else {
                $action["attributes"]["loadas"] = isset($action["attributes"]["loadas"]) ? $action["attributes"]["loadas"] : 'center';
                $successFunction = 'afApp.load("' . $action["attributes"]["url"] . $requestParams . ',"' . $action["attributes"]["loadas"] . '")';
            }
        }
        //popup = true will overwrite the successFunction
        if (!isset($action['attributes']['popupSettings'])) {
            $action['attributes']['popupSettings'] = "";
        }
        if (isset($action['attributes']['popup']) && $action['attributes']['popup'] && $action['attributes']['popup'] !== "false") {
            $successFunction = 'afApp.widgetPopup("' . $action["attributes"]["url"] . '","","","' . $action['attributes']['popupSettings'] . '");';
        }
        // Confirm function
        if ($action["attributes"]["confirm"] != "false" && $action["attributes"]["confirmMsg"]) {
            $confirmFunction = '
				Ext.Msg.show({
				   title:"Confirmation Required",
				   msg: "' . $confirmMsg . '",
				   buttons: Ext.Msg.YESNO,
				   fn: function(buttonId){if(buttonId == "yes"){' . $functionForUpdater . $successFunction . '}},
				   icon: Ext.MessageBox.QUESTION					   
				});
			';
        } else {
            $confirmFunction = $functionForUpdater . $successFunction;
        }
        $sourceForButton = $noDataInGridFunction . $noItemsSelectedFunction . $confirmFunction;
        $handlersForMoreActions = array('click' => array('parameters' => 'field,event', 'source' => (isset($action['attributes']['script']) ? $action['attributes']['script'] : '') . ";" . $sourceForButton));
        if (isset($action["handlers"])) {
            if (!isset($action["attributes"]["handlers"]["click"])) {
                $action["attributes"]["handlers"]["click"] = array('parameters' => 'field,event', 'source' => (isset($action['attributes']['script']) ? $action['attributes']['script'] : '') . ";" . $sourceForButton);
            } else {
                $action["attributes"]["handlers"]["click"]["source"] .= (isset($action['attributes']['script']) ? $action['attributes']['script'] : '') . ";" . $sourceForButton;
            }
            $handlersForMoreActions = $action["attributes"]["handlers"];
        }
        $parameterForButton = array('label' => $action["attributes"]["label"], 'icon' => $action["attributes"]["icon"], 'iconCls' => $action["attributes"]["iconCls"], 'listeners' => $handlersForMoreActions);
        return ComponentCredential::filter($parameterForButton, $action['attributes']['url']);
    }
    public function end()
    {
        /*$this->attributes['listeners']['afterrender']=$this->afExtjs->asMethod(array(
        			"parameters"=>"value, metadata, record",
        			"source"=>"var tb = this.getTopToolbar();
        			if(!tb) return;	
        			var box = this.getBox();
        			tb.setWidth(box.width);	"
        		));	
        		*/
        $this->attributes['canMask'] = $this->afExtjs->asMethod(array("parameters" => "", "source" => "return !Ext.isIE&&!" . $this->privateName . ".disableLoadMask&&!Ext.get('loading');"));
        if (!$this->attributes['tree']) {
            $this->attributes['view'] = $this->afExtjs->GroupingColorView(array('forceFit' => $this->attributes['forceFit'], 'groupTextTpl' => ' {text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'));
            if (isset($this->attributes['clearGrouping']) && $this->attributes['clearGrouping']) {
                @($this->attributes['listeners']['render']["source"] .= "this.store.clearGrouping();");
            }
        } else {
            $this->afExtjs->setAddons(array('css' => array($this->afExtjs->getPluginsDir() . 'treegrid/css/TreeGrid.css'), 'js' => array($this->afExtjs->getPluginsDir() . 'treegrid/TreeGrid.js', $this->afExtjs->getPluginsDir() . 'treegrid/Ext.ux.SynchronousTreeExpand.js')));
            $this->attributes['viewConfig'] = $this->afExtjs->asAnonymousClass(array('forceFit' => $this->attributes['forceFit']));
        }
        if (isset($this->proxy['url']) && count($this->columns) > 0) {
            $this->proxy['url'] = sfContext::getInstance()->getRequest()->getRelativeUrlRoot() . $this->proxy['url'];
            $filtersPrivateName = 'filters_' . Util::makeRandomKey();
            $storePrivateName = 'store_' . Util::makeRandomKey();
            $readerPrivateName = 'reader_' . Util::makeRandomKey();
            if ($this->attributes['pager']) {
                $pagingToolbarPrivateName = 'pt_' . Util::makeRandomKey();
            }
            $wasSort = false;
            $firstSortableCol = null;
            $summaryPlugin = false;
            foreach ($this->columns as $column) {
                $temp_column = null;
                $temp_field = null;
                $temp_name = 'Header ' . Util::makeRandomKey();
                $temp_column['dataIndex'] = isset($column['name']) ? $column['name'] : Util::stripText($temp_name);
                $temp_field['name'] = isset($column['name']) ? $column['name'] : Util::stripText($temp_name);
                //$temp_field['type']=isset($column['type'])?$column['type']:'auto';
                $temp_field['sortType'] = isset($column['sortType']) ? $column['sortType'] : 'asText';
                $temp_column['sortType'] = isset($column['sortType']) ? $column['sortType'] : 'asText';
                //Grid summary plugin
                $temp_column['summaryType'] = isset($column['summaryType']) ? $column['summaryType'] : null;
                if (!$summaryPlugin && $temp_column['summaryType'] != null) {
                    $this->attributes['plugins'][] = "new Ext.ux.grid.GridSummary";
                    $summaryPlugin = true;
                }
                $temp_column['header'] = isset($column['label']) ? $column['label'] : $temp_name;
                $temp_column['sortable'] = isset($column['sortable']) ? $column['sortable'] : true;
                if (isset($column['width']) && $column['width'] != 'auto') {
                    $temp_column['width'] = $column['width'];
                }
                $temp_column['hidden'] = isset($column['hidden']) ? $column['hidden'] : false;
                $temp_column['hideable'] = isset($column['hideable']) ? $column['hideable'] : true;
                $temp_column = $this->formatNumberColumn($temp_column);
                /**
                 * Edit link at defined column
                 * Please comment this block if the edit should be under the Actions column.
                 * This section looks the edit="true" in the xml columns. If found, and if 
                 * there is a row actions matching the name or label with edit, this will
                 * be transformed to the edit="true" column
                 */
                if (isset($column['edit']) && $column['edit'] || isset($column['action'])) {
                    //print_r($this->actionsObject);
                    if ($this->actionsObject) {
                        $actions = $this->actionsObject->getActions();
                        //print_r($actions);
                        if (is_array($actions)) {
                            foreach ($actions as $key => $action) {
                                if (isset($column['action']) && preg_match("/list[0-9]+_" . preg_replace("/^\\//", "", $column['action']) . "\$/", $action['name']) || isset($column['edit']) && $column['edit'] === "true" && (preg_match("/_edit\$/", $action['name']) || preg_match("/edit\$/i", $action['label']) || preg_match("/_modify\$/", $action['name']) || preg_match("/modify\$/i", $action['label']) || preg_match("/_update\$/", $action['name']) || preg_match("/update\$/i", $action['label']))) {
                                    $urlIndex = $action['urlIndex'];
                                    $credential = ComponentCredential::urlHasCredential($action['url']);
                                    $actionUrl = UrlUtil::url($action['url']);
                                    if (isset($action['load']) && $action['load'] == "page") {
                                        $actionUrl = $action['url'];
                                    }
                                    $temp_column['renderer'] = $this->afExtjs->asMethod(array("parameters" => "value, metadata, record", "source" => "if(!" . intval($credential) . ") return value;var action = record.get('" . $urlIndex . "'); if(!action) return value; var m = action.toString().match(/.*?\\?(.*)/);return '<a  href=\"" . $actionUrl . "?'+m[1]+'\" qtip=\"" . (isset($action['tooltip']) ? $action['tooltip'] : '') . "\">'+ value + '</a>';"));
                                    $this->actionsObject = $this->actionsObject->changeProperty($action['name'], 'hidden', true);
                                    if (isset(afExtjs::getInstance()->private[$this->actionsObject->privateName])) {
                                        unset(afExtjs::getInstance()->private[$this->actionsObject->privateName]);
                                    }
                                    $this->actionsObject->end();
                                    $this->movedRowActions++;
                                }
                            }
                        }
                    }
                }
                /*
                 * check for context menu
                 */
                $style = '';
                $arrowSpan = '';
                if (isset($column['contextMenu']) && $column['contextMenu']) {
                    $style = "";
                    $arrowSpan = '<span class="interactive-arrow"><a class="interactive-arrow-a"  href="#">&nbsp;</a></span>';
                    $contextMenu = context_menu($column['contextMenu'])->privateName;
                    $this->contextMenu[$temp_field['name']] = $contextMenu;
                    $temp_column['renderer'] = $this->afExtjs->asMethod(array("parameters" => "value, metadata, record", "source" => "return '<span {$style}>{$arrowSpan}' + value + '</span>';"));
                }
                /*else{
                			$contextMenu = context_menu('',array('grid'))->privateName;
                			$this->contextMenu[$temp_field['name']] = $contextMenu;
                		}*/
                /**********************************************************************************/
                if (isset($column['qtip']) && $column['qtip']) {
                    $temp_column['renderer'] = $this->afExtjs->asMethod(array("parameters" => "value, metadata, record", "source" => "var qtip = Ext.util.Format.htmlEncode(value); return '<span qtip=\"' + qtip + '\" {$style}>{$arrowSpan}' + value + '</span>';"));
                }
                //If numeric data, right align while rendering...
                // Disabled for now. JS error: "record is undefined"
                //$this->handleNumericColumns($temp_column);
                // Add filter here
                afExtjsGridFilter::add($this, $column, $temp_column, $temp_field);
                //Remote filter
                if (isset($column['sortIndex'])) {
                    $temp_column['sortIndex'] = $column['sortIndex'];
                }
                if (!isset($temp_column['id'])) {
                    $temp_column['id'] = $temp_column['dataIndex'];
                }
                if (!$this->attributes['tree']) {
                    if (isset($column['id']) && $column['id']) {
                        $temp_column['id'] = $temp_column['dataIndex'];
                        if (!isset($this->attributes[$readerPrivateName]['id'])) {
                            $this->attributes[$readerPrivateName]['id'] = $temp_column['dataIndex'];
                        }
                    }
                    if (isset($column['groupField']) && $column['groupField']) {
                        $this->attributes[$storePrivateName]['groupField'] = $temp_column['dataIndex'];
                    }
                }
                if (!$wasSort && isset($column['sort']) && in_array($column['sort'], array('ASC', 'DESC'))) {
                    $wasSort = true;
                    $this->defineSortInfo($storePrivateName, $temp_column['dataIndex'], $column['sort']);
                }
                if (!$firstSortableCol && ArrayUtil::isTrue($temp_column, 'sortable')) {
                    $firstSortableCol = $temp_column['dataIndex'];
                }
                $this->attributes['columns'][] = $this->afExtjs->asAnonymousClass($temp_column);
                if ($this->attributes['tree'] && !isset($this->attributes['master_column_id'])) {
                    $this->attributes['master_column_id'] = $temp_column['dataIndex'];
                }
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass($temp_field);
            }
            /*
             * Add listeners for context menu
             */
            $this->_addListenersForContextMenu($attributes);
            /**********************************************************/
            if (!$wasSort && $firstSortableCol) {
                $this->defineSortInfo($storePrivateName, $firstSortableCol, 'ASC');
            }
            $count_actions = is_object($this->actionsObject) ? count($this->actionsObject->attributes['actions']) : 0;
            if ($count_actions > 0) {
                for ($i = 1; $i <= $count_actions; $i++) {
                    $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => 'action' . $i, 'type' => 'string'));
                    $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => 'hide' . $i, 'type' => 'boolean'));
                }
            }
            $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => 'message'));
            $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => 'redirect'));
            $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => 'load'));
            if ($this->attributes['tree']) {
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_id', 'type' => 'int'));
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_parent', 'type' => 'auto'));
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_is_leaf', 'type' => 'bool'));
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_color', 'type' => 'auto'));
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_cell_color', 'type' => 'auto'));
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_buttonOnColumn', 'type' => 'auto'));
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_buttonText', 'type' => 'auto'));
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_buttonDescription', 'type' => 'auto'));
                if ($this->attributes['select']) {
                    $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_selected', 'type' => 'auto'));
                }
                $this->attributes[$readerPrivateName]['id'] = '_id';
            } else {
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_color', 'type' => 'auto'));
                $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_cell_color', 'type' => 'auto'));
                //Select for normal grid too.....
                if ($this->attributes['select']) {
                    $this->attributes[$readerPrivateName]['fields'][] = $this->afExtjs->asAnonymousClass(array('name' => '_selected', 'type' => 'auto'));
                }
                //..................................
                if (!isset($this->attributes[$readerPrivateName]['id'])) {
                    $this->attributes[$readerPrivateName]['id'] = '_id';
                }
            }
            $this->attributes[$readerPrivateName]['totalProperty'] = 'totalCount';
            $this->attributes[$readerPrivateName]['root'] = 'rows';
            $this->attributes[$readerPrivateName]['properties'] = 'properties';
            $this->afExtjs->private[$readerPrivateName] = $this->afExtjs->JsonReader($this->attributes[$readerPrivateName]);
            unset($this->attributes[$readerPrivateName]);
            $this->attributes[$storePrivateName]['reader'] = $this->afExtjs->asVar($readerPrivateName);
            if (isset($this->attributes['remoteSort'])) {
                $this->attributes[$storePrivateName]['remoteSort'] = $this->attributes['remoteSort'];
                unset($this->attributes['remoteSort']);
            }
            $this->attributes[$storePrivateName]['proxy'] = $this->afExtjs->HttpProxy(array('url' => $this->proxy['url'], 'method' => 'GET', 'disableCaching' => false, 'listeners' => array('beforeload' => $this->afExtjs->asMethod(array('parameters' => 'proxy,params', 'source' => 'proxy.lastParams=params')), 'exception' => self::getJsExceptionListener($this->afExtjs, $this->privateName))));
            $beforeloadListener = "\r\n\t\t\t\tif(" . $this->privateName . ".canMask()){" . $this->privateName . ".getEl().mask('Loading, please Wait...', 'x-mask-loading');}\r\n\t\t\t";
            if (isset($this->proxy['stateId'])) {
                $this->attributes[$storePrivateName]['pt_state_loaded'] = false;
                $this->attributes[$storePrivateName]['pt_state'] = "Ext.state.Manager.get('" . $this->proxy['stateId'] . "')";
                $this->attributes[$storePrivateName]['listeners']['beforeload'] = $this->afExtjs->asMethod(array("parameters" => "object,options", "source" => "if(!this.pt_state_loaded&&this.pt_state){options.params=this.pt_state;this.pt_state_loaded=true;}" . $beforeloadListener));
            } else {
                $this->attributes[$storePrivateName]['listeners']['beforeload'] = $this->afExtjs->asMethod(array("parameters" => "object,options", "source" => $beforeloadListener));
            }
            $this->attributes[$storePrivateName]['listeners']['load'] = $this->afExtjs->asMethod(array("parameters" => "object,records,options", "source" => '/*console.log(eval(' . $this->privateName . '.bindForm));*/if(records.length>0&&records[0].json.redirect&&records[0].json.message&&records[0].json.load){var rec=records[0].json;Ext.Msg.alert("Failure", rec.message, function(){afApp.load(rec.redirect,rec.load);});}else{if(' . $this->privateName . '.canMask()){' . $this->privateName . '.getEl().unmask();}}
																			' . $this->privateName . '.ownerCt.ownerCt.doLayout();/*Chrome fix*/' . $this->privateName . '.body.dom.lastChild.style.width=\'100%\';/*Toolbars fix*/if(' . $this->privateName . '.bbar){' . $this->privateName . '.bbar.dom.style.width=\'auto\';' . $this->privateName . '.bbar.dom.firstChild.style.width=\'auto\';}if(' . $this->privateName . '.tbar){' . $this->privateName . '.tbar.dom.style.width=\'auto\';' . $this->privateName . '.tbar.dom.firstChild.style.width=\'auto\';}' . ($this->dataLoadedHandler != '' ? "{$this->dataLoadedHandler}({$this->privateName});" : '') . $this->resizeToolBars()));
            $this->attributes[$storePrivateName]['listeners']['loadexception'] = $this->afExtjs->asMethod(array("parameters" => "", "source" => 'if(' . $this->privateName . '.canMask()){' . $this->privateName . '.getEl().unmask();}'));
            if (!$this->attributes['tree']) {
                $this->afExtjs->private[$storePrivateName] = $this->afExtjs->GroupingStore($this->attributes[$storePrivateName]);
            } else {
                $this->afExtjs->private[$storePrivateName] = $this->afExtjs->AdjacencyListStore($this->attributes[$storePrivateName]);
            }
            unset($this->attributes[$storePrivateName]);
            if ($this->attributes['pager']) {
                $this->attributes[$pagingToolbarPrivateName]['store'] = $this->afExtjs->asVar($storePrivateName);
                $this->attributes[$pagingToolbarPrivateName]['displayInfo'] = true;
                if (isset($this->attributes['pagerTemplate'])) {
                    $this->attributes[$pagingToolbarPrivateName]['displayMsg'] = $this->parsePagerTemplate($this->attributes['pagerTemplate']);
                }
                $this->attributes[$pagingToolbarPrivateName]['pageSize'] = isset($this->proxy['limit']) ? $this->proxy['limit'] : 20;
                if (isset($this->proxy['stateId'])) {
                    $this->attributes[$pagingToolbarPrivateName]['stateId'] = $this->proxy['stateId'];
                    $this->attributes[$pagingToolbarPrivateName]['stateEvents'] = array('change');
                    $this->attributes[$pagingToolbarPrivateName]['stateful'] = true;
                    $this->attributes[$pagingToolbarPrivateName]['getState'] = $this->afExtjs->asMethod(array("parameters" => "", "source" => "return { start: " . (isset($this->proxy['start']) ? $this->proxy['start'] : "this.cursor") . ",\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlimit: this.pageSize };"));
                }
                if (count($this->filters) > 0) {
                    //$this->attributes[$pagingToolbarPrivateName]['plugins'] = $this->afExtjs->asVar($filtersPrivateName);
                }
                if (!$this->attributes['tree']) {
                    $this->afExtjs->private[$pagingToolbarPrivateName] = $this->afExtjs->PagingToolbar($this->attributes[$pagingToolbarPrivateName]);
                } else {
                    $this->afExtjs->private[$pagingToolbarPrivateName] = $this->afExtjs->GridTreePagingToolbar($this->attributes[$pagingToolbarPrivateName]);
                }
                unset($this->attributes[$pagingToolbarPrivateName]);
            }
        }
        if (count($this->filters) > 0) {
            $this->attributes[$filtersPrivateName]['filters'] = $this->filters;
            $this->attributes[$filtersPrivateName]['local'] = isset($this->attributes['remoteFilter']) && $this->attributes['remoteFilter'] ? false : true;
            //$this->attributes[$filtersPrivateName]['filterby']=sfContext::getInstance()->getActionStack()->getLastEntry()->getActionInstance()->getRequestParameter("filterby",false);
            $this->attributes[$filtersPrivateName]['filterby'] = sfContext::getInstance()->getUser()->getAttribute('filterby', false);
            $this->attributes[$filtersPrivateName]['filterbyKeyword'] = sfContext::getInstance()->getUser()->getAttribute('filterbyKeyword', false);
            sfContext::getInstance()->getUser()->setAttribute('filterby', false);
            sfContext::getInstance()->getUser()->setAttribute('filterbyKeyword', false);
            //$this->attributes['title'] = $this->attributes['title'].": <font color=red>(Filtered by keyword: '".$this->attributes[$filtersPrivateName]['filterbyKeyword']."'</font>)";
            $this->afExtjs->private[$filtersPrivateName] = $this->afExtjs->GridFilters($this->attributes[$filtersPrivateName]);
            $this->attributes['plugins'][] = $this->afExtjs->asVar($filtersPrivateName);
            unset($this->attributes[$filtersPrivateName]);
        }
        if ($count_actions > 0) {
            if ($this->movedRowActions) {
                if ($count_actions - $this->movedRowActions > 0) {
                    $this->attributes['columns'][] = $this->afExtjs->asVar($this->actionsObject->privateName);
                }
            } else {
                $this->attributes['columns'][] = $this->afExtjs->asVar($this->actionsObject->privateName);
            }
            $this->attributes['plugins'][] = $this->afExtjs->asVar($this->actionsObject->privateName);
        }
        $this->attributes['store'] = $this->afExtjs->asVar($storePrivateName);
        if ($this->attributes['pager']) {
            $this->attributes['bbar'] = $this->afExtjs->asVar($pagingToolbarPrivateName);
        }
        //changed to have select on normal grid too..
        //if($this->attributes['tree'] && $this->attributes['select'])
        if ($this->attributes['select']) {
            $this->afExtjs->setAddons(array('js' => array($this->afExtjs->getPluginsDir() . 'treegrid/Ext.ux.CheckboxSelectionModel.js')));
            $selectionModelPrivateName = 'sm_' . Util::makeRandomKey();
            $this->afExtjs->private[$selectionModelPrivateName] = $this->afExtjs->UxCheckboxSelectionModel(array());
            $this->attributes['sm'] = $this->afExtjs->asVar($selectionModelPrivateName);
            //if($this->attributes['tree'])
            $this->attributes['columns'][] = $this->afExtjs->asVar($selectionModelPrivateName);
            //array_unshift($this->attributes['columns'],$this->afExtjs->asVar($selectionModelPrivateName));
            /*
             * Since the insertion of checkbox selection model at the beginning of the grid, the tree structrue get lost, though it was 
             * fine for non-tree grid. To overcome this first the grid is rendered as it is with the checkbox selection model at the end
             * and when the grid is rendered the checkbox selection model is now moved to the initial column position of the grid.
             */
            $jsSource = "\r\n\t\t\t\tvar gcm = " . $this->privateName . ".getColumnModel();\r\n\t\t\t\tif(gcm.getColumnHeader(gcm.getColumnCount()-1) == '<div class=\"x-grid3-hd-checker\" id=\"hd-checker\">&#160;</div>') \r\n\t\t\t\tgcm.moveColumn(gcm.getColumnCount()-1,0);\r\n\t\t\t\t";
        } else {
            $jsSource = '';
        }
        @($this->attributes['listeners']['render']["source"] .= "\r\n\t\t\tthis.store.load({\r\n\t\t\t\tparams:{\r\n\t\t\t\t\tstart:" . (isset($this->proxy['start']) ? $this->proxy['start'] : 0) . ", \r\n\t\t\t\t\tlimit:" . (isset($this->proxy['limit']) ? $this->proxy['limit'] : 20) . "\r\n\t\t\t\t}\r\n\t\t\t});");
        $attributes['listeners']['render']["source"] = $this->attributes['listeners']['render']["source"];
        $attributes['listeners']['render']["source"] .= $jsSource;
        unset($this->attributes['listeners']['render']["source"]);
        $this->attributes['listeners']['render'] = $this->afExtjs->asMethod(array("parameters" => "", "source" => $attributes['listeners']['render']["source"]));
        unset($attributes['listeners']['render']["source"]);
        //attach center loading ajax to links with class="widgetLoad"
        $this->attributes['listeners']['mouseover'] = $this->afExtjs->asMethod(array("parameters" => "", "source" => "afApp.attachHrefWidgetLoad();"));
        if (count($this->filters) > 0) {
            $this->afExtjs->setAddons(array('js' => array($this->afExtjs->getPluginsDir() . 'grid-filtering/ux/menu/EditableItem.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/menu/ComboMenu.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/menu/RangeMenu.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/GridFilters.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/DrillFilter.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/RePositionFilters.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/SaveSearchState.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/FilterInfo.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/FilterOption.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/filter/Filter.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/filter/BooleanFilter.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/filter/ComboFilter.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/filter/DateFilter.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/filter/ListFilter.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/filter/NumericFilter.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/filter/StringFilter.js', $this->afExtjs->getPluginsDir() . 'grid-filtering/ux/grid/filter/TextFilter.js'), 'css' => array($this->afExtjs->getPluginsDir() . 'grid-filtering/resources/style.css')));
            // Add reset filters on menu action if there is filter in grid
            $this->addMenuActionsItem(array('label' => 'Filters', 'icon' => '/images/famfamfam/drink.png', 'listeners' => array('click' => array('parameters' => '', 'source' => 'var grid = ' . $this->privateName . ';
							var filters = grid.filters;
							if(!filters) return;							
							var saveFilter = Ext.ux.SaveSearchState(grid);
							saveFilter.viewSavedList();'))));
            $this->addMenuActionsItem(array('xtype' => 'menuseparator'));
            if (isset($this->attributes['name']) || isset($this->attributes['path'])) {
                $savedFilters = afSaveFilterPeer::getFiltersByName(isset($this->attributes['name']) ? $this->attributes['name'] : $this->attributes['path']);
                $fc = 0;
                foreach ($savedFilters as $f) {
                    //if($fc > 4) break;
                    $this->addMenuActionsItem(array('label' => ++$fc . ". " . $f->getName(), 'listeners' => array('click' => array('parameters' => '', 'source' => '
    							var grid = ' . $this->privateName . ';
    							var filters = grid.filters;
    							if(!filters) return;							
    							var saveFilter = Ext.ux.SaveSearchState(grid);							
    							saveFilter.restore(\'' . $f->getFilter() . '\',"' . $f->getName() . '");'))));
                }
            }
        }
        $this->addMenuActions();
        if (!$this->attributes['tree']) {
            $this->afExtjs->private[$this->privateName] = $this->afExtjs->GridPanel($this->attributes);
        } else {
            $this->afExtjs->private[$this->privateName] = $this->afExtjs->GridTreePanel($this->attributes);
        }
        //print_r($this);
    }
Пример #4
0
 private function checkWidgetCredentials($module = null, $action = null)
 {
     $action_name = $action === null ? $this->context->getActionName() : $action;
     $module = $module === null ? $this->context->getModuleName() : $module;
     $configUtils = new afConfigUtils($module);
     $path = $configUtils->getConfigFilePath($action_name . '.xml', true);
     /**
      * quick fix for symfony credentials
      */
     return ComponentCredential::actionHasCredential($module, $action_name);
     $this->readXmlDocument($path, true);
     $permissions = $this->fetch("//s:permissions[@for='" . $action_name . "']");
     if (!$permissions->length) {
         return true;
     }
     $url = $this->getnode("url", $this->document->documentElement);
     $rights = $this->fetch("./s:right", $permissions->item(0));
     $credentials = "";
     foreach ($rights as $right) {
         $r = $this->get($right, "name");
         if ($r == "*") {
             return true;
         }
         $credentials .= $this->get($right, "name") . ",";
     }
     if ($this->checkCredentials($credentials) === false) {
         if ($this->type === self::PANEL || $this->type === self::WIZARD) {
             $actionInstance->redirect($url ? $this->get($url) : sfConfig::get("app_parser_denied"));
         } else {
             return false;
         }
     }
 }