2011-03-16 11:33:05 +09:00
|
|
|
var SN_EXTENDED = SN_EXTENDED || {};
|
|
|
|
|
2011-03-16 13:23:34 +09:00
|
|
|
SN_EXTENDED.reorder = function(cls) {
|
2011-03-14 08:32:13 +09:00
|
|
|
|
2011-03-16 13:23:34 +09:00
|
|
|
var divs = $('div[class=' + cls + ']');
|
2011-03-14 08:32:13 +09:00
|
|
|
|
2011-03-14 17:49:46 +09:00
|
|
|
$(divs).each(function(i, div) {
|
2011-03-16 15:58:45 +09:00
|
|
|
$(div).find('a.add_row').hide();
|
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 13:23:34 +09:00
|
|
|
var lastDiv = $(divs).last().closest('tr');
|
|
|
|
lastDiv.addClass('supersizeme');
|
2011-03-16 02:08:41 +09:00
|
|
|
|
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) {
|
2011-03-16 16:25:02 +09:00
|
|
|
$(divs).find('a.remove_row').fadeOut("slow");
|
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+/);
|
|
|
|
return id;
|
|
|
|
};
|
|
|
|
|
2011-03-16 13:23:34 +09:00
|
|
|
SN_EXTENDED.rowCount = function(cls) {
|
|
|
|
var divs = $.find('div[class=' + cls + ']');
|
2011-03-14 17:49:46 +09:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.resetRow = function(elem) {
|
2011-03-16 15:51:28 +09:00
|
|
|
$(elem).find('input, textarea').attr('value', '');
|
2011-03-14 08:32:13 +09:00
|
|
|
$(elem).find("select option[value='office']").attr("selected", true);
|
2011-03-16 13:23:34 +09:00
|
|
|
};
|
2011-03-14 08:32:13 +09:00
|
|
|
|
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');
|
2011-03-16 13:23:34 +09:00
|
|
|
var id = div.attr('id');
|
|
|
|
var cls = div.attr('class');
|
2011-03-14 17:49:46 +09:00
|
|
|
var index = id.match(/\d+/);
|
2011-03-14 08:32:13 +09:00
|
|
|
var newIndex = parseInt(index) + 1;
|
2011-03-16 16:09:06 +09:00
|
|
|
var newtr = $(div).closest('tr').removeClass('supersizeme').clone();
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.replaceIndex(newtr, index, newIndex);
|
|
|
|
SN_EXTENDED.resetRow(newtr);
|
2011-03-16 13:23:34 +09:00
|
|
|
$(div).closest('tr').after(newtr);
|
|
|
|
SN_EXTENDED.reorder(cls);
|
2011-03-14 08:32:13 +09:00
|
|
|
};
|
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
SN_EXTENDED.removeRow = function() {
|
2011-03-16 15:51:28 +09:00
|
|
|
|
2011-03-14 17:49:46 +09:00
|
|
|
var div = $(this).closest('div');
|
|
|
|
var id = $(div).attr('id');
|
2011-03-16 13:23:34 +09:00
|
|
|
var cls = $(div).attr('class');
|
2011-03-16 15:51:28 +09:00
|
|
|
var that = this;
|
|
|
|
|
|
|
|
$("#confirm-dialog").dialog({
|
|
|
|
buttons : {
|
|
|
|
"Confirm" : function() {
|
2011-03-16 16:23:34 +09:00
|
|
|
$(this).dialog("close");
|
2011-03-16 15:51:28 +09:00
|
|
|
var target = $(that).closest('tr');
|
|
|
|
target.fadeOut("slow", function() {
|
2011-03-16 16:23:34 +09:00
|
|
|
$(target).remove();
|
|
|
|
SN_EXTENDED.reorder(cls);
|
2011-03-16 15:51:28 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
"Cancel" : function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-03-16 16:23:34 +09:00
|
|
|
var cnt = SN_EXTENDED.rowCount(cls);
|
|
|
|
|
2011-03-14 17:49:46 +09:00
|
|
|
if (cnt > 1) {
|
2011-03-16 15:51:28 +09:00
|
|
|
$("#confirm-dialog").dialog("open");
|
2011-03-14 17:49:46 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-03-16 13:23:34 +09:00
|
|
|
$(document).ready(function() {
|
2011-03-16 11:33:05 +09:00
|
|
|
|
2011-03-16 15:51:28 +09:00
|
|
|
$("#confirm-dialog").dialog({
|
|
|
|
autoOpen: false,
|
|
|
|
modal: true
|
|
|
|
});
|
|
|
|
|
2011-03-16 13:23:34 +09:00
|
|
|
$("input#extprofile-manager").autocomplete({
|
|
|
|
source: 'finduser',
|
|
|
|
minLength: 2 });
|
2011-03-16 11:33:05 +09:00
|
|
|
|
2011-03-16 15:51:28 +09:00
|
|
|
$("input[name$=-start], input[name$=-end], #extprofile-birthday").datepicker({ dateFormat: 'd M yy' });
|
2011-03-16 15:02:05 +09:00
|
|
|
|
2011-03-16 11:33:05 +09:00
|
|
|
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
|
|
|
});
|