예제 #1
0
 /**
  * factory to create a grid
  * @param string $name
  * @return \Ublaboo\DataGrid\DataGrid
  */
 public function createComponentPacsConfigGrid($name)
 {
     // create object
     $grid = new \Ublaboo\DataGrid\DataGrid($this, $name);
     // set data source
     $grid->setDataSource($this->model->getTable());
     // set columns hidable
     $grid->setColumnsHideable();
     // add collumn Comment which is sortable and may be filtered
     $grid->addFilterText('comment', _('Comment'));
     $grid->addColumnText('comment', _('Comment'))->setSortable();
     // add collumn group which is sortable and may be filtered
     $grid->addFilterSelect('group', _('Group'), $this->groups);
     $grid->addColumnText('group', _('Group'))->setSortable();
     // add collumn item (dicom.ini key) which is sortable and may be filtered
     $grid->addFilterText('item', _('Item'));
     $grid->addColumnText('item', _('Item'))->setSortable();
     // add collumn value (dicom.ini value) which is sortable and may be filtered and if os authorized allowed inline editing
     $grid->addFilterText('value', _('Value'));
     $colValue = $grid->addColumnText('value', _('Value'))->setSortable();
     if ($this->user->isAllowed("config", "edit")) {
         $colValue->setEditableCallback(function ($id, $value) {
             if (!$this->user->isAllowed("config", "edit")) {
                 $this->flashMessage(_("You are not allowed to do this action."), "danger");
                 $this->redirect("this");
             }
             if ($this->model->isEditable($id) == true) {
                 $this->model->saveChanges($id, $value);
                 $this->flashMessage(_("Value was updated"), "success");
                 $this->redirect("this");
             } else {
                 $this->flashMessage(_("Sorry this is not editable value"), "warning");
                 $this->redirect("this");
             }
         });
     }
     // all non editable columns are grey
     $grid->setRowCallback(function ($item, $row) {
         if ($item->editable == 0) {
             $row->addClass("nonEditable");
         }
     });
     // add column active which may be sortable and filtered
     if (!$this->user->isAllowed("config", "edit")) {
         $grid->addFilterSelect('active', _('Active?'), [1 => $this->answers[1], 0 => $this->answers[0], '' => _("All")]);
     } else {
         $grid->addColumnStatus('active', _("Active?"))->addOption(1, _("Yes"))->setIcon('check')->setClass('btn-success')->endOption()->addOption(0, _("No"))->setIcon('close')->setClass('btn-danger')->endOption()->onChange[] = function ($id, $newValue) {
             if (!$this->user->isAllowed("config", "edit")) {
                 $this->flashMessage(_("You are not allowed to do this action."), "danger");
                 $this->redirect("this");
             }
             try {
                 $this->model->changeActive($id, $newValue);
                 $this->redirect("this");
             } catch (PacsConfigException $exc) {
                 $this->flashMessage($exc->getMessage(), "danger");
                 $this->redirect("this");
             }
         };
     }
     // add action - delete if is allowed
     if ($this->user->isAllowed("config", "delete")) {
         $grid->addAction("delete!", _("Delete"))->setClass('btn btn-xs btn-danger')->setIcon("trash")->setConfirm(_('Do you really want to delete row') . '%s?', 'comment');
         $grid->allowRowsAction('delete!', function ($item) {
             return $item->editable == 1;
         });
     }
     $grid->setItemsPerPageList([10, 50, 100, 9999]);
     return $grid;
 }