M classes/application.pike +20 -5
@@ 2,6 2,7 @@ import Tools.Logging;
inherit Fins.Application;
+mapping preferences = ([]);
mapping plugins = ([]);
mapping event_handlers = ([]);
mapping destination_handlers = ([]);
@@ 127,7 128,7 @@ void start_plugins()
{
foreach(plugin->query_preferences(); string p; mapping pv)
{
- new_pref("plugin." + plugin->name + "." + p, pv->value, pv->type);
+ new_pref("plugin." + plugin->name + "." + p, pv);
}
}
@@ 220,6 221,19 @@ object get_current_user(object id)
return id->misc->session_variables->user;
}
+
+mapping get_preference_definition(object pref)
+{
+ werror("basename: %O\n", pref["basename"]);
+ mapping pd = preferences[pref["basename"]] + ([]);
+ werror("pd: %O\n", pd);;
+ if(functionp(pd["options"]))
+ pd["options"] = pd["options"]();
+
+ return pd;
+}
+
+
object get_sys_pref(string pref)
{
object p;
@@ 245,18 259,19 @@ object new_string_pref(string pref, stri
}
}
-object new_pref(string pref, string value, int type)
+object new_pref(string pref, mapping data)
{
- object p;
+ object p;
+ if(!preferences[pref]) preferences[pref] = ((["name":pref, "friendly_name": pref]) | data );
(p = get_sys_pref(pref));
if(p) return p;
else
{ Log.info("Creating new preference object '" + pref + "'.");
p = ds->new("Preference");
p["name"] = pref;
- p["type"] = type;
+ p["type"] = data->type;
p["description"] = "";
- p["value"] = value;
+ p["value"] = data->value;
p->save();
return p;
}
M modules/SpeedyDelivery.pmod/DataMappings.pmod/Preference.pike +35 -1
@@ 2,10 2,44 @@ import Fins.Model;
inherit Fins.Model.DataObject;
-void post_define(object context)
+protected void post_define(object context)
{
add_field(context, TransformField("shortname", "name", lambda(mixed n, object i){return (n/".")[-1];}));
add_field(context, TransformField("booleanvalue", "value", lambda(mixed n, object i){return (((int)n)?"true":"false");}));
+ add_field(context, TransformField("yesnovalue", "value", lambda(mixed n, object i){return (((int)n)?"Yes":"No");}));
+ add_field(context, TransformField("typedvalue", "value", typedvalue));
+ add_field(context, TransformField("def", "name", getprefdef));
+ add_field(context, TransformField("basename", "name", getbasename));
set_alternate_key("name");
}
+ mixed getbasename(mixed n, object i)
+ {
+/* if(i["user_pref"])
+ {
+ int l = search(n, ".");
+ if(l==-1)
+ return 0; // ERROR!
+ return "user." + n[l+1..];
+
+ }
+ else
+*/
+ {
+ return i["name"];
+ }
+ }
+
+
+ mixed getprefdef(mixed n, object i)
+ {
+ return(i->context->app->get_preference_definition(i));
+ }
+
+ mixed typedvalue(mixed n, object i)
+ {
+ if(i["type"] == Fins.BOOLEAN)
+ return (int)n;
+ else return n;
+ }
+
M modules/SpeedyDelivery.pmod/Plugin.pike +1 -1
@@ 54,7 54,7 @@ int enabled()
{
mixed m;
- m = app->new_pref("plugin." + name + ".enabled", _enabled, SpeedyDelivery.BOOLEAN);
+ m = app->new_pref("plugin." + name + ".enabled", (["value": _enabled, "type": Fins.BOOLEAN]));
return m->get_value();
}