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').fadeOut("slow");
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('input').removeAttr('disabled');
50 $(elem).find("select option[value='office']").attr("selected", true);
51 $(elem).find("input:checkbox").attr('checked', false);
52 $(elem).find("input[name$=-start], input[name$=-end]").each(function() {
53 $(this).removeClass('hasDatepicker');
54 $(this).datepicker({ dateFormat: 'd M yy' });
58 SN_EXTENDED.addRow = function() {
59 var div = $(this).closest('div');
60 var id = div.attr('id');
61 var cls = div.attr('class');
62 var index = id.match(/\d+/);
63 var newIndex = parseInt(index) + 1;
64 var newtr = $(div).closest('tr').removeClass('supersizeme').clone();
65 SN_EXTENDED.replaceIndex(newtr, index, newIndex);
66 SN_EXTENDED.resetRow(newtr);
67 $(div).closest('tr').after(newtr);
68 SN_EXTENDED.reorder(cls);
71 SN_EXTENDED.removeRow = function() {
73 var div = $(this).closest('div');
74 var id = $(div).attr('id');
75 var cls = $(div).attr('class');
78 $("#confirm-dialog").dialog({
80 "Confirm" : function() {
81 $(this).dialog("close");
82 var target = $(that).closest('tr');
83 target.fadeOut("slow", function() {
85 SN_EXTENDED.reorder(cls);
88 "Cancel" : function() {
89 $(this).dialog("close");
94 var cnt = SN_EXTENDED.rowCount(cls);
97 $("#confirm-dialog").dialog("open");
101 $(document).ready(function() {
103 $("#confirm-dialog").dialog({
108 $("input#extprofile-manager").autocomplete({
112 $("input[name$=-start], input[name$=-end], #extprofile-birthday").datepicker({ dateFormat: 'd M yy' });
114 var multifields = ["phone-item", "experience-item", "education-item", "im-item", 'website-item'];
116 for (f in multifields) {
117 SN_EXTENDED.reorder(multifields[f]);
120 $("input#extprofile-manager").autocomplete({
124 $('.add_row').live('click', SN_EXTENDED.addRow);
125 $('.remove_row').live('click', SN_EXTENDED.removeRow);
127 $('input:checkbox[name$=current]').each(function() {
128 var input = $(this).parent().siblings('input[id$=-end]');
129 if ($(this).is(':checked')) {
130 $(input).attr('disabled', 'true');
134 $('input:checkbox[name$=current]').live('click', function() {
135 var input = $(this).parent().siblings('input[id$=-end]');
136 if ($(this).is(':checked')) {
138 $(input).attr('disabled', 'true');
140 $(input).removeAttr('disabled');