cryptonas-branches/pythonrewrite/templates/macros.cs

145 lines
5.9 KiB
C#

<?cs # $Id$ ?><?cs
def:link(path, attr1, value1, attr2, value2)
?><?cs each:attrs = Temp
?><?cs set:attrs = ""
?><?cs /each
?><?cs each:attrs = Settings.LinkAttrs
?><?cs set:Temp[url_escape(name(attrs))] = url_escape(attrs)
?><?cs /each
?><?cs if:attr1 != "" ?><?cs set:Temp[attr1] = value1 ?><?cs /if
?><?cs if:attr2 != "" ?><?cs set:Temp[attr2] = value2 ?><?cs /if
?><?cs var:ScriptName
?>/<?cs var:path
?><?cs set:first_each = 1
?><?cs if:subcount(Temp) > 0
?><?cs each:attrs = Temp
?><?cs if:(name(attrs) != "") && (attrs != "")
?><?cs if:first_each == 1 ?><?cs
set:first_each = 0 ?>?<?cs
else
?>&amp;<?cs /if
?><?cs var:url_escape(name(attrs)) ?>=<?cs var:url_escape(attrs)
?><?cs /if
?><?cs /each
?><?cs /if ?><?cs
/def ?><?cs
# the following macro is as ugly as possible - but somehow we have to manage
to use 'normal' and 'plugin' messages in a clean way:
Lang.WarningMessage.??? - used by core functions
Lang.Plugins.PLUGINNAME.WarningMessage.??? - used by plugins ?><?cs
def:message_dispatch(mname, type, category)
?><?cs # split the message name into a (potentially existing) plugin-name prefix and the suffix (the python equivalent of the following three lines would be:
plugPrefix, PlugSuffix = mname[0:mname.find(".",8), mname[mname.find(".",8)+1:]
?><?cs loop:x = #8, #40, #1 ?><?cs if:(string.slice(mname,x,x+1) == ".") && !(?savedX) ?><?cs set:savedX = x ?><?cs /if ?><?cs /loop
?><?cs set:plugPrefix = string.slice(mname,0,savedX)
?><?cs set:plugSuffix = string.slice(mname,savedX+1,string.length(mname))
?><?cs # choose the appropriate symbol file
?><?cs if:type == "success" ?><?cs set:symbolFile = "dialog-information_tango.png"
?><?cs elif:type == "warning" ?><?cs set:symbolFile = "dialog-error_tango.png"
?><?cs /if
?><?cs # preparations are done - now start writing
?><div class="message"><table><tr><td><img class="message_symbol" src="<?cs
call:link('cryptobox-misc/' + symbolFile,'','','','')
?>" alt="icon: info" /></td><td><?cs
# check if it is a 'normal' message ?><?cs
if:?Lang[category][mname].Title ?>
<h1><?cs var:html_escape(Lang[category][mname].Title) ?></h1>
<p><?cs var:html_escape(Lang[category][mname].Text) ?></p>
<?cs # check if the mname starts with "Plugins." ... ?><?cs
elif:(string.slice(mname,0,8) == "Plugins.") && ?Lang[plugPrefix][category][plugSuffix].Title ?>
<h1><?cs var:html_escape(Lang[plugPrefix][category][plugSuffix].Title) ?></h1>
<p><?cs var:html_escape(Lang[plugPrefix][category][plugSuffix].Text) ?></p>
<?cs # the message does not seem to exist ... ?><?cs
else ?>
<h1>unknown <?cs var:type ?> message</h1>
<p>could not find <?cs var:type ?> message: '<?cs var:mname ?>'</p>
<?cs /if ?></td></tr></table></div><?cs
/def ?><?cs
def:warning(mname)
?><?cs call:message_dispatch(mname, "warning", "WarningMessage") ?><?cs
/def ?><?cs
def:error(mname)
?><?cs call:message_dispatch(mname, "error", "ErrorMessage") ?><?cs
/def ?><?cs
def:success(mname)
?><?cs call:message_dispatch(mname, "success", "SuccessMessage") ?><?cs
/def ?><?cs
def:print_form_header(form_name, action) ?><?cs #
# the header of a form - including Setting.LinkAttrs
?><form name="<?cs var:html_escape(form_name) ?>" action="<?cs call:link(action,"","","","") ?>" method="post" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"><?cs
/def ?><?cs
def:show_plugin(plugin, type) ?><?cs
# show the icon and the name of a plugin of a give type (system/volume/menu) ?>
<div class="plugin_<?cs var:html_escape(type) ?> plugin_<?cs var:html_escape(type) ?>_<?cs if:Data.ActivePlugin == plugin ?>active<?cs else ?>passive<?cs /if ?>">
<a href="<?cs call:link('plugins/' + plugin,'','','','') ?>" title="<?cs var:html_escape(Settings.PluginList[plugin].Link) ?>">
<img src="<?cs call:link('icons/plugins/' + plugin, '','','','') ?>" alt="<?cs var:html_escape('icon: ' + plugin) ?>" /><br/><?cs
var:html_escape(Settings.PluginList[plugin].Link) ?></a></div><?cs
/def ?><?cs
def:show_volume(index) ?><?cs
# show the icon of the volume ?>
<?cs if:Data.Disks[index].active ?><?cs
if:Data.Disks[index].encryption ?><?cs
set:filename='volume_active_crypto.png' ?><?cs
else ?><?cs
set:filename='volume_active_plain.png' ?><?cs
/if ?><?cs
else ?><?cs
if:Data.Disks[index].encryption ?><?cs
set:filename='volume_passive_crypto.png' ?><?cs
else ?><?cs
set:filename='volume_passive_plain.png' ?><?cs
/if ?><?cs
/if ?>
<div class="volume">
<a href="<?cs call:link('plugins/volume_mount','device',Data.Disks[index].device,'','') ?>" title="<?cs var:html_escape(Data.Disks[index].name) ?>">
<img src="<?cs call:link('cryptobox-misc/' + filename,'','','','') ?>" alt="icon: volume" /><br/><?cs
var:html_escape(Data.Disks[index].name) ?> (<?cs
var:html_escape(Data.Disks[index].size) ?>)</a></div><?cs
/def ?><?cs
def:help_link(pagename) ?><?cs
# show an iconed link to a specific help page for the current form ?>
<div class="help_link">
<a href="<?cs call:link('plugins/help','page',pagename,'','') ?>" title="<?cs var:html_escape(Lang.Button.HelpForForm) ?>">
<?cs var:html_escape(Lang.Button.HelpForForm) ?>
<img class="message_symbol" src="/icons/plugins/help" alt="icon: help" />
</a></div><?cs
/def ?><?cs
def:hint(text) ?><?cs
# show a warning hint ?>
<div class="message">
<table><tr><td><img class="message_symbol" src="/cryptobox-misc/dialog-warning_tango.png" alt="icon: warning" /></td>
<td><?cs var:html_escape(text) ?></td></tr></table></div><?cs
/def ?><?cs
def:handle_messages() ?><?cs
# call this function once for every page - otherwise your risk to loose messages
?><?cs if:messages_are_handled ?>HANDLE_MESSAGE CALLED TWICE - PLEASE FIX THIS<?cs /if
?><?cs if:Data.Error ?><?cs include:Settings.TemplateDir + '/error.cs' ?><?cs /if
?><?cs if:Data.Warning ?><?cs call:warning(Data.Warning) ?><?cs /if
?><?cs if:Data.Success ?><?cs call:success(Data.Success) ?><?cs /if
?><?cs set:messages_are_handled = 1 ?><?cs
/def ?>