Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 120 lines (99 sloc) 3.281 kb
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
<?php
/***********************************************************
..

Reference:
http://atk4.com/doc/ref

**ATK4*****************************************************
This file is part of Agile Toolkit 4
http://www.atk4.com/
(c) 2008-2011 Agile Technologies Ireland Limited
Distributed under Affero General Public License v3
If you are using this file in YOUR web software, you
must make your make source code for YOUR web software
public.

See LICENSE.txt for more information

You can obtain non-public copy of Agile Toolkit 4 at
http://www.atk4.com/commercial/

*****************************************************ATK4**/
class Page_EntityManager extends Page {
public $controller=null;
public $model=null;
public $c;

public $allow_add=true;
public $allow_edit=true;
public $allow_delete=true;

public $grid_actual_fields=false;
public $edit_actual_fields=false;
public $add_actual_fields; // by default same as edit
public $read_only=false;

public $grid;
public $form;

function init(){
parent::init();
if(!$_GET['entitymanager'])$_GET['entitymanager']=$this->name;
$this->api->stickyGET('entitymanager');
if(!isset($this->add_actual_fields))$this->add_actual_fields=$this->edit_actual_fields;
if(!$this->c){
if($this->controller){
$this->c=$this->add($this->controller);
}elseif($this->model){
$this->c=$this->add('Controller');
$this->c->setModel('Model_'.$this->model);
}
}
}
function reloadJS(){
return $this->js()->_selector('#'.$_GET['entitymanager'].'_grid')->atk4_loader('reload');
}

function initMainPage(){
$this->grid=$g=$this->add('MVCGrid','grid');
$g->js(true)->atk4_loader(array('url'=>$this->api->getDestinationURL(null,array('cut_object'=>$g->name))));


if($this->grid_actual_fields)
$c=$this->c->setActualFields($this->grid_actual_fields);

$g->setController($c=$this->c);

if($this->allow_edit)
$g->addColumnPlain('expander_widget', 'edit', $this->read_only?'view':'edit');
if($this->allow_add){
$g->addButton('Add')->js('click')->univ()->dialogURL('Add new',$this->api->getDestinationURL('./edit'));
}
if($this->allow_delete){
$g->addColumnPlain('confirm','delete');
if($_GET['delete']){
$c->loadData($_GET['delete']);
$c->delete();
$g->js(null,$g->js()->univ()->successMessage('Record deleted'))->reload()->execute();
}
}
}
function page_edit(){
if(!$this->allow_edit)exit;
$this->form=$f=$this->add('MVCForm','form');
$c=$this->c;

if($_GET['id']){
if($this->edit_actual_fields)
$c->setActualFields($this->edit_actual_fields);
}else{
if($this->add_actual_fields)
$c->setActualFields($this->add_actual_fields);
}

$f->setController($c);
if($this->read_only){
unset($f->elements['Save']);
$f->js(true)->find('input,select')->attr('disabled',true);
}

if($_GET['id'] && !$this->read_only){
if(!$f->hasElement('Save'))
$f->addSubmit('Save');
}else{
unset($f->elements['Save']);
}

if($_GET['id'])$c->loadData($_GET['id']);

if($f->isSubmitted() && !$this->read_only){
$f->update();
$f->js(null,$this->reloadJS())->univ()
->successMessage($_GET['id']?'Changes saved':'Record added')
->closeDialog()
->execute();
}
}
}
Something went wrong with that request. Please try again.