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( 'radio', function( editor )
  6 {
  7 	return {
  8 		title : editor.lang.checkboxAndRadio.radioTitle,
  9 		minWidth : 400,
 10 		minHeight : 200,
 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() == "input" && element.getAttribute( 'type' ) == "radio" )
 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( 'input' );
 34 				element.setAttribute( 'type', 'radio' );
 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.checkboxAndRadio.radioTitle,
 49 				title : editor.lang.checkboxAndRadio.radioTitle,
 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 : 'txtValue',
 70 						type : 'text',
 71 						label : editor.lang.checkboxAndRadio.value,
 72 						'default' : '',
 73 						accessKey : 'V',
 74 						setup : function( element )
 75 						{
 76 							this.setValue( element.getAttribute( 'value' ) );
 77 						},
 78 						commit : function( element )
 79 						{
 80 							if ( this.getValue() != '' || this.isChanged() )
 81 								element.setAttribute( 'value', this.getValue() );
 82 						}
 83 					},
 84 					{
 85 						id : 'cmbSelected',
 86 						type : 'checkbox',
 87 						label : editor.lang.checkboxAndRadio.selected,
 88 						'default' : '',
 89 						accessKey : 'S',
 90 						value : "checked",
 91 						setup : function( element )
 92 						{
 93 							this.setValue( element.getAttribute( 'checked' ) );
 94 						},
 95 						commit : function( element )
 96 						{
 97 							if ( this.getValue() == true || this.isChanged() )
 98 								element.setAttribute( 'checked', this.getValue() );
 99 						}
100 					}
101 				]
102 			}
103 		]
104 	};
105 });
106