Mokuji /www/app/AdminModule/presenters/AdminModulesPresenter.php

Language PHP Lines 141
MD5 Hash 668cc63d3ba930f56d0800663f2d4bb6
Repository https://github.com/bazo/Mokuji.git View Raw File View Project SPDX
  1
  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
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
class Admin_ModulesPresenter extends Admin_SecurePresenter
{
	public function actionDefault()
	{
            $this->view = 'modules';
	}
	
	public function createComponentPage($name)
	{
            $page = new Page($this,$name);
            $item = $page->addItem("Link");
            $item->contentFactory = array($this,'createAddNewLink');
            $item = $page->addItem("modules");
            $item->contentFactory = array($this,'createComponentModulesGrid');
            $item->hasSnippets = true;
	}

	public function createAddNewLink($name, $page)
	{
            $link = Html::el('a')->href($this->link('install!'))->class('ajax')->add(Html::el('div')->id('create-new-link')->add(Html::el('div')->id('icon-install'))->add(Html::el('span')->add('Install')));
            return $link;
	}
	//GRID
	public function createComponentModulesGrid($name, $page)
	{
            $grid = new DataGrid($page, $name);
            $grid->rememberState = TRUE; // povolí ukládání stavů komponenty do session
            $grid->timeout = '+ 7 days';
            $ds = $this->model('Modules')->getDs();
            $grid->bindDataTable($ds);

            $grid->keyName = 'module_name';
            $grid->addColumn('module_name', 'Name')->addFilter();

            $grid->addColumn('status', 'Status')->addSelectboxFilter(array('enabled' => "Enabled", 'disabled' => "Disabled"), TRUE);
            $grid->addActionColumn('Actions');
            $grid->addAction('StatusToggle', 'changeStatus!', null, $useAjax = TRUE);

            $grid->addAction('Delete', 'confirmForm:confirmDelete!', Html::el('span')->class('icon icon-explode'), $useAjax = TRUE);
            $renderer = $grid->getRenderer();
            $renderer->paginatorFormat = '%input%';
            $renderer->onActionRender[] = array($this, 'formatActions');

            $grid->setRenderer($renderer);
            return $grid;
	}

        public function formatActions(Html $action, DibiRow $data)
        {
          if($action->attrs['title'] == 'StatusToggle' || $action->attrs['title'] == 'Enable' || $action->attrs['title'] == 'Disable')
          {
              if($data->status == 'enabled') {
                  $action->attrs['title'] = 'Disable';
                  $action->removeChildren();
                  $action->add(Html::el('span')->class('icon icon-stop'));
                  $action->href = $action->href.'&new_status=disabled';
              }
              if($data->status == 'disabled') {
                  $action->attrs['title'] = 'Enable';
                  $action->removeChildren();
                  $action->add(Html::el('span')->class('icon icon-play'));
                  $action->href = $action->href.'&new_status=enabled';
              }

              return $action;
          }
        }

	function createComponentConfirmForm()
        {
            $form = new ConfirmationDialog();
            $form->addConfirmer(
                        'delete', // název signálu bude 'confirmDelete!'
                        array($this, 'deleteModule'), // callback na funkci při kliku na YES
                        array($this, 'questionDelete') // otázka (může být i callback vracející string)
                        );
            return $form;
	}
	
	public function questionDelete($dialog, $params)
	{
            return 'Really delete module '.$params['module_name'].'?';
	}
	
	public function deleteModule($params, $dialog)
	{
            try{
                    $this['page']->redraw('grid');
                    $this->flash('Page '.$title.' deleted!');
                    if(!$this->isAjax()) {$this->redirect('Pages:');}
            }
            catch(DibiDriverException $e)
            {
                    $this->flash($e->getMessage());
            }	
	}

	public function handleChangeStatus($module_name, $new_status)
	{
            ModuleManager::changeStatus($module_name, $new_status);
            $this['page']->refresh('modules');
            if($new_status == 'enabled')
            {
                Environment::getApplication()->installModules();
                $this->invalidateControl('menu');
            }
            else $this->redirect('this');
	}
	
	public function handleInstall()
    {
        $this->view = 'installer';
        $this->invalidateControl('form');
    }
    
    public function createComponentFormModuleInstaller($name)
    {
        $form = new LiveForm($this, $name);
        $form->addFile('file', 'Select file')->addCondition(Form::FILLED, 'Please select a file');
        $form->addButton('btnClose', 'Close');
        $form->addSubmit('btnSubmit', 'Install')->onClick[] = array($this, 'formModuleInstallerSubmitted');
        return $form;
    }
    
    public function formModuleInstallerSubmitted(Button $button)
    {
        $form = $button->getForm();
        $values = $form->getValues();
        unset($values['btnClose']);
        $file = $values['file'];
        if($file->isOK())
        {
            $file->move(MODULES_DIR.'/'.$file->getName());
            
        }
    }
	
}
?>
Back to Top