init
[Pman.Core] / widgets / ColorField.js
1 //<script type="text/javascript">
2
3
4 /**
5 * Color field
6 */
7
8
9 Roo.form.ColorField = function(config){
10     Roo.form.ColorField.superclass.constructor.call(this, config);
11  
12    
13 };
14 Roo.extend(Roo.form.ColorField, Roo.form.TriggerField , {
15      
16     defaultAutoCreate : {tag: 'input', type: 'text', size: '6',   autocomplete: 'off'},
17     validateValue : function(value){
18         this.setBgColor(value);
19         return true;
20     },
21     menuListeners : {
22         select: function(m, d){
23             this.setValue(d);
24         },
25         show : function(){ 
26             this.onFocus();
27         },
28         hide : function(){
29             this.focus.defer(10, this);
30             var ml = this.menuListeners;
31             this.menu.un('select', ml.select, this);
32             this.menu.un('show', ml.show, this);
33             this.menu.un('hide', ml.hide, this);
34         }
35     },
36     onTriggerClick : function(){
37         if(this.disabled){
38             return;
39         }
40         if(this.menu == null){
41             this.menu = new Roo.menu.ColorMenu();
42         }
43          
44         this.menu.on(Roo.apply({}, this.menuListeners, {
45             scope:this
46         }));
47         //this.menu.picker.setValue(this.getValue() || new Date());
48         this.menu.show(this.el, 'tl-bl?');
49     }, 
50     setValue: function(d) {
51         d = (typeof(d) != 'undefined') && d.length ? d : 'FFFFFF';
52         
53         Roo.form.ColorField.superclass.setValue.call(this, d);
54         this.setBgColor(d);
55     },
56     
57     setBgColor : function(d) {
58         var d = (typeof(d) != 'undefined') && d.length ? d : 'FFFFFF';
59         this.el.dom.style.background ='#' + d;
60     }
61 });