Roo/bootstrap/Slider.js
authorJulian Knowles <julian@roojs.com>
Mon, 27 Jan 2014 08:53:39 +0000 (16:53 +0800)
committerJulian Knowles <julian@roojs.com>
Mon, 27 Jan 2014 08:53:39 +0000 (16:53 +0800)
Roo/bootstrap/Slider.js

index 542624b..ddfb077 100644 (file)
 /*
  * - LGPL
  *
- * page container.
+ * row
  * 
  */
 
-
 /**
- * @class Roo.bootstrap.Container
+ * @class Roo.bootstrap.Button
  * @extends Roo.bootstrap.Component
- * Bootstrap Container class
- * @cfg {Boolean} jumbotron is it a jubmotron element
- * @cfg {String} html content of element
- *    
+ * Bootstrap Button class
+ * @cfg {String} html The button content
+ * @cfg {String} weight default (or empty) | primary | success | info | warning
+ * @cfg {String} size empty | lg | sm | xs
+ * @cfg {String} tag empty | a | input | submit
+ * @cfg {String} href empty or href
+ * @cfg {Boolean} disabled false | true
+ * @cfg {Boolean} isClose false | true
+ * @cfg {String} empty | see glyphicon reference list
+ * @cfg {String} badge text for badge
+ * 
  * @constructor
- * Create a new Container
+ * Create a new button
  * @param {Object} config The config object
  */
 
+
 Roo.bootstrap.Slider = function(config){
     Roo.bootstrap.Slider.superclass.constructor.call(this, config);
+    this.addEvents({
+        // raw events
+        /**
+         * @event click
+         * The raw click event for the entire grid.
+         * @param {Roo.EventObject} e
+         */
+        "click" : true
+    });
 };
 
 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component,  {
-       
+    
+    html: false,
+    active: false,
+    weight: '',
+    size: '',
+    tag: 'button',
+    href: '',
+    disabled: false,
+    isClose: false,
+    glyphicon: '',
+    badge: '',
+    
+    type: false,
+    ontext: 'ON',
+    offtext: 'OFF',
+    defaulton: true,
+    
     getAutoCreate : function(){
+        Roo.log("Button Parent is : " + this.parent().xtype);
         
         var cfg = {
-            tag: 'div'
+            cls: '',
+            tag : 'button',
+            html: 'hello'
+        }
+        
+        if (this.type==='switch') {
+            cfg={
+                tag: 'div',
+                cls: 'slider-frame',
+                cn: [
+                    {
+                        tag: 'span',
+                        'data-on-text':'ON',
+                        'data-off-text':'OFF',
+                        cls: 'slider-button',
+                        html: this.offtext
+                    }
+                ]
+            };
+            
+            if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
+                cfg.cls += ' '+this.weight;
+            }
+            
+            return cfg;
+        }
+        
+        
+        if (this.parent().btn&&this.parent().type=='ButtonGroup') {
+            cfg.cls='btn';
+            if (this.parentType != 'Navbar') {
+                this.weight = this.weight.length ?  this.weight : 'default';
+            }
+            if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
+                
+                cfg.cls += ' btn-' + this.weight;
+            } else {
+                
+            }
+        }
+        
+        cfg.html = this.html || cfg.html;
+        
+        if (this.isClose) {
+            cfg.cls += ' close';
+            
+            cfg["aria-hidden"] = true;
+            
+            cfg.html = "&times;";
+            
+            return cfg;
+        }
+        
+        if (this.active) {
+            cfg.cls += ' active';
+        }
+        
+        cfg.cls += this.size.length ? (' btn-' + this.size) : '';
+        
+        if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
+            throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
+            this.tag = 'button';
+        } else {
+            cfg.tag = this.tag;
+        }
+         
+        //gsRoo.log(this.parentType);
+        if (this.parentType == 'Navbar') {
+            cfg.tag = 'li';
+            
+            cfg.cls = '';
+            cfg.cn =  [{
+                tag : 'a',
+                html : this.html,
+                href : this.href || '#'
+            }];
+            if (this.menu) {
+                cfg.cn[0].html = this.html  + ' <span class="caret"></span>';
+                cfg.cls += ' dropdown';
+            }   
+            
+            delete cfg.html;
+            
+        } else if (this.menu) {
+            cfg.tag='a'
+            cfg.cls += ' dropdown test';
+        }
+        
+        
+        
+        if (this.disabled) {
+            cfg.disabled = 'disabled';
+        }
+        
+        if (this.items) {
+            Roo.log('changing to ul' );
+            cfg.tag = 'ul';
+            this.glyphicon = 'caret';
+        }
+        
+        if (this.glyphicon) {
+            cfg.html = ' ' + cfg.html;
+            
+            cfg.cn = [
+                {
+                    tag: 'span',
+                    cls: 'glyphicon glyphicon-' + this.glyphicon
+                }
+            ];
+        }
+        
+        if (this.badge) {
+            cfg.html += ' ';
+            
+            cfg.tag = 'a';
+            
+            cfg.cls='btn';
+            
+            cfg.href=this.href;
+            
+            cfg.cn = [
+                cfg.html,
+                {
+                    tag: 'span',
+                    cls: 'badge',
+                    html: this.badge
+                }
+            ]
+            
+            cfg.html='';
+        }
+        
+        if (cfg.tag !== 'a' && this.href !== '') {
+            throw "Tag must be a to set href.";
+        } else if (this.href !== '') {
+            cfg.href = this.href;
         }
         
         return cfg;
+    },
+    initEvents: function() {
+       // Roo.log('init events?');
+       // Roo.log(this.el.dom);
+        this.el.select('a',true).on('click',
+                function(e) {
+                    this.fireEvent('click', this);
+                },
+                this
+        );
     }
    
 });