PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/bazo/Mokuji
PHP | 140 lines | 122 code | 17 blank | 1 comment | 15 complexity | 668cc63d3ba930f56d0800663f2d4bb6 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT
  1. <?php
  2. class Admin_ModulesPresenter extends Admin_SecurePresenter
  3. {
  4. public function actionDefault()
  5. {
  6. $this->view = 'modules';
  7. }
  8. public function createComponentPage($name)
  9. {
  10. $page = new Page($this,$name);
  11. $item = $page->addItem("Link");
  12. $item->contentFactory = array($this,'createAddNewLink');
  13. $item = $page->addItem("modules");
  14. $item->contentFactory = array($this,'createComponentModulesGrid');
  15. $item->hasSnippets = true;
  16. }
  17. public function createAddNewLink($name, $page)
  18. {
  19. $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')));
  20. return $link;
  21. }
  22. //GRID
  23. public function createComponentModulesGrid($name, $page)
  24. {
  25. $grid = new DataGrid($page, $name);
  26. $grid->rememberState = TRUE; // povolí ukládání stavů komponenty do session
  27. $grid->timeout = '+ 7 days';
  28. $ds = $this->model('Modules')->getDs();
  29. $grid->bindDataTable($ds);
  30. $grid->keyName = 'module_name';
  31. $grid->addColumn('module_name', 'Name')->addFilter();
  32. $grid->addColumn('status', 'Status')->addSelectboxFilter(array('enabled' => "Enabled", 'disabled' => "Disabled"), TRUE);
  33. $grid->addActionColumn('Actions');
  34. $grid->addAction('StatusToggle', 'changeStatus!', null, $useAjax = TRUE);
  35. $grid->addAction('Delete', 'confirmForm:confirmDelete!', Html::el('span')->class('icon icon-explode'), $useAjax = TRUE);
  36. $renderer = $grid->getRenderer();
  37. $renderer->paginatorFormat = '%input%';
  38. $renderer->onActionRender[] = array($this, 'formatActions');
  39. $grid->setRenderer($renderer);
  40. return $grid;
  41. }
  42. public function formatActions(Html $action, DibiRow $data)
  43. {
  44. if($action->attrs['title'] == 'StatusToggle' || $action->attrs['title'] == 'Enable' || $action->attrs['title'] == 'Disable')
  45. {
  46. if($data->status == 'enabled') {
  47. $action->attrs['title'] = 'Disable';
  48. $action->removeChildren();
  49. $action->add(Html::el('span')->class('icon icon-stop'));
  50. $action->href = $action->href.'&new_status=disabled';
  51. }
  52. if($data->status == 'disabled') {
  53. $action->attrs['title'] = 'Enable';
  54. $action->removeChildren();
  55. $action->add(Html::el('span')->class('icon icon-play'));
  56. $action->href = $action->href.'&new_status=enabled';
  57. }
  58. return $action;
  59. }
  60. }
  61. function createComponentConfirmForm()
  62. {
  63. $form = new ConfirmationDialog();
  64. $form->addConfirmer(
  65. 'delete', // název signálu bude 'confirmDelete!'
  66. array($this, 'deleteModule'), // callback na funkci při kliku na YES
  67. array($this, 'questionDelete') // otázka (může být i callback vracející string)
  68. );
  69. return $form;
  70. }
  71. public function questionDelete($dialog, $params)
  72. {
  73. return 'Really delete module '.$params['module_name'].'?';
  74. }
  75. public function deleteModule($params, $dialog)
  76. {
  77. try{
  78. $this['page']->redraw('grid');
  79. $this->flash('Page '.$title.' deleted!');
  80. if(!$this->isAjax()) {$this->redirect('Pages:');}
  81. }
  82. catch(DibiDriverException $e)
  83. {
  84. $this->flash($e->getMessage());
  85. }
  86. }
  87. public function handleChangeStatus($module_name, $new_status)
  88. {
  89. ModuleManager::changeStatus($module_name, $new_status);
  90. $this['page']->refresh('modules');
  91. if($new_status == 'enabled')
  92. {
  93. Environment::getApplication()->installModules();
  94. $this->invalidateControl('menu');
  95. }
  96. else $this->redirect('this');
  97. }
  98. public function handleInstall()
  99. {
  100. $this->view = 'installer';
  101. $this->invalidateControl('form');
  102. }
  103. public function createComponentFormModuleInstaller($name)
  104. {
  105. $form = new LiveForm($this, $name);
  106. $form->addFile('file', 'Select file')->addCondition(Form::FILLED, 'Please select a file');
  107. $form->addButton('btnClose', 'Close');
  108. $form->addSubmit('btnSubmit', 'Install')->onClick[] = array($this, 'formModuleInstallerSubmitted');
  109. return $form;
  110. }
  111. public function formModuleInstallerSubmitted(Button $button)
  112. {
  113. $form = $button->getForm();
  114. $values = $form->getValues();
  115. unset($values['btnClose']);
  116. $file = $values['file'];
  117. if($file->isOK())
  118. {
  119. $file->move(MODULES_DIR.'/'.$file->getName());
  120. }
  121. }
  122. }
  123. ?>