summaryrefslogtreecommitdiff
path: root/demos/composer/protected/pages/Home.php
blob: 07f02e7e14e3acccab878305053ba3d8ef2712c7 (plain)
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
<?php

Prado::using('Application.pages.ClassDefinition');

class Home extends TPage
{
	private $_classDefinition=null;

	public function getClassDefinition()
	{
		if(!$this->_classDefinition)
			$this->_classDefinition=new ClassDefinition;
		return $this->_classDefinition;
	}

	public function onInit($param)
	{
		parent::onInit($param);
		if(!$this->IsPostBack)
		{
			$properties=$this->ClassDefinition->Properties;
			$properties[]=new PropertyDefinition;
			$properties[]=new PropertyDefinition;
			$properties[]=new PropertyDefinition;
			$this->PropertyList->DataSource=$properties;
			$this->dataBind();
		}
	}

	public function propertyAction($sender,$param)
	{
		if($param->CommandName==='add')
			$this->ClassDefinition->Properties->add(new PropertyDefinition);
		if($param->CommandName==='remove')
			$this->ClassDefinition->Properties->removeAt($param->CommandParameter);
		else if($param->CommandName==='up')
		{
			$property=$this->ClassDefinition->Properties->itemAt($param->CommandParameter);
			$this->ClassDefinition->Properties->removeAt($param->CommandParameter);
			$this->ClassDefinition->Properties->insertAt($param->CommandParameter-1,$property);
		}
		else if($param->CommandName==='down')
		{
			$property=$this->ClassDefinition->Properties->itemAt($param->CommandParameter);
			$this->ClassDefinition->Properties->removeAt($param->CommandParameter);
			$this->ClassDefinition->Properties->insertAt($param->CommandParameter+1,$property);
		}
		$this->PropertyList->DataSource=$this->ClassDefinition->Properties;
		$this->PropertyList->dataBind();
	}

	public function eventAction($sender,$param)
	{
		if($param->CommandName==='add')
			$this->ClassDefinition->Events->add(new EventDefinition);
		else if($param->CommandName==='remove')
			$this->ClassDefinition->Events->removeAt($param->CommandParameter);
		else if($param->CommandName==='up')
		{
			$property=$this->ClassDefinition->Events->itemAt($param->CommandParameter);
			$this->ClassDefinition->Events->removeAt($param->CommandParameter);
			$this->ClassDefinition->Events->insertAt($param->CommandParameter-1,$property);
		}
		else if($param->CommandName==='down')
		{
			$property=$this->ClassDefinition->Events->itemAt($param->CommandParameter);
			$this->ClassDefinition->Events->removeAt($param->CommandParameter);
			$this->ClassDefinition->Events->insertAt($param->CommandParameter+1,$property);
		}
		$this->EventList->DataSource=$this->ClassDefinition->Events;
		$this->EventList->dataBind();
	}

	public function onLoad($param)
	{
		parent::onLoad($param);
		//if($this->IsPostBack && $this->IsValid)
		if($this->IsPostBack)
		{
			$def=$this->ClassDefinition;
			$def->reset();
			$def->ClassName=$this->ClassName->Text;
			$def->ParentClass=$this->ParentClass->Text;
			$def->Interfaces=$this->Interfaces->Text;
			$def->Comments=$this->Comments->Text;
			$def->Author=$this->AuthorName->Text;
			$def->Email=$this->AuthorEmail->Text;
			foreach($this->PropertyList->Items as $item)
			{
				$property=new PropertyDefinition;
				$property->Name=$item->PropertyName->Text;
				$property->Type=$item->PropertyType->Text;
				$property->DefaultValue=$item->DefaultValue->Text;
				$property->ReadOnly=$item->ReadOnly->Checked;
				$property->IsProtected=$item->IsProtected->Checked;
				$property->Comments=$item->Comments->Text;
				$property->Storage=$item->Storage->Text;
				$def->Properties[]=$property;
			}
			foreach($this->EventList->Items as $item)
			{
				$event=new EventDefinition;
				$event->Name=$item->EventName->Text;
				$event->Comments=$item->Comments->Text;
				$def->Events[]=$event;
			}
		}
	}

	public function generateCode($sender,$param)
	{
		$writer=Prado::createComponent('TTextWriter');
		$this->ClassDefinition->render($writer);
		$this->SourceCode->Text=$writer->flush();
	}
}

?>