Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > AJAX
AJAX Forum sur la programmation AJAX. Avant de poster : Cours AJAX, FAQ AJAX, Toutes les FAQ JavaScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/05/2011, 17h02   #1
Futur Membre du Club
 
FX
Inscription : juillet 2010
Messages : 75
Détails du profil
Informations personnelles :
Nom : FX

Informations forums :
Inscription : juillet 2010
Messages : 75
Points : 17
Points : 17
Par défaut serialize data CKEditor UI Dialog

bonjour,
j'ai une boite ui dialog avec un champ textarea avec CKEditor.

Comment puis-je récupérer les données et les serializer, mon champ est DocuCommentaire.

J'ai crée des instances CKEDITOR en fin de code ci-dessous, mais cela ne fonctionne pas.

Code :
1
2
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<script src="ressources/javascript/jquery-1.4.4.js"></script>
<script src="ressources/javascript/jquery.ui.core.js"></script>
<script src="ressources/javascript/jquery.ui.widget.js"></script>
<script src="ressources/javascript/jquery.ui.datepicker.js"></script>
<script src="ressources/javascript/jquery.ui.datepicker-fr.js"></script>
<script src="ressources/javascript/jquery.ui.mouse.js"></script>
<script src="ressources/javascript/jquery.ui.button.js"></script>
<script src="ressources/javascript/jquery.ui.position.js"></script>
<script src="ressources/javascript/jquery.ui.dialog.js"></script>
<script src="ressources/javascript/jquery.validate.js"></script>
<script src="ressources/javascript/jquery.form.js"></script>
<script src="ressources/javascript/jquery.url.js"></script>
<script src="ressources/javascript/fileuploader.js"></script>
<script src="ressources/javascript/qunit.js"></script>
<script type="text/javascript" src="ressources/ckeditor/ckeditor.js"></script>
<script>
$(document).ready(function() {
			//textarea avec editeur
			CKEDITOR.replace( 'DocuCommentaire',
				{
					toolbar : 'Basic',
				});
 
 
		//Ajout du fichier
 
		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}
 
		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 entre " +
					min + " et " + max + "." );
				return false;
			} else {
				return true;
			}
		}
 
		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}	
 
 
 
 
				var DocuLibelle = $( "#DocuLibelle" ),
				DocumentId =  $( "#DocumentId" ),
				DocuFichier =  $( "#DocuFichier" ),
				DocuCommentaire =  $( "#DocuCommentaire" ),
				DocuNumero =  $( "#DocuNumero" ),
				EspaceId =  $( "#EspaceId" )
			allFields = $( [] ).add( DocuLibelle ).add( DocuCommentaire ).add( DocumentId ).add( EspaceId ).add(DocuFichier).add(DocuNumero),
			tips = $( ".validate-fichier" );
 
		$( "#dialog-form-fichier" ).dialog({
			<? if(isset($_GET['DocumentId']))
			{	
			echo('autoOpen: true,');
			echo('height: 600,');
			}
			else {
			echo('autoOpen: false,');
			echo('height: 300,');
			} ?>
			width: 500,
			modal: true,
			overlay: { backgroundColor: "#000", opacity: 0.5 },			
			buttons: {
 
				"Valider": function() {
					var bValid = true;
					allFields.removeClass( "ui-state-error" );
 
					bValid = bValid && checkLength( DocuLibelle, "nom", 3, 50 );
 
					if ( bValid ) {
						$(".ajax-fichier").trigger('submit');
					}
				},
				"Annuler": function() {
					$("#dialog-form-fichier").dialog('close');
					<? if(isset($_GET['DocumentId']))
						echo('window.location.href = "espace-collaboratif-documents.php?EspaceId='.$_GET['EspaceId'].'"');
						else
						echo('window.location.reload(true);');
					?>
				}
			},
			close: function() {
					<? if(isset($_GET['DocumentId']))
						echo('window.location.href = "espace-collaboratif-documents.php?EspaceId='.$_GET['EspaceId'].'"');
						else
						echo('window.location.reload(true);');
					?>
			}
		});
 
		$(".ajax-fichier").submit(
		function(e) {
		var datas = $(this).serialize();          
		$.ajax({
			type: "POST",      // envoi des données en POST
			url: "espace-collaboratif-documents.php",    
			data: datas,     // sélection des champs à envoyer
			success: function() { 
				$("#dialog-form-fichier").dialog('close');
					<? if(isset($_GET['DocumentId']))
						echo('window.location.href = "espace-collaboratif-documents.php?EspaceId='.$_GET['EspaceId'].'"');
						else
						echo('window.location.reload(true);');
					?>
			}
		});
		return false; // Pour empêcher le submit vers la page 'action'
	});
 
 
 
		//Bouton Ajouter fichier
		$( "#ajouter-fichier" )
			.click(function() {	
				$( "#dialog-form-fichier" ).dialog( "open" );
			});		
 
		/* essai FileUploader */
 
        var submitFileName, submitId;
		var  EspaceId=$("#EspaceId").val();//recupere valeur EspaceId
 
        var uploader = new qq.FileUploader({	
            element: document.getElementById('file-uploader'),
			multiple: false,
            action: 'action_upload.php',
			params: {
					EspaceId:EspaceId
			},
			maxConnections: 1,
            allowedExtensions: ['doc', 'docx', 'pdf', 'jpg', 'jpeg', 'txt', 'ppt', 'csv', 'xls', 'xlsx', 'pptx'], 
            minSizeLimit: 10,
            onSubmit: function(id, fileName){
                    submitId = id;
                    submitFileName = fileName; 
 
            },
			onComplete: function(id, fileName, responseJSON){
				//Upload unique	
				$('#file-uploader').find('.qq-upload-button').attr('style', 'display:none');			
 
				if (responseJSON.success) {
					$('#file-uploader').find('.qq-upload-failed-text').text('Chargement réussi');
					$('#file-uploader').find('.qq-upload-failed-text').attr('style', 'display:inline');
					var filename=responseJSON.fileName;
 
					$("#DocuFichier").val(filename);//Insere input hidden la valeur filename uploaded
				 }
				 else
				 {
					$('#file-uploader').find('.qq-upload-failed-text').text('Chargement échoué');
				 }
 
			},
			onCancel: function(id, fileName){
			}
        }); 
 
	});
