PageRenderTime 89ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/app/plugins/javan/controllers/jv_core_controller.php

https://github.com/ata/steak
PHP | 78 lines | 70 code | 6 blank | 2 comment | 7 complexity | ea9bae18a65b9d06302b50aa67282226 MD5 | raw file
  1. <?php
  2. class JvCoreController extends JavanAppController {
  3. var $components = array('RequestHandler');
  4. var $helpers = array('Ajax');
  5. var $uses = array();
  6. function menu() {
  7. $this->loadModel('Link');
  8. $menus = $this->Link->find('all', array('recursive'=>3,'conditions'=>'Link.parent_id IS NULL'));
  9. $this->set(compact('menus'));
  10. }
  11. function ajax_menu_add($pid=null, $edit=false){
  12. $this->loadModel('Link');
  13. if(!empty($this->data)){
  14. Configure::write('debug', 0);
  15. $this->RequestHandler->setContent('json', 'text/x-json');
  16. if($this->data['Link']['path']){
  17. $path = explode('/', $this->data['Link']['path']);
  18. $this->data['Link']['controller'] = $path[0];
  19. $this->data['Link']['action'] = $path[1];
  20. }
  21. if ($this->Link->save($this->data)) {
  22. $response['error'] = array("code"=>0);
  23. $response['redirect'] = array('action'=>'menu');
  24. } else {
  25. $errorMessages = $this->validateErrors($this->Link);
  26. $response['error'] = array("code"=>1, "messages"=>$errorMessages);
  27. $response['redirect'] = array('action'=>'menu');
  28. }
  29. $this->set(compact("response"));
  30. $this->render('message');
  31. }else{
  32. $reservedLinks = $this->Link->find('all', array('recursive'=>-1));
  33. $actions = $this->JvUtil->listActions($reservedLinks);
  34. $path = "";
  35. if($edit){
  36. $this->data = $this->Link->read(null, $pid);
  37. $pid = $this->data['Link']['parent_id'];
  38. $path = $this->data['Link']['controller']."/".$this->data['Link']['action'];
  39. $actions = am($actions, array($path=>$path));
  40. }
  41. $this->set(compact("pid","actions", "edit", "path"));
  42. }
  43. }
  44. function ajax_menu_delete($id){
  45. $this->RequestHandler->renderAs($this, "json");
  46. Configure::write('debug', 0);
  47. if(!$id){
  48. // error message here
  49. }else{
  50. $this->loadModel('Link');
  51. if($this->Link->delete($id)){
  52. $this->set('response', array("deleted_id"=>$id));
  53. }else{
  54. // cannot delete
  55. }
  56. }
  57. $this->render('message');
  58. }
  59. function order(){
  60. $this->autoRender = false;
  61. $orderedList = current($this->params['form']);
  62. $this->loadModel('Link');
  63. $position = 1;
  64. foreach($orderedList as $linkId){
  65. $this->Link->id = $linkId;
  66. $data['Link']['position'] = $position;
  67. $this->Link->save($data);
  68. $position++;
  69. }
  70. }
  71. }
  72. ?>