1 var reorder = function(class) {
2 console.log("QQQ Enter reorder");
4 var divs = $.find('div[class=' + class + ']');
5 console.log('divs length = ' + divs.length);
7 $(divs).find('a').hide();
9 $(divs).each(function(i, div) {
10 console.log("ROW " + i);
11 $(div).find('a.remove_row').show();
12 replaceIndex(rowIndex(div), i);
15 $(divs).last().find('a.add_row').show();
17 if (divs.length == 1) {
18 $(divs).find('a.remove_row').hide();
23 var rowIndex = function(div) {
24 var idstr = $(div).attr('id');
25 var id = idstr.match(/\d+/);
26 console.log("id = " + id);
30 var rowCount = function(class) {
31 var divs = $.find('div[class=' + class + ']');
35 var replaceIndex = function(elem, oldIndex, newIndex) {
36 $(elem).find('*').each(function() {
37 $.each(this.attributes, function(i, attrib) {
38 var regexp = /extprofile-.*-\d.*/;
39 var value = attrib.value;
40 var match = value.match(regexp);
42 attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
43 console.log('match: oldIndex = ' + oldIndex + ' newIndex = ' + newIndex + ' name = ' + attrib.name + ' value = ' + attrib.value);
49 var resetRow = function(elem) {
50 $(elem).find('input').attr('value', '');
51 $(elem).find("select option[value='office']").attr("selected", true);
54 var addRow = function() {
55 var div = $(this).closest('div');
56 var id = $(div).attr('id');
57 var class = $(div).attr('class');
58 var index = id.match(/\d+/);
59 console.log("Current row = " + index + ', class = ' + class);
60 var tr = $(this).closest('tr');
61 var newtr = $(tr).clone();
62 var newIndex = parseInt(index) + 1;
63 replaceIndex(newtr, index, newIndex);
69 var removeRow = function() {
70 var div = $(this).closest('div');
71 var id = $(div).attr('id');
72 var class = $(div).attr('class');
74 cnt = rowCount(class);
75 console.debug("removeRow - cnt = " + cnt);
77 var target = $(this).closest('tr');
83 var init = function() {
84 reorder('phone-edit');
85 reorder('experience-edit');
86 reorder('education-edit');
94 $('.add_row').live('click', addRow);
95 $('.remove_row').live('click', removeRow);