-var removeRow = function() {
- var cnt = rowCount(this);
- var table = $(this).closest('table');
- console.log("row count = " + cnt);
- if (cnt > 1) {
- var target = $(this).closest('tr');
- target.remove();
- reorder(table);
- }
-};
-
-var rowCount = function(row) {
- var top = $(row).closest('table');
- var trs = $(top).find('tr');
- return trs.length - 1; // exclude th section header row
-};
+var SN_EXTENDED = SN_EXTENDED || {};
-var reorder = function(table) {
- var trs = $(table).find('tr').has('td');
+SN_EXTENDED.reorder = function(cls) {
- $(trs).find('a').hide();
+ var divs = $('div[class=' + cls + ']');
- $(trs).each(function(i, tr) {
- console.log("ROW " + i);
- $(tr).find('a.remove_row').show();
- replaceIndex(rowIndex(tr), i);
+ $(divs).each(function(i, div) {
+ $(div).find('a.remove_row').show();
+ SN_EXTENDED.replaceIndex(SN_EXTENDED.rowIndex(div), i);
});
- $(trs).last().find('a.add_row').show();
+ var lastDiv = $(divs).last().closest('tr');
+ lastDiv.addClass('supersizeme');
- if (trs.length == 1) {
- $(trs).find('a.remove_row').hide();
+ $(divs).last().find('a.add_row').show();
+
+ if (divs.length == 1) {
+ $(divs).find('a.remove_row').hide();
}
+};
+SN_EXTENDED.rowIndex = function(div) {
+ var idstr = $(div).attr('id');
+ var id = idstr.match(/\d+/);
+ return id;
};
-var rowIndex = function(elem) {
- var idStr = $(elem).find('div').attr('id');
- var id = idStr.match(/\d+/);
- console.log("id = " + id);
+SN_EXTENDED.rowCount = function(cls) {
+ var divs = $.find('div[class=' + cls + ']');
+ return divs.length;
};
-var replaceIndex = function(elem, oldIndex, newIndex) {
+SN_EXTENDED.replaceIndex = function(elem, oldIndex, newIndex) {
$(elem).find('*').each(function() {
$.each(this.attributes, function(i, attrib) {
var regexp = /extprofile-.*-\d.*/;
var value = attrib.value;
var match = value.match(regexp);
- if (match != null) {
+ if (match !== null) {
attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
- console.log('match: oldIndex = ' + oldIndex + ' newIndex = ' + newIndex + ' name = ' + attrib.name + ' value = ' + attrib.value);
}
});
});
}
-var resetRow = function(elem) {
+SN_EXTENDED.resetRow = function(elem) {
$(elem).find('input').attr('value', '');
$(elem).find("select option[value='office']").attr("selected", true);
-}
+};
-var addRow = function() {
- var divId = $(this).closest('div').attr('id');
- var index = divId.match(/\d+/);
- console.log("Current row = " + index);
- var tr = $(this).closest('tr');
- var newtr = $(tr).clone();
+SN_EXTENDED.addRow = function() {
+ var div = $(this).closest('div');
+ var id = div.attr('id');
+ var cls = div.attr('class');
+ var index = id.match(/\d+/);
var newIndex = parseInt(index) + 1;
- replaceIndex(newtr, index, newIndex);
- resetRow(newtr);
- $(tr).after(newtr);
- console.log("number of rows: " + rowCount(tr));
- reorder($(this).closest('table'));
+ var newtr = $(div).closest('tr').clone();
+ SN_EXTENDED.replaceIndex(newtr, index, newIndex);
+ $(newtr).removeClass('supersizeme');
+ SN_EXTENDED.resetRow(newtr);
+ $(div).closest('tr').after(newtr);
+ SN_EXTENDED.reorder(cls);
};
-$(document).ready(
+SN_EXTENDED.removeRow = function() {
+ var div = $(this).closest('div');
+ var id = $(div).attr('id');
+ var cls = $(div).attr('class');
-function() {
- $('.add_row').live('click', addRow);
- $('.remove_row').live('click', removeRow);
-}
+ var cnt = SN_EXTENDED.rowCount(cls);
+ if (cnt > 1) {
+ var target = $(this).closest('tr');
+ target.remove();
+ SN_EXTENDED.reorder(cls);
+ }
+};
+
+$(document).ready(function() {
+
+ $("input#extprofile-manager").autocomplete({
+ source: 'finduser',
+ minLength: 2 });
+
+ $.datepicker.formatDate('yy-mm-dd');
+
+ $("input[name$=-start], input[name$=-end], #extprofile-birthday").datepicker({ dateFormat: 'd M yy' });
+
+ var multifields = ["phone-item", "experience-item", "education-item", "im-item"];
+
+ for (f in multifields) {
+ SN_EXTENDED.reorder(multifields[f]);
+ }
+
+ $("input#extprofile-manager").autocomplete({
+ source: 'finduser',
+ minLength: 2 });
+
+ $('.add_row').live('click', SN_EXTENDED.addRow);
+ $('.remove_row').live('click', SN_EXTENDED.removeRow);
-);
\ No newline at end of file
+});