4 * base class for bootstrap elements.
8 Roo.bootstrap = Roo.bootstrap || {};
10 * @class Roo.bootstrap.Component
11 * @extends Roo.Component
12 * Bootstrap Component base class
13 * @cfg {String} cls css class
14 * @cfg {String} style any extra css
15 * @cfg {Object} xattr extra attributes to add to 'element' (used by builder to store stuff.)
16 * @cfg {Boolean} can_build_overlaid True if element can be rebuild from a HTML page
17 * @cfg {string} dataId cutomer id
18 * @cfg {string} name Specifies name attribute
19 * @cfg {string} tooltip Text for the tooltip
20 * @cfg {string} container_method method to fetch parents container element (used by NavHeaderbar - getHeaderChildContainer)
23 * Do not use directly - it does not do anything..
24 * @param {Object} config The config object
29 Roo.bootstrap.Component = function(config){
30 Roo.bootstrap.Component.superclass.constructor.call(this, config);
34 * @event childrenrendered
35 * Fires when the children have been rendered..
36 * @param {Roo.bootstrap.Component} this
38 "childrenrendered" : true
47 Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent, {
50 allowDomMove : false, // to stop relocations in parent onRender...
60 * Initialize Events for the element
62 initEvents : function() { },
68 can_build_overlaid : true,
70 container_method : false,
77 // returns the parent component..
78 return Roo.ComponentMgr.get(this.parentId)
84 onRender : function(ct, position)
86 // Roo.log("Call onRender: " + this.xtype);
88 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
91 if (this.el.attr('xtype')) {
92 this.el.attr('xtypex', this.el.attr('xtype'));
93 this.el.dom.removeAttribute('xtype');
103 var cfg = Roo.apply({}, this.getAutoCreate());
105 cfg.id = this.id || Roo.id();
107 // fill in the extra attributes
108 if (this.xattr && typeof(this.xattr) =='object') {
109 for (var i in this.xattr) {
110 cfg[i] = this.xattr[i];
115 cfg.dataId = this.dataId;
119 cfg.cls = (typeof(cfg.cls) == 'undefined') ? this.cls : cfg.cls + ' ' + this.cls;
122 if (this.style) { // fixme needs to support more complex style data.
123 cfg.style = this.style;
127 cfg.name = this.name;
130 this.el = ct.createChild(cfg, position);
133 this.tooltipEl().attr('tooltip', this.tooltip);
136 if(this.tabIndex !== undefined){
137 this.el.dom.setAttribute('tabIndex', this.tabIndex);
144 * Fetch the element to add children to
145 * @return {Roo.Element} defaults to this.el
147 getChildContainer : function()
152 * Fetch the element to display the tooltip on.
153 * @return {Roo.Element} defaults to this.el
155 tooltipEl : function()
160 addxtype : function(tree,cntr)
164 cn = Roo.factory(tree);
165 //Roo.log(['addxtype', cn]);
167 cn.parentType = this.xtype; //??
168 cn.parentId = this.id;
170 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
171 if (typeof(cn.container_method) == 'string') {
172 cntr = cn.container_method;
176 var has_flexy_each = (typeof(tree['flexy:foreach']) != 'undefined');
178 var has_flexy_if = (typeof(tree['flexy:if']) != 'undefined');
180 var build_from_html = Roo.XComponent.build_from_html;
182 var is_body = (tree.xtype == 'Body') ;
184 var page_has_body = (Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body');
186 var self_cntr_el = Roo.get(this[cntr](false));
188 // do not try and build conditional elements
189 if ((has_flexy_each || has_flexy_if || this.can_build_overlaid == false ) && build_from_html) {
193 if (!has_flexy_each || !build_from_html || is_body || !page_has_body) {
194 if(!has_flexy_if || typeof(tree.name) == 'undefined' || !build_from_html || is_body || !page_has_body){
195 return this.addxtypeChild(tree,cntr, is_body);
198 var echild =self_cntr_el ? self_cntr_el.child('>*[name=' + tree.name + ']') : false;
201 return this.addxtypeChild(Roo.apply({}, tree),cntr);
204 Roo.log('skipping render');
210 if (!build_from_html) {
214 // this i think handles overlaying multiple children of the same type
215 // with the sam eelement.. - which might be buggy..
217 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
223 if (echild && echild.attr('xtype').split('.').pop() != cn.xtype) {
227 ret = this.addxtypeChild(Roo.apply({}, tree),cntr);
234 addxtypeChild : function (tree, cntr, is_body)
236 Roo.debug && Roo.log('addxtypeChild:' + cntr);
238 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
241 var has_flexy = (typeof(tree['flexy:if']) != 'undefined') ||
242 (typeof(tree['flexy:foreach']) != 'undefined');
246 skip_children = false;
247 // render the element if it's not BODY.
250 cn = Roo.factory(tree);
252 cn.parentType = this.xtype; //??
253 cn.parentId = this.id;
255 var build_from_html = Roo.XComponent.build_from_html;
258 // does the container contain child eleemnts with 'xtype' attributes.
259 // that match this xtype..
260 // note - when we render we create these as well..
261 // so we should check to see if body has xtype set.
262 if (build_from_html && Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body') {
264 var self_cntr_el = Roo.get(this[cntr](false));
265 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
267 //Roo.log(Roo.XComponent.build_from_html);
268 //Roo.log("got echild:");
271 // there is a scenario where some of the child elements are flexy:if (and all of the same type)
272 // and are not displayed -this causes this to use up the wrong element when matching.
273 // at present the only work around for this is to nest flexy:if elements in another element that is always rendered.
276 if (echild && echild.attr('xtype').split('.').pop() == cn.xtype) {
277 // Roo.log("found child for " + this.xtype +": " + echild.attr('xtype') );
283 //echild.dom.removeAttribute('xtype');
285 Roo.debug && Roo.log("MISSING " + cn.xtype + " on child of " + (this.el ? this.el.attr('xbuilderid') : 'no parent'));
286 Roo.debug && Roo.log(self_cntr_el);
287 Roo.debug && Roo.log(echild);
288 Roo.debug && Roo.log(cn);
294 // if object has flexy:if - then it may or may not be rendered.
295 if (build_from_html && has_flexy && !cn.el && cn.can_build_overlaid) {
296 // skip a flexy if element.
297 Roo.debug && Roo.log('skipping render');
298 Roo.debug && Roo.log(tree);
300 Roo.debug && Roo.log('skipping all children');
301 skip_children = true;
306 // actually if flexy:foreach is found, we really want to create
307 // multiple copies here...
309 //Roo.log(this[cntr]());
310 // some elements do not have render methods.. like the layouts...
311 cn.render && cn.render(this[cntr](true));
313 // then add the element..
321 if (typeof (tree.menu) != 'undefined') {
322 tree.menu.parentType = cn.xtype;
323 tree.menu.triggerEl = cn.el;
324 nitems.push(cn.addxtype(Roo.apply({}, tree.menu)));
328 if (!tree.items || !tree.items.length) {
330 //Roo.log(["no children", this]);
335 var items = tree.items;
338 //Roo.log(items.length);
340 if (!skip_children) {
341 for(var i =0;i < items.length;i++) {
342 // Roo.log(['add child', items[i]]);
343 nitems.push(cn.addxtype(Roo.apply({}, items[i])));
349 //Roo.log("fire childrenrendered");
351 cn.fireEvent('childrenrendered', this);
356 * Show a component - removes 'hidden' class
361 this.el.removeClass('hidden');
365 * Hide a component - adds 'hidden' class
369 if (this.el && !this.el.hasClass('hidden')) {
370 this.el.addClass('hidden');
384 * @class Roo.bootstrap.Body
385 * @extends Roo.bootstrap.Component
386 * Bootstrap Body class
390 * @param {Object} config The config object
393 Roo.bootstrap.Body = function(config){
394 Roo.bootstrap.Body.superclass.constructor.call(this, config);
395 this.el = Roo.get(document.body);
396 if (this.cls && this.cls.length) {
397 Roo.get(document.body).addClass(this.cls);
401 Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component, {
403 is_body : true,// just to make sure it's constructed?
408 onRender : function(ct, position)
410 /* Roo.log("Roo.bootstrap.Body - onRender");
411 if (this.cls && this.cls.length) {
412 Roo.get(document.body).addClass(this.cls);
432 * @class Roo.bootstrap.ButtonGroup
433 * @extends Roo.bootstrap.Component
434 * Bootstrap ButtonGroup class
435 * @cfg {String} size lg | sm | xs (default empty normal)
436 * @cfg {String} align vertical | justified (default none)
437 * @cfg {String} direction up | down (default down)
438 * @cfg {Boolean} toolbar false | true
439 * @cfg {Boolean} btn true | false
444 * @param {Object} config The config object
447 Roo.bootstrap.ButtonGroup = function(config){
448 Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config);
451 Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component, {
459 getAutoCreate : function(){
465 cfg.html = this.html || cfg.html;
476 if (['vertical','justified'].indexOf(this.align)!==-1) {
477 cfg.cls = 'btn-group-' + this.align;
479 if (this.align == 'justified') {
480 console.log(this.items);
484 if (['lg','sm','xs'].indexOf(this.size)!==-1) {
485 cfg.cls += ' btn-group-' + this.size;
488 if (this.direction == 'up') {
489 cfg.cls += ' dropup' ;
505 * @class Roo.bootstrap.Button
506 * @extends Roo.bootstrap.Component
507 * Bootstrap Button class
508 * @cfg {String} html The button content
509 * @cfg {String} weight ( primary | success | info | warning | danger | link ) default
510 * @cfg {String} size ( lg | sm | xs)
511 * @cfg {String} tag ( a | input | submit)
512 * @cfg {String} href empty or href
513 * @cfg {Boolean} disabled default false;
514 * @cfg {Boolean} isClose default false;
515 * @cfg {String} glyphicon (| adjust | align-center | align-justify | align-left | align-right | arrow-down | arrow-left | arrow-right | arrow-up | asterisk | backward | ban-circle | barcode | bell | bold | book | bookmark | briefcase | bullhorn | calendar | camera | certificate | check | chevron-down | chevron-left | chevron-right | chevron-up | circle-arrow-down | circle-arrow-left | circle-arrow-right | circle-arrow-up | cloud | cloud-download | cloud-upload | cog | collapse-down | collapse-up | comment | compressed | copyright-mark | credit-card | cutlery | dashboard | download | download-alt | earphone | edit | eject | envelope | euro | exclamation-sign | expand | export | eye-close | eye-open | facetime-video | fast-backward | fast-forward | file | film | filter | fire | flag | flash | floppy-disk | floppy-open | floppy-remove | floppy-save | floppy-saved | folder-close | folder-open | font | forward | fullscreen | gbp | gift | glass | globe | hand-down | hand-left | hand-right | hand-up | hd-video | hdd | header | headphones | heart | heart-empty | home | import | inbox | indent-left | indent-right | info-sign | italic | leaf | link | list | list-alt | lock | log-in | log-out | magnet | map-marker | minus | minus-sign | move | music | new-window | off | ok | ok-circle | ok-sign | open | paperclip | pause | pencil | phone | phone-alt | picture | plane | play | play-circle | plus | plus-sign | print | pushpin | qrcode | question-sign | random | record | refresh | registration-mark | remove | remove-circle | remove-sign | repeat | resize-full | resize-horizontal | resize-small | resize-vertical | retweet | road | save | saved | screenshot | sd-video | search | send | share | share-alt | shopping-cart | signal | sort | sort-by-alphabet | sort-by-alphabet-alt | sort-by-attributes | sort-by-attributes-alt | sort-by-order | sort-by-order-alt | sound-5-1 | sound-6-1 | sound-7-1 | sound-dolby | sound-stereo | star | star-empty | stats | step-backward | step-forward | stop | subtitles | tag | tags | tasks | text-height | text-width | th | th-large | th-list | thumbs-down | thumbs-up | time | tint | tower | transfer | trash | tree-conifer | tree-deciduous | unchecked | upload | usd | user | volume-down | volume-off | volume-up | warning-sign | wrench | zoom-in | zoom-out)
516 * @cfg {String} badge text for badge
517 * @cfg {String} theme default
518 * @cfg {Boolean} inverse
519 * @cfg {Boolean} toggle
520 * @cfg {String} ontext text for on toggle state
521 * @cfg {String} offtext text for off toggle state
522 * @cfg {Boolean} defaulton
523 * @cfg {Boolean} preventDefault default true
524 * @cfg {Boolean} removeClass remove the standard class..
525 * @cfg {String} target target for a href. (_self|_blank|_parent|_top| other)
528 * Create a new button
529 * @param {Object} config The config object
533 Roo.bootstrap.Button = function(config){
534 Roo.bootstrap.Button.superclass.constructor.call(this, config);
539 * When a butotn is pressed
540 * @param {Roo.bootstrap.Button} this
541 * @param {Roo.EventObject} e
546 * After the button has been toggles
547 * @param {Roo.EventObject} e
548 * @param {boolean} pressed (also available as button.pressed)
554 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
572 preventDefault: true,
581 getAutoCreate : function(){
589 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
590 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
595 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
597 if (this.toggle == true) {
600 cls: 'slider-frame roo-button',
605 'data-off-text':'OFF',
606 cls: 'slider-button',
612 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
613 cfg.cls += ' '+this.weight;
622 cfg["aria-hidden"] = true;
624 cfg.html = "×";
630 if (this.theme==='default') {
631 cfg.cls = 'btn roo-button';
633 //if (this.parentType != 'Navbar') {
634 this.weight = this.weight.length ? this.weight : 'default';
636 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
638 cfg.cls += ' btn-' + this.weight;
640 } else if (this.theme==='glow') {
643 cfg.cls = 'btn-glow roo-button';
645 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
647 cfg.cls += ' ' + this.weight;
653 this.cls += ' inverse';
658 cfg.cls += ' active';
662 cfg.disabled = 'disabled';
666 Roo.log('changing to ul' );
668 this.glyphicon = 'caret';
671 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
673 //gsRoo.log(this.parentType);
674 if (this.parentType === 'Navbar' && !this.parent().bar) {
675 Roo.log('changing to li?');
684 href : this.href || '#'
687 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
688 cfg.cls += ' dropdown';
695 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
697 if (this.glyphicon) {
698 cfg.html = ' ' + cfg.html;
703 cls: 'glyphicon glyphicon-' + this.glyphicon
713 // cfg.cls='btn roo-button';
717 var value = cfg.html;
722 cls: 'glyphicon glyphicon-' + this.glyphicon,
741 cfg.cls += ' dropdown';
742 cfg.html = typeof(cfg.html) != 'undefined' ? cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
745 if (cfg.tag !== 'a' && this.href !== '') {
746 throw "Tag must be a to set href.";
747 } else if (this.href.length > 0) {
748 cfg.href = this.href;
751 if(this.removeClass){
756 cfg.target = this.target;
761 initEvents: function() {
762 // Roo.log('init events?');
763 // Roo.log(this.el.dom);
766 if (typeof (this.menu) != 'undefined') {
767 this.menu.parentType = this.xtype;
768 this.menu.triggerEl = this.el;
769 this.addxtype(Roo.apply({}, this.menu));
773 if (this.el.hasClass('roo-button')) {
774 this.el.on('click', this.onClick, this);
776 this.el.select('.roo-button').on('click', this.onClick, this);
779 if(this.removeClass){
780 this.el.on('click', this.onClick, this);
783 this.el.enableDisplayMode();
786 onClick : function(e)
793 Roo.log('button on click ');
794 if(this.preventDefault){
797 if (this.pressed === true || this.pressed === false) {
798 this.pressed = !this.pressed;
799 this.el[this.pressed ? 'addClass' : 'removeClass']('active');
800 this.fireEvent('toggle', this, e, this.pressed);
804 this.fireEvent('click', this, e);
808 * Enables this button
812 this.disabled = false;
813 this.el.removeClass('disabled');
817 * Disable this button
821 this.disabled = true;
822 this.el.addClass('disabled');
825 * sets the active state on/off,
826 * @param {Boolean} state (optional) Force a particular state
828 setActive : function(v) {
830 this.el[v ? 'addClass' : 'removeClass']('active');
833 * toggles the current active state
835 toggleActive : function()
837 var active = this.el.hasClass('active');
838 this.setActive(!active);
842 setText : function(str)
844 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
848 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
871 * @class Roo.bootstrap.Column
872 * @extends Roo.bootstrap.Component
873 * Bootstrap Column class
874 * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
875 * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
876 * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
877 * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
878 * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
879 * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
880 * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
881 * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
884 * @cfg {Boolean} hidden (true|false) hide the element
885 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
886 * @cfg {String} fa (ban|check|...) font awesome icon
887 * @cfg {Number} fasize (1|2|....) font awsome size
889 * @cfg {String} icon (info-sign|check|...) glyphicon name
891 * @cfg {String} html content of column.
894 * Create a new Column
895 * @param {Object} config The config object
898 Roo.bootstrap.Column = function(config){
899 Roo.bootstrap.Column.superclass.constructor.call(this, config);
902 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, {
920 getAutoCreate : function(){
921 var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
929 ['xs','sm','md','lg'].map(function(size){
930 //Roo.log( size + ':' + settings[size]);
932 if (settings[size+'off'] !== false) {
933 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
936 if (settings[size] === false) {
940 if (!settings[size]) { // 0 = hidden
941 cfg.cls += ' hidden-' + size;
944 cfg.cls += ' col-' + size + '-' + settings[size];
949 cfg.cls += ' hidden';
952 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
953 cfg.cls +=' alert alert-' + this.alert;
957 if (this.html.length) {
958 cfg.html = this.html;
962 if (this.fasize > 1) {
963 fasize = ' fa-' + this.fasize + 'x';
965 cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
970 cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + (cfg.html || '');
989 * @class Roo.bootstrap.Container
990 * @extends Roo.bootstrap.Component
991 * Bootstrap Container class
992 * @cfg {Boolean} jumbotron is it a jumbotron element
993 * @cfg {String} html content of element
994 * @cfg {String} well (lg|sm|md) a well, large, small or medium.
995 * @cfg {String} panel (primary|success|info|warning|danger) render as panel - type - primary/success.....
996 * @cfg {String} header content of header (for panel)
997 * @cfg {String} footer content of footer (for panel)
998 * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
999 * @cfg {String} tag (header|aside|section) type of HTML tag.
1000 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1001 * @cfg {String} fa font awesome icon
1002 * @cfg {String} icon (info-sign|check|...) glyphicon name
1003 * @cfg {Boolean} hidden (true|false) hide the element
1004 * @cfg {Boolean} expandable (true|false) default false
1005 * @cfg {Boolean} expanded (true|false) default true
1006 * @cfg {String} rheader contet on the right of header
1007 * @cfg {Boolean} clickable (true|false) default false
1011 * Create a new Container
1012 * @param {Object} config The config object
1015 Roo.bootstrap.Container = function(config){
1016 Roo.bootstrap.Container.superclass.constructor.call(this, config);
1022 * After the panel has been expand
1024 * @param {Roo.bootstrap.Container} this
1029 * After the panel has been collapsed
1031 * @param {Roo.bootstrap.Container} this
1036 * When a element is chick
1037 * @param {Roo.bootstrap.Container} this
1038 * @param {Roo.EventObject} e
1044 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, {
1062 getChildContainer : function() {
1068 if (this.panel.length) {
1069 return this.el.select('.panel-body',true).first();
1076 getAutoCreate : function(){
1079 tag : this.tag || 'div',
1083 if (this.jumbotron) {
1084 cfg.cls = 'jumbotron';
1089 // - this is applied by the parent..
1091 // cfg.cls = this.cls + '';
1094 if (this.sticky.length) {
1096 var bd = Roo.get(document.body);
1097 if (!bd.hasClass('bootstrap-sticky')) {
1098 bd.addClass('bootstrap-sticky');
1099 Roo.select('html',true).setStyle('height', '100%');
1102 cfg.cls += 'bootstrap-sticky-' + this.sticky;
1106 if (this.well.length) {
1107 switch (this.well) {
1110 cfg.cls +=' well well-' +this.well;
1119 cfg.cls += ' hidden';
1123 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1124 cfg.cls +=' alert alert-' + this.alert;
1129 if (this.panel.length) {
1130 cfg.cls += ' panel panel-' + this.panel;
1132 if (this.header.length) {
1136 if(this.expandable){
1138 cfg.cls = cfg.cls + ' expandable';
1142 cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus')
1150 cls : 'panel-title',
1151 html : (this.expandable ? ' ' : '') + this.header
1155 cls: 'panel-header-right',
1161 cls : 'panel-heading',
1162 style : this.expandable ? 'cursor: pointer' : '',
1170 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1175 if (this.footer.length) {
1177 cls : 'panel-footer',
1186 body.html = this.html || cfg.html;
1187 // prefix with the icons..
1189 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1192 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1197 if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1198 cfg.cls = 'container';
1204 initEvents: function()
1206 if(this.expandable){
1207 var headerEl = this.headerEl();
1210 headerEl.on('click', this.onToggleClick, this);
1215 this.el.on('click', this.onClick, this);
1220 onToggleClick : function()
1222 var headerEl = this.headerEl();
1238 if(this.fireEvent('expand', this)) {
1240 this.expanded = true;
1242 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1244 this.el.select('.panel-body',true).first().removeClass('hide');
1246 var toggleEl = this.toggleEl();
1252 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1257 collapse : function()
1259 if(this.fireEvent('collapse', this)) {
1261 this.expanded = false;
1263 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1264 this.el.select('.panel-body',true).first().addClass('hide');
1266 var toggleEl = this.toggleEl();
1272 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1276 toggleEl : function()
1278 if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1282 return this.el.select('.panel-heading .fa',true).first();
1285 headerEl : function()
1287 if(!this.el || !this.panel.length || !this.header.length){
1291 return this.el.select('.panel-heading',true).first()
1294 titleEl : function()
1296 if(!this.el || !this.panel.length || !this.header.length){
1300 return this.el.select('.panel-title',true).first();
1303 setTitle : function(v)
1305 var titleEl = this.titleEl();
1311 titleEl.dom.innerHTML = v;
1314 getTitle : function()
1317 var titleEl = this.titleEl();
1323 return titleEl.dom.innerHTML;
1326 setRightTitle : function(v)
1328 var t = this.el.select('.panel-header-right',true).first();
1334 t.dom.innerHTML = v;
1337 onClick : function(e)
1341 this.fireEvent('click', this, e);
1355 * @class Roo.bootstrap.Img
1356 * @extends Roo.bootstrap.Component
1357 * Bootstrap Img class
1358 * @cfg {Boolean} imgResponsive false | true
1359 * @cfg {String} border rounded | circle | thumbnail
1360 * @cfg {String} src image source
1361 * @cfg {String} alt image alternative text
1362 * @cfg {String} href a tag href
1363 * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
1364 * @cfg {String} xsUrl xs image source
1365 * @cfg {String} smUrl sm image source
1366 * @cfg {String} mdUrl md image source
1367 * @cfg {String} lgUrl lg image source
1370 * Create a new Input
1371 * @param {Object} config The config object
1374 Roo.bootstrap.Img = function(config){
1375 Roo.bootstrap.Img.superclass.constructor.call(this, config);
1381 * The img click event for the img.
1382 * @param {Roo.EventObject} e
1388 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
1390 imgResponsive: true,
1400 getAutoCreate : function()
1402 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1403 return this.createSingleImg();
1408 cls: 'roo-image-responsive-group',
1413 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
1415 if(!_this[size + 'Url']){
1421 cls: (_this.imgResponsive) ? 'img-responsive' : '',
1422 html: _this.html || cfg.html,
1423 src: _this[size + 'Url']
1426 img.cls += ' roo-image-responsive-' + size;
1428 var s = ['xs', 'sm', 'md', 'lg'];
1430 s.splice(s.indexOf(size), 1);
1432 Roo.each(s, function(ss){
1433 img.cls += ' hidden-' + ss;
1436 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
1437 cfg.cls += ' img-' + _this.border;
1441 cfg.alt = _this.alt;
1454 a.target = _this.target;
1458 cfg.cn.push((_this.href) ? a : img);
1465 createSingleImg : function()
1469 cls: (this.imgResponsive) ? 'img-responsive' : '',
1471 src : 'about:blank' // just incase src get's set to undefined?!?
1474 cfg.html = this.html || cfg.html;
1476 cfg.src = this.src || cfg.src;
1478 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
1479 cfg.cls += ' img-' + this.border;
1496 a.target = this.target;
1501 return (this.href) ? a : cfg;
1504 initEvents: function()
1507 this.el.on('click', this.onClick, this);
1512 onClick : function(e)
1514 Roo.log('img onclick');
1515 this.fireEvent('click', this, e);
1529 * @class Roo.bootstrap.Link
1530 * @extends Roo.bootstrap.Component
1531 * Bootstrap Link Class
1532 * @cfg {String} alt image alternative text
1533 * @cfg {String} href a tag href
1534 * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
1535 * @cfg {String} html the content of the link.
1536 * @cfg {String} anchor name for the anchor link
1537 * @cfg {String} fa - favicon
1539 * @cfg {Boolean} preventDefault (true | false) default false
1543 * Create a new Input
1544 * @param {Object} config The config object
1547 Roo.bootstrap.Link = function(config){
1548 Roo.bootstrap.Link.superclass.constructor.call(this, config);
1554 * The img click event for the img.
1555 * @param {Roo.EventObject} e
1561 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component, {
1565 preventDefault: false,
1571 getAutoCreate : function()
1573 var html = this.html || '';
1575 if (this.fa !== false) {
1576 html = '<i class="fa fa-' + this.fa + '"></i>';
1581 // anchor's do not require html/href...
1582 if (this.anchor === false) {
1584 cfg.href = this.href || '#';
1586 cfg.name = this.anchor;
1587 if (this.html !== false || this.fa !== false) {
1590 if (this.href !== false) {
1591 cfg.href = this.href;
1595 if(this.alt !== false){
1600 if(this.target !== false) {
1601 cfg.target = this.target;
1607 initEvents: function() {
1609 if(!this.href || this.preventDefault){
1610 this.el.on('click', this.onClick, this);
1614 onClick : function(e)
1616 if(this.preventDefault){
1619 //Roo.log('img onclick');
1620 this.fireEvent('click', this, e);
1633 * @class Roo.bootstrap.Header
1634 * @extends Roo.bootstrap.Component
1635 * Bootstrap Header class
1636 * @cfg {String} html content of header
1637 * @cfg {Number} level (1|2|3|4|5|6) default 1
1640 * Create a new Header
1641 * @param {Object} config The config object
1645 Roo.bootstrap.Header = function(config){
1646 Roo.bootstrap.Header.superclass.constructor.call(this, config);
1649 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, {
1657 getAutoCreate : function(){
1662 tag: 'h' + (1 *this.level),
1663 html: this.html || ''
1675 * Ext JS Library 1.1.1
1676 * Copyright(c) 2006-2007, Ext JS, LLC.
1678 * Originally Released Under LGPL - original licence link has changed is not relivant.
1681 * <script type="text/javascript">
1685 * @class Roo.bootstrap.MenuMgr
1686 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
1689 Roo.bootstrap.MenuMgr = function(){
1690 var menus, active, groups = {}, attached = false, lastShow = new Date();
1692 // private - called when first menu is created
1695 active = new Roo.util.MixedCollection();
1696 Roo.get(document).addKeyListener(27, function(){
1697 if(active.length > 0){
1705 if(active && active.length > 0){
1706 var c = active.clone();
1716 if(active.length < 1){
1717 Roo.get(document).un("mouseup", onMouseDown);
1725 var last = active.last();
1726 lastShow = new Date();
1729 Roo.get(document).on("mouseup", onMouseDown);
1734 //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
1735 m.parentMenu.activeChild = m;
1736 }else if(last && last.isVisible()){
1737 //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
1742 function onBeforeHide(m){
1744 m.activeChild.hide();
1746 if(m.autoHideTimer){
1747 clearTimeout(m.autoHideTimer);
1748 delete m.autoHideTimer;
1753 function onBeforeShow(m){
1754 var pm = m.parentMenu;
1755 if(!pm && !m.allowOtherMenus){
1757 }else if(pm && pm.activeChild && active != m){
1758 pm.activeChild.hide();
1762 // private this should really trigger on mouseup..
1763 function onMouseDown(e){
1764 Roo.log("on Mouse Up");
1766 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
1767 Roo.log("MenuManager hideAll");
1776 function onBeforeCheck(mi, state){
1778 var g = groups[mi.group];
1779 for(var i = 0, l = g.length; i < l; i++){
1781 g[i].setChecked(false);
1790 * Hides all menus that are currently visible
1792 hideAll : function(){
1797 register : function(menu){
1801 menus[menu.id] = menu;
1802 menu.on("beforehide", onBeforeHide);
1803 menu.on("hide", onHide);
1804 menu.on("beforeshow", onBeforeShow);
1805 menu.on("show", onShow);
1807 if(g && menu.events["checkchange"]){
1811 groups[g].push(menu);
1812 menu.on("checkchange", onCheck);
1817 * Returns a {@link Roo.menu.Menu} object
1818 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
1819 * be used to generate and return a new Menu instance.
1821 get : function(menu){
1822 if(typeof menu == "string"){ // menu id
1824 }else if(menu.events){ // menu instance
1827 /*else if(typeof menu.length == 'number'){ // array of menu items?
1828 return new Roo.bootstrap.Menu({items:menu});
1829 }else{ // otherwise, must be a config
1830 return new Roo.bootstrap.Menu(menu);
1837 unregister : function(menu){
1838 delete menus[menu.id];
1839 menu.un("beforehide", onBeforeHide);
1840 menu.un("hide", onHide);
1841 menu.un("beforeshow", onBeforeShow);
1842 menu.un("show", onShow);
1844 if(g && menu.events["checkchange"]){
1845 groups[g].remove(menu);
1846 menu.un("checkchange", onCheck);
1851 registerCheckable : function(menuItem){
1852 var g = menuItem.group;
1857 groups[g].push(menuItem);
1858 menuItem.on("beforecheckchange", onBeforeCheck);
1863 unregisterCheckable : function(menuItem){
1864 var g = menuItem.group;
1866 groups[g].remove(menuItem);
1867 menuItem.un("beforecheckchange", onBeforeCheck);
1879 * @class Roo.bootstrap.Menu
1880 * @extends Roo.bootstrap.Component
1881 * Bootstrap Menu class - container for MenuItems
1882 * @cfg {String} type (dropdown|treeview|submenu) type of menu
1883 * @cfg {bool} hidden if the menu should be hidden when rendered.
1884 * @cfg {bool} stopEvent (true|false) Stop event after trigger press (default true)
1885 * @cfg {bool} isLink (true|false) the menu has link disable auto expand and collaspe (default false)
1889 * @param {Object} config The config object
1893 Roo.bootstrap.Menu = function(config){
1894 Roo.bootstrap.Menu.superclass.constructor.call(this, config);
1895 if (this.registerMenu && this.type != 'treeview') {
1896 Roo.bootstrap.MenuMgr.register(this);
1901 * Fires before this menu is displayed
1902 * @param {Roo.menu.Menu} this
1907 * Fires before this menu is hidden
1908 * @param {Roo.menu.Menu} this
1913 * Fires after this menu is displayed
1914 * @param {Roo.menu.Menu} this
1919 * Fires after this menu is hidden
1920 * @param {Roo.menu.Menu} this
1925 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
1926 * @param {Roo.menu.Menu} this
1927 * @param {Roo.menu.Item} menuItem The menu item that was clicked
1928 * @param {Roo.EventObject} e
1933 * Fires when the mouse is hovering over this menu
1934 * @param {Roo.menu.Menu} this
1935 * @param {Roo.EventObject} e
1936 * @param {Roo.menu.Item} menuItem The menu item that was clicked
1941 * Fires when the mouse exits this menu
1942 * @param {Roo.menu.Menu} this
1943 * @param {Roo.EventObject} e
1944 * @param {Roo.menu.Item} menuItem The menu item that was clicked
1949 * Fires when a menu item contained in this menu is clicked
1950 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
1951 * @param {Roo.EventObject} e
1955 this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
1958 Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component, {
1962 triggerEl : false, // is this set by component builder? -- it should really be fetched from parent()???
1965 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
1967 registerMenu : true,
1969 menuItems :false, // stores the menu items..
1979 getChildContainer : function() {
1983 getAutoCreate : function(){
1985 //if (['right'].indexOf(this.align)!==-1) {
1986 // cfg.cn[1].cls += ' pull-right'
1992 cls : 'dropdown-menu' ,
1993 style : 'z-index:1000'
1997 if (this.type === 'submenu') {
1998 cfg.cls = 'submenu active';
2000 if (this.type === 'treeview') {
2001 cfg.cls = 'treeview-menu';
2006 initEvents : function() {
2008 // Roo.log("ADD event");
2009 // Roo.log(this.triggerEl.dom);
2011 this.triggerEl.on('click', this.onTriggerClick, this);
2013 this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
2015 this.triggerEl.addClass('dropdown-toggle');
2018 this.el.on('touchstart' , this.onTouch, this);
2020 this.el.on('click' , this.onClick, this);
2022 this.el.on("mouseover", this.onMouseOver, this);
2023 this.el.on("mouseout", this.onMouseOut, this);
2027 findTargetItem : function(e)
2029 var t = e.getTarget(".dropdown-menu-item", this.el, true);
2033 //Roo.log(t); Roo.log(t.id);
2035 //Roo.log(this.menuitems);
2036 return this.menuitems.get(t.id);
2038 //return this.items.get(t.menuItemId);
2044 onTouch : function(e)
2046 Roo.log("menu.onTouch");
2047 //e.stopEvent(); this make the user popdown broken
2051 onClick : function(e)
2053 Roo.log("menu.onClick");
2055 var t = this.findTargetItem(e);
2056 if(!t || t.isContainer){
2061 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
2062 if(t == this.activeItem && t.shouldDeactivate(e)){
2063 this.activeItem.deactivate();
2064 delete this.activeItem;
2068 this.setActiveItem(t, true);
2076 Roo.log('pass click event');
2080 this.fireEvent("click", this, t, e);
2084 (function() { _this.hide(); }).defer(500);
2087 onMouseOver : function(e){
2088 var t = this.findTargetItem(e);
2091 // if(t.canActivate && !t.disabled){
2092 // this.setActiveItem(t, true);
2096 this.fireEvent("mouseover", this, e, t);
2098 isVisible : function(){
2099 return !this.hidden;
2101 onMouseOut : function(e){
2102 var t = this.findTargetItem(e);
2105 // if(t == this.activeItem && t.shouldDeactivate(e)){
2106 // this.activeItem.deactivate();
2107 // delete this.activeItem;
2110 this.fireEvent("mouseout", this, e, t);
2115 * Displays this menu relative to another element
2116 * @param {String/HTMLElement/Roo.Element} element The element to align to
2117 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
2118 * the element (defaults to this.defaultAlign)
2119 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2121 show : function(el, pos, parentMenu){
2122 this.parentMenu = parentMenu;
2126 this.fireEvent("beforeshow", this);
2127 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
2130 * Displays this menu at a specific xy position
2131 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
2132 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2134 showAt : function(xy, parentMenu, /* private: */_e){
2135 this.parentMenu = parentMenu;
2140 this.fireEvent("beforeshow", this);
2141 //xy = this.el.adjustForConstraints(xy);
2145 this.hideMenuItems();
2146 this.hidden = false;
2147 this.triggerEl.addClass('open');
2149 if(this.el.getWidth() + xy[0] > Roo.lib.Dom.getViewWidth()){
2150 xy[0] = xy[0] - this.el.getWidth() + this.triggerEl.getWidth();
2153 if(this.el.getStyle('top').slice(-1) != "%"){
2158 this.fireEvent("show", this);
2164 this.doFocus.defer(50, this);
2168 doFocus : function(){
2170 this.focusEl.focus();
2175 * Hides this menu and optionally all parent menus
2176 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
2178 hide : function(deep)
2181 this.hideMenuItems();
2182 if(this.el && this.isVisible()){
2183 this.fireEvent("beforehide", this);
2184 if(this.activeItem){
2185 this.activeItem.deactivate();
2186 this.activeItem = null;
2188 this.triggerEl.removeClass('open');;
2190 this.fireEvent("hide", this);
2192 if(deep === true && this.parentMenu){
2193 this.parentMenu.hide(true);
2197 onTriggerClick : function(e)
2199 Roo.log('trigger click');
2201 var target = e.getTarget();
2203 Roo.log(target.nodeName.toLowerCase());
2205 if(target.nodeName.toLowerCase() === 'i'){
2211 onTriggerPress : function(e)
2213 Roo.log('trigger press');
2214 //Roo.log(e.getTarget());
2215 // Roo.log(this.triggerEl.dom);
2217 // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
2218 var pel = Roo.get(e.getTarget());
2219 if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
2220 Roo.log('is treeview or dropdown?');
2224 if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
2228 if (this.isVisible()) {
2233 this.show(this.triggerEl, false, false);
2236 if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
2243 hideMenuItems : function()
2245 Roo.log("hide Menu Items");
2249 //$(backdrop).remove()
2250 this.el.select('.open',true).each(function(aa) {
2252 aa.removeClass('open');
2253 //var parent = getParent($(this))
2254 //var relatedTarget = { relatedTarget: this }
2256 //$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
2257 //if (e.isDefaultPrevented()) return
2258 //$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
2261 addxtypeChild : function (tree, cntr) {
2262 var comp= Roo.bootstrap.Menu.superclass.addxtypeChild.call(this, tree, cntr);
2264 this.menuitems.add(comp);
2285 * @class Roo.bootstrap.MenuItem
2286 * @extends Roo.bootstrap.Component
2287 * Bootstrap MenuItem class
2288 * @cfg {String} html the menu label
2289 * @cfg {String} href the link
2290 * @cfg {Boolean} preventDefault do not trigger A href on clicks.
2291 * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
2292 * @cfg {Boolean} active used on sidebars to highlight active itesm
2293 * @cfg {String} fa favicon to show on left of menu item.
2294 * @cfg {Roo.bootsrap.Menu} menu the child menu.
2298 * Create a new MenuItem
2299 * @param {Object} config The config object
2303 Roo.bootstrap.MenuItem = function(config){
2304 Roo.bootstrap.MenuItem.superclass.constructor.call(this, config);
2309 * The raw click event for the entire grid.
2310 * @param {Roo.bootstrap.MenuItem} this
2311 * @param {Roo.EventObject} e
2317 Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component, {
2321 preventDefault: true,
2322 isContainer : false,
2326 getAutoCreate : function(){
2328 if(this.isContainer){
2331 cls: 'dropdown-menu-item'
2345 if (this.fa !== false) {
2348 cls : 'fa fa-' + this.fa
2357 cls: 'dropdown-menu-item',
2360 if (this.parent().type == 'treeview') {
2361 cfg.cls = 'treeview-menu';
2364 cfg.cls += ' active';
2369 anc.href = this.href || cfg.cn[0].href ;
2370 ctag.html = this.html || cfg.cn[0].html ;
2374 initEvents: function()
2376 if (this.parent().type == 'treeview') {
2377 this.el.select('a').on('click', this.onClick, this);
2380 this.menu.parentType = this.xtype;
2381 this.menu.triggerEl = this.el;
2382 this.menu = this.addxtype(Roo.apply({}, this.menu));
2386 onClick : function(e)
2388 Roo.log('item on click ');
2389 //if(this.preventDefault){
2390 // e.preventDefault();
2392 //this.parent().hideMenuItems();
2394 this.fireEvent('click', this, e);
2413 * @class Roo.bootstrap.MenuSeparator
2414 * @extends Roo.bootstrap.Component
2415 * Bootstrap MenuSeparator class
2418 * Create a new MenuItem
2419 * @param {Object} config The config object
2423 Roo.bootstrap.MenuSeparator = function(config){
2424 Roo.bootstrap.MenuSeparator.superclass.constructor.call(this, config);
2427 Roo.extend(Roo.bootstrap.MenuSeparator, Roo.bootstrap.Component, {
2429 getAutoCreate : function(){
2448 * @class Roo.bootstrap.Modal
2449 * @extends Roo.bootstrap.Component
2450 * Bootstrap Modal class
2451 * @cfg {String} title Title of dialog
2452 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
2453 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
2454 * @cfg {Boolean} specificTitle default false
2455 * @cfg {Array} buttons Array of buttons or standard button set..
2456 * @cfg {String} buttonPosition (left|right|center) default right
2457 * @cfg {Boolean} animate default true
2458 * @cfg {Boolean} allow_close default true
2459 * @cfg {Boolean} fitwindow default true
2463 * Create a new Modal Dialog
2464 * @param {Object} config The config object
2467 Roo.bootstrap.Modal = function(config){
2468 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
2473 * The raw btnclick event for the button
2474 * @param {Roo.EventObject} e
2478 this.buttons = this.buttons || [];
2481 this.tmpl = Roo.factory(this.tmpl);
2486 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
2488 title : 'test dialog',
2498 specificTitle: false,
2500 buttonPosition: 'right',
2517 onRender : function(ct, position)
2519 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
2522 var cfg = Roo.apply({}, this.getAutoCreate());
2525 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
2527 //if (!cfg.name.length) {
2531 cfg.cls += ' ' + this.cls;
2534 cfg.style = this.style;
2536 this.el = Roo.get(document.body).createChild(cfg, position);
2538 //var type = this.el.dom.type;
2541 if(this.tabIndex !== undefined){
2542 this.el.dom.setAttribute('tabIndex', this.tabIndex);
2545 this.dialogEl = this.el.select('.modal-dialog',true).first();
2546 this.bodyEl = this.el.select('.modal-body',true).first();
2547 this.closeEl = this.el.select('.modal-header .close', true).first();
2548 this.footerEl = this.el.select('.modal-footer',true).first();
2549 this.titleEl = this.el.select('.modal-title',true).first();
2553 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2554 this.maskEl.enableDisplayMode("block");
2556 //this.el.addClass("x-dlg-modal");
2558 if (this.buttons.length) {
2559 Roo.each(this.buttons, function(bb) {
2560 var b = Roo.apply({}, bb);
2561 b.xns = b.xns || Roo.bootstrap;
2562 b.xtype = b.xtype || 'Button';
2563 if (typeof(b.listeners) == 'undefined') {
2564 b.listeners = { click : this.onButtonClick.createDelegate(this) };
2567 var btn = Roo.factory(b);
2569 btn.render(this.el.select('.modal-footer div').first());
2573 // render the children.
2576 if(typeof(this.items) != 'undefined'){
2577 var items = this.items;
2580 for(var i =0;i < items.length;i++) {
2581 nitems.push(this.addxtype(Roo.apply({}, items[i])));
2585 this.items = nitems;
2587 // where are these used - they used to be body/close/footer
2591 //this.el.addClass([this.fieldClass, this.cls]);
2595 getAutoCreate : function(){
2600 html : this.html || ''
2605 cls : 'modal-title',
2609 if(this.specificTitle){
2615 if (this.allow_close) {
2626 style : 'display: none',
2629 cls: "modal-dialog",
2632 cls : "modal-content",
2635 cls : 'modal-header',
2640 cls : 'modal-footer',
2644 cls: 'btn-' + this.buttonPosition
2661 modal.cls += ' fade';
2667 getChildContainer : function() {
2672 getButtonContainer : function() {
2673 return this.el.select('.modal-footer div',true).first();
2676 initEvents : function()
2678 if (this.allow_close) {
2679 this.closeEl.on('click', this.hide, this);
2681 Roo.EventManager.onWindowResize(this.resize, this, true);
2688 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2689 if (this.fitwindow) {
2690 var w = this.width || Roo.lib.Dom.getViewportWidth(true) - 30;
2691 var h = this.height || Roo.lib.Dom.getViewportHeight(true) - 30;
2696 setSize : function(w,h)
2706 if (!this.rendered) {
2710 this.el.setStyle('display', 'block');
2712 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
2715 this.el.addClass('in');
2718 this.el.addClass('in');
2722 // not sure how we can show data in here..
2724 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
2727 Roo.get(document.body).addClass("x-body-masked");
2728 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2730 this.el.setStyle('zIndex', '10001');
2732 this.fireEvent('show', this);
2733 this.items.forEach(function(e) {
2734 e.layout ? e.layout() : false;
2745 Roo.get(document.body).removeClass("x-body-masked");
2746 this.el.removeClass('in');
2747 this.el.select('.modal-dialog', true).first().setStyle('transform','');
2749 if(this.animate){ // why
2751 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
2753 this.el.setStyle('display', 'none');
2756 this.fireEvent('hide', this);
2759 addButton : function(str, cb)
2763 var b = Roo.apply({}, { html : str } );
2764 b.xns = b.xns || Roo.bootstrap;
2765 b.xtype = b.xtype || 'Button';
2766 if (typeof(b.listeners) == 'undefined') {
2767 b.listeners = { click : cb.createDelegate(this) };
2770 var btn = Roo.factory(b);
2772 btn.render(this.el.select('.modal-footer div').first());
2778 setDefaultButton : function(btn)
2780 //this.el.select('.modal-footer').()
2784 resizeTo: function(w,h)
2788 this.dialogEl.setWidth(w);
2789 if (this.diff === false) {
2790 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
2793 this.bodyEl.setHeight(h-this.diff);
2797 setContentSize : function(w, h)
2801 onButtonClick: function(btn,e)
2804 this.fireEvent('btnclick', btn.name, e);
2807 * Set the title of the Dialog
2808 * @param {String} str new Title
2810 setTitle: function(str) {
2811 this.titleEl.dom.innerHTML = str;
2814 * Set the body of the Dialog
2815 * @param {String} str new Title
2817 setBody: function(str) {
2818 this.bodyEl.dom.innerHTML = str;
2821 * Set the body of the Dialog using the template
2822 * @param {Obj} data - apply this data to the template and replace the body contents.
2824 applyBody: function(obj)
2827 Roo.log("Error - using apply Body without a template");
2830 this.tmpl.overwrite(this.bodyEl, obj);
2836 Roo.apply(Roo.bootstrap.Modal, {
2838 * Button config that displays a single OK button
2847 * Button config that displays Yes and No buttons
2863 * Button config that displays OK and Cancel buttons
2878 * Button config that displays Yes, No and Cancel buttons
2901 * messagebox - can be used as a replace
2905 * @class Roo.MessageBox
2906 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
2910 Roo.Msg.alert('Status', 'Changes saved successfully.');
2912 // Prompt for user data:
2913 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
2915 // process text value...
2919 // Show a dialog using config options:
2921 title:'Save Changes?',
2922 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
2923 buttons: Roo.Msg.YESNOCANCEL,
2930 Roo.bootstrap.MessageBox = function(){
2931 var dlg, opt, mask, waitTimer;
2932 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
2933 var buttons, activeTextEl, bwidth;
2937 var handleButton = function(button){
2939 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
2943 var handleHide = function(){
2945 dlg.el.removeClass(opt.cls);
2948 // Roo.TaskMgr.stop(waitTimer);
2949 // waitTimer = null;
2954 var updateButtons = function(b){
2957 buttons["ok"].hide();
2958 buttons["cancel"].hide();
2959 buttons["yes"].hide();
2960 buttons["no"].hide();
2961 //dlg.footer.dom.style.display = 'none';
2964 dlg.footerEl.dom.style.display = '';
2965 for(var k in buttons){
2966 if(typeof buttons[k] != "function"){
2969 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
2970 width += buttons[k].el.getWidth()+15;
2980 var handleEsc = function(d, k, e){
2981 if(opt && opt.closable !== false){
2991 * Returns a reference to the underlying {@link Roo.BasicDialog} element
2992 * @return {Roo.BasicDialog} The BasicDialog element
2994 getDialog : function(){
2996 dlg = new Roo.bootstrap.Modal( {
2999 //constraintoviewport:false,
3001 //collapsible : false,
3006 //buttonAlign:"center",
3007 closeClick : function(){
3008 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
3011 handleButton("cancel");
3016 dlg.on("hide", handleHide);
3018 //dlg.addKeyListener(27, handleEsc);
3020 this.buttons = buttons;
3021 var bt = this.buttonText;
3022 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
3023 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
3024 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
3025 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
3027 bodyEl = dlg.bodyEl.createChild({
3029 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
3030 '<textarea class="roo-mb-textarea"></textarea>' +
3031 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
3033 msgEl = bodyEl.dom.firstChild;
3034 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
3035 textboxEl.enableDisplayMode();
3036 textboxEl.addKeyListener([10,13], function(){
3037 if(dlg.isVisible() && opt && opt.buttons){
3040 }else if(opt.buttons.yes){
3041 handleButton("yes");
3045 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
3046 textareaEl.enableDisplayMode();
3047 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
3048 progressEl.enableDisplayMode();
3049 var pf = progressEl.dom.firstChild;
3051 pp = Roo.get(pf.firstChild);
3052 pp.setHeight(pf.offsetHeight);
3060 * Updates the message box body text
3061 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
3062 * the XHTML-compliant non-breaking space character '&#160;')
3063 * @return {Roo.MessageBox} This message box
3065 updateText : function(text){
3066 if(!dlg.isVisible() && !opt.width){
3067 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
3069 msgEl.innerHTML = text || ' ';
3071 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
3072 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
3074 Math.min(opt.width || cw , this.maxWidth),
3075 Math.max(opt.minWidth || this.minWidth, bwidth)
3078 activeTextEl.setWidth(w);
3080 if(dlg.isVisible()){
3081 dlg.fixedcenter = false;
3083 // to big, make it scroll. = But as usual stupid IE does not support
3086 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
3087 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
3088 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
3090 bodyEl.dom.style.height = '';
3091 bodyEl.dom.style.overflowY = '';
3094 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
3096 bodyEl.dom.style.overflowX = '';
3099 dlg.setContentSize(w, bodyEl.getHeight());
3100 if(dlg.isVisible()){
3101 dlg.fixedcenter = true;
3107 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
3108 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
3109 * @param {Number} value Any number between 0 and 1 (e.g., .5)
3110 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
3111 * @return {Roo.MessageBox} This message box
3113 updateProgress : function(value, text){
3115 this.updateText(text);
3117 if (pp) { // weird bug on my firefox - for some reason this is not defined
3118 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
3124 * Returns true if the message box is currently displayed
3125 * @return {Boolean} True if the message box is visible, else false
3127 isVisible : function(){
3128 return dlg && dlg.isVisible();
3132 * Hides the message box if it is displayed
3135 if(this.isVisible()){
3141 * Displays a new message box, or reinitializes an existing message box, based on the config options
3142 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
3143 * The following config object properties are supported:
3145 Property Type Description
3146 ---------- --------------- ------------------------------------------------------------------------------------
3147 animEl String/Element An id or Element from which the message box should animate as it opens and
3148 closes (defaults to undefined)
3149 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
3150 cancel:'Bar'}), or false to not show any buttons (defaults to false)
3151 closable Boolean False to hide the top-right close button (defaults to true). Note that
3152 progress and wait dialogs will ignore this property and always hide the
3153 close button as they can only be closed programmatically.
3154 cls String A custom CSS class to apply to the message box element
3155 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
3156 displayed (defaults to 75)
3157 fn Function A callback function to execute after closing the dialog. The arguments to the
3158 function will be btn (the name of the button that was clicked, if applicable,
3159 e.g. "ok"), and text (the value of the active text field, if applicable).
3160 Progress and wait dialogs will ignore this option since they do not respond to
3161 user actions and can only be closed programmatically, so any required function
3162 should be called by the same code after it closes the dialog.
3163 icon String A CSS class that provides a background image to be used as an icon for
3164 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
3165 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
3166 minWidth Number The minimum width in pixels of the message box (defaults to 100)
3167 modal Boolean False to allow user interaction with the page while the message box is
3168 displayed (defaults to true)
3169 msg String A string that will replace the existing message box body text (defaults
3170 to the XHTML-compliant non-breaking space character ' ')
3171 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
3172 progress Boolean True to display a progress bar (defaults to false)
3173 progressText String The text to display inside the progress bar if progress = true (defaults to '')
3174 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
3175 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
3176 title String The title text
3177 value String The string value to set into the active textbox element if displayed
3178 wait Boolean True to display a progress bar (defaults to false)
3179 width Number The width of the dialog in pixels
3186 msg: 'Please enter your address:',
3188 buttons: Roo.MessageBox.OKCANCEL,
3191 animEl: 'addAddressBtn'
3194 * @param {Object} config Configuration options
3195 * @return {Roo.MessageBox} This message box
3197 show : function(options)
3200 // this causes nightmares if you show one dialog after another
3201 // especially on callbacks..
3203 if(this.isVisible()){
3206 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
3207 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
3208 Roo.log("New Dialog Message:" + options.msg )
3209 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
3210 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
3213 var d = this.getDialog();
3215 d.setTitle(opt.title || " ");
3216 d.closeEl.setDisplayed(opt.closable !== false);
3217 activeTextEl = textboxEl;
3218 opt.prompt = opt.prompt || (opt.multiline ? true : false);
3223 textareaEl.setHeight(typeof opt.multiline == "number" ?
3224 opt.multiline : this.defaultTextHeight);
3225 activeTextEl = textareaEl;
3234 progressEl.setDisplayed(opt.progress === true);
3235 this.updateProgress(0);
3236 activeTextEl.dom.value = opt.value || "";
3238 dlg.setDefaultButton(activeTextEl);
3240 var bs = opt.buttons;
3244 }else if(bs && bs.yes){
3245 db = buttons["yes"];
3247 dlg.setDefaultButton(db);
3249 bwidth = updateButtons(opt.buttons);
3250 this.updateText(opt.msg);
3252 d.el.addClass(opt.cls);
3254 d.proxyDrag = opt.proxyDrag === true;
3255 d.modal = opt.modal !== false;
3256 d.mask = opt.modal !== false ? mask : false;
3258 // force it to the end of the z-index stack so it gets a cursor in FF
3259 document.body.appendChild(dlg.el.dom);
3260 d.animateTarget = null;
3261 d.show(options.animEl);
3267 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
3268 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
3269 * and closing the message box when the process is complete.
3270 * @param {String} title The title bar text
3271 * @param {String} msg The message box body text
3272 * @return {Roo.MessageBox} This message box
3274 progress : function(title, msg){
3281 minWidth: this.minProgressWidth,
3288 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
3289 * If a callback function is passed it will be called after the user clicks the button, and the
3290 * id of the button that was clicked will be passed as the only parameter to the callback
3291 * (could also be the top-right close button).
3292 * @param {String} title The title bar text
3293 * @param {String} msg The message box body text
3294 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3295 * @param {Object} scope (optional) The scope of the callback function
3296 * @return {Roo.MessageBox} This message box
3298 alert : function(title, msg, fn, scope){
3311 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
3312 * interaction while waiting for a long-running process to complete that does not have defined intervals.
3313 * You are responsible for closing the message box when the process is complete.
3314 * @param {String} msg The message box body text
3315 * @param {String} title (optional) The title bar text
3316 * @return {Roo.MessageBox} This message box
3318 wait : function(msg, title){
3329 waitTimer = Roo.TaskMgr.start({
3331 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
3339 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
3340 * If a callback function is passed it will be called after the user clicks either button, and the id of the
3341 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
3342 * @param {String} title The title bar text
3343 * @param {String} msg The message box body text
3344 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3345 * @param {Object} scope (optional) The scope of the callback function
3346 * @return {Roo.MessageBox} This message box
3348 confirm : function(title, msg, fn, scope){
3352 buttons: this.YESNO,
3361 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
3362 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
3363 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
3364 * (could also be the top-right close button) and the text that was entered will be passed as the two
3365 * parameters to the callback.
3366 * @param {String} title The title bar text
3367 * @param {String} msg The message box body text
3368 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3369 * @param {Object} scope (optional) The scope of the callback function
3370 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
3371 * property, or the height in pixels to create the textbox (defaults to false / single-line)
3372 * @return {Roo.MessageBox} This message box
3374 prompt : function(title, msg, fn, scope, multiline){
3378 buttons: this.OKCANCEL,
3383 multiline: multiline,
3390 * Button config that displays a single OK button
3395 * Button config that displays Yes and No buttons
3398 YESNO : {yes:true, no:true},
3400 * Button config that displays OK and Cancel buttons
3403 OKCANCEL : {ok:true, cancel:true},
3405 * Button config that displays Yes, No and Cancel buttons
3408 YESNOCANCEL : {yes:true, no:true, cancel:true},
3411 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
3414 defaultTextHeight : 75,
3416 * The maximum width in pixels of the message box (defaults to 600)
3421 * The minimum width in pixels of the message box (defaults to 100)
3426 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
3427 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
3430 minProgressWidth : 250,
3432 * An object containing the default button text strings that can be overriden for localized language support.
3433 * Supported properties are: ok, cancel, yes and no.
3434 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
3447 * Shorthand for {@link Roo.MessageBox}
3449 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
3450 Roo.Msg = Roo.Msg || Roo.MessageBox;
3459 * @class Roo.bootstrap.Navbar
3460 * @extends Roo.bootstrap.Component
3461 * Bootstrap Navbar class
3464 * Create a new Navbar
3465 * @param {Object} config The config object
3469 Roo.bootstrap.Navbar = function(config){
3470 Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
3474 * @event beforetoggle
3475 * Fire before toggle the menu
3476 * @param {Roo.EventObject} e
3478 "beforetoggle" : true
3482 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component, {
3491 getAutoCreate : function(){
3494 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
3498 initEvents :function ()
3500 //Roo.log(this.el.select('.navbar-toggle',true));
3501 this.el.select('.navbar-toggle',true).on('click', function() {
3502 if(this.fireEvent('beforetoggle', this) !== false){
3503 this.el.select('.navbar-collapse',true).toggleClass('in');
3513 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
3515 var size = this.el.getSize();
3516 this.maskEl.setSize(size.width, size.height);
3517 this.maskEl.enableDisplayMode("block");
3526 getChildContainer : function()
3528 if (this.el.select('.collapse').getCount()) {
3529 return this.el.select('.collapse',true).first();
3562 * @class Roo.bootstrap.NavSimplebar
3563 * @extends Roo.bootstrap.Navbar
3564 * Bootstrap Sidebar class
3566 * @cfg {Boolean} inverse is inverted color
3568 * @cfg {String} type (nav | pills | tabs)
3569 * @cfg {Boolean} arrangement stacked | justified
3570 * @cfg {String} align (left | right) alignment
3572 * @cfg {Boolean} main (true|false) main nav bar? default false
3573 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
3575 * @cfg {String} tag (header|footer|nav|div) default is nav
3581 * Create a new Sidebar
3582 * @param {Object} config The config object
3586 Roo.bootstrap.NavSimplebar = function(config){
3587 Roo.bootstrap.NavSimplebar.superclass.constructor.call(this, config);
3590 Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar, {
3606 getAutoCreate : function(){
3610 tag : this.tag || 'div',
3623 this.type = this.type || 'nav';
3624 if (['tabs','pills'].indexOf(this.type)!==-1) {
3625 cfg.cn[0].cls += ' nav-' + this.type
3629 if (this.type!=='nav') {
3630 Roo.log('nav type must be nav/tabs/pills')
3632 cfg.cn[0].cls += ' navbar-nav'
3638 if (['stacked','justified'].indexOf(this.arrangement)!==-1) {
3639 cfg.cn[0].cls += ' nav-' + this.arrangement;
3643 if (this.align === 'right') {
3644 cfg.cn[0].cls += ' navbar-right';
3648 cfg.cls += ' navbar-inverse';
3675 * @class Roo.bootstrap.NavHeaderbar
3676 * @extends Roo.bootstrap.NavSimplebar
3677 * Bootstrap Sidebar class
3679 * @cfg {String} brand what is brand
3680 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
3681 * @cfg {String} brand_href href of the brand
3682 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
3683 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
3684 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
3685 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
3688 * Create a new Sidebar
3689 * @param {Object} config The config object
3693 Roo.bootstrap.NavHeaderbar = function(config){
3694 Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
3698 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar, {
3705 desktopCenter : false,
3708 getAutoCreate : function(){
3711 tag: this.nav || 'nav',
3718 if (this.desktopCenter) {
3719 cn.push({cls : 'container', cn : []});
3726 cls: 'navbar-header',
3731 cls: 'navbar-toggle',
3732 'data-toggle': 'collapse',
3737 html: 'Toggle navigation'
3759 cls: 'collapse navbar-collapse',
3763 cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
3765 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
3766 cfg.cls += ' navbar-' + this.position;
3768 // tag can override this..
3770 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
3773 if (this.brand !== '') {
3776 href: this.brand_href ? this.brand_href : '#',
3777 cls: 'navbar-brand',
3785 cfg.cls += ' main-nav';
3793 getHeaderChildContainer : function()
3795 if (this.srButton && this.el.select('.navbar-header').getCount()) {
3796 return this.el.select('.navbar-header',true).first();
3799 return this.getChildContainer();
3803 initEvents : function()
3805 Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
3807 if (this.autohide) {
3812 Roo.get(document).on('scroll',function(e) {
3813 var ns = Roo.get(document).getScroll().top;
3814 var os = prevScroll;
3818 ft.removeClass('slideDown');
3819 ft.addClass('slideUp');
3822 ft.removeClass('slideUp');
3823 ft.addClass('slideDown');
3844 * @class Roo.bootstrap.NavSidebar
3845 * @extends Roo.bootstrap.Navbar
3846 * Bootstrap Sidebar class
3849 * Create a new Sidebar
3850 * @param {Object} config The config object
3854 Roo.bootstrap.NavSidebar = function(config){
3855 Roo.bootstrap.NavSidebar.superclass.constructor.call(this, config);
3858 Roo.extend(Roo.bootstrap.NavSidebar, Roo.bootstrap.Navbar, {
3860 sidebar : true, // used by Navbar Item and NavbarGroup at present...
3862 getAutoCreate : function(){
3867 cls: 'sidebar sidebar-nav'
3889 * @class Roo.bootstrap.NavGroup
3890 * @extends Roo.bootstrap.Component
3891 * Bootstrap NavGroup class
3892 * @cfg {String} align (left|right)
3893 * @cfg {Boolean} inverse
3894 * @cfg {String} type (nav|pills|tab) default nav
3895 * @cfg {String} navId - reference Id for navbar.
3899 * Create a new nav group
3900 * @param {Object} config The config object
3903 Roo.bootstrap.NavGroup = function(config){
3904 Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
3907 Roo.bootstrap.NavGroup.register(this);
3911 * Fires when the active item changes
3912 * @param {Roo.bootstrap.NavGroup} this
3913 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
3914 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
3921 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
3932 getAutoCreate : function()
3934 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
3941 if (['tabs','pills'].indexOf(this.type)!==-1) {
3942 cfg.cls += ' nav-' + this.type
3944 if (this.type!=='nav') {
3945 Roo.log('nav type must be nav/tabs/pills')
3947 cfg.cls += ' navbar-nav'
3950 if (this.parent().sidebar) {
3953 cls: 'dashboard-menu sidebar-menu'
3959 if (this.form === true) {
3965 if (this.align === 'right') {
3966 cfg.cls += ' navbar-right';
3968 cfg.cls += ' navbar-left';
3972 if (this.align === 'right') {
3973 cfg.cls += ' navbar-right';
3977 cfg.cls += ' navbar-inverse';
3985 * sets the active Navigation item
3986 * @param {Roo.bootstrap.NavItem} the new current navitem
3988 setActiveItem : function(item)
3991 Roo.each(this.navItems, function(v){
3996 v.setActive(false, true);
4003 item.setActive(true, true);
4004 this.fireEvent('changed', this, item, prev);
4009 * gets the active Navigation item
4010 * @return {Roo.bootstrap.NavItem} the current navitem
4012 getActive : function()
4016 Roo.each(this.navItems, function(v){
4027 indexOfNav : function()
4031 Roo.each(this.navItems, function(v,i){
4042 * adds a Navigation item
4043 * @param {Roo.bootstrap.NavItem} the navitem to add
4045 addItem : function(cfg)
4047 var cn = new Roo.bootstrap.NavItem(cfg);
4049 cn.parentId = this.id;
4050 cn.onRender(this.el, null);
4054 * register a Navigation item
4055 * @param {Roo.bootstrap.NavItem} the navitem to add
4057 register : function(item)
4059 this.navItems.push( item);
4060 item.navId = this.navId;
4065 * clear all the Navigation item
4068 clearAll : function()
4071 this.el.dom.innerHTML = '';
4074 getNavItem: function(tabId)
4077 Roo.each(this.navItems, function(e) {
4078 if (e.tabId == tabId) {
4088 setActiveNext : function()
4090 var i = this.indexOfNav(this.getActive());
4091 if (i > this.navItems.length) {
4094 this.setActiveItem(this.navItems[i+1]);
4096 setActivePrev : function()
4098 var i = this.indexOfNav(this.getActive());
4102 this.setActiveItem(this.navItems[i-1]);
4104 clearWasActive : function(except) {
4105 Roo.each(this.navItems, function(e) {
4106 if (e.tabId != except.tabId && e.was_active) {
4107 e.was_active = false;
4114 getWasActive : function ()
4117 Roo.each(this.navItems, function(e) {
4132 Roo.apply(Roo.bootstrap.NavGroup, {
4136 * register a Navigation Group
4137 * @param {Roo.bootstrap.NavGroup} the navgroup to add
4139 register : function(navgrp)
4141 this.groups[navgrp.navId] = navgrp;
4145 * fetch a Navigation Group based on the navigation ID
4146 * @param {string} the navgroup to add
4147 * @returns {Roo.bootstrap.NavGroup} the navgroup
4149 get: function(navId) {
4150 if (typeof(this.groups[navId]) == 'undefined') {
4152 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
4154 return this.groups[navId] ;
4169 * @class Roo.bootstrap.NavItem
4170 * @extends Roo.bootstrap.Component
4171 * Bootstrap Navbar.NavItem class
4172 * @cfg {String} href link to
4173 * @cfg {String} html content of button
4174 * @cfg {String} badge text inside badge
4175 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
4176 * @cfg {String} glyphicon name of glyphicon
4177 * @cfg {String} icon name of font awesome icon
4178 * @cfg {Boolean} active Is item active
4179 * @cfg {Boolean} disabled Is item disabled
4181 * @cfg {Boolean} preventDefault (true | false) default false
4182 * @cfg {String} tabId the tab that this item activates.
4183 * @cfg {String} tagtype (a|span) render as a href or span?
4184 * @cfg {Boolean} animateRef (true|false) link to element default false
4187 * Create a new Navbar Item
4188 * @param {Object} config The config object
4190 Roo.bootstrap.NavItem = function(config){
4191 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
4196 * The raw click event for the entire grid.
4197 * @param {Roo.EventObject} e
4202 * Fires when the active item active state changes
4203 * @param {Roo.bootstrap.NavItem} this
4204 * @param {boolean} state the new state
4210 * Fires when scroll to element
4211 * @param {Roo.bootstrap.NavItem} this
4212 * @param {Object} options
4213 * @param {Roo.EventObject} e
4221 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
4229 preventDefault : false,
4236 getAutoCreate : function(){
4245 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
4247 if (this.disabled) {
4248 cfg.cls += ' disabled';
4251 if (this.href || this.html || this.glyphicon || this.icon) {
4255 href : this.href || "#",
4256 html: this.html || ''
4261 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
4264 if(this.glyphicon) {
4265 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
4270 cfg.cn[0].html += " <span class='caret'></span>";
4274 if (this.badge !== '') {
4276 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
4284 initEvents: function()
4286 if (typeof (this.menu) != 'undefined') {
4287 this.menu.parentType = this.xtype;
4288 this.menu.triggerEl = this.el;
4289 this.menu = this.addxtype(Roo.apply({}, this.menu));
4292 this.el.select('a',true).on('click', this.onClick, this);
4294 if(this.tagtype == 'span'){
4295 this.el.select('span',true).on('click', this.onClick, this);
4298 // at this point parent should be available..
4299 this.parent().register(this);
4302 onClick : function(e)
4304 if (e.getTarget('.dropdown-menu-item')) {
4305 // did you click on a menu itemm.... - then don't trigger onclick..
4310 this.preventDefault ||
4313 Roo.log("NavItem - prevent Default?");
4317 if (this.disabled) {
4321 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4322 if (tg && tg.transition) {
4323 Roo.log("waiting for the transitionend");
4329 //Roo.log("fire event clicked");
4330 if(this.fireEvent('click', this, e) === false){
4334 if(this.tagtype == 'span'){
4338 //Roo.log(this.href);
4339 var ael = this.el.select('a',true).first();
4342 if(ael && this.animateRef && this.href.indexOf('#') > -1){
4343 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
4344 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
4345 return; // ignore... - it's a 'hash' to another page.
4347 Roo.log("NavItem - prevent Default?");
4349 this.scrollToElement(e);
4353 var p = this.parent();
4355 if (['tabs','pills'].indexOf(p.type)!==-1) {
4356 if (typeof(p.setActiveItem) !== 'undefined') {
4357 p.setActiveItem(this);
4361 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
4362 if (p.parentType == 'NavHeaderbar' && !this.menu) {
4363 // remove the collapsed menu expand...
4364 p.parent().el.select('.navbar-collapse',true).removeClass('in');
4368 isActive: function () {
4371 setActive : function(state, fire, is_was_active)
4373 if (this.active && !state && this.navId) {
4374 this.was_active = true;
4375 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4377 nv.clearWasActive(this);
4381 this.active = state;
4384 this.el.removeClass('active');
4385 } else if (!this.el.hasClass('active')) {
4386 this.el.addClass('active');
4389 this.fireEvent('changed', this, state);
4392 // show a panel if it's registered and related..
4394 if (!this.navId || !this.tabId || !state || is_was_active) {
4398 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4402 var pan = tg.getPanelByName(this.tabId);
4406 // if we can not flip to new panel - go back to old nav highlight..
4407 if (false == tg.showPanel(pan)) {
4408 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4410 var onav = nv.getWasActive();
4412 onav.setActive(true, false, true);
4421 // this should not be here...
4422 setDisabled : function(state)
4424 this.disabled = state;
4426 this.el.removeClass('disabled');
4427 } else if (!this.el.hasClass('disabled')) {
4428 this.el.addClass('disabled');
4434 * Fetch the element to display the tooltip on.
4435 * @return {Roo.Element} defaults to this.el
4437 tooltipEl : function()
4439 return this.el.select('' + this.tagtype + '', true).first();
4442 scrollToElement : function(e)
4444 var c = document.body;
4447 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
4449 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
4450 c = document.documentElement;
4453 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
4459 var o = target.calcOffsetsTo(c);
4466 this.fireEvent('scrollto', this, options, e);
4468 Roo.get(c).scrollTo('top', options.value, true);
4481 * <span> icon </span>
4482 * <span> text </span>
4483 * <span>badge </span>
4487 * @class Roo.bootstrap.NavSidebarItem
4488 * @extends Roo.bootstrap.NavItem
4489 * Bootstrap Navbar.NavSidebarItem class
4490 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
4491 * {bool} open is the menu open
4493 * Create a new Navbar Button
4494 * @param {Object} config The config object
4496 Roo.bootstrap.NavSidebarItem = function(config){
4497 Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
4502 * The raw click event for the entire grid.
4503 * @param {Roo.EventObject} e
4508 * Fires when the active item active state changes
4509 * @param {Roo.bootstrap.NavSidebarItem} this
4510 * @param {boolean} state the new state
4518 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem, {
4520 badgeWeight : 'default',
4524 getAutoCreate : function(){
4529 href : this.href || '#',
4541 html : this.html || ''
4546 cfg.cls += ' active';
4549 if (this.disabled) {
4550 cfg.cls += ' disabled';
4553 cfg.cls += ' open x-open';
4556 if (this.glyphicon || this.icon) {
4557 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
4558 a.cn.push({ tag : 'i', cls : c }) ;
4563 if (this.badge !== '') {
4565 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
4569 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
4570 a.cls += 'dropdown-toggle treeview' ;
4578 initEvents : function()
4580 if (typeof (this.menu) != 'undefined') {
4581 this.menu.parentType = this.xtype;
4582 this.menu.triggerEl = this.el;
4583 this.menu = this.addxtype(Roo.apply({}, this.menu));
4586 this.el.on('click', this.onClick, this);
4589 if(this.badge !== ''){
4591 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
4596 onClick : function(e)
4603 if(this.preventDefault){
4607 this.fireEvent('click', this);
4610 disable : function()
4612 this.setDisabled(true);
4617 this.setDisabled(false);
4620 setDisabled : function(state)
4622 if(this.disabled == state){
4626 this.disabled = state;
4629 this.el.addClass('disabled');
4633 this.el.removeClass('disabled');
4638 setActive : function(state)
4640 if(this.active == state){
4644 this.active = state;
4647 this.el.addClass('active');
4651 this.el.removeClass('active');
4656 isActive: function ()
4661 setBadge : function(str)
4667 this.badgeEl.dom.innerHTML = str;
4684 * @class Roo.bootstrap.Row
4685 * @extends Roo.bootstrap.Component
4686 * Bootstrap Row class (contains columns...)
4690 * @param {Object} config The config object
4693 Roo.bootstrap.Row = function(config){
4694 Roo.bootstrap.Row.superclass.constructor.call(this, config);
4697 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
4699 getAutoCreate : function(){
4718 * @class Roo.bootstrap.Element
4719 * @extends Roo.bootstrap.Component
4720 * Bootstrap Element class
4721 * @cfg {String} html contents of the element
4722 * @cfg {String} tag tag of the element
4723 * @cfg {String} cls class of the element
4724 * @cfg {Boolean} preventDefault (true|false) default false
4725 * @cfg {Boolean} clickable (true|false) default false
4728 * Create a new Element
4729 * @param {Object} config The config object
4732 Roo.bootstrap.Element = function(config){
4733 Roo.bootstrap.Element.superclass.constructor.call(this, config);
4739 * When a element is chick
4740 * @param {Roo.bootstrap.Element} this
4741 * @param {Roo.EventObject} e
4747 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
4752 preventDefault: false,
4755 getAutoCreate : function(){
4766 initEvents: function()
4768 Roo.bootstrap.Element.superclass.initEvents.call(this);
4771 this.el.on('click', this.onClick, this);
4776 onClick : function(e)
4778 if(this.preventDefault){
4782 this.fireEvent('click', this, e);
4785 getValue : function()
4787 return this.el.dom.innerHTML;
4790 setValue : function(value)
4792 this.el.dom.innerHTML = value;
4807 * @class Roo.bootstrap.Pagination
4808 * @extends Roo.bootstrap.Component
4809 * Bootstrap Pagination class
4810 * @cfg {String} size xs | sm | md | lg
4811 * @cfg {Boolean} inverse false | true
4814 * Create a new Pagination
4815 * @param {Object} config The config object
4818 Roo.bootstrap.Pagination = function(config){
4819 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
4822 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
4828 getAutoCreate : function(){
4834 cfg.cls += ' inverse';
4840 cfg.cls += " " + this.cls;
4858 * @class Roo.bootstrap.PaginationItem
4859 * @extends Roo.bootstrap.Component
4860 * Bootstrap PaginationItem class
4861 * @cfg {String} html text
4862 * @cfg {String} href the link
4863 * @cfg {Boolean} preventDefault (true | false) default true
4864 * @cfg {Boolean} active (true | false) default false
4865 * @cfg {Boolean} disabled default false
4869 * Create a new PaginationItem
4870 * @param {Object} config The config object
4874 Roo.bootstrap.PaginationItem = function(config){
4875 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
4880 * The raw click event for the entire grid.
4881 * @param {Roo.EventObject} e
4887 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
4891 preventDefault: true,
4896 getAutoCreate : function(){
4902 href : this.href ? this.href : '#',
4903 html : this.html ? this.html : ''
4913 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
4917 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
4923 initEvents: function() {
4925 this.el.on('click', this.onClick, this);
4928 onClick : function(e)
4930 Roo.log('PaginationItem on click ');
4931 if(this.preventDefault){
4939 this.fireEvent('click', this, e);
4955 * @class Roo.bootstrap.Slider
4956 * @extends Roo.bootstrap.Component
4957 * Bootstrap Slider class
4960 * Create a new Slider
4961 * @param {Object} config The config object
4964 Roo.bootstrap.Slider = function(config){
4965 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
4968 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
4970 getAutoCreate : function(){
4974 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
4978 cls: 'ui-slider-handle ui-state-default ui-corner-all'
4990 * Ext JS Library 1.1.1
4991 * Copyright(c) 2006-2007, Ext JS, LLC.
4993 * Originally Released Under LGPL - original licence link has changed is not relivant.
4996 * <script type="text/javascript">
5001 * @class Roo.grid.ColumnModel
5002 * @extends Roo.util.Observable
5003 * This is the default implementation of a ColumnModel used by the Grid. It defines
5004 * the columns in the grid.
5007 var colModel = new Roo.grid.ColumnModel([
5008 {header: "Ticker", width: 60, sortable: true, locked: true},
5009 {header: "Company Name", width: 150, sortable: true},
5010 {header: "Market Cap.", width: 100, sortable: true},
5011 {header: "$ Sales", width: 100, sortable: true, renderer: money},
5012 {header: "Employees", width: 100, sortable: true, resizable: false}
5017 * The config options listed for this class are options which may appear in each
5018 * individual column definition.
5019 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
5021 * @param {Object} config An Array of column config objects. See this class's
5022 * config objects for details.
5024 Roo.grid.ColumnModel = function(config){
5026 * The config passed into the constructor
5028 this.config = config;
5031 // if no id, create one
5032 // if the column does not have a dataIndex mapping,
5033 // map it to the order it is in the config
5034 for(var i = 0, len = config.length; i < len; i++){
5036 if(typeof c.dataIndex == "undefined"){
5039 if(typeof c.renderer == "string"){
5040 c.renderer = Roo.util.Format[c.renderer];
5042 if(typeof c.id == "undefined"){
5045 if(c.editor && c.editor.xtype){
5046 c.editor = Roo.factory(c.editor, Roo.grid);
5048 if(c.editor && c.editor.isFormField){
5049 c.editor = new Roo.grid.GridEditor(c.editor);
5051 this.lookup[c.id] = c;
5055 * The width of columns which have no width specified (defaults to 100)
5058 this.defaultWidth = 100;
5061 * Default sortable of columns which have no sortable specified (defaults to false)
5064 this.defaultSortable = false;
5068 * @event widthchange
5069 * Fires when the width of a column changes.
5070 * @param {ColumnModel} this
5071 * @param {Number} columnIndex The column index
5072 * @param {Number} newWidth The new width
5074 "widthchange": true,
5076 * @event headerchange
5077 * Fires when the text of a header changes.
5078 * @param {ColumnModel} this
5079 * @param {Number} columnIndex The column index
5080 * @param {Number} newText The new header text
5082 "headerchange": true,
5084 * @event hiddenchange
5085 * Fires when a column is hidden or "unhidden".
5086 * @param {ColumnModel} this
5087 * @param {Number} columnIndex The column index
5088 * @param {Boolean} hidden true if hidden, false otherwise
5090 "hiddenchange": true,
5092 * @event columnmoved
5093 * Fires when a column is moved.
5094 * @param {ColumnModel} this
5095 * @param {Number} oldIndex
5096 * @param {Number} newIndex
5098 "columnmoved" : true,
5100 * @event columlockchange
5101 * Fires when a column's locked state is changed
5102 * @param {ColumnModel} this
5103 * @param {Number} colIndex
5104 * @param {Boolean} locked true if locked
5106 "columnlockchange" : true
5108 Roo.grid.ColumnModel.superclass.constructor.call(this);
5110 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
5112 * @cfg {String} header The header text to display in the Grid view.
5115 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
5116 * {@link Roo.data.Record} definition from which to draw the column's value. If not
5117 * specified, the column's index is used as an index into the Record's data Array.
5120 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
5121 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
5124 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
5125 * Defaults to the value of the {@link #defaultSortable} property.
5126 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
5129 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
5132 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
5135 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
5138 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
5141 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
5142 * given the cell's data value. See {@link #setRenderer}. If not specified, the
5143 * default renderer uses the raw data value. If an object is returned (bootstrap only)
5144 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
5147 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
5150 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
5153 * @cfg {String} cursor (Optional)
5156 * @cfg {String} tooltip (Optional)
5159 * @cfg {Number} xs (Optional)
5162 * @cfg {Number} sm (Optional)
5165 * @cfg {Number} md (Optional)
5168 * @cfg {Number} lg (Optional)
5171 * Returns the id of the column at the specified index.
5172 * @param {Number} index The column index
5173 * @return {String} the id
5175 getColumnId : function(index){
5176 return this.config[index].id;
5180 * Returns the column for a specified id.
5181 * @param {String} id The column id
5182 * @return {Object} the column
5184 getColumnById : function(id){
5185 return this.lookup[id];
5190 * Returns the column for a specified dataIndex.
5191 * @param {String} dataIndex The column dataIndex
5192 * @return {Object|Boolean} the column or false if not found
5194 getColumnByDataIndex: function(dataIndex){
5195 var index = this.findColumnIndex(dataIndex);
5196 return index > -1 ? this.config[index] : false;
5200 * Returns the index for a specified column id.
5201 * @param {String} id The column id
5202 * @return {Number} the index, or -1 if not found
5204 getIndexById : function(id){
5205 for(var i = 0, len = this.config.length; i < len; i++){
5206 if(this.config[i].id == id){
5214 * Returns the index for a specified column dataIndex.
5215 * @param {String} dataIndex The column dataIndex
5216 * @return {Number} the index, or -1 if not found
5219 findColumnIndex : function(dataIndex){
5220 for(var i = 0, len = this.config.length; i < len; i++){
5221 if(this.config[i].dataIndex == dataIndex){
5229 moveColumn : function(oldIndex, newIndex){
5230 var c = this.config[oldIndex];
5231 this.config.splice(oldIndex, 1);
5232 this.config.splice(newIndex, 0, c);
5233 this.dataMap = null;
5234 this.fireEvent("columnmoved", this, oldIndex, newIndex);
5237 isLocked : function(colIndex){
5238 return this.config[colIndex].locked === true;
5241 setLocked : function(colIndex, value, suppressEvent){
5242 if(this.isLocked(colIndex) == value){
5245 this.config[colIndex].locked = value;
5247 this.fireEvent("columnlockchange", this, colIndex, value);
5251 getTotalLockedWidth : function(){
5253 for(var i = 0; i < this.config.length; i++){
5254 if(this.isLocked(i) && !this.isHidden(i)){
5255 this.totalWidth += this.getColumnWidth(i);
5261 getLockedCount : function(){
5262 for(var i = 0, len = this.config.length; i < len; i++){
5263 if(!this.isLocked(i)){
5268 return this.config.length;
5272 * Returns the number of columns.
5275 getColumnCount : function(visibleOnly){
5276 if(visibleOnly === true){
5278 for(var i = 0, len = this.config.length; i < len; i++){
5279 if(!this.isHidden(i)){
5285 return this.config.length;
5289 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
5290 * @param {Function} fn
5291 * @param {Object} scope (optional)
5292 * @return {Array} result
5294 getColumnsBy : function(fn, scope){
5296 for(var i = 0, len = this.config.length; i < len; i++){
5297 var c = this.config[i];
5298 if(fn.call(scope||this, c, i) === true){
5306 * Returns true if the specified column is sortable.
5307 * @param {Number} col The column index
5310 isSortable : function(col){
5311 if(typeof this.config[col].sortable == "undefined"){
5312 return this.defaultSortable;
5314 return this.config[col].sortable;
5318 * Returns the rendering (formatting) function defined for the column.
5319 * @param {Number} col The column index.
5320 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5322 getRenderer : function(col){
5323 if(!this.config[col].renderer){
5324 return Roo.grid.ColumnModel.defaultRenderer;
5326 return this.config[col].renderer;
5330 * Sets the rendering (formatting) function for a column.
5331 * @param {Number} col The column index
5332 * @param {Function} fn The function to use to process the cell's raw data
5333 * to return HTML markup for the grid view. The render function is called with
5334 * the following parameters:<ul>
5335 * <li>Data value.</li>
5336 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
5337 * <li>css A CSS style string to apply to the table cell.</li>
5338 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
5339 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
5340 * <li>Row index</li>
5341 * <li>Column index</li>
5342 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
5344 setRenderer : function(col, fn){
5345 this.config[col].renderer = fn;
5349 * Returns the width for the specified column.
5350 * @param {Number} col The column index
5353 getColumnWidth : function(col){
5354 return this.config[col].width * 1 || this.defaultWidth;
5358 * Sets the width for a column.
5359 * @param {Number} col The column index
5360 * @param {Number} width The new width
5362 setColumnWidth : function(col, width, suppressEvent){
5363 this.config[col].width = width;
5364 this.totalWidth = null;
5366 this.fireEvent("widthchange", this, col, width);
5371 * Returns the total width of all columns.
5372 * @param {Boolean} includeHidden True to include hidden column widths
5375 getTotalWidth : function(includeHidden){
5376 if(!this.totalWidth){
5377 this.totalWidth = 0;
5378 for(var i = 0, len = this.config.length; i < len; i++){
5379 if(includeHidden || !this.isHidden(i)){
5380 this.totalWidth += this.getColumnWidth(i);
5384 return this.totalWidth;
5388 * Returns the header for the specified column.
5389 * @param {Number} col The column index
5392 getColumnHeader : function(col){
5393 return this.config[col].header;
5397 * Sets the header for a column.
5398 * @param {Number} col The column index
5399 * @param {String} header The new header
5401 setColumnHeader : function(col, header){
5402 this.config[col].header = header;
5403 this.fireEvent("headerchange", this, col, header);
5407 * Returns the tooltip for the specified column.
5408 * @param {Number} col The column index
5411 getColumnTooltip : function(col){
5412 return this.config[col].tooltip;
5415 * Sets the tooltip for a column.
5416 * @param {Number} col The column index
5417 * @param {String} tooltip The new tooltip
5419 setColumnTooltip : function(col, tooltip){
5420 this.config[col].tooltip = tooltip;
5424 * Returns the dataIndex for the specified column.
5425 * @param {Number} col The column index
5428 getDataIndex : function(col){
5429 return this.config[col].dataIndex;
5433 * Sets the dataIndex for a column.
5434 * @param {Number} col The column index
5435 * @param {Number} dataIndex The new dataIndex
5437 setDataIndex : function(col, dataIndex){
5438 this.config[col].dataIndex = dataIndex;
5444 * Returns true if the cell is editable.
5445 * @param {Number} colIndex The column index
5446 * @param {Number} rowIndex The row index - this is nto actually used..?
5449 isCellEditable : function(colIndex, rowIndex){
5450 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
5454 * Returns the editor defined for the cell/column.
5455 * return false or null to disable editing.
5456 * @param {Number} colIndex The column index
5457 * @param {Number} rowIndex The row index
5460 getCellEditor : function(colIndex, rowIndex){
5461 return this.config[colIndex].editor;
5465 * Sets if a column is editable.
5466 * @param {Number} col The column index
5467 * @param {Boolean} editable True if the column is editable
5469 setEditable : function(col, editable){
5470 this.config[col].editable = editable;
5475 * Returns true if the column is hidden.
5476 * @param {Number} colIndex The column index
5479 isHidden : function(colIndex){
5480 return this.config[colIndex].hidden;
5485 * Returns true if the column width cannot be changed
5487 isFixed : function(colIndex){
5488 return this.config[colIndex].fixed;
5492 * Returns true if the column can be resized
5495 isResizable : function(colIndex){
5496 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5499 * Sets if a column is hidden.
5500 * @param {Number} colIndex The column index
5501 * @param {Boolean} hidden True if the column is hidden
5503 setHidden : function(colIndex, hidden){
5504 this.config[colIndex].hidden = hidden;
5505 this.totalWidth = null;
5506 this.fireEvent("hiddenchange", this, colIndex, hidden);
5510 * Sets the editor for a column.
5511 * @param {Number} col The column index
5512 * @param {Object} editor The editor object
5514 setEditor : function(col, editor){
5515 this.config[col].editor = editor;
5519 Roo.grid.ColumnModel.defaultRenderer = function(value){
5520 if(typeof value == "string" && value.length < 1){
5526 // Alias for backwards compatibility
5527 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
5530 * Ext JS Library 1.1.1
5531 * Copyright(c) 2006-2007, Ext JS, LLC.
5533 * Originally Released Under LGPL - original licence link has changed is not relivant.
5536 * <script type="text/javascript">
5540 * @class Roo.LoadMask
5541 * A simple utility class for generically masking elements while loading data. If the element being masked has
5542 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
5543 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
5544 * element's UpdateManager load indicator and will be destroyed after the initial load.
5546 * Create a new LoadMask
5547 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
5548 * @param {Object} config The config object
5550 Roo.LoadMask = function(el, config){
5551 this.el = Roo.get(el);
5552 Roo.apply(this, config);
5554 this.store.on('beforeload', this.onBeforeLoad, this);
5555 this.store.on('load', this.onLoad, this);
5556 this.store.on('loadexception', this.onLoadException, this);
5557 this.removeMask = false;
5559 var um = this.el.getUpdateManager();
5560 um.showLoadIndicator = false; // disable the default indicator
5561 um.on('beforeupdate', this.onBeforeLoad, this);
5562 um.on('update', this.onLoad, this);
5563 um.on('failure', this.onLoad, this);
5564 this.removeMask = true;
5568 Roo.LoadMask.prototype = {
5570 * @cfg {Boolean} removeMask
5571 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
5572 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
5576 * The text to display in a centered loading message box (defaults to 'Loading...')
5580 * @cfg {String} msgCls
5581 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
5583 msgCls : 'x-mask-loading',
5586 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
5592 * Disables the mask to prevent it from being displayed
5594 disable : function(){
5595 this.disabled = true;
5599 * Enables the mask so that it can be displayed
5601 enable : function(){
5602 this.disabled = false;
5605 onLoadException : function()
5609 if (typeof(arguments[3]) != 'undefined') {
5610 Roo.MessageBox.alert("Error loading",arguments[3]);
5614 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
5615 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
5624 this.el.unmask(this.removeMask);
5629 this.el.unmask(this.removeMask);
5633 onBeforeLoad : function(){
5635 this.el.mask(this.msg, this.msgCls);
5640 destroy : function(){
5642 this.store.un('beforeload', this.onBeforeLoad, this);
5643 this.store.un('load', this.onLoad, this);
5644 this.store.un('loadexception', this.onLoadException, this);
5646 var um = this.el.getUpdateManager();
5647 um.un('beforeupdate', this.onBeforeLoad, this);
5648 um.un('update', this.onLoad, this);
5649 um.un('failure', this.onLoad, this);
5660 * @class Roo.bootstrap.Table
5661 * @extends Roo.bootstrap.Component
5662 * Bootstrap Table class
5663 * @cfg {String} cls table class
5664 * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
5665 * @cfg {String} bgcolor Specifies the background color for a table
5666 * @cfg {Number} border Specifies whether the table cells should have borders or not
5667 * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
5668 * @cfg {Number} cellspacing Specifies the space between cells
5669 * @cfg {String} frame Specifies which parts of the outside borders that should be visible
5670 * @cfg {String} rules Specifies which parts of the inside borders that should be visible
5671 * @cfg {String} sortable Specifies that the table should be sortable
5672 * @cfg {String} summary Specifies a summary of the content of a table
5673 * @cfg {Number} width Specifies the width of a table
5674 * @cfg {String} layout table layout (auto | fixed | initial | inherit)
5676 * @cfg {boolean} striped Should the rows be alternative striped
5677 * @cfg {boolean} bordered Add borders to the table
5678 * @cfg {boolean} hover Add hover highlighting
5679 * @cfg {boolean} condensed Format condensed
5680 * @cfg {boolean} responsive Format condensed
5681 * @cfg {Boolean} loadMask (true|false) default false
5682 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
5683 * @cfg {Boolean} headerShow (true|false) generate thead, default true
5684 * @cfg {Boolean} rowSelection (true|false) default false
5685 * @cfg {Boolean} cellSelection (true|false) default false
5686 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
5687 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
5691 * Create a new Table
5692 * @param {Object} config The config object
5695 Roo.bootstrap.Table = function(config){
5696 Roo.bootstrap.Table.superclass.constructor.call(this, config);
5701 this.rowSelection = (typeof(config.RowSelection) != 'undefined') ? config.RowSelection : this.rowSelection;
5702 this.cellSelection = (typeof(config.CellSelection) != 'undefined') ? config.CellSelection : this.cellSelection;
5703 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
5704 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
5708 this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
5709 this.sm = this.selModel;
5710 this.sm.xmodule = this.xmodule || false;
5712 if (this.cm && typeof(this.cm.config) == 'undefined') {
5713 this.colModel = new Roo.grid.ColumnModel(this.cm);
5714 this.cm = this.colModel;
5715 this.cm.xmodule = this.xmodule || false;
5718 this.store= Roo.factory(this.store, Roo.data);
5719 this.ds = this.store;
5720 this.ds.xmodule = this.xmodule || false;
5723 if (this.footer && this.store) {
5724 this.footer.dataSource = this.ds;
5725 this.footer = Roo.factory(this.footer);
5732 * Fires when a cell is clicked
5733 * @param {Roo.bootstrap.Table} this
5734 * @param {Roo.Element} el
5735 * @param {Number} rowIndex
5736 * @param {Number} columnIndex
5737 * @param {Roo.EventObject} e
5741 * @event celldblclick
5742 * Fires when a cell is double clicked
5743 * @param {Roo.bootstrap.Table} this
5744 * @param {Roo.Element} el
5745 * @param {Number} rowIndex
5746 * @param {Number} columnIndex
5747 * @param {Roo.EventObject} e
5749 "celldblclick" : true,
5752 * Fires when a row is clicked
5753 * @param {Roo.bootstrap.Table} this
5754 * @param {Roo.Element} el
5755 * @param {Number} rowIndex
5756 * @param {Roo.EventObject} e
5760 * @event rowdblclick
5761 * Fires when a row is double clicked
5762 * @param {Roo.bootstrap.Table} this
5763 * @param {Roo.Element} el
5764 * @param {Number} rowIndex
5765 * @param {Roo.EventObject} e
5767 "rowdblclick" : true,
5770 * Fires when a mouseover occur
5771 * @param {Roo.bootstrap.Table} this
5772 * @param {Roo.Element} el
5773 * @param {Number} rowIndex
5774 * @param {Number} columnIndex
5775 * @param {Roo.EventObject} e
5780 * Fires when a mouseout occur
5781 * @param {Roo.bootstrap.Table} this
5782 * @param {Roo.Element} el
5783 * @param {Number} rowIndex
5784 * @param {Number} columnIndex
5785 * @param {Roo.EventObject} e
5790 * Fires when a row is rendered, so you can change add a style to it.
5791 * @param {Roo.bootstrap.Table} this
5792 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
5796 * @event rowsrendered
5797 * Fires when all the rows have been rendered
5798 * @param {Roo.bootstrap.Table} this
5800 'rowsrendered' : true,
5802 * @event contextmenu
5803 * The raw contextmenu event for the entire grid.
5804 * @param {Roo.EventObject} e
5806 "contextmenu" : true,
5808 * @event rowcontextmenu
5809 * Fires when a row is right clicked
5810 * @param {Roo.bootstrap.Table} this
5811 * @param {Number} rowIndex
5812 * @param {Roo.EventObject} e
5814 "rowcontextmenu" : true,
5816 * @event cellcontextmenu
5817 * Fires when a cell is right clicked
5818 * @param {Roo.bootstrap.Table} this
5819 * @param {Number} rowIndex
5820 * @param {Number} cellIndex
5821 * @param {Roo.EventObject} e
5823 "cellcontextmenu" : true,
5825 * @event headercontextmenu
5826 * Fires when a header is right clicked
5827 * @param {Roo.bootstrap.Table} this
5828 * @param {Number} columnIndex
5829 * @param {Roo.EventObject} e
5831 "headercontextmenu" : true
5835 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
5861 rowSelection : false,
5862 cellSelection : false,
5865 // Roo.Element - the tbody
5867 // Roo.Element - thead element
5870 container: false, // used by gridpanel...
5872 getAutoCreate : function()
5874 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
5881 if (this.scrollBody) {
5882 cfg.cls += ' table-body-fixed';
5885 cfg.cls += ' table-striped';
5889 cfg.cls += ' table-hover';
5891 if (this.bordered) {
5892 cfg.cls += ' table-bordered';
5894 if (this.condensed) {
5895 cfg.cls += ' table-condensed';
5897 if (this.responsive) {
5898 cfg.cls += ' table-responsive';
5902 cfg.cls+= ' ' +this.cls;
5905 // this lot should be simplifed...
5908 cfg.align=this.align;
5911 cfg.bgcolor=this.bgcolor;
5914 cfg.border=this.border;
5916 if (this.cellpadding) {
5917 cfg.cellpadding=this.cellpadding;
5919 if (this.cellspacing) {
5920 cfg.cellspacing=this.cellspacing;
5923 cfg.frame=this.frame;
5926 cfg.rules=this.rules;
5928 if (this.sortable) {
5929 cfg.sortable=this.sortable;
5932 cfg.summary=this.summary;
5935 cfg.width=this.width;
5938 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
5941 if(this.store || this.cm){
5942 if(this.headerShow){
5943 cfg.cn.push(this.renderHeader());
5946 cfg.cn.push(this.renderBody());
5948 if(this.footerShow){
5949 cfg.cn.push(this.renderFooter());
5951 // where does this come from?
5952 //cfg.cls+= ' TableGrid';
5955 return { cn : [ cfg ] };
5958 initEvents : function()
5960 if(!this.store || !this.cm){
5964 //Roo.log('initEvents with ds!!!!');
5966 this.mainBody = this.el.select('tbody', true).first();
5967 this.mainHead = this.el.select('thead', true).first();
5973 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
5974 e.on('click', _this.sort, _this);
5977 this.el.on("click", this.onClick, this);
5978 this.el.on("dblclick", this.onDblClick, this);
5980 // why is this done????? = it breaks dialogs??
5981 //this.parent().el.setStyle('position', 'relative');
5985 this.footer.parentId = this.id;
5986 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
5989 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
5991 this.store.on('load', this.onLoad, this);
5992 this.store.on('beforeload', this.onBeforeLoad, this);
5993 this.store.on('update', this.onUpdate, this);
5994 this.store.on('add', this.onAdd, this);
5996 this.el.on("contextmenu", this.onContextMenu, this);
5998 this.mainBody.on('scroll', this.onBodyScroll, this);
6003 onContextMenu : function(e, t)
6005 this.processEvent("contextmenu", e);
6008 processEvent : function(name, e)
6010 if (name != 'touchstart' ) {
6011 this.fireEvent(name, e);
6014 var t = e.getTarget();
6016 var cell = Roo.get(t);
6022 if(cell.findParent('tfoot', false, true)){
6026 if(cell.findParent('thead', false, true)){
6028 if(e.getTarget().nodeName.toLowerCase() != 'th'){
6029 cell = Roo.get(t).findParent('th', false, true);
6031 Roo.log("failed to find th in thead?");
6032 Roo.log(e.getTarget());
6037 var cellIndex = cell.dom.cellIndex;
6039 var ename = name == 'touchstart' ? 'click' : name;
6040 this.fireEvent("header" + ename, this, cellIndex, e);
6045 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6046 cell = Roo.get(t).findParent('td', false, true);
6048 Roo.log("failed to find th in tbody?");
6049 Roo.log(e.getTarget());
6054 var row = cell.findParent('tr', false, true);
6055 var cellIndex = cell.dom.cellIndex;
6056 var rowIndex = row.dom.rowIndex - 1;
6060 this.fireEvent("row" + name, this, rowIndex, e);
6064 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
6070 onMouseover : function(e, el)
6072 var cell = Roo.get(el);
6078 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6079 cell = cell.findParent('td', false, true);
6082 var row = cell.findParent('tr', false, true);
6083 var cellIndex = cell.dom.cellIndex;
6084 var rowIndex = row.dom.rowIndex - 1; // start from 0
6086 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
6090 onMouseout : function(e, el)
6092 var cell = Roo.get(el);
6098 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6099 cell = cell.findParent('td', false, true);
6102 var row = cell.findParent('tr', false, true);
6103 var cellIndex = cell.dom.cellIndex;
6104 var rowIndex = row.dom.rowIndex - 1; // start from 0
6106 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
6110 onClick : function(e, el)
6112 var cell = Roo.get(el);
6114 if(!cell || (!this.cellSelection && !this.rowSelection)){
6118 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6119 cell = cell.findParent('td', false, true);
6122 if(!cell || typeof(cell) == 'undefined'){
6126 var row = cell.findParent('tr', false, true);
6128 if(!row || typeof(row) == 'undefined'){
6132 var cellIndex = cell.dom.cellIndex;
6133 var rowIndex = this.getRowIndex(row);
6135 // why??? - should these not be based on SelectionModel?
6136 if(this.cellSelection){
6137 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
6140 if(this.rowSelection){
6141 this.fireEvent('rowclick', this, row, rowIndex, e);
6147 onDblClick : function(e,el)
6149 var cell = Roo.get(el);
6151 if(!cell || (!this.CellSelection && !this.RowSelection)){
6155 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6156 cell = cell.findParent('td', false, true);
6159 if(!cell || typeof(cell) == 'undefined'){
6163 var row = cell.findParent('tr', false, true);
6165 if(!row || typeof(row) == 'undefined'){
6169 var cellIndex = cell.dom.cellIndex;
6170 var rowIndex = this.getRowIndex(row);
6172 if(this.CellSelection){
6173 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
6176 if(this.RowSelection){
6177 this.fireEvent('rowdblclick', this, row, rowIndex, e);
6181 sort : function(e,el)
6183 var col = Roo.get(el);
6185 if(!col.hasClass('sortable')){
6189 var sort = col.attr('sort');
6192 if(col.select('i', true).first().hasClass('glyphicon-arrow-up')){
6196 this.store.sortInfo = {field : sort, direction : dir};
6199 Roo.log("calling footer first");
6200 this.footer.onClick('first');
6203 this.store.load({ params : { start : 0 } });
6207 renderHeader : function()
6215 this.totalWidth = 0;
6217 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6219 var config = cm.config[i];
6224 html: cm.getColumnHeader(i)
6229 if(typeof(config.sortable) != 'undefined' && config.sortable){
6231 c.html = '<i class="glyphicon"></i>' + c.html;
6234 if(typeof(config.lgHeader) != 'undefined'){
6235 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
6238 if(typeof(config.mdHeader) != 'undefined'){
6239 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
6242 if(typeof(config.smHeader) != 'undefined'){
6243 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
6246 if(typeof(config.xsHeader) != 'undefined'){
6247 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
6254 if(typeof(config.tooltip) != 'undefined'){
6255 c.tooltip = config.tooltip;
6258 if(typeof(config.colspan) != 'undefined'){
6259 c.colspan = config.colspan;
6262 if(typeof(config.hidden) != 'undefined' && config.hidden){
6263 c.style += ' display:none;';
6266 if(typeof(config.dataIndex) != 'undefined'){
6267 c.sort = config.dataIndex;
6272 if(typeof(config.align) != 'undefined' && config.align.length){
6273 c.style += ' text-align:' + config.align + ';';
6276 if(typeof(config.width) != 'undefined'){
6277 c.style += ' width:' + config.width + 'px;';
6278 this.totalWidth += config.width;
6280 this.totalWidth += 100; // assume minimum of 100 per column?
6283 if(typeof(config.cls) != 'undefined'){
6284 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
6287 ['xs','sm','md','lg'].map(function(size){
6289 if(typeof(config[size]) == 'undefined'){
6293 if (!config[size]) { // 0 = hidden
6294 c.cls += ' hidden-' + size;
6298 c.cls += ' col-' + size + '-' + config[size];
6308 renderBody : function()
6318 colspan : this.cm.getColumnCount()
6328 renderFooter : function()
6338 colspan : this.cm.getColumnCount()
6352 // Roo.log('ds onload');
6357 var ds = this.store;
6359 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6360 e.select('i', true).removeClass(['glyphicon-arrow-up', 'glyphicon-arrow-down']);
6361 if (_this.store.sortInfo) {
6363 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
6364 e.select('i', true).addClass(['glyphicon-arrow-up']);
6367 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
6368 e.select('i', true).addClass(['glyphicon-arrow-down']);
6373 var tbody = this.mainBody;
6375 if(ds.getCount() > 0){
6376 ds.data.each(function(d,rowIndex){
6377 var row = this.renderRow(cm, ds, rowIndex);
6379 tbody.createChild(row);
6383 if(row.cellObjects.length){
6384 Roo.each(row.cellObjects, function(r){
6385 _this.renderCellObject(r);
6392 Roo.each(this.el.select('tbody td', true).elements, function(e){
6393 e.on('mouseover', _this.onMouseover, _this);
6396 Roo.each(this.el.select('tbody td', true).elements, function(e){
6397 e.on('mouseout', _this.onMouseout, _this);
6399 this.fireEvent('rowsrendered', this);
6400 //if(this.loadMask){
6401 // this.maskEl.hide();
6408 onUpdate : function(ds,record)
6410 this.refreshRow(record);
6413 onRemove : function(ds, record, index, isUpdate){
6414 if(isUpdate !== true){
6415 this.fireEvent("beforerowremoved", this, index, record);
6417 var bt = this.mainBody.dom;
6419 var rows = this.el.select('tbody > tr', true).elements;
6421 if(typeof(rows[index]) != 'undefined'){
6422 bt.removeChild(rows[index].dom);
6425 // if(bt.rows[index]){
6426 // bt.removeChild(bt.rows[index]);
6429 if(isUpdate !== true){
6430 //this.stripeRows(index);
6431 //this.syncRowHeights(index, index);
6433 this.fireEvent("rowremoved", this, index, record);
6437 onAdd : function(ds, records, rowIndex)
6439 //Roo.log('on Add called');
6440 // - note this does not handle multiple adding very well..
6441 var bt = this.mainBody.dom;
6442 for (var i =0 ; i < records.length;i++) {
6443 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
6444 //Roo.log(records[i]);
6445 //Roo.log(this.store.getAt(rowIndex+i));
6446 this.insertRow(this.store, rowIndex + i, false);
6453 refreshRow : function(record){
6454 var ds = this.store, index;
6455 if(typeof record == 'number'){
6457 record = ds.getAt(index);
6459 index = ds.indexOf(record);
6461 this.insertRow(ds, index, true);
6462 this.onRemove(ds, record, index+1, true);
6463 //this.syncRowHeights(index, index);
6465 this.fireEvent("rowupdated", this, index, record);
6468 insertRow : function(dm, rowIndex, isUpdate){
6471 this.fireEvent("beforerowsinserted", this, rowIndex);
6473 //var s = this.getScrollState();
6474 var row = this.renderRow(this.cm, this.store, rowIndex);
6475 // insert before rowIndex..
6476 var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
6480 if(row.cellObjects.length){
6481 Roo.each(row.cellObjects, function(r){
6482 _this.renderCellObject(r);
6487 this.fireEvent("rowsinserted", this, rowIndex);
6488 //this.syncRowHeights(firstRow, lastRow);
6489 //this.stripeRows(firstRow);
6496 getRowDom : function(rowIndex)
6498 var rows = this.el.select('tbody > tr', true).elements;
6500 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
6503 // returns the object tree for a tr..
6506 renderRow : function(cm, ds, rowIndex)
6509 var d = ds.getAt(rowIndex);
6516 var cellObjects = [];
6518 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6519 var config = cm.config[i];
6521 var renderer = cm.getRenderer(i);
6525 if(typeof(renderer) !== 'undefined'){
6526 value = renderer(d.data[cm.getDataIndex(i)], false, d);
6528 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
6529 // and are rendered into the cells after the row is rendered - using the id for the element.
6531 if(typeof(value) === 'object'){
6541 rowIndex : rowIndex,
6546 this.fireEvent('rowclass', this, rowcfg);
6550 cls : rowcfg.rowClass,
6552 html: (typeof(value) === 'object') ? '' : value
6559 if(typeof(config.colspan) != 'undefined'){
6560 td.colspan = config.colspan;
6563 if(typeof(config.hidden) != 'undefined' && config.hidden){
6564 td.style += ' display:none;';
6567 if(typeof(config.align) != 'undefined' && config.align.length){
6568 td.style += ' text-align:' + config.align + ';';
6571 if(typeof(config.width) != 'undefined'){
6572 td.style += ' width:' + config.width + 'px;';
6575 if(typeof(config.cursor) != 'undefined'){
6576 td.style += ' cursor:' + config.cursor + ';';
6579 if(typeof(config.cls) != 'undefined'){
6580 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
6583 ['xs','sm','md','lg'].map(function(size){
6585 if(typeof(config[size]) == 'undefined'){
6589 if (!config[size]) { // 0 = hidden
6590 td.cls += ' hidden-' + size;
6594 td.cls += ' col-' + size + '-' + config[size];
6602 row.cellObjects = cellObjects;
6610 onBeforeLoad : function()
6612 //Roo.log('ds onBeforeLoad');
6616 //if(this.loadMask){
6617 // this.maskEl.show();
6625 this.el.select('tbody', true).first().dom.innerHTML = '';
6628 * Show or hide a row.
6629 * @param {Number} rowIndex to show or hide
6630 * @param {Boolean} state hide
6632 setRowVisibility : function(rowIndex, state)
6634 var bt = this.mainBody.dom;
6636 var rows = this.el.select('tbody > tr', true).elements;
6638 if(typeof(rows[rowIndex]) == 'undefined'){
6641 rows[rowIndex].dom.style.display = state ? '' : 'none';
6645 getSelectionModel : function(){
6647 this.selModel = new Roo.bootstrap.Table.RowSelectionModel();
6649 return this.selModel;
6652 * Render the Roo.bootstrap object from renderder
6654 renderCellObject : function(r)
6658 var t = r.cfg.render(r.container);
6661 Roo.each(r.cfg.cn, function(c){
6663 container: t.getChildContainer(),
6666 _this.renderCellObject(child);
6671 getRowIndex : function(row)
6675 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
6686 * Returns the grid's underlying element = used by panel.Grid
6687 * @return {Element} The element
6689 getGridEl : function(){
6693 * Forces a resize - used by panel.Grid
6694 * @return {Element} The element
6696 autoSize : function(){
6697 //var ctr = Roo.get(this.container.dom.parentElement);
6698 var ctr = Roo.get(this.el.dom);
6700 var thd = this.getGridEl().select('thead',true).first();
6701 var tbd = this.getGridEl().select('tbody', true).first();
6704 var cw = ctr.getWidth();
6708 tbd.setSize(ctr.getWidth(), ctr.getHeight() - thd.getHeight());
6709 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
6712 cw = Math.max(cw, this.totalWidth);
6713 this.getGridEl().select('tr',true).setWidth(cw);
6715 return; // we doe not have a view in this design..
6718 onBodyScroll: function()
6721 //Roo.log("body scrolled');" + this.mainBody.dom.scrollLeft);
6722 this.mainHead.setStyle({
6723 'position' : 'relative',
6724 'left': (-1* this.mainBody.dom.scrollLeft) + 'px'
6741 * @class Roo.bootstrap.TableCell
6742 * @extends Roo.bootstrap.Component
6743 * Bootstrap TableCell class
6744 * @cfg {String} html cell contain text
6745 * @cfg {String} cls cell class
6746 * @cfg {String} tag cell tag (td|th) default td
6747 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
6748 * @cfg {String} align Aligns the content in a cell
6749 * @cfg {String} axis Categorizes cells
6750 * @cfg {String} bgcolor Specifies the background color of a cell
6751 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
6752 * @cfg {Number} colspan Specifies the number of columns a cell should span
6753 * @cfg {String} headers Specifies one or more header cells a cell is related to
6754 * @cfg {Number} height Sets the height of a cell
6755 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
6756 * @cfg {Number} rowspan Sets the number of rows a cell should span
6757 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
6758 * @cfg {String} valign Vertical aligns the content in a cell
6759 * @cfg {Number} width Specifies the width of a cell
6762 * Create a new TableCell
6763 * @param {Object} config The config object
6766 Roo.bootstrap.TableCell = function(config){
6767 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
6770 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
6790 getAutoCreate : function(){
6791 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
6811 cfg.align=this.align
6817 cfg.bgcolor=this.bgcolor
6820 cfg.charoff=this.charoff
6823 cfg.colspan=this.colspan
6826 cfg.headers=this.headers
6829 cfg.height=this.height
6832 cfg.nowrap=this.nowrap
6835 cfg.rowspan=this.rowspan
6838 cfg.scope=this.scope
6841 cfg.valign=this.valign
6844 cfg.width=this.width
6863 * @class Roo.bootstrap.TableRow
6864 * @extends Roo.bootstrap.Component
6865 * Bootstrap TableRow class
6866 * @cfg {String} cls row class
6867 * @cfg {String} align Aligns the content in a table row
6868 * @cfg {String} bgcolor Specifies a background color for a table row
6869 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
6870 * @cfg {String} valign Vertical aligns the content in a table row
6873 * Create a new TableRow
6874 * @param {Object} config The config object
6877 Roo.bootstrap.TableRow = function(config){
6878 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
6881 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
6889 getAutoCreate : function(){
6890 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
6900 cfg.align = this.align;
6903 cfg.bgcolor = this.bgcolor;
6906 cfg.charoff = this.charoff;
6909 cfg.valign = this.valign;
6927 * @class Roo.bootstrap.TableBody
6928 * @extends Roo.bootstrap.Component
6929 * Bootstrap TableBody class
6930 * @cfg {String} cls element class
6931 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
6932 * @cfg {String} align Aligns the content inside the element
6933 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
6934 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
6937 * Create a new TableBody
6938 * @param {Object} config The config object
6941 Roo.bootstrap.TableBody = function(config){
6942 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
6945 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
6953 getAutoCreate : function(){
6954 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
6968 cfg.align = this.align;
6971 cfg.charoff = this.charoff;
6974 cfg.valign = this.valign;
6981 // initEvents : function()
6988 // this.store = Roo.factory(this.store, Roo.data);
6989 // this.store.on('load', this.onLoad, this);
6991 // this.store.load();
6995 // onLoad: function ()
6997 // this.fireEvent('load', this);
7007 * Ext JS Library 1.1.1
7008 * Copyright(c) 2006-2007, Ext JS, LLC.
7010 * Originally Released Under LGPL - original licence link has changed is not relivant.
7013 * <script type="text/javascript">
7016 // as we use this in bootstrap.
7017 Roo.namespace('Roo.form');
7019 * @class Roo.form.Action
7020 * Internal Class used to handle form actions
7022 * @param {Roo.form.BasicForm} el The form element or its id
7023 * @param {Object} config Configuration options
7028 // define the action interface
7029 Roo.form.Action = function(form, options){
7031 this.options = options || {};
7034 * Client Validation Failed
7037 Roo.form.Action.CLIENT_INVALID = 'client';
7039 * Server Validation Failed
7042 Roo.form.Action.SERVER_INVALID = 'server';
7044 * Connect to Server Failed
7047 Roo.form.Action.CONNECT_FAILURE = 'connect';
7049 * Reading Data from Server Failed
7052 Roo.form.Action.LOAD_FAILURE = 'load';
7054 Roo.form.Action.prototype = {
7056 failureType : undefined,
7057 response : undefined,
7061 run : function(options){
7066 success : function(response){
7071 handleResponse : function(response){
7075 // default connection failure
7076 failure : function(response){
7078 this.response = response;
7079 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7080 this.form.afterAction(this, false);
7083 processResponse : function(response){
7084 this.response = response;
7085 if(!response.responseText){
7088 this.result = this.handleResponse(response);
7092 // utility functions used internally
7093 getUrl : function(appendParams){
7094 var url = this.options.url || this.form.url || this.form.el.dom.action;
7096 var p = this.getParams();
7098 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
7104 getMethod : function(){
7105 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
7108 getParams : function(){
7109 var bp = this.form.baseParams;
7110 var p = this.options.params;
7112 if(typeof p == "object"){
7113 p = Roo.urlEncode(Roo.applyIf(p, bp));
7114 }else if(typeof p == 'string' && bp){
7115 p += '&' + Roo.urlEncode(bp);
7118 p = Roo.urlEncode(bp);
7123 createCallback : function(){
7125 success: this.success,
7126 failure: this.failure,
7128 timeout: (this.form.timeout*1000),
7129 upload: this.form.fileUpload ? this.success : undefined
7134 Roo.form.Action.Submit = function(form, options){
7135 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
7138 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
7141 haveProgress : false,
7142 uploadComplete : false,
7144 // uploadProgress indicator.
7145 uploadProgress : function()
7147 if (!this.form.progressUrl) {
7151 if (!this.haveProgress) {
7152 Roo.MessageBox.progress("Uploading", "Uploading");
7154 if (this.uploadComplete) {
7155 Roo.MessageBox.hide();
7159 this.haveProgress = true;
7161 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
7163 var c = new Roo.data.Connection();
7165 url : this.form.progressUrl,
7170 success : function(req){
7171 //console.log(data);
7175 rdata = Roo.decode(req.responseText)
7177 Roo.log("Invalid data from server..");
7181 if (!rdata || !rdata.success) {
7183 Roo.MessageBox.alert(Roo.encode(rdata));
7186 var data = rdata.data;
7188 if (this.uploadComplete) {
7189 Roo.MessageBox.hide();
7194 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
7195 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
7198 this.uploadProgress.defer(2000,this);
7201 failure: function(data) {
7202 Roo.log('progress url failed ');
7213 // run get Values on the form, so it syncs any secondary forms.
7214 this.form.getValues();
7216 var o = this.options;
7217 var method = this.getMethod();
7218 var isPost = method == 'POST';
7219 if(o.clientValidation === false || this.form.isValid()){
7221 if (this.form.progressUrl) {
7222 this.form.findField('UPLOAD_IDENTIFIER').setValue(
7223 (new Date() * 1) + '' + Math.random());
7228 Roo.Ajax.request(Roo.apply(this.createCallback(), {
7229 form:this.form.el.dom,
7230 url:this.getUrl(!isPost),
7232 params:isPost ? this.getParams() : null,
7233 isUpload: this.form.fileUpload
7236 this.uploadProgress();
7238 }else if (o.clientValidation !== false){ // client validation failed
7239 this.failureType = Roo.form.Action.CLIENT_INVALID;
7240 this.form.afterAction(this, false);
7244 success : function(response)
7246 this.uploadComplete= true;
7247 if (this.haveProgress) {
7248 Roo.MessageBox.hide();
7252 var result = this.processResponse(response);
7253 if(result === true || result.success){
7254 this.form.afterAction(this, true);
7258 this.form.markInvalid(result.errors);
7259 this.failureType = Roo.form.Action.SERVER_INVALID;
7261 this.form.afterAction(this, false);
7263 failure : function(response)
7265 this.uploadComplete= true;
7266 if (this.haveProgress) {
7267 Roo.MessageBox.hide();
7270 this.response = response;
7271 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7272 this.form.afterAction(this, false);
7275 handleResponse : function(response){
7276 if(this.form.errorReader){
7277 var rs = this.form.errorReader.read(response);
7280 for(var i = 0, len = rs.records.length; i < len; i++) {
7281 var r = rs.records[i];
7285 if(errors.length < 1){
7289 success : rs.success,
7295 ret = Roo.decode(response.responseText);
7299 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
7309 Roo.form.Action.Load = function(form, options){
7310 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
7311 this.reader = this.form.reader;
7314 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
7319 Roo.Ajax.request(Roo.apply(
7320 this.createCallback(), {
7321 method:this.getMethod(),
7322 url:this.getUrl(false),
7323 params:this.getParams()
7327 success : function(response){
7329 var result = this.processResponse(response);
7330 if(result === true || !result.success || !result.data){
7331 this.failureType = Roo.form.Action.LOAD_FAILURE;
7332 this.form.afterAction(this, false);
7335 this.form.clearInvalid();
7336 this.form.setValues(result.data);
7337 this.form.afterAction(this, true);
7340 handleResponse : function(response){
7341 if(this.form.reader){
7342 var rs = this.form.reader.read(response);
7343 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
7345 success : rs.success,
7349 return Roo.decode(response.responseText);
7353 Roo.form.Action.ACTION_TYPES = {
7354 'load' : Roo.form.Action.Load,
7355 'submit' : Roo.form.Action.Submit
7364 * @class Roo.bootstrap.Form
7365 * @extends Roo.bootstrap.Component
7366 * Bootstrap Form class
7367 * @cfg {String} method GET | POST (default POST)
7368 * @cfg {String} labelAlign top | left (default top)
7369 * @cfg {String} align left | right - for navbars
7370 * @cfg {Boolean} loadMask load mask when submit (default true)
7375 * @param {Object} config The config object
7379 Roo.bootstrap.Form = function(config){
7380 Roo.bootstrap.Form.superclass.constructor.call(this, config);
7383 * @event clientvalidation
7384 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
7385 * @param {Form} this
7386 * @param {Boolean} valid true if the form has passed client-side validation
7388 clientvalidation: true,
7390 * @event beforeaction
7391 * Fires before any action is performed. Return false to cancel the action.
7392 * @param {Form} this
7393 * @param {Action} action The action to be performed
7397 * @event actionfailed
7398 * Fires when an action fails.
7399 * @param {Form} this
7400 * @param {Action} action The action that failed
7402 actionfailed : true,
7404 * @event actioncomplete
7405 * Fires when an action is completed.
7406 * @param {Form} this
7407 * @param {Action} action The action that completed
7409 actioncomplete : true
7414 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component, {
7417 * @cfg {String} method
7418 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
7423 * The URL to use for form actions if one isn't supplied in the action options.
7426 * @cfg {Boolean} fileUpload
7427 * Set to true if this form is a file upload.
7431 * @cfg {Object} baseParams
7432 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
7436 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
7440 * @cfg {Sting} align (left|right) for navbar forms
7445 activeAction : null,
7448 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
7449 * element by passing it or its id or mask the form itself by passing in true.
7452 waitMsgTarget : false,
7456 getAutoCreate : function(){
7460 method : this.method || 'POST',
7461 id : this.id || Roo.id(),
7464 if (this.parent().xtype.match(/^Nav/)) {
7465 cfg.cls = 'navbar-form navbar-' + this.align;
7469 if (this.labelAlign == 'left' ) {
7470 cfg.cls += ' form-horizontal';
7476 initEvents : function()
7478 this.el.on('submit', this.onSubmit, this);
7479 // this was added as random key presses on the form where triggering form submit.
7480 this.el.on('keypress', function(e) {
7481 if (e.getCharCode() != 13) {
7484 // we might need to allow it for textareas.. and some other items.
7485 // check e.getTarget().
7487 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
7491 Roo.log("keypress blocked");
7499 onSubmit : function(e){
7504 * Returns true if client-side validation on the form is successful.
7507 isValid : function(){
7508 var items = this.getItems();
7510 items.each(function(f){
7519 * Returns true if any fields in this form have changed since their original load.
7522 isDirty : function(){
7524 var items = this.getItems();
7525 items.each(function(f){
7535 * Performs a predefined action (submit or load) or custom actions you define on this form.
7536 * @param {String} actionName The name of the action type
7537 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
7538 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
7539 * accept other config options):
7541 Property Type Description
7542 ---------------- --------------- ----------------------------------------------------------------------------------
7543 url String The url for the action (defaults to the form's url)
7544 method String The form method to use (defaults to the form's method, or POST if not defined)
7545 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
7546 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
7547 validate the form on the client (defaults to false)
7549 * @return {BasicForm} this
7551 doAction : function(action, options){
7552 if(typeof action == 'string'){
7553 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
7555 if(this.fireEvent('beforeaction', this, action) !== false){
7556 this.beforeAction(action);
7557 action.run.defer(100, action);
7563 beforeAction : function(action){
7564 var o = action.options;
7567 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7569 // not really supported yet.. ??
7571 //if(this.waitMsgTarget === true){
7572 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7573 //}else if(this.waitMsgTarget){
7574 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
7575 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
7577 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
7583 afterAction : function(action, success){
7584 this.activeAction = null;
7585 var o = action.options;
7587 //if(this.waitMsgTarget === true){
7589 //}else if(this.waitMsgTarget){
7590 // this.waitMsgTarget.unmask();
7592 // Roo.MessageBox.updateProgress(1);
7593 // Roo.MessageBox.hide();
7600 Roo.callback(o.success, o.scope, [this, action]);
7601 this.fireEvent('actioncomplete', this, action);
7605 // failure condition..
7606 // we have a scenario where updates need confirming.
7607 // eg. if a locking scenario exists..
7608 // we look for { errors : { needs_confirm : true }} in the response.
7610 (typeof(action.result) != 'undefined') &&
7611 (typeof(action.result.errors) != 'undefined') &&
7612 (typeof(action.result.errors.needs_confirm) != 'undefined')
7615 Roo.log("not supported yet");
7618 Roo.MessageBox.confirm(
7619 "Change requires confirmation",
7620 action.result.errorMsg,
7625 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
7635 Roo.callback(o.failure, o.scope, [this, action]);
7636 // show an error message if no failed handler is set..
7637 if (!this.hasListener('actionfailed')) {
7638 Roo.log("need to add dialog support");
7640 Roo.MessageBox.alert("Error",
7641 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
7642 action.result.errorMsg :
7643 "Saving Failed, please check your entries or try again"
7648 this.fireEvent('actionfailed', this, action);
7653 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
7654 * @param {String} id The value to search for
7657 findField : function(id){
7658 var items = this.getItems();
7659 var field = items.get(id);
7661 items.each(function(f){
7662 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
7669 return field || null;
7672 * Mark fields in this form invalid in bulk.
7673 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
7674 * @return {BasicForm} this
7676 markInvalid : function(errors){
7677 if(errors instanceof Array){
7678 for(var i = 0, len = errors.length; i < len; i++){
7679 var fieldError = errors[i];
7680 var f = this.findField(fieldError.id);
7682 f.markInvalid(fieldError.msg);
7688 if(typeof errors[id] != 'function' && (field = this.findField(id))){
7689 field.markInvalid(errors[id]);
7693 //Roo.each(this.childForms || [], function (f) {
7694 // f.markInvalid(errors);
7701 * Set values for fields in this form in bulk.
7702 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
7703 * @return {BasicForm} this
7705 setValues : function(values){
7706 if(values instanceof Array){ // array of objects
7707 for(var i = 0, len = values.length; i < len; i++){
7709 var f = this.findField(v.id);
7711 f.setValue(v.value);
7712 if(this.trackResetOnLoad){
7713 f.originalValue = f.getValue();
7717 }else{ // object hash
7720 if(typeof values[id] != 'function' && (field = this.findField(id))){
7722 if (field.setFromData &&
7724 field.displayField &&
7725 // combos' with local stores can
7726 // be queried via setValue()
7727 // to set their value..
7728 (field.store && !field.store.isLocal)
7732 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
7733 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
7734 field.setFromData(sd);
7737 field.setValue(values[id]);
7741 if(this.trackResetOnLoad){
7742 field.originalValue = field.getValue();
7748 //Roo.each(this.childForms || [], function (f) {
7749 // f.setValues(values);
7756 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
7757 * they are returned as an array.
7758 * @param {Boolean} asString
7761 getValues : function(asString){
7762 //if (this.childForms) {
7763 // copy values from the child forms
7764 // Roo.each(this.childForms, function (f) {
7765 // this.setValues(f.getValues());
7771 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
7772 if(asString === true){
7775 return Roo.urlDecode(fs);
7779 * Returns the fields in this form as an object with key/value pairs.
7780 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
7783 getFieldValues : function(with_hidden)
7785 var items = this.getItems();
7787 items.each(function(f){
7791 var v = f.getValue();
7792 if (f.inputType =='radio') {
7793 if (typeof(ret[f.getName()]) == 'undefined') {
7794 ret[f.getName()] = ''; // empty..
7797 if (!f.el.dom.checked) {
7805 // not sure if this supported any more..
7806 if ((typeof(v) == 'object') && f.getRawValue) {
7807 v = f.getRawValue() ; // dates..
7809 // combo boxes where name != hiddenName...
7810 if (f.name != f.getName()) {
7811 ret[f.name] = f.getRawValue();
7813 ret[f.getName()] = v;
7820 * Clears all invalid messages in this form.
7821 * @return {BasicForm} this
7823 clearInvalid : function(){
7824 var items = this.getItems();
7826 items.each(function(f){
7837 * @return {BasicForm} this
7840 var items = this.getItems();
7841 items.each(function(f){
7845 Roo.each(this.childForms || [], function (f) {
7852 getItems : function()
7854 var r=new Roo.util.MixedCollection(false, function(o){
7855 return o.id || (o.id = Roo.id());
7857 var iter = function(el) {
7864 Roo.each(el.items,function(e) {
7884 * Ext JS Library 1.1.1
7885 * Copyright(c) 2006-2007, Ext JS, LLC.
7887 * Originally Released Under LGPL - original licence link has changed is not relivant.
7890 * <script type="text/javascript">
7893 * @class Roo.form.VTypes
7894 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
7897 Roo.form.VTypes = function(){
7898 // closure these in so they are only created once.
7899 var alpha = /^[a-zA-Z_]+$/;
7900 var alphanum = /^[a-zA-Z0-9_]+$/;
7901 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
7902 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
7904 // All these messages and functions are configurable
7907 * The function used to validate email addresses
7908 * @param {String} value The email address
7910 'email' : function(v){
7911 return email.test(v);
7914 * The error text to display when the email validation function returns false
7917 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
7919 * The keystroke filter mask to be applied on email input
7922 'emailMask' : /[a-z0-9_\.\-@]/i,
7925 * The function used to validate URLs
7926 * @param {String} value The URL
7928 'url' : function(v){
7932 * The error text to display when the url validation function returns false
7935 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
7938 * The function used to validate alpha values
7939 * @param {String} value The value
7941 'alpha' : function(v){
7942 return alpha.test(v);
7945 * The error text to display when the alpha validation function returns false
7948 'alphaText' : 'This field should only contain letters and _',
7950 * The keystroke filter mask to be applied on alpha input
7953 'alphaMask' : /[a-z_]/i,
7956 * The function used to validate alphanumeric values
7957 * @param {String} value The value
7959 'alphanum' : function(v){
7960 return alphanum.test(v);
7963 * The error text to display when the alphanumeric validation function returns false
7966 'alphanumText' : 'This field should only contain letters, numbers and _',
7968 * The keystroke filter mask to be applied on alphanumeric input
7971 'alphanumMask' : /[a-z0-9_]/i
7981 * @class Roo.bootstrap.Input
7982 * @extends Roo.bootstrap.Component
7983 * Bootstrap Input class
7984 * @cfg {Boolean} disabled is it disabled
7985 * @cfg {String} inputType button | checkbox | email | file | hidden | image | number | password | radio | range | reset | search | submit | text
7986 * @cfg {String} name name of the input
7987 * @cfg {string} fieldLabel - the label associated
7988 * @cfg {string} placeholder - placeholder to put in text.
7989 * @cfg {string} before - input group add on before
7990 * @cfg {string} after - input group add on after
7991 * @cfg {string} size - (lg|sm) or leave empty..
7992 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
7993 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
7994 * @cfg {Number} md colspan out of 12 for computer-sized screens
7995 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
7996 * @cfg {string} value default value of the input
7997 * @cfg {Number} labelWidth set the width of label (0-12)
7998 * @cfg {String} labelAlign (top|left)
7999 * @cfg {Boolean} readOnly Specifies that the field should be read-only
8000 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
8002 * @cfg {String} align (left|center|right) Default left
8003 * @cfg {Boolean} forceFeedback (true|false) Default false
8009 * Create a new Input
8010 * @param {Object} config The config object
8013 Roo.bootstrap.Input = function(config){
8014 Roo.bootstrap.Input.superclass.constructor.call(this, config);
8019 * Fires when this field receives input focus.
8020 * @param {Roo.form.Field} this
8025 * Fires when this field loses input focus.
8026 * @param {Roo.form.Field} this
8031 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
8032 * {@link Roo.EventObject#getKey} to determine which key was pressed.
8033 * @param {Roo.form.Field} this
8034 * @param {Roo.EventObject} e The event object
8039 * Fires just before the field blurs if the field value has changed.
8040 * @param {Roo.form.Field} this
8041 * @param {Mixed} newValue The new value
8042 * @param {Mixed} oldValue The original value
8047 * Fires after the field has been marked as invalid.
8048 * @param {Roo.form.Field} this
8049 * @param {String} msg The validation message
8054 * Fires after the field has been validated with no errors.
8055 * @param {Roo.form.Field} this
8060 * Fires after the key up
8061 * @param {Roo.form.Field} this
8062 * @param {Roo.EventObject} e The event Object
8068 Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component, {
8070 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
8071 automatic validation (defaults to "keyup").
8073 validationEvent : "keyup",
8075 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
8077 validateOnBlur : true,
8079 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
8081 validationDelay : 250,
8083 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
8085 focusClass : "x-form-focus", // not needed???
8089 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
8091 invalidClass : "has-warning",
8094 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
8096 validClass : "has-success",
8099 * @cfg {Boolean} hasFeedback (true|false) default true
8104 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8106 invalidFeedbackClass : "glyphicon-warning-sign",
8109 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8111 validFeedbackClass : "glyphicon-ok",
8114 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
8116 selectOnFocus : false,
8119 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
8123 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
8128 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
8130 disableKeyFilter : false,
8133 * @cfg {Boolean} disabled True to disable the field (defaults to false).
8137 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
8141 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
8143 blankText : "This field is required",
8146 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
8150 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
8152 maxLength : Number.MAX_VALUE,
8154 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
8156 minLengthText : "The minimum length for this field is {0}",
8158 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
8160 maxLengthText : "The maximum length for this field is {0}",
8164 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
8165 * If available, this function will be called only after the basic validators all return true, and will be passed the
8166 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
8170 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
8171 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
8172 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
8176 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
8180 autocomplete: false,
8199 formatedValue : false,
8200 forceFeedback : false,
8202 parentLabelAlign : function()
8205 while (parent.parent()) {
8206 parent = parent.parent();
8207 if (typeof(parent.labelAlign) !='undefined') {
8208 return parent.labelAlign;
8215 getAutoCreate : function(){
8217 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8225 if(this.inputType != 'hidden'){
8226 cfg.cls = 'form-group' //input-group
8232 type : this.inputType,
8234 cls : 'form-control',
8235 placeholder : this.placeholder || '',
8236 autocomplete : this.autocomplete || 'new-password'
8241 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
8244 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
8245 input.maxLength = this.maxLength;
8248 if (this.disabled) {
8249 input.disabled=true;
8252 if (this.readOnly) {
8253 input.readonly=true;
8257 input.name = this.name;
8260 input.cls += ' input-' + this.size;
8263 ['xs','sm','md','lg'].map(function(size){
8264 if (settings[size]) {
8265 cfg.cls += ' col-' + size + '-' + settings[size];
8269 var inputblock = input;
8273 cls: 'glyphicon form-control-feedback'
8276 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8279 cls : 'has-feedback',
8287 if (this.before || this.after) {
8290 cls : 'input-group',
8294 if (this.before && typeof(this.before) == 'string') {
8296 inputblock.cn.push({
8298 cls : 'roo-input-before input-group-addon',
8302 if (this.before && typeof(this.before) == 'object') {
8303 this.before = Roo.factory(this.before);
8305 inputblock.cn.push({
8307 cls : 'roo-input-before input-group-' +
8308 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8312 inputblock.cn.push(input);
8314 if (this.after && typeof(this.after) == 'string') {
8315 inputblock.cn.push({
8317 cls : 'roo-input-after input-group-addon',
8321 if (this.after && typeof(this.after) == 'object') {
8322 this.after = Roo.factory(this.after);
8324 inputblock.cn.push({
8326 cls : 'roo-input-after input-group-' +
8327 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8331 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8332 inputblock.cls += ' has-feedback';
8333 inputblock.cn.push(feedback);
8337 if (align ==='left' && this.fieldLabel.length) {
8344 cls : 'control-label col-sm-' + this.labelWidth,
8345 html : this.fieldLabel
8349 cls : "col-sm-" + (12 - this.labelWidth),
8356 } else if ( this.fieldLabel.length) {
8362 //cls : 'input-group-addon',
8363 html : this.fieldLabel
8382 if (this.parentType === 'Navbar' && this.parent().bar) {
8383 cfg.cls += ' navbar-form';
8385 if (this.parentType === 'NavGroup') {
8386 cfg.cls += ' navbar-form';
8393 * return the real input element.
8395 inputEl: function ()
8397 return this.el.select('input.form-control',true).first();
8400 tooltipEl : function()
8402 return this.inputEl();
8405 setDisabled : function(v)
8407 var i = this.inputEl().dom;
8409 i.removeAttribute('disabled');
8413 i.setAttribute('disabled','true');
8415 initEvents : function()
8418 this.inputEl().on("keydown" , this.fireKey, this);
8419 this.inputEl().on("focus", this.onFocus, this);
8420 this.inputEl().on("blur", this.onBlur, this);
8422 this.inputEl().relayEvent('keyup', this);
8424 // reference to original value for reset
8425 this.originalValue = this.getValue();
8426 //Roo.form.TextField.superclass.initEvents.call(this);
8427 if(this.validationEvent == 'keyup'){
8428 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
8429 this.inputEl().on('keyup', this.filterValidation, this);
8431 else if(this.validationEvent !== false){
8432 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
8435 if(this.selectOnFocus){
8436 this.on("focus", this.preFocus, this);
8439 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
8440 this.inputEl().on("keypress", this.filterKeys, this);
8443 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
8444 this.el.on("click", this.autoSize, this);
8447 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
8448 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
8451 if (typeof(this.before) == 'object') {
8452 this.before.render(this.el.select('.roo-input-before',true).first());
8454 if (typeof(this.after) == 'object') {
8455 this.after.render(this.el.select('.roo-input-after',true).first());
8460 filterValidation : function(e){
8461 if(!e.isNavKeyPress()){
8462 this.validationTask.delay(this.validationDelay);
8466 * Validates the field value
8467 * @return {Boolean} True if the value is valid, else false
8469 validate : function(){
8470 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
8471 if(this.disabled || this.validateValue(this.getRawValue())){
8482 * Validates a value according to the field's validation rules and marks the field as invalid
8483 * if the validation fails
8484 * @param {Mixed} value The value to validate
8485 * @return {Boolean} True if the value is valid, else false
8487 validateValue : function(value){
8488 if(value.length < 1) { // if it's blank
8489 if(this.allowBlank){
8495 if(value.length < this.minLength){
8498 if(value.length > this.maxLength){
8502 var vt = Roo.form.VTypes;
8503 if(!vt[this.vtype](value, this)){
8507 if(typeof this.validator == "function"){
8508 var msg = this.validator(value);
8514 if(this.regex && !this.regex.test(value)){
8524 fireKey : function(e){
8525 //Roo.log('field ' + e.getKey());
8526 if(e.isNavKeyPress()){
8527 this.fireEvent("specialkey", this, e);
8530 focus : function (selectText){
8532 this.inputEl().focus();
8533 if(selectText === true){
8534 this.inputEl().dom.select();
8540 onFocus : function(){
8541 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
8542 // this.el.addClass(this.focusClass);
8545 this.hasFocus = true;
8546 this.startValue = this.getValue();
8547 this.fireEvent("focus", this);
8551 beforeBlur : Roo.emptyFn,
8555 onBlur : function(){
8557 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
8558 //this.el.removeClass(this.focusClass);
8560 this.hasFocus = false;
8561 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
8564 var v = this.getValue();
8565 if(String(v) !== String(this.startValue)){
8566 this.fireEvent('change', this, v, this.startValue);
8568 this.fireEvent("blur", this);
8572 * Resets the current field value to the originally loaded value and clears any validation messages
8575 this.setValue(this.originalValue);
8579 * Returns the name of the field
8580 * @return {Mixed} name The name field
8582 getName: function(){
8586 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
8587 * @return {Mixed} value The field value
8589 getValue : function(){
8591 var v = this.inputEl().getValue();
8596 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
8597 * @return {Mixed} value The field value
8599 getRawValue : function(){
8600 var v = this.inputEl().getValue();
8606 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
8607 * @param {Mixed} value The value to set
8609 setRawValue : function(v){
8610 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
8613 selectText : function(start, end){
8614 var v = this.getRawValue();
8616 start = start === undefined ? 0 : start;
8617 end = end === undefined ? v.length : end;
8618 var d = this.inputEl().dom;
8619 if(d.setSelectionRange){
8620 d.setSelectionRange(start, end);
8621 }else if(d.createTextRange){
8622 var range = d.createTextRange();
8623 range.moveStart("character", start);
8624 range.moveEnd("character", v.length-end);
8631 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
8632 * @param {Mixed} value The value to set
8634 setValue : function(v){
8637 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
8643 processValue : function(value){
8644 if(this.stripCharsRe){
8645 var newValue = value.replace(this.stripCharsRe, '');
8646 if(newValue !== value){
8647 this.setRawValue(newValue);
8654 preFocus : function(){
8656 if(this.selectOnFocus){
8657 this.inputEl().dom.select();
8660 filterKeys : function(e){
8662 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
8665 var c = e.getCharCode(), cc = String.fromCharCode(c);
8666 if(Roo.isIE && (e.isSpecialKey() || !cc)){
8669 if(!this.maskRe.test(cc)){
8674 * Clear any invalid styles/messages for this field
8676 clearInvalid : function(){
8678 if(!this.el || this.preventMark){ // not rendered
8682 var label = this.el.select('label', true).first();
8683 var icon = this.el.select('i.fa-star', true).first();
8689 this.el.removeClass(this.invalidClass);
8691 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8693 var feedback = this.el.select('.form-control-feedback', true).first();
8696 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
8701 this.fireEvent('valid', this);
8705 * Mark this field as valid
8707 markValid : function()
8709 if(!this.el || this.preventMark){ // not rendered
8713 this.el.removeClass([this.invalidClass, this.validClass]);
8715 var feedback = this.el.select('.form-control-feedback', true).first();
8718 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
8721 if(this.disabled || this.allowBlank){
8725 var formGroup = this.el.findParent('.form-group', false, true);
8729 var label = formGroup.select('label', true).first();
8730 var icon = formGroup.select('i.fa-star', true).first();
8737 this.el.addClass(this.validClass);
8739 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
8741 var feedback = this.el.select('.form-control-feedback', true).first();
8744 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
8745 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
8750 this.fireEvent('valid', this);
8754 * Mark this field as invalid
8755 * @param {String} msg The validation message
8757 markInvalid : function(msg)
8759 if(!this.el || this.preventMark){ // not rendered
8763 this.el.removeClass([this.invalidClass, this.validClass]);
8765 var feedback = this.el.select('.form-control-feedback', true).first();
8768 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
8771 if(this.disabled || this.allowBlank){
8775 var formGroup = this.el.findParent('.form-group', false, true);
8778 var label = formGroup.select('label', true).first();
8779 var icon = formGroup.select('i.fa-star', true).first();
8781 if(!this.getValue().length && label && !icon){
8782 this.el.findParent('.form-group', false, true).createChild({
8784 cls : 'text-danger fa fa-lg fa-star',
8785 tooltip : 'This field is required',
8786 style : 'margin-right:5px;'
8792 this.el.addClass(this.invalidClass);
8794 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8796 var feedback = this.el.select('.form-control-feedback', true).first();
8799 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
8801 if(this.getValue().length || this.forceFeedback){
8802 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
8809 this.fireEvent('invalid', this, msg);
8812 SafariOnKeyDown : function(event)
8814 // this is a workaround for a password hang bug on chrome/ webkit.
8816 var isSelectAll = false;
8818 if(this.inputEl().dom.selectionEnd > 0){
8819 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
8821 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
8822 event.preventDefault();
8827 if(isSelectAll && event.getCharCode() > 31){ // not backspace and delete key
8829 event.preventDefault();
8830 // this is very hacky as keydown always get's upper case.
8832 var cc = String.fromCharCode(event.getCharCode());
8833 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
8837 adjustWidth : function(tag, w){
8838 tag = tag.toLowerCase();
8839 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
8840 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
8844 if(tag == 'textarea'){
8847 }else if(Roo.isOpera){
8851 if(tag == 'textarea'){
8870 * @class Roo.bootstrap.TextArea
8871 * @extends Roo.bootstrap.Input
8872 * Bootstrap TextArea class
8873 * @cfg {Number} cols Specifies the visible width of a text area
8874 * @cfg {Number} rows Specifies the visible number of lines in a text area
8875 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
8876 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
8877 * @cfg {string} html text
8880 * Create a new TextArea
8881 * @param {Object} config The config object
8884 Roo.bootstrap.TextArea = function(config){
8885 Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
8889 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input, {
8899 getAutoCreate : function(){
8901 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8912 value : this.value || '',
8913 html: this.html || '',
8914 cls : 'form-control',
8915 placeholder : this.placeholder || ''
8919 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
8920 input.maxLength = this.maxLength;
8924 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
8928 input.cols = this.cols;
8931 if (this.readOnly) {
8932 input.readonly = true;
8936 input.name = this.name;
8940 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
8944 ['xs','sm','md','lg'].map(function(size){
8945 if (settings[size]) {
8946 cfg.cls += ' col-' + size + '-' + settings[size];
8950 var inputblock = input;
8952 if(this.hasFeedback && !this.allowBlank){
8956 cls: 'glyphicon form-control-feedback'
8960 cls : 'has-feedback',
8969 if (this.before || this.after) {
8972 cls : 'input-group',
8976 inputblock.cn.push({
8978 cls : 'input-group-addon',
8983 inputblock.cn.push(input);
8985 if(this.hasFeedback && !this.allowBlank){
8986 inputblock.cls += ' has-feedback';
8987 inputblock.cn.push(feedback);
8991 inputblock.cn.push({
8993 cls : 'input-group-addon',
9000 if (align ==='left' && this.fieldLabel.length) {
9001 // Roo.log("left and has label");
9007 cls : 'control-label col-sm-' + this.labelWidth,
9008 html : this.fieldLabel
9012 cls : "col-sm-" + (12 - this.labelWidth),
9019 } else if ( this.fieldLabel.length) {
9020 // Roo.log(" label");
9025 //cls : 'input-group-addon',
9026 html : this.fieldLabel
9036 // Roo.log(" no label && no align");
9046 if (this.disabled) {
9047 input.disabled=true;
9054 * return the real textarea element.
9056 inputEl: function ()
9058 return this.el.select('textarea.form-control',true).first();
9062 * Clear any invalid styles/messages for this field
9064 clearInvalid : function()
9067 if(!this.el || this.preventMark){ // not rendered
9071 var label = this.el.select('label', true).first();
9072 var icon = this.el.select('i.fa-star', true).first();
9078 this.el.removeClass(this.invalidClass);
9080 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9082 var feedback = this.el.select('.form-control-feedback', true).first();
9085 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9090 this.fireEvent('valid', this);
9094 * Mark this field as valid
9096 markValid : function()
9098 if(!this.el || this.preventMark){ // not rendered
9102 this.el.removeClass([this.invalidClass, this.validClass]);
9104 var feedback = this.el.select('.form-control-feedback', true).first();
9107 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9110 if(this.disabled || this.allowBlank){
9114 var label = this.el.select('label', true).first();
9115 var icon = this.el.select('i.fa-star', true).first();
9121 this.el.addClass(this.validClass);
9123 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9125 var feedback = this.el.select('.form-control-feedback', true).first();
9128 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9129 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9134 this.fireEvent('valid', this);
9138 * Mark this field as invalid
9139 * @param {String} msg The validation message
9141 markInvalid : function(msg)
9143 if(!this.el || this.preventMark){ // not rendered
9147 this.el.removeClass([this.invalidClass, this.validClass]);
9149 var feedback = this.el.select('.form-control-feedback', true).first();
9152 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9155 if(this.disabled || this.allowBlank){
9159 var label = this.el.select('label', true).first();
9160 var icon = this.el.select('i.fa-star', true).first();
9162 if(!this.getValue().length && label && !icon){
9163 this.el.createChild({
9165 cls : 'text-danger fa fa-lg fa-star',
9166 tooltip : 'This field is required',
9167 style : 'margin-right:5px;'
9171 this.el.addClass(this.invalidClass);
9173 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9175 var feedback = this.el.select('.form-control-feedback', true).first();
9178 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9180 if(this.getValue().length || this.forceFeedback){
9181 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9188 this.fireEvent('invalid', this, msg);
9196 * trigger field - base class for combo..
9201 * @class Roo.bootstrap.TriggerField
9202 * @extends Roo.bootstrap.Input
9203 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
9204 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
9205 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
9206 * for which you can provide a custom implementation. For example:
9208 var trigger = new Roo.bootstrap.TriggerField();
9209 trigger.onTriggerClick = myTriggerFn;
9210 trigger.applyTo('my-field');
9213 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
9214 * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
9215 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
9216 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
9217 * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
9220 * Create a new TriggerField.
9221 * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
9222 * to the base TextField)
9224 Roo.bootstrap.TriggerField = function(config){
9225 this.mimicing = false;
9226 Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
9229 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input, {
9231 * @cfg {String} triggerClass A CSS class to apply to the trigger
9234 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
9239 * @cfg {Boolean} removable (true|false) special filter default false
9243 /** @cfg {Boolean} grow @hide */
9244 /** @cfg {Number} growMin @hide */
9245 /** @cfg {Number} growMax @hide */
9251 autoSize: Roo.emptyFn,
9258 actionMode : 'wrap',
9263 getAutoCreate : function(){
9265 var align = this.labelAlign || this.parentLabelAlign();
9270 cls: 'form-group' //input-group
9277 type : this.inputType,
9278 cls : 'form-control',
9279 autocomplete: 'new-password',
9280 placeholder : this.placeholder || ''
9284 input.name = this.name;
9287 input.cls += ' input-' + this.size;
9290 if (this.disabled) {
9291 input.disabled=true;
9294 var inputblock = input;
9296 if(this.hasFeedback && !this.allowBlank){
9300 cls: 'glyphicon form-control-feedback'
9303 if(this.removable && !this.editable && !this.tickable){
9305 cls : 'has-feedback',
9311 cls : 'roo-combo-removable-btn close'
9318 cls : 'has-feedback',
9327 if(this.removable && !this.editable && !this.tickable){
9329 cls : 'roo-removable',
9335 cls : 'roo-combo-removable-btn close'
9342 if (this.before || this.after) {
9345 cls : 'input-group',
9349 inputblock.cn.push({
9351 cls : 'input-group-addon',
9356 inputblock.cn.push(input);
9358 if(this.hasFeedback && !this.allowBlank){
9359 inputblock.cls += ' has-feedback';
9360 inputblock.cn.push(feedback);
9364 inputblock.cn.push({
9366 cls : 'input-group-addon',
9379 cls: 'form-hidden-field'
9393 cls: 'form-hidden-field'
9397 cls: 'roo-select2-choices',
9401 cls: 'roo-select2-search-field',
9414 cls: 'roo-select2-container input-group',
9419 // cls: 'typeahead typeahead-long dropdown-menu',
9420 // style: 'display:none'
9425 if(!this.multiple && this.showToggleBtn){
9431 if (this.caret != false) {
9434 cls: 'fa fa-' + this.caret
9441 cls : 'input-group-addon btn dropdown-toggle',
9446 cls: 'combobox-clear',
9460 combobox.cls += ' roo-select2-container-multi';
9463 if (align ==='left' && this.fieldLabel.length) {
9465 // Roo.log("left and has label");
9471 cls : 'control-label col-sm-' + this.labelWidth,
9472 html : this.fieldLabel
9476 cls : "col-sm-" + (12 - this.labelWidth),
9483 } else if ( this.fieldLabel.length) {
9484 // Roo.log(" label");
9489 //cls : 'input-group-addon',
9490 html : this.fieldLabel
9500 // Roo.log(" no label && no align");
9507 ['xs','sm','md','lg'].map(function(size){
9508 if (settings[size]) {
9509 cfg.cls += ' col-' + size + '-' + settings[size];
9520 onResize : function(w, h){
9521 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
9522 // if(typeof w == 'number'){
9523 // var x = w - this.trigger.getWidth();
9524 // this.inputEl().setWidth(this.adjustWidth('input', x));
9525 // this.trigger.setStyle('left', x+'px');
9530 adjustSize : Roo.BoxComponent.prototype.adjustSize,
9533 getResizeEl : function(){
9534 return this.inputEl();
9538 getPositionEl : function(){
9539 return this.inputEl();
9543 alignErrorIcon : function(){
9544 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
9548 initEvents : function(){
9552 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
9553 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
9554 if(!this.multiple && this.showToggleBtn){
9555 this.trigger = this.el.select('span.dropdown-toggle',true).first();
9556 if(this.hideTrigger){
9557 this.trigger.setDisplayed(false);
9559 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
9563 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
9566 if(this.removable && !this.editable && !this.tickable){
9567 var close = this.closeTriggerEl();
9570 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
9571 close.on('click', this.removeBtnClick, this, close);
9575 //this.trigger.addClassOnOver('x-form-trigger-over');
9576 //this.trigger.addClassOnClick('x-form-trigger-click');
9579 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
9583 closeTriggerEl : function()
9585 var close = this.el.select('.roo-combo-removable-btn', true).first();
9586 return close ? close : false;
9589 removeBtnClick : function(e, h, el)
9593 if(this.fireEvent("remove", this) !== false){
9595 this.fireEvent("afterremove", this)
9599 createList : function()
9601 this.list = Roo.get(document.body).createChild({
9603 cls: 'typeahead typeahead-long dropdown-menu',
9604 style: 'display:none'
9607 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
9612 initTrigger : function(){
9617 onDestroy : function(){
9619 this.trigger.removeAllListeners();
9620 // this.trigger.remove();
9623 // this.wrap.remove();
9625 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
9629 onFocus : function(){
9630 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
9633 this.wrap.addClass('x-trigger-wrap-focus');
9634 this.mimicing = true;
9635 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
9636 if(this.monitorTab){
9637 this.el.on("keydown", this.checkTab, this);
9644 checkTab : function(e){
9645 if(e.getKey() == e.TAB){
9651 onBlur : function(){
9656 mimicBlur : function(e, t){
9658 if(!this.wrap.contains(t) && this.validateBlur()){
9665 triggerBlur : function(){
9666 this.mimicing = false;
9667 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
9668 if(this.monitorTab){
9669 this.el.un("keydown", this.checkTab, this);
9671 //this.wrap.removeClass('x-trigger-wrap-focus');
9672 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
9676 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
9677 validateBlur : function(e, t){
9682 onDisable : function(){
9683 this.inputEl().dom.disabled = true;
9684 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
9686 // this.wrap.addClass('x-item-disabled');
9691 onEnable : function(){
9692 this.inputEl().dom.disabled = false;
9693 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
9695 // this.el.removeClass('x-item-disabled');
9700 onShow : function(){
9701 var ae = this.getActionEl();
9704 ae.dom.style.display = '';
9705 ae.dom.style.visibility = 'visible';
9711 onHide : function(){
9712 var ae = this.getActionEl();
9713 ae.dom.style.display = 'none';
9717 * The function that should handle the trigger's click event. This method does nothing by default until overridden
9718 * by an implementing function.
9720 * @param {EventObject} e
9722 onTriggerClick : Roo.emptyFn
9726 * Ext JS Library 1.1.1
9727 * Copyright(c) 2006-2007, Ext JS, LLC.
9729 * Originally Released Under LGPL - original licence link has changed is not relivant.
9732 * <script type="text/javascript">
9737 * @class Roo.data.SortTypes
9739 * Defines the default sorting (casting?) comparison functions used when sorting data.
9741 Roo.data.SortTypes = {
9743 * Default sort that does nothing
9744 * @param {Mixed} s The value being converted
9745 * @return {Mixed} The comparison value
9752 * The regular expression used to strip tags
9756 stripTagsRE : /<\/?[^>]+>/gi,
9759 * Strips all HTML tags to sort on text only
9760 * @param {Mixed} s The value being converted
9761 * @return {String} The comparison value
9763 asText : function(s){
9764 return String(s).replace(this.stripTagsRE, "");
9768 * Strips all HTML tags to sort on text only - Case insensitive
9769 * @param {Mixed} s The value being converted
9770 * @return {String} The comparison value
9772 asUCText : function(s){
9773 return String(s).toUpperCase().replace(this.stripTagsRE, "");
9777 * Case insensitive string
9778 * @param {Mixed} s The value being converted
9779 * @return {String} The comparison value
9781 asUCString : function(s) {
9782 return String(s).toUpperCase();
9787 * @param {Mixed} s The value being converted
9788 * @return {Number} The comparison value
9790 asDate : function(s) {
9794 if(s instanceof Date){
9797 return Date.parse(String(s));
9802 * @param {Mixed} s The value being converted
9803 * @return {Float} The comparison value
9805 asFloat : function(s) {
9806 var val = parseFloat(String(s).replace(/,/g, ""));
9815 * @param {Mixed} s The value being converted
9816 * @return {Number} The comparison value
9818 asInt : function(s) {
9819 var val = parseInt(String(s).replace(/,/g, ""));
9827 * Ext JS Library 1.1.1
9828 * Copyright(c) 2006-2007, Ext JS, LLC.
9830 * Originally Released Under LGPL - original licence link has changed is not relivant.
9833 * <script type="text/javascript">
9837 * @class Roo.data.Record
9838 * Instances of this class encapsulate both record <em>definition</em> information, and record
9839 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
9840 * to access Records cached in an {@link Roo.data.Store} object.<br>
9842 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
9843 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
9846 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
9848 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
9849 * {@link #create}. The parameters are the same.
9850 * @param {Array} data An associative Array of data values keyed by the field name.
9851 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
9852 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
9853 * not specified an integer id is generated.
9855 Roo.data.Record = function(data, id){
9856 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
9861 * Generate a constructor for a specific record layout.
9862 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
9863 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
9864 * Each field definition object may contain the following properties: <ul>
9865 * <li><b>name</b> : String<p style="margin-left:1em">The name by which the field is referenced within the Record. This is referenced by,
9866 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
9867 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
9868 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
9869 * is being used, then this is a string containing the javascript expression to reference the data relative to
9870 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
9871 * to the data item relative to the record element. If the mapping expression is the same as the field name,
9872 * this may be omitted.</p></li>
9873 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
9874 * <ul><li>auto (Default, implies no conversion)</li>
9879 * <li>date</li></ul></p></li>
9880 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
9881 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
9882 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
9883 * by the Reader into an object that will be stored in the Record. It is passed the
9884 * following parameters:<ul>
9885 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
9887 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
9889 * <br>usage:<br><pre><code>
9890 var TopicRecord = Roo.data.Record.create(
9891 {name: 'title', mapping: 'topic_title'},
9892 {name: 'author', mapping: 'username'},
9893 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
9894 {name: 'lastPost', mapping: 'post_time', type: 'date'},
9895 {name: 'lastPoster', mapping: 'user2'},
9896 {name: 'excerpt', mapping: 'post_text'}
9899 var myNewRecord = new TopicRecord({
9900 title: 'Do my job please',
9903 lastPost: new Date(),
9904 lastPoster: 'Animal',
9905 excerpt: 'No way dude!'
9907 myStore.add(myNewRecord);
9912 Roo.data.Record.create = function(o){
9914 f.superclass.constructor.apply(this, arguments);
9916 Roo.extend(f, Roo.data.Record);
9917 var p = f.prototype;
9918 p.fields = new Roo.util.MixedCollection(false, function(field){
9921 for(var i = 0, len = o.length; i < len; i++){
9922 p.fields.add(new Roo.data.Field(o[i]));
9924 f.getField = function(name){
9925 return p.fields.get(name);
9930 Roo.data.Record.AUTO_ID = 1000;
9931 Roo.data.Record.EDIT = 'edit';
9932 Roo.data.Record.REJECT = 'reject';
9933 Roo.data.Record.COMMIT = 'commit';
9935 Roo.data.Record.prototype = {
9937 * Readonly flag - true if this record has been modified.
9946 join : function(store){
9951 * Set the named field to the specified value.
9952 * @param {String} name The name of the field to set.
9953 * @param {Object} value The value to set the field to.
9955 set : function(name, value){
9956 if(this.data[name] == value){
9963 if(typeof this.modified[name] == 'undefined'){
9964 this.modified[name] = this.data[name];
9966 this.data[name] = value;
9967 if(!this.editing && this.store){
9968 this.store.afterEdit(this);
9973 * Get the value of the named field.
9974 * @param {String} name The name of the field to get the value of.
9975 * @return {Object} The value of the field.
9977 get : function(name){
9978 return this.data[name];
9982 beginEdit : function(){
9983 this.editing = true;
9988 cancelEdit : function(){
9989 this.editing = false;
9990 delete this.modified;
9994 endEdit : function(){
9995 this.editing = false;
9996 if(this.dirty && this.store){
9997 this.store.afterEdit(this);
10002 * Usually called by the {@link Roo.data.Store} which owns the Record.
10003 * Rejects all changes made to the Record since either creation, or the last commit operation.
10004 * Modified fields are reverted to their original values.
10006 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10007 * of reject operations.
10009 reject : function(){
10010 var m = this.modified;
10012 if(typeof m[n] != "function"){
10013 this.data[n] = m[n];
10016 this.dirty = false;
10017 delete this.modified;
10018 this.editing = false;
10020 this.store.afterReject(this);
10025 * Usually called by the {@link Roo.data.Store} which owns the Record.
10026 * Commits all changes made to the Record since either creation, or the last commit operation.
10028 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10029 * of commit operations.
10031 commit : function(){
10032 this.dirty = false;
10033 delete this.modified;
10034 this.editing = false;
10036 this.store.afterCommit(this);
10041 hasError : function(){
10042 return this.error != null;
10046 clearError : function(){
10051 * Creates a copy of this record.
10052 * @param {String} id (optional) A new record id if you don't want to use this record's id
10055 copy : function(newId) {
10056 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
10060 * Ext JS Library 1.1.1
10061 * Copyright(c) 2006-2007, Ext JS, LLC.
10063 * Originally Released Under LGPL - original licence link has changed is not relivant.
10066 * <script type="text/javascript">
10072 * @class Roo.data.Store
10073 * @extends Roo.util.Observable
10074 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
10075 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
10077 * A Store object uses an implementation of {@link Roo.data.DataProxy} to access a data object unless you call loadData() directly and pass in your data. The Store object
10078 * has no knowledge of the format of the data returned by the Proxy.<br>
10080 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
10081 * instances from the data object. These records are cached and made available through accessor functions.
10083 * Creates a new Store.
10084 * @param {Object} config A config object containing the objects needed for the Store to access data,
10085 * and read the data into Records.
10087 Roo.data.Store = function(config){
10088 this.data = new Roo.util.MixedCollection(false);
10089 this.data.getKey = function(o){
10092 this.baseParams = {};
10094 this.paramNames = {
10099 "multisort" : "_multisort"
10102 if(config && config.data){
10103 this.inlineData = config.data;
10104 delete config.data;
10107 Roo.apply(this, config);
10109 if(this.reader){ // reader passed
10110 this.reader = Roo.factory(this.reader, Roo.data);
10111 this.reader.xmodule = this.xmodule || false;
10112 if(!this.recordType){
10113 this.recordType = this.reader.recordType;
10115 if(this.reader.onMetaChange){
10116 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
10120 if(this.recordType){
10121 this.fields = this.recordType.prototype.fields;
10123 this.modified = [];
10127 * @event datachanged
10128 * Fires when the data cache has changed, and a widget which is using this Store
10129 * as a Record cache should refresh its view.
10130 * @param {Store} this
10132 datachanged : true,
10134 * @event metachange
10135 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
10136 * @param {Store} this
10137 * @param {Object} meta The JSON metadata
10142 * Fires when Records have been added to the Store
10143 * @param {Store} this
10144 * @param {Roo.data.Record[]} records The array of Records added
10145 * @param {Number} index The index at which the record(s) were added
10150 * Fires when a Record has been removed from the Store
10151 * @param {Store} this
10152 * @param {Roo.data.Record} record The Record that was removed
10153 * @param {Number} index The index at which the record was removed
10158 * Fires when a Record has been updated
10159 * @param {Store} this
10160 * @param {Roo.data.Record} record The Record that was updated
10161 * @param {String} operation The update operation being performed. Value may be one of:
10163 Roo.data.Record.EDIT
10164 Roo.data.Record.REJECT
10165 Roo.data.Record.COMMIT
10171 * Fires when the data cache has been cleared.
10172 * @param {Store} this
10176 * @event beforeload
10177 * Fires before a request is made for a new data object. If the beforeload handler returns false
10178 * the load action will be canceled.
10179 * @param {Store} this
10180 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10184 * @event beforeloadadd
10185 * Fires after a new set of Records has been loaded.
10186 * @param {Store} this
10187 * @param {Roo.data.Record[]} records The Records that were loaded
10188 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10190 beforeloadadd : true,
10193 * Fires after a new set of Records has been loaded, before they are added to the store.
10194 * @param {Store} this
10195 * @param {Roo.data.Record[]} records The Records that were loaded
10196 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10197 * @params {Object} return from reader
10201 * @event loadexception
10202 * Fires if an exception occurs in the Proxy during loading.
10203 * Called with the signature of the Proxy's "loadexception" event.
10204 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
10207 * @param {Object} return from JsonData.reader() - success, totalRecords, records
10208 * @param {Object} load options
10209 * @param {Object} jsonData from your request (normally this contains the Exception)
10211 loadexception : true
10215 this.proxy = Roo.factory(this.proxy, Roo.data);
10216 this.proxy.xmodule = this.xmodule || false;
10217 this.relayEvents(this.proxy, ["loadexception"]);
10219 this.sortToggle = {};
10220 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
10222 Roo.data.Store.superclass.constructor.call(this);
10224 if(this.inlineData){
10225 this.loadData(this.inlineData);
10226 delete this.inlineData;
10230 Roo.extend(Roo.data.Store, Roo.util.Observable, {
10232 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
10233 * without a remote query - used by combo/forms at present.
10237 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
10240 * @cfg {Array} data Inline data to be loaded when the store is initialized.
10243 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
10244 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
10247 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
10248 * on any HTTP request
10251 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
10254 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
10258 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
10259 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
10261 remoteSort : false,
10264 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
10265 * loaded or when a record is removed. (defaults to false).
10267 pruneModifiedRecords : false,
10270 lastOptions : null,
10273 * Add Records to the Store and fires the add event.
10274 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
10276 add : function(records){
10277 records = [].concat(records);
10278 for(var i = 0, len = records.length; i < len; i++){
10279 records[i].join(this);
10281 var index = this.data.length;
10282 this.data.addAll(records);
10283 this.fireEvent("add", this, records, index);
10287 * Remove a Record from the Store and fires the remove event.
10288 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
10290 remove : function(record){
10291 var index = this.data.indexOf(record);
10292 this.data.removeAt(index);
10293 if(this.pruneModifiedRecords){
10294 this.modified.remove(record);
10296 this.fireEvent("remove", this, record, index);
10300 * Remove all Records from the Store and fires the clear event.
10302 removeAll : function(){
10304 if(this.pruneModifiedRecords){
10305 this.modified = [];
10307 this.fireEvent("clear", this);
10311 * Inserts Records to the Store at the given index and fires the add event.
10312 * @param {Number} index The start index at which to insert the passed Records.
10313 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
10315 insert : function(index, records){
10316 records = [].concat(records);
10317 for(var i = 0, len = records.length; i < len; i++){
10318 this.data.insert(index, records[i]);
10319 records[i].join(this);
10321 this.fireEvent("add", this, records, index);
10325 * Get the index within the cache of the passed Record.
10326 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
10327 * @return {Number} The index of the passed Record. Returns -1 if not found.
10329 indexOf : function(record){
10330 return this.data.indexOf(record);
10334 * Get the index within the cache of the Record with the passed id.
10335 * @param {String} id The id of the Record to find.
10336 * @return {Number} The index of the Record. Returns -1 if not found.
10338 indexOfId : function(id){
10339 return this.data.indexOfKey(id);
10343 * Get the Record with the specified id.
10344 * @param {String} id The id of the Record to find.
10345 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
10347 getById : function(id){
10348 return this.data.key(id);
10352 * Get the Record at the specified index.
10353 * @param {Number} index The index of the Record to find.
10354 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
10356 getAt : function(index){
10357 return this.data.itemAt(index);
10361 * Returns a range of Records between specified indices.
10362 * @param {Number} startIndex (optional) The starting index (defaults to 0)
10363 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
10364 * @return {Roo.data.Record[]} An array of Records
10366 getRange : function(start, end){
10367 return this.data.getRange(start, end);
10371 storeOptions : function(o){
10372 o = Roo.apply({}, o);
10375 this.lastOptions = o;
10379 * Loads the Record cache from the configured Proxy using the configured Reader.
10381 * If using remote paging, then the first load call must specify the <em>start</em>
10382 * and <em>limit</em> properties in the options.params property to establish the initial
10383 * position within the dataset, and the number of Records to cache on each read from the Proxy.
10385 * <strong>It is important to note that for remote data sources, loading is asynchronous,
10386 * and this call will return before the new data has been loaded. Perform any post-processing
10387 * in a callback function, or in a "load" event handler.</strong>
10389 * @param {Object} options An object containing properties which control loading options:<ul>
10390 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
10391 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
10392 * passed the following arguments:<ul>
10393 * <li>r : Roo.data.Record[]</li>
10394 * <li>options: Options object from the load call</li>
10395 * <li>success: Boolean success indicator</li></ul></li>
10396 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
10397 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
10400 load : function(options){
10401 options = options || {};
10402 if(this.fireEvent("beforeload", this, options) !== false){
10403 this.storeOptions(options);
10404 var p = Roo.apply(options.params || {}, this.baseParams);
10405 // if meta was not loaded from remote source.. try requesting it.
10406 if (!this.reader.metaFromRemote) {
10407 p._requestMeta = 1;
10409 if(this.sortInfo && this.remoteSort){
10410 var pn = this.paramNames;
10411 p[pn["sort"]] = this.sortInfo.field;
10412 p[pn["dir"]] = this.sortInfo.direction;
10414 if (this.multiSort) {
10415 var pn = this.paramNames;
10416 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
10419 this.proxy.load(p, this.reader, this.loadRecords, this, options);
10424 * Reloads the Record cache from the configured Proxy using the configured Reader and
10425 * the options from the last load operation performed.
10426 * @param {Object} options (optional) An object containing properties which may override the options
10427 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
10428 * the most recently used options are reused).
10430 reload : function(options){
10431 this.load(Roo.applyIf(options||{}, this.lastOptions));
10435 // Called as a callback by the Reader during a load operation.
10436 loadRecords : function(o, options, success){
10437 if(!o || success === false){
10438 if(success !== false){
10439 this.fireEvent("load", this, [], options, o);
10441 if(options.callback){
10442 options.callback.call(options.scope || this, [], options, false);
10446 // if data returned failure - throw an exception.
10447 if (o.success === false) {
10448 // show a message if no listener is registered.
10449 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
10450 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
10452 // loadmask wil be hooked into this..
10453 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
10456 var r = o.records, t = o.totalRecords || r.length;
10458 this.fireEvent("beforeloadadd", this, r, options, o);
10460 if(!options || options.add !== true){
10461 if(this.pruneModifiedRecords){
10462 this.modified = [];
10464 for(var i = 0, len = r.length; i < len; i++){
10468 this.data = this.snapshot;
10469 delete this.snapshot;
10472 this.data.addAll(r);
10473 this.totalLength = t;
10475 this.fireEvent("datachanged", this);
10477 this.totalLength = Math.max(t, this.data.length+r.length);
10480 this.fireEvent("load", this, r, options, o);
10481 if(options.callback){
10482 options.callback.call(options.scope || this, r, options, true);
10488 * Loads data from a passed data block. A Reader which understands the format of the data
10489 * must have been configured in the constructor.
10490 * @param {Object} data The data block from which to read the Records. The format of the data expected
10491 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
10492 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
10494 loadData : function(o, append){
10495 var r = this.reader.readRecords(o);
10496 this.loadRecords(r, {add: append}, true);
10500 * Gets the number of cached records.
10502 * <em>If using paging, this may not be the total size of the dataset. If the data object
10503 * used by the Reader contains the dataset size, then the getTotalCount() function returns
10504 * the data set size</em>
10506 getCount : function(){
10507 return this.data.length || 0;
10511 * Gets the total number of records in the dataset as returned by the server.
10513 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
10514 * the dataset size</em>
10516 getTotalCount : function(){
10517 return this.totalLength || 0;
10521 * Returns the sort state of the Store as an object with two properties:
10523 field {String} The name of the field by which the Records are sorted
10524 direction {String} The sort order, "ASC" or "DESC"
10527 getSortState : function(){
10528 return this.sortInfo;
10532 applySort : function(){
10533 if(this.sortInfo && !this.remoteSort){
10534 var s = this.sortInfo, f = s.field;
10535 var st = this.fields.get(f).sortType;
10536 var fn = function(r1, r2){
10537 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
10538 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
10540 this.data.sort(s.direction, fn);
10541 if(this.snapshot && this.snapshot != this.data){
10542 this.snapshot.sort(s.direction, fn);
10548 * Sets the default sort column and order to be used by the next load operation.
10549 * @param {String} fieldName The name of the field to sort by.
10550 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
10552 setDefaultSort : function(field, dir){
10553 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
10557 * Sort the Records.
10558 * If remote sorting is used, the sort is performed on the server, and the cache is
10559 * reloaded. If local sorting is used, the cache is sorted internally.
10560 * @param {String} fieldName The name of the field to sort by.
10561 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
10563 sort : function(fieldName, dir){
10564 var f = this.fields.get(fieldName);
10566 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
10568 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
10569 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
10574 this.sortToggle[f.name] = dir;
10575 this.sortInfo = {field: f.name, direction: dir};
10576 if(!this.remoteSort){
10578 this.fireEvent("datachanged", this);
10580 this.load(this.lastOptions);
10585 * Calls the specified function for each of the Records in the cache.
10586 * @param {Function} fn The function to call. The Record is passed as the first parameter.
10587 * Returning <em>false</em> aborts and exits the iteration.
10588 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
10590 each : function(fn, scope){
10591 this.data.each(fn, scope);
10595 * Gets all records modified since the last commit. Modified records are persisted across load operations
10596 * (e.g., during paging).
10597 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
10599 getModifiedRecords : function(){
10600 return this.modified;
10604 createFilterFn : function(property, value, anyMatch){
10605 if(!value.exec){ // not a regex
10606 value = String(value);
10607 if(value.length == 0){
10610 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
10612 return function(r){
10613 return value.test(r.data[property]);
10618 * Sums the value of <i>property</i> for each record between start and end and returns the result.
10619 * @param {String} property A field on your records
10620 * @param {Number} start The record index to start at (defaults to 0)
10621 * @param {Number} end The last record index to include (defaults to length - 1)
10622 * @return {Number} The sum
10624 sum : function(property, start, end){
10625 var rs = this.data.items, v = 0;
10626 start = start || 0;
10627 end = (end || end === 0) ? end : rs.length-1;
10629 for(var i = start; i <= end; i++){
10630 v += (rs[i].data[property] || 0);
10636 * Filter the records by a specified property.
10637 * @param {String} field A field on your records
10638 * @param {String/RegExp} value Either a string that the field
10639 * should start with or a RegExp to test against the field
10640 * @param {Boolean} anyMatch True to match any part not just the beginning
10642 filter : function(property, value, anyMatch){
10643 var fn = this.createFilterFn(property, value, anyMatch);
10644 return fn ? this.filterBy(fn) : this.clearFilter();
10648 * Filter by a function. The specified function will be called with each
10649 * record in this data source. If the function returns true the record is included,
10650 * otherwise it is filtered.
10651 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
10652 * @param {Object} scope (optional) The scope of the function (defaults to this)
10654 filterBy : function(fn, scope){
10655 this.snapshot = this.snapshot || this.data;
10656 this.data = this.queryBy(fn, scope||this);
10657 this.fireEvent("datachanged", this);
10661 * Query the records by a specified property.
10662 * @param {String} field A field on your records
10663 * @param {String/RegExp} value Either a string that the field
10664 * should start with or a RegExp to test against the field
10665 * @param {Boolean} anyMatch True to match any part not just the beginning
10666 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
10668 query : function(property, value, anyMatch){
10669 var fn = this.createFilterFn(property, value, anyMatch);
10670 return fn ? this.queryBy(fn) : this.data.clone();
10674 * Query by a function. The specified function will be called with each
10675 * record in this data source. If the function returns true the record is included
10677 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
10678 * @param {Object} scope (optional) The scope of the function (defaults to this)
10679 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
10681 queryBy : function(fn, scope){
10682 var data = this.snapshot || this.data;
10683 return data.filterBy(fn, scope||this);
10687 * Collects unique values for a particular dataIndex from this store.
10688 * @param {String} dataIndex The property to collect
10689 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
10690 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
10691 * @return {Array} An array of the unique values
10693 collect : function(dataIndex, allowNull, bypassFilter){
10694 var d = (bypassFilter === true && this.snapshot) ?
10695 this.snapshot.items : this.data.items;
10696 var v, sv, r = [], l = {};
10697 for(var i = 0, len = d.length; i < len; i++){
10698 v = d[i].data[dataIndex];
10700 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
10709 * Revert to a view of the Record cache with no filtering applied.
10710 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
10712 clearFilter : function(suppressEvent){
10713 if(this.snapshot && this.snapshot != this.data){
10714 this.data = this.snapshot;
10715 delete this.snapshot;
10716 if(suppressEvent !== true){
10717 this.fireEvent("datachanged", this);
10723 afterEdit : function(record){
10724 if(this.modified.indexOf(record) == -1){
10725 this.modified.push(record);
10727 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
10731 afterReject : function(record){
10732 this.modified.remove(record);
10733 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
10737 afterCommit : function(record){
10738 this.modified.remove(record);
10739 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
10743 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
10744 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
10746 commitChanges : function(){
10747 var m = this.modified.slice(0);
10748 this.modified = [];
10749 for(var i = 0, len = m.length; i < len; i++){
10755 * Cancel outstanding changes on all changed records.
10757 rejectChanges : function(){
10758 var m = this.modified.slice(0);
10759 this.modified = [];
10760 for(var i = 0, len = m.length; i < len; i++){
10765 onMetaChange : function(meta, rtype, o){
10766 this.recordType = rtype;
10767 this.fields = rtype.prototype.fields;
10768 delete this.snapshot;
10769 this.sortInfo = meta.sortInfo || this.sortInfo;
10770 this.modified = [];
10771 this.fireEvent('metachange', this, this.reader.meta);
10774 moveIndex : function(data, type)
10776 var index = this.indexOf(data);
10778 var newIndex = index + type;
10782 this.insert(newIndex, data);
10787 * Ext JS Library 1.1.1
10788 * Copyright(c) 2006-2007, Ext JS, LLC.
10790 * Originally Released Under LGPL - original licence link has changed is not relivant.
10793 * <script type="text/javascript">
10797 * @class Roo.data.SimpleStore
10798 * @extends Roo.data.Store
10799 * Small helper class to make creating Stores from Array data easier.
10800 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
10801 * @cfg {Array} fields An array of field definition objects, or field name strings.
10802 * @cfg {Array} data The multi-dimensional array of data
10804 * @param {Object} config
10806 Roo.data.SimpleStore = function(config){
10807 Roo.data.SimpleStore.superclass.constructor.call(this, {
10809 reader: new Roo.data.ArrayReader({
10812 Roo.data.Record.create(config.fields)
10814 proxy : new Roo.data.MemoryProxy(config.data)
10818 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
10820 * Ext JS Library 1.1.1
10821 * Copyright(c) 2006-2007, Ext JS, LLC.
10823 * Originally Released Under LGPL - original licence link has changed is not relivant.
10826 * <script type="text/javascript">
10831 * @extends Roo.data.Store
10832 * @class Roo.data.JsonStore
10833 * Small helper class to make creating Stores for JSON data easier. <br/>
10835 var store = new Roo.data.JsonStore({
10836 url: 'get-images.php',
10838 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
10841 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
10842 * JsonReader and HttpProxy (unless inline data is provided).</b>
10843 * @cfg {Array} fields An array of field definition objects, or field name strings.
10845 * @param {Object} config
10847 Roo.data.JsonStore = function(c){
10848 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
10849 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
10850 reader: new Roo.data.JsonReader(c, c.fields)
10853 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
10855 * Ext JS Library 1.1.1
10856 * Copyright(c) 2006-2007, Ext JS, LLC.
10858 * Originally Released Under LGPL - original licence link has changed is not relivant.
10861 * <script type="text/javascript">
10865 Roo.data.Field = function(config){
10866 if(typeof config == "string"){
10867 config = {name: config};
10869 Roo.apply(this, config);
10872 this.type = "auto";
10875 var st = Roo.data.SortTypes;
10876 // named sortTypes are supported, here we look them up
10877 if(typeof this.sortType == "string"){
10878 this.sortType = st[this.sortType];
10881 // set default sortType for strings and dates
10882 if(!this.sortType){
10885 this.sortType = st.asUCString;
10888 this.sortType = st.asDate;
10891 this.sortType = st.none;
10896 var stripRe = /[\$,%]/g;
10898 // prebuilt conversion function for this field, instead of
10899 // switching every time we're reading a value
10901 var cv, dateFormat = this.dateFormat;
10906 cv = function(v){ return v; };
10909 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
10913 return v !== undefined && v !== null && v !== '' ?
10914 parseInt(String(v).replace(stripRe, ""), 10) : '';
10919 return v !== undefined && v !== null && v !== '' ?
10920 parseFloat(String(v).replace(stripRe, ""), 10) : '';
10925 cv = function(v){ return v === true || v === "true" || v == 1; };
10932 if(v instanceof Date){
10936 if(dateFormat == "timestamp"){
10937 return new Date(v*1000);
10939 return Date.parseDate(v, dateFormat);
10941 var parsed = Date.parse(v);
10942 return parsed ? new Date(parsed) : null;
10951 Roo.data.Field.prototype = {
10959 * Ext JS Library 1.1.1
10960 * Copyright(c) 2006-2007, Ext JS, LLC.
10962 * Originally Released Under LGPL - original licence link has changed is not relivant.
10965 * <script type="text/javascript">
10968 // Base class for reading structured data from a data source. This class is intended to be
10969 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
10972 * @class Roo.data.DataReader
10973 * Base class for reading structured data from a data source. This class is intended to be
10974 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
10977 Roo.data.DataReader = function(meta, recordType){
10981 this.recordType = recordType instanceof Array ?
10982 Roo.data.Record.create(recordType) : recordType;
10985 Roo.data.DataReader.prototype = {
10987 * Create an empty record
10988 * @param {Object} data (optional) - overlay some values
10989 * @return {Roo.data.Record} record created.
10991 newRow : function(d) {
10993 this.recordType.prototype.fields.each(function(c) {
10995 case 'int' : da[c.name] = 0; break;
10996 case 'date' : da[c.name] = new Date(); break;
10997 case 'float' : da[c.name] = 0.0; break;
10998 case 'boolean' : da[c.name] = false; break;
10999 default : da[c.name] = ""; break;
11003 return new this.recordType(Roo.apply(da, d));
11008 * Ext JS Library 1.1.1
11009 * Copyright(c) 2006-2007, Ext JS, LLC.
11011 * Originally Released Under LGPL - original licence link has changed is not relivant.
11014 * <script type="text/javascript">
11018 * @class Roo.data.DataProxy
11019 * @extends Roo.data.Observable
11020 * This class is an abstract base class for implementations which provide retrieval of
11021 * unformatted data objects.<br>
11023 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
11024 * (of the appropriate type which knows how to parse the data object) to provide a block of
11025 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
11027 * Custom implementations must implement the load method as described in
11028 * {@link Roo.data.HttpProxy#load}.
11030 Roo.data.DataProxy = function(){
11033 * @event beforeload
11034 * Fires before a network request is made to retrieve a data object.
11035 * @param {Object} This DataProxy object.
11036 * @param {Object} params The params parameter to the load function.
11041 * Fires before the load method's callback is called.
11042 * @param {Object} This DataProxy object.
11043 * @param {Object} o The data object.
11044 * @param {Object} arg The callback argument object passed to the load function.
11048 * @event loadexception
11049 * Fires if an Exception occurs during data retrieval.
11050 * @param {Object} This DataProxy object.
11051 * @param {Object} o The data object.
11052 * @param {Object} arg The callback argument object passed to the load function.
11053 * @param {Object} e The Exception.
11055 loadexception : true
11057 Roo.data.DataProxy.superclass.constructor.call(this);
11060 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
11063 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
11067 * Ext JS Library 1.1.1
11068 * Copyright(c) 2006-2007, Ext JS, LLC.
11070 * Originally Released Under LGPL - original licence link has changed is not relivant.
11073 * <script type="text/javascript">
11076 * @class Roo.data.MemoryProxy
11077 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
11078 * to the Reader when its load method is called.
11080 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
11082 Roo.data.MemoryProxy = function(data){
11086 Roo.data.MemoryProxy.superclass.constructor.call(this);
11090 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
11093 * Load data from the requested source (in this case an in-memory
11094 * data object passed to the constructor), read the data object into
11095 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
11096 * process that block using the passed callback.
11097 * @param {Object} params This parameter is not used by the MemoryProxy class.
11098 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11099 * object into a block of Roo.data.Records.
11100 * @param {Function} callback The function into which to pass the block of Roo.data.records.
11101 * The function must be passed <ul>
11102 * <li>The Record block object</li>
11103 * <li>The "arg" argument from the load function</li>
11104 * <li>A boolean success indicator</li>
11106 * @param {Object} scope The scope in which to call the callback
11107 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11109 load : function(params, reader, callback, scope, arg){
11110 params = params || {};
11113 result = reader.readRecords(this.data);
11115 this.fireEvent("loadexception", this, arg, null, e);
11116 callback.call(scope, null, arg, false);
11119 callback.call(scope, result, arg, true);
11123 update : function(params, records){
11128 * Ext JS Library 1.1.1
11129 * Copyright(c) 2006-2007, Ext JS, LLC.
11131 * Originally Released Under LGPL - original licence link has changed is not relivant.
11134 * <script type="text/javascript">
11137 * @class Roo.data.HttpProxy
11138 * @extends Roo.data.DataProxy
11139 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
11140 * configured to reference a certain URL.<br><br>
11142 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
11143 * from which the running page was served.<br><br>
11145 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
11147 * Be aware that to enable the browser to parse an XML document, the server must set
11148 * the Content-Type header in the HTTP response to "text/xml".
11150 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
11151 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
11152 * will be used to make the request.
11154 Roo.data.HttpProxy = function(conn){
11155 Roo.data.HttpProxy.superclass.constructor.call(this);
11156 // is conn a conn config or a real conn?
11158 this.useAjax = !conn || !conn.events;
11162 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
11163 // thse are take from connection...
11166 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
11169 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
11170 * extra parameters to each request made by this object. (defaults to undefined)
11173 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
11174 * to each request made by this object. (defaults to undefined)
11177 * @cfg {String} method (Optional) The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
11180 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11183 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
11189 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11193 * Return the {@link Roo.data.Connection} object being used by this Proxy.
11194 * @return {Connection} The Connection object. This object may be used to subscribe to events on
11195 * a finer-grained basis than the DataProxy events.
11197 getConnection : function(){
11198 return this.useAjax ? Roo.Ajax : this.conn;
11202 * Load data from the configured {@link Roo.data.Connection}, read the data object into
11203 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
11204 * process that block using the passed callback.
11205 * @param {Object} params An object containing properties which are to be used as HTTP parameters
11206 * for the request to the remote server.
11207 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11208 * object into a block of Roo.data.Records.
11209 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
11210 * The function must be passed <ul>
11211 * <li>The Record block object</li>
11212 * <li>The "arg" argument from the load function</li>
11213 * <li>A boolean success indicator</li>
11215 * @param {Object} scope The scope in which to call the callback
11216 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11218 load : function(params, reader, callback, scope, arg){
11219 if(this.fireEvent("beforeload", this, params) !== false){
11221 params : params || {},
11223 callback : callback,
11228 callback : this.loadResponse,
11232 Roo.applyIf(o, this.conn);
11233 if(this.activeRequest){
11234 Roo.Ajax.abort(this.activeRequest);
11236 this.activeRequest = Roo.Ajax.request(o);
11238 this.conn.request(o);
11241 callback.call(scope||this, null, arg, false);
11246 loadResponse : function(o, success, response){
11247 delete this.activeRequest;
11249 this.fireEvent("loadexception", this, o, response);
11250 o.request.callback.call(o.request.scope, null, o.request.arg, false);
11255 result = o.reader.read(response);
11257 this.fireEvent("loadexception", this, o, response, e);
11258 o.request.callback.call(o.request.scope, null, o.request.arg, false);
11262 this.fireEvent("load", this, o, o.request.arg);
11263 o.request.callback.call(o.request.scope, result, o.request.arg, true);
11267 update : function(dataSet){
11272 updateResponse : function(dataSet){
11277 * Ext JS Library 1.1.1
11278 * Copyright(c) 2006-2007, Ext JS, LLC.
11280 * Originally Released Under LGPL - original licence link has changed is not relivant.
11283 * <script type="text/javascript">
11287 * @class Roo.data.ScriptTagProxy
11288 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
11289 * other than the originating domain of the running page.<br><br>
11291 * <em>Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain
11292 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
11294 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
11295 * source code that is used as the source inside a <script> tag.<br><br>
11297 * In order for the browser to process the returned data, the server must wrap the data object
11298 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
11299 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
11300 * depending on whether the callback name was passed:
11303 boolean scriptTag = false;
11304 String cb = request.getParameter("callback");
11307 response.setContentType("text/javascript");
11309 response.setContentType("application/x-json");
11311 Writer out = response.getWriter();
11313 out.write(cb + "(");
11315 out.print(dataBlock.toJsonString());
11322 * @param {Object} config A configuration object.
11324 Roo.data.ScriptTagProxy = function(config){
11325 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
11326 Roo.apply(this, config);
11327 this.head = document.getElementsByTagName("head")[0];
11330 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
11332 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
11334 * @cfg {String} url The URL from which to request the data object.
11337 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
11341 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
11342 * the server the name of the callback function set up by the load call to process the returned data object.
11343 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
11344 * javascript output which calls this named function passing the data object as its only parameter.
11346 callbackParam : "callback",
11348 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
11349 * name to the request.
11354 * Load data from the configured URL, read the data object into
11355 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
11356 * process that block using the passed callback.
11357 * @param {Object} params An object containing properties which are to be used as HTTP parameters
11358 * for the request to the remote server.
11359 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11360 * object into a block of Roo.data.Records.
11361 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
11362 * The function must be passed <ul>
11363 * <li>The Record block object</li>
11364 * <li>The "arg" argument from the load function</li>
11365 * <li>A boolean success indicator</li>
11367 * @param {Object} scope The scope in which to call the callback
11368 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11370 load : function(params, reader, callback, scope, arg){
11371 if(this.fireEvent("beforeload", this, params) !== false){
11373 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
11375 var url = this.url;
11376 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
11378 url += "&_dc=" + (new Date().getTime());
11380 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
11383 cb : "stcCallback"+transId,
11384 scriptId : "stcScript"+transId,
11388 callback : callback,
11394 window[trans.cb] = function(o){
11395 conn.handleResponse(o, trans);
11398 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
11400 if(this.autoAbort !== false){
11404 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
11406 var script = document.createElement("script");
11407 script.setAttribute("src", url);
11408 script.setAttribute("type", "text/javascript");
11409 script.setAttribute("id", trans.scriptId);
11410 this.head.appendChild(script);
11412 this.trans = trans;
11414 callback.call(scope||this, null, arg, false);
11419 isLoading : function(){
11420 return this.trans ? true : false;
11424 * Abort the current server request.
11426 abort : function(){
11427 if(this.isLoading()){
11428 this.destroyTrans(this.trans);
11433 destroyTrans : function(trans, isLoaded){
11434 this.head.removeChild(document.getElementById(trans.scriptId));
11435 clearTimeout(trans.timeoutId);
11437 window[trans.cb] = undefined;
11439 delete window[trans.cb];
11442 // if hasn't been loaded, wait for load to remove it to prevent script error
11443 window[trans.cb] = function(){
11444 window[trans.cb] = undefined;
11446 delete window[trans.cb];
11453 handleResponse : function(o, trans){
11454 this.trans = false;
11455 this.destroyTrans(trans, true);
11458 result = trans.reader.readRecords(o);
11460 this.fireEvent("loadexception", this, o, trans.arg, e);
11461 trans.callback.call(trans.scope||window, null, trans.arg, false);
11464 this.fireEvent("load", this, o, trans.arg);
11465 trans.callback.call(trans.scope||window, result, trans.arg, true);
11469 handleFailure : function(trans){
11470 this.trans = false;
11471 this.destroyTrans(trans, false);
11472 this.fireEvent("loadexception", this, null, trans.arg);
11473 trans.callback.call(trans.scope||window, null, trans.arg, false);
11477 * Ext JS Library 1.1.1
11478 * Copyright(c) 2006-2007, Ext JS, LLC.
11480 * Originally Released Under LGPL - original licence link has changed is not relivant.
11483 * <script type="text/javascript">
11487 * @class Roo.data.JsonReader
11488 * @extends Roo.data.DataReader
11489 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
11490 * based on mappings in a provided Roo.data.Record constructor.
11492 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
11493 * in the reply previously.
11498 var RecordDef = Roo.data.Record.create([
11499 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
11500 {name: 'occupation'} // This field will use "occupation" as the mapping.
11502 var myReader = new Roo.data.JsonReader({
11503 totalProperty: "results", // The property which contains the total dataset size (optional)
11504 root: "rows", // The property which contains an Array of row objects
11505 id: "id" // The property within each row object that provides an ID for the record (optional)
11509 * This would consume a JSON file like this:
11511 { 'results': 2, 'rows': [
11512 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
11513 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
11516 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
11517 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
11518 * paged from the remote server.
11519 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
11520 * @cfg {String} root name of the property which contains the Array of row objects.
11521 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
11522 * @cfg {Array} fields Array of field definition objects
11524 * Create a new JsonReader
11525 * @param {Object} meta Metadata configuration options
11526 * @param {Object} recordType Either an Array of field definition objects,
11527 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
11529 Roo.data.JsonReader = function(meta, recordType){
11532 // set some defaults:
11533 Roo.applyIf(meta, {
11534 totalProperty: 'total',
11535 successProperty : 'success',
11540 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
11542 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
11545 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
11546 * Used by Store query builder to append _requestMeta to params.
11549 metaFromRemote : false,
11551 * This method is only used by a DataProxy which has retrieved data from a remote server.
11552 * @param {Object} response The XHR object which contains the JSON data in its responseText.
11553 * @return {Object} data A data block which is used by an Roo.data.Store object as
11554 * a cache of Roo.data.Records.
11556 read : function(response){
11557 var json = response.responseText;
11559 var o = /* eval:var:o */ eval("("+json+")");
11561 throw {message: "JsonReader.read: Json object not found"};
11567 this.metaFromRemote = true;
11568 this.meta = o.metaData;
11569 this.recordType = Roo.data.Record.create(o.metaData.fields);
11570 this.onMetaChange(this.meta, this.recordType, o);
11572 return this.readRecords(o);
11575 // private function a store will implement
11576 onMetaChange : function(meta, recordType, o){
11583 simpleAccess: function(obj, subsc) {
11590 getJsonAccessor: function(){
11592 return function(expr) {
11594 return(re.test(expr))
11595 ? new Function("obj", "return obj." + expr)
11600 return Roo.emptyFn;
11605 * Create a data block containing Roo.data.Records from an XML document.
11606 * @param {Object} o An object which contains an Array of row objects in the property specified
11607 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
11608 * which contains the total size of the dataset.
11609 * @return {Object} data A data block which is used by an Roo.data.Store object as
11610 * a cache of Roo.data.Records.
11612 readRecords : function(o){
11614 * After any data loads, the raw JSON data is available for further custom processing.
11618 var s = this.meta, Record = this.recordType,
11619 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
11621 // Generate extraction functions for the totalProperty, the root, the id, and for each field
11623 if(s.totalProperty) {
11624 this.getTotal = this.getJsonAccessor(s.totalProperty);
11626 if(s.successProperty) {
11627 this.getSuccess = this.getJsonAccessor(s.successProperty);
11629 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
11631 var g = this.getJsonAccessor(s.id);
11632 this.getId = function(rec) {
11634 return (r === undefined || r === "") ? null : r;
11637 this.getId = function(){return null;};
11640 for(var jj = 0; jj < fl; jj++){
11642 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
11643 this.ef[jj] = this.getJsonAccessor(map);
11647 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
11648 if(s.totalProperty){
11649 var vt = parseInt(this.getTotal(o), 10);
11654 if(s.successProperty){
11655 var vs = this.getSuccess(o);
11656 if(vs === false || vs === 'false'){
11661 for(var i = 0; i < c; i++){
11664 var id = this.getId(n);
11665 for(var j = 0; j < fl; j++){
11667 var v = this.ef[j](n);
11669 Roo.log('missing convert for ' + f.name);
11673 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
11675 var record = new Record(values, id);
11677 records[i] = record;
11683 totalRecords : totalRecords
11688 * Ext JS Library 1.1.1
11689 * Copyright(c) 2006-2007, Ext JS, LLC.
11691 * Originally Released Under LGPL - original licence link has changed is not relivant.
11694 * <script type="text/javascript">
11698 * @class Roo.data.ArrayReader
11699 * @extends Roo.data.DataReader
11700 * Data reader class to create an Array of Roo.data.Record objects from an Array.
11701 * Each element of that Array represents a row of data fields. The
11702 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
11703 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
11707 var RecordDef = Roo.data.Record.create([
11708 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
11709 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
11711 var myReader = new Roo.data.ArrayReader({
11712 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
11716 * This would consume an Array like this:
11718 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
11720 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
11722 * Create a new JsonReader
11723 * @param {Object} meta Metadata configuration options.
11724 * @param {Object} recordType Either an Array of field definition objects
11725 * as specified to {@link Roo.data.Record#create},
11726 * or an {@link Roo.data.Record} object
11727 * created using {@link Roo.data.Record#create}.
11729 Roo.data.ArrayReader = function(meta, recordType){
11730 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
11733 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
11735 * Create a data block containing Roo.data.Records from an XML document.
11736 * @param {Object} o An Array of row objects which represents the dataset.
11737 * @return {Object} data A data block which is used by an Roo.data.Store object as
11738 * a cache of Roo.data.Records.
11740 readRecords : function(o){
11741 var sid = this.meta ? this.meta.id : null;
11742 var recordType = this.recordType, fields = recordType.prototype.fields;
11745 for(var i = 0; i < root.length; i++){
11748 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
11749 for(var j = 0, jlen = fields.length; j < jlen; j++){
11750 var f = fields.items[j];
11751 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
11752 var v = n[k] !== undefined ? n[k] : f.defaultValue;
11754 values[f.name] = v;
11756 var record = new recordType(values, id);
11758 records[records.length] = record;
11762 totalRecords : records.length
11771 * @class Roo.bootstrap.ComboBox
11772 * @extends Roo.bootstrap.TriggerField
11773 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
11774 * @cfg {Boolean} append (true|false) default false
11775 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
11776 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
11777 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
11778 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
11779 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
11780 * @cfg {Boolean} animate default true
11781 * @cfg {Boolean} emptyResultText only for touch device
11782 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
11784 * Create a new ComboBox.
11785 * @param {Object} config Configuration options
11787 Roo.bootstrap.ComboBox = function(config){
11788 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
11792 * Fires when the dropdown list is expanded
11793 * @param {Roo.bootstrap.ComboBox} combo This combo box
11798 * Fires when the dropdown list is collapsed
11799 * @param {Roo.bootstrap.ComboBox} combo This combo box
11803 * @event beforeselect
11804 * Fires before a list item is selected. Return false to cancel the selection.
11805 * @param {Roo.bootstrap.ComboBox} combo This combo box
11806 * @param {Roo.data.Record} record The data record returned from the underlying store
11807 * @param {Number} index The index of the selected item in the dropdown list
11809 'beforeselect' : true,
11812 * Fires when a list item is selected
11813 * @param {Roo.bootstrap.ComboBox} combo This combo box
11814 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
11815 * @param {Number} index The index of the selected item in the dropdown list
11819 * @event beforequery
11820 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
11821 * The event object passed has these properties:
11822 * @param {Roo.bootstrap.ComboBox} combo This combo box
11823 * @param {String} query The query
11824 * @param {Boolean} forceAll true to force "all" query
11825 * @param {Boolean} cancel true to cancel the query
11826 * @param {Object} e The query event object
11828 'beforequery': true,
11831 * Fires when the 'add' icon is pressed (add a listener to enable add button)
11832 * @param {Roo.bootstrap.ComboBox} combo This combo box
11837 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
11838 * @param {Roo.bootstrap.ComboBox} combo This combo box
11839 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
11844 * Fires when the remove value from the combobox array
11845 * @param {Roo.bootstrap.ComboBox} combo This combo box
11849 * @event afterremove
11850 * Fires when the remove value from the combobox array
11851 * @param {Roo.bootstrap.ComboBox} combo This combo box
11853 'afterremove' : true,
11855 * @event specialfilter
11856 * Fires when specialfilter
11857 * @param {Roo.bootstrap.ComboBox} combo This combo box
11859 'specialfilter' : true,
11862 * Fires when tick the element
11863 * @param {Roo.bootstrap.ComboBox} combo This combo box
11867 * @event touchviewdisplay
11868 * Fires when touch view require special display (default is using displayField)
11869 * @param {Roo.bootstrap.ComboBox} combo This combo box
11870 * @param {Object} cfg set html .
11872 'touchviewdisplay' : true
11877 this.tickItems = [];
11879 this.selectedIndex = -1;
11880 if(this.mode == 'local'){
11881 if(config.queryDelay === undefined){
11882 this.queryDelay = 10;
11884 if(config.minChars === undefined){
11890 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
11893 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
11894 * rendering into an Roo.Editor, defaults to false)
11897 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
11898 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
11901 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
11904 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
11905 * the dropdown list (defaults to undefined, with no header element)
11909 * @cfg {String/Roo.Template} tpl The template to use to render the output
11913 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
11915 listWidth: undefined,
11917 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
11918 * mode = 'remote' or 'text' if mode = 'local')
11920 displayField: undefined,
11923 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
11924 * mode = 'remote' or 'value' if mode = 'local').
11925 * Note: use of a valueField requires the user make a selection
11926 * in order for a value to be mapped.
11928 valueField: undefined,
11932 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
11933 * field's data value (defaults to the underlying DOM element's name)
11935 hiddenName: undefined,
11937 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
11941 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
11943 selectedClass: 'active',
11946 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
11950 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
11951 * anchor positions (defaults to 'tl-bl')
11953 listAlign: 'tl-bl?',
11955 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
11959 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
11960 * query specified by the allQuery config option (defaults to 'query')
11962 triggerAction: 'query',
11964 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
11965 * (defaults to 4, does not apply if editable = false)
11969 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
11970 * delay (typeAheadDelay) if it matches a known value (defaults to false)
11974 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
11975 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
11979 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
11980 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
11984 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
11985 * when editable = true (defaults to false)
11987 selectOnFocus:false,
11989 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
11991 queryParam: 'query',
11993 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
11994 * when mode = 'remote' (defaults to 'Loading...')
11996 loadingText: 'Loading...',
11998 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
12002 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
12006 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
12007 * traditional select (defaults to true)
12011 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
12015 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
12019 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
12020 * listWidth has a higher value)
12024 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
12025 * allow the user to set arbitrary text into the field (defaults to false)
12027 forceSelection:false,
12029 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
12030 * if typeAhead = true (defaults to 250)
12032 typeAheadDelay : 250,
12034 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
12035 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
12037 valueNotFoundText : undefined,
12039 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
12041 blockFocus : false,
12044 * @cfg {Boolean} disableClear Disable showing of clear button.
12046 disableClear : false,
12048 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
12050 alwaysQuery : false,
12053 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
12058 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
12060 invalidClass : "has-warning",
12063 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
12065 validClass : "has-success",
12068 * @cfg {Boolean} specialFilter (true|false) special filter default false
12070 specialFilter : false,
12073 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
12075 mobileTouchView : true,
12087 btnPosition : 'right',
12088 triggerList : true,
12089 showToggleBtn : true,
12091 emptyResultText: 'Empty',
12092 triggerText : 'Select',
12094 // element that contains real text value.. (when hidden is used..)
12096 getAutoCreate : function()
12104 if(Roo.isTouch && this.mobileTouchView){
12105 cfg = this.getAutoCreateTouchView();
12112 if(!this.tickable){
12113 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
12118 * ComboBox with tickable selections
12121 var align = this.labelAlign || this.parentLabelAlign();
12124 cls : 'form-group roo-combobox-tickable' //input-group
12129 cls : 'tickable-buttons',
12134 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
12135 html : this.triggerText
12141 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
12148 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
12155 buttons.cn.unshift({
12157 cls: 'roo-select2-search-field-input'
12163 Roo.each(buttons.cn, function(c){
12165 c.cls += ' btn-' + _this.size;
12168 if (_this.disabled) {
12179 cls: 'form-hidden-field'
12183 cls: 'roo-select2-choices',
12187 cls: 'roo-select2-search-field',
12199 cls: 'roo-select2-container input-group roo-select2-container-multi',
12204 // cls: 'typeahead typeahead-long dropdown-menu',
12205 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
12210 if(this.hasFeedback && !this.allowBlank){
12214 cls: 'glyphicon form-control-feedback'
12217 combobox.cn.push(feedback);
12220 if (align ==='left' && this.fieldLabel.length) {
12222 // Roo.log("left and has label");
12228 cls : 'control-label col-sm-' + this.labelWidth,
12229 html : this.fieldLabel
12233 cls : "col-sm-" + (12 - this.labelWidth),
12240 } else if ( this.fieldLabel.length) {
12241 // Roo.log(" label");
12246 //cls : 'input-group-addon',
12247 html : this.fieldLabel
12257 // Roo.log(" no label && no align");
12264 ['xs','sm','md','lg'].map(function(size){
12265 if (settings[size]) {
12266 cfg.cls += ' col-' + size + '-' + settings[size];
12274 _initEventsCalled : false,
12277 initEvents: function()
12280 if (this._initEventsCalled) { // as we call render... prevent looping...
12283 this._initEventsCalled = true;
12286 throw "can not find store for combo";
12289 this.store = Roo.factory(this.store, Roo.data);
12291 // if we are building from html. then this element is so complex, that we can not really
12292 // use the rendered HTML.
12293 // so we have to trash and replace the previous code.
12294 if (Roo.XComponent.build_from_html) {
12296 // remove this element....
12297 var e = this.el.dom, k=0;
12298 while (e ) { e = e.previousSibling; ++k;}
12303 this.rendered = false;
12305 this.render(this.parent().getChildContainer(true), k);
12316 if(Roo.isTouch && this.mobileTouchView){
12317 this.initTouchView();
12322 this.initTickableEvents();
12326 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
12328 if(this.hiddenName){
12330 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
12332 this.hiddenField.dom.value =
12333 this.hiddenValue !== undefined ? this.hiddenValue :
12334 this.value !== undefined ? this.value : '';
12336 // prevent input submission
12337 this.el.dom.removeAttribute('name');
12338 this.hiddenField.dom.setAttribute('name', this.hiddenName);
12343 // this.el.dom.setAttribute('autocomplete', 'off');
12346 var cls = 'x-combo-list';
12348 //this.list = new Roo.Layer({
12349 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
12355 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
12356 _this.list.setWidth(lw);
12359 this.list.on('mouseover', this.onViewOver, this);
12360 this.list.on('mousemove', this.onViewMove, this);
12362 this.list.on('scroll', this.onViewScroll, this);
12365 this.list.swallowEvent('mousewheel');
12366 this.assetHeight = 0;
12369 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
12370 this.assetHeight += this.header.getHeight();
12373 this.innerList = this.list.createChild({cls:cls+'-inner'});
12374 this.innerList.on('mouseover', this.onViewOver, this);
12375 this.innerList.on('mousemove', this.onViewMove, this);
12376 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
12378 if(this.allowBlank && !this.pageSize && !this.disableClear){
12379 this.footer = this.list.createChild({cls:cls+'-ft'});
12380 this.pageTb = new Roo.Toolbar(this.footer);
12384 this.footer = this.list.createChild({cls:cls+'-ft'});
12385 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
12386 {pageSize: this.pageSize});
12390 if (this.pageTb && this.allowBlank && !this.disableClear) {
12392 this.pageTb.add(new Roo.Toolbar.Fill(), {
12393 cls: 'x-btn-icon x-btn-clear',
12395 handler: function()
12398 _this.clearValue();
12399 _this.onSelect(false, -1);
12404 this.assetHeight += this.footer.getHeight();
12409 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
12412 this.view = new Roo.View(this.list, this.tpl, {
12413 singleSelect:true, store: this.store, selectedClass: this.selectedClass
12415 //this.view.wrapEl.setDisplayed(false);
12416 this.view.on('click', this.onViewClick, this);
12420 this.store.on('beforeload', this.onBeforeLoad, this);
12421 this.store.on('load', this.onLoad, this);
12422 this.store.on('loadexception', this.onLoadException, this);
12424 if(this.resizable){
12425 this.resizer = new Roo.Resizable(this.list, {
12426 pinned:true, handles:'se'
12428 this.resizer.on('resize', function(r, w, h){
12429 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
12430 this.listWidth = w;
12431 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
12432 this.restrictHeight();
12434 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
12437 if(!this.editable){
12438 this.editable = true;
12439 this.setEditable(false);
12444 if (typeof(this.events.add.listeners) != 'undefined') {
12446 this.addicon = this.wrap.createChild(
12447 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
12449 this.addicon.on('click', function(e) {
12450 this.fireEvent('add', this);
12453 if (typeof(this.events.edit.listeners) != 'undefined') {
12455 this.editicon = this.wrap.createChild(
12456 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
12457 if (this.addicon) {
12458 this.editicon.setStyle('margin-left', '40px');
12460 this.editicon.on('click', function(e) {
12462 // we fire even if inothing is selected..
12463 this.fireEvent('edit', this, this.lastData );
12469 this.keyNav = new Roo.KeyNav(this.inputEl(), {
12470 "up" : function(e){
12471 this.inKeyMode = true;
12475 "down" : function(e){
12476 if(!this.isExpanded()){
12477 this.onTriggerClick();
12479 this.inKeyMode = true;
12484 "enter" : function(e){
12485 // this.onViewClick();
12489 if(this.fireEvent("specialkey", this, e)){
12490 this.onViewClick(false);
12496 "esc" : function(e){
12500 "tab" : function(e){
12503 if(this.fireEvent("specialkey", this, e)){
12504 this.onViewClick(false);
12512 doRelay : function(foo, bar, hname){
12513 if(hname == 'down' || this.scope.isExpanded()){
12514 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
12523 this.queryDelay = Math.max(this.queryDelay || 10,
12524 this.mode == 'local' ? 10 : 250);
12527 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
12529 if(this.typeAhead){
12530 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
12532 if(this.editable !== false){
12533 this.inputEl().on("keyup", this.onKeyUp, this);
12535 if(this.forceSelection){
12536 this.inputEl().on('blur', this.doForce, this);
12540 this.choices = this.el.select('ul.roo-select2-choices', true).first();
12541 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
12545 initTickableEvents: function()
12549 if(this.hiddenName){
12551 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
12553 this.hiddenField.dom.value =
12554 this.hiddenValue !== undefined ? this.hiddenValue :
12555 this.value !== undefined ? this.value : '';
12557 // prevent input submission
12558 this.el.dom.removeAttribute('name');
12559 this.hiddenField.dom.setAttribute('name', this.hiddenName);
12564 // this.list = this.el.select('ul.dropdown-menu',true).first();
12566 this.choices = this.el.select('ul.roo-select2-choices', true).first();
12567 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
12568 if(this.triggerList){
12569 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
12572 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
12573 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
12575 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
12576 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
12578 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
12579 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
12581 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
12582 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
12583 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
12586 this.cancelBtn.hide();
12591 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
12592 _this.list.setWidth(lw);
12595 this.list.on('mouseover', this.onViewOver, this);
12596 this.list.on('mousemove', this.onViewMove, this);
12598 this.list.on('scroll', this.onViewScroll, this);
12601 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}" type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></li>';
12604 this.view = new Roo.View(this.list, this.tpl, {
12605 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
12608 //this.view.wrapEl.setDisplayed(false);
12609 this.view.on('click', this.onViewClick, this);
12613 this.store.on('beforeload', this.onBeforeLoad, this);
12614 this.store.on('load', this.onLoad, this);
12615 this.store.on('loadexception', this.onLoadException, this);
12618 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
12619 "up" : function(e){
12620 this.inKeyMode = true;
12624 "down" : function(e){
12625 this.inKeyMode = true;
12629 "enter" : function(e){
12630 if(this.fireEvent("specialkey", this, e)){
12631 this.onViewClick(false);
12637 "esc" : function(e){
12638 this.onTickableFooterButtonClick(e, false, false);
12641 "tab" : function(e){
12642 this.fireEvent("specialkey", this, e);
12644 this.onTickableFooterButtonClick(e, false, false);
12651 doRelay : function(e, fn, key){
12652 if(this.scope.isExpanded()){
12653 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
12662 this.queryDelay = Math.max(this.queryDelay || 10,
12663 this.mode == 'local' ? 10 : 250);
12666 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
12668 if(this.typeAhead){
12669 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
12672 if(this.editable !== false){
12673 this.tickableInputEl().on("keyup", this.onKeyUp, this);
12678 onDestroy : function(){
12680 this.view.setStore(null);
12681 this.view.el.removeAllListeners();
12682 this.view.el.remove();
12683 this.view.purgeListeners();
12686 this.list.dom.innerHTML = '';
12690 this.store.un('beforeload', this.onBeforeLoad, this);
12691 this.store.un('load', this.onLoad, this);
12692 this.store.un('loadexception', this.onLoadException, this);
12694 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
12698 fireKey : function(e){
12699 if(e.isNavKeyPress() && !this.list.isVisible()){
12700 this.fireEvent("specialkey", this, e);
12705 onResize: function(w, h){
12706 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
12708 // if(typeof w != 'number'){
12709 // // we do not handle it!?!?
12712 // var tw = this.trigger.getWidth();
12713 // // tw += this.addicon ? this.addicon.getWidth() : 0;
12714 // // tw += this.editicon ? this.editicon.getWidth() : 0;
12716 // this.inputEl().setWidth( this.adjustWidth('input', x));
12718 // //this.trigger.setStyle('left', x+'px');
12720 // if(this.list && this.listWidth === undefined){
12721 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
12722 // this.list.setWidth(lw);
12723 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
12731 * Allow or prevent the user from directly editing the field text. If false is passed,
12732 * the user will only be able to select from the items defined in the dropdown list. This method
12733 * is the runtime equivalent of setting the 'editable' config option at config time.
12734 * @param {Boolean} value True to allow the user to directly edit the field text
12736 setEditable : function(value){
12737 if(value == this.editable){
12740 this.editable = value;
12742 this.inputEl().dom.setAttribute('readOnly', true);
12743 this.inputEl().on('mousedown', this.onTriggerClick, this);
12744 this.inputEl().addClass('x-combo-noedit');
12746 this.inputEl().dom.setAttribute('readOnly', false);
12747 this.inputEl().un('mousedown', this.onTriggerClick, this);
12748 this.inputEl().removeClass('x-combo-noedit');
12754 onBeforeLoad : function(combo,opts){
12755 if(!this.hasFocus){
12759 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
12761 this.restrictHeight();
12762 this.selectedIndex = -1;
12766 onLoad : function(){
12768 this.hasQuery = false;
12770 if(!this.hasFocus){
12774 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
12775 this.loading.hide();
12778 if(this.store.getCount() > 0){
12780 this.restrictHeight();
12781 if(this.lastQuery == this.allQuery){
12782 if(this.editable && !this.tickable){
12783 this.inputEl().dom.select();
12787 !this.selectByValue(this.value, true) &&
12790 !this.store.lastOptions ||
12791 typeof(this.store.lastOptions.add) == 'undefined' ||
12792 this.store.lastOptions.add != true
12795 this.select(0, true);
12798 if(this.autoFocus){
12801 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
12802 this.taTask.delay(this.typeAheadDelay);
12806 this.onEmptyResults();
12812 onLoadException : function()
12814 this.hasQuery = false;
12816 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
12817 this.loading.hide();
12820 if(this.tickable && this.editable){
12825 // only causes errors at present
12826 //Roo.log(this.store.reader.jsonData);
12827 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
12829 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
12835 onTypeAhead : function(){
12836 if(this.store.getCount() > 0){
12837 var r = this.store.getAt(0);
12838 var newValue = r.data[this.displayField];
12839 var len = newValue.length;
12840 var selStart = this.getRawValue().length;
12842 if(selStart != len){
12843 this.setRawValue(newValue);
12844 this.selectText(selStart, newValue.length);
12850 onSelect : function(record, index){
12852 if(this.fireEvent('beforeselect', this, record, index) !== false){
12854 this.setFromData(index > -1 ? record.data : false);
12857 this.fireEvent('select', this, record, index);
12862 * Returns the currently selected field value or empty string if no value is set.
12863 * @return {String} value The selected value
12865 getValue : function(){
12868 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
12871 if(this.valueField){
12872 return typeof this.value != 'undefined' ? this.value : '';
12874 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
12879 * Clears any text/value currently set in the field
12881 clearValue : function(){
12882 if(this.hiddenField){
12883 this.hiddenField.dom.value = '';
12886 this.setRawValue('');
12887 this.lastSelectionText = '';
12888 this.lastData = false;
12890 var close = this.closeTriggerEl();
12899 * Sets the specified value into the field. If the value finds a match, the corresponding record text
12900 * will be displayed in the field. If the value does not match the data value of an existing item,
12901 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
12902 * Otherwise the field will be blank (although the value will still be set).
12903 * @param {String} value The value to match
12905 setValue : function(v){
12912 if(this.valueField){
12913 var r = this.findRecord(this.valueField, v);
12915 text = r.data[this.displayField];
12916 }else if(this.valueNotFoundText !== undefined){
12917 text = this.valueNotFoundText;
12920 this.lastSelectionText = text;
12921 if(this.hiddenField){
12922 this.hiddenField.dom.value = v;
12924 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
12927 var close = this.closeTriggerEl();
12930 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
12934 * @property {Object} the last set data for the element
12939 * Sets the value of the field based on a object which is related to the record format for the store.
12940 * @param {Object} value the value to set as. or false on reset?
12942 setFromData : function(o){
12949 var dv = ''; // display value
12950 var vv = ''; // value value..
12952 if (this.displayField) {
12953 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
12955 // this is an error condition!!!
12956 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
12959 if(this.valueField){
12960 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
12963 var close = this.closeTriggerEl();
12966 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
12969 if(this.hiddenField){
12970 this.hiddenField.dom.value = vv;
12972 this.lastSelectionText = dv;
12973 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
12977 // no hidden field.. - we store the value in 'value', but still display
12978 // display field!!!!
12979 this.lastSelectionText = dv;
12980 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
12987 reset : function(){
12988 // overridden so that last data is reset..
12995 this.setValue(this.originalValue);
12996 this.clearInvalid();
12997 this.lastData = false;
12999 this.view.clearSelections();
13003 findRecord : function(prop, value){
13005 if(this.store.getCount() > 0){
13006 this.store.each(function(r){
13007 if(r.data[prop] == value){
13017 getName: function()
13019 // returns hidden if it's set..
13020 if (!this.rendered) {return ''};
13021 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
13025 onViewMove : function(e, t){
13026 this.inKeyMode = false;
13030 onViewOver : function(e, t){
13031 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
13034 var item = this.view.findItemFromChild(t);
13037 var index = this.view.indexOf(item);
13038 this.select(index, false);
13043 onViewClick : function(view, doFocus, el, e)
13045 var index = this.view.getSelectedIndexes()[0];
13047 var r = this.store.getAt(index);
13051 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
13058 Roo.each(this.tickItems, function(v,k){
13060 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
13062 _this.tickItems.splice(k, 1);
13064 if(typeof(e) == 'undefined' && view == false){
13065 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
13077 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
13078 this.tickItems.push(r.data);
13081 if(typeof(e) == 'undefined' && view == false){
13082 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
13089 this.onSelect(r, index);
13091 if(doFocus !== false && !this.blockFocus){
13092 this.inputEl().focus();
13097 restrictHeight : function(){
13098 //this.innerList.dom.style.height = '';
13099 //var inner = this.innerList.dom;
13100 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
13101 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
13102 //this.list.beginUpdate();
13103 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
13104 this.list.alignTo(this.inputEl(), this.listAlign);
13105 this.list.alignTo(this.inputEl(), this.listAlign);
13106 //this.list.endUpdate();
13110 onEmptyResults : function(){
13112 if(this.tickable && this.editable){
13113 this.restrictHeight();
13121 * Returns true if the dropdown list is expanded, else false.
13123 isExpanded : function(){
13124 return this.list.isVisible();
13128 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
13129 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
13130 * @param {String} value The data value of the item to select
13131 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
13132 * selected item if it is not currently in view (defaults to true)
13133 * @return {Boolean} True if the value matched an item in the list, else false
13135 selectByValue : function(v, scrollIntoView){
13136 if(v !== undefined && v !== null){
13137 var r = this.findRecord(this.valueField || this.displayField, v);
13139 this.select(this.store.indexOf(r), scrollIntoView);
13147 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
13148 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
13149 * @param {Number} index The zero-based index of the list item to select
13150 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
13151 * selected item if it is not currently in view (defaults to true)
13153 select : function(index, scrollIntoView){
13154 this.selectedIndex = index;
13155 this.view.select(index);
13156 if(scrollIntoView !== false){
13157 var el = this.view.getNode(index);
13159 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
13162 this.list.scrollChildIntoView(el, false);
13168 selectNext : function(){
13169 var ct = this.store.getCount();
13171 if(this.selectedIndex == -1){
13173 }else if(this.selectedIndex < ct-1){
13174 this.select(this.selectedIndex+1);
13180 selectPrev : function(){
13181 var ct = this.store.getCount();
13183 if(this.selectedIndex == -1){
13185 }else if(this.selectedIndex != 0){
13186 this.select(this.selectedIndex-1);
13192 onKeyUp : function(e){
13193 if(this.editable !== false && !e.isSpecialKey()){
13194 this.lastKey = e.getKey();
13195 this.dqTask.delay(this.queryDelay);
13200 validateBlur : function(){
13201 return !this.list || !this.list.isVisible();
13205 initQuery : function(){
13207 var v = this.getRawValue();
13209 if(this.tickable && this.editable){
13210 v = this.tickableInputEl().getValue();
13217 doForce : function(){
13218 if(this.inputEl().dom.value.length > 0){
13219 this.inputEl().dom.value =
13220 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
13226 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
13227 * query allowing the query action to be canceled if needed.
13228 * @param {String} query The SQL query to execute
13229 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
13230 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
13231 * saved in the current store (defaults to false)
13233 doQuery : function(q, forceAll){
13235 if(q === undefined || q === null){
13240 forceAll: forceAll,
13244 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
13249 forceAll = qe.forceAll;
13250 if(forceAll === true || (q.length >= this.minChars)){
13252 this.hasQuery = true;
13254 if(this.lastQuery != q || this.alwaysQuery){
13255 this.lastQuery = q;
13256 if(this.mode == 'local'){
13257 this.selectedIndex = -1;
13259 this.store.clearFilter();
13262 if(this.specialFilter){
13263 this.fireEvent('specialfilter', this);
13268 this.store.filter(this.displayField, q);
13271 this.store.fireEvent("datachanged", this.store);
13278 this.store.baseParams[this.queryParam] = q;
13280 var options = {params : this.getParams(q)};
13283 options.add = true;
13284 options.params.start = this.page * this.pageSize;
13287 this.store.load(options);
13290 * this code will make the page width larger, at the beginning, the list not align correctly,
13291 * we should expand the list on onLoad
13292 * so command out it
13297 this.selectedIndex = -1;
13302 this.loadNext = false;
13306 getParams : function(q){
13308 //p[this.queryParam] = q;
13312 p.limit = this.pageSize;
13318 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
13320 collapse : function(){
13321 if(!this.isExpanded()){
13328 this.hasFocus = false;
13330 this.cancelBtn.hide();
13331 this.trigger.show();
13334 this.tickableInputEl().dom.value = '';
13335 this.tickableInputEl().blur();
13340 Roo.get(document).un('mousedown', this.collapseIf, this);
13341 Roo.get(document).un('mousewheel', this.collapseIf, this);
13342 if (!this.editable) {
13343 Roo.get(document).un('keydown', this.listKeyPress, this);
13345 this.fireEvent('collapse', this);
13349 collapseIf : function(e){
13350 var in_combo = e.within(this.el);
13351 var in_list = e.within(this.list);
13352 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
13354 if (in_combo || in_list || is_list) {
13355 //e.stopPropagation();
13360 this.onTickableFooterButtonClick(e, false, false);
13368 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
13370 expand : function(){
13372 if(this.isExpanded() || !this.hasFocus){
13376 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
13377 this.list.setWidth(lw);
13384 this.restrictHeight();
13388 this.tickItems = Roo.apply([], this.item);
13391 this.cancelBtn.show();
13392 this.trigger.hide();
13395 this.tickableInputEl().focus();
13400 Roo.get(document).on('mousedown', this.collapseIf, this);
13401 Roo.get(document).on('mousewheel', this.collapseIf, this);
13402 if (!this.editable) {
13403 Roo.get(document).on('keydown', this.listKeyPress, this);
13406 this.fireEvent('expand', this);
13410 // Implements the default empty TriggerField.onTriggerClick function
13411 onTriggerClick : function(e)
13413 Roo.log('trigger click');
13415 if(this.disabled || !this.triggerList){
13420 this.loadNext = false;
13422 if(this.isExpanded()){
13424 if (!this.blockFocus) {
13425 this.inputEl().focus();
13429 this.hasFocus = true;
13430 if(this.triggerAction == 'all') {
13431 this.doQuery(this.allQuery, true);
13433 this.doQuery(this.getRawValue());
13435 if (!this.blockFocus) {
13436 this.inputEl().focus();
13441 onTickableTriggerClick : function(e)
13448 this.loadNext = false;
13449 this.hasFocus = true;
13451 if(this.triggerAction == 'all') {
13452 this.doQuery(this.allQuery, true);
13454 this.doQuery(this.getRawValue());
13458 onSearchFieldClick : function(e)
13460 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
13461 this.onTickableFooterButtonClick(e, false, false);
13465 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
13470 this.loadNext = false;
13471 this.hasFocus = true;
13473 if(this.triggerAction == 'all') {
13474 this.doQuery(this.allQuery, true);
13476 this.doQuery(this.getRawValue());
13480 listKeyPress : function(e)
13482 //Roo.log('listkeypress');
13483 // scroll to first matching element based on key pres..
13484 if (e.isSpecialKey()) {
13487 var k = String.fromCharCode(e.getKey()).toUpperCase();
13490 var csel = this.view.getSelectedNodes();
13491 var cselitem = false;
13493 var ix = this.view.indexOf(csel[0]);
13494 cselitem = this.store.getAt(ix);
13495 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
13501 this.store.each(function(v) {
13503 // start at existing selection.
13504 if (cselitem.id == v.id) {
13510 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
13511 match = this.store.indexOf(v);
13517 if (match === false) {
13518 return true; // no more action?
13521 this.view.select(match);
13522 var sn = Roo.get(this.view.getSelectedNodes()[0]);
13523 sn.scrollIntoView(sn.dom.parentNode, false);
13526 onViewScroll : function(e, t){
13528 if(this.view.el.getScroll().top == 0 ||this.view.el.getScroll().top < this.view.el.dom.scrollHeight - this.view.el.dom.clientHeight || !this.hasFocus || !this.append || this.hasQuery){
13532 this.hasQuery = true;
13534 this.loading = this.list.select('.loading', true).first();
13536 if(this.loading === null){
13537 this.list.createChild({
13539 cls: 'loading roo-select2-more-results roo-select2-active',
13540 html: 'Loading more results...'
13543 this.loading = this.list.select('.loading', true).first();
13545 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
13547 this.loading.hide();
13550 this.loading.show();
13555 this.loadNext = true;
13557 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
13562 addItem : function(o)
13564 var dv = ''; // display value
13566 if (this.displayField) {
13567 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
13569 // this is an error condition!!!
13570 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
13577 var choice = this.choices.createChild({
13579 cls: 'roo-select2-search-choice',
13588 cls: 'roo-select2-search-choice-close',
13593 }, this.searchField);
13595 var close = choice.select('a.roo-select2-search-choice-close', true).first();
13597 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
13605 this.inputEl().dom.value = '';
13610 onRemoveItem : function(e, _self, o)
13612 e.preventDefault();
13614 this.lastItem = Roo.apply([], this.item);
13616 var index = this.item.indexOf(o.data) * 1;
13619 Roo.log('not this item?!');
13623 this.item.splice(index, 1);
13628 this.fireEvent('remove', this, e);
13634 syncValue : function()
13636 if(!this.item.length){
13643 Roo.each(this.item, function(i){
13644 if(_this.valueField){
13645 value.push(i[_this.valueField]);
13652 this.value = value.join(',');
13654 if(this.hiddenField){
13655 this.hiddenField.dom.value = this.value;
13658 this.store.fireEvent("datachanged", this.store);
13661 clearItem : function()
13663 if(!this.multiple){
13669 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
13677 if(this.tickable && !Roo.isTouch){
13678 this.view.refresh();
13682 inputEl: function ()
13684 if(Roo.isTouch && this.mobileTouchView){
13685 return this.el.select('input.form-control',true).first();
13689 return this.searchField;
13692 return this.el.select('input.form-control',true).first();
13696 onTickableFooterButtonClick : function(e, btn, el)
13698 e.preventDefault();
13700 this.lastItem = Roo.apply([], this.item);
13702 if(btn && btn.name == 'cancel'){
13703 this.tickItems = Roo.apply([], this.item);
13712 Roo.each(this.tickItems, function(o){
13720 validate : function()
13722 var v = this.getRawValue();
13725 v = this.getValue();
13728 if(this.disabled || this.allowBlank || v.length){
13733 this.markInvalid();
13737 tickableInputEl : function()
13739 if(!this.tickable || !this.editable){
13740 return this.inputEl();
13743 return this.inputEl().select('.roo-select2-search-field-input', true).first();
13747 getAutoCreateTouchView : function()
13752 cls: 'form-group' //input-group
13758 type : this.inputType,
13759 cls : 'form-control x-combo-noedit',
13760 autocomplete: 'new-password',
13761 placeholder : this.placeholder || '',
13766 input.name = this.name;
13770 input.cls += ' input-' + this.size;
13773 if (this.disabled) {
13774 input.disabled = true;
13785 inputblock.cls += ' input-group';
13787 inputblock.cn.unshift({
13789 cls : 'input-group-addon',
13794 if(this.removable && !this.multiple){
13795 inputblock.cls += ' roo-removable';
13797 inputblock.cn.push({
13800 cls : 'roo-combo-removable-btn close'
13804 if(this.hasFeedback && !this.allowBlank){
13806 inputblock.cls += ' has-feedback';
13808 inputblock.cn.push({
13810 cls: 'glyphicon form-control-feedback'
13817 inputblock.cls += (this.before) ? '' : ' input-group';
13819 inputblock.cn.push({
13821 cls : 'input-group-addon',
13832 cls: 'form-hidden-field'
13846 cls: 'form-hidden-field'
13850 cls: 'roo-select2-choices',
13854 cls: 'roo-select2-search-field',
13867 cls: 'roo-select2-container input-group',
13874 combobox.cls += ' roo-select2-container-multi';
13877 var align = this.labelAlign || this.parentLabelAlign();
13881 if(this.fieldLabel.length){
13883 var lw = align === 'left' ? ('col-sm' + this.labelWidth) : '';
13884 var cw = align === 'left' ? ('col-sm' + (12 - this.labelWidth)) : '';
13889 cls : 'control-label ' + lw,
13890 html : this.fieldLabel
13902 var settings = this;
13904 ['xs','sm','md','lg'].map(function(size){
13905 if (settings[size]) {
13906 cfg.cls += ' col-' + size + '-' + settings[size];
13913 initTouchView : function()
13915 this.renderTouchView();
13917 this.touchViewEl.on('scroll', function(){
13918 this.el.dom.scrollTop = 0;
13921 this.originalValue = this.getValue();
13923 this.inputEl().on("click", this.showTouchView, this);
13925 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
13926 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
13928 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
13930 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
13931 this.store.on('load', this.onTouchViewLoad, this);
13932 this.store.on('loadexception', this.onTouchViewLoadException, this);
13934 if(this.hiddenName){
13936 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13938 this.hiddenField.dom.value =
13939 this.hiddenValue !== undefined ? this.hiddenValue :
13940 this.value !== undefined ? this.value : '';
13942 this.el.dom.removeAttribute('name');
13943 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13947 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13948 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13951 if(this.removable && !this.multiple){
13952 var close = this.closeTriggerEl();
13954 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
13955 close.on('click', this.removeBtnClick, this, close);
13959 * fix the bug in Safari iOS8
13961 this.inputEl().on("focus", function(e){
13962 document.activeElement.blur();
13970 renderTouchView : function()
13972 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
13973 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
13975 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
13976 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
13978 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
13979 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
13980 this.touchViewBodyEl.setStyle('overflow', 'auto');
13982 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
13983 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
13985 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
13986 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
13990 showTouchView : function()
13996 this.touchViewHeaderEl.hide();
13998 if(this.fieldLabel.length){
13999 this.touchViewHeaderEl.dom.innerHTML = this.fieldLabel;
14000 this.touchViewHeaderEl.show();
14003 this.touchViewEl.show();
14005 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
14006 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
14008 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
14010 if(this.fieldLabel.length){
14011 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
14014 this.touchViewBodyEl.setHeight(bodyHeight);
14018 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
14020 this.touchViewEl.addClass('in');
14023 this.doTouchViewQuery();
14027 hideTouchView : function()
14029 this.touchViewEl.removeClass('in');
14033 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
14035 this.touchViewEl.setStyle('display', 'none');
14040 setTouchViewValue : function()
14047 Roo.each(this.tickItems, function(o){
14052 this.hideTouchView();
14055 doTouchViewQuery : function()
14064 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
14068 if(!this.alwaysQuery || this.mode == 'local'){
14069 this.onTouchViewLoad();
14076 onTouchViewBeforeLoad : function(combo,opts)
14082 onTouchViewLoad : function()
14084 if(this.store.getCount() < 1){
14085 this.onTouchViewEmptyResults();
14089 this.clearTouchView();
14091 var rawValue = this.getRawValue();
14093 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
14095 this.tickItems = [];
14097 this.store.data.each(function(d, rowIndex){
14098 var row = this.touchViewListGroup.createChild(template);
14100 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
14101 row.addClass(d.data.cls);
14104 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
14107 html : d.data[this.displayField]
14110 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
14111 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
14115 if(!this.multiple && this.valueField && typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue()){
14116 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
14119 if(this.multiple && this.valueField && typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1){
14120 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
14121 this.tickItems.push(d.data);
14124 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
14128 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
14130 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
14132 if(this.fieldLabel.length){
14133 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
14136 var listHeight = this.touchViewListGroup.getHeight();
14140 if(firstChecked && listHeight > bodyHeight){
14141 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
14146 onTouchViewLoadException : function()
14148 this.hideTouchView();
14151 onTouchViewEmptyResults : function()
14153 this.clearTouchView();
14155 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
14157 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
14161 clearTouchView : function()
14163 this.touchViewListGroup.dom.innerHTML = '';
14166 onTouchViewClick : function(e, el, o)
14168 e.preventDefault();
14171 var rowIndex = o.rowIndex;
14173 var r = this.store.getAt(rowIndex);
14175 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
14177 if(!this.multiple){
14178 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
14179 c.dom.removeAttribute('checked');
14182 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
14184 this.setFromData(r.data);
14186 var close = this.closeTriggerEl();
14192 this.hideTouchView();
14194 this.fireEvent('select', this, r, rowIndex);
14199 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
14200 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
14201 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
14205 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
14206 this.addItem(r.data);
14207 this.tickItems.push(r.data);
14213 * @cfg {Boolean} grow
14217 * @cfg {Number} growMin
14221 * @cfg {Number} growMax
14230 Roo.apply(Roo.bootstrap.ComboBox, {
14234 cls: 'modal-header',
14256 cls: 'list-group-item',
14260 cls: 'roo-combobox-list-group-item-value'
14264 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
14278 listItemCheckbox : {
14280 cls: 'list-group-item',
14284 cls: 'roo-combobox-list-group-item-value'
14288 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
14304 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
14309 cls: 'modal-footer',
14317 cls: 'col-xs-6 text-left',
14320 cls: 'btn btn-danger roo-touch-view-cancel',
14326 cls: 'col-xs-6 text-right',
14329 cls: 'btn btn-success roo-touch-view-ok',
14340 Roo.apply(Roo.bootstrap.ComboBox, {
14342 touchViewTemplate : {
14344 cls: 'modal fade roo-combobox-touch-view',
14348 cls: 'modal-dialog',
14349 style : 'position:fixed', // we have to fix position....
14353 cls: 'modal-content',
14355 Roo.bootstrap.ComboBox.header,
14356 Roo.bootstrap.ComboBox.body,
14357 Roo.bootstrap.ComboBox.footer
14366 * Ext JS Library 1.1.1
14367 * Copyright(c) 2006-2007, Ext JS, LLC.
14369 * Originally Released Under LGPL - original licence link has changed is not relivant.
14372 * <script type="text/javascript">
14377 * @extends Roo.util.Observable
14378 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
14379 * This class also supports single and multi selection modes. <br>
14380 * Create a data model bound view:
14382 var store = new Roo.data.Store(...);
14384 var view = new Roo.View({
14386 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
14388 singleSelect: true,
14389 selectedClass: "ydataview-selected",
14393 // listen for node click?
14394 view.on("click", function(vw, index, node, e){
14395 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
14399 dataModel.load("foobar.xml");
14401 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
14403 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
14404 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
14406 * Note: old style constructor is still suported (container, template, config)
14409 * Create a new View
14410 * @param {Object} config The config object
14413 Roo.View = function(config, depreciated_tpl, depreciated_config){
14415 this.parent = false;
14417 if (typeof(depreciated_tpl) == 'undefined') {
14418 // new way.. - universal constructor.
14419 Roo.apply(this, config);
14420 this.el = Roo.get(this.el);
14423 this.el = Roo.get(config);
14424 this.tpl = depreciated_tpl;
14425 Roo.apply(this, depreciated_config);
14427 this.wrapEl = this.el.wrap().wrap();
14428 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
14431 if(typeof(this.tpl) == "string"){
14432 this.tpl = new Roo.Template(this.tpl);
14434 // support xtype ctors..
14435 this.tpl = new Roo.factory(this.tpl, Roo);
14439 this.tpl.compile();
14444 * @event beforeclick
14445 * Fires before a click is processed. Returns false to cancel the default action.
14446 * @param {Roo.View} this
14447 * @param {Number} index The index of the target node
14448 * @param {HTMLElement} node The target node
14449 * @param {Roo.EventObject} e The raw event object
14451 "beforeclick" : true,
14454 * Fires when a template node is clicked.
14455 * @param {Roo.View} this
14456 * @param {Number} index The index of the target node
14457 * @param {HTMLElement} node The target node
14458 * @param {Roo.EventObject} e The raw event object
14463 * Fires when a template node is double clicked.
14464 * @param {Roo.View} this
14465 * @param {Number} index The index of the target node
14466 * @param {HTMLElement} node The target node
14467 * @param {Roo.EventObject} e The raw event object
14471 * @event contextmenu
14472 * Fires when a template node is right clicked.
14473 * @param {Roo.View} this
14474 * @param {Number} index The index of the target node
14475 * @param {HTMLElement} node The target node
14476 * @param {Roo.EventObject} e The raw event object
14478 "contextmenu" : true,
14480 * @event selectionchange
14481 * Fires when the selected nodes change.
14482 * @param {Roo.View} this
14483 * @param {Array} selections Array of the selected nodes
14485 "selectionchange" : true,
14488 * @event beforeselect
14489 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
14490 * @param {Roo.View} this
14491 * @param {HTMLElement} node The node to be selected
14492 * @param {Array} selections Array of currently selected nodes
14494 "beforeselect" : true,
14496 * @event preparedata
14497 * Fires on every row to render, to allow you to change the data.
14498 * @param {Roo.View} this
14499 * @param {Object} data to be rendered (change this)
14501 "preparedata" : true
14509 "click": this.onClick,
14510 "dblclick": this.onDblClick,
14511 "contextmenu": this.onContextMenu,
14515 this.selections = [];
14517 this.cmp = new Roo.CompositeElementLite([]);
14519 this.store = Roo.factory(this.store, Roo.data);
14520 this.setStore(this.store, true);
14523 if ( this.footer && this.footer.xtype) {
14525 var fctr = this.wrapEl.appendChild(document.createElement("div"));
14527 this.footer.dataSource = this.store;
14528 this.footer.container = fctr;
14529 this.footer = Roo.factory(this.footer, Roo);
14530 fctr.insertFirst(this.el);
14532 // this is a bit insane - as the paging toolbar seems to detach the el..
14533 // dom.parentNode.parentNode.parentNode
14534 // they get detached?
14538 Roo.View.superclass.constructor.call(this);
14543 Roo.extend(Roo.View, Roo.util.Observable, {
14546 * @cfg {Roo.data.Store} store Data store to load data from.
14551 * @cfg {String|Roo.Element} el The container element.
14556 * @cfg {String|Roo.Template} tpl The template used by this View
14560 * @cfg {String} dataName the named area of the template to use as the data area
14561 * Works with domtemplates roo-name="name"
14565 * @cfg {String} selectedClass The css class to add to selected nodes
14567 selectedClass : "x-view-selected",
14569 * @cfg {String} emptyText The empty text to show when nothing is loaded.
14574 * @cfg {String} text to display on mask (default Loading)
14578 * @cfg {Boolean} multiSelect Allow multiple selection
14580 multiSelect : false,
14582 * @cfg {Boolean} singleSelect Allow single selection
14584 singleSelect: false,
14587 * @cfg {Boolean} toggleSelect - selecting
14589 toggleSelect : false,
14592 * @cfg {Boolean} tickable - selecting
14597 * Returns the element this view is bound to.
14598 * @return {Roo.Element}
14600 getEl : function(){
14601 return this.wrapEl;
14607 * Refreshes the view. - called by datachanged on the store. - do not call directly.
14609 refresh : function(){
14610 //Roo.log('refresh');
14613 // if we are using something like 'domtemplate', then
14614 // the what gets used is:
14615 // t.applySubtemplate(NAME, data, wrapping data..)
14616 // the outer template then get' applied with
14617 // the store 'extra data'
14618 // and the body get's added to the
14619 // roo-name="data" node?
14620 // <span class='roo-tpl-{name}'></span> ?????
14624 this.clearSelections();
14625 this.el.update("");
14627 var records = this.store.getRange();
14628 if(records.length < 1) {
14630 // is this valid?? = should it render a template??
14632 this.el.update(this.emptyText);
14636 if (this.dataName) {
14637 this.el.update(t.apply(this.store.meta)); //????
14638 el = this.el.child('.roo-tpl-' + this.dataName);
14641 for(var i = 0, len = records.length; i < len; i++){
14642 var data = this.prepareData(records[i].data, i, records[i]);
14643 this.fireEvent("preparedata", this, data, i, records[i]);
14645 var d = Roo.apply({}, data);
14648 Roo.apply(d, {'roo-id' : Roo.id()});
14652 Roo.each(this.parent.item, function(item){
14653 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
14656 Roo.apply(d, {'roo-data-checked' : 'checked'});
14660 html[html.length] = Roo.util.Format.trim(
14662 t.applySubtemplate(this.dataName, d, this.store.meta) :
14669 el.update(html.join(""));
14670 this.nodes = el.dom.childNodes;
14671 this.updateIndexes(0);
14676 * Function to override to reformat the data that is sent to
14677 * the template for each node.
14678 * DEPRICATED - use the preparedata event handler.
14679 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
14680 * a JSON object for an UpdateManager bound view).
14682 prepareData : function(data, index, record)
14684 this.fireEvent("preparedata", this, data, index, record);
14688 onUpdate : function(ds, record){
14689 // Roo.log('on update');
14690 this.clearSelections();
14691 var index = this.store.indexOf(record);
14692 var n = this.nodes[index];
14693 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
14694 n.parentNode.removeChild(n);
14695 this.updateIndexes(index, index);
14701 onAdd : function(ds, records, index)
14703 //Roo.log(['on Add', ds, records, index] );
14704 this.clearSelections();
14705 if(this.nodes.length == 0){
14709 var n = this.nodes[index];
14710 for(var i = 0, len = records.length; i < len; i++){
14711 var d = this.prepareData(records[i].data, i, records[i]);
14713 this.tpl.insertBefore(n, d);
14716 this.tpl.append(this.el, d);
14719 this.updateIndexes(index);
14722 onRemove : function(ds, record, index){
14723 // Roo.log('onRemove');
14724 this.clearSelections();
14725 var el = this.dataName ?
14726 this.el.child('.roo-tpl-' + this.dataName) :
14729 el.dom.removeChild(this.nodes[index]);
14730 this.updateIndexes(index);
14734 * Refresh an individual node.
14735 * @param {Number} index
14737 refreshNode : function(index){
14738 this.onUpdate(this.store, this.store.getAt(index));
14741 updateIndexes : function(startIndex, endIndex){
14742 var ns = this.nodes;
14743 startIndex = startIndex || 0;
14744 endIndex = endIndex || ns.length - 1;
14745 for(var i = startIndex; i <= endIndex; i++){
14746 ns[i].nodeIndex = i;
14751 * Changes the data store this view uses and refresh the view.
14752 * @param {Store} store
14754 setStore : function(store, initial){
14755 if(!initial && this.store){
14756 this.store.un("datachanged", this.refresh);
14757 this.store.un("add", this.onAdd);
14758 this.store.un("remove", this.onRemove);
14759 this.store.un("update", this.onUpdate);
14760 this.store.un("clear", this.refresh);
14761 this.store.un("beforeload", this.onBeforeLoad);
14762 this.store.un("load", this.onLoad);
14763 this.store.un("loadexception", this.onLoad);
14767 store.on("datachanged", this.refresh, this);
14768 store.on("add", this.onAdd, this);
14769 store.on("remove", this.onRemove, this);
14770 store.on("update", this.onUpdate, this);
14771 store.on("clear", this.refresh, this);
14772 store.on("beforeload", this.onBeforeLoad, this);
14773 store.on("load", this.onLoad, this);
14774 store.on("loadexception", this.onLoad, this);
14782 * onbeforeLoad - masks the loading area.
14785 onBeforeLoad : function(store,opts)
14787 //Roo.log('onBeforeLoad');
14789 this.el.update("");
14791 this.el.mask(this.mask ? this.mask : "Loading" );
14793 onLoad : function ()
14800 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
14801 * @param {HTMLElement} node
14802 * @return {HTMLElement} The template node
14804 findItemFromChild : function(node){
14805 var el = this.dataName ?
14806 this.el.child('.roo-tpl-' + this.dataName,true) :
14809 if(!node || node.parentNode == el){
14812 var p = node.parentNode;
14813 while(p && p != el){
14814 if(p.parentNode == el){
14823 onClick : function(e){
14824 var item = this.findItemFromChild(e.getTarget());
14826 var index = this.indexOf(item);
14827 if(this.onItemClick(item, index, e) !== false){
14828 this.fireEvent("click", this, index, item, e);
14831 this.clearSelections();
14836 onContextMenu : function(e){
14837 var item = this.findItemFromChild(e.getTarget());
14839 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
14844 onDblClick : function(e){
14845 var item = this.findItemFromChild(e.getTarget());
14847 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
14851 onItemClick : function(item, index, e)
14853 if(this.fireEvent("beforeclick", this, index, item, e) === false){
14856 if (this.toggleSelect) {
14857 var m = this.isSelected(item) ? 'unselect' : 'select';
14860 _t[m](item, true, false);
14863 if(this.multiSelect || this.singleSelect){
14864 if(this.multiSelect && e.shiftKey && this.lastSelection){
14865 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
14867 this.select(item, this.multiSelect && e.ctrlKey);
14868 this.lastSelection = item;
14871 if(!this.tickable){
14872 e.preventDefault();
14880 * Get the number of selected nodes.
14883 getSelectionCount : function(){
14884 return this.selections.length;
14888 * Get the currently selected nodes.
14889 * @return {Array} An array of HTMLElements
14891 getSelectedNodes : function(){
14892 return this.selections;
14896 * Get the indexes of the selected nodes.
14899 getSelectedIndexes : function(){
14900 var indexes = [], s = this.selections;
14901 for(var i = 0, len = s.length; i < len; i++){
14902 indexes.push(s[i].nodeIndex);
14908 * Clear all selections
14909 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
14911 clearSelections : function(suppressEvent){
14912 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
14913 this.cmp.elements = this.selections;
14914 this.cmp.removeClass(this.selectedClass);
14915 this.selections = [];
14916 if(!suppressEvent){
14917 this.fireEvent("selectionchange", this, this.selections);
14923 * Returns true if the passed node is selected
14924 * @param {HTMLElement/Number} node The node or node index
14925 * @return {Boolean}
14927 isSelected : function(node){
14928 var s = this.selections;
14932 node = this.getNode(node);
14933 return s.indexOf(node) !== -1;
14938 * @param {Array/HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node, id of a template node or an array of any of those to select
14939 * @param {Boolean} keepExisting (optional) true to keep existing selections
14940 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
14942 select : function(nodeInfo, keepExisting, suppressEvent){
14943 if(nodeInfo instanceof Array){
14945 this.clearSelections(true);
14947 for(var i = 0, len = nodeInfo.length; i < len; i++){
14948 this.select(nodeInfo[i], true, true);
14952 var node = this.getNode(nodeInfo);
14953 if(!node || this.isSelected(node)){
14954 return; // already selected.
14957 this.clearSelections(true);
14960 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
14961 Roo.fly(node).addClass(this.selectedClass);
14962 this.selections.push(node);
14963 if(!suppressEvent){
14964 this.fireEvent("selectionchange", this, this.selections);
14972 * @param {Array/HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node, id of a template node or an array of any of those to select
14973 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
14974 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
14976 unselect : function(nodeInfo, keepExisting, suppressEvent)
14978 if(nodeInfo instanceof Array){
14979 Roo.each(this.selections, function(s) {
14980 this.unselect(s, nodeInfo);
14984 var node = this.getNode(nodeInfo);
14985 if(!node || !this.isSelected(node)){
14986 //Roo.log("not selected");
14987 return; // not selected.
14991 Roo.each(this.selections, function(s) {
14993 Roo.fly(node).removeClass(this.selectedClass);
15000 this.selections= ns;
15001 this.fireEvent("selectionchange", this, this.selections);
15005 * Gets a template node.
15006 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
15007 * @return {HTMLElement} The node or null if it wasn't found
15009 getNode : function(nodeInfo){
15010 if(typeof nodeInfo == "string"){
15011 return document.getElementById(nodeInfo);
15012 }else if(typeof nodeInfo == "number"){
15013 return this.nodes[nodeInfo];
15019 * Gets a range template nodes.
15020 * @param {Number} startIndex
15021 * @param {Number} endIndex
15022 * @return {Array} An array of nodes
15024 getNodes : function(start, end){
15025 var ns = this.nodes;
15026 start = start || 0;
15027 end = typeof end == "undefined" ? ns.length - 1 : end;
15030 for(var i = start; i <= end; i++){
15034 for(var i = start; i >= end; i--){
15042 * Finds the index of the passed node
15043 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
15044 * @return {Number} The index of the node or -1
15046 indexOf : function(node){
15047 node = this.getNode(node);
15048 if(typeof node.nodeIndex == "number"){
15049 return node.nodeIndex;
15051 var ns = this.nodes;
15052 for(var i = 0, len = ns.length; i < len; i++){
15063 * based on jquery fullcalendar
15067 Roo.bootstrap = Roo.bootstrap || {};
15069 * @class Roo.bootstrap.Calendar
15070 * @extends Roo.bootstrap.Component
15071 * Bootstrap Calendar class
15072 * @cfg {Boolean} loadMask (true|false) default false
15073 * @cfg {Object} header generate the user specific header of the calendar, default false
15076 * Create a new Container
15077 * @param {Object} config The config object
15082 Roo.bootstrap.Calendar = function(config){
15083 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
15087 * Fires when a date is selected
15088 * @param {DatePicker} this
15089 * @param {Date} date The selected date
15093 * @event monthchange
15094 * Fires when the displayed month changes
15095 * @param {DatePicker} this
15096 * @param {Date} date The selected month
15098 'monthchange': true,
15100 * @event evententer
15101 * Fires when mouse over an event
15102 * @param {Calendar} this
15103 * @param {event} Event
15105 'evententer': true,
15107 * @event eventleave
15108 * Fires when the mouse leaves an
15109 * @param {Calendar} this
15112 'eventleave': true,
15114 * @event eventclick
15115 * Fires when the mouse click an
15116 * @param {Calendar} this
15125 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
15128 * @cfg {Number} startDay
15129 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
15137 getAutoCreate : function(){
15140 var fc_button = function(name, corner, style, content ) {
15141 return Roo.apply({},{
15143 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
15145 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
15148 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
15159 style : 'width:100%',
15166 cls : 'fc-header-left',
15168 fc_button('prev', 'left', 'arrow', '‹' ),
15169 fc_button('next', 'right', 'arrow', '›' ),
15170 { tag: 'span', cls: 'fc-header-space' },
15171 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
15179 cls : 'fc-header-center',
15183 cls: 'fc-header-title',
15186 html : 'month / year'
15194 cls : 'fc-header-right',
15196 /* fc_button('month', 'left', '', 'month' ),
15197 fc_button('week', '', '', 'week' ),
15198 fc_button('day', 'right', '', 'day' )
15210 header = this.header;
15213 var cal_heads = function() {
15215 // fixme - handle this.
15217 for (var i =0; i < Date.dayNames.length; i++) {
15218 var d = Date.dayNames[i];
15221 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
15222 html : d.substring(0,3)
15226 ret[0].cls += ' fc-first';
15227 ret[6].cls += ' fc-last';
15230 var cal_cell = function(n) {
15233 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
15238 cls: 'fc-day-number',
15242 cls: 'fc-day-content',
15246 style: 'position: relative;' // height: 17px;
15258 var cal_rows = function() {
15261 for (var r = 0; r < 6; r++) {
15268 for (var i =0; i < Date.dayNames.length; i++) {
15269 var d = Date.dayNames[i];
15270 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
15273 row.cn[0].cls+=' fc-first';
15274 row.cn[0].cn[0].style = 'min-height:90px';
15275 row.cn[6].cls+=' fc-last';
15279 ret[0].cls += ' fc-first';
15280 ret[4].cls += ' fc-prev-last';
15281 ret[5].cls += ' fc-last';
15288 cls: 'fc-border-separate',
15289 style : 'width:100%',
15297 cls : 'fc-first fc-last',
15315 cls : 'fc-content',
15316 style : "position: relative;",
15319 cls : 'fc-view fc-view-month fc-grid',
15320 style : 'position: relative',
15321 unselectable : 'on',
15324 cls : 'fc-event-container',
15325 style : 'position:absolute;z-index:8;top:0;left:0;'
15343 initEvents : function()
15346 throw "can not find store for calendar";
15352 style: "text-align:center",
15356 style: "background-color:white;width:50%;margin:250 auto",
15360 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
15371 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
15373 var size = this.el.select('.fc-content', true).first().getSize();
15374 this.maskEl.setSize(size.width, size.height);
15375 this.maskEl.enableDisplayMode("block");
15376 if(!this.loadMask){
15377 this.maskEl.hide();
15380 this.store = Roo.factory(this.store, Roo.data);
15381 this.store.on('load', this.onLoad, this);
15382 this.store.on('beforeload', this.onBeforeLoad, this);
15386 this.cells = this.el.select('.fc-day',true);
15387 //Roo.log(this.cells);
15388 this.textNodes = this.el.query('.fc-day-number');
15389 this.cells.addClassOnOver('fc-state-hover');
15391 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
15392 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
15393 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
15394 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
15396 this.on('monthchange', this.onMonthChange, this);
15398 this.update(new Date().clearTime());
15401 resize : function() {
15402 var sz = this.el.getSize();
15404 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
15405 this.el.select('.fc-day-content div',true).setHeight(34);
15410 showPrevMonth : function(e){
15411 this.update(this.activeDate.add("mo", -1));
15413 showToday : function(e){
15414 this.update(new Date().clearTime());
15417 showNextMonth : function(e){
15418 this.update(this.activeDate.add("mo", 1));
15422 showPrevYear : function(){
15423 this.update(this.activeDate.add("y", -1));
15427 showNextYear : function(){
15428 this.update(this.activeDate.add("y", 1));
15433 update : function(date)
15435 var vd = this.activeDate;
15436 this.activeDate = date;
15437 // if(vd && this.el){
15438 // var t = date.getTime();
15439 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
15440 // Roo.log('using add remove');
15442 // this.fireEvent('monthchange', this, date);
15444 // this.cells.removeClass("fc-state-highlight");
15445 // this.cells.each(function(c){
15446 // if(c.dateValue == t){
15447 // c.addClass("fc-state-highlight");
15448 // setTimeout(function(){
15449 // try{c.dom.firstChild.focus();}catch(e){}
15459 var days = date.getDaysInMonth();
15461 var firstOfMonth = date.getFirstDateOfMonth();
15462 var startingPos = firstOfMonth.getDay()-this.startDay;
15464 if(startingPos < this.startDay){
15468 var pm = date.add(Date.MONTH, -1);
15469 var prevStart = pm.getDaysInMonth()-startingPos;
15471 this.cells = this.el.select('.fc-day',true);
15472 this.textNodes = this.el.query('.fc-day-number');
15473 this.cells.addClassOnOver('fc-state-hover');
15475 var cells = this.cells.elements;
15476 var textEls = this.textNodes;
15478 Roo.each(cells, function(cell){
15479 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
15482 days += startingPos;
15484 // convert everything to numbers so it's fast
15485 var day = 86400000;
15486 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
15489 //Roo.log(prevStart);
15491 var today = new Date().clearTime().getTime();
15492 var sel = date.clearTime().getTime();
15493 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
15494 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
15495 var ddMatch = this.disabledDatesRE;
15496 var ddText = this.disabledDatesText;
15497 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
15498 var ddaysText = this.disabledDaysText;
15499 var format = this.format;
15501 var setCellClass = function(cal, cell){
15505 //Roo.log('set Cell Class');
15507 var t = d.getTime();
15511 cell.dateValue = t;
15513 cell.className += " fc-today";
15514 cell.className += " fc-state-highlight";
15515 cell.title = cal.todayText;
15518 // disable highlight in other month..
15519 //cell.className += " fc-state-highlight";
15524 cell.className = " fc-state-disabled";
15525 cell.title = cal.minText;
15529 cell.className = " fc-state-disabled";
15530 cell.title = cal.maxText;
15534 if(ddays.indexOf(d.getDay()) != -1){
15535 cell.title = ddaysText;
15536 cell.className = " fc-state-disabled";
15539 if(ddMatch && format){
15540 var fvalue = d.dateFormat(format);
15541 if(ddMatch.test(fvalue)){
15542 cell.title = ddText.replace("%0", fvalue);
15543 cell.className = " fc-state-disabled";
15547 if (!cell.initialClassName) {
15548 cell.initialClassName = cell.dom.className;
15551 cell.dom.className = cell.initialClassName + ' ' + cell.className;
15556 for(; i < startingPos; i++) {
15557 textEls[i].innerHTML = (++prevStart);
15558 d.setDate(d.getDate()+1);
15560 cells[i].className = "fc-past fc-other-month";
15561 setCellClass(this, cells[i]);
15566 for(; i < days; i++){
15567 intDay = i - startingPos + 1;
15568 textEls[i].innerHTML = (intDay);
15569 d.setDate(d.getDate()+1);
15571 cells[i].className = ''; // "x-date-active";
15572 setCellClass(this, cells[i]);
15576 for(; i < 42; i++) {
15577 textEls[i].innerHTML = (++extraDays);
15578 d.setDate(d.getDate()+1);
15580 cells[i].className = "fc-future fc-other-month";
15581 setCellClass(this, cells[i]);
15584 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
15586 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
15588 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
15589 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
15591 if(totalRows != 6){
15592 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
15593 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
15596 this.fireEvent('monthchange', this, date);
15600 if(!this.internalRender){
15601 var main = this.el.dom.firstChild;
15602 var w = main.offsetWidth;
15603 this.el.setWidth(w + this.el.getBorderWidth("lr"));
15604 Roo.fly(main).setWidth(w);
15605 this.internalRender = true;
15606 // opera does not respect the auto grow header center column
15607 // then, after it gets a width opera refuses to recalculate
15608 // without a second pass
15609 if(Roo.isOpera && !this.secondPass){
15610 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
15611 this.secondPass = true;
15612 this.update.defer(10, this, [date]);
15619 findCell : function(dt) {
15620 dt = dt.clearTime().getTime();
15622 this.cells.each(function(c){
15623 //Roo.log("check " +c.dateValue + '?=' + dt);
15624 if(c.dateValue == dt){
15634 findCells : function(ev) {
15635 var s = ev.start.clone().clearTime().getTime();
15637 var e= ev.end.clone().clearTime().getTime();
15640 this.cells.each(function(c){
15641 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
15643 if(c.dateValue > e){
15646 if(c.dateValue < s){
15655 // findBestRow: function(cells)
15659 // for (var i =0 ; i < cells.length;i++) {
15660 // ret = Math.max(cells[i].rows || 0,ret);
15667 addItem : function(ev)
15669 // look for vertical location slot in
15670 var cells = this.findCells(ev);
15672 // ev.row = this.findBestRow(cells);
15674 // work out the location.
15678 for(var i =0; i < cells.length; i++) {
15680 cells[i].row = cells[0].row;
15683 cells[i].row = cells[i].row + 1;
15693 if (crow.start.getY() == cells[i].getY()) {
15695 crow.end = cells[i];
15712 cells[0].events.push(ev);
15714 this.calevents.push(ev);
15717 clearEvents: function() {
15719 if(!this.calevents){
15723 Roo.each(this.cells.elements, function(c){
15729 Roo.each(this.calevents, function(e) {
15730 Roo.each(e.els, function(el) {
15731 el.un('mouseenter' ,this.onEventEnter, this);
15732 el.un('mouseleave' ,this.onEventLeave, this);
15737 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
15743 renderEvents: function()
15747 this.cells.each(function(c) {
15756 if(c.row != c.events.length){
15757 r = 4 - (4 - (c.row - c.events.length));
15760 c.events = ev.slice(0, r);
15761 c.more = ev.slice(r);
15763 if(c.more.length && c.more.length == 1){
15764 c.events.push(c.more.pop());
15767 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
15771 this.cells.each(function(c) {
15773 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
15776 for (var e = 0; e < c.events.length; e++){
15777 var ev = c.events[e];
15778 var rows = ev.rows;
15780 for(var i = 0; i < rows.length; i++) {
15782 // how many rows should it span..
15785 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
15786 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
15788 unselectable : "on",
15791 cls: 'fc-event-inner',
15795 // cls: 'fc-event-time',
15796 // html : cells.length > 1 ? '' : ev.time
15800 cls: 'fc-event-title',
15801 html : String.format('{0}', ev.title)
15808 cls: 'ui-resizable-handle ui-resizable-e',
15809 html : '  '
15816 cfg.cls += ' fc-event-start';
15818 if ((i+1) == rows.length) {
15819 cfg.cls += ' fc-event-end';
15822 var ctr = _this.el.select('.fc-event-container',true).first();
15823 var cg = ctr.createChild(cfg);
15825 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
15826 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
15828 var r = (c.more.length) ? 1 : 0;
15829 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
15830 cg.setWidth(ebox.right - sbox.x -2);
15832 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
15833 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
15834 cg.on('click', _this.onEventClick, _this, ev);
15845 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
15846 style : 'position: absolute',
15847 unselectable : "on",
15850 cls: 'fc-event-inner',
15854 cls: 'fc-event-title',
15862 cls: 'ui-resizable-handle ui-resizable-e',
15863 html : '  '
15869 var ctr = _this.el.select('.fc-event-container',true).first();
15870 var cg = ctr.createChild(cfg);
15872 var sbox = c.select('.fc-day-content',true).first().getBox();
15873 var ebox = c.select('.fc-day-content',true).first().getBox();
15875 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
15876 cg.setWidth(ebox.right - sbox.x -2);
15878 cg.on('click', _this.onMoreEventClick, _this, c.more);
15888 onEventEnter: function (e, el,event,d) {
15889 this.fireEvent('evententer', this, el, event);
15892 onEventLeave: function (e, el,event,d) {
15893 this.fireEvent('eventleave', this, el, event);
15896 onEventClick: function (e, el,event,d) {
15897 this.fireEvent('eventclick', this, el, event);
15900 onMonthChange: function () {
15904 onMoreEventClick: function(e, el, more)
15908 this.calpopover.placement = 'right';
15909 this.calpopover.setTitle('More');
15911 this.calpopover.setContent('');
15913 var ctr = this.calpopover.el.select('.popover-content', true).first();
15915 Roo.each(more, function(m){
15917 cls : 'fc-event-hori fc-event-draggable',
15920 var cg = ctr.createChild(cfg);
15922 cg.on('click', _this.onEventClick, _this, m);
15925 this.calpopover.show(el);
15930 onLoad: function ()
15932 this.calevents = [];
15935 if(this.store.getCount() > 0){
15936 this.store.data.each(function(d){
15939 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
15940 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
15941 time : d.data.start_time,
15942 title : d.data.title,
15943 description : d.data.description,
15944 venue : d.data.venue
15949 this.renderEvents();
15951 if(this.calevents.length && this.loadMask){
15952 this.maskEl.hide();
15956 onBeforeLoad: function()
15958 this.clearEvents();
15960 this.maskEl.show();
15974 * @class Roo.bootstrap.Popover
15975 * @extends Roo.bootstrap.Component
15976 * Bootstrap Popover class
15977 * @cfg {String} html contents of the popover (or false to use children..)
15978 * @cfg {String} title of popover (or false to hide)
15979 * @cfg {String} placement how it is placed
15980 * @cfg {String} trigger click || hover (or false to trigger manually)
15981 * @cfg {String} over what (parent or false to trigger manually.)
15982 * @cfg {Number} delay - delay before showing
15985 * Create a new Popover
15986 * @param {Object} config The config object
15989 Roo.bootstrap.Popover = function(config){
15990 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
15996 * After the popover show
15998 * @param {Roo.bootstrap.Popover} this
16003 * After the popover hide
16005 * @param {Roo.bootstrap.Popover} this
16011 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
16013 title: 'Fill in a title',
16016 placement : 'right',
16017 trigger : 'hover', // hover
16023 can_build_overlaid : false,
16025 getChildContainer : function()
16027 return this.el.select('.popover-content',true).first();
16030 getAutoCreate : function(){
16033 cls : 'popover roo-dynamic',
16034 style: 'display:block',
16040 cls : 'popover-inner',
16044 cls: 'popover-title',
16048 cls : 'popover-content',
16059 setTitle: function(str)
16062 this.el.select('.popover-title',true).first().dom.innerHTML = str;
16064 setContent: function(str)
16067 this.el.select('.popover-content',true).first().dom.innerHTML = str;
16069 // as it get's added to the bottom of the page.
16070 onRender : function(ct, position)
16072 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
16074 var cfg = Roo.apply({}, this.getAutoCreate());
16078 cfg.cls += ' ' + this.cls;
16081 cfg.style = this.style;
16083 //Roo.log("adding to ");
16084 this.el = Roo.get(document.body).createChild(cfg, position);
16085 // Roo.log(this.el);
16090 initEvents : function()
16092 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
16093 this.el.enableDisplayMode('block');
16095 if (this.over === false) {
16098 if (this.triggers === false) {
16101 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
16102 var triggers = this.trigger ? this.trigger.split(' ') : [];
16103 Roo.each(triggers, function(trigger) {
16105 if (trigger == 'click') {
16106 on_el.on('click', this.toggle, this);
16107 } else if (trigger != 'manual') {
16108 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
16109 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
16111 on_el.on(eventIn ,this.enter, this);
16112 on_el.on(eventOut, this.leave, this);
16123 toggle : function () {
16124 this.hoverState == 'in' ? this.leave() : this.enter();
16127 enter : function () {
16129 clearTimeout(this.timeout);
16131 this.hoverState = 'in';
16133 if (!this.delay || !this.delay.show) {
16138 this.timeout = setTimeout(function () {
16139 if (_t.hoverState == 'in') {
16142 }, this.delay.show)
16145 leave : function() {
16146 clearTimeout(this.timeout);
16148 this.hoverState = 'out';
16150 if (!this.delay || !this.delay.hide) {
16155 this.timeout = setTimeout(function () {
16156 if (_t.hoverState == 'out') {
16159 }, this.delay.hide)
16162 show : function (on_el)
16165 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
16169 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
16170 if (this.html !== false) {
16171 this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
16173 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
16174 if (!this.title.length) {
16175 this.el.select('.popover-title',true).hide();
16178 var placement = typeof this.placement == 'function' ?
16179 this.placement.call(this, this.el, on_el) :
16182 var autoToken = /\s?auto?\s?/i;
16183 var autoPlace = autoToken.test(placement);
16185 placement = placement.replace(autoToken, '') || 'top';
16189 //this.el.setXY([0,0]);
16191 this.el.dom.style.display='block';
16192 this.el.addClass(placement);
16194 //this.el.appendTo(on_el);
16196 var p = this.getPosition();
16197 var box = this.el.getBox();
16202 var align = Roo.bootstrap.Popover.alignment[placement];
16203 this.el.alignTo(on_el, align[0],align[1]);
16204 //var arrow = this.el.select('.arrow',true).first();
16205 //arrow.set(align[2],
16207 this.el.addClass('in');
16210 if (this.el.hasClass('fade')) {
16214 this.hoverState = 'in';
16216 this.fireEvent('show', this);
16221 this.el.setXY([0,0]);
16222 this.el.removeClass('in');
16224 this.hoverState = null;
16226 this.fireEvent('hide', this);
16231 Roo.bootstrap.Popover.alignment = {
16232 'left' : ['r-l', [-10,0], 'right'],
16233 'right' : ['l-r', [10,0], 'left'],
16234 'bottom' : ['t-b', [0,10], 'top'],
16235 'top' : [ 'b-t', [0,-10], 'bottom']
16246 * @class Roo.bootstrap.Progress
16247 * @extends Roo.bootstrap.Component
16248 * Bootstrap Progress class
16249 * @cfg {Boolean} striped striped of the progress bar
16250 * @cfg {Boolean} active animated of the progress bar
16254 * Create a new Progress
16255 * @param {Object} config The config object
16258 Roo.bootstrap.Progress = function(config){
16259 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
16262 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
16267 getAutoCreate : function(){
16275 cfg.cls += ' progress-striped';
16279 cfg.cls += ' active';
16298 * @class Roo.bootstrap.ProgressBar
16299 * @extends Roo.bootstrap.Component
16300 * Bootstrap ProgressBar class
16301 * @cfg {Number} aria_valuenow aria-value now
16302 * @cfg {Number} aria_valuemin aria-value min
16303 * @cfg {Number} aria_valuemax aria-value max
16304 * @cfg {String} label label for the progress bar
16305 * @cfg {String} panel (success | info | warning | danger )
16306 * @cfg {String} role role of the progress bar
16307 * @cfg {String} sr_only text
16311 * Create a new ProgressBar
16312 * @param {Object} config The config object
16315 Roo.bootstrap.ProgressBar = function(config){
16316 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
16319 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
16323 aria_valuemax : 100,
16329 getAutoCreate : function()
16334 cls: 'progress-bar',
16335 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
16347 cfg.role = this.role;
16350 if(this.aria_valuenow){
16351 cfg['aria-valuenow'] = this.aria_valuenow;
16354 if(this.aria_valuemin){
16355 cfg['aria-valuemin'] = this.aria_valuemin;
16358 if(this.aria_valuemax){
16359 cfg['aria-valuemax'] = this.aria_valuemax;
16362 if(this.label && !this.sr_only){
16363 cfg.html = this.label;
16367 cfg.cls += ' progress-bar-' + this.panel;
16373 update : function(aria_valuenow)
16375 this.aria_valuenow = aria_valuenow;
16377 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
16392 * @class Roo.bootstrap.TabGroup
16393 * @extends Roo.bootstrap.Column
16394 * Bootstrap Column class
16395 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
16396 * @cfg {Boolean} carousel true to make the group behave like a carousel
16397 * @cfg {Boolean} bullets show bullets for the panels
16398 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
16399 * @cfg {Boolean} slideOnTouch (true|false) slide on touch .. default false
16400 * @cfg {Number} timer auto slide timer .. default 0 millisecond
16403 * Create a new TabGroup
16404 * @param {Object} config The config object
16407 Roo.bootstrap.TabGroup = function(config){
16408 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
16410 this.navId = Roo.id();
16413 Roo.bootstrap.TabGroup.register(this);
16417 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
16420 transition : false,
16425 slideOnTouch : false,
16427 getAutoCreate : function()
16429 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
16431 cfg.cls += ' tab-content';
16433 if (this.carousel) {
16434 cfg.cls += ' carousel slide';
16437 cls : 'carousel-inner'
16440 if(this.bullets && !Roo.isTouch){
16443 cls : 'carousel-bullets',
16447 if(this.bullets_cls){
16448 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
16451 for (var i = 0; i < this.bullets; i++){
16453 cls : 'bullet bullet-' + i
16461 cfg.cn[0].cn = bullets;
16468 initEvents: function()
16470 if(Roo.isTouch && this.slideOnTouch){
16471 this.el.on("touchstart", this.onTouchStart, this);
16474 if(this.autoslide){
16477 this.slideFn = window.setInterval(function() {
16478 _this.showPanelNext();
16484 onTouchStart : function(e, el, o)
16486 if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
16490 this.showPanelNext();
16493 getChildContainer : function()
16495 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
16499 * register a Navigation item
16500 * @param {Roo.bootstrap.NavItem} the navitem to add
16502 register : function(item)
16504 this.tabs.push( item);
16505 item.navId = this.navId; // not really needed..
16510 getActivePanel : function()
16513 Roo.each(this.tabs, function(t) {
16523 getPanelByName : function(n)
16526 Roo.each(this.tabs, function(t) {
16527 if (t.tabId == n) {
16535 indexOfPanel : function(p)
16538 Roo.each(this.tabs, function(t,i) {
16539 if (t.tabId == p.tabId) {
16548 * show a specific panel
16549 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
16550 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
16552 showPanel : function (pan)
16554 if(this.transition || typeof(pan) == 'undefined'){
16555 Roo.log("waiting for the transitionend");
16559 if (typeof(pan) == 'number') {
16560 pan = this.tabs[pan];
16563 if (typeof(pan) == 'string') {
16564 pan = this.getPanelByName(pan);
16567 var cur = this.getActivePanel();
16570 Roo.log('pan or acitve pan is undefined');
16574 if (pan.tabId == this.getActivePanel().tabId) {
16578 if (false === cur.fireEvent('beforedeactivate')) {
16582 if(this.bullets > 0 && !Roo.isTouch){
16583 this.setActiveBullet(this.indexOfPanel(pan));
16586 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
16588 this.transition = true;
16589 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
16590 var lr = dir == 'next' ? 'left' : 'right';
16591 pan.el.addClass(dir); // or prev
16592 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
16593 cur.el.addClass(lr); // or right
16594 pan.el.addClass(lr);
16597 cur.el.on('transitionend', function() {
16598 Roo.log("trans end?");
16600 pan.el.removeClass([lr,dir]);
16601 pan.setActive(true);
16603 cur.el.removeClass([lr]);
16604 cur.setActive(false);
16606 _this.transition = false;
16608 }, this, { single: true } );
16613 cur.setActive(false);
16614 pan.setActive(true);
16619 showPanelNext : function()
16621 var i = this.indexOfPanel(this.getActivePanel());
16623 if (i >= this.tabs.length - 1 && !this.autoslide) {
16627 if (i >= this.tabs.length - 1 && this.autoslide) {
16631 this.showPanel(this.tabs[i+1]);
16634 showPanelPrev : function()
16636 var i = this.indexOfPanel(this.getActivePanel());
16638 if (i < 1 && !this.autoslide) {
16642 if (i < 1 && this.autoslide) {
16643 i = this.tabs.length;
16646 this.showPanel(this.tabs[i-1]);
16650 addBullet: function()
16652 if(!this.bullets || Roo.isTouch){
16655 var ctr = this.el.select('.carousel-bullets',true).first();
16656 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
16657 var bullet = ctr.createChild({
16658 cls : 'bullet bullet-' + i
16659 },ctr.dom.lastChild);
16664 bullet.on('click', (function(e, el, o, ii, t){
16666 e.preventDefault();
16668 this.showPanel(ii);
16670 if(this.autoslide && this.slideFn){
16671 clearInterval(this.slideFn);
16672 this.slideFn = window.setInterval(function() {
16673 _this.showPanelNext();
16677 }).createDelegate(this, [i, bullet], true));
16682 setActiveBullet : function(i)
16688 Roo.each(this.el.select('.bullet', true).elements, function(el){
16689 el.removeClass('selected');
16692 var bullet = this.el.select('.bullet-' + i, true).first();
16698 bullet.addClass('selected');
16709 Roo.apply(Roo.bootstrap.TabGroup, {
16713 * register a Navigation Group
16714 * @param {Roo.bootstrap.NavGroup} the navgroup to add
16716 register : function(navgrp)
16718 this.groups[navgrp.navId] = navgrp;
16722 * fetch a Navigation Group based on the navigation ID
16723 * if one does not exist , it will get created.
16724 * @param {string} the navgroup to add
16725 * @returns {Roo.bootstrap.NavGroup} the navgroup
16727 get: function(navId) {
16728 if (typeof(this.groups[navId]) == 'undefined') {
16729 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
16731 return this.groups[navId] ;
16746 * @class Roo.bootstrap.TabPanel
16747 * @extends Roo.bootstrap.Component
16748 * Bootstrap TabPanel class
16749 * @cfg {Boolean} active panel active
16750 * @cfg {String} html panel content
16751 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
16752 * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
16756 * Create a new TabPanel
16757 * @param {Object} config The config object
16760 Roo.bootstrap.TabPanel = function(config){
16761 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
16765 * Fires when the active status changes
16766 * @param {Roo.bootstrap.TabPanel} this
16767 * @param {Boolean} state the new state
16772 * @event beforedeactivate
16773 * Fires before a tab is de-activated - can be used to do validation on a form.
16774 * @param {Roo.bootstrap.TabPanel} this
16775 * @return {Boolean} false if there is an error
16778 'beforedeactivate': true
16781 this.tabId = this.tabId || Roo.id();
16785 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
16792 getAutoCreate : function(){
16795 // item is needed for carousel - not sure if it has any effect otherwise
16796 cls: 'tab-pane item',
16797 html: this.html || ''
16801 cfg.cls += ' active';
16805 cfg.tabId = this.tabId;
16812 initEvents: function()
16814 var p = this.parent();
16815 this.navId = this.navId || p.navId;
16817 if (typeof(this.navId) != 'undefined') {
16818 // not really needed.. but just in case.. parent should be a NavGroup.
16819 var tg = Roo.bootstrap.TabGroup.get(this.navId);
16823 var i = tg.tabs.length - 1;
16825 if(this.active && tg.bullets > 0 && i < tg.bullets){
16826 tg.setActiveBullet(i);
16833 onRender : function(ct, position)
16835 // Roo.log("Call onRender: " + this.xtype);
16837 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
16845 setActive: function(state)
16847 Roo.log("panel - set active " + this.tabId + "=" + state);
16849 this.active = state;
16851 this.el.removeClass('active');
16853 } else if (!this.el.hasClass('active')) {
16854 this.el.addClass('active');
16857 this.fireEvent('changed', this, state);
16874 * @class Roo.bootstrap.DateField
16875 * @extends Roo.bootstrap.Input
16876 * Bootstrap DateField class
16877 * @cfg {Number} weekStart default 0
16878 * @cfg {String} viewMode default empty, (months|years)
16879 * @cfg {String} minViewMode default empty, (months|years)
16880 * @cfg {Number} startDate default -Infinity
16881 * @cfg {Number} endDate default Infinity
16882 * @cfg {Boolean} todayHighlight default false
16883 * @cfg {Boolean} todayBtn default false
16884 * @cfg {Boolean} calendarWeeks default false
16885 * @cfg {Object} daysOfWeekDisabled default empty
16886 * @cfg {Boolean} singleMode default false (true | false)
16888 * @cfg {Boolean} keyboardNavigation default true
16889 * @cfg {String} language default en
16892 * Create a new DateField
16893 * @param {Object} config The config object
16896 Roo.bootstrap.DateField = function(config){
16897 Roo.bootstrap.DateField.superclass.constructor.call(this, config);
16901 * Fires when this field show.
16902 * @param {Roo.bootstrap.DateField} this
16903 * @param {Mixed} date The date value
16908 * Fires when this field hide.
16909 * @param {Roo.bootstrap.DateField} this
16910 * @param {Mixed} date The date value
16915 * Fires when select a date.
16916 * @param {Roo.bootstrap.DateField} this
16917 * @param {Mixed} date The date value
16921 * @event beforeselect
16922 * Fires when before select a date.
16923 * @param {Roo.bootstrap.DateField} this
16924 * @param {Mixed} date The date value
16926 beforeselect : true
16930 Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, {
16933 * @cfg {String} format
16934 * The default date format string which can be overriden for localization support. The format must be
16935 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
16939 * @cfg {String} altFormats
16940 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
16941 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
16943 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
16951 todayHighlight : false,
16957 keyboardNavigation: true,
16959 calendarWeeks: false,
16961 startDate: -Infinity,
16965 daysOfWeekDisabled: [],
16969 singleMode : false,
16971 UTCDate: function()
16973 return new Date(Date.UTC.apply(Date, arguments));
16976 UTCToday: function()
16978 var today = new Date();
16979 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
16982 getDate: function() {
16983 var d = this.getUTCDate();
16984 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
16987 getUTCDate: function() {
16991 setDate: function(d) {
16992 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
16995 setUTCDate: function(d) {
16997 this.setValue(this.formatDate(this.date));
17000 onRender: function(ct, position)
17003 Roo.bootstrap.DateField.superclass.onRender.call(this, ct, position);
17005 this.language = this.language || 'en';
17006 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
17007 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
17009 this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
17010 this.format = this.format || 'm/d/y';
17011 this.isInline = false;
17012 this.isInput = true;
17013 this.component = this.el.select('.add-on', true).first() || false;
17014 this.component = (this.component && this.component.length === 0) ? false : this.component;
17015 this.hasInput = this.component && this.inputEL().length;
17017 if (typeof(this.minViewMode === 'string')) {
17018 switch (this.minViewMode) {
17020 this.minViewMode = 1;
17023 this.minViewMode = 2;
17026 this.minViewMode = 0;
17031 if (typeof(this.viewMode === 'string')) {
17032 switch (this.viewMode) {
17045 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.DateField.template);
17047 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.DateField.template);
17049 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
17051 this.picker().on('mousedown', this.onMousedown, this);
17052 this.picker().on('click', this.onClick, this);
17054 this.picker().addClass('datepicker-dropdown');
17056 this.startViewMode = this.viewMode;
17058 if(this.singleMode){
17059 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
17060 v.setVisibilityMode(Roo.Element.DISPLAY);
17064 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
17065 v.setStyle('width', '189px');
17069 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
17070 if(!this.calendarWeeks){
17075 v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
17076 v.attr('colspan', function(i, val){
17077 return parseInt(val) + 1;
17082 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
17084 this.setStartDate(this.startDate);
17085 this.setEndDate(this.endDate);
17087 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
17094 if(this.isInline) {
17099 picker : function()
17101 return this.pickerEl;
17102 // return this.el.select('.datepicker', true).first();
17105 fillDow: function()
17107 var dowCnt = this.weekStart;
17116 if(this.calendarWeeks){
17124 while (dowCnt < this.weekStart + 7) {
17128 html: Roo.bootstrap.DateField.dates[this.language].daysMin[(dowCnt++)%7]
17132 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
17135 fillMonths: function()
17138 var months = this.picker().select('>.datepicker-months td', true).first();
17140 months.dom.innerHTML = '';
17146 html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
17149 months.createChild(month);
17156 this.date = (typeof(this.date) === 'undefined' || ((typeof(this.date) === 'string') && !this.date.length)) ? this.UTCToday() : (typeof(this.date) === 'string') ? this.parseDate(this.date) : this.date;
17158 if (this.date < this.startDate) {
17159 this.viewDate = new Date(this.startDate);
17160 } else if (this.date > this.endDate) {
17161 this.viewDate = new Date(this.endDate);
17163 this.viewDate = new Date(this.date);
17171 var d = new Date(this.viewDate),
17172 year = d.getUTCFullYear(),
17173 month = d.getUTCMonth(),
17174 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
17175 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
17176 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
17177 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
17178 currentDate = this.date && this.date.valueOf(),
17179 today = this.UTCToday();
17181 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].months[month]+' '+year;
17183 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
17185 // this.picker.select('>tfoot th.today').
17186 // .text(dates[this.language].today)
17187 // .toggle(this.todayBtn !== false);
17189 this.updateNavArrows();
17192 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
17194 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
17196 prevMonth.setUTCDate(day);
17198 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
17200 var nextMonth = new Date(prevMonth);
17202 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
17204 nextMonth = nextMonth.valueOf();
17206 var fillMonths = false;
17208 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
17210 while(prevMonth.valueOf() < nextMonth) {
17213 if (prevMonth.getUTCDay() === this.weekStart) {
17215 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
17223 if(this.calendarWeeks){
17224 // ISO 8601: First week contains first thursday.
17225 // ISO also states week starts on Monday, but we can be more abstract here.
17227 // Start of current week: based on weekstart/current date
17228 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
17229 // Thursday of this week
17230 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
17231 // First Thursday of year, year from thursday
17232 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
17233 // Calendar week: ms between thursdays, div ms per day, div 7 days
17234 calWeek = (th - yth) / 864e5 / 7 + 1;
17236 fillMonths.cn.push({
17244 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
17246 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
17249 if (this.todayHighlight &&
17250 prevMonth.getUTCFullYear() == today.getFullYear() &&
17251 prevMonth.getUTCMonth() == today.getMonth() &&
17252 prevMonth.getUTCDate() == today.getDate()) {
17253 clsName += ' today';
17256 if (currentDate && prevMonth.valueOf() === currentDate) {
17257 clsName += ' active';
17260 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
17261 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
17262 clsName += ' disabled';
17265 fillMonths.cn.push({
17267 cls: 'day ' + clsName,
17268 html: prevMonth.getDate()
17271 prevMonth.setDate(prevMonth.getDate()+1);
17274 var currentYear = this.date && this.date.getUTCFullYear();
17275 var currentMonth = this.date && this.date.getUTCMonth();
17277 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
17279 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
17280 v.removeClass('active');
17282 if(currentYear === year && k === currentMonth){
17283 v.addClass('active');
17286 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
17287 v.addClass('disabled');
17293 year = parseInt(year/10, 10) * 10;
17295 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
17297 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
17300 for (var i = -1; i < 11; i++) {
17301 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
17303 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
17311 showMode: function(dir)
17314 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
17317 Roo.each(this.picker().select('>div',true).elements, function(v){
17318 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
17321 this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
17326 if(this.isInline) {
17330 this.picker().removeClass(['bottom', 'top']);
17332 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
17334 * place to the top of element!
17338 this.picker().addClass('top');
17339 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
17344 this.picker().addClass('bottom');
17346 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
17349 parseDate : function(value)
17351 if(!value || value instanceof Date){
17354 var v = Date.parseDate(value, this.format);
17355 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
17356 v = Date.parseDate(value, 'Y-m-d');
17358 if(!v && this.altFormats){
17359 if(!this.altFormatsArray){
17360 this.altFormatsArray = this.altFormats.split("|");
17362 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
17363 v = Date.parseDate(value, this.altFormatsArray[i]);
17369 formatDate : function(date, fmt)
17371 return (!date || !(date instanceof Date)) ?
17372 date : date.dateFormat(fmt || this.format);
17375 onFocus : function()
17377 Roo.bootstrap.DateField.superclass.onFocus.call(this);
17381 onBlur : function()
17383 Roo.bootstrap.DateField.superclass.onBlur.call(this);
17385 var d = this.inputEl().getValue();
17394 this.picker().show();
17398 this.fireEvent('show', this, this.date);
17403 if(this.isInline) {
17406 this.picker().hide();
17407 this.viewMode = this.startViewMode;
17410 this.fireEvent('hide', this, this.date);
17414 onMousedown: function(e)
17416 e.stopPropagation();
17417 e.preventDefault();
17422 Roo.bootstrap.DateField.superclass.keyup.call(this);
17426 setValue: function(v)
17428 if(this.fireEvent('beforeselect', this, v) !== false){
17429 var d = new Date(this.parseDate(v) ).clearTime();
17431 if(isNaN(d.getTime())){
17432 this.date = this.viewDate = '';
17433 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
17437 v = this.formatDate(d);
17439 Roo.bootstrap.DateField.superclass.setValue.call(this, v);
17441 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
17445 this.fireEvent('select', this, this.date);
17449 getValue: function()
17451 return this.formatDate(this.date);
17454 fireKey: function(e)
17456 if (!this.picker().isVisible()){
17457 if (e.keyCode == 27) { // allow escape to hide and re-show picker
17463 var dateChanged = false,
17465 newDate, newViewDate;
17470 e.preventDefault();
17474 if (!this.keyboardNavigation) {
17477 dir = e.keyCode == 37 ? -1 : 1;
17480 newDate = this.moveYear(this.date, dir);
17481 newViewDate = this.moveYear(this.viewDate, dir);
17482 } else if (e.shiftKey){
17483 newDate = this.moveMonth(this.date, dir);
17484 newViewDate = this.moveMonth(this.viewDate, dir);
17486 newDate = new Date(this.date);
17487 newDate.setUTCDate(this.date.getUTCDate() + dir);
17488 newViewDate = new Date(this.viewDate);
17489 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
17491 if (this.dateWithinRange(newDate)){
17492 this.date = newDate;
17493 this.viewDate = newViewDate;
17494 this.setValue(this.formatDate(this.date));
17496 e.preventDefault();
17497 dateChanged = true;
17502 if (!this.keyboardNavigation) {
17505 dir = e.keyCode == 38 ? -1 : 1;
17507 newDate = this.moveYear(this.date, dir);
17508 newViewDate = this.moveYear(this.viewDate, dir);
17509 } else if (e.shiftKey){
17510 newDate = this.moveMonth(this.date, dir);
17511 newViewDate = this.moveMonth(this.viewDate, dir);
17513 newDate = new Date(this.date);
17514 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
17515 newViewDate = new Date(this.viewDate);
17516 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
17518 if (this.dateWithinRange(newDate)){
17519 this.date = newDate;
17520 this.viewDate = newViewDate;
17521 this.setValue(this.formatDate(this.date));
17523 e.preventDefault();
17524 dateChanged = true;
17528 this.setValue(this.formatDate(this.date));
17530 e.preventDefault();
17533 this.setValue(this.formatDate(this.date));
17547 onClick: function(e)
17549 e.stopPropagation();
17550 e.preventDefault();
17552 var target = e.getTarget();
17554 if(target.nodeName.toLowerCase() === 'i'){
17555 target = Roo.get(target).dom.parentNode;
17558 var nodeName = target.nodeName;
17559 var className = target.className;
17560 var html = target.innerHTML;
17561 //Roo.log(nodeName);
17563 switch(nodeName.toLowerCase()) {
17565 switch(className) {
17571 var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
17572 switch(this.viewMode){
17574 this.viewDate = this.moveMonth(this.viewDate, dir);
17578 this.viewDate = this.moveYear(this.viewDate, dir);
17584 var date = new Date();
17585 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
17587 this.setValue(this.formatDate(this.date));
17594 if (className.indexOf('disabled') < 0) {
17595 this.viewDate.setUTCDate(1);
17596 if (className.indexOf('month') > -1) {
17597 this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
17599 var year = parseInt(html, 10) || 0;
17600 this.viewDate.setUTCFullYear(year);
17604 if(this.singleMode){
17605 this.setValue(this.formatDate(this.viewDate));
17616 //Roo.log(className);
17617 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
17618 var day = parseInt(html, 10) || 1;
17619 var year = this.viewDate.getUTCFullYear(),
17620 month = this.viewDate.getUTCMonth();
17622 if (className.indexOf('old') > -1) {
17629 } else if (className.indexOf('new') > -1) {
17637 //Roo.log([year,month,day]);
17638 this.date = this.UTCDate(year, month, day,0,0,0,0);
17639 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
17641 //Roo.log(this.formatDate(this.date));
17642 this.setValue(this.formatDate(this.date));
17649 setStartDate: function(startDate)
17651 this.startDate = startDate || -Infinity;
17652 if (this.startDate !== -Infinity) {
17653 this.startDate = this.parseDate(this.startDate);
17656 this.updateNavArrows();
17659 setEndDate: function(endDate)
17661 this.endDate = endDate || Infinity;
17662 if (this.endDate !== Infinity) {
17663 this.endDate = this.parseDate(this.endDate);
17666 this.updateNavArrows();
17669 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
17671 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
17672 if (typeof(this.daysOfWeekDisabled) !== 'object') {
17673 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
17675 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
17676 return parseInt(d, 10);
17679 this.updateNavArrows();
17682 updateNavArrows: function()
17684 if(this.singleMode){
17688 var d = new Date(this.viewDate),
17689 year = d.getUTCFullYear(),
17690 month = d.getUTCMonth();
17692 Roo.each(this.picker().select('.prev', true).elements, function(v){
17694 switch (this.viewMode) {
17697 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
17703 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
17710 Roo.each(this.picker().select('.next', true).elements, function(v){
17712 switch (this.viewMode) {
17715 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
17721 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
17729 moveMonth: function(date, dir)
17734 var new_date = new Date(date.valueOf()),
17735 day = new_date.getUTCDate(),
17736 month = new_date.getUTCMonth(),
17737 mag = Math.abs(dir),
17739 dir = dir > 0 ? 1 : -1;
17742 // If going back one month, make sure month is not current month
17743 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
17745 return new_date.getUTCMonth() == month;
17747 // If going forward one month, make sure month is as expected
17748 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
17750 return new_date.getUTCMonth() != new_month;
17752 new_month = month + dir;
17753 new_date.setUTCMonth(new_month);
17754 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
17755 if (new_month < 0 || new_month > 11) {
17756 new_month = (new_month + 12) % 12;
17759 // For magnitudes >1, move one month at a time...
17760 for (var i=0; i<mag; i++) {
17761 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
17762 new_date = this.moveMonth(new_date, dir);
17764 // ...then reset the day, keeping it in the new month
17765 new_month = new_date.getUTCMonth();
17766 new_date.setUTCDate(day);
17768 return new_month != new_date.getUTCMonth();
17771 // Common date-resetting loop -- if date is beyond end of month, make it
17774 new_date.setUTCDate(--day);
17775 new_date.setUTCMonth(new_month);
17780 moveYear: function(date, dir)
17782 return this.moveMonth(date, dir*12);
17785 dateWithinRange: function(date)
17787 return date >= this.startDate && date <= this.endDate;
17793 this.picker().remove();
17798 Roo.apply(Roo.bootstrap.DateField, {
17809 html: '<i class="fa fa-arrow-left"/>'
17819 html: '<i class="fa fa-arrow-right"/>'
17861 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
17862 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
17863 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
17864 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
17865 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
17878 navFnc: 'FullYear',
17883 navFnc: 'FullYear',
17888 Roo.apply(Roo.bootstrap.DateField, {
17892 cls: 'datepicker dropdown-menu roo-dynamic',
17896 cls: 'datepicker-days',
17900 cls: 'table-condensed',
17902 Roo.bootstrap.DateField.head,
17906 Roo.bootstrap.DateField.footer
17913 cls: 'datepicker-months',
17917 cls: 'table-condensed',
17919 Roo.bootstrap.DateField.head,
17920 Roo.bootstrap.DateField.content,
17921 Roo.bootstrap.DateField.footer
17928 cls: 'datepicker-years',
17932 cls: 'table-condensed',
17934 Roo.bootstrap.DateField.head,
17935 Roo.bootstrap.DateField.content,
17936 Roo.bootstrap.DateField.footer
17955 * @class Roo.bootstrap.TimeField
17956 * @extends Roo.bootstrap.Input
17957 * Bootstrap DateField class
17961 * Create a new TimeField
17962 * @param {Object} config The config object
17965 Roo.bootstrap.TimeField = function(config){
17966 Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
17970 * Fires when this field show.
17971 * @param {Roo.bootstrap.DateField} thisthis
17972 * @param {Mixed} date The date value
17977 * Fires when this field hide.
17978 * @param {Roo.bootstrap.DateField} this
17979 * @param {Mixed} date The date value
17984 * Fires when select a date.
17985 * @param {Roo.bootstrap.DateField} this
17986 * @param {Mixed} date The date value
17992 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
17995 * @cfg {String} format
17996 * The default time format string which can be overriden for localization support. The format must be
17997 * valid according to {@link Date#parseDate} (defaults to 'H:i').
18001 onRender: function(ct, position)
18004 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
18006 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
18008 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18010 this.pop = this.picker().select('>.datepicker-time',true).first();
18011 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18013 this.picker().on('mousedown', this.onMousedown, this);
18014 this.picker().on('click', this.onClick, this);
18016 this.picker().addClass('datepicker-dropdown');
18021 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
18022 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
18023 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
18024 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
18025 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
18026 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
18030 fireKey: function(e){
18031 if (!this.picker().isVisible()){
18032 if (e.keyCode == 27) { // allow escape to hide and re-show picker
18038 e.preventDefault();
18046 this.onTogglePeriod();
18049 this.onIncrementMinutes();
18052 this.onDecrementMinutes();
18061 onClick: function(e) {
18062 e.stopPropagation();
18063 e.preventDefault();
18066 picker : function()
18068 return this.el.select('.datepicker', true).first();
18071 fillTime: function()
18073 var time = this.pop.select('tbody', true).first();
18075 time.dom.innerHTML = '';
18090 cls: 'hours-up glyphicon glyphicon-chevron-up'
18110 cls: 'minutes-up glyphicon glyphicon-chevron-up'
18131 cls: 'timepicker-hour',
18146 cls: 'timepicker-minute',
18161 cls: 'btn btn-primary period',
18183 cls: 'hours-down glyphicon glyphicon-chevron-down'
18203 cls: 'minutes-down glyphicon glyphicon-chevron-down'
18221 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
18228 var hours = this.time.getHours();
18229 var minutes = this.time.getMinutes();
18242 hours = hours - 12;
18246 hours = '0' + hours;
18250 minutes = '0' + minutes;
18253 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
18254 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
18255 this.pop.select('button', true).first().dom.innerHTML = period;
18261 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
18263 var cls = ['bottom'];
18265 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
18272 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
18277 this.picker().addClass(cls.join('-'));
18281 Roo.each(cls, function(c){
18283 _this.picker().setTop(_this.inputEl().getHeight());
18287 _this.picker().setTop(0 - _this.picker().getHeight());
18292 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
18296 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
18303 onFocus : function()
18305 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
18309 onBlur : function()
18311 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
18317 this.picker().show();
18322 this.fireEvent('show', this, this.date);
18327 this.picker().hide();
18330 this.fireEvent('hide', this, this.date);
18333 setTime : function()
18336 this.setValue(this.time.format(this.format));
18338 this.fireEvent('select', this, this.date);
18343 onMousedown: function(e){
18344 e.stopPropagation();
18345 e.preventDefault();
18348 onIncrementHours: function()
18350 Roo.log('onIncrementHours');
18351 this.time = this.time.add(Date.HOUR, 1);
18356 onDecrementHours: function()
18358 Roo.log('onDecrementHours');
18359 this.time = this.time.add(Date.HOUR, -1);
18363 onIncrementMinutes: function()
18365 Roo.log('onIncrementMinutes');
18366 this.time = this.time.add(Date.MINUTE, 1);
18370 onDecrementMinutes: function()
18372 Roo.log('onDecrementMinutes');
18373 this.time = this.time.add(Date.MINUTE, -1);
18377 onTogglePeriod: function()
18379 Roo.log('onTogglePeriod');
18380 this.time = this.time.add(Date.HOUR, 12);
18387 Roo.apply(Roo.bootstrap.TimeField, {
18417 cls: 'btn btn-info ok',
18429 Roo.apply(Roo.bootstrap.TimeField, {
18433 cls: 'datepicker dropdown-menu',
18437 cls: 'datepicker-time',
18441 cls: 'table-condensed',
18443 Roo.bootstrap.TimeField.content,
18444 Roo.bootstrap.TimeField.footer
18463 * @class Roo.bootstrap.MonthField
18464 * @extends Roo.bootstrap.Input
18465 * Bootstrap MonthField class
18467 * @cfg {String} language default en
18470 * Create a new MonthField
18471 * @param {Object} config The config object
18474 Roo.bootstrap.MonthField = function(config){
18475 Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
18480 * Fires when this field show.
18481 * @param {Roo.bootstrap.MonthField} this
18482 * @param {Mixed} date The date value
18487 * Fires when this field hide.
18488 * @param {Roo.bootstrap.MonthField} this
18489 * @param {Mixed} date The date value
18494 * Fires when select a date.
18495 * @param {Roo.bootstrap.MonthField} this
18496 * @param {String} oldvalue The old value
18497 * @param {String} newvalue The new value
18503 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
18505 onRender: function(ct, position)
18508 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
18510 this.language = this.language || 'en';
18511 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
18512 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
18514 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
18515 this.isInline = false;
18516 this.isInput = true;
18517 this.component = this.el.select('.add-on', true).first() || false;
18518 this.component = (this.component && this.component.length === 0) ? false : this.component;
18519 this.hasInput = this.component && this.inputEL().length;
18521 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
18523 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18525 this.picker().on('mousedown', this.onMousedown, this);
18526 this.picker().on('click', this.onClick, this);
18528 this.picker().addClass('datepicker-dropdown');
18530 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
18531 v.setStyle('width', '189px');
18538 if(this.isInline) {
18544 setValue: function(v, suppressEvent)
18546 var o = this.getValue();
18548 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
18552 if(suppressEvent !== true){
18553 this.fireEvent('select', this, o, v);
18558 getValue: function()
18563 onClick: function(e)
18565 e.stopPropagation();
18566 e.preventDefault();
18568 var target = e.getTarget();
18570 if(target.nodeName.toLowerCase() === 'i'){
18571 target = Roo.get(target).dom.parentNode;
18574 var nodeName = target.nodeName;
18575 var className = target.className;
18576 var html = target.innerHTML;
18578 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
18582 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
18584 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
18590 picker : function()
18592 return this.pickerEl;
18595 fillMonths: function()
18598 var months = this.picker().select('>.datepicker-months td', true).first();
18600 months.dom.innerHTML = '';
18606 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
18609 months.createChild(month);
18618 if(typeof(this.vIndex) == 'undefined' && this.value.length){
18619 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
18622 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
18623 e.removeClass('active');
18625 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
18626 e.addClass('active');
18633 if(this.isInline) {
18637 this.picker().removeClass(['bottom', 'top']);
18639 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
18641 * place to the top of element!
18645 this.picker().addClass('top');
18646 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
18651 this.picker().addClass('bottom');
18653 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
18656 onFocus : function()
18658 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
18662 onBlur : function()
18664 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
18666 var d = this.inputEl().getValue();
18675 this.picker().show();
18676 this.picker().select('>.datepicker-months', true).first().show();
18680 this.fireEvent('show', this, this.date);
18685 if(this.isInline) {
18688 this.picker().hide();
18689 this.fireEvent('hide', this, this.date);
18693 onMousedown: function(e)
18695 e.stopPropagation();
18696 e.preventDefault();
18701 Roo.bootstrap.MonthField.superclass.keyup.call(this);
18705 fireKey: function(e)
18707 if (!this.picker().isVisible()){
18708 if (e.keyCode == 27) {// allow escape to hide and re-show picker
18719 e.preventDefault();
18723 dir = e.keyCode == 37 ? -1 : 1;
18725 this.vIndex = this.vIndex + dir;
18727 if(this.vIndex < 0){
18731 if(this.vIndex > 11){
18735 if(isNaN(this.vIndex)){
18739 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
18745 dir = e.keyCode == 38 ? -1 : 1;
18747 this.vIndex = this.vIndex + dir * 4;
18749 if(this.vIndex < 0){
18753 if(this.vIndex > 11){
18757 if(isNaN(this.vIndex)){
18761 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
18766 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
18767 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
18771 e.preventDefault();
18774 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
18775 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
18791 this.picker().remove();
18796 Roo.apply(Roo.bootstrap.MonthField, {
18815 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
18816 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
18821 Roo.apply(Roo.bootstrap.MonthField, {
18825 cls: 'datepicker dropdown-menu roo-dynamic',
18829 cls: 'datepicker-months',
18833 cls: 'table-condensed',
18835 Roo.bootstrap.DateField.content
18855 * @class Roo.bootstrap.CheckBox
18856 * @extends Roo.bootstrap.Input
18857 * Bootstrap CheckBox class
18859 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
18860 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
18861 * @cfg {String} boxLabel The text that appears beside the checkbox
18862 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
18863 * @cfg {Boolean} checked initnal the element
18864 * @cfg {Boolean} inline inline the element (default false)
18865 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
18868 * Create a new CheckBox
18869 * @param {Object} config The config object
18872 Roo.bootstrap.CheckBox = function(config){
18873 Roo.bootstrap.CheckBox.superclass.constructor.call(this, config);
18878 * Fires when the element is checked or unchecked.
18879 * @param {Roo.bootstrap.CheckBox} this This input
18880 * @param {Boolean} checked The new checked value
18887 Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input, {
18889 inputType: 'checkbox',
18897 getAutoCreate : function()
18899 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
18905 cfg.cls = 'form-group ' + this.inputType; //input-group
18908 cfg.cls += ' ' + this.inputType + '-inline';
18914 type : this.inputType,
18915 value : this.inputType == 'radio' ? this.inputValue : ((!this.checked) ? this.valueOff : this.inputValue),
18916 cls : 'roo-' + this.inputType, //'form-box',
18917 placeholder : this.placeholder || ''
18921 if (this.weight) { // Validity check?
18922 cfg.cls += " " + this.inputType + "-" + this.weight;
18925 if (this.disabled) {
18926 input.disabled=true;
18930 input.checked = this.checked;
18934 input.name = this.name;
18938 input.cls += ' input-' + this.size;
18943 ['xs','sm','md','lg'].map(function(size){
18944 if (settings[size]) {
18945 cfg.cls += ' col-' + size + '-' + settings[size];
18949 var inputblock = input;
18951 if (this.before || this.after) {
18954 cls : 'input-group',
18959 inputblock.cn.push({
18961 cls : 'input-group-addon',
18966 inputblock.cn.push(input);
18969 inputblock.cn.push({
18971 cls : 'input-group-addon',
18978 if (align ==='left' && this.fieldLabel.length) {
18979 // Roo.log("left and has label");
18985 cls : 'control-label col-md-' + this.labelWidth,
18986 html : this.fieldLabel
18990 cls : "col-md-" + (12 - this.labelWidth),
18997 } else if ( this.fieldLabel.length) {
18998 // Roo.log(" label");
19002 tag: this.boxLabel ? 'span' : 'label',
19004 cls: 'control-label box-input-label',
19005 //cls : 'input-group-addon',
19006 html : this.fieldLabel
19016 // Roo.log(" no label && no align");
19017 cfg.cn = [ inputblock ] ;
19023 var boxLabelCfg = {
19025 //'for': id, // box label is handled by onclick - so no for...
19027 html: this.boxLabel
19031 boxLabelCfg.tooltip = this.tooltip;
19034 cfg.cn.push(boxLabelCfg);
19044 * return the real input element.
19046 inputEl: function ()
19048 return this.el.select('input.roo-' + this.inputType,true).first();
19051 labelEl: function()
19053 return this.el.select('label.control-label',true).first();
19055 /* depricated... */
19059 return this.labelEl();
19062 boxLabelEl: function()
19064 return this.el.select('label.box-label',true).first();
19067 initEvents : function()
19069 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
19071 this.inputEl().on('click', this.onClick, this);
19073 if (this.boxLabel) {
19074 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
19077 this.startValue = this.getValue();
19080 Roo.bootstrap.CheckBox.register(this);
19084 onClick : function()
19086 this.setChecked(!this.checked);
19089 setChecked : function(state,suppressEvent)
19091 this.startValue = this.getValue();
19093 if(this.inputType == 'radio'){
19095 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
19096 e.dom.checked = false;
19099 this.inputEl().dom.checked = true;
19101 this.inputEl().dom.value = this.inputValue;
19103 if(suppressEvent !== true){
19104 this.fireEvent('check', this, true);
19112 this.checked = state;
19114 this.inputEl().dom.checked = state;
19116 this.inputEl().dom.value = state ? this.inputValue : this.valueOff;
19118 if(suppressEvent !== true){
19119 this.fireEvent('check', this, state);
19125 getValue : function()
19127 if(this.inputType == 'radio'){
19128 return this.getGroupValue();
19131 return this.inputEl().getValue();
19135 getGroupValue : function()
19137 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
19141 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
19144 setValue : function(v,suppressEvent)
19146 if(this.inputType == 'radio'){
19147 this.setGroupValue(v, suppressEvent);
19151 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
19156 setGroupValue : function(v, suppressEvent)
19158 this.startValue = this.getValue();
19160 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
19161 e.dom.checked = false;
19163 if(e.dom.value == v){
19164 e.dom.checked = true;
19168 if(suppressEvent !== true){
19169 this.fireEvent('check', this, true);
19177 validate : function()
19181 (this.inputType == 'radio' && this.validateRadio()) ||
19182 (this.inputType == 'checkbox' && this.validateCheckbox())
19188 this.markInvalid();
19192 validateRadio : function()
19196 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
19197 if(!e.dom.checked){
19209 validateCheckbox : function()
19212 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
19215 var group = Roo.bootstrap.CheckBox.get(this.groupId);
19223 for(var i in group){
19228 r = (group[i].getValue() == group[i].inputValue) ? true : false;
19235 * Mark this field as valid
19237 markValid : function()
19239 if(this.allowBlank){
19245 this.fireEvent('valid', this);
19247 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
19250 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
19257 if(this.inputType == 'radio'){
19258 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
19259 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
19260 e.findParent('.form-group', false, true).addClass(_this.validClass);
19267 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
19268 this.el.findParent('.form-group', false, true).addClass(this.validClass);
19272 var group = Roo.bootstrap.CheckBox.get(this.groupId);
19278 for(var i in group){
19279 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
19280 group[i].el.findParent('.form-group', false, true).addClass(this.validClass);
19285 * Mark this field as invalid
19286 * @param {String} msg The validation message
19288 markInvalid : function(msg)
19290 if(this.allowBlank){
19296 this.fireEvent('invalid', this, msg);
19298 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
19301 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
19305 label.markInvalid();
19308 if(this.inputType == 'radio'){
19309 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
19310 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
19311 e.findParent('.form-group', false, true).addClass(_this.invalidClass);
19318 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
19319 this.el.findParent('.form-group', false, true).addClass(this.invalidClass);
19323 var group = Roo.bootstrap.CheckBox.get(this.groupId);
19329 for(var i in group){
19330 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
19331 group[i].el.findParent('.form-group', false, true).addClass(this.invalidClass);
19338 Roo.apply(Roo.bootstrap.CheckBox, {
19343 * register a CheckBox Group
19344 * @param {Roo.bootstrap.CheckBox} the CheckBox to add
19346 register : function(checkbox)
19348 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
19349 this.groups[checkbox.groupId] = {};
19352 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
19356 this.groups[checkbox.groupId][checkbox.name] = checkbox;
19360 * fetch a CheckBox Group based on the group ID
19361 * @param {string} the group ID
19362 * @returns {Roo.bootstrap.CheckBox} the CheckBox group
19364 get: function(groupId) {
19365 if (typeof(this.groups[groupId]) == 'undefined') {
19369 return this.groups[groupId] ;
19381 *<div class="radio">
19383 <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
19384 Option one is this and that—be sure to include why it's great
19391 *<label class="radio-inline">fieldLabel</label>
19392 *<label class="radio-inline">
19393 <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> 1
19401 * @class Roo.bootstrap.Radio
19402 * @extends Roo.bootstrap.CheckBox
19403 * Bootstrap Radio class
19406 * Create a new Radio
19407 * @param {Object} config The config object
19410 Roo.bootstrap.Radio = function(config){
19411 Roo.bootstrap.Radio.superclass.constructor.call(this, config);
19415 Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.CheckBox, {
19417 inputType: 'radio',
19421 getAutoCreate : function()
19423 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
19424 align = align || 'left'; // default...
19431 tag : this.inline ? 'span' : 'div',
19436 var inline = this.inline ? ' radio-inline' : '';
19440 // does not need for, as we wrap the input with it..
19442 cls : 'control-label box-label' + inline,
19445 var labelWidth = this.labelWidth ? this.labelWidth *1 : 100;
19449 //cls : 'control-label' + inline,
19450 html : this.fieldLabel,
19451 style : 'width:' + labelWidth + 'px;line-height:1;vertical-align:bottom;cursor:default;' // should be css really.
19460 type : this.inputType,
19461 //value : (!this.checked) ? this.valueOff : this.inputValue,
19462 value : this.inputValue,
19464 placeholder : this.placeholder || '' // ?? needed????
19467 if (this.weight) { // Validity check?
19468 input.cls += " radio-" + this.weight;
19470 if (this.disabled) {
19471 input.disabled=true;
19475 input.checked = this.checked;
19479 input.name = this.name;
19483 input.cls += ' input-' + this.size;
19486 //?? can span's inline have a width??
19489 ['xs','sm','md','lg'].map(function(size){
19490 if (settings[size]) {
19491 cfg.cls += ' col-' + size + '-' + settings[size];
19495 var inputblock = input;
19497 if (this.before || this.after) {
19500 cls : 'input-group',
19505 inputblock.cn.push({
19507 cls : 'input-group-addon',
19511 inputblock.cn.push(input);
19513 inputblock.cn.push({
19515 cls : 'input-group-addon',
19523 if (this.fieldLabel && this.fieldLabel.length) {
19524 cfg.cn.push(fieldLabel);
19527 // normal bootstrap puts the input inside the label.
19528 // however with our styled version - it has to go after the input.
19530 //lbl.cn.push(inputblock);
19534 cls: 'radio' + inline,
19541 cfg.cn.push( lblwrap);
19546 html: this.boxLabel
19555 initEvents : function()
19557 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
19559 this.inputEl().on('click', this.onClick, this);
19560 if (this.boxLabel) {
19561 //Roo.log('find label');
19562 this.el.select('span.radio label span',true).first().on('click', this.onClick, this);
19567 inputEl: function ()
19569 return this.el.select('input.roo-radio',true).first();
19571 onClick : function()
19574 this.setChecked(true);
19577 setChecked : function(state,suppressEvent)
19580 Roo.each(this.inputEl().up('form').select('input[name='+this.inputEl().dom.name+']', true).elements, function(v){
19581 v.dom.checked = false;
19584 Roo.log(this.inputEl().dom);
19585 this.checked = state;
19586 this.inputEl().dom.checked = state;
19588 if(suppressEvent !== true){
19589 this.fireEvent('check', this, state);
19592 //this.inputEl().dom.value = state ? this.inputValue : this.valueOff;
19596 getGroupValue : function()
19599 Roo.each(this.inputEl().up('form').select('input[name='+this.inputEl().dom.name+']', true).elements, function(v){
19600 if(v.dom.checked == true){
19601 value = v.dom.value;
19609 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
19610 * @return {Mixed} value The field value
19612 getValue : function(){
19613 return this.getGroupValue();
19619 //<script type="text/javascript">
19622 * Based Ext JS Library 1.1.1
19623 * Copyright(c) 2006-2007, Ext JS, LLC.
19629 * @class Roo.HtmlEditorCore
19630 * @extends Roo.Component
19631 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
19633 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
19636 Roo.HtmlEditorCore = function(config){
19639 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
19644 * @event initialize
19645 * Fires when the editor is fully initialized (including the iframe)
19646 * @param {Roo.HtmlEditorCore} this
19651 * Fires when the editor is first receives the focus. Any insertion must wait
19652 * until after this event.
19653 * @param {Roo.HtmlEditorCore} this
19657 * @event beforesync
19658 * Fires before the textarea is updated with content from the editor iframe. Return false
19659 * to cancel the sync.
19660 * @param {Roo.HtmlEditorCore} this
19661 * @param {String} html
19665 * @event beforepush
19666 * Fires before the iframe editor is updated with content from the textarea. Return false
19667 * to cancel the push.
19668 * @param {Roo.HtmlEditorCore} this
19669 * @param {String} html
19674 * Fires when the textarea is updated with content from the editor iframe.
19675 * @param {Roo.HtmlEditorCore} this
19676 * @param {String} html
19681 * Fires when the iframe editor is updated with content from the textarea.
19682 * @param {Roo.HtmlEditorCore} this
19683 * @param {String} html
19688 * @event editorevent
19689 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
19690 * @param {Roo.HtmlEditorCore} this
19696 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
19698 // defaults : white / black...
19699 this.applyBlacklists();
19706 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
19710 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
19716 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
19721 * @cfg {Number} height (in pixels)
19725 * @cfg {Number} width (in pixels)
19730 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
19733 stylesheets: false,
19738 // private properties
19739 validationEvent : false,
19741 initialized : false,
19743 sourceEditMode : false,
19744 onFocus : Roo.emptyFn,
19746 hideMode:'offsets',
19750 // blacklist + whitelisted elements..
19757 * Protected method that will not generally be called directly. It
19758 * is called when the editor initializes the iframe with HTML contents. Override this method if you
19759 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
19761 getDocMarkup : function(){
19765 // inherit styels from page...??
19766 if (this.stylesheets === false) {
19768 Roo.get(document.head).select('style').each(function(node) {
19769 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
19772 Roo.get(document.head).select('link').each(function(node) {
19773 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
19776 } else if (!this.stylesheets.length) {
19778 st = '<style type="text/css">' +
19779 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
19785 st += '<style type="text/css">' +
19786 'IMG { cursor: pointer } ' +
19790 return '<html><head>' + st +
19791 //<style type="text/css">' +
19792 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
19794 ' </head><body class="roo-htmleditor-body"></body></html>';
19798 onRender : function(ct, position)
19801 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
19802 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
19805 this.el.dom.style.border = '0 none';
19806 this.el.dom.setAttribute('tabIndex', -1);
19807 this.el.addClass('x-hidden hide');
19811 if(Roo.isIE){ // fix IE 1px bogus margin
19812 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
19816 this.frameId = Roo.id();
19820 var iframe = this.owner.wrap.createChild({
19822 cls: 'form-control', // bootstrap..
19824 name: this.frameId,
19825 frameBorder : 'no',
19826 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
19831 this.iframe = iframe.dom;
19833 this.assignDocWin();
19835 this.doc.designMode = 'on';
19838 this.doc.write(this.getDocMarkup());
19842 var task = { // must defer to wait for browser to be ready
19844 //console.log("run task?" + this.doc.readyState);
19845 this.assignDocWin();
19846 if(this.doc.body || this.doc.readyState == 'complete'){
19848 this.doc.designMode="on";
19852 Roo.TaskMgr.stop(task);
19853 this.initEditor.defer(10, this);
19860 Roo.TaskMgr.start(task);
19865 onResize : function(w, h)
19867 Roo.log('resize: ' +w + ',' + h );
19868 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
19872 if(typeof w == 'number'){
19874 this.iframe.style.width = w + 'px';
19876 if(typeof h == 'number'){
19878 this.iframe.style.height = h + 'px';
19880 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
19887 * Toggles the editor between standard and source edit mode.
19888 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
19890 toggleSourceEdit : function(sourceEditMode){
19892 this.sourceEditMode = sourceEditMode === true;
19894 if(this.sourceEditMode){
19896 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
19899 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
19900 //this.iframe.className = '';
19903 //this.setSize(this.owner.wrap.getSize());
19904 //this.fireEvent('editmodechange', this, this.sourceEditMode);
19911 * Protected method that will not generally be called directly. If you need/want
19912 * custom HTML cleanup, this is the method you should override.
19913 * @param {String} html The HTML to be cleaned
19914 * return {String} The cleaned HTML
19916 cleanHtml : function(html){
19917 html = String(html);
19918 if(html.length > 5){
19919 if(Roo.isSafari){ // strip safari nonsense
19920 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
19923 if(html == ' '){
19930 * HTML Editor -> Textarea
19931 * Protected method that will not generally be called directly. Syncs the contents
19932 * of the editor iframe with the textarea.
19934 syncValue : function(){
19935 if(this.initialized){
19936 var bd = (this.doc.body || this.doc.documentElement);
19937 //this.cleanUpPaste(); -- this is done else where and causes havoc..
19938 var html = bd.innerHTML;
19940 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
19941 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
19943 html = '<div style="'+m[0]+'">' + html + '</div>';
19946 html = this.cleanHtml(html);
19947 // fix up the special chars.. normaly like back quotes in word...
19948 // however we do not want to do this with chinese..
19949 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
19950 var cc = b.charCodeAt();
19952 (cc >= 0x4E00 && cc < 0xA000 ) ||
19953 (cc >= 0x3400 && cc < 0x4E00 ) ||
19954 (cc >= 0xf900 && cc < 0xfb00 )
19960 if(this.owner.fireEvent('beforesync', this, html) !== false){
19961 this.el.dom.value = html;
19962 this.owner.fireEvent('sync', this, html);
19968 * Protected method that will not generally be called directly. Pushes the value of the textarea
19969 * into the iframe editor.
19971 pushValue : function(){
19972 if(this.initialized){
19973 var v = this.el.dom.value.trim();
19975 // if(v.length < 1){
19979 if(this.owner.fireEvent('beforepush', this, v) !== false){
19980 var d = (this.doc.body || this.doc.documentElement);
19982 this.cleanUpPaste();
19983 this.el.dom.value = d.innerHTML;
19984 this.owner.fireEvent('push', this, v);
19990 deferFocus : function(){
19991 this.focus.defer(10, this);
19995 focus : function(){
19996 if(this.win && !this.sourceEditMode){
20003 assignDocWin: function()
20005 var iframe = this.iframe;
20008 this.doc = iframe.contentWindow.document;
20009 this.win = iframe.contentWindow;
20011 // if (!Roo.get(this.frameId)) {
20014 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
20015 // this.win = Roo.get(this.frameId).dom.contentWindow;
20017 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
20021 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
20022 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
20027 initEditor : function(){
20028 //console.log("INIT EDITOR");
20029 this.assignDocWin();
20033 this.doc.designMode="on";
20035 this.doc.write(this.getDocMarkup());
20038 var dbody = (this.doc.body || this.doc.documentElement);
20039 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
20040 // this copies styles from the containing element into thsi one..
20041 // not sure why we need all of this..
20042 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
20044 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
20045 //ss['background-attachment'] = 'fixed'; // w3c
20046 dbody.bgProperties = 'fixed'; // ie
20047 //Roo.DomHelper.applyStyles(dbody, ss);
20048 Roo.EventManager.on(this.doc, {
20049 //'mousedown': this.onEditorEvent,
20050 'mouseup': this.onEditorEvent,
20051 'dblclick': this.onEditorEvent,
20052 'click': this.onEditorEvent,
20053 'keyup': this.onEditorEvent,
20058 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
20060 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
20061 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
20063 this.initialized = true;
20065 this.owner.fireEvent('initialize', this);
20070 onDestroy : function(){
20076 //for (var i =0; i < this.toolbars.length;i++) {
20077 // // fixme - ask toolbars for heights?
20078 // this.toolbars[i].onDestroy();
20081 //this.wrap.dom.innerHTML = '';
20082 //this.wrap.remove();
20087 onFirstFocus : function(){
20089 this.assignDocWin();
20092 this.activated = true;
20095 if(Roo.isGecko){ // prevent silly gecko errors
20097 var s = this.win.getSelection();
20098 if(!s.focusNode || s.focusNode.nodeType != 3){
20099 var r = s.getRangeAt(0);
20100 r.selectNodeContents((this.doc.body || this.doc.documentElement));
20105 this.execCmd('useCSS', true);
20106 this.execCmd('styleWithCSS', false);
20109 this.owner.fireEvent('activate', this);
20113 adjustFont: function(btn){
20114 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
20115 //if(Roo.isSafari){ // safari
20118 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
20119 if(Roo.isSafari){ // safari
20120 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
20121 v = (v < 10) ? 10 : v;
20122 v = (v > 48) ? 48 : v;
20123 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
20128 v = Math.max(1, v+adjust);
20130 this.execCmd('FontSize', v );
20133 onEditorEvent : function(e)
20135 this.owner.fireEvent('editorevent', this, e);
20136 // this.updateToolbar();
20137 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
20140 insertTag : function(tg)
20142 // could be a bit smarter... -> wrap the current selected tRoo..
20143 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
20145 range = this.createRange(this.getSelection());
20146 var wrappingNode = this.doc.createElement(tg.toLowerCase());
20147 wrappingNode.appendChild(range.extractContents());
20148 range.insertNode(wrappingNode);
20155 this.execCmd("formatblock", tg);
20159 insertText : function(txt)
20163 var range = this.createRange();
20164 range.deleteContents();
20165 //alert(Sender.getAttribute('label'));
20167 range.insertNode(this.doc.createTextNode(txt));
20173 * Executes a Midas editor command on the editor document and performs necessary focus and
20174 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
20175 * @param {String} cmd The Midas command
20176 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
20178 relayCmd : function(cmd, value){
20180 this.execCmd(cmd, value);
20181 this.owner.fireEvent('editorevent', this);
20182 //this.updateToolbar();
20183 this.owner.deferFocus();
20187 * Executes a Midas editor command directly on the editor document.
20188 * For visual commands, you should use {@link #relayCmd} instead.
20189 * <b>This should only be called after the editor is initialized.</b>
20190 * @param {String} cmd The Midas command
20191 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
20193 execCmd : function(cmd, value){
20194 this.doc.execCommand(cmd, false, value === undefined ? null : value);
20201 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
20203 * @param {String} text | dom node..
20205 insertAtCursor : function(text)
20210 if(!this.activated){
20216 var r = this.doc.selection.createRange();
20227 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
20231 // from jquery ui (MIT licenced)
20233 var win = this.win;
20235 if (win.getSelection && win.getSelection().getRangeAt) {
20236 range = win.getSelection().getRangeAt(0);
20237 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
20238 range.insertNode(node);
20239 } else if (win.document.selection && win.document.selection.createRange) {
20240 // no firefox support
20241 var txt = typeof(text) == 'string' ? text : text.outerHTML;
20242 win.document.selection.createRange().pasteHTML(txt);
20244 // no firefox support
20245 var txt = typeof(text) == 'string' ? text : text.outerHTML;
20246 this.execCmd('InsertHTML', txt);
20255 mozKeyPress : function(e){
20257 var c = e.getCharCode(), cmd;
20260 c = String.fromCharCode(c).toLowerCase();
20274 this.cleanUpPaste.defer(100, this);
20282 e.preventDefault();
20290 fixKeys : function(){ // load time branching for fastest keydown performance
20292 return function(e){
20293 var k = e.getKey(), r;
20296 r = this.doc.selection.createRange();
20299 r.pasteHTML('    ');
20306 r = this.doc.selection.createRange();
20308 var target = r.parentElement();
20309 if(!target || target.tagName.toLowerCase() != 'li'){
20311 r.pasteHTML('<br />');
20317 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
20318 this.cleanUpPaste.defer(100, this);
20324 }else if(Roo.isOpera){
20325 return function(e){
20326 var k = e.getKey();
20330 this.execCmd('InsertHTML','    ');
20333 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
20334 this.cleanUpPaste.defer(100, this);
20339 }else if(Roo.isSafari){
20340 return function(e){
20341 var k = e.getKey();
20345 this.execCmd('InsertText','\t');
20349 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
20350 this.cleanUpPaste.defer(100, this);
20358 getAllAncestors: function()
20360 var p = this.getSelectedNode();
20363 a.push(p); // push blank onto stack..
20364 p = this.getParentElement();
20368 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
20372 a.push(this.doc.body);
20376 lastSelNode : false,
20379 getSelection : function()
20381 this.assignDocWin();
20382 return Roo.isIE ? this.doc.selection : this.win.getSelection();
20385 getSelectedNode: function()
20387 // this may only work on Gecko!!!
20389 // should we cache this!!!!
20394 var range = this.createRange(this.getSelection()).cloneRange();
20397 var parent = range.parentElement();
20399 var testRange = range.duplicate();
20400 testRange.moveToElementText(parent);
20401 if (testRange.inRange(range)) {
20404 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
20407 parent = parent.parentElement;
20412 // is ancestor a text element.
20413 var ac = range.commonAncestorContainer;
20414 if (ac.nodeType == 3) {
20415 ac = ac.parentNode;
20418 var ar = ac.childNodes;
20421 var other_nodes = [];
20422 var has_other_nodes = false;
20423 for (var i=0;i<ar.length;i++) {
20424 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
20427 // fullly contained node.
20429 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
20434 // probably selected..
20435 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
20436 other_nodes.push(ar[i]);
20440 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
20445 has_other_nodes = true;
20447 if (!nodes.length && other_nodes.length) {
20448 nodes= other_nodes;
20450 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
20456 createRange: function(sel)
20458 // this has strange effects when using with
20459 // top toolbar - not sure if it's a great idea.
20460 //this.editor.contentWindow.focus();
20461 if (typeof sel != "undefined") {
20463 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
20465 return this.doc.createRange();
20468 return this.doc.createRange();
20471 getParentElement: function()
20474 this.assignDocWin();
20475 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
20477 var range = this.createRange(sel);
20480 var p = range.commonAncestorContainer;
20481 while (p.nodeType == 3) { // text node
20492 * Range intersection.. the hard stuff...
20496 * [ -- selected range --- ]
20500 * if end is before start or hits it. fail.
20501 * if start is after end or hits it fail.
20503 * if either hits (but other is outside. - then it's not
20509 // @see http://www.thismuchiknow.co.uk/?p=64.
20510 rangeIntersectsNode : function(range, node)
20512 var nodeRange = node.ownerDocument.createRange();
20514 nodeRange.selectNode(node);
20516 nodeRange.selectNodeContents(node);
20519 var rangeStartRange = range.cloneRange();
20520 rangeStartRange.collapse(true);
20522 var rangeEndRange = range.cloneRange();
20523 rangeEndRange.collapse(false);
20525 var nodeStartRange = nodeRange.cloneRange();
20526 nodeStartRange.collapse(true);
20528 var nodeEndRange = nodeRange.cloneRange();
20529 nodeEndRange.collapse(false);
20531 return rangeStartRange.compareBoundaryPoints(
20532 Range.START_TO_START, nodeEndRange) == -1 &&
20533 rangeEndRange.compareBoundaryPoints(
20534 Range.START_TO_START, nodeStartRange) == 1;
20538 rangeCompareNode : function(range, node)
20540 var nodeRange = node.ownerDocument.createRange();
20542 nodeRange.selectNode(node);
20544 nodeRange.selectNodeContents(node);
20548 range.collapse(true);
20550 nodeRange.collapse(true);
20552 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
20553 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
20555 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
20557 var nodeIsBefore = ss == 1;
20558 var nodeIsAfter = ee == -1;
20560 if (nodeIsBefore && nodeIsAfter) {
20563 if (!nodeIsBefore && nodeIsAfter) {
20564 return 1; //right trailed.
20567 if (nodeIsBefore && !nodeIsAfter) {
20568 return 2; // left trailed.
20574 // private? - in a new class?
20575 cleanUpPaste : function()
20577 // cleans up the whole document..
20578 Roo.log('cleanuppaste');
20580 this.cleanUpChildren(this.doc.body);
20581 var clean = this.cleanWordChars(this.doc.body.innerHTML);
20582 if (clean != this.doc.body.innerHTML) {
20583 this.doc.body.innerHTML = clean;
20588 cleanWordChars : function(input) {// change the chars to hex code
20589 var he = Roo.HtmlEditorCore;
20591 var output = input;
20592 Roo.each(he.swapCodes, function(sw) {
20593 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
20595 output = output.replace(swapper, sw[1]);
20602 cleanUpChildren : function (n)
20604 if (!n.childNodes.length) {
20607 for (var i = n.childNodes.length-1; i > -1 ; i--) {
20608 this.cleanUpChild(n.childNodes[i]);
20615 cleanUpChild : function (node)
20618 //console.log(node);
20619 if (node.nodeName == "#text") {
20620 // clean up silly Windows -- stuff?
20623 if (node.nodeName == "#comment") {
20624 node.parentNode.removeChild(node);
20625 // clean up silly Windows -- stuff?
20628 var lcname = node.tagName.toLowerCase();
20629 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
20630 // whitelist of tags..
20632 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
20634 node.parentNode.removeChild(node);
20639 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
20641 // remove <a name=....> as rendering on yahoo mailer is borked with this.
20642 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
20644 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
20645 // remove_keep_children = true;
20648 if (remove_keep_children) {
20649 this.cleanUpChildren(node);
20650 // inserts everything just before this node...
20651 while (node.childNodes.length) {
20652 var cn = node.childNodes[0];
20653 node.removeChild(cn);
20654 node.parentNode.insertBefore(cn, node);
20656 node.parentNode.removeChild(node);
20660 if (!node.attributes || !node.attributes.length) {
20661 this.cleanUpChildren(node);
20665 function cleanAttr(n,v)
20668 if (v.match(/^\./) || v.match(/^\//)) {
20671 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/)) {
20674 if (v.match(/^#/)) {
20677 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
20678 node.removeAttribute(n);
20682 var cwhite = this.cwhite;
20683 var cblack = this.cblack;
20685 function cleanStyle(n,v)
20687 if (v.match(/expression/)) { //XSS?? should we even bother..
20688 node.removeAttribute(n);
20692 var parts = v.split(/;/);
20695 Roo.each(parts, function(p) {
20696 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
20700 var l = p.split(':').shift().replace(/\s+/g,'');
20701 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
20703 if ( cwhite.length && cblack.indexOf(l) > -1) {
20704 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
20705 //node.removeAttribute(n);
20709 // only allow 'c whitelisted system attributes'
20710 if ( cwhite.length && cwhite.indexOf(l) < 0) {
20711 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
20712 //node.removeAttribute(n);
20722 if (clean.length) {
20723 node.setAttribute(n, clean.join(';'));
20725 node.removeAttribute(n);
20731 for (var i = node.attributes.length-1; i > -1 ; i--) {
20732 var a = node.attributes[i];
20735 if (a.name.toLowerCase().substr(0,2)=='on') {
20736 node.removeAttribute(a.name);
20739 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
20740 node.removeAttribute(a.name);
20743 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
20744 cleanAttr(a.name,a.value); // fixme..
20747 if (a.name == 'style') {
20748 cleanStyle(a.name,a.value);
20751 /// clean up MS crap..
20752 // tecnically this should be a list of valid class'es..
20755 if (a.name == 'class') {
20756 if (a.value.match(/^Mso/)) {
20757 node.className = '';
20760 if (a.value.match(/body/)) {
20761 node.className = '';
20772 this.cleanUpChildren(node);
20778 * Clean up MS wordisms...
20780 cleanWord : function(node)
20785 this.cleanWord(this.doc.body);
20788 if (node.nodeName == "#text") {
20789 // clean up silly Windows -- stuff?
20792 if (node.nodeName == "#comment") {
20793 node.parentNode.removeChild(node);
20794 // clean up silly Windows -- stuff?
20798 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
20799 node.parentNode.removeChild(node);
20803 // remove - but keep children..
20804 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
20805 while (node.childNodes.length) {
20806 var cn = node.childNodes[0];
20807 node.removeChild(cn);
20808 node.parentNode.insertBefore(cn, node);
20810 node.parentNode.removeChild(node);
20811 this.iterateChildren(node, this.cleanWord);
20815 if (node.className.length) {
20817 var cn = node.className.split(/\W+/);
20819 Roo.each(cn, function(cls) {
20820 if (cls.match(/Mso[a-zA-Z]+/)) {
20825 node.className = cna.length ? cna.join(' ') : '';
20827 node.removeAttribute("class");
20831 if (node.hasAttribute("lang")) {
20832 node.removeAttribute("lang");
20835 if (node.hasAttribute("style")) {
20837 var styles = node.getAttribute("style").split(";");
20839 Roo.each(styles, function(s) {
20840 if (!s.match(/:/)) {
20843 var kv = s.split(":");
20844 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
20847 // what ever is left... we allow.
20850 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
20851 if (!nstyle.length) {
20852 node.removeAttribute('style');
20855 this.iterateChildren(node, this.cleanWord);
20861 * iterateChildren of a Node, calling fn each time, using this as the scole..
20862 * @param {DomNode} node node to iterate children of.
20863 * @param {Function} fn method of this class to call on each item.
20865 iterateChildren : function(node, fn)
20867 if (!node.childNodes.length) {
20870 for (var i = node.childNodes.length-1; i > -1 ; i--) {
20871 fn.call(this, node.childNodes[i])
20877 * cleanTableWidths.
20879 * Quite often pasting from word etc.. results in tables with column and widths.
20880 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
20883 cleanTableWidths : function(node)
20888 this.cleanTableWidths(this.doc.body);
20893 if (node.nodeName == "#text" || node.nodeName == "#comment") {
20896 Roo.log(node.tagName);
20897 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
20898 this.iterateChildren(node, this.cleanTableWidths);
20901 if (node.hasAttribute('width')) {
20902 node.removeAttribute('width');
20906 if (node.hasAttribute("style")) {
20909 var styles = node.getAttribute("style").split(";");
20911 Roo.each(styles, function(s) {
20912 if (!s.match(/:/)) {
20915 var kv = s.split(":");
20916 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
20919 // what ever is left... we allow.
20922 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
20923 if (!nstyle.length) {
20924 node.removeAttribute('style');
20928 this.iterateChildren(node, this.cleanTableWidths);
20936 domToHTML : function(currentElement, depth, nopadtext) {
20938 depth = depth || 0;
20939 nopadtext = nopadtext || false;
20941 if (!currentElement) {
20942 return this.domToHTML(this.doc.body);
20945 //Roo.log(currentElement);
20947 var allText = false;
20948 var nodeName = currentElement.nodeName;
20949 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
20951 if (nodeName == '#text') {
20953 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
20958 if (nodeName != 'BODY') {
20961 // Prints the node tagName, such as <A>, <IMG>, etc
20964 for(i = 0; i < currentElement.attributes.length;i++) {
20966 var aname = currentElement.attributes.item(i).name;
20967 if (!currentElement.attributes.item(i).value.length) {
20970 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
20973 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
20982 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
20985 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
20990 // Traverse the tree
20992 var currentElementChild = currentElement.childNodes.item(i);
20993 var allText = true;
20994 var innerHTML = '';
20996 while (currentElementChild) {
20997 // Formatting code (indent the tree so it looks nice on the screen)
20998 var nopad = nopadtext;
20999 if (lastnode == 'SPAN') {
21003 if (currentElementChild.nodeName == '#text') {
21004 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
21005 toadd = nopadtext ? toadd : toadd.trim();
21006 if (!nopad && toadd.length > 80) {
21007 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
21009 innerHTML += toadd;
21012 currentElementChild = currentElement.childNodes.item(i);
21018 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
21020 // Recursively traverse the tree structure of the child node
21021 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
21022 lastnode = currentElementChild.nodeName;
21024 currentElementChild=currentElement.childNodes.item(i);
21030 // The remaining code is mostly for formatting the tree
21031 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
21036 ret+= "</"+tagName+">";
21042 applyBlacklists : function()
21044 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
21045 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
21049 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
21050 if (b.indexOf(tag) > -1) {
21053 this.white.push(tag);
21057 Roo.each(w, function(tag) {
21058 if (b.indexOf(tag) > -1) {
21061 if (this.white.indexOf(tag) > -1) {
21064 this.white.push(tag);
21069 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
21070 if (w.indexOf(tag) > -1) {
21073 this.black.push(tag);
21077 Roo.each(b, function(tag) {
21078 if (w.indexOf(tag) > -1) {
21081 if (this.black.indexOf(tag) > -1) {
21084 this.black.push(tag);
21089 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
21090 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
21094 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
21095 if (b.indexOf(tag) > -1) {
21098 this.cwhite.push(tag);
21102 Roo.each(w, function(tag) {
21103 if (b.indexOf(tag) > -1) {
21106 if (this.cwhite.indexOf(tag) > -1) {
21109 this.cwhite.push(tag);
21114 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
21115 if (w.indexOf(tag) > -1) {
21118 this.cblack.push(tag);
21122 Roo.each(b, function(tag) {
21123 if (w.indexOf(tag) > -1) {
21126 if (this.cblack.indexOf(tag) > -1) {
21129 this.cblack.push(tag);
21134 setStylesheets : function(stylesheets)
21136 if(typeof(stylesheets) == 'string'){
21137 Roo.get(this.iframe.contentDocument.head).createChild({
21139 rel : 'stylesheet',
21148 Roo.each(stylesheets, function(s) {
21153 Roo.get(_this.iframe.contentDocument.head).createChild({
21155 rel : 'stylesheet',
21164 removeStylesheets : function()
21168 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
21173 // hide stuff that is not compatible
21187 * @event specialkey
21191 * @cfg {String} fieldClass @hide
21194 * @cfg {String} focusClass @hide
21197 * @cfg {String} autoCreate @hide
21200 * @cfg {String} inputType @hide
21203 * @cfg {String} invalidClass @hide
21206 * @cfg {String} invalidText @hide
21209 * @cfg {String} msgFx @hide
21212 * @cfg {String} validateOnBlur @hide
21216 Roo.HtmlEditorCore.white = [
21217 'area', 'br', 'img', 'input', 'hr', 'wbr',
21219 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
21220 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
21221 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
21222 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
21223 'table', 'ul', 'xmp',
21225 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
21228 'dir', 'menu', 'ol', 'ul', 'dl',
21234 Roo.HtmlEditorCore.black = [
21235 // 'embed', 'object', // enable - backend responsiblity to clean thiese
21237 'base', 'basefont', 'bgsound', 'blink', 'body',
21238 'frame', 'frameset', 'head', 'html', 'ilayer',
21239 'iframe', 'layer', 'link', 'meta', 'object',
21240 'script', 'style' ,'title', 'xml' // clean later..
21242 Roo.HtmlEditorCore.clean = [
21243 'script', 'style', 'title', 'xml'
21245 Roo.HtmlEditorCore.remove = [
21250 Roo.HtmlEditorCore.ablack = [
21254 Roo.HtmlEditorCore.aclean = [
21255 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
21259 Roo.HtmlEditorCore.pwhite= [
21260 'http', 'https', 'mailto'
21263 // white listed style attributes.
21264 Roo.HtmlEditorCore.cwhite= [
21265 // 'text-align', /// default is to allow most things..
21271 // black listed style attributes.
21272 Roo.HtmlEditorCore.cblack= [
21273 // 'font-size' -- this can be set by the project
21277 Roo.HtmlEditorCore.swapCodes =[
21296 * @class Roo.bootstrap.HtmlEditor
21297 * @extends Roo.bootstrap.TextArea
21298 * Bootstrap HtmlEditor class
21301 * Create a new HtmlEditor
21302 * @param {Object} config The config object
21305 Roo.bootstrap.HtmlEditor = function(config){
21306 Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
21307 if (!this.toolbars) {
21308 this.toolbars = [];
21310 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
21313 * @event initialize
21314 * Fires when the editor is fully initialized (including the iframe)
21315 * @param {HtmlEditor} this
21320 * Fires when the editor is first receives the focus. Any insertion must wait
21321 * until after this event.
21322 * @param {HtmlEditor} this
21326 * @event beforesync
21327 * Fires before the textarea is updated with content from the editor iframe. Return false
21328 * to cancel the sync.
21329 * @param {HtmlEditor} this
21330 * @param {String} html
21334 * @event beforepush
21335 * Fires before the iframe editor is updated with content from the textarea. Return false
21336 * to cancel the push.
21337 * @param {HtmlEditor} this
21338 * @param {String} html
21343 * Fires when the textarea is updated with content from the editor iframe.
21344 * @param {HtmlEditor} this
21345 * @param {String} html
21350 * Fires when the iframe editor is updated with content from the textarea.
21351 * @param {HtmlEditor} this
21352 * @param {String} html
21356 * @event editmodechange
21357 * Fires when the editor switches edit modes
21358 * @param {HtmlEditor} this
21359 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
21361 editmodechange: true,
21363 * @event editorevent
21364 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
21365 * @param {HtmlEditor} this
21369 * @event firstfocus
21370 * Fires when on first focus - needed by toolbars..
21371 * @param {HtmlEditor} this
21376 * Auto save the htmlEditor value as a file into Events
21377 * @param {HtmlEditor} this
21381 * @event savedpreview
21382 * preview the saved version of htmlEditor
21383 * @param {HtmlEditor} this
21390 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
21394 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
21399 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
21404 * @cfg {Number} height (in pixels)
21408 * @cfg {Number} width (in pixels)
21413 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
21416 stylesheets: false,
21421 // private properties
21422 validationEvent : false,
21424 initialized : false,
21427 onFocus : Roo.emptyFn,
21429 hideMode:'offsets',
21432 tbContainer : false,
21434 toolbarContainer :function() {
21435 return this.wrap.select('.x-html-editor-tb',true).first();
21439 * Protected method that will not generally be called directly. It
21440 * is called when the editor creates its toolbar. Override this method if you need to
21441 * add custom toolbar buttons.
21442 * @param {HtmlEditor} editor
21444 createToolbar : function(){
21446 Roo.log("create toolbars");
21448 this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
21449 this.toolbars[0].render(this.toolbarContainer());
21453 // if (!editor.toolbars || !editor.toolbars.length) {
21454 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
21457 // for (var i =0 ; i < editor.toolbars.length;i++) {
21458 // editor.toolbars[i] = Roo.factory(
21459 // typeof(editor.toolbars[i]) == 'string' ?
21460 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
21461 // Roo.bootstrap.HtmlEditor);
21462 // editor.toolbars[i].init(editor);
21468 onRender : function(ct, position)
21470 // Roo.log("Call onRender: " + this.xtype);
21472 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
21474 this.wrap = this.inputEl().wrap({
21475 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
21478 this.editorcore.onRender(ct, position);
21480 if (this.resizable) {
21481 this.resizeEl = new Roo.Resizable(this.wrap, {
21485 minHeight : this.height,
21486 height: this.height,
21487 handles : this.resizable,
21490 resize : function(r, w, h) {
21491 _t.onResize(w,h); // -something
21497 this.createToolbar(this);
21500 if(!this.width && this.resizable){
21501 this.setSize(this.wrap.getSize());
21503 if (this.resizeEl) {
21504 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
21505 // should trigger onReize..
21511 onResize : function(w, h)
21513 Roo.log('resize: ' +w + ',' + h );
21514 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
21518 if(this.inputEl() ){
21519 if(typeof w == 'number'){
21520 var aw = w - this.wrap.getFrameWidth('lr');
21521 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
21524 if(typeof h == 'number'){
21525 var tbh = -11; // fixme it needs to tool bar size!
21526 for (var i =0; i < this.toolbars.length;i++) {
21527 // fixme - ask toolbars for heights?
21528 tbh += this.toolbars[i].el.getHeight();
21529 //if (this.toolbars[i].footer) {
21530 // tbh += this.toolbars[i].footer.el.getHeight();
21538 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
21539 ah -= 5; // knock a few pixes off for look..
21540 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
21544 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
21545 this.editorcore.onResize(ew,eh);
21550 * Toggles the editor between standard and source edit mode.
21551 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21553 toggleSourceEdit : function(sourceEditMode)
21555 this.editorcore.toggleSourceEdit(sourceEditMode);
21557 if(this.editorcore.sourceEditMode){
21558 Roo.log('editor - showing textarea');
21561 // Roo.log(this.syncValue());
21563 this.inputEl().removeClass(['hide', 'x-hidden']);
21564 this.inputEl().dom.removeAttribute('tabIndex');
21565 this.inputEl().focus();
21567 Roo.log('editor - hiding textarea');
21569 // Roo.log(this.pushValue());
21572 this.inputEl().addClass(['hide', 'x-hidden']);
21573 this.inputEl().dom.setAttribute('tabIndex', -1);
21574 //this.deferFocus();
21577 if(this.resizable){
21578 this.setSize(this.wrap.getSize());
21581 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
21584 // private (for BoxComponent)
21585 adjustSize : Roo.BoxComponent.prototype.adjustSize,
21587 // private (for BoxComponent)
21588 getResizeEl : function(){
21592 // private (for BoxComponent)
21593 getPositionEl : function(){
21598 initEvents : function(){
21599 this.originalValue = this.getValue();
21603 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
21606 // markInvalid : Roo.emptyFn,
21608 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
21611 // clearInvalid : Roo.emptyFn,
21613 setValue : function(v){
21614 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
21615 this.editorcore.pushValue();
21620 deferFocus : function(){
21621 this.focus.defer(10, this);
21625 focus : function(){
21626 this.editorcore.focus();
21632 onDestroy : function(){
21638 for (var i =0; i < this.toolbars.length;i++) {
21639 // fixme - ask toolbars for heights?
21640 this.toolbars[i].onDestroy();
21643 this.wrap.dom.innerHTML = '';
21644 this.wrap.remove();
21649 onFirstFocus : function(){
21650 //Roo.log("onFirstFocus");
21651 this.editorcore.onFirstFocus();
21652 for (var i =0; i < this.toolbars.length;i++) {
21653 this.toolbars[i].onFirstFocus();
21659 syncValue : function()
21661 this.editorcore.syncValue();
21664 pushValue : function()
21666 this.editorcore.pushValue();
21670 // hide stuff that is not compatible
21684 * @event specialkey
21688 * @cfg {String} fieldClass @hide
21691 * @cfg {String} focusClass @hide
21694 * @cfg {String} autoCreate @hide
21697 * @cfg {String} inputType @hide
21700 * @cfg {String} invalidClass @hide
21703 * @cfg {String} invalidText @hide
21706 * @cfg {String} msgFx @hide
21709 * @cfg {String} validateOnBlur @hide
21718 Roo.namespace('Roo.bootstrap.htmleditor');
21720 * @class Roo.bootstrap.HtmlEditorToolbar1
21725 new Roo.bootstrap.HtmlEditor({
21728 new Roo.bootstrap.HtmlEditorToolbar1({
21729 disable : { fonts: 1 , format: 1, ..., ... , ...],
21735 * @cfg {Object} disable List of elements to disable..
21736 * @cfg {Array} btns List of additional buttons.
21740 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
21743 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
21746 Roo.apply(this, config);
21748 // default disabled, based on 'good practice'..
21749 this.disable = this.disable || {};
21750 Roo.applyIf(this.disable, {
21753 specialElements : true
21755 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
21757 this.editor = config.editor;
21758 this.editorcore = config.editor.editorcore;
21760 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
21762 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
21763 // dont call parent... till later.
21765 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.NavSimplebar, {
21770 editorcore : false,
21775 "h1","h2","h3","h4","h5","h6",
21777 "abbr", "acronym", "address", "cite", "samp", "var",
21781 onRender : function(ct, position)
21783 // Roo.log("Call onRender: " + this.xtype);
21785 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
21787 this.el.dom.style.marginBottom = '0';
21789 var editorcore = this.editorcore;
21790 var editor= this.editor;
21793 var btn = function(id,cmd , toggle, handler){
21795 var event = toggle ? 'toggle' : 'click';
21800 xns: Roo.bootstrap,
21803 enableToggle:toggle !== false,
21805 pressed : toggle ? false : null,
21808 a.listeners[toggle ? 'toggle' : 'click'] = function() {
21809 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
21818 xns: Roo.bootstrap,
21819 glyphicon : 'font',
21823 xns: Roo.bootstrap,
21827 Roo.each(this.formats, function(f) {
21828 style.menu.items.push({
21830 xns: Roo.bootstrap,
21831 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
21836 editorcore.insertTag(this.tagname);
21843 children.push(style);
21846 btn('bold',false,true);
21847 btn('italic',false,true);
21848 btn('align-left', 'justifyleft',true);
21849 btn('align-center', 'justifycenter',true);
21850 btn('align-right' , 'justifyright',true);
21851 btn('link', false, false, function(btn) {
21852 //Roo.log("create link?");
21853 var url = prompt(this.createLinkText, this.defaultLinkValue);
21854 if(url && url != 'http:/'+'/'){
21855 this.editorcore.relayCmd('createlink', url);
21858 btn('list','insertunorderedlist',true);
21859 btn('pencil', false,true, function(btn){
21862 this.toggleSourceEdit(btn.pressed);
21868 xns: Roo.bootstrap,
21873 xns: Roo.bootstrap,
21878 cog.menu.items.push({
21880 xns: Roo.bootstrap,
21881 html : Clean styles,
21886 editorcore.insertTag(this.tagname);
21895 this.xtype = 'NavSimplebar';
21897 for(var i=0;i< children.length;i++) {
21899 this.buttons.add(this.addxtypeChild(children[i]));
21903 editor.on('editorevent', this.updateToolbar, this);
21905 onBtnClick : function(id)
21907 this.editorcore.relayCmd(id);
21908 this.editorcore.focus();
21912 * Protected method that will not generally be called directly. It triggers
21913 * a toolbar update by reading the markup state of the current selection in the editor.
21915 updateToolbar: function(){
21917 if(!this.editorcore.activated){
21918 this.editor.onFirstFocus(); // is this neeed?
21922 var btns = this.buttons;
21923 var doc = this.editorcore.doc;
21924 btns.get('bold').setActive(doc.queryCommandState('bold'));
21925 btns.get('italic').setActive(doc.queryCommandState('italic'));
21926 //btns.get('underline').setActive(doc.queryCommandState('underline'));
21928 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
21929 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
21930 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
21932 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
21933 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
21936 var ans = this.editorcore.getAllAncestors();
21937 if (this.formatCombo) {
21940 var store = this.formatCombo.store;
21941 this.formatCombo.setValue("");
21942 for (var i =0; i < ans.length;i++) {
21943 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
21945 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
21953 // hides menus... - so this cant be on a menu...
21954 Roo.bootstrap.MenuMgr.hideAll();
21956 Roo.bootstrap.MenuMgr.hideAll();
21957 //this.editorsyncValue();
21959 onFirstFocus: function() {
21960 this.buttons.each(function(item){
21964 toggleSourceEdit : function(sourceEditMode){
21967 if(sourceEditMode){
21968 Roo.log("disabling buttons");
21969 this.buttons.each( function(item){
21970 if(item.cmd != 'pencil'){
21976 Roo.log("enabling buttons");
21977 if(this.editorcore.initialized){
21978 this.buttons.each( function(item){
21984 Roo.log("calling toggole on editor");
21985 // tell the editor that it's been pressed..
21986 this.editor.toggleSourceEdit(sourceEditMode);
21996 * @class Roo.bootstrap.Table.AbstractSelectionModel
21997 * @extends Roo.util.Observable
21998 * Abstract base class for grid SelectionModels. It provides the interface that should be
21999 * implemented by descendant classes. This class should not be directly instantiated.
22002 Roo.bootstrap.Table.AbstractSelectionModel = function(){
22003 this.locked = false;
22004 Roo.bootstrap.Table.AbstractSelectionModel.superclass.constructor.call(this);
22008 Roo.extend(Roo.bootstrap.Table.AbstractSelectionModel, Roo.util.Observable, {
22009 /** @ignore Called by the grid automatically. Do not call directly. */
22010 init : function(grid){
22016 * Locks the selections.
22019 this.locked = true;
22023 * Unlocks the selections.
22025 unlock : function(){
22026 this.locked = false;
22030 * Returns true if the selections are locked.
22031 * @return {Boolean}
22033 isLocked : function(){
22034 return this.locked;
22038 * @extends Roo.bootstrap.Table.AbstractSelectionModel
22039 * @class Roo.bootstrap.Table.RowSelectionModel
22040 * The default SelectionModel used by {@link Roo.bootstrap.Table}.
22041 * It supports multiple selections and keyboard selection/navigation.
22043 * @param {Object} config
22046 Roo.bootstrap.Table.RowSelectionModel = function(config){
22047 Roo.apply(this, config);
22048 this.selections = new Roo.util.MixedCollection(false, function(o){
22053 this.lastActive = false;
22057 * @event selectionchange
22058 * Fires when the selection changes
22059 * @param {SelectionModel} this
22061 "selectionchange" : true,
22063 * @event afterselectionchange
22064 * Fires after the selection changes (eg. by key press or clicking)
22065 * @param {SelectionModel} this
22067 "afterselectionchange" : true,
22069 * @event beforerowselect
22070 * Fires when a row is selected being selected, return false to cancel.
22071 * @param {SelectionModel} this
22072 * @param {Number} rowIndex The selected index
22073 * @param {Boolean} keepExisting False if other selections will be cleared
22075 "beforerowselect" : true,
22078 * Fires when a row is selected.
22079 * @param {SelectionModel} this
22080 * @param {Number} rowIndex The selected index
22081 * @param {Roo.data.Record} r The record
22083 "rowselect" : true,
22085 * @event rowdeselect
22086 * Fires when a row is deselected.
22087 * @param {SelectionModel} this
22088 * @param {Number} rowIndex The selected index
22090 "rowdeselect" : true
22092 Roo.bootstrap.Table.RowSelectionModel.superclass.constructor.call(this);
22093 this.locked = false;
22096 Roo.extend(Roo.bootstrap.Table.RowSelectionModel, Roo.bootstrap.Table.AbstractSelectionModel, {
22098 * @cfg {Boolean} singleSelect
22099 * True to allow selection of only one row at a time (defaults to false)
22101 singleSelect : false,
22104 initEvents : function(){
22106 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
22107 this.grid.on("mousedown", this.handleMouseDown, this);
22108 }else{ // allow click to work like normal
22109 this.grid.on("rowclick", this.handleDragableRowClick, this);
22112 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
22113 "up" : function(e){
22115 this.selectPrevious(e.shiftKey);
22116 }else if(this.last !== false && this.lastActive !== false){
22117 var last = this.last;
22118 this.selectRange(this.last, this.lastActive-1);
22119 this.grid.getView().focusRow(this.lastActive);
22120 if(last !== false){
22124 this.selectFirstRow();
22126 this.fireEvent("afterselectionchange", this);
22128 "down" : function(e){
22130 this.selectNext(e.shiftKey);
22131 }else if(this.last !== false && this.lastActive !== false){
22132 var last = this.last;
22133 this.selectRange(this.last, this.lastActive+1);
22134 this.grid.getView().focusRow(this.lastActive);
22135 if(last !== false){
22139 this.selectFirstRow();
22141 this.fireEvent("afterselectionchange", this);
22146 var view = this.grid.view;
22147 view.on("refresh", this.onRefresh, this);
22148 view.on("rowupdated", this.onRowUpdated, this);
22149 view.on("rowremoved", this.onRemove, this);
22153 onRefresh : function(){
22154 var ds = this.grid.dataSource, i, v = this.grid.view;
22155 var s = this.selections;
22156 s.each(function(r){
22157 if((i = ds.indexOfId(r.id)) != -1){
22166 onRemove : function(v, index, r){
22167 this.selections.remove(r);
22171 onRowUpdated : function(v, index, r){
22172 if(this.isSelected(r)){
22173 v.onRowSelect(index);
22179 * @param {Array} records The records to select
22180 * @param {Boolean} keepExisting (optional) True to keep existing selections
22182 selectRecords : function(records, keepExisting){
22184 this.clearSelections();
22186 var ds = this.grid.dataSource;
22187 for(var i = 0, len = records.length; i < len; i++){
22188 this.selectRow(ds.indexOf(records[i]), true);
22193 * Gets the number of selected rows.
22196 getCount : function(){
22197 return this.selections.length;
22201 * Selects the first row in the grid.
22203 selectFirstRow : function(){
22208 * Select the last row.
22209 * @param {Boolean} keepExisting (optional) True to keep existing selections
22211 selectLastRow : function(keepExisting){
22212 this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
22216 * Selects the row immediately following the last selected row.
22217 * @param {Boolean} keepExisting (optional) True to keep existing selections
22219 selectNext : function(keepExisting){
22220 if(this.last !== false && (this.last+1) < this.grid.dataSource.getCount()){
22221 this.selectRow(this.last+1, keepExisting);
22222 this.grid.getView().focusRow(this.last);
22227 * Selects the row that precedes the last selected row.
22228 * @param {Boolean} keepExisting (optional) True to keep existing selections
22230 selectPrevious : function(keepExisting){
22232 this.selectRow(this.last-1, keepExisting);
22233 this.grid.getView().focusRow(this.last);
22238 * Returns the selected records
22239 * @return {Array} Array of selected records
22241 getSelections : function(){
22242 return [].concat(this.selections.items);
22246 * Returns the first selected record.
22249 getSelected : function(){
22250 return this.selections.itemAt(0);
22255 * Clears all selections.
22257 clearSelections : function(fast){
22262 var ds = this.grid.dataSource;
22263 var s = this.selections;
22264 s.each(function(r){
22265 this.deselectRow(ds.indexOfId(r.id));
22269 this.selections.clear();
22276 * Selects all rows.
22278 selectAll : function(){
22282 this.selections.clear();
22283 for(var i = 0, len = this.grid.dataSource.getCount(); i < len; i++){
22284 this.selectRow(i, true);
22289 * Returns True if there is a selection.
22290 * @return {Boolean}
22292 hasSelection : function(){
22293 return this.selections.length > 0;
22297 * Returns True if the specified row is selected.
22298 * @param {Number/Record} record The record or index of the record to check
22299 * @return {Boolean}
22301 isSelected : function(index){
22302 var r = typeof index == "number" ? this.grid.dataSource.getAt(index) : index;
22303 return (r && this.selections.key(r.id) ? true : false);
22307 * Returns True if the specified record id is selected.
22308 * @param {String} id The id of record to check
22309 * @return {Boolean}
22311 isIdSelected : function(id){
22312 return (this.selections.key(id) ? true : false);
22316 handleMouseDown : function(e, t){
22317 var view = this.grid.getView(), rowIndex;
22318 if(this.isLocked() || (rowIndex = view.findRowIndex(t)) === false){
22321 if(e.shiftKey && this.last !== false){
22322 var last = this.last;
22323 this.selectRange(last, rowIndex, e.ctrlKey);
22324 this.last = last; // reset the last
22325 view.focusRow(rowIndex);
22327 var isSelected = this.isSelected(rowIndex);
22328 if(e.button !== 0 && isSelected){
22329 view.focusRow(rowIndex);
22330 }else if(e.ctrlKey && isSelected){
22331 this.deselectRow(rowIndex);
22332 }else if(!isSelected){
22333 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
22334 view.focusRow(rowIndex);
22337 this.fireEvent("afterselectionchange", this);
22340 handleDragableRowClick : function(grid, rowIndex, e)
22342 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
22343 this.selectRow(rowIndex, false);
22344 grid.view.focusRow(rowIndex);
22345 this.fireEvent("afterselectionchange", this);
22350 * Selects multiple rows.
22351 * @param {Array} rows Array of the indexes of the row to select
22352 * @param {Boolean} keepExisting (optional) True to keep existing selections
22354 selectRows : function(rows, keepExisting){
22356 this.clearSelections();
22358 for(var i = 0, len = rows.length; i < len; i++){
22359 this.selectRow(rows[i], true);
22364 * Selects a range of rows. All rows in between startRow and endRow are also selected.
22365 * @param {Number} startRow The index of the first row in the range
22366 * @param {Number} endRow The index of the last row in the range
22367 * @param {Boolean} keepExisting (optional) True to retain existing selections
22369 selectRange : function(startRow, endRow, keepExisting){
22374 this.clearSelections();
22376 if(startRow <= endRow){
22377 for(var i = startRow; i <= endRow; i++){
22378 this.selectRow(i, true);
22381 for(var i = startRow; i >= endRow; i--){
22382 this.selectRow(i, true);
22388 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
22389 * @param {Number} startRow The index of the first row in the range
22390 * @param {Number} endRow The index of the last row in the range
22392 deselectRange : function(startRow, endRow, preventViewNotify){
22396 for(var i = startRow; i <= endRow; i++){
22397 this.deselectRow(i, preventViewNotify);
22403 * @param {Number} row The index of the row to select
22404 * @param {Boolean} keepExisting (optional) True to keep existing selections
22406 selectRow : function(index, keepExisting, preventViewNotify){
22407 if(this.locked || (index < 0 || index >= this.grid.dataSource.getCount())) {
22410 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
22411 if(!keepExisting || this.singleSelect){
22412 this.clearSelections();
22414 var r = this.grid.dataSource.getAt(index);
22415 this.selections.add(r);
22416 this.last = this.lastActive = index;
22417 if(!preventViewNotify){
22418 this.grid.getView().onRowSelect(index);
22420 this.fireEvent("rowselect", this, index, r);
22421 this.fireEvent("selectionchange", this);
22427 * @param {Number} row The index of the row to deselect
22429 deselectRow : function(index, preventViewNotify){
22433 if(this.last == index){
22436 if(this.lastActive == index){
22437 this.lastActive = false;
22439 var r = this.grid.dataSource.getAt(index);
22440 this.selections.remove(r);
22441 if(!preventViewNotify){
22442 this.grid.getView().onRowDeselect(index);
22444 this.fireEvent("rowdeselect", this, index);
22445 this.fireEvent("selectionchange", this);
22449 restoreLast : function(){
22451 this.last = this._last;
22456 acceptsNav : function(row, col, cm){
22457 return !cm.isHidden(col) && cm.isCellEditable(col, row);
22461 onEditorKey : function(field, e){
22462 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
22467 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
22469 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
22471 }else if(k == e.ENTER && !e.ctrlKey){
22475 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
22477 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
22479 }else if(k == e.ESC){
22483 g.startEditing(newCell[0], newCell[1]);
22488 * Ext JS Library 1.1.1
22489 * Copyright(c) 2006-2007, Ext JS, LLC.
22491 * Originally Released Under LGPL - original licence link has changed is not relivant.
22494 * <script type="text/javascript">
22498 * @class Roo.bootstrap.PagingToolbar
22499 * @extends Roo.bootstrap.NavSimplebar
22500 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
22502 * Create a new PagingToolbar
22503 * @param {Object} config The config object
22504 * @param {Roo.data.Store} store
22506 Roo.bootstrap.PagingToolbar = function(config)
22508 // old args format still supported... - xtype is prefered..
22509 // created from xtype...
22511 this.ds = config.dataSource;
22513 if (config.store && !this.ds) {
22514 this.store= Roo.factory(config.store, Roo.data);
22515 this.ds = this.store;
22516 this.ds.xmodule = this.xmodule || false;
22519 this.toolbarItems = [];
22520 if (config.items) {
22521 this.toolbarItems = config.items;
22524 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
22529 this.bind(this.ds);
22532 this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
22536 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
22538 * @cfg {Roo.data.Store} dataSource
22539 * The underlying data store providing the paged data
22542 * @cfg {String/HTMLElement/Element} container
22543 * container The id or element that will contain the toolbar
22546 * @cfg {Boolean} displayInfo
22547 * True to display the displayMsg (defaults to false)
22550 * @cfg {Number} pageSize
22551 * The number of records to display per page (defaults to 20)
22555 * @cfg {String} displayMsg
22556 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
22558 displayMsg : 'Displaying {0} - {1} of {2}',
22560 * @cfg {String} emptyMsg
22561 * The message to display when no records are found (defaults to "No data to display")
22563 emptyMsg : 'No data to display',
22565 * Customizable piece of the default paging text (defaults to "Page")
22568 beforePageText : "Page",
22570 * Customizable piece of the default paging text (defaults to "of %0")
22573 afterPageText : "of {0}",
22575 * Customizable piece of the default paging text (defaults to "First Page")
22578 firstText : "First Page",
22580 * Customizable piece of the default paging text (defaults to "Previous Page")
22583 prevText : "Previous Page",
22585 * Customizable piece of the default paging text (defaults to "Next Page")
22588 nextText : "Next Page",
22590 * Customizable piece of the default paging text (defaults to "Last Page")
22593 lastText : "Last Page",
22595 * Customizable piece of the default paging text (defaults to "Refresh")
22598 refreshText : "Refresh",
22602 onRender : function(ct, position)
22604 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
22605 this.navgroup.parentId = this.id;
22606 this.navgroup.onRender(this.el, null);
22607 // add the buttons to the navgroup
22609 if(this.displayInfo){
22610 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
22611 this.displayEl = this.el.select('.x-paging-info', true).first();
22612 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
22613 // this.displayEl = navel.el.select('span',true).first();
22619 Roo.each(_this.buttons, function(e){ // this might need to use render????
22620 Roo.factory(e).onRender(_this.el, null);
22624 Roo.each(_this.toolbarItems, function(e) {
22625 _this.navgroup.addItem(e);
22629 this.first = this.navgroup.addItem({
22630 tooltip: this.firstText,
22632 icon : 'fa fa-backward',
22634 preventDefault: true,
22635 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
22638 this.prev = this.navgroup.addItem({
22639 tooltip: this.prevText,
22641 icon : 'fa fa-step-backward',
22643 preventDefault: true,
22644 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
22646 //this.addSeparator();
22649 var field = this.navgroup.addItem( {
22651 cls : 'x-paging-position',
22653 html : this.beforePageText +
22654 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
22655 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
22658 this.field = field.el.select('input', true).first();
22659 this.field.on("keydown", this.onPagingKeydown, this);
22660 this.field.on("focus", function(){this.dom.select();});
22663 this.afterTextEl = field.el.select('.x-paging-after',true).first();
22664 //this.field.setHeight(18);
22665 //this.addSeparator();
22666 this.next = this.navgroup.addItem({
22667 tooltip: this.nextText,
22669 html : ' <i class="fa fa-step-forward">',
22671 preventDefault: true,
22672 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
22674 this.last = this.navgroup.addItem({
22675 tooltip: this.lastText,
22676 icon : 'fa fa-forward',
22679 preventDefault: true,
22680 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
22682 //this.addSeparator();
22683 this.loading = this.navgroup.addItem({
22684 tooltip: this.refreshText,
22685 icon: 'fa fa-refresh',
22686 preventDefault: true,
22687 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
22693 updateInfo : function(){
22694 if(this.displayEl){
22695 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
22696 var msg = count == 0 ?
22700 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
22702 this.displayEl.update(msg);
22707 onLoad : function(ds, r, o){
22708 this.cursor = o.params ? o.params.start : 0;
22709 var d = this.getPageData(),
22713 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
22714 this.field.dom.value = ap;
22715 this.first.setDisabled(ap == 1);
22716 this.prev.setDisabled(ap == 1);
22717 this.next.setDisabled(ap == ps);
22718 this.last.setDisabled(ap == ps);
22719 this.loading.enable();
22724 getPageData : function(){
22725 var total = this.ds.getTotalCount();
22728 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
22729 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
22734 onLoadError : function(){
22735 this.loading.enable();
22739 onPagingKeydown : function(e){
22740 var k = e.getKey();
22741 var d = this.getPageData();
22743 var v = this.field.dom.value, pageNum;
22744 if(!v || isNaN(pageNum = parseInt(v, 10))){
22745 this.field.dom.value = d.activePage;
22748 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
22749 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
22752 else if(k == e.HOME || (k == e.UP && e.ctrlKey) || (k == e.PAGEUP && e.ctrlKey) || (k == e.RIGHT && e.ctrlKey) || k == e.END || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey))
22754 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
22755 this.field.dom.value = pageNum;
22756 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
22759 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
22761 var v = this.field.dom.value, pageNum;
22762 var increment = (e.shiftKey) ? 10 : 1;
22763 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
22766 if(!v || isNaN(pageNum = parseInt(v, 10))) {
22767 this.field.dom.value = d.activePage;
22770 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
22772 this.field.dom.value = parseInt(v, 10) + increment;
22773 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
22774 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
22781 beforeLoad : function(){
22783 this.loading.disable();
22788 onClick : function(which){
22797 ds.load({params:{start: 0, limit: this.pageSize}});
22800 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
22803 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
22806 var total = ds.getTotalCount();
22807 var extra = total % this.pageSize;
22808 var lastStart = extra ? (total - extra) : total-this.pageSize;
22809 ds.load({params:{start: lastStart, limit: this.pageSize}});
22812 ds.load({params:{start: this.cursor, limit: this.pageSize}});
22818 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
22819 * @param {Roo.data.Store} store The data store to unbind
22821 unbind : function(ds){
22822 ds.un("beforeload", this.beforeLoad, this);
22823 ds.un("load", this.onLoad, this);
22824 ds.un("loadexception", this.onLoadError, this);
22825 ds.un("remove", this.updateInfo, this);
22826 ds.un("add", this.updateInfo, this);
22827 this.ds = undefined;
22831 * Binds the paging toolbar to the specified {@link Roo.data.Store}
22832 * @param {Roo.data.Store} store The data store to bind
22834 bind : function(ds){
22835 ds.on("beforeload", this.beforeLoad, this);
22836 ds.on("load", this.onLoad, this);
22837 ds.on("loadexception", this.onLoadError, this);
22838 ds.on("remove", this.updateInfo, this);
22839 ds.on("add", this.updateInfo, this);
22850 * @class Roo.bootstrap.MessageBar
22851 * @extends Roo.bootstrap.Component
22852 * Bootstrap MessageBar class
22853 * @cfg {String} html contents of the MessageBar
22854 * @cfg {String} weight (info | success | warning | danger) default info
22855 * @cfg {String} beforeClass insert the bar before the given class
22856 * @cfg {Boolean} closable (true | false) default false
22857 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
22860 * Create a new Element
22861 * @param {Object} config The config object
22864 Roo.bootstrap.MessageBar = function(config){
22865 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
22868 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
22874 beforeClass: 'bootstrap-sticky-wrap',
22876 getAutoCreate : function(){
22880 cls: 'alert alert-dismissable alert-' + this.weight,
22885 html: this.html || ''
22891 cfg.cls += ' alert-messages-fixed';
22905 onRender : function(ct, position)
22907 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
22910 var cfg = Roo.apply({}, this.getAutoCreate());
22914 cfg.cls += ' ' + this.cls;
22917 cfg.style = this.style;
22919 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
22921 this.el.setVisibilityMode(Roo.Element.DISPLAY);
22924 this.el.select('>button.close').on('click', this.hide, this);
22930 if (!this.rendered) {
22936 this.fireEvent('show', this);
22942 if (!this.rendered) {
22948 this.fireEvent('hide', this);
22951 update : function()
22953 // var e = this.el.dom.firstChild;
22955 // if(this.closable){
22956 // e = e.nextSibling;
22959 // e.data = this.html || '';
22961 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
22977 * @class Roo.bootstrap.Graph
22978 * @extends Roo.bootstrap.Component
22979 * Bootstrap Graph class
22983 @cfg {String} graphtype bar | vbar | pie
22984 @cfg {number} g_x coodinator | centre x (pie)
22985 @cfg {number} g_y coodinator | centre y (pie)
22986 @cfg {number} g_r radius (pie)
22987 @cfg {number} g_height height of the chart (respected by all elements in the set)
22988 @cfg {number} g_width width of the chart (respected by all elements in the set)
22989 @cfg {Object} title The title of the chart
22992 -opts (object) options for the chart
22994 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
22995 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
22997 o colors (array) colors be used repeatedly to plot the bars. If multicolumn bar is used each sequence of bars with use a different color.
22998 o stacked (boolean) whether or not to tread values as in a stacked bar chart
23000 o stretch (boolean)
23002 -opts (object) options for the pie
23005 o startAngle (number)
23006 o endAngle (number)
23010 * Create a new Input
23011 * @param {Object} config The config object
23014 Roo.bootstrap.Graph = function(config){
23015 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
23021 * The img click event for the img.
23022 * @param {Roo.EventObject} e
23028 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
23039 //g_colors: this.colors,
23046 getAutoCreate : function(){
23057 onRender : function(ct,position){
23060 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
23062 if (typeof(Raphael) == 'undefined') {
23063 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
23067 this.raphael = Raphael(this.el.dom);
23069 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
23070 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
23071 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
23072 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
23074 r.text(160, 10, "Single Series Chart").attr(txtattr);
23075 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
23076 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
23077 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
23079 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
23080 r.barchart(330, 10, 300, 220, data1);
23081 r.barchart(10, 250, 300, 220, data2, {stacked: true});
23082 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
23085 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
23086 // r.barchart(30, 30, 560, 250, xdata, {
23087 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
23088 // axis : "0 0 1 1",
23089 // axisxlabels : xdata
23090 // //yvalues : cols,
23093 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
23095 // this.load(null,xdata,{
23096 // axis : "0 0 1 1",
23097 // axisxlabels : xdata
23102 load : function(graphtype,xdata,opts)
23104 this.raphael.clear();
23106 graphtype = this.graphtype;
23111 var r = this.raphael,
23112 fin = function () {
23113 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
23115 fout = function () {
23116 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
23118 pfin = function() {
23119 this.sector.stop();
23120 this.sector.scale(1.1, 1.1, this.cx, this.cy);
23123 this.label[0].stop();
23124 this.label[0].attr({ r: 7.5 });
23125 this.label[1].attr({ "font-weight": 800 });
23128 pfout = function() {
23129 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
23132 this.label[0].animate({ r: 5 }, 500, "bounce");
23133 this.label[1].attr({ "font-weight": 400 });
23139 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
23142 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
23145 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
23146 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
23148 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
23155 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
23160 setTitle: function(o)
23165 initEvents: function() {
23168 this.el.on('click', this.onClick, this);
23172 onClick : function(e)
23174 Roo.log('img onclick');
23175 this.fireEvent('click', this, e);
23187 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
23190 * @class Roo.bootstrap.dash.NumberBox
23191 * @extends Roo.bootstrap.Component
23192 * Bootstrap NumberBox class
23193 * @cfg {String} headline Box headline
23194 * @cfg {String} content Box content
23195 * @cfg {String} icon Box icon
23196 * @cfg {String} footer Footer text
23197 * @cfg {String} fhref Footer href
23200 * Create a new NumberBox
23201 * @param {Object} config The config object
23205 Roo.bootstrap.dash.NumberBox = function(config){
23206 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
23210 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
23219 getAutoCreate : function(){
23223 cls : 'small-box ',
23231 cls : 'roo-headline',
23232 html : this.headline
23236 cls : 'roo-content',
23237 html : this.content
23251 cls : 'ion ' + this.icon
23260 cls : 'small-box-footer',
23261 href : this.fhref || '#',
23265 cfg.cn.push(footer);
23272 onRender : function(ct,position){
23273 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
23280 setHeadline: function (value)
23282 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
23285 setFooter: function (value, href)
23287 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
23290 this.el.select('a.small-box-footer',true).first().attr('href', href);
23295 setContent: function (value)
23297 this.el.select('.roo-content',true).first().dom.innerHTML = value;
23300 initEvents: function()
23314 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
23317 * @class Roo.bootstrap.dash.TabBox
23318 * @extends Roo.bootstrap.Component
23319 * Bootstrap TabBox class
23320 * @cfg {String} title Title of the TabBox
23321 * @cfg {String} icon Icon of the TabBox
23322 * @cfg {Boolean} showtabs (true|false) show the tabs default true
23323 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
23326 * Create a new TabBox
23327 * @param {Object} config The config object
23331 Roo.bootstrap.dash.TabBox = function(config){
23332 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
23337 * When a pane is added
23338 * @param {Roo.bootstrap.dash.TabPane} pane
23342 * @event activatepane
23343 * When a pane is activated
23344 * @param {Roo.bootstrap.dash.TabPane} pane
23346 "activatepane" : true
23354 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
23359 tabScrollable : false,
23361 getChildContainer : function()
23363 return this.el.select('.tab-content', true).first();
23366 getAutoCreate : function(){
23370 cls: 'pull-left header',
23378 cls: 'fa ' + this.icon
23384 cls: 'nav nav-tabs pull-right',
23390 if(this.tabScrollable){
23397 cls: 'nav nav-tabs pull-right',
23408 cls: 'nav-tabs-custom',
23413 cls: 'tab-content no-padding',
23421 initEvents : function()
23423 //Roo.log('add add pane handler');
23424 this.on('addpane', this.onAddPane, this);
23427 * Updates the box title
23428 * @param {String} html to set the title to.
23430 setTitle : function(value)
23432 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
23434 onAddPane : function(pane)
23436 this.panes.push(pane);
23437 //Roo.log('addpane');
23439 // tabs are rendere left to right..
23440 if(!this.showtabs){
23444 var ctr = this.el.select('.nav-tabs', true).first();
23447 var existing = ctr.select('.nav-tab',true);
23448 var qty = existing.getCount();;
23451 var tab = ctr.createChild({
23453 cls : 'nav-tab' + (qty ? '' : ' active'),
23461 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
23464 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
23466 pane.el.addClass('active');
23471 onTabClick : function(ev,un,ob,pane)
23473 //Roo.log('tab - prev default');
23474 ev.preventDefault();
23477 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
23478 pane.tab.addClass('active');
23479 //Roo.log(pane.title);
23480 this.getChildContainer().select('.tab-pane',true).removeClass('active');
23481 // technically we should have a deactivate event.. but maybe add later.
23482 // and it should not de-activate the selected tab...
23483 this.fireEvent('activatepane', pane);
23484 pane.el.addClass('active');
23485 pane.fireEvent('activate');
23490 getActivePane : function()
23493 Roo.each(this.panes, function(p) {
23494 if(p.el.hasClass('active')){
23515 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
23517 * @class Roo.bootstrap.TabPane
23518 * @extends Roo.bootstrap.Component
23519 * Bootstrap TabPane class
23520 * @cfg {Boolean} active (false | true) Default false
23521 * @cfg {String} title title of panel
23525 * Create a new TabPane
23526 * @param {Object} config The config object
23529 Roo.bootstrap.dash.TabPane = function(config){
23530 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
23536 * When a pane is activated
23537 * @param {Roo.bootstrap.dash.TabPane} pane
23544 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
23549 // the tabBox that this is attached to.
23552 getAutoCreate : function()
23560 cfg.cls += ' active';
23565 initEvents : function()
23567 //Roo.log('trigger add pane handler');
23568 this.parent().fireEvent('addpane', this)
23572 * Updates the tab title
23573 * @param {String} html to set the title to.
23575 setTitle: function(str)
23581 this.tab.select('a', true).first().dom.innerHTML = str;
23598 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
23601 * @class Roo.bootstrap.menu.Menu
23602 * @extends Roo.bootstrap.Component
23603 * Bootstrap Menu class - container for Menu
23604 * @cfg {String} html Text of the menu
23605 * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
23606 * @cfg {String} icon Font awesome icon
23607 * @cfg {String} pos Menu align to (top | bottom) default bottom
23611 * Create a new Menu
23612 * @param {Object} config The config object
23616 Roo.bootstrap.menu.Menu = function(config){
23617 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
23621 * @event beforeshow
23622 * Fires before this menu is displayed
23623 * @param {Roo.bootstrap.menu.Menu} this
23627 * @event beforehide
23628 * Fires before this menu is hidden
23629 * @param {Roo.bootstrap.menu.Menu} this
23634 * Fires after this menu is displayed
23635 * @param {Roo.bootstrap.menu.Menu} this
23640 * Fires after this menu is hidden
23641 * @param {Roo.bootstrap.menu.Menu} this
23646 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
23647 * @param {Roo.bootstrap.menu.Menu} this
23648 * @param {Roo.EventObject} e
23655 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
23659 weight : 'default',
23664 getChildContainer : function() {
23665 if(this.isSubMenu){
23669 return this.el.select('ul.dropdown-menu', true).first();
23672 getAutoCreate : function()
23677 cls : 'roo-menu-text',
23685 cls : 'fa ' + this.icon
23696 cls : 'dropdown-button btn btn-' + this.weight,
23701 cls : 'dropdown-toggle btn btn-' + this.weight,
23711 cls : 'dropdown-menu'
23717 if(this.pos == 'top'){
23718 cfg.cls += ' dropup';
23721 if(this.isSubMenu){
23724 cls : 'dropdown-menu'
23731 onRender : function(ct, position)
23733 this.isSubMenu = ct.hasClass('dropdown-submenu');
23735 Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
23738 initEvents : function()
23740 if(this.isSubMenu){
23744 this.hidden = true;
23746 this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
23747 this.triggerEl.on('click', this.onTriggerPress, this);
23749 this.buttonEl = this.el.select('button.dropdown-button', true).first();
23750 this.buttonEl.on('click', this.onClick, this);
23756 if(this.isSubMenu){
23760 return this.el.select('ul.dropdown-menu', true).first();
23763 onClick : function(e)
23765 this.fireEvent("click", this, e);
23768 onTriggerPress : function(e)
23770 if (this.isVisible()) {
23777 isVisible : function(){
23778 return !this.hidden;
23783 this.fireEvent("beforeshow", this);
23785 this.hidden = false;
23786 this.el.addClass('open');
23788 Roo.get(document).on("mouseup", this.onMouseUp, this);
23790 this.fireEvent("show", this);
23797 this.fireEvent("beforehide", this);
23799 this.hidden = true;
23800 this.el.removeClass('open');
23802 Roo.get(document).un("mouseup", this.onMouseUp);
23804 this.fireEvent("hide", this);
23807 onMouseUp : function()
23821 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
23824 * @class Roo.bootstrap.menu.Item
23825 * @extends Roo.bootstrap.Component
23826 * Bootstrap MenuItem class
23827 * @cfg {Boolean} submenu (true | false) default false
23828 * @cfg {String} html text of the item
23829 * @cfg {String} href the link
23830 * @cfg {Boolean} disable (true | false) default false
23831 * @cfg {Boolean} preventDefault (true | false) default true
23832 * @cfg {String} icon Font awesome icon
23833 * @cfg {String} pos Submenu align to (left | right) default right
23837 * Create a new Item
23838 * @param {Object} config The config object
23842 Roo.bootstrap.menu.Item = function(config){
23843 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
23847 * Fires when the mouse is hovering over this menu
23848 * @param {Roo.bootstrap.menu.Item} this
23849 * @param {Roo.EventObject} e
23854 * Fires when the mouse exits this menu
23855 * @param {Roo.bootstrap.menu.Item} this
23856 * @param {Roo.EventObject} e
23862 * The raw click event for the entire grid.
23863 * @param {Roo.EventObject} e
23869 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
23874 preventDefault: true,
23879 getAutoCreate : function()
23884 cls : 'roo-menu-item-text',
23892 cls : 'fa ' + this.icon
23901 href : this.href || '#',
23908 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
23912 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
23914 if(this.pos == 'left'){
23915 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
23922 initEvents : function()
23924 this.el.on('mouseover', this.onMouseOver, this);
23925 this.el.on('mouseout', this.onMouseOut, this);
23927 this.el.select('a', true).first().on('click', this.onClick, this);
23931 onClick : function(e)
23933 if(this.preventDefault){
23934 e.preventDefault();
23937 this.fireEvent("click", this, e);
23940 onMouseOver : function(e)
23942 if(this.submenu && this.pos == 'left'){
23943 this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
23946 this.fireEvent("mouseover", this, e);
23949 onMouseOut : function(e)
23951 this.fireEvent("mouseout", this, e);
23963 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
23966 * @class Roo.bootstrap.menu.Separator
23967 * @extends Roo.bootstrap.Component
23968 * Bootstrap Separator class
23971 * Create a new Separator
23972 * @param {Object} config The config object
23976 Roo.bootstrap.menu.Separator = function(config){
23977 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
23980 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
23982 getAutoCreate : function(){
24003 * @class Roo.bootstrap.Tooltip
24004 * Bootstrap Tooltip class
24005 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
24006 * to determine which dom element triggers the tooltip.
24008 * It needs to add support for additional attributes like tooltip-position
24011 * Create a new Toolti
24012 * @param {Object} config The config object
24015 Roo.bootstrap.Tooltip = function(config){
24016 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
24019 Roo.apply(Roo.bootstrap.Tooltip, {
24021 * @function init initialize tooltip monitoring.
24025 currentTip : false,
24026 currentRegion : false,
24032 Roo.get(document).on('mouseover', this.enter ,this);
24033 Roo.get(document).on('mouseout', this.leave, this);
24036 this.currentTip = new Roo.bootstrap.Tooltip();
24039 enter : function(ev)
24041 var dom = ev.getTarget();
24043 //Roo.log(['enter',dom]);
24044 var el = Roo.fly(dom);
24045 if (this.currentEl) {
24047 //Roo.log(this.currentEl);
24048 //Roo.log(this.currentEl.contains(dom));
24049 if (this.currentEl == el) {
24052 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
24058 if (this.currentTip.el) {
24059 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
24064 // you can not look for children, as if el is the body.. then everythign is the child..
24065 if (!el.attr('tooltip')) { //
24066 if (!el.select("[tooltip]").elements.length) {
24069 // is the mouse over this child...?
24070 bindEl = el.select("[tooltip]").first();
24071 var xy = ev.getXY();
24072 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
24073 //Roo.log("not in region.");
24076 //Roo.log("child element over..");
24079 this.currentEl = bindEl;
24080 this.currentTip.bind(bindEl);
24081 this.currentRegion = Roo.lib.Region.getRegion(dom);
24082 this.currentTip.enter();
24085 leave : function(ev)
24087 var dom = ev.getTarget();
24088 //Roo.log(['leave',dom]);
24089 if (!this.currentEl) {
24094 if (dom != this.currentEl.dom) {
24097 var xy = ev.getXY();
24098 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
24101 // only activate leave if mouse cursor is outside... bounding box..
24106 if (this.currentTip) {
24107 this.currentTip.leave();
24109 //Roo.log('clear currentEl');
24110 this.currentEl = false;
24115 'left' : ['r-l', [-2,0], 'right'],
24116 'right' : ['l-r', [2,0], 'left'],
24117 'bottom' : ['t-b', [0,2], 'top'],
24118 'top' : [ 'b-t', [0,-2], 'bottom']
24124 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
24129 delay : null, // can be { show : 300 , hide: 500}
24133 hoverState : null, //???
24135 placement : 'bottom',
24137 getAutoCreate : function(){
24144 cls : 'tooltip-arrow'
24147 cls : 'tooltip-inner'
24154 bind : function(el)
24160 enter : function () {
24162 if (this.timeout != null) {
24163 clearTimeout(this.timeout);
24166 this.hoverState = 'in';
24167 //Roo.log("enter - show");
24168 if (!this.delay || !this.delay.show) {
24173 this.timeout = setTimeout(function () {
24174 if (_t.hoverState == 'in') {
24177 }, this.delay.show);
24181 clearTimeout(this.timeout);
24183 this.hoverState = 'out';
24184 if (!this.delay || !this.delay.hide) {
24190 this.timeout = setTimeout(function () {
24191 //Roo.log("leave - timeout");
24193 if (_t.hoverState == 'out') {
24195 Roo.bootstrap.Tooltip.currentEl = false;
24203 this.render(document.body);
24206 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
24208 var tip = this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
24210 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
24212 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
24214 var placement = typeof this.placement == 'function' ?
24215 this.placement.call(this, this.el, on_el) :
24218 var autoToken = /\s?auto?\s?/i;
24219 var autoPlace = autoToken.test(placement);
24221 placement = placement.replace(autoToken, '') || 'top';
24225 //this.el.setXY([0,0]);
24227 //this.el.dom.style.display='block';
24229 //this.el.appendTo(on_el);
24231 var p = this.getPosition();
24232 var box = this.el.getBox();
24238 var align = Roo.bootstrap.Tooltip.alignment[placement];
24240 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
24242 if(placement == 'top' || placement == 'bottom'){
24244 placement = 'right';
24247 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
24248 placement = 'left';
24252 align = Roo.bootstrap.Tooltip.alignment[placement];
24254 this.el.alignTo(this.bindEl, align[0],align[1]);
24255 //var arrow = this.el.select('.arrow',true).first();
24256 //arrow.set(align[2],
24258 this.el.addClass(placement);
24260 this.el.addClass('in fade');
24262 this.hoverState = null;
24264 if (this.el.hasClass('fade')) {
24275 //this.el.setXY([0,0]);
24276 this.el.removeClass('in');
24292 * @class Roo.bootstrap.LocationPicker
24293 * @extends Roo.bootstrap.Component
24294 * Bootstrap LocationPicker class
24295 * @cfg {Number} latitude Position when init default 0
24296 * @cfg {Number} longitude Position when init default 0
24297 * @cfg {Number} zoom default 15
24298 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
24299 * @cfg {Boolean} mapTypeControl default false
24300 * @cfg {Boolean} disableDoubleClickZoom default false
24301 * @cfg {Boolean} scrollwheel default true
24302 * @cfg {Boolean} streetViewControl default false
24303 * @cfg {Number} radius default 0
24304 * @cfg {String} locationName
24305 * @cfg {Boolean} draggable default true
24306 * @cfg {Boolean} enableAutocomplete default false
24307 * @cfg {Boolean} enableReverseGeocode default true
24308 * @cfg {String} markerTitle
24311 * Create a new LocationPicker
24312 * @param {Object} config The config object
24316 Roo.bootstrap.LocationPicker = function(config){
24318 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
24323 * Fires when the picker initialized.
24324 * @param {Roo.bootstrap.LocationPicker} this
24325 * @param {Google Location} location
24329 * @event positionchanged
24330 * Fires when the picker position changed.
24331 * @param {Roo.bootstrap.LocationPicker} this
24332 * @param {Google Location} location
24334 positionchanged : true,
24337 * Fires when the map resize.
24338 * @param {Roo.bootstrap.LocationPicker} this
24343 * Fires when the map show.
24344 * @param {Roo.bootstrap.LocationPicker} this
24349 * Fires when the map hide.
24350 * @param {Roo.bootstrap.LocationPicker} this
24355 * Fires when click the map.
24356 * @param {Roo.bootstrap.LocationPicker} this
24357 * @param {Map event} e
24361 * @event mapRightClick
24362 * Fires when right click the map.
24363 * @param {Roo.bootstrap.LocationPicker} this
24364 * @param {Map event} e
24366 mapRightClick : true,
24368 * @event markerClick
24369 * Fires when click the marker.
24370 * @param {Roo.bootstrap.LocationPicker} this
24371 * @param {Map event} e
24373 markerClick : true,
24375 * @event markerRightClick
24376 * Fires when right click the marker.
24377 * @param {Roo.bootstrap.LocationPicker} this
24378 * @param {Map event} e
24380 markerRightClick : true,
24382 * @event OverlayViewDraw
24383 * Fires when OverlayView Draw
24384 * @param {Roo.bootstrap.LocationPicker} this
24386 OverlayViewDraw : true,
24388 * @event OverlayViewOnAdd
24389 * Fires when OverlayView Draw
24390 * @param {Roo.bootstrap.LocationPicker} this
24392 OverlayViewOnAdd : true,
24394 * @event OverlayViewOnRemove
24395 * Fires when OverlayView Draw
24396 * @param {Roo.bootstrap.LocationPicker} this
24398 OverlayViewOnRemove : true,
24400 * @event OverlayViewShow
24401 * Fires when OverlayView Draw
24402 * @param {Roo.bootstrap.LocationPicker} this
24403 * @param {Pixel} cpx
24405 OverlayViewShow : true,
24407 * @event OverlayViewHide
24408 * Fires when OverlayView Draw
24409 * @param {Roo.bootstrap.LocationPicker} this
24411 OverlayViewHide : true,
24413 * @event loadexception
24414 * Fires when load google lib failed.
24415 * @param {Roo.bootstrap.LocationPicker} this
24417 loadexception : true
24422 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
24424 gMapContext: false,
24430 mapTypeControl: false,
24431 disableDoubleClickZoom: false,
24433 streetViewControl: false,
24437 enableAutocomplete: false,
24438 enableReverseGeocode: true,
24441 getAutoCreate: function()
24446 cls: 'roo-location-picker'
24452 initEvents: function(ct, position)
24454 if(!this.el.getWidth() || this.isApplied()){
24458 this.el.setVisibilityMode(Roo.Element.DISPLAY);
24463 initial: function()
24465 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
24466 this.fireEvent('loadexception', this);
24470 if(!this.mapTypeId){
24471 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
24474 this.gMapContext = this.GMapContext();
24476 this.initOverlayView();
24478 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
24482 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
24483 _this.setPosition(_this.gMapContext.marker.position);
24486 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
24487 _this.fireEvent('mapClick', this, event);
24491 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
24492 _this.fireEvent('mapRightClick', this, event);
24496 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
24497 _this.fireEvent('markerClick', this, event);
24501 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
24502 _this.fireEvent('markerRightClick', this, event);
24506 this.setPosition(this.gMapContext.location);
24508 this.fireEvent('initial', this, this.gMapContext.location);
24511 initOverlayView: function()
24515 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
24519 _this.fireEvent('OverlayViewDraw', _this);
24524 _this.fireEvent('OverlayViewOnAdd', _this);
24527 onRemove: function()
24529 _this.fireEvent('OverlayViewOnRemove', _this);
24532 show: function(cpx)
24534 _this.fireEvent('OverlayViewShow', _this, cpx);
24539 _this.fireEvent('OverlayViewHide', _this);
24545 fromLatLngToContainerPixel: function(event)
24547 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
24550 isApplied: function()
24552 return this.getGmapContext() == false ? false : true;
24555 getGmapContext: function()
24557 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
24560 GMapContext: function()
24562 var position = new google.maps.LatLng(this.latitude, this.longitude);
24564 var _map = new google.maps.Map(this.el.dom, {
24567 mapTypeId: this.mapTypeId,
24568 mapTypeControl: this.mapTypeControl,
24569 disableDoubleClickZoom: this.disableDoubleClickZoom,
24570 scrollwheel: this.scrollwheel,
24571 streetViewControl: this.streetViewControl,
24572 locationName: this.locationName,
24573 draggable: this.draggable,
24574 enableAutocomplete: this.enableAutocomplete,
24575 enableReverseGeocode: this.enableReverseGeocode
24578 var _marker = new google.maps.Marker({
24579 position: position,
24581 title: this.markerTitle,
24582 draggable: this.draggable
24589 location: position,
24590 radius: this.radius,
24591 locationName: this.locationName,
24592 addressComponents: {
24593 formatted_address: null,
24594 addressLine1: null,
24595 addressLine2: null,
24597 streetNumber: null,
24601 stateOrProvince: null
24604 domContainer: this.el.dom,
24605 geodecoder: new google.maps.Geocoder()
24609 drawCircle: function(center, radius, options)
24611 if (this.gMapContext.circle != null) {
24612 this.gMapContext.circle.setMap(null);
24616 options = Roo.apply({}, options, {
24617 strokeColor: "#0000FF",
24618 strokeOpacity: .35,
24620 fillColor: "#0000FF",
24624 options.map = this.gMapContext.map;
24625 options.radius = radius;
24626 options.center = center;
24627 this.gMapContext.circle = new google.maps.Circle(options);
24628 return this.gMapContext.circle;
24634 setPosition: function(location)
24636 this.gMapContext.location = location;
24637 this.gMapContext.marker.setPosition(location);
24638 this.gMapContext.map.panTo(location);
24639 this.drawCircle(location, this.gMapContext.radius, {});
24643 if (this.gMapContext.settings.enableReverseGeocode) {
24644 this.gMapContext.geodecoder.geocode({
24645 latLng: this.gMapContext.location
24646 }, function(results, status) {
24648 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
24649 _this.gMapContext.locationName = results[0].formatted_address;
24650 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
24652 _this.fireEvent('positionchanged', this, location);
24659 this.fireEvent('positionchanged', this, location);
24664 google.maps.event.trigger(this.gMapContext.map, "resize");
24666 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
24668 this.fireEvent('resize', this);
24671 setPositionByLatLng: function(latitude, longitude)
24673 this.setPosition(new google.maps.LatLng(latitude, longitude));
24676 getCurrentPosition: function()
24679 latitude: this.gMapContext.location.lat(),
24680 longitude: this.gMapContext.location.lng()
24684 getAddressName: function()
24686 return this.gMapContext.locationName;
24689 getAddressComponents: function()
24691 return this.gMapContext.addressComponents;
24694 address_component_from_google_geocode: function(address_components)
24698 for (var i = 0; i < address_components.length; i++) {
24699 var component = address_components[i];
24700 if (component.types.indexOf("postal_code") >= 0) {
24701 result.postalCode = component.short_name;
24702 } else if (component.types.indexOf("street_number") >= 0) {
24703 result.streetNumber = component.short_name;
24704 } else if (component.types.indexOf("route") >= 0) {
24705 result.streetName = component.short_name;
24706 } else if (component.types.indexOf("neighborhood") >= 0) {
24707 result.city = component.short_name;
24708 } else if (component.types.indexOf("locality") >= 0) {
24709 result.city = component.short_name;
24710 } else if (component.types.indexOf("sublocality") >= 0) {
24711 result.district = component.short_name;
24712 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
24713 result.stateOrProvince = component.short_name;
24714 } else if (component.types.indexOf("country") >= 0) {
24715 result.country = component.short_name;
24719 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
24720 result.addressLine2 = "";
24724 setZoomLevel: function(zoom)
24726 this.gMapContext.map.setZoom(zoom);
24739 this.fireEvent('show', this);
24750 this.fireEvent('hide', this);
24755 Roo.apply(Roo.bootstrap.LocationPicker, {
24757 OverlayView : function(map, options)
24759 options = options || {};
24773 * @class Roo.bootstrap.Alert
24774 * @extends Roo.bootstrap.Component
24775 * Bootstrap Alert class
24776 * @cfg {String} title The title of alert
24777 * @cfg {String} html The content of alert
24778 * @cfg {String} weight ( success | info | warning | danger )
24779 * @cfg {String} faicon font-awesomeicon
24782 * Create a new alert
24783 * @param {Object} config The config object
24787 Roo.bootstrap.Alert = function(config){
24788 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
24792 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
24799 getAutoCreate : function()
24808 cls : 'roo-alert-icon'
24813 cls : 'roo-alert-title',
24818 cls : 'roo-alert-text',
24825 cfg.cn[0].cls += ' fa ' + this.faicon;
24829 cfg.cls += ' alert-' + this.weight;
24835 initEvents: function()
24837 this.el.setVisibilityMode(Roo.Element.DISPLAY);
24840 setTitle : function(str)
24842 this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
24845 setText : function(str)
24847 this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
24850 setWeight : function(weight)
24853 this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
24856 this.weight = weight;
24858 this.el.select('.alert',true).first().addClass('alert-' + this.weight);
24861 setIcon : function(icon)
24864 this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
24867 this.faicon = icon;
24869 this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
24890 * @class Roo.bootstrap.UploadCropbox
24891 * @extends Roo.bootstrap.Component
24892 * Bootstrap UploadCropbox class
24893 * @cfg {String} emptyText show when image has been loaded
24894 * @cfg {String} rotateNotify show when image too small to rotate
24895 * @cfg {Number} errorTimeout default 3000
24896 * @cfg {Number} minWidth default 300
24897 * @cfg {Number} minHeight default 300
24898 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
24899 * @cfg {Boolean} isDocument (true|false) default false
24900 * @cfg {String} url action url
24901 * @cfg {String} paramName default 'imageUpload'
24902 * @cfg {String} method default POST
24903 * @cfg {Boolean} loadMask (true|false) default true
24904 * @cfg {Boolean} loadingText default 'Loading...'
24907 * Create a new UploadCropbox
24908 * @param {Object} config The config object
24911 Roo.bootstrap.UploadCropbox = function(config){
24912 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
24916 * @event beforeselectfile
24917 * Fire before select file
24918 * @param {Roo.bootstrap.UploadCropbox} this
24920 "beforeselectfile" : true,
24923 * Fire after initEvent
24924 * @param {Roo.bootstrap.UploadCropbox} this
24929 * Fire after initEvent
24930 * @param {Roo.bootstrap.UploadCropbox} this
24931 * @param {String} data
24936 * Fire when preparing the file data
24937 * @param {Roo.bootstrap.UploadCropbox} this
24938 * @param {Object} file
24943 * Fire when get exception
24944 * @param {Roo.bootstrap.UploadCropbox} this
24945 * @param {XMLHttpRequest} xhr
24947 "exception" : true,
24949 * @event beforeloadcanvas
24950 * Fire before load the canvas
24951 * @param {Roo.bootstrap.UploadCropbox} this
24952 * @param {String} src
24954 "beforeloadcanvas" : true,
24957 * Fire when trash image
24958 * @param {Roo.bootstrap.UploadCropbox} this
24963 * Fire when download the image
24964 * @param {Roo.bootstrap.UploadCropbox} this
24968 * @event footerbuttonclick
24969 * Fire when footerbuttonclick
24970 * @param {Roo.bootstrap.UploadCropbox} this
24971 * @param {String} type
24973 "footerbuttonclick" : true,
24977 * @param {Roo.bootstrap.UploadCropbox} this
24982 * Fire when rotate the image
24983 * @param {Roo.bootstrap.UploadCropbox} this
24984 * @param {String} pos
24989 * Fire when inspect the file
24990 * @param {Roo.bootstrap.UploadCropbox} this
24991 * @param {Object} file
24996 * Fire when xhr upload the file
24997 * @param {Roo.bootstrap.UploadCropbox} this
24998 * @param {Object} data
25003 * Fire when arrange the file data
25004 * @param {Roo.bootstrap.UploadCropbox} this
25005 * @param {Object} formData
25010 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
25013 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
25015 emptyText : 'Click to upload image',
25016 rotateNotify : 'Image is too small to rotate',
25017 errorTimeout : 3000,
25031 cropType : 'image/jpeg',
25033 canvasLoaded : false,
25034 isDocument : false,
25036 paramName : 'imageUpload',
25038 loadingText : 'Loading...',
25041 getAutoCreate : function()
25045 cls : 'roo-upload-cropbox',
25049 cls : 'roo-upload-cropbox-selector',
25054 cls : 'roo-upload-cropbox-body',
25055 style : 'cursor:pointer',
25059 cls : 'roo-upload-cropbox-preview'
25063 cls : 'roo-upload-cropbox-thumb'
25067 cls : 'roo-upload-cropbox-empty-notify',
25068 html : this.emptyText
25072 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
25073 html : this.rotateNotify
25079 cls : 'roo-upload-cropbox-footer',
25082 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
25092 onRender : function(ct, position)
25094 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
25096 if (this.buttons.length) {
25098 Roo.each(this.buttons, function(bb) {
25100 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
25102 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
25108 this.maskEl = this.el;
25112 initEvents : function()
25114 this.urlAPI = (window.createObjectURL && window) ||
25115 (window.URL && URL.revokeObjectURL && URL) ||
25116 (window.webkitURL && webkitURL);
25118 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
25119 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25121 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
25122 this.selectorEl.hide();
25124 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
25125 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25127 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
25128 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25129 this.thumbEl.hide();
25131 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
25132 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25134 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
25135 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25136 this.errorEl.hide();
25138 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
25139 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25140 this.footerEl.hide();
25142 this.setThumbBoxSize();
25148 this.fireEvent('initial', this);
25155 window.addEventListener("resize", function() { _this.resize(); } );
25157 this.bodyEl.on('click', this.beforeSelectFile, this);
25160 this.bodyEl.on('touchstart', this.onTouchStart, this);
25161 this.bodyEl.on('touchmove', this.onTouchMove, this);
25162 this.bodyEl.on('touchend', this.onTouchEnd, this);
25166 this.bodyEl.on('mousedown', this.onMouseDown, this);
25167 this.bodyEl.on('mousemove', this.onMouseMove, this);
25168 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
25169 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
25170 Roo.get(document).on('mouseup', this.onMouseUp, this);
25173 this.selectorEl.on('change', this.onFileSelected, this);
25179 this.baseScale = 1;
25181 this.baseRotate = 1;
25182 this.dragable = false;
25183 this.pinching = false;
25186 this.cropData = false;
25187 this.notifyEl.dom.innerHTML = this.emptyText;
25189 this.selectorEl.dom.value = '';
25193 resize : function()
25195 if(this.fireEvent('resize', this) != false){
25196 this.setThumbBoxPosition();
25197 this.setCanvasPosition();
25201 onFooterButtonClick : function(e, el, o, type)
25204 case 'rotate-left' :
25205 this.onRotateLeft(e);
25207 case 'rotate-right' :
25208 this.onRotateRight(e);
25211 this.beforeSelectFile(e);
25226 this.fireEvent('footerbuttonclick', this, type);
25229 beforeSelectFile : function(e)
25231 e.preventDefault();
25233 if(this.fireEvent('beforeselectfile', this) != false){
25234 this.selectorEl.dom.click();
25238 onFileSelected : function(e)
25240 e.preventDefault();
25242 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
25246 var file = this.selectorEl.dom.files[0];
25248 if(this.fireEvent('inspect', this, file) != false){
25249 this.prepare(file);
25254 trash : function(e)
25256 this.fireEvent('trash', this);
25259 download : function(e)
25261 this.fireEvent('download', this);
25264 loadCanvas : function(src)
25266 if(this.fireEvent('beforeloadcanvas', this, src) != false){
25270 this.imageEl = document.createElement('img');
25274 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
25276 this.imageEl.src = src;
25280 onLoadCanvas : function()
25282 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
25283 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
25285 this.bodyEl.un('click', this.beforeSelectFile, this);
25287 this.notifyEl.hide();
25288 this.thumbEl.show();
25289 this.footerEl.show();
25291 this.baseRotateLevel();
25293 if(this.isDocument){
25294 this.setThumbBoxSize();
25297 this.setThumbBoxPosition();
25299 this.baseScaleLevel();
25305 this.canvasLoaded = true;
25308 this.maskEl.unmask();
25313 setCanvasPosition : function()
25315 if(!this.canvasEl){
25319 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
25320 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
25322 this.previewEl.setLeft(pw);
25323 this.previewEl.setTop(ph);
25327 onMouseDown : function(e)
25331 this.dragable = true;
25332 this.pinching = false;
25334 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
25335 this.dragable = false;
25339 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
25340 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
25344 onMouseMove : function(e)
25348 if(!this.canvasLoaded){
25352 if (!this.dragable){
25356 var minX = Math.ceil(this.thumbEl.getLeft(true));
25357 var minY = Math.ceil(this.thumbEl.getTop(true));
25359 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
25360 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
25362 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
25363 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
25365 x = x - this.mouseX;
25366 y = y - this.mouseY;
25368 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
25369 var bgY = Math.ceil(y + this.previewEl.getTop(true));
25371 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
25372 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
25374 this.previewEl.setLeft(bgX);
25375 this.previewEl.setTop(bgY);
25377 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
25378 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
25381 onMouseUp : function(e)
25385 this.dragable = false;
25388 onMouseWheel : function(e)
25392 this.startScale = this.scale;
25394 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
25396 if(!this.zoomable()){
25397 this.scale = this.startScale;
25406 zoomable : function()
25408 var minScale = this.thumbEl.getWidth() / this.minWidth;
25410 if(this.minWidth < this.minHeight){
25411 minScale = this.thumbEl.getHeight() / this.minHeight;
25414 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
25415 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
25419 (this.rotate == 0 || this.rotate == 180) &&
25421 width > this.imageEl.OriginWidth ||
25422 height > this.imageEl.OriginHeight ||
25423 (width < this.minWidth && height < this.minHeight)
25431 (this.rotate == 90 || this.rotate == 270) &&
25433 width > this.imageEl.OriginWidth ||
25434 height > this.imageEl.OriginHeight ||
25435 (width < this.minHeight && height < this.minWidth)
25442 !this.isDocument &&
25443 (this.rotate == 0 || this.rotate == 180) &&
25445 width < this.minWidth ||
25446 width > this.imageEl.OriginWidth ||
25447 height < this.minHeight ||
25448 height > this.imageEl.OriginHeight
25455 !this.isDocument &&
25456 (this.rotate == 90 || this.rotate == 270) &&
25458 width < this.minHeight ||
25459 width > this.imageEl.OriginWidth ||
25460 height < this.minWidth ||
25461 height > this.imageEl.OriginHeight
25471 onRotateLeft : function(e)
25473 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
25475 var minScale = this.thumbEl.getWidth() / this.minWidth;
25477 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
25478 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
25480 this.startScale = this.scale;
25482 while (this.getScaleLevel() < minScale){
25484 this.scale = this.scale + 1;
25486 if(!this.zoomable()){
25491 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
25492 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
25497 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
25504 this.scale = this.startScale;
25506 this.onRotateFail();
25511 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
25513 if(this.isDocument){
25514 this.setThumbBoxSize();
25515 this.setThumbBoxPosition();
25516 this.setCanvasPosition();
25521 this.fireEvent('rotate', this, 'left');
25525 onRotateRight : function(e)
25527 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
25529 var minScale = this.thumbEl.getWidth() / this.minWidth;
25531 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
25532 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
25534 this.startScale = this.scale;
25536 while (this.getScaleLevel() < minScale){
25538 this.scale = this.scale + 1;
25540 if(!this.zoomable()){
25545 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
25546 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
25551 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
25558 this.scale = this.startScale;
25560 this.onRotateFail();
25565 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
25567 if(this.isDocument){
25568 this.setThumbBoxSize();
25569 this.setThumbBoxPosition();
25570 this.setCanvasPosition();
25575 this.fireEvent('rotate', this, 'right');
25578 onRotateFail : function()
25580 this.errorEl.show(true);
25584 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
25589 this.previewEl.dom.innerHTML = '';
25591 var canvasEl = document.createElement("canvas");
25593 var contextEl = canvasEl.getContext("2d");
25595 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
25596 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
25597 var center = this.imageEl.OriginWidth / 2;
25599 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
25600 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
25601 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
25602 center = this.imageEl.OriginHeight / 2;
25605 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
25607 contextEl.translate(center, center);
25608 contextEl.rotate(this.rotate * Math.PI / 180);
25610 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
25612 this.canvasEl = document.createElement("canvas");
25614 this.contextEl = this.canvasEl.getContext("2d");
25616 switch (this.rotate) {
25619 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
25620 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
25622 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
25627 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
25628 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
25630 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
25631 this.contextEl.drawImage(canvasEl, Math.abs(this.canvasEl.width - this.canvasEl.height), 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
25635 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
25640 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
25641 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
25643 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
25644 this.contextEl.drawImage(canvasEl, 0, Math.abs(this.canvasEl.width - this.canvasEl.height), this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
25648 this.contextEl.drawImage(canvasEl, Math.abs(this.canvasEl.width - this.canvasEl.height), 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
25653 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
25654 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
25656 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
25657 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
25661 this.contextEl.drawImage(canvasEl, 0, Math.abs(this.canvasEl.width - this.canvasEl.height), this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
25668 this.previewEl.appendChild(this.canvasEl);
25670 this.setCanvasPosition();
25675 if(!this.canvasLoaded){
25679 var imageCanvas = document.createElement("canvas");
25681 var imageContext = imageCanvas.getContext("2d");
25683 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
25684 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
25686 var center = imageCanvas.width / 2;
25688 imageContext.translate(center, center);
25690 imageContext.rotate(this.rotate * Math.PI / 180);
25692 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
25694 var canvas = document.createElement("canvas");
25696 var context = canvas.getContext("2d");
25698 canvas.width = this.minWidth;
25699 canvas.height = this.minHeight;
25701 switch (this.rotate) {
25704 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
25705 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
25707 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
25708 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
25710 var targetWidth = this.minWidth - 2 * x;
25711 var targetHeight = this.minHeight - 2 * y;
25715 if((x == 0 && y == 0) || (x == 0 && y > 0)){
25716 scale = targetWidth / width;
25719 if(x > 0 && y == 0){
25720 scale = targetHeight / height;
25723 if(x > 0 && y > 0){
25724 scale = targetWidth / width;
25726 if(width < height){
25727 scale = targetHeight / height;
25731 context.scale(scale, scale);
25733 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
25734 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
25736 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
25737 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
25739 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
25744 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
25745 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
25747 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
25748 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
25750 var targetWidth = this.minWidth - 2 * x;
25751 var targetHeight = this.minHeight - 2 * y;
25755 if((x == 0 && y == 0) || (x == 0 && y > 0)){
25756 scale = targetWidth / width;
25759 if(x > 0 && y == 0){
25760 scale = targetHeight / height;
25763 if(x > 0 && y > 0){
25764 scale = targetWidth / width;
25766 if(width < height){
25767 scale = targetHeight / height;
25771 context.scale(scale, scale);
25773 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
25774 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
25776 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
25777 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
25779 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
25781 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
25786 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
25787 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
25789 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
25790 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
25792 var targetWidth = this.minWidth - 2 * x;
25793 var targetHeight = this.minHeight - 2 * y;
25797 if((x == 0 && y == 0) || (x == 0 && y > 0)){
25798 scale = targetWidth / width;
25801 if(x > 0 && y == 0){
25802 scale = targetHeight / height;
25805 if(x > 0 && y > 0){
25806 scale = targetWidth / width;
25808 if(width < height){
25809 scale = targetHeight / height;
25813 context.scale(scale, scale);
25815 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
25816 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
25818 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
25819 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
25821 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
25822 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
25824 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
25829 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
25830 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
25832 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
25833 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
25835 var targetWidth = this.minWidth - 2 * x;
25836 var targetHeight = this.minHeight - 2 * y;
25840 if((x == 0 && y == 0) || (x == 0 && y > 0)){
25841 scale = targetWidth / width;
25844 if(x > 0 && y == 0){
25845 scale = targetHeight / height;
25848 if(x > 0 && y > 0){
25849 scale = targetWidth / width;
25851 if(width < height){
25852 scale = targetHeight / height;
25856 context.scale(scale, scale);
25858 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
25859 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
25861 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
25862 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
25864 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
25866 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
25873 this.cropData = canvas.toDataURL(this.cropType);
25875 if(this.fireEvent('crop', this, this.cropData) !== false){
25876 this.process(this.file, this.cropData);
25883 setThumbBoxSize : function()
25887 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
25888 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
25889 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
25891 this.minWidth = width;
25892 this.minHeight = height;
25894 if(this.rotate == 90 || this.rotate == 270){
25895 this.minWidth = height;
25896 this.minHeight = width;
25901 width = Math.ceil(this.minWidth * height / this.minHeight);
25903 if(this.minWidth > this.minHeight){
25905 height = Math.ceil(this.minHeight * width / this.minWidth);
25908 this.thumbEl.setStyle({
25909 width : width + 'px',
25910 height : height + 'px'
25917 setThumbBoxPosition : function()
25919 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
25920 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
25922 this.thumbEl.setLeft(x);
25923 this.thumbEl.setTop(y);
25927 baseRotateLevel : function()
25929 this.baseRotate = 1;
25932 typeof(this.exif) != 'undefined' &&
25933 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
25934 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
25936 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
25939 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
25943 baseScaleLevel : function()
25947 if(this.isDocument){
25949 if(this.baseRotate == 6 || this.baseRotate == 8){
25951 height = this.thumbEl.getHeight();
25952 this.baseScale = height / this.imageEl.OriginWidth;
25954 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
25955 width = this.thumbEl.getWidth();
25956 this.baseScale = width / this.imageEl.OriginHeight;
25962 height = this.thumbEl.getHeight();
25963 this.baseScale = height / this.imageEl.OriginHeight;
25965 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
25966 width = this.thumbEl.getWidth();
25967 this.baseScale = width / this.imageEl.OriginWidth;
25973 if(this.baseRotate == 6 || this.baseRotate == 8){
25975 width = this.thumbEl.getHeight();
25976 this.baseScale = width / this.imageEl.OriginHeight;
25978 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
25979 height = this.thumbEl.getWidth();
25980 this.baseScale = height / this.imageEl.OriginHeight;
25983 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
25984 height = this.thumbEl.getWidth();
25985 this.baseScale = height / this.imageEl.OriginHeight;
25987 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
25988 width = this.thumbEl.getHeight();
25989 this.baseScale = width / this.imageEl.OriginWidth;
25996 width = this.thumbEl.getWidth();
25997 this.baseScale = width / this.imageEl.OriginWidth;
25999 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
26000 height = this.thumbEl.getHeight();
26001 this.baseScale = height / this.imageEl.OriginHeight;
26004 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
26006 height = this.thumbEl.getHeight();
26007 this.baseScale = height / this.imageEl.OriginHeight;
26009 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
26010 width = this.thumbEl.getWidth();
26011 this.baseScale = width / this.imageEl.OriginWidth;
26019 getScaleLevel : function()
26021 return this.baseScale * Math.pow(1.1, this.scale);
26024 onTouchStart : function(e)
26026 if(!this.canvasLoaded){
26027 this.beforeSelectFile(e);
26031 var touches = e.browserEvent.touches;
26037 if(touches.length == 1){
26038 this.onMouseDown(e);
26042 if(touches.length != 2){
26048 for(var i = 0, finger; finger = touches[i]; i++){
26049 coords.push(finger.pageX, finger.pageY);
26052 var x = Math.pow(coords[0] - coords[2], 2);
26053 var y = Math.pow(coords[1] - coords[3], 2);
26055 this.startDistance = Math.sqrt(x + y);
26057 this.startScale = this.scale;
26059 this.pinching = true;
26060 this.dragable = false;
26064 onTouchMove : function(e)
26066 if(!this.pinching && !this.dragable){
26070 var touches = e.browserEvent.touches;
26077 this.onMouseMove(e);
26083 for(var i = 0, finger; finger = touches[i]; i++){
26084 coords.push(finger.pageX, finger.pageY);
26087 var x = Math.pow(coords[0] - coords[2], 2);
26088 var y = Math.pow(coords[1] - coords[3], 2);
26090 this.endDistance = Math.sqrt(x + y);
26092 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
26094 if(!this.zoomable()){
26095 this.scale = this.startScale;
26103 onTouchEnd : function(e)
26105 this.pinching = false;
26106 this.dragable = false;
26110 process : function(file, crop)
26113 this.maskEl.mask(this.loadingText);
26116 this.xhr = new XMLHttpRequest();
26118 file.xhr = this.xhr;
26120 this.xhr.open(this.method, this.url, true);
26123 "Accept": "application/json",
26124 "Cache-Control": "no-cache",
26125 "X-Requested-With": "XMLHttpRequest"
26128 for (var headerName in headers) {
26129 var headerValue = headers[headerName];
26131 this.xhr.setRequestHeader(headerName, headerValue);
26137 this.xhr.onload = function()
26139 _this.xhrOnLoad(_this.xhr);
26142 this.xhr.onerror = function()
26144 _this.xhrOnError(_this.xhr);
26147 var formData = new FormData();
26149 formData.append('returnHTML', 'NO');
26152 formData.append('crop', crop);
26155 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
26156 formData.append(this.paramName, file, file.name);
26159 if(typeof(file.filename) != 'undefined'){
26160 formData.append('filename', file.filename);
26163 if(typeof(file.mimetype) != 'undefined'){
26164 formData.append('mimetype', file.mimetype);
26167 if(this.fireEvent('arrange', this, formData) != false){
26168 this.xhr.send(formData);
26172 xhrOnLoad : function(xhr)
26175 this.maskEl.unmask();
26178 if (xhr.readyState !== 4) {
26179 this.fireEvent('exception', this, xhr);
26183 var response = Roo.decode(xhr.responseText);
26185 if(!response.success){
26186 this.fireEvent('exception', this, xhr);
26190 var response = Roo.decode(xhr.responseText);
26192 this.fireEvent('upload', this, response);
26196 xhrOnError : function()
26199 this.maskEl.unmask();
26202 Roo.log('xhr on error');
26204 var response = Roo.decode(xhr.responseText);
26210 prepare : function(file)
26213 this.maskEl.mask(this.loadingText);
26219 if(typeof(file) === 'string'){
26220 this.loadCanvas(file);
26224 if(!file || !this.urlAPI){
26229 this.cropType = file.type;
26233 if(this.fireEvent('prepare', this, this.file) != false){
26235 var reader = new FileReader();
26237 reader.onload = function (e) {
26238 if (e.target.error) {
26239 Roo.log(e.target.error);
26243 var buffer = e.target.result,
26244 dataView = new DataView(buffer),
26246 maxOffset = dataView.byteLength - 4,
26250 if (dataView.getUint16(0) === 0xffd8) {
26251 while (offset < maxOffset) {
26252 markerBytes = dataView.getUint16(offset);
26254 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
26255 markerLength = dataView.getUint16(offset + 2) + 2;
26256 if (offset + markerLength > dataView.byteLength) {
26257 Roo.log('Invalid meta data: Invalid segment size.');
26261 if(markerBytes == 0xffe1){
26262 _this.parseExifData(
26269 offset += markerLength;
26279 var url = _this.urlAPI.createObjectURL(_this.file);
26281 _this.loadCanvas(url);
26286 reader.readAsArrayBuffer(this.file);
26292 parseExifData : function(dataView, offset, length)
26294 var tiffOffset = offset + 10,
26298 if (dataView.getUint32(offset + 4) !== 0x45786966) {
26299 // No Exif data, might be XMP data instead
26303 // Check for the ASCII code for "Exif" (0x45786966):
26304 if (dataView.getUint32(offset + 4) !== 0x45786966) {
26305 // No Exif data, might be XMP data instead
26308 if (tiffOffset + 8 > dataView.byteLength) {
26309 Roo.log('Invalid Exif data: Invalid segment size.');
26312 // Check for the two null bytes:
26313 if (dataView.getUint16(offset + 8) !== 0x0000) {
26314 Roo.log('Invalid Exif data: Missing byte alignment offset.');
26317 // Check the byte alignment:
26318 switch (dataView.getUint16(tiffOffset)) {
26320 littleEndian = true;
26323 littleEndian = false;
26326 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
26329 // Check for the TIFF tag marker (0x002A):
26330 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
26331 Roo.log('Invalid Exif data: Missing TIFF marker.');
26334 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
26335 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
26337 this.parseExifTags(
26340 tiffOffset + dirOffset,
26345 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
26350 if (dirOffset + 6 > dataView.byteLength) {
26351 Roo.log('Invalid Exif data: Invalid directory offset.');
26354 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
26355 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
26356 if (dirEndOffset + 4 > dataView.byteLength) {
26357 Roo.log('Invalid Exif data: Invalid directory size.');
26360 for (i = 0; i < tagsNumber; i += 1) {
26364 dirOffset + 2 + 12 * i, // tag offset
26368 // Return the offset to the next directory:
26369 return dataView.getUint32(dirEndOffset, littleEndian);
26372 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
26374 var tag = dataView.getUint16(offset, littleEndian);
26376 this.exif[tag] = this.getExifValue(
26380 dataView.getUint16(offset + 2, littleEndian), // tag type
26381 dataView.getUint32(offset + 4, littleEndian), // tag length
26386 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
26388 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
26397 Roo.log('Invalid Exif data: Invalid tag type.');
26401 tagSize = tagType.size * length;
26402 // Determine if the value is contained in the dataOffset bytes,
26403 // or if the value at the dataOffset is a pointer to the actual data:
26404 dataOffset = tagSize > 4 ?
26405 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
26406 if (dataOffset + tagSize > dataView.byteLength) {
26407 Roo.log('Invalid Exif data: Invalid data offset.');
26410 if (length === 1) {
26411 return tagType.getValue(dataView, dataOffset, littleEndian);
26414 for (i = 0; i < length; i += 1) {
26415 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
26418 if (tagType.ascii) {
26420 // Concatenate the chars:
26421 for (i = 0; i < values.length; i += 1) {
26423 // Ignore the terminating NULL byte(s):
26424 if (c === '\u0000') {
26436 Roo.apply(Roo.bootstrap.UploadCropbox, {
26438 'Orientation': 0x0112
26442 1: 0, //'top-left',
26444 3: 180, //'bottom-right',
26445 // 4: 'bottom-left',
26447 6: 90, //'right-top',
26448 // 7: 'right-bottom',
26449 8: 270 //'left-bottom'
26453 // byte, 8-bit unsigned int:
26455 getValue: function (dataView, dataOffset) {
26456 return dataView.getUint8(dataOffset);
26460 // ascii, 8-bit byte:
26462 getValue: function (dataView, dataOffset) {
26463 return String.fromCharCode(dataView.getUint8(dataOffset));
26468 // short, 16 bit int:
26470 getValue: function (dataView, dataOffset, littleEndian) {
26471 return dataView.getUint16(dataOffset, littleEndian);
26475 // long, 32 bit int:
26477 getValue: function (dataView, dataOffset, littleEndian) {
26478 return dataView.getUint32(dataOffset, littleEndian);
26482 // rational = two long values, first is numerator, second is denominator:
26484 getValue: function (dataView, dataOffset, littleEndian) {
26485 return dataView.getUint32(dataOffset, littleEndian) /
26486 dataView.getUint32(dataOffset + 4, littleEndian);
26490 // slong, 32 bit signed int:
26492 getValue: function (dataView, dataOffset, littleEndian) {
26493 return dataView.getInt32(dataOffset, littleEndian);
26497 // srational, two slongs, first is numerator, second is denominator:
26499 getValue: function (dataView, dataOffset, littleEndian) {
26500 return dataView.getInt32(dataOffset, littleEndian) /
26501 dataView.getInt32(dataOffset + 4, littleEndian);
26511 cls : 'btn-group roo-upload-cropbox-rotate-left',
26512 action : 'rotate-left',
26516 cls : 'btn btn-default',
26517 html : '<i class="fa fa-undo"></i>'
26523 cls : 'btn-group roo-upload-cropbox-picture',
26524 action : 'picture',
26528 cls : 'btn btn-default',
26529 html : '<i class="fa fa-picture-o"></i>'
26535 cls : 'btn-group roo-upload-cropbox-rotate-right',
26536 action : 'rotate-right',
26540 cls : 'btn btn-default',
26541 html : '<i class="fa fa-repeat"></i>'
26549 cls : 'btn-group roo-upload-cropbox-rotate-left',
26550 action : 'rotate-left',
26554 cls : 'btn btn-default',
26555 html : '<i class="fa fa-undo"></i>'
26561 cls : 'btn-group roo-upload-cropbox-download',
26562 action : 'download',
26566 cls : 'btn btn-default',
26567 html : '<i class="fa fa-download"></i>'
26573 cls : 'btn-group roo-upload-cropbox-crop',
26578 cls : 'btn btn-default',
26579 html : '<i class="fa fa-crop"></i>'
26585 cls : 'btn-group roo-upload-cropbox-trash',
26590 cls : 'btn btn-default',
26591 html : '<i class="fa fa-trash"></i>'
26597 cls : 'btn-group roo-upload-cropbox-rotate-right',
26598 action : 'rotate-right',
26602 cls : 'btn btn-default',
26603 html : '<i class="fa fa-repeat"></i>'
26611 cls : 'btn-group roo-upload-cropbox-rotate-left',
26612 action : 'rotate-left',
26616 cls : 'btn btn-default',
26617 html : '<i class="fa fa-undo"></i>'
26623 cls : 'btn-group roo-upload-cropbox-rotate-right',
26624 action : 'rotate-right',
26628 cls : 'btn btn-default',
26629 html : '<i class="fa fa-repeat"></i>'
26642 * @class Roo.bootstrap.DocumentManager
26643 * @extends Roo.bootstrap.Component
26644 * Bootstrap DocumentManager class
26645 * @cfg {String} paramName default 'imageUpload'
26646 * @cfg {String} method default POST
26647 * @cfg {String} url action url
26648 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
26649 * @cfg {Boolean} multiple multiple upload default true
26650 * @cfg {Number} thumbSize default 300
26651 * @cfg {String} fieldLabel
26652 * @cfg {Number} labelWidth default 4
26653 * @cfg {String} labelAlign (left|top) default left
26654 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
26657 * Create a new DocumentManager
26658 * @param {Object} config The config object
26661 Roo.bootstrap.DocumentManager = function(config){
26662 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
26667 * Fire when initial the DocumentManager
26668 * @param {Roo.bootstrap.DocumentManager} this
26673 * inspect selected file
26674 * @param {Roo.bootstrap.DocumentManager} this
26675 * @param {File} file
26680 * Fire when xhr load exception
26681 * @param {Roo.bootstrap.DocumentManager} this
26682 * @param {XMLHttpRequest} xhr
26684 "exception" : true,
26687 * prepare the form data
26688 * @param {Roo.bootstrap.DocumentManager} this
26689 * @param {Object} formData
26694 * Fire when remove the file
26695 * @param {Roo.bootstrap.DocumentManager} this
26696 * @param {Object} file
26701 * Fire after refresh the file
26702 * @param {Roo.bootstrap.DocumentManager} this
26707 * Fire after click the image
26708 * @param {Roo.bootstrap.DocumentManager} this
26709 * @param {Object} file
26714 * Fire when upload a image and editable set to true
26715 * @param {Roo.bootstrap.DocumentManager} this
26716 * @param {Object} file
26720 * @event beforeselectfile
26721 * Fire before select file
26722 * @param {Roo.bootstrap.DocumentManager} this
26724 "beforeselectfile" : true,
26727 * Fire before process file
26728 * @param {Roo.bootstrap.DocumentManager} this
26729 * @param {Object} file
26736 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
26745 paramName : 'imageUpload',
26748 labelAlign : 'left',
26755 getAutoCreate : function()
26757 var managerWidget = {
26759 cls : 'roo-document-manager',
26763 cls : 'roo-document-manager-selector',
26768 cls : 'roo-document-manager-uploader',
26772 cls : 'roo-document-manager-upload-btn',
26773 html : '<i class="fa fa-plus"></i>'
26784 cls : 'column col-md-12',
26789 if(this.fieldLabel.length){
26794 cls : 'column col-md-12',
26795 html : this.fieldLabel
26799 cls : 'column col-md-12',
26804 if(this.labelAlign == 'left'){
26808 cls : 'column col-md-' + this.labelWidth,
26809 html : this.fieldLabel
26813 cls : 'column col-md-' + (12 - this.labelWidth),
26823 cls : 'row clearfix',
26831 initEvents : function()
26833 this.managerEl = this.el.select('.roo-document-manager', true).first();
26834 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26836 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
26837 this.selectorEl.hide();
26840 this.selectorEl.attr('multiple', 'multiple');
26843 this.selectorEl.on('change', this.onFileSelected, this);
26845 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
26846 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26848 this.uploader.on('click', this.onUploaderClick, this);
26850 this.renderProgressDialog();
26854 window.addEventListener("resize", function() { _this.refresh(); } );
26856 this.fireEvent('initial', this);
26859 renderProgressDialog : function()
26863 this.progressDialog = new Roo.bootstrap.Modal({
26864 cls : 'roo-document-manager-progress-dialog',
26865 allow_close : false,
26875 btnclick : function() {
26876 _this.uploadCancel();
26882 this.progressDialog.render(Roo.get(document.body));
26884 this.progress = new Roo.bootstrap.Progress({
26885 cls : 'roo-document-manager-progress',
26890 this.progress.render(this.progressDialog.getChildContainer());
26892 this.progressBar = new Roo.bootstrap.ProgressBar({
26893 cls : 'roo-document-manager-progress-bar',
26896 aria_valuemax : 12,
26900 this.progressBar.render(this.progress.getChildContainer());
26903 onUploaderClick : function(e)
26905 e.preventDefault();
26907 if(this.fireEvent('beforeselectfile', this) != false){
26908 this.selectorEl.dom.click();
26913 onFileSelected : function(e)
26915 e.preventDefault();
26917 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
26921 Roo.each(this.selectorEl.dom.files, function(file){
26922 if(this.fireEvent('inspect', this, file) != false){
26923 this.files.push(file);
26933 this.selectorEl.dom.value = '';
26935 if(!this.files.length){
26939 if(this.boxes > 0 && this.files.length > this.boxes){
26940 this.files = this.files.slice(0, this.boxes);
26943 this.uploader.show();
26945 if(this.boxes > 0 && this.files.length > this.boxes - 1){
26946 this.uploader.hide();
26955 Roo.each(this.files, function(file){
26957 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
26958 var f = this.renderPreview(file);
26963 if(file.type.indexOf('image') != -1){
26964 this.delegates.push(
26966 _this.process(file);
26967 }).createDelegate(this)
26975 _this.process(file);
26976 }).createDelegate(this)
26981 this.files = files;
26983 this.delegates = this.delegates.concat(docs);
26985 if(!this.delegates.length){
26990 this.progressBar.aria_valuemax = this.delegates.length;
26997 arrange : function()
26999 if(!this.delegates.length){
27000 this.progressDialog.hide();
27005 var delegate = this.delegates.shift();
27007 this.progressDialog.show();
27009 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
27011 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
27016 refresh : function()
27018 this.uploader.show();
27020 if(this.boxes > 0 && this.files.length > this.boxes - 1){
27021 this.uploader.hide();
27024 Roo.isTouch ? this.closable(false) : this.closable(true);
27026 this.fireEvent('refresh', this);
27029 onRemove : function(e, el, o)
27031 e.preventDefault();
27033 this.fireEvent('remove', this, o);
27037 remove : function(o)
27041 Roo.each(this.files, function(file){
27042 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
27051 this.files = files;
27058 Roo.each(this.files, function(file){
27063 file.target.remove();
27072 onClick : function(e, el, o)
27074 e.preventDefault();
27076 this.fireEvent('click', this, o);
27080 closable : function(closable)
27082 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
27084 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27096 xhrOnLoad : function(xhr)
27098 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
27102 if (xhr.readyState !== 4) {
27104 this.fireEvent('exception', this, xhr);
27108 var response = Roo.decode(xhr.responseText);
27110 if(!response.success){
27112 this.fireEvent('exception', this, xhr);
27116 var file = this.renderPreview(response.data);
27118 this.files.push(file);
27124 xhrOnError : function(xhr)
27126 Roo.log('xhr on error');
27128 var response = Roo.decode(xhr.responseText);
27135 process : function(file)
27137 if(this.fireEvent('process', this, file) !== false){
27138 if(this.editable && file.type.indexOf('image') != -1){
27139 this.fireEvent('edit', this, file);
27143 this.uploadStart(file, false);
27150 uploadStart : function(file, crop)
27152 this.xhr = new XMLHttpRequest();
27154 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
27159 file.xhr = this.xhr;
27161 this.managerEl.createChild({
27163 cls : 'roo-document-manager-loading',
27167 tooltip : file.name,
27168 cls : 'roo-document-manager-thumb',
27169 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
27175 this.xhr.open(this.method, this.url, true);
27178 "Accept": "application/json",
27179 "Cache-Control": "no-cache",
27180 "X-Requested-With": "XMLHttpRequest"
27183 for (var headerName in headers) {
27184 var headerValue = headers[headerName];
27186 this.xhr.setRequestHeader(headerName, headerValue);
27192 this.xhr.onload = function()
27194 _this.xhrOnLoad(_this.xhr);
27197 this.xhr.onerror = function()
27199 _this.xhrOnError(_this.xhr);
27202 var formData = new FormData();
27204 formData.append('returnHTML', 'NO');
27207 formData.append('crop', crop);
27210 formData.append(this.paramName, file, file.name);
27212 if(this.fireEvent('prepare', this, formData) != false){
27213 this.xhr.send(formData);
27217 uploadCancel : function()
27224 this.delegates = [];
27226 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
27233 renderPreview : function(file)
27235 if(typeof(file.target) != 'undefined' && file.target){
27239 var previewEl = this.managerEl.createChild({
27241 cls : 'roo-document-manager-preview',
27245 tooltip : file.filename,
27246 cls : 'roo-document-manager-thumb',
27247 html : '<img src="' + baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename + '">'
27252 html : '<i class="fa fa-times-circle"></i>'
27257 var close = previewEl.select('button.close', true).first();
27259 close.on('click', this.onRemove, this, file);
27261 file.target = previewEl;
27263 var image = previewEl.select('img', true).first();
27267 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
27269 image.on('click', this.onClick, this, file);
27275 onPreviewLoad : function(file, image)
27277 if(typeof(file.target) == 'undefined' || !file.target){
27281 var width = image.dom.naturalWidth || image.dom.width;
27282 var height = image.dom.naturalHeight || image.dom.height;
27284 if(width > height){
27285 file.target.addClass('wide');
27289 file.target.addClass('tall');
27294 uploadFromSource : function(file, crop)
27296 this.xhr = new XMLHttpRequest();
27298 this.managerEl.createChild({
27300 cls : 'roo-document-manager-loading',
27304 tooltip : file.name,
27305 cls : 'roo-document-manager-thumb',
27306 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
27312 this.xhr.open(this.method, this.url, true);
27315 "Accept": "application/json",
27316 "Cache-Control": "no-cache",
27317 "X-Requested-With": "XMLHttpRequest"
27320 for (var headerName in headers) {
27321 var headerValue = headers[headerName];
27323 this.xhr.setRequestHeader(headerName, headerValue);
27329 this.xhr.onload = function()
27331 _this.xhrOnLoad(_this.xhr);
27334 this.xhr.onerror = function()
27336 _this.xhrOnError(_this.xhr);
27339 var formData = new FormData();
27341 formData.append('returnHTML', 'NO');
27343 formData.append('crop', crop);
27345 if(typeof(file.filename) != 'undefined'){
27346 formData.append('filename', file.filename);
27349 if(typeof(file.mimetype) != 'undefined'){
27350 formData.append('mimetype', file.mimetype);
27353 if(this.fireEvent('prepare', this, formData) != false){
27354 this.xhr.send(formData);
27364 * @class Roo.bootstrap.DocumentViewer
27365 * @extends Roo.bootstrap.Component
27366 * Bootstrap DocumentViewer class
27369 * Create a new DocumentViewer
27370 * @param {Object} config The config object
27373 Roo.bootstrap.DocumentViewer = function(config){
27374 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
27379 * Fire after initEvent
27380 * @param {Roo.bootstrap.DocumentViewer} this
27386 * @param {Roo.bootstrap.DocumentViewer} this
27391 * Fire after trash button
27392 * @param {Roo.bootstrap.DocumentViewer} this
27399 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
27401 getAutoCreate : function()
27405 cls : 'roo-document-viewer',
27409 cls : 'roo-document-viewer-body',
27413 cls : 'roo-document-viewer-thumb',
27417 cls : 'roo-document-viewer-image'
27425 cls : 'roo-document-viewer-footer',
27428 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
27436 cls : 'btn btn-default roo-document-viewer-trash',
27437 html : '<i class="fa fa-trash"></i>'
27450 initEvents : function()
27453 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
27454 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27456 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
27457 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27459 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
27460 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27462 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
27463 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27465 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
27466 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27468 this.bodyEl.on('click', this.onClick, this);
27470 this.trashBtn.on('click', this.onTrash, this);
27474 initial : function()
27476 // this.thumbEl.setStyle('line-height', this.thumbEl.getHeight(true) + 'px');
27479 this.fireEvent('initial', this);
27483 onClick : function(e)
27485 e.preventDefault();
27487 this.fireEvent('click', this);
27490 onTrash : function(e)
27492 e.preventDefault();
27494 this.fireEvent('trash', this);
27506 * @class Roo.bootstrap.NavProgressBar
27507 * @extends Roo.bootstrap.Component
27508 * Bootstrap NavProgressBar class
27511 * Create a new nav progress bar
27512 * @param {Object} config The config object
27515 Roo.bootstrap.NavProgressBar = function(config){
27516 Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
27518 this.bullets = this.bullets || [];
27520 // Roo.bootstrap.NavProgressBar.register(this);
27524 * Fires when the active item changes
27525 * @param {Roo.bootstrap.NavProgressBar} this
27526 * @param {Roo.bootstrap.NavProgressItem} selected The item selected
27527 * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item
27534 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component, {
27539 getAutoCreate : function()
27541 var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
27545 cls : 'roo-navigation-bar-group',
27549 cls : 'roo-navigation-top-bar'
27553 cls : 'roo-navigation-bullets-bar',
27557 cls : 'roo-navigation-bar'
27564 cls : 'roo-navigation-bottom-bar'
27574 initEvents: function()
27579 onRender : function(ct, position)
27581 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
27583 if(this.bullets.length){
27584 Roo.each(this.bullets, function(b){
27593 addItem : function(cfg)
27595 var item = new Roo.bootstrap.NavProgressItem(cfg);
27597 item.parentId = this.id;
27598 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
27601 var top = new Roo.bootstrap.Element({
27603 cls : 'roo-navigation-bar-text'
27606 var bottom = new Roo.bootstrap.Element({
27608 cls : 'roo-navigation-bar-text'
27611 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
27612 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
27614 var topText = new Roo.bootstrap.Element({
27616 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
27619 var bottomText = new Roo.bootstrap.Element({
27621 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
27624 topText.onRender(top.el, null);
27625 bottomText.onRender(bottom.el, null);
27628 item.bottomEl = bottom;
27631 this.barItems.push(item);
27636 getActive : function()
27638 var active = false;
27640 Roo.each(this.barItems, function(v){
27642 if (!v.isActive()) {
27654 setActiveItem : function(item)
27658 Roo.each(this.barItems, function(v){
27659 if (v.rid == item.rid) {
27663 if (v.isActive()) {
27664 v.setActive(false);
27669 item.setActive(true);
27671 this.fireEvent('changed', this, item, prev);
27674 getBarItem: function(rid)
27678 Roo.each(this.barItems, function(e) {
27679 if (e.rid != rid) {
27690 indexOfItem : function(item)
27694 Roo.each(this.barItems, function(v, i){
27696 if (v.rid != item.rid) {
27707 setActiveNext : function()
27709 var i = this.indexOfItem(this.getActive());
27711 if (i > this.barItems.length) {
27715 this.setActiveItem(this.barItems[i+1]);
27718 setActivePrev : function()
27720 var i = this.indexOfItem(this.getActive());
27726 this.setActiveItem(this.barItems[i-1]);
27729 format : function()
27731 if(!this.barItems.length){
27735 var width = 100 / this.barItems.length;
27737 Roo.each(this.barItems, function(i){
27738 i.el.setStyle('width', width + '%');
27739 i.topEl.el.setStyle('width', width + '%');
27740 i.bottomEl.el.setStyle('width', width + '%');
27749 * Nav Progress Item
27754 * @class Roo.bootstrap.NavProgressItem
27755 * @extends Roo.bootstrap.Component
27756 * Bootstrap NavProgressItem class
27757 * @cfg {String} rid the reference id
27758 * @cfg {Boolean} active (true|false) Is item active default false
27759 * @cfg {Boolean} disabled (true|false) Is item active default false
27760 * @cfg {String} html
27761 * @cfg {String} position (top|bottom) text position default bottom
27762 * @cfg {String} icon show icon instead of number
27765 * Create a new NavProgressItem
27766 * @param {Object} config The config object
27768 Roo.bootstrap.NavProgressItem = function(config){
27769 Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
27774 * The raw click event for the entire grid.
27775 * @param {Roo.bootstrap.NavProgressItem} this
27776 * @param {Roo.EventObject} e
27783 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component, {
27789 position : 'bottom',
27792 getAutoCreate : function()
27794 var iconCls = 'roo-navigation-bar-item-icon';
27796 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
27800 cls: 'roo-navigation-bar-item',
27810 cfg.cls += ' active';
27813 cfg.cls += ' disabled';
27819 disable : function()
27821 this.setDisabled(true);
27824 enable : function()
27826 this.setDisabled(false);
27829 initEvents: function()
27831 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
27833 this.iconEl.on('click', this.onClick, this);
27836 onClick : function(e)
27838 e.preventDefault();
27844 if(this.fireEvent('click', this, e) === false){
27848 this.parent().setActiveItem(this);
27851 isActive: function ()
27853 return this.active;
27856 setActive : function(state)
27858 if(this.active == state){
27862 this.active = state;
27865 this.el.addClass('active');
27869 this.el.removeClass('active');
27874 setDisabled : function(state)
27876 if(this.disabled == state){
27880 this.disabled = state;
27883 this.el.addClass('disabled');
27887 this.el.removeClass('disabled');
27890 tooltipEl : function()
27892 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
27905 * @class Roo.bootstrap.FieldLabel
27906 * @extends Roo.bootstrap.Component
27907 * Bootstrap FieldLabel class
27908 * @cfg {String} html contents of the element
27909 * @cfg {String} tag tag of the element default label
27910 * @cfg {String} cls class of the element
27911 * @cfg {String} target label target
27912 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
27913 * @cfg {String} invalidClass default "text-danger fa fa-lg fa-exclamation-triangle"
27914 * @cfg {String} validClass default "text-success fa fa-lg fa-check"
27915 * @cfg {String} iconTooltip default "This field is required"
27918 * Create a new FieldLabel
27919 * @param {Object} config The config object
27922 Roo.bootstrap.FieldLabel = function(config){
27923 Roo.bootstrap.Element.superclass.constructor.call(this, config);
27928 * Fires after the field has been marked as invalid.
27929 * @param {Roo.form.FieldLabel} this
27930 * @param {String} msg The validation message
27935 * Fires after the field has been validated with no errors.
27936 * @param {Roo.form.FieldLabel} this
27942 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component, {
27949 invalidClass : 'text-danger fa fa-lg fa-exclamation-triangle',
27950 validClass : 'text-success fa fa-lg fa-check',
27951 iconTooltip : 'This field is required',
27953 getAutoCreate : function(){
27957 cls : 'roo-bootstrap-field-label ' + this.cls,
27963 tooltip : this.iconTooltip
27975 initEvents: function()
27977 Roo.bootstrap.Element.superclass.initEvents.call(this);
27979 this.iconEl = this.el.select('i', true).first();
27981 this.iconEl.setVisibilityMode(Roo.Element.DISPLAY).hide();
27983 Roo.bootstrap.FieldLabel.register(this);
27987 * Mark this field as valid
27989 markValid : function()
27991 this.iconEl.show();
27993 this.iconEl.removeClass(this.invalidClass);
27995 this.iconEl.addClass(this.validClass);
27997 this.fireEvent('valid', this);
28001 * Mark this field as invalid
28002 * @param {String} msg The validation message
28004 markInvalid : function(msg)
28006 this.iconEl.show();
28008 this.iconEl.removeClass(this.validClass);
28010 this.iconEl.addClass(this.invalidClass);
28012 this.fireEvent('invalid', this, msg);
28018 Roo.apply(Roo.bootstrap.FieldLabel, {
28023 * register a FieldLabel Group
28024 * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
28026 register : function(label)
28028 if(this.groups.hasOwnProperty(label.target)){
28032 this.groups[label.target] = label;
28036 * fetch a FieldLabel Group based on the target
28037 * @param {string} target
28038 * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
28040 get: function(target) {
28041 if (typeof(this.groups[target]) == 'undefined') {
28045 return this.groups[target] ;
28054 * page DateSplitField.
28060 * @class Roo.bootstrap.DateSplitField
28061 * @extends Roo.bootstrap.Component
28062 * Bootstrap DateSplitField class
28063 * @cfg {string} fieldLabel - the label associated
28064 * @cfg {Number} labelWidth set the width of label (0-12)
28065 * @cfg {String} labelAlign (top|left)
28066 * @cfg {Boolean} dayAllowBlank (true|false) default false
28067 * @cfg {Boolean} monthAllowBlank (true|false) default false
28068 * @cfg {Boolean} yearAllowBlank (true|false) default false
28069 * @cfg {string} dayPlaceholder
28070 * @cfg {string} monthPlaceholder
28071 * @cfg {string} yearPlaceholder
28072 * @cfg {string} dayFormat default 'd'
28073 * @cfg {string} monthFormat default 'm'
28074 * @cfg {string} yearFormat default 'Y'
28078 * Create a new DateSplitField
28079 * @param {Object} config The config object
28082 Roo.bootstrap.DateSplitField = function(config){
28083 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
28089 * getting the data of years
28090 * @param {Roo.bootstrap.DateSplitField} this
28091 * @param {Object} years
28096 * getting the data of days
28097 * @param {Roo.bootstrap.DateSplitField} this
28098 * @param {Object} days
28103 * Fires after the field has been marked as invalid.
28104 * @param {Roo.form.Field} this
28105 * @param {String} msg The validation message
28110 * Fires after the field has been validated with no errors.
28111 * @param {Roo.form.Field} this
28117 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
28120 labelAlign : 'top',
28122 dayAllowBlank : false,
28123 monthAllowBlank : false,
28124 yearAllowBlank : false,
28125 dayPlaceholder : '',
28126 monthPlaceholder : '',
28127 yearPlaceholder : '',
28131 isFormField : true,
28133 getAutoCreate : function()
28137 cls : 'row roo-date-split-field-group',
28142 cls : 'form-hidden-field roo-date-split-field-group-value',
28148 if(this.fieldLabel){
28151 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
28155 html : this.fieldLabel
28161 Roo.each(['day', 'month', 'year'], function(t){
28164 cls : 'column roo-date-split-field-' + t + ' col-md-' + ((this.labelAlign == 'top') ? '4' : ((12 - this.labelWidth) / 3))
28171 inputEl: function ()
28173 return this.el.select('.roo-date-split-field-group-value', true).first();
28176 onRender : function(ct, position)
28180 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
28182 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
28184 this.dayField = new Roo.bootstrap.ComboBox({
28185 allowBlank : this.dayAllowBlank,
28186 alwaysQuery : true,
28187 displayField : 'value',
28190 forceSelection : true,
28192 placeholder : this.dayPlaceholder,
28193 selectOnFocus : true,
28194 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
28195 triggerAction : 'all',
28197 valueField : 'value',
28198 store : new Roo.data.SimpleStore({
28199 data : (function() {
28201 _this.fireEvent('days', _this, days);
28204 fields : [ 'value' ]
28207 select : function (_self, record, index)
28209 _this.setValue(_this.getValue());
28214 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
28216 this.monthField = new Roo.bootstrap.MonthField({
28217 after : '<i class=\"fa fa-calendar\"></i>',
28218 allowBlank : this.monthAllowBlank,
28219 placeholder : this.monthPlaceholder,
28222 render : function (_self)
28224 this.el.select('span.input-group-addon', true).first().on('click', function(e){
28225 e.preventDefault();
28229 select : function (_self, oldvalue, newvalue)
28231 _this.setValue(_this.getValue());
28236 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
28238 this.yearField = new Roo.bootstrap.ComboBox({
28239 allowBlank : this.yearAllowBlank,
28240 alwaysQuery : true,
28241 displayField : 'value',
28244 forceSelection : true,
28246 placeholder : this.yearPlaceholder,
28247 selectOnFocus : true,
28248 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
28249 triggerAction : 'all',
28251 valueField : 'value',
28252 store : new Roo.data.SimpleStore({
28253 data : (function() {
28255 _this.fireEvent('years', _this, years);
28258 fields : [ 'value' ]
28261 select : function (_self, record, index)
28263 _this.setValue(_this.getValue());
28268 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
28271 setValue : function(v, format)
28273 this.inputEl.dom.value = v;
28275 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
28277 var d = Date.parseDate(v, f);
28284 this.setDay(d.format(this.dayFormat));
28285 this.setMonth(d.format(this.monthFormat));
28286 this.setYear(d.format(this.yearFormat));
28293 setDay : function(v)
28295 this.dayField.setValue(v);
28296 this.inputEl.dom.value = this.getValue();
28301 setMonth : function(v)
28303 this.monthField.setValue(v, true);
28304 this.inputEl.dom.value = this.getValue();
28309 setYear : function(v)
28311 this.yearField.setValue(v);
28312 this.inputEl.dom.value = this.getValue();
28317 getDay : function()
28319 return this.dayField.getValue();
28322 getMonth : function()
28324 return this.monthField.getValue();
28327 getYear : function()
28329 return this.yearField.getValue();
28332 getValue : function()
28334 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
28336 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
28346 this.inputEl.dom.value = '';
28351 validate : function()
28353 var d = this.dayField.validate();
28354 var m = this.monthField.validate();
28355 var y = this.yearField.validate();
28360 (!this.dayAllowBlank && !d) ||
28361 (!this.monthAllowBlank && !m) ||
28362 (!this.yearAllowBlank && !y)
28367 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
28376 this.markInvalid();
28381 markValid : function()
28384 var label = this.el.select('label', true).first();
28385 var icon = this.el.select('i.fa-star', true).first();
28391 this.fireEvent('valid', this);
28395 * Mark this field as invalid
28396 * @param {String} msg The validation message
28398 markInvalid : function(msg)
28401 var label = this.el.select('label', true).first();
28402 var icon = this.el.select('i.fa-star', true).first();
28404 if(label && !icon){
28405 this.el.select('.roo-date-split-field-label', true).createChild({
28407 cls : 'text-danger fa fa-lg fa-star',
28408 tooltip : 'This field is required',
28409 style : 'margin-right:5px;'
28413 this.fireEvent('invalid', this, msg);
28416 clearInvalid : function()
28418 var label = this.el.select('label', true).first();
28419 var icon = this.el.select('i.fa-star', true).first();
28425 this.fireEvent('valid', this);
28428 getName: function()
28438 * http://masonry.desandro.com
28440 * The idea is to render all the bricks based on vertical width...
28442 * The original code extends 'outlayer' - we might need to use that....
28448 * @class Roo.bootstrap.LayoutMasonry
28449 * @extends Roo.bootstrap.Component
28450 * Bootstrap Layout Masonry class
28453 * Create a new Element
28454 * @param {Object} config The config object
28457 Roo.bootstrap.LayoutMasonry = function(config){
28458 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
28464 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
28467 * @cfg {Boolean} isLayoutInstant = no animation?
28469 isLayoutInstant : false, // needed?
28472 * @cfg {Number} boxWidth width of the columns
28477 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
28482 * @cfg {Number} padWidth padding below box..
28487 * @cfg {Number} gutter gutter width..
28492 * @cfg {Number} maxCols maximum number of columns
28498 * @cfg {Boolean} isAutoInitial defalut true
28500 isAutoInitial : true,
28505 * @cfg {Boolean} isHorizontal defalut false
28507 isHorizontal : false,
28509 currentSize : null,
28515 bricks: null, //CompositeElement
28519 _isLayoutInited : false,
28521 // isAlternative : false, // only use for vertical layout...
28524 * @cfg {Number} alternativePadWidth padding below box..
28526 alternativePadWidth : 50,
28528 getAutoCreate : function(){
28532 cls: 'blog-masonary-wrapper ' + this.cls,
28534 cls : 'mas-boxes masonary'
28541 getChildContainer: function( )
28543 if (this.boxesEl) {
28544 return this.boxesEl;
28547 this.boxesEl = this.el.select('.mas-boxes').first();
28549 return this.boxesEl;
28553 initEvents : function()
28557 if(this.isAutoInitial){
28558 Roo.log('hook children rendered');
28559 this.on('childrenrendered', function() {
28560 Roo.log('children rendered');
28566 initial : function()
28568 this.currentSize = this.el.getBox(true);
28570 Roo.EventManager.onWindowResize(this.resize, this);
28572 if(!this.isAutoInitial){
28580 //this.layout.defer(500,this);
28584 resize : function()
28588 var cs = this.el.getBox(true);
28590 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
28591 Roo.log("no change in with or X");
28595 this.currentSize = cs;
28601 layout : function()
28603 this._resetLayout();
28605 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
28607 this.layoutItems( isInstant );
28609 this._isLayoutInited = true;
28613 _resetLayout : function()
28615 if(this.isHorizontal){
28616 this.horizontalMeasureColumns();
28620 this.verticalMeasureColumns();
28624 verticalMeasureColumns : function()
28626 this.getContainerWidth();
28628 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
28629 // this.colWidth = Math.floor(this.containerWidth * 0.8);
28633 var boxWidth = this.boxWidth + this.padWidth;
28635 if(this.containerWidth < this.boxWidth){
28636 boxWidth = this.containerWidth
28639 var containerWidth = this.containerWidth;
28641 var cols = Math.floor(containerWidth / boxWidth);
28643 this.cols = Math.max( cols, 1 );
28645 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
28647 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
28649 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
28651 this.colWidth = boxWidth + avail - this.padWidth;
28653 this.unitWidth = Math.floor((this.colWidth - (this.gutter * 2)) / 3);
28654 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
28657 horizontalMeasureColumns : function()
28659 this.getContainerWidth();
28661 var boxWidth = this.boxWidth;
28663 if(this.containerWidth < boxWidth){
28664 boxWidth = this.containerWidth;
28667 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
28669 this.el.setHeight(boxWidth);
28673 getContainerWidth : function()
28675 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
28678 layoutItems : function( isInstant )
28680 var items = Roo.apply([], this.bricks);
28682 if(this.isHorizontal){
28683 this._horizontalLayoutItems( items , isInstant );
28687 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
28688 // this._verticalAlternativeLayoutItems( items , isInstant );
28692 this._verticalLayoutItems( items , isInstant );
28696 _verticalLayoutItems : function ( items , isInstant)
28698 if ( !items || !items.length ) {
28703 ['xs', 'xs', 'xs', 'tall'],
28704 ['xs', 'xs', 'tall'],
28705 ['xs', 'xs', 'sm'],
28706 ['xs', 'xs', 'xs'],
28712 ['sm', 'xs', 'xs'],
28716 ['tall', 'xs', 'xs', 'xs'],
28717 ['tall', 'xs', 'xs'],
28729 Roo.each(items, function(item, k){
28731 switch (item.size) {
28732 // these layouts take up a full box,
28743 boxes.push([item]);
28766 var filterPattern = function(box, length)
28774 var pattern = box.slice(0, length);
28778 Roo.each(pattern, function(i){
28779 format.push(i.size);
28782 Roo.each(standard, function(s){
28784 if(String(s) != String(format)){
28793 if(!match && length == 1){
28798 filterPattern(box, length - 1);
28802 queue.push(pattern);
28804 box = box.slice(length, box.length);
28806 filterPattern(box, 4);
28812 Roo.each(boxes, function(box, k){
28818 if(box.length == 1){
28823 filterPattern(box, 4);
28827 this._processVerticalLayoutQueue( queue, isInstant );
28831 // _verticalAlternativeLayoutItems : function( items , isInstant )
28833 // if ( !items || !items.length ) {
28837 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
28841 _horizontalLayoutItems : function ( items , isInstant)
28843 if ( !items || !items.length || items.length < 3) {
28849 var eItems = items.slice(0, 3);
28851 items = items.slice(3, items.length);
28854 ['xs', 'xs', 'xs', 'wide'],
28855 ['xs', 'xs', 'wide'],
28856 ['xs', 'xs', 'sm'],
28857 ['xs', 'xs', 'xs'],
28863 ['sm', 'xs', 'xs'],
28867 ['wide', 'xs', 'xs', 'xs'],
28868 ['wide', 'xs', 'xs'],
28881 Roo.each(items, function(item, k){
28883 switch (item.size) {
28894 boxes.push([item]);
28918 var filterPattern = function(box, length)
28926 var pattern = box.slice(0, length);
28930 Roo.each(pattern, function(i){
28931 format.push(i.size);
28934 Roo.each(standard, function(s){
28936 if(String(s) != String(format)){
28945 if(!match && length == 1){
28950 filterPattern(box, length - 1);
28954 queue.push(pattern);
28956 box = box.slice(length, box.length);
28958 filterPattern(box, 4);
28964 Roo.each(boxes, function(box, k){
28970 if(box.length == 1){
28975 filterPattern(box, 4);
28982 var pos = this.el.getBox(true);
28986 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
28988 var hit_end = false;
28990 Roo.each(queue, function(box){
28994 Roo.each(box, function(b){
28996 b.el.setVisibilityMode(Roo.Element.DISPLAY);
29006 Roo.each(box, function(b){
29008 b.el.setVisibilityMode(Roo.Element.DISPLAY);
29011 mx = Math.max(mx, b.x);
29015 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
29019 Roo.each(box, function(b){
29021 b.el.setVisibilityMode(Roo.Element.DISPLAY);
29035 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
29038 /** Sets position of item in DOM
29039 * @param {Element} item
29040 * @param {Number} x - horizontal position
29041 * @param {Number} y - vertical position
29042 * @param {Boolean} isInstant - disables transitions
29044 _processVerticalLayoutQueue : function( queue, isInstant )
29046 var pos = this.el.getBox(true);
29051 for (var i = 0; i < this.cols; i++){
29055 Roo.each(queue, function(box, k){
29057 var col = k % this.cols;
29059 Roo.each(box, function(b,kk){
29061 b.el.position('absolute');
29063 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
29064 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
29066 if(b.size == 'md-left' || b.size == 'md-right'){
29067 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
29068 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
29071 b.el.setWidth(width);
29072 b.el.setHeight(height);
29074 b.el.select('iframe',true).setSize(width,height);
29078 for (var i = 0; i < this.cols; i++){
29080 if(maxY[i] < maxY[col]){
29085 col = Math.min(col, i);
29089 x = pos.x + col * (this.colWidth + this.padWidth);
29093 var positions = [];
29095 switch (box.length){
29097 positions = this.getVerticalOneBoxColPositions(x, y, box);
29100 positions = this.getVerticalTwoBoxColPositions(x, y, box);
29103 positions = this.getVerticalThreeBoxColPositions(x, y, box);
29106 positions = this.getVerticalFourBoxColPositions(x, y, box);
29112 Roo.each(box, function(b,kk){
29114 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
29116 var sz = b.el.getSize();
29118 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
29126 for (var i = 0; i < this.cols; i++){
29127 mY = Math.max(mY, maxY[i]);
29130 this.el.setHeight(mY - pos.y);
29134 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
29136 // var pos = this.el.getBox(true);
29139 // var maxX = pos.right;
29141 // var maxHeight = 0;
29143 // Roo.each(items, function(item, k){
29147 // item.el.position('absolute');
29149 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
29151 // item.el.setWidth(width);
29153 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
29155 // item.el.setHeight(height);
29158 // item.el.setXY([x, y], isInstant ? false : true);
29160 // item.el.setXY([maxX - width, y], isInstant ? false : true);
29163 // y = y + height + this.alternativePadWidth;
29165 // maxHeight = maxHeight + height + this.alternativePadWidth;
29169 // this.el.setHeight(maxHeight);
29173 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
29175 var pos = this.el.getBox(true);
29180 var maxX = pos.right;
29182 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
29184 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
29186 Roo.each(queue, function(box, k){
29188 Roo.each(box, function(b, kk){
29190 b.el.position('absolute');
29192 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
29193 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
29195 if(b.size == 'md-left' || b.size == 'md-right'){
29196 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
29197 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
29200 b.el.setWidth(width);
29201 b.el.setHeight(height);
29209 var positions = [];
29211 switch (box.length){
29213 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
29216 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
29219 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
29222 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
29228 Roo.each(box, function(b,kk){
29230 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
29232 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
29240 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
29242 Roo.each(eItems, function(b,k){
29244 b.size = (k == 0) ? 'sm' : 'xs';
29245 b.x = (k == 0) ? 2 : 1;
29246 b.y = (k == 0) ? 2 : 1;
29248 b.el.position('absolute');
29250 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
29252 b.el.setWidth(width);
29254 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
29256 b.el.setHeight(height);
29260 var positions = [];
29263 x : maxX - this.unitWidth * 2 - this.gutter,
29268 x : maxX - this.unitWidth,
29269 y : minY + (this.unitWidth + this.gutter) * 2
29273 x : maxX - this.unitWidth * 3 - this.gutter * 2,
29277 Roo.each(eItems, function(b,k){
29279 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
29285 getVerticalOneBoxColPositions : function(x, y, box)
29289 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
29291 if(box[0].size == 'md-left'){
29295 if(box[0].size == 'md-right'){
29300 x : x + (this.unitWidth + this.gutter) * rand,
29307 getVerticalTwoBoxColPositions : function(x, y, box)
29311 if(box[0].size == 'xs'){
29315 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
29319 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
29333 x : x + (this.unitWidth + this.gutter) * 2,
29334 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
29341 getVerticalThreeBoxColPositions : function(x, y, box)
29345 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
29353 x : x + (this.unitWidth + this.gutter) * 1,
29358 x : x + (this.unitWidth + this.gutter) * 2,
29366 if(box[0].size == 'xs' && box[1].size == 'xs'){
29375 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
29379 x : x + (this.unitWidth + this.gutter) * 1,
29393 x : x + (this.unitWidth + this.gutter) * 2,
29398 x : x + (this.unitWidth + this.gutter) * 2,
29399 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
29406 getVerticalFourBoxColPositions : function(x, y, box)
29410 if(box[0].size == 'xs'){
29419 y : y + (this.unitHeight + this.gutter) * 1
29424 y : y + (this.unitHeight + this.gutter) * 2
29428 x : x + (this.unitWidth + this.gutter) * 1,
29442 x : x + (this.unitWidth + this.gutter) * 2,
29447 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
29448 y : y + (this.unitHeight + this.gutter) * 1
29452 x : x + (this.unitWidth + this.gutter) * 2,
29453 y : y + (this.unitWidth + this.gutter) * 2
29460 getHorizontalOneBoxColPositions : function(maxX, minY, box)
29464 if(box[0].size == 'md-left'){
29466 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
29473 if(box[0].size == 'md-right'){
29475 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
29476 y : minY + (this.unitWidth + this.gutter) * 1
29482 var rand = Math.floor(Math.random() * (4 - box[0].y));
29485 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29486 y : minY + (this.unitWidth + this.gutter) * rand
29493 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
29497 if(box[0].size == 'xs'){
29500 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29505 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
29506 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
29514 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29519 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
29520 y : minY + (this.unitWidth + this.gutter) * 2
29527 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
29531 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
29534 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29539 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
29540 y : minY + (this.unitWidth + this.gutter) * 1
29544 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
29545 y : minY + (this.unitWidth + this.gutter) * 2
29552 if(box[0].size == 'xs' && box[1].size == 'xs'){
29555 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29560 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
29565 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
29566 y : minY + (this.unitWidth + this.gutter) * 1
29574 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29579 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
29580 y : minY + (this.unitWidth + this.gutter) * 2
29584 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
29585 y : minY + (this.unitWidth + this.gutter) * 2
29592 getHorizontalFourBoxColPositions : function(maxX, minY, box)
29596 if(box[0].size == 'xs'){
29599 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29604 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
29609 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
29614 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
29615 y : minY + (this.unitWidth + this.gutter) * 1
29623 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29628 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
29629 y : minY + (this.unitWidth + this.gutter) * 2
29633 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
29634 y : minY + (this.unitWidth + this.gutter) * 2
29638 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1) - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
29639 y : minY + (this.unitWidth + this.gutter) * 2
29653 * http://masonry.desandro.com
29655 * The idea is to render all the bricks based on vertical width...
29657 * The original code extends 'outlayer' - we might need to use that....
29663 * @class Roo.bootstrap.LayoutMasonryAuto
29664 * @extends Roo.bootstrap.Component
29665 * Bootstrap Layout Masonry class
29668 * Create a new Element
29669 * @param {Object} config The config object
29672 Roo.bootstrap.LayoutMasonryAuto = function(config){
29673 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
29676 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
29679 * @cfg {Boolean} isFitWidth - resize the width..
29681 isFitWidth : false, // options..
29683 * @cfg {Boolean} isOriginLeft = left align?
29685 isOriginLeft : true,
29687 * @cfg {Boolean} isOriginTop = top align?
29689 isOriginTop : false,
29691 * @cfg {Boolean} isLayoutInstant = no animation?
29693 isLayoutInstant : false, // needed?
29695 * @cfg {Boolean} isResizingContainer = not sure if this is used..
29697 isResizingContainer : true,
29699 * @cfg {Number} columnWidth width of the columns
29705 * @cfg {Number} maxCols maximum number of columns
29710 * @cfg {Number} padHeight padding below box..
29716 * @cfg {Boolean} isAutoInitial defalut true
29719 isAutoInitial : true,
29725 initialColumnWidth : 0,
29726 currentSize : null,
29728 colYs : null, // array.
29735 bricks: null, //CompositeElement
29736 cols : 0, // array?
29737 // element : null, // wrapped now this.el
29738 _isLayoutInited : null,
29741 getAutoCreate : function(){
29745 cls: 'blog-masonary-wrapper ' + this.cls,
29747 cls : 'mas-boxes masonary'
29754 getChildContainer: function( )
29756 if (this.boxesEl) {
29757 return this.boxesEl;
29760 this.boxesEl = this.el.select('.mas-boxes').first();
29762 return this.boxesEl;
29766 initEvents : function()
29770 if(this.isAutoInitial){
29771 Roo.log('hook children rendered');
29772 this.on('childrenrendered', function() {
29773 Roo.log('children rendered');
29780 initial : function()
29782 this.reloadItems();
29784 this.currentSize = this.el.getBox(true);
29786 /// was window resize... - let's see if this works..
29787 Roo.EventManager.onWindowResize(this.resize, this);
29789 if(!this.isAutoInitial){
29794 this.layout.defer(500,this);
29797 reloadItems: function()
29799 this.bricks = this.el.select('.masonry-brick', true);
29801 this.bricks.each(function(b) {
29802 //Roo.log(b.getSize());
29803 if (!b.attr('originalwidth')) {
29804 b.attr('originalwidth', b.getSize().width);
29809 Roo.log(this.bricks.elements.length);
29812 resize : function()
29815 var cs = this.el.getBox(true);
29817 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
29818 Roo.log("no change in with or X");
29821 this.currentSize = cs;
29825 layout : function()
29828 this._resetLayout();
29829 //this._manageStamps();
29831 // don't animate first layout
29832 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
29833 this.layoutItems( isInstant );
29835 // flag for initalized
29836 this._isLayoutInited = true;
29839 layoutItems : function( isInstant )
29841 //var items = this._getItemsForLayout( this.items );
29842 // original code supports filtering layout items.. we just ignore it..
29844 this._layoutItems( this.bricks , isInstant );
29846 this._postLayout();
29848 _layoutItems : function ( items , isInstant)
29850 //this.fireEvent( 'layout', this, items );
29853 if ( !items || !items.elements.length ) {
29854 // no items, emit event with empty array
29859 items.each(function(item) {
29860 Roo.log("layout item");
29862 // get x/y object from method
29863 var position = this._getItemLayoutPosition( item );
29865 position.item = item;
29866 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
29867 queue.push( position );
29870 this._processLayoutQueue( queue );
29872 /** Sets position of item in DOM
29873 * @param {Element} item
29874 * @param {Number} x - horizontal position
29875 * @param {Number} y - vertical position
29876 * @param {Boolean} isInstant - disables transitions
29878 _processLayoutQueue : function( queue )
29880 for ( var i=0, len = queue.length; i < len; i++ ) {
29881 var obj = queue[i];
29882 obj.item.position('absolute');
29883 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
29889 * Any logic you want to do after each layout,
29890 * i.e. size the container
29892 _postLayout : function()
29894 this.resizeContainer();
29897 resizeContainer : function()
29899 if ( !this.isResizingContainer ) {
29902 var size = this._getContainerSize();
29904 this.el.setSize(size.width,size.height);
29905 this.boxesEl.setSize(size.width,size.height);
29911 _resetLayout : function()
29913 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
29914 this.colWidth = this.el.getWidth();
29915 //this.gutter = this.el.getWidth();
29917 this.measureColumns();
29923 this.colYs.push( 0 );
29929 measureColumns : function()
29931 this.getContainerWidth();
29932 // if columnWidth is 0, default to outerWidth of first item
29933 if ( !this.columnWidth ) {
29934 var firstItem = this.bricks.first();
29935 Roo.log(firstItem);
29936 this.columnWidth = this.containerWidth;
29937 if (firstItem && firstItem.attr('originalwidth') ) {
29938 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
29940 // columnWidth fall back to item of first element
29941 Roo.log("set column width?");
29942 this.initialColumnWidth = this.columnWidth ;
29944 // if first elem has no width, default to size of container
29949 if (this.initialColumnWidth) {
29950 this.columnWidth = this.initialColumnWidth;
29955 // column width is fixed at the top - however if container width get's smaller we should
29958 // this bit calcs how man columns..
29960 var columnWidth = this.columnWidth += this.gutter;
29962 // calculate columns
29963 var containerWidth = this.containerWidth + this.gutter;
29965 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
29966 // fix rounding errors, typically with gutters
29967 var excess = columnWidth - containerWidth % columnWidth;
29970 // if overshoot is less than a pixel, round up, otherwise floor it
29971 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
29972 cols = Math[ mathMethod ]( cols );
29973 this.cols = Math.max( cols, 1 );
29974 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
29976 // padding positioning..
29977 var totalColWidth = this.cols * this.columnWidth;
29978 var padavail = this.containerWidth - totalColWidth;
29979 // so for 2 columns - we need 3 'pads'
29981 var padNeeded = (1+this.cols) * this.padWidth;
29983 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
29985 this.columnWidth += padExtra
29986 //this.padWidth = Math.floor(padavail / ( this.cols));
29988 // adjust colum width so that padding is fixed??
29990 // we have 3 columns ... total = width * 3
29991 // we have X left over... that should be used by
29993 //if (this.expandC) {
30001 getContainerWidth : function()
30003 /* // container is parent if fit width
30004 var container = this.isFitWidth ? this.element.parentNode : this.element;
30005 // check that this.size and size are there
30006 // IE8 triggers resize on body size change, so they might not be
30008 var size = getSize( container ); //FIXME
30009 this.containerWidth = size && size.innerWidth; //FIXME
30012 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
30016 _getItemLayoutPosition : function( item ) // what is item?
30018 // we resize the item to our columnWidth..
30020 item.setWidth(this.columnWidth);
30021 item.autoBoxAdjust = false;
30023 var sz = item.getSize();
30025 // how many columns does this brick span
30026 var remainder = this.containerWidth % this.columnWidth;
30028 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
30029 // round if off by 1 pixel, otherwise use ceil
30030 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
30031 colSpan = Math.min( colSpan, this.cols );
30033 // normally this should be '1' as we dont' currently allow multi width columns..
30035 var colGroup = this._getColGroup( colSpan );
30036 // get the minimum Y value from the columns
30037 var minimumY = Math.min.apply( Math, colGroup );
30038 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
30040 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
30042 // position the brick
30044 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
30045 y: this.currentSize.y + minimumY + this.padHeight
30049 // apply setHeight to necessary columns
30050 var setHeight = minimumY + sz.height + this.padHeight;
30051 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
30053 var setSpan = this.cols + 1 - colGroup.length;
30054 for ( var i = 0; i < setSpan; i++ ) {
30055 this.colYs[ shortColIndex + i ] = setHeight ;
30062 * @param {Number} colSpan - number of columns the element spans
30063 * @returns {Array} colGroup
30065 _getColGroup : function( colSpan )
30067 if ( colSpan < 2 ) {
30068 // if brick spans only one column, use all the column Ys
30073 // how many different places could this brick fit horizontally
30074 var groupCount = this.cols + 1 - colSpan;
30075 // for each group potential horizontal position
30076 for ( var i = 0; i < groupCount; i++ ) {
30077 // make an array of colY values for that one group
30078 var groupColYs = this.colYs.slice( i, i + colSpan );
30079 // and get the max value of the array
30080 colGroup[i] = Math.max.apply( Math, groupColYs );
30085 _manageStamp : function( stamp )
30087 var stampSize = stamp.getSize();
30088 var offset = stamp.getBox();
30089 // get the columns that this stamp affects
30090 var firstX = this.isOriginLeft ? offset.x : offset.right;
30091 var lastX = firstX + stampSize.width;
30092 var firstCol = Math.floor( firstX / this.columnWidth );
30093 firstCol = Math.max( 0, firstCol );
30095 var lastCol = Math.floor( lastX / this.columnWidth );
30096 // lastCol should not go over if multiple of columnWidth #425
30097 lastCol -= lastX % this.columnWidth ? 0 : 1;
30098 lastCol = Math.min( this.cols - 1, lastCol );
30100 // set colYs to bottom of the stamp
30101 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
30104 for ( var i = firstCol; i <= lastCol; i++ ) {
30105 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
30110 _getContainerSize : function()
30112 this.maxY = Math.max.apply( Math, this.colYs );
30117 if ( this.isFitWidth ) {
30118 size.width = this._getContainerFitWidth();
30124 _getContainerFitWidth : function()
30126 var unusedCols = 0;
30127 // count unused columns
30130 if ( this.colYs[i] !== 0 ) {
30135 // fit container to columns that have been used
30136 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
30139 needsResizeLayout : function()
30141 var previousWidth = this.containerWidth;
30142 this.getContainerWidth();
30143 return previousWidth !== this.containerWidth;
30158 * @class Roo.bootstrap.MasonryBrick
30159 * @extends Roo.bootstrap.Component
30160 * Bootstrap MasonryBrick class
30163 * Create a new MasonryBrick
30164 * @param {Object} config The config object
30167 Roo.bootstrap.MasonryBrick = function(config){
30168 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
30174 * When a MasonryBrick is clcik
30175 * @param {Roo.bootstrap.MasonryBrick} this
30176 * @param {Roo.EventObject} e
30182 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
30185 * @cfg {String} title
30189 * @cfg {String} html
30193 * @cfg {String} bgimage
30197 * @cfg {String} videourl
30201 * @cfg {String} cls
30205 * @cfg {String} href
30209 * @cfg {String} (xs|sm|md|md-left|md-right|tall|wide) size
30214 * @cfg {String} (center|bottom) placetitle
30218 getAutoCreate : function()
30220 var cls = 'masonry-brick';
30222 if(this.href.length){
30223 cls += ' masonry-brick-link';
30226 if(this.bgimage.length){
30227 cls += ' masonry-brick-image';
30231 cls += ' masonry-' + this.size + '-brick';
30234 if(this.placetitle.length){
30236 switch (this.placetitle) {
30238 cls += ' masonry-center-title';
30241 cls += ' masonry-bottom-title';
30248 if(!this.html.length && !this.bgimage.length){
30249 cls += ' masonry-center-title';
30252 if(!this.html.length && this.bgimage.length){
30253 cls += ' masonry-bottom-title';
30258 cls += ' ' + this.cls;
30262 tag: (this.href.length) ? 'a' : 'div',
30267 cls: 'masonry-brick-paragraph',
30273 if(this.href.length){
30274 cfg.href = this.href;
30277 var cn = cfg.cn[0].cn;
30279 if(this.title.length){
30282 cls: 'masonry-brick-title',
30287 if(this.html.length){
30290 cls: 'masonry-brick-text',
30294 if (!this.title.length && !this.html.length) {
30295 cfg.cn[0].cls += ' hide';
30298 if(this.bgimage.length){
30301 cls: 'masonry-brick-image-view',
30305 if(this.videourl.length){
30306 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
30307 // youtube support only?
30310 cls: 'masonry-brick-image-view',
30313 allowfullscreen : true
30322 initEvents: function()
30324 switch (this.size) {
30326 // this.intSize = 1;
30331 // this.intSize = 2;
30338 // this.intSize = 3;
30343 // this.intSize = 3;
30348 // this.intSize = 3;
30353 // this.intSize = 3;
30365 this.el.on('touchstart', this.onTouchStart, this);
30366 this.el.on('touchmove', this.onTouchMove, this);
30367 this.el.on('touchend', this.onTouchEnd, this);
30368 this.el.on('contextmenu', this.onContextMenu, this);
30370 this.el.on('mouseenter' ,this.enter, this);
30371 this.el.on('mouseleave', this.leave, this);
30374 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
30375 this.parent().bricks.push(this);
30380 onClick: function(e, el)
30388 var time = this.endTimer - this.startTimer;
30396 e.preventDefault();
30399 enter: function(e, el)
30401 e.preventDefault();
30403 if(this.bgimage.length && this.html.length){
30404 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
30408 leave: function(e, el)
30410 e.preventDefault();
30412 if(this.bgimage.length && this.html.length){
30413 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
30417 onTouchStart: function(e, el)
30419 // e.preventDefault();
30421 if(!this.bgimage.length || !this.html.length){
30425 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
30427 this.timer = new Date().getTime();
30429 this.touchmoved = false;
30432 onTouchMove: function(e, el)
30434 this.touchmoved = true;
30436 onContextMenu : function(e,el)
30438 e.preventDefault();
30439 e.stopPropagation();
30444 onTouchEnd: function(e, el)
30446 // e.preventDefault();
30448 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
30455 if(!this.bgimage.length || !this.html.length){
30457 if(this.href.length){
30458 window.location.href = this.href;
30464 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
30466 window.location.href = this.href;
30481 * @class Roo.bootstrap.Brick
30482 * @extends Roo.bootstrap.Component
30483 * Bootstrap Brick class
30486 * Create a new Brick
30487 * @param {Object} config The config object
30490 Roo.bootstrap.Brick = function(config){
30491 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
30497 * When a Brick is click
30498 * @param {Roo.bootstrap.Brick} this
30499 * @param {Roo.EventObject} e
30505 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
30508 * @cfg {String} title
30512 * @cfg {String} html
30516 * @cfg {String} bgimage
30520 * @cfg {String} cls
30524 * @cfg {String} href
30528 * @cfg {String} video
30532 * @cfg {Boolean} square
30536 getAutoCreate : function()
30538 var cls = 'roo-brick';
30540 if(this.href.length){
30541 cls += ' roo-brick-link';
30544 if(this.bgimage.length){
30545 cls += ' roo-brick-image';
30548 if(!this.html.length && !this.bgimage.length){
30549 cls += ' roo-brick-center-title';
30552 if(!this.html.length && this.bgimage.length){
30553 cls += ' roo-brick-bottom-title';
30557 cls += ' ' + this.cls;
30561 tag: (this.href.length) ? 'a' : 'div',
30566 cls: 'roo-brick-paragraph',
30572 if(this.href.length){
30573 cfg.href = this.href;
30576 var cn = cfg.cn[0].cn;
30578 if(this.title.length){
30581 cls: 'roo-brick-title',
30586 if(this.html.length){
30589 cls: 'roo-brick-text',
30596 if(this.bgimage.length){
30599 cls: 'roo-brick-image-view',
30607 initEvents: function()
30609 if(this.title.length || this.html.length){
30610 this.el.on('mouseenter' ,this.enter, this);
30611 this.el.on('mouseleave', this.leave, this);
30615 Roo.EventManager.onWindowResize(this.resize, this);
30620 resize : function()
30622 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
30624 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
30625 // paragraph.setHeight(paragraph.getWidth());
30627 if(this.bgimage.length){
30628 var image = this.el.select('.roo-brick-image-view', true).first();
30629 image.setWidth(paragraph.getWidth());
30630 image.setHeight(paragraph.getWidth());
30635 enter: function(e, el)
30637 e.preventDefault();
30639 if(this.bgimage.length){
30640 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
30641 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
30645 leave: function(e, el)
30647 e.preventDefault();
30649 if(this.bgimage.length){
30650 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
30651 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
30661 * Ext JS Library 1.1.1
30662 * Copyright(c) 2006-2007, Ext JS, LLC.
30664 * Originally Released Under LGPL - original licence link has changed is not relivant.
30667 * <script type="text/javascript">
30672 * @class Roo.bootstrap.SplitBar
30673 * @extends Roo.util.Observable
30674 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
30678 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
30679 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
30680 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
30681 split.minSize = 100;
30682 split.maxSize = 600;
30683 split.animate = true;
30684 split.on('moved', splitterMoved);
30687 * Create a new SplitBar
30688 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
30689 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
30690 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
30691 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
30692 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
30693 position of the SplitBar).
30695 Roo.bootstrap.SplitBar = function(cfg){
30700 // dragElement : elm
30701 // resizingElement: el,
30703 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
30704 // placement : Roo.bootstrap.SplitBar.LEFT ,
30705 // existingProxy ???
30708 this.el = Roo.get(cfg.dragElement, true);
30709 this.el.dom.unselectable = "on";
30711 this.resizingEl = Roo.get(cfg.resizingElement, true);
30715 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
30716 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
30719 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
30722 * The minimum size of the resizing element. (Defaults to 0)
30728 * The maximum size of the resizing element. (Defaults to 2000)
30731 this.maxSize = 2000;
30734 * Whether to animate the transition to the new size
30737 this.animate = false;
30740 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
30743 this.useShim = false;
30748 if(!cfg.existingProxy){
30750 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
30752 this.proxy = Roo.get(cfg.existingProxy).dom;
30755 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
30758 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
30761 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
30764 this.dragSpecs = {};
30767 * @private The adapter to use to positon and resize elements
30769 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
30770 this.adapter.init(this);
30772 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
30774 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
30775 this.el.addClass("roo-splitbar-h");
30778 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
30779 this.el.addClass("roo-splitbar-v");
30785 * Fires when the splitter is moved (alias for {@link #event-moved})
30786 * @param {Roo.bootstrap.SplitBar} this
30787 * @param {Number} newSize the new width or height
30792 * Fires when the splitter is moved
30793 * @param {Roo.bootstrap.SplitBar} this
30794 * @param {Number} newSize the new width or height
30798 * @event beforeresize
30799 * Fires before the splitter is dragged
30800 * @param {Roo.bootstrap.SplitBar} this
30802 "beforeresize" : true,
30804 "beforeapply" : true
30807 Roo.util.Observable.call(this);
30810 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
30811 onStartProxyDrag : function(x, y){
30812 this.fireEvent("beforeresize", this);
30814 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
30816 o.enableDisplayMode("block");
30817 // all splitbars share the same overlay
30818 Roo.bootstrap.SplitBar.prototype.overlay = o;
30820 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
30821 this.overlay.show();
30822 Roo.get(this.proxy).setDisplayed("block");
30823 var size = this.adapter.getElementSize(this);
30824 this.activeMinSize = this.getMinimumSize();;
30825 this.activeMaxSize = this.getMaximumSize();;
30826 var c1 = size - this.activeMinSize;
30827 var c2 = Math.max(this.activeMaxSize - size, 0);
30828 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
30829 this.dd.resetConstraints();
30830 this.dd.setXConstraint(
30831 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
30832 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
30834 this.dd.setYConstraint(0, 0);
30836 this.dd.resetConstraints();
30837 this.dd.setXConstraint(0, 0);
30838 this.dd.setYConstraint(
30839 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
30840 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
30843 this.dragSpecs.startSize = size;
30844 this.dragSpecs.startPoint = [x, y];
30845 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
30849 * @private Called after the drag operation by the DDProxy
30851 onEndProxyDrag : function(e){
30852 Roo.get(this.proxy).setDisplayed(false);
30853 var endPoint = Roo.lib.Event.getXY(e);
30855 this.overlay.hide();
30858 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
30859 newSize = this.dragSpecs.startSize +
30860 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
30861 endPoint[0] - this.dragSpecs.startPoint[0] :
30862 this.dragSpecs.startPoint[0] - endPoint[0]
30865 newSize = this.dragSpecs.startSize +
30866 (this.placement == Roo.bootstrap.SplitBar.TOP ?
30867 endPoint[1] - this.dragSpecs.startPoint[1] :
30868 this.dragSpecs.startPoint[1] - endPoint[1]
30871 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
30872 if(newSize != this.dragSpecs.startSize){
30873 if(this.fireEvent('beforeapply', this, newSize) !== false){
30874 this.adapter.setElementSize(this, newSize);
30875 this.fireEvent("moved", this, newSize);
30876 this.fireEvent("resize", this, newSize);
30882 * Get the adapter this SplitBar uses
30883 * @return The adapter object
30885 getAdapter : function(){
30886 return this.adapter;
30890 * Set the adapter this SplitBar uses
30891 * @param {Object} adapter A SplitBar adapter object
30893 setAdapter : function(adapter){
30894 this.adapter = adapter;
30895 this.adapter.init(this);
30899 * Gets the minimum size for the resizing element
30900 * @return {Number} The minimum size
30902 getMinimumSize : function(){
30903 return this.minSize;
30907 * Sets the minimum size for the resizing element
30908 * @param {Number} minSize The minimum size
30910 setMinimumSize : function(minSize){
30911 this.minSize = minSize;
30915 * Gets the maximum size for the resizing element
30916 * @return {Number} The maximum size
30918 getMaximumSize : function(){
30919 return this.maxSize;
30923 * Sets the maximum size for the resizing element
30924 * @param {Number} maxSize The maximum size
30926 setMaximumSize : function(maxSize){
30927 this.maxSize = maxSize;
30931 * Sets the initialize size for the resizing element
30932 * @param {Number} size The initial size
30934 setCurrentSize : function(size){
30935 var oldAnimate = this.animate;
30936 this.animate = false;
30937 this.adapter.setElementSize(this, size);
30938 this.animate = oldAnimate;
30942 * Destroy this splitbar.
30943 * @param {Boolean} removeEl True to remove the element
30945 destroy : function(removeEl){
30947 this.shim.remove();
30950 this.proxy.parentNode.removeChild(this.proxy);
30958 * @private static Create our own proxy element element. So it will be the same same size on all browsers, we won't use borders. Instead we use a background color.
30960 Roo.bootstrap.SplitBar.createProxy = function(dir){
30961 var proxy = new Roo.Element(document.createElement("div"));
30962 proxy.unselectable();
30963 var cls = 'roo-splitbar-proxy';
30964 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
30965 document.body.appendChild(proxy.dom);
30970 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
30971 * Default Adapter. It assumes the splitter and resizing element are not positioned
30972 * elements and only gets/sets the width of the element. Generally used for table based layouts.
30974 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
30977 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
30978 // do nothing for now
30979 init : function(s){
30983 * Called before drag operations to get the current size of the resizing element.
30984 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
30986 getElementSize : function(s){
30987 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
30988 return s.resizingEl.getWidth();
30990 return s.resizingEl.getHeight();
30995 * Called after drag operations to set the size of the resizing element.
30996 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
30997 * @param {Number} newSize The new size to set
30998 * @param {Function} onComplete A function to be invoked when resizing is complete
31000 setElementSize : function(s, newSize, onComplete){
31001 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
31003 s.resizingEl.setWidth(newSize);
31005 onComplete(s, newSize);
31008 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
31013 s.resizingEl.setHeight(newSize);
31015 onComplete(s, newSize);
31018 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
31025 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
31026 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
31027 * Adapter that moves the splitter element to align with the resized sizing element.
31028 * Used with an absolute positioned SplitBar.
31029 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
31030 * document.body, make sure you assign an id to the body element.
31032 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
31033 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
31034 this.container = Roo.get(container);
31037 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
31038 init : function(s){
31039 this.basic.init(s);
31042 getElementSize : function(s){
31043 return this.basic.getElementSize(s);
31046 setElementSize : function(s, newSize, onComplete){
31047 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
31050 moveSplitter : function(s){
31051 var yes = Roo.bootstrap.SplitBar;
31052 switch(s.placement){
31054 s.el.setX(s.resizingEl.getRight());
31057 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
31060 s.el.setY(s.resizingEl.getBottom());
31063 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
31070 * Orientation constant - Create a vertical SplitBar
31074 Roo.bootstrap.SplitBar.VERTICAL = 1;
31077 * Orientation constant - Create a horizontal SplitBar
31081 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
31084 * Placement constant - The resizing element is to the left of the splitter element
31088 Roo.bootstrap.SplitBar.LEFT = 1;
31091 * Placement constant - The resizing element is to the right of the splitter element
31095 Roo.bootstrap.SplitBar.RIGHT = 2;
31098 * Placement constant - The resizing element is positioned above the splitter element
31102 Roo.bootstrap.SplitBar.TOP = 3;
31105 * Placement constant - The resizing element is positioned under splitter element
31109 Roo.bootstrap.SplitBar.BOTTOM = 4;
31110 Roo.namespace("Roo.bootstrap.layout");/*
31112 * Ext JS Library 1.1.1
31113 * Copyright(c) 2006-2007, Ext JS, LLC.
31115 * Originally Released Under LGPL - original licence link has changed is not relivant.
31118 * <script type="text/javascript">
31122 * @class Roo.bootstrap.layout.Manager
31123 * @extends Roo.bootstrap.Component
31124 * Base class for layout managers.
31126 Roo.bootstrap.layout.Manager = function(config)
31128 Roo.bootstrap.layout.Manager.superclass.constructor.call(this);
31134 /** false to disable window resize monitoring @type Boolean */
31135 this.monitorWindowResize = true;
31140 * Fires when a layout is performed.
31141 * @param {Roo.LayoutManager} this
31145 * @event regionresized
31146 * Fires when the user resizes a region.
31147 * @param {Roo.LayoutRegion} region The resized region
31148 * @param {Number} newSize The new size (width for east/west, height for north/south)
31150 "regionresized" : true,
31152 * @event regioncollapsed
31153 * Fires when a region is collapsed.
31154 * @param {Roo.LayoutRegion} region The collapsed region
31156 "regioncollapsed" : true,
31158 * @event regionexpanded
31159 * Fires when a region is expanded.
31160 * @param {Roo.LayoutRegion} region The expanded region
31162 "regionexpanded" : true
31164 this.updating = false;
31167 this.el = Roo.get(config.el);
31173 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
31178 monitorWindowResize : true,
31184 onRender : function(ct, position)
31187 this.el = Roo.get(ct);
31193 initEvents: function()
31197 // ie scrollbar fix
31198 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
31199 document.body.scroll = "no";
31200 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
31201 this.el.position('relative');
31203 this.id = this.el.id;
31204 this.el.addClass("roo-layout-container");
31205 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
31206 if(this.el.dom != document.body ) {
31207 this.el.on('resize', this.layout,this);
31208 this.el.on('show', this.layout,this);
31214 * Returns true if this layout is currently being updated
31215 * @return {Boolean}
31217 isUpdating : function(){
31218 return this.updating;
31222 * Suspend the LayoutManager from doing auto-layouts while
31223 * making multiple add or remove calls
31225 beginUpdate : function(){
31226 this.updating = true;
31230 * Restore auto-layouts and optionally disable the manager from performing a layout
31231 * @param {Boolean} noLayout true to disable a layout update
31233 endUpdate : function(noLayout){
31234 this.updating = false;
31240 layout: function(){
31244 onRegionResized : function(region, newSize){
31245 this.fireEvent("regionresized", region, newSize);
31249 onRegionCollapsed : function(region){
31250 this.fireEvent("regioncollapsed", region);
31253 onRegionExpanded : function(region){
31254 this.fireEvent("regionexpanded", region);
31258 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
31259 * performs box-model adjustments.
31260 * @return {Object} The size as an object {width: (the width), height: (the height)}
31262 getViewSize : function()
31265 if(this.el.dom != document.body){
31266 size = this.el.getSize();
31268 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
31270 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
31271 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
31276 * Returns the Element this layout is bound to.
31277 * @return {Roo.Element}
31279 getEl : function(){
31284 * Returns the specified region.
31285 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
31286 * @return {Roo.LayoutRegion}
31288 getRegion : function(target){
31289 return this.regions[target.toLowerCase()];
31292 onWindowResize : function(){
31293 if(this.monitorWindowResize){
31299 * Ext JS Library 1.1.1
31300 * Copyright(c) 2006-2007, Ext JS, LLC.
31302 * Originally Released Under LGPL - original licence link has changed is not relivant.
31305 * <script type="text/javascript">
31308 * @class Roo.bootstrap.layout.Border
31309 * @extends Roo.bootstrap.layout.Manager
31310 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
31311 * please see: examples/bootstrap/nested.html<br><br>
31313 <b>The container the layout is rendered into can be either the body element or any other element.
31314 If it is not the body element, the container needs to either be an absolute positioned element,
31315 or you will need to add "position:relative" to the css of the container. You will also need to specify
31316 the container size if it is not the body element.</b>
31319 * Create a new Border
31320 * @param {Object} config Configuration options
31322 Roo.bootstrap.layout.Border = function(config){
31323 config = config || {};
31324 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
31328 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
31329 if(config[region]){
31330 config[region].region = region;
31331 this.addRegion(config[region]);
31337 Roo.bootstrap.layout.Border.regions = ["north","south","east","west","center"];
31339 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
31341 * Creates and adds a new region if it doesn't already exist.
31342 * @param {String} target The target region key (north, south, east, west or center).
31343 * @param {Object} config The regions config object
31344 * @return {BorderLayoutRegion} The new region
31346 addRegion : function(config)
31348 if(!this.regions[config.region]){
31349 var r = this.factory(config);
31350 this.bindRegion(r);
31352 return this.regions[config.region];
31356 bindRegion : function(r){
31357 this.regions[r.config.region] = r;
31359 r.on("visibilitychange", this.layout, this);
31360 r.on("paneladded", this.layout, this);
31361 r.on("panelremoved", this.layout, this);
31362 r.on("invalidated", this.layout, this);
31363 r.on("resized", this.onRegionResized, this);
31364 r.on("collapsed", this.onRegionCollapsed, this);
31365 r.on("expanded", this.onRegionExpanded, this);
31369 * Performs a layout update.
31371 layout : function()
31373 if(this.updating) {
31376 var size = this.getViewSize();
31377 var w = size.width;
31378 var h = size.height;
31383 //var x = 0, y = 0;
31385 var rs = this.regions;
31386 var north = rs["north"];
31387 var south = rs["south"];
31388 var west = rs["west"];
31389 var east = rs["east"];
31390 var center = rs["center"];
31391 //if(this.hideOnLayout){ // not supported anymore
31392 //c.el.setStyle("display", "none");
31394 if(north && north.isVisible()){
31395 var b = north.getBox();
31396 var m = north.getMargins();
31397 b.width = w - (m.left+m.right);
31400 centerY = b.height + b.y + m.bottom;
31401 centerH -= centerY;
31402 north.updateBox(this.safeBox(b));
31404 if(south && south.isVisible()){
31405 var b = south.getBox();
31406 var m = south.getMargins();
31407 b.width = w - (m.left+m.right);
31409 var totalHeight = (b.height + m.top + m.bottom);
31410 b.y = h - totalHeight + m.top;
31411 centerH -= totalHeight;
31412 south.updateBox(this.safeBox(b));
31414 if(west && west.isVisible()){
31415 var b = west.getBox();
31416 var m = west.getMargins();
31417 b.height = centerH - (m.top+m.bottom);
31419 b.y = centerY + m.top;
31420 var totalWidth = (b.width + m.left + m.right);
31421 centerX += totalWidth;
31422 centerW -= totalWidth;
31423 west.updateBox(this.safeBox(b));
31425 if(east && east.isVisible()){
31426 var b = east.getBox();
31427 var m = east.getMargins();
31428 b.height = centerH - (m.top+m.bottom);
31429 var totalWidth = (b.width + m.left + m.right);
31430 b.x = w - totalWidth + m.left;
31431 b.y = centerY + m.top;
31432 centerW -= totalWidth;
31433 east.updateBox(this.safeBox(b));
31436 var m = center.getMargins();
31438 x: centerX + m.left,
31439 y: centerY + m.top,
31440 width: centerW - (m.left+m.right),
31441 height: centerH - (m.top+m.bottom)
31443 //if(this.hideOnLayout){
31444 //center.el.setStyle("display", "block");
31446 center.updateBox(this.safeBox(centerBox));
31449 this.fireEvent("layout", this);
31453 safeBox : function(box){
31454 box.width = Math.max(0, box.width);
31455 box.height = Math.max(0, box.height);
31460 * Adds a ContentPanel (or subclass) to this layout.
31461 * @param {String} target The target region key (north, south, east, west or center).
31462 * @param {Roo.ContentPanel} panel The panel to add
31463 * @return {Roo.ContentPanel} The added panel
31465 add : function(target, panel){
31467 target = target.toLowerCase();
31468 return this.regions[target].add(panel);
31472 * Remove a ContentPanel (or subclass) to this layout.
31473 * @param {String} target The target region key (north, south, east, west or center).
31474 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
31475 * @return {Roo.ContentPanel} The removed panel
31477 remove : function(target, panel){
31478 target = target.toLowerCase();
31479 return this.regions[target].remove(panel);
31483 * Searches all regions for a panel with the specified id
31484 * @param {String} panelId
31485 * @return {Roo.ContentPanel} The panel or null if it wasn't found
31487 findPanel : function(panelId){
31488 var rs = this.regions;
31489 for(var target in rs){
31490 if(typeof rs[target] != "function"){
31491 var p = rs[target].getPanel(panelId);
31501 * Searches all regions for a panel with the specified id and activates (shows) it.
31502 * @param {String/ContentPanel} panelId The panels id or the panel itself
31503 * @return {Roo.ContentPanel} The shown panel or null
31505 showPanel : function(panelId) {
31506 var rs = this.regions;
31507 for(var target in rs){
31508 var r = rs[target];
31509 if(typeof r != "function"){
31510 if(r.hasPanel(panelId)){
31511 return r.showPanel(panelId);
31519 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
31520 * @param {Roo.state.Provider} provider (optional) An alternate state provider
31523 restoreState : function(provider){
31525 provider = Roo.state.Manager;
31527 var sm = new Roo.LayoutStateManager();
31528 sm.init(this, provider);
31534 * Adds a xtype elements to the layout.
31538 xtype : 'ContentPanel',
31545 xtype : 'NestedLayoutPanel',
31551 items : [ ... list of content panels or nested layout panels.. ]
31555 * @param {Object} cfg Xtype definition of item to add.
31557 addxtype : function(cfg)
31559 // basically accepts a pannel...
31560 // can accept a layout region..!?!?
31561 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
31564 // theory? children can only be panels??
31566 //if (!cfg.xtype.match(/Panel$/)) {
31571 if (typeof(cfg.region) == 'undefined') {
31572 Roo.log("Failed to add Panel, region was not set");
31576 var region = cfg.region;
31582 xitems = cfg.items;
31589 case 'Content': // ContentPanel (el, cfg)
31590 case 'Scroll': // ContentPanel (el, cfg)
31592 cfg.autoCreate = true;
31593 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
31595 // var el = this.el.createChild();
31596 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
31599 this.add(region, ret);
31603 case 'TreePanel': // our new panel!
31604 cfg.el = this.el.createChild();
31605 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
31606 this.add(region, ret);
31611 // create a new Layout (which is a Border Layout...
31613 var clayout = cfg.layout;
31614 clayout.el = this.el.createChild();
31615 clayout.items = clayout.items || [];
31619 // replace this exitems with the clayout ones..
31620 xitems = clayout.items;
31622 // force background off if it's in center...
31623 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
31624 cfg.background = false;
31626 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
31629 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
31630 //console.log('adding nested layout panel ' + cfg.toSource());
31631 this.add(region, ret);
31632 nb = {}; /// find first...
31637 // needs grid and region
31639 //var el = this.getRegion(region).el.createChild();
31641 *var el = this.el.createChild();
31642 // create the grid first...
31643 cfg.grid.container = el;
31644 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
31647 if (region == 'center' && this.active ) {
31648 cfg.background = false;
31651 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
31653 this.add(region, ret);
31655 if (cfg.background) {
31656 // render grid on panel activation (if panel background)
31657 ret.on('activate', function(gp) {
31658 if (!gp.grid.rendered) {
31659 // gp.grid.render(el);
31663 // cfg.grid.render(el);
31669 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
31670 // it was the old xcomponent building that caused this before.
31671 // espeically if border is the top element in the tree.
31681 if (typeof(Roo[cfg.xtype]) != 'undefined') {
31683 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
31684 this.add(region, ret);
31688 throw "Can not add '" + cfg.xtype + "' to Border";
31694 this.beginUpdate();
31698 Roo.each(xitems, function(i) {
31699 region = nb && i.region ? i.region : false;
31701 var add = ret.addxtype(i);
31704 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
31705 if (!i.background) {
31706 abn[region] = nb[region] ;
31713 // make the last non-background panel active..
31714 //if (nb) { Roo.log(abn); }
31717 for(var r in abn) {
31718 region = this.getRegion(r);
31720 // tried using nb[r], but it does not work..
31722 region.showPanel(abn[r]);
31733 factory : function(cfg)
31736 var validRegions = Roo.bootstrap.layout.Border.regions;
31738 var target = cfg.region;
31741 var r = Roo.bootstrap.layout;
31745 return new r.North(cfg);
31747 return new r.South(cfg);
31749 return new r.East(cfg);
31751 return new r.West(cfg);
31753 return new r.Center(cfg);
31755 throw 'Layout region "'+target+'" not supported.';
31762 * Ext JS Library 1.1.1
31763 * Copyright(c) 2006-2007, Ext JS, LLC.
31765 * Originally Released Under LGPL - original licence link has changed is not relivant.
31768 * <script type="text/javascript">
31772 * @class Roo.bootstrap.layout.Basic
31773 * @extends Roo.util.Observable
31774 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
31775 * and does not have a titlebar, tabs or any other features. All it does is size and position
31776 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
31777 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
31778 * @cfg {string} region the region that it inhabits..
31779 * @cfg {bool} skipConfig skip config?
31783 Roo.bootstrap.layout.Basic = function(config){
31785 this.mgr = config.mgr;
31787 this.position = config.region;
31789 var skipConfig = config.skipConfig;
31793 * @scope Roo.BasicLayoutRegion
31797 * @event beforeremove
31798 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
31799 * @param {Roo.LayoutRegion} this
31800 * @param {Roo.ContentPanel} panel The panel
31801 * @param {Object} e The cancel event object
31803 "beforeremove" : true,
31805 * @event invalidated
31806 * Fires when the layout for this region is changed.
31807 * @param {Roo.LayoutRegion} this
31809 "invalidated" : true,
31811 * @event visibilitychange
31812 * Fires when this region is shown or hidden
31813 * @param {Roo.LayoutRegion} this
31814 * @param {Boolean} visibility true or false
31816 "visibilitychange" : true,
31818 * @event paneladded
31819 * Fires when a panel is added.
31820 * @param {Roo.LayoutRegion} this
31821 * @param {Roo.ContentPanel} panel The panel
31823 "paneladded" : true,
31825 * @event panelremoved
31826 * Fires when a panel is removed.
31827 * @param {Roo.LayoutRegion} this
31828 * @param {Roo.ContentPanel} panel The panel
31830 "panelremoved" : true,
31832 * @event beforecollapse
31833 * Fires when this region before collapse.
31834 * @param {Roo.LayoutRegion} this
31836 "beforecollapse" : true,
31839 * Fires when this region is collapsed.
31840 * @param {Roo.LayoutRegion} this
31842 "collapsed" : true,
31845 * Fires when this region is expanded.
31846 * @param {Roo.LayoutRegion} this
31851 * Fires when this region is slid into view.
31852 * @param {Roo.LayoutRegion} this
31854 "slideshow" : true,
31857 * Fires when this region slides out of view.
31858 * @param {Roo.LayoutRegion} this
31860 "slidehide" : true,
31862 * @event panelactivated
31863 * Fires when a panel is activated.
31864 * @param {Roo.LayoutRegion} this
31865 * @param {Roo.ContentPanel} panel The activated panel
31867 "panelactivated" : true,
31870 * Fires when the user resizes this region.
31871 * @param {Roo.LayoutRegion} this
31872 * @param {Number} newSize The new size (width for east/west, height for north/south)
31876 /** A collection of panels in this region. @type Roo.util.MixedCollection */
31877 this.panels = new Roo.util.MixedCollection();
31878 this.panels.getKey = this.getPanelId.createDelegate(this);
31880 this.activePanel = null;
31881 // ensure listeners are added...
31883 if (config.listeners || config.events) {
31884 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
31885 listeners : config.listeners || {},
31886 events : config.events || {}
31890 if(skipConfig !== true){
31891 this.applyConfig(config);
31895 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
31897 getPanelId : function(p){
31901 applyConfig : function(config){
31902 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
31903 this.config = config;
31908 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
31909 * the width, for horizontal (north, south) the height.
31910 * @param {Number} newSize The new width or height
31912 resizeTo : function(newSize){
31913 var el = this.el ? this.el :
31914 (this.activePanel ? this.activePanel.getEl() : null);
31916 switch(this.position){
31919 el.setWidth(newSize);
31920 this.fireEvent("resized", this, newSize);
31924 el.setHeight(newSize);
31925 this.fireEvent("resized", this, newSize);
31931 getBox : function(){
31932 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
31935 getMargins : function(){
31936 return this.margins;
31939 updateBox : function(box){
31941 var el = this.activePanel.getEl();
31942 el.dom.style.left = box.x + "px";
31943 el.dom.style.top = box.y + "px";
31944 this.activePanel.setSize(box.width, box.height);
31948 * Returns the container element for this region.
31949 * @return {Roo.Element}
31951 getEl : function(){
31952 return this.activePanel;
31956 * Returns true if this region is currently visible.
31957 * @return {Boolean}
31959 isVisible : function(){
31960 return this.activePanel ? true : false;
31963 setActivePanel : function(panel){
31964 panel = this.getPanel(panel);
31965 if(this.activePanel && this.activePanel != panel){
31966 this.activePanel.setActiveState(false);
31967 this.activePanel.getEl().setLeftTop(-10000,-10000);
31969 this.activePanel = panel;
31970 panel.setActiveState(true);
31972 panel.setSize(this.box.width, this.box.height);
31974 this.fireEvent("panelactivated", this, panel);
31975 this.fireEvent("invalidated");
31979 * Show the specified panel.
31980 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
31981 * @return {Roo.ContentPanel} The shown panel or null
31983 showPanel : function(panel){
31984 panel = this.getPanel(panel);
31986 this.setActivePanel(panel);
31992 * Get the active panel for this region.
31993 * @return {Roo.ContentPanel} The active panel or null
31995 getActivePanel : function(){
31996 return this.activePanel;
32000 * Add the passed ContentPanel(s)
32001 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
32002 * @return {Roo.ContentPanel} The panel added (if only one was added)
32004 add : function(panel){
32005 if(arguments.length > 1){
32006 for(var i = 0, len = arguments.length; i < len; i++) {
32007 this.add(arguments[i]);
32011 if(this.hasPanel(panel)){
32012 this.showPanel(panel);
32015 var el = panel.getEl();
32016 if(el.dom.parentNode != this.mgr.el.dom){
32017 this.mgr.el.dom.appendChild(el.dom);
32019 if(panel.setRegion){
32020 panel.setRegion(this);
32022 this.panels.add(panel);
32023 el.setStyle("position", "absolute");
32024 if(!panel.background){
32025 this.setActivePanel(panel);
32026 if(this.config.initialSize && this.panels.getCount()==1){
32027 this.resizeTo(this.config.initialSize);
32030 this.fireEvent("paneladded", this, panel);
32035 * Returns true if the panel is in this region.
32036 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
32037 * @return {Boolean}
32039 hasPanel : function(panel){
32040 if(typeof panel == "object"){ // must be panel obj
32041 panel = panel.getId();
32043 return this.getPanel(panel) ? true : false;
32047 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
32048 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
32049 * @param {Boolean} preservePanel Overrides the config preservePanel option
32050 * @return {Roo.ContentPanel} The panel that was removed
32052 remove : function(panel, preservePanel){
32053 panel = this.getPanel(panel);
32058 this.fireEvent("beforeremove", this, panel, e);
32059 if(e.cancel === true){
32062 var panelId = panel.getId();
32063 this.panels.removeKey(panelId);
32068 * Returns the panel specified or null if it's not in this region.
32069 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
32070 * @return {Roo.ContentPanel}
32072 getPanel : function(id){
32073 if(typeof id == "object"){ // must be panel obj
32076 return this.panels.get(id);
32080 * Returns this regions position (north/south/east/west/center).
32083 getPosition: function(){
32084 return this.position;
32088 * Ext JS Library 1.1.1
32089 * Copyright(c) 2006-2007, Ext JS, LLC.
32091 * Originally Released Under LGPL - original licence link has changed is not relivant.
32094 * <script type="text/javascript">
32098 * @class Roo.bootstrap.layout.Region
32099 * @extends Roo.bootstrap.layout.Basic
32100 * This class represents a region in a layout manager.
32102 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
32103 * @cfg {Object} cmargins Margins for the element when collapsed (defaults to: north/south {top: 2, left: 0, right:0, bottom: 2} or east/west {top: 0, left: 2, right:2, bottom: 0})
32104 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
32105 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
32106 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
32107 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
32108 * @cfg {String} title The title for the region (overrides panel titles)
32109 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
32110 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
32111 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
32112 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
32113 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
32114 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
32115 * the space available, similar to FireFox 1.5 tabs (defaults to false)
32116 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
32117 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
32118 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
32120 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
32121 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
32122 * @cfg {Boolean} disableTabTips True to disable tab tooltips
32123 * @cfg {Number} width For East/West panels
32124 * @cfg {Number} height For North/South panels
32125 * @cfg {Boolean} split To show the splitter
32126 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
32128 * @cfg {string} cls Extra CSS classes to add to region
32130 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
32131 * @cfg {string} region the region that it inhabits..
32134 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
32135 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
32137 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
32138 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
32139 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
32141 Roo.bootstrap.layout.Region = function(config)
32143 this.applyConfig(config);
32145 var mgr = config.mgr;
32146 var pos = config.region;
32147 config.skipConfig = true;
32148 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
32151 this.onRender(mgr.el);
32154 this.visible = true;
32155 this.collapsed = false;
32158 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
32160 position: '', // set by wrapper (eg. north/south etc..)
32162 createBody : function(){
32163 /** This region's body element
32164 * @type Roo.Element */
32165 this.bodyEl = this.el.createChild({
32167 cls: "roo-layout-panel-body tab-content" // bootstrap added...
32171 onRender: function(ctr, pos)
32173 var dh = Roo.DomHelper;
32174 /** This region's container element
32175 * @type Roo.Element */
32176 this.el = dh.append(ctr.dom, {
32178 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
32180 /** This region's title element
32181 * @type Roo.Element */
32183 this.titleEl = dh.append(this.el.dom,
32186 unselectable: "on",
32187 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
32189 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
32190 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
32193 this.titleEl.enableDisplayMode();
32194 /** This region's title text element
32195 * @type HTMLElement */
32196 this.titleTextEl = this.titleEl.dom.firstChild;
32197 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
32199 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
32200 this.closeBtn.enableDisplayMode();
32201 this.closeBtn.on("click", this.closeClicked, this);
32202 this.closeBtn.hide();
32204 this.createBody(this.config);
32205 if(this.config.hideWhenEmpty){
32207 this.on("paneladded", this.validateVisibility, this);
32208 this.on("panelremoved", this.validateVisibility, this);
32210 if(this.autoScroll){
32211 this.bodyEl.setStyle("overflow", "auto");
32213 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
32215 //if(c.titlebar !== false){
32216 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
32217 this.titleEl.hide();
32219 this.titleEl.show();
32220 if(this.config.title){
32221 this.titleTextEl.innerHTML = this.config.title;
32225 if(this.config.collapsed){
32226 this.collapse(true);
32228 if(this.config.hidden){
32233 applyConfig : function(c)
32236 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
32237 var dh = Roo.DomHelper;
32238 if(c.titlebar !== false){
32239 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
32240 this.collapseBtn.on("click", this.collapse, this);
32241 this.collapseBtn.enableDisplayMode();
32243 if(c.showPin === true || this.showPin){
32244 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
32245 this.stickBtn.enableDisplayMode();
32246 this.stickBtn.on("click", this.expand, this);
32247 this.stickBtn.hide();
32252 /** This region's collapsed element
32253 * @type Roo.Element */
32256 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
32257 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
32260 if(c.floatable !== false){
32261 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
32262 this.collapsedEl.on("click", this.collapseClick, this);
32265 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
32266 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
32267 id: "message", unselectable: "on", style:{"float":"left"}});
32268 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
32270 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
32271 this.expandBtn.on("click", this.expand, this);
32275 if(this.collapseBtn){
32276 this.collapseBtn.setVisible(c.collapsible == true);
32279 this.cmargins = c.cmargins || this.cmargins ||
32280 (this.position == "west" || this.position == "east" ?
32281 {top: 0, left: 2, right:2, bottom: 0} :
32282 {top: 2, left: 0, right:0, bottom: 2});
32284 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
32287 this.bottomTabs = c.tabPosition != "top";
32289 this.autoScroll = c.autoScroll || false;
32294 this.duration = c.duration || .30;
32295 this.slideDuration = c.slideDuration || .45;
32300 * Returns true if this region is currently visible.
32301 * @return {Boolean}
32303 isVisible : function(){
32304 return this.visible;
32308 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
32309 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
32311 //setCollapsedTitle : function(title){
32312 // title = title || " ";
32313 // if(this.collapsedTitleTextEl){
32314 // this.collapsedTitleTextEl.innerHTML = title;
32318 getBox : function(){
32320 // if(!this.collapsed){
32321 b = this.el.getBox(false, true);
32323 // b = this.collapsedEl.getBox(false, true);
32328 getMargins : function(){
32329 return this.margins;
32330 //return this.collapsed ? this.cmargins : this.margins;
32333 highlight : function(){
32334 this.el.addClass("x-layout-panel-dragover");
32337 unhighlight : function(){
32338 this.el.removeClass("x-layout-panel-dragover");
32341 updateBox : function(box)
32344 if(!this.collapsed){
32345 this.el.dom.style.left = box.x + "px";
32346 this.el.dom.style.top = box.y + "px";
32347 this.updateBody(box.width, box.height);
32349 this.collapsedEl.dom.style.left = box.x + "px";
32350 this.collapsedEl.dom.style.top = box.y + "px";
32351 this.collapsedEl.setSize(box.width, box.height);
32354 this.tabs.autoSizeTabs();
32358 updateBody : function(w, h)
32361 this.el.setWidth(w);
32362 w -= this.el.getBorderWidth("rl");
32363 if(this.config.adjustments){
32364 w += this.config.adjustments[0];
32368 this.el.setHeight(h);
32369 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
32370 h -= this.el.getBorderWidth("tb");
32371 if(this.config.adjustments){
32372 h += this.config.adjustments[1];
32374 this.bodyEl.setHeight(h);
32376 h = this.tabs.syncHeight(h);
32379 if(this.panelSize){
32380 w = w !== null ? w : this.panelSize.width;
32381 h = h !== null ? h : this.panelSize.height;
32383 if(this.activePanel){
32384 var el = this.activePanel.getEl();
32385 w = w !== null ? w : el.getWidth();
32386 h = h !== null ? h : el.getHeight();
32387 this.panelSize = {width: w, height: h};
32388 this.activePanel.setSize(w, h);
32390 if(Roo.isIE && this.tabs){
32391 this.tabs.el.repaint();
32396 * Returns the container element for this region.
32397 * @return {Roo.Element}
32399 getEl : function(){
32404 * Hides this region.
32407 //if(!this.collapsed){
32408 this.el.dom.style.left = "-2000px";
32411 // this.collapsedEl.dom.style.left = "-2000px";
32412 // this.collapsedEl.hide();
32414 this.visible = false;
32415 this.fireEvent("visibilitychange", this, false);
32419 * Shows this region if it was previously hidden.
32422 //if(!this.collapsed){
32425 // this.collapsedEl.show();
32427 this.visible = true;
32428 this.fireEvent("visibilitychange", this, true);
32431 closeClicked : function(){
32432 if(this.activePanel){
32433 this.remove(this.activePanel);
32437 collapseClick : function(e){
32439 e.stopPropagation();
32442 e.stopPropagation();
32448 * Collapses this region.
32449 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
32452 collapse : function(skipAnim, skipCheck = false){
32453 if(this.collapsed) {
32457 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
32459 this.collapsed = true;
32461 this.split.el.hide();
32463 if(this.config.animate && skipAnim !== true){
32464 this.fireEvent("invalidated", this);
32465 this.animateCollapse();
32467 this.el.setLocation(-20000,-20000);
32469 this.collapsedEl.show();
32470 this.fireEvent("collapsed", this);
32471 this.fireEvent("invalidated", this);
32477 animateCollapse : function(){
32482 * Expands this region if it was previously collapsed.
32483 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
32484 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
32487 expand : function(e, skipAnim){
32489 e.stopPropagation();
32491 if(!this.collapsed || this.el.hasActiveFx()) {
32495 this.afterSlideIn();
32498 this.collapsed = false;
32499 if(this.config.animate && skipAnim !== true){
32500 this.animateExpand();
32504 this.split.el.show();
32506 this.collapsedEl.setLocation(-2000,-2000);
32507 this.collapsedEl.hide();
32508 this.fireEvent("invalidated", this);
32509 this.fireEvent("expanded", this);
32513 animateExpand : function(){
32517 initTabs : function()
32519 this.bodyEl.setStyle("overflow", "hidden");
32520 var ts = new Roo.bootstrap.panel.Tabs({
32521 el: this.bodyEl.dom,
32522 tabPosition: this.bottomTabs ? 'bottom' : 'top',
32523 disableTooltips: this.config.disableTabTips,
32524 toolbar : this.config.toolbar
32527 if(this.config.hideTabs){
32528 ts.stripWrap.setDisplayed(false);
32531 ts.resizeTabs = this.config.resizeTabs === true;
32532 ts.minTabWidth = this.config.minTabWidth || 40;
32533 ts.maxTabWidth = this.config.maxTabWidth || 250;
32534 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
32535 ts.monitorResize = false;
32536 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
32537 ts.bodyEl.addClass('roo-layout-tabs-body');
32538 this.panels.each(this.initPanelAsTab, this);
32541 initPanelAsTab : function(panel){
32542 var ti = this.tabs.addTab(
32544 panel.getTitle(), null,
32545 this.config.closeOnTab && panel.isClosable()
32547 if(panel.tabTip !== undefined){
32548 ti.setTooltip(panel.tabTip);
32550 ti.on("activate", function(){
32551 this.setActivePanel(panel);
32554 if(this.config.closeOnTab){
32555 ti.on("beforeclose", function(t, e){
32557 this.remove(panel);
32563 updatePanelTitle : function(panel, title)
32565 if(this.activePanel == panel){
32566 this.updateTitle(title);
32569 var ti = this.tabs.getTab(panel.getEl().id);
32571 if(panel.tabTip !== undefined){
32572 ti.setTooltip(panel.tabTip);
32577 updateTitle : function(title){
32578 if(this.titleTextEl && !this.config.title){
32579 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
32583 setActivePanel : function(panel)
32585 panel = this.getPanel(panel);
32586 if(this.activePanel && this.activePanel != panel){
32587 this.activePanel.setActiveState(false);
32589 this.activePanel = panel;
32590 panel.setActiveState(true);
32591 if(this.panelSize){
32592 panel.setSize(this.panelSize.width, this.panelSize.height);
32595 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
32597 this.updateTitle(panel.getTitle());
32599 this.fireEvent("invalidated", this);
32601 this.fireEvent("panelactivated", this, panel);
32605 * Shows the specified panel.
32606 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
32607 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
32609 showPanel : function(panel)
32611 panel = this.getPanel(panel);
32614 var tab = this.tabs.getTab(panel.getEl().id);
32615 if(tab.isHidden()){
32616 this.tabs.unhideTab(tab.id);
32620 this.setActivePanel(panel);
32627 * Get the active panel for this region.
32628 * @return {Roo.ContentPanel} The active panel or null
32630 getActivePanel : function(){
32631 return this.activePanel;
32634 validateVisibility : function(){
32635 if(this.panels.getCount() < 1){
32636 this.updateTitle(" ");
32637 this.closeBtn.hide();
32640 if(!this.isVisible()){
32647 * Adds the passed ContentPanel(s) to this region.
32648 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
32649 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
32651 add : function(panel){
32652 if(arguments.length > 1){
32653 for(var i = 0, len = arguments.length; i < len; i++) {
32654 this.add(arguments[i]);
32658 if(this.hasPanel(panel)){
32659 this.showPanel(panel);
32662 panel.setRegion(this);
32663 this.panels.add(panel);
32664 if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
32665 this.bodyEl.dom.appendChild(panel.getEl().dom);
32666 if(panel.background !== true){
32667 this.setActivePanel(panel);
32669 this.fireEvent("paneladded", this, panel);
32675 this.initPanelAsTab(panel);
32679 if(panel.background !== true){
32680 this.tabs.activate(panel.getEl().id);
32682 this.fireEvent("paneladded", this, panel);
32687 * Hides the tab for the specified panel.
32688 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
32690 hidePanel : function(panel){
32691 if(this.tabs && (panel = this.getPanel(panel))){
32692 this.tabs.hideTab(panel.getEl().id);
32697 * Unhides the tab for a previously hidden panel.
32698 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
32700 unhidePanel : function(panel){
32701 if(this.tabs && (panel = this.getPanel(panel))){
32702 this.tabs.unhideTab(panel.getEl().id);
32706 clearPanels : function(){
32707 while(this.panels.getCount() > 0){
32708 this.remove(this.panels.first());
32713 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
32714 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
32715 * @param {Boolean} preservePanel Overrides the config preservePanel option
32716 * @return {Roo.ContentPanel} The panel that was removed
32718 remove : function(panel, preservePanel)
32720 panel = this.getPanel(panel);
32725 this.fireEvent("beforeremove", this, panel, e);
32726 if(e.cancel === true){
32729 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
32730 var panelId = panel.getId();
32731 this.panels.removeKey(panelId);
32733 document.body.appendChild(panel.getEl().dom);
32736 this.tabs.removeTab(panel.getEl().id);
32737 }else if (!preservePanel){
32738 this.bodyEl.dom.removeChild(panel.getEl().dom);
32740 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
32741 var p = this.panels.first();
32742 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
32743 tempEl.appendChild(p.getEl().dom);
32744 this.bodyEl.update("");
32745 this.bodyEl.dom.appendChild(p.getEl().dom);
32747 this.updateTitle(p.getTitle());
32749 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
32750 this.setActivePanel(p);
32752 panel.setRegion(null);
32753 if(this.activePanel == panel){
32754 this.activePanel = null;
32756 if(this.config.autoDestroy !== false && preservePanel !== true){
32757 try{panel.destroy();}catch(e){}
32759 this.fireEvent("panelremoved", this, panel);
32764 * Returns the TabPanel component used by this region
32765 * @return {Roo.TabPanel}
32767 getTabs : function(){
32771 createTool : function(parentEl, className){
32772 var btn = Roo.DomHelper.append(parentEl, {
32774 cls: "x-layout-tools-button",
32777 cls: "roo-layout-tools-button-inner " + className,
32781 btn.addClassOnOver("roo-layout-tools-button-over");
32786 * Ext JS Library 1.1.1
32787 * Copyright(c) 2006-2007, Ext JS, LLC.
32789 * Originally Released Under LGPL - original licence link has changed is not relivant.
32792 * <script type="text/javascript">
32798 * @class Roo.SplitLayoutRegion
32799 * @extends Roo.LayoutRegion
32800 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
32802 Roo.bootstrap.layout.Split = function(config){
32803 this.cursor = config.cursor;
32804 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
32807 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
32809 splitTip : "Drag to resize.",
32810 collapsibleSplitTip : "Drag to resize. Double click to hide.",
32811 useSplitTips : false,
32813 applyConfig : function(config){
32814 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
32817 onRender : function(ctr,pos) {
32819 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
32820 if(!this.config.split){
32825 var splitEl = Roo.DomHelper.append(ctr.dom, {
32827 id: this.el.id + "-split",
32828 cls: "roo-layout-split roo-layout-split-"+this.position,
32831 /** The SplitBar for this region
32832 * @type Roo.SplitBar */
32833 // does not exist yet...
32834 Roo.log([this.position, this.orientation]);
32836 this.split = new Roo.bootstrap.SplitBar({
32837 dragElement : splitEl,
32838 resizingElement: this.el,
32839 orientation : this.orientation
32842 this.split.on("moved", this.onSplitMove, this);
32843 this.split.useShim = this.config.useShim === true;
32844 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
32845 if(this.useSplitTips){
32846 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
32848 //if(config.collapsible){
32849 // this.split.el.on("dblclick", this.collapse, this);
32852 if(typeof this.config.minSize != "undefined"){
32853 this.split.minSize = this.config.minSize;
32855 if(typeof this.config.maxSize != "undefined"){
32856 this.split.maxSize = this.config.maxSize;
32858 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
32859 this.hideSplitter();
32864 getHMaxSize : function(){
32865 var cmax = this.config.maxSize || 10000;
32866 var center = this.mgr.getRegion("center");
32867 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
32870 getVMaxSize : function(){
32871 var cmax = this.config.maxSize || 10000;
32872 var center = this.mgr.getRegion("center");
32873 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
32876 onSplitMove : function(split, newSize){
32877 this.fireEvent("resized", this, newSize);
32881 * Returns the {@link Roo.SplitBar} for this region.
32882 * @return {Roo.SplitBar}
32884 getSplitBar : function(){
32889 this.hideSplitter();
32890 Roo.bootstrap.layout.Split.superclass.hide.call(this);
32893 hideSplitter : function(){
32895 this.split.el.setLocation(-2000,-2000);
32896 this.split.el.hide();
32902 this.split.el.show();
32904 Roo.bootstrap.layout.Split.superclass.show.call(this);
32907 beforeSlide: function(){
32908 if(Roo.isGecko){// firefox overflow auto bug workaround
32909 this.bodyEl.clip();
32911 this.tabs.bodyEl.clip();
32913 if(this.activePanel){
32914 this.activePanel.getEl().clip();
32916 if(this.activePanel.beforeSlide){
32917 this.activePanel.beforeSlide();
32923 afterSlide : function(){
32924 if(Roo.isGecko){// firefox overflow auto bug workaround
32925 this.bodyEl.unclip();
32927 this.tabs.bodyEl.unclip();
32929 if(this.activePanel){
32930 this.activePanel.getEl().unclip();
32931 if(this.activePanel.afterSlide){
32932 this.activePanel.afterSlide();
32938 initAutoHide : function(){
32939 if(this.autoHide !== false){
32940 if(!this.autoHideHd){
32941 var st = new Roo.util.DelayedTask(this.slideIn, this);
32942 this.autoHideHd = {
32943 "mouseout": function(e){
32944 if(!e.within(this.el, true)){
32948 "mouseover" : function(e){
32954 this.el.on(this.autoHideHd);
32958 clearAutoHide : function(){
32959 if(this.autoHide !== false){
32960 this.el.un("mouseout", this.autoHideHd.mouseout);
32961 this.el.un("mouseover", this.autoHideHd.mouseover);
32965 clearMonitor : function(){
32966 Roo.get(document).un("click", this.slideInIf, this);
32969 // these names are backwards but not changed for compat
32970 slideOut : function(){
32971 if(this.isSlid || this.el.hasActiveFx()){
32974 this.isSlid = true;
32975 if(this.collapseBtn){
32976 this.collapseBtn.hide();
32978 this.closeBtnState = this.closeBtn.getStyle('display');
32979 this.closeBtn.hide();
32981 this.stickBtn.show();
32984 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
32985 this.beforeSlide();
32986 this.el.setStyle("z-index", 10001);
32987 this.el.slideIn(this.getSlideAnchor(), {
32988 callback: function(){
32990 this.initAutoHide();
32991 Roo.get(document).on("click", this.slideInIf, this);
32992 this.fireEvent("slideshow", this);
32999 afterSlideIn : function(){
33000 this.clearAutoHide();
33001 this.isSlid = false;
33002 this.clearMonitor();
33003 this.el.setStyle("z-index", "");
33004 if(this.collapseBtn){
33005 this.collapseBtn.show();
33007 this.closeBtn.setStyle('display', this.closeBtnState);
33009 this.stickBtn.hide();
33011 this.fireEvent("slidehide", this);
33014 slideIn : function(cb){
33015 if(!this.isSlid || this.el.hasActiveFx()){
33019 this.isSlid = false;
33020 this.beforeSlide();
33021 this.el.slideOut(this.getSlideAnchor(), {
33022 callback: function(){
33023 this.el.setLeftTop(-10000, -10000);
33025 this.afterSlideIn();
33033 slideInIf : function(e){
33034 if(!e.within(this.el)){
33039 animateCollapse : function(){
33040 this.beforeSlide();
33041 this.el.setStyle("z-index", 20000);
33042 var anchor = this.getSlideAnchor();
33043 this.el.slideOut(anchor, {
33044 callback : function(){
33045 this.el.setStyle("z-index", "");
33046 this.collapsedEl.slideIn(anchor, {duration:.3});
33048 this.el.setLocation(-10000,-10000);
33050 this.fireEvent("collapsed", this);
33057 animateExpand : function(){
33058 this.beforeSlide();
33059 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
33060 this.el.setStyle("z-index", 20000);
33061 this.collapsedEl.hide({
33064 this.el.slideIn(this.getSlideAnchor(), {
33065 callback : function(){
33066 this.el.setStyle("z-index", "");
33069 this.split.el.show();
33071 this.fireEvent("invalidated", this);
33072 this.fireEvent("expanded", this);
33100 getAnchor : function(){
33101 return this.anchors[this.position];
33104 getCollapseAnchor : function(){
33105 return this.canchors[this.position];
33108 getSlideAnchor : function(){
33109 return this.sanchors[this.position];
33112 getAlignAdj : function(){
33113 var cm = this.cmargins;
33114 switch(this.position){
33130 getExpandAdj : function(){
33131 var c = this.collapsedEl, cm = this.cmargins;
33132 switch(this.position){
33134 return [-(cm.right+c.getWidth()+cm.left), 0];
33137 return [cm.right+c.getWidth()+cm.left, 0];
33140 return [0, -(cm.top+cm.bottom+c.getHeight())];
33143 return [0, cm.top+cm.bottom+c.getHeight()];
33149 * Ext JS Library 1.1.1
33150 * Copyright(c) 2006-2007, Ext JS, LLC.
33152 * Originally Released Under LGPL - original licence link has changed is not relivant.
33155 * <script type="text/javascript">
33158 * These classes are private internal classes
33160 Roo.bootstrap.layout.Center = function(config){
33161 config.region = "center";
33162 Roo.bootstrap.layout.Region.call(this, config);
33163 this.visible = true;
33164 this.minWidth = config.minWidth || 20;
33165 this.minHeight = config.minHeight || 20;
33168 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
33170 // center panel can't be hidden
33174 // center panel can't be hidden
33177 getMinWidth: function(){
33178 return this.minWidth;
33181 getMinHeight: function(){
33182 return this.minHeight;
33195 Roo.bootstrap.layout.North = function(config)
33197 config.region = 'north';
33198 config.cursor = 'n-resize';
33200 Roo.bootstrap.layout.Split.call(this, config);
33204 this.split.placement = Roo.bootstrap.SplitBar.TOP;
33205 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
33206 this.split.el.addClass("roo-layout-split-v");
33208 var size = config.initialSize || config.height;
33209 if(typeof size != "undefined"){
33210 this.el.setHeight(size);
33213 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
33215 orientation: Roo.bootstrap.SplitBar.VERTICAL,
33219 getBox : function(){
33220 if(this.collapsed){
33221 return this.collapsedEl.getBox();
33223 var box = this.el.getBox();
33225 box.height += this.split.el.getHeight();
33230 updateBox : function(box){
33231 if(this.split && !this.collapsed){
33232 box.height -= this.split.el.getHeight();
33233 this.split.el.setLeft(box.x);
33234 this.split.el.setTop(box.y+box.height);
33235 this.split.el.setWidth(box.width);
33237 if(this.collapsed){
33238 this.updateBody(box.width, null);
33240 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
33248 Roo.bootstrap.layout.South = function(config){
33249 config.region = 'south';
33250 config.cursor = 's-resize';
33251 Roo.bootstrap.layout.Split.call(this, config);
33253 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
33254 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
33255 this.split.el.addClass("roo-layout-split-v");
33257 var size = config.initialSize || config.height;
33258 if(typeof size != "undefined"){
33259 this.el.setHeight(size);
33263 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
33264 orientation: Roo.bootstrap.SplitBar.VERTICAL,
33265 getBox : function(){
33266 if(this.collapsed){
33267 return this.collapsedEl.getBox();
33269 var box = this.el.getBox();
33271 var sh = this.split.el.getHeight();
33278 updateBox : function(box){
33279 if(this.split && !this.collapsed){
33280 var sh = this.split.el.getHeight();
33283 this.split.el.setLeft(box.x);
33284 this.split.el.setTop(box.y-sh);
33285 this.split.el.setWidth(box.width);
33287 if(this.collapsed){
33288 this.updateBody(box.width, null);
33290 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
33294 Roo.bootstrap.layout.East = function(config){
33295 config.region = "east";
33296 config.cursor = "e-resize";
33297 Roo.bootstrap.layout.Split.call(this, config);
33299 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
33300 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
33301 this.split.el.addClass("roo-layout-split-h");
33303 var size = config.initialSize || config.width;
33304 if(typeof size != "undefined"){
33305 this.el.setWidth(size);
33308 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
33309 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
33310 getBox : function(){
33311 if(this.collapsed){
33312 return this.collapsedEl.getBox();
33314 var box = this.el.getBox();
33316 var sw = this.split.el.getWidth();
33323 updateBox : function(box){
33324 if(this.split && !this.collapsed){
33325 var sw = this.split.el.getWidth();
33327 this.split.el.setLeft(box.x);
33328 this.split.el.setTop(box.y);
33329 this.split.el.setHeight(box.height);
33332 if(this.collapsed){
33333 this.updateBody(null, box.height);
33335 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
33339 Roo.bootstrap.layout.West = function(config){
33340 config.region = "west";
33341 config.cursor = "w-resize";
33343 Roo.bootstrap.layout.Split.call(this, config);
33345 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
33346 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
33347 this.split.el.addClass("roo-layout-split-h");
33351 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
33352 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
33354 onRender: function(ctr, pos)
33356 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
33357 var size = this.config.initialSize || this.config.width;
33358 if(typeof size != "undefined"){
33359 this.el.setWidth(size);
33363 getBox : function(){
33364 if(this.collapsed){
33365 return this.collapsedEl.getBox();
33367 var box = this.el.getBox();
33369 box.width += this.split.el.getWidth();
33374 updateBox : function(box){
33375 if(this.split && !this.collapsed){
33376 var sw = this.split.el.getWidth();
33378 this.split.el.setLeft(box.x+box.width);
33379 this.split.el.setTop(box.y);
33380 this.split.el.setHeight(box.height);
33382 if(this.collapsed){
33383 this.updateBody(null, box.height);
33385 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
33388 Roo.namespace("Roo.bootstrap.panel");/*
33390 * Ext JS Library 1.1.1
33391 * Copyright(c) 2006-2007, Ext JS, LLC.
33393 * Originally Released Under LGPL - original licence link has changed is not relivant.
33396 * <script type="text/javascript">
33399 * @class Roo.ContentPanel
33400 * @extends Roo.util.Observable
33401 * A basic ContentPanel element.
33402 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
33403 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
33404 * @cfg {Boolean/Object} autoCreate True to auto generate the DOM element for this panel, or a {@link Roo.DomHelper} config of the element to create
33405 * @cfg {Boolean} closable True if the panel can be closed/removed
33406 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
33407 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
33408 * @cfg {Toolbar} toolbar A toolbar for this panel
33409 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
33410 * @cfg {String} title The title for this panel
33411 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
33412 * @cfg {String} url Calls {@link #setUrl} with this value
33413 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
33414 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
33415 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
33416 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
33419 * Create a new ContentPanel.
33420 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
33421 * @param {String/Object} config A string to set only the title or a config object
33422 * @param {String} content (optional) Set the HTML content for this panel
33423 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
33425 Roo.bootstrap.panel.Content = function( config){
33427 var el = config.el;
33428 var content = config.content;
33430 if(config.autoCreate){ // xtype is available if this is called from factory
33433 this.el = Roo.get(el);
33434 if(!this.el && config && config.autoCreate){
33435 if(typeof config.autoCreate == "object"){
33436 if(!config.autoCreate.id){
33437 config.autoCreate.id = config.id||el;
33439 this.el = Roo.DomHelper.append(document.body,
33440 config.autoCreate, true);
33442 var elcfg = { tag: "div",
33443 cls: "roo-layout-inactive-content",
33447 elcfg.html = config.html;
33451 this.el = Roo.DomHelper.append(document.body, elcfg , true);
33454 this.closable = false;
33455 this.loaded = false;
33456 this.active = false;
33459 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
33461 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
33463 this.wrapEl = this.el.wrap();
33465 if (config.toolbar.items) {
33466 ti = config.toolbar.items ;
33467 delete config.toolbar.items ;
33471 this.toolbar.render(this.wrapEl, 'before');
33472 for(var i =0;i < ti.length;i++) {
33473 // Roo.log(['add child', items[i]]);
33474 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
33476 this.toolbar.items = nitems;
33477 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
33478 delete config.toolbar;
33482 // xtype created footer. - not sure if will work as we normally have to render first..
33483 if (this.footer && !this.footer.el && this.footer.xtype) {
33484 if (!this.wrapEl) {
33485 this.wrapEl = this.el.wrap();
33488 this.footer.container = this.wrapEl.createChild();
33490 this.footer = Roo.factory(this.footer, Roo);
33495 if(typeof config == "string"){
33496 this.title = config;
33498 Roo.apply(this, config);
33502 this.resizeEl = Roo.get(this.resizeEl, true);
33504 this.resizeEl = this.el;
33506 // handle view.xtype
33514 * Fires when this panel is activated.
33515 * @param {Roo.ContentPanel} this
33519 * @event deactivate
33520 * Fires when this panel is activated.
33521 * @param {Roo.ContentPanel} this
33523 "deactivate" : true,
33527 * Fires when this panel is resized if fitToFrame is true.
33528 * @param {Roo.ContentPanel} this
33529 * @param {Number} width The width after any component adjustments
33530 * @param {Number} height The height after any component adjustments
33536 * Fires when this tab is created
33537 * @param {Roo.ContentPanel} this
33548 if(this.autoScroll){
33549 this.resizeEl.setStyle("overflow", "auto");
33551 // fix randome scrolling
33552 //this.el.on('scroll', function() {
33553 // Roo.log('fix random scolling');
33554 // this.scrollTo('top',0);
33557 content = content || this.content;
33559 this.setContent(content);
33561 if(config && config.url){
33562 this.setUrl(this.url, this.params, this.loadOnce);
33567 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
33569 if (this.view && typeof(this.view.xtype) != 'undefined') {
33570 this.view.el = this.el.appendChild(document.createElement("div"));
33571 this.view = Roo.factory(this.view);
33572 this.view.render && this.view.render(false, '');
33576 this.fireEvent('render', this);
33579 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
33581 setRegion : function(region){
33582 this.region = region;
33584 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
33586 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
33591 * Returns the toolbar for this Panel if one was configured.
33592 * @return {Roo.Toolbar}
33594 getToolbar : function(){
33595 return this.toolbar;
33598 setActiveState : function(active){
33599 this.active = active;
33601 this.fireEvent("deactivate", this);
33603 this.fireEvent("activate", this);
33607 * Updates this panel's element
33608 * @param {String} content The new content
33609 * @param {Boolean} loadScripts (optional) true to look for and process scripts
33611 setContent : function(content, loadScripts){
33612 this.el.update(content, loadScripts);
33615 ignoreResize : function(w, h){
33616 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
33619 this.lastSize = {width: w, height: h};
33624 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
33625 * @return {Roo.UpdateManager} The UpdateManager
33627 getUpdateManager : function(){
33628 return this.el.getUpdateManager();
33631 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
33632 * @param {Object/String/Function} url The url for this request or a function to call to get the url or a config object containing any of the following options:
33635 url: "your-url.php",
33636 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
33637 callback: yourFunction,
33638 scope: yourObject, //(optional scope)
33641 text: "Loading...",
33646 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
33647 * are shorthand for <i>disableCaching</i>, <i>indicatorText</i> and <i>loadScripts</i> and are used to set their associated property on this panel UpdateManager instance.
33648 * @param {String/Object} params (optional) The parameters to pass as either a URL encoded string "param1=1&param2=2" or an object {param1: 1, param2: 2}
33649 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
33650 * @param {Boolean} discardUrl (optional) By default when you execute an update the defaultUrl is changed to the last used URL. If true, it will not store the URL.
33651 * @return {Roo.ContentPanel} this
33654 var um = this.el.getUpdateManager();
33655 um.update.apply(um, arguments);
33661 * Set a URL to be used to load the content for this panel. When this panel is activated, the content will be loaded from that URL.
33662 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
33663 * @param {String/Object} params (optional) The string params for the update call or an object of the params. See {@link Roo.UpdateManager#update} for more details. (Defaults to null)
33664 * @param {Boolean} loadOnce (optional) Whether to only load the content once. If this is false it makes the Ajax call every time this panel is activated. (Defaults to false)
33665 * @return {Roo.UpdateManager} The UpdateManager
33667 setUrl : function(url, params, loadOnce){
33668 if(this.refreshDelegate){
33669 this.removeListener("activate", this.refreshDelegate);
33671 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
33672 this.on("activate", this.refreshDelegate);
33673 return this.el.getUpdateManager();
33676 _handleRefresh : function(url, params, loadOnce){
33677 if(!loadOnce || !this.loaded){
33678 var updater = this.el.getUpdateManager();
33679 updater.update(url, params, this._setLoaded.createDelegate(this));
33683 _setLoaded : function(){
33684 this.loaded = true;
33688 * Returns this panel's id
33691 getId : function(){
33696 * Returns this panel's element - used by regiosn to add.
33697 * @return {Roo.Element}
33699 getEl : function(){
33700 return this.wrapEl || this.el;
33705 adjustForComponents : function(width, height)
33707 //Roo.log('adjustForComponents ');
33708 if(this.resizeEl != this.el){
33709 width -= this.el.getFrameWidth('lr');
33710 height -= this.el.getFrameWidth('tb');
33713 var te = this.toolbar.getEl();
33714 height -= te.getHeight();
33715 te.setWidth(width);
33718 var te = this.footer.getEl();
33719 Roo.log("footer:" + te.getHeight());
33721 height -= te.getHeight();
33722 te.setWidth(width);
33726 if(this.adjustments){
33727 width += this.adjustments[0];
33728 height += this.adjustments[1];
33730 return {"width": width, "height": height};
33733 setSize : function(width, height){
33734 if(this.fitToFrame && !this.ignoreResize(width, height)){
33735 if(this.fitContainer && this.resizeEl != this.el){
33736 this.el.setSize(width, height);
33738 var size = this.adjustForComponents(width, height);
33739 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
33740 this.fireEvent('resize', this, size.width, size.height);
33745 * Returns this panel's title
33748 getTitle : function(){
33753 * Set this panel's title
33754 * @param {String} title
33756 setTitle : function(title){
33757 this.title = title;
33759 this.region.updatePanelTitle(this, title);
33764 * Returns true is this panel was configured to be closable
33765 * @return {Boolean}
33767 isClosable : function(){
33768 return this.closable;
33771 beforeSlide : function(){
33773 this.resizeEl.clip();
33776 afterSlide : function(){
33778 this.resizeEl.unclip();
33782 * Force a content refresh from the URL specified in the {@link #setUrl} method.
33783 * Will fail silently if the {@link #setUrl} method has not been called.
33784 * This does not activate the panel, just updates its content.
33786 refresh : function(){
33787 if(this.refreshDelegate){
33788 this.loaded = false;
33789 this.refreshDelegate();
33794 * Destroys this panel
33796 destroy : function(){
33797 this.el.removeAllListeners();
33798 var tempEl = document.createElement("span");
33799 tempEl.appendChild(this.el.dom);
33800 tempEl.innerHTML = "";
33806 * form - if the content panel contains a form - this is a reference to it.
33807 * @type {Roo.form.Form}
33811 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
33812 * This contains a reference to it.
33818 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
33828 * @param {Object} cfg Xtype definition of item to add.
33832 getChildContainer: function () {
33833 return this.getEl();
33838 var ret = new Roo.factory(cfg);
33843 if (cfg.xtype.match(/^Form$/)) {
33846 //if (this.footer) {
33847 // el = this.footer.container.insertSibling(false, 'before');
33849 el = this.el.createChild();
33852 this.form = new Roo.form.Form(cfg);
33855 if ( this.form.allItems.length) {
33856 this.form.render(el.dom);
33860 // should only have one of theses..
33861 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
33862 // views.. should not be just added - used named prop 'view''
33864 cfg.el = this.el.appendChild(document.createElement("div"));
33867 var ret = new Roo.factory(cfg);
33869 ret.render && ret.render(false, ''); // render blank..
33879 * @class Roo.bootstrap.panel.Grid
33880 * @extends Roo.bootstrap.panel.Content
33882 * Create a new GridPanel.
33883 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
33884 * @param {Object} config A the config object
33890 Roo.bootstrap.panel.Grid = function(config)
33894 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
33895 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
33897 config.el = this.wrapper;
33898 //this.el = this.wrapper;
33900 if (config.container) {
33901 // ctor'ed from a Border/panel.grid
33904 this.wrapper.setStyle("overflow", "hidden");
33905 this.wrapper.addClass('roo-grid-container');
33910 if(config.toolbar){
33911 var tool_el = this.wrapper.createChild();
33912 this.toolbar = Roo.factory(config.toolbar);
33914 if (config.toolbar.items) {
33915 ti = config.toolbar.items ;
33916 delete config.toolbar.items ;
33920 this.toolbar.render(tool_el);
33921 for(var i =0;i < ti.length;i++) {
33922 // Roo.log(['add child', items[i]]);
33923 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
33925 this.toolbar.items = nitems;
33927 delete config.toolbar;
33930 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
33931 config.grid.scrollBody = true;;
33932 config.grid.monitorWindowResize = false; // turn off autosizing
33933 config.grid.autoHeight = false;
33934 config.grid.autoWidth = false;
33936 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
33938 if (config.background) {
33939 // render grid on panel activation (if panel background)
33940 this.on('activate', function(gp) {
33941 if (!gp.grid.rendered) {
33942 gp.grid.render(el);
33943 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
33949 this.grid.render(this.wrapper);
33950 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
33953 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
33954 // ??? needed ??? config.el = this.wrapper;
33959 // xtype created footer. - not sure if will work as we normally have to render first..
33960 if (this.footer && !this.footer.el && this.footer.xtype) {
33962 var ctr = this.grid.getView().getFooterPanel(true);
33963 this.footer.dataSource = this.grid.dataSource;
33964 this.footer = Roo.factory(this.footer, Roo);
33965 this.footer.render(ctr);
33975 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
33976 getId : function(){
33977 return this.grid.id;
33981 * Returns the grid for this panel
33982 * @return {Roo.bootstrap.Table}
33984 getGrid : function(){
33988 setSize : function(width, height){
33989 if(!this.ignoreResize(width, height)){
33990 var grid = this.grid;
33991 var size = this.adjustForComponents(width, height);
33992 var gridel = grid.getGridEl();
33993 gridel.setSize(size.width, size.height);
33995 var thd = grid.getGridEl().select('thead',true).first();
33996 var tbd = grid.getGridEl().select('tbody', true).first();
33998 tbd.setSize(width, height - thd.getHeight());
34007 beforeSlide : function(){
34008 this.grid.getView().scroller.clip();
34011 afterSlide : function(){
34012 this.grid.getView().scroller.unclip();
34015 destroy : function(){
34016 this.grid.destroy();
34018 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
34023 * @class Roo.bootstrap.panel.Nest
34024 * @extends Roo.bootstrap.panel.Content
34026 * Create a new Panel, that can contain a layout.Border.
34029 * @param {Roo.BorderLayout} layout The layout for this panel
34030 * @param {String/Object} config A string to set only the title or a config object
34032 Roo.bootstrap.panel.Nest = function(config)
34034 // construct with only one argument..
34035 /* FIXME - implement nicer consturctors
34036 if (layout.layout) {
34038 layout = config.layout;
34039 delete config.layout;
34041 if (layout.xtype && !layout.getEl) {
34042 // then layout needs constructing..
34043 layout = Roo.factory(layout, Roo);
34047 config.el = config.layout.getEl();
34049 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
34051 config.layout.monitorWindowResize = false; // turn off autosizing
34052 this.layout = config.layout;
34053 this.layout.getEl().addClass("roo-layout-nested-layout");
34060 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
34062 setSize : function(width, height){
34063 if(!this.ignoreResize(width, height)){
34064 var size = this.adjustForComponents(width, height);
34065 var el = this.layout.getEl();
34066 el.setSize(size.width, size.height);
34067 var touch = el.dom.offsetWidth;
34068 this.layout.layout();
34069 // ie requires a double layout on the first pass
34070 if(Roo.isIE && !this.initialized){
34071 this.initialized = true;
34072 this.layout.layout();
34077 // activate all subpanels if not currently active..
34079 setActiveState : function(active){
34080 this.active = active;
34082 this.fireEvent("deactivate", this);
34086 this.fireEvent("activate", this);
34087 // not sure if this should happen before or after..
34088 if (!this.layout) {
34089 return; // should not happen..
34092 for (var r in this.layout.regions) {
34093 reg = this.layout.getRegion(r);
34094 if (reg.getActivePanel()) {
34095 //reg.showPanel(reg.getActivePanel()); // force it to activate..
34096 reg.setActivePanel(reg.getActivePanel());
34099 if (!reg.panels.length) {
34102 reg.showPanel(reg.getPanel(0));
34111 * Returns the nested BorderLayout for this panel
34112 * @return {Roo.BorderLayout}
34114 getLayout : function(){
34115 return this.layout;
34119 * Adds a xtype elements to the layout of the nested panel
34123 xtype : 'ContentPanel',
34130 xtype : 'NestedLayoutPanel',
34136 items : [ ... list of content panels or nested layout panels.. ]
34140 * @param {Object} cfg Xtype definition of item to add.
34142 addxtype : function(cfg) {
34143 return this.layout.addxtype(cfg);
34148 * Ext JS Library 1.1.1
34149 * Copyright(c) 2006-2007, Ext JS, LLC.
34151 * Originally Released Under LGPL - original licence link has changed is not relivant.
34154 * <script type="text/javascript">
34157 * @class Roo.TabPanel
34158 * @extends Roo.util.Observable
34159 * A lightweight tab container.
34163 // basic tabs 1, built from existing content
34164 var tabs = new Roo.TabPanel("tabs1");
34165 tabs.addTab("script", "View Script");
34166 tabs.addTab("markup", "View Markup");
34167 tabs.activate("script");
34169 // more advanced tabs, built from javascript
34170 var jtabs = new Roo.TabPanel("jtabs");
34171 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
34173 // set up the UpdateManager
34174 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
34175 var updater = tab2.getUpdateManager();
34176 updater.setDefaultUrl("ajax1.htm");
34177 tab2.on('activate', updater.refresh, updater, true);
34179 // Use setUrl for Ajax loading
34180 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
34181 tab3.setUrl("ajax2.htm", null, true);
34184 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
34187 jtabs.activate("jtabs-1");
34190 * Create a new TabPanel.
34191 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
34192 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
34194 Roo.bootstrap.panel.Tabs = function(config){
34196 * The container element for this TabPanel.
34197 * @type Roo.Element
34199 this.el = Roo.get(config.el);
34202 if(typeof config == "boolean"){
34203 this.tabPosition = config ? "bottom" : "top";
34205 Roo.apply(this, config);
34209 if(this.tabPosition == "bottom"){
34210 this.bodyEl = Roo.get(this.createBody(this.el.dom));
34211 this.el.addClass("roo-tabs-bottom");
34213 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
34214 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
34215 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
34217 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
34219 if(this.tabPosition != "bottom"){
34220 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
34221 * @type Roo.Element
34223 this.bodyEl = Roo.get(this.createBody(this.el.dom));
34224 this.el.addClass("roo-tabs-top");
34228 this.bodyEl.setStyle("position", "relative");
34230 this.active = null;
34231 this.activateDelegate = this.activate.createDelegate(this);
34236 * Fires when the active tab changes
34237 * @param {Roo.TabPanel} this
34238 * @param {Roo.TabPanelItem} activePanel The new active tab
34242 * @event beforetabchange
34243 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
34244 * @param {Roo.TabPanel} this
34245 * @param {Object} e Set cancel to true on this object to cancel the tab change
34246 * @param {Roo.TabPanelItem} tab The tab being changed to
34248 "beforetabchange" : true
34251 Roo.EventManager.onWindowResize(this.onResize, this);
34252 this.cpad = this.el.getPadding("lr");
34253 this.hiddenCount = 0;
34256 // toolbar on the tabbar support...
34257 if (this.toolbar) {
34258 alert("no toolbar support yet");
34259 this.toolbar = false;
34261 var tcfg = this.toolbar;
34262 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
34263 this.toolbar = new Roo.Toolbar(tcfg);
34264 if (Roo.isSafari) {
34265 var tbl = tcfg.container.child('table', true);
34266 tbl.setAttribute('width', '100%');
34274 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
34277 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
34279 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
34281 tabPosition : "top",
34283 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
34285 currentTabWidth : 0,
34287 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
34291 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
34295 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
34297 preferredTabWidth : 175,
34299 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
34301 resizeTabs : false,
34303 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
34305 monitorResize : true,
34307 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
34312 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
34313 * @param {String} id The id of the div to use <b>or create</b>
34314 * @param {String} text The text for the tab
34315 * @param {String} content (optional) Content to put in the TabPanelItem body
34316 * @param {Boolean} closable (optional) True to create a close icon on the tab
34317 * @return {Roo.TabPanelItem} The created TabPanelItem
34319 addTab : function(id, text, content, closable)
34321 var item = new Roo.bootstrap.panel.TabItem({
34325 closable : closable
34327 this.addTabItem(item);
34329 item.setContent(content);
34335 * Returns the {@link Roo.TabPanelItem} with the specified id/index
34336 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
34337 * @return {Roo.TabPanelItem}
34339 getTab : function(id){
34340 return this.items[id];
34344 * Hides the {@link Roo.TabPanelItem} with the specified id/index
34345 * @param {String/Number} id The id or index of the TabPanelItem to hide.
34347 hideTab : function(id){
34348 var t = this.items[id];
34351 this.hiddenCount++;
34352 this.autoSizeTabs();
34357 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
34358 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
34360 unhideTab : function(id){
34361 var t = this.items[id];
34363 t.setHidden(false);
34364 this.hiddenCount--;
34365 this.autoSizeTabs();
34370 * Adds an existing {@link Roo.TabPanelItem}.
34371 * @param {Roo.TabPanelItem} item The TabPanelItem to add
34373 addTabItem : function(item){
34374 this.items[item.id] = item;
34375 this.items.push(item);
34376 // if(this.resizeTabs){
34377 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
34378 // this.autoSizeTabs();
34380 // item.autoSize();
34385 * Removes a {@link Roo.TabPanelItem}.
34386 * @param {String/Number} id The id or index of the TabPanelItem to remove.
34388 removeTab : function(id){
34389 var items = this.items;
34390 var tab = items[id];
34391 if(!tab) { return; }
34392 var index = items.indexOf(tab);
34393 if(this.active == tab && items.length > 1){
34394 var newTab = this.getNextAvailable(index);
34399 this.stripEl.dom.removeChild(tab.pnode.dom);
34400 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
34401 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
34403 items.splice(index, 1);
34404 delete this.items[tab.id];
34405 tab.fireEvent("close", tab);
34406 tab.purgeListeners();
34407 this.autoSizeTabs();
34410 getNextAvailable : function(start){
34411 var items = this.items;
34413 // look for a next tab that will slide over to
34414 // replace the one being removed
34415 while(index < items.length){
34416 var item = items[++index];
34417 if(item && !item.isHidden()){
34421 // if one isn't found select the previous tab (on the left)
34424 var item = items[--index];
34425 if(item && !item.isHidden()){
34433 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
34434 * @param {String/Number} id The id or index of the TabPanelItem to disable.
34436 disableTab : function(id){
34437 var tab = this.items[id];
34438 if(tab && this.active != tab){
34444 * Enables a {@link Roo.TabPanelItem} that is disabled.
34445 * @param {String/Number} id The id or index of the TabPanelItem to enable.
34447 enableTab : function(id){
34448 var tab = this.items[id];
34453 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
34454 * @param {String/Number} id The id or index of the TabPanelItem to activate.
34455 * @return {Roo.TabPanelItem} The TabPanelItem.
34457 activate : function(id){
34458 var tab = this.items[id];
34462 if(tab == this.active || tab.disabled){
34466 this.fireEvent("beforetabchange", this, e, tab);
34467 if(e.cancel !== true && !tab.disabled){
34469 this.active.hide();
34471 this.active = this.items[id];
34472 this.active.show();
34473 this.fireEvent("tabchange", this, this.active);
34479 * Gets the active {@link Roo.TabPanelItem}.
34480 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
34482 getActiveTab : function(){
34483 return this.active;
34487 * Updates the tab body element to fit the height of the container element
34488 * for overflow scrolling
34489 * @param {Number} targetHeight (optional) Override the starting height from the elements height
34491 syncHeight : function(targetHeight){
34492 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
34493 var bm = this.bodyEl.getMargins();
34494 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
34495 this.bodyEl.setHeight(newHeight);
34499 onResize : function(){
34500 if(this.monitorResize){
34501 this.autoSizeTabs();
34506 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
34508 beginUpdate : function(){
34509 this.updating = true;
34513 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
34515 endUpdate : function(){
34516 this.updating = false;
34517 this.autoSizeTabs();
34521 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
34523 autoSizeTabs : function(){
34524 var count = this.items.length;
34525 var vcount = count - this.hiddenCount;
34526 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
34529 var w = Math.max(this.el.getWidth() - this.cpad, 10);
34530 var availWidth = Math.floor(w / vcount);
34531 var b = this.stripBody;
34532 if(b.getWidth() > w){
34533 var tabs = this.items;
34534 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
34535 if(availWidth < this.minTabWidth){
34536 /*if(!this.sleft){ // incomplete scrolling code
34537 this.createScrollButtons();
34540 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
34543 if(this.currentTabWidth < this.preferredTabWidth){
34544 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
34550 * Returns the number of tabs in this TabPanel.
34553 getCount : function(){
34554 return this.items.length;
34558 * Resizes all the tabs to the passed width
34559 * @param {Number} The new width
34561 setTabWidth : function(width){
34562 this.currentTabWidth = width;
34563 for(var i = 0, len = this.items.length; i < len; i++) {
34564 if(!this.items[i].isHidden()) {
34565 this.items[i].setWidth(width);
34571 * Destroys this TabPanel
34572 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
34574 destroy : function(removeEl){
34575 Roo.EventManager.removeResizeListener(this.onResize, this);
34576 for(var i = 0, len = this.items.length; i < len; i++){
34577 this.items[i].purgeListeners();
34579 if(removeEl === true){
34580 this.el.update("");
34585 createStrip : function(container)
34587 var strip = document.createElement("nav");
34588 strip.className = "navbar navbar-default"; //"x-tabs-wrap";
34589 container.appendChild(strip);
34593 createStripList : function(strip)
34595 // div wrapper for retard IE
34596 // returns the "tr" element.
34597 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
34598 //'<div class="x-tabs-strip-wrap">'+
34599 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
34600 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
34601 return strip.firstChild; //.firstChild.firstChild.firstChild;
34603 createBody : function(container)
34605 var body = document.createElement("div");
34606 Roo.id(body, "tab-body");
34607 //Roo.fly(body).addClass("x-tabs-body");
34608 Roo.fly(body).addClass("tab-content");
34609 container.appendChild(body);
34612 createItemBody :function(bodyEl, id){
34613 var body = Roo.getDom(id);
34615 body = document.createElement("div");
34618 //Roo.fly(body).addClass("x-tabs-item-body");
34619 Roo.fly(body).addClass("tab-pane");
34620 bodyEl.insertBefore(body, bodyEl.firstChild);
34624 createStripElements : function(stripEl, text, closable)
34626 var td = document.createElement("li"); // was td..
34627 stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
34628 //stripEl.appendChild(td);
34630 td.className = "x-tabs-closable";
34631 if(!this.closeTpl){
34632 this.closeTpl = new Roo.Template(
34633 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
34634 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
34635 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
34638 var el = this.closeTpl.overwrite(td, {"text": text});
34639 var close = el.getElementsByTagName("div")[0];
34640 var inner = el.getElementsByTagName("em")[0];
34641 return {"el": el, "close": close, "inner": inner};
34644 // not sure what this is..
34646 //this.tabTpl = new Roo.Template(
34647 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
34648 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
34650 this.tabTpl = new Roo.Template(
34652 '<span unselectable="on"' +
34653 (this.disableTooltips ? '' : ' title="{text}"') +
34654 ' >{text}</span></span></a>'
34658 var el = this.tabTpl.overwrite(td, {"text": text});
34659 var inner = el.getElementsByTagName("span")[0];
34660 return {"el": el, "inner": inner};
34668 * @class Roo.TabPanelItem
34669 * @extends Roo.util.Observable
34670 * Represents an individual item (tab plus body) in a TabPanel.
34671 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
34672 * @param {String} id The id of this TabPanelItem
34673 * @param {String} text The text for the tab of this TabPanelItem
34674 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
34676 Roo.bootstrap.panel.TabItem = function(config){
34678 * The {@link Roo.TabPanel} this TabPanelItem belongs to
34679 * @type Roo.TabPanel
34681 this.tabPanel = config.panel;
34683 * The id for this TabPanelItem
34686 this.id = config.id;
34688 this.disabled = false;
34690 this.text = config.text;
34692 this.loaded = false;
34693 this.closable = config.closable;
34696 * The body element for this TabPanelItem.
34697 * @type Roo.Element
34699 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
34700 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
34701 this.bodyEl.setStyle("display", "block");
34702 this.bodyEl.setStyle("zoom", "1");
34703 //this.hideAction();
34705 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable);
34707 this.el = Roo.get(els.el);
34708 this.inner = Roo.get(els.inner, true);
34709 this.textEl = Roo.get(this.el.dom.firstChild, true);
34710 this.pnode = Roo.get(els.el.parentNode, true);
34711 this.el.on("mousedown", this.onTabMouseDown, this);
34712 this.el.on("click", this.onTabClick, this);
34714 if(config.closable){
34715 var c = Roo.get(els.close, true);
34716 c.dom.title = this.closeText;
34717 c.addClassOnOver("close-over");
34718 c.on("click", this.closeClick, this);
34724 * Fires when this tab becomes the active tab.
34725 * @param {Roo.TabPanel} tabPanel The parent TabPanel
34726 * @param {Roo.TabPanelItem} this
34730 * @event beforeclose
34731 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
34732 * @param {Roo.TabPanelItem} this
34733 * @param {Object} e Set cancel to true on this object to cancel the close.
34735 "beforeclose": true,
34738 * Fires when this tab is closed.
34739 * @param {Roo.TabPanelItem} this
34743 * @event deactivate
34744 * Fires when this tab is no longer the active tab.
34745 * @param {Roo.TabPanel} tabPanel The parent TabPanel
34746 * @param {Roo.TabPanelItem} this
34748 "deactivate" : true
34750 this.hidden = false;
34752 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
34755 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
34757 purgeListeners : function(){
34758 Roo.util.Observable.prototype.purgeListeners.call(this);
34759 this.el.removeAllListeners();
34762 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
34765 this.pnode.addClass("active");
34768 this.tabPanel.stripWrap.repaint();
34770 this.fireEvent("activate", this.tabPanel, this);
34774 * Returns true if this tab is the active tab.
34775 * @return {Boolean}
34777 isActive : function(){
34778 return this.tabPanel.getActiveTab() == this;
34782 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
34785 this.pnode.removeClass("active");
34787 this.fireEvent("deactivate", this.tabPanel, this);
34790 hideAction : function(){
34791 this.bodyEl.hide();
34792 this.bodyEl.setStyle("position", "absolute");
34793 this.bodyEl.setLeft("-20000px");
34794 this.bodyEl.setTop("-20000px");
34797 showAction : function(){
34798 this.bodyEl.setStyle("position", "relative");
34799 this.bodyEl.setTop("");
34800 this.bodyEl.setLeft("");
34801 this.bodyEl.show();
34805 * Set the tooltip for the tab.
34806 * @param {String} tooltip The tab's tooltip
34808 setTooltip : function(text){
34809 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
34810 this.textEl.dom.qtip = text;
34811 this.textEl.dom.removeAttribute('title');
34813 this.textEl.dom.title = text;
34817 onTabClick : function(e){
34818 e.preventDefault();
34819 this.tabPanel.activate(this.id);
34822 onTabMouseDown : function(e){
34823 e.preventDefault();
34824 this.tabPanel.activate(this.id);
34827 getWidth : function(){
34828 return this.inner.getWidth();
34831 setWidth : function(width){
34832 var iwidth = width - this.pnode.getPadding("lr");
34833 this.inner.setWidth(iwidth);
34834 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
34835 this.pnode.setWidth(width);
34839 * Show or hide the tab
34840 * @param {Boolean} hidden True to hide or false to show.
34842 setHidden : function(hidden){
34843 this.hidden = hidden;
34844 this.pnode.setStyle("display", hidden ? "none" : "");
34848 * Returns true if this tab is "hidden"
34849 * @return {Boolean}
34851 isHidden : function(){
34852 return this.hidden;
34856 * Returns the text for this tab
34859 getText : function(){
34863 autoSize : function(){
34864 //this.el.beginMeasure();
34865 this.textEl.setWidth(1);
34867 * #2804 [new] Tabs in Roojs
34868 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
34870 //this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
34871 //this.el.endMeasure();
34875 * Sets the text for the tab (Note: this also sets the tooltip text)
34876 * @param {String} text The tab's text and tooltip
34878 setText : function(text){
34880 this.textEl.update(text);
34881 this.setTooltip(text);
34882 //if(!this.tabPanel.resizeTabs){
34883 // this.autoSize();
34887 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
34889 activate : function(){
34890 this.tabPanel.activate(this.id);
34894 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
34896 disable : function(){
34897 if(this.tabPanel.active != this){
34898 this.disabled = true;
34899 this.pnode.addClass("disabled");
34904 * Enables this TabPanelItem if it was previously disabled.
34906 enable : function(){
34907 this.disabled = false;
34908 this.pnode.removeClass("disabled");
34912 * Sets the content for this TabPanelItem.
34913 * @param {String} content The content
34914 * @param {Boolean} loadScripts true to look for and load scripts
34916 setContent : function(content, loadScripts){
34917 this.bodyEl.update(content, loadScripts);
34921 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
34922 * @return {Roo.UpdateManager} The UpdateManager
34924 getUpdateManager : function(){
34925 return this.bodyEl.getUpdateManager();
34929 * Set a URL to be used to load the content for this TabPanelItem.
34930 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
34931 * @param {String/Object} params (optional) The string params for the update call or an object of the params. See {@link Roo.UpdateManager#update} for more details. (Defaults to null)
34932 * @param {Boolean} loadOnce (optional) Whether to only load the content once. If this is false it makes the Ajax call every time this TabPanelItem is activated. (Defaults to false)
34933 * @return {Roo.UpdateManager} The UpdateManager
34935 setUrl : function(url, params, loadOnce){
34936 if(this.refreshDelegate){
34937 this.un('activate', this.refreshDelegate);
34939 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
34940 this.on("activate", this.refreshDelegate);
34941 return this.bodyEl.getUpdateManager();
34945 _handleRefresh : function(url, params, loadOnce){
34946 if(!loadOnce || !this.loaded){
34947 var updater = this.bodyEl.getUpdateManager();
34948 updater.update(url, params, this._setLoaded.createDelegate(this));
34953 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
34954 * Will fail silently if the setUrl method has not been called.
34955 * This does not activate the panel, just updates its content.
34957 refresh : function(){
34958 if(this.refreshDelegate){
34959 this.loaded = false;
34960 this.refreshDelegate();
34965 _setLoaded : function(){
34966 this.loaded = true;
34970 closeClick : function(e){
34973 this.fireEvent("beforeclose", this, o);
34974 if(o.cancel !== true){
34975 this.tabPanel.removeTab(this.id);
34979 * The text displayed in the tooltip for the close icon.
34982 closeText : "Close this tab"