/
row_edit.coretag
174 lines (156 loc) · 4.05 KB
/
row_edit.coretag
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Copyright 2002-2007 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
UserTag row-edit Order key table size columns
UserTag row-edit HasEndTag
UserTag row-edit addAttr
UserTag row-edit Interpolate 1
UserTag row-edit Version 1.12
UserTag row-edit Routine <<EOR
sub {
my ($key,$table,$size,$columns,$opt) = @_;
use vars qw/$CGI $Values $Variable/;
#::logDebug("row_edit options=" . ::uneval($opt));
$table = $table || $CGI::values{mv_data_table} || return "BLANK DB";
my $db = ::database_exists_ref($table);
my $mtab = $::Variable->{UI_META_TABLE} || 'mv_metadata';
my $mdb = ::database_exists_ref($mtab);
$opt->{view} ||= $CGI->{ui_meta_view};
my $view = Vend::Table::Editor::meta_record($table, $opt->{view}) || {};
my $tm_extra = '';
my $ta_extra = '';
my $tf_extra = '';
if($opt->{extra}) {
$tf_extra = " $opt->{extra}";
}
if($opt->{meta_extra}) {
$tm_extra .= " $opt->{meta_extra}";
}
if($opt->{textarea_extra}) {
$tm_extra .= " $opt->{textarea_extra}";
}
$ta_extra ||= $tf_extra;
$tm_extra ||= $tf_extra;
my $prependor = '';
if($opt->{pointer}) {
$prependor = $opt->{pointer};
$prependor =~ s/\D+//;
$prependor = $prependor ? $prependor . '_' : '';
#::logDebug("setting prependor to $prependor");
}
my $appendor = '';
if($opt->{stacker}) {
$appendor = "__$opt->{stacker}";
#::logDebug("setting appendor to $appendor");
}
return errmsg("non-existent table '%s' for row-edit", $table)
unless $db;
$db = $db->ref();
my $acl = UI::Primitive::get_ui_table_acl();
my $record;
my $bad;
if ($key) {
eval {
$bad = ! $db->record_exists($key);
$bad = errmsg('DELETED') if $bad;
};
$bad = errmsg('ERROR') if $@;
if($bad) {
# Do nothing, we are already bad
}
elsif($acl) {
$bad = errmsg('Not available')
if ! UI::Primitive::ui_acl_atom($acl, 'keys', $key);
}
else {
$record = $db->row_hash($key);
}
}
$record ||= {};
my @cols;
if($columns ||= $view->{spread_cols} || $view->{attribute}) {
@cols = split /[\s,\0]+/, $columns;
my %col;
for($db->columns()) {
$col{$_} = 1;
}
@cols = grep defined $col{$_}, @cols;
}
else {
@cols = $db->columns();
}
if($acl) {
@cols = UI::Primitive::ui_acl_grep( $acl, 'fields', @cols);
}
# See if we have a textarea reference
my %ta;
if($opt->{textarea}) {
my @tmp = split /[\s,\0]+/, $opt->{textarea};
for(@tmp) {
$ta{$_} = 1;
}
}
my $out = '';
my $meta = $CGI->{ui_no_meta_display} ? '' : $view->{spread_meta};
my %do_ta;
my %do_meta;
if($meta) {
my @metas = grep /\S/, split /[\0,\s]+/, $meta;
@do_meta{@metas} = @metas;
}
if($view->{spread_textarea}) {
my @tas = grep /\S/, split /[\0,\s]+/, $view->{spread_textarea};
@do_ta{@tas} = @tas;
}
my $tmp;
$size = $size || $view->{spread_width} || $view->{width} || 12;
if($bad) {
for(@cols) {
$out .= "<TD$tf_extra>$bad</TD>";
}
}
elsif($key or $opt->{blank}) {
for(@cols) {
my $text = $opt->{blank} ? '' : $record->{$_} || '';
my $msg = '';
if($do_meta{$_}) {
my $tmp = Vend::Tags->display( {
table => $table,
column => $_,
name => "$prependor$_$appendor",
value => $text,
template => ' $WIDGET$ ',
specific => $opt->{ui_meta_specific},
key => $key,
});
$out .= "<TD$tm_extra>$tmp</TD>";
next;
}
elsif($do_ta{$_}) {
my $rows = $opt->{height} || 4;
HTML::Entities::encode($text, $ESCAPE_CHARS::std);
$out .= <<EOF;
<TD$ta_extra><TEXTAREA NAME="$prependor$_$appendor" COLS="$size" ROWS="$rows">$text</TEXTAREA>$msg</TD>
EOF
}
else {
$text =~ s/"/"/g;
$out .= <<EOF;
<TD$tf_extra><INPUT NAME="$prependor$_$appendor" SIZE=$size VALUE="$text">$msg</TD>
EOF
}
}
}
else {
for(@cols) {
$out .= <<EOF;
<TH ALIGN=left>$_</TH>
EOF
}
}
return $out;
}
EOR