Make changes to details.js. See commit message.

- Add/Remove links are now only available for multivalue
  attributes (Param.multivalue = true) and attributes with param
  types, that are multivalue by definition (as of now only List).
  Single-value attributes with no value are displayed as empty
  input elements.
- When updating an attribute, leading and trailing spaces are
  stripped
- Context help available in the form of hints, that are extracted
  form Param.hint.
This commit is contained in:
Pavel Zuna 2010-08-25 12:49:30 -04:00 committed by Adam Young
parent 2742001ed0
commit ead85f2866
2 changed files with 155 additions and 112 deletions

View File

@ -93,16 +93,17 @@ function ipa_details_update(pkey, on_win, on_fail)
var attr = dt.attr('title');
if (!attr || attr.indexOf('call_') == 0)
return;
var value = jQuery.trim(jobj.val());
var param_info = ipa_get_param_info(attr);
if (param_info) {
modlist[attr] = jobj.val();
modlist[attr] = value;
return;
}
if (!attrs_wo_option[attr])
attrs_wo_option[attr] = [];
attrs_wo_option[attr].push(jobj.val());
attrs_wo_option[attr].push(value);
});
$('.entryattrs dt').each(function () {
@ -209,6 +210,7 @@ function ipa_generate_dl(jobj, id, name, dts)
/* HTML templates for ipa_details_display() */
var _ipa_a_add_template =
'<a href="jslink" onclick="return (_ipa_add_on_click(this))" title="A">Add</a>';
var _ipa_span_doc_template = '<span class="attrhint">Hint: D</span>';
/* populate definition lists with the class 'entryattrs' with entry attributes
*
@ -244,15 +246,42 @@ function ipa_details_display(entry_attrs)
jobj.after(_ipa_dd_first_template.replace('I', '-'));
} else {
/* title contains attribute name - default behaviour */
var multivalue = false;
var hint_span = '';
var param_info = ipa_get_param_info(attr);
if (param_info) {
if (param_info['multivalue'] || param_info['class'] == 'List')
multivalue = true;
var hint = param_info['hint'];
if (hint)
hint_span = _ipa_span_hint_template.replace('D', hint);
}
var value = entry_attrs[attr];
if (value) {
ipa_insert_first_dd(jobj, ipa_create_input(attr, value[0]));
ipa_insert_first_dd(
jobj, ipa_create_input(attr, value[0]) + hint_span
);
for (var i = 1; i < value.length; ++i) {
jobj = jobj.next();
ipa_insert_other_dd(jobj, ipa_create_input(attr, value[i]));
}
if (multivalue) {
ipa_insert_other_dd(
jobj.next(), _ipa_a_add_template.replace('A', attr)
);
}
} else {
ipa_insert_first_dd(jobj, _ipa_a_add_template.replace('A', attr));
if (multivalue) {
ipa_insert_first_dd(
jobj, _ipa_a_add_template.replace('A', attr) + hint_span
);
} else {
ipa_insert_first_dd(
jobj, ipa_create_input(attr, '') + hint_span
);
}
}
}
});
@ -278,6 +307,7 @@ var _ipa_param_type_2_handler_map = {
'Str': _ipa_create_text_input,
'Int': _ipa_create_text_input,
'Bool': _ipa_create_text_input,
'List': _ipa_create_text_input,
};
/* create an HTML element for displaying/editing an attribute
@ -289,10 +319,7 @@ function ipa_create_input(attr, value)
var param_info = ipa_get_param_info(attr);
if (!param_info) {
/* no information about the param is available, default to text input */
return (
_ipa_create_text_input(attr, value, null) +
_ipa_create_remove_link(attr, null)
);
return (_ipa_create_text_input(attr, value, null));
}
/* check if the param value can be modified */
@ -302,11 +329,14 @@ function ipa_create_input(attr, value)
/* call handler by param class */
var handler = _ipa_param_type_2_handler_map[param_info['class']];
if (handler) {
if (param_info['multivalue'] || param_info['class'] == 'List') {
return (
handler(attr, value, param_info) +
_ipa_create_remove_link(attr, param_info)
);
}
return (handler(attr, value, param_info));
}
/* no handler for this type? don't allow modification */
return (value.toString());
@ -355,10 +385,14 @@ function ipa_details_reset()
function _ipa_add_on_click(obj)
{
var jobj = $(obj);
var attr = jobj.attr('title');
var par = jobj.parent();
par.append(ipa_create_input(jobj.attr('title'), ''));
par.prepend(ipa_create_input(attr, ''));
ipa_insert_other_dd(par, _ipa_a_add_template.replace('A', attr));
jobj.next('input').focus();
jobj.remove();
return (false);
}
@ -371,6 +405,8 @@ function _ipa_remove_on_click(obj)
var next = par.next('dd');
if (next.length) {
if (par.hasClass('first')) {
var hint = par.children('span').detach();
next.append(hint);
next.addClass('first');
next.removeClass('other');
}

View File

@ -182,6 +182,13 @@ div#backtotop {
text-align: right;
}
span.attrhint {
font-size: 8pt;
left: 40em;
margin-left: 100px;
position: absolute;
}
/*Navigation */