b655bf | 2004-06-30 | Martin Stjernholm | |
|
0e834c | 2000-02-24 | Martin Nilsson | |
|
84af18 | 1997-11-14 | Per Hedbor | |
|
b655bf | 2004-06-30 | Martin Stjernholm | | constant cvs_version = "$Id: wizard_tag.pike,v 1.33 2004/06/30 16:59:27 mast Exp $";
|
84af18 | 1997-11-14 | Per Hedbor | | constant thread_safe=1;
#include <module.h>
inherit "module";
inherit "wizard";
|
b3281f | 2000-09-10 | Martin Nilsson | | constant module_type = MODULE_TAG;
|
bc0fa0 | 2001-03-08 | Per Hedbor | | constant module_name = "Tags: Wizard generator";
|
69ab4c | 2000-04-06 | Mattias Wingstedt | | constant module_doc =
#"Provides the <tt><wizard></tt> tag that is used to create wizard
like user interface. Each wizard can contain several pages with form. The
user moves through each page in order and the module keeps track of all
the user's choices.";
|
84af18 | 1997-11-14 | Per Hedbor | |
|
cf33bb | 2000-02-04 | Marcus Wellhardh | | string internal_verify(string t, mapping args, string contents, int l, int ol,
mapping m)
{
|
e97f1e | 2000-02-08 | Marcus Wellhardh | | if(sizeof(args))
contents = make_container("if", args, contents);
m->verify += ({ ({ contents, ol + l, m->id }) });
return "<__wizard_error__ id=\"id_"+(m->id++)+"\">";
|
cf33bb | 2000-02-04 | Marcus Wellhardh | | }
|
f1be80 | 1998-02-22 | Per Hedbor | | string internal_page(string t, mapping args, string contents, int l, int ol,
|
e97f1e | 2000-02-08 | Marcus Wellhardh | | mapping f, RequestID id)
|
84af18 | 1997-11-14 | Per Hedbor | | {
|
cf33bb | 2000-02-04 | Marcus Wellhardh | | mapping m = ([ "verify":({ }) ]);
|
0e834c | 2000-02-24 | Martin Nilsson | |
|
cf33bb | 2000-02-04 | Marcus Wellhardh | | f->pages += ({ ({
parse_html_lines(contents, ([]), ([ "verify":internal_verify ]), l, m),
ol + l, m->verify }) });
|
84af18 | 1997-11-14 | Per Hedbor | | }
|
6d03cf | 1998-07-22 | Johan Schön | | string internal_done(string t, mapping args, string contents, int l, int ol,
|
e97f1e | 2000-02-08 | Marcus Wellhardh | | mapping f, RequestID id)
|
6d03cf | 1998-07-22 | Johan Schön | | {
f->done=contents;
}
|
f1be80 | 1998-02-22 | Per Hedbor | | string fix_relative(string file, object id)
{
if(file != "" && file[0] == '/') return file;
file = combine_path(dirname(id->not_query) + "/", file);
return file;
}
string old_pike = "";
object old_wizard = 0;
|
959a49 | 1998-07-03 | Marcus Comstedt | | string tag_wizard(string t, mapping args, string contents, object id,
object file, mapping defines)
|
84af18 | 1997-11-14 | Per Hedbor | | {
|
558cba | 1998-08-17 | Peter Bortas | | if(!id->misc->line)
id->misc->line=-1;
|
84af18 | 1997-11-14 | Per Hedbor | | mapping f = ([ "pages":({}) ]);
|
62fbb1 | 1998-07-19 | Henrik Grubbström (Grubba) | | string pike = ("inherit \"wizard\";\n" +
|
558cba | 1998-08-17 | Peter Bortas | | sprintf("# "+id->misc->line+" %O\n"
|
62fbb1 | 1998-07-19 | Henrik Grubbström (Grubba) | | "string name = %O;\n",
|
b796b5 | 1998-11-18 | Per Hedbor | | id->not_query, (args->name||"unnamed")));
|
21b2fc | 2000-03-20 | Martin Stjernholm | |
if (args->method || args->enctype) {
string method = "";
if (args->method)
method += " method=" + Roxen.html_encode_tag_value (args->method);
if (args->enctype)
method += " enctype=" + Roxen.html_encode_tag_value (args->enctype);
pike += sprintf ("constant wizard_method = %O;\n", method);
}
|
84af18 | 1997-11-14 | Per Hedbor | | int p;
|
41d0f9 | 1998-02-20 | Per Hedbor | | foreach(glob("*-label", indices(args)), string a)
{
|
558cba | 1998-08-17 | Peter Bortas | | pike += sprintf("# "+id->misc->line+" %O\n",
|
62fbb1 | 1998-07-19 | Henrik Grubbström (Grubba) | | id->not_query);
pike += sprintf(" string "+replace(replace(a,"-","_"),({"(",")","+",">"}),
|
0e834c | 2000-02-24 | Martin Nilsson | | ({"","","",""}))+
|
62fbb1 | 1998-07-19 | Henrik Grubbström (Grubba) | | " = %O;\n", args[a]);
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
f1be80 | 1998-02-22 | Per Hedbor | |
if(args->ok)
{
|
558cba | 1998-08-17 | Peter Bortas | | pike += sprintf("# "+id->misc->line+" %O\n", id->not_query);
|
62fbb1 | 1998-07-19 | Henrik Grubbström (Grubba) | | pike += sprintf("mixed wizard_done(object id)\n"
"{\n"
" id->not_query = %O;\n\""+
|
b796b5 | 1998-11-18 | Per Hedbor | | " return id->conf->get_file( id );\n"
|
62fbb1 | 1998-07-19 | Henrik Grubbström (Grubba) | | "}\n\n",
fix_relative(args->ok, id));
|
f1be80 | 1998-02-22 | Per Hedbor | | }
|
6d03cf | 1998-07-22 | Johan Schön | |
parse_html_lines(contents,
([]),
([ "page":internal_page,
|
0e834c | 2000-02-24 | Martin Nilsson | | "done":internal_done ]),
|
e97f1e | 2000-02-08 | Marcus Wellhardh | | (int)id->misc->line, f, id);
|
048740 | 1998-08-05 | Henrik Grubbström (Grubba) | | if (f->done && !args->ok) {
|
cb9dc4 | 1998-08-19 | Henrik Grubbström (Grubba) | | pike += sprintf("mixed wizard_done(object id)\n"
"{\n"
|
03873f | 1998-11-02 | Per Hedbor | | " return parse_rxml(%O,id);\n"
|
cb9dc4 | 1998-08-19 | Henrik Grubbström (Grubba) | | "}\n", f->done);
|
048740 | 1998-08-05 | Henrik Grubbström (Grubba) | | }
|
f1be80 | 1998-02-22 | Per Hedbor | | foreach(f->pages, array q)
|
84af18 | 1997-11-14 | Per Hedbor | | {
|
62fbb1 | 1998-07-19 | Henrik Grubbström (Grubba) | | pike += sprintf("# "+q[1]+" %O\n", id->not_query);
pike += sprintf("string page_"+p+"(object id) {" +
|
03873f | 1998-11-02 | Per Hedbor | | " return parse_rxml(%O,id);\n"
|
62fbb1 | 1998-07-19 | Henrik Grubbström (Grubba) | | "}\n", q[0]);
|
e97f1e | 2000-02-08 | Marcus Wellhardh | |
|
cf33bb | 2000-02-04 | Marcus Wellhardh | | if(q[2] && sizeof(q[2])) {
|
e97f1e | 2000-02-08 | Marcus Wellhardh | |
pike += "int verify_"+p+"(object id) {\n"
" int c;\n"
" string s = \"\";\n"
" id->misc->__wizard_error__ = ([ ]);\n";
|
0e834c | 2000-02-24 | Martin Nilsson | | foreach(q[2], array v)
|
e97f1e | 2000-02-08 | Marcus Wellhardh | | pike += sprintf(" s = parse_rxml(%O, id);\n"
" if(id->misc->defines[\" _ok\"]) {\n"
" id->misc->__wizard_error__->id_%d = s;\n"
" c++;\n"
" }\n", v[0], v[2]);
|
0e834c | 2000-02-24 | Martin Nilsson | |
|
e97f1e | 2000-02-08 | Marcus Wellhardh | | pike += " if(c)\n"
" return 1;\n"
"}\n";
|
cf33bb | 2000-02-04 | Marcus Wellhardh | | }
|
0e834c | 2000-02-24 | Martin Nilsson | |
|
84af18 | 1997-11-14 | Per Hedbor | | p++;
}
|
e97f1e | 2000-02-08 | Marcus Wellhardh | |
|
f1be80 | 1998-02-22 | Per Hedbor | | object w;
if(pike == old_pike)
w = old_wizard;
else
{
old_wizard = w = compile_string(pike)();
old_pike = pike;
}
|
6d03cf | 1998-07-22 | Johan Schön | | mixed res = w->wizard_for(id,fix_relative(args->cancel||args->done||"",id));
|
f1be80 | 1998-02-22 | Per Hedbor | |
|
84af18 | 1997-11-14 | Per Hedbor | | if(mappingp(res))
{
|
b7bf69 | 2001-11-23 | Martin Stjernholm | | RXML_CONTEXT->set_misc (" _error", res->error);
|
3e77c7 | 2002-01-30 | Martin Stjernholm | | RXML_CONTEXT->extend_scope ("header", res->extra_heads);
|
f1be80 | 1998-02-22 | Per Hedbor | | return res->data||(res->file&&res->file->read())||"";
|
84af18 | 1997-11-14 | Per Hedbor | | }
return res;
}
|
cf33bb | 2000-02-04 | Marcus Wellhardh | | string tag_wizard_error(string t, mapping args, object id,
object file, mapping defines)
{
|
e97f1e | 2000-02-08 | Marcus Wellhardh | | if(id->misc->__wizard_error__ && args->id &&
id->misc->__wizard_error__[args->id])
return id->misc->__wizard_error__[args->id];
|
cf33bb | 2000-02-04 | Marcus Wellhardh | | return "";
}
|
84af18 | 1997-11-14 | Per Hedbor | |
|
cf33bb | 2000-02-04 | Marcus Wellhardh | | mapping query_tag_callers()
{
return ([ "__wizard_error__" : tag_wizard_error ]);
}
|
cd3402 | 1999-05-19 | David Hedbor | |
|
84af18 | 1997-11-14 | Per Hedbor | | mapping query_container_callers()
{
return ([ "wizard" : tag_wizard ]);
}
|