Incam_PROFIND_Web/www/themes/profind/js/profind-template.js
2012-11-12 11:57:20 +00:00

52 lines
1.6 KiB
JavaScript

/**
* * This script depends on jquery.format.js
*/
$(document).ready(function() {
profind_template.init();
});
profind_template = {
init: function() {
profind_template.hideHeaderIfEmpty();
profind_template.onAppend();
$(".add").click(function(){
var template = jQuery.format(jQuery.trim($(this).siblings(".template").val()));
var place = $(this).parents(".templateFrame:first").children(".templateTarget");
var i = place.find(".rowIndex").length>0 ? place.find(".rowIndex").max()+1 : 0;
$(template(i)).appendTo(place);
profind_template.showHeader(this);
profind_template.onAppend();
return false;
});
$(".remove").live("click", function() {
if ($(this).siblings(".pk").val() === '') {
$(this).parents(".templateContent:first").remove();
} else {
$(this).siblings(".to_remove").val(1);
$(this).parents(".templateContent:first").hide();
}
profind_template.hideHeaderIfEmpty();
return false;
});
},
hideHeaderIfEmpty: function() {
var place = $('.templateTarget').filter(function(){return $.trim($(this).text())===''});
$(place).siblings('.templateHead').hide();
$(place).parents(".templateFrame:first").removeClass('table');
},
showHeader: function(element) {
var place = $(element).parents(".templateFrame:first");
$(place).children('.templateHead').show();
$(place).addClass('table');
},
onAppend: function() {
}
};