2011-03-16 11:33:05 +09:00
|
|
|
var SN_EXTENDED = SN_EXTENDED || {};
|
|
|
|
|
|
|
|
SN_EXTENDED.reorder = function(class) {
|
2011-03-14 17:49:46 +09:00
|
|
|
console.log("QQQ Enter reorder");
|
2011-03-14 08:32:13 +09:00
|
|
|
|
2011-03-14 17:49:46 +09:00
|
|
|
var divs = $.find('div[class=' + class + ']');
|
|
|
|
console.log('divs length = ' + divs.length);
|
2011-03-14 08:32:13 +09:00
|
|
|
|
2011-03-14 17:49:46 +09:00
|
|
|
$(divs).find('a').hide();
|
2011-03-14 08:32:13 +09:00
|
|
|
|
2011-03-14 17:49:46 +09:00
|
|
|
$(divs).each(function(i, div) {
|
2011-03-14 08:32:13 +09:00
|
|
|
console.log("ROW " + i);
|
2011-03-14 17:49:46 +09:00
|
|
|
$(div).find('a.remove_row').show();
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.replaceIndex(SN_EXTENDED.rowIndex(div), i);
|
2011-03-14 08:32:13 +09:00
|
|
|
});
|
|
|
|
|
2011-03-16 02:08:41 +09:00
|
|
|
$this = $(divs).last().closest('tr');
|
|
|
|
$this.addClass('supersizeme');
|
|
|
|
|
2011-03-14 17:49:46 +09:00
|
|
|
$(divs).last().find('a.add_row').show();
|
2011-03-14 08:32:13 +09:00
|
|
|
|
2011-03-14 17:49:46 +09:00
|
|
|
if (divs.length == 1) {
|
|
|
|
$(divs).find('a.remove_row').hide();
|
2011-03-14 08:32:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.rowIndex = function(div) {
|
2011-03-14 17:49:46 +09:00
|
|
|
var idstr = $(div).attr('id');
|
|
|
|
var id = idstr.match(/\d+/);
|
2011-03-14 08:32:13 +09:00
|
|
|
console.log("id = " + id);
|
2011-03-14 17:49:46 +09:00
|
|
|
return id;
|
|
|
|
};
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.rowCount = function(class) {
|
2011-03-14 17:49:46 +09:00
|
|
|
var divs = $.find('div[class=' + class + ']');
|
|
|
|
return divs.length;
|
2011-03-14 08:32:13 +09:00
|
|
|
};
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.replaceIndex = function(elem, oldIndex, newIndex) {
|
2011-03-14 08:32:13 +09:00
|
|
|
$(elem).find('*').each(function() {
|
|
|
|
$.each(this.attributes, function(i, attrib) {
|
|
|
|
var regexp = /extprofile-.*-\d.*/;
|
|
|
|
var value = attrib.value;
|
|
|
|
var match = value.match(regexp);
|
2011-03-14 17:49:46 +09:00
|
|
|
if (match !== null) {
|
2011-03-14 08:32:13 +09:00
|
|
|
attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
|
|
|
|
console.log('match: oldIndex = ' + oldIndex + ' newIndex = ' + newIndex + ' name = ' + attrib.name + ' value = ' + attrib.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.resetRow = function(elem) {
|
2011-03-14 08:32:13 +09:00
|
|
|
$(elem).find('input').attr('value', '');
|
|
|
|
$(elem).find("select option[value='office']").attr("selected", true);
|
|
|
|
}
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.addRow = function() {
|
2011-03-14 17:49:46 +09:00
|
|
|
var div = $(this).closest('div');
|
|
|
|
var id = $(div).attr('id');
|
|
|
|
var class = $(div).attr('class');
|
|
|
|
var index = id.match(/\d+/);
|
|
|
|
console.log("Current row = " + index + ', class = ' + class);
|
2011-03-16 02:08:41 +09:00
|
|
|
var trold = $(this).closest('tr');
|
|
|
|
var tr = $(trold).removeClass('supersizeme');
|
2011-03-14 08:32:13 +09:00
|
|
|
var newtr = $(tr).clone();
|
|
|
|
var newIndex = parseInt(index) + 1;
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.replaceIndex(newtr, index, newIndex);
|
|
|
|
SN_EXTENDED.resetRow(newtr);
|
2011-03-14 08:32:13 +09:00
|
|
|
$(tr).after(newtr);
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.reorder(class);
|
2011-03-14 08:32:13 +09:00
|
|
|
};
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.removeRow = function() {
|
2011-03-14 17:49:46 +09:00
|
|
|
var div = $(this).closest('div');
|
|
|
|
var id = $(div).attr('id');
|
|
|
|
var class = $(div).attr('class');
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
cnt = SN_EXTENDED.rowCount(class);
|
2011-03-14 17:49:46 +09:00
|
|
|
console.debug("removeRow - cnt = " + cnt);
|
|
|
|
if (cnt > 1) {
|
|
|
|
var target = $(this).closest('tr');
|
|
|
|
target.remove();
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.reorder(class);
|
2011-03-14 17:49:46 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
$(document).ready(
|
|
|
|
|
|
|
|
function() {
|
|
|
|
|
|
|
|
var multifields = ["phone-item", "experience-item", "education-item", "im-item"];
|
|
|
|
|
|
|
|
for (f in multifields) {
|
|
|
|
SN_EXTENDED.reorder(multifields[f]);
|
|
|
|
}
|
2011-03-16 10:45:08 +09:00
|
|
|
|
|
|
|
$("input#extprofile-manager").autocomplete({
|
|
|
|
source: 'finduser',
|
|
|
|
minLength: 2 });
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
$('.add_row').live('click', SN_EXTENDED.addRow);
|
|
|
|
$('.remove_row').live('click', SN_EXTENDED.removeRow);
|
2011-03-14 08:32:13 +09:00
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
});
|