| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 
 |  $(document).ready(function() {
 
		 function updateTips(t) {
			$("#validateTips").text(t).effect("highlight",{},1500);
		}
 
		function checkLength(o,n,min,max) {
 
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("La longueur du " + n + " doit être comprise "+min+" et "+max+".");
				return false;
			} else {
				return true;
			}
 
		}
 
 
 
		function checkMessage(o,n) {
 
			if ( o.val().length <= 0 ) {
				o.addClass('ui-state-error');
				updateTips("Vous devez écrire quelque chose dans le message.");
				return false;
			} else {
				return true;
			}
 
		}
 
 
        $('a.ajax').click(function() {
            var url = this.href;
            // show a spinner or something via css
            var dialog = $('<div style="display:none" class="loading"></div>').appendTo('body');
            // open the dialog
            dialog.dialog({
                // add a close listener to prevent adding multiple divs to the document
                close: function(event, ui) {
                    // remove div with all data and events
                    dialog.remove();
                },
                modal: true,
 
				buttons: {
				'Envoyer': function() {
				    var sujet = $("#sujet"),
			message = $("#messager"),
 
			allFields = $([]).add(sujet).add(message),
					 bValid = true;
					allFields.removeClass('ui-state-error');
 
                    bValid = bValid && checkLength(sujet,"sujet",3,16);
					bValid = bValid && checkMessage(message,"message"); 
 
 
					if (bValid) {
					   var messageDelay = 4000; //durée d'apprition du message e milliseconde  
					   var form_data = {sujets : $('#sujet').val(),messages : $('#messager').val(),destinataires : $('#destinataire').val()
			                   };
                $.ajax({
                    url: $('a.ajax').attr('alt'),
                    type: 'POST',
                    async : false,
                    data: form_data,
                    success: function(msg) {
					            if(msg='1'){
								$(this).dialog('close');
					            response = 'Votre message est bien parti';
                                $('#successMessage').html(response);
	                            $('#successMessage').fadeIn().delay(messageDelay).fadeOut();
                                }
								else{
								response = $.trim(msg);
                                $('#successMessage').html(response);
	                            $('#successMessage').fadeIn().delay(messageDelay).fadeOut();
                                }
								}
                });
 
                return false;
					}
 
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			}
            });
            // load remote content
            dialog.load(
                url, 
                {}, // omit this param object to issue a GET request instead a POST request, otherwise you may provide post parameters within the object
                function (responseText, textStatus, XMLHttpRequest) {
                    // remove the loading class
                    dialog.removeClass('loading');
                }
            );
            //prevent the browser to follow the link
            return false;
        });
 
        }); | 
Partager