</script>
<script type="text/javascript">
 
CKEDITOR.instances["DocuCommentaire"].document.on('keydown', function(event)
{
    CKEDITOR.tools.setTimeout( function()
    { 
        $("#DocuCommentaire2").val(CKEDITOR.instances.DocuCommentaire.getData()); 
    }, 0);
});
 
CKEDITOR.instances["DocuCommentaire"].document.on('paste', function(event)
{
    CKEDITOR.tools.setTimeout( function()
    { 
        $("#DocuCommentaire2").val(CKEDITOR.instances.DocuCommentaire.getData()); 
    }, 0);
});
 
 
</script>
pixworld est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/05/2011, 22h31   #2
Futur Membre du Club
 
FX
Inscription : juillet 2010
Messages : 75
Détails du profil
Informations personnelles :
Nom : FX

Informations forums :
Inscription : juillet 2010
Messages : 75
Points : 17
Points : 17
pour tout ceux qui recherchent une solution à ce problème, elle est très simple mais n'est indiquée nulle part après avoir consulté de nombreux posts.

dans le header mettre :
Code :
<script type="text/javascript" src="ressources/ckeditor/ckeditor.js"></script>
Dans le code HTML mettre votre balise textarea :

Code :
<textarea name="DocuCommentaire" id="DocuCommentaire" cols="30" rows="4"></textarea>
dans le javascript déclarer CKeditor pour le champ textarea concerné puis serializer vos donnees:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<script>
$(document).ready(function() {
			//textarea avec editeur
			CKEDITOR.replace( 'DocuCommentaire',
				{
					toolbar : 'Basic',
				});
 
				var DocuLibelle = $( "#DocuLibelle" ),
				DocumentId =  $( "#DocumentId" ),
				DocuFichier =  $( "#DocuFichier" ),
				DocuCommentaire =  $( "#DocuCommentaire" ),
				DocuNumero =  $( "#DocuNumero" ),
				EspaceId =  $( "#EspaceId" )
			allFields = $( [] ).add( DocuLibelle ).add( DocuCommentaire ).add( DocumentId ).add( EspaceId ).add(DocuFichier).add(DocuNumero),
			tips = $( ".validate-fichier" );	
 
	});
</script>
Puis dans le submit, récupérer le contenu du CKeditor avec les 2 lignes suivantes comprenant le nom de votre textarea, ici DocuCommentaire.

Code :
1
2
		var editor = $( '#cke_contents_DocuCommentaire iframe' ).contents().find( 'body' ).html();
		$("#DocuCommentaire").val(editor);

voici un exemple complet de l'intégration de Ckeditor dans une boite UI Dialog

