more quote identeiifers fixessss
[Pman.Core] / widgets / StarField.js
1 //<script type="text/javascript">
2 /**
3  * @class Ext.form.Checkbox
4  * @extends Ext.form.Field
5  * Single checkbox field.  Can be used as a direct replacement for traditional checkbox fields.
6  * @constructor
7  * Creates a new Checkbox
8  * @param {Object} config Configuration options
9  */
10 Ext.form.StarField = function(config){
11     Ext.form.StarField.superclass.constructor.call(this, config);
12      
13 };
14
15 Ext.extend(Ext.form.StarField, Ext.form.Field,  {
16      
17      /**
18      * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
19      */
20     
21     /**
22      * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
23      */
24     focusClass : undefined,
25     /**
26      * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
27      */
28     fieldClass: 'x-form-field',
29     /**
30      * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
31      */
32     checked: false,
33     /**
34      * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
35      * {tag: "input", type: "checkbox", autocomplete: "off"})
36      */
37    // defaultAutoCreate : { tag: 'div' },
38      defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
39     /**
40      * @cfg {String} addTitle Text to include for adding a title.
41      */
42      addTitle : false,
43     //
44     onResize : function(){
45         Ext.form.Field.superclass.onResize.apply(this, arguments);
46         
47     },
48
49     initEvents : function(){
50         // Ext.form.Checkbox.superclass.initEvents.call(this);
51         // has no events...
52        
53     },
54
55
56     getResizeEl : function(){
57         return this.wrap;
58     },
59
60     getPositionEl : function(){
61         return this.wrap;
62     },
63
64     // private
65     onRender : function(ct, position){
66         
67         this.style = this.style || '';
68         var style = this.style;
69         var _this= this;
70         delete this.style;
71         
72         Ext.form.StarField.superclass.onRender.call(this, ct, position);
73         this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
74         this.viewEl = this.wrap.createChild({ tag: 'img',  src: Roo.BLANK_IMAGE_URL });
75         
76         
77         this.viewEl.applyStyles('width:60px;height:15px;margin:3px;margin-left:1px;');
78         this.viewEl.applyStyles('background-image: url(' + rootURL +'/Pman/templates/images/fivestars.gif);' );
79         
80         
81         //if(this.inputValue !== undefined){
82         //this.setValue(this.value);
83         this.viewEl.on('mouseup',  function(e) { 
84             var xy = _this.viewEl.getXY();
85             var offset = Math.floor( (e.xy[0] - xy[0]) / 12.0) +1;
86             _this.setValue(offset);
87         });
88         this.viewEl.on('mousemove',  function(e) { 
89             var xy = _this.viewEl.getXY();
90             var offset = Math.floor( (e.xy[0] - xy[0]) / 12.0) +1;
91             _this.viewEl.setStyle('background-color', '#eee');
92             _this.viewEl.setStyle('background-position', '-' + (60 - (offset * 12)) + ' 0');
93         });
94         this.viewEl.on('mouseout',  function(e) { 
95             _this.setValue(_this.value);
96            
97         });
98         
99     },
100
101     // private
102     initValue : Ext.emptyFn,
103
104     /**
105      * Returns the checked state of the checkbox.
106      * @return {Boolean} True if checked, else false
107      */
108     
109     /**
110      * Sets the value of the item. 
111      * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
112      */
113     setValue : function(v){
114         
115         v = parseInt(v);
116         
117         if (isNaN(v)) {
118             v = 0;
119         }
120         v = v < 0 ? 0 : v;
121         v = v > 5 ? 5 : v;
122         
123         this.value = v;
124         this.viewEl.setStyle('background-color', '#fff');
125         this.viewEl.setStyle('background-position', '-' + (60 - (v * 12)) + ' 0');
126         
127         
128         Roo.form.StarField.superclass.setValue.call(this, v);
129     }
130     
131      
132     
133     
134 });