Exemplo n.º 1
0
 public function Table(App_Grid_Filter $filter, array $list = null)
 {
     $this->_gridid = $this->getGridId();
     $this->_formid = $this->getFormId();
     $req = Zend_Controller_Front::getInstance()->getRequest();
     $this->_request = $req;
     if ($filter->isPrepared() != true) {
         $filter->setup();
     }
     $module = $req->getModuleName();
     $controller = $req->getControllerName();
     $resource = strtolower("{$module}:{$controller}");
     $isAllowedEdit = Sam_Acl::getInstance()->isAllowed($resource, "edit");
     $isAllowedNew = Sam_Acl::getInstance()->isAllowed($resource, "new");
     $isAllowedDelete = Sam_Acl::getInstance()->isAllowed($resource, "delete");
     if ($filter->isPrepared() == true) {
         $filter->setRequest($req);
         if (isset($filter->getGridConfig()->pagination) and trim($filter->getGridConfig()->pagination) == 'false') {
             //echo 'enabledPagination ';
             $this->_enabledPagination = false;
         }
         if (isset($filter->getGridConfig()->newrowMethod) and trim($filter->getGridConfig()->newrowMethod) == 'blankrow') {
             $this->_enabledAddNewRowAction = true;
         } elseif ($filter->getGridConfig()->newrowMethod == 'dialog' or $filter->getGridConfig()->newrowMethod == 'OpenNewDialog') {
             $this->_enabledOpenNewDialogAction = true;
         }
         $this->_tableType = $filter->getGridConfig()->type;
         // แก้ใน global 1 ด้วย
         if (trim($filter->getGridConfig()->type) == self::TABLE_TYPE_EDITINLINE) {
             $this->_enabledInlineEdit = true;
             $this->_enabledRowOnClicAction = false;
             $this->_tableType = self::TABLE_TYPE_EDITINLINE;
             if (!$isAllowedEdit) {
                 $this->_tableType = self::TABLE_TYPE_DEFAULT;
                 $this->_enabledInlineEdit = false;
             }
         }
         if (isset($filter->getGridConfig()->scrollbar) and in_array($filter->getGridConfig()->scrollbar, array('false', 'disabled'))) {
             $this->_enabledScollbar = false;
         }
         if ($filter->getGridConfig()->onRowClickAction == 'false' or $filter->getGridConfig()->onRowClickAction == 'disabled') {
             $this->_enabledRowOnClicAction = false;
         }
         if (true == $filter->isDeleteButtonDisabled() or false == $isAllowedDelete) {
             $this->_enabledDeleteAction = false;
         }
         if (true == $filter->isEditButtonDisabled()) {
             $this->_enabledEditIconOnClicAction = false;
         } else {
             $this->_enabledEditIconOnClicAction = true;
             $this->_openEditFormIn = trim($filter->getGridConfig()->editMethod) != '' ? $filter->getGridConfig()->editMethod : $this->_openEditFormIn;
         }
         // if(true ==$this->_enabledInlineEdit ){
         // 	$this->_enabledEditIconOnClicAction =false;
         // }
     }
     if ($isAllowedNew) {
         if ($this->_enabledAddNewRowAction) {
             $this->addButonOnActionBar('addBlankRecord', array('class' => 'ui-icon-circle-plus', 'text' => 'New', 'width' => '100px'));
         }
         if ($this->_enabledOpenNewDialogAction) {
             $this->addButonOnActionBar('btnOpenNewDialog', array('class' => 'ui-icon-circle-plus', 'text' => 'New', 'width' => '100px'));
         }
     }
     if ($this->_enabledInlineEdit) {
         $this->addButonOnActionBar('btnSaveGrid', array('class' => 'ui-icon-disk', 'text' => 'Save', 'width' => '100px'));
     }
     $ui = $filter->getUiName();
     $this->_modelName = $filter->getModelName();
     if ($this->_tableType == self::TABLE_TYPE_TREETABLE) {
         $this->_tablebodyClass = " ";
     }
     // Add Action Button
     // เพิ่มปุ่ม   edit กดแล้วไปหน้า edit เลย
     if ($this->_enabledEditIconOnClicAction == true and $isAllowedEdit == true) {
         $filter->addAction(array('action' => 'edit', 'iconUrl' => '/images/grid/edit.png', 'class' => 'IMG_ROW_EDIT'));
         //$filter->setGridActions($actions);
         $this->_enabledEditIconOnClicAction = true;
     }
     //เพิ่มปุ่ม delete
     if (true == $this->_enabledDeleteAction and true == $isAllowedDelete) {
         $filter->addAction(array('action' => 'delete', 'iconUrl' => '/images/grid/publish_x.png', 'class' => 'IMGDELETE'));
     }
     $tableConfig = $this->getTableConfig($this->_modelName, $ui);
     $this->_columnConfig = $tableConfig;
     $this->_modelConfig = $this->getModelConfig($this->_modelName);
     if ($list == null) {
         if ($this->_tableType == self::TABLE_TYPE_TREETABLE) {
             $list = $filter->getTreeList();
         } else {
             $list = $filter->getList();
         }
     }
     $this->_filter = $filter;
     if ($this->filter()->isActionDisabled()) {
         $this->_printMode = true;
         $x = $this->renderSimpleTable($filter, $list);
     } else {
         $x = $this->redertable($filter, $list);
     }
     return $x;
 }