1 /*
  2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
  3 For licensing, see LICENSE.html or http://ckeditor.com/license
  4 */
  5 CKEDITOR.dialog.add( 'form', function( editor )
  6 {
  7 	return {
  8 		title : editor.lang.form.title,
  9 		minWidth : 400,
 10 		minHeight : 270,
 11 		onShow : function()
 12 		{
 13 			// IE BUG: Selection must be in the editor for getSelectedElement()
 14 			// to work.
 15 			this.restoreSelection();
 16
 17 			var element = this.getParentEditor().getSelection().getSelectedElement();
 18 			if ( element && element.getName() == "form" )
 19 			{
 20 				this._element = element;
 21 				this.setupContent( element );
 22 			}
 23 		},
 24 		onOk : function()
 25 		{
 26 			var editor,
 27 				element = this._element,
 28 				isInsertMode = !element;
 29
 30 			if ( isInsertMode )
 31 			{
 32 				editor = this.getParentEditor();
 33 				element = editor.document.createElement( 'form' );
 34 				element.append( editor.document.createElement( 'br' ) );
 35 			}
 36 			this.commitContent( element );
 37
 38 			if ( isInsertMode )
 39 			{
 40 				this.restoreSelection();
 41 				this.clearSavedSelection();
 42 				editor.insertElement( element );
 43 			}
 44 		},
 45 		contents : [
 46 			{
 47 				id : 'info',
 48 				label : editor.lang.form.title,
 49 				title : editor.lang.form.title,
 50 				elements : [
 51 					{
 52 						id : 'txtName',
 53 						type : 'text',
 54 						label : editor.lang.common.name,
 55 						'default' : '',
 56 						accessKey : 'N',
 57 						setup : function( element )
 58 						{
 59 							this.setValue( element.getAttribute( 'name' ) );
 60 							this.focus();
 61 						},
 62 						commit : function( element )
 63 						{
 64 							if ( this.getValue() != '' || this.isChanged() )
 65 								element.setAttribute( 'name', this.getValue() );
 66 						}
 67 					},
 68 					{
 69 						id : 'txtAction',
 70 						type : 'text',
 71 						label : editor.lang.form.action,
 72 						'default' : '',
 73 						accessKey : 'A',
 74 						setup : function( element )
 75 						{
 76 							this.setValue( element.getAttribute( 'action' ) );
 77 						},
 78 						commit : function( element )
 79 						{
 80 							if ( this.getValue() != '' || this.isChanged() )
 81 								element.setAttribute( 'action', this.getValue() );
 82 						}
 83 					},
 84 					{
 85 						type : 'hbox',
 86 						widths : [ '45%', '55%' ],
 87 						children :
 88 						[
 89 							{
 90 								id : 'txtId',
 91 								type : 'text',
 92 								label : editor.lang.common.id,
 93 								'default' : '',
 94 								accessKey : 'I',
 95 								setup : function( element )
 96 								{
 97 									this.setValue( element.getAttribute( 'id' ) );
 98 								},
 99 								commit : function( element )
100 								{
101 									if ( this.getValue() != '' || this.isChanged() )
102 										element.setAttribute( 'id', this.getValue() );
103 								}
104 							},
105 							{
106 								id : 'cmbEncoding',
107 								type : 'select',
108 								label : editor.lang.form.encoding,
109 								style : 'width:100%',
110 								accessKey : 'E',
111 								'default' : '',
112 								items :
113 								[
114 									[ '' ],
115 									[ 'text/plain' ],
116 									[ 'multipart/form-data' ],
117 									[ 'application/x-www-form-urlencoded' ]
118 								],
119 								setup : function( element )
120 								{
121 									this.setValue( element.getAttribute( 'encoding' ) );
122 								},
123 								commit : function( element )
124 								{
125 									if ( this.getValue() != '' || this.isChanged() )
126 										element.setAttribute( 'encoding', this.getValue() );
127 								}
128 							}
129 						]
130 					},
131 					{
132 						type : 'hbox',
133 						widths : [ '45%', '55%' ],
134 						children :
135 						[
136 							{
137 								id : 'cmbTarget',
138 								type : 'select',
139 								label : editor.lang.form.target,
140 								style : 'width:100%',
141 								accessKey : 'M',
142 								'default' : '',
143 								items :
144 								[
145 									[ editor.lang.form.targetNotSet, '' ],
146 									[ editor.lang.form.targetNew, '_blank' ],
147 									[ editor.lang.form.targetTop, '_top' ],
148 									[ editor.lang.form.targetSelf, '_self' ],
149 									[ editor.lang.form.targetParent, '_parent' ]
150 								],
151 								setup : function( element )
152 								{
153 									this.setValue( element.getAttribute( 'target' ) );
154 								},
155 								commit : function( element )
156 								{
157 									if ( this.getValue() != '' || this.isChanged() )
158 										element.setAttribute( 'target', this.getValue() );
159 								}
160 							},
161 							{
162 								id : 'cmbMethod',
163 								type : 'select',
164 								label : editor.lang.form.method,
165 								accessKey : 'M',
166 								'default' : 'GET',
167 								items :
168 								[
169 									[ 'GET', 'get' ],
170 									[ 'POST', 'post' ]
171 								],
172 								setup : function( element )
173 								{
174 									this.setValue( element.getAttribute( 'method' ) );
175 								},
176 								commit : function( element )
177 								{
178 									element.setAttribute( 'method', this.getValue() );
179 								}
180 							}
181 						]
182 					}
183 				]
184 			}
185 		]
186 	};
187 });
188