small changes in template winix function

git-svn-id: svn://ttmath.org/publicrep/winix/trunk@637 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2010-08-14 14:45:25 +00:00
parent f3cd3b88b9
commit 1e7d297c0e
14 changed files with 138 additions and 90 deletions

View File

@ -86,6 +86,7 @@ void Request::Clear()
item_tab.clear();
item.Clear();
dir_tab.clear();
last_item = 0;
is_item = false;
function = 0;
param_tab.clear();

View File

@ -107,9 +107,8 @@ struct Request
// send as attachment (causing header: content-disposition: attachment)
bool send_as_attachment;
// !! moze dolozyc pole Item * last_item
// i ono bedzie wskazywalo na albo item (jesli jest) albo na ostatni katalog
// ?
// this is a pointer either to the item (if exists) or to the last directory
Item * last_item;
Request();

View File

@ -128,17 +128,15 @@ Item * pdir;
void System::RedirectToLastDir()
{
// !! dac sprawdzenie czy istnieje
RedirectTo( *request->dir_tab.back() );
if( !request->dir_tab.empty() )
RedirectTo( *request->dir_tab.back() );
}
void System::RedirectToLastItem()
{
if( request->is_item )
RedirectTo(request->item);
else
RedirectTo( *request->dir_tab.back() );// !! dac sprawdzenie czy istnieje
if( request->last_item )
RedirectTo( *request->last_item );
}

View File

@ -58,6 +58,8 @@ void FunctionParser::ParseDirectories()
++get_index;
}
request->last_item = request->dir_tab.back();
}
@ -77,6 +79,8 @@ void FunctionParser::ParseItem()
if( request->status == WINIX_ERR_OK )
{
request->last_item = &request->item;
if( request->role == Request::authorizer && request->item.auth == Item::auth_none )
{
log << log1 << "FP: item.url: " << url << " exists but has not a static content (authorizer role)" << logend;

View File

@ -40,27 +40,64 @@ bool Template::HasAccess()
}
void Template::EditTemplate(Item & item)
void Template::PutLog(Item & item)
{
html_file = request->PostVar("template");
TrimWhite(html_file);
request->status = db->EditTemplateItemById(item.id, html_file);
log << log3 << "Template: changed template for item.id: " << item.id << ", new template: ";
if( request->status == WINIX_ERR_OK )
item.html_template = html_file;
if( item.html_template.empty() )
log << "(taking from mount point)";
else
log << item.html_template;
log << logend;
}
void Template::CreateTemplateFileName(const std::string & index_str)
{
int index = atoi(index_str.c_str());
if( index < 0 )
{
html_template.clear();
}
else
if( index == 0 )
{
html_template = config->templates_index;
}
else
{
index -= 1;
Mount::ParamRow & par = system->mounts.pmount->param[Mount::par_html_template];
if( !par.defined || (size_t)index >= par.arg.size() )
html_template.clear();
else
html_template = par.arg[index];
}
}
void Template::ChangeTemplate(Item & item)
{
if( html_template != item.html_template )
{
request->status = db->EditTemplateItemById(item.id, html_template);
if( request->status == WINIX_ERR_OK )
{
item.html_template = html_template;
PutLog(item);
}
}
}
void Template::MakePost()
{
if( request->is_item )
{
EditTemplate(request->item);
}
else
{
EditTemplate(*request->dir_tab.back());
}
CreateTemplateFileName(request->PostVar("template"));
ChangeTemplate(*request->last_item);
system->RedirectToLastItem();
}

View File

@ -28,8 +28,10 @@ public:
private:
std::string html_file;
void EditTemplate(Item & item);
std::string html_template;
void CreateTemplateFileName(const std::string & index_str);
void ChangeTemplate(Item & item);
void PutLog(Item & item);
};

View File

@ -1,10 +1,10 @@
[if-no winix_err_is "0"]
<p class="error">
[if-one winix_is_err_in_locales]
[winix_err_msg_from_locales]
[else]
{winix_err_default} [winix_err_code]
[end]
</p>
[end]
[if-no winix_err_is "0"]
<p class="error">
[if-one winix_is_err_in_locales]
[winix_err_msg_from_locales]
[else]
{winix_err_default} [winix_err_code]
[end]
</p>
[end]

View File

@ -1,2 +1,2 @@
[include "fun_priv.html"]
[include "fun_priv.html"]

View File

@ -1 +1 @@
[include "fun_priv.html"]
[include "fun_priv.html"]

View File

@ -1,61 +1,61 @@
<h1>{template_header}</h1>
[include "error.html"]
<p>
[if item_is]
{template_info_file}:
[if item_has_html_template]
[item_html_template]
[else]
{template_from_mount_point}
[if mount_has_html_template]
([mount_first_html_template])
[else]
([template_index])
[end]
[end]
[else]
{template_info_dir}:
[if dir_last_has_html_template]
[dir_last_html_template]
[else]
{template_from_mount_point}
[if mount_has_html_template]
([mount_first_html_template])
[else]
([template_index])
[end]
[end]
[end]
</p>
<h1>{template_header}</h1>
[include "error.html"]
<p>
[if item_is]
{template_info_file}:
[if item_has_html_template]
[item_html_template]
[else]
{template_from_mount_point}
[if mount_has_html_template]
([mount_first_html_template])
[else]
([template_index])
[end]
[end]
[else]
{template_info_dir}:
[if dir_last_has_html_template]
[dir_last_html_template]
[else]
{template_from_mount_point}
[if mount_has_html_template]
([mount_first_html_template])
[else]
([template_index])
[end]
[end]
[end]
</p>
<form id="additem" method="post" action="[doc_base_url][dir][if-one item_is][item_url]/[end]template">
<fieldset>
<legend>{template_form_legend}</legend>
{template_form_info}:
{template_form_info}:
<select name="template" class="template">
[# the first should be an empty string (value="") which means: a first template from the mount point]
<option value="">({template_form_from_mount_point})</option>
<select name="template" class="template">
[# the first should be an empty string (value="") which means: a first template from the mount point]
<option value="-1">({template_form_from_mount_point})</option>
[for template_tab]
<option[if-one template_tab_isdefault] selected[end]>[template_tab_file_name]</option>
<option value="[template_tab_index]"[if-one template_tab_isdefault] selected[end]>[template_tab_file_name]</option>
[end]
</select>

View File

@ -3,4 +3,4 @@
[include "error.html"]
<p>Winix [sys_ver_major].[sys_ver_minor].[sys_ver_revision]</p>
<p>Winix [sys_ver_major].[sys_ver_minor].[sys_ver_revision]</p>

View File

@ -93,6 +93,11 @@ void template_tab(Info & i)
}
void template_tab_index(Info & i)
{
i.out << temp_index;
}
void template_tab_isdefault(Info & i)
{

View File

@ -460,6 +460,7 @@ void Templates::CreateFunctions()
*/
ezc_functions.Insert("template_index", template_index);
ezc_functions.Insert("template_tab", template_tab);
ezc_functions.Insert("template_tab_index", template_tab_index);
ezc_functions.Insert("template_tab_isdefault", template_tab_isdefault);
ezc_functions.Insert("template_tab_file_name", template_tab_file_name);

View File

@ -418,6 +418,7 @@ namespace TemplatesFunctions
*/
void template_index(Info & i);
void template_tab(Info & i);
void template_tab_index(Info & i);
void template_tab_isdefault(Info & i);
void template_tab_file_name(Info & i);