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( 'checkbox', function( editor )
  6 {
  7 	return {
  8 		title : editor.lang.checkboxAndRadio.checkboxTitle,
  9 		minWidth : 400,
 10 		minHeight : 230,
 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
 19 			if ( element && element.getAttribute( 'type' ) == "checkbox" )
 20 			{
 21 				this._element = element;
 22 				this.setupContent( element );
 23 			}
 24 		},
 25 		onOk : function()
 26 		{
 27 			var editor,
 28 				element = this._element,
 29 				isInsertMode = !element;
 30
 31 			if ( isInsertMode )
 32 			{
 33 				editor = this.getParentEditor();
 34 				element = editor.document.createElement( 'input' );
 35 				element.setAttribute( 'type', 'checkbox' );
 36 			}
 37
 38 			this.commitContent( element );
 39
 40 			if ( isInsertMode )
 41 			{
 42 				this.restoreSelection();
 43 				this.clearSavedSelection();
 44 				editor.insertElement( element );
 45 			}
 46 		},
 47 		contents : [
 48 			{
 49 				id : 'info',
 50 				label : editor.lang.checkboxAndRadio.checkboxTitle,
 51 				title : editor.lang.checkboxAndRadio.checkboxTitle,
 52 				startupFocus : 'txtName',
 53 				elements : [
 54 					{
 55 						id : 'txtName',
 56 						type : 'text',
 57 						label : editor.lang.common.name,
 58 						'default' : '',
 59 						accessKey : 'N',
 60 						setup : function( element )
 61 						{
 62 							this.setValue( element.getAttribute( 'name' ) );
 63 							this.focus();
 64 						},
 65 						commit : function( element )
 66 						{
 67 							if ( this.getValue() != '' || this.isChanged() )
 68 								element.setAttribute( 'name', this.getValue() );
 69 						}
 70 					},
 71 					{
 72 						id : 'txtValue',
 73 						type : 'text',
 74 						label : editor.lang.checkboxAndRadio.value,
 75 						'default' : '',
 76 						accessKey : 'V',
 77 						setup : function( element )
 78 						{
 79 							this.setValue( element.getAttribute( 'value' ) );
 80 						},
 81 						commit : function( element )
 82 						{
 83 							if ( this.getValue() != '' || this.isChanged() )
 84 								element.setAttribute( 'value', this.getValue() );
 85 						}
 86 					},
 87 					{
 88 						id : 'cmbSelected',
 89 						type : 'checkbox',
 90 						label : editor.lang.checkboxAndRadio.selected,
 91 						'default' : '',
 92 						accessKey : 'S',
 93 						value : "checked",
 94 						setup : function( element )
 95 						{
 96 							this.setValue( element.getAttribute( 'checked' ) );
 97 						},
 98 						commit : function( element )
 99 						{
100 							if ( this.getValue() == true || this.isChanged() )
101 								element.setAttribute( 'checked', this.getValue() );
102 						}
103 					}
104 				]
105 			}
106 		]
107 	};
108 });
109