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
141
142
143
144
|
define_type('autoctype',-optional='id',-required='table');
local(
'id' = integer,
'code' = string,
'result' = boolean,
'column_names' = array,
'inline_parameters' = array,
'table' = string,
'error' = string);
define_tag('onCreate');
self->table = #table;
local('ivars') = @self->properties->first;
inline(
-database = $tsdb,
-sql = 'select * from 'self->table' limit 1');
loop(field_name(-count));
select(field_name(loop_count,-type));
case('text');
#ivars->insert((field_name(loop_count)) = string);
case:('number');
#ivars->insert((field_name(loop_count)) = decimal);
case:('date/time');
#ivars->insert((field_name(loop_count)) = (field_name(loop_count,-type)));
case;
#ivars->insert((field_name(loop_count)) = string);
/select;
/loop;
/inline;
if(local_defined('id'));
self->id = #id;
else;
self->id = 0;
/if;
self->code = 'select * from <table> where id = <id>';
self->code->(replace:'<id>',self->id);
self->code->(replace:'<table>',self->table);
inline:
-database = $tsdb,
-sql = self->code;
self->column_names = field_names;
loop(field_name(-count));
var:'x' = (field_name(loop_count));
self->$x = field($x);
/loop;
if:found_count == 1;
self->result = true;
else;
self->result = false;
/if;
/inline;
/define_tag;
define_tag('save');
iterate(self->column_names,(var('nam')));
if($nam != 'id');
self->inline_parameters->(insert($nam = self->$nam));
/if;
/iterate;
if:self->id > 0;
inline(
-database=$tsdb,
-table=self->table,
-keyfield='id',
-keyvalue=self->id,
self->inline_parameters,
-update);
self->code=action_statement;
self->error = error_currenterror;
/inline;
else;
inline(
-database=$tsdb,
-table=self->table,
-keyfield='id',
-keyvalue=self->id,
self->inline_parameters,
-add);
self->id = keyfield_value;
self->code=action_statement;
self->error = error_currenterror;
/inline;
/if;
/define_tag;
define_tag('clone');
iterate(self->column_names,(var('nam')));
if($nam != 'id');
self->inline_parameters->(insert($nam = self->$nam));
/if;
/iterate;
if:self->id > 0;
self->error = 'No item active';
else;
inline(
-database=$tsdb,
-table=self->table,
-keyfield='id',
-keyvalue=self->id,
self->inline_parameters,
-add);
self->id = keyfield_value;
self->code=action_statement;
self->error = error_currenterror;
/inline;
/if;
/define_tag;
define_tag('delete');
inline(
-database=$tsdb,
-table=self->table,
-delete,
-keyfield='id',
-keyvalue=self->id);
self->id = 0;
self->code=action_statement;
self->error = error_currenterror;
/inline;
/define_tag;
define_tag('outputProperties');
// This outputs a table into the page that shows all the variables
local:'outputString' = '<table style="font-size:10px;margin:0px;">';
var:'z' = self->properties->get:1;
iterate($z,(var:'k'));
#outputString->(append('<tr>'));
#outputString->(append('<td style="padding: 0px 10px 1px 10px;">'));
#outputString->(append($k->first));
#outputString->(append('</td><td style="padding: 0px 10px 1px 10px;">'));
#outputString->(append($k->second));
#outputString->(append('</td><tr>'));
#outputString->(append('<tr>'));
/iterate;
#outputString->(append('</table>'));
return(@#outputString);
/define_tag;
/define_type;
|