#!/bin/sh

#turn off auto expansion
set -f

_()
{
LANG=${in_language%%;*}.utf8 gettext "alterator-nut" "$1"
}


. /usr/share/alterator/build/backend3.sh

on_message()
{
	case "$in_action" in
		#information for renderer
		template)
			echo '('
			if [ "$in__objects" = "/" ] ;then
				echo ' template "form"'
				echo ' translate "alterator-nut"'
				echo ' url "nut-device-list.html"'
				[ "$in_orig_action" = "new" -a -n "$in_name" ] &&
				    printf 'redirect "/nut-devices/%s/drivers"' "$in_name"
			elif echo "$in__objects"|egrep -qs "^[a-z0-9]+$" ;then
				echo ' template "form"'
				echo ' translate "alterator-nut"'
				echo ' url "nut-device-object.html"'
				echo ' redirect "/nut-devices"'
			elif echo "$in__objects"|grep -qs "/drivers$";then
				echo ' template "card-index"'
				echo ' translate "alterator-nut"'
				echo ' url "nut-drivers.html"'
				printf ' redirect "/nut-devices/%s"' "$(dirname "$in__objects")"
			fi
			echo ')'
			;;
		*)
			echo '#f'
			;;
	esac
}

message_loop
