var position = null;
function valider(id) {
$('#action').val('save');
$.ajax({
url: 'wdp/wdp_root/process.php',
data: $('#form_' + id).serialize(),
async: true,
type: 'POST',
success: function (html){
rafraichir(id);
},
error: function (xhr, ajaxOptions, thrownError){
alert(xhr.responseText);
}
});
}
function doGuestbook(action, id, message) {
if (action == 'edit') {
$('#' + message + ' .message_body_text').hide();
$('#' + message + ' .message_body_text_form').show();
$('#' + message + ' .message_head_fields').hide();
$('#' + message + ' .message_head_fields_form').show();
$('#' + message + ' .message_head_name').hide();
$('#' + message + ' .message_head_name_form').show();
$('#' + message + ' .message_footer').hide();
$('#' + message + ' .message_footer_form').show();
return;
}
if (action == 'cancel') {
$('#' + message + ' .message_body_text').show();
$('#' + message + ' .message_body_text_form').hide();
$('#' + message + ' .message_head_fields').show();
$('#' + message + ' .message_head_fields_form').hide();
$('#' + message + ' .message_head_name').show();
$('#' + message + ' .message_head_name_form').hide();
$('#' + message + ' .message_footer').show();
$('#' + message + ' .message_footer_form').hide();
return;
}
if (action == 'delete') {
if (!confirm('Etes-vous sûr de vouloir supprimer ce message ?')) {
return;
}
}
if (action == 'modifyMessage') {
data = 'id=' + id + '&type=XMLGuestbook&action=' + action + '&page=' + $('#page').val() + '&message=' + message + '&' + $('#message_' + message).serialize();
} else {
data = 'id=' + id + '&type=XMLGuestbook&action=' + action + '&page=' + $('#page').val() + '&message=' + message;
}
$.ajax({
url: 'wdp/wdp_root/process.php',
data: data,
async: true,
type: 'POST',
success: function (items){
loadGuestbook(items);
},
error: function (xhr, ajaxOptions, thrownError){
alert(xhr.responseText);
}
});
}
function previewMessage(id) {
data = 'type=XMLGuestbook&action=previewMessage' + '&' + $('#form_' + id).serialize();
$.ajax({
url: 'wdp/wdp_root/public.php',
data: data,
async: true,
type: 'POST',
success: function (data){
$.fancybox({
'titleShow' : false,
'hideOnContentClick' : true,
'content' : data,
onComplete: function() {
captchaBind();
}
});
},
error: function (xhr, ajaxOptions, thrownError){
alert(xhr.responseText);
}
});
}
function rafraichir(id) {
$('#action').val('refresh');
$.ajax({
url: 'wdp/wdp_root/process.php',
data: $('#form_' + id).serialize(),
async: false,
type: 'POST',
success: function (html){
if($('#wrapper-' + id).length != 0)
{
// modification
$('#wrapper-' + id).replaceWith(html);
}
else
{
// création
if (position != null)
{
$('#' + position).before(html);
}
else
{
$('#wdp_modules').append(html);
}
position = null;
}
// fermeture fancybox
$.fancybox.close();
},
error: function (xhr, ajaxOptions, thrownError){
alert(xhr.responseText);
}
});
}
//appel d'une URL et affichage de la réponse dans une fancyBox
function ajaxFancyLoad(url, data, fullscreen) {
$.ajax({
url: url,
data: data,
async: false,
type: 'POST',
success: function (html){
// affichage fancybox
if (fullscreen) {
$.fancybox(
{
'centerOnScroll': true,
'hideOnContentClick': false,
'hideOnOverlayClick': true,
'autoDimensions': false,
'overlayOpacity': 0.5,
'overlayColor': '#000000',
'width' : '100%',
'height' : '100%',
'content': html,
onComplete: function() {
$('#fancybox-inner textarea').each(function () {
$(this).focus();
});
$('#loadedpage').val($('#page').val());
$('#loadedlang').val($('#lang').val());
$(document).unbind('keydown.fb');
if (jQuery.browser.msie) {
$("html").css("overflow", "hidden");
} else {
$("body").css("overflow", "hidden");
}
},
onClosed: function() {
if (jQuery.browser.msie) {
$("html").css("overflow", "auto");
} else {
$("body").css("overflow", "auto");
}
}
});
} else {
$.fancybox(
{
'hideOnContentClick': false,
'hideOnOverlayClick': true,
'autoDimensions': false,
'overlayOpacity': 0.5,
'overlayColor': '#000000',
'content': html,
onComplete: function() {
$('#fancybox-inner textarea').each(function () {
$(this).focus();
});
$('#loadedpage').val($('#page').val());
$('#loadedlang').val($('#lang').val());
$(document).unbind('keydown.fb');
if (jQuery.browser.msie) {
$("html").css("overflow", "hidden");
} else {
$("body").css("overflow", "hidden");
}
},
onClosed: function() {
if (jQuery.browser.msie) {
$("html").css("overflow", "auto");
} else {
$("body").css("overflow", "auto");
}
}
});
}
},
error: function (xhr, ajaxOptions, thrownError){
alert(xhr.responseText);
}
});
}
//up, down, del
function process(action, id) {
if (action == 'del') {
if (!confirm('Etes-vous sûr de vouloir supprimer cet élément ?')) {
return;
}
}
$.ajax({
type: 'POST',
processData: true,
url: 'wdp/wdp_root/process.php',
data: 'id=' + id + '&action=' + action + '&page=' + $('#page').val(),
dataType: 'html',
success: function(data){
if (action == 'del') {
$('.tooltip').hide();
$('#' + id).remove();
} else if (action == 'up') {
var element = $('#' + id);
var prevElement = element.prevAll('.element:first');
prevElement.before(element);
} else if (action == 'down') {
var element = $('#' + id);
var nextElement = element.nextAll('.element:first');
nextElement.after(element);
}
},
error: function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
}
//up, down, del
function processPix(action, id) {
if (action == 'del') {
if (confirm('Etes-vous sûr de vouloir supprimer cette image ?')) {
$('#' + id).remove();
}
} else if (action == 'up') {
var element = $('#' + id);
var prevElement = element.prevAll('.image:first');
prevElement.before(element);
refreshImages(id);
} else if (action == 'down') {
var element = $('#' + id);
var nextElement = element.nextAll('.image:first');
nextElement.after(element);
refreshImages(id);
}
else if (action == 'save') {
refreshImages(id);
valider(id);
}
}
// image deletion function
function deleteImage( $item ) {
recycle_icon = "Rétablir l'image";
$item.fadeOut(function() {
var $list = $( "ul", $("#trash") ).length ?
$( "ul", $("#trash")) :
$( "
" ).appendTo($("#trash"));
$item.find( "a.ui-icon-trash" ).remove();
$item.append( recycle_icon ).appendTo( $list ).fadeIn(function() {
$item
.animate({ width: "48px" })
.find( "img" )
.animate({ height: "38px" });
});
});
}
// image recycle function
function recycleImage( $item ) {
trash_icon = "Delete image";
$item.fadeOut(function() {
$item.find( "a.ui-icon-refresh" ).remove().end()
.css( "width", "96px").append( trash_icon ).find( "img" ).css( "width", "" ).css( "height", "" ).end()
.appendTo($("#gallery"))
.fadeIn();
});
}
function refreshImages(id) {
images = new Array();
$('#gallery .image').each(function(index) {
images.push($(this).attr('id'));
});
$('#textarea_' + id).val(images.join());
}
$(document).ready(function() {
$('.scrollToTop').live('click', function(event){
event.preventDefault();
$('html,body').animate({scrollTop: 0}, 'slow');
});
// upload de fichiers
$('input[class=file]').live("change",function() {
$('#action').val('upload');
var idImage = $(this).attr('id').split("_");
$('#idx').val(idImage[1]);
form = $('#form_' + idImage[0]);
$.fancybox.showActivity();
$('input[type=file], .envoyer').css("visibility", "hidden");
$('input[id=enregistrer]').attr("disabled", "disabled");
$('.pleasewait').html('Chargement en cours ... veuillez patienter...
');
$(this).upload(
'wdp/wdp_root/process.php',
form.serialize(),
function(res) {
idx = $('#idx').val();
$('#filename_'+ idx).val(res.filename);
$('#current_' + res.id + '_' + idx).attr("src", res.path);
$('input[type=file], .envoyer').css("visibility", "visible");
$('input[id=enregistrer]').attr("disabled", "");
$('.pleasewait').html('');
$.fancybox.hideActivity();
},
'json'
);
});
// upload de fichiers
$('input[class=img_tableau]').live("change",function() {
$('#action').val('upload');
var idImage = $(this).attr('id').split("_");
$('#idx').val(idImage[1]);
form = $('#form_' + idImage[0]);
$.fancybox.showActivity();
//$('input[id^=' + $(this).attr('id') + ']').attr("readonly", "readonly");
$('input[type=file], .envoyer').css("visibility", "hidden");
$('input[id=enregistrer]').attr("disabled", "disabled");
$('.pleasewait').html('Chargement en cours ... veuillez patienter...
');
$(this).upload(
'wdp/wdp_root/process.php',
form.serialize(),
function(res) {
idx = $('#idx').val();
img = '';
$('.edition').html(img);
$('textarea#textarea_' + res.id).cleditor()[0].focus();
$('textarea#textarea_' + res.id).cleditor()[0].clear();
$('textarea#textarea_' + res.id).cleditor()[0].execCommand('inserthtml', img);
$('input[type=file], .envoyer').css("visibility", "visible");
$('input[id=enregistrer]').attr("disabled", "");
$('.pleasewait').html('');
$.fancybox.hideActivity();
},
'json'
);
});
// upload de fichiers
$('input[class=img_pedigree]').live("change",function() {
$('#action').val('upload');
var idImage = $(this).attr('id').split("_");
$('#idx').val(idImage[1]);
form = $('#form_' + idImage[0]);
$.fancybox.showActivity();
$('input[type=file], .envoyer').css("visibility", "hidden");
$('input[id=enregistrer]').attr("disabled", "disabled");
$('.pleasewait').html('Chargement en cours ... veuillez patienter...
');
$(this).upload(
'wdp/wdp_root/process.php',
form.serialize(),
function(res) {
idx = $('#idx').val();
$('#content_'+ idx).val(res.filename);
img = '';
$('#' + res.id + '_' + idx).html(img);
$('input[type=file], .envoyer').css("visibility", "visible");
$('input[id=enregistrer]').attr("disabled", "");
$('.pleasewait').html('');
$.fancybox.hideActivity();
},
'json'
);
});
// upload de fichiers
$('input[class^=slide]').live("change",function() {
$('#action').val('upload');
var idImage = $(this).attr('id').split("_");
$('#idx').val(idImage[1]);
form = $('#form_' + idImage[0]);
$.fancybox.showActivity();
$('input[type=file], .envoyer').css("visibility", "hidden");
$('input[id=enregistrer]').attr("disabled", "disabled");
$('.pleasewait').html('Chargement en cours ... veuillez patienter...
');
$(this).upload(
'wdp/wdp_root/process.php',
form.serialize(),
function(res) {
idx = $('#idx').val();
$('#' + res.id + '_' + idx).attr('id', res.id + '_' + eval(parseInt(parseInt(idx)+1)));
$('#' + res.id + '_' + idx).attr('name', res.id + '_' + eval(parseInt(parseInt(idx)+1)));
var html = "";
html += "";
html += "Déplacer dans la Corbeille";
html += "";
if( $('#gallery > .image').length > 0)
{
if ($(this).hasClass('last'))
$('#gallery > .image:last').after(html);
else
$('#gallery > .image:first').before(html);
}
else
$('#gallery').html(html);
$('input[type=file], .envoyer').css("visibility", "visible");
$('input[id=enregistrer]').attr("disabled", "");
$('.pleasewait').html('');
$.fancybox.hideActivity();
},
'json'
);
});
// upload de fichiers
$('input[class=document]').live("change",function() {
$('#action').val('upload');
form = $('#form_' + $(this).attr('id'));
$.fancybox.showActivity();
$('input[type=file], .envoyer').css("visibility", "hidden");
$('input[id=enregistrer]').attr("disabled", "disabled");
$('.pleasewait').html('Chargement en cours ... veuillez patienter...
');
$(this).upload(
'wdp/wdp_root/process.php',
form.serialize(),
function(res) {
$('#filename').val(res.filename);
$('#document').html(res.filename);
$('#document').attr("href", 'wdp/wdp_ihm/download.php?page=wdp_tmp&file=' + res.filename);
$('input[type=file], .envoyer').css("visibility", "visible");
$('input[id=enregistrer]').attr("disabled", "");
$('.pleasewait').html('');
$.fancybox.hideActivity();
},
'json'
);
});
// génération de titre
$('input[class=preview]').live("click",function() {
$('#action').val('preview');
var idImage = $(this).prev('input').attr('id').split("_");
$('#idx').val("1");
form = $('#form_' + idImage[1]);
$.ajax({
type: 'POST',
processData: true,
url: 'wdp/wdp_root/process.php',
data: form.serialize(),
dataType: 'json',
success: function(res){
idx = $('#idx').val();
$('#filename_'+ idx).val(res.filename);
$('#current_' + res.id + '_' + idx).attr("src", res.path);
},
error: function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
});
// resolve the icons behavior with event delegation
$("ul.gallery > li").live("click",function(event) {
var $item = $( this ),
$target = $( event.target );
if ( $target.is( "a.ui-icon-trash" ) ) {
deleteImage( $item );
} else if ( $target.is( "a.ui-icon-zoomin" ) ) {
viewLargerImage( $target );
} else if ( $target.is( "a.ui-icon-refresh" ) ) {
recycleImage( $item );
}
return false;
});
$('.annuler').live("click", function() {
$.fancybox.close();
});
$('input[type=text]').live("keypress",function(e) {
if (e.keyCode == 13) return false;
});
$("a.fancy-image").fancybox({
'titleShow' : false,
'hideOnContentClick' : true
});
$("span.fancy-pedigree").live("click", function() {
$.fancybox({
'centerOnScroll': true,
'hideOnContentClick': true,
'hideOnOverlayClick': true,
'autoDimensions': false,
'overlayOpacity': 0.5,
'overlayColor': '#000000',
'width' : 1000,
'height' : '100%',
'content' : $(this).next('div').html()
});
});
$(document).bind("ajaxSend", function(){
$.fancybox.showActivity();
}).bind("ajaxComplete", function(){
$.fancybox.hideActivity();
}).bind("ajaxError", function(){
$.fancybox.hideActivity();
});
$("#elem_tableau table td").live('click', function(event) {
if (!$(this).hasClass('buttons')) {
add_buttons();
}
clickCell(this);
});
$("#iefix table td").live('click', function(event) {
clickCell(this);
});
$('textarea[class="editor"]').live("focus",function() {
id = '#' + $(this).attr('id');
var cl_width;
type = $(id).parents('form').attr('class');
if (type == 'XMLText')
cl_width = '900';
else
cl_width = 440;
$(id).cleditor({
width: cl_width, // width not including margins, borders or padding
height: 250, // height not including margins, borders or padding
controls: // controls to add to the toolbar
"bold italic underline bullets | size " +
"| color " +
" | alignleft center alignright justify | undo redo | " +
" link unlink | pastetext",
colors: "87621b df9954 4b4645",
fonts: "",
sizes: "1,2,3,4,5,6",
useCSS: false, // use CSS to style HTML when possible (not supported in ie)
docType: // Document type contained within the editor
'',
docCSSFile: // CSS file used to style the document contained within the editor
"",
bodyStyle: // style to assign to document body contained within the editor
"margin:4px; font:10pt Arial,Verdana; cursor:text"
});
if ($('#elem_tableau').length > 0)
ieFix();
});
$(function() {
$('.element,img,#global').bind("contextmenu", function(e) {
if ($('#page').val().substr(0, 5) != 'liens' && $('#page').val().substr(0, 5) != 'links')
e.preventDefault();
});
});
$(".ajouterligne").live('click', function(event) {
appendTxt = '';
$('#elem_tableau table').find('tr').eq(1).find('td').each(function(index){
if (!$(this).hasClass('buttons'))
appendTxt += ' | ';
});
appendTxt += ' | ';
appendTxt += '
';
$(this).parent('td').parent('tr').after(appendTxt);
});
$(".supprimerligne").live('click', function(event) {
if ($('#elem_tableau table').find('tr').length <= 2) {
return false;
}
if (!confirm("Etes vous sûr de vouloir supprimer entièrement cette ligne ?"))
return false;
$(this).parent('td').parent('tr').remove();
});
$(".ajoutercolonne").live('click', function(event) {
index = $(this).parent('td').index();
$('#elem_tableau table').find('tr').each(function(i){
if (i == 0)
$(this).find('td').eq(index).after(getNewCellColonne());
else
$(this).find('td').eq(index).after(' | ');
});
});
$(".supprimercolonne").live('click', function(event) {
if ($('#elem_tableau table').find('tr').first().find('td').length <= 2) {
return false;
}
if (!confirm("Etes vous sûr de vouloir supprimer entièrement cette colonne ?"))
return false;
index = $(this).parent('td').index();
$('#elem_tableau table').find('tr').each(function(i){
$(this).find('td').eq(index).remove();
});
});
});
function uniqid() {
var n=Math.floor(Math.random()*11);
var k = Math.floor(Math.random()* 1000000);
var m = k;
return 'id' + m;
}
function saveTableau(id) {
updateTextArea();
remove_buttons();
$('#elem_tableau').find('td').each(function(){
$(this).removeClass("edition");
});
$('#textarea_' + id).val($('#elem_tableau').html());
valider(id);
}
$(".elem_predigree_img").live('click', function(event) {
if (!confirm("Etes vous sûr de vouloir supprimer cette image ?"))
return false;
$(this).parent().parent().find('input[type="hidden"]').val('');
$(this).remove();
});
function edit(type, id) {
data = 'id=' + id + '&type=' + type + '&action=edit&page=' + $('#page').val() + '&position=' + position;
ajaxFancyLoad('wdp/wdp_root/process.php', data, true);
}
function addbefore(id) {
position = id;
ajaxFancyLoad("wdp/wdp_ihm/assistant.php", null, true);
}