Code :
1
2
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<script src="ressources/javascript/jquery-1.4.4.js"></script>
<script src="ressources/javascript/jquery.ui.core.js"></script>
<script src="ressources/javascript/jquery.ui.widget.js"></script>
<script src="ressources/javascript/jquery.ui.datepicker.js"></script>
<script src="ressources/javascript/jquery.ui.datepicker-fr.js"></script>
<script src="ressources/javascript/jquery.ui.mouse.js"></script>
<script src="ressources/javascript/jquery.ui.button.js"></script>
<script src="ressources/javascript/jquery.ui.position.js"></script>
<script src="ressources/javascript/jquery.ui.dialog.js"></script>
<script src="ressources/javascript/jquery.validate.js"></script>
<script src="ressources/javascript/jquery.form.js"></script>
<script src="ressources/javascript/jquery.url.js"></script>
<script src="ressources/javascript/fileuploader.js"></script>
<script src="ressources/javascript/qunit.js"></script>
<script type="text/javascript" src="ressources/ckeditor/ckeditor.js"></script>
<style>
		div#versions-liste { width:100%; margin: 10px 0; }
		div#versions-liste table { margin: 1em 0; border-collapse: collapse; width: 100%; }
		div#versions-liste table td, div#versions-liste table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
	</style>
<script>
$(document).ready(function() {
			//textarea avec editeur
			CKEDITOR.replace( 'DocuCommentaire',
				{
					toolbar : 'Basic',
				});	
 
			//Bouton retour
		$( "#bouton-retour" ).click(function(e) {
				e.preventDefault();
				window.history.back();//retour page precedente
			});			
		//Bouton de confirmation de suppression
		$("#dialog-confirm").dialog({
		  autoOpen: false,
		  overlay: { backgroundColor: "#000", opacity: 0.5 },
		  modal: true
		});
 
	  //ouvre la boite de confirmation suppression
	  $(".supprimer").click(function(e) {
		e.preventDefault();
		var targetUrl = $(this).attr("href");
		//formulaire de boite supp
		$("#dialog-confirm").dialog({
		  buttons : {
			"Oui" : function() {
			  window.location.href = targetUrl;//envoi vers url suppression
			},
			"Non" : function() {
			  $(this).dialog("close");
			}
		  }
		});
		//ouvre la boite de confirmation suppression
		$("#dialog-confirm").dialog("open");
	  });
 
		//Datepicker
		$( "#DocuDate" ).datepicker({
			showOn: "both",
			buttonImage: "ressources/images/btn-calendrier.png",
			buttonImageOnly: true
		});	  
 
 
 
		//Ajout du fichier
 
		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}
 
		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 entre " +
					min + " et " + max + "." );
				return false;
			} else {
				return true;
			}
		}
 
		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}	
 
 
 
 
				var DocuLibelle = $( "#DocuLibelle" ),
				DocumentId =  $( "#DocumentId" ),
				DocuFichier =  $( "#DocuFichier" ),
				DocuCommentaire =  $( "#DocuCommentaire" ),
				DocuNumero =  $( "#DocuNumero" ),
				EspaceId =  $( "#EspaceId" )
			allFields = $( [] ).add( DocuLibelle ).add( DocuCommentaire ).add( DocumentId ).add( EspaceId ).add(DocuFichier).add(DocuNumero),
			tips = $( ".validate-fichier" );
 
		$( "#dialog-form-fichier" ).dialog({
			<? if(isset($_GET['DocumentId']))
			{	
			echo('autoOpen: true,');
			echo('height: 600,');
			}
			else {
			echo('autoOpen: false,');
			echo('height: 300,');
			} ?>
			width: 500,
			modal: true,
			overlay: { backgroundColor: "#000", opacity: 0.5 },			
			buttons: {
 
				"Valider": function() {
					var bValid = true;
					allFields.removeClass( "ui-state-error" );
 
					bValid = bValid && checkLength( DocuLibelle, "nom", 3, 50 );
 
					if ( bValid ) {
						$(".ajax-fichier").trigger('submit');
					}
				},
				"Annuler": function() {
					$("#dialog-form-fichier").dialog('close');
					<? if(isset($_GET['DocumentId']))
						echo('window.location.href = "espace-collaboratif-documents.php?EspaceId='.$_GET['EspaceId'].'"');
						else
						echo('window.location.reload(true);');
					?>
				}
			},
			close: function() {
					<? if(isset($_GET['DocumentId']))
						echo('window.location.href = "espace-collaboratif-documents.php?EspaceId='.$_GET['EspaceId'].'"');
						else
						echo('window.location.reload(true);');
					?>
			}
		});
 
		$(".ajax-fichier").submit(
		function(e) {
		var editor = $( '#cke_contents_DocuCommentaire iframe' ).contents().find( 'body' ).html();
		$("#DocuCommentaire").val(editor);
		var datas = $(this).serialize();          
		$.ajax({
			type: "POST",      // envoi des données en POST
			url: "espace-collaboratif-documents.php",    
			data: datas,     // sélection des champs à envoyer
			success: function() { 
				$("#dialog-form-fichier").dialog('close');
					<?  if(isset($_GET['DocumentId']))
						echo('window.location.href = "espace-collaboratif-documents.php?EspaceId='.$_GET['EspaceId'].'"');
						else
						echo('window.location.reload(true);');
					?>
			}
		});
		return false; // Pour empêcher le submit vers la page 'action'
	});
 
 
 
		//Bouton Ajouter fichier
		$( "#ajouter-fichier" )
			.click(function() {	
				$( "#dialog-form-fichier" ).dialog( "open" );
			});		
 
		/* essai FileUploader */
 
        var submitFileName, submitId;
		var  EspaceId=$("#EspaceId").val();//recupere valeur EspaceId
 
        var uploader = new qq.FileUploader({	
            element: document.getElementById('file-uploader'),
			multiple: false,
            action: 'action_upload.php',
			params: {
					EspaceId:EspaceId
			},
			maxConnections: 1,
            allowedExtensions: ['doc', 'docx', 'pdf', 'jpg', 'jpeg', 'txt', 'ppt', 'csv', 'xls', 'xlsx', 'pptx'], 
            minSizeLimit: 10,
            onSubmit: function(id, fileName){
                    submitId = id;
                    submitFileName = fileName; 
 
            },
			onComplete: function(id, fileName, responseJSON){
				//Upload unique	
				$('#file-uploader').find('.qq-upload-button').attr('style', 'display:none');			
 
				if (responseJSON.success) {
					$('#file-uploader').find('.qq-upload-failed-text').text('Chargement réussi');
					$('#file-uploader').find('.qq-upload-failed-text').attr('style', 'display:inline');
					var filename=responseJSON.fileName;
 
					$("#DocuFichier").val(filename);//Insere input hidden la valeur filename uploaded
				 }
				 else
				 {
					$('#file-uploader').find('.qq-upload-failed-text').text('Chargement échoué');
				 }
 
			},
			onCancel: function(id, fileName){
			}
        }); 
 
	});
