From df5fa8b71b08d72ccc45ee08db1fd42a4c6d7ab6 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Wed, 29 Sep 2010 16:57:07 -0400 Subject: Item Level Undo Also adding some unit tests for details. Using JQuery UI buttons for update and reset Now triggers on keydown, not change --- install/static/details.js | 146 +++++++++++++++++----------- install/static/test/all_tests.html | 1 + install/static/test/data/json_metadata.json | 2 +- install/static/test/details_tests.html | 22 +++++ install/static/test/details_tests.js | 92 ++++++++++++++++++ install/static/test/index.html | 1 + 6 files changed, 208 insertions(+), 56 deletions(-) create mode 100644 install/static/test/details_tests.html create mode 100644 install/static/test/details_tests.js diff --git a/install/static/details.js b/install/static/details.js index 4e37ed69..f16dc364 100644 --- a/install/static/details.js +++ b/install/static/details.js @@ -1,5 +1,6 @@ /* Authors: * Pavel Zuna + * Adam Young * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information @@ -43,8 +44,8 @@ function ipa_details_create(obj_name, dls, container) details.append('
'); var jobj = details.children().last(); - jobj.append('Reset'); - jobj.append('Update'); + jobj.append(' Reset'); + jobj.append('Update'); details.append('
'); @@ -58,21 +59,23 @@ function ipa_details_create(obj_name, dls, container) jobj.append('Back to Top'); } -var _ipa_h2_template = '

− I

'; -var _ipa_dl_template = '
'; -var _ipa_dt_template = '
N:
'; function ipa_generate_dl(jobj, id, name, dts) { if (!dts) return; - var obj_name = jobj.parent().attr('title'); + var parent = jobj.parent(); + var obj_name = parent.attr('title'); - jobj.after(_ipa_h2_template.replace('I', name)); - jobj = jobj.next(); - jobj.after(_ipa_dl_template.replace('I', id)); - jobj = jobj.next(); + parent.append($("

",{ + click: function(){_h2_on_click(this)}, + html:"− "+name + })); + + var dl = $('
',{ + id:id, + "class":"entryattrs"}) for (var i = 0; i < dts.length; ++i) { var label = ''; @@ -83,12 +86,14 @@ function ipa_generate_dl(jobj, id, name, dts) } if ((!label) && (dts[i].length > 1)) label = dts[i][1]; - jobj.append( - _ipa_dt_template.replace('T', dts[i][0]).replace('N', label) + dl.append( + $('
',{ + title:dts[i][0], + html:label+":"}) ); } - - jobj.after('
'); + parent.append(dl); + parent.append('
'); } function ipa_details_load(jobj, pkey, on_win, on_fail) @@ -210,6 +215,7 @@ function ipa_details_update(obj_name, pkey, on_win, on_fail) var _ipa_a_add_template = 'Add'; var _ipa_span_doc_template = 'Hint: D'; +var _ipa_span_hint_template = 'Hint: D'; /* populate definition lists with the class 'entryattrs' with entry attributes * @@ -248,26 +254,29 @@ function ipa_details_display(obj_name, entry_attrs) } else { /* title contains attribute name - default behaviour */ var multivalue = false; - var hint_span = ''; + var hint_span = null; var param_info = ipa_get_param_info(obj_name, 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); + if (hint){ + hint_span = $("",{ + "class":"attrhint", + html:"Hint: " + hint}); + } } var value = entry_attrs[attr]; if (value) { ipa_insert_first_dd( - jobj, ipa_create_input(obj_name, attr, value[0]) + hint_span + jobj, ipa_create_input(obj_name, attr, value[0],hint_span) ); for (var i = 1; i < value.length; ++i) { jobj = jobj.next(); ipa_insert_other_dd( - jobj, ipa_create_input(obj_name, attr, value[i]) + jobj, ipa_create_input(obj_name, attr, value[i],hint_span) ); } if (multivalue) { @@ -278,11 +287,11 @@ function ipa_details_display(obj_name, entry_attrs) } else { if (multivalue) { ipa_insert_first_dd( - jobj, _ipa_a_add_template.replace('A', attr) + hint_span + jobj, _ipa_a_add_template.replace('A', attr) /*.append( hint_span)*/ ); } else { ipa_insert_first_dd( - jobj, ipa_create_input(obj_name, attr, '') + hint_span + jobj, ipa_create_input(obj_name, attr, '')/*.append( hint_span)*/ ); } } @@ -290,18 +299,16 @@ function ipa_details_display(obj_name, entry_attrs) }); } -var _ipa_dd_first_template = '
I
'; function ipa_insert_first_dd(jobj, content) { - jobj.after(_ipa_dd_first_template.replace('I', content)); -} + jobj.after( $('
').append(content)) -var _ipa_dd_other_template = '
I
'; +} function ipa_insert_other_dd(jobj, content) { - jobj.after(_ipa_dd_other_template.replace('I', content)); + jobj.after($('
').append(content)); } @@ -317,32 +324,37 @@ var _ipa_param_type_2_handler_map = { * arguments: * attr - LDAP attribute name * value - the attributes value */ -function ipa_create_input(obj_name, attr, value) +function ipa_create_input(obj_name, attr, value,hint) { + var input = $("