-/*
- * - LGPL
- *
- * Alert
- *
- */
-
/**
* @class Roo.bootstrap.Alert
* @extends Roo.bootstrap.Component
- * Bootstrap Alert class
+ * Bootstrap Alert class - shows an alert area box
+ * eg
+ * <div class="alert alert-danger" role="alert"><span class="fa fa-exclamation-triangle"></span><span class="sr-only">Error:</span>
+ Enter a valid email address
+</div>
+ * @licence LGPL
* @cfg {String} title The title of alert
* @cfg {String} html The content of alert
- * @cfg {String} weight ( success | info | warning | danger )
- * @cfg {String} faicon font-awesomeicon
+ * @cfg {String} weight (success|info|warning|danger) Weight of the message
+ * @cfg {String} fa font-awesomeicon
+ * @cfg {Number} seconds default:-1 Number of seconds until it disapears (-1 means never.)
+ * @cfg {Boolean} close true to show a x closer
+ *
*
* @constructor
* Create a new alert
};
-Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
+Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
title: '',
html: '',
- weight: '',
- faicon: '',
+ weight: false,
+ fa: false,
+ faicon: false, // BC
+ close : false,
+
- getAutoCreate : function(){
+ getAutoCreate : function()
+ {
var cfg = {
- tag : 'button',
- cls : 'roo-button',
- html: ''
- };
-
- 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;
- }
- cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
-
- if (this.toggle == true) {
- cfg={
- tag: 'div',
- cls: 'slider-frame roo-button',
- 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.isClose) {
- cfg.cls += ' close';
-
- cfg["aria-hidden"] = true;
-
- cfg.html = "×";
-
- return cfg;
- }
-
-
- if (this.theme==='default') {
- cfg.cls = 'btn roo-button';
-
- //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 if (this.theme==='glow') {
-
- cfg.tag = 'a';
- cfg.cls = 'btn-glow roo-button';
-
- if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
-
- cfg.cls += ' ' + this.weight;
- }
- }
-
-
- if (this.inverse) {
- this.cls += ' inverse';
- }
-
-
- if (this.active) {
- cfg.cls += ' active';
- }
-
- if (this.disabled) {
- cfg.disabled = 'disabled';
- }
-
- if (this.items) {
- Roo.log('changing to ul' );
- cfg.tag = 'ul';
- this.glyphicon = 'caret';
- }
-
- cfg.cls += this.size.length ? (' btn-' + this.size) : '';
-
- //gsRoo.log(this.parentType);
- if (this.parentType === 'Navbar' && !this.parent().bar) {
- Roo.log('changing to li?');
-
- cfg.tag = 'li';
-
- cfg.cls = '';
- cfg.cn = [{
- tag : 'a',
- cls : 'roo-button',
- 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;
-
- }
-
- cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
-
- if (this.glyphicon) {
- cfg.html = ' ' + cfg.html;
-
- cfg.cn = [
+ tag : 'div',
+ cls : 'alert',
+ cn : [
{
- tag: 'span',
- cls: 'glyphicon glyphicon-' + this.glyphicon
- }
- ];
- }
-
- if (this.badge) {
- cfg.html += ' ';
-
- cfg.tag = 'a';
-
-// cfg.cls='btn roo-button';
-
- cfg.href=this.href;
-
- var value = cfg.html;
-
- if(this.glyphicon){
- value = {
- tag: 'span',
- cls: 'glyphicon glyphicon-' + this.glyphicon,
- html: this.html
- };
-
- }
-
- cfg.cn = [
- value,
+ tag: 'button',
+ type : "button",
+ cls: "close",
+ html : '×',
+ style : this.close ? '' : 'display:none'
+ },
+ {
+ tag : 'i',
+ cls : 'roo-alert-icon'
+
+ },
+ {
+ tag : 'b',
+ cls : 'roo-alert-title',
+ html : this.title
+ },
{
- tag: 'span',
- cls: 'badge',
- html: this.badge
+ tag : 'span',
+ cls : 'roo-alert-text',
+ html : this.html
}
- ];
-
- cfg.html='';
- }
-
- if (this.menu) {
- cfg.cls += ' dropdown';
- cfg.html = typeof(cfg.html) != 'undefined' ? cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
- }
+ ]
+ };
- if (cfg.tag !== 'a' && this.href !== '') {
- throw "Tag must be a to set href.";
- } else if (this.href.length > 0) {
- cfg.href = this.href;
+ if(this.faicon){
+ cfg.cn[0].cls += ' fa ' + this.faicon;
}
-
- if(this.removeClass){
- cfg.cls = '';
+ if(this.fa){
+ cfg.cn[0].cls += ' fa ' + this.fa;
}
- if(this.target){
- cfg.target = this.target;
+ if(this.weight){
+ cfg.cls += ' alert-' + this.weight;
}
return cfg;
},
- initEvents: function() {
- // Roo.log('init events?');
-// Roo.log(this.el.dom);
- // add the menu...
-
- if (typeof (this.menu) != 'undefined') {
- this.menu.parentType = this.xtype;
- this.menu.triggerEl = this.el;
- this.addxtype(Roo.apply({}, this.menu));
- }
-
-
- if (this.el.hasClass('roo-button')) {
- this.el.on('click', this.onClick, this);
- } else {
- this.el.select('.roo-button').on('click', this.onClick, this);
- }
-
- if(this.removeClass){
- this.el.on('click', this.onClick, this);
- }
-
- this.el.enableDisplayMode();
-
- },
- onClick : function(e)
+
+ initEvents: function()
{
- if (this.disabled) {
- return;
+ this.el.setVisibilityMode(Roo.Element.DISPLAY);
+ this.titleEl = this.el.select('.roo-alert-title',true).first();
+ this.iconEl = this.el.select('.roo-alert-icon',true).first();
+ this.htmlEl = this.el.select('.roo-alert-text',true).first();
+ if (this.seconds > 0) {
+ this.hide.defer(this.seconds, this);
}
-
-
- Roo.log('button on click ');
- if(this.preventDefault){
- e.preventDefault();
- }
- if (this.pressed === true || this.pressed === false) {
- this.pressed = !this.pressed;
- this.el[this.pressed ? 'addClass' : 'removeClass']('active');
- this.fireEvent('toggle', this, e, this.pressed);
- }
-
-
- this.fireEvent('click', this, e);
},
-
/**
- * Enables this button
+ * Set the Title Message HTML
+ * @param {String} html
*/
- enable : function()
+ setTitle : function(str)
{
- this.disabled = false;
- this.el.removeClass('disabled');
+ this.titleEl.dom.innerHTML = str;
},
-
- /**
- * Disable this button
+
+ /**
+ * Set the Body Message HTML
+ * @param {String} html
*/
- disable : function()
+ setHtml : function(str)
{
- this.disabled = true;
- this.el.addClass('disabled');
+ this.htmlEl.dom.innerHTML = str;
},
- /**
- * sets the active state on/off,
- * @param {Boolean} state (optional) Force a particular state
+ /**
+ * Set the Weight of the alert
+ * @param {String} (success|info|warning|danger) weight
*/
- setActive : function(v) {
+
+ setWeight : function(weight)
+ {
+ if(this.weight){
+ this.el.removeClass('alert-' + this.weight);
+ }
- this.el[v ? 'addClass' : 'removeClass']('active');
+ this.weight = weight;
+
+ this.el.addClass('alert-' + this.weight);
},
- /**
- * toggles the current active state
+ /**
+ * Set the Icon of the alert
+ * @param {String} see fontawsome names (name without the 'fa-' bit)
*/
- toggleActive : function()
+ setIcon : function(icon)
{
- var active = this.el.hasClass('active');
- this.setActive(!active);
-
+ if(this.faicon){
+ this.alertEl.removeClass(['fa', 'fa-' + this.faicon]);
+ }
+ this.faicon = icon;
+
+ this.alertEl.addClass(['fa', 'fa-' + this.faicon]);
},
- setText : function(str)
- {
- this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
- },
- getText : function()
+ /**
+ * Hide the Alert
+ */
+ hide: function()
{
- return this.el.select('.roo-button-text',true).first().dom.innerHTML;
- },
- hide: function() {
-
-
this.el.hide();
},
- show: function() {
-
+ /**
+ * Show the Alert
+ */
+ show: function()
+ {
this.el.show();
}
-
});
\ No newline at end of file