</script>
</head>
<!--Dialog fichier!-->
<div id="dialog-form-fichier" title="<? if(isset($_GET['DocumentId'])) echo "Fichier : ".stripslashes($data_fichier['DocuLibelle']); else echo "Ajouter un Fichier";?> ">
	<p class="validate-fichier"></p>
	<form class="ajax-fichier" enctype="multipart/form-data">
	<fieldset>
	<div class="ligne-form">
		<label for="name">Libellé :</label>
		<? if(isset($_GET['DocumentId']))
		echo('<input type="text" name="DocuLibelle" id="DocuLibelle" class="input_grand" value="'.stripslashes($data_fichier['DocuLibelle']).'"/>'); 
		else
		echo('<input type="text" name="DocuLibelle" id="DocuLibelle" class="input_grand" value=""/>'); ?>
	</div>	
 
	<div class="ligne-form">
		<label for="DocuDate">Date :</label>
		<? if(isset($_GET['DocumentId']))
		echo('<input type="text" name="DocuDate" id="DocuDate" class="input_moyen" maxlength="10" onchange="date(\'DocuDate\');" onkeypress="chiffres(event);" value="'.DateExtraction($data_fichier['DocuDate']).'"/>'); 
		else
		echo('<input type="text" name="DocuDate" id="DocuDate" class="input_moyen" value=""/>'); ?>
	</div>	
	<div class="ligne-form">
		<label for="DocuCommentaire">Description :</label>
	</div>	
	<div class="ligne-form">
		<? if(isset($_GET['DocumentId']))
			echo('<textarea name="DocuCommentaire" id="DocuCommentaire" cols="30" rows="4">'.stripslashes($data_fichier['DocuCommentaire']).'</textarea>');
		else
			echo('<textarea name="DocuCommentaire" id="DocuCommentaire" cols="30" rows="4"></textarea>'); ?>
	</div>
pixworld est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 17h26.


 
 
 
 
Partenaires

Hébergement Web