1 var SN_EXTENDED = SN_EXTENDED || {};
3 SN_EXTENDED.reorder = function(cls) {
5 var divs = $('div[class=' + cls + ']');
7 $(divs).each(function(i, div) {
8 $(div).find('a.add_row').hide();
9 $(div).find('a.remove_row').show();
10 SN_EXTENDED.replaceIndex(SN_EXTENDED.rowIndex(div), i);
13 var lastDiv = $(divs).last().closest('tr');
14 lastDiv.addClass('supersizeme');
16 $(divs).last().find('a.add_row').show();
18 if (divs.length == 1) {
19 $(divs).find('a.remove_row').hide();
23 SN_EXTENDED.rowIndex = function(div) {
24 var idstr = $(div).attr('id');
25 var id = idstr.match(/\d+/);
29 SN_EXTENDED.rowCount = function(cls) {
30 var divs = $.find('div[class=' + cls + ']');
34 SN_EXTENDED.replaceIndex = function(elem, oldIndex, newIndex) {
35 $(elem).find('*').each(function() {
36 $.each(this.attributes, function(i, attrib) {
37 var regexp = /extprofile-.*-\d.*/;
38 var value = attrib.value;
39 var match = value.match(regexp);
41 attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
47 SN_EXTENDED.resetRow = function(elem) {
48 $(elem).find('input, textarea').attr('value', '');
49 $(elem).find("select option[value='office']").attr("selected", true);
52 SN_EXTENDED.addRow = function() {
53 var div = $(this).closest('div');
54 var id = div.attr('id');
55 var cls = div.attr('class');
56 var index = id.match(/\d+/);
57 var newIndex = parseInt(index) + 1;
58 var newtr = $(div).closest('tr').removeClass('supersizeme').clone();
59 SN_EXTENDED.replaceIndex(newtr, index, newIndex);
60 SN_EXTENDED.resetRow(newtr);
61 $(div).closest('tr').after(newtr);
62 SN_EXTENDED.reorder(cls);
65 SN_EXTENDED.removeRow = function() {
67 var div = $(this).closest('div');
68 var id = $(div).attr('id');
69 var cls = $(div).attr('class');
72 $("#confirm-dialog").dialog({
74 "Confirm" : function() {
75 $(this).dialog("close");
76 var target = $(that).closest('tr');
77 target.fadeOut("slow", function() {
79 SN_EXTENDED.reorder(cls);
82 "Cancel" : function() {
83 $(this).dialog("close");
88 var cnt = SN_EXTENDED.rowCount(cls);
91 $("#confirm-dialog").dialog("open");
95 $(document).ready(function() {
97 $("#confirm-dialog").dialog({
102 $("input#extprofile-manager").autocomplete({
106 $("input[name$=-start], input[name$=-end], #extprofile-birthday").datepicker({ dateFormat: 'd M yy' });
108 var multifields = ["phone-item", "experience-item", "education-item", "im-item"];
110 for (f in multifields) {
111 SN_EXTENDED.reorder(multifields[f]);
114 $("input#extprofile-manager").autocomplete({
118 $('.add_row').live('click', SN_EXTENDED.addRow);
119 $('.remove_row').live('click', SN_EXTENDED.removeRow);