|
WFTK_EXPORT XML * repos_action_list (XML * repository, const char * list, const char * key, const char * mode)
{
return (repos_action_list_direct (repository, repos_defn (repository, list), key, mode));
}
WFTK_EXPORT XML * repos_action_list_direct (XML * repository, XML * list, const char * key, const char * mode)
{
XML * object = repos_get (repository, xml_attrval (list, "id"), key);
XML * ret = repos_action_list_object_direct (repository, list, object, mode);
if (object) xml_free (object);
return ret;
}
WFTK_EXPORT XML * repos_action_list_object (XML * repository, const char * list, XML * object, const char * mode)
{
return (repos_action_list_object_direct (repository, repos_defn (repository, list), object, mode));
}
WFTK_EXPORT XML * repos_action_list_object_direct (XML * repository, XML * list, XML * object, const char * mode)
{
XML * actions = xml_create ("list");
XML * action;
XML * states;
XML * mark;
if (!list) return (actions);
if (!object || !strcmp (mode, "new")) {
action = xml_create ("action");
xml_set (action, "id", "add");
xml_setf (action, "label", "Add new %s", xml_attrval (list, "id")); /* TODO: label should be configurable. */
xml_append (actions, action);
} else {
/* Standard actions against object. */
action = xml_create ("action");
xml_set (action, "id", "mod");
xml_set (action, "label", "Update");
xml_append (actions, action); /* TODO: check actual permissions, view, etc. */
action = xml_create ("action");
xml_set (action, "id", "del");
xml_set (action, "label", "Delete");
xml_append (actions, action);
/* State transitions also count as actions, of course. We modify the name a little to avoid collisions (with a "state-" prefix). */
states = repos_list_choices (repository, xml_attrval (list, "id"), object, "_state");
for (mark = xml_firstelem (states); mark; mark = xml_nextelem (mark)) {
if (!*xml_attrval (mark, "selected")) {
action = xml_create ("action");
xml_set (action, "id", "state-");
xml_attrcat (action, "id", xml_attrval (mark, "value"));
xml_set_nodup (action, "label", xml_stringcontenthtml (mark));
xml_append (actions, action);
}
}
if (states) xml_free (states);
/* Completion of active, passive, and potential tasks are also all actions. TODO: deal with these. */
/* If the object itself is a task, completion might be added here if list_choices didn't already list it. TODO: figure that out. */
}
/* TODO: pass the whole list in for rule processing to determine permissibility. God knows what that will take. */
return (actions);
}
|