Roxen.git / server / etc / modules / Variable.pmod / module.pmod

version» Context lines:

Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1263:    }   }            // =====================================================================   // MultipleChoice (one of many) baseclass   // =====================================================================      class MultipleChoice - //! Base class for multiple-choice (one of many) variables. + //! Base class for multiple-choice (one or many of many) variables.   {    inherit Variable;    protected array _list = ({});    protected mapping _table = ([]);    -  +  protected int(0..1) multiselect; +  +  //! Identifier to use to detect presence of +  //! support for multiselect mode. +  constant multiselect_supported = 1; +     string diff( int render )    { -  if(!render) +  if(!render) { +  if (multiselect) +  return "(" + map(default_value(), _title) * ", " + ")";    return "("+_title( default_value() )+")";    } -  +  }       void set_choice_list( array to )    //! Set the list of choices.    {    _list = to;    }       array get_choice_list( )    //! Get the list of choices. Used by this class as well.    //! You can overload this function if you want a dynamic list.
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1301:    _table = to;    }       mapping get_translation_table( )    //! Get the lookup table. Used by this class as well.    //! You can overload this function if you want a dynamic table.    {    return _table;    }    +  int(0..1) set_from_form(RequestID id, void|int(0..1) force) +  { +  if (!multiselect) return ::set_from_form(id); +  if (!id->real_variables[path()]) return 0; +  set_warning(0); +  mapping(string:string) m = get_form_vars(id); +  array(mixed) values = ({}); +  foreach(id->real_variables[path()] || ({}), string form_val) { +  mixed val = transform_from_form(form_val, m); +  array b = ({ 0, val }); +  mixed err = catch { b = verify_set_from_form(val); }; +  if (err) { +  add_warning(err); +  return 0; +  } else if (sizeof(b) != 2) { +  add_warning("Internal error: Illegal sized array " +  "from verify_set_from_form\n"); +  return 0; +  } +  if (b[0]) { +  add_warning(b[0]); +  } +  values += ({ b[1] }); +  } +  set(values); +  return 1; +  } +     protected string _name( mixed what )    //! Get the name used as value for an element gotten from the    //! get_choice_list() function.    {    return (string)what;    }       protected string _title( mixed what )    //! Get the title used as description (shown to the user) for an    //! element gotten from the get_choice_list() function.
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1322:    if( mapping tt = get_translation_table() )    return tt[ what ] || (string)what;    return (string)what;    }       string render_form( RequestID id, void|mapping additional_args )    {    string autosubmit = "";    if(additional_args && additional_args->autosubmit)    autosubmit = " autosubmit='autosubmit' onChange='javascript:submit();'"; -  string res = "<select name='"+path()+"'"+autosubmit+">\n"; +  if (multiselect) { +  array(string) current = map(query(), _name); +  string res = "<table>\n"; +  foreach( get_choice_list(), mixed elem ) +  { +  mapping m = ([ +  "type": "checkbox", +  "name": path(), +  "value": _name(elem), +  ]); +  if(has_value(current, m->value)) { +  m->checked="checked"; +  current -= ({ m->value }); +  } +  res += sprintf("<tr><td>%s</td><td>%s</td></tr>\n", +  Roxen.make_tag( "input", m), +  Roxen.html_encode_string(_title(elem))); +  } +  // Make an entry for the current values if they're not in the list, +  // to ensure that the value doesn't change as a side-effect by +  // another change. +  foreach(current, mixed elem ) +  { +  mapping m = ([ +  "type": "checkbox", +  "name": path(), +  "value": _name(elem), +  "checked": "checked", +  ]); +  string title = sprintf(LOCALE(332,"(keep stale value %s)"), current); +  res += sprintf("<tr><td>%s</td><td>%s</td></tr>\n", +  Roxen.make_tag( "input", m), +  Roxen.html_encode_string(title)); +  } +  return res + "</table>"; +  } else {    string current = _name (query());    int selected = 0; -  +  string res = "<select name='"+path()+"'"+autosubmit+">\n";    foreach( get_choice_list(), mixed elem )    {    mapping m = ([]);    m->value = _name( elem );    if( equal( m->value, current ) ) {    m->selected="selected";    selected = 1;    }    res += " "+Roxen.make_container( "option", m, _title( elem ) )+"\n";    }    if (!selected)    // Make an entry for the current value if it's not in the list,    // so no other value appears to be selected, and to ensure that    // the value doesn't change as a side-effect by another change.    res += " " + Roxen.make_container (    "option", (["value":current, "selected": "selected"]),    sprintf(LOCALE(332,"(keep stale value %s)"),current));    return res + "</select>";    } -  +  }       protected void create( mixed default_value, array|mapping choices,    void|int _flags, void|LocaleString std_name,    void|LocaleString std_doc )    //! Constructor.    //!    //! Choices is the list of possible choices, can be set with    //! set_choice_list at any time.    //!    //! Flags is a bitwise or of one or more of    //!    //! VAR_EXPERT Only for experts    //! VAR_MORE Only visible when more-mode is on (default on)    //! VAR_DEVELOPER Only visible when devel-mode is on (default on)    //! VAR_INITIAL Should be configured initially.    //!    //! The std_name and std_doc is the name and documentation string    //! for the default locale (always english)    {    ::create( default_value, _flags, std_name, std_doc ); -  +  multiselect = arrayp(default_value);    if( mappingp( choices ) ) {    set_translation_table( choices );    set_choice_list( sort(indices(choices)) );    } else    set_choice_list( choices );    }   }         // =====================================================================
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1564:    ::create( default_value, ({}), flags, std_name, std_doc );    }   }      //! Select a module in the current configuration.   class ModuleChoice   {    inherit StringChoice;    constant type = "ModuleChoice";    protected Configuration conf; -  protected string module_id; -  protected string default_id; +  protected string|array(string) module_id; +  protected string|array(string) default_id;    protected int automatic_dependency;       int low_set(RoxenModule to)    { -  RoxenModule old = changed_values[_id]; +  array(RoxenModule)|RoxenModule old = changed_values[_id];    if (!old) {    if (module_id) { -  +  if (multiselect) { +  old = map(module_id, transform_from_form); +  } else {    old = transform_from_form(module_id); -  +  }    } else {    old = default_value();    if (old) {    module_id = _name(old);    }    }    if (old) {    changed_values[_id] = old;    }    }    if (to == old) return 0;    changed_values[_id] = to;    if (module_id == _name(to)) return 0; // Reloaded module or similar.    module_id = _name(to);    if( get_changed_callback() )    get_changed_callback()( this_object() );    return 1;    }       // NOTE: Will be called with a string at module init! -  int set(string|RoxenModule to) +  int set(string|array(string)|RoxenModule|array(RoxenModule) to)    { -  if (stringp(to)) { +  if (multiselect && arrayp(to) && sizeof(to) && stringp(to[0])) {    module_id = to; -  +  array(RoxenModule) mods = map(to, transform_from_form); +  if (automatic_dependency) { +  foreach(mods; int i; RoxenModule mod) { +  if (!mod && conf->enabled_modules[to[i]]) { +  conf->add_modules(({to[i]}), 1); +  mod = transform_from_form(to[i]); +  } +  if (!mod && conf->enabled_modules[to[i]]) +  // The module exists but isn't started yet. Don't call set() +  // in this case since that will cause a bogus warning. +  return 0; +  mods[i] = mod; +  } +  } +  to = mods; +  } else if (stringp(to)) { +  module_id = to;    RoxenModule mod = transform_from_form (to);    if (!mod && automatic_dependency && conf->enabled_modules[to]) {    conf->add_modules (({to}), 1);    mod = transform_from_form (to);    }    if (!mod && conf->enabled_modules[to])    // The module exists but isn't started yet. Don't call set()    // in this case since that will cause a bogus warning.    return 0;    to = mod;    }    return ::set(to);    }    -  RoxenModule query() +  RoxenModule|array(RoxenModule) query()    { -  RoxenModule res = changed_values[_id]; -  if (!res) { +  array(RoxenModule)|RoxenModule res = changed_values[_id]; +  if (!res || (multiselect && has_value(res, 0))) {    if (module_id) {    // The module might have been reloaded.    // Try locating it again. -  +  if (multiselect) { +  res = map(module_id, transform_from_form); +  } else {    res = transform_from_form(module_id); -  if (res) low_set(res); +  }    } else {    res = default_value(); -  +  }    if (res) low_set(res);    } -  } +     return res;    }       //! Fetch the unsorted list of choices.    protected array low_get_choice_list()    {    return indices(conf->otomod);    }       array get_choice_list()
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1657:    return res;    }       protected string _name(RoxenModule val)    {    return val?val->module_local_id():"";    }       protected string _title(RoxenModule val)    { -  return val?val->module_name:""; +  return val?Roxen.get_modfullname(val):"";    }       RoxenModule transform_from_form(string module_id, mapping|void v)    {    return conf->find_module(module_id);    }    -  RoxenModule default_value() +  RoxenModule|array(RoxenModule) default_value()    {    if (default_id) { -  +  if (multiselect) return map(default_id, transform_from_form);    return transform_from_form(default_id);    }    array(RoxenModule) modules = get_choice_list();    if (sizeof(modules)) {    return modules[0];    }    return UNDEFINED;    }       array(string|mixed) verify_set( mixed new_value )
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1694:       //! @param default_id    //! The @[RoxenModule.module_local_id] of the default value.    //! @param conf    //! The current configuration.    //! @param no_automatic_dependency    //! Do not automatically depend on the chosen module. Normally, if    //! it already exists in the configuration then it will be loaded    //! before @expr{start@} in this module is called. Setting this    //! flag disables that. -  protected void create(string default_id, int flags, +  protected void create(string|array(string) default_id, int flags,    string std_name, string std_doc,    Configuration conf,    void|int no_automatic_dependency)    {    this_program::default_id = default_id;    this_program::conf = conf;    automatic_dependency = !no_automatic_dependency;    ::create(0, ({}), flags, std_name, std_doc); -  +  multiselect = arrayp(default_id);    }   }      //! Select a module that provides the specified interface.   class ProviderChoice   {    inherit ModuleChoice;    constant type = "ProviderChoice";    protected string provides;