#
#		ITSV GmbH
#	CCDB - Command and Control Database
#
#	FILE:			dquerymfile_rwlist.txt
#	DESCRIPTION:	DQUERY definition for DQUERY rwlist
#					displays selected records from CCRW with EDIT fields
#
@querytitle				RW-Einträge anzeigen und bearbeiten
@querydescription		zeigt ausgewählte CCRW-Einträge mit der Möglichkeit der Bearbeitung and
@group					RWDATA
@querytype				dbselect
@attributenames			whereclause:string:{{whereclauseoptions}}
@whereclauseoptions {	labeltext:		"Auswahlkriterium",
						typedesc:		"WHERE-Klausel im SQL-Statement zur Abfrage aus der Tabelle CCRW (ohne vorangestelltes WHERE)",
						is_optional:	true }
@title					Regelwerks-Einträge
@pre_query
	aux.default_param(that.query,"whereclause","");
	that.query.sql = "select RWTYP,RWPARENT,RWNAME,RWVALUE,RWDESC, '' as \"SAVE\", '' as \"DELETE\", '' as \"ACTRESULT\" from CCRW"+
					(that.query.whereclause?" where "+that.query.whereclause:"")+
					" UNION "+
					" select '' as RWTYP, '' as RWPARENT, '' as RWNAME, '' as RWVALUE, '' as RWDESC, '' as \"SAVE\", '' as \"DELETE\", 'neuer Eintrag' as \"ACTRESULT\"";
	if (that.query.whereclause) that.query.title += " ("+that.query.whereclause+")"
@post_query
	proc: {
		let escaped_whereclause = that.query.whereclause.replace(/\"/g,'&#x22');
		that.result.toptext = 	"<ul>"+
								"  <li>Die Abfrage hat "+that.result.getRowCount()+" Einträge gefunden</li>\r\n"+
								"</ul>\r\n"+
								"<h3>Weitere Aktionen</h3>\r\n"+
								"<ul>"+
								" <li><table>"+
								"  <tr><form action=\"/dquery\" method=\"GET\">"+
									"<input type=\"hidden\" name=\"dataname\" value=\"updccrwrec\"></input>"+
									"<input type=\"hidden\" name=\"action\" value=\"deleterecs\"></input>"+
									"<td><label for_input=\"whereclause\">L&ouml;sch-Auswahl</label></td>"+
									"<td><input type=\"text\" name=\"whereclause\" size=\"132\" value=\""+escaped_whereclause+"\"></input></td>"+
									"<td><input type=\"submit\" name=\"submit\" value=\"Ausgew&auml;hlte Dateien l&ouml;schen\"></input></td>"+
									"</form></tr>"+
								"  <tr><form action=\"/dquery\" method=\"GET\">"+
								"    <input type=\"hidden\" name=\"dataname\" value=\"rwlist\"></input>"+
								"    <td><label for_input=\"whereclause\">Neue Bedingung</label></td>"+
								"    <td><input type=\"text\" name=\"whereclause\" size=\"132\" value=\""+escaped_whereclause+"\"></input></td>"+
								"    <td><input type=\"submit\" name=\"submit\" value=\"mit dieser Bedingung neu abfragen\"></input></td>"+
								"    </form></tr>"+
								" </table></li>\r\n";
		that.result.toptext +=  "</ul>\r\n";
	}

@decoration	{ /* no_DEBUG_EVAL */
	decorate_colcell:	{
		RWTYP:		{	cmds:	[	{	token:	"$TEXTINPUT"
									}
								]
					},
		RWPARENT:	{	cmds:	[	{	token:	"$TEXTINPUT"
									}
								]
					},
		RWNAME:		{	cmds:	[	{	token:	"$TEXTINPUT",
										name:	"RWNAME",
										options:	{	width:	32
													}
									}
								]
					},
		RWVALUE:	{	cmds:	[	{	token:	"$TEXTAREA",
										name:	"RWVALUE",
										options:	{	rows:	1,
														style:	"font-family: monospace;"
													}
									}
								]
					},
		RWDESC:		{	cmds:	[	{	token:	"$TEXTAREA",
										name:	"RWDESC",
										options:	{	rows:	1,
														cols:	15
													}
									}
								]
					},
		SAVE:		{	cmds:	[	{	token:	"$BUTTON",
										name:	"Speichern",
										options:	{	action:					"execrest",
														dataname:				"updccrwrec",
														parameters:				"action,RWTYP,RWPARENT,RWNAME,RWVALUE,RWDESC",
														action_parametername:	"action",
														action_value:			"update",
														RWTYP_parametername:	"RWTYP",
														RWTYP_fromcol:			0,
														RWPARENT_parametername:	"RWPARENT",
														RWPARENT_fromcol:		1,
														RWNAME_parametername:	"RWNAME",
														RWNAME_fromcol:			2,
														RWVALUE_parametername:	"RWVALUE",
														RWVALUE_fromcol:		3,
														RWDESC_parametername:	"RWDESC",
														RWDESC_fromcol:			4,
														resulttocol:			7
													}
									}
								]
					},
		DELETE:		{	cmds:	[	{	token:	"$BUTTON",
										name:	"Löschen",
										options:	{	action:					"execrest",
														dataname:				"updccrwrec",
														parameters:				"action,RWTYP,RWPARENT,RWNAME",
														action_parametername:	"action",
														action_value:			"delete",
														RWTYP_parametername:	"RWTYP",
														RWTYP_fromcol:			0,
														RWPARENT_parametername:	"RWPARENT",
														RWPARENT_fromcol:		1,
														RWNAME_parametername:	"RWNAME",
														RWNAME_fromcol:			2,
														resulttocol:			7
													}
									}
								]
					},
		ACTRESULT:	{	cmds:	[	{	token:	"$IDCELL"
									}
								]
					}
		}
	}