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') != 'auto' && 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 false
2460 * @cfg {String} size (sm|lg) default empty
2464 * Create a new Modal Dialog
2465 * @param {Object} config The config object
2468 Roo.bootstrap.Modal = function(config){
2469 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
2474 * The raw btnclick event for the button
2475 * @param {Roo.EventObject} e
2479 this.buttons = this.buttons || [];
2482 this.tmpl = Roo.factory(this.tmpl);
2487 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
2489 title : 'test dialog',
2499 specificTitle: false,
2501 buttonPosition: 'right',
2520 onRender : function(ct, position)
2522 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
2525 var cfg = Roo.apply({}, this.getAutoCreate());
2528 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
2530 //if (!cfg.name.length) {
2534 cfg.cls += ' ' + this.cls;
2537 cfg.style = this.style;
2539 this.el = Roo.get(document.body).createChild(cfg, position);
2541 //var type = this.el.dom.type;
2544 if(this.tabIndex !== undefined){
2545 this.el.dom.setAttribute('tabIndex', this.tabIndex);
2548 this.dialogEl = this.el.select('.modal-dialog',true).first();
2549 this.bodyEl = this.el.select('.modal-body',true).first();
2550 this.closeEl = this.el.select('.modal-header .close', true).first();
2551 this.footerEl = this.el.select('.modal-footer',true).first();
2552 this.titleEl = this.el.select('.modal-title',true).first();
2556 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2557 this.maskEl.enableDisplayMode("block");
2559 //this.el.addClass("x-dlg-modal");
2561 if (this.buttons.length) {
2562 Roo.each(this.buttons, function(bb) {
2563 var b = Roo.apply({}, bb);
2564 b.xns = b.xns || Roo.bootstrap;
2565 b.xtype = b.xtype || 'Button';
2566 if (typeof(b.listeners) == 'undefined') {
2567 b.listeners = { click : this.onButtonClick.createDelegate(this) };
2570 var btn = Roo.factory(b);
2572 btn.render(this.el.select('.modal-footer div').first());
2576 // render the children.
2579 if(typeof(this.items) != 'undefined'){
2580 var items = this.items;
2583 for(var i =0;i < items.length;i++) {
2584 nitems.push(this.addxtype(Roo.apply({}, items[i])));
2588 this.items = nitems;
2590 // where are these used - they used to be body/close/footer
2594 //this.el.addClass([this.fieldClass, this.cls]);
2598 getAutoCreate : function(){
2603 html : this.html || ''
2608 cls : 'modal-title',
2612 if(this.specificTitle){
2618 if (this.allow_close) {
2630 if(this.size.length){
2631 size = 'modal-' + this.size;
2636 style : 'display: none',
2639 cls: "modal-dialog " + size,
2642 cls : "modal-content",
2645 cls : 'modal-header',
2650 cls : 'modal-footer',
2654 cls: 'btn-' + this.buttonPosition
2671 modal.cls += ' fade';
2677 getChildContainer : function() {
2682 getButtonContainer : function() {
2683 return this.el.select('.modal-footer div',true).first();
2686 initEvents : function()
2688 if (this.allow_close) {
2689 this.closeEl.on('click', this.hide, this);
2691 Roo.EventManager.onWindowResize(this.resize, this, true);
2698 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2699 if (this.fitwindow) {
2700 var w = this.width || Roo.lib.Dom.getViewportWidth(true) - 30;
2701 var h = this.height || Roo.lib.Dom.getViewportHeight(true) - 60;
2706 setSize : function(w,h)
2716 if (!this.rendered) {
2720 this.el.setStyle('display', 'block');
2722 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
2725 this.el.addClass('in');
2728 this.el.addClass('in');
2732 // not sure how we can show data in here..
2734 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
2737 Roo.get(document.body).addClass("x-body-masked");
2738 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2740 this.el.setStyle('zIndex', '10001');
2742 this.fireEvent('show', this);
2747 this.items.forEach( function(e) {
2748 e.layout ? e.layout() : false;
2757 Roo.get(document.body).removeClass("x-body-masked");
2758 this.el.removeClass('in');
2759 this.el.select('.modal-dialog', true).first().setStyle('transform','');
2761 if(this.animate){ // why
2763 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
2765 this.el.setStyle('display', 'none');
2768 this.fireEvent('hide', this);
2771 addButton : function(str, cb)
2775 var b = Roo.apply({}, { html : str } );
2776 b.xns = b.xns || Roo.bootstrap;
2777 b.xtype = b.xtype || 'Button';
2778 if (typeof(b.listeners) == 'undefined') {
2779 b.listeners = { click : cb.createDelegate(this) };
2782 var btn = Roo.factory(b);
2784 btn.render(this.el.select('.modal-footer div').first());
2790 setDefaultButton : function(btn)
2792 //this.el.select('.modal-footer').()
2796 resizeTo: function(w,h)
2800 this.dialogEl.setWidth(w);
2801 if (this.diff === false) {
2802 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
2805 this.bodyEl.setHeight(h-this.diff);
2809 setContentSize : function(w, h)
2813 onButtonClick: function(btn,e)
2816 this.fireEvent('btnclick', btn.name, e);
2819 * Set the title of the Dialog
2820 * @param {String} str new Title
2822 setTitle: function(str) {
2823 this.titleEl.dom.innerHTML = str;
2826 * Set the body of the Dialog
2827 * @param {String} str new Title
2829 setBody: function(str) {
2830 this.bodyEl.dom.innerHTML = str;
2833 * Set the body of the Dialog using the template
2834 * @param {Obj} data - apply this data to the template and replace the body contents.
2836 applyBody: function(obj)
2839 Roo.log("Error - using apply Body without a template");
2842 this.tmpl.overwrite(this.bodyEl, obj);
2848 Roo.apply(Roo.bootstrap.Modal, {
2850 * Button config that displays a single OK button
2859 * Button config that displays Yes and No buttons
2875 * Button config that displays OK and Cancel buttons
2890 * Button config that displays Yes, No and Cancel buttons
2913 * messagebox - can be used as a replace
2917 * @class Roo.MessageBox
2918 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
2922 Roo.Msg.alert('Status', 'Changes saved successfully.');
2924 // Prompt for user data:
2925 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
2927 // process text value...
2931 // Show a dialog using config options:
2933 title:'Save Changes?',
2934 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
2935 buttons: Roo.Msg.YESNOCANCEL,
2942 Roo.bootstrap.MessageBox = function(){
2943 var dlg, opt, mask, waitTimer;
2944 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
2945 var buttons, activeTextEl, bwidth;
2949 var handleButton = function(button){
2951 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
2955 var handleHide = function(){
2957 dlg.el.removeClass(opt.cls);
2960 // Roo.TaskMgr.stop(waitTimer);
2961 // waitTimer = null;
2966 var updateButtons = function(b){
2969 buttons["ok"].hide();
2970 buttons["cancel"].hide();
2971 buttons["yes"].hide();
2972 buttons["no"].hide();
2973 //dlg.footer.dom.style.display = 'none';
2976 dlg.footerEl.dom.style.display = '';
2977 for(var k in buttons){
2978 if(typeof buttons[k] != "function"){
2981 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
2982 width += buttons[k].el.getWidth()+15;
2992 var handleEsc = function(d, k, e){
2993 if(opt && opt.closable !== false){
3003 * Returns a reference to the underlying {@link Roo.BasicDialog} element
3004 * @return {Roo.BasicDialog} The BasicDialog element
3006 getDialog : function(){
3008 dlg = new Roo.bootstrap.Modal( {
3011 //constraintoviewport:false,
3013 //collapsible : false,
3018 //buttonAlign:"center",
3019 closeClick : function(){
3020 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
3023 handleButton("cancel");
3028 dlg.on("hide", handleHide);
3030 //dlg.addKeyListener(27, handleEsc);
3032 this.buttons = buttons;
3033 var bt = this.buttonText;
3034 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
3035 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
3036 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
3037 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
3039 bodyEl = dlg.bodyEl.createChild({
3041 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
3042 '<textarea class="roo-mb-textarea"></textarea>' +
3043 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
3045 msgEl = bodyEl.dom.firstChild;
3046 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
3047 textboxEl.enableDisplayMode();
3048 textboxEl.addKeyListener([10,13], function(){
3049 if(dlg.isVisible() && opt && opt.buttons){
3052 }else if(opt.buttons.yes){
3053 handleButton("yes");
3057 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
3058 textareaEl.enableDisplayMode();
3059 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
3060 progressEl.enableDisplayMode();
3061 var pf = progressEl.dom.firstChild;
3063 pp = Roo.get(pf.firstChild);
3064 pp.setHeight(pf.offsetHeight);
3072 * Updates the message box body text
3073 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
3074 * the XHTML-compliant non-breaking space character '&#160;')
3075 * @return {Roo.MessageBox} This message box
3077 updateText : function(text){
3078 if(!dlg.isVisible() && !opt.width){
3079 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
3081 msgEl.innerHTML = text || ' ';
3083 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
3084 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
3086 Math.min(opt.width || cw , this.maxWidth),
3087 Math.max(opt.minWidth || this.minWidth, bwidth)
3090 activeTextEl.setWidth(w);
3092 if(dlg.isVisible()){
3093 dlg.fixedcenter = false;
3095 // to big, make it scroll. = But as usual stupid IE does not support
3098 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
3099 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
3100 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
3102 bodyEl.dom.style.height = '';
3103 bodyEl.dom.style.overflowY = '';
3106 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
3108 bodyEl.dom.style.overflowX = '';
3111 dlg.setContentSize(w, bodyEl.getHeight());
3112 if(dlg.isVisible()){
3113 dlg.fixedcenter = true;
3119 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
3120 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
3121 * @param {Number} value Any number between 0 and 1 (e.g., .5)
3122 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
3123 * @return {Roo.MessageBox} This message box
3125 updateProgress : function(value, text){
3127 this.updateText(text);
3129 if (pp) { // weird bug on my firefox - for some reason this is not defined
3130 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
3136 * Returns true if the message box is currently displayed
3137 * @return {Boolean} True if the message box is visible, else false
3139 isVisible : function(){
3140 return dlg && dlg.isVisible();
3144 * Hides the message box if it is displayed
3147 if(this.isVisible()){
3153 * Displays a new message box, or reinitializes an existing message box, based on the config options
3154 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
3155 * The following config object properties are supported:
3157 Property Type Description
3158 ---------- --------------- ------------------------------------------------------------------------------------
3159 animEl String/Element An id or Element from which the message box should animate as it opens and
3160 closes (defaults to undefined)
3161 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
3162 cancel:'Bar'}), or false to not show any buttons (defaults to false)
3163 closable Boolean False to hide the top-right close button (defaults to true). Note that
3164 progress and wait dialogs will ignore this property and always hide the
3165 close button as they can only be closed programmatically.
3166 cls String A custom CSS class to apply to the message box element
3167 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
3168 displayed (defaults to 75)
3169 fn Function A callback function to execute after closing the dialog. The arguments to the
3170 function will be btn (the name of the button that was clicked, if applicable,
3171 e.g. "ok"), and text (the value of the active text field, if applicable).
3172 Progress and wait dialogs will ignore this option since they do not respond to
3173 user actions and can only be closed programmatically, so any required function
3174 should be called by the same code after it closes the dialog.
3175 icon String A CSS class that provides a background image to be used as an icon for
3176 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
3177 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
3178 minWidth Number The minimum width in pixels of the message box (defaults to 100)
3179 modal Boolean False to allow user interaction with the page while the message box is
3180 displayed (defaults to true)
3181 msg String A string that will replace the existing message box body text (defaults
3182 to the XHTML-compliant non-breaking space character ' ')
3183 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
3184 progress Boolean True to display a progress bar (defaults to false)
3185 progressText String The text to display inside the progress bar if progress = true (defaults to '')
3186 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
3187 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
3188 title String The title text
3189 value String The string value to set into the active textbox element if displayed
3190 wait Boolean True to display a progress bar (defaults to false)
3191 width Number The width of the dialog in pixels
3198 msg: 'Please enter your address:',
3200 buttons: Roo.MessageBox.OKCANCEL,
3203 animEl: 'addAddressBtn'
3206 * @param {Object} config Configuration options
3207 * @return {Roo.MessageBox} This message box
3209 show : function(options)
3212 // this causes nightmares if you show one dialog after another
3213 // especially on callbacks..
3215 if(this.isVisible()){
3218 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
3219 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
3220 Roo.log("New Dialog Message:" + options.msg )
3221 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
3222 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
3225 var d = this.getDialog();
3227 d.setTitle(opt.title || " ");
3228 d.closeEl.setDisplayed(opt.closable !== false);
3229 activeTextEl = textboxEl;
3230 opt.prompt = opt.prompt || (opt.multiline ? true : false);
3235 textareaEl.setHeight(typeof opt.multiline == "number" ?
3236 opt.multiline : this.defaultTextHeight);
3237 activeTextEl = textareaEl;
3246 progressEl.setDisplayed(opt.progress === true);
3247 this.updateProgress(0);
3248 activeTextEl.dom.value = opt.value || "";
3250 dlg.setDefaultButton(activeTextEl);
3252 var bs = opt.buttons;
3256 }else if(bs && bs.yes){
3257 db = buttons["yes"];
3259 dlg.setDefaultButton(db);
3261 bwidth = updateButtons(opt.buttons);
3262 this.updateText(opt.msg);
3264 d.el.addClass(opt.cls);
3266 d.proxyDrag = opt.proxyDrag === true;
3267 d.modal = opt.modal !== false;
3268 d.mask = opt.modal !== false ? mask : false;
3270 // force it to the end of the z-index stack so it gets a cursor in FF
3271 document.body.appendChild(dlg.el.dom);
3272 d.animateTarget = null;
3273 d.show(options.animEl);
3279 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
3280 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
3281 * and closing the message box when the process is complete.
3282 * @param {String} title The title bar text
3283 * @param {String} msg The message box body text
3284 * @return {Roo.MessageBox} This message box
3286 progress : function(title, msg){
3293 minWidth: this.minProgressWidth,
3300 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
3301 * If a callback function is passed it will be called after the user clicks the button, and the
3302 * id of the button that was clicked will be passed as the only parameter to the callback
3303 * (could also be the top-right close button).
3304 * @param {String} title The title bar text
3305 * @param {String} msg The message box body text
3306 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3307 * @param {Object} scope (optional) The scope of the callback function
3308 * @return {Roo.MessageBox} This message box
3310 alert : function(title, msg, fn, scope){
3323 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
3324 * interaction while waiting for a long-running process to complete that does not have defined intervals.
3325 * You are responsible for closing the message box when the process is complete.
3326 * @param {String} msg The message box body text
3327 * @param {String} title (optional) The title bar text
3328 * @return {Roo.MessageBox} This message box
3330 wait : function(msg, title){
3341 waitTimer = Roo.TaskMgr.start({
3343 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
3351 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
3352 * If a callback function is passed it will be called after the user clicks either button, and the id of the
3353 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
3354 * @param {String} title The title bar text
3355 * @param {String} msg The message box body text
3356 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3357 * @param {Object} scope (optional) The scope of the callback function
3358 * @return {Roo.MessageBox} This message box
3360 confirm : function(title, msg, fn, scope){
3364 buttons: this.YESNO,
3373 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
3374 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
3375 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
3376 * (could also be the top-right close button) and the text that was entered will be passed as the two
3377 * parameters to the callback.
3378 * @param {String} title The title bar text
3379 * @param {String} msg The message box body text
3380 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3381 * @param {Object} scope (optional) The scope of the callback function
3382 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
3383 * property, or the height in pixels to create the textbox (defaults to false / single-line)
3384 * @return {Roo.MessageBox} This message box
3386 prompt : function(title, msg, fn, scope, multiline){
3390 buttons: this.OKCANCEL,
3395 multiline: multiline,
3402 * Button config that displays a single OK button
3407 * Button config that displays Yes and No buttons
3410 YESNO : {yes:true, no:true},
3412 * Button config that displays OK and Cancel buttons
3415 OKCANCEL : {ok:true, cancel:true},
3417 * Button config that displays Yes, No and Cancel buttons
3420 YESNOCANCEL : {yes:true, no:true, cancel:true},
3423 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
3426 defaultTextHeight : 75,
3428 * The maximum width in pixels of the message box (defaults to 600)
3433 * The minimum width in pixels of the message box (defaults to 100)
3438 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
3439 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
3442 minProgressWidth : 250,
3444 * An object containing the default button text strings that can be overriden for localized language support.
3445 * Supported properties are: ok, cancel, yes and no.
3446 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
3459 * Shorthand for {@link Roo.MessageBox}
3461 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
3462 Roo.Msg = Roo.Msg || Roo.MessageBox;
3471 * @class Roo.bootstrap.Navbar
3472 * @extends Roo.bootstrap.Component
3473 * Bootstrap Navbar class
3476 * Create a new Navbar
3477 * @param {Object} config The config object
3481 Roo.bootstrap.Navbar = function(config){
3482 Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
3486 * @event beforetoggle
3487 * Fire before toggle the menu
3488 * @param {Roo.EventObject} e
3490 "beforetoggle" : true
3494 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component, {
3503 getAutoCreate : function(){
3506 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
3510 initEvents :function ()
3512 //Roo.log(this.el.select('.navbar-toggle',true));
3513 this.el.select('.navbar-toggle',true).on('click', function() {
3514 if(this.fireEvent('beforetoggle', this) !== false){
3515 this.el.select('.navbar-collapse',true).toggleClass('in');
3525 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
3527 var size = this.el.getSize();
3528 this.maskEl.setSize(size.width, size.height);
3529 this.maskEl.enableDisplayMode("block");
3538 getChildContainer : function()
3540 if (this.el.select('.collapse').getCount()) {
3541 return this.el.select('.collapse',true).first();
3574 * @class Roo.bootstrap.NavSimplebar
3575 * @extends Roo.bootstrap.Navbar
3576 * Bootstrap Sidebar class
3578 * @cfg {Boolean} inverse is inverted color
3580 * @cfg {String} type (nav | pills | tabs)
3581 * @cfg {Boolean} arrangement stacked | justified
3582 * @cfg {String} align (left | right) alignment
3584 * @cfg {Boolean} main (true|false) main nav bar? default false
3585 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
3587 * @cfg {String} tag (header|footer|nav|div) default is nav
3593 * Create a new Sidebar
3594 * @param {Object} config The config object
3598 Roo.bootstrap.NavSimplebar = function(config){
3599 Roo.bootstrap.NavSimplebar.superclass.constructor.call(this, config);
3602 Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar, {
3618 getAutoCreate : function(){
3622 tag : this.tag || 'div',
3635 this.type = this.type || 'nav';
3636 if (['tabs','pills'].indexOf(this.type)!==-1) {
3637 cfg.cn[0].cls += ' nav-' + this.type
3641 if (this.type!=='nav') {
3642 Roo.log('nav type must be nav/tabs/pills')
3644 cfg.cn[0].cls += ' navbar-nav'
3650 if (['stacked','justified'].indexOf(this.arrangement)!==-1) {
3651 cfg.cn[0].cls += ' nav-' + this.arrangement;
3655 if (this.align === 'right') {
3656 cfg.cn[0].cls += ' navbar-right';
3660 cfg.cls += ' navbar-inverse';
3687 * @class Roo.bootstrap.NavHeaderbar
3688 * @extends Roo.bootstrap.NavSimplebar
3689 * Bootstrap Sidebar class
3691 * @cfg {String} brand what is brand
3692 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
3693 * @cfg {String} brand_href href of the brand
3694 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
3695 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
3696 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
3697 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
3700 * Create a new Sidebar
3701 * @param {Object} config The config object
3705 Roo.bootstrap.NavHeaderbar = function(config){
3706 Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
3710 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar, {
3717 desktopCenter : false,
3720 getAutoCreate : function(){
3723 tag: this.nav || 'nav',
3730 if (this.desktopCenter) {
3731 cn.push({cls : 'container', cn : []});
3738 cls: 'navbar-header',
3743 cls: 'navbar-toggle',
3744 'data-toggle': 'collapse',
3749 html: 'Toggle navigation'
3771 cls: 'collapse navbar-collapse',
3775 cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
3777 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
3778 cfg.cls += ' navbar-' + this.position;
3780 // tag can override this..
3782 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
3785 if (this.brand !== '') {
3788 href: this.brand_href ? this.brand_href : '#',
3789 cls: 'navbar-brand',
3797 cfg.cls += ' main-nav';
3805 getHeaderChildContainer : function()
3807 if (this.srButton && this.el.select('.navbar-header').getCount()) {
3808 return this.el.select('.navbar-header',true).first();
3811 return this.getChildContainer();
3815 initEvents : function()
3817 Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
3819 if (this.autohide) {
3824 Roo.get(document).on('scroll',function(e) {
3825 var ns = Roo.get(document).getScroll().top;
3826 var os = prevScroll;
3830 ft.removeClass('slideDown');
3831 ft.addClass('slideUp');
3834 ft.removeClass('slideUp');
3835 ft.addClass('slideDown');
3856 * @class Roo.bootstrap.NavSidebar
3857 * @extends Roo.bootstrap.Navbar
3858 * Bootstrap Sidebar class
3861 * Create a new Sidebar
3862 * @param {Object} config The config object
3866 Roo.bootstrap.NavSidebar = function(config){
3867 Roo.bootstrap.NavSidebar.superclass.constructor.call(this, config);
3870 Roo.extend(Roo.bootstrap.NavSidebar, Roo.bootstrap.Navbar, {
3872 sidebar : true, // used by Navbar Item and NavbarGroup at present...
3874 getAutoCreate : function(){
3879 cls: 'sidebar sidebar-nav'
3901 * @class Roo.bootstrap.NavGroup
3902 * @extends Roo.bootstrap.Component
3903 * Bootstrap NavGroup class
3904 * @cfg {String} align (left|right)
3905 * @cfg {Boolean} inverse
3906 * @cfg {String} type (nav|pills|tab) default nav
3907 * @cfg {String} navId - reference Id for navbar.
3911 * Create a new nav group
3912 * @param {Object} config The config object
3915 Roo.bootstrap.NavGroup = function(config){
3916 Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
3919 Roo.bootstrap.NavGroup.register(this);
3923 * Fires when the active item changes
3924 * @param {Roo.bootstrap.NavGroup} this
3925 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
3926 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
3933 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
3944 getAutoCreate : function()
3946 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
3953 if (['tabs','pills'].indexOf(this.type)!==-1) {
3954 cfg.cls += ' nav-' + this.type
3956 if (this.type!=='nav') {
3957 Roo.log('nav type must be nav/tabs/pills')
3959 cfg.cls += ' navbar-nav'
3962 if (this.parent().sidebar) {
3965 cls: 'dashboard-menu sidebar-menu'
3971 if (this.form === true) {
3977 if (this.align === 'right') {
3978 cfg.cls += ' navbar-right';
3980 cfg.cls += ' navbar-left';
3984 if (this.align === 'right') {
3985 cfg.cls += ' navbar-right';
3989 cfg.cls += ' navbar-inverse';
3997 * sets the active Navigation item
3998 * @param {Roo.bootstrap.NavItem} the new current navitem
4000 setActiveItem : function(item)
4003 Roo.each(this.navItems, function(v){
4008 v.setActive(false, true);
4015 item.setActive(true, true);
4016 this.fireEvent('changed', this, item, prev);
4021 * gets the active Navigation item
4022 * @return {Roo.bootstrap.NavItem} the current navitem
4024 getActive : function()
4028 Roo.each(this.navItems, function(v){
4039 indexOfNav : function()
4043 Roo.each(this.navItems, function(v,i){
4054 * adds a Navigation item
4055 * @param {Roo.bootstrap.NavItem} the navitem to add
4057 addItem : function(cfg)
4059 var cn = new Roo.bootstrap.NavItem(cfg);
4061 cn.parentId = this.id;
4062 cn.onRender(this.el, null);
4066 * register a Navigation item
4067 * @param {Roo.bootstrap.NavItem} the navitem to add
4069 register : function(item)
4071 this.navItems.push( item);
4072 item.navId = this.navId;
4077 * clear all the Navigation item
4080 clearAll : function()
4083 this.el.dom.innerHTML = '';
4086 getNavItem: function(tabId)
4089 Roo.each(this.navItems, function(e) {
4090 if (e.tabId == tabId) {
4100 setActiveNext : function()
4102 var i = this.indexOfNav(this.getActive());
4103 if (i > this.navItems.length) {
4106 this.setActiveItem(this.navItems[i+1]);
4108 setActivePrev : function()
4110 var i = this.indexOfNav(this.getActive());
4114 this.setActiveItem(this.navItems[i-1]);
4116 clearWasActive : function(except) {
4117 Roo.each(this.navItems, function(e) {
4118 if (e.tabId != except.tabId && e.was_active) {
4119 e.was_active = false;
4126 getWasActive : function ()
4129 Roo.each(this.navItems, function(e) {
4144 Roo.apply(Roo.bootstrap.NavGroup, {
4148 * register a Navigation Group
4149 * @param {Roo.bootstrap.NavGroup} the navgroup to add
4151 register : function(navgrp)
4153 this.groups[navgrp.navId] = navgrp;
4157 * fetch a Navigation Group based on the navigation ID
4158 * @param {string} the navgroup to add
4159 * @returns {Roo.bootstrap.NavGroup} the navgroup
4161 get: function(navId) {
4162 if (typeof(this.groups[navId]) == 'undefined') {
4164 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
4166 return this.groups[navId] ;
4181 * @class Roo.bootstrap.NavItem
4182 * @extends Roo.bootstrap.Component
4183 * Bootstrap Navbar.NavItem class
4184 * @cfg {String} href link to
4185 * @cfg {String} html content of button
4186 * @cfg {String} badge text inside badge
4187 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
4188 * @cfg {String} glyphicon name of glyphicon
4189 * @cfg {String} icon name of font awesome icon
4190 * @cfg {Boolean} active Is item active
4191 * @cfg {Boolean} disabled Is item disabled
4193 * @cfg {Boolean} preventDefault (true | false) default false
4194 * @cfg {String} tabId the tab that this item activates.
4195 * @cfg {String} tagtype (a|span) render as a href or span?
4196 * @cfg {Boolean} animateRef (true|false) link to element default false
4199 * Create a new Navbar Item
4200 * @param {Object} config The config object
4202 Roo.bootstrap.NavItem = function(config){
4203 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
4208 * The raw click event for the entire grid.
4209 * @param {Roo.EventObject} e
4214 * Fires when the active item active state changes
4215 * @param {Roo.bootstrap.NavItem} this
4216 * @param {boolean} state the new state
4222 * Fires when scroll to element
4223 * @param {Roo.bootstrap.NavItem} this
4224 * @param {Object} options
4225 * @param {Roo.EventObject} e
4233 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
4241 preventDefault : false,
4248 getAutoCreate : function(){
4257 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
4259 if (this.disabled) {
4260 cfg.cls += ' disabled';
4263 if (this.href || this.html || this.glyphicon || this.icon) {
4267 href : this.href || "#",
4268 html: this.html || ''
4273 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
4276 if(this.glyphicon) {
4277 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
4282 cfg.cn[0].html += " <span class='caret'></span>";
4286 if (this.badge !== '') {
4288 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
4296 initEvents: function()
4298 if (typeof (this.menu) != 'undefined') {
4299 this.menu.parentType = this.xtype;
4300 this.menu.triggerEl = this.el;
4301 this.menu = this.addxtype(Roo.apply({}, this.menu));
4304 this.el.select('a',true).on('click', this.onClick, this);
4306 if(this.tagtype == 'span'){
4307 this.el.select('span',true).on('click', this.onClick, this);
4310 // at this point parent should be available..
4311 this.parent().register(this);
4314 onClick : function(e)
4316 if (e.getTarget('.dropdown-menu-item')) {
4317 // did you click on a menu itemm.... - then don't trigger onclick..
4322 this.preventDefault ||
4325 Roo.log("NavItem - prevent Default?");
4329 if (this.disabled) {
4333 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4334 if (tg && tg.transition) {
4335 Roo.log("waiting for the transitionend");
4341 //Roo.log("fire event clicked");
4342 if(this.fireEvent('click', this, e) === false){
4346 if(this.tagtype == 'span'){
4350 //Roo.log(this.href);
4351 var ael = this.el.select('a',true).first();
4354 if(ael && this.animateRef && this.href.indexOf('#') > -1){
4355 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
4356 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
4357 return; // ignore... - it's a 'hash' to another page.
4359 Roo.log("NavItem - prevent Default?");
4361 this.scrollToElement(e);
4365 var p = this.parent();
4367 if (['tabs','pills'].indexOf(p.type)!==-1) {
4368 if (typeof(p.setActiveItem) !== 'undefined') {
4369 p.setActiveItem(this);
4373 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
4374 if (p.parentType == 'NavHeaderbar' && !this.menu) {
4375 // remove the collapsed menu expand...
4376 p.parent().el.select('.navbar-collapse',true).removeClass('in');
4380 isActive: function () {
4383 setActive : function(state, fire, is_was_active)
4385 if (this.active && !state && this.navId) {
4386 this.was_active = true;
4387 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4389 nv.clearWasActive(this);
4393 this.active = state;
4396 this.el.removeClass('active');
4397 } else if (!this.el.hasClass('active')) {
4398 this.el.addClass('active');
4401 this.fireEvent('changed', this, state);
4404 // show a panel if it's registered and related..
4406 if (!this.navId || !this.tabId || !state || is_was_active) {
4410 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4414 var pan = tg.getPanelByName(this.tabId);
4418 // if we can not flip to new panel - go back to old nav highlight..
4419 if (false == tg.showPanel(pan)) {
4420 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4422 var onav = nv.getWasActive();
4424 onav.setActive(true, false, true);
4433 // this should not be here...
4434 setDisabled : function(state)
4436 this.disabled = state;
4438 this.el.removeClass('disabled');
4439 } else if (!this.el.hasClass('disabled')) {
4440 this.el.addClass('disabled');
4446 * Fetch the element to display the tooltip on.
4447 * @return {Roo.Element} defaults to this.el
4449 tooltipEl : function()
4451 return this.el.select('' + this.tagtype + '', true).first();
4454 scrollToElement : function(e)
4456 var c = document.body;
4459 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
4461 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
4462 c = document.documentElement;
4465 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
4471 var o = target.calcOffsetsTo(c);
4478 this.fireEvent('scrollto', this, options, e);
4480 Roo.get(c).scrollTo('top', options.value, true);
4493 * <span> icon </span>
4494 * <span> text </span>
4495 * <span>badge </span>
4499 * @class Roo.bootstrap.NavSidebarItem
4500 * @extends Roo.bootstrap.NavItem
4501 * Bootstrap Navbar.NavSidebarItem class
4502 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
4503 * {bool} open is the menu open
4505 * Create a new Navbar Button
4506 * @param {Object} config The config object
4508 Roo.bootstrap.NavSidebarItem = function(config){
4509 Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
4514 * The raw click event for the entire grid.
4515 * @param {Roo.EventObject} e
4520 * Fires when the active item active state changes
4521 * @param {Roo.bootstrap.NavSidebarItem} this
4522 * @param {boolean} state the new state
4530 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem, {
4532 badgeWeight : 'default',
4536 getAutoCreate : function(){
4541 href : this.href || '#',
4553 html : this.html || ''
4558 cfg.cls += ' active';
4561 if (this.disabled) {
4562 cfg.cls += ' disabled';
4565 cfg.cls += ' open x-open';
4568 if (this.glyphicon || this.icon) {
4569 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
4570 a.cn.push({ tag : 'i', cls : c }) ;
4575 if (this.badge !== '') {
4577 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
4581 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
4582 a.cls += 'dropdown-toggle treeview' ;
4590 initEvents : function()
4592 if (typeof (this.menu) != 'undefined') {
4593 this.menu.parentType = this.xtype;
4594 this.menu.triggerEl = this.el;
4595 this.menu = this.addxtype(Roo.apply({}, this.menu));
4598 this.el.on('click', this.onClick, this);
4601 if(this.badge !== ''){
4603 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
4608 onClick : function(e)
4615 if(this.preventDefault){
4619 this.fireEvent('click', this);
4622 disable : function()
4624 this.setDisabled(true);
4629 this.setDisabled(false);
4632 setDisabled : function(state)
4634 if(this.disabled == state){
4638 this.disabled = state;
4641 this.el.addClass('disabled');
4645 this.el.removeClass('disabled');
4650 setActive : function(state)
4652 if(this.active == state){
4656 this.active = state;
4659 this.el.addClass('active');
4663 this.el.removeClass('active');
4668 isActive: function ()
4673 setBadge : function(str)
4679 this.badgeEl.dom.innerHTML = str;
4696 * @class Roo.bootstrap.Row
4697 * @extends Roo.bootstrap.Component
4698 * Bootstrap Row class (contains columns...)
4702 * @param {Object} config The config object
4705 Roo.bootstrap.Row = function(config){
4706 Roo.bootstrap.Row.superclass.constructor.call(this, config);
4709 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
4711 getAutoCreate : function(){
4730 * @class Roo.bootstrap.Element
4731 * @extends Roo.bootstrap.Component
4732 * Bootstrap Element class
4733 * @cfg {String} html contents of the element
4734 * @cfg {String} tag tag of the element
4735 * @cfg {String} cls class of the element
4736 * @cfg {Boolean} preventDefault (true|false) default false
4737 * @cfg {Boolean} clickable (true|false) default false
4740 * Create a new Element
4741 * @param {Object} config The config object
4744 Roo.bootstrap.Element = function(config){
4745 Roo.bootstrap.Element.superclass.constructor.call(this, config);
4751 * When a element is chick
4752 * @param {Roo.bootstrap.Element} this
4753 * @param {Roo.EventObject} e
4759 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
4764 preventDefault: false,
4767 getAutoCreate : function(){
4778 initEvents: function()
4780 Roo.bootstrap.Element.superclass.initEvents.call(this);
4783 this.el.on('click', this.onClick, this);
4788 onClick : function(e)
4790 if(this.preventDefault){
4794 this.fireEvent('click', this, e);
4797 getValue : function()
4799 return this.el.dom.innerHTML;
4802 setValue : function(value)
4804 this.el.dom.innerHTML = value;
4819 * @class Roo.bootstrap.Pagination
4820 * @extends Roo.bootstrap.Component
4821 * Bootstrap Pagination class
4822 * @cfg {String} size xs | sm | md | lg
4823 * @cfg {Boolean} inverse false | true
4826 * Create a new Pagination
4827 * @param {Object} config The config object
4830 Roo.bootstrap.Pagination = function(config){
4831 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
4834 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
4840 getAutoCreate : function(){
4846 cfg.cls += ' inverse';
4852 cfg.cls += " " + this.cls;
4870 * @class Roo.bootstrap.PaginationItem
4871 * @extends Roo.bootstrap.Component
4872 * Bootstrap PaginationItem class
4873 * @cfg {String} html text
4874 * @cfg {String} href the link
4875 * @cfg {Boolean} preventDefault (true | false) default true
4876 * @cfg {Boolean} active (true | false) default false
4877 * @cfg {Boolean} disabled default false
4881 * Create a new PaginationItem
4882 * @param {Object} config The config object
4886 Roo.bootstrap.PaginationItem = function(config){
4887 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
4892 * The raw click event for the entire grid.
4893 * @param {Roo.EventObject} e
4899 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
4903 preventDefault: true,
4908 getAutoCreate : function(){
4914 href : this.href ? this.href : '#',
4915 html : this.html ? this.html : ''
4925 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
4929 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
4935 initEvents: function() {
4937 this.el.on('click', this.onClick, this);
4940 onClick : function(e)
4942 Roo.log('PaginationItem on click ');
4943 if(this.preventDefault){
4951 this.fireEvent('click', this, e);
4967 * @class Roo.bootstrap.Slider
4968 * @extends Roo.bootstrap.Component
4969 * Bootstrap Slider class
4972 * Create a new Slider
4973 * @param {Object} config The config object
4976 Roo.bootstrap.Slider = function(config){
4977 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
4980 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
4982 getAutoCreate : function(){
4986 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
4990 cls: 'ui-slider-handle ui-state-default ui-corner-all'
5002 * Ext JS Library 1.1.1
5003 * Copyright(c) 2006-2007, Ext JS, LLC.
5005 * Originally Released Under LGPL - original licence link has changed is not relivant.
5008 * <script type="text/javascript">
5013 * @class Roo.grid.ColumnModel
5014 * @extends Roo.util.Observable
5015 * This is the default implementation of a ColumnModel used by the Grid. It defines
5016 * the columns in the grid.
5019 var colModel = new Roo.grid.ColumnModel([
5020 {header: "Ticker", width: 60, sortable: true, locked: true},
5021 {header: "Company Name", width: 150, sortable: true},
5022 {header: "Market Cap.", width: 100, sortable: true},
5023 {header: "$ Sales", width: 100, sortable: true, renderer: money},
5024 {header: "Employees", width: 100, sortable: true, resizable: false}
5029 * The config options listed for this class are options which may appear in each
5030 * individual column definition.
5031 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
5033 * @param {Object} config An Array of column config objects. See this class's
5034 * config objects for details.
5036 Roo.grid.ColumnModel = function(config){
5038 * The config passed into the constructor
5040 this.config = config;
5043 // if no id, create one
5044 // if the column does not have a dataIndex mapping,
5045 // map it to the order it is in the config
5046 for(var i = 0, len = config.length; i < len; i++){
5048 if(typeof c.dataIndex == "undefined"){
5051 if(typeof c.renderer == "string"){
5052 c.renderer = Roo.util.Format[c.renderer];
5054 if(typeof c.id == "undefined"){
5057 if(c.editor && c.editor.xtype){
5058 c.editor = Roo.factory(c.editor, Roo.grid);
5060 if(c.editor && c.editor.isFormField){
5061 c.editor = new Roo.grid.GridEditor(c.editor);
5063 this.lookup[c.id] = c;
5067 * The width of columns which have no width specified (defaults to 100)
5070 this.defaultWidth = 100;
5073 * Default sortable of columns which have no sortable specified (defaults to false)
5076 this.defaultSortable = false;
5080 * @event widthchange
5081 * Fires when the width of a column changes.
5082 * @param {ColumnModel} this
5083 * @param {Number} columnIndex The column index
5084 * @param {Number} newWidth The new width
5086 "widthchange": true,
5088 * @event headerchange
5089 * Fires when the text of a header changes.
5090 * @param {ColumnModel} this
5091 * @param {Number} columnIndex The column index
5092 * @param {Number} newText The new header text
5094 "headerchange": true,
5096 * @event hiddenchange
5097 * Fires when a column is hidden or "unhidden".
5098 * @param {ColumnModel} this
5099 * @param {Number} columnIndex The column index
5100 * @param {Boolean} hidden true if hidden, false otherwise
5102 "hiddenchange": true,
5104 * @event columnmoved
5105 * Fires when a column is moved.
5106 * @param {ColumnModel} this
5107 * @param {Number} oldIndex
5108 * @param {Number} newIndex
5110 "columnmoved" : true,
5112 * @event columlockchange
5113 * Fires when a column's locked state is changed
5114 * @param {ColumnModel} this
5115 * @param {Number} colIndex
5116 * @param {Boolean} locked true if locked
5118 "columnlockchange" : true
5120 Roo.grid.ColumnModel.superclass.constructor.call(this);
5122 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
5124 * @cfg {String} header The header text to display in the Grid view.
5127 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
5128 * {@link Roo.data.Record} definition from which to draw the column's value. If not
5129 * specified, the column's index is used as an index into the Record's data Array.
5132 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
5133 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
5136 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
5137 * Defaults to the value of the {@link #defaultSortable} property.
5138 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
5141 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
5144 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
5147 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
5150 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
5153 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
5154 * given the cell's data value. See {@link #setRenderer}. If not specified, the
5155 * default renderer uses the raw data value. If an object is returned (bootstrap only)
5156 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
5159 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
5162 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
5165 * @cfg {String} cursor (Optional)
5168 * @cfg {String} tooltip (Optional)
5171 * @cfg {Number} xs (Optional)
5174 * @cfg {Number} sm (Optional)
5177 * @cfg {Number} md (Optional)
5180 * @cfg {Number} lg (Optional)
5183 * Returns the id of the column at the specified index.
5184 * @param {Number} index The column index
5185 * @return {String} the id
5187 getColumnId : function(index){
5188 return this.config[index].id;
5192 * Returns the column for a specified id.
5193 * @param {String} id The column id
5194 * @return {Object} the column
5196 getColumnById : function(id){
5197 return this.lookup[id];
5202 * Returns the column for a specified dataIndex.
5203 * @param {String} dataIndex The column dataIndex
5204 * @return {Object|Boolean} the column or false if not found
5206 getColumnByDataIndex: function(dataIndex){
5207 var index = this.findColumnIndex(dataIndex);
5208 return index > -1 ? this.config[index] : false;
5212 * Returns the index for a specified column id.
5213 * @param {String} id The column id
5214 * @return {Number} the index, or -1 if not found
5216 getIndexById : function(id){
5217 for(var i = 0, len = this.config.length; i < len; i++){
5218 if(this.config[i].id == id){
5226 * Returns the index for a specified column dataIndex.
5227 * @param {String} dataIndex The column dataIndex
5228 * @return {Number} the index, or -1 if not found
5231 findColumnIndex : function(dataIndex){
5232 for(var i = 0, len = this.config.length; i < len; i++){
5233 if(this.config[i].dataIndex == dataIndex){
5241 moveColumn : function(oldIndex, newIndex){
5242 var c = this.config[oldIndex];
5243 this.config.splice(oldIndex, 1);
5244 this.config.splice(newIndex, 0, c);
5245 this.dataMap = null;
5246 this.fireEvent("columnmoved", this, oldIndex, newIndex);
5249 isLocked : function(colIndex){
5250 return this.config[colIndex].locked === true;
5253 setLocked : function(colIndex, value, suppressEvent){
5254 if(this.isLocked(colIndex) == value){
5257 this.config[colIndex].locked = value;
5259 this.fireEvent("columnlockchange", this, colIndex, value);
5263 getTotalLockedWidth : function(){
5265 for(var i = 0; i < this.config.length; i++){
5266 if(this.isLocked(i) && !this.isHidden(i)){
5267 this.totalWidth += this.getColumnWidth(i);
5273 getLockedCount : function(){
5274 for(var i = 0, len = this.config.length; i < len; i++){
5275 if(!this.isLocked(i)){
5280 return this.config.length;
5284 * Returns the number of columns.
5287 getColumnCount : function(visibleOnly){
5288 if(visibleOnly === true){
5290 for(var i = 0, len = this.config.length; i < len; i++){
5291 if(!this.isHidden(i)){
5297 return this.config.length;
5301 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
5302 * @param {Function} fn
5303 * @param {Object} scope (optional)
5304 * @return {Array} result
5306 getColumnsBy : function(fn, scope){
5308 for(var i = 0, len = this.config.length; i < len; i++){
5309 var c = this.config[i];
5310 if(fn.call(scope||this, c, i) === true){
5318 * Returns true if the specified column is sortable.
5319 * @param {Number} col The column index
5322 isSortable : function(col){
5323 if(typeof this.config[col].sortable == "undefined"){
5324 return this.defaultSortable;
5326 return this.config[col].sortable;
5330 * Returns the rendering (formatting) function defined for the column.
5331 * @param {Number} col The column index.
5332 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5334 getRenderer : function(col){
5335 if(!this.config[col].renderer){
5336 return Roo.grid.ColumnModel.defaultRenderer;
5338 return this.config[col].renderer;
5342 * Sets the rendering (formatting) function for a column.
5343 * @param {Number} col The column index
5344 * @param {Function} fn The function to use to process the cell's raw data
5345 * to return HTML markup for the grid view. The render function is called with
5346 * the following parameters:<ul>
5347 * <li>Data value.</li>
5348 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
5349 * <li>css A CSS style string to apply to the table cell.</li>
5350 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
5351 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
5352 * <li>Row index</li>
5353 * <li>Column index</li>
5354 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
5356 setRenderer : function(col, fn){
5357 this.config[col].renderer = fn;
5361 * Returns the width for the specified column.
5362 * @param {Number} col The column index
5365 getColumnWidth : function(col){
5366 return this.config[col].width * 1 || this.defaultWidth;
5370 * Sets the width for a column.
5371 * @param {Number} col The column index
5372 * @param {Number} width The new width
5374 setColumnWidth : function(col, width, suppressEvent){
5375 this.config[col].width = width;
5376 this.totalWidth = null;
5378 this.fireEvent("widthchange", this, col, width);
5383 * Returns the total width of all columns.
5384 * @param {Boolean} includeHidden True to include hidden column widths
5387 getTotalWidth : function(includeHidden){
5388 if(!this.totalWidth){
5389 this.totalWidth = 0;
5390 for(var i = 0, len = this.config.length; i < len; i++){
5391 if(includeHidden || !this.isHidden(i)){
5392 this.totalWidth += this.getColumnWidth(i);
5396 return this.totalWidth;
5400 * Returns the header for the specified column.
5401 * @param {Number} col The column index
5404 getColumnHeader : function(col){
5405 return this.config[col].header;
5409 * Sets the header for a column.
5410 * @param {Number} col The column index
5411 * @param {String} header The new header
5413 setColumnHeader : function(col, header){
5414 this.config[col].header = header;
5415 this.fireEvent("headerchange", this, col, header);
5419 * Returns the tooltip for the specified column.
5420 * @param {Number} col The column index
5423 getColumnTooltip : function(col){
5424 return this.config[col].tooltip;
5427 * Sets the tooltip for a column.
5428 * @param {Number} col The column index
5429 * @param {String} tooltip The new tooltip
5431 setColumnTooltip : function(col, tooltip){
5432 this.config[col].tooltip = tooltip;
5436 * Returns the dataIndex for the specified column.
5437 * @param {Number} col The column index
5440 getDataIndex : function(col){
5441 return this.config[col].dataIndex;
5445 * Sets the dataIndex for a column.
5446 * @param {Number} col The column index
5447 * @param {Number} dataIndex The new dataIndex
5449 setDataIndex : function(col, dataIndex){
5450 this.config[col].dataIndex = dataIndex;
5456 * Returns true if the cell is editable.
5457 * @param {Number} colIndex The column index
5458 * @param {Number} rowIndex The row index - this is nto actually used..?
5461 isCellEditable : function(colIndex, rowIndex){
5462 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
5466 * Returns the editor defined for the cell/column.
5467 * return false or null to disable editing.
5468 * @param {Number} colIndex The column index
5469 * @param {Number} rowIndex The row index
5472 getCellEditor : function(colIndex, rowIndex){
5473 return this.config[colIndex].editor;
5477 * Sets if a column is editable.
5478 * @param {Number} col The column index
5479 * @param {Boolean} editable True if the column is editable
5481 setEditable : function(col, editable){
5482 this.config[col].editable = editable;
5487 * Returns true if the column is hidden.
5488 * @param {Number} colIndex The column index
5491 isHidden : function(colIndex){
5492 return this.config[colIndex].hidden;
5497 * Returns true if the column width cannot be changed
5499 isFixed : function(colIndex){
5500 return this.config[colIndex].fixed;
5504 * Returns true if the column can be resized
5507 isResizable : function(colIndex){
5508 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5511 * Sets if a column is hidden.
5512 * @param {Number} colIndex The column index
5513 * @param {Boolean} hidden True if the column is hidden
5515 setHidden : function(colIndex, hidden){
5516 this.config[colIndex].hidden = hidden;
5517 this.totalWidth = null;
5518 this.fireEvent("hiddenchange", this, colIndex, hidden);
5522 * Sets the editor for a column.
5523 * @param {Number} col The column index
5524 * @param {Object} editor The editor object
5526 setEditor : function(col, editor){
5527 this.config[col].editor = editor;
5531 Roo.grid.ColumnModel.defaultRenderer = function(value){
5532 if(typeof value == "string" && value.length < 1){
5538 // Alias for backwards compatibility
5539 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
5542 * Ext JS Library 1.1.1
5543 * Copyright(c) 2006-2007, Ext JS, LLC.
5545 * Originally Released Under LGPL - original licence link has changed is not relivant.
5548 * <script type="text/javascript">
5552 * @class Roo.LoadMask
5553 * A simple utility class for generically masking elements while loading data. If the element being masked has
5554 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
5555 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
5556 * element's UpdateManager load indicator and will be destroyed after the initial load.
5558 * Create a new LoadMask
5559 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
5560 * @param {Object} config The config object
5562 Roo.LoadMask = function(el, config){
5563 this.el = Roo.get(el);
5564 Roo.apply(this, config);
5566 this.store.on('beforeload', this.onBeforeLoad, this);
5567 this.store.on('load', this.onLoad, this);
5568 this.store.on('loadexception', this.onLoadException, this);
5569 this.removeMask = false;
5571 var um = this.el.getUpdateManager();
5572 um.showLoadIndicator = false; // disable the default indicator
5573 um.on('beforeupdate', this.onBeforeLoad, this);
5574 um.on('update', this.onLoad, this);
5575 um.on('failure', this.onLoad, this);
5576 this.removeMask = true;
5580 Roo.LoadMask.prototype = {
5582 * @cfg {Boolean} removeMask
5583 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
5584 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
5588 * The text to display in a centered loading message box (defaults to 'Loading...')
5592 * @cfg {String} msgCls
5593 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
5595 msgCls : 'x-mask-loading',
5598 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
5604 * Disables the mask to prevent it from being displayed
5606 disable : function(){
5607 this.disabled = true;
5611 * Enables the mask so that it can be displayed
5613 enable : function(){
5614 this.disabled = false;
5617 onLoadException : function()
5621 if (typeof(arguments[3]) != 'undefined') {
5622 Roo.MessageBox.alert("Error loading",arguments[3]);
5626 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
5627 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
5636 this.el.unmask(this.removeMask);
5641 this.el.unmask(this.removeMask);
5645 onBeforeLoad : function(){
5647 this.el.mask(this.msg, this.msgCls);
5652 destroy : function(){
5654 this.store.un('beforeload', this.onBeforeLoad, this);
5655 this.store.un('load', this.onLoad, this);
5656 this.store.un('loadexception', this.onLoadException, this);
5658 var um = this.el.getUpdateManager();
5659 um.un('beforeupdate', this.onBeforeLoad, this);
5660 um.un('update', this.onLoad, this);
5661 um.un('failure', this.onLoad, this);
5672 * @class Roo.bootstrap.Table
5673 * @extends Roo.bootstrap.Component
5674 * Bootstrap Table class
5675 * @cfg {String} cls table class
5676 * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
5677 * @cfg {String} bgcolor Specifies the background color for a table
5678 * @cfg {Number} border Specifies whether the table cells should have borders or not
5679 * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
5680 * @cfg {Number} cellspacing Specifies the space between cells
5681 * @cfg {String} frame Specifies which parts of the outside borders that should be visible
5682 * @cfg {String} rules Specifies which parts of the inside borders that should be visible
5683 * @cfg {String} sortable Specifies that the table should be sortable
5684 * @cfg {String} summary Specifies a summary of the content of a table
5685 * @cfg {Number} width Specifies the width of a table
5686 * @cfg {String} layout table layout (auto | fixed | initial | inherit)
5688 * @cfg {boolean} striped Should the rows be alternative striped
5689 * @cfg {boolean} bordered Add borders to the table
5690 * @cfg {boolean} hover Add hover highlighting
5691 * @cfg {boolean} condensed Format condensed
5692 * @cfg {boolean} responsive Format condensed
5693 * @cfg {Boolean} loadMask (true|false) default false
5694 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
5695 * @cfg {Boolean} headerShow (true|false) generate thead, default true
5696 * @cfg {Boolean} rowSelection (true|false) default false
5697 * @cfg {Boolean} cellSelection (true|false) default false
5698 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
5699 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
5703 * Create a new Table
5704 * @param {Object} config The config object
5707 Roo.bootstrap.Table = function(config){
5708 Roo.bootstrap.Table.superclass.constructor.call(this, config);
5713 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
5714 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
5715 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
5716 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
5718 this.sm = this.sm || {xtype: 'RowSelectionModel'};
5720 this.sm.grid = this;
5721 this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
5722 this.sm = this.selModel;
5723 this.sm.xmodule = this.xmodule || false;
5726 if (this.cm && typeof(this.cm.config) == 'undefined') {
5727 this.colModel = new Roo.grid.ColumnModel(this.cm);
5728 this.cm = this.colModel;
5729 this.cm.xmodule = this.xmodule || false;
5732 this.store= Roo.factory(this.store, Roo.data);
5733 this.ds = this.store;
5734 this.ds.xmodule = this.xmodule || false;
5737 if (this.footer && this.store) {
5738 this.footer.dataSource = this.ds;
5739 this.footer = Roo.factory(this.footer);
5746 * Fires when a cell is clicked
5747 * @param {Roo.bootstrap.Table} this
5748 * @param {Roo.Element} el
5749 * @param {Number} rowIndex
5750 * @param {Number} columnIndex
5751 * @param {Roo.EventObject} e
5755 * @event celldblclick
5756 * Fires when a cell is double clicked
5757 * @param {Roo.bootstrap.Table} this
5758 * @param {Roo.Element} el
5759 * @param {Number} rowIndex
5760 * @param {Number} columnIndex
5761 * @param {Roo.EventObject} e
5763 "celldblclick" : true,
5766 * Fires when a row is clicked
5767 * @param {Roo.bootstrap.Table} this
5768 * @param {Roo.Element} el
5769 * @param {Number} rowIndex
5770 * @param {Roo.EventObject} e
5774 * @event rowdblclick
5775 * Fires when a row is double clicked
5776 * @param {Roo.bootstrap.Table} this
5777 * @param {Roo.Element} el
5778 * @param {Number} rowIndex
5779 * @param {Roo.EventObject} e
5781 "rowdblclick" : true,
5784 * Fires when a mouseover occur
5785 * @param {Roo.bootstrap.Table} this
5786 * @param {Roo.Element} el
5787 * @param {Number} rowIndex
5788 * @param {Number} columnIndex
5789 * @param {Roo.EventObject} e
5794 * Fires when a mouseout occur
5795 * @param {Roo.bootstrap.Table} this
5796 * @param {Roo.Element} el
5797 * @param {Number} rowIndex
5798 * @param {Number} columnIndex
5799 * @param {Roo.EventObject} e
5804 * Fires when a row is rendered, so you can change add a style to it.
5805 * @param {Roo.bootstrap.Table} this
5806 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
5810 * @event rowsrendered
5811 * Fires when all the rows have been rendered
5812 * @param {Roo.bootstrap.Table} this
5814 'rowsrendered' : true,
5816 * @event contextmenu
5817 * The raw contextmenu event for the entire grid.
5818 * @param {Roo.EventObject} e
5820 "contextmenu" : true,
5822 * @event rowcontextmenu
5823 * Fires when a row is right clicked
5824 * @param {Roo.bootstrap.Table} this
5825 * @param {Number} rowIndex
5826 * @param {Roo.EventObject} e
5828 "rowcontextmenu" : true,
5830 * @event cellcontextmenu
5831 * Fires when a cell is right clicked
5832 * @param {Roo.bootstrap.Table} this
5833 * @param {Number} rowIndex
5834 * @param {Number} cellIndex
5835 * @param {Roo.EventObject} e
5837 "cellcontextmenu" : true,
5839 * @event headercontextmenu
5840 * Fires when a header is right clicked
5841 * @param {Roo.bootstrap.Table} this
5842 * @param {Number} columnIndex
5843 * @param {Roo.EventObject} e
5845 "headercontextmenu" : true
5849 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
5875 rowSelection : false,
5876 cellSelection : false,
5879 // Roo.Element - the tbody
5881 // Roo.Element - thead element
5884 container: false, // used by gridpanel...
5886 getAutoCreate : function()
5888 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
5895 if (this.scrollBody) {
5896 cfg.cls += ' table-body-fixed';
5899 cfg.cls += ' table-striped';
5903 cfg.cls += ' table-hover';
5905 if (this.bordered) {
5906 cfg.cls += ' table-bordered';
5908 if (this.condensed) {
5909 cfg.cls += ' table-condensed';
5911 if (this.responsive) {
5912 cfg.cls += ' table-responsive';
5916 cfg.cls+= ' ' +this.cls;
5919 // this lot should be simplifed...
5922 cfg.align=this.align;
5925 cfg.bgcolor=this.bgcolor;
5928 cfg.border=this.border;
5930 if (this.cellpadding) {
5931 cfg.cellpadding=this.cellpadding;
5933 if (this.cellspacing) {
5934 cfg.cellspacing=this.cellspacing;
5937 cfg.frame=this.frame;
5940 cfg.rules=this.rules;
5942 if (this.sortable) {
5943 cfg.sortable=this.sortable;
5946 cfg.summary=this.summary;
5949 cfg.width=this.width;
5952 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
5955 if(this.store || this.cm){
5956 if(this.headerShow){
5957 cfg.cn.push(this.renderHeader());
5960 cfg.cn.push(this.renderBody());
5962 if(this.footerShow){
5963 cfg.cn.push(this.renderFooter());
5965 // where does this come from?
5966 //cfg.cls+= ' TableGrid';
5969 return { cn : [ cfg ] };
5972 initEvents : function()
5974 if(!this.store || !this.cm){
5977 if (this.selModel) {
5978 this.selModel.initEvents();
5982 //Roo.log('initEvents with ds!!!!');
5984 this.mainBody = this.el.select('tbody', true).first();
5985 this.mainHead = this.el.select('thead', true).first();
5992 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
5993 e.on('click', _this.sort, _this);
5996 this.el.on("click", this.onClick, this);
5997 this.el.on("dblclick", this.onDblClick, this);
5999 // why is this done????? = it breaks dialogs??
6000 //this.parent().el.setStyle('position', 'relative');
6004 this.footer.parentId = this.id;
6005 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
6008 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
6010 this.store.on('load', this.onLoad, this);
6011 this.store.on('beforeload', this.onBeforeLoad, this);
6012 this.store.on('update', this.onUpdate, this);
6013 this.store.on('add', this.onAdd, this);
6014 this.store.on("clear", this.clear, this);
6016 this.el.on("contextmenu", this.onContextMenu, this);
6018 this.mainBody.on('scroll', this.onBodyScroll, this);
6023 onContextMenu : function(e, t)
6025 this.processEvent("contextmenu", e);
6028 processEvent : function(name, e)
6030 if (name != 'touchstart' ) {
6031 this.fireEvent(name, e);
6034 var t = e.getTarget();
6036 var cell = Roo.get(t);
6042 if(cell.findParent('tfoot', false, true)){
6046 if(cell.findParent('thead', false, true)){
6048 if(e.getTarget().nodeName.toLowerCase() != 'th'){
6049 cell = Roo.get(t).findParent('th', false, true);
6051 Roo.log("failed to find th in thead?");
6052 Roo.log(e.getTarget());
6057 var cellIndex = cell.dom.cellIndex;
6059 var ename = name == 'touchstart' ? 'click' : name;
6060 this.fireEvent("header" + ename, this, cellIndex, e);
6065 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6066 cell = Roo.get(t).findParent('td', false, true);
6068 Roo.log("failed to find th in tbody?");
6069 Roo.log(e.getTarget());
6074 var row = cell.findParent('tr', false, true);
6075 var cellIndex = cell.dom.cellIndex;
6076 var rowIndex = row.dom.rowIndex - 1;
6080 this.fireEvent("row" + name, this, rowIndex, e);
6084 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
6090 onMouseover : 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('mouseover', this, cell, rowIndex, cellIndex, e);
6110 onMouseout : function(e, el)
6112 var cell = Roo.get(el);
6118 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6119 cell = cell.findParent('td', false, true);
6122 var row = cell.findParent('tr', false, true);
6123 var cellIndex = cell.dom.cellIndex;
6124 var rowIndex = row.dom.rowIndex - 1; // start from 0
6126 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
6130 onClick : function(e, el)
6132 var cell = Roo.get(el);
6134 if(!cell || (!this.cellSelection && !this.rowSelection)){
6138 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6139 cell = cell.findParent('td', false, true);
6142 if(!cell || typeof(cell) == 'undefined'){
6146 var row = cell.findParent('tr', false, true);
6148 if(!row || typeof(row) == 'undefined'){
6152 var cellIndex = cell.dom.cellIndex;
6153 var rowIndex = this.getRowIndex(row);
6155 // why??? - should these not be based on SelectionModel?
6156 if(this.cellSelection){
6157 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
6160 if(this.rowSelection){
6161 this.fireEvent('rowclick', this, row, rowIndex, e);
6167 onDblClick : function(e,el)
6169 var cell = Roo.get(el);
6171 if(!cell || (!this.cellSelection && !this.rowSelection)){
6175 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6176 cell = cell.findParent('td', false, true);
6179 if(!cell || typeof(cell) == 'undefined'){
6183 var row = cell.findParent('tr', false, true);
6185 if(!row || typeof(row) == 'undefined'){
6189 var cellIndex = cell.dom.cellIndex;
6190 var rowIndex = this.getRowIndex(row);
6192 if(this.cellSelection){
6193 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
6196 if(this.rowSelection){
6197 this.fireEvent('rowdblclick', this, row, rowIndex, e);
6201 sort : function(e,el)
6203 var col = Roo.get(el);
6205 if(!col.hasClass('sortable')){
6209 var sort = col.attr('sort');
6212 if(col.select('i', true).first().hasClass('glyphicon-arrow-up')){
6216 this.store.sortInfo = {field : sort, direction : dir};
6219 Roo.log("calling footer first");
6220 this.footer.onClick('first');
6223 this.store.load({ params : { start : 0 } });
6227 renderHeader : function()
6235 this.totalWidth = 0;
6237 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6239 var config = cm.config[i];
6244 html: cm.getColumnHeader(i)
6249 if(typeof(config.sortable) != 'undefined' && config.sortable){
6251 c.html = '<i class="glyphicon"></i>' + c.html;
6254 if(typeof(config.lgHeader) != 'undefined'){
6255 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
6258 if(typeof(config.mdHeader) != 'undefined'){
6259 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
6262 if(typeof(config.smHeader) != 'undefined'){
6263 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
6266 if(typeof(config.xsHeader) != 'undefined'){
6267 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
6274 if(typeof(config.tooltip) != 'undefined'){
6275 c.tooltip = config.tooltip;
6278 if(typeof(config.colspan) != 'undefined'){
6279 c.colspan = config.colspan;
6282 if(typeof(config.hidden) != 'undefined' && config.hidden){
6283 c.style += ' display:none;';
6286 if(typeof(config.dataIndex) != 'undefined'){
6287 c.sort = config.dataIndex;
6292 if(typeof(config.align) != 'undefined' && config.align.length){
6293 c.style += ' text-align:' + config.align + ';';
6296 if(typeof(config.width) != 'undefined'){
6297 c.style += ' width:' + config.width + 'px;';
6298 this.totalWidth += config.width;
6300 this.totalWidth += 100; // assume minimum of 100 per column?
6303 if(typeof(config.cls) != 'undefined'){
6304 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
6307 ['xs','sm','md','lg'].map(function(size){
6309 if(typeof(config[size]) == 'undefined'){
6313 if (!config[size]) { // 0 = hidden
6314 c.cls += ' hidden-' + size;
6318 c.cls += ' col-' + size + '-' + config[size];
6328 renderBody : function()
6338 colspan : this.cm.getColumnCount()
6348 renderFooter : function()
6358 colspan : this.cm.getColumnCount()
6372 // Roo.log('ds onload');
6377 var ds = this.store;
6379 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6380 e.select('i', true).removeClass(['glyphicon-arrow-up', 'glyphicon-arrow-down']);
6381 if (_this.store.sortInfo) {
6383 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
6384 e.select('i', true).addClass(['glyphicon-arrow-up']);
6387 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
6388 e.select('i', true).addClass(['glyphicon-arrow-down']);
6393 var tbody = this.mainBody;
6395 if(ds.getCount() > 0){
6396 ds.data.each(function(d,rowIndex){
6397 var row = this.renderRow(cm, ds, rowIndex);
6399 tbody.createChild(row);
6403 if(row.cellObjects.length){
6404 Roo.each(row.cellObjects, function(r){
6405 _this.renderCellObject(r);
6412 Roo.each(this.el.select('tbody td', true).elements, function(e){
6413 e.on('mouseover', _this.onMouseover, _this);
6416 Roo.each(this.el.select('tbody td', true).elements, function(e){
6417 e.on('mouseout', _this.onMouseout, _this);
6419 this.fireEvent('rowsrendered', this);
6420 //if(this.loadMask){
6421 // this.maskEl.hide();
6428 onUpdate : function(ds,record)
6430 this.refreshRow(record);
6434 onRemove : function(ds, record, index, isUpdate){
6435 if(isUpdate !== true){
6436 this.fireEvent("beforerowremoved", this, index, record);
6438 var bt = this.mainBody.dom;
6440 var rows = this.el.select('tbody > tr', true).elements;
6442 if(typeof(rows[index]) != 'undefined'){
6443 bt.removeChild(rows[index].dom);
6446 // if(bt.rows[index]){
6447 // bt.removeChild(bt.rows[index]);
6450 if(isUpdate !== true){
6451 //this.stripeRows(index);
6452 //this.syncRowHeights(index, index);
6454 this.fireEvent("rowremoved", this, index, record);
6458 onAdd : function(ds, records, rowIndex)
6460 //Roo.log('on Add called');
6461 // - note this does not handle multiple adding very well..
6462 var bt = this.mainBody.dom;
6463 for (var i =0 ; i < records.length;i++) {
6464 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
6465 //Roo.log(records[i]);
6466 //Roo.log(this.store.getAt(rowIndex+i));
6467 this.insertRow(this.store, rowIndex + i, false);
6474 refreshRow : function(record){
6475 var ds = this.store, index;
6476 if(typeof record == 'number'){
6478 record = ds.getAt(index);
6480 index = ds.indexOf(record);
6482 this.insertRow(ds, index, true);
6484 this.onRemove(ds, record, index+1, true);
6486 //this.syncRowHeights(index, index);
6488 this.fireEvent("rowupdated", this, index, record);
6491 insertRow : function(dm, rowIndex, isUpdate){
6494 this.fireEvent("beforerowsinserted", this, rowIndex);
6496 //var s = this.getScrollState();
6497 var row = this.renderRow(this.cm, this.store, rowIndex);
6498 // insert before rowIndex..
6499 var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
6503 if(row.cellObjects.length){
6504 Roo.each(row.cellObjects, function(r){
6505 _this.renderCellObject(r);
6510 this.fireEvent("rowsinserted", this, rowIndex);
6511 //this.syncRowHeights(firstRow, lastRow);
6512 //this.stripeRows(firstRow);
6519 getRowDom : function(rowIndex)
6521 var rows = this.el.select('tbody > tr', true).elements;
6523 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
6526 // returns the object tree for a tr..
6529 renderRow : function(cm, ds, rowIndex)
6532 var d = ds.getAt(rowIndex);
6539 var cellObjects = [];
6541 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6542 var config = cm.config[i];
6544 var renderer = cm.getRenderer(i);
6548 if(typeof(renderer) !== 'undefined'){
6549 value = renderer(d.data[cm.getDataIndex(i)], false, d);
6551 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
6552 // and are rendered into the cells after the row is rendered - using the id for the element.
6554 if(typeof(value) === 'object'){
6564 rowIndex : rowIndex,
6569 this.fireEvent('rowclass', this, rowcfg);
6573 cls : rowcfg.rowClass,
6575 html: (typeof(value) === 'object') ? '' : value
6582 if(typeof(config.colspan) != 'undefined'){
6583 td.colspan = config.colspan;
6586 if(typeof(config.hidden) != 'undefined' && config.hidden){
6587 td.style += ' display:none;';
6590 if(typeof(config.align) != 'undefined' && config.align.length){
6591 td.style += ' text-align:' + config.align + ';';
6594 if(typeof(config.width) != 'undefined'){
6595 td.style += ' width:' + config.width + 'px;';
6598 if(typeof(config.cursor) != 'undefined'){
6599 td.style += ' cursor:' + config.cursor + ';';
6602 if(typeof(config.cls) != 'undefined'){
6603 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
6606 ['xs','sm','md','lg'].map(function(size){
6608 if(typeof(config[size]) == 'undefined'){
6612 if (!config[size]) { // 0 = hidden
6613 td.cls += ' hidden-' + size;
6617 td.cls += ' col-' + size + '-' + config[size];
6625 row.cellObjects = cellObjects;
6633 onBeforeLoad : function()
6635 //Roo.log('ds onBeforeLoad');
6639 //if(this.loadMask){
6640 // this.maskEl.show();
6648 this.el.select('tbody', true).first().dom.innerHTML = '';
6651 * Show or hide a row.
6652 * @param {Number} rowIndex to show or hide
6653 * @param {Boolean} state hide
6655 setRowVisibility : function(rowIndex, state)
6657 var bt = this.mainBody.dom;
6659 var rows = this.el.select('tbody > tr', true).elements;
6661 if(typeof(rows[rowIndex]) == 'undefined'){
6664 rows[rowIndex].dom.style.display = state ? '' : 'none';
6668 getSelectionModel : function(){
6670 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
6672 return this.selModel;
6675 * Render the Roo.bootstrap object from renderder
6677 renderCellObject : function(r)
6681 var t = r.cfg.render(r.container);
6684 Roo.each(r.cfg.cn, function(c){
6686 container: t.getChildContainer(),
6689 _this.renderCellObject(child);
6694 getRowIndex : function(row)
6698 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
6709 * Returns the grid's underlying element = used by panel.Grid
6710 * @return {Element} The element
6712 getGridEl : function(){
6716 * Forces a resize - used by panel.Grid
6717 * @return {Element} The element
6719 autoSize : function()
6721 //var ctr = Roo.get(this.container.dom.parentElement);
6722 var ctr = Roo.get(this.el.dom);
6724 var thd = this.getGridEl().select('thead',true).first();
6725 var tbd = this.getGridEl().select('tbody', true).first();
6728 var cw = ctr.getWidth();
6732 tbd.setSize(ctr.getWidth(), ctr.getHeight() - thd.getHeight());
6733 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
6736 cw = Math.max(cw, this.totalWidth);
6737 this.getGridEl().select('tr',true).setWidth(cw);
6738 // resize 'expandable coloumn?
6740 return; // we doe not have a view in this design..
6743 onBodyScroll: function()
6746 //Roo.log("body scrolled');" + this.mainBody.dom.scrollLeft);
6747 this.mainHead.setStyle({
6748 'position' : 'relative',
6749 'left': (-1* this.mainBody.dom.scrollLeft) + 'px'
6766 * @class Roo.bootstrap.TableCell
6767 * @extends Roo.bootstrap.Component
6768 * Bootstrap TableCell class
6769 * @cfg {String} html cell contain text
6770 * @cfg {String} cls cell class
6771 * @cfg {String} tag cell tag (td|th) default td
6772 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
6773 * @cfg {String} align Aligns the content in a cell
6774 * @cfg {String} axis Categorizes cells
6775 * @cfg {String} bgcolor Specifies the background color of a cell
6776 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
6777 * @cfg {Number} colspan Specifies the number of columns a cell should span
6778 * @cfg {String} headers Specifies one or more header cells a cell is related to
6779 * @cfg {Number} height Sets the height of a cell
6780 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
6781 * @cfg {Number} rowspan Sets the number of rows a cell should span
6782 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
6783 * @cfg {String} valign Vertical aligns the content in a cell
6784 * @cfg {Number} width Specifies the width of a cell
6787 * Create a new TableCell
6788 * @param {Object} config The config object
6791 Roo.bootstrap.TableCell = function(config){
6792 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
6795 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
6815 getAutoCreate : function(){
6816 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
6836 cfg.align=this.align
6842 cfg.bgcolor=this.bgcolor
6845 cfg.charoff=this.charoff
6848 cfg.colspan=this.colspan
6851 cfg.headers=this.headers
6854 cfg.height=this.height
6857 cfg.nowrap=this.nowrap
6860 cfg.rowspan=this.rowspan
6863 cfg.scope=this.scope
6866 cfg.valign=this.valign
6869 cfg.width=this.width
6888 * @class Roo.bootstrap.TableRow
6889 * @extends Roo.bootstrap.Component
6890 * Bootstrap TableRow class
6891 * @cfg {String} cls row class
6892 * @cfg {String} align Aligns the content in a table row
6893 * @cfg {String} bgcolor Specifies a background color for a table row
6894 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
6895 * @cfg {String} valign Vertical aligns the content in a table row
6898 * Create a new TableRow
6899 * @param {Object} config The config object
6902 Roo.bootstrap.TableRow = function(config){
6903 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
6906 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
6914 getAutoCreate : function(){
6915 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
6925 cfg.align = this.align;
6928 cfg.bgcolor = this.bgcolor;
6931 cfg.charoff = this.charoff;
6934 cfg.valign = this.valign;
6952 * @class Roo.bootstrap.TableBody
6953 * @extends Roo.bootstrap.Component
6954 * Bootstrap TableBody class
6955 * @cfg {String} cls element class
6956 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
6957 * @cfg {String} align Aligns the content inside the element
6958 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
6959 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
6962 * Create a new TableBody
6963 * @param {Object} config The config object
6966 Roo.bootstrap.TableBody = function(config){
6967 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
6970 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
6978 getAutoCreate : function(){
6979 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
6993 cfg.align = this.align;
6996 cfg.charoff = this.charoff;
6999 cfg.valign = this.valign;
7006 // initEvents : function()
7013 // this.store = Roo.factory(this.store, Roo.data);
7014 // this.store.on('load', this.onLoad, this);
7016 // this.store.load();
7020 // onLoad: function ()
7022 // this.fireEvent('load', this);
7032 * Ext JS Library 1.1.1
7033 * Copyright(c) 2006-2007, Ext JS, LLC.
7035 * Originally Released Under LGPL - original licence link has changed is not relivant.
7038 * <script type="text/javascript">
7041 // as we use this in bootstrap.
7042 Roo.namespace('Roo.form');
7044 * @class Roo.form.Action
7045 * Internal Class used to handle form actions
7047 * @param {Roo.form.BasicForm} el The form element or its id
7048 * @param {Object} config Configuration options
7053 // define the action interface
7054 Roo.form.Action = function(form, options){
7056 this.options = options || {};
7059 * Client Validation Failed
7062 Roo.form.Action.CLIENT_INVALID = 'client';
7064 * Server Validation Failed
7067 Roo.form.Action.SERVER_INVALID = 'server';
7069 * Connect to Server Failed
7072 Roo.form.Action.CONNECT_FAILURE = 'connect';
7074 * Reading Data from Server Failed
7077 Roo.form.Action.LOAD_FAILURE = 'load';
7079 Roo.form.Action.prototype = {
7081 failureType : undefined,
7082 response : undefined,
7086 run : function(options){
7091 success : function(response){
7096 handleResponse : function(response){
7100 // default connection failure
7101 failure : function(response){
7103 this.response = response;
7104 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7105 this.form.afterAction(this, false);
7108 processResponse : function(response){
7109 this.response = response;
7110 if(!response.responseText){
7113 this.result = this.handleResponse(response);
7117 // utility functions used internally
7118 getUrl : function(appendParams){
7119 var url = this.options.url || this.form.url || this.form.el.dom.action;
7121 var p = this.getParams();
7123 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
7129 getMethod : function(){
7130 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
7133 getParams : function(){
7134 var bp = this.form.baseParams;
7135 var p = this.options.params;
7137 if(typeof p == "object"){
7138 p = Roo.urlEncode(Roo.applyIf(p, bp));
7139 }else if(typeof p == 'string' && bp){
7140 p += '&' + Roo.urlEncode(bp);
7143 p = Roo.urlEncode(bp);
7148 createCallback : function(){
7150 success: this.success,
7151 failure: this.failure,
7153 timeout: (this.form.timeout*1000),
7154 upload: this.form.fileUpload ? this.success : undefined
7159 Roo.form.Action.Submit = function(form, options){
7160 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
7163 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
7166 haveProgress : false,
7167 uploadComplete : false,
7169 // uploadProgress indicator.
7170 uploadProgress : function()
7172 if (!this.form.progressUrl) {
7176 if (!this.haveProgress) {
7177 Roo.MessageBox.progress("Uploading", "Uploading");
7179 if (this.uploadComplete) {
7180 Roo.MessageBox.hide();
7184 this.haveProgress = true;
7186 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
7188 var c = new Roo.data.Connection();
7190 url : this.form.progressUrl,
7195 success : function(req){
7196 //console.log(data);
7200 rdata = Roo.decode(req.responseText)
7202 Roo.log("Invalid data from server..");
7206 if (!rdata || !rdata.success) {
7208 Roo.MessageBox.alert(Roo.encode(rdata));
7211 var data = rdata.data;
7213 if (this.uploadComplete) {
7214 Roo.MessageBox.hide();
7219 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
7220 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
7223 this.uploadProgress.defer(2000,this);
7226 failure: function(data) {
7227 Roo.log('progress url failed ');
7238 // run get Values on the form, so it syncs any secondary forms.
7239 this.form.getValues();
7241 var o = this.options;
7242 var method = this.getMethod();
7243 var isPost = method == 'POST';
7244 if(o.clientValidation === false || this.form.isValid()){
7246 if (this.form.progressUrl) {
7247 this.form.findField('UPLOAD_IDENTIFIER').setValue(
7248 (new Date() * 1) + '' + Math.random());
7253 Roo.Ajax.request(Roo.apply(this.createCallback(), {
7254 form:this.form.el.dom,
7255 url:this.getUrl(!isPost),
7257 params:isPost ? this.getParams() : null,
7258 isUpload: this.form.fileUpload
7261 this.uploadProgress();
7263 }else if (o.clientValidation !== false){ // client validation failed
7264 this.failureType = Roo.form.Action.CLIENT_INVALID;
7265 this.form.afterAction(this, false);
7269 success : function(response)
7271 this.uploadComplete= true;
7272 if (this.haveProgress) {
7273 Roo.MessageBox.hide();
7277 var result = this.processResponse(response);
7278 if(result === true || result.success){
7279 this.form.afterAction(this, true);
7283 this.form.markInvalid(result.errors);
7284 this.failureType = Roo.form.Action.SERVER_INVALID;
7286 this.form.afterAction(this, false);
7288 failure : function(response)
7290 this.uploadComplete= true;
7291 if (this.haveProgress) {
7292 Roo.MessageBox.hide();
7295 this.response = response;
7296 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7297 this.form.afterAction(this, false);
7300 handleResponse : function(response){
7301 if(this.form.errorReader){
7302 var rs = this.form.errorReader.read(response);
7305 for(var i = 0, len = rs.records.length; i < len; i++) {
7306 var r = rs.records[i];
7310 if(errors.length < 1){
7314 success : rs.success,
7320 ret = Roo.decode(response.responseText);
7324 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
7334 Roo.form.Action.Load = function(form, options){
7335 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
7336 this.reader = this.form.reader;
7339 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
7344 Roo.Ajax.request(Roo.apply(
7345 this.createCallback(), {
7346 method:this.getMethod(),
7347 url:this.getUrl(false),
7348 params:this.getParams()
7352 success : function(response){
7354 var result = this.processResponse(response);
7355 if(result === true || !result.success || !result.data){
7356 this.failureType = Roo.form.Action.LOAD_FAILURE;
7357 this.form.afterAction(this, false);
7360 this.form.clearInvalid();
7361 this.form.setValues(result.data);
7362 this.form.afterAction(this, true);
7365 handleResponse : function(response){
7366 if(this.form.reader){
7367 var rs = this.form.reader.read(response);
7368 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
7370 success : rs.success,
7374 return Roo.decode(response.responseText);
7378 Roo.form.Action.ACTION_TYPES = {
7379 'load' : Roo.form.Action.Load,
7380 'submit' : Roo.form.Action.Submit
7389 * @class Roo.bootstrap.Form
7390 * @extends Roo.bootstrap.Component
7391 * Bootstrap Form class
7392 * @cfg {String} method GET | POST (default POST)
7393 * @cfg {String} labelAlign top | left (default top)
7394 * @cfg {String} align left | right - for navbars
7395 * @cfg {Boolean} loadMask load mask when submit (default true)
7400 * @param {Object} config The config object
7404 Roo.bootstrap.Form = function(config){
7405 Roo.bootstrap.Form.superclass.constructor.call(this, config);
7408 * @event clientvalidation
7409 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
7410 * @param {Form} this
7411 * @param {Boolean} valid true if the form has passed client-side validation
7413 clientvalidation: true,
7415 * @event beforeaction
7416 * Fires before any action is performed. Return false to cancel the action.
7417 * @param {Form} this
7418 * @param {Action} action The action to be performed
7422 * @event actionfailed
7423 * Fires when an action fails.
7424 * @param {Form} this
7425 * @param {Action} action The action that failed
7427 actionfailed : true,
7429 * @event actioncomplete
7430 * Fires when an action is completed.
7431 * @param {Form} this
7432 * @param {Action} action The action that completed
7434 actioncomplete : true
7439 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component, {
7442 * @cfg {String} method
7443 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
7448 * The URL to use for form actions if one isn't supplied in the action options.
7451 * @cfg {Boolean} fileUpload
7452 * Set to true if this form is a file upload.
7456 * @cfg {Object} baseParams
7457 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
7461 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
7465 * @cfg {Sting} align (left|right) for navbar forms
7470 activeAction : null,
7473 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
7474 * element by passing it or its id or mask the form itself by passing in true.
7477 waitMsgTarget : false,
7481 getAutoCreate : function(){
7485 method : this.method || 'POST',
7486 id : this.id || Roo.id(),
7489 if (this.parent().xtype.match(/^Nav/)) {
7490 cfg.cls = 'navbar-form navbar-' + this.align;
7494 if (this.labelAlign == 'left' ) {
7495 cfg.cls += ' form-horizontal';
7501 initEvents : function()
7503 this.el.on('submit', this.onSubmit, this);
7504 // this was added as random key presses on the form where triggering form submit.
7505 this.el.on('keypress', function(e) {
7506 if (e.getCharCode() != 13) {
7509 // we might need to allow it for textareas.. and some other items.
7510 // check e.getTarget().
7512 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
7516 Roo.log("keypress blocked");
7524 onSubmit : function(e){
7529 * Returns true if client-side validation on the form is successful.
7532 isValid : function(){
7533 var items = this.getItems();
7535 items.each(function(f){
7544 * Returns true if any fields in this form have changed since their original load.
7547 isDirty : function(){
7549 var items = this.getItems();
7550 items.each(function(f){
7560 * Performs a predefined action (submit or load) or custom actions you define on this form.
7561 * @param {String} actionName The name of the action type
7562 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
7563 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
7564 * accept other config options):
7566 Property Type Description
7567 ---------------- --------------- ----------------------------------------------------------------------------------
7568 url String The url for the action (defaults to the form's url)
7569 method String The form method to use (defaults to the form's method, or POST if not defined)
7570 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
7571 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
7572 validate the form on the client (defaults to false)
7574 * @return {BasicForm} this
7576 doAction : function(action, options){
7577 if(typeof action == 'string'){
7578 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
7580 if(this.fireEvent('beforeaction', this, action) !== false){
7581 this.beforeAction(action);
7582 action.run.defer(100, action);
7588 beforeAction : function(action){
7589 var o = action.options;
7592 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7594 // not really supported yet.. ??
7596 //if(this.waitMsgTarget === true){
7597 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7598 //}else if(this.waitMsgTarget){
7599 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
7600 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
7602 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
7608 afterAction : function(action, success){
7609 this.activeAction = null;
7610 var o = action.options;
7612 //if(this.waitMsgTarget === true){
7614 //}else if(this.waitMsgTarget){
7615 // this.waitMsgTarget.unmask();
7617 // Roo.MessageBox.updateProgress(1);
7618 // Roo.MessageBox.hide();
7625 Roo.callback(o.success, o.scope, [this, action]);
7626 this.fireEvent('actioncomplete', this, action);
7630 // failure condition..
7631 // we have a scenario where updates need confirming.
7632 // eg. if a locking scenario exists..
7633 // we look for { errors : { needs_confirm : true }} in the response.
7635 (typeof(action.result) != 'undefined') &&
7636 (typeof(action.result.errors) != 'undefined') &&
7637 (typeof(action.result.errors.needs_confirm) != 'undefined')
7640 Roo.log("not supported yet");
7643 Roo.MessageBox.confirm(
7644 "Change requires confirmation",
7645 action.result.errorMsg,
7650 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
7660 Roo.callback(o.failure, o.scope, [this, action]);
7661 // show an error message if no failed handler is set..
7662 if (!this.hasListener('actionfailed')) {
7663 Roo.log("need to add dialog support");
7665 Roo.MessageBox.alert("Error",
7666 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
7667 action.result.errorMsg :
7668 "Saving Failed, please check your entries or try again"
7673 this.fireEvent('actionfailed', this, action);
7678 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
7679 * @param {String} id The value to search for
7682 findField : function(id){
7683 var items = this.getItems();
7684 var field = items.get(id);
7686 items.each(function(f){
7687 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
7694 return field || null;
7697 * Mark fields in this form invalid in bulk.
7698 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
7699 * @return {BasicForm} this
7701 markInvalid : function(errors){
7702 if(errors instanceof Array){
7703 for(var i = 0, len = errors.length; i < len; i++){
7704 var fieldError = errors[i];
7705 var f = this.findField(fieldError.id);
7707 f.markInvalid(fieldError.msg);
7713 if(typeof errors[id] != 'function' && (field = this.findField(id))){
7714 field.markInvalid(errors[id]);
7718 //Roo.each(this.childForms || [], function (f) {
7719 // f.markInvalid(errors);
7726 * Set values for fields in this form in bulk.
7727 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
7728 * @return {BasicForm} this
7730 setValues : function(values){
7731 if(values instanceof Array){ // array of objects
7732 for(var i = 0, len = values.length; i < len; i++){
7734 var f = this.findField(v.id);
7736 f.setValue(v.value);
7737 if(this.trackResetOnLoad){
7738 f.originalValue = f.getValue();
7742 }else{ // object hash
7745 if(typeof values[id] != 'function' && (field = this.findField(id))){
7747 if (field.setFromData &&
7749 field.displayField &&
7750 // combos' with local stores can
7751 // be queried via setValue()
7752 // to set their value..
7753 (field.store && !field.store.isLocal)
7757 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
7758 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
7759 field.setFromData(sd);
7762 field.setValue(values[id]);
7766 if(this.trackResetOnLoad){
7767 field.originalValue = field.getValue();
7773 //Roo.each(this.childForms || [], function (f) {
7774 // f.setValues(values);
7781 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
7782 * they are returned as an array.
7783 * @param {Boolean} asString
7786 getValues : function(asString){
7787 //if (this.childForms) {
7788 // copy values from the child forms
7789 // Roo.each(this.childForms, function (f) {
7790 // this.setValues(f.getValues());
7796 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
7797 if(asString === true){
7800 return Roo.urlDecode(fs);
7804 * Returns the fields in this form as an object with key/value pairs.
7805 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
7808 getFieldValues : function(with_hidden)
7810 var items = this.getItems();
7812 items.each(function(f){
7816 var v = f.getValue();
7817 if (f.inputType =='radio') {
7818 if (typeof(ret[f.getName()]) == 'undefined') {
7819 ret[f.getName()] = ''; // empty..
7822 if (!f.el.dom.checked) {
7830 // not sure if this supported any more..
7831 if ((typeof(v) == 'object') && f.getRawValue) {
7832 v = f.getRawValue() ; // dates..
7834 // combo boxes where name != hiddenName...
7835 if (f.name != f.getName()) {
7836 ret[f.name] = f.getRawValue();
7838 ret[f.getName()] = v;
7845 * Clears all invalid messages in this form.
7846 * @return {BasicForm} this
7848 clearInvalid : function(){
7849 var items = this.getItems();
7851 items.each(function(f){
7862 * @return {BasicForm} this
7865 var items = this.getItems();
7866 items.each(function(f){
7870 Roo.each(this.childForms || [], function (f) {
7877 getItems : function()
7879 var r=new Roo.util.MixedCollection(false, function(o){
7880 return o.id || (o.id = Roo.id());
7882 var iter = function(el) {
7889 Roo.each(el.items,function(e) {
7909 * Ext JS Library 1.1.1
7910 * Copyright(c) 2006-2007, Ext JS, LLC.
7912 * Originally Released Under LGPL - original licence link has changed is not relivant.
7915 * <script type="text/javascript">
7918 * @class Roo.form.VTypes
7919 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
7922 Roo.form.VTypes = function(){
7923 // closure these in so they are only created once.
7924 var alpha = /^[a-zA-Z_]+$/;
7925 var alphanum = /^[a-zA-Z0-9_]+$/;
7926 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
7927 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
7929 // All these messages and functions are configurable
7932 * The function used to validate email addresses
7933 * @param {String} value The email address
7935 'email' : function(v){
7936 return email.test(v);
7939 * The error text to display when the email validation function returns false
7942 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
7944 * The keystroke filter mask to be applied on email input
7947 'emailMask' : /[a-z0-9_\.\-@]/i,
7950 * The function used to validate URLs
7951 * @param {String} value The URL
7953 'url' : function(v){
7957 * The error text to display when the url validation function returns false
7960 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
7963 * The function used to validate alpha values
7964 * @param {String} value The value
7966 'alpha' : function(v){
7967 return alpha.test(v);
7970 * The error text to display when the alpha validation function returns false
7973 'alphaText' : 'This field should only contain letters and _',
7975 * The keystroke filter mask to be applied on alpha input
7978 'alphaMask' : /[a-z_]/i,
7981 * The function used to validate alphanumeric values
7982 * @param {String} value The value
7984 'alphanum' : function(v){
7985 return alphanum.test(v);
7988 * The error text to display when the alphanumeric validation function returns false
7991 'alphanumText' : 'This field should only contain letters, numbers and _',
7993 * The keystroke filter mask to be applied on alphanumeric input
7996 'alphanumMask' : /[a-z0-9_]/i
8006 * @class Roo.bootstrap.Input
8007 * @extends Roo.bootstrap.Component
8008 * Bootstrap Input class
8009 * @cfg {Boolean} disabled is it disabled
8010 * @cfg {String} inputType button | checkbox | email | file | hidden | image | number | password | radio | range | reset | search | submit | text
8011 * @cfg {String} name name of the input
8012 * @cfg {string} fieldLabel - the label associated
8013 * @cfg {string} placeholder - placeholder to put in text.
8014 * @cfg {string} before - input group add on before
8015 * @cfg {string} after - input group add on after
8016 * @cfg {string} size - (lg|sm) or leave empty..
8017 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
8018 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
8019 * @cfg {Number} md colspan out of 12 for computer-sized screens
8020 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
8021 * @cfg {string} value default value of the input
8022 * @cfg {Number} labelWidth set the width of label (0-12)
8023 * @cfg {String} labelAlign (top|left)
8024 * @cfg {Boolean} readOnly Specifies that the field should be read-only
8025 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
8026 * @cfg {String} indicatorpos (left|right) default left
8028 * @cfg {String} align (left|center|right) Default left
8029 * @cfg {Boolean} forceFeedback (true|false) Default false
8035 * Create a new Input
8036 * @param {Object} config The config object
8039 Roo.bootstrap.Input = function(config){
8040 Roo.bootstrap.Input.superclass.constructor.call(this, config);
8045 * Fires when this field receives input focus.
8046 * @param {Roo.form.Field} this
8051 * Fires when this field loses input focus.
8052 * @param {Roo.form.Field} this
8057 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
8058 * {@link Roo.EventObject#getKey} to determine which key was pressed.
8059 * @param {Roo.form.Field} this
8060 * @param {Roo.EventObject} e The event object
8065 * Fires just before the field blurs if the field value has changed.
8066 * @param {Roo.form.Field} this
8067 * @param {Mixed} newValue The new value
8068 * @param {Mixed} oldValue The original value
8073 * Fires after the field has been marked as invalid.
8074 * @param {Roo.form.Field} this
8075 * @param {String} msg The validation message
8080 * Fires after the field has been validated with no errors.
8081 * @param {Roo.form.Field} this
8086 * Fires after the key up
8087 * @param {Roo.form.Field} this
8088 * @param {Roo.EventObject} e The event Object
8094 Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component, {
8096 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
8097 automatic validation (defaults to "keyup").
8099 validationEvent : "keyup",
8101 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
8103 validateOnBlur : true,
8105 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
8107 validationDelay : 250,
8109 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
8111 focusClass : "x-form-focus", // not needed???
8115 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
8117 invalidClass : "has-warning",
8120 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
8122 validClass : "has-success",
8125 * @cfg {Boolean} hasFeedback (true|false) default true
8130 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8132 invalidFeedbackClass : "glyphicon-warning-sign",
8135 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8137 validFeedbackClass : "glyphicon-ok",
8140 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
8142 selectOnFocus : false,
8145 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
8149 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
8154 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
8156 disableKeyFilter : false,
8159 * @cfg {Boolean} disabled True to disable the field (defaults to false).
8163 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
8167 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
8169 blankText : "This field is required",
8172 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
8176 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
8178 maxLength : Number.MAX_VALUE,
8180 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
8182 minLengthText : "The minimum length for this field is {0}",
8184 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
8186 maxLengthText : "The maximum length for this field is {0}",
8190 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
8191 * If available, this function will be called only after the basic validators all return true, and will be passed the
8192 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
8196 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
8197 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
8198 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
8202 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
8206 autocomplete: false,
8225 formatedValue : false,
8226 forceFeedback : false,
8228 indicatorpos : 'left',
8230 parentLabelAlign : function()
8233 while (parent.parent()) {
8234 parent = parent.parent();
8235 if (typeof(parent.labelAlign) !='undefined') {
8236 return parent.labelAlign;
8243 getAutoCreate : function()
8245 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8251 if(this.inputType != 'hidden'){
8252 cfg.cls = 'form-group' //input-group
8258 type : this.inputType,
8260 cls : 'form-control',
8261 placeholder : this.placeholder || '',
8262 autocomplete : this.autocomplete || 'new-password'
8266 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
8269 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
8270 input.maxLength = this.maxLength;
8273 if (this.disabled) {
8274 input.disabled=true;
8277 if (this.readOnly) {
8278 input.readonly=true;
8282 input.name = this.name;
8286 input.cls += ' input-' + this.size;
8290 ['xs','sm','md','lg'].map(function(size){
8291 if (settings[size]) {
8292 cfg.cls += ' col-' + size + '-' + settings[size];
8296 var inputblock = input;
8300 cls: 'glyphicon form-control-feedback'
8303 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8306 cls : 'has-feedback',
8314 if (this.before || this.after) {
8317 cls : 'input-group',
8321 if (this.before && typeof(this.before) == 'string') {
8323 inputblock.cn.push({
8325 cls : 'roo-input-before input-group-addon',
8329 if (this.before && typeof(this.before) == 'object') {
8330 this.before = Roo.factory(this.before);
8332 inputblock.cn.push({
8334 cls : 'roo-input-before input-group-' +
8335 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8339 inputblock.cn.push(input);
8341 if (this.after && typeof(this.after) == 'string') {
8342 inputblock.cn.push({
8344 cls : 'roo-input-after input-group-addon',
8348 if (this.after && typeof(this.after) == 'object') {
8349 this.after = Roo.factory(this.after);
8351 inputblock.cn.push({
8353 cls : 'roo-input-after input-group-' +
8354 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8358 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8359 inputblock.cls += ' has-feedback';
8360 inputblock.cn.push(feedback);
8364 if (align ==='left' && this.fieldLabel.length) {
8369 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
8370 tooltip : 'This field is required'
8375 cls : 'control-label col-sm-' + this.labelWidth,
8376 html : this.fieldLabel
8380 cls : "col-sm-" + (12 - this.labelWidth),
8388 if(this.indicatorpos == 'right'){
8393 cls : 'control-label col-sm-' + this.labelWidth,
8394 html : this.fieldLabel
8399 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
8400 tooltip : 'This field is required'
8403 cls : "col-sm-" + (12 - this.labelWidth),
8412 } else if ( this.fieldLabel.length) {
8417 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
8418 tooltip : 'This field is required'
8422 //cls : 'input-group-addon',
8423 html : this.fieldLabel
8431 if(this.indicatorpos == 'right'){
8436 //cls : 'input-group-addon',
8437 html : this.fieldLabel
8442 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
8443 tooltip : 'This field is required'
8463 if (this.parentType === 'Navbar' && this.parent().bar) {
8464 cfg.cls += ' navbar-form';
8467 if (this.parentType === 'NavGroup') {
8468 cfg.cls += ' navbar-form';
8476 * return the real input element.
8478 inputEl: function ()
8480 return this.el.select('input.form-control',true).first();
8483 tooltipEl : function()
8485 return this.inputEl();
8488 indicatorEl : function()
8490 var indicator = this.el.select('i.roo-required-indicator',true).first();
8500 setDisabled : function(v)
8502 var i = this.inputEl().dom;
8504 i.removeAttribute('disabled');
8508 i.setAttribute('disabled','true');
8510 initEvents : function()
8513 this.inputEl().on("keydown" , this.fireKey, this);
8514 this.inputEl().on("focus", this.onFocus, this);
8515 this.inputEl().on("blur", this.onBlur, this);
8517 this.inputEl().relayEvent('keyup', this);
8519 this.indicator = this.indicatorEl();
8522 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
8523 this.indicator.hide();
8526 // reference to original value for reset
8527 this.originalValue = this.getValue();
8528 //Roo.form.TextField.superclass.initEvents.call(this);
8529 if(this.validationEvent == 'keyup'){
8530 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
8531 this.inputEl().on('keyup', this.filterValidation, this);
8533 else if(this.validationEvent !== false){
8534 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
8537 if(this.selectOnFocus){
8538 this.on("focus", this.preFocus, this);
8541 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
8542 this.inputEl().on("keypress", this.filterKeys, this);
8544 this.inputEl().relayEvent('keypress', this);
8547 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
8548 this.el.on("click", this.autoSize, this);
8551 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
8552 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
8555 if (typeof(this.before) == 'object') {
8556 this.before.render(this.el.select('.roo-input-before',true).first());
8558 if (typeof(this.after) == 'object') {
8559 this.after.render(this.el.select('.roo-input-after',true).first());
8564 filterValidation : function(e){
8565 if(!e.isNavKeyPress()){
8566 this.validationTask.delay(this.validationDelay);
8570 * Validates the field value
8571 * @return {Boolean} True if the value is valid, else false
8573 validate : function(){
8574 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
8575 if(this.disabled || this.validateValue(this.getRawValue())){
8586 * Validates a value according to the field's validation rules and marks the field as invalid
8587 * if the validation fails
8588 * @param {Mixed} value The value to validate
8589 * @return {Boolean} True if the value is valid, else false
8591 validateValue : function(value){
8592 if(value.length < 1) { // if it's blank
8593 if(this.allowBlank){
8599 if(value.length < this.minLength){
8602 if(value.length > this.maxLength){
8606 var vt = Roo.form.VTypes;
8607 if(!vt[this.vtype](value, this)){
8611 if(typeof this.validator == "function"){
8612 var msg = this.validator(value);
8618 if(this.regex && !this.regex.test(value)){
8628 fireKey : function(e){
8629 //Roo.log('field ' + e.getKey());
8630 if(e.isNavKeyPress()){
8631 this.fireEvent("specialkey", this, e);
8634 focus : function (selectText){
8636 this.inputEl().focus();
8637 if(selectText === true){
8638 this.inputEl().dom.select();
8644 onFocus : function(){
8645 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
8646 // this.el.addClass(this.focusClass);
8649 this.hasFocus = true;
8650 this.startValue = this.getValue();
8651 this.fireEvent("focus", this);
8655 beforeBlur : Roo.emptyFn,
8659 onBlur : function(){
8661 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
8662 //this.el.removeClass(this.focusClass);
8664 this.hasFocus = false;
8665 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
8668 var v = this.getValue();
8669 if(String(v) !== String(this.startValue)){
8670 this.fireEvent('change', this, v, this.startValue);
8672 this.fireEvent("blur", this);
8676 * Resets the current field value to the originally loaded value and clears any validation messages
8679 this.setValue(this.originalValue);
8683 * Returns the name of the field
8684 * @return {Mixed} name The name field
8686 getName: function(){
8690 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
8691 * @return {Mixed} value The field value
8693 getValue : function(){
8695 var v = this.inputEl().getValue();
8700 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
8701 * @return {Mixed} value The field value
8703 getRawValue : function(){
8704 var v = this.inputEl().getValue();
8710 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
8711 * @param {Mixed} value The value to set
8713 setRawValue : function(v){
8714 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
8717 selectText : function(start, end){
8718 var v = this.getRawValue();
8720 start = start === undefined ? 0 : start;
8721 end = end === undefined ? v.length : end;
8722 var d = this.inputEl().dom;
8723 if(d.setSelectionRange){
8724 d.setSelectionRange(start, end);
8725 }else if(d.createTextRange){
8726 var range = d.createTextRange();
8727 range.moveStart("character", start);
8728 range.moveEnd("character", v.length-end);
8735 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
8736 * @param {Mixed} value The value to set
8738 setValue : function(v){
8741 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
8747 processValue : function(value){
8748 if(this.stripCharsRe){
8749 var newValue = value.replace(this.stripCharsRe, '');
8750 if(newValue !== value){
8751 this.setRawValue(newValue);
8758 preFocus : function(){
8760 if(this.selectOnFocus){
8761 this.inputEl().dom.select();
8764 filterKeys : function(e){
8766 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
8769 var c = e.getCharCode(), cc = String.fromCharCode(c);
8770 if(Roo.isIE && (e.isSpecialKey() || !cc)){
8773 if(!this.maskRe.test(cc)){
8778 * Clear any invalid styles/messages for this field
8780 clearInvalid : function(){
8782 if(!this.el || this.preventMark){ // not rendered
8787 this.indicator.hide();
8790 this.el.removeClass(this.invalidClass);
8792 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8794 var feedback = this.el.select('.form-control-feedback', true).first();
8797 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
8802 this.fireEvent('valid', this);
8806 * Mark this field as valid
8808 markValid : function()
8810 if(!this.el || this.preventMark){ // not rendered
8814 this.el.removeClass([this.invalidClass, this.validClass]);
8816 var feedback = this.el.select('.form-control-feedback', true).first();
8819 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
8822 if(this.disabled || this.allowBlank){
8827 this.indicator.hide();
8830 this.el.addClass(this.validClass);
8832 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
8834 var feedback = this.el.select('.form-control-feedback', true).first();
8837 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
8838 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
8843 this.fireEvent('valid', this);
8847 * Mark this field as invalid
8848 * @param {String} msg The validation message
8850 markInvalid : function(msg)
8852 if(!this.el || this.preventMark){ // not rendered
8856 this.el.removeClass([this.invalidClass, this.validClass]);
8858 var feedback = this.el.select('.form-control-feedback', true).first();
8861 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
8864 if(this.disabled || this.allowBlank){
8869 this.indicator.show();
8872 this.el.addClass(this.invalidClass);
8874 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8876 var feedback = this.el.select('.form-control-feedback', true).first();
8879 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
8881 if(this.getValue().length || this.forceFeedback){
8882 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
8889 this.fireEvent('invalid', this, msg);
8892 SafariOnKeyDown : function(event)
8894 // this is a workaround for a password hang bug on chrome/ webkit.
8896 var isSelectAll = false;
8898 if(this.inputEl().dom.selectionEnd > 0){
8899 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
8901 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
8902 event.preventDefault();
8907 if(isSelectAll && event.getCharCode() > 31){ // not backspace and delete key
8909 event.preventDefault();
8910 // this is very hacky as keydown always get's upper case.
8912 var cc = String.fromCharCode(event.getCharCode());
8913 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
8917 adjustWidth : function(tag, w){
8918 tag = tag.toLowerCase();
8919 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
8920 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
8924 if(tag == 'textarea'){
8927 }else if(Roo.isOpera){
8931 if(tag == 'textarea'){
8950 * @class Roo.bootstrap.TextArea
8951 * @extends Roo.bootstrap.Input
8952 * Bootstrap TextArea class
8953 * @cfg {Number} cols Specifies the visible width of a text area
8954 * @cfg {Number} rows Specifies the visible number of lines in a text area
8955 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
8956 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
8957 * @cfg {string} html text
8960 * Create a new TextArea
8961 * @param {Object} config The config object
8964 Roo.bootstrap.TextArea = function(config){
8965 Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
8969 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input, {
8979 getAutoCreate : function(){
8981 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8992 value : this.value || '',
8993 html: this.html || '',
8994 cls : 'form-control',
8995 placeholder : this.placeholder || ''
8999 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
9000 input.maxLength = this.maxLength;
9004 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
9008 input.cols = this.cols;
9011 if (this.readOnly) {
9012 input.readonly = true;
9016 input.name = this.name;
9020 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
9024 ['xs','sm','md','lg'].map(function(size){
9025 if (settings[size]) {
9026 cfg.cls += ' col-' + size + '-' + settings[size];
9030 var inputblock = input;
9032 if(this.hasFeedback && !this.allowBlank){
9036 cls: 'glyphicon form-control-feedback'
9040 cls : 'has-feedback',
9049 if (this.before || this.after) {
9052 cls : 'input-group',
9056 inputblock.cn.push({
9058 cls : 'input-group-addon',
9063 inputblock.cn.push(input);
9065 if(this.hasFeedback && !this.allowBlank){
9066 inputblock.cls += ' has-feedback';
9067 inputblock.cn.push(feedback);
9071 inputblock.cn.push({
9073 cls : 'input-group-addon',
9080 if (align ==='left' && this.fieldLabel.length) {
9081 // Roo.log("left and has label");
9087 cls : 'control-label col-sm-' + this.labelWidth,
9088 html : this.fieldLabel
9092 cls : "col-sm-" + (12 - this.labelWidth),
9099 } else if ( this.fieldLabel.length) {
9100 // Roo.log(" label");
9105 //cls : 'input-group-addon',
9106 html : this.fieldLabel
9116 // Roo.log(" no label && no align");
9126 if (this.disabled) {
9127 input.disabled=true;
9134 * return the real textarea element.
9136 inputEl: function ()
9138 return this.el.select('textarea.form-control',true).first();
9142 * Clear any invalid styles/messages for this field
9144 clearInvalid : function()
9147 if(!this.el || this.preventMark){ // not rendered
9151 var label = this.el.select('label', true).first();
9152 var icon = this.el.select('i.fa-star', true).first();
9158 this.el.removeClass(this.invalidClass);
9160 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9162 var feedback = this.el.select('.form-control-feedback', true).first();
9165 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9170 this.fireEvent('valid', this);
9174 * Mark this field as valid
9176 markValid : function()
9178 if(!this.el || this.preventMark){ // not rendered
9182 this.el.removeClass([this.invalidClass, this.validClass]);
9184 var feedback = this.el.select('.form-control-feedback', true).first();
9187 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9190 if(this.disabled || this.allowBlank){
9194 var label = this.el.select('label', true).first();
9195 var icon = this.el.select('i.fa-star', true).first();
9201 this.el.addClass(this.validClass);
9203 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9205 var feedback = this.el.select('.form-control-feedback', true).first();
9208 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9209 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9214 this.fireEvent('valid', this);
9218 * Mark this field as invalid
9219 * @param {String} msg The validation message
9221 markInvalid : function(msg)
9223 if(!this.el || this.preventMark){ // not rendered
9227 this.el.removeClass([this.invalidClass, this.validClass]);
9229 var feedback = this.el.select('.form-control-feedback', true).first();
9232 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9235 if(this.disabled || this.allowBlank){
9239 var label = this.el.select('label', true).first();
9240 var icon = this.el.select('i.fa-star', true).first();
9242 if(!this.getValue().length && label && !icon){
9243 this.el.createChild({
9245 cls : 'text-danger fa fa-lg fa-star',
9246 tooltip : 'This field is required',
9247 style : 'margin-right:5px;'
9251 this.el.addClass(this.invalidClass);
9253 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9255 var feedback = this.el.select('.form-control-feedback', true).first();
9258 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9260 if(this.getValue().length || this.forceFeedback){
9261 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9268 this.fireEvent('invalid', this, msg);
9276 * trigger field - base class for combo..
9281 * @class Roo.bootstrap.TriggerField
9282 * @extends Roo.bootstrap.Input
9283 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
9284 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
9285 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
9286 * for which you can provide a custom implementation. For example:
9288 var trigger = new Roo.bootstrap.TriggerField();
9289 trigger.onTriggerClick = myTriggerFn;
9290 trigger.applyTo('my-field');
9293 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
9294 * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
9295 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
9296 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
9297 * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
9300 * Create a new TriggerField.
9301 * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
9302 * to the base TextField)
9304 Roo.bootstrap.TriggerField = function(config){
9305 this.mimicing = false;
9306 Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
9309 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input, {
9311 * @cfg {String} triggerClass A CSS class to apply to the trigger
9314 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
9319 * @cfg {Boolean} removable (true|false) special filter default false
9323 /** @cfg {Boolean} grow @hide */
9324 /** @cfg {Number} growMin @hide */
9325 /** @cfg {Number} growMax @hide */
9331 autoSize: Roo.emptyFn,
9338 actionMode : 'wrap',
9343 getAutoCreate : function(){
9345 var align = this.labelAlign || this.parentLabelAlign();
9350 cls: 'form-group' //input-group
9357 type : this.inputType,
9358 cls : 'form-control',
9359 autocomplete: 'new-password',
9360 placeholder : this.placeholder || ''
9364 input.name = this.name;
9367 input.cls += ' input-' + this.size;
9370 if (this.disabled) {
9371 input.disabled=true;
9374 var inputblock = input;
9376 if(this.hasFeedback && !this.allowBlank){
9380 cls: 'glyphicon form-control-feedback'
9383 if(this.removable && !this.editable && !this.tickable){
9385 cls : 'has-feedback',
9391 cls : 'roo-combo-removable-btn close'
9398 cls : 'has-feedback',
9407 if(this.removable && !this.editable && !this.tickable){
9409 cls : 'roo-removable',
9415 cls : 'roo-combo-removable-btn close'
9422 if (this.before || this.after) {
9425 cls : 'input-group',
9429 inputblock.cn.push({
9431 cls : 'input-group-addon',
9436 inputblock.cn.push(input);
9438 if(this.hasFeedback && !this.allowBlank){
9439 inputblock.cls += ' has-feedback';
9440 inputblock.cn.push(feedback);
9444 inputblock.cn.push({
9446 cls : 'input-group-addon',
9459 cls: 'form-hidden-field'
9473 cls: 'form-hidden-field'
9477 cls: 'roo-select2-choices',
9481 cls: 'roo-select2-search-field',
9494 cls: 'roo-select2-container input-group',
9499 // cls: 'typeahead typeahead-long dropdown-menu',
9500 // style: 'display:none'
9505 if(!this.multiple && this.showToggleBtn){
9511 if (this.caret != false) {
9514 cls: 'fa fa-' + this.caret
9521 cls : 'input-group-addon btn dropdown-toggle',
9526 cls: 'combobox-clear',
9540 combobox.cls += ' roo-select2-container-multi';
9543 if (align ==='left' && this.fieldLabel.length && this.labelWidth) {
9545 // Roo.log("left and has label");
9549 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9550 tooltip : 'This field is required'
9555 cls : 'control-label col-sm-' + this.labelWidth,
9556 html : this.fieldLabel
9560 cls : "col-sm-" + (12 - this.labelWidth),
9568 if(this.indicatorpos == 'right'){
9573 cls : 'control-label col-sm-' + this.labelWidth,
9574 html : this.fieldLabel
9579 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9580 tooltip : 'This field is required'
9583 cls : "col-sm-" + (12 - this.labelWidth),
9592 } else if ( this.fieldLabel.length) {
9593 // Roo.log(" label");
9597 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9598 tooltip : 'This field is required'
9602 //cls : 'input-group-addon',
9603 html : this.fieldLabel
9611 if(this.indicatorpos == 'right'){
9616 //cls : 'input-group-addon',
9617 html : this.fieldLabel
9622 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9623 tooltip : 'This field is required'
9634 // Roo.log(" no label && no align");
9641 ['xs','sm','md','lg'].map(function(size){
9642 if (settings[size]) {
9643 cfg.cls += ' col-' + size + '-' + settings[size];
9654 onResize : function(w, h){
9655 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
9656 // if(typeof w == 'number'){
9657 // var x = w - this.trigger.getWidth();
9658 // this.inputEl().setWidth(this.adjustWidth('input', x));
9659 // this.trigger.setStyle('left', x+'px');
9664 adjustSize : Roo.BoxComponent.prototype.adjustSize,
9667 getResizeEl : function(){
9668 return this.inputEl();
9672 getPositionEl : function(){
9673 return this.inputEl();
9677 alignErrorIcon : function(){
9678 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
9682 initEvents : function(){
9686 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
9687 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
9688 if(!this.multiple && this.showToggleBtn){
9689 this.trigger = this.el.select('span.dropdown-toggle',true).first();
9690 if(this.hideTrigger){
9691 this.trigger.setDisplayed(false);
9693 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
9697 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
9700 if(this.removable && !this.editable && !this.tickable){
9701 var close = this.closeTriggerEl();
9704 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
9705 close.on('click', this.removeBtnClick, this, close);
9709 //this.trigger.addClassOnOver('x-form-trigger-over');
9710 //this.trigger.addClassOnClick('x-form-trigger-click');
9713 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
9717 closeTriggerEl : function()
9719 var close = this.el.select('.roo-combo-removable-btn', true).first();
9720 return close ? close : false;
9723 removeBtnClick : function(e, h, el)
9727 if(this.fireEvent("remove", this) !== false){
9729 this.fireEvent("afterremove", this)
9733 createList : function()
9735 this.list = Roo.get(document.body).createChild({
9737 cls: 'typeahead typeahead-long dropdown-menu',
9738 style: 'display:none'
9741 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
9746 initTrigger : function(){
9751 onDestroy : function(){
9753 this.trigger.removeAllListeners();
9754 // this.trigger.remove();
9757 // this.wrap.remove();
9759 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
9763 onFocus : function(){
9764 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
9767 this.wrap.addClass('x-trigger-wrap-focus');
9768 this.mimicing = true;
9769 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
9770 if(this.monitorTab){
9771 this.el.on("keydown", this.checkTab, this);
9778 checkTab : function(e){
9779 if(e.getKey() == e.TAB){
9785 onBlur : function(){
9790 mimicBlur : function(e, t){
9792 if(!this.wrap.contains(t) && this.validateBlur()){
9799 triggerBlur : function(){
9800 this.mimicing = false;
9801 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
9802 if(this.monitorTab){
9803 this.el.un("keydown", this.checkTab, this);
9805 //this.wrap.removeClass('x-trigger-wrap-focus');
9806 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
9810 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
9811 validateBlur : function(e, t){
9816 onDisable : function(){
9817 this.inputEl().dom.disabled = true;
9818 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
9820 // this.wrap.addClass('x-item-disabled');
9825 onEnable : function(){
9826 this.inputEl().dom.disabled = false;
9827 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
9829 // this.el.removeClass('x-item-disabled');
9834 onShow : function(){
9835 var ae = this.getActionEl();
9838 ae.dom.style.display = '';
9839 ae.dom.style.visibility = 'visible';
9845 onHide : function(){
9846 var ae = this.getActionEl();
9847 ae.dom.style.display = 'none';
9851 * The function that should handle the trigger's click event. This method does nothing by default until overridden
9852 * by an implementing function.
9854 * @param {EventObject} e
9856 onTriggerClick : Roo.emptyFn
9860 * Ext JS Library 1.1.1
9861 * Copyright(c) 2006-2007, Ext JS, LLC.
9863 * Originally Released Under LGPL - original licence link has changed is not relivant.
9866 * <script type="text/javascript">
9871 * @class Roo.data.SortTypes
9873 * Defines the default sorting (casting?) comparison functions used when sorting data.
9875 Roo.data.SortTypes = {
9877 * Default sort that does nothing
9878 * @param {Mixed} s The value being converted
9879 * @return {Mixed} The comparison value
9886 * The regular expression used to strip tags
9890 stripTagsRE : /<\/?[^>]+>/gi,
9893 * Strips all HTML tags to sort on text only
9894 * @param {Mixed} s The value being converted
9895 * @return {String} The comparison value
9897 asText : function(s){
9898 return String(s).replace(this.stripTagsRE, "");
9902 * Strips all HTML tags to sort on text only - Case insensitive
9903 * @param {Mixed} s The value being converted
9904 * @return {String} The comparison value
9906 asUCText : function(s){
9907 return String(s).toUpperCase().replace(this.stripTagsRE, "");
9911 * Case insensitive string
9912 * @param {Mixed} s The value being converted
9913 * @return {String} The comparison value
9915 asUCString : function(s) {
9916 return String(s).toUpperCase();
9921 * @param {Mixed} s The value being converted
9922 * @return {Number} The comparison value
9924 asDate : function(s) {
9928 if(s instanceof Date){
9931 return Date.parse(String(s));
9936 * @param {Mixed} s The value being converted
9937 * @return {Float} The comparison value
9939 asFloat : function(s) {
9940 var val = parseFloat(String(s).replace(/,/g, ""));
9949 * @param {Mixed} s The value being converted
9950 * @return {Number} The comparison value
9952 asInt : function(s) {
9953 var val = parseInt(String(s).replace(/,/g, ""));
9961 * Ext JS Library 1.1.1
9962 * Copyright(c) 2006-2007, Ext JS, LLC.
9964 * Originally Released Under LGPL - original licence link has changed is not relivant.
9967 * <script type="text/javascript">
9971 * @class Roo.data.Record
9972 * Instances of this class encapsulate both record <em>definition</em> information, and record
9973 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
9974 * to access Records cached in an {@link Roo.data.Store} object.<br>
9976 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
9977 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
9980 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
9982 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
9983 * {@link #create}. The parameters are the same.
9984 * @param {Array} data An associative Array of data values keyed by the field name.
9985 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
9986 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
9987 * not specified an integer id is generated.
9989 Roo.data.Record = function(data, id){
9990 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
9995 * Generate a constructor for a specific record layout.
9996 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
9997 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
9998 * Each field definition object may contain the following properties: <ul>
9999 * <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,
10000 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
10001 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
10002 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
10003 * is being used, then this is a string containing the javascript expression to reference the data relative to
10004 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
10005 * to the data item relative to the record element. If the mapping expression is the same as the field name,
10006 * this may be omitted.</p></li>
10007 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
10008 * <ul><li>auto (Default, implies no conversion)</li>
10013 * <li>date</li></ul></p></li>
10014 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
10015 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
10016 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
10017 * by the Reader into an object that will be stored in the Record. It is passed the
10018 * following parameters:<ul>
10019 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
10021 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
10023 * <br>usage:<br><pre><code>
10024 var TopicRecord = Roo.data.Record.create(
10025 {name: 'title', mapping: 'topic_title'},
10026 {name: 'author', mapping: 'username'},
10027 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
10028 {name: 'lastPost', mapping: 'post_time', type: 'date'},
10029 {name: 'lastPoster', mapping: 'user2'},
10030 {name: 'excerpt', mapping: 'post_text'}
10033 var myNewRecord = new TopicRecord({
10034 title: 'Do my job please',
10037 lastPost: new Date(),
10038 lastPoster: 'Animal',
10039 excerpt: 'No way dude!'
10041 myStore.add(myNewRecord);
10046 Roo.data.Record.create = function(o){
10047 var f = function(){
10048 f.superclass.constructor.apply(this, arguments);
10050 Roo.extend(f, Roo.data.Record);
10051 var p = f.prototype;
10052 p.fields = new Roo.util.MixedCollection(false, function(field){
10055 for(var i = 0, len = o.length; i < len; i++){
10056 p.fields.add(new Roo.data.Field(o[i]));
10058 f.getField = function(name){
10059 return p.fields.get(name);
10064 Roo.data.Record.AUTO_ID = 1000;
10065 Roo.data.Record.EDIT = 'edit';
10066 Roo.data.Record.REJECT = 'reject';
10067 Roo.data.Record.COMMIT = 'commit';
10069 Roo.data.Record.prototype = {
10071 * Readonly flag - true if this record has been modified.
10080 join : function(store){
10081 this.store = store;
10085 * Set the named field to the specified value.
10086 * @param {String} name The name of the field to set.
10087 * @param {Object} value The value to set the field to.
10089 set : function(name, value){
10090 if(this.data[name] == value){
10094 if(!this.modified){
10095 this.modified = {};
10097 if(typeof this.modified[name] == 'undefined'){
10098 this.modified[name] = this.data[name];
10100 this.data[name] = value;
10101 if(!this.editing && this.store){
10102 this.store.afterEdit(this);
10107 * Get the value of the named field.
10108 * @param {String} name The name of the field to get the value of.
10109 * @return {Object} The value of the field.
10111 get : function(name){
10112 return this.data[name];
10116 beginEdit : function(){
10117 this.editing = true;
10118 this.modified = {};
10122 cancelEdit : function(){
10123 this.editing = false;
10124 delete this.modified;
10128 endEdit : function(){
10129 this.editing = false;
10130 if(this.dirty && this.store){
10131 this.store.afterEdit(this);
10136 * Usually called by the {@link Roo.data.Store} which owns the Record.
10137 * Rejects all changes made to the Record since either creation, or the last commit operation.
10138 * Modified fields are reverted to their original values.
10140 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10141 * of reject operations.
10143 reject : function(){
10144 var m = this.modified;
10146 if(typeof m[n] != "function"){
10147 this.data[n] = m[n];
10150 this.dirty = false;
10151 delete this.modified;
10152 this.editing = false;
10154 this.store.afterReject(this);
10159 * Usually called by the {@link Roo.data.Store} which owns the Record.
10160 * Commits all changes made to the Record since either creation, or the last commit operation.
10162 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10163 * of commit operations.
10165 commit : function(){
10166 this.dirty = false;
10167 delete this.modified;
10168 this.editing = false;
10170 this.store.afterCommit(this);
10175 hasError : function(){
10176 return this.error != null;
10180 clearError : function(){
10185 * Creates a copy of this record.
10186 * @param {String} id (optional) A new record id if you don't want to use this record's id
10189 copy : function(newId) {
10190 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
10194 * Ext JS Library 1.1.1
10195 * Copyright(c) 2006-2007, Ext JS, LLC.
10197 * Originally Released Under LGPL - original licence link has changed is not relivant.
10200 * <script type="text/javascript">
10206 * @class Roo.data.Store
10207 * @extends Roo.util.Observable
10208 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
10209 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
10211 * 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
10212 * has no knowledge of the format of the data returned by the Proxy.<br>
10214 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
10215 * instances from the data object. These records are cached and made available through accessor functions.
10217 * Creates a new Store.
10218 * @param {Object} config A config object containing the objects needed for the Store to access data,
10219 * and read the data into Records.
10221 Roo.data.Store = function(config){
10222 this.data = new Roo.util.MixedCollection(false);
10223 this.data.getKey = function(o){
10226 this.baseParams = {};
10228 this.paramNames = {
10233 "multisort" : "_multisort"
10236 if(config && config.data){
10237 this.inlineData = config.data;
10238 delete config.data;
10241 Roo.apply(this, config);
10243 if(this.reader){ // reader passed
10244 this.reader = Roo.factory(this.reader, Roo.data);
10245 this.reader.xmodule = this.xmodule || false;
10246 if(!this.recordType){
10247 this.recordType = this.reader.recordType;
10249 if(this.reader.onMetaChange){
10250 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
10254 if(this.recordType){
10255 this.fields = this.recordType.prototype.fields;
10257 this.modified = [];
10261 * @event datachanged
10262 * Fires when the data cache has changed, and a widget which is using this Store
10263 * as a Record cache should refresh its view.
10264 * @param {Store} this
10266 datachanged : true,
10268 * @event metachange
10269 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
10270 * @param {Store} this
10271 * @param {Object} meta The JSON metadata
10276 * Fires when Records have been added to the Store
10277 * @param {Store} this
10278 * @param {Roo.data.Record[]} records The array of Records added
10279 * @param {Number} index The index at which the record(s) were added
10284 * Fires when a Record has been removed from the Store
10285 * @param {Store} this
10286 * @param {Roo.data.Record} record The Record that was removed
10287 * @param {Number} index The index at which the record was removed
10292 * Fires when a Record has been updated
10293 * @param {Store} this
10294 * @param {Roo.data.Record} record The Record that was updated
10295 * @param {String} operation The update operation being performed. Value may be one of:
10297 Roo.data.Record.EDIT
10298 Roo.data.Record.REJECT
10299 Roo.data.Record.COMMIT
10305 * Fires when the data cache has been cleared.
10306 * @param {Store} this
10310 * @event beforeload
10311 * Fires before a request is made for a new data object. If the beforeload handler returns false
10312 * the load action will be canceled.
10313 * @param {Store} this
10314 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10318 * @event beforeloadadd
10319 * Fires after a new set of Records has been loaded.
10320 * @param {Store} this
10321 * @param {Roo.data.Record[]} records The Records that were loaded
10322 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10324 beforeloadadd : true,
10327 * Fires after a new set of Records has been loaded, before they are added to the store.
10328 * @param {Store} this
10329 * @param {Roo.data.Record[]} records The Records that were loaded
10330 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10331 * @params {Object} return from reader
10335 * @event loadexception
10336 * Fires if an exception occurs in the Proxy during loading.
10337 * Called with the signature of the Proxy's "loadexception" event.
10338 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
10341 * @param {Object} return from JsonData.reader() - success, totalRecords, records
10342 * @param {Object} load options
10343 * @param {Object} jsonData from your request (normally this contains the Exception)
10345 loadexception : true
10349 this.proxy = Roo.factory(this.proxy, Roo.data);
10350 this.proxy.xmodule = this.xmodule || false;
10351 this.relayEvents(this.proxy, ["loadexception"]);
10353 this.sortToggle = {};
10354 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
10356 Roo.data.Store.superclass.constructor.call(this);
10358 if(this.inlineData){
10359 this.loadData(this.inlineData);
10360 delete this.inlineData;
10364 Roo.extend(Roo.data.Store, Roo.util.Observable, {
10366 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
10367 * without a remote query - used by combo/forms at present.
10371 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
10374 * @cfg {Array} data Inline data to be loaded when the store is initialized.
10377 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
10378 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
10381 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
10382 * on any HTTP request
10385 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
10388 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
10392 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
10393 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
10395 remoteSort : false,
10398 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
10399 * loaded or when a record is removed. (defaults to false).
10401 pruneModifiedRecords : false,
10404 lastOptions : null,
10407 * Add Records to the Store and fires the add event.
10408 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
10410 add : function(records){
10411 records = [].concat(records);
10412 for(var i = 0, len = records.length; i < len; i++){
10413 records[i].join(this);
10415 var index = this.data.length;
10416 this.data.addAll(records);
10417 this.fireEvent("add", this, records, index);
10421 * Remove a Record from the Store and fires the remove event.
10422 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
10424 remove : function(record){
10425 var index = this.data.indexOf(record);
10426 this.data.removeAt(index);
10427 if(this.pruneModifiedRecords){
10428 this.modified.remove(record);
10430 this.fireEvent("remove", this, record, index);
10434 * Remove all Records from the Store and fires the clear event.
10436 removeAll : function(){
10438 if(this.pruneModifiedRecords){
10439 this.modified = [];
10441 this.fireEvent("clear", this);
10445 * Inserts Records to the Store at the given index and fires the add event.
10446 * @param {Number} index The start index at which to insert the passed Records.
10447 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
10449 insert : function(index, records){
10450 records = [].concat(records);
10451 for(var i = 0, len = records.length; i < len; i++){
10452 this.data.insert(index, records[i]);
10453 records[i].join(this);
10455 this.fireEvent("add", this, records, index);
10459 * Get the index within the cache of the passed Record.
10460 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
10461 * @return {Number} The index of the passed Record. Returns -1 if not found.
10463 indexOf : function(record){
10464 return this.data.indexOf(record);
10468 * Get the index within the cache of the Record with the passed id.
10469 * @param {String} id The id of the Record to find.
10470 * @return {Number} The index of the Record. Returns -1 if not found.
10472 indexOfId : function(id){
10473 return this.data.indexOfKey(id);
10477 * Get the Record with the specified id.
10478 * @param {String} id The id of the Record to find.
10479 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
10481 getById : function(id){
10482 return this.data.key(id);
10486 * Get the Record at the specified index.
10487 * @param {Number} index The index of the Record to find.
10488 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
10490 getAt : function(index){
10491 return this.data.itemAt(index);
10495 * Returns a range of Records between specified indices.
10496 * @param {Number} startIndex (optional) The starting index (defaults to 0)
10497 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
10498 * @return {Roo.data.Record[]} An array of Records
10500 getRange : function(start, end){
10501 return this.data.getRange(start, end);
10505 storeOptions : function(o){
10506 o = Roo.apply({}, o);
10509 this.lastOptions = o;
10513 * Loads the Record cache from the configured Proxy using the configured Reader.
10515 * If using remote paging, then the first load call must specify the <em>start</em>
10516 * and <em>limit</em> properties in the options.params property to establish the initial
10517 * position within the dataset, and the number of Records to cache on each read from the Proxy.
10519 * <strong>It is important to note that for remote data sources, loading is asynchronous,
10520 * and this call will return before the new data has been loaded. Perform any post-processing
10521 * in a callback function, or in a "load" event handler.</strong>
10523 * @param {Object} options An object containing properties which control loading options:<ul>
10524 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
10525 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
10526 * passed the following arguments:<ul>
10527 * <li>r : Roo.data.Record[]</li>
10528 * <li>options: Options object from the load call</li>
10529 * <li>success: Boolean success indicator</li></ul></li>
10530 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
10531 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
10534 load : function(options){
10535 options = options || {};
10536 if(this.fireEvent("beforeload", this, options) !== false){
10537 this.storeOptions(options);
10538 var p = Roo.apply(options.params || {}, this.baseParams);
10539 // if meta was not loaded from remote source.. try requesting it.
10540 if (!this.reader.metaFromRemote) {
10541 p._requestMeta = 1;
10543 if(this.sortInfo && this.remoteSort){
10544 var pn = this.paramNames;
10545 p[pn["sort"]] = this.sortInfo.field;
10546 p[pn["dir"]] = this.sortInfo.direction;
10548 if (this.multiSort) {
10549 var pn = this.paramNames;
10550 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
10553 this.proxy.load(p, this.reader, this.loadRecords, this, options);
10558 * Reloads the Record cache from the configured Proxy using the configured Reader and
10559 * the options from the last load operation performed.
10560 * @param {Object} options (optional) An object containing properties which may override the options
10561 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
10562 * the most recently used options are reused).
10564 reload : function(options){
10565 this.load(Roo.applyIf(options||{}, this.lastOptions));
10569 // Called as a callback by the Reader during a load operation.
10570 loadRecords : function(o, options, success){
10571 if(!o || success === false){
10572 if(success !== false){
10573 this.fireEvent("load", this, [], options, o);
10575 if(options.callback){
10576 options.callback.call(options.scope || this, [], options, false);
10580 // if data returned failure - throw an exception.
10581 if (o.success === false) {
10582 // show a message if no listener is registered.
10583 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
10584 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
10586 // loadmask wil be hooked into this..
10587 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
10590 var r = o.records, t = o.totalRecords || r.length;
10592 this.fireEvent("beforeloadadd", this, r, options, o);
10594 if(!options || options.add !== true){
10595 if(this.pruneModifiedRecords){
10596 this.modified = [];
10598 for(var i = 0, len = r.length; i < len; i++){
10602 this.data = this.snapshot;
10603 delete this.snapshot;
10606 this.data.addAll(r);
10607 this.totalLength = t;
10609 this.fireEvent("datachanged", this);
10611 this.totalLength = Math.max(t, this.data.length+r.length);
10614 this.fireEvent("load", this, r, options, o);
10615 if(options.callback){
10616 options.callback.call(options.scope || this, r, options, true);
10622 * Loads data from a passed data block. A Reader which understands the format of the data
10623 * must have been configured in the constructor.
10624 * @param {Object} data The data block from which to read the Records. The format of the data expected
10625 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
10626 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
10628 loadData : function(o, append){
10629 var r = this.reader.readRecords(o);
10630 this.loadRecords(r, {add: append}, true);
10634 * Gets the number of cached records.
10636 * <em>If using paging, this may not be the total size of the dataset. If the data object
10637 * used by the Reader contains the dataset size, then the getTotalCount() function returns
10638 * the data set size</em>
10640 getCount : function(){
10641 return this.data.length || 0;
10645 * Gets the total number of records in the dataset as returned by the server.
10647 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
10648 * the dataset size</em>
10650 getTotalCount : function(){
10651 return this.totalLength || 0;
10655 * Returns the sort state of the Store as an object with two properties:
10657 field {String} The name of the field by which the Records are sorted
10658 direction {String} The sort order, "ASC" or "DESC"
10661 getSortState : function(){
10662 return this.sortInfo;
10666 applySort : function(){
10667 if(this.sortInfo && !this.remoteSort){
10668 var s = this.sortInfo, f = s.field;
10669 var st = this.fields.get(f).sortType;
10670 var fn = function(r1, r2){
10671 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
10672 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
10674 this.data.sort(s.direction, fn);
10675 if(this.snapshot && this.snapshot != this.data){
10676 this.snapshot.sort(s.direction, fn);
10682 * Sets the default sort column and order to be used by the next load operation.
10683 * @param {String} fieldName The name of the field to sort by.
10684 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
10686 setDefaultSort : function(field, dir){
10687 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
10691 * Sort the Records.
10692 * If remote sorting is used, the sort is performed on the server, and the cache is
10693 * reloaded. If local sorting is used, the cache is sorted internally.
10694 * @param {String} fieldName The name of the field to sort by.
10695 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
10697 sort : function(fieldName, dir){
10698 var f = this.fields.get(fieldName);
10700 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
10702 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
10703 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
10708 this.sortToggle[f.name] = dir;
10709 this.sortInfo = {field: f.name, direction: dir};
10710 if(!this.remoteSort){
10712 this.fireEvent("datachanged", this);
10714 this.load(this.lastOptions);
10719 * Calls the specified function for each of the Records in the cache.
10720 * @param {Function} fn The function to call. The Record is passed as the first parameter.
10721 * Returning <em>false</em> aborts and exits the iteration.
10722 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
10724 each : function(fn, scope){
10725 this.data.each(fn, scope);
10729 * Gets all records modified since the last commit. Modified records are persisted across load operations
10730 * (e.g., during paging).
10731 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
10733 getModifiedRecords : function(){
10734 return this.modified;
10738 createFilterFn : function(property, value, anyMatch){
10739 if(!value.exec){ // not a regex
10740 value = String(value);
10741 if(value.length == 0){
10744 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
10746 return function(r){
10747 return value.test(r.data[property]);
10752 * Sums the value of <i>property</i> for each record between start and end and returns the result.
10753 * @param {String} property A field on your records
10754 * @param {Number} start The record index to start at (defaults to 0)
10755 * @param {Number} end The last record index to include (defaults to length - 1)
10756 * @return {Number} The sum
10758 sum : function(property, start, end){
10759 var rs = this.data.items, v = 0;
10760 start = start || 0;
10761 end = (end || end === 0) ? end : rs.length-1;
10763 for(var i = start; i <= end; i++){
10764 v += (rs[i].data[property] || 0);
10770 * Filter the records by a specified property.
10771 * @param {String} field A field on your records
10772 * @param {String/RegExp} value Either a string that the field
10773 * should start with or a RegExp to test against the field
10774 * @param {Boolean} anyMatch True to match any part not just the beginning
10776 filter : function(property, value, anyMatch){
10777 var fn = this.createFilterFn(property, value, anyMatch);
10778 return fn ? this.filterBy(fn) : this.clearFilter();
10782 * Filter by a function. The specified function will be called with each
10783 * record in this data source. If the function returns true the record is included,
10784 * otherwise it is filtered.
10785 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
10786 * @param {Object} scope (optional) The scope of the function (defaults to this)
10788 filterBy : function(fn, scope){
10789 this.snapshot = this.snapshot || this.data;
10790 this.data = this.queryBy(fn, scope||this);
10791 this.fireEvent("datachanged", this);
10795 * Query the records by a specified property.
10796 * @param {String} field A field on your records
10797 * @param {String/RegExp} value Either a string that the field
10798 * should start with or a RegExp to test against the field
10799 * @param {Boolean} anyMatch True to match any part not just the beginning
10800 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
10802 query : function(property, value, anyMatch){
10803 var fn = this.createFilterFn(property, value, anyMatch);
10804 return fn ? this.queryBy(fn) : this.data.clone();
10808 * Query by a function. The specified function will be called with each
10809 * record in this data source. If the function returns true the record is included
10811 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
10812 * @param {Object} scope (optional) The scope of the function (defaults to this)
10813 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
10815 queryBy : function(fn, scope){
10816 var data = this.snapshot || this.data;
10817 return data.filterBy(fn, scope||this);
10821 * Collects unique values for a particular dataIndex from this store.
10822 * @param {String} dataIndex The property to collect
10823 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
10824 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
10825 * @return {Array} An array of the unique values
10827 collect : function(dataIndex, allowNull, bypassFilter){
10828 var d = (bypassFilter === true && this.snapshot) ?
10829 this.snapshot.items : this.data.items;
10830 var v, sv, r = [], l = {};
10831 for(var i = 0, len = d.length; i < len; i++){
10832 v = d[i].data[dataIndex];
10834 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
10843 * Revert to a view of the Record cache with no filtering applied.
10844 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
10846 clearFilter : function(suppressEvent){
10847 if(this.snapshot && this.snapshot != this.data){
10848 this.data = this.snapshot;
10849 delete this.snapshot;
10850 if(suppressEvent !== true){
10851 this.fireEvent("datachanged", this);
10857 afterEdit : function(record){
10858 if(this.modified.indexOf(record) == -1){
10859 this.modified.push(record);
10861 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
10865 afterReject : function(record){
10866 this.modified.remove(record);
10867 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
10871 afterCommit : function(record){
10872 this.modified.remove(record);
10873 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
10877 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
10878 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
10880 commitChanges : function(){
10881 var m = this.modified.slice(0);
10882 this.modified = [];
10883 for(var i = 0, len = m.length; i < len; i++){
10889 * Cancel outstanding changes on all changed records.
10891 rejectChanges : function(){
10892 var m = this.modified.slice(0);
10893 this.modified = [];
10894 for(var i = 0, len = m.length; i < len; i++){
10899 onMetaChange : function(meta, rtype, o){
10900 this.recordType = rtype;
10901 this.fields = rtype.prototype.fields;
10902 delete this.snapshot;
10903 this.sortInfo = meta.sortInfo || this.sortInfo;
10904 this.modified = [];
10905 this.fireEvent('metachange', this, this.reader.meta);
10908 moveIndex : function(data, type)
10910 var index = this.indexOf(data);
10912 var newIndex = index + type;
10916 this.insert(newIndex, data);
10921 * Ext JS Library 1.1.1
10922 * Copyright(c) 2006-2007, Ext JS, LLC.
10924 * Originally Released Under LGPL - original licence link has changed is not relivant.
10927 * <script type="text/javascript">
10931 * @class Roo.data.SimpleStore
10932 * @extends Roo.data.Store
10933 * Small helper class to make creating Stores from Array data easier.
10934 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
10935 * @cfg {Array} fields An array of field definition objects, or field name strings.
10936 * @cfg {Array} data The multi-dimensional array of data
10938 * @param {Object} config
10940 Roo.data.SimpleStore = function(config){
10941 Roo.data.SimpleStore.superclass.constructor.call(this, {
10943 reader: new Roo.data.ArrayReader({
10946 Roo.data.Record.create(config.fields)
10948 proxy : new Roo.data.MemoryProxy(config.data)
10952 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
10954 * Ext JS Library 1.1.1
10955 * Copyright(c) 2006-2007, Ext JS, LLC.
10957 * Originally Released Under LGPL - original licence link has changed is not relivant.
10960 * <script type="text/javascript">
10965 * @extends Roo.data.Store
10966 * @class Roo.data.JsonStore
10967 * Small helper class to make creating Stores for JSON data easier. <br/>
10969 var store = new Roo.data.JsonStore({
10970 url: 'get-images.php',
10972 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
10975 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
10976 * JsonReader and HttpProxy (unless inline data is provided).</b>
10977 * @cfg {Array} fields An array of field definition objects, or field name strings.
10979 * @param {Object} config
10981 Roo.data.JsonStore = function(c){
10982 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
10983 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
10984 reader: new Roo.data.JsonReader(c, c.fields)
10987 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
10989 * Ext JS Library 1.1.1
10990 * Copyright(c) 2006-2007, Ext JS, LLC.
10992 * Originally Released Under LGPL - original licence link has changed is not relivant.
10995 * <script type="text/javascript">
10999 Roo.data.Field = function(config){
11000 if(typeof config == "string"){
11001 config = {name: config};
11003 Roo.apply(this, config);
11006 this.type = "auto";
11009 var st = Roo.data.SortTypes;
11010 // named sortTypes are supported, here we look them up
11011 if(typeof this.sortType == "string"){
11012 this.sortType = st[this.sortType];
11015 // set default sortType for strings and dates
11016 if(!this.sortType){
11019 this.sortType = st.asUCString;
11022 this.sortType = st.asDate;
11025 this.sortType = st.none;
11030 var stripRe = /[\$,%]/g;
11032 // prebuilt conversion function for this field, instead of
11033 // switching every time we're reading a value
11035 var cv, dateFormat = this.dateFormat;
11040 cv = function(v){ return v; };
11043 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
11047 return v !== undefined && v !== null && v !== '' ?
11048 parseInt(String(v).replace(stripRe, ""), 10) : '';
11053 return v !== undefined && v !== null && v !== '' ?
11054 parseFloat(String(v).replace(stripRe, ""), 10) : '';
11059 cv = function(v){ return v === true || v === "true" || v == 1; };
11066 if(v instanceof Date){
11070 if(dateFormat == "timestamp"){
11071 return new Date(v*1000);
11073 return Date.parseDate(v, dateFormat);
11075 var parsed = Date.parse(v);
11076 return parsed ? new Date(parsed) : null;
11085 Roo.data.Field.prototype = {
11093 * Ext JS Library 1.1.1
11094 * Copyright(c) 2006-2007, Ext JS, LLC.
11096 * Originally Released Under LGPL - original licence link has changed is not relivant.
11099 * <script type="text/javascript">
11102 // Base class for reading structured data from a data source. This class is intended to be
11103 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
11106 * @class Roo.data.DataReader
11107 * Base class for reading structured data from a data source. This class is intended to be
11108 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
11111 Roo.data.DataReader = function(meta, recordType){
11115 this.recordType = recordType instanceof Array ?
11116 Roo.data.Record.create(recordType) : recordType;
11119 Roo.data.DataReader.prototype = {
11121 * Create an empty record
11122 * @param {Object} data (optional) - overlay some values
11123 * @return {Roo.data.Record} record created.
11125 newRow : function(d) {
11127 this.recordType.prototype.fields.each(function(c) {
11129 case 'int' : da[c.name] = 0; break;
11130 case 'date' : da[c.name] = new Date(); break;
11131 case 'float' : da[c.name] = 0.0; break;
11132 case 'boolean' : da[c.name] = false; break;
11133 default : da[c.name] = ""; break;
11137 return new this.recordType(Roo.apply(da, d));
11142 * Ext JS Library 1.1.1
11143 * Copyright(c) 2006-2007, Ext JS, LLC.
11145 * Originally Released Under LGPL - original licence link has changed is not relivant.
11148 * <script type="text/javascript">
11152 * @class Roo.data.DataProxy
11153 * @extends Roo.data.Observable
11154 * This class is an abstract base class for implementations which provide retrieval of
11155 * unformatted data objects.<br>
11157 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
11158 * (of the appropriate type which knows how to parse the data object) to provide a block of
11159 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
11161 * Custom implementations must implement the load method as described in
11162 * {@link Roo.data.HttpProxy#load}.
11164 Roo.data.DataProxy = function(){
11167 * @event beforeload
11168 * Fires before a network request is made to retrieve a data object.
11169 * @param {Object} This DataProxy object.
11170 * @param {Object} params The params parameter to the load function.
11175 * Fires before the load method's callback is called.
11176 * @param {Object} This DataProxy object.
11177 * @param {Object} o The data object.
11178 * @param {Object} arg The callback argument object passed to the load function.
11182 * @event loadexception
11183 * Fires if an Exception occurs during data retrieval.
11184 * @param {Object} This DataProxy object.
11185 * @param {Object} o The data object.
11186 * @param {Object} arg The callback argument object passed to the load function.
11187 * @param {Object} e The Exception.
11189 loadexception : true
11191 Roo.data.DataProxy.superclass.constructor.call(this);
11194 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
11197 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
11201 * Ext JS Library 1.1.1
11202 * Copyright(c) 2006-2007, Ext JS, LLC.
11204 * Originally Released Under LGPL - original licence link has changed is not relivant.
11207 * <script type="text/javascript">
11210 * @class Roo.data.MemoryProxy
11211 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
11212 * to the Reader when its load method is called.
11214 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
11216 Roo.data.MemoryProxy = function(data){
11220 Roo.data.MemoryProxy.superclass.constructor.call(this);
11224 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
11227 * Load data from the requested source (in this case an in-memory
11228 * data object passed to the constructor), read the data object into
11229 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
11230 * process that block using the passed callback.
11231 * @param {Object} params This parameter is not used by the MemoryProxy class.
11232 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11233 * object into a block of Roo.data.Records.
11234 * @param {Function} callback The function into which to pass the block of Roo.data.records.
11235 * The function must be passed <ul>
11236 * <li>The Record block object</li>
11237 * <li>The "arg" argument from the load function</li>
11238 * <li>A boolean success indicator</li>
11240 * @param {Object} scope The scope in which to call the callback
11241 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11243 load : function(params, reader, callback, scope, arg){
11244 params = params || {};
11247 result = reader.readRecords(this.data);
11249 this.fireEvent("loadexception", this, arg, null, e);
11250 callback.call(scope, null, arg, false);
11253 callback.call(scope, result, arg, true);
11257 update : function(params, records){
11262 * Ext JS Library 1.1.1
11263 * Copyright(c) 2006-2007, Ext JS, LLC.
11265 * Originally Released Under LGPL - original licence link has changed is not relivant.
11268 * <script type="text/javascript">
11271 * @class Roo.data.HttpProxy
11272 * @extends Roo.data.DataProxy
11273 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
11274 * configured to reference a certain URL.<br><br>
11276 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
11277 * from which the running page was served.<br><br>
11279 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
11281 * Be aware that to enable the browser to parse an XML document, the server must set
11282 * the Content-Type header in the HTTP response to "text/xml".
11284 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
11285 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
11286 * will be used to make the request.
11288 Roo.data.HttpProxy = function(conn){
11289 Roo.data.HttpProxy.superclass.constructor.call(this);
11290 // is conn a conn config or a real conn?
11292 this.useAjax = !conn || !conn.events;
11296 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
11297 // thse are take from connection...
11300 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
11303 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
11304 * extra parameters to each request made by this object. (defaults to undefined)
11307 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
11308 * to each request made by this object. (defaults to undefined)
11311 * @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)
11314 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11317 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
11323 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11327 * Return the {@link Roo.data.Connection} object being used by this Proxy.
11328 * @return {Connection} The Connection object. This object may be used to subscribe to events on
11329 * a finer-grained basis than the DataProxy events.
11331 getConnection : function(){
11332 return this.useAjax ? Roo.Ajax : this.conn;
11336 * Load data from the configured {@link Roo.data.Connection}, read the data object into
11337 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
11338 * process that block using the passed callback.
11339 * @param {Object} params An object containing properties which are to be used as HTTP parameters
11340 * for the request to the remote server.
11341 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11342 * object into a block of Roo.data.Records.
11343 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
11344 * The function must be passed <ul>
11345 * <li>The Record block object</li>
11346 * <li>The "arg" argument from the load function</li>
11347 * <li>A boolean success indicator</li>
11349 * @param {Object} scope The scope in which to call the callback
11350 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11352 load : function(params, reader, callback, scope, arg){
11353 if(this.fireEvent("beforeload", this, params) !== false){
11355 params : params || {},
11357 callback : callback,
11362 callback : this.loadResponse,
11366 Roo.applyIf(o, this.conn);
11367 if(this.activeRequest){
11368 Roo.Ajax.abort(this.activeRequest);
11370 this.activeRequest = Roo.Ajax.request(o);
11372 this.conn.request(o);
11375 callback.call(scope||this, null, arg, false);
11380 loadResponse : function(o, success, response){
11381 delete this.activeRequest;
11383 this.fireEvent("loadexception", this, o, response);
11384 o.request.callback.call(o.request.scope, null, o.request.arg, false);
11389 result = o.reader.read(response);
11391 this.fireEvent("loadexception", this, o, response, e);
11392 o.request.callback.call(o.request.scope, null, o.request.arg, false);
11396 this.fireEvent("load", this, o, o.request.arg);
11397 o.request.callback.call(o.request.scope, result, o.request.arg, true);
11401 update : function(dataSet){
11406 updateResponse : function(dataSet){
11411 * Ext JS Library 1.1.1
11412 * Copyright(c) 2006-2007, Ext JS, LLC.
11414 * Originally Released Under LGPL - original licence link has changed is not relivant.
11417 * <script type="text/javascript">
11421 * @class Roo.data.ScriptTagProxy
11422 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
11423 * other than the originating domain of the running page.<br><br>
11425 * <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
11426 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
11428 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
11429 * source code that is used as the source inside a <script> tag.<br><br>
11431 * In order for the browser to process the returned data, the server must wrap the data object
11432 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
11433 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
11434 * depending on whether the callback name was passed:
11437 boolean scriptTag = false;
11438 String cb = request.getParameter("callback");
11441 response.setContentType("text/javascript");
11443 response.setContentType("application/x-json");
11445 Writer out = response.getWriter();
11447 out.write(cb + "(");
11449 out.print(dataBlock.toJsonString());
11456 * @param {Object} config A configuration object.
11458 Roo.data.ScriptTagProxy = function(config){
11459 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
11460 Roo.apply(this, config);
11461 this.head = document.getElementsByTagName("head")[0];
11464 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
11466 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
11468 * @cfg {String} url The URL from which to request the data object.
11471 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
11475 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
11476 * the server the name of the callback function set up by the load call to process the returned data object.
11477 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
11478 * javascript output which calls this named function passing the data object as its only parameter.
11480 callbackParam : "callback",
11482 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
11483 * name to the request.
11488 * Load data from the configured URL, read the data object into
11489 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
11490 * process that block using the passed callback.
11491 * @param {Object} params An object containing properties which are to be used as HTTP parameters
11492 * for the request to the remote server.
11493 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11494 * object into a block of Roo.data.Records.
11495 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
11496 * The function must be passed <ul>
11497 * <li>The Record block object</li>
11498 * <li>The "arg" argument from the load function</li>
11499 * <li>A boolean success indicator</li>
11501 * @param {Object} scope The scope in which to call the callback
11502 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11504 load : function(params, reader, callback, scope, arg){
11505 if(this.fireEvent("beforeload", this, params) !== false){
11507 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
11509 var url = this.url;
11510 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
11512 url += "&_dc=" + (new Date().getTime());
11514 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
11517 cb : "stcCallback"+transId,
11518 scriptId : "stcScript"+transId,
11522 callback : callback,
11528 window[trans.cb] = function(o){
11529 conn.handleResponse(o, trans);
11532 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
11534 if(this.autoAbort !== false){
11538 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
11540 var script = document.createElement("script");
11541 script.setAttribute("src", url);
11542 script.setAttribute("type", "text/javascript");
11543 script.setAttribute("id", trans.scriptId);
11544 this.head.appendChild(script);
11546 this.trans = trans;
11548 callback.call(scope||this, null, arg, false);
11553 isLoading : function(){
11554 return this.trans ? true : false;
11558 * Abort the current server request.
11560 abort : function(){
11561 if(this.isLoading()){
11562 this.destroyTrans(this.trans);
11567 destroyTrans : function(trans, isLoaded){
11568 this.head.removeChild(document.getElementById(trans.scriptId));
11569 clearTimeout(trans.timeoutId);
11571 window[trans.cb] = undefined;
11573 delete window[trans.cb];
11576 // if hasn't been loaded, wait for load to remove it to prevent script error
11577 window[trans.cb] = function(){
11578 window[trans.cb] = undefined;
11580 delete window[trans.cb];
11587 handleResponse : function(o, trans){
11588 this.trans = false;
11589 this.destroyTrans(trans, true);
11592 result = trans.reader.readRecords(o);
11594 this.fireEvent("loadexception", this, o, trans.arg, e);
11595 trans.callback.call(trans.scope||window, null, trans.arg, false);
11598 this.fireEvent("load", this, o, trans.arg);
11599 trans.callback.call(trans.scope||window, result, trans.arg, true);
11603 handleFailure : function(trans){
11604 this.trans = false;
11605 this.destroyTrans(trans, false);
11606 this.fireEvent("loadexception", this, null, trans.arg);
11607 trans.callback.call(trans.scope||window, null, trans.arg, false);
11611 * Ext JS Library 1.1.1
11612 * Copyright(c) 2006-2007, Ext JS, LLC.
11614 * Originally Released Under LGPL - original licence link has changed is not relivant.
11617 * <script type="text/javascript">
11621 * @class Roo.data.JsonReader
11622 * @extends Roo.data.DataReader
11623 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
11624 * based on mappings in a provided Roo.data.Record constructor.
11626 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
11627 * in the reply previously.
11632 var RecordDef = Roo.data.Record.create([
11633 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
11634 {name: 'occupation'} // This field will use "occupation" as the mapping.
11636 var myReader = new Roo.data.JsonReader({
11637 totalProperty: "results", // The property which contains the total dataset size (optional)
11638 root: "rows", // The property which contains an Array of row objects
11639 id: "id" // The property within each row object that provides an ID for the record (optional)
11643 * This would consume a JSON file like this:
11645 { 'results': 2, 'rows': [
11646 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
11647 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
11650 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
11651 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
11652 * paged from the remote server.
11653 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
11654 * @cfg {String} root name of the property which contains the Array of row objects.
11655 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
11656 * @cfg {Array} fields Array of field definition objects
11658 * Create a new JsonReader
11659 * @param {Object} meta Metadata configuration options
11660 * @param {Object} recordType Either an Array of field definition objects,
11661 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
11663 Roo.data.JsonReader = function(meta, recordType){
11666 // set some defaults:
11667 Roo.applyIf(meta, {
11668 totalProperty: 'total',
11669 successProperty : 'success',
11674 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
11676 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
11679 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
11680 * Used by Store query builder to append _requestMeta to params.
11683 metaFromRemote : false,
11685 * This method is only used by a DataProxy which has retrieved data from a remote server.
11686 * @param {Object} response The XHR object which contains the JSON data in its responseText.
11687 * @return {Object} data A data block which is used by an Roo.data.Store object as
11688 * a cache of Roo.data.Records.
11690 read : function(response){
11691 var json = response.responseText;
11693 var o = /* eval:var:o */ eval("("+json+")");
11695 throw {message: "JsonReader.read: Json object not found"};
11701 this.metaFromRemote = true;
11702 this.meta = o.metaData;
11703 this.recordType = Roo.data.Record.create(o.metaData.fields);
11704 this.onMetaChange(this.meta, this.recordType, o);
11706 return this.readRecords(o);
11709 // private function a store will implement
11710 onMetaChange : function(meta, recordType, o){
11717 simpleAccess: function(obj, subsc) {
11724 getJsonAccessor: function(){
11726 return function(expr) {
11728 return(re.test(expr))
11729 ? new Function("obj", "return obj." + expr)
11734 return Roo.emptyFn;
11739 * Create a data block containing Roo.data.Records from an XML document.
11740 * @param {Object} o An object which contains an Array of row objects in the property specified
11741 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
11742 * which contains the total size of the dataset.
11743 * @return {Object} data A data block which is used by an Roo.data.Store object as
11744 * a cache of Roo.data.Records.
11746 readRecords : function(o){
11748 * After any data loads, the raw JSON data is available for further custom processing.
11752 var s = this.meta, Record = this.recordType,
11753 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
11755 // Generate extraction functions for the totalProperty, the root, the id, and for each field
11757 if(s.totalProperty) {
11758 this.getTotal = this.getJsonAccessor(s.totalProperty);
11760 if(s.successProperty) {
11761 this.getSuccess = this.getJsonAccessor(s.successProperty);
11763 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
11765 var g = this.getJsonAccessor(s.id);
11766 this.getId = function(rec) {
11768 return (r === undefined || r === "") ? null : r;
11771 this.getId = function(){return null;};
11774 for(var jj = 0; jj < fl; jj++){
11776 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
11777 this.ef[jj] = this.getJsonAccessor(map);
11781 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
11782 if(s.totalProperty){
11783 var vt = parseInt(this.getTotal(o), 10);
11788 if(s.successProperty){
11789 var vs = this.getSuccess(o);
11790 if(vs === false || vs === 'false'){
11795 for(var i = 0; i < c; i++){
11798 var id = this.getId(n);
11799 for(var j = 0; j < fl; j++){
11801 var v = this.ef[j](n);
11803 Roo.log('missing convert for ' + f.name);
11807 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
11809 var record = new Record(values, id);
11811 records[i] = record;
11817 totalRecords : totalRecords
11822 * Ext JS Library 1.1.1
11823 * Copyright(c) 2006-2007, Ext JS, LLC.
11825 * Originally Released Under LGPL - original licence link has changed is not relivant.
11828 * <script type="text/javascript">
11832 * @class Roo.data.ArrayReader
11833 * @extends Roo.data.DataReader
11834 * Data reader class to create an Array of Roo.data.Record objects from an Array.
11835 * Each element of that Array represents a row of data fields. The
11836 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
11837 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
11841 var RecordDef = Roo.data.Record.create([
11842 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
11843 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
11845 var myReader = new Roo.data.ArrayReader({
11846 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
11850 * This would consume an Array like this:
11852 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
11854 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
11856 * Create a new JsonReader
11857 * @param {Object} meta Metadata configuration options.
11858 * @param {Object} recordType Either an Array of field definition objects
11859 * as specified to {@link Roo.data.Record#create},
11860 * or an {@link Roo.data.Record} object
11861 * created using {@link Roo.data.Record#create}.
11863 Roo.data.ArrayReader = function(meta, recordType){
11864 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
11867 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
11869 * Create a data block containing Roo.data.Records from an XML document.
11870 * @param {Object} o An Array of row objects which represents the dataset.
11871 * @return {Object} data A data block which is used by an Roo.data.Store object as
11872 * a cache of Roo.data.Records.
11874 readRecords : function(o){
11875 var sid = this.meta ? this.meta.id : null;
11876 var recordType = this.recordType, fields = recordType.prototype.fields;
11879 for(var i = 0; i < root.length; i++){
11882 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
11883 for(var j = 0, jlen = fields.length; j < jlen; j++){
11884 var f = fields.items[j];
11885 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
11886 var v = n[k] !== undefined ? n[k] : f.defaultValue;
11888 values[f.name] = v;
11890 var record = new recordType(values, id);
11892 records[records.length] = record;
11896 totalRecords : records.length
11905 * @class Roo.bootstrap.ComboBox
11906 * @extends Roo.bootstrap.TriggerField
11907 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
11908 * @cfg {Boolean} append (true|false) default false
11909 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
11910 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
11911 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
11912 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
11913 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
11914 * @cfg {Boolean} animate default true
11915 * @cfg {Boolean} emptyResultText only for touch device
11916 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
11918 * Create a new ComboBox.
11919 * @param {Object} config Configuration options
11921 Roo.bootstrap.ComboBox = function(config){
11922 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
11926 * Fires when the dropdown list is expanded
11927 * @param {Roo.bootstrap.ComboBox} combo This combo box
11932 * Fires when the dropdown list is collapsed
11933 * @param {Roo.bootstrap.ComboBox} combo This combo box
11937 * @event beforeselect
11938 * Fires before a list item is selected. Return false to cancel the selection.
11939 * @param {Roo.bootstrap.ComboBox} combo This combo box
11940 * @param {Roo.data.Record} record The data record returned from the underlying store
11941 * @param {Number} index The index of the selected item in the dropdown list
11943 'beforeselect' : true,
11946 * Fires when a list item is selected
11947 * @param {Roo.bootstrap.ComboBox} combo This combo box
11948 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
11949 * @param {Number} index The index of the selected item in the dropdown list
11953 * @event beforequery
11954 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
11955 * The event object passed has these properties:
11956 * @param {Roo.bootstrap.ComboBox} combo This combo box
11957 * @param {String} query The query
11958 * @param {Boolean} forceAll true to force "all" query
11959 * @param {Boolean} cancel true to cancel the query
11960 * @param {Object} e The query event object
11962 'beforequery': true,
11965 * Fires when the 'add' icon is pressed (add a listener to enable add button)
11966 * @param {Roo.bootstrap.ComboBox} combo This combo box
11971 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
11972 * @param {Roo.bootstrap.ComboBox} combo This combo box
11973 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
11978 * Fires when the remove value from the combobox array
11979 * @param {Roo.bootstrap.ComboBox} combo This combo box
11983 * @event afterremove
11984 * Fires when the remove value from the combobox array
11985 * @param {Roo.bootstrap.ComboBox} combo This combo box
11987 'afterremove' : true,
11989 * @event specialfilter
11990 * Fires when specialfilter
11991 * @param {Roo.bootstrap.ComboBox} combo This combo box
11993 'specialfilter' : true,
11996 * Fires when tick the element
11997 * @param {Roo.bootstrap.ComboBox} combo This combo box
12001 * @event touchviewdisplay
12002 * Fires when touch view require special display (default is using displayField)
12003 * @param {Roo.bootstrap.ComboBox} combo This combo box
12004 * @param {Object} cfg set html .
12006 'touchviewdisplay' : true
12011 this.tickItems = [];
12013 this.selectedIndex = -1;
12014 if(this.mode == 'local'){
12015 if(config.queryDelay === undefined){
12016 this.queryDelay = 10;
12018 if(config.minChars === undefined){
12024 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
12027 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
12028 * rendering into an Roo.Editor, defaults to false)
12031 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
12032 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
12035 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
12038 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
12039 * the dropdown list (defaults to undefined, with no header element)
12043 * @cfg {String/Roo.Template} tpl The template to use to render the output
12047 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
12049 listWidth: undefined,
12051 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
12052 * mode = 'remote' or 'text' if mode = 'local')
12054 displayField: undefined,
12057 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
12058 * mode = 'remote' or 'value' if mode = 'local').
12059 * Note: use of a valueField requires the user make a selection
12060 * in order for a value to be mapped.
12062 valueField: undefined,
12064 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
12069 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
12070 * field's data value (defaults to the underlying DOM element's name)
12072 hiddenName: undefined,
12074 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
12078 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
12080 selectedClass: 'active',
12083 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
12087 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
12088 * anchor positions (defaults to 'tl-bl')
12090 listAlign: 'tl-bl?',
12092 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
12096 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
12097 * query specified by the allQuery config option (defaults to 'query')
12099 triggerAction: 'query',
12101 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
12102 * (defaults to 4, does not apply if editable = false)
12106 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
12107 * delay (typeAheadDelay) if it matches a known value (defaults to false)
12111 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
12112 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
12116 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
12117 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
12121 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
12122 * when editable = true (defaults to false)
12124 selectOnFocus:false,
12126 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
12128 queryParam: 'query',
12130 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
12131 * when mode = 'remote' (defaults to 'Loading...')
12133 loadingText: 'Loading...',
12135 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
12139 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
12143 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
12144 * traditional select (defaults to true)
12148 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
12152 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
12156 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
12157 * listWidth has a higher value)
12161 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
12162 * allow the user to set arbitrary text into the field (defaults to false)
12164 forceSelection:false,
12166 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
12167 * if typeAhead = true (defaults to 250)
12169 typeAheadDelay : 250,
12171 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
12172 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
12174 valueNotFoundText : undefined,
12176 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
12178 blockFocus : false,
12181 * @cfg {Boolean} disableClear Disable showing of clear button.
12183 disableClear : false,
12185 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
12187 alwaysQuery : false,
12190 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
12195 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
12197 invalidClass : "has-warning",
12200 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
12202 validClass : "has-success",
12205 * @cfg {Boolean} specialFilter (true|false) special filter default false
12207 specialFilter : false,
12210 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
12212 mobileTouchView : true,
12224 btnPosition : 'right',
12225 triggerList : true,
12226 showToggleBtn : true,
12228 emptyResultText: 'Empty',
12229 triggerText : 'Select',
12231 // element that contains real text value.. (when hidden is used..)
12233 getAutoCreate : function()
12241 if(Roo.isTouch && this.mobileTouchView){
12242 cfg = this.getAutoCreateTouchView();
12249 if(!this.tickable){
12250 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
12255 * ComboBox with tickable selections
12258 var align = this.labelAlign || this.parentLabelAlign();
12261 cls : 'form-group roo-combobox-tickable' //input-group
12266 cls : 'tickable-buttons',
12271 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
12272 html : this.triggerText
12278 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
12285 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
12292 buttons.cn.unshift({
12294 cls: 'roo-select2-search-field-input'
12300 Roo.each(buttons.cn, function(c){
12302 c.cls += ' btn-' + _this.size;
12305 if (_this.disabled) {
12316 cls: 'form-hidden-field'
12320 cls: 'roo-select2-choices',
12324 cls: 'roo-select2-search-field',
12336 cls: 'roo-select2-container input-group roo-select2-container-multi',
12341 // cls: 'typeahead typeahead-long dropdown-menu',
12342 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
12347 if(this.hasFeedback && !this.allowBlank){
12351 cls: 'glyphicon form-control-feedback'
12354 combobox.cn.push(feedback);
12357 if (align ==='left' && this.fieldLabel.length && this.labelWidth) {
12359 // Roo.log("left and has label");
12363 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
12364 tooltip : 'This field is required'
12369 cls : 'control-label col-sm-' + this.labelWidth,
12370 html : this.fieldLabel
12374 cls : "col-sm-" + (12 - this.labelWidth),
12382 if(this.indicatorpos == 'right'){
12388 cls : 'control-label col-sm-' + this.labelWidth,
12389 html : this.fieldLabel
12394 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
12395 tooltip : 'This field is required'
12398 cls : "col-sm-" + (12 - this.labelWidth),
12409 } else if ( this.fieldLabel.length) {
12410 // Roo.log(" label");
12414 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
12415 tooltip : 'This field is required'
12419 //cls : 'input-group-addon',
12420 html : this.fieldLabel
12428 if(this.indicatorpos == 'right'){
12433 //cls : 'input-group-addon',
12434 html : this.fieldLabel
12440 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
12441 tooltip : 'This field is required'
12452 // Roo.log(" no label && no align");
12459 ['xs','sm','md','lg'].map(function(size){
12460 if (settings[size]) {
12461 cfg.cls += ' col-' + size + '-' + settings[size];
12469 _initEventsCalled : false,
12472 initEvents: function()
12475 if (this._initEventsCalled) { // as we call render... prevent looping...
12478 this._initEventsCalled = true;
12481 throw "can not find store for combo";
12484 this.store = Roo.factory(this.store, Roo.data);
12486 // if we are building from html. then this element is so complex, that we can not really
12487 // use the rendered HTML.
12488 // so we have to trash and replace the previous code.
12489 if (Roo.XComponent.build_from_html) {
12491 // remove this element....
12492 var e = this.el.dom, k=0;
12493 while (e ) { e = e.previousSibling; ++k;}
12498 this.rendered = false;
12500 this.render(this.parent().getChildContainer(true), k);
12511 if(Roo.isTouch && this.mobileTouchView){
12512 this.initTouchView();
12517 this.initTickableEvents();
12521 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
12523 if(this.hiddenName){
12525 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
12527 this.hiddenField.dom.value =
12528 this.hiddenValue !== undefined ? this.hiddenValue :
12529 this.value !== undefined ? this.value : '';
12531 // prevent input submission
12532 this.el.dom.removeAttribute('name');
12533 this.hiddenField.dom.setAttribute('name', this.hiddenName);
12538 // this.el.dom.setAttribute('autocomplete', 'off');
12541 var cls = 'x-combo-list';
12543 //this.list = new Roo.Layer({
12544 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
12550 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
12551 _this.list.setWidth(lw);
12554 this.list.on('mouseover', this.onViewOver, this);
12555 this.list.on('mousemove', this.onViewMove, this);
12557 this.list.on('scroll', this.onViewScroll, this);
12560 this.list.swallowEvent('mousewheel');
12561 this.assetHeight = 0;
12564 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
12565 this.assetHeight += this.header.getHeight();
12568 this.innerList = this.list.createChild({cls:cls+'-inner'});
12569 this.innerList.on('mouseover', this.onViewOver, this);
12570 this.innerList.on('mousemove', this.onViewMove, this);
12571 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
12573 if(this.allowBlank && !this.pageSize && !this.disableClear){
12574 this.footer = this.list.createChild({cls:cls+'-ft'});
12575 this.pageTb = new Roo.Toolbar(this.footer);
12579 this.footer = this.list.createChild({cls:cls+'-ft'});
12580 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
12581 {pageSize: this.pageSize});
12585 if (this.pageTb && this.allowBlank && !this.disableClear) {
12587 this.pageTb.add(new Roo.Toolbar.Fill(), {
12588 cls: 'x-btn-icon x-btn-clear',
12590 handler: function()
12593 _this.clearValue();
12594 _this.onSelect(false, -1);
12599 this.assetHeight += this.footer.getHeight();
12604 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
12607 this.view = new Roo.View(this.list, this.tpl, {
12608 singleSelect:true, store: this.store, selectedClass: this.selectedClass
12610 //this.view.wrapEl.setDisplayed(false);
12611 this.view.on('click', this.onViewClick, this);
12615 this.store.on('beforeload', this.onBeforeLoad, this);
12616 this.store.on('load', this.onLoad, this);
12617 this.store.on('loadexception', this.onLoadException, this);
12619 if(this.resizable){
12620 this.resizer = new Roo.Resizable(this.list, {
12621 pinned:true, handles:'se'
12623 this.resizer.on('resize', function(r, w, h){
12624 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
12625 this.listWidth = w;
12626 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
12627 this.restrictHeight();
12629 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
12632 if(!this.editable){
12633 this.editable = true;
12634 this.setEditable(false);
12639 if (typeof(this.events.add.listeners) != 'undefined') {
12641 this.addicon = this.wrap.createChild(
12642 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
12644 this.addicon.on('click', function(e) {
12645 this.fireEvent('add', this);
12648 if (typeof(this.events.edit.listeners) != 'undefined') {
12650 this.editicon = this.wrap.createChild(
12651 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
12652 if (this.addicon) {
12653 this.editicon.setStyle('margin-left', '40px');
12655 this.editicon.on('click', function(e) {
12657 // we fire even if inothing is selected..
12658 this.fireEvent('edit', this, this.lastData );
12664 this.keyNav = new Roo.KeyNav(this.inputEl(), {
12665 "up" : function(e){
12666 this.inKeyMode = true;
12670 "down" : function(e){
12671 if(!this.isExpanded()){
12672 this.onTriggerClick();
12674 this.inKeyMode = true;
12679 "enter" : function(e){
12680 // this.onViewClick();
12684 if(this.fireEvent("specialkey", this, e)){
12685 this.onViewClick(false);
12691 "esc" : function(e){
12695 "tab" : function(e){
12698 if(this.fireEvent("specialkey", this, e)){
12699 this.onViewClick(false);
12707 doRelay : function(foo, bar, hname){
12708 if(hname == 'down' || this.scope.isExpanded()){
12709 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
12718 this.queryDelay = Math.max(this.queryDelay || 10,
12719 this.mode == 'local' ? 10 : 250);
12722 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
12724 if(this.typeAhead){
12725 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
12727 if(this.editable !== false){
12728 this.inputEl().on("keyup", this.onKeyUp, this);
12730 if(this.forceSelection){
12731 this.inputEl().on('blur', this.doForce, this);
12735 this.choices = this.el.select('ul.roo-select2-choices', true).first();
12736 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
12740 initTickableEvents: function()
12744 if(this.hiddenName){
12746 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
12748 this.hiddenField.dom.value =
12749 this.hiddenValue !== undefined ? this.hiddenValue :
12750 this.value !== undefined ? this.value : '';
12752 // prevent input submission
12753 this.el.dom.removeAttribute('name');
12754 this.hiddenField.dom.setAttribute('name', this.hiddenName);
12759 // this.list = this.el.select('ul.dropdown-menu',true).first();
12761 this.choices = this.el.select('ul.roo-select2-choices', true).first();
12762 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
12763 if(this.triggerList){
12764 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
12767 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
12768 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
12770 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
12771 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
12773 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
12774 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
12776 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
12777 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
12778 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
12781 this.cancelBtn.hide();
12786 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
12787 _this.list.setWidth(lw);
12790 this.list.on('mouseover', this.onViewOver, this);
12791 this.list.on('mousemove', this.onViewMove, this);
12793 this.list.on('scroll', this.onViewScroll, this);
12796 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>';
12799 this.view = new Roo.View(this.list, this.tpl, {
12800 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
12803 //this.view.wrapEl.setDisplayed(false);
12804 this.view.on('click', this.onViewClick, this);
12808 this.store.on('beforeload', this.onBeforeLoad, this);
12809 this.store.on('load', this.onLoad, this);
12810 this.store.on('loadexception', this.onLoadException, this);
12813 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
12814 "up" : function(e){
12815 this.inKeyMode = true;
12819 "down" : function(e){
12820 this.inKeyMode = true;
12824 "enter" : function(e){
12825 if(this.fireEvent("specialkey", this, e)){
12826 this.onViewClick(false);
12832 "esc" : function(e){
12833 this.onTickableFooterButtonClick(e, false, false);
12836 "tab" : function(e){
12837 this.fireEvent("specialkey", this, e);
12839 this.onTickableFooterButtonClick(e, false, false);
12846 doRelay : function(e, fn, key){
12847 if(this.scope.isExpanded()){
12848 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
12857 this.queryDelay = Math.max(this.queryDelay || 10,
12858 this.mode == 'local' ? 10 : 250);
12861 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
12863 if(this.typeAhead){
12864 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
12867 if(this.editable !== false){
12868 this.tickableInputEl().on("keyup", this.onKeyUp, this);
12873 onDestroy : function(){
12875 this.view.setStore(null);
12876 this.view.el.removeAllListeners();
12877 this.view.el.remove();
12878 this.view.purgeListeners();
12881 this.list.dom.innerHTML = '';
12885 this.store.un('beforeload', this.onBeforeLoad, this);
12886 this.store.un('load', this.onLoad, this);
12887 this.store.un('loadexception', this.onLoadException, this);
12889 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
12893 fireKey : function(e){
12894 if(e.isNavKeyPress() && !this.list.isVisible()){
12895 this.fireEvent("specialkey", this, e);
12900 onResize: function(w, h){
12901 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
12903 // if(typeof w != 'number'){
12904 // // we do not handle it!?!?
12907 // var tw = this.trigger.getWidth();
12908 // // tw += this.addicon ? this.addicon.getWidth() : 0;
12909 // // tw += this.editicon ? this.editicon.getWidth() : 0;
12911 // this.inputEl().setWidth( this.adjustWidth('input', x));
12913 // //this.trigger.setStyle('left', x+'px');
12915 // if(this.list && this.listWidth === undefined){
12916 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
12917 // this.list.setWidth(lw);
12918 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
12926 * Allow or prevent the user from directly editing the field text. If false is passed,
12927 * the user will only be able to select from the items defined in the dropdown list. This method
12928 * is the runtime equivalent of setting the 'editable' config option at config time.
12929 * @param {Boolean} value True to allow the user to directly edit the field text
12931 setEditable : function(value){
12932 if(value == this.editable){
12935 this.editable = value;
12937 this.inputEl().dom.setAttribute('readOnly', true);
12938 this.inputEl().on('mousedown', this.onTriggerClick, this);
12939 this.inputEl().addClass('x-combo-noedit');
12941 this.inputEl().dom.setAttribute('readOnly', false);
12942 this.inputEl().un('mousedown', this.onTriggerClick, this);
12943 this.inputEl().removeClass('x-combo-noedit');
12949 onBeforeLoad : function(combo,opts){
12950 if(!this.hasFocus){
12954 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
12956 this.restrictHeight();
12957 this.selectedIndex = -1;
12961 onLoad : function(){
12963 this.hasQuery = false;
12965 if(!this.hasFocus){
12969 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
12970 this.loading.hide();
12973 if(this.store.getCount() > 0){
12975 this.restrictHeight();
12976 if(this.lastQuery == this.allQuery){
12977 if(this.editable && !this.tickable){
12978 this.inputEl().dom.select();
12982 !this.selectByValue(this.value, true) &&
12985 !this.store.lastOptions ||
12986 typeof(this.store.lastOptions.add) == 'undefined' ||
12987 this.store.lastOptions.add != true
12990 this.select(0, true);
12993 if(this.autoFocus){
12996 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
12997 this.taTask.delay(this.typeAheadDelay);
13001 this.onEmptyResults();
13007 onLoadException : function()
13009 this.hasQuery = false;
13011 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13012 this.loading.hide();
13015 if(this.tickable && this.editable){
13020 // only causes errors at present
13021 //Roo.log(this.store.reader.jsonData);
13022 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
13024 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
13030 onTypeAhead : function(){
13031 if(this.store.getCount() > 0){
13032 var r = this.store.getAt(0);
13033 var newValue = r.data[this.displayField];
13034 var len = newValue.length;
13035 var selStart = this.getRawValue().length;
13037 if(selStart != len){
13038 this.setRawValue(newValue);
13039 this.selectText(selStart, newValue.length);
13045 onSelect : function(record, index){
13047 if(this.fireEvent('beforeselect', this, record, index) !== false){
13049 this.setFromData(index > -1 ? record.data : false);
13052 this.fireEvent('select', this, record, index);
13057 * Returns the currently selected field value or empty string if no value is set.
13058 * @return {String} value The selected value
13060 getValue : function(){
13063 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
13066 if(this.valueField){
13067 return typeof this.value != 'undefined' ? this.value : '';
13069 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
13074 * Clears any text/value currently set in the field
13076 clearValue : function(){
13077 if(this.hiddenField){
13078 this.hiddenField.dom.value = '';
13081 this.setRawValue('');
13082 this.lastSelectionText = '';
13083 this.lastData = false;
13085 var close = this.closeTriggerEl();
13096 * Sets the specified value into the field. If the value finds a match, the corresponding record text
13097 * will be displayed in the field. If the value does not match the data value of an existing item,
13098 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
13099 * Otherwise the field will be blank (although the value will still be set).
13100 * @param {String} value The value to match
13102 setValue : function(v){
13109 if(this.valueField){
13110 var r = this.findRecord(this.valueField, v);
13112 text = r.data[this.displayField];
13113 }else if(this.valueNotFoundText !== undefined){
13114 text = this.valueNotFoundText;
13117 this.lastSelectionText = text;
13118 if(this.hiddenField){
13119 this.hiddenField.dom.value = v;
13121 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
13124 var close = this.closeTriggerEl();
13127 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
13133 * @property {Object} the last set data for the element
13138 * Sets the value of the field based on a object which is related to the record format for the store.
13139 * @param {Object} value the value to set as. or false on reset?
13141 setFromData : function(o){
13148 var dv = ''; // display value
13149 var vv = ''; // value value..
13151 if (this.displayField) {
13152 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
13154 // this is an error condition!!!
13155 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
13158 if(this.valueField){
13159 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
13162 var close = this.closeTriggerEl();
13165 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
13168 if(this.hiddenField){
13169 this.hiddenField.dom.value = vv;
13171 this.lastSelectionText = dv;
13172 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
13176 // no hidden field.. - we store the value in 'value', but still display
13177 // display field!!!!
13178 this.lastSelectionText = dv;
13179 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
13186 reset : function(){
13187 // overridden so that last data is reset..
13194 this.setValue(this.originalValue);
13195 //this.clearInvalid();
13196 this.lastData = false;
13198 this.view.clearSelections();
13204 findRecord : function(prop, value){
13206 if(this.store.getCount() > 0){
13207 this.store.each(function(r){
13208 if(r.data[prop] == value){
13218 getName: function()
13220 // returns hidden if it's set..
13221 if (!this.rendered) {return ''};
13222 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
13226 onViewMove : function(e, t){
13227 this.inKeyMode = false;
13231 onViewOver : function(e, t){
13232 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
13235 var item = this.view.findItemFromChild(t);
13238 var index = this.view.indexOf(item);
13239 this.select(index, false);
13244 onViewClick : function(view, doFocus, el, e)
13246 var index = this.view.getSelectedIndexes()[0];
13248 var r = this.store.getAt(index);
13252 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
13259 Roo.each(this.tickItems, function(v,k){
13261 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
13263 _this.tickItems.splice(k, 1);
13265 if(typeof(e) == 'undefined' && view == false){
13266 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
13278 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
13279 this.tickItems.push(r.data);
13282 if(typeof(e) == 'undefined' && view == false){
13283 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
13290 this.onSelect(r, index);
13292 if(doFocus !== false && !this.blockFocus){
13293 this.inputEl().focus();
13298 restrictHeight : function(){
13299 //this.innerList.dom.style.height = '';
13300 //var inner = this.innerList.dom;
13301 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
13302 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
13303 //this.list.beginUpdate();
13304 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
13305 this.list.alignTo(this.inputEl(), this.listAlign);
13306 this.list.alignTo(this.inputEl(), this.listAlign);
13307 //this.list.endUpdate();
13311 onEmptyResults : function(){
13313 if(this.tickable && this.editable){
13314 this.restrictHeight();
13322 * Returns true if the dropdown list is expanded, else false.
13324 isExpanded : function(){
13325 return this.list.isVisible();
13329 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
13330 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
13331 * @param {String} value The data value of the item to select
13332 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
13333 * selected item if it is not currently in view (defaults to true)
13334 * @return {Boolean} True if the value matched an item in the list, else false
13336 selectByValue : function(v, scrollIntoView){
13337 if(v !== undefined && v !== null){
13338 var r = this.findRecord(this.valueField || this.displayField, v);
13340 this.select(this.store.indexOf(r), scrollIntoView);
13348 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
13349 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
13350 * @param {Number} index The zero-based index of the list item to select
13351 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
13352 * selected item if it is not currently in view (defaults to true)
13354 select : function(index, scrollIntoView){
13355 this.selectedIndex = index;
13356 this.view.select(index);
13357 if(scrollIntoView !== false){
13358 var el = this.view.getNode(index);
13360 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
13363 this.list.scrollChildIntoView(el, false);
13369 selectNext : function(){
13370 var ct = this.store.getCount();
13372 if(this.selectedIndex == -1){
13374 }else if(this.selectedIndex < ct-1){
13375 this.select(this.selectedIndex+1);
13381 selectPrev : function(){
13382 var ct = this.store.getCount();
13384 if(this.selectedIndex == -1){
13386 }else if(this.selectedIndex != 0){
13387 this.select(this.selectedIndex-1);
13393 onKeyUp : function(e){
13394 if(this.editable !== false && !e.isSpecialKey()){
13395 this.lastKey = e.getKey();
13396 this.dqTask.delay(this.queryDelay);
13401 validateBlur : function(){
13402 return !this.list || !this.list.isVisible();
13406 initQuery : function(){
13408 var v = this.getRawValue();
13410 if(this.tickable && this.editable){
13411 v = this.tickableInputEl().getValue();
13418 doForce : function(){
13419 if(this.inputEl().dom.value.length > 0){
13420 this.inputEl().dom.value =
13421 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
13427 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
13428 * query allowing the query action to be canceled if needed.
13429 * @param {String} query The SQL query to execute
13430 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
13431 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
13432 * saved in the current store (defaults to false)
13434 doQuery : function(q, forceAll){
13436 if(q === undefined || q === null){
13441 forceAll: forceAll,
13445 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
13450 forceAll = qe.forceAll;
13451 if(forceAll === true || (q.length >= this.minChars)){
13453 this.hasQuery = true;
13455 if(this.lastQuery != q || this.alwaysQuery){
13456 this.lastQuery = q;
13457 if(this.mode == 'local'){
13458 this.selectedIndex = -1;
13460 this.store.clearFilter();
13463 if(this.specialFilter){
13464 this.fireEvent('specialfilter', this);
13469 this.store.filter(this.displayField, q);
13472 this.store.fireEvent("datachanged", this.store);
13479 this.store.baseParams[this.queryParam] = q;
13481 var options = {params : this.getParams(q)};
13484 options.add = true;
13485 options.params.start = this.page * this.pageSize;
13488 this.store.load(options);
13491 * this code will make the page width larger, at the beginning, the list not align correctly,
13492 * we should expand the list on onLoad
13493 * so command out it
13498 this.selectedIndex = -1;
13503 this.loadNext = false;
13507 getParams : function(q){
13509 //p[this.queryParam] = q;
13513 p.limit = this.pageSize;
13519 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
13521 collapse : function(){
13522 if(!this.isExpanded()){
13529 this.hasFocus = false;
13531 this.cancelBtn.hide();
13532 this.trigger.show();
13535 this.tickableInputEl().dom.value = '';
13536 this.tickableInputEl().blur();
13541 Roo.get(document).un('mousedown', this.collapseIf, this);
13542 Roo.get(document).un('mousewheel', this.collapseIf, this);
13543 if (!this.editable) {
13544 Roo.get(document).un('keydown', this.listKeyPress, this);
13546 this.fireEvent('collapse', this);
13552 collapseIf : function(e){
13553 var in_combo = e.within(this.el);
13554 var in_list = e.within(this.list);
13555 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
13557 if (in_combo || in_list || is_list) {
13558 //e.stopPropagation();
13563 this.onTickableFooterButtonClick(e, false, false);
13571 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
13573 expand : function(){
13575 if(this.isExpanded() || !this.hasFocus){
13579 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
13580 this.list.setWidth(lw);
13587 this.restrictHeight();
13591 this.tickItems = Roo.apply([], this.item);
13594 this.cancelBtn.show();
13595 this.trigger.hide();
13598 this.tickableInputEl().focus();
13603 Roo.get(document).on('mousedown', this.collapseIf, this);
13604 Roo.get(document).on('mousewheel', this.collapseIf, this);
13605 if (!this.editable) {
13606 Roo.get(document).on('keydown', this.listKeyPress, this);
13609 this.fireEvent('expand', this);
13613 // Implements the default empty TriggerField.onTriggerClick function
13614 onTriggerClick : function(e)
13616 Roo.log('trigger click');
13618 if(this.disabled || !this.triggerList){
13623 this.loadNext = false;
13625 if(this.isExpanded()){
13627 if (!this.blockFocus) {
13628 this.inputEl().focus();
13632 this.hasFocus = true;
13633 if(this.triggerAction == 'all') {
13634 this.doQuery(this.allQuery, true);
13636 this.doQuery(this.getRawValue());
13638 if (!this.blockFocus) {
13639 this.inputEl().focus();
13644 onTickableTriggerClick : function(e)
13651 this.loadNext = false;
13652 this.hasFocus = true;
13654 if(this.triggerAction == 'all') {
13655 this.doQuery(this.allQuery, true);
13657 this.doQuery(this.getRawValue());
13661 onSearchFieldClick : function(e)
13663 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
13664 this.onTickableFooterButtonClick(e, false, false);
13668 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
13673 this.loadNext = false;
13674 this.hasFocus = true;
13676 if(this.triggerAction == 'all') {
13677 this.doQuery(this.allQuery, true);
13679 this.doQuery(this.getRawValue());
13683 listKeyPress : function(e)
13685 //Roo.log('listkeypress');
13686 // scroll to first matching element based on key pres..
13687 if (e.isSpecialKey()) {
13690 var k = String.fromCharCode(e.getKey()).toUpperCase();
13693 var csel = this.view.getSelectedNodes();
13694 var cselitem = false;
13696 var ix = this.view.indexOf(csel[0]);
13697 cselitem = this.store.getAt(ix);
13698 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
13704 this.store.each(function(v) {
13706 // start at existing selection.
13707 if (cselitem.id == v.id) {
13713 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
13714 match = this.store.indexOf(v);
13720 if (match === false) {
13721 return true; // no more action?
13724 this.view.select(match);
13725 var sn = Roo.get(this.view.getSelectedNodes()[0]);
13726 sn.scrollIntoView(sn.dom.parentNode, false);
13729 onViewScroll : function(e, t){
13731 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){
13735 this.hasQuery = true;
13737 this.loading = this.list.select('.loading', true).first();
13739 if(this.loading === null){
13740 this.list.createChild({
13742 cls: 'loading roo-select2-more-results roo-select2-active',
13743 html: 'Loading more results...'
13746 this.loading = this.list.select('.loading', true).first();
13748 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
13750 this.loading.hide();
13753 this.loading.show();
13758 this.loadNext = true;
13760 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
13765 addItem : function(o)
13767 var dv = ''; // display value
13769 if (this.displayField) {
13770 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
13772 // this is an error condition!!!
13773 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
13780 var choice = this.choices.createChild({
13782 cls: 'roo-select2-search-choice',
13791 cls: 'roo-select2-search-choice-close',
13796 }, this.searchField);
13798 var close = choice.select('a.roo-select2-search-choice-close', true).first();
13800 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
13808 this.inputEl().dom.value = '';
13813 onRemoveItem : function(e, _self, o)
13815 e.preventDefault();
13817 this.lastItem = Roo.apply([], this.item);
13819 var index = this.item.indexOf(o.data) * 1;
13822 Roo.log('not this item?!');
13826 this.item.splice(index, 1);
13831 this.fireEvent('remove', this, e);
13837 syncValue : function()
13839 if(!this.item.length){
13846 Roo.each(this.item, function(i){
13847 if(_this.valueField){
13848 value.push(i[_this.valueField]);
13855 this.value = value.join(',');
13857 if(this.hiddenField){
13858 this.hiddenField.dom.value = this.value;
13861 this.store.fireEvent("datachanged", this.store);
13866 clearItem : function()
13868 if(!this.multiple){
13874 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
13882 if(this.tickable && !Roo.isTouch){
13883 this.view.refresh();
13887 inputEl: function ()
13889 if(Roo.isTouch && this.mobileTouchView){
13890 return this.el.select('input.form-control',true).first();
13894 return this.searchField;
13897 return this.el.select('input.form-control',true).first();
13901 onTickableFooterButtonClick : function(e, btn, el)
13903 e.preventDefault();
13905 this.lastItem = Roo.apply([], this.item);
13907 if(btn && btn.name == 'cancel'){
13908 this.tickItems = Roo.apply([], this.item);
13917 Roo.each(this.tickItems, function(o){
13925 validate : function()
13927 var v = this.getRawValue();
13930 v = this.getValue();
13933 if(this.disabled || this.allowBlank || v.length){
13938 this.markInvalid();
13942 tickableInputEl : function()
13944 if(!this.tickable || !this.editable){
13945 return this.inputEl();
13948 return this.inputEl().select('.roo-select2-search-field-input', true).first();
13952 getAutoCreateTouchView : function()
13957 cls: 'form-group' //input-group
13963 type : this.inputType,
13964 cls : 'form-control x-combo-noedit',
13965 autocomplete: 'new-password',
13966 placeholder : this.placeholder || '',
13971 input.name = this.name;
13975 input.cls += ' input-' + this.size;
13978 if (this.disabled) {
13979 input.disabled = true;
13990 inputblock.cls += ' input-group';
13992 inputblock.cn.unshift({
13994 cls : 'input-group-addon',
13999 if(this.removable && !this.multiple){
14000 inputblock.cls += ' roo-removable';
14002 inputblock.cn.push({
14005 cls : 'roo-combo-removable-btn close'
14009 if(this.hasFeedback && !this.allowBlank){
14011 inputblock.cls += ' has-feedback';
14013 inputblock.cn.push({
14015 cls: 'glyphicon form-control-feedback'
14022 inputblock.cls += (this.before) ? '' : ' input-group';
14024 inputblock.cn.push({
14026 cls : 'input-group-addon',
14037 cls: 'form-hidden-field'
14051 cls: 'form-hidden-field'
14055 cls: 'roo-select2-choices',
14059 cls: 'roo-select2-search-field',
14072 cls: 'roo-select2-container input-group roo-touchview-combobox ',
14078 if(!this.multiple && this.showToggleBtn){
14085 if (this.caret != false) {
14088 cls: 'fa fa-' + this.caret
14095 cls : 'input-group-addon btn dropdown-toggle',
14100 cls: 'combobox-clear',
14114 combobox.cls += ' roo-select2-container-multi';
14117 var align = this.labelAlign || this.parentLabelAlign();
14121 if(this.fieldLabel.length && this.labelWidth){
14123 var lw = align === 'left' ? ('col-sm' + this.labelWidth) : '';
14124 var cw = align === 'left' ? ('col-sm' + (12 - this.labelWidth)) : '';
14129 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
14130 tooltip : 'This field is required'
14134 cls : 'control-label ' + lw,
14135 html : this.fieldLabel
14146 if(this.indicatorpos == 'right'){
14150 cls : 'control-label ' + lw,
14151 html : this.fieldLabel
14156 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
14157 tooltip : 'This field is required'
14169 var settings = this;
14171 ['xs','sm','md','lg'].map(function(size){
14172 if (settings[size]) {
14173 cfg.cls += ' col-' + size + '-' + settings[size];
14180 initTouchView : function()
14182 this.renderTouchView();
14184 this.touchViewEl.on('scroll', function(){
14185 this.el.dom.scrollTop = 0;
14188 this.originalValue = this.getValue();
14190 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
14192 this.inputEl().on("click", this.showTouchView, this);
14193 this.triggerEl.on("click", this.showTouchView, this);
14195 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
14196 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
14198 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
14200 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
14201 this.store.on('load', this.onTouchViewLoad, this);
14202 this.store.on('loadexception', this.onTouchViewLoadException, this);
14204 if(this.hiddenName){
14206 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
14208 this.hiddenField.dom.value =
14209 this.hiddenValue !== undefined ? this.hiddenValue :
14210 this.value !== undefined ? this.value : '';
14212 this.el.dom.removeAttribute('name');
14213 this.hiddenField.dom.setAttribute('name', this.hiddenName);
14217 this.choices = this.el.select('ul.roo-select2-choices', true).first();
14218 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
14221 if(this.removable && !this.multiple){
14222 var close = this.closeTriggerEl();
14224 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
14225 close.on('click', this.removeBtnClick, this, close);
14229 * fix the bug in Safari iOS8
14231 this.inputEl().on("focus", function(e){
14232 document.activeElement.blur();
14240 renderTouchView : function()
14242 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
14243 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14245 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
14246 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14248 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
14249 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14250 this.touchViewBodyEl.setStyle('overflow', 'auto');
14252 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
14253 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14255 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
14256 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14260 showTouchView : function()
14266 this.touchViewHeaderEl.hide();
14268 if(this.modalTitle.length){
14269 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
14270 this.touchViewHeaderEl.show();
14273 this.touchViewEl.show();
14275 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
14276 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
14277 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
14279 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
14281 if(this.modalTitle.length){
14282 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
14285 this.touchViewBodyEl.setHeight(bodyHeight);
14289 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
14291 this.touchViewEl.addClass('in');
14294 this.doTouchViewQuery();
14298 hideTouchView : function()
14300 this.touchViewEl.removeClass('in');
14304 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
14306 this.touchViewEl.setStyle('display', 'none');
14311 setTouchViewValue : function()
14318 Roo.each(this.tickItems, function(o){
14323 this.hideTouchView();
14326 doTouchViewQuery : function()
14335 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
14339 if(!this.alwaysQuery || this.mode == 'local'){
14340 this.onTouchViewLoad();
14347 onTouchViewBeforeLoad : function(combo,opts)
14353 onTouchViewLoad : function()
14355 if(this.store.getCount() < 1){
14356 this.onTouchViewEmptyResults();
14360 this.clearTouchView();
14362 var rawValue = this.getRawValue();
14364 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
14366 this.tickItems = [];
14368 this.store.data.each(function(d, rowIndex){
14369 var row = this.touchViewListGroup.createChild(template);
14371 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
14372 row.addClass(d.data.cls);
14375 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
14378 html : d.data[this.displayField]
14381 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
14382 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
14385 row.removeClass('selected');
14386 if(!this.multiple && this.valueField &&
14387 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
14390 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
14391 row.addClass('selected');
14394 if(this.multiple && this.valueField &&
14395 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
14399 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
14400 this.tickItems.push(d.data);
14403 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
14407 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
14409 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
14411 if(this.modalTitle.length){
14412 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
14415 var listHeight = this.touchViewListGroup.getHeight();
14419 if(firstChecked && listHeight > bodyHeight){
14420 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
14425 onTouchViewLoadException : function()
14427 this.hideTouchView();
14430 onTouchViewEmptyResults : function()
14432 this.clearTouchView();
14434 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
14436 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
14440 clearTouchView : function()
14442 this.touchViewListGroup.dom.innerHTML = '';
14445 onTouchViewClick : function(e, el, o)
14447 e.preventDefault();
14450 var rowIndex = o.rowIndex;
14452 var r = this.store.getAt(rowIndex);
14454 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
14456 if(!this.multiple){
14457 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
14458 c.dom.removeAttribute('checked');
14461 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
14463 this.setFromData(r.data);
14465 var close = this.closeTriggerEl();
14471 this.hideTouchView();
14473 this.fireEvent('select', this, r, rowIndex);
14478 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
14479 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
14480 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
14484 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
14485 this.addItem(r.data);
14486 this.tickItems.push(r.data);
14492 * @cfg {Boolean} grow
14496 * @cfg {Number} growMin
14500 * @cfg {Number} growMax
14509 Roo.apply(Roo.bootstrap.ComboBox, {
14513 cls: 'modal-header',
14535 cls: 'list-group-item',
14539 cls: 'roo-combobox-list-group-item-value'
14543 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
14557 listItemCheckbox : {
14559 cls: 'list-group-item',
14563 cls: 'roo-combobox-list-group-item-value'
14567 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
14583 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
14588 cls: 'modal-footer',
14596 cls: 'col-xs-6 text-left',
14599 cls: 'btn btn-danger roo-touch-view-cancel',
14605 cls: 'col-xs-6 text-right',
14608 cls: 'btn btn-success roo-touch-view-ok',
14619 Roo.apply(Roo.bootstrap.ComboBox, {
14621 touchViewTemplate : {
14623 cls: 'modal fade roo-combobox-touch-view',
14627 cls: 'modal-dialog',
14628 style : 'position:fixed', // we have to fix position....
14632 cls: 'modal-content',
14634 Roo.bootstrap.ComboBox.header,
14635 Roo.bootstrap.ComboBox.body,
14636 Roo.bootstrap.ComboBox.footer
14645 * Ext JS Library 1.1.1
14646 * Copyright(c) 2006-2007, Ext JS, LLC.
14648 * Originally Released Under LGPL - original licence link has changed is not relivant.
14651 * <script type="text/javascript">
14656 * @extends Roo.util.Observable
14657 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
14658 * This class also supports single and multi selection modes. <br>
14659 * Create a data model bound view:
14661 var store = new Roo.data.Store(...);
14663 var view = new Roo.View({
14665 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
14667 singleSelect: true,
14668 selectedClass: "ydataview-selected",
14672 // listen for node click?
14673 view.on("click", function(vw, index, node, e){
14674 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
14678 dataModel.load("foobar.xml");
14680 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
14682 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
14683 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
14685 * Note: old style constructor is still suported (container, template, config)
14688 * Create a new View
14689 * @param {Object} config The config object
14692 Roo.View = function(config, depreciated_tpl, depreciated_config){
14694 this.parent = false;
14696 if (typeof(depreciated_tpl) == 'undefined') {
14697 // new way.. - universal constructor.
14698 Roo.apply(this, config);
14699 this.el = Roo.get(this.el);
14702 this.el = Roo.get(config);
14703 this.tpl = depreciated_tpl;
14704 Roo.apply(this, depreciated_config);
14706 this.wrapEl = this.el.wrap().wrap();
14707 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
14710 if(typeof(this.tpl) == "string"){
14711 this.tpl = new Roo.Template(this.tpl);
14713 // support xtype ctors..
14714 this.tpl = new Roo.factory(this.tpl, Roo);
14718 this.tpl.compile();
14723 * @event beforeclick
14724 * Fires before a click is processed. Returns false to cancel the default action.
14725 * @param {Roo.View} this
14726 * @param {Number} index The index of the target node
14727 * @param {HTMLElement} node The target node
14728 * @param {Roo.EventObject} e The raw event object
14730 "beforeclick" : true,
14733 * Fires when a template node is clicked.
14734 * @param {Roo.View} this
14735 * @param {Number} index The index of the target node
14736 * @param {HTMLElement} node The target node
14737 * @param {Roo.EventObject} e The raw event object
14742 * Fires when a template node is double clicked.
14743 * @param {Roo.View} this
14744 * @param {Number} index The index of the target node
14745 * @param {HTMLElement} node The target node
14746 * @param {Roo.EventObject} e The raw event object
14750 * @event contextmenu
14751 * Fires when a template node is right clicked.
14752 * @param {Roo.View} this
14753 * @param {Number} index The index of the target node
14754 * @param {HTMLElement} node The target node
14755 * @param {Roo.EventObject} e The raw event object
14757 "contextmenu" : true,
14759 * @event selectionchange
14760 * Fires when the selected nodes change.
14761 * @param {Roo.View} this
14762 * @param {Array} selections Array of the selected nodes
14764 "selectionchange" : true,
14767 * @event beforeselect
14768 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
14769 * @param {Roo.View} this
14770 * @param {HTMLElement} node The node to be selected
14771 * @param {Array} selections Array of currently selected nodes
14773 "beforeselect" : true,
14775 * @event preparedata
14776 * Fires on every row to render, to allow you to change the data.
14777 * @param {Roo.View} this
14778 * @param {Object} data to be rendered (change this)
14780 "preparedata" : true
14788 "click": this.onClick,
14789 "dblclick": this.onDblClick,
14790 "contextmenu": this.onContextMenu,
14794 this.selections = [];
14796 this.cmp = new Roo.CompositeElementLite([]);
14798 this.store = Roo.factory(this.store, Roo.data);
14799 this.setStore(this.store, true);
14802 if ( this.footer && this.footer.xtype) {
14804 var fctr = this.wrapEl.appendChild(document.createElement("div"));
14806 this.footer.dataSource = this.store;
14807 this.footer.container = fctr;
14808 this.footer = Roo.factory(this.footer, Roo);
14809 fctr.insertFirst(this.el);
14811 // this is a bit insane - as the paging toolbar seems to detach the el..
14812 // dom.parentNode.parentNode.parentNode
14813 // they get detached?
14817 Roo.View.superclass.constructor.call(this);
14822 Roo.extend(Roo.View, Roo.util.Observable, {
14825 * @cfg {Roo.data.Store} store Data store to load data from.
14830 * @cfg {String|Roo.Element} el The container element.
14835 * @cfg {String|Roo.Template} tpl The template used by this View
14839 * @cfg {String} dataName the named area of the template to use as the data area
14840 * Works with domtemplates roo-name="name"
14844 * @cfg {String} selectedClass The css class to add to selected nodes
14846 selectedClass : "x-view-selected",
14848 * @cfg {String} emptyText The empty text to show when nothing is loaded.
14853 * @cfg {String} text to display on mask (default Loading)
14857 * @cfg {Boolean} multiSelect Allow multiple selection
14859 multiSelect : false,
14861 * @cfg {Boolean} singleSelect Allow single selection
14863 singleSelect: false,
14866 * @cfg {Boolean} toggleSelect - selecting
14868 toggleSelect : false,
14871 * @cfg {Boolean} tickable - selecting
14876 * Returns the element this view is bound to.
14877 * @return {Roo.Element}
14879 getEl : function(){
14880 return this.wrapEl;
14886 * Refreshes the view. - called by datachanged on the store. - do not call directly.
14888 refresh : function(){
14889 //Roo.log('refresh');
14892 // if we are using something like 'domtemplate', then
14893 // the what gets used is:
14894 // t.applySubtemplate(NAME, data, wrapping data..)
14895 // the outer template then get' applied with
14896 // the store 'extra data'
14897 // and the body get's added to the
14898 // roo-name="data" node?
14899 // <span class='roo-tpl-{name}'></span> ?????
14903 this.clearSelections();
14904 this.el.update("");
14906 var records = this.store.getRange();
14907 if(records.length < 1) {
14909 // is this valid?? = should it render a template??
14911 this.el.update(this.emptyText);
14915 if (this.dataName) {
14916 this.el.update(t.apply(this.store.meta)); //????
14917 el = this.el.child('.roo-tpl-' + this.dataName);
14920 for(var i = 0, len = records.length; i < len; i++){
14921 var data = this.prepareData(records[i].data, i, records[i]);
14922 this.fireEvent("preparedata", this, data, i, records[i]);
14924 var d = Roo.apply({}, data);
14927 Roo.apply(d, {'roo-id' : Roo.id()});
14931 Roo.each(this.parent.item, function(item){
14932 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
14935 Roo.apply(d, {'roo-data-checked' : 'checked'});
14939 html[html.length] = Roo.util.Format.trim(
14941 t.applySubtemplate(this.dataName, d, this.store.meta) :
14948 el.update(html.join(""));
14949 this.nodes = el.dom.childNodes;
14950 this.updateIndexes(0);
14955 * Function to override to reformat the data that is sent to
14956 * the template for each node.
14957 * DEPRICATED - use the preparedata event handler.
14958 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
14959 * a JSON object for an UpdateManager bound view).
14961 prepareData : function(data, index, record)
14963 this.fireEvent("preparedata", this, data, index, record);
14967 onUpdate : function(ds, record){
14968 // Roo.log('on update');
14969 this.clearSelections();
14970 var index = this.store.indexOf(record);
14971 var n = this.nodes[index];
14972 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
14973 n.parentNode.removeChild(n);
14974 this.updateIndexes(index, index);
14980 onAdd : function(ds, records, index)
14982 //Roo.log(['on Add', ds, records, index] );
14983 this.clearSelections();
14984 if(this.nodes.length == 0){
14988 var n = this.nodes[index];
14989 for(var i = 0, len = records.length; i < len; i++){
14990 var d = this.prepareData(records[i].data, i, records[i]);
14992 this.tpl.insertBefore(n, d);
14995 this.tpl.append(this.el, d);
14998 this.updateIndexes(index);
15001 onRemove : function(ds, record, index){
15002 // Roo.log('onRemove');
15003 this.clearSelections();
15004 var el = this.dataName ?
15005 this.el.child('.roo-tpl-' + this.dataName) :
15008 el.dom.removeChild(this.nodes[index]);
15009 this.updateIndexes(index);
15013 * Refresh an individual node.
15014 * @param {Number} index
15016 refreshNode : function(index){
15017 this.onUpdate(this.store, this.store.getAt(index));
15020 updateIndexes : function(startIndex, endIndex){
15021 var ns = this.nodes;
15022 startIndex = startIndex || 0;
15023 endIndex = endIndex || ns.length - 1;
15024 for(var i = startIndex; i <= endIndex; i++){
15025 ns[i].nodeIndex = i;
15030 * Changes the data store this view uses and refresh the view.
15031 * @param {Store} store
15033 setStore : function(store, initial){
15034 if(!initial && this.store){
15035 this.store.un("datachanged", this.refresh);
15036 this.store.un("add", this.onAdd);
15037 this.store.un("remove", this.onRemove);
15038 this.store.un("update", this.onUpdate);
15039 this.store.un("clear", this.refresh);
15040 this.store.un("beforeload", this.onBeforeLoad);
15041 this.store.un("load", this.onLoad);
15042 this.store.un("loadexception", this.onLoad);
15046 store.on("datachanged", this.refresh, this);
15047 store.on("add", this.onAdd, this);
15048 store.on("remove", this.onRemove, this);
15049 store.on("update", this.onUpdate, this);
15050 store.on("clear", this.refresh, this);
15051 store.on("beforeload", this.onBeforeLoad, this);
15052 store.on("load", this.onLoad, this);
15053 store.on("loadexception", this.onLoad, this);
15061 * onbeforeLoad - masks the loading area.
15064 onBeforeLoad : function(store,opts)
15066 //Roo.log('onBeforeLoad');
15068 this.el.update("");
15070 this.el.mask(this.mask ? this.mask : "Loading" );
15072 onLoad : function ()
15079 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
15080 * @param {HTMLElement} node
15081 * @return {HTMLElement} The template node
15083 findItemFromChild : function(node){
15084 var el = this.dataName ?
15085 this.el.child('.roo-tpl-' + this.dataName,true) :
15088 if(!node || node.parentNode == el){
15091 var p = node.parentNode;
15092 while(p && p != el){
15093 if(p.parentNode == el){
15102 onClick : function(e){
15103 var item = this.findItemFromChild(e.getTarget());
15105 var index = this.indexOf(item);
15106 if(this.onItemClick(item, index, e) !== false){
15107 this.fireEvent("click", this, index, item, e);
15110 this.clearSelections();
15115 onContextMenu : function(e){
15116 var item = this.findItemFromChild(e.getTarget());
15118 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
15123 onDblClick : function(e){
15124 var item = this.findItemFromChild(e.getTarget());
15126 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
15130 onItemClick : function(item, index, e)
15132 if(this.fireEvent("beforeclick", this, index, item, e) === false){
15135 if (this.toggleSelect) {
15136 var m = this.isSelected(item) ? 'unselect' : 'select';
15139 _t[m](item, true, false);
15142 if(this.multiSelect || this.singleSelect){
15143 if(this.multiSelect && e.shiftKey && this.lastSelection){
15144 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
15146 this.select(item, this.multiSelect && e.ctrlKey);
15147 this.lastSelection = item;
15150 if(!this.tickable){
15151 e.preventDefault();
15159 * Get the number of selected nodes.
15162 getSelectionCount : function(){
15163 return this.selections.length;
15167 * Get the currently selected nodes.
15168 * @return {Array} An array of HTMLElements
15170 getSelectedNodes : function(){
15171 return this.selections;
15175 * Get the indexes of the selected nodes.
15178 getSelectedIndexes : function(){
15179 var indexes = [], s = this.selections;
15180 for(var i = 0, len = s.length; i < len; i++){
15181 indexes.push(s[i].nodeIndex);
15187 * Clear all selections
15188 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
15190 clearSelections : function(suppressEvent){
15191 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
15192 this.cmp.elements = this.selections;
15193 this.cmp.removeClass(this.selectedClass);
15194 this.selections = [];
15195 if(!suppressEvent){
15196 this.fireEvent("selectionchange", this, this.selections);
15202 * Returns true if the passed node is selected
15203 * @param {HTMLElement/Number} node The node or node index
15204 * @return {Boolean}
15206 isSelected : function(node){
15207 var s = this.selections;
15211 node = this.getNode(node);
15212 return s.indexOf(node) !== -1;
15217 * @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
15218 * @param {Boolean} keepExisting (optional) true to keep existing selections
15219 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
15221 select : function(nodeInfo, keepExisting, suppressEvent){
15222 if(nodeInfo instanceof Array){
15224 this.clearSelections(true);
15226 for(var i = 0, len = nodeInfo.length; i < len; i++){
15227 this.select(nodeInfo[i], true, true);
15231 var node = this.getNode(nodeInfo);
15232 if(!node || this.isSelected(node)){
15233 return; // already selected.
15236 this.clearSelections(true);
15239 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
15240 Roo.fly(node).addClass(this.selectedClass);
15241 this.selections.push(node);
15242 if(!suppressEvent){
15243 this.fireEvent("selectionchange", this, this.selections);
15251 * @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
15252 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
15253 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
15255 unselect : function(nodeInfo, keepExisting, suppressEvent)
15257 if(nodeInfo instanceof Array){
15258 Roo.each(this.selections, function(s) {
15259 this.unselect(s, nodeInfo);
15263 var node = this.getNode(nodeInfo);
15264 if(!node || !this.isSelected(node)){
15265 //Roo.log("not selected");
15266 return; // not selected.
15270 Roo.each(this.selections, function(s) {
15272 Roo.fly(node).removeClass(this.selectedClass);
15279 this.selections= ns;
15280 this.fireEvent("selectionchange", this, this.selections);
15284 * Gets a template node.
15285 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
15286 * @return {HTMLElement} The node or null if it wasn't found
15288 getNode : function(nodeInfo){
15289 if(typeof nodeInfo == "string"){
15290 return document.getElementById(nodeInfo);
15291 }else if(typeof nodeInfo == "number"){
15292 return this.nodes[nodeInfo];
15298 * Gets a range template nodes.
15299 * @param {Number} startIndex
15300 * @param {Number} endIndex
15301 * @return {Array} An array of nodes
15303 getNodes : function(start, end){
15304 var ns = this.nodes;
15305 start = start || 0;
15306 end = typeof end == "undefined" ? ns.length - 1 : end;
15309 for(var i = start; i <= end; i++){
15313 for(var i = start; i >= end; i--){
15321 * Finds the index of the passed node
15322 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
15323 * @return {Number} The index of the node or -1
15325 indexOf : function(node){
15326 node = this.getNode(node);
15327 if(typeof node.nodeIndex == "number"){
15328 return node.nodeIndex;
15330 var ns = this.nodes;
15331 for(var i = 0, len = ns.length; i < len; i++){
15342 * based on jquery fullcalendar
15346 Roo.bootstrap = Roo.bootstrap || {};
15348 * @class Roo.bootstrap.Calendar
15349 * @extends Roo.bootstrap.Component
15350 * Bootstrap Calendar class
15351 * @cfg {Boolean} loadMask (true|false) default false
15352 * @cfg {Object} header generate the user specific header of the calendar, default false
15355 * Create a new Container
15356 * @param {Object} config The config object
15361 Roo.bootstrap.Calendar = function(config){
15362 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
15366 * Fires when a date is selected
15367 * @param {DatePicker} this
15368 * @param {Date} date The selected date
15372 * @event monthchange
15373 * Fires when the displayed month changes
15374 * @param {DatePicker} this
15375 * @param {Date} date The selected month
15377 'monthchange': true,
15379 * @event evententer
15380 * Fires when mouse over an event
15381 * @param {Calendar} this
15382 * @param {event} Event
15384 'evententer': true,
15386 * @event eventleave
15387 * Fires when the mouse leaves an
15388 * @param {Calendar} this
15391 'eventleave': true,
15393 * @event eventclick
15394 * Fires when the mouse click an
15395 * @param {Calendar} this
15404 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
15407 * @cfg {Number} startDay
15408 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
15416 getAutoCreate : function(){
15419 var fc_button = function(name, corner, style, content ) {
15420 return Roo.apply({},{
15422 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
15424 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
15427 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
15438 style : 'width:100%',
15445 cls : 'fc-header-left',
15447 fc_button('prev', 'left', 'arrow', '‹' ),
15448 fc_button('next', 'right', 'arrow', '›' ),
15449 { tag: 'span', cls: 'fc-header-space' },
15450 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
15458 cls : 'fc-header-center',
15462 cls: 'fc-header-title',
15465 html : 'month / year'
15473 cls : 'fc-header-right',
15475 /* fc_button('month', 'left', '', 'month' ),
15476 fc_button('week', '', '', 'week' ),
15477 fc_button('day', 'right', '', 'day' )
15489 header = this.header;
15492 var cal_heads = function() {
15494 // fixme - handle this.
15496 for (var i =0; i < Date.dayNames.length; i++) {
15497 var d = Date.dayNames[i];
15500 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
15501 html : d.substring(0,3)
15505 ret[0].cls += ' fc-first';
15506 ret[6].cls += ' fc-last';
15509 var cal_cell = function(n) {
15512 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
15517 cls: 'fc-day-number',
15521 cls: 'fc-day-content',
15525 style: 'position: relative;' // height: 17px;
15537 var cal_rows = function() {
15540 for (var r = 0; r < 6; r++) {
15547 for (var i =0; i < Date.dayNames.length; i++) {
15548 var d = Date.dayNames[i];
15549 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
15552 row.cn[0].cls+=' fc-first';
15553 row.cn[0].cn[0].style = 'min-height:90px';
15554 row.cn[6].cls+=' fc-last';
15558 ret[0].cls += ' fc-first';
15559 ret[4].cls += ' fc-prev-last';
15560 ret[5].cls += ' fc-last';
15567 cls: 'fc-border-separate',
15568 style : 'width:100%',
15576 cls : 'fc-first fc-last',
15594 cls : 'fc-content',
15595 style : "position: relative;",
15598 cls : 'fc-view fc-view-month fc-grid',
15599 style : 'position: relative',
15600 unselectable : 'on',
15603 cls : 'fc-event-container',
15604 style : 'position:absolute;z-index:8;top:0;left:0;'
15622 initEvents : function()
15625 throw "can not find store for calendar";
15631 style: "text-align:center",
15635 style: "background-color:white;width:50%;margin:250 auto",
15639 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
15650 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
15652 var size = this.el.select('.fc-content', true).first().getSize();
15653 this.maskEl.setSize(size.width, size.height);
15654 this.maskEl.enableDisplayMode("block");
15655 if(!this.loadMask){
15656 this.maskEl.hide();
15659 this.store = Roo.factory(this.store, Roo.data);
15660 this.store.on('load', this.onLoad, this);
15661 this.store.on('beforeload', this.onBeforeLoad, this);
15665 this.cells = this.el.select('.fc-day',true);
15666 //Roo.log(this.cells);
15667 this.textNodes = this.el.query('.fc-day-number');
15668 this.cells.addClassOnOver('fc-state-hover');
15670 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
15671 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
15672 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
15673 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
15675 this.on('monthchange', this.onMonthChange, this);
15677 this.update(new Date().clearTime());
15680 resize : function() {
15681 var sz = this.el.getSize();
15683 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
15684 this.el.select('.fc-day-content div',true).setHeight(34);
15689 showPrevMonth : function(e){
15690 this.update(this.activeDate.add("mo", -1));
15692 showToday : function(e){
15693 this.update(new Date().clearTime());
15696 showNextMonth : function(e){
15697 this.update(this.activeDate.add("mo", 1));
15701 showPrevYear : function(){
15702 this.update(this.activeDate.add("y", -1));
15706 showNextYear : function(){
15707 this.update(this.activeDate.add("y", 1));
15712 update : function(date)
15714 var vd = this.activeDate;
15715 this.activeDate = date;
15716 // if(vd && this.el){
15717 // var t = date.getTime();
15718 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
15719 // Roo.log('using add remove');
15721 // this.fireEvent('monthchange', this, date);
15723 // this.cells.removeClass("fc-state-highlight");
15724 // this.cells.each(function(c){
15725 // if(c.dateValue == t){
15726 // c.addClass("fc-state-highlight");
15727 // setTimeout(function(){
15728 // try{c.dom.firstChild.focus();}catch(e){}
15738 var days = date.getDaysInMonth();
15740 var firstOfMonth = date.getFirstDateOfMonth();
15741 var startingPos = firstOfMonth.getDay()-this.startDay;
15743 if(startingPos < this.startDay){
15747 var pm = date.add(Date.MONTH, -1);
15748 var prevStart = pm.getDaysInMonth()-startingPos;
15750 this.cells = this.el.select('.fc-day',true);
15751 this.textNodes = this.el.query('.fc-day-number');
15752 this.cells.addClassOnOver('fc-state-hover');
15754 var cells = this.cells.elements;
15755 var textEls = this.textNodes;
15757 Roo.each(cells, function(cell){
15758 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
15761 days += startingPos;
15763 // convert everything to numbers so it's fast
15764 var day = 86400000;
15765 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
15768 //Roo.log(prevStart);
15770 var today = new Date().clearTime().getTime();
15771 var sel = date.clearTime().getTime();
15772 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
15773 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
15774 var ddMatch = this.disabledDatesRE;
15775 var ddText = this.disabledDatesText;
15776 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
15777 var ddaysText = this.disabledDaysText;
15778 var format = this.format;
15780 var setCellClass = function(cal, cell){
15784 //Roo.log('set Cell Class');
15786 var t = d.getTime();
15790 cell.dateValue = t;
15792 cell.className += " fc-today";
15793 cell.className += " fc-state-highlight";
15794 cell.title = cal.todayText;
15797 // disable highlight in other month..
15798 //cell.className += " fc-state-highlight";
15803 cell.className = " fc-state-disabled";
15804 cell.title = cal.minText;
15808 cell.className = " fc-state-disabled";
15809 cell.title = cal.maxText;
15813 if(ddays.indexOf(d.getDay()) != -1){
15814 cell.title = ddaysText;
15815 cell.className = " fc-state-disabled";
15818 if(ddMatch && format){
15819 var fvalue = d.dateFormat(format);
15820 if(ddMatch.test(fvalue)){
15821 cell.title = ddText.replace("%0", fvalue);
15822 cell.className = " fc-state-disabled";
15826 if (!cell.initialClassName) {
15827 cell.initialClassName = cell.dom.className;
15830 cell.dom.className = cell.initialClassName + ' ' + cell.className;
15835 for(; i < startingPos; i++) {
15836 textEls[i].innerHTML = (++prevStart);
15837 d.setDate(d.getDate()+1);
15839 cells[i].className = "fc-past fc-other-month";
15840 setCellClass(this, cells[i]);
15845 for(; i < days; i++){
15846 intDay = i - startingPos + 1;
15847 textEls[i].innerHTML = (intDay);
15848 d.setDate(d.getDate()+1);
15850 cells[i].className = ''; // "x-date-active";
15851 setCellClass(this, cells[i]);
15855 for(; i < 42; i++) {
15856 textEls[i].innerHTML = (++extraDays);
15857 d.setDate(d.getDate()+1);
15859 cells[i].className = "fc-future fc-other-month";
15860 setCellClass(this, cells[i]);
15863 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
15865 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
15867 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
15868 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
15870 if(totalRows != 6){
15871 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
15872 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
15875 this.fireEvent('monthchange', this, date);
15879 if(!this.internalRender){
15880 var main = this.el.dom.firstChild;
15881 var w = main.offsetWidth;
15882 this.el.setWidth(w + this.el.getBorderWidth("lr"));
15883 Roo.fly(main).setWidth(w);
15884 this.internalRender = true;
15885 // opera does not respect the auto grow header center column
15886 // then, after it gets a width opera refuses to recalculate
15887 // without a second pass
15888 if(Roo.isOpera && !this.secondPass){
15889 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
15890 this.secondPass = true;
15891 this.update.defer(10, this, [date]);
15898 findCell : function(dt) {
15899 dt = dt.clearTime().getTime();
15901 this.cells.each(function(c){
15902 //Roo.log("check " +c.dateValue + '?=' + dt);
15903 if(c.dateValue == dt){
15913 findCells : function(ev) {
15914 var s = ev.start.clone().clearTime().getTime();
15916 var e= ev.end.clone().clearTime().getTime();
15919 this.cells.each(function(c){
15920 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
15922 if(c.dateValue > e){
15925 if(c.dateValue < s){
15934 // findBestRow: function(cells)
15938 // for (var i =0 ; i < cells.length;i++) {
15939 // ret = Math.max(cells[i].rows || 0,ret);
15946 addItem : function(ev)
15948 // look for vertical location slot in
15949 var cells = this.findCells(ev);
15951 // ev.row = this.findBestRow(cells);
15953 // work out the location.
15957 for(var i =0; i < cells.length; i++) {
15959 cells[i].row = cells[0].row;
15962 cells[i].row = cells[i].row + 1;
15972 if (crow.start.getY() == cells[i].getY()) {
15974 crow.end = cells[i];
15991 cells[0].events.push(ev);
15993 this.calevents.push(ev);
15996 clearEvents: function() {
15998 if(!this.calevents){
16002 Roo.each(this.cells.elements, function(c){
16008 Roo.each(this.calevents, function(e) {
16009 Roo.each(e.els, function(el) {
16010 el.un('mouseenter' ,this.onEventEnter, this);
16011 el.un('mouseleave' ,this.onEventLeave, this);
16016 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
16022 renderEvents: function()
16026 this.cells.each(function(c) {
16035 if(c.row != c.events.length){
16036 r = 4 - (4 - (c.row - c.events.length));
16039 c.events = ev.slice(0, r);
16040 c.more = ev.slice(r);
16042 if(c.more.length && c.more.length == 1){
16043 c.events.push(c.more.pop());
16046 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
16050 this.cells.each(function(c) {
16052 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
16055 for (var e = 0; e < c.events.length; e++){
16056 var ev = c.events[e];
16057 var rows = ev.rows;
16059 for(var i = 0; i < rows.length; i++) {
16061 // how many rows should it span..
16064 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
16065 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
16067 unselectable : "on",
16070 cls: 'fc-event-inner',
16074 // cls: 'fc-event-time',
16075 // html : cells.length > 1 ? '' : ev.time
16079 cls: 'fc-event-title',
16080 html : String.format('{0}', ev.title)
16087 cls: 'ui-resizable-handle ui-resizable-e',
16088 html : '  '
16095 cfg.cls += ' fc-event-start';
16097 if ((i+1) == rows.length) {
16098 cfg.cls += ' fc-event-end';
16101 var ctr = _this.el.select('.fc-event-container',true).first();
16102 var cg = ctr.createChild(cfg);
16104 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
16105 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
16107 var r = (c.more.length) ? 1 : 0;
16108 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
16109 cg.setWidth(ebox.right - sbox.x -2);
16111 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
16112 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
16113 cg.on('click', _this.onEventClick, _this, ev);
16124 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
16125 style : 'position: absolute',
16126 unselectable : "on",
16129 cls: 'fc-event-inner',
16133 cls: 'fc-event-title',
16141 cls: 'ui-resizable-handle ui-resizable-e',
16142 html : '  '
16148 var ctr = _this.el.select('.fc-event-container',true).first();
16149 var cg = ctr.createChild(cfg);
16151 var sbox = c.select('.fc-day-content',true).first().getBox();
16152 var ebox = c.select('.fc-day-content',true).first().getBox();
16154 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
16155 cg.setWidth(ebox.right - sbox.x -2);
16157 cg.on('click', _this.onMoreEventClick, _this, c.more);
16167 onEventEnter: function (e, el,event,d) {
16168 this.fireEvent('evententer', this, el, event);
16171 onEventLeave: function (e, el,event,d) {
16172 this.fireEvent('eventleave', this, el, event);
16175 onEventClick: function (e, el,event,d) {
16176 this.fireEvent('eventclick', this, el, event);
16179 onMonthChange: function () {
16183 onMoreEventClick: function(e, el, more)
16187 this.calpopover.placement = 'right';
16188 this.calpopover.setTitle('More');
16190 this.calpopover.setContent('');
16192 var ctr = this.calpopover.el.select('.popover-content', true).first();
16194 Roo.each(more, function(m){
16196 cls : 'fc-event-hori fc-event-draggable',
16199 var cg = ctr.createChild(cfg);
16201 cg.on('click', _this.onEventClick, _this, m);
16204 this.calpopover.show(el);
16209 onLoad: function ()
16211 this.calevents = [];
16214 if(this.store.getCount() > 0){
16215 this.store.data.each(function(d){
16218 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
16219 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
16220 time : d.data.start_time,
16221 title : d.data.title,
16222 description : d.data.description,
16223 venue : d.data.venue
16228 this.renderEvents();
16230 if(this.calevents.length && this.loadMask){
16231 this.maskEl.hide();
16235 onBeforeLoad: function()
16237 this.clearEvents();
16239 this.maskEl.show();
16253 * @class Roo.bootstrap.Popover
16254 * @extends Roo.bootstrap.Component
16255 * Bootstrap Popover class
16256 * @cfg {String} html contents of the popover (or false to use children..)
16257 * @cfg {String} title of popover (or false to hide)
16258 * @cfg {String} placement how it is placed
16259 * @cfg {String} trigger click || hover (or false to trigger manually)
16260 * @cfg {String} over what (parent or false to trigger manually.)
16261 * @cfg {Number} delay - delay before showing
16264 * Create a new Popover
16265 * @param {Object} config The config object
16268 Roo.bootstrap.Popover = function(config){
16269 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
16275 * After the popover show
16277 * @param {Roo.bootstrap.Popover} this
16282 * After the popover hide
16284 * @param {Roo.bootstrap.Popover} this
16290 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
16292 title: 'Fill in a title',
16295 placement : 'right',
16296 trigger : 'hover', // hover
16302 can_build_overlaid : false,
16304 getChildContainer : function()
16306 return this.el.select('.popover-content',true).first();
16309 getAutoCreate : function(){
16312 cls : 'popover roo-dynamic',
16313 style: 'display:block',
16319 cls : 'popover-inner',
16323 cls: 'popover-title',
16327 cls : 'popover-content',
16338 setTitle: function(str)
16341 this.el.select('.popover-title',true).first().dom.innerHTML = str;
16343 setContent: function(str)
16346 this.el.select('.popover-content',true).first().dom.innerHTML = str;
16348 // as it get's added to the bottom of the page.
16349 onRender : function(ct, position)
16351 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
16353 var cfg = Roo.apply({}, this.getAutoCreate());
16357 cfg.cls += ' ' + this.cls;
16360 cfg.style = this.style;
16362 //Roo.log("adding to ");
16363 this.el = Roo.get(document.body).createChild(cfg, position);
16364 // Roo.log(this.el);
16369 initEvents : function()
16371 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
16372 this.el.enableDisplayMode('block');
16374 if (this.over === false) {
16377 if (this.triggers === false) {
16380 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
16381 var triggers = this.trigger ? this.trigger.split(' ') : [];
16382 Roo.each(triggers, function(trigger) {
16384 if (trigger == 'click') {
16385 on_el.on('click', this.toggle, this);
16386 } else if (trigger != 'manual') {
16387 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
16388 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
16390 on_el.on(eventIn ,this.enter, this);
16391 on_el.on(eventOut, this.leave, this);
16402 toggle : function () {
16403 this.hoverState == 'in' ? this.leave() : this.enter();
16406 enter : function () {
16408 clearTimeout(this.timeout);
16410 this.hoverState = 'in';
16412 if (!this.delay || !this.delay.show) {
16417 this.timeout = setTimeout(function () {
16418 if (_t.hoverState == 'in') {
16421 }, this.delay.show)
16424 leave : function() {
16425 clearTimeout(this.timeout);
16427 this.hoverState = 'out';
16429 if (!this.delay || !this.delay.hide) {
16434 this.timeout = setTimeout(function () {
16435 if (_t.hoverState == 'out') {
16438 }, this.delay.hide)
16441 show : function (on_el)
16444 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
16448 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
16449 if (this.html !== false) {
16450 this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
16452 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
16453 if (!this.title.length) {
16454 this.el.select('.popover-title',true).hide();
16457 var placement = typeof this.placement == 'function' ?
16458 this.placement.call(this, this.el, on_el) :
16461 var autoToken = /\s?auto?\s?/i;
16462 var autoPlace = autoToken.test(placement);
16464 placement = placement.replace(autoToken, '') || 'top';
16468 //this.el.setXY([0,0]);
16470 this.el.dom.style.display='block';
16471 this.el.addClass(placement);
16473 //this.el.appendTo(on_el);
16475 var p = this.getPosition();
16476 var box = this.el.getBox();
16481 var align = Roo.bootstrap.Popover.alignment[placement];
16482 this.el.alignTo(on_el, align[0],align[1]);
16483 //var arrow = this.el.select('.arrow',true).first();
16484 //arrow.set(align[2],
16486 this.el.addClass('in');
16489 if (this.el.hasClass('fade')) {
16493 this.hoverState = 'in';
16495 this.fireEvent('show', this);
16500 this.el.setXY([0,0]);
16501 this.el.removeClass('in');
16503 this.hoverState = null;
16505 this.fireEvent('hide', this);
16510 Roo.bootstrap.Popover.alignment = {
16511 'left' : ['r-l', [-10,0], 'right'],
16512 'right' : ['l-r', [10,0], 'left'],
16513 'bottom' : ['t-b', [0,10], 'top'],
16514 'top' : [ 'b-t', [0,-10], 'bottom']
16525 * @class Roo.bootstrap.Progress
16526 * @extends Roo.bootstrap.Component
16527 * Bootstrap Progress class
16528 * @cfg {Boolean} striped striped of the progress bar
16529 * @cfg {Boolean} active animated of the progress bar
16533 * Create a new Progress
16534 * @param {Object} config The config object
16537 Roo.bootstrap.Progress = function(config){
16538 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
16541 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
16546 getAutoCreate : function(){
16554 cfg.cls += ' progress-striped';
16558 cfg.cls += ' active';
16577 * @class Roo.bootstrap.ProgressBar
16578 * @extends Roo.bootstrap.Component
16579 * Bootstrap ProgressBar class
16580 * @cfg {Number} aria_valuenow aria-value now
16581 * @cfg {Number} aria_valuemin aria-value min
16582 * @cfg {Number} aria_valuemax aria-value max
16583 * @cfg {String} label label for the progress bar
16584 * @cfg {String} panel (success | info | warning | danger )
16585 * @cfg {String} role role of the progress bar
16586 * @cfg {String} sr_only text
16590 * Create a new ProgressBar
16591 * @param {Object} config The config object
16594 Roo.bootstrap.ProgressBar = function(config){
16595 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
16598 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
16602 aria_valuemax : 100,
16608 getAutoCreate : function()
16613 cls: 'progress-bar',
16614 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
16626 cfg.role = this.role;
16629 if(this.aria_valuenow){
16630 cfg['aria-valuenow'] = this.aria_valuenow;
16633 if(this.aria_valuemin){
16634 cfg['aria-valuemin'] = this.aria_valuemin;
16637 if(this.aria_valuemax){
16638 cfg['aria-valuemax'] = this.aria_valuemax;
16641 if(this.label && !this.sr_only){
16642 cfg.html = this.label;
16646 cfg.cls += ' progress-bar-' + this.panel;
16652 update : function(aria_valuenow)
16654 this.aria_valuenow = aria_valuenow;
16656 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
16671 * @class Roo.bootstrap.TabGroup
16672 * @extends Roo.bootstrap.Column
16673 * Bootstrap Column class
16674 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
16675 * @cfg {Boolean} carousel true to make the group behave like a carousel
16676 * @cfg {Boolean} bullets show bullets for the panels
16677 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
16678 * @cfg {Boolean} slideOnTouch (true|false) slide on touch .. default false
16679 * @cfg {Number} timer auto slide timer .. default 0 millisecond
16680 * @cfg {Boolean} showarrow (true|false) show arrow default true
16683 * Create a new TabGroup
16684 * @param {Object} config The config object
16687 Roo.bootstrap.TabGroup = function(config){
16688 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
16690 this.navId = Roo.id();
16693 Roo.bootstrap.TabGroup.register(this);
16697 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
16700 transition : false,
16705 slideOnTouch : false,
16708 getAutoCreate : function()
16710 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
16712 cfg.cls += ' tab-content';
16714 if (this.carousel) {
16715 cfg.cls += ' carousel slide';
16718 cls : 'carousel-inner',
16722 if(this.bullets && !Roo.isTouch){
16725 cls : 'carousel-bullets',
16729 if(this.bullets_cls){
16730 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
16737 cfg.cn[0].cn.push(bullets);
16740 if(this.showarrow){
16741 cfg.cn[0].cn.push({
16743 class : 'carousel-arrow',
16747 class : 'carousel-prev',
16751 class : 'fa fa-chevron-left'
16757 class : 'carousel-next',
16761 class : 'fa fa-chevron-right'
16774 initEvents: function()
16776 if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
16777 this.el.on("touchstart", this.onTouchStart, this);
16780 if(this.autoslide){
16783 this.slideFn = window.setInterval(function() {
16784 _this.showPanelNext();
16788 if(this.showarrow){
16789 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
16790 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
16796 onTouchStart : function(e, el, o)
16798 if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
16802 this.showPanelNext();
16805 getChildContainer : function()
16807 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
16811 * register a Navigation item
16812 * @param {Roo.bootstrap.NavItem} the navitem to add
16814 register : function(item)
16816 this.tabs.push( item);
16817 item.navId = this.navId; // not really needed..
16822 getActivePanel : function()
16825 Roo.each(this.tabs, function(t) {
16835 getPanelByName : function(n)
16838 Roo.each(this.tabs, function(t) {
16839 if (t.tabId == n) {
16847 indexOfPanel : function(p)
16850 Roo.each(this.tabs, function(t,i) {
16851 if (t.tabId == p.tabId) {
16860 * show a specific panel
16861 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
16862 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
16864 showPanel : function (pan)
16866 if(this.transition || typeof(pan) == 'undefined'){
16867 Roo.log("waiting for the transitionend");
16871 if (typeof(pan) == 'number') {
16872 pan = this.tabs[pan];
16875 if (typeof(pan) == 'string') {
16876 pan = this.getPanelByName(pan);
16879 var cur = this.getActivePanel();
16882 Roo.log('pan or acitve pan is undefined');
16886 if (pan.tabId == this.getActivePanel().tabId) {
16890 if (false === cur.fireEvent('beforedeactivate')) {
16894 if(this.bullets > 0 && !Roo.isTouch){
16895 this.setActiveBullet(this.indexOfPanel(pan));
16898 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
16900 this.transition = true;
16901 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
16902 var lr = dir == 'next' ? 'left' : 'right';
16903 pan.el.addClass(dir); // or prev
16904 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
16905 cur.el.addClass(lr); // or right
16906 pan.el.addClass(lr);
16909 cur.el.on('transitionend', function() {
16910 Roo.log("trans end?");
16912 pan.el.removeClass([lr,dir]);
16913 pan.setActive(true);
16915 cur.el.removeClass([lr]);
16916 cur.setActive(false);
16918 _this.transition = false;
16920 }, this, { single: true } );
16925 cur.setActive(false);
16926 pan.setActive(true);
16931 showPanelNext : function()
16933 var i = this.indexOfPanel(this.getActivePanel());
16935 if (i >= this.tabs.length - 1 && !this.autoslide) {
16939 if (i >= this.tabs.length - 1 && this.autoslide) {
16943 this.showPanel(this.tabs[i+1]);
16946 showPanelPrev : function()
16948 var i = this.indexOfPanel(this.getActivePanel());
16950 if (i < 1 && !this.autoslide) {
16954 if (i < 1 && this.autoslide) {
16955 i = this.tabs.length;
16958 this.showPanel(this.tabs[i-1]);
16962 addBullet: function()
16964 if(!this.bullets || Roo.isTouch){
16967 var ctr = this.el.select('.carousel-bullets',true).first();
16968 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
16969 var bullet = ctr.createChild({
16970 cls : 'bullet bullet-' + i
16971 },ctr.dom.lastChild);
16976 bullet.on('click', (function(e, el, o, ii, t){
16978 e.preventDefault();
16980 this.showPanel(ii);
16982 if(this.autoslide && this.slideFn){
16983 clearInterval(this.slideFn);
16984 this.slideFn = window.setInterval(function() {
16985 _this.showPanelNext();
16989 }).createDelegate(this, [i, bullet], true));
16994 setActiveBullet : function(i)
17000 Roo.each(this.el.select('.bullet', true).elements, function(el){
17001 el.removeClass('selected');
17004 var bullet = this.el.select('.bullet-' + i, true).first();
17010 bullet.addClass('selected');
17021 Roo.apply(Roo.bootstrap.TabGroup, {
17025 * register a Navigation Group
17026 * @param {Roo.bootstrap.NavGroup} the navgroup to add
17028 register : function(navgrp)
17030 this.groups[navgrp.navId] = navgrp;
17034 * fetch a Navigation Group based on the navigation ID
17035 * if one does not exist , it will get created.
17036 * @param {string} the navgroup to add
17037 * @returns {Roo.bootstrap.NavGroup} the navgroup
17039 get: function(navId) {
17040 if (typeof(this.groups[navId]) == 'undefined') {
17041 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
17043 return this.groups[navId] ;
17058 * @class Roo.bootstrap.TabPanel
17059 * @extends Roo.bootstrap.Component
17060 * Bootstrap TabPanel class
17061 * @cfg {Boolean} active panel active
17062 * @cfg {String} html panel content
17063 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
17064 * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
17065 * @cfg {String} href click to link..
17069 * Create a new TabPanel
17070 * @param {Object} config The config object
17073 Roo.bootstrap.TabPanel = function(config){
17074 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
17078 * Fires when the active status changes
17079 * @param {Roo.bootstrap.TabPanel} this
17080 * @param {Boolean} state the new state
17085 * @event beforedeactivate
17086 * Fires before a tab is de-activated - can be used to do validation on a form.
17087 * @param {Roo.bootstrap.TabPanel} this
17088 * @return {Boolean} false if there is an error
17091 'beforedeactivate': true
17094 this.tabId = this.tabId || Roo.id();
17098 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
17106 getAutoCreate : function(){
17109 // item is needed for carousel - not sure if it has any effect otherwise
17110 cls: 'tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
17111 html: this.html || ''
17115 cfg.cls += ' active';
17119 cfg.tabId = this.tabId;
17126 initEvents: function()
17128 var p = this.parent();
17129 this.navId = this.navId || p.navId;
17131 if (typeof(this.navId) != 'undefined') {
17132 // not really needed.. but just in case.. parent should be a NavGroup.
17133 var tg = Roo.bootstrap.TabGroup.get(this.navId);
17137 var i = tg.tabs.length - 1;
17139 if(this.active && tg.bullets > 0 && i < tg.bullets){
17140 tg.setActiveBullet(i);
17144 if(this.href.length){
17145 this.el.on('click', this.onClick, this);
17150 onRender : function(ct, position)
17152 // Roo.log("Call onRender: " + this.xtype);
17154 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
17162 setActive: function(state)
17164 Roo.log("panel - set active " + this.tabId + "=" + state);
17166 this.active = state;
17168 this.el.removeClass('active');
17170 } else if (!this.el.hasClass('active')) {
17171 this.el.addClass('active');
17174 this.fireEvent('changed', this, state);
17177 onClick: function(e)
17179 e.preventDefault();
17181 window.location.href = this.href;
17198 * @class Roo.bootstrap.DateField
17199 * @extends Roo.bootstrap.Input
17200 * Bootstrap DateField class
17201 * @cfg {Number} weekStart default 0
17202 * @cfg {String} viewMode default empty, (months|years)
17203 * @cfg {String} minViewMode default empty, (months|years)
17204 * @cfg {Number} startDate default -Infinity
17205 * @cfg {Number} endDate default Infinity
17206 * @cfg {Boolean} todayHighlight default false
17207 * @cfg {Boolean} todayBtn default false
17208 * @cfg {Boolean} calendarWeeks default false
17209 * @cfg {Object} daysOfWeekDisabled default empty
17210 * @cfg {Boolean} singleMode default false (true | false)
17212 * @cfg {Boolean} keyboardNavigation default true
17213 * @cfg {String} language default en
17216 * Create a new DateField
17217 * @param {Object} config The config object
17220 Roo.bootstrap.DateField = function(config){
17221 Roo.bootstrap.DateField.superclass.constructor.call(this, config);
17225 * Fires when this field show.
17226 * @param {Roo.bootstrap.DateField} this
17227 * @param {Mixed} date The date value
17232 * Fires when this field hide.
17233 * @param {Roo.bootstrap.DateField} this
17234 * @param {Mixed} date The date value
17239 * Fires when select a date.
17240 * @param {Roo.bootstrap.DateField} this
17241 * @param {Mixed} date The date value
17245 * @event beforeselect
17246 * Fires when before select a date.
17247 * @param {Roo.bootstrap.DateField} this
17248 * @param {Mixed} date The date value
17250 beforeselect : true
17254 Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, {
17257 * @cfg {String} format
17258 * The default date format string which can be overriden for localization support. The format must be
17259 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
17263 * @cfg {String} altFormats
17264 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
17265 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
17267 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
17275 todayHighlight : false,
17281 keyboardNavigation: true,
17283 calendarWeeks: false,
17285 startDate: -Infinity,
17289 daysOfWeekDisabled: [],
17293 singleMode : false,
17295 UTCDate: function()
17297 return new Date(Date.UTC.apply(Date, arguments));
17300 UTCToday: function()
17302 var today = new Date();
17303 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
17306 getDate: function() {
17307 var d = this.getUTCDate();
17308 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
17311 getUTCDate: function() {
17315 setDate: function(d) {
17316 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
17319 setUTCDate: function(d) {
17321 this.setValue(this.formatDate(this.date));
17324 onRender: function(ct, position)
17327 Roo.bootstrap.DateField.superclass.onRender.call(this, ct, position);
17329 this.language = this.language || 'en';
17330 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
17331 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
17333 this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
17334 this.format = this.format || 'm/d/y';
17335 this.isInline = false;
17336 this.isInput = true;
17337 this.component = this.el.select('.add-on', true).first() || false;
17338 this.component = (this.component && this.component.length === 0) ? false : this.component;
17339 this.hasInput = this.component && this.inputEl().length;
17341 if (typeof(this.minViewMode === 'string')) {
17342 switch (this.minViewMode) {
17344 this.minViewMode = 1;
17347 this.minViewMode = 2;
17350 this.minViewMode = 0;
17355 if (typeof(this.viewMode === 'string')) {
17356 switch (this.viewMode) {
17369 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.DateField.template);
17371 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.DateField.template);
17373 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
17375 this.picker().on('mousedown', this.onMousedown, this);
17376 this.picker().on('click', this.onClick, this);
17378 this.picker().addClass('datepicker-dropdown');
17380 this.startViewMode = this.viewMode;
17382 if(this.singleMode){
17383 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
17384 v.setVisibilityMode(Roo.Element.DISPLAY);
17388 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
17389 v.setStyle('width', '189px');
17393 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
17394 if(!this.calendarWeeks){
17399 v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
17400 v.attr('colspan', function(i, val){
17401 return parseInt(val) + 1;
17406 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
17408 this.setStartDate(this.startDate);
17409 this.setEndDate(this.endDate);
17411 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
17418 if(this.isInline) {
17423 picker : function()
17425 return this.pickerEl;
17426 // return this.el.select('.datepicker', true).first();
17429 fillDow: function()
17431 var dowCnt = this.weekStart;
17440 if(this.calendarWeeks){
17448 while (dowCnt < this.weekStart + 7) {
17452 html: Roo.bootstrap.DateField.dates[this.language].daysMin[(dowCnt++)%7]
17456 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
17459 fillMonths: function()
17462 var months = this.picker().select('>.datepicker-months td', true).first();
17464 months.dom.innerHTML = '';
17470 html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
17473 months.createChild(month);
17480 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;
17482 if (this.date < this.startDate) {
17483 this.viewDate = new Date(this.startDate);
17484 } else if (this.date > this.endDate) {
17485 this.viewDate = new Date(this.endDate);
17487 this.viewDate = new Date(this.date);
17495 var d = new Date(this.viewDate),
17496 year = d.getUTCFullYear(),
17497 month = d.getUTCMonth(),
17498 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
17499 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
17500 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
17501 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
17502 currentDate = this.date && this.date.valueOf(),
17503 today = this.UTCToday();
17505 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].months[month]+' '+year;
17507 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
17509 // this.picker.select('>tfoot th.today').
17510 // .text(dates[this.language].today)
17511 // .toggle(this.todayBtn !== false);
17513 this.updateNavArrows();
17516 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
17518 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
17520 prevMonth.setUTCDate(day);
17522 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
17524 var nextMonth = new Date(prevMonth);
17526 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
17528 nextMonth = nextMonth.valueOf();
17530 var fillMonths = false;
17532 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
17534 while(prevMonth.valueOf() < nextMonth) {
17537 if (prevMonth.getUTCDay() === this.weekStart) {
17539 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
17547 if(this.calendarWeeks){
17548 // ISO 8601: First week contains first thursday.
17549 // ISO also states week starts on Monday, but we can be more abstract here.
17551 // Start of current week: based on weekstart/current date
17552 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
17553 // Thursday of this week
17554 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
17555 // First Thursday of year, year from thursday
17556 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
17557 // Calendar week: ms between thursdays, div ms per day, div 7 days
17558 calWeek = (th - yth) / 864e5 / 7 + 1;
17560 fillMonths.cn.push({
17568 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
17570 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
17573 if (this.todayHighlight &&
17574 prevMonth.getUTCFullYear() == today.getFullYear() &&
17575 prevMonth.getUTCMonth() == today.getMonth() &&
17576 prevMonth.getUTCDate() == today.getDate()) {
17577 clsName += ' today';
17580 if (currentDate && prevMonth.valueOf() === currentDate) {
17581 clsName += ' active';
17584 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
17585 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
17586 clsName += ' disabled';
17589 fillMonths.cn.push({
17591 cls: 'day ' + clsName,
17592 html: prevMonth.getDate()
17595 prevMonth.setDate(prevMonth.getDate()+1);
17598 var currentYear = this.date && this.date.getUTCFullYear();
17599 var currentMonth = this.date && this.date.getUTCMonth();
17601 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
17603 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
17604 v.removeClass('active');
17606 if(currentYear === year && k === currentMonth){
17607 v.addClass('active');
17610 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
17611 v.addClass('disabled');
17617 year = parseInt(year/10, 10) * 10;
17619 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
17621 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
17624 for (var i = -1; i < 11; i++) {
17625 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
17627 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
17635 showMode: function(dir)
17638 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
17641 Roo.each(this.picker().select('>div',true).elements, function(v){
17642 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
17645 this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
17650 if(this.isInline) {
17654 this.picker().removeClass(['bottom', 'top']);
17656 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
17658 * place to the top of element!
17662 this.picker().addClass('top');
17663 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
17668 this.picker().addClass('bottom');
17670 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
17673 parseDate : function(value)
17675 if(!value || value instanceof Date){
17678 var v = Date.parseDate(value, this.format);
17679 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
17680 v = Date.parseDate(value, 'Y-m-d');
17682 if(!v && this.altFormats){
17683 if(!this.altFormatsArray){
17684 this.altFormatsArray = this.altFormats.split("|");
17686 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
17687 v = Date.parseDate(value, this.altFormatsArray[i]);
17693 formatDate : function(date, fmt)
17695 return (!date || !(date instanceof Date)) ?
17696 date : date.dateFormat(fmt || this.format);
17699 onFocus : function()
17701 Roo.bootstrap.DateField.superclass.onFocus.call(this);
17705 onBlur : function()
17707 Roo.bootstrap.DateField.superclass.onBlur.call(this);
17709 var d = this.inputEl().getValue();
17718 this.picker().show();
17722 this.fireEvent('show', this, this.date);
17727 if(this.isInline) {
17730 this.picker().hide();
17731 this.viewMode = this.startViewMode;
17734 this.fireEvent('hide', this, this.date);
17738 onMousedown: function(e)
17740 e.stopPropagation();
17741 e.preventDefault();
17746 Roo.bootstrap.DateField.superclass.keyup.call(this);
17750 setValue: function(v)
17752 if(this.fireEvent('beforeselect', this, v) !== false){
17753 var d = new Date(this.parseDate(v) ).clearTime();
17755 if(isNaN(d.getTime())){
17756 this.date = this.viewDate = '';
17757 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
17761 v = this.formatDate(d);
17763 Roo.bootstrap.DateField.superclass.setValue.call(this, v);
17765 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
17769 this.fireEvent('select', this, this.date);
17773 getValue: function()
17775 return this.formatDate(this.date);
17778 fireKey: function(e)
17780 if (!this.picker().isVisible()){
17781 if (e.keyCode == 27) { // allow escape to hide and re-show picker
17787 var dateChanged = false,
17789 newDate, newViewDate;
17794 e.preventDefault();
17798 if (!this.keyboardNavigation) {
17801 dir = e.keyCode == 37 ? -1 : 1;
17804 newDate = this.moveYear(this.date, dir);
17805 newViewDate = this.moveYear(this.viewDate, dir);
17806 } else if (e.shiftKey){
17807 newDate = this.moveMonth(this.date, dir);
17808 newViewDate = this.moveMonth(this.viewDate, dir);
17810 newDate = new Date(this.date);
17811 newDate.setUTCDate(this.date.getUTCDate() + dir);
17812 newViewDate = new Date(this.viewDate);
17813 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
17815 if (this.dateWithinRange(newDate)){
17816 this.date = newDate;
17817 this.viewDate = newViewDate;
17818 this.setValue(this.formatDate(this.date));
17820 e.preventDefault();
17821 dateChanged = true;
17826 if (!this.keyboardNavigation) {
17829 dir = e.keyCode == 38 ? -1 : 1;
17831 newDate = this.moveYear(this.date, dir);
17832 newViewDate = this.moveYear(this.viewDate, dir);
17833 } else if (e.shiftKey){
17834 newDate = this.moveMonth(this.date, dir);
17835 newViewDate = this.moveMonth(this.viewDate, dir);
17837 newDate = new Date(this.date);
17838 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
17839 newViewDate = new Date(this.viewDate);
17840 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
17842 if (this.dateWithinRange(newDate)){
17843 this.date = newDate;
17844 this.viewDate = newViewDate;
17845 this.setValue(this.formatDate(this.date));
17847 e.preventDefault();
17848 dateChanged = true;
17852 this.setValue(this.formatDate(this.date));
17854 e.preventDefault();
17857 this.setValue(this.formatDate(this.date));
17871 onClick: function(e)
17873 e.stopPropagation();
17874 e.preventDefault();
17876 var target = e.getTarget();
17878 if(target.nodeName.toLowerCase() === 'i'){
17879 target = Roo.get(target).dom.parentNode;
17882 var nodeName = target.nodeName;
17883 var className = target.className;
17884 var html = target.innerHTML;
17885 //Roo.log(nodeName);
17887 switch(nodeName.toLowerCase()) {
17889 switch(className) {
17895 var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
17896 switch(this.viewMode){
17898 this.viewDate = this.moveMonth(this.viewDate, dir);
17902 this.viewDate = this.moveYear(this.viewDate, dir);
17908 var date = new Date();
17909 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
17911 this.setValue(this.formatDate(this.date));
17918 if (className.indexOf('disabled') < 0) {
17919 this.viewDate.setUTCDate(1);
17920 if (className.indexOf('month') > -1) {
17921 this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
17923 var year = parseInt(html, 10) || 0;
17924 this.viewDate.setUTCFullYear(year);
17928 if(this.singleMode){
17929 this.setValue(this.formatDate(this.viewDate));
17940 //Roo.log(className);
17941 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
17942 var day = parseInt(html, 10) || 1;
17943 var year = this.viewDate.getUTCFullYear(),
17944 month = this.viewDate.getUTCMonth();
17946 if (className.indexOf('old') > -1) {
17953 } else if (className.indexOf('new') > -1) {
17961 //Roo.log([year,month,day]);
17962 this.date = this.UTCDate(year, month, day,0,0,0,0);
17963 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
17965 //Roo.log(this.formatDate(this.date));
17966 this.setValue(this.formatDate(this.date));
17973 setStartDate: function(startDate)
17975 this.startDate = startDate || -Infinity;
17976 if (this.startDate !== -Infinity) {
17977 this.startDate = this.parseDate(this.startDate);
17980 this.updateNavArrows();
17983 setEndDate: function(endDate)
17985 this.endDate = endDate || Infinity;
17986 if (this.endDate !== Infinity) {
17987 this.endDate = this.parseDate(this.endDate);
17990 this.updateNavArrows();
17993 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
17995 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
17996 if (typeof(this.daysOfWeekDisabled) !== 'object') {
17997 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
17999 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
18000 return parseInt(d, 10);
18003 this.updateNavArrows();
18006 updateNavArrows: function()
18008 if(this.singleMode){
18012 var d = new Date(this.viewDate),
18013 year = d.getUTCFullYear(),
18014 month = d.getUTCMonth();
18016 Roo.each(this.picker().select('.prev', true).elements, function(v){
18018 switch (this.viewMode) {
18021 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
18027 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
18034 Roo.each(this.picker().select('.next', true).elements, function(v){
18036 switch (this.viewMode) {
18039 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
18045 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
18053 moveMonth: function(date, dir)
18058 var new_date = new Date(date.valueOf()),
18059 day = new_date.getUTCDate(),
18060 month = new_date.getUTCMonth(),
18061 mag = Math.abs(dir),
18063 dir = dir > 0 ? 1 : -1;
18066 // If going back one month, make sure month is not current month
18067 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
18069 return new_date.getUTCMonth() == month;
18071 // If going forward one month, make sure month is as expected
18072 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
18074 return new_date.getUTCMonth() != new_month;
18076 new_month = month + dir;
18077 new_date.setUTCMonth(new_month);
18078 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
18079 if (new_month < 0 || new_month > 11) {
18080 new_month = (new_month + 12) % 12;
18083 // For magnitudes >1, move one month at a time...
18084 for (var i=0; i<mag; i++) {
18085 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
18086 new_date = this.moveMonth(new_date, dir);
18088 // ...then reset the day, keeping it in the new month
18089 new_month = new_date.getUTCMonth();
18090 new_date.setUTCDate(day);
18092 return new_month != new_date.getUTCMonth();
18095 // Common date-resetting loop -- if date is beyond end of month, make it
18098 new_date.setUTCDate(--day);
18099 new_date.setUTCMonth(new_month);
18104 moveYear: function(date, dir)
18106 return this.moveMonth(date, dir*12);
18109 dateWithinRange: function(date)
18111 return date >= this.startDate && date <= this.endDate;
18117 this.picker().remove();
18120 validateValue : function(value)
18122 if(value.length < 1) {
18123 if(this.allowBlank){
18129 if(value.length < this.minLength){
18132 if(value.length > this.maxLength){
18136 var vt = Roo.form.VTypes;
18137 if(!vt[this.vtype](value, this)){
18141 if(typeof this.validator == "function"){
18142 var msg = this.validator(value);
18148 if(this.regex && !this.regex.test(value)){
18152 if(typeof(this.parseDate(value)) == 'undefined'){
18156 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
18160 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
18170 Roo.apply(Roo.bootstrap.DateField, {
18181 html: '<i class="fa fa-arrow-left"/>'
18191 html: '<i class="fa fa-arrow-right"/>'
18233 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
18234 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
18235 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
18236 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
18237 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
18250 navFnc: 'FullYear',
18255 navFnc: 'FullYear',
18260 Roo.apply(Roo.bootstrap.DateField, {
18264 cls: 'datepicker dropdown-menu roo-dynamic',
18268 cls: 'datepicker-days',
18272 cls: 'table-condensed',
18274 Roo.bootstrap.DateField.head,
18278 Roo.bootstrap.DateField.footer
18285 cls: 'datepicker-months',
18289 cls: 'table-condensed',
18291 Roo.bootstrap.DateField.head,
18292 Roo.bootstrap.DateField.content,
18293 Roo.bootstrap.DateField.footer
18300 cls: 'datepicker-years',
18304 cls: 'table-condensed',
18306 Roo.bootstrap.DateField.head,
18307 Roo.bootstrap.DateField.content,
18308 Roo.bootstrap.DateField.footer
18327 * @class Roo.bootstrap.TimeField
18328 * @extends Roo.bootstrap.Input
18329 * Bootstrap DateField class
18333 * Create a new TimeField
18334 * @param {Object} config The config object
18337 Roo.bootstrap.TimeField = function(config){
18338 Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
18342 * Fires when this field show.
18343 * @param {Roo.bootstrap.DateField} thisthis
18344 * @param {Mixed} date The date value
18349 * Fires when this field hide.
18350 * @param {Roo.bootstrap.DateField} this
18351 * @param {Mixed} date The date value
18356 * Fires when select a date.
18357 * @param {Roo.bootstrap.DateField} this
18358 * @param {Mixed} date The date value
18364 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
18367 * @cfg {String} format
18368 * The default time format string which can be overriden for localization support. The format must be
18369 * valid according to {@link Date#parseDate} (defaults to 'H:i').
18373 onRender: function(ct, position)
18376 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
18378 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
18380 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18382 this.pop = this.picker().select('>.datepicker-time',true).first();
18383 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18385 this.picker().on('mousedown', this.onMousedown, this);
18386 this.picker().on('click', this.onClick, this);
18388 this.picker().addClass('datepicker-dropdown');
18393 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
18394 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
18395 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
18396 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
18397 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
18398 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
18402 fireKey: function(e){
18403 if (!this.picker().isVisible()){
18404 if (e.keyCode == 27) { // allow escape to hide and re-show picker
18410 e.preventDefault();
18418 this.onTogglePeriod();
18421 this.onIncrementMinutes();
18424 this.onDecrementMinutes();
18433 onClick: function(e) {
18434 e.stopPropagation();
18435 e.preventDefault();
18438 picker : function()
18440 return this.el.select('.datepicker', true).first();
18443 fillTime: function()
18445 var time = this.pop.select('tbody', true).first();
18447 time.dom.innerHTML = '';
18462 cls: 'hours-up glyphicon glyphicon-chevron-up'
18482 cls: 'minutes-up glyphicon glyphicon-chevron-up'
18503 cls: 'timepicker-hour',
18518 cls: 'timepicker-minute',
18533 cls: 'btn btn-primary period',
18555 cls: 'hours-down glyphicon glyphicon-chevron-down'
18575 cls: 'minutes-down glyphicon glyphicon-chevron-down'
18593 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
18600 var hours = this.time.getHours();
18601 var minutes = this.time.getMinutes();
18614 hours = hours - 12;
18618 hours = '0' + hours;
18622 minutes = '0' + minutes;
18625 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
18626 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
18627 this.pop.select('button', true).first().dom.innerHTML = period;
18633 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
18635 var cls = ['bottom'];
18637 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
18644 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
18649 this.picker().addClass(cls.join('-'));
18653 Roo.each(cls, function(c){
18655 _this.picker().setTop(_this.inputEl().getHeight());
18659 _this.picker().setTop(0 - _this.picker().getHeight());
18664 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
18668 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
18675 onFocus : function()
18677 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
18681 onBlur : function()
18683 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
18689 this.picker().show();
18694 this.fireEvent('show', this, this.date);
18699 this.picker().hide();
18702 this.fireEvent('hide', this, this.date);
18705 setTime : function()
18708 this.setValue(this.time.format(this.format));
18710 this.fireEvent('select', this, this.date);
18715 onMousedown: function(e){
18716 e.stopPropagation();
18717 e.preventDefault();
18720 onIncrementHours: function()
18722 Roo.log('onIncrementHours');
18723 this.time = this.time.add(Date.HOUR, 1);
18728 onDecrementHours: function()
18730 Roo.log('onDecrementHours');
18731 this.time = this.time.add(Date.HOUR, -1);
18735 onIncrementMinutes: function()
18737 Roo.log('onIncrementMinutes');
18738 this.time = this.time.add(Date.MINUTE, 1);
18742 onDecrementMinutes: function()
18744 Roo.log('onDecrementMinutes');
18745 this.time = this.time.add(Date.MINUTE, -1);
18749 onTogglePeriod: function()
18751 Roo.log('onTogglePeriod');
18752 this.time = this.time.add(Date.HOUR, 12);
18759 Roo.apply(Roo.bootstrap.TimeField, {
18789 cls: 'btn btn-info ok',
18801 Roo.apply(Roo.bootstrap.TimeField, {
18805 cls: 'datepicker dropdown-menu',
18809 cls: 'datepicker-time',
18813 cls: 'table-condensed',
18815 Roo.bootstrap.TimeField.content,
18816 Roo.bootstrap.TimeField.footer
18835 * @class Roo.bootstrap.MonthField
18836 * @extends Roo.bootstrap.Input
18837 * Bootstrap MonthField class
18839 * @cfg {String} language default en
18842 * Create a new MonthField
18843 * @param {Object} config The config object
18846 Roo.bootstrap.MonthField = function(config){
18847 Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
18852 * Fires when this field show.
18853 * @param {Roo.bootstrap.MonthField} this
18854 * @param {Mixed} date The date value
18859 * Fires when this field hide.
18860 * @param {Roo.bootstrap.MonthField} this
18861 * @param {Mixed} date The date value
18866 * Fires when select a date.
18867 * @param {Roo.bootstrap.MonthField} this
18868 * @param {String} oldvalue The old value
18869 * @param {String} newvalue The new value
18875 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
18877 onRender: function(ct, position)
18880 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
18882 this.language = this.language || 'en';
18883 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
18884 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
18886 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
18887 this.isInline = false;
18888 this.isInput = true;
18889 this.component = this.el.select('.add-on', true).first() || false;
18890 this.component = (this.component && this.component.length === 0) ? false : this.component;
18891 this.hasInput = this.component && this.inputEL().length;
18893 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
18895 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18897 this.picker().on('mousedown', this.onMousedown, this);
18898 this.picker().on('click', this.onClick, this);
18900 this.picker().addClass('datepicker-dropdown');
18902 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
18903 v.setStyle('width', '189px');
18910 if(this.isInline) {
18916 setValue: function(v, suppressEvent)
18918 var o = this.getValue();
18920 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
18924 if(suppressEvent !== true){
18925 this.fireEvent('select', this, o, v);
18930 getValue: function()
18935 onClick: function(e)
18937 e.stopPropagation();
18938 e.preventDefault();
18940 var target = e.getTarget();
18942 if(target.nodeName.toLowerCase() === 'i'){
18943 target = Roo.get(target).dom.parentNode;
18946 var nodeName = target.nodeName;
18947 var className = target.className;
18948 var html = target.innerHTML;
18950 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
18954 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
18956 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
18962 picker : function()
18964 return this.pickerEl;
18967 fillMonths: function()
18970 var months = this.picker().select('>.datepicker-months td', true).first();
18972 months.dom.innerHTML = '';
18978 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
18981 months.createChild(month);
18990 if(typeof(this.vIndex) == 'undefined' && this.value.length){
18991 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
18994 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
18995 e.removeClass('active');
18997 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
18998 e.addClass('active');
19005 if(this.isInline) {
19009 this.picker().removeClass(['bottom', 'top']);
19011 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
19013 * place to the top of element!
19017 this.picker().addClass('top');
19018 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
19023 this.picker().addClass('bottom');
19025 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
19028 onFocus : function()
19030 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
19034 onBlur : function()
19036 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
19038 var d = this.inputEl().getValue();
19047 this.picker().show();
19048 this.picker().select('>.datepicker-months', true).first().show();
19052 this.fireEvent('show', this, this.date);
19057 if(this.isInline) {
19060 this.picker().hide();
19061 this.fireEvent('hide', this, this.date);
19065 onMousedown: function(e)
19067 e.stopPropagation();
19068 e.preventDefault();
19073 Roo.bootstrap.MonthField.superclass.keyup.call(this);
19077 fireKey: function(e)
19079 if (!this.picker().isVisible()){
19080 if (e.keyCode == 27) {// allow escape to hide and re-show picker
19091 e.preventDefault();
19095 dir = e.keyCode == 37 ? -1 : 1;
19097 this.vIndex = this.vIndex + dir;
19099 if(this.vIndex < 0){
19103 if(this.vIndex > 11){
19107 if(isNaN(this.vIndex)){
19111 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
19117 dir = e.keyCode == 38 ? -1 : 1;
19119 this.vIndex = this.vIndex + dir * 4;
19121 if(this.vIndex < 0){
19125 if(this.vIndex > 11){
19129 if(isNaN(this.vIndex)){
19133 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
19138 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
19139 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
19143 e.preventDefault();
19146 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
19147 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
19163 this.picker().remove();
19168 Roo.apply(Roo.bootstrap.MonthField, {
19187 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
19188 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
19193 Roo.apply(Roo.bootstrap.MonthField, {
19197 cls: 'datepicker dropdown-menu roo-dynamic',
19201 cls: 'datepicker-months',
19205 cls: 'table-condensed',
19207 Roo.bootstrap.DateField.content
19227 * @class Roo.bootstrap.CheckBox
19228 * @extends Roo.bootstrap.Input
19229 * Bootstrap CheckBox class
19231 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
19232 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
19233 * @cfg {String} boxLabel The text that appears beside the checkbox
19234 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
19235 * @cfg {Boolean} checked initnal the element
19236 * @cfg {Boolean} inline inline the element (default false)
19237 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
19240 * Create a new CheckBox
19241 * @param {Object} config The config object
19244 Roo.bootstrap.CheckBox = function(config){
19245 Roo.bootstrap.CheckBox.superclass.constructor.call(this, config);
19250 * Fires when the element is checked or unchecked.
19251 * @param {Roo.bootstrap.CheckBox} this This input
19252 * @param {Boolean} checked The new checked value
19259 Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input, {
19261 inputType: 'checkbox',
19269 getAutoCreate : function()
19271 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
19277 cfg.cls = 'form-group ' + this.inputType; //input-group
19280 cfg.cls += ' ' + this.inputType + '-inline';
19286 type : this.inputType,
19287 value : this.inputType == 'radio' ? this.inputValue : ((!this.checked) ? this.valueOff : this.inputValue),
19288 cls : 'roo-' + this.inputType, //'form-box',
19289 placeholder : this.placeholder || ''
19293 if (this.weight) { // Validity check?
19294 cfg.cls += " " + this.inputType + "-" + this.weight;
19297 if (this.disabled) {
19298 input.disabled=true;
19302 input.checked = this.checked;
19306 input.name = this.name;
19310 input.cls += ' input-' + this.size;
19315 ['xs','sm','md','lg'].map(function(size){
19316 if (settings[size]) {
19317 cfg.cls += ' col-' + size + '-' + settings[size];
19321 var inputblock = input;
19323 if (this.before || this.after) {
19326 cls : 'input-group',
19331 inputblock.cn.push({
19333 cls : 'input-group-addon',
19338 inputblock.cn.push(input);
19341 inputblock.cn.push({
19343 cls : 'input-group-addon',
19350 if (align ==='left' && this.fieldLabel.length) {
19351 // Roo.log("left and has label");
19357 cls : 'control-label col-md-' + this.labelWidth,
19358 html : this.fieldLabel
19362 cls : "col-md-" + (12 - this.labelWidth),
19369 } else if ( this.fieldLabel.length) {
19370 // Roo.log(" label");
19374 tag: this.boxLabel ? 'span' : 'label',
19376 cls: 'control-label box-input-label',
19377 //cls : 'input-group-addon',
19378 html : this.fieldLabel
19388 // Roo.log(" no label && no align");
19389 cfg.cn = [ inputblock ] ;
19395 var boxLabelCfg = {
19397 //'for': id, // box label is handled by onclick - so no for...
19399 html: this.boxLabel
19403 boxLabelCfg.tooltip = this.tooltip;
19406 cfg.cn.push(boxLabelCfg);
19416 * return the real input element.
19418 inputEl: function ()
19420 return this.el.select('input.roo-' + this.inputType,true).first();
19423 labelEl: function()
19425 return this.el.select('label.control-label',true).first();
19427 /* depricated... */
19431 return this.labelEl();
19434 boxLabelEl: function()
19436 return this.el.select('label.box-label',true).first();
19439 initEvents : function()
19441 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
19443 this.inputEl().on('click', this.onClick, this);
19445 if (this.boxLabel) {
19446 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
19449 this.startValue = this.getValue();
19452 Roo.bootstrap.CheckBox.register(this);
19456 onClick : function()
19458 this.setChecked(!this.checked);
19461 setChecked : function(state,suppressEvent)
19463 this.startValue = this.getValue();
19465 if(this.inputType == 'radio'){
19467 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
19468 e.dom.checked = false;
19471 this.inputEl().dom.checked = true;
19473 this.inputEl().dom.value = this.inputValue;
19475 if(suppressEvent !== true){
19476 this.fireEvent('check', this, true);
19484 this.checked = state;
19486 this.inputEl().dom.checked = state;
19488 this.inputEl().dom.value = state ? this.inputValue : this.valueOff;
19490 if(suppressEvent !== true){
19491 this.fireEvent('check', this, state);
19497 getValue : function()
19499 if(this.inputType == 'radio'){
19500 return this.getGroupValue();
19503 return this.inputEl().getValue();
19507 getGroupValue : function()
19509 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
19513 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
19516 setValue : function(v,suppressEvent)
19518 if(this.inputType == 'radio'){
19519 this.setGroupValue(v, suppressEvent);
19523 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
19528 setGroupValue : function(v, suppressEvent)
19530 this.startValue = this.getValue();
19532 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
19533 e.dom.checked = false;
19535 if(e.dom.value == v){
19536 e.dom.checked = true;
19540 if(suppressEvent !== true){
19541 this.fireEvent('check', this, true);
19549 validate : function()
19553 (this.inputType == 'radio' && this.validateRadio()) ||
19554 (this.inputType == 'checkbox' && this.validateCheckbox())
19560 this.markInvalid();
19564 validateRadio : function()
19566 if(this.allowBlank){
19572 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
19573 if(!e.dom.checked){
19585 validateCheckbox : function()
19588 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
19591 var group = Roo.bootstrap.CheckBox.get(this.groupId);
19599 for(var i in group){
19604 r = (group[i].getValue() == group[i].inputValue) ? true : false;
19611 * Mark this field as valid
19613 markValid : function()
19615 if(this.allowBlank){
19621 this.fireEvent('valid', this);
19623 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
19626 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
19633 if(this.inputType == 'radio'){
19634 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
19635 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
19636 e.findParent('.form-group', false, true).addClass(_this.validClass);
19643 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
19644 this.el.findParent('.form-group', false, true).addClass(this.validClass);
19648 var group = Roo.bootstrap.CheckBox.get(this.groupId);
19654 for(var i in group){
19655 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
19656 group[i].el.findParent('.form-group', false, true).addClass(this.validClass);
19661 * Mark this field as invalid
19662 * @param {String} msg The validation message
19664 markInvalid : function(msg)
19666 if(this.allowBlank){
19672 this.fireEvent('invalid', this, msg);
19674 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
19677 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
19681 label.markInvalid();
19684 if(this.inputType == 'radio'){
19685 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
19686 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
19687 e.findParent('.form-group', false, true).addClass(_this.invalidClass);
19694 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
19695 this.el.findParent('.form-group', false, true).addClass(this.invalidClass);
19699 var group = Roo.bootstrap.CheckBox.get(this.groupId);
19705 for(var i in group){
19706 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
19707 group[i].el.findParent('.form-group', false, true).addClass(this.invalidClass);
19714 Roo.apply(Roo.bootstrap.CheckBox, {
19719 * register a CheckBox Group
19720 * @param {Roo.bootstrap.CheckBox} the CheckBox to add
19722 register : function(checkbox)
19724 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
19725 this.groups[checkbox.groupId] = {};
19728 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
19732 this.groups[checkbox.groupId][checkbox.name] = checkbox;
19736 * fetch a CheckBox Group based on the group ID
19737 * @param {string} the group ID
19738 * @returns {Roo.bootstrap.CheckBox} the CheckBox group
19740 get: function(groupId) {
19741 if (typeof(this.groups[groupId]) == 'undefined') {
19745 return this.groups[groupId] ;
19757 *<div class="radio">
19759 <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
19760 Option one is this and that—be sure to include why it's great
19767 *<label class="radio-inline">fieldLabel</label>
19768 *<label class="radio-inline">
19769 <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> 1
19777 * @class Roo.bootstrap.Radio
19778 * @extends Roo.bootstrap.CheckBox
19779 * Bootstrap Radio class
19782 * Create a new Radio
19783 * @param {Object} config The config object
19786 Roo.bootstrap.Radio = function(config){
19787 Roo.bootstrap.Radio.superclass.constructor.call(this, config);
19791 Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.CheckBox, {
19793 inputType: 'radio',
19797 getAutoCreate : function()
19799 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
19800 align = align || 'left'; // default...
19807 tag : this.inline ? 'span' : 'div',
19812 var inline = this.inline ? ' radio-inline' : '';
19816 // does not need for, as we wrap the input with it..
19818 cls : 'control-label box-label' + inline,
19821 var labelWidth = this.labelWidth ? this.labelWidth *1 : 100;
19825 //cls : 'control-label' + inline,
19826 html : this.fieldLabel,
19827 style : 'width:' + labelWidth + 'px;line-height:1;vertical-align:bottom;cursor:default;' // should be css really.
19836 type : this.inputType,
19837 //value : (!this.checked) ? this.valueOff : this.inputValue,
19838 value : this.inputValue,
19840 placeholder : this.placeholder || '' // ?? needed????
19843 if (this.weight) { // Validity check?
19844 input.cls += " radio-" + this.weight;
19846 if (this.disabled) {
19847 input.disabled=true;
19851 input.checked = this.checked;
19855 input.name = this.name;
19859 input.cls += ' input-' + this.size;
19862 //?? can span's inline have a width??
19865 ['xs','sm','md','lg'].map(function(size){
19866 if (settings[size]) {
19867 cfg.cls += ' col-' + size + '-' + settings[size];
19871 var inputblock = input;
19873 if (this.before || this.after) {
19876 cls : 'input-group',
19881 inputblock.cn.push({
19883 cls : 'input-group-addon',
19887 inputblock.cn.push(input);
19889 inputblock.cn.push({
19891 cls : 'input-group-addon',
19899 if (this.fieldLabel && this.fieldLabel.length) {
19900 cfg.cn.push(fieldLabel);
19903 // normal bootstrap puts the input inside the label.
19904 // however with our styled version - it has to go after the input.
19906 //lbl.cn.push(inputblock);
19910 cls: 'radio' + inline,
19917 cfg.cn.push( lblwrap);
19922 html: this.boxLabel
19931 initEvents : function()
19933 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
19935 this.inputEl().on('click', this.onClick, this);
19936 if (this.boxLabel) {
19937 //Roo.log('find label');
19938 this.el.select('span.radio label span',true).first().on('click', this.onClick, this);
19943 inputEl: function ()
19945 return this.el.select('input.roo-radio',true).first();
19947 onClick : function()
19950 this.setChecked(true);
19953 setChecked : function(state,suppressEvent)
19956 Roo.each(this.inputEl().up('form').select('input[name='+this.inputEl().dom.name+']', true).elements, function(v){
19957 v.dom.checked = false;
19960 Roo.log(this.inputEl().dom);
19961 this.checked = state;
19962 this.inputEl().dom.checked = state;
19964 if(suppressEvent !== true){
19965 this.fireEvent('check', this, state);
19968 //this.inputEl().dom.value = state ? this.inputValue : this.valueOff;
19972 getGroupValue : function()
19975 Roo.each(this.inputEl().up('form').select('input[name='+this.inputEl().dom.name+']', true).elements, function(v){
19976 if(v.dom.checked == true){
19977 value = v.dom.value;
19985 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
19986 * @return {Mixed} value The field value
19988 getValue : function(){
19989 return this.getGroupValue();
19995 //<script type="text/javascript">
19998 * Based Ext JS Library 1.1.1
19999 * Copyright(c) 2006-2007, Ext JS, LLC.
20005 * @class Roo.HtmlEditorCore
20006 * @extends Roo.Component
20007 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
20009 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
20012 Roo.HtmlEditorCore = function(config){
20015 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
20020 * @event initialize
20021 * Fires when the editor is fully initialized (including the iframe)
20022 * @param {Roo.HtmlEditorCore} this
20027 * Fires when the editor is first receives the focus. Any insertion must wait
20028 * until after this event.
20029 * @param {Roo.HtmlEditorCore} this
20033 * @event beforesync
20034 * Fires before the textarea is updated with content from the editor iframe. Return false
20035 * to cancel the sync.
20036 * @param {Roo.HtmlEditorCore} this
20037 * @param {String} html
20041 * @event beforepush
20042 * Fires before the iframe editor is updated with content from the textarea. Return false
20043 * to cancel the push.
20044 * @param {Roo.HtmlEditorCore} this
20045 * @param {String} html
20050 * Fires when the textarea is updated with content from the editor iframe.
20051 * @param {Roo.HtmlEditorCore} this
20052 * @param {String} html
20057 * Fires when the iframe editor is updated with content from the textarea.
20058 * @param {Roo.HtmlEditorCore} this
20059 * @param {String} html
20064 * @event editorevent
20065 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
20066 * @param {Roo.HtmlEditorCore} this
20072 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
20074 // defaults : white / black...
20075 this.applyBlacklists();
20082 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
20086 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
20092 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
20097 * @cfg {Number} height (in pixels)
20101 * @cfg {Number} width (in pixels)
20106 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
20109 stylesheets: false,
20114 // private properties
20115 validationEvent : false,
20117 initialized : false,
20119 sourceEditMode : false,
20120 onFocus : Roo.emptyFn,
20122 hideMode:'offsets',
20126 // blacklist + whitelisted elements..
20133 * Protected method that will not generally be called directly. It
20134 * is called when the editor initializes the iframe with HTML contents. Override this method if you
20135 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
20137 getDocMarkup : function(){
20141 // inherit styels from page...??
20142 if (this.stylesheets === false) {
20144 Roo.get(document.head).select('style').each(function(node) {
20145 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
20148 Roo.get(document.head).select('link').each(function(node) {
20149 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
20152 } else if (!this.stylesheets.length) {
20154 st = '<style type="text/css">' +
20155 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
20161 st += '<style type="text/css">' +
20162 'IMG { cursor: pointer } ' +
20166 return '<html><head>' + st +
20167 //<style type="text/css">' +
20168 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
20170 ' </head><body class="roo-htmleditor-body"></body></html>';
20174 onRender : function(ct, position)
20177 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
20178 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
20181 this.el.dom.style.border = '0 none';
20182 this.el.dom.setAttribute('tabIndex', -1);
20183 this.el.addClass('x-hidden hide');
20187 if(Roo.isIE){ // fix IE 1px bogus margin
20188 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
20192 this.frameId = Roo.id();
20196 var iframe = this.owner.wrap.createChild({
20198 cls: 'form-control', // bootstrap..
20200 name: this.frameId,
20201 frameBorder : 'no',
20202 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
20207 this.iframe = iframe.dom;
20209 this.assignDocWin();
20211 this.doc.designMode = 'on';
20214 this.doc.write(this.getDocMarkup());
20218 var task = { // must defer to wait for browser to be ready
20220 //console.log("run task?" + this.doc.readyState);
20221 this.assignDocWin();
20222 if(this.doc.body || this.doc.readyState == 'complete'){
20224 this.doc.designMode="on";
20228 Roo.TaskMgr.stop(task);
20229 this.initEditor.defer(10, this);
20236 Roo.TaskMgr.start(task);
20241 onResize : function(w, h)
20243 Roo.log('resize: ' +w + ',' + h );
20244 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
20248 if(typeof w == 'number'){
20250 this.iframe.style.width = w + 'px';
20252 if(typeof h == 'number'){
20254 this.iframe.style.height = h + 'px';
20256 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
20263 * Toggles the editor between standard and source edit mode.
20264 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
20266 toggleSourceEdit : function(sourceEditMode){
20268 this.sourceEditMode = sourceEditMode === true;
20270 if(this.sourceEditMode){
20272 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
20275 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
20276 //this.iframe.className = '';
20279 //this.setSize(this.owner.wrap.getSize());
20280 //this.fireEvent('editmodechange', this, this.sourceEditMode);
20287 * Protected method that will not generally be called directly. If you need/want
20288 * custom HTML cleanup, this is the method you should override.
20289 * @param {String} html The HTML to be cleaned
20290 * return {String} The cleaned HTML
20292 cleanHtml : function(html){
20293 html = String(html);
20294 if(html.length > 5){
20295 if(Roo.isSafari){ // strip safari nonsense
20296 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
20299 if(html == ' '){
20306 * HTML Editor -> Textarea
20307 * Protected method that will not generally be called directly. Syncs the contents
20308 * of the editor iframe with the textarea.
20310 syncValue : function(){
20311 if(this.initialized){
20312 var bd = (this.doc.body || this.doc.documentElement);
20313 //this.cleanUpPaste(); -- this is done else where and causes havoc..
20314 var html = bd.innerHTML;
20316 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
20317 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
20319 html = '<div style="'+m[0]+'">' + html + '</div>';
20322 html = this.cleanHtml(html);
20323 // fix up the special chars.. normaly like back quotes in word...
20324 // however we do not want to do this with chinese..
20325 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
20326 var cc = b.charCodeAt();
20328 (cc >= 0x4E00 && cc < 0xA000 ) ||
20329 (cc >= 0x3400 && cc < 0x4E00 ) ||
20330 (cc >= 0xf900 && cc < 0xfb00 )
20336 if(this.owner.fireEvent('beforesync', this, html) !== false){
20337 this.el.dom.value = html;
20338 this.owner.fireEvent('sync', this, html);
20344 * Protected method that will not generally be called directly. Pushes the value of the textarea
20345 * into the iframe editor.
20347 pushValue : function(){
20348 if(this.initialized){
20349 var v = this.el.dom.value.trim();
20351 // if(v.length < 1){
20355 if(this.owner.fireEvent('beforepush', this, v) !== false){
20356 var d = (this.doc.body || this.doc.documentElement);
20358 this.cleanUpPaste();
20359 this.el.dom.value = d.innerHTML;
20360 this.owner.fireEvent('push', this, v);
20366 deferFocus : function(){
20367 this.focus.defer(10, this);
20371 focus : function(){
20372 if(this.win && !this.sourceEditMode){
20379 assignDocWin: function()
20381 var iframe = this.iframe;
20384 this.doc = iframe.contentWindow.document;
20385 this.win = iframe.contentWindow;
20387 // if (!Roo.get(this.frameId)) {
20390 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
20391 // this.win = Roo.get(this.frameId).dom.contentWindow;
20393 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
20397 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
20398 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
20403 initEditor : function(){
20404 //console.log("INIT EDITOR");
20405 this.assignDocWin();
20409 this.doc.designMode="on";
20411 this.doc.write(this.getDocMarkup());
20414 var dbody = (this.doc.body || this.doc.documentElement);
20415 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
20416 // this copies styles from the containing element into thsi one..
20417 // not sure why we need all of this..
20418 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
20420 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
20421 //ss['background-attachment'] = 'fixed'; // w3c
20422 dbody.bgProperties = 'fixed'; // ie
20423 //Roo.DomHelper.applyStyles(dbody, ss);
20424 Roo.EventManager.on(this.doc, {
20425 //'mousedown': this.onEditorEvent,
20426 'mouseup': this.onEditorEvent,
20427 'dblclick': this.onEditorEvent,
20428 'click': this.onEditorEvent,
20429 'keyup': this.onEditorEvent,
20434 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
20436 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
20437 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
20439 this.initialized = true;
20441 this.owner.fireEvent('initialize', this);
20446 onDestroy : function(){
20452 //for (var i =0; i < this.toolbars.length;i++) {
20453 // // fixme - ask toolbars for heights?
20454 // this.toolbars[i].onDestroy();
20457 //this.wrap.dom.innerHTML = '';
20458 //this.wrap.remove();
20463 onFirstFocus : function(){
20465 this.assignDocWin();
20468 this.activated = true;
20471 if(Roo.isGecko){ // prevent silly gecko errors
20473 var s = this.win.getSelection();
20474 if(!s.focusNode || s.focusNode.nodeType != 3){
20475 var r = s.getRangeAt(0);
20476 r.selectNodeContents((this.doc.body || this.doc.documentElement));
20481 this.execCmd('useCSS', true);
20482 this.execCmd('styleWithCSS', false);
20485 this.owner.fireEvent('activate', this);
20489 adjustFont: function(btn){
20490 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
20491 //if(Roo.isSafari){ // safari
20494 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
20495 if(Roo.isSafari){ // safari
20496 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
20497 v = (v < 10) ? 10 : v;
20498 v = (v > 48) ? 48 : v;
20499 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
20504 v = Math.max(1, v+adjust);
20506 this.execCmd('FontSize', v );
20509 onEditorEvent : function(e)
20511 this.owner.fireEvent('editorevent', this, e);
20512 // this.updateToolbar();
20513 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
20516 insertTag : function(tg)
20518 // could be a bit smarter... -> wrap the current selected tRoo..
20519 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
20521 range = this.createRange(this.getSelection());
20522 var wrappingNode = this.doc.createElement(tg.toLowerCase());
20523 wrappingNode.appendChild(range.extractContents());
20524 range.insertNode(wrappingNode);
20531 this.execCmd("formatblock", tg);
20535 insertText : function(txt)
20539 var range = this.createRange();
20540 range.deleteContents();
20541 //alert(Sender.getAttribute('label'));
20543 range.insertNode(this.doc.createTextNode(txt));
20549 * Executes a Midas editor command on the editor document and performs necessary focus and
20550 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
20551 * @param {String} cmd The Midas command
20552 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
20554 relayCmd : function(cmd, value){
20556 this.execCmd(cmd, value);
20557 this.owner.fireEvent('editorevent', this);
20558 //this.updateToolbar();
20559 this.owner.deferFocus();
20563 * Executes a Midas editor command directly on the editor document.
20564 * For visual commands, you should use {@link #relayCmd} instead.
20565 * <b>This should only be called after the editor is initialized.</b>
20566 * @param {String} cmd The Midas command
20567 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
20569 execCmd : function(cmd, value){
20570 this.doc.execCommand(cmd, false, value === undefined ? null : value);
20577 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
20579 * @param {String} text | dom node..
20581 insertAtCursor : function(text)
20586 if(!this.activated){
20592 var r = this.doc.selection.createRange();
20603 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
20607 // from jquery ui (MIT licenced)
20609 var win = this.win;
20611 if (win.getSelection && win.getSelection().getRangeAt) {
20612 range = win.getSelection().getRangeAt(0);
20613 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
20614 range.insertNode(node);
20615 } else if (win.document.selection && win.document.selection.createRange) {
20616 // no firefox support
20617 var txt = typeof(text) == 'string' ? text : text.outerHTML;
20618 win.document.selection.createRange().pasteHTML(txt);
20620 // no firefox support
20621 var txt = typeof(text) == 'string' ? text : text.outerHTML;
20622 this.execCmd('InsertHTML', txt);
20631 mozKeyPress : function(e){
20633 var c = e.getCharCode(), cmd;
20636 c = String.fromCharCode(c).toLowerCase();
20650 this.cleanUpPaste.defer(100, this);
20658 e.preventDefault();
20666 fixKeys : function(){ // load time branching for fastest keydown performance
20668 return function(e){
20669 var k = e.getKey(), r;
20672 r = this.doc.selection.createRange();
20675 r.pasteHTML('    ');
20682 r = this.doc.selection.createRange();
20684 var target = r.parentElement();
20685 if(!target || target.tagName.toLowerCase() != 'li'){
20687 r.pasteHTML('<br />');
20693 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
20694 this.cleanUpPaste.defer(100, this);
20700 }else if(Roo.isOpera){
20701 return function(e){
20702 var k = e.getKey();
20706 this.execCmd('InsertHTML','    ');
20709 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
20710 this.cleanUpPaste.defer(100, this);
20715 }else if(Roo.isSafari){
20716 return function(e){
20717 var k = e.getKey();
20721 this.execCmd('InsertText','\t');
20725 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
20726 this.cleanUpPaste.defer(100, this);
20734 getAllAncestors: function()
20736 var p = this.getSelectedNode();
20739 a.push(p); // push blank onto stack..
20740 p = this.getParentElement();
20744 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
20748 a.push(this.doc.body);
20752 lastSelNode : false,
20755 getSelection : function()
20757 this.assignDocWin();
20758 return Roo.isIE ? this.doc.selection : this.win.getSelection();
20761 getSelectedNode: function()
20763 // this may only work on Gecko!!!
20765 // should we cache this!!!!
20770 var range = this.createRange(this.getSelection()).cloneRange();
20773 var parent = range.parentElement();
20775 var testRange = range.duplicate();
20776 testRange.moveToElementText(parent);
20777 if (testRange.inRange(range)) {
20780 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
20783 parent = parent.parentElement;
20788 // is ancestor a text element.
20789 var ac = range.commonAncestorContainer;
20790 if (ac.nodeType == 3) {
20791 ac = ac.parentNode;
20794 var ar = ac.childNodes;
20797 var other_nodes = [];
20798 var has_other_nodes = false;
20799 for (var i=0;i<ar.length;i++) {
20800 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
20803 // fullly contained node.
20805 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
20810 // probably selected..
20811 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
20812 other_nodes.push(ar[i]);
20816 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
20821 has_other_nodes = true;
20823 if (!nodes.length && other_nodes.length) {
20824 nodes= other_nodes;
20826 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
20832 createRange: function(sel)
20834 // this has strange effects when using with
20835 // top toolbar - not sure if it's a great idea.
20836 //this.editor.contentWindow.focus();
20837 if (typeof sel != "undefined") {
20839 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
20841 return this.doc.createRange();
20844 return this.doc.createRange();
20847 getParentElement: function()
20850 this.assignDocWin();
20851 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
20853 var range = this.createRange(sel);
20856 var p = range.commonAncestorContainer;
20857 while (p.nodeType == 3) { // text node
20868 * Range intersection.. the hard stuff...
20872 * [ -- selected range --- ]
20876 * if end is before start or hits it. fail.
20877 * if start is after end or hits it fail.
20879 * if either hits (but other is outside. - then it's not
20885 // @see http://www.thismuchiknow.co.uk/?p=64.
20886 rangeIntersectsNode : function(range, node)
20888 var nodeRange = node.ownerDocument.createRange();
20890 nodeRange.selectNode(node);
20892 nodeRange.selectNodeContents(node);
20895 var rangeStartRange = range.cloneRange();
20896 rangeStartRange.collapse(true);
20898 var rangeEndRange = range.cloneRange();
20899 rangeEndRange.collapse(false);
20901 var nodeStartRange = nodeRange.cloneRange();
20902 nodeStartRange.collapse(true);
20904 var nodeEndRange = nodeRange.cloneRange();
20905 nodeEndRange.collapse(false);
20907 return rangeStartRange.compareBoundaryPoints(
20908 Range.START_TO_START, nodeEndRange) == -1 &&
20909 rangeEndRange.compareBoundaryPoints(
20910 Range.START_TO_START, nodeStartRange) == 1;
20914 rangeCompareNode : function(range, node)
20916 var nodeRange = node.ownerDocument.createRange();
20918 nodeRange.selectNode(node);
20920 nodeRange.selectNodeContents(node);
20924 range.collapse(true);
20926 nodeRange.collapse(true);
20928 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
20929 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
20931 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
20933 var nodeIsBefore = ss == 1;
20934 var nodeIsAfter = ee == -1;
20936 if (nodeIsBefore && nodeIsAfter) {
20939 if (!nodeIsBefore && nodeIsAfter) {
20940 return 1; //right trailed.
20943 if (nodeIsBefore && !nodeIsAfter) {
20944 return 2; // left trailed.
20950 // private? - in a new class?
20951 cleanUpPaste : function()
20953 // cleans up the whole document..
20954 Roo.log('cleanuppaste');
20956 this.cleanUpChildren(this.doc.body);
20957 var clean = this.cleanWordChars(this.doc.body.innerHTML);
20958 if (clean != this.doc.body.innerHTML) {
20959 this.doc.body.innerHTML = clean;
20964 cleanWordChars : function(input) {// change the chars to hex code
20965 var he = Roo.HtmlEditorCore;
20967 var output = input;
20968 Roo.each(he.swapCodes, function(sw) {
20969 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
20971 output = output.replace(swapper, sw[1]);
20978 cleanUpChildren : function (n)
20980 if (!n.childNodes.length) {
20983 for (var i = n.childNodes.length-1; i > -1 ; i--) {
20984 this.cleanUpChild(n.childNodes[i]);
20991 cleanUpChild : function (node)
20994 //console.log(node);
20995 if (node.nodeName == "#text") {
20996 // clean up silly Windows -- stuff?
20999 if (node.nodeName == "#comment") {
21000 node.parentNode.removeChild(node);
21001 // clean up silly Windows -- stuff?
21004 var lcname = node.tagName.toLowerCase();
21005 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
21006 // whitelist of tags..
21008 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
21010 node.parentNode.removeChild(node);
21015 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
21017 // remove <a name=....> as rendering on yahoo mailer is borked with this.
21018 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
21020 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
21021 // remove_keep_children = true;
21024 if (remove_keep_children) {
21025 this.cleanUpChildren(node);
21026 // inserts everything just before this node...
21027 while (node.childNodes.length) {
21028 var cn = node.childNodes[0];
21029 node.removeChild(cn);
21030 node.parentNode.insertBefore(cn, node);
21032 node.parentNode.removeChild(node);
21036 if (!node.attributes || !node.attributes.length) {
21037 this.cleanUpChildren(node);
21041 function cleanAttr(n,v)
21044 if (v.match(/^\./) || v.match(/^\//)) {
21047 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/)) {
21050 if (v.match(/^#/)) {
21053 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
21054 node.removeAttribute(n);
21058 var cwhite = this.cwhite;
21059 var cblack = this.cblack;
21061 function cleanStyle(n,v)
21063 if (v.match(/expression/)) { //XSS?? should we even bother..
21064 node.removeAttribute(n);
21068 var parts = v.split(/;/);
21071 Roo.each(parts, function(p) {
21072 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
21076 var l = p.split(':').shift().replace(/\s+/g,'');
21077 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
21079 if ( cwhite.length && cblack.indexOf(l) > -1) {
21080 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
21081 //node.removeAttribute(n);
21085 // only allow 'c whitelisted system attributes'
21086 if ( cwhite.length && cwhite.indexOf(l) < 0) {
21087 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
21088 //node.removeAttribute(n);
21098 if (clean.length) {
21099 node.setAttribute(n, clean.join(';'));
21101 node.removeAttribute(n);
21107 for (var i = node.attributes.length-1; i > -1 ; i--) {
21108 var a = node.attributes[i];
21111 if (a.name.toLowerCase().substr(0,2)=='on') {
21112 node.removeAttribute(a.name);
21115 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
21116 node.removeAttribute(a.name);
21119 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
21120 cleanAttr(a.name,a.value); // fixme..
21123 if (a.name == 'style') {
21124 cleanStyle(a.name,a.value);
21127 /// clean up MS crap..
21128 // tecnically this should be a list of valid class'es..
21131 if (a.name == 'class') {
21132 if (a.value.match(/^Mso/)) {
21133 node.className = '';
21136 if (a.value.match(/body/)) {
21137 node.className = '';
21148 this.cleanUpChildren(node);
21154 * Clean up MS wordisms...
21156 cleanWord : function(node)
21161 this.cleanWord(this.doc.body);
21164 if (node.nodeName == "#text") {
21165 // clean up silly Windows -- stuff?
21168 if (node.nodeName == "#comment") {
21169 node.parentNode.removeChild(node);
21170 // clean up silly Windows -- stuff?
21174 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
21175 node.parentNode.removeChild(node);
21179 // remove - but keep children..
21180 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
21181 while (node.childNodes.length) {
21182 var cn = node.childNodes[0];
21183 node.removeChild(cn);
21184 node.parentNode.insertBefore(cn, node);
21186 node.parentNode.removeChild(node);
21187 this.iterateChildren(node, this.cleanWord);
21191 if (node.className.length) {
21193 var cn = node.className.split(/\W+/);
21195 Roo.each(cn, function(cls) {
21196 if (cls.match(/Mso[a-zA-Z]+/)) {
21201 node.className = cna.length ? cna.join(' ') : '';
21203 node.removeAttribute("class");
21207 if (node.hasAttribute("lang")) {
21208 node.removeAttribute("lang");
21211 if (node.hasAttribute("style")) {
21213 var styles = node.getAttribute("style").split(";");
21215 Roo.each(styles, function(s) {
21216 if (!s.match(/:/)) {
21219 var kv = s.split(":");
21220 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
21223 // what ever is left... we allow.
21226 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
21227 if (!nstyle.length) {
21228 node.removeAttribute('style');
21231 this.iterateChildren(node, this.cleanWord);
21237 * iterateChildren of a Node, calling fn each time, using this as the scole..
21238 * @param {DomNode} node node to iterate children of.
21239 * @param {Function} fn method of this class to call on each item.
21241 iterateChildren : function(node, fn)
21243 if (!node.childNodes.length) {
21246 for (var i = node.childNodes.length-1; i > -1 ; i--) {
21247 fn.call(this, node.childNodes[i])
21253 * cleanTableWidths.
21255 * Quite often pasting from word etc.. results in tables with column and widths.
21256 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
21259 cleanTableWidths : function(node)
21264 this.cleanTableWidths(this.doc.body);
21269 if (node.nodeName == "#text" || node.nodeName == "#comment") {
21272 Roo.log(node.tagName);
21273 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
21274 this.iterateChildren(node, this.cleanTableWidths);
21277 if (node.hasAttribute('width')) {
21278 node.removeAttribute('width');
21282 if (node.hasAttribute("style")) {
21285 var styles = node.getAttribute("style").split(";");
21287 Roo.each(styles, function(s) {
21288 if (!s.match(/:/)) {
21291 var kv = s.split(":");
21292 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
21295 // what ever is left... we allow.
21298 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
21299 if (!nstyle.length) {
21300 node.removeAttribute('style');
21304 this.iterateChildren(node, this.cleanTableWidths);
21312 domToHTML : function(currentElement, depth, nopadtext) {
21314 depth = depth || 0;
21315 nopadtext = nopadtext || false;
21317 if (!currentElement) {
21318 return this.domToHTML(this.doc.body);
21321 //Roo.log(currentElement);
21323 var allText = false;
21324 var nodeName = currentElement.nodeName;
21325 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
21327 if (nodeName == '#text') {
21329 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
21334 if (nodeName != 'BODY') {
21337 // Prints the node tagName, such as <A>, <IMG>, etc
21340 for(i = 0; i < currentElement.attributes.length;i++) {
21342 var aname = currentElement.attributes.item(i).name;
21343 if (!currentElement.attributes.item(i).value.length) {
21346 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
21349 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
21358 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
21361 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
21366 // Traverse the tree
21368 var currentElementChild = currentElement.childNodes.item(i);
21369 var allText = true;
21370 var innerHTML = '';
21372 while (currentElementChild) {
21373 // Formatting code (indent the tree so it looks nice on the screen)
21374 var nopad = nopadtext;
21375 if (lastnode == 'SPAN') {
21379 if (currentElementChild.nodeName == '#text') {
21380 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
21381 toadd = nopadtext ? toadd : toadd.trim();
21382 if (!nopad && toadd.length > 80) {
21383 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
21385 innerHTML += toadd;
21388 currentElementChild = currentElement.childNodes.item(i);
21394 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
21396 // Recursively traverse the tree structure of the child node
21397 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
21398 lastnode = currentElementChild.nodeName;
21400 currentElementChild=currentElement.childNodes.item(i);
21406 // The remaining code is mostly for formatting the tree
21407 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
21412 ret+= "</"+tagName+">";
21418 applyBlacklists : function()
21420 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
21421 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
21425 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
21426 if (b.indexOf(tag) > -1) {
21429 this.white.push(tag);
21433 Roo.each(w, function(tag) {
21434 if (b.indexOf(tag) > -1) {
21437 if (this.white.indexOf(tag) > -1) {
21440 this.white.push(tag);
21445 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
21446 if (w.indexOf(tag) > -1) {
21449 this.black.push(tag);
21453 Roo.each(b, function(tag) {
21454 if (w.indexOf(tag) > -1) {
21457 if (this.black.indexOf(tag) > -1) {
21460 this.black.push(tag);
21465 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
21466 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
21470 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
21471 if (b.indexOf(tag) > -1) {
21474 this.cwhite.push(tag);
21478 Roo.each(w, function(tag) {
21479 if (b.indexOf(tag) > -1) {
21482 if (this.cwhite.indexOf(tag) > -1) {
21485 this.cwhite.push(tag);
21490 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
21491 if (w.indexOf(tag) > -1) {
21494 this.cblack.push(tag);
21498 Roo.each(b, function(tag) {
21499 if (w.indexOf(tag) > -1) {
21502 if (this.cblack.indexOf(tag) > -1) {
21505 this.cblack.push(tag);
21510 setStylesheets : function(stylesheets)
21512 if(typeof(stylesheets) == 'string'){
21513 Roo.get(this.iframe.contentDocument.head).createChild({
21515 rel : 'stylesheet',
21524 Roo.each(stylesheets, function(s) {
21529 Roo.get(_this.iframe.contentDocument.head).createChild({
21531 rel : 'stylesheet',
21540 removeStylesheets : function()
21544 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
21549 // hide stuff that is not compatible
21563 * @event specialkey
21567 * @cfg {String} fieldClass @hide
21570 * @cfg {String} focusClass @hide
21573 * @cfg {String} autoCreate @hide
21576 * @cfg {String} inputType @hide
21579 * @cfg {String} invalidClass @hide
21582 * @cfg {String} invalidText @hide
21585 * @cfg {String} msgFx @hide
21588 * @cfg {String} validateOnBlur @hide
21592 Roo.HtmlEditorCore.white = [
21593 'area', 'br', 'img', 'input', 'hr', 'wbr',
21595 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
21596 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
21597 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
21598 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
21599 'table', 'ul', 'xmp',
21601 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
21604 'dir', 'menu', 'ol', 'ul', 'dl',
21610 Roo.HtmlEditorCore.black = [
21611 // 'embed', 'object', // enable - backend responsiblity to clean thiese
21613 'base', 'basefont', 'bgsound', 'blink', 'body',
21614 'frame', 'frameset', 'head', 'html', 'ilayer',
21615 'iframe', 'layer', 'link', 'meta', 'object',
21616 'script', 'style' ,'title', 'xml' // clean later..
21618 Roo.HtmlEditorCore.clean = [
21619 'script', 'style', 'title', 'xml'
21621 Roo.HtmlEditorCore.remove = [
21626 Roo.HtmlEditorCore.ablack = [
21630 Roo.HtmlEditorCore.aclean = [
21631 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
21635 Roo.HtmlEditorCore.pwhite= [
21636 'http', 'https', 'mailto'
21639 // white listed style attributes.
21640 Roo.HtmlEditorCore.cwhite= [
21641 // 'text-align', /// default is to allow most things..
21647 // black listed style attributes.
21648 Roo.HtmlEditorCore.cblack= [
21649 // 'font-size' -- this can be set by the project
21653 Roo.HtmlEditorCore.swapCodes =[
21672 * @class Roo.bootstrap.HtmlEditor
21673 * @extends Roo.bootstrap.TextArea
21674 * Bootstrap HtmlEditor class
21677 * Create a new HtmlEditor
21678 * @param {Object} config The config object
21681 Roo.bootstrap.HtmlEditor = function(config){
21682 Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
21683 if (!this.toolbars) {
21684 this.toolbars = [];
21686 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
21689 * @event initialize
21690 * Fires when the editor is fully initialized (including the iframe)
21691 * @param {HtmlEditor} this
21696 * Fires when the editor is first receives the focus. Any insertion must wait
21697 * until after this event.
21698 * @param {HtmlEditor} this
21702 * @event beforesync
21703 * Fires before the textarea is updated with content from the editor iframe. Return false
21704 * to cancel the sync.
21705 * @param {HtmlEditor} this
21706 * @param {String} html
21710 * @event beforepush
21711 * Fires before the iframe editor is updated with content from the textarea. Return false
21712 * to cancel the push.
21713 * @param {HtmlEditor} this
21714 * @param {String} html
21719 * Fires when the textarea is updated with content from the editor iframe.
21720 * @param {HtmlEditor} this
21721 * @param {String} html
21726 * Fires when the iframe editor is updated with content from the textarea.
21727 * @param {HtmlEditor} this
21728 * @param {String} html
21732 * @event editmodechange
21733 * Fires when the editor switches edit modes
21734 * @param {HtmlEditor} this
21735 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
21737 editmodechange: true,
21739 * @event editorevent
21740 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
21741 * @param {HtmlEditor} this
21745 * @event firstfocus
21746 * Fires when on first focus - needed by toolbars..
21747 * @param {HtmlEditor} this
21752 * Auto save the htmlEditor value as a file into Events
21753 * @param {HtmlEditor} this
21757 * @event savedpreview
21758 * preview the saved version of htmlEditor
21759 * @param {HtmlEditor} this
21766 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
21770 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
21775 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
21780 * @cfg {Number} height (in pixels)
21784 * @cfg {Number} width (in pixels)
21789 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
21792 stylesheets: false,
21797 // private properties
21798 validationEvent : false,
21800 initialized : false,
21803 onFocus : Roo.emptyFn,
21805 hideMode:'offsets',
21808 tbContainer : false,
21810 toolbarContainer :function() {
21811 return this.wrap.select('.x-html-editor-tb',true).first();
21815 * Protected method that will not generally be called directly. It
21816 * is called when the editor creates its toolbar. Override this method if you need to
21817 * add custom toolbar buttons.
21818 * @param {HtmlEditor} editor
21820 createToolbar : function(){
21822 Roo.log("create toolbars");
21824 this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
21825 this.toolbars[0].render(this.toolbarContainer());
21829 // if (!editor.toolbars || !editor.toolbars.length) {
21830 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
21833 // for (var i =0 ; i < editor.toolbars.length;i++) {
21834 // editor.toolbars[i] = Roo.factory(
21835 // typeof(editor.toolbars[i]) == 'string' ?
21836 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
21837 // Roo.bootstrap.HtmlEditor);
21838 // editor.toolbars[i].init(editor);
21844 onRender : function(ct, position)
21846 // Roo.log("Call onRender: " + this.xtype);
21848 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
21850 this.wrap = this.inputEl().wrap({
21851 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
21854 this.editorcore.onRender(ct, position);
21856 if (this.resizable) {
21857 this.resizeEl = new Roo.Resizable(this.wrap, {
21861 minHeight : this.height,
21862 height: this.height,
21863 handles : this.resizable,
21866 resize : function(r, w, h) {
21867 _t.onResize(w,h); // -something
21873 this.createToolbar(this);
21876 if(!this.width && this.resizable){
21877 this.setSize(this.wrap.getSize());
21879 if (this.resizeEl) {
21880 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
21881 // should trigger onReize..
21887 onResize : function(w, h)
21889 Roo.log('resize: ' +w + ',' + h );
21890 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
21894 if(this.inputEl() ){
21895 if(typeof w == 'number'){
21896 var aw = w - this.wrap.getFrameWidth('lr');
21897 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
21900 if(typeof h == 'number'){
21901 var tbh = -11; // fixme it needs to tool bar size!
21902 for (var i =0; i < this.toolbars.length;i++) {
21903 // fixme - ask toolbars for heights?
21904 tbh += this.toolbars[i].el.getHeight();
21905 //if (this.toolbars[i].footer) {
21906 // tbh += this.toolbars[i].footer.el.getHeight();
21914 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
21915 ah -= 5; // knock a few pixes off for look..
21916 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
21920 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
21921 this.editorcore.onResize(ew,eh);
21926 * Toggles the editor between standard and source edit mode.
21927 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21929 toggleSourceEdit : function(sourceEditMode)
21931 this.editorcore.toggleSourceEdit(sourceEditMode);
21933 if(this.editorcore.sourceEditMode){
21934 Roo.log('editor - showing textarea');
21937 // Roo.log(this.syncValue());
21939 this.inputEl().removeClass(['hide', 'x-hidden']);
21940 this.inputEl().dom.removeAttribute('tabIndex');
21941 this.inputEl().focus();
21943 Roo.log('editor - hiding textarea');
21945 // Roo.log(this.pushValue());
21948 this.inputEl().addClass(['hide', 'x-hidden']);
21949 this.inputEl().dom.setAttribute('tabIndex', -1);
21950 //this.deferFocus();
21953 if(this.resizable){
21954 this.setSize(this.wrap.getSize());
21957 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
21960 // private (for BoxComponent)
21961 adjustSize : Roo.BoxComponent.prototype.adjustSize,
21963 // private (for BoxComponent)
21964 getResizeEl : function(){
21968 // private (for BoxComponent)
21969 getPositionEl : function(){
21974 initEvents : function(){
21975 this.originalValue = this.getValue();
21979 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
21982 // markInvalid : Roo.emptyFn,
21984 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
21987 // clearInvalid : Roo.emptyFn,
21989 setValue : function(v){
21990 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
21991 this.editorcore.pushValue();
21996 deferFocus : function(){
21997 this.focus.defer(10, this);
22001 focus : function(){
22002 this.editorcore.focus();
22008 onDestroy : function(){
22014 for (var i =0; i < this.toolbars.length;i++) {
22015 // fixme - ask toolbars for heights?
22016 this.toolbars[i].onDestroy();
22019 this.wrap.dom.innerHTML = '';
22020 this.wrap.remove();
22025 onFirstFocus : function(){
22026 //Roo.log("onFirstFocus");
22027 this.editorcore.onFirstFocus();
22028 for (var i =0; i < this.toolbars.length;i++) {
22029 this.toolbars[i].onFirstFocus();
22035 syncValue : function()
22037 this.editorcore.syncValue();
22040 pushValue : function()
22042 this.editorcore.pushValue();
22046 // hide stuff that is not compatible
22060 * @event specialkey
22064 * @cfg {String} fieldClass @hide
22067 * @cfg {String} focusClass @hide
22070 * @cfg {String} autoCreate @hide
22073 * @cfg {String} inputType @hide
22076 * @cfg {String} invalidClass @hide
22079 * @cfg {String} invalidText @hide
22082 * @cfg {String} msgFx @hide
22085 * @cfg {String} validateOnBlur @hide
22094 Roo.namespace('Roo.bootstrap.htmleditor');
22096 * @class Roo.bootstrap.HtmlEditorToolbar1
22101 new Roo.bootstrap.HtmlEditor({
22104 new Roo.bootstrap.HtmlEditorToolbar1({
22105 disable : { fonts: 1 , format: 1, ..., ... , ...],
22111 * @cfg {Object} disable List of elements to disable..
22112 * @cfg {Array} btns List of additional buttons.
22116 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
22119 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
22122 Roo.apply(this, config);
22124 // default disabled, based on 'good practice'..
22125 this.disable = this.disable || {};
22126 Roo.applyIf(this.disable, {
22129 specialElements : true
22131 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
22133 this.editor = config.editor;
22134 this.editorcore = config.editor.editorcore;
22136 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
22138 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
22139 // dont call parent... till later.
22141 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.NavSimplebar, {
22146 editorcore : false,
22151 "h1","h2","h3","h4","h5","h6",
22153 "abbr", "acronym", "address", "cite", "samp", "var",
22157 onRender : function(ct, position)
22159 // Roo.log("Call onRender: " + this.xtype);
22161 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
22163 this.el.dom.style.marginBottom = '0';
22165 var editorcore = this.editorcore;
22166 var editor= this.editor;
22169 var btn = function(id,cmd , toggle, handler){
22171 var event = toggle ? 'toggle' : 'click';
22176 xns: Roo.bootstrap,
22179 enableToggle:toggle !== false,
22181 pressed : toggle ? false : null,
22184 a.listeners[toggle ? 'toggle' : 'click'] = function() {
22185 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
22194 xns: Roo.bootstrap,
22195 glyphicon : 'font',
22199 xns: Roo.bootstrap,
22203 Roo.each(this.formats, function(f) {
22204 style.menu.items.push({
22206 xns: Roo.bootstrap,
22207 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
22212 editorcore.insertTag(this.tagname);
22219 children.push(style);
22222 btn('bold',false,true);
22223 btn('italic',false,true);
22224 btn('align-left', 'justifyleft',true);
22225 btn('align-center', 'justifycenter',true);
22226 btn('align-right' , 'justifyright',true);
22227 btn('link', false, false, function(btn) {
22228 //Roo.log("create link?");
22229 var url = prompt(this.createLinkText, this.defaultLinkValue);
22230 if(url && url != 'http:/'+'/'){
22231 this.editorcore.relayCmd('createlink', url);
22234 btn('list','insertunorderedlist',true);
22235 btn('pencil', false,true, function(btn){
22238 this.toggleSourceEdit(btn.pressed);
22244 xns: Roo.bootstrap,
22249 xns: Roo.bootstrap,
22254 cog.menu.items.push({
22256 xns: Roo.bootstrap,
22257 html : Clean styles,
22262 editorcore.insertTag(this.tagname);
22271 this.xtype = 'NavSimplebar';
22273 for(var i=0;i< children.length;i++) {
22275 this.buttons.add(this.addxtypeChild(children[i]));
22279 editor.on('editorevent', this.updateToolbar, this);
22281 onBtnClick : function(id)
22283 this.editorcore.relayCmd(id);
22284 this.editorcore.focus();
22288 * Protected method that will not generally be called directly. It triggers
22289 * a toolbar update by reading the markup state of the current selection in the editor.
22291 updateToolbar: function(){
22293 if(!this.editorcore.activated){
22294 this.editor.onFirstFocus(); // is this neeed?
22298 var btns = this.buttons;
22299 var doc = this.editorcore.doc;
22300 btns.get('bold').setActive(doc.queryCommandState('bold'));
22301 btns.get('italic').setActive(doc.queryCommandState('italic'));
22302 //btns.get('underline').setActive(doc.queryCommandState('underline'));
22304 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
22305 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
22306 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
22308 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
22309 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
22312 var ans = this.editorcore.getAllAncestors();
22313 if (this.formatCombo) {
22316 var store = this.formatCombo.store;
22317 this.formatCombo.setValue("");
22318 for (var i =0; i < ans.length;i++) {
22319 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
22321 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
22329 // hides menus... - so this cant be on a menu...
22330 Roo.bootstrap.MenuMgr.hideAll();
22332 Roo.bootstrap.MenuMgr.hideAll();
22333 //this.editorsyncValue();
22335 onFirstFocus: function() {
22336 this.buttons.each(function(item){
22340 toggleSourceEdit : function(sourceEditMode){
22343 if(sourceEditMode){
22344 Roo.log("disabling buttons");
22345 this.buttons.each( function(item){
22346 if(item.cmd != 'pencil'){
22352 Roo.log("enabling buttons");
22353 if(this.editorcore.initialized){
22354 this.buttons.each( function(item){
22360 Roo.log("calling toggole on editor");
22361 // tell the editor that it's been pressed..
22362 this.editor.toggleSourceEdit(sourceEditMode);
22372 * @class Roo.bootstrap.Table.AbstractSelectionModel
22373 * @extends Roo.util.Observable
22374 * Abstract base class for grid SelectionModels. It provides the interface that should be
22375 * implemented by descendant classes. This class should not be directly instantiated.
22378 Roo.bootstrap.Table.AbstractSelectionModel = function(){
22379 this.locked = false;
22380 Roo.bootstrap.Table.AbstractSelectionModel.superclass.constructor.call(this);
22384 Roo.extend(Roo.bootstrap.Table.AbstractSelectionModel, Roo.util.Observable, {
22385 /** @ignore Called by the grid automatically. Do not call directly. */
22386 init : function(grid){
22392 * Locks the selections.
22395 this.locked = true;
22399 * Unlocks the selections.
22401 unlock : function(){
22402 this.locked = false;
22406 * Returns true if the selections are locked.
22407 * @return {Boolean}
22409 isLocked : function(){
22410 return this.locked;
22414 * @extends Roo.bootstrap.Table.AbstractSelectionModel
22415 * @class Roo.bootstrap.Table.RowSelectionModel
22416 * The default SelectionModel used by {@link Roo.bootstrap.Table}.
22417 * It supports multiple selections and keyboard selection/navigation.
22419 * @param {Object} config
22422 Roo.bootstrap.Table.RowSelectionModel = function(config){
22423 Roo.apply(this, config);
22424 this.selections = new Roo.util.MixedCollection(false, function(o){
22429 this.lastActive = false;
22433 * @event selectionchange
22434 * Fires when the selection changes
22435 * @param {SelectionModel} this
22437 "selectionchange" : true,
22439 * @event afterselectionchange
22440 * Fires after the selection changes (eg. by key press or clicking)
22441 * @param {SelectionModel} this
22443 "afterselectionchange" : true,
22445 * @event beforerowselect
22446 * Fires when a row is selected being selected, return false to cancel.
22447 * @param {SelectionModel} this
22448 * @param {Number} rowIndex The selected index
22449 * @param {Boolean} keepExisting False if other selections will be cleared
22451 "beforerowselect" : true,
22454 * Fires when a row is selected.
22455 * @param {SelectionModel} this
22456 * @param {Number} rowIndex The selected index
22457 * @param {Roo.data.Record} r The record
22459 "rowselect" : true,
22461 * @event rowdeselect
22462 * Fires when a row is deselected.
22463 * @param {SelectionModel} this
22464 * @param {Number} rowIndex The selected index
22466 "rowdeselect" : true
22468 Roo.bootstrap.Table.RowSelectionModel.superclass.constructor.call(this);
22469 this.locked = false;
22472 Roo.extend(Roo.bootstrap.Table.RowSelectionModel, Roo.bootstrap.Table.AbstractSelectionModel, {
22474 * @cfg {Boolean} singleSelect
22475 * True to allow selection of only one row at a time (defaults to false)
22477 singleSelect : false,
22480 initEvents : function()
22483 //if(!this.grid.enableDragDrop && !this.grid.enableDrag){
22484 // this.growclickrid.on("mousedown", this.handleMouseDown, this);
22485 //}else{ // allow click to work like normal
22486 // this.grid.on("rowclick", this.handleDragableRowClick, this);
22488 //this.grid.on("rowdblclick", this.handleMouseDBClick, this);
22489 this.grid.on("rowclick", this.handleMouseDown, this);
22491 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
22492 "up" : function(e){
22494 this.selectPrevious(e.shiftKey);
22495 }else if(this.last !== false && this.lastActive !== false){
22496 var last = this.last;
22497 this.selectRange(this.last, this.lastActive-1);
22498 this.grid.getView().focusRow(this.lastActive);
22499 if(last !== false){
22503 this.selectFirstRow();
22505 this.fireEvent("afterselectionchange", this);
22507 "down" : function(e){
22509 this.selectNext(e.shiftKey);
22510 }else if(this.last !== false && this.lastActive !== false){
22511 var last = this.last;
22512 this.selectRange(this.last, this.lastActive+1);
22513 this.grid.getView().focusRow(this.lastActive);
22514 if(last !== false){
22518 this.selectFirstRow();
22520 this.fireEvent("afterselectionchange", this);
22524 this.grid.store.on('load', function(){
22525 this.selections.clear();
22528 var view = this.grid.view;
22529 view.on("refresh", this.onRefresh, this);
22530 view.on("rowupdated", this.onRowUpdated, this);
22531 view.on("rowremoved", this.onRemove, this);
22536 onRefresh : function()
22538 var ds = this.grid.store, i, v = this.grid.view;
22539 var s = this.selections;
22540 s.each(function(r){
22541 if((i = ds.indexOfId(r.id)) != -1){
22550 onRemove : function(v, index, r){
22551 this.selections.remove(r);
22555 onRowUpdated : function(v, index, r){
22556 if(this.isSelected(r)){
22557 v.onRowSelect(index);
22563 * @param {Array} records The records to select
22564 * @param {Boolean} keepExisting (optional) True to keep existing selections
22566 selectRecords : function(records, keepExisting)
22569 this.clearSelections();
22571 var ds = this.grid.store;
22572 for(var i = 0, len = records.length; i < len; i++){
22573 this.selectRow(ds.indexOf(records[i]), true);
22578 * Gets the number of selected rows.
22581 getCount : function(){
22582 return this.selections.length;
22586 * Selects the first row in the grid.
22588 selectFirstRow : function(){
22593 * Select the last row.
22594 * @param {Boolean} keepExisting (optional) True to keep existing selections
22596 selectLastRow : function(keepExisting){
22597 //this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
22598 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
22602 * Selects the row immediately following the last selected row.
22603 * @param {Boolean} keepExisting (optional) True to keep existing selections
22605 selectNext : function(keepExisting)
22607 if(this.last !== false && (this.last+1) < this.grid.store.getCount()){
22608 this.selectRow(this.last+1, keepExisting);
22609 this.grid.getView().focusRow(this.last);
22614 * Selects the row that precedes the last selected row.
22615 * @param {Boolean} keepExisting (optional) True to keep existing selections
22617 selectPrevious : function(keepExisting){
22619 this.selectRow(this.last-1, keepExisting);
22620 this.grid.getView().focusRow(this.last);
22625 * Returns the selected records
22626 * @return {Array} Array of selected records
22628 getSelections : function(){
22629 return [].concat(this.selections.items);
22633 * Returns the first selected record.
22636 getSelected : function(){
22637 return this.selections.itemAt(0);
22642 * Clears all selections.
22644 clearSelections : function(fast)
22650 var ds = this.grid.store;
22651 var s = this.selections;
22652 s.each(function(r){
22653 this.deselectRow(ds.indexOfId(r.id));
22657 this.selections.clear();
22664 * Selects all rows.
22666 selectAll : function(){
22670 this.selections.clear();
22671 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
22672 this.selectRow(i, true);
22677 * Returns True if there is a selection.
22678 * @return {Boolean}
22680 hasSelection : function(){
22681 return this.selections.length > 0;
22685 * Returns True if the specified row is selected.
22686 * @param {Number/Record} record The record or index of the record to check
22687 * @return {Boolean}
22689 isSelected : function(index){
22690 var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
22691 return (r && this.selections.key(r.id) ? true : false);
22695 * Returns True if the specified record id is selected.
22696 * @param {String} id The id of record to check
22697 * @return {Boolean}
22699 isIdSelected : function(id){
22700 return (this.selections.key(id) ? true : false);
22705 handleMouseDBClick : function(e, t){
22709 handleMouseDown : function(e, t)
22711 var rowIndex = this.grid.headerShow ? t.dom.rowIndex - 1 : t.dom.rowIndex ; // first row is header???
22712 if(this.isLocked() || rowIndex < 0 ){
22715 if(e.shiftKey && this.last !== false){
22716 var last = this.last;
22717 this.selectRange(last, rowIndex, e.ctrlKey);
22718 this.last = last; // reset the last
22722 var isSelected = this.isSelected(rowIndex);
22723 //Roo.log("select row:" + rowIndex);
22725 this.deselectRow(rowIndex);
22727 this.selectRow(rowIndex, true);
22731 if(e.button !== 0 && isSelected){
22732 alert('rowIndex 2: ' + rowIndex);
22733 view.focusRow(rowIndex);
22734 }else if(e.ctrlKey && isSelected){
22735 this.deselectRow(rowIndex);
22736 }else if(!isSelected){
22737 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
22738 view.focusRow(rowIndex);
22742 this.fireEvent("afterselectionchange", this);
22745 handleDragableRowClick : function(grid, rowIndex, e)
22747 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
22748 this.selectRow(rowIndex, false);
22749 grid.view.focusRow(rowIndex);
22750 this.fireEvent("afterselectionchange", this);
22755 * Selects multiple rows.
22756 * @param {Array} rows Array of the indexes of the row to select
22757 * @param {Boolean} keepExisting (optional) True to keep existing selections
22759 selectRows : function(rows, keepExisting){
22761 this.clearSelections();
22763 for(var i = 0, len = rows.length; i < len; i++){
22764 this.selectRow(rows[i], true);
22769 * Selects a range of rows. All rows in between startRow and endRow are also selected.
22770 * @param {Number} startRow The index of the first row in the range
22771 * @param {Number} endRow The index of the last row in the range
22772 * @param {Boolean} keepExisting (optional) True to retain existing selections
22774 selectRange : function(startRow, endRow, keepExisting){
22779 this.clearSelections();
22781 if(startRow <= endRow){
22782 for(var i = startRow; i <= endRow; i++){
22783 this.selectRow(i, true);
22786 for(var i = startRow; i >= endRow; i--){
22787 this.selectRow(i, true);
22793 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
22794 * @param {Number} startRow The index of the first row in the range
22795 * @param {Number} endRow The index of the last row in the range
22797 deselectRange : function(startRow, endRow, preventViewNotify){
22801 for(var i = startRow; i <= endRow; i++){
22802 this.deselectRow(i, preventViewNotify);
22808 * @param {Number} row The index of the row to select
22809 * @param {Boolean} keepExisting (optional) True to keep existing selections
22811 selectRow : function(index, keepExisting, preventViewNotify)
22813 if(this.locked || (index < 0 || index > this.grid.store.getCount())) {
22816 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
22817 if(!keepExisting || this.singleSelect){
22818 this.clearSelections();
22821 var r = this.grid.store.getAt(index);
22822 //console.log('selectRow - record id :' + r.id);
22824 this.selections.add(r);
22825 this.last = this.lastActive = index;
22826 if(!preventViewNotify){
22827 var proxy = new Roo.Element(
22828 this.grid.getRowDom(index)
22830 proxy.addClass('bg-info info');
22832 this.fireEvent("rowselect", this, index, r);
22833 this.fireEvent("selectionchange", this);
22839 * @param {Number} row The index of the row to deselect
22841 deselectRow : function(index, preventViewNotify)
22846 if(this.last == index){
22849 if(this.lastActive == index){
22850 this.lastActive = false;
22853 var r = this.grid.store.getAt(index);
22858 this.selections.remove(r);
22859 //.console.log('deselectRow - record id :' + r.id);
22860 if(!preventViewNotify){
22862 var proxy = new Roo.Element(
22863 this.grid.getRowDom(index)
22865 proxy.removeClass('bg-info info');
22867 this.fireEvent("rowdeselect", this, index);
22868 this.fireEvent("selectionchange", this);
22872 restoreLast : function(){
22874 this.last = this._last;
22879 acceptsNav : function(row, col, cm){
22880 return !cm.isHidden(col) && cm.isCellEditable(col, row);
22884 onEditorKey : function(field, e){
22885 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
22890 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
22892 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
22894 }else if(k == e.ENTER && !e.ctrlKey){
22898 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
22900 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
22902 }else if(k == e.ESC){
22906 g.startEditing(newCell[0], newCell[1]);
22912 * Ext JS Library 1.1.1
22913 * Copyright(c) 2006-2007, Ext JS, LLC.
22915 * Originally Released Under LGPL - original licence link has changed is not relivant.
22918 * <script type="text/javascript">
22922 * @class Roo.bootstrap.PagingToolbar
22923 * @extends Roo.bootstrap.NavSimplebar
22924 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
22926 * Create a new PagingToolbar
22927 * @param {Object} config The config object
22928 * @param {Roo.data.Store} store
22930 Roo.bootstrap.PagingToolbar = function(config)
22932 // old args format still supported... - xtype is prefered..
22933 // created from xtype...
22935 this.ds = config.dataSource;
22937 if (config.store && !this.ds) {
22938 this.store= Roo.factory(config.store, Roo.data);
22939 this.ds = this.store;
22940 this.ds.xmodule = this.xmodule || false;
22943 this.toolbarItems = [];
22944 if (config.items) {
22945 this.toolbarItems = config.items;
22948 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
22953 this.bind(this.ds);
22956 this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
22960 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
22962 * @cfg {Roo.data.Store} dataSource
22963 * The underlying data store providing the paged data
22966 * @cfg {String/HTMLElement/Element} container
22967 * container The id or element that will contain the toolbar
22970 * @cfg {Boolean} displayInfo
22971 * True to display the displayMsg (defaults to false)
22974 * @cfg {Number} pageSize
22975 * The number of records to display per page (defaults to 20)
22979 * @cfg {String} displayMsg
22980 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
22982 displayMsg : 'Displaying {0} - {1} of {2}',
22984 * @cfg {String} emptyMsg
22985 * The message to display when no records are found (defaults to "No data to display")
22987 emptyMsg : 'No data to display',
22989 * Customizable piece of the default paging text (defaults to "Page")
22992 beforePageText : "Page",
22994 * Customizable piece of the default paging text (defaults to "of %0")
22997 afterPageText : "of {0}",
22999 * Customizable piece of the default paging text (defaults to "First Page")
23002 firstText : "First Page",
23004 * Customizable piece of the default paging text (defaults to "Previous Page")
23007 prevText : "Previous Page",
23009 * Customizable piece of the default paging text (defaults to "Next Page")
23012 nextText : "Next Page",
23014 * Customizable piece of the default paging text (defaults to "Last Page")
23017 lastText : "Last Page",
23019 * Customizable piece of the default paging text (defaults to "Refresh")
23022 refreshText : "Refresh",
23026 onRender : function(ct, position)
23028 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
23029 this.navgroup.parentId = this.id;
23030 this.navgroup.onRender(this.el, null);
23031 // add the buttons to the navgroup
23033 if(this.displayInfo){
23034 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
23035 this.displayEl = this.el.select('.x-paging-info', true).first();
23036 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
23037 // this.displayEl = navel.el.select('span',true).first();
23043 Roo.each(_this.buttons, function(e){ // this might need to use render????
23044 Roo.factory(e).onRender(_this.el, null);
23048 Roo.each(_this.toolbarItems, function(e) {
23049 _this.navgroup.addItem(e);
23053 this.first = this.navgroup.addItem({
23054 tooltip: this.firstText,
23056 icon : 'fa fa-backward',
23058 preventDefault: true,
23059 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
23062 this.prev = this.navgroup.addItem({
23063 tooltip: this.prevText,
23065 icon : 'fa fa-step-backward',
23067 preventDefault: true,
23068 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
23070 //this.addSeparator();
23073 var field = this.navgroup.addItem( {
23075 cls : 'x-paging-position',
23077 html : this.beforePageText +
23078 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
23079 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
23082 this.field = field.el.select('input', true).first();
23083 this.field.on("keydown", this.onPagingKeydown, this);
23084 this.field.on("focus", function(){this.dom.select();});
23087 this.afterTextEl = field.el.select('.x-paging-after',true).first();
23088 //this.field.setHeight(18);
23089 //this.addSeparator();
23090 this.next = this.navgroup.addItem({
23091 tooltip: this.nextText,
23093 html : ' <i class="fa fa-step-forward">',
23095 preventDefault: true,
23096 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
23098 this.last = this.navgroup.addItem({
23099 tooltip: this.lastText,
23100 icon : 'fa fa-forward',
23103 preventDefault: true,
23104 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
23106 //this.addSeparator();
23107 this.loading = this.navgroup.addItem({
23108 tooltip: this.refreshText,
23109 icon: 'fa fa-refresh',
23110 preventDefault: true,
23111 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
23117 updateInfo : function(){
23118 if(this.displayEl){
23119 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
23120 var msg = count == 0 ?
23124 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
23126 this.displayEl.update(msg);
23131 onLoad : function(ds, r, o){
23132 this.cursor = o.params ? o.params.start : 0;
23133 var d = this.getPageData(),
23137 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
23138 this.field.dom.value = ap;
23139 this.first.setDisabled(ap == 1);
23140 this.prev.setDisabled(ap == 1);
23141 this.next.setDisabled(ap == ps);
23142 this.last.setDisabled(ap == ps);
23143 this.loading.enable();
23148 getPageData : function(){
23149 var total = this.ds.getTotalCount();
23152 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
23153 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
23158 onLoadError : function(){
23159 this.loading.enable();
23163 onPagingKeydown : function(e){
23164 var k = e.getKey();
23165 var d = this.getPageData();
23167 var v = this.field.dom.value, pageNum;
23168 if(!v || isNaN(pageNum = parseInt(v, 10))){
23169 this.field.dom.value = d.activePage;
23172 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
23173 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
23176 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))
23178 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
23179 this.field.dom.value = pageNum;
23180 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
23183 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
23185 var v = this.field.dom.value, pageNum;
23186 var increment = (e.shiftKey) ? 10 : 1;
23187 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
23190 if(!v || isNaN(pageNum = parseInt(v, 10))) {
23191 this.field.dom.value = d.activePage;
23194 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
23196 this.field.dom.value = parseInt(v, 10) + increment;
23197 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
23198 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
23205 beforeLoad : function(){
23207 this.loading.disable();
23212 onClick : function(which){
23221 ds.load({params:{start: 0, limit: this.pageSize}});
23224 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
23227 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
23230 var total = ds.getTotalCount();
23231 var extra = total % this.pageSize;
23232 var lastStart = extra ? (total - extra) : total-this.pageSize;
23233 ds.load({params:{start: lastStart, limit: this.pageSize}});
23236 ds.load({params:{start: this.cursor, limit: this.pageSize}});
23242 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
23243 * @param {Roo.data.Store} store The data store to unbind
23245 unbind : function(ds){
23246 ds.un("beforeload", this.beforeLoad, this);
23247 ds.un("load", this.onLoad, this);
23248 ds.un("loadexception", this.onLoadError, this);
23249 ds.un("remove", this.updateInfo, this);
23250 ds.un("add", this.updateInfo, this);
23251 this.ds = undefined;
23255 * Binds the paging toolbar to the specified {@link Roo.data.Store}
23256 * @param {Roo.data.Store} store The data store to bind
23258 bind : function(ds){
23259 ds.on("beforeload", this.beforeLoad, this);
23260 ds.on("load", this.onLoad, this);
23261 ds.on("loadexception", this.onLoadError, this);
23262 ds.on("remove", this.updateInfo, this);
23263 ds.on("add", this.updateInfo, this);
23274 * @class Roo.bootstrap.MessageBar
23275 * @extends Roo.bootstrap.Component
23276 * Bootstrap MessageBar class
23277 * @cfg {String} html contents of the MessageBar
23278 * @cfg {String} weight (info | success | warning | danger) default info
23279 * @cfg {String} beforeClass insert the bar before the given class
23280 * @cfg {Boolean} closable (true | false) default false
23281 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
23284 * Create a new Element
23285 * @param {Object} config The config object
23288 Roo.bootstrap.MessageBar = function(config){
23289 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
23292 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
23298 beforeClass: 'bootstrap-sticky-wrap',
23300 getAutoCreate : function(){
23304 cls: 'alert alert-dismissable alert-' + this.weight,
23309 html: this.html || ''
23315 cfg.cls += ' alert-messages-fixed';
23329 onRender : function(ct, position)
23331 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
23334 var cfg = Roo.apply({}, this.getAutoCreate());
23338 cfg.cls += ' ' + this.cls;
23341 cfg.style = this.style;
23343 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
23345 this.el.setVisibilityMode(Roo.Element.DISPLAY);
23348 this.el.select('>button.close').on('click', this.hide, this);
23354 if (!this.rendered) {
23360 this.fireEvent('show', this);
23366 if (!this.rendered) {
23372 this.fireEvent('hide', this);
23375 update : function()
23377 // var e = this.el.dom.firstChild;
23379 // if(this.closable){
23380 // e = e.nextSibling;
23383 // e.data = this.html || '';
23385 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
23401 * @class Roo.bootstrap.Graph
23402 * @extends Roo.bootstrap.Component
23403 * Bootstrap Graph class
23407 @cfg {String} graphtype bar | vbar | pie
23408 @cfg {number} g_x coodinator | centre x (pie)
23409 @cfg {number} g_y coodinator | centre y (pie)
23410 @cfg {number} g_r radius (pie)
23411 @cfg {number} g_height height of the chart (respected by all elements in the set)
23412 @cfg {number} g_width width of the chart (respected by all elements in the set)
23413 @cfg {Object} title The title of the chart
23416 -opts (object) options for the chart
23418 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
23419 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
23421 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.
23422 o stacked (boolean) whether or not to tread values as in a stacked bar chart
23424 o stretch (boolean)
23426 -opts (object) options for the pie
23429 o startAngle (number)
23430 o endAngle (number)
23434 * Create a new Input
23435 * @param {Object} config The config object
23438 Roo.bootstrap.Graph = function(config){
23439 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
23445 * The img click event for the img.
23446 * @param {Roo.EventObject} e
23452 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
23463 //g_colors: this.colors,
23470 getAutoCreate : function(){
23481 onRender : function(ct,position){
23484 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
23486 if (typeof(Raphael) == 'undefined') {
23487 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
23491 this.raphael = Raphael(this.el.dom);
23493 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
23494 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
23495 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
23496 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
23498 r.text(160, 10, "Single Series Chart").attr(txtattr);
23499 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
23500 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
23501 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
23503 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
23504 r.barchart(330, 10, 300, 220, data1);
23505 r.barchart(10, 250, 300, 220, data2, {stacked: true});
23506 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
23509 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
23510 // r.barchart(30, 30, 560, 250, xdata, {
23511 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
23512 // axis : "0 0 1 1",
23513 // axisxlabels : xdata
23514 // //yvalues : cols,
23517 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
23519 // this.load(null,xdata,{
23520 // axis : "0 0 1 1",
23521 // axisxlabels : xdata
23526 load : function(graphtype,xdata,opts)
23528 this.raphael.clear();
23530 graphtype = this.graphtype;
23535 var r = this.raphael,
23536 fin = function () {
23537 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
23539 fout = function () {
23540 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
23542 pfin = function() {
23543 this.sector.stop();
23544 this.sector.scale(1.1, 1.1, this.cx, this.cy);
23547 this.label[0].stop();
23548 this.label[0].attr({ r: 7.5 });
23549 this.label[1].attr({ "font-weight": 800 });
23552 pfout = function() {
23553 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
23556 this.label[0].animate({ r: 5 }, 500, "bounce");
23557 this.label[1].attr({ "font-weight": 400 });
23563 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
23566 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
23569 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
23570 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
23572 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
23579 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
23584 setTitle: function(o)
23589 initEvents: function() {
23592 this.el.on('click', this.onClick, this);
23596 onClick : function(e)
23598 Roo.log('img onclick');
23599 this.fireEvent('click', this, e);
23611 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
23614 * @class Roo.bootstrap.dash.NumberBox
23615 * @extends Roo.bootstrap.Component
23616 * Bootstrap NumberBox class
23617 * @cfg {String} headline Box headline
23618 * @cfg {String} content Box content
23619 * @cfg {String} icon Box icon
23620 * @cfg {String} footer Footer text
23621 * @cfg {String} fhref Footer href
23624 * Create a new NumberBox
23625 * @param {Object} config The config object
23629 Roo.bootstrap.dash.NumberBox = function(config){
23630 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
23634 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
23643 getAutoCreate : function(){
23647 cls : 'small-box ',
23655 cls : 'roo-headline',
23656 html : this.headline
23660 cls : 'roo-content',
23661 html : this.content
23675 cls : 'ion ' + this.icon
23684 cls : 'small-box-footer',
23685 href : this.fhref || '#',
23689 cfg.cn.push(footer);
23696 onRender : function(ct,position){
23697 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
23704 setHeadline: function (value)
23706 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
23709 setFooter: function (value, href)
23711 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
23714 this.el.select('a.small-box-footer',true).first().attr('href', href);
23719 setContent: function (value)
23721 this.el.select('.roo-content',true).first().dom.innerHTML = value;
23724 initEvents: function()
23738 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
23741 * @class Roo.bootstrap.dash.TabBox
23742 * @extends Roo.bootstrap.Component
23743 * Bootstrap TabBox class
23744 * @cfg {String} title Title of the TabBox
23745 * @cfg {String} icon Icon of the TabBox
23746 * @cfg {Boolean} showtabs (true|false) show the tabs default true
23747 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
23750 * Create a new TabBox
23751 * @param {Object} config The config object
23755 Roo.bootstrap.dash.TabBox = function(config){
23756 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
23761 * When a pane is added
23762 * @param {Roo.bootstrap.dash.TabPane} pane
23766 * @event activatepane
23767 * When a pane is activated
23768 * @param {Roo.bootstrap.dash.TabPane} pane
23770 "activatepane" : true
23778 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
23783 tabScrollable : false,
23785 getChildContainer : function()
23787 return this.el.select('.tab-content', true).first();
23790 getAutoCreate : function(){
23794 cls: 'pull-left header',
23802 cls: 'fa ' + this.icon
23808 cls: 'nav nav-tabs pull-right',
23814 if(this.tabScrollable){
23821 cls: 'nav nav-tabs pull-right',
23832 cls: 'nav-tabs-custom',
23837 cls: 'tab-content no-padding',
23845 initEvents : function()
23847 //Roo.log('add add pane handler');
23848 this.on('addpane', this.onAddPane, this);
23851 * Updates the box title
23852 * @param {String} html to set the title to.
23854 setTitle : function(value)
23856 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
23858 onAddPane : function(pane)
23860 this.panes.push(pane);
23861 //Roo.log('addpane');
23863 // tabs are rendere left to right..
23864 if(!this.showtabs){
23868 var ctr = this.el.select('.nav-tabs', true).first();
23871 var existing = ctr.select('.nav-tab',true);
23872 var qty = existing.getCount();;
23875 var tab = ctr.createChild({
23877 cls : 'nav-tab' + (qty ? '' : ' active'),
23885 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
23888 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
23890 pane.el.addClass('active');
23895 onTabClick : function(ev,un,ob,pane)
23897 //Roo.log('tab - prev default');
23898 ev.preventDefault();
23901 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
23902 pane.tab.addClass('active');
23903 //Roo.log(pane.title);
23904 this.getChildContainer().select('.tab-pane',true).removeClass('active');
23905 // technically we should have a deactivate event.. but maybe add later.
23906 // and it should not de-activate the selected tab...
23907 this.fireEvent('activatepane', pane);
23908 pane.el.addClass('active');
23909 pane.fireEvent('activate');
23914 getActivePane : function()
23917 Roo.each(this.panes, function(p) {
23918 if(p.el.hasClass('active')){
23939 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
23941 * @class Roo.bootstrap.TabPane
23942 * @extends Roo.bootstrap.Component
23943 * Bootstrap TabPane class
23944 * @cfg {Boolean} active (false | true) Default false
23945 * @cfg {String} title title of panel
23949 * Create a new TabPane
23950 * @param {Object} config The config object
23953 Roo.bootstrap.dash.TabPane = function(config){
23954 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
23960 * When a pane is activated
23961 * @param {Roo.bootstrap.dash.TabPane} pane
23968 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
23973 // the tabBox that this is attached to.
23976 getAutoCreate : function()
23984 cfg.cls += ' active';
23989 initEvents : function()
23991 //Roo.log('trigger add pane handler');
23992 this.parent().fireEvent('addpane', this)
23996 * Updates the tab title
23997 * @param {String} html to set the title to.
23999 setTitle: function(str)
24005 this.tab.select('a', true).first().dom.innerHTML = str;
24022 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
24025 * @class Roo.bootstrap.menu.Menu
24026 * @extends Roo.bootstrap.Component
24027 * Bootstrap Menu class - container for Menu
24028 * @cfg {String} html Text of the menu
24029 * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
24030 * @cfg {String} icon Font awesome icon
24031 * @cfg {String} pos Menu align to (top | bottom) default bottom
24035 * Create a new Menu
24036 * @param {Object} config The config object
24040 Roo.bootstrap.menu.Menu = function(config){
24041 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
24045 * @event beforeshow
24046 * Fires before this menu is displayed
24047 * @param {Roo.bootstrap.menu.Menu} this
24051 * @event beforehide
24052 * Fires before this menu is hidden
24053 * @param {Roo.bootstrap.menu.Menu} this
24058 * Fires after this menu is displayed
24059 * @param {Roo.bootstrap.menu.Menu} this
24064 * Fires after this menu is hidden
24065 * @param {Roo.bootstrap.menu.Menu} this
24070 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
24071 * @param {Roo.bootstrap.menu.Menu} this
24072 * @param {Roo.EventObject} e
24079 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
24083 weight : 'default',
24088 getChildContainer : function() {
24089 if(this.isSubMenu){
24093 return this.el.select('ul.dropdown-menu', true).first();
24096 getAutoCreate : function()
24101 cls : 'roo-menu-text',
24109 cls : 'fa ' + this.icon
24120 cls : 'dropdown-button btn btn-' + this.weight,
24125 cls : 'dropdown-toggle btn btn-' + this.weight,
24135 cls : 'dropdown-menu'
24141 if(this.pos == 'top'){
24142 cfg.cls += ' dropup';
24145 if(this.isSubMenu){
24148 cls : 'dropdown-menu'
24155 onRender : function(ct, position)
24157 this.isSubMenu = ct.hasClass('dropdown-submenu');
24159 Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
24162 initEvents : function()
24164 if(this.isSubMenu){
24168 this.hidden = true;
24170 this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
24171 this.triggerEl.on('click', this.onTriggerPress, this);
24173 this.buttonEl = this.el.select('button.dropdown-button', true).first();
24174 this.buttonEl.on('click', this.onClick, this);
24180 if(this.isSubMenu){
24184 return this.el.select('ul.dropdown-menu', true).first();
24187 onClick : function(e)
24189 this.fireEvent("click", this, e);
24192 onTriggerPress : function(e)
24194 if (this.isVisible()) {
24201 isVisible : function(){
24202 return !this.hidden;
24207 this.fireEvent("beforeshow", this);
24209 this.hidden = false;
24210 this.el.addClass('open');
24212 Roo.get(document).on("mouseup", this.onMouseUp, this);
24214 this.fireEvent("show", this);
24221 this.fireEvent("beforehide", this);
24223 this.hidden = true;
24224 this.el.removeClass('open');
24226 Roo.get(document).un("mouseup", this.onMouseUp);
24228 this.fireEvent("hide", this);
24231 onMouseUp : function()
24245 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
24248 * @class Roo.bootstrap.menu.Item
24249 * @extends Roo.bootstrap.Component
24250 * Bootstrap MenuItem class
24251 * @cfg {Boolean} submenu (true | false) default false
24252 * @cfg {String} html text of the item
24253 * @cfg {String} href the link
24254 * @cfg {Boolean} disable (true | false) default false
24255 * @cfg {Boolean} preventDefault (true | false) default true
24256 * @cfg {String} icon Font awesome icon
24257 * @cfg {String} pos Submenu align to (left | right) default right
24261 * Create a new Item
24262 * @param {Object} config The config object
24266 Roo.bootstrap.menu.Item = function(config){
24267 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
24271 * Fires when the mouse is hovering over this menu
24272 * @param {Roo.bootstrap.menu.Item} this
24273 * @param {Roo.EventObject} e
24278 * Fires when the mouse exits this menu
24279 * @param {Roo.bootstrap.menu.Item} this
24280 * @param {Roo.EventObject} e
24286 * The raw click event for the entire grid.
24287 * @param {Roo.EventObject} e
24293 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
24298 preventDefault: true,
24303 getAutoCreate : function()
24308 cls : 'roo-menu-item-text',
24316 cls : 'fa ' + this.icon
24325 href : this.href || '#',
24332 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
24336 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
24338 if(this.pos == 'left'){
24339 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
24346 initEvents : function()
24348 this.el.on('mouseover', this.onMouseOver, this);
24349 this.el.on('mouseout', this.onMouseOut, this);
24351 this.el.select('a', true).first().on('click', this.onClick, this);
24355 onClick : function(e)
24357 if(this.preventDefault){
24358 e.preventDefault();
24361 this.fireEvent("click", this, e);
24364 onMouseOver : function(e)
24366 if(this.submenu && this.pos == 'left'){
24367 this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
24370 this.fireEvent("mouseover", this, e);
24373 onMouseOut : function(e)
24375 this.fireEvent("mouseout", this, e);
24387 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
24390 * @class Roo.bootstrap.menu.Separator
24391 * @extends Roo.bootstrap.Component
24392 * Bootstrap Separator class
24395 * Create a new Separator
24396 * @param {Object} config The config object
24400 Roo.bootstrap.menu.Separator = function(config){
24401 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
24404 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
24406 getAutoCreate : function(){
24427 * @class Roo.bootstrap.Tooltip
24428 * Bootstrap Tooltip class
24429 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
24430 * to determine which dom element triggers the tooltip.
24432 * It needs to add support for additional attributes like tooltip-position
24435 * Create a new Toolti
24436 * @param {Object} config The config object
24439 Roo.bootstrap.Tooltip = function(config){
24440 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
24443 Roo.apply(Roo.bootstrap.Tooltip, {
24445 * @function init initialize tooltip monitoring.
24449 currentTip : false,
24450 currentRegion : false,
24456 Roo.get(document).on('mouseover', this.enter ,this);
24457 Roo.get(document).on('mouseout', this.leave, this);
24460 this.currentTip = new Roo.bootstrap.Tooltip();
24463 enter : function(ev)
24465 var dom = ev.getTarget();
24467 //Roo.log(['enter',dom]);
24468 var el = Roo.fly(dom);
24469 if (this.currentEl) {
24471 //Roo.log(this.currentEl);
24472 //Roo.log(this.currentEl.contains(dom));
24473 if (this.currentEl == el) {
24476 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
24482 if (this.currentTip.el) {
24483 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
24487 if(!el || el.dom == document){
24493 // you can not look for children, as if el is the body.. then everythign is the child..
24494 if (!el.attr('tooltip')) { //
24495 if (!el.select("[tooltip]").elements.length) {
24498 // is the mouse over this child...?
24499 bindEl = el.select("[tooltip]").first();
24500 var xy = ev.getXY();
24501 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
24502 //Roo.log("not in region.");
24505 //Roo.log("child element over..");
24508 this.currentEl = bindEl;
24509 this.currentTip.bind(bindEl);
24510 this.currentRegion = Roo.lib.Region.getRegion(dom);
24511 this.currentTip.enter();
24514 leave : function(ev)
24516 var dom = ev.getTarget();
24517 //Roo.log(['leave',dom]);
24518 if (!this.currentEl) {
24523 if (dom != this.currentEl.dom) {
24526 var xy = ev.getXY();
24527 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
24530 // only activate leave if mouse cursor is outside... bounding box..
24535 if (this.currentTip) {
24536 this.currentTip.leave();
24538 //Roo.log('clear currentEl');
24539 this.currentEl = false;
24544 'left' : ['r-l', [-2,0], 'right'],
24545 'right' : ['l-r', [2,0], 'left'],
24546 'bottom' : ['t-b', [0,2], 'top'],
24547 'top' : [ 'b-t', [0,-2], 'bottom']
24553 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
24558 delay : null, // can be { show : 300 , hide: 500}
24562 hoverState : null, //???
24564 placement : 'bottom',
24566 getAutoCreate : function(){
24573 cls : 'tooltip-arrow'
24576 cls : 'tooltip-inner'
24583 bind : function(el)
24589 enter : function () {
24591 if (this.timeout != null) {
24592 clearTimeout(this.timeout);
24595 this.hoverState = 'in';
24596 //Roo.log("enter - show");
24597 if (!this.delay || !this.delay.show) {
24602 this.timeout = setTimeout(function () {
24603 if (_t.hoverState == 'in') {
24606 }, this.delay.show);
24610 clearTimeout(this.timeout);
24612 this.hoverState = 'out';
24613 if (!this.delay || !this.delay.hide) {
24619 this.timeout = setTimeout(function () {
24620 //Roo.log("leave - timeout");
24622 if (_t.hoverState == 'out') {
24624 Roo.bootstrap.Tooltip.currentEl = false;
24632 this.render(document.body);
24635 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
24637 var tip = this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
24639 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
24641 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
24643 var placement = typeof this.placement == 'function' ?
24644 this.placement.call(this, this.el, on_el) :
24647 var autoToken = /\s?auto?\s?/i;
24648 var autoPlace = autoToken.test(placement);
24650 placement = placement.replace(autoToken, '') || 'top';
24654 //this.el.setXY([0,0]);
24656 //this.el.dom.style.display='block';
24658 //this.el.appendTo(on_el);
24660 var p = this.getPosition();
24661 var box = this.el.getBox();
24667 var align = Roo.bootstrap.Tooltip.alignment[placement];
24669 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
24671 if(placement == 'top' || placement == 'bottom'){
24673 placement = 'right';
24676 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
24677 placement = 'left';
24680 var scroll = Roo.select('body', true).first().getScroll();
24682 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
24688 align = Roo.bootstrap.Tooltip.alignment[placement];
24690 this.el.alignTo(this.bindEl, align[0],align[1]);
24691 //var arrow = this.el.select('.arrow',true).first();
24692 //arrow.set(align[2],
24694 this.el.addClass(placement);
24696 this.el.addClass('in fade');
24698 this.hoverState = null;
24700 if (this.el.hasClass('fade')) {
24711 //this.el.setXY([0,0]);
24712 this.el.removeClass('in');
24728 * @class Roo.bootstrap.LocationPicker
24729 * @extends Roo.bootstrap.Component
24730 * Bootstrap LocationPicker class
24731 * @cfg {Number} latitude Position when init default 0
24732 * @cfg {Number} longitude Position when init default 0
24733 * @cfg {Number} zoom default 15
24734 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
24735 * @cfg {Boolean} mapTypeControl default false
24736 * @cfg {Boolean} disableDoubleClickZoom default false
24737 * @cfg {Boolean} scrollwheel default true
24738 * @cfg {Boolean} streetViewControl default false
24739 * @cfg {Number} radius default 0
24740 * @cfg {String} locationName
24741 * @cfg {Boolean} draggable default true
24742 * @cfg {Boolean} enableAutocomplete default false
24743 * @cfg {Boolean} enableReverseGeocode default true
24744 * @cfg {String} markerTitle
24747 * Create a new LocationPicker
24748 * @param {Object} config The config object
24752 Roo.bootstrap.LocationPicker = function(config){
24754 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
24759 * Fires when the picker initialized.
24760 * @param {Roo.bootstrap.LocationPicker} this
24761 * @param {Google Location} location
24765 * @event positionchanged
24766 * Fires when the picker position changed.
24767 * @param {Roo.bootstrap.LocationPicker} this
24768 * @param {Google Location} location
24770 positionchanged : true,
24773 * Fires when the map resize.
24774 * @param {Roo.bootstrap.LocationPicker} this
24779 * Fires when the map show.
24780 * @param {Roo.bootstrap.LocationPicker} this
24785 * Fires when the map hide.
24786 * @param {Roo.bootstrap.LocationPicker} this
24791 * Fires when click the map.
24792 * @param {Roo.bootstrap.LocationPicker} this
24793 * @param {Map event} e
24797 * @event mapRightClick
24798 * Fires when right click the map.
24799 * @param {Roo.bootstrap.LocationPicker} this
24800 * @param {Map event} e
24802 mapRightClick : true,
24804 * @event markerClick
24805 * Fires when click the marker.
24806 * @param {Roo.bootstrap.LocationPicker} this
24807 * @param {Map event} e
24809 markerClick : true,
24811 * @event markerRightClick
24812 * Fires when right click the marker.
24813 * @param {Roo.bootstrap.LocationPicker} this
24814 * @param {Map event} e
24816 markerRightClick : true,
24818 * @event OverlayViewDraw
24819 * Fires when OverlayView Draw
24820 * @param {Roo.bootstrap.LocationPicker} this
24822 OverlayViewDraw : true,
24824 * @event OverlayViewOnAdd
24825 * Fires when OverlayView Draw
24826 * @param {Roo.bootstrap.LocationPicker} this
24828 OverlayViewOnAdd : true,
24830 * @event OverlayViewOnRemove
24831 * Fires when OverlayView Draw
24832 * @param {Roo.bootstrap.LocationPicker} this
24834 OverlayViewOnRemove : true,
24836 * @event OverlayViewShow
24837 * Fires when OverlayView Draw
24838 * @param {Roo.bootstrap.LocationPicker} this
24839 * @param {Pixel} cpx
24841 OverlayViewShow : true,
24843 * @event OverlayViewHide
24844 * Fires when OverlayView Draw
24845 * @param {Roo.bootstrap.LocationPicker} this
24847 OverlayViewHide : true,
24849 * @event loadexception
24850 * Fires when load google lib failed.
24851 * @param {Roo.bootstrap.LocationPicker} this
24853 loadexception : true
24858 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
24860 gMapContext: false,
24866 mapTypeControl: false,
24867 disableDoubleClickZoom: false,
24869 streetViewControl: false,
24873 enableAutocomplete: false,
24874 enableReverseGeocode: true,
24877 getAutoCreate: function()
24882 cls: 'roo-location-picker'
24888 initEvents: function(ct, position)
24890 if(!this.el.getWidth() || this.isApplied()){
24894 this.el.setVisibilityMode(Roo.Element.DISPLAY);
24899 initial: function()
24901 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
24902 this.fireEvent('loadexception', this);
24906 if(!this.mapTypeId){
24907 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
24910 this.gMapContext = this.GMapContext();
24912 this.initOverlayView();
24914 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
24918 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
24919 _this.setPosition(_this.gMapContext.marker.position);
24922 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
24923 _this.fireEvent('mapClick', this, event);
24927 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
24928 _this.fireEvent('mapRightClick', this, event);
24932 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
24933 _this.fireEvent('markerClick', this, event);
24937 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
24938 _this.fireEvent('markerRightClick', this, event);
24942 this.setPosition(this.gMapContext.location);
24944 this.fireEvent('initial', this, this.gMapContext.location);
24947 initOverlayView: function()
24951 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
24955 _this.fireEvent('OverlayViewDraw', _this);
24960 _this.fireEvent('OverlayViewOnAdd', _this);
24963 onRemove: function()
24965 _this.fireEvent('OverlayViewOnRemove', _this);
24968 show: function(cpx)
24970 _this.fireEvent('OverlayViewShow', _this, cpx);
24975 _this.fireEvent('OverlayViewHide', _this);
24981 fromLatLngToContainerPixel: function(event)
24983 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
24986 isApplied: function()
24988 return this.getGmapContext() == false ? false : true;
24991 getGmapContext: function()
24993 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
24996 GMapContext: function()
24998 var position = new google.maps.LatLng(this.latitude, this.longitude);
25000 var _map = new google.maps.Map(this.el.dom, {
25003 mapTypeId: this.mapTypeId,
25004 mapTypeControl: this.mapTypeControl,
25005 disableDoubleClickZoom: this.disableDoubleClickZoom,
25006 scrollwheel: this.scrollwheel,
25007 streetViewControl: this.streetViewControl,
25008 locationName: this.locationName,
25009 draggable: this.draggable,
25010 enableAutocomplete: this.enableAutocomplete,
25011 enableReverseGeocode: this.enableReverseGeocode
25014 var _marker = new google.maps.Marker({
25015 position: position,
25017 title: this.markerTitle,
25018 draggable: this.draggable
25025 location: position,
25026 radius: this.radius,
25027 locationName: this.locationName,
25028 addressComponents: {
25029 formatted_address: null,
25030 addressLine1: null,
25031 addressLine2: null,
25033 streetNumber: null,
25037 stateOrProvince: null
25040 domContainer: this.el.dom,
25041 geodecoder: new google.maps.Geocoder()
25045 drawCircle: function(center, radius, options)
25047 if (this.gMapContext.circle != null) {
25048 this.gMapContext.circle.setMap(null);
25052 options = Roo.apply({}, options, {
25053 strokeColor: "#0000FF",
25054 strokeOpacity: .35,
25056 fillColor: "#0000FF",
25060 options.map = this.gMapContext.map;
25061 options.radius = radius;
25062 options.center = center;
25063 this.gMapContext.circle = new google.maps.Circle(options);
25064 return this.gMapContext.circle;
25070 setPosition: function(location)
25072 this.gMapContext.location = location;
25073 this.gMapContext.marker.setPosition(location);
25074 this.gMapContext.map.panTo(location);
25075 this.drawCircle(location, this.gMapContext.radius, {});
25079 if (this.gMapContext.settings.enableReverseGeocode) {
25080 this.gMapContext.geodecoder.geocode({
25081 latLng: this.gMapContext.location
25082 }, function(results, status) {
25084 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
25085 _this.gMapContext.locationName = results[0].formatted_address;
25086 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
25088 _this.fireEvent('positionchanged', this, location);
25095 this.fireEvent('positionchanged', this, location);
25100 google.maps.event.trigger(this.gMapContext.map, "resize");
25102 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
25104 this.fireEvent('resize', this);
25107 setPositionByLatLng: function(latitude, longitude)
25109 this.setPosition(new google.maps.LatLng(latitude, longitude));
25112 getCurrentPosition: function()
25115 latitude: this.gMapContext.location.lat(),
25116 longitude: this.gMapContext.location.lng()
25120 getAddressName: function()
25122 return this.gMapContext.locationName;
25125 getAddressComponents: function()
25127 return this.gMapContext.addressComponents;
25130 address_component_from_google_geocode: function(address_components)
25134 for (var i = 0; i < address_components.length; i++) {
25135 var component = address_components[i];
25136 if (component.types.indexOf("postal_code") >= 0) {
25137 result.postalCode = component.short_name;
25138 } else if (component.types.indexOf("street_number") >= 0) {
25139 result.streetNumber = component.short_name;
25140 } else if (component.types.indexOf("route") >= 0) {
25141 result.streetName = component.short_name;
25142 } else if (component.types.indexOf("neighborhood") >= 0) {
25143 result.city = component.short_name;
25144 } else if (component.types.indexOf("locality") >= 0) {
25145 result.city = component.short_name;
25146 } else if (component.types.indexOf("sublocality") >= 0) {
25147 result.district = component.short_name;
25148 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
25149 result.stateOrProvince = component.short_name;
25150 } else if (component.types.indexOf("country") >= 0) {
25151 result.country = component.short_name;
25155 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
25156 result.addressLine2 = "";
25160 setZoomLevel: function(zoom)
25162 this.gMapContext.map.setZoom(zoom);
25175 this.fireEvent('show', this);
25186 this.fireEvent('hide', this);
25191 Roo.apply(Roo.bootstrap.LocationPicker, {
25193 OverlayView : function(map, options)
25195 options = options || {};
25209 * @class Roo.bootstrap.Alert
25210 * @extends Roo.bootstrap.Component
25211 * Bootstrap Alert class
25212 * @cfg {String} title The title of alert
25213 * @cfg {String} html The content of alert
25214 * @cfg {String} weight ( success | info | warning | danger )
25215 * @cfg {String} faicon font-awesomeicon
25218 * Create a new alert
25219 * @param {Object} config The config object
25223 Roo.bootstrap.Alert = function(config){
25224 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
25228 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
25235 getAutoCreate : function()
25244 cls : 'roo-alert-icon'
25249 cls : 'roo-alert-title',
25254 cls : 'roo-alert-text',
25261 cfg.cn[0].cls += ' fa ' + this.faicon;
25265 cfg.cls += ' alert-' + this.weight;
25271 initEvents: function()
25273 this.el.setVisibilityMode(Roo.Element.DISPLAY);
25276 setTitle : function(str)
25278 this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
25281 setText : function(str)
25283 this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
25286 setWeight : function(weight)
25289 this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
25292 this.weight = weight;
25294 this.el.select('.alert',true).first().addClass('alert-' + this.weight);
25297 setIcon : function(icon)
25300 this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
25303 this.faicon = icon;
25305 this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
25326 * @class Roo.bootstrap.UploadCropbox
25327 * @extends Roo.bootstrap.Component
25328 * Bootstrap UploadCropbox class
25329 * @cfg {String} emptyText show when image has been loaded
25330 * @cfg {String} rotateNotify show when image too small to rotate
25331 * @cfg {Number} errorTimeout default 3000
25332 * @cfg {Number} minWidth default 300
25333 * @cfg {Number} minHeight default 300
25334 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
25335 * @cfg {Boolean} isDocument (true|false) default false
25336 * @cfg {String} url action url
25337 * @cfg {String} paramName default 'imageUpload'
25338 * @cfg {String} method default POST
25339 * @cfg {Boolean} loadMask (true|false) default true
25340 * @cfg {Boolean} loadingText default 'Loading...'
25343 * Create a new UploadCropbox
25344 * @param {Object} config The config object
25347 Roo.bootstrap.UploadCropbox = function(config){
25348 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
25352 * @event beforeselectfile
25353 * Fire before select file
25354 * @param {Roo.bootstrap.UploadCropbox} this
25356 "beforeselectfile" : true,
25359 * Fire after initEvent
25360 * @param {Roo.bootstrap.UploadCropbox} this
25365 * Fire after initEvent
25366 * @param {Roo.bootstrap.UploadCropbox} this
25367 * @param {String} data
25372 * Fire when preparing the file data
25373 * @param {Roo.bootstrap.UploadCropbox} this
25374 * @param {Object} file
25379 * Fire when get exception
25380 * @param {Roo.bootstrap.UploadCropbox} this
25381 * @param {XMLHttpRequest} xhr
25383 "exception" : true,
25385 * @event beforeloadcanvas
25386 * Fire before load the canvas
25387 * @param {Roo.bootstrap.UploadCropbox} this
25388 * @param {String} src
25390 "beforeloadcanvas" : true,
25393 * Fire when trash image
25394 * @param {Roo.bootstrap.UploadCropbox} this
25399 * Fire when download the image
25400 * @param {Roo.bootstrap.UploadCropbox} this
25404 * @event footerbuttonclick
25405 * Fire when footerbuttonclick
25406 * @param {Roo.bootstrap.UploadCropbox} this
25407 * @param {String} type
25409 "footerbuttonclick" : true,
25413 * @param {Roo.bootstrap.UploadCropbox} this
25418 * Fire when rotate the image
25419 * @param {Roo.bootstrap.UploadCropbox} this
25420 * @param {String} pos
25425 * Fire when inspect the file
25426 * @param {Roo.bootstrap.UploadCropbox} this
25427 * @param {Object} file
25432 * Fire when xhr upload the file
25433 * @param {Roo.bootstrap.UploadCropbox} this
25434 * @param {Object} data
25439 * Fire when arrange the file data
25440 * @param {Roo.bootstrap.UploadCropbox} this
25441 * @param {Object} formData
25446 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
25449 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
25451 emptyText : 'Click to upload image',
25452 rotateNotify : 'Image is too small to rotate',
25453 errorTimeout : 3000,
25467 cropType : 'image/jpeg',
25469 canvasLoaded : false,
25470 isDocument : false,
25472 paramName : 'imageUpload',
25474 loadingText : 'Loading...',
25477 getAutoCreate : function()
25481 cls : 'roo-upload-cropbox',
25485 cls : 'roo-upload-cropbox-selector',
25490 cls : 'roo-upload-cropbox-body',
25491 style : 'cursor:pointer',
25495 cls : 'roo-upload-cropbox-preview'
25499 cls : 'roo-upload-cropbox-thumb'
25503 cls : 'roo-upload-cropbox-empty-notify',
25504 html : this.emptyText
25508 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
25509 html : this.rotateNotify
25515 cls : 'roo-upload-cropbox-footer',
25518 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
25528 onRender : function(ct, position)
25530 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
25532 if (this.buttons.length) {
25534 Roo.each(this.buttons, function(bb) {
25536 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
25538 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
25544 this.maskEl = this.el;
25548 initEvents : function()
25550 this.urlAPI = (window.createObjectURL && window) ||
25551 (window.URL && URL.revokeObjectURL && URL) ||
25552 (window.webkitURL && webkitURL);
25554 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
25555 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25557 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
25558 this.selectorEl.hide();
25560 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
25561 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25563 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
25564 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25565 this.thumbEl.hide();
25567 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
25568 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25570 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
25571 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25572 this.errorEl.hide();
25574 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
25575 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
25576 this.footerEl.hide();
25578 this.setThumbBoxSize();
25584 this.fireEvent('initial', this);
25591 window.addEventListener("resize", function() { _this.resize(); } );
25593 this.bodyEl.on('click', this.beforeSelectFile, this);
25596 this.bodyEl.on('touchstart', this.onTouchStart, this);
25597 this.bodyEl.on('touchmove', this.onTouchMove, this);
25598 this.bodyEl.on('touchend', this.onTouchEnd, this);
25602 this.bodyEl.on('mousedown', this.onMouseDown, this);
25603 this.bodyEl.on('mousemove', this.onMouseMove, this);
25604 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
25605 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
25606 Roo.get(document).on('mouseup', this.onMouseUp, this);
25609 this.selectorEl.on('change', this.onFileSelected, this);
25615 this.baseScale = 1;
25617 this.baseRotate = 1;
25618 this.dragable = false;
25619 this.pinching = false;
25622 this.cropData = false;
25623 this.notifyEl.dom.innerHTML = this.emptyText;
25625 this.selectorEl.dom.value = '';
25629 resize : function()
25631 if(this.fireEvent('resize', this) != false){
25632 this.setThumbBoxPosition();
25633 this.setCanvasPosition();
25637 onFooterButtonClick : function(e, el, o, type)
25640 case 'rotate-left' :
25641 this.onRotateLeft(e);
25643 case 'rotate-right' :
25644 this.onRotateRight(e);
25647 this.beforeSelectFile(e);
25662 this.fireEvent('footerbuttonclick', this, type);
25665 beforeSelectFile : function(e)
25667 e.preventDefault();
25669 if(this.fireEvent('beforeselectfile', this) != false){
25670 this.selectorEl.dom.click();
25674 onFileSelected : function(e)
25676 e.preventDefault();
25678 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
25682 var file = this.selectorEl.dom.files[0];
25684 if(this.fireEvent('inspect', this, file) != false){
25685 this.prepare(file);
25690 trash : function(e)
25692 this.fireEvent('trash', this);
25695 download : function(e)
25697 this.fireEvent('download', this);
25700 loadCanvas : function(src)
25702 if(this.fireEvent('beforeloadcanvas', this, src) != false){
25706 this.imageEl = document.createElement('img');
25710 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
25712 this.imageEl.src = src;
25716 onLoadCanvas : function()
25718 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
25719 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
25721 this.bodyEl.un('click', this.beforeSelectFile, this);
25723 this.notifyEl.hide();
25724 this.thumbEl.show();
25725 this.footerEl.show();
25727 this.baseRotateLevel();
25729 if(this.isDocument){
25730 this.setThumbBoxSize();
25733 this.setThumbBoxPosition();
25735 this.baseScaleLevel();
25741 this.canvasLoaded = true;
25744 this.maskEl.unmask();
25749 setCanvasPosition : function()
25751 if(!this.canvasEl){
25755 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
25756 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
25758 this.previewEl.setLeft(pw);
25759 this.previewEl.setTop(ph);
25763 onMouseDown : function(e)
25767 this.dragable = true;
25768 this.pinching = false;
25770 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
25771 this.dragable = false;
25775 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
25776 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
25780 onMouseMove : function(e)
25784 if(!this.canvasLoaded){
25788 if (!this.dragable){
25792 var minX = Math.ceil(this.thumbEl.getLeft(true));
25793 var minY = Math.ceil(this.thumbEl.getTop(true));
25795 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
25796 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
25798 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
25799 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
25801 x = x - this.mouseX;
25802 y = y - this.mouseY;
25804 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
25805 var bgY = Math.ceil(y + this.previewEl.getTop(true));
25807 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
25808 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
25810 this.previewEl.setLeft(bgX);
25811 this.previewEl.setTop(bgY);
25813 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
25814 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
25817 onMouseUp : function(e)
25821 this.dragable = false;
25824 onMouseWheel : function(e)
25828 this.startScale = this.scale;
25830 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
25832 if(!this.zoomable()){
25833 this.scale = this.startScale;
25842 zoomable : function()
25844 var minScale = this.thumbEl.getWidth() / this.minWidth;
25846 if(this.minWidth < this.minHeight){
25847 minScale = this.thumbEl.getHeight() / this.minHeight;
25850 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
25851 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
25855 (this.rotate == 0 || this.rotate == 180) &&
25857 width > this.imageEl.OriginWidth ||
25858 height > this.imageEl.OriginHeight ||
25859 (width < this.minWidth && height < this.minHeight)
25867 (this.rotate == 90 || this.rotate == 270) &&
25869 width > this.imageEl.OriginWidth ||
25870 height > this.imageEl.OriginHeight ||
25871 (width < this.minHeight && height < this.minWidth)
25878 !this.isDocument &&
25879 (this.rotate == 0 || this.rotate == 180) &&
25881 width < this.minWidth ||
25882 width > this.imageEl.OriginWidth ||
25883 height < this.minHeight ||
25884 height > this.imageEl.OriginHeight
25891 !this.isDocument &&
25892 (this.rotate == 90 || this.rotate == 270) &&
25894 width < this.minHeight ||
25895 width > this.imageEl.OriginWidth ||
25896 height < this.minWidth ||
25897 height > this.imageEl.OriginHeight
25907 onRotateLeft : function(e)
25909 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
25911 var minScale = this.thumbEl.getWidth() / this.minWidth;
25913 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
25914 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
25916 this.startScale = this.scale;
25918 while (this.getScaleLevel() < minScale){
25920 this.scale = this.scale + 1;
25922 if(!this.zoomable()){
25927 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
25928 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
25933 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
25940 this.scale = this.startScale;
25942 this.onRotateFail();
25947 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
25949 if(this.isDocument){
25950 this.setThumbBoxSize();
25951 this.setThumbBoxPosition();
25952 this.setCanvasPosition();
25957 this.fireEvent('rotate', this, 'left');
25961 onRotateRight : function(e)
25963 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
25965 var minScale = this.thumbEl.getWidth() / this.minWidth;
25967 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
25968 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
25970 this.startScale = this.scale;
25972 while (this.getScaleLevel() < minScale){
25974 this.scale = this.scale + 1;
25976 if(!this.zoomable()){
25981 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
25982 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
25987 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
25994 this.scale = this.startScale;
25996 this.onRotateFail();
26001 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
26003 if(this.isDocument){
26004 this.setThumbBoxSize();
26005 this.setThumbBoxPosition();
26006 this.setCanvasPosition();
26011 this.fireEvent('rotate', this, 'right');
26014 onRotateFail : function()
26016 this.errorEl.show(true);
26020 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
26025 this.previewEl.dom.innerHTML = '';
26027 var canvasEl = document.createElement("canvas");
26029 var contextEl = canvasEl.getContext("2d");
26031 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
26032 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
26033 var center = this.imageEl.OriginWidth / 2;
26035 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
26036 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
26037 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
26038 center = this.imageEl.OriginHeight / 2;
26041 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
26043 contextEl.translate(center, center);
26044 contextEl.rotate(this.rotate * Math.PI / 180);
26046 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
26048 this.canvasEl = document.createElement("canvas");
26050 this.contextEl = this.canvasEl.getContext("2d");
26052 switch (this.rotate) {
26055 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
26056 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
26058 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
26063 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
26064 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
26066 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
26067 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);
26071 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
26076 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
26077 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
26079 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
26080 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);
26084 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);
26089 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
26090 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
26092 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
26093 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
26097 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);
26104 this.previewEl.appendChild(this.canvasEl);
26106 this.setCanvasPosition();
26111 if(!this.canvasLoaded){
26115 var imageCanvas = document.createElement("canvas");
26117 var imageContext = imageCanvas.getContext("2d");
26119 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
26120 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
26122 var center = imageCanvas.width / 2;
26124 imageContext.translate(center, center);
26126 imageContext.rotate(this.rotate * Math.PI / 180);
26128 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
26130 var canvas = document.createElement("canvas");
26132 var context = canvas.getContext("2d");
26134 canvas.width = this.minWidth;
26135 canvas.height = this.minHeight;
26137 switch (this.rotate) {
26140 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
26141 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
26143 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
26144 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
26146 var targetWidth = this.minWidth - 2 * x;
26147 var targetHeight = this.minHeight - 2 * y;
26151 if((x == 0 && y == 0) || (x == 0 && y > 0)){
26152 scale = targetWidth / width;
26155 if(x > 0 && y == 0){
26156 scale = targetHeight / height;
26159 if(x > 0 && y > 0){
26160 scale = targetWidth / width;
26162 if(width < height){
26163 scale = targetHeight / height;
26167 context.scale(scale, scale);
26169 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
26170 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
26172 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
26173 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
26175 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
26180 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
26181 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
26183 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
26184 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
26186 var targetWidth = this.minWidth - 2 * x;
26187 var targetHeight = this.minHeight - 2 * y;
26191 if((x == 0 && y == 0) || (x == 0 && y > 0)){
26192 scale = targetWidth / width;
26195 if(x > 0 && y == 0){
26196 scale = targetHeight / height;
26199 if(x > 0 && y > 0){
26200 scale = targetWidth / width;
26202 if(width < height){
26203 scale = targetHeight / height;
26207 context.scale(scale, scale);
26209 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
26210 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
26212 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
26213 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
26215 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
26217 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
26222 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
26223 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
26225 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
26226 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
26228 var targetWidth = this.minWidth - 2 * x;
26229 var targetHeight = this.minHeight - 2 * y;
26233 if((x == 0 && y == 0) || (x == 0 && y > 0)){
26234 scale = targetWidth / width;
26237 if(x > 0 && y == 0){
26238 scale = targetHeight / height;
26241 if(x > 0 && y > 0){
26242 scale = targetWidth / width;
26244 if(width < height){
26245 scale = targetHeight / height;
26249 context.scale(scale, scale);
26251 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
26252 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
26254 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
26255 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
26257 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
26258 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
26260 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
26265 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
26266 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
26268 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
26269 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
26271 var targetWidth = this.minWidth - 2 * x;
26272 var targetHeight = this.minHeight - 2 * y;
26276 if((x == 0 && y == 0) || (x == 0 && y > 0)){
26277 scale = targetWidth / width;
26280 if(x > 0 && y == 0){
26281 scale = targetHeight / height;
26284 if(x > 0 && y > 0){
26285 scale = targetWidth / width;
26287 if(width < height){
26288 scale = targetHeight / height;
26292 context.scale(scale, scale);
26294 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
26295 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
26297 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
26298 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
26300 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
26302 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
26309 this.cropData = canvas.toDataURL(this.cropType);
26311 if(this.fireEvent('crop', this, this.cropData) !== false){
26312 this.process(this.file, this.cropData);
26319 setThumbBoxSize : function()
26323 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
26324 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
26325 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
26327 this.minWidth = width;
26328 this.minHeight = height;
26330 if(this.rotate == 90 || this.rotate == 270){
26331 this.minWidth = height;
26332 this.minHeight = width;
26337 width = Math.ceil(this.minWidth * height / this.minHeight);
26339 if(this.minWidth > this.minHeight){
26341 height = Math.ceil(this.minHeight * width / this.minWidth);
26344 this.thumbEl.setStyle({
26345 width : width + 'px',
26346 height : height + 'px'
26353 setThumbBoxPosition : function()
26355 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
26356 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
26358 this.thumbEl.setLeft(x);
26359 this.thumbEl.setTop(y);
26363 baseRotateLevel : function()
26365 this.baseRotate = 1;
26368 typeof(this.exif) != 'undefined' &&
26369 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
26370 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
26372 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
26375 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
26379 baseScaleLevel : function()
26383 if(this.isDocument){
26385 if(this.baseRotate == 6 || this.baseRotate == 8){
26387 height = this.thumbEl.getHeight();
26388 this.baseScale = height / this.imageEl.OriginWidth;
26390 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
26391 width = this.thumbEl.getWidth();
26392 this.baseScale = width / this.imageEl.OriginHeight;
26398 height = this.thumbEl.getHeight();
26399 this.baseScale = height / this.imageEl.OriginHeight;
26401 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
26402 width = this.thumbEl.getWidth();
26403 this.baseScale = width / this.imageEl.OriginWidth;
26409 if(this.baseRotate == 6 || this.baseRotate == 8){
26411 width = this.thumbEl.getHeight();
26412 this.baseScale = width / this.imageEl.OriginHeight;
26414 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
26415 height = this.thumbEl.getWidth();
26416 this.baseScale = height / this.imageEl.OriginHeight;
26419 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
26420 height = this.thumbEl.getWidth();
26421 this.baseScale = height / this.imageEl.OriginHeight;
26423 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
26424 width = this.thumbEl.getHeight();
26425 this.baseScale = width / this.imageEl.OriginWidth;
26432 width = this.thumbEl.getWidth();
26433 this.baseScale = width / this.imageEl.OriginWidth;
26435 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
26436 height = this.thumbEl.getHeight();
26437 this.baseScale = height / this.imageEl.OriginHeight;
26440 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
26442 height = this.thumbEl.getHeight();
26443 this.baseScale = height / this.imageEl.OriginHeight;
26445 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
26446 width = this.thumbEl.getWidth();
26447 this.baseScale = width / this.imageEl.OriginWidth;
26455 getScaleLevel : function()
26457 return this.baseScale * Math.pow(1.1, this.scale);
26460 onTouchStart : function(e)
26462 if(!this.canvasLoaded){
26463 this.beforeSelectFile(e);
26467 var touches = e.browserEvent.touches;
26473 if(touches.length == 1){
26474 this.onMouseDown(e);
26478 if(touches.length != 2){
26484 for(var i = 0, finger; finger = touches[i]; i++){
26485 coords.push(finger.pageX, finger.pageY);
26488 var x = Math.pow(coords[0] - coords[2], 2);
26489 var y = Math.pow(coords[1] - coords[3], 2);
26491 this.startDistance = Math.sqrt(x + y);
26493 this.startScale = this.scale;
26495 this.pinching = true;
26496 this.dragable = false;
26500 onTouchMove : function(e)
26502 if(!this.pinching && !this.dragable){
26506 var touches = e.browserEvent.touches;
26513 this.onMouseMove(e);
26519 for(var i = 0, finger; finger = touches[i]; i++){
26520 coords.push(finger.pageX, finger.pageY);
26523 var x = Math.pow(coords[0] - coords[2], 2);
26524 var y = Math.pow(coords[1] - coords[3], 2);
26526 this.endDistance = Math.sqrt(x + y);
26528 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
26530 if(!this.zoomable()){
26531 this.scale = this.startScale;
26539 onTouchEnd : function(e)
26541 this.pinching = false;
26542 this.dragable = false;
26546 process : function(file, crop)
26549 this.maskEl.mask(this.loadingText);
26552 this.xhr = new XMLHttpRequest();
26554 file.xhr = this.xhr;
26556 this.xhr.open(this.method, this.url, true);
26559 "Accept": "application/json",
26560 "Cache-Control": "no-cache",
26561 "X-Requested-With": "XMLHttpRequest"
26564 for (var headerName in headers) {
26565 var headerValue = headers[headerName];
26567 this.xhr.setRequestHeader(headerName, headerValue);
26573 this.xhr.onload = function()
26575 _this.xhrOnLoad(_this.xhr);
26578 this.xhr.onerror = function()
26580 _this.xhrOnError(_this.xhr);
26583 var formData = new FormData();
26585 formData.append('returnHTML', 'NO');
26588 formData.append('crop', crop);
26591 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
26592 formData.append(this.paramName, file, file.name);
26595 if(typeof(file.filename) != 'undefined'){
26596 formData.append('filename', file.filename);
26599 if(typeof(file.mimetype) != 'undefined'){
26600 formData.append('mimetype', file.mimetype);
26603 if(this.fireEvent('arrange', this, formData) != false){
26604 this.xhr.send(formData);
26608 xhrOnLoad : function(xhr)
26611 this.maskEl.unmask();
26614 if (xhr.readyState !== 4) {
26615 this.fireEvent('exception', this, xhr);
26619 var response = Roo.decode(xhr.responseText);
26621 if(!response.success){
26622 this.fireEvent('exception', this, xhr);
26626 var response = Roo.decode(xhr.responseText);
26628 this.fireEvent('upload', this, response);
26632 xhrOnError : function()
26635 this.maskEl.unmask();
26638 Roo.log('xhr on error');
26640 var response = Roo.decode(xhr.responseText);
26646 prepare : function(file)
26649 this.maskEl.mask(this.loadingText);
26655 if(typeof(file) === 'string'){
26656 this.loadCanvas(file);
26660 if(!file || !this.urlAPI){
26665 this.cropType = file.type;
26669 if(this.fireEvent('prepare', this, this.file) != false){
26671 var reader = new FileReader();
26673 reader.onload = function (e) {
26674 if (e.target.error) {
26675 Roo.log(e.target.error);
26679 var buffer = e.target.result,
26680 dataView = new DataView(buffer),
26682 maxOffset = dataView.byteLength - 4,
26686 if (dataView.getUint16(0) === 0xffd8) {
26687 while (offset < maxOffset) {
26688 markerBytes = dataView.getUint16(offset);
26690 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
26691 markerLength = dataView.getUint16(offset + 2) + 2;
26692 if (offset + markerLength > dataView.byteLength) {
26693 Roo.log('Invalid meta data: Invalid segment size.');
26697 if(markerBytes == 0xffe1){
26698 _this.parseExifData(
26705 offset += markerLength;
26715 var url = _this.urlAPI.createObjectURL(_this.file);
26717 _this.loadCanvas(url);
26722 reader.readAsArrayBuffer(this.file);
26728 parseExifData : function(dataView, offset, length)
26730 var tiffOffset = offset + 10,
26734 if (dataView.getUint32(offset + 4) !== 0x45786966) {
26735 // No Exif data, might be XMP data instead
26739 // Check for the ASCII code for "Exif" (0x45786966):
26740 if (dataView.getUint32(offset + 4) !== 0x45786966) {
26741 // No Exif data, might be XMP data instead
26744 if (tiffOffset + 8 > dataView.byteLength) {
26745 Roo.log('Invalid Exif data: Invalid segment size.');
26748 // Check for the two null bytes:
26749 if (dataView.getUint16(offset + 8) !== 0x0000) {
26750 Roo.log('Invalid Exif data: Missing byte alignment offset.');
26753 // Check the byte alignment:
26754 switch (dataView.getUint16(tiffOffset)) {
26756 littleEndian = true;
26759 littleEndian = false;
26762 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
26765 // Check for the TIFF tag marker (0x002A):
26766 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
26767 Roo.log('Invalid Exif data: Missing TIFF marker.');
26770 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
26771 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
26773 this.parseExifTags(
26776 tiffOffset + dirOffset,
26781 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
26786 if (dirOffset + 6 > dataView.byteLength) {
26787 Roo.log('Invalid Exif data: Invalid directory offset.');
26790 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
26791 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
26792 if (dirEndOffset + 4 > dataView.byteLength) {
26793 Roo.log('Invalid Exif data: Invalid directory size.');
26796 for (i = 0; i < tagsNumber; i += 1) {
26800 dirOffset + 2 + 12 * i, // tag offset
26804 // Return the offset to the next directory:
26805 return dataView.getUint32(dirEndOffset, littleEndian);
26808 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
26810 var tag = dataView.getUint16(offset, littleEndian);
26812 this.exif[tag] = this.getExifValue(
26816 dataView.getUint16(offset + 2, littleEndian), // tag type
26817 dataView.getUint32(offset + 4, littleEndian), // tag length
26822 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
26824 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
26833 Roo.log('Invalid Exif data: Invalid tag type.');
26837 tagSize = tagType.size * length;
26838 // Determine if the value is contained in the dataOffset bytes,
26839 // or if the value at the dataOffset is a pointer to the actual data:
26840 dataOffset = tagSize > 4 ?
26841 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
26842 if (dataOffset + tagSize > dataView.byteLength) {
26843 Roo.log('Invalid Exif data: Invalid data offset.');
26846 if (length === 1) {
26847 return tagType.getValue(dataView, dataOffset, littleEndian);
26850 for (i = 0; i < length; i += 1) {
26851 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
26854 if (tagType.ascii) {
26856 // Concatenate the chars:
26857 for (i = 0; i < values.length; i += 1) {
26859 // Ignore the terminating NULL byte(s):
26860 if (c === '\u0000') {
26872 Roo.apply(Roo.bootstrap.UploadCropbox, {
26874 'Orientation': 0x0112
26878 1: 0, //'top-left',
26880 3: 180, //'bottom-right',
26881 // 4: 'bottom-left',
26883 6: 90, //'right-top',
26884 // 7: 'right-bottom',
26885 8: 270 //'left-bottom'
26889 // byte, 8-bit unsigned int:
26891 getValue: function (dataView, dataOffset) {
26892 return dataView.getUint8(dataOffset);
26896 // ascii, 8-bit byte:
26898 getValue: function (dataView, dataOffset) {
26899 return String.fromCharCode(dataView.getUint8(dataOffset));
26904 // short, 16 bit int:
26906 getValue: function (dataView, dataOffset, littleEndian) {
26907 return dataView.getUint16(dataOffset, littleEndian);
26911 // long, 32 bit int:
26913 getValue: function (dataView, dataOffset, littleEndian) {
26914 return dataView.getUint32(dataOffset, littleEndian);
26918 // rational = two long values, first is numerator, second is denominator:
26920 getValue: function (dataView, dataOffset, littleEndian) {
26921 return dataView.getUint32(dataOffset, littleEndian) /
26922 dataView.getUint32(dataOffset + 4, littleEndian);
26926 // slong, 32 bit signed int:
26928 getValue: function (dataView, dataOffset, littleEndian) {
26929 return dataView.getInt32(dataOffset, littleEndian);
26933 // srational, two slongs, first is numerator, second is denominator:
26935 getValue: function (dataView, dataOffset, littleEndian) {
26936 return dataView.getInt32(dataOffset, littleEndian) /
26937 dataView.getInt32(dataOffset + 4, littleEndian);
26947 cls : 'btn-group roo-upload-cropbox-rotate-left',
26948 action : 'rotate-left',
26952 cls : 'btn btn-default',
26953 html : '<i class="fa fa-undo"></i>'
26959 cls : 'btn-group roo-upload-cropbox-picture',
26960 action : 'picture',
26964 cls : 'btn btn-default',
26965 html : '<i class="fa fa-picture-o"></i>'
26971 cls : 'btn-group roo-upload-cropbox-rotate-right',
26972 action : 'rotate-right',
26976 cls : 'btn btn-default',
26977 html : '<i class="fa fa-repeat"></i>'
26985 cls : 'btn-group roo-upload-cropbox-rotate-left',
26986 action : 'rotate-left',
26990 cls : 'btn btn-default',
26991 html : '<i class="fa fa-undo"></i>'
26997 cls : 'btn-group roo-upload-cropbox-download',
26998 action : 'download',
27002 cls : 'btn btn-default',
27003 html : '<i class="fa fa-download"></i>'
27009 cls : 'btn-group roo-upload-cropbox-crop',
27014 cls : 'btn btn-default',
27015 html : '<i class="fa fa-crop"></i>'
27021 cls : 'btn-group roo-upload-cropbox-trash',
27026 cls : 'btn btn-default',
27027 html : '<i class="fa fa-trash"></i>'
27033 cls : 'btn-group roo-upload-cropbox-rotate-right',
27034 action : 'rotate-right',
27038 cls : 'btn btn-default',
27039 html : '<i class="fa fa-repeat"></i>'
27047 cls : 'btn-group roo-upload-cropbox-rotate-left',
27048 action : 'rotate-left',
27052 cls : 'btn btn-default',
27053 html : '<i class="fa fa-undo"></i>'
27059 cls : 'btn-group roo-upload-cropbox-rotate-right',
27060 action : 'rotate-right',
27064 cls : 'btn btn-default',
27065 html : '<i class="fa fa-repeat"></i>'
27078 * @class Roo.bootstrap.DocumentManager
27079 * @extends Roo.bootstrap.Component
27080 * Bootstrap DocumentManager class
27081 * @cfg {String} paramName default 'imageUpload'
27082 * @cfg {String} method default POST
27083 * @cfg {String} url action url
27084 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
27085 * @cfg {Boolean} multiple multiple upload default true
27086 * @cfg {Number} thumbSize default 300
27087 * @cfg {String} fieldLabel
27088 * @cfg {Number} labelWidth default 4
27089 * @cfg {String} labelAlign (left|top) default left
27090 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
27093 * Create a new DocumentManager
27094 * @param {Object} config The config object
27097 Roo.bootstrap.DocumentManager = function(config){
27098 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
27103 * Fire when initial the DocumentManager
27104 * @param {Roo.bootstrap.DocumentManager} this
27109 * inspect selected file
27110 * @param {Roo.bootstrap.DocumentManager} this
27111 * @param {File} file
27116 * Fire when xhr load exception
27117 * @param {Roo.bootstrap.DocumentManager} this
27118 * @param {XMLHttpRequest} xhr
27120 "exception" : true,
27123 * prepare the form data
27124 * @param {Roo.bootstrap.DocumentManager} this
27125 * @param {Object} formData
27130 * Fire when remove the file
27131 * @param {Roo.bootstrap.DocumentManager} this
27132 * @param {Object} file
27137 * Fire after refresh the file
27138 * @param {Roo.bootstrap.DocumentManager} this
27143 * Fire after click the image
27144 * @param {Roo.bootstrap.DocumentManager} this
27145 * @param {Object} file
27150 * Fire when upload a image and editable set to true
27151 * @param {Roo.bootstrap.DocumentManager} this
27152 * @param {Object} file
27156 * @event beforeselectfile
27157 * Fire before select file
27158 * @param {Roo.bootstrap.DocumentManager} this
27160 "beforeselectfile" : true,
27163 * Fire before process file
27164 * @param {Roo.bootstrap.DocumentManager} this
27165 * @param {Object} file
27172 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
27181 paramName : 'imageUpload',
27184 labelAlign : 'left',
27191 getAutoCreate : function()
27193 var managerWidget = {
27195 cls : 'roo-document-manager',
27199 cls : 'roo-document-manager-selector',
27204 cls : 'roo-document-manager-uploader',
27208 cls : 'roo-document-manager-upload-btn',
27209 html : '<i class="fa fa-plus"></i>'
27220 cls : 'column col-md-12',
27225 if(this.fieldLabel.length){
27230 cls : 'column col-md-12',
27231 html : this.fieldLabel
27235 cls : 'column col-md-12',
27240 if(this.labelAlign == 'left'){
27244 cls : 'column col-md-' + this.labelWidth,
27245 html : this.fieldLabel
27249 cls : 'column col-md-' + (12 - this.labelWidth),
27259 cls : 'row clearfix',
27267 initEvents : function()
27269 this.managerEl = this.el.select('.roo-document-manager', true).first();
27270 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27272 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
27273 this.selectorEl.hide();
27276 this.selectorEl.attr('multiple', 'multiple');
27279 this.selectorEl.on('change', this.onFileSelected, this);
27281 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
27282 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27284 this.uploader.on('click', this.onUploaderClick, this);
27286 this.renderProgressDialog();
27290 window.addEventListener("resize", function() { _this.refresh(); } );
27292 this.fireEvent('initial', this);
27295 renderProgressDialog : function()
27299 this.progressDialog = new Roo.bootstrap.Modal({
27300 cls : 'roo-document-manager-progress-dialog',
27301 allow_close : false,
27311 btnclick : function() {
27312 _this.uploadCancel();
27318 this.progressDialog.render(Roo.get(document.body));
27320 this.progress = new Roo.bootstrap.Progress({
27321 cls : 'roo-document-manager-progress',
27326 this.progress.render(this.progressDialog.getChildContainer());
27328 this.progressBar = new Roo.bootstrap.ProgressBar({
27329 cls : 'roo-document-manager-progress-bar',
27332 aria_valuemax : 12,
27336 this.progressBar.render(this.progress.getChildContainer());
27339 onUploaderClick : function(e)
27341 e.preventDefault();
27343 if(this.fireEvent('beforeselectfile', this) != false){
27344 this.selectorEl.dom.click();
27349 onFileSelected : function(e)
27351 e.preventDefault();
27353 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
27357 Roo.each(this.selectorEl.dom.files, function(file){
27358 if(this.fireEvent('inspect', this, file) != false){
27359 this.files.push(file);
27369 this.selectorEl.dom.value = '';
27371 if(!this.files.length){
27375 if(this.boxes > 0 && this.files.length > this.boxes){
27376 this.files = this.files.slice(0, this.boxes);
27379 this.uploader.show();
27381 if(this.boxes > 0 && this.files.length > this.boxes - 1){
27382 this.uploader.hide();
27391 Roo.each(this.files, function(file){
27393 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
27394 var f = this.renderPreview(file);
27399 if(file.type.indexOf('image') != -1){
27400 this.delegates.push(
27402 _this.process(file);
27403 }).createDelegate(this)
27411 _this.process(file);
27412 }).createDelegate(this)
27417 this.files = files;
27419 this.delegates = this.delegates.concat(docs);
27421 if(!this.delegates.length){
27426 this.progressBar.aria_valuemax = this.delegates.length;
27433 arrange : function()
27435 if(!this.delegates.length){
27436 this.progressDialog.hide();
27441 var delegate = this.delegates.shift();
27443 this.progressDialog.show();
27445 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
27447 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
27452 refresh : function()
27454 this.uploader.show();
27456 if(this.boxes > 0 && this.files.length > this.boxes - 1){
27457 this.uploader.hide();
27460 Roo.isTouch ? this.closable(false) : this.closable(true);
27462 this.fireEvent('refresh', this);
27465 onRemove : function(e, el, o)
27467 e.preventDefault();
27469 this.fireEvent('remove', this, o);
27473 remove : function(o)
27477 Roo.each(this.files, function(file){
27478 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
27487 this.files = files;
27494 Roo.each(this.files, function(file){
27499 file.target.remove();
27508 onClick : function(e, el, o)
27510 e.preventDefault();
27512 this.fireEvent('click', this, o);
27516 closable : function(closable)
27518 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
27520 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27532 xhrOnLoad : function(xhr)
27534 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
27538 if (xhr.readyState !== 4) {
27540 this.fireEvent('exception', this, xhr);
27544 var response = Roo.decode(xhr.responseText);
27546 if(!response.success){
27548 this.fireEvent('exception', this, xhr);
27552 var file = this.renderPreview(response.data);
27554 this.files.push(file);
27560 xhrOnError : function(xhr)
27562 Roo.log('xhr on error');
27564 var response = Roo.decode(xhr.responseText);
27571 process : function(file)
27573 if(this.fireEvent('process', this, file) !== false){
27574 if(this.editable && file.type.indexOf('image') != -1){
27575 this.fireEvent('edit', this, file);
27579 this.uploadStart(file, false);
27586 uploadStart : function(file, crop)
27588 this.xhr = new XMLHttpRequest();
27590 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
27595 file.xhr = this.xhr;
27597 this.managerEl.createChild({
27599 cls : 'roo-document-manager-loading',
27603 tooltip : file.name,
27604 cls : 'roo-document-manager-thumb',
27605 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
27611 this.xhr.open(this.method, this.url, true);
27614 "Accept": "application/json",
27615 "Cache-Control": "no-cache",
27616 "X-Requested-With": "XMLHttpRequest"
27619 for (var headerName in headers) {
27620 var headerValue = headers[headerName];
27622 this.xhr.setRequestHeader(headerName, headerValue);
27628 this.xhr.onload = function()
27630 _this.xhrOnLoad(_this.xhr);
27633 this.xhr.onerror = function()
27635 _this.xhrOnError(_this.xhr);
27638 var formData = new FormData();
27640 formData.append('returnHTML', 'NO');
27643 formData.append('crop', crop);
27646 formData.append(this.paramName, file, file.name);
27648 if(this.fireEvent('prepare', this, formData) != false){
27649 this.xhr.send(formData);
27653 uploadCancel : function()
27660 this.delegates = [];
27662 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
27669 renderPreview : function(file)
27671 if(typeof(file.target) != 'undefined' && file.target){
27675 var previewEl = this.managerEl.createChild({
27677 cls : 'roo-document-manager-preview',
27681 tooltip : file.filename,
27682 cls : 'roo-document-manager-thumb',
27683 html : '<img src="' + baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename + '">'
27688 html : '<i class="fa fa-times-circle"></i>'
27693 var close = previewEl.select('button.close', true).first();
27695 close.on('click', this.onRemove, this, file);
27697 file.target = previewEl;
27699 var image = previewEl.select('img', true).first();
27703 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
27705 image.on('click', this.onClick, this, file);
27711 onPreviewLoad : function(file, image)
27713 if(typeof(file.target) == 'undefined' || !file.target){
27717 var width = image.dom.naturalWidth || image.dom.width;
27718 var height = image.dom.naturalHeight || image.dom.height;
27720 if(width > height){
27721 file.target.addClass('wide');
27725 file.target.addClass('tall');
27730 uploadFromSource : function(file, crop)
27732 this.xhr = new XMLHttpRequest();
27734 this.managerEl.createChild({
27736 cls : 'roo-document-manager-loading',
27740 tooltip : file.name,
27741 cls : 'roo-document-manager-thumb',
27742 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
27748 this.xhr.open(this.method, this.url, true);
27751 "Accept": "application/json",
27752 "Cache-Control": "no-cache",
27753 "X-Requested-With": "XMLHttpRequest"
27756 for (var headerName in headers) {
27757 var headerValue = headers[headerName];
27759 this.xhr.setRequestHeader(headerName, headerValue);
27765 this.xhr.onload = function()
27767 _this.xhrOnLoad(_this.xhr);
27770 this.xhr.onerror = function()
27772 _this.xhrOnError(_this.xhr);
27775 var formData = new FormData();
27777 formData.append('returnHTML', 'NO');
27779 formData.append('crop', crop);
27781 if(typeof(file.filename) != 'undefined'){
27782 formData.append('filename', file.filename);
27785 if(typeof(file.mimetype) != 'undefined'){
27786 formData.append('mimetype', file.mimetype);
27789 if(this.fireEvent('prepare', this, formData) != false){
27790 this.xhr.send(formData);
27800 * @class Roo.bootstrap.DocumentViewer
27801 * @extends Roo.bootstrap.Component
27802 * Bootstrap DocumentViewer class
27805 * Create a new DocumentViewer
27806 * @param {Object} config The config object
27809 Roo.bootstrap.DocumentViewer = function(config){
27810 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
27815 * Fire after initEvent
27816 * @param {Roo.bootstrap.DocumentViewer} this
27822 * @param {Roo.bootstrap.DocumentViewer} this
27827 * Fire after trash button
27828 * @param {Roo.bootstrap.DocumentViewer} this
27835 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
27837 getAutoCreate : function()
27841 cls : 'roo-document-viewer',
27845 cls : 'roo-document-viewer-body',
27849 cls : 'roo-document-viewer-thumb',
27853 cls : 'roo-document-viewer-image'
27861 cls : 'roo-document-viewer-footer',
27864 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
27872 cls : 'btn btn-default roo-document-viewer-trash',
27873 html : '<i class="fa fa-trash"></i>'
27886 initEvents : function()
27889 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
27890 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27892 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
27893 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27895 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
27896 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27898 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
27899 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27901 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
27902 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27904 this.bodyEl.on('click', this.onClick, this);
27906 this.trashBtn.on('click', this.onTrash, this);
27910 initial : function()
27912 // this.thumbEl.setStyle('line-height', this.thumbEl.getHeight(true) + 'px');
27915 this.fireEvent('initial', this);
27919 onClick : function(e)
27921 e.preventDefault();
27923 this.fireEvent('click', this);
27926 onTrash : function(e)
27928 e.preventDefault();
27930 this.fireEvent('trash', this);
27942 * @class Roo.bootstrap.NavProgressBar
27943 * @extends Roo.bootstrap.Component
27944 * Bootstrap NavProgressBar class
27947 * Create a new nav progress bar
27948 * @param {Object} config The config object
27951 Roo.bootstrap.NavProgressBar = function(config){
27952 Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
27954 this.bullets = this.bullets || [];
27956 // Roo.bootstrap.NavProgressBar.register(this);
27960 * Fires when the active item changes
27961 * @param {Roo.bootstrap.NavProgressBar} this
27962 * @param {Roo.bootstrap.NavProgressItem} selected The item selected
27963 * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item
27970 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component, {
27975 getAutoCreate : function()
27977 var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
27981 cls : 'roo-navigation-bar-group',
27985 cls : 'roo-navigation-top-bar'
27989 cls : 'roo-navigation-bullets-bar',
27993 cls : 'roo-navigation-bar'
28000 cls : 'roo-navigation-bottom-bar'
28010 initEvents: function()
28015 onRender : function(ct, position)
28017 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
28019 if(this.bullets.length){
28020 Roo.each(this.bullets, function(b){
28029 addItem : function(cfg)
28031 var item = new Roo.bootstrap.NavProgressItem(cfg);
28033 item.parentId = this.id;
28034 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
28037 var top = new Roo.bootstrap.Element({
28039 cls : 'roo-navigation-bar-text'
28042 var bottom = new Roo.bootstrap.Element({
28044 cls : 'roo-navigation-bar-text'
28047 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
28048 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
28050 var topText = new Roo.bootstrap.Element({
28052 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
28055 var bottomText = new Roo.bootstrap.Element({
28057 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
28060 topText.onRender(top.el, null);
28061 bottomText.onRender(bottom.el, null);
28064 item.bottomEl = bottom;
28067 this.barItems.push(item);
28072 getActive : function()
28074 var active = false;
28076 Roo.each(this.barItems, function(v){
28078 if (!v.isActive()) {
28090 setActiveItem : function(item)
28094 Roo.each(this.barItems, function(v){
28095 if (v.rid == item.rid) {
28099 if (v.isActive()) {
28100 v.setActive(false);
28105 item.setActive(true);
28107 this.fireEvent('changed', this, item, prev);
28110 getBarItem: function(rid)
28114 Roo.each(this.barItems, function(e) {
28115 if (e.rid != rid) {
28126 indexOfItem : function(item)
28130 Roo.each(this.barItems, function(v, i){
28132 if (v.rid != item.rid) {
28143 setActiveNext : function()
28145 var i = this.indexOfItem(this.getActive());
28147 if (i > this.barItems.length) {
28151 this.setActiveItem(this.barItems[i+1]);
28154 setActivePrev : function()
28156 var i = this.indexOfItem(this.getActive());
28162 this.setActiveItem(this.barItems[i-1]);
28165 format : function()
28167 if(!this.barItems.length){
28171 var width = 100 / this.barItems.length;
28173 Roo.each(this.barItems, function(i){
28174 i.el.setStyle('width', width + '%');
28175 i.topEl.el.setStyle('width', width + '%');
28176 i.bottomEl.el.setStyle('width', width + '%');
28185 * Nav Progress Item
28190 * @class Roo.bootstrap.NavProgressItem
28191 * @extends Roo.bootstrap.Component
28192 * Bootstrap NavProgressItem class
28193 * @cfg {String} rid the reference id
28194 * @cfg {Boolean} active (true|false) Is item active default false
28195 * @cfg {Boolean} disabled (true|false) Is item active default false
28196 * @cfg {String} html
28197 * @cfg {String} position (top|bottom) text position default bottom
28198 * @cfg {String} icon show icon instead of number
28201 * Create a new NavProgressItem
28202 * @param {Object} config The config object
28204 Roo.bootstrap.NavProgressItem = function(config){
28205 Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
28210 * The raw click event for the entire grid.
28211 * @param {Roo.bootstrap.NavProgressItem} this
28212 * @param {Roo.EventObject} e
28219 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component, {
28225 position : 'bottom',
28228 getAutoCreate : function()
28230 var iconCls = 'roo-navigation-bar-item-icon';
28232 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
28236 cls: 'roo-navigation-bar-item',
28246 cfg.cls += ' active';
28249 cfg.cls += ' disabled';
28255 disable : function()
28257 this.setDisabled(true);
28260 enable : function()
28262 this.setDisabled(false);
28265 initEvents: function()
28267 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
28269 this.iconEl.on('click', this.onClick, this);
28272 onClick : function(e)
28274 e.preventDefault();
28280 if(this.fireEvent('click', this, e) === false){
28284 this.parent().setActiveItem(this);
28287 isActive: function ()
28289 return this.active;
28292 setActive : function(state)
28294 if(this.active == state){
28298 this.active = state;
28301 this.el.addClass('active');
28305 this.el.removeClass('active');
28310 setDisabled : function(state)
28312 if(this.disabled == state){
28316 this.disabled = state;
28319 this.el.addClass('disabled');
28323 this.el.removeClass('disabled');
28326 tooltipEl : function()
28328 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
28341 * @class Roo.bootstrap.FieldLabel
28342 * @extends Roo.bootstrap.Component
28343 * Bootstrap FieldLabel class
28344 * @cfg {String} html contents of the element
28345 * @cfg {String} tag tag of the element default label
28346 * @cfg {String} cls class of the element
28347 * @cfg {String} target label target
28348 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
28349 * @cfg {String} invalidClass default "text-danger fa fa-lg fa-exclamation-triangle"
28350 * @cfg {String} validClass default "text-success fa fa-lg fa-check"
28351 * @cfg {String} iconTooltip default "This field is required"
28354 * Create a new FieldLabel
28355 * @param {Object} config The config object
28358 Roo.bootstrap.FieldLabel = function(config){
28359 Roo.bootstrap.Element.superclass.constructor.call(this, config);
28364 * Fires after the field has been marked as invalid.
28365 * @param {Roo.form.FieldLabel} this
28366 * @param {String} msg The validation message
28371 * Fires after the field has been validated with no errors.
28372 * @param {Roo.form.FieldLabel} this
28378 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component, {
28385 invalidClass : 'text-danger fa fa-lg fa-exclamation-triangle',
28386 validClass : 'text-success fa fa-lg fa-check',
28387 iconTooltip : 'This field is required',
28389 getAutoCreate : function(){
28393 cls : 'roo-bootstrap-field-label ' + this.cls,
28399 tooltip : this.iconTooltip
28411 initEvents: function()
28413 Roo.bootstrap.Element.superclass.initEvents.call(this);
28415 this.iconEl = this.el.select('i', true).first();
28417 this.iconEl.setVisibilityMode(Roo.Element.DISPLAY).hide();
28419 Roo.bootstrap.FieldLabel.register(this);
28423 * Mark this field as valid
28425 markValid : function()
28427 this.iconEl.show();
28429 this.iconEl.removeClass(this.invalidClass);
28431 this.iconEl.addClass(this.validClass);
28433 this.fireEvent('valid', this);
28437 * Mark this field as invalid
28438 * @param {String} msg The validation message
28440 markInvalid : function(msg)
28442 this.iconEl.show();
28444 this.iconEl.removeClass(this.validClass);
28446 this.iconEl.addClass(this.invalidClass);
28448 this.fireEvent('invalid', this, msg);
28454 Roo.apply(Roo.bootstrap.FieldLabel, {
28459 * register a FieldLabel Group
28460 * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
28462 register : function(label)
28464 if(this.groups.hasOwnProperty(label.target)){
28468 this.groups[label.target] = label;
28472 * fetch a FieldLabel Group based on the target
28473 * @param {string} target
28474 * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
28476 get: function(target) {
28477 if (typeof(this.groups[target]) == 'undefined') {
28481 return this.groups[target] ;
28490 * page DateSplitField.
28496 * @class Roo.bootstrap.DateSplitField
28497 * @extends Roo.bootstrap.Component
28498 * Bootstrap DateSplitField class
28499 * @cfg {string} fieldLabel - the label associated
28500 * @cfg {Number} labelWidth set the width of label (0-12)
28501 * @cfg {String} labelAlign (top|left)
28502 * @cfg {Boolean} dayAllowBlank (true|false) default false
28503 * @cfg {Boolean} monthAllowBlank (true|false) default false
28504 * @cfg {Boolean} yearAllowBlank (true|false) default false
28505 * @cfg {string} dayPlaceholder
28506 * @cfg {string} monthPlaceholder
28507 * @cfg {string} yearPlaceholder
28508 * @cfg {string} dayFormat default 'd'
28509 * @cfg {string} monthFormat default 'm'
28510 * @cfg {string} yearFormat default 'Y'
28514 * Create a new DateSplitField
28515 * @param {Object} config The config object
28518 Roo.bootstrap.DateSplitField = function(config){
28519 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
28525 * getting the data of years
28526 * @param {Roo.bootstrap.DateSplitField} this
28527 * @param {Object} years
28532 * getting the data of days
28533 * @param {Roo.bootstrap.DateSplitField} this
28534 * @param {Object} days
28539 * Fires after the field has been marked as invalid.
28540 * @param {Roo.form.Field} this
28541 * @param {String} msg The validation message
28546 * Fires after the field has been validated with no errors.
28547 * @param {Roo.form.Field} this
28553 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
28556 labelAlign : 'top',
28558 dayAllowBlank : false,
28559 monthAllowBlank : false,
28560 yearAllowBlank : false,
28561 dayPlaceholder : '',
28562 monthPlaceholder : '',
28563 yearPlaceholder : '',
28567 isFormField : true,
28569 getAutoCreate : function()
28573 cls : 'row roo-date-split-field-group',
28578 cls : 'form-hidden-field roo-date-split-field-group-value',
28584 if(this.fieldLabel){
28587 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
28591 html : this.fieldLabel
28597 Roo.each(['day', 'month', 'year'], function(t){
28600 cls : 'column roo-date-split-field-' + t + ' col-md-' + ((this.labelAlign == 'top') ? '4' : ((12 - this.labelWidth) / 3))
28607 inputEl: function ()
28609 return this.el.select('.roo-date-split-field-group-value', true).first();
28612 onRender : function(ct, position)
28616 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
28618 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
28620 this.dayField = new Roo.bootstrap.ComboBox({
28621 allowBlank : this.dayAllowBlank,
28622 alwaysQuery : true,
28623 displayField : 'value',
28626 forceSelection : true,
28628 placeholder : this.dayPlaceholder,
28629 selectOnFocus : true,
28630 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
28631 triggerAction : 'all',
28633 valueField : 'value',
28634 store : new Roo.data.SimpleStore({
28635 data : (function() {
28637 _this.fireEvent('days', _this, days);
28640 fields : [ 'value' ]
28643 select : function (_self, record, index)
28645 _this.setValue(_this.getValue());
28650 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
28652 this.monthField = new Roo.bootstrap.MonthField({
28653 after : '<i class=\"fa fa-calendar\"></i>',
28654 allowBlank : this.monthAllowBlank,
28655 placeholder : this.monthPlaceholder,
28658 render : function (_self)
28660 this.el.select('span.input-group-addon', true).first().on('click', function(e){
28661 e.preventDefault();
28665 select : function (_self, oldvalue, newvalue)
28667 _this.setValue(_this.getValue());
28672 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
28674 this.yearField = new Roo.bootstrap.ComboBox({
28675 allowBlank : this.yearAllowBlank,
28676 alwaysQuery : true,
28677 displayField : 'value',
28680 forceSelection : true,
28682 placeholder : this.yearPlaceholder,
28683 selectOnFocus : true,
28684 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
28685 triggerAction : 'all',
28687 valueField : 'value',
28688 store : new Roo.data.SimpleStore({
28689 data : (function() {
28691 _this.fireEvent('years', _this, years);
28694 fields : [ 'value' ]
28697 select : function (_self, record, index)
28699 _this.setValue(_this.getValue());
28704 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
28707 setValue : function(v, format)
28709 this.inputEl.dom.value = v;
28711 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
28713 var d = Date.parseDate(v, f);
28720 this.setDay(d.format(this.dayFormat));
28721 this.setMonth(d.format(this.monthFormat));
28722 this.setYear(d.format(this.yearFormat));
28729 setDay : function(v)
28731 this.dayField.setValue(v);
28732 this.inputEl.dom.value = this.getValue();
28737 setMonth : function(v)
28739 this.monthField.setValue(v, true);
28740 this.inputEl.dom.value = this.getValue();
28745 setYear : function(v)
28747 this.yearField.setValue(v);
28748 this.inputEl.dom.value = this.getValue();
28753 getDay : function()
28755 return this.dayField.getValue();
28758 getMonth : function()
28760 return this.monthField.getValue();
28763 getYear : function()
28765 return this.yearField.getValue();
28768 getValue : function()
28770 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
28772 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
28782 this.inputEl.dom.value = '';
28787 validate : function()
28789 var d = this.dayField.validate();
28790 var m = this.monthField.validate();
28791 var y = this.yearField.validate();
28796 (!this.dayAllowBlank && !d) ||
28797 (!this.monthAllowBlank && !m) ||
28798 (!this.yearAllowBlank && !y)
28803 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
28812 this.markInvalid();
28817 markValid : function()
28820 var label = this.el.select('label', true).first();
28821 var icon = this.el.select('i.fa-star', true).first();
28827 this.fireEvent('valid', this);
28831 * Mark this field as invalid
28832 * @param {String} msg The validation message
28834 markInvalid : function(msg)
28837 var label = this.el.select('label', true).first();
28838 var icon = this.el.select('i.fa-star', true).first();
28840 if(label && !icon){
28841 this.el.select('.roo-date-split-field-label', true).createChild({
28843 cls : 'text-danger fa fa-lg fa-star',
28844 tooltip : 'This field is required',
28845 style : 'margin-right:5px;'
28849 this.fireEvent('invalid', this, msg);
28852 clearInvalid : function()
28854 var label = this.el.select('label', true).first();
28855 var icon = this.el.select('i.fa-star', true).first();
28861 this.fireEvent('valid', this);
28864 getName: function()
28874 * http://masonry.desandro.com
28876 * The idea is to render all the bricks based on vertical width...
28878 * The original code extends 'outlayer' - we might need to use that....
28884 * @class Roo.bootstrap.LayoutMasonry
28885 * @extends Roo.bootstrap.Component
28886 * Bootstrap Layout Masonry class
28889 * Create a new Element
28890 * @param {Object} config The config object
28893 Roo.bootstrap.LayoutMasonry = function(config){
28894 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
28900 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
28903 * @cfg {Boolean} isLayoutInstant = no animation?
28905 isLayoutInstant : false, // needed?
28908 * @cfg {Number} boxWidth width of the columns
28913 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
28918 * @cfg {Number} padWidth padding below box..
28923 * @cfg {Number} gutter gutter width..
28928 * @cfg {Number} maxCols maximum number of columns
28934 * @cfg {Boolean} isAutoInitial defalut true
28936 isAutoInitial : true,
28941 * @cfg {Boolean} isHorizontal defalut false
28943 isHorizontal : false,
28945 currentSize : null,
28951 bricks: null, //CompositeElement
28955 _isLayoutInited : false,
28957 // isAlternative : false, // only use for vertical layout...
28960 * @cfg {Number} alternativePadWidth padding below box..
28962 alternativePadWidth : 50,
28964 getAutoCreate : function(){
28968 cls: 'blog-masonary-wrapper ' + this.cls,
28970 cls : 'mas-boxes masonary'
28977 getChildContainer: function( )
28979 if (this.boxesEl) {
28980 return this.boxesEl;
28983 this.boxesEl = this.el.select('.mas-boxes').first();
28985 return this.boxesEl;
28989 initEvents : function()
28993 if(this.isAutoInitial){
28994 Roo.log('hook children rendered');
28995 this.on('childrenrendered', function() {
28996 Roo.log('children rendered');
29002 initial : function()
29004 this.currentSize = this.el.getBox(true);
29006 Roo.EventManager.onWindowResize(this.resize, this);
29008 if(!this.isAutoInitial){
29016 //this.layout.defer(500,this);
29020 resize : function()
29024 var cs = this.el.getBox(true);
29026 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
29027 Roo.log("no change in with or X");
29031 this.currentSize = cs;
29037 layout : function()
29039 this._resetLayout();
29041 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
29043 this.layoutItems( isInstant );
29045 this._isLayoutInited = true;
29049 _resetLayout : function()
29051 if(this.isHorizontal){
29052 this.horizontalMeasureColumns();
29056 this.verticalMeasureColumns();
29060 verticalMeasureColumns : function()
29062 this.getContainerWidth();
29064 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
29065 // this.colWidth = Math.floor(this.containerWidth * 0.8);
29069 var boxWidth = this.boxWidth + this.padWidth;
29071 if(this.containerWidth < this.boxWidth){
29072 boxWidth = this.containerWidth
29075 var containerWidth = this.containerWidth;
29077 var cols = Math.floor(containerWidth / boxWidth);
29079 this.cols = Math.max( cols, 1 );
29081 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
29083 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
29085 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
29087 this.colWidth = boxWidth + avail - this.padWidth;
29089 this.unitWidth = Math.floor((this.colWidth - (this.gutter * 2)) / 3);
29090 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
29093 horizontalMeasureColumns : function()
29095 this.getContainerWidth();
29097 var boxWidth = this.boxWidth;
29099 if(this.containerWidth < boxWidth){
29100 boxWidth = this.containerWidth;
29103 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
29105 this.el.setHeight(boxWidth);
29109 getContainerWidth : function()
29111 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
29114 layoutItems : function( isInstant )
29116 var items = Roo.apply([], this.bricks);
29118 if(this.isHorizontal){
29119 this._horizontalLayoutItems( items , isInstant );
29123 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
29124 // this._verticalAlternativeLayoutItems( items , isInstant );
29128 this._verticalLayoutItems( items , isInstant );
29132 _verticalLayoutItems : function ( items , isInstant)
29134 if ( !items || !items.length ) {
29139 ['xs', 'xs', 'xs', 'tall'],
29140 ['xs', 'xs', 'tall'],
29141 ['xs', 'xs', 'sm'],
29142 ['xs', 'xs', 'xs'],
29148 ['sm', 'xs', 'xs'],
29152 ['tall', 'xs', 'xs', 'xs'],
29153 ['tall', 'xs', 'xs'],
29165 Roo.each(items, function(item, k){
29167 switch (item.size) {
29168 // these layouts take up a full box,
29179 boxes.push([item]);
29202 var filterPattern = function(box, length)
29210 var pattern = box.slice(0, length);
29214 Roo.each(pattern, function(i){
29215 format.push(i.size);
29218 Roo.each(standard, function(s){
29220 if(String(s) != String(format)){
29229 if(!match && length == 1){
29234 filterPattern(box, length - 1);
29238 queue.push(pattern);
29240 box = box.slice(length, box.length);
29242 filterPattern(box, 4);
29248 Roo.each(boxes, function(box, k){
29254 if(box.length == 1){
29259 filterPattern(box, 4);
29263 this._processVerticalLayoutQueue( queue, isInstant );
29267 // _verticalAlternativeLayoutItems : function( items , isInstant )
29269 // if ( !items || !items.length ) {
29273 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
29277 _horizontalLayoutItems : function ( items , isInstant)
29279 if ( !items || !items.length || items.length < 3) {
29285 var eItems = items.slice(0, 3);
29287 items = items.slice(3, items.length);
29290 ['xs', 'xs', 'xs', 'wide'],
29291 ['xs', 'xs', 'wide'],
29292 ['xs', 'xs', 'sm'],
29293 ['xs', 'xs', 'xs'],
29299 ['sm', 'xs', 'xs'],
29303 ['wide', 'xs', 'xs', 'xs'],
29304 ['wide', 'xs', 'xs'],
29317 Roo.each(items, function(item, k){
29319 switch (item.size) {
29330 boxes.push([item]);
29354 var filterPattern = function(box, length)
29362 var pattern = box.slice(0, length);
29366 Roo.each(pattern, function(i){
29367 format.push(i.size);
29370 Roo.each(standard, function(s){
29372 if(String(s) != String(format)){
29381 if(!match && length == 1){
29386 filterPattern(box, length - 1);
29390 queue.push(pattern);
29392 box = box.slice(length, box.length);
29394 filterPattern(box, 4);
29400 Roo.each(boxes, function(box, k){
29406 if(box.length == 1){
29411 filterPattern(box, 4);
29418 var pos = this.el.getBox(true);
29422 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
29424 var hit_end = false;
29426 Roo.each(queue, function(box){
29430 Roo.each(box, function(b){
29432 b.el.setVisibilityMode(Roo.Element.DISPLAY);
29442 Roo.each(box, function(b){
29444 b.el.setVisibilityMode(Roo.Element.DISPLAY);
29447 mx = Math.max(mx, b.x);
29451 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
29455 Roo.each(box, function(b){
29457 b.el.setVisibilityMode(Roo.Element.DISPLAY);
29471 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
29474 /** Sets position of item in DOM
29475 * @param {Element} item
29476 * @param {Number} x - horizontal position
29477 * @param {Number} y - vertical position
29478 * @param {Boolean} isInstant - disables transitions
29480 _processVerticalLayoutQueue : function( queue, isInstant )
29482 var pos = this.el.getBox(true);
29487 for (var i = 0; i < this.cols; i++){
29491 Roo.each(queue, function(box, k){
29493 var col = k % this.cols;
29495 Roo.each(box, function(b,kk){
29497 b.el.position('absolute');
29499 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
29500 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
29502 if(b.size == 'md-left' || b.size == 'md-right'){
29503 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
29504 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
29507 b.el.setWidth(width);
29508 b.el.setHeight(height);
29510 b.el.select('iframe',true).setSize(width,height);
29514 for (var i = 0; i < this.cols; i++){
29516 if(maxY[i] < maxY[col]){
29521 col = Math.min(col, i);
29525 x = pos.x + col * (this.colWidth + this.padWidth);
29529 var positions = [];
29531 switch (box.length){
29533 positions = this.getVerticalOneBoxColPositions(x, y, box);
29536 positions = this.getVerticalTwoBoxColPositions(x, y, box);
29539 positions = this.getVerticalThreeBoxColPositions(x, y, box);
29542 positions = this.getVerticalFourBoxColPositions(x, y, box);
29548 Roo.each(box, function(b,kk){
29550 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
29552 var sz = b.el.getSize();
29554 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
29562 for (var i = 0; i < this.cols; i++){
29563 mY = Math.max(mY, maxY[i]);
29566 this.el.setHeight(mY - pos.y);
29570 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
29572 // var pos = this.el.getBox(true);
29575 // var maxX = pos.right;
29577 // var maxHeight = 0;
29579 // Roo.each(items, function(item, k){
29583 // item.el.position('absolute');
29585 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
29587 // item.el.setWidth(width);
29589 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
29591 // item.el.setHeight(height);
29594 // item.el.setXY([x, y], isInstant ? false : true);
29596 // item.el.setXY([maxX - width, y], isInstant ? false : true);
29599 // y = y + height + this.alternativePadWidth;
29601 // maxHeight = maxHeight + height + this.alternativePadWidth;
29605 // this.el.setHeight(maxHeight);
29609 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
29611 var pos = this.el.getBox(true);
29616 var maxX = pos.right;
29618 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
29620 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
29622 Roo.each(queue, function(box, k){
29624 Roo.each(box, function(b, kk){
29626 b.el.position('absolute');
29628 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
29629 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
29631 if(b.size == 'md-left' || b.size == 'md-right'){
29632 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
29633 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
29636 b.el.setWidth(width);
29637 b.el.setHeight(height);
29645 var positions = [];
29647 switch (box.length){
29649 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
29652 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
29655 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
29658 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
29664 Roo.each(box, function(b,kk){
29666 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
29668 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
29676 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
29678 Roo.each(eItems, function(b,k){
29680 b.size = (k == 0) ? 'sm' : 'xs';
29681 b.x = (k == 0) ? 2 : 1;
29682 b.y = (k == 0) ? 2 : 1;
29684 b.el.position('absolute');
29686 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
29688 b.el.setWidth(width);
29690 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
29692 b.el.setHeight(height);
29696 var positions = [];
29699 x : maxX - this.unitWidth * 2 - this.gutter,
29704 x : maxX - this.unitWidth,
29705 y : minY + (this.unitWidth + this.gutter) * 2
29709 x : maxX - this.unitWidth * 3 - this.gutter * 2,
29713 Roo.each(eItems, function(b,k){
29715 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
29721 getVerticalOneBoxColPositions : function(x, y, box)
29725 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
29727 if(box[0].size == 'md-left'){
29731 if(box[0].size == 'md-right'){
29736 x : x + (this.unitWidth + this.gutter) * rand,
29743 getVerticalTwoBoxColPositions : function(x, y, box)
29747 if(box[0].size == 'xs'){
29751 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
29755 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
29769 x : x + (this.unitWidth + this.gutter) * 2,
29770 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
29777 getVerticalThreeBoxColPositions : function(x, y, box)
29781 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
29789 x : x + (this.unitWidth + this.gutter) * 1,
29794 x : x + (this.unitWidth + this.gutter) * 2,
29802 if(box[0].size == 'xs' && box[1].size == 'xs'){
29811 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
29815 x : x + (this.unitWidth + this.gutter) * 1,
29829 x : x + (this.unitWidth + this.gutter) * 2,
29834 x : x + (this.unitWidth + this.gutter) * 2,
29835 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
29842 getVerticalFourBoxColPositions : function(x, y, box)
29846 if(box[0].size == 'xs'){
29855 y : y + (this.unitHeight + this.gutter) * 1
29860 y : y + (this.unitHeight + this.gutter) * 2
29864 x : x + (this.unitWidth + this.gutter) * 1,
29878 x : x + (this.unitWidth + this.gutter) * 2,
29883 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
29884 y : y + (this.unitHeight + this.gutter) * 1
29888 x : x + (this.unitWidth + this.gutter) * 2,
29889 y : y + (this.unitWidth + this.gutter) * 2
29896 getHorizontalOneBoxColPositions : function(maxX, minY, box)
29900 if(box[0].size == 'md-left'){
29902 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
29909 if(box[0].size == 'md-right'){
29911 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
29912 y : minY + (this.unitWidth + this.gutter) * 1
29918 var rand = Math.floor(Math.random() * (4 - box[0].y));
29921 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29922 y : minY + (this.unitWidth + this.gutter) * rand
29929 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
29933 if(box[0].size == 'xs'){
29936 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29941 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
29942 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
29950 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29955 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
29956 y : minY + (this.unitWidth + this.gutter) * 2
29963 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
29967 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
29970 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29975 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
29976 y : minY + (this.unitWidth + this.gutter) * 1
29980 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
29981 y : minY + (this.unitWidth + this.gutter) * 2
29988 if(box[0].size == 'xs' && box[1].size == 'xs'){
29991 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
29996 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
30001 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
30002 y : minY + (this.unitWidth + this.gutter) * 1
30010 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
30015 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
30016 y : minY + (this.unitWidth + this.gutter) * 2
30020 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
30021 y : minY + (this.unitWidth + this.gutter) * 2
30028 getHorizontalFourBoxColPositions : function(maxX, minY, box)
30032 if(box[0].size == 'xs'){
30035 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
30040 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
30045 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),
30050 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
30051 y : minY + (this.unitWidth + this.gutter) * 1
30059 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
30064 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
30065 y : minY + (this.unitWidth + this.gutter) * 2
30069 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
30070 y : minY + (this.unitWidth + this.gutter) * 2
30074 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),
30075 y : minY + (this.unitWidth + this.gutter) * 2
30089 * http://masonry.desandro.com
30091 * The idea is to render all the bricks based on vertical width...
30093 * The original code extends 'outlayer' - we might need to use that....
30099 * @class Roo.bootstrap.LayoutMasonryAuto
30100 * @extends Roo.bootstrap.Component
30101 * Bootstrap Layout Masonry class
30104 * Create a new Element
30105 * @param {Object} config The config object
30108 Roo.bootstrap.LayoutMasonryAuto = function(config){
30109 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
30112 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
30115 * @cfg {Boolean} isFitWidth - resize the width..
30117 isFitWidth : false, // options..
30119 * @cfg {Boolean} isOriginLeft = left align?
30121 isOriginLeft : true,
30123 * @cfg {Boolean} isOriginTop = top align?
30125 isOriginTop : false,
30127 * @cfg {Boolean} isLayoutInstant = no animation?
30129 isLayoutInstant : false, // needed?
30131 * @cfg {Boolean} isResizingContainer = not sure if this is used..
30133 isResizingContainer : true,
30135 * @cfg {Number} columnWidth width of the columns
30141 * @cfg {Number} maxCols maximum number of columns
30146 * @cfg {Number} padHeight padding below box..
30152 * @cfg {Boolean} isAutoInitial defalut true
30155 isAutoInitial : true,
30161 initialColumnWidth : 0,
30162 currentSize : null,
30164 colYs : null, // array.
30171 bricks: null, //CompositeElement
30172 cols : 0, // array?
30173 // element : null, // wrapped now this.el
30174 _isLayoutInited : null,
30177 getAutoCreate : function(){
30181 cls: 'blog-masonary-wrapper ' + this.cls,
30183 cls : 'mas-boxes masonary'
30190 getChildContainer: function( )
30192 if (this.boxesEl) {
30193 return this.boxesEl;
30196 this.boxesEl = this.el.select('.mas-boxes').first();
30198 return this.boxesEl;
30202 initEvents : function()
30206 if(this.isAutoInitial){
30207 Roo.log('hook children rendered');
30208 this.on('childrenrendered', function() {
30209 Roo.log('children rendered');
30216 initial : function()
30218 this.reloadItems();
30220 this.currentSize = this.el.getBox(true);
30222 /// was window resize... - let's see if this works..
30223 Roo.EventManager.onWindowResize(this.resize, this);
30225 if(!this.isAutoInitial){
30230 this.layout.defer(500,this);
30233 reloadItems: function()
30235 this.bricks = this.el.select('.masonry-brick', true);
30237 this.bricks.each(function(b) {
30238 //Roo.log(b.getSize());
30239 if (!b.attr('originalwidth')) {
30240 b.attr('originalwidth', b.getSize().width);
30245 Roo.log(this.bricks.elements.length);
30248 resize : function()
30251 var cs = this.el.getBox(true);
30253 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
30254 Roo.log("no change in with or X");
30257 this.currentSize = cs;
30261 layout : function()
30264 this._resetLayout();
30265 //this._manageStamps();
30267 // don't animate first layout
30268 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
30269 this.layoutItems( isInstant );
30271 // flag for initalized
30272 this._isLayoutInited = true;
30275 layoutItems : function( isInstant )
30277 //var items = this._getItemsForLayout( this.items );
30278 // original code supports filtering layout items.. we just ignore it..
30280 this._layoutItems( this.bricks , isInstant );
30282 this._postLayout();
30284 _layoutItems : function ( items , isInstant)
30286 //this.fireEvent( 'layout', this, items );
30289 if ( !items || !items.elements.length ) {
30290 // no items, emit event with empty array
30295 items.each(function(item) {
30296 Roo.log("layout item");
30298 // get x/y object from method
30299 var position = this._getItemLayoutPosition( item );
30301 position.item = item;
30302 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
30303 queue.push( position );
30306 this._processLayoutQueue( queue );
30308 /** Sets position of item in DOM
30309 * @param {Element} item
30310 * @param {Number} x - horizontal position
30311 * @param {Number} y - vertical position
30312 * @param {Boolean} isInstant - disables transitions
30314 _processLayoutQueue : function( queue )
30316 for ( var i=0, len = queue.length; i < len; i++ ) {
30317 var obj = queue[i];
30318 obj.item.position('absolute');
30319 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
30325 * Any logic you want to do after each layout,
30326 * i.e. size the container
30328 _postLayout : function()
30330 this.resizeContainer();
30333 resizeContainer : function()
30335 if ( !this.isResizingContainer ) {
30338 var size = this._getContainerSize();
30340 this.el.setSize(size.width,size.height);
30341 this.boxesEl.setSize(size.width,size.height);
30347 _resetLayout : function()
30349 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
30350 this.colWidth = this.el.getWidth();
30351 //this.gutter = this.el.getWidth();
30353 this.measureColumns();
30359 this.colYs.push( 0 );
30365 measureColumns : function()
30367 this.getContainerWidth();
30368 // if columnWidth is 0, default to outerWidth of first item
30369 if ( !this.columnWidth ) {
30370 var firstItem = this.bricks.first();
30371 Roo.log(firstItem);
30372 this.columnWidth = this.containerWidth;
30373 if (firstItem && firstItem.attr('originalwidth') ) {
30374 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
30376 // columnWidth fall back to item of first element
30377 Roo.log("set column width?");
30378 this.initialColumnWidth = this.columnWidth ;
30380 // if first elem has no width, default to size of container
30385 if (this.initialColumnWidth) {
30386 this.columnWidth = this.initialColumnWidth;
30391 // column width is fixed at the top - however if container width get's smaller we should
30394 // this bit calcs how man columns..
30396 var columnWidth = this.columnWidth += this.gutter;
30398 // calculate columns
30399 var containerWidth = this.containerWidth + this.gutter;
30401 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
30402 // fix rounding errors, typically with gutters
30403 var excess = columnWidth - containerWidth % columnWidth;
30406 // if overshoot is less than a pixel, round up, otherwise floor it
30407 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
30408 cols = Math[ mathMethod ]( cols );
30409 this.cols = Math.max( cols, 1 );
30410 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
30412 // padding positioning..
30413 var totalColWidth = this.cols * this.columnWidth;
30414 var padavail = this.containerWidth - totalColWidth;
30415 // so for 2 columns - we need 3 'pads'
30417 var padNeeded = (1+this.cols) * this.padWidth;
30419 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
30421 this.columnWidth += padExtra
30422 //this.padWidth = Math.floor(padavail / ( this.cols));
30424 // adjust colum width so that padding is fixed??
30426 // we have 3 columns ... total = width * 3
30427 // we have X left over... that should be used by
30429 //if (this.expandC) {
30437 getContainerWidth : function()
30439 /* // container is parent if fit width
30440 var container = this.isFitWidth ? this.element.parentNode : this.element;
30441 // check that this.size and size are there
30442 // IE8 triggers resize on body size change, so they might not be
30444 var size = getSize( container ); //FIXME
30445 this.containerWidth = size && size.innerWidth; //FIXME
30448 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
30452 _getItemLayoutPosition : function( item ) // what is item?
30454 // we resize the item to our columnWidth..
30456 item.setWidth(this.columnWidth);
30457 item.autoBoxAdjust = false;
30459 var sz = item.getSize();
30461 // how many columns does this brick span
30462 var remainder = this.containerWidth % this.columnWidth;
30464 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
30465 // round if off by 1 pixel, otherwise use ceil
30466 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
30467 colSpan = Math.min( colSpan, this.cols );
30469 // normally this should be '1' as we dont' currently allow multi width columns..
30471 var colGroup = this._getColGroup( colSpan );
30472 // get the minimum Y value from the columns
30473 var minimumY = Math.min.apply( Math, colGroup );
30474 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
30476 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
30478 // position the brick
30480 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
30481 y: this.currentSize.y + minimumY + this.padHeight
30485 // apply setHeight to necessary columns
30486 var setHeight = minimumY + sz.height + this.padHeight;
30487 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
30489 var setSpan = this.cols + 1 - colGroup.length;
30490 for ( var i = 0; i < setSpan; i++ ) {
30491 this.colYs[ shortColIndex + i ] = setHeight ;
30498 * @param {Number} colSpan - number of columns the element spans
30499 * @returns {Array} colGroup
30501 _getColGroup : function( colSpan )
30503 if ( colSpan < 2 ) {
30504 // if brick spans only one column, use all the column Ys
30509 // how many different places could this brick fit horizontally
30510 var groupCount = this.cols + 1 - colSpan;
30511 // for each group potential horizontal position
30512 for ( var i = 0; i < groupCount; i++ ) {
30513 // make an array of colY values for that one group
30514 var groupColYs = this.colYs.slice( i, i + colSpan );
30515 // and get the max value of the array
30516 colGroup[i] = Math.max.apply( Math, groupColYs );
30521 _manageStamp : function( stamp )
30523 var stampSize = stamp.getSize();
30524 var offset = stamp.getBox();
30525 // get the columns that this stamp affects
30526 var firstX = this.isOriginLeft ? offset.x : offset.right;
30527 var lastX = firstX + stampSize.width;
30528 var firstCol = Math.floor( firstX / this.columnWidth );
30529 firstCol = Math.max( 0, firstCol );
30531 var lastCol = Math.floor( lastX / this.columnWidth );
30532 // lastCol should not go over if multiple of columnWidth #425
30533 lastCol -= lastX % this.columnWidth ? 0 : 1;
30534 lastCol = Math.min( this.cols - 1, lastCol );
30536 // set colYs to bottom of the stamp
30537 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
30540 for ( var i = firstCol; i <= lastCol; i++ ) {
30541 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
30546 _getContainerSize : function()
30548 this.maxY = Math.max.apply( Math, this.colYs );
30553 if ( this.isFitWidth ) {
30554 size.width = this._getContainerFitWidth();
30560 _getContainerFitWidth : function()
30562 var unusedCols = 0;
30563 // count unused columns
30566 if ( this.colYs[i] !== 0 ) {
30571 // fit container to columns that have been used
30572 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
30575 needsResizeLayout : function()
30577 var previousWidth = this.containerWidth;
30578 this.getContainerWidth();
30579 return previousWidth !== this.containerWidth;
30594 * @class Roo.bootstrap.MasonryBrick
30595 * @extends Roo.bootstrap.Component
30596 * Bootstrap MasonryBrick class
30599 * Create a new MasonryBrick
30600 * @param {Object} config The config object
30603 Roo.bootstrap.MasonryBrick = function(config){
30604 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
30610 * When a MasonryBrick is clcik
30611 * @param {Roo.bootstrap.MasonryBrick} this
30612 * @param {Roo.EventObject} e
30618 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
30621 * @cfg {String} title
30625 * @cfg {String} html
30629 * @cfg {String} bgimage
30633 * @cfg {String} videourl
30637 * @cfg {String} cls
30641 * @cfg {String} href
30645 * @cfg {String} (xs|sm|md|md-left|md-right|tall|wide) size
30650 * @cfg {String} (center|bottom) placetitle
30654 getAutoCreate : function()
30656 var cls = 'masonry-brick';
30658 if(this.href.length){
30659 cls += ' masonry-brick-link';
30662 if(this.bgimage.length){
30663 cls += ' masonry-brick-image';
30667 cls += ' masonry-' + this.size + '-brick';
30670 if(this.placetitle.length){
30672 switch (this.placetitle) {
30674 cls += ' masonry-center-title';
30677 cls += ' masonry-bottom-title';
30684 if(!this.html.length && !this.bgimage.length){
30685 cls += ' masonry-center-title';
30688 if(!this.html.length && this.bgimage.length){
30689 cls += ' masonry-bottom-title';
30694 cls += ' ' + this.cls;
30698 tag: (this.href.length) ? 'a' : 'div',
30703 cls: 'masonry-brick-paragraph',
30709 if(this.href.length){
30710 cfg.href = this.href;
30713 var cn = cfg.cn[0].cn;
30715 if(this.title.length){
30718 cls: 'masonry-brick-title',
30723 if(this.html.length){
30726 cls: 'masonry-brick-text',
30730 if (!this.title.length && !this.html.length) {
30731 cfg.cn[0].cls += ' hide';
30734 if(this.bgimage.length){
30737 cls: 'masonry-brick-image-view',
30741 if(this.videourl.length){
30742 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
30743 // youtube support only?
30746 cls: 'masonry-brick-image-view',
30749 allowfullscreen : true
30758 initEvents: function()
30760 switch (this.size) {
30762 // this.intSize = 1;
30767 // this.intSize = 2;
30774 // this.intSize = 3;
30779 // this.intSize = 3;
30784 // this.intSize = 3;
30789 // this.intSize = 3;
30801 this.el.on('touchstart', this.onTouchStart, this);
30802 this.el.on('touchmove', this.onTouchMove, this);
30803 this.el.on('touchend', this.onTouchEnd, this);
30804 this.el.on('contextmenu', this.onContextMenu, this);
30806 this.el.on('mouseenter' ,this.enter, this);
30807 this.el.on('mouseleave', this.leave, this);
30810 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
30811 this.parent().bricks.push(this);
30816 onClick: function(e, el)
30822 var time = this.endTimer - this.startTimer;
30830 e.preventDefault();
30833 enter: function(e, el)
30835 e.preventDefault();
30837 if(this.bgimage.length && this.html.length){
30838 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
30842 leave: function(e, el)
30844 e.preventDefault();
30846 if(this.bgimage.length && this.html.length){
30847 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
30851 onTouchStart: function(e, el)
30853 // e.preventDefault();
30855 this.touchmoved = false;
30857 if(!this.bgimage.length || !this.html.length){
30861 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
30863 this.timer = new Date().getTime();
30867 onTouchMove: function(e, el)
30869 this.touchmoved = true;
30872 onContextMenu : function(e,el)
30874 e.preventDefault();
30875 e.stopPropagation();
30879 onTouchEnd: function(e, el)
30881 // e.preventDefault();
30883 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
30890 if(!this.bgimage.length || !this.html.length){
30892 if(this.href.length){
30893 window.location.href = this.href;
30899 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
30901 window.location.href = this.href;
30916 * @class Roo.bootstrap.Brick
30917 * @extends Roo.bootstrap.Component
30918 * Bootstrap Brick class
30921 * Create a new Brick
30922 * @param {Object} config The config object
30925 Roo.bootstrap.Brick = function(config){
30926 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
30932 * When a Brick is click
30933 * @param {Roo.bootstrap.Brick} this
30934 * @param {Roo.EventObject} e
30940 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
30943 * @cfg {String} title
30947 * @cfg {String} html
30951 * @cfg {String} bgimage
30955 * @cfg {String} cls
30959 * @cfg {String} href
30963 * @cfg {String} video
30967 * @cfg {Boolean} square
30971 getAutoCreate : function()
30973 var cls = 'roo-brick';
30975 if(this.href.length){
30976 cls += ' roo-brick-link';
30979 if(this.bgimage.length){
30980 cls += ' roo-brick-image';
30983 if(!this.html.length && !this.bgimage.length){
30984 cls += ' roo-brick-center-title';
30987 if(!this.html.length && this.bgimage.length){
30988 cls += ' roo-brick-bottom-title';
30992 cls += ' ' + this.cls;
30996 tag: (this.href.length) ? 'a' : 'div',
31001 cls: 'roo-brick-paragraph',
31007 if(this.href.length){
31008 cfg.href = this.href;
31011 var cn = cfg.cn[0].cn;
31013 if(this.title.length){
31016 cls: 'roo-brick-title',
31021 if(this.html.length){
31024 cls: 'roo-brick-text',
31031 if(this.bgimage.length){
31034 cls: 'roo-brick-image-view',
31042 initEvents: function()
31044 if(this.title.length || this.html.length){
31045 this.el.on('mouseenter' ,this.enter, this);
31046 this.el.on('mouseleave', this.leave, this);
31050 Roo.EventManager.onWindowResize(this.resize, this);
31055 resize : function()
31057 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
31059 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
31060 // paragraph.setHeight(paragraph.getWidth());
31062 if(this.bgimage.length){
31063 var image = this.el.select('.roo-brick-image-view', true).first();
31064 image.setWidth(paragraph.getWidth());
31065 image.setHeight(paragraph.getWidth());
31070 enter: function(e, el)
31072 e.preventDefault();
31074 if(this.bgimage.length){
31075 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
31076 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
31080 leave: function(e, el)
31082 e.preventDefault();
31084 if(this.bgimage.length){
31085 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
31086 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
31096 * Ext JS Library 1.1.1
31097 * Copyright(c) 2006-2007, Ext JS, LLC.
31099 * Originally Released Under LGPL - original licence link has changed is not relivant.
31102 * <script type="text/javascript">
31107 * @class Roo.bootstrap.SplitBar
31108 * @extends Roo.util.Observable
31109 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
31113 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
31114 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
31115 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
31116 split.minSize = 100;
31117 split.maxSize = 600;
31118 split.animate = true;
31119 split.on('moved', splitterMoved);
31122 * Create a new SplitBar
31123 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
31124 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
31125 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
31126 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
31127 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
31128 position of the SplitBar).
31130 Roo.bootstrap.SplitBar = function(cfg){
31135 // dragElement : elm
31136 // resizingElement: el,
31138 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
31139 // placement : Roo.bootstrap.SplitBar.LEFT ,
31140 // existingProxy ???
31143 this.el = Roo.get(cfg.dragElement, true);
31144 this.el.dom.unselectable = "on";
31146 this.resizingEl = Roo.get(cfg.resizingElement, true);
31150 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
31151 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
31154 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
31157 * The minimum size of the resizing element. (Defaults to 0)
31163 * The maximum size of the resizing element. (Defaults to 2000)
31166 this.maxSize = 2000;
31169 * Whether to animate the transition to the new size
31172 this.animate = false;
31175 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
31178 this.useShim = false;
31183 if(!cfg.existingProxy){
31185 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
31187 this.proxy = Roo.get(cfg.existingProxy).dom;
31190 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
31193 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
31196 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
31199 this.dragSpecs = {};
31202 * @private The adapter to use to positon and resize elements
31204 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
31205 this.adapter.init(this);
31207 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
31209 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
31210 this.el.addClass("roo-splitbar-h");
31213 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
31214 this.el.addClass("roo-splitbar-v");
31220 * Fires when the splitter is moved (alias for {@link #event-moved})
31221 * @param {Roo.bootstrap.SplitBar} this
31222 * @param {Number} newSize the new width or height
31227 * Fires when the splitter is moved
31228 * @param {Roo.bootstrap.SplitBar} this
31229 * @param {Number} newSize the new width or height
31233 * @event beforeresize
31234 * Fires before the splitter is dragged
31235 * @param {Roo.bootstrap.SplitBar} this
31237 "beforeresize" : true,
31239 "beforeapply" : true
31242 Roo.util.Observable.call(this);
31245 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
31246 onStartProxyDrag : function(x, y){
31247 this.fireEvent("beforeresize", this);
31249 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
31251 o.enableDisplayMode("block");
31252 // all splitbars share the same overlay
31253 Roo.bootstrap.SplitBar.prototype.overlay = o;
31255 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
31256 this.overlay.show();
31257 Roo.get(this.proxy).setDisplayed("block");
31258 var size = this.adapter.getElementSize(this);
31259 this.activeMinSize = this.getMinimumSize();;
31260 this.activeMaxSize = this.getMaximumSize();;
31261 var c1 = size - this.activeMinSize;
31262 var c2 = Math.max(this.activeMaxSize - size, 0);
31263 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
31264 this.dd.resetConstraints();
31265 this.dd.setXConstraint(
31266 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
31267 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
31269 this.dd.setYConstraint(0, 0);
31271 this.dd.resetConstraints();
31272 this.dd.setXConstraint(0, 0);
31273 this.dd.setYConstraint(
31274 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
31275 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
31278 this.dragSpecs.startSize = size;
31279 this.dragSpecs.startPoint = [x, y];
31280 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
31284 * @private Called after the drag operation by the DDProxy
31286 onEndProxyDrag : function(e){
31287 Roo.get(this.proxy).setDisplayed(false);
31288 var endPoint = Roo.lib.Event.getXY(e);
31290 this.overlay.hide();
31293 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
31294 newSize = this.dragSpecs.startSize +
31295 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
31296 endPoint[0] - this.dragSpecs.startPoint[0] :
31297 this.dragSpecs.startPoint[0] - endPoint[0]
31300 newSize = this.dragSpecs.startSize +
31301 (this.placement == Roo.bootstrap.SplitBar.TOP ?
31302 endPoint[1] - this.dragSpecs.startPoint[1] :
31303 this.dragSpecs.startPoint[1] - endPoint[1]
31306 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
31307 if(newSize != this.dragSpecs.startSize){
31308 if(this.fireEvent('beforeapply', this, newSize) !== false){
31309 this.adapter.setElementSize(this, newSize);
31310 this.fireEvent("moved", this, newSize);
31311 this.fireEvent("resize", this, newSize);
31317 * Get the adapter this SplitBar uses
31318 * @return The adapter object
31320 getAdapter : function(){
31321 return this.adapter;
31325 * Set the adapter this SplitBar uses
31326 * @param {Object} adapter A SplitBar adapter object
31328 setAdapter : function(adapter){
31329 this.adapter = adapter;
31330 this.adapter.init(this);
31334 * Gets the minimum size for the resizing element
31335 * @return {Number} The minimum size
31337 getMinimumSize : function(){
31338 return this.minSize;
31342 * Sets the minimum size for the resizing element
31343 * @param {Number} minSize The minimum size
31345 setMinimumSize : function(minSize){
31346 this.minSize = minSize;
31350 * Gets the maximum size for the resizing element
31351 * @return {Number} The maximum size
31353 getMaximumSize : function(){
31354 return this.maxSize;
31358 * Sets the maximum size for the resizing element
31359 * @param {Number} maxSize The maximum size
31361 setMaximumSize : function(maxSize){
31362 this.maxSize = maxSize;
31366 * Sets the initialize size for the resizing element
31367 * @param {Number} size The initial size
31369 setCurrentSize : function(size){
31370 var oldAnimate = this.animate;
31371 this.animate = false;
31372 this.adapter.setElementSize(this, size);
31373 this.animate = oldAnimate;
31377 * Destroy this splitbar.
31378 * @param {Boolean} removeEl True to remove the element
31380 destroy : function(removeEl){
31382 this.shim.remove();
31385 this.proxy.parentNode.removeChild(this.proxy);
31393 * @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.
31395 Roo.bootstrap.SplitBar.createProxy = function(dir){
31396 var proxy = new Roo.Element(document.createElement("div"));
31397 proxy.unselectable();
31398 var cls = 'roo-splitbar-proxy';
31399 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
31400 document.body.appendChild(proxy.dom);
31405 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
31406 * Default Adapter. It assumes the splitter and resizing element are not positioned
31407 * elements and only gets/sets the width of the element. Generally used for table based layouts.
31409 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
31412 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
31413 // do nothing for now
31414 init : function(s){
31418 * Called before drag operations to get the current size of the resizing element.
31419 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
31421 getElementSize : function(s){
31422 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
31423 return s.resizingEl.getWidth();
31425 return s.resizingEl.getHeight();
31430 * Called after drag operations to set the size of the resizing element.
31431 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
31432 * @param {Number} newSize The new size to set
31433 * @param {Function} onComplete A function to be invoked when resizing is complete
31435 setElementSize : function(s, newSize, onComplete){
31436 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
31438 s.resizingEl.setWidth(newSize);
31440 onComplete(s, newSize);
31443 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
31448 s.resizingEl.setHeight(newSize);
31450 onComplete(s, newSize);
31453 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
31460 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
31461 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
31462 * Adapter that moves the splitter element to align with the resized sizing element.
31463 * Used with an absolute positioned SplitBar.
31464 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
31465 * document.body, make sure you assign an id to the body element.
31467 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
31468 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
31469 this.container = Roo.get(container);
31472 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
31473 init : function(s){
31474 this.basic.init(s);
31477 getElementSize : function(s){
31478 return this.basic.getElementSize(s);
31481 setElementSize : function(s, newSize, onComplete){
31482 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
31485 moveSplitter : function(s){
31486 var yes = Roo.bootstrap.SplitBar;
31487 switch(s.placement){
31489 s.el.setX(s.resizingEl.getRight());
31492 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
31495 s.el.setY(s.resizingEl.getBottom());
31498 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
31505 * Orientation constant - Create a vertical SplitBar
31509 Roo.bootstrap.SplitBar.VERTICAL = 1;
31512 * Orientation constant - Create a horizontal SplitBar
31516 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
31519 * Placement constant - The resizing element is to the left of the splitter element
31523 Roo.bootstrap.SplitBar.LEFT = 1;
31526 * Placement constant - The resizing element is to the right of the splitter element
31530 Roo.bootstrap.SplitBar.RIGHT = 2;
31533 * Placement constant - The resizing element is positioned above the splitter element
31537 Roo.bootstrap.SplitBar.TOP = 3;
31540 * Placement constant - The resizing element is positioned under splitter element
31544 Roo.bootstrap.SplitBar.BOTTOM = 4;
31545 Roo.namespace("Roo.bootstrap.layout");/*
31547 * Ext JS Library 1.1.1
31548 * Copyright(c) 2006-2007, Ext JS, LLC.
31550 * Originally Released Under LGPL - original licence link has changed is not relivant.
31553 * <script type="text/javascript">
31557 * @class Roo.bootstrap.layout.Manager
31558 * @extends Roo.bootstrap.Component
31559 * Base class for layout managers.
31561 Roo.bootstrap.layout.Manager = function(config)
31563 Roo.bootstrap.layout.Manager.superclass.constructor.call(this);
31569 /** false to disable window resize monitoring @type Boolean */
31570 this.monitorWindowResize = true;
31575 * Fires when a layout is performed.
31576 * @param {Roo.LayoutManager} this
31580 * @event regionresized
31581 * Fires when the user resizes a region.
31582 * @param {Roo.LayoutRegion} region The resized region
31583 * @param {Number} newSize The new size (width for east/west, height for north/south)
31585 "regionresized" : true,
31587 * @event regioncollapsed
31588 * Fires when a region is collapsed.
31589 * @param {Roo.LayoutRegion} region The collapsed region
31591 "regioncollapsed" : true,
31593 * @event regionexpanded
31594 * Fires when a region is expanded.
31595 * @param {Roo.LayoutRegion} region The expanded region
31597 "regionexpanded" : true
31599 this.updating = false;
31602 this.el = Roo.get(config.el);
31608 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
31613 monitorWindowResize : true,
31619 onRender : function(ct, position)
31622 this.el = Roo.get(ct);
31628 initEvents: function()
31632 // ie scrollbar fix
31633 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
31634 document.body.scroll = "no";
31635 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
31636 this.el.position('relative');
31638 this.id = this.el.id;
31639 this.el.addClass("roo-layout-container");
31640 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
31641 if(this.el.dom != document.body ) {
31642 this.el.on('resize', this.layout,this);
31643 this.el.on('show', this.layout,this);
31649 * Returns true if this layout is currently being updated
31650 * @return {Boolean}
31652 isUpdating : function(){
31653 return this.updating;
31657 * Suspend the LayoutManager from doing auto-layouts while
31658 * making multiple add or remove calls
31660 beginUpdate : function(){
31661 this.updating = true;
31665 * Restore auto-layouts and optionally disable the manager from performing a layout
31666 * @param {Boolean} noLayout true to disable a layout update
31668 endUpdate : function(noLayout){
31669 this.updating = false;
31675 layout: function(){
31679 onRegionResized : function(region, newSize){
31680 this.fireEvent("regionresized", region, newSize);
31684 onRegionCollapsed : function(region){
31685 this.fireEvent("regioncollapsed", region);
31688 onRegionExpanded : function(region){
31689 this.fireEvent("regionexpanded", region);
31693 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
31694 * performs box-model adjustments.
31695 * @return {Object} The size as an object {width: (the width), height: (the height)}
31697 getViewSize : function()
31700 if(this.el.dom != document.body){
31701 size = this.el.getSize();
31703 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
31705 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
31706 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
31711 * Returns the Element this layout is bound to.
31712 * @return {Roo.Element}
31714 getEl : function(){
31719 * Returns the specified region.
31720 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
31721 * @return {Roo.LayoutRegion}
31723 getRegion : function(target){
31724 return this.regions[target.toLowerCase()];
31727 onWindowResize : function(){
31728 if(this.monitorWindowResize){
31734 * Ext JS Library 1.1.1
31735 * Copyright(c) 2006-2007, Ext JS, LLC.
31737 * Originally Released Under LGPL - original licence link has changed is not relivant.
31740 * <script type="text/javascript">
31743 * @class Roo.bootstrap.layout.Border
31744 * @extends Roo.bootstrap.layout.Manager
31745 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
31746 * please see: examples/bootstrap/nested.html<br><br>
31748 <b>The container the layout is rendered into can be either the body element or any other element.
31749 If it is not the body element, the container needs to either be an absolute positioned element,
31750 or you will need to add "position:relative" to the css of the container. You will also need to specify
31751 the container size if it is not the body element.</b>
31754 * Create a new Border
31755 * @param {Object} config Configuration options
31757 Roo.bootstrap.layout.Border = function(config){
31758 config = config || {};
31759 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
31763 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
31764 if(config[region]){
31765 config[region].region = region;
31766 this.addRegion(config[region]);
31772 Roo.bootstrap.layout.Border.regions = ["north","south","east","west","center"];
31774 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
31776 * Creates and adds a new region if it doesn't already exist.
31777 * @param {String} target The target region key (north, south, east, west or center).
31778 * @param {Object} config The regions config object
31779 * @return {BorderLayoutRegion} The new region
31781 addRegion : function(config)
31783 if(!this.regions[config.region]){
31784 var r = this.factory(config);
31785 this.bindRegion(r);
31787 return this.regions[config.region];
31791 bindRegion : function(r){
31792 this.regions[r.config.region] = r;
31794 r.on("visibilitychange", this.layout, this);
31795 r.on("paneladded", this.layout, this);
31796 r.on("panelremoved", this.layout, this);
31797 r.on("invalidated", this.layout, this);
31798 r.on("resized", this.onRegionResized, this);
31799 r.on("collapsed", this.onRegionCollapsed, this);
31800 r.on("expanded", this.onRegionExpanded, this);
31804 * Performs a layout update.
31806 layout : function()
31808 if(this.updating) {
31812 // render all the rebions if they have not been done alreayd?
31813 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
31814 if(this.regions[region] && !this.regions[region].bodyEl){
31815 this.regions[region].onRender(this.el)
31819 var size = this.getViewSize();
31820 var w = size.width;
31821 var h = size.height;
31826 //var x = 0, y = 0;
31828 var rs = this.regions;
31829 var north = rs["north"];
31830 var south = rs["south"];
31831 var west = rs["west"];
31832 var east = rs["east"];
31833 var center = rs["center"];
31834 //if(this.hideOnLayout){ // not supported anymore
31835 //c.el.setStyle("display", "none");
31837 if(north && north.isVisible()){
31838 var b = north.getBox();
31839 var m = north.getMargins();
31840 b.width = w - (m.left+m.right);
31843 centerY = b.height + b.y + m.bottom;
31844 centerH -= centerY;
31845 north.updateBox(this.safeBox(b));
31847 if(south && south.isVisible()){
31848 var b = south.getBox();
31849 var m = south.getMargins();
31850 b.width = w - (m.left+m.right);
31852 var totalHeight = (b.height + m.top + m.bottom);
31853 b.y = h - totalHeight + m.top;
31854 centerH -= totalHeight;
31855 south.updateBox(this.safeBox(b));
31857 if(west && west.isVisible()){
31858 var b = west.getBox();
31859 var m = west.getMargins();
31860 b.height = centerH - (m.top+m.bottom);
31862 b.y = centerY + m.top;
31863 var totalWidth = (b.width + m.left + m.right);
31864 centerX += totalWidth;
31865 centerW -= totalWidth;
31866 west.updateBox(this.safeBox(b));
31868 if(east && east.isVisible()){
31869 var b = east.getBox();
31870 var m = east.getMargins();
31871 b.height = centerH - (m.top+m.bottom);
31872 var totalWidth = (b.width + m.left + m.right);
31873 b.x = w - totalWidth + m.left;
31874 b.y = centerY + m.top;
31875 centerW -= totalWidth;
31876 east.updateBox(this.safeBox(b));
31879 var m = center.getMargins();
31881 x: centerX + m.left,
31882 y: centerY + m.top,
31883 width: centerW - (m.left+m.right),
31884 height: centerH - (m.top+m.bottom)
31886 //if(this.hideOnLayout){
31887 //center.el.setStyle("display", "block");
31889 center.updateBox(this.safeBox(centerBox));
31892 this.fireEvent("layout", this);
31896 safeBox : function(box){
31897 box.width = Math.max(0, box.width);
31898 box.height = Math.max(0, box.height);
31903 * Adds a ContentPanel (or subclass) to this layout.
31904 * @param {String} target The target region key (north, south, east, west or center).
31905 * @param {Roo.ContentPanel} panel The panel to add
31906 * @return {Roo.ContentPanel} The added panel
31908 add : function(target, panel){
31910 target = target.toLowerCase();
31911 return this.regions[target].add(panel);
31915 * Remove a ContentPanel (or subclass) to this layout.
31916 * @param {String} target The target region key (north, south, east, west or center).
31917 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
31918 * @return {Roo.ContentPanel} The removed panel
31920 remove : function(target, panel){
31921 target = target.toLowerCase();
31922 return this.regions[target].remove(panel);
31926 * Searches all regions for a panel with the specified id
31927 * @param {String} panelId
31928 * @return {Roo.ContentPanel} The panel or null if it wasn't found
31930 findPanel : function(panelId){
31931 var rs = this.regions;
31932 for(var target in rs){
31933 if(typeof rs[target] != "function"){
31934 var p = rs[target].getPanel(panelId);
31944 * Searches all regions for a panel with the specified id and activates (shows) it.
31945 * @param {String/ContentPanel} panelId The panels id or the panel itself
31946 * @return {Roo.ContentPanel} The shown panel or null
31948 showPanel : function(panelId) {
31949 var rs = this.regions;
31950 for(var target in rs){
31951 var r = rs[target];
31952 if(typeof r != "function"){
31953 if(r.hasPanel(panelId)){
31954 return r.showPanel(panelId);
31962 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
31963 * @param {Roo.state.Provider} provider (optional) An alternate state provider
31966 restoreState : function(provider){
31968 provider = Roo.state.Manager;
31970 var sm = new Roo.LayoutStateManager();
31971 sm.init(this, provider);
31977 * Adds a xtype elements to the layout.
31981 xtype : 'ContentPanel',
31988 xtype : 'NestedLayoutPanel',
31994 items : [ ... list of content panels or nested layout panels.. ]
31998 * @param {Object} cfg Xtype definition of item to add.
32000 addxtype : function(cfg)
32002 // basically accepts a pannel...
32003 // can accept a layout region..!?!?
32004 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
32007 // theory? children can only be panels??
32009 //if (!cfg.xtype.match(/Panel$/)) {
32014 if (typeof(cfg.region) == 'undefined') {
32015 Roo.log("Failed to add Panel, region was not set");
32019 var region = cfg.region;
32025 xitems = cfg.items;
32032 case 'Content': // ContentPanel (el, cfg)
32033 case 'Scroll': // ContentPanel (el, cfg)
32035 cfg.autoCreate = true;
32036 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
32038 // var el = this.el.createChild();
32039 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
32042 this.add(region, ret);
32046 case 'TreePanel': // our new panel!
32047 cfg.el = this.el.createChild();
32048 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
32049 this.add(region, ret);
32054 // create a new Layout (which is a Border Layout...
32056 var clayout = cfg.layout;
32057 clayout.el = this.el.createChild();
32058 clayout.items = clayout.items || [];
32062 // replace this exitems with the clayout ones..
32063 xitems = clayout.items;
32065 // force background off if it's in center...
32066 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
32067 cfg.background = false;
32069 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
32072 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
32073 //console.log('adding nested layout panel ' + cfg.toSource());
32074 this.add(region, ret);
32075 nb = {}; /// find first...
32080 // needs grid and region
32082 //var el = this.getRegion(region).el.createChild();
32084 *var el = this.el.createChild();
32085 // create the grid first...
32086 cfg.grid.container = el;
32087 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
32090 if (region == 'center' && this.active ) {
32091 cfg.background = false;
32094 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
32096 this.add(region, ret);
32098 if (cfg.background) {
32099 // render grid on panel activation (if panel background)
32100 ret.on('activate', function(gp) {
32101 if (!gp.grid.rendered) {
32102 // gp.grid.render(el);
32106 // cfg.grid.render(el);
32112 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
32113 // it was the old xcomponent building that caused this before.
32114 // espeically if border is the top element in the tree.
32124 if (typeof(Roo[cfg.xtype]) != 'undefined') {
32126 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
32127 this.add(region, ret);
32131 throw "Can not add '" + cfg.xtype + "' to Border";
32137 this.beginUpdate();
32141 Roo.each(xitems, function(i) {
32142 region = nb && i.region ? i.region : false;
32144 var add = ret.addxtype(i);
32147 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
32148 if (!i.background) {
32149 abn[region] = nb[region] ;
32156 // make the last non-background panel active..
32157 //if (nb) { Roo.log(abn); }
32160 for(var r in abn) {
32161 region = this.getRegion(r);
32163 // tried using nb[r], but it does not work..
32165 region.showPanel(abn[r]);
32176 factory : function(cfg)
32179 var validRegions = Roo.bootstrap.layout.Border.regions;
32181 var target = cfg.region;
32184 var r = Roo.bootstrap.layout;
32188 return new r.North(cfg);
32190 return new r.South(cfg);
32192 return new r.East(cfg);
32194 return new r.West(cfg);
32196 return new r.Center(cfg);
32198 throw 'Layout region "'+target+'" not supported.';
32205 * Ext JS Library 1.1.1
32206 * Copyright(c) 2006-2007, Ext JS, LLC.
32208 * Originally Released Under LGPL - original licence link has changed is not relivant.
32211 * <script type="text/javascript">
32215 * @class Roo.bootstrap.layout.Basic
32216 * @extends Roo.util.Observable
32217 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
32218 * and does not have a titlebar, tabs or any other features. All it does is size and position
32219 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
32220 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
32221 * @cfg {string} region the region that it inhabits..
32222 * @cfg {bool} skipConfig skip config?
32226 Roo.bootstrap.layout.Basic = function(config){
32228 this.mgr = config.mgr;
32230 this.position = config.region;
32232 var skipConfig = config.skipConfig;
32236 * @scope Roo.BasicLayoutRegion
32240 * @event beforeremove
32241 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
32242 * @param {Roo.LayoutRegion} this
32243 * @param {Roo.ContentPanel} panel The panel
32244 * @param {Object} e The cancel event object
32246 "beforeremove" : true,
32248 * @event invalidated
32249 * Fires when the layout for this region is changed.
32250 * @param {Roo.LayoutRegion} this
32252 "invalidated" : true,
32254 * @event visibilitychange
32255 * Fires when this region is shown or hidden
32256 * @param {Roo.LayoutRegion} this
32257 * @param {Boolean} visibility true or false
32259 "visibilitychange" : true,
32261 * @event paneladded
32262 * Fires when a panel is added.
32263 * @param {Roo.LayoutRegion} this
32264 * @param {Roo.ContentPanel} panel The panel
32266 "paneladded" : true,
32268 * @event panelremoved
32269 * Fires when a panel is removed.
32270 * @param {Roo.LayoutRegion} this
32271 * @param {Roo.ContentPanel} panel The panel
32273 "panelremoved" : true,
32275 * @event beforecollapse
32276 * Fires when this region before collapse.
32277 * @param {Roo.LayoutRegion} this
32279 "beforecollapse" : true,
32282 * Fires when this region is collapsed.
32283 * @param {Roo.LayoutRegion} this
32285 "collapsed" : true,
32288 * Fires when this region is expanded.
32289 * @param {Roo.LayoutRegion} this
32294 * Fires when this region is slid into view.
32295 * @param {Roo.LayoutRegion} this
32297 "slideshow" : true,
32300 * Fires when this region slides out of view.
32301 * @param {Roo.LayoutRegion} this
32303 "slidehide" : true,
32305 * @event panelactivated
32306 * Fires when a panel is activated.
32307 * @param {Roo.LayoutRegion} this
32308 * @param {Roo.ContentPanel} panel The activated panel
32310 "panelactivated" : true,
32313 * Fires when the user resizes this region.
32314 * @param {Roo.LayoutRegion} this
32315 * @param {Number} newSize The new size (width for east/west, height for north/south)
32319 /** A collection of panels in this region. @type Roo.util.MixedCollection */
32320 this.panels = new Roo.util.MixedCollection();
32321 this.panels.getKey = this.getPanelId.createDelegate(this);
32323 this.activePanel = null;
32324 // ensure listeners are added...
32326 if (config.listeners || config.events) {
32327 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
32328 listeners : config.listeners || {},
32329 events : config.events || {}
32333 if(skipConfig !== true){
32334 this.applyConfig(config);
32338 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
32340 getPanelId : function(p){
32344 applyConfig : function(config){
32345 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
32346 this.config = config;
32351 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
32352 * the width, for horizontal (north, south) the height.
32353 * @param {Number} newSize The new width or height
32355 resizeTo : function(newSize){
32356 var el = this.el ? this.el :
32357 (this.activePanel ? this.activePanel.getEl() : null);
32359 switch(this.position){
32362 el.setWidth(newSize);
32363 this.fireEvent("resized", this, newSize);
32367 el.setHeight(newSize);
32368 this.fireEvent("resized", this, newSize);
32374 getBox : function(){
32375 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
32378 getMargins : function(){
32379 return this.margins;
32382 updateBox : function(box){
32384 var el = this.activePanel.getEl();
32385 el.dom.style.left = box.x + "px";
32386 el.dom.style.top = box.y + "px";
32387 this.activePanel.setSize(box.width, box.height);
32391 * Returns the container element for this region.
32392 * @return {Roo.Element}
32394 getEl : function(){
32395 return this.activePanel;
32399 * Returns true if this region is currently visible.
32400 * @return {Boolean}
32402 isVisible : function(){
32403 return this.activePanel ? true : false;
32406 setActivePanel : function(panel){
32407 panel = this.getPanel(panel);
32408 if(this.activePanel && this.activePanel != panel){
32409 this.activePanel.setActiveState(false);
32410 this.activePanel.getEl().setLeftTop(-10000,-10000);
32412 this.activePanel = panel;
32413 panel.setActiveState(true);
32415 panel.setSize(this.box.width, this.box.height);
32417 this.fireEvent("panelactivated", this, panel);
32418 this.fireEvent("invalidated");
32422 * Show the specified panel.
32423 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
32424 * @return {Roo.ContentPanel} The shown panel or null
32426 showPanel : function(panel){
32427 panel = this.getPanel(panel);
32429 this.setActivePanel(panel);
32435 * Get the active panel for this region.
32436 * @return {Roo.ContentPanel} The active panel or null
32438 getActivePanel : function(){
32439 return this.activePanel;
32443 * Add the passed ContentPanel(s)
32444 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
32445 * @return {Roo.ContentPanel} The panel added (if only one was added)
32447 add : function(panel){
32448 if(arguments.length > 1){
32449 for(var i = 0, len = arguments.length; i < len; i++) {
32450 this.add(arguments[i]);
32454 if(this.hasPanel(panel)){
32455 this.showPanel(panel);
32458 var el = panel.getEl();
32459 if(el.dom.parentNode != this.mgr.el.dom){
32460 this.mgr.el.dom.appendChild(el.dom);
32462 if(panel.setRegion){
32463 panel.setRegion(this);
32465 this.panels.add(panel);
32466 el.setStyle("position", "absolute");
32467 if(!panel.background){
32468 this.setActivePanel(panel);
32469 if(this.config.initialSize && this.panels.getCount()==1){
32470 this.resizeTo(this.config.initialSize);
32473 this.fireEvent("paneladded", this, panel);
32478 * Returns true if the panel is in this region.
32479 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
32480 * @return {Boolean}
32482 hasPanel : function(panel){
32483 if(typeof panel == "object"){ // must be panel obj
32484 panel = panel.getId();
32486 return this.getPanel(panel) ? true : false;
32490 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
32491 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
32492 * @param {Boolean} preservePanel Overrides the config preservePanel option
32493 * @return {Roo.ContentPanel} The panel that was removed
32495 remove : function(panel, preservePanel){
32496 panel = this.getPanel(panel);
32501 this.fireEvent("beforeremove", this, panel, e);
32502 if(e.cancel === true){
32505 var panelId = panel.getId();
32506 this.panels.removeKey(panelId);
32511 * Returns the panel specified or null if it's not in this region.
32512 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
32513 * @return {Roo.ContentPanel}
32515 getPanel : function(id){
32516 if(typeof id == "object"){ // must be panel obj
32519 return this.panels.get(id);
32523 * Returns this regions position (north/south/east/west/center).
32526 getPosition: function(){
32527 return this.position;
32531 * Ext JS Library 1.1.1
32532 * Copyright(c) 2006-2007, Ext JS, LLC.
32534 * Originally Released Under LGPL - original licence link has changed is not relivant.
32537 * <script type="text/javascript">
32541 * @class Roo.bootstrap.layout.Region
32542 * @extends Roo.bootstrap.layout.Basic
32543 * This class represents a region in a layout manager.
32545 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
32546 * @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})
32547 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
32548 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
32549 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
32550 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
32551 * @cfg {String} title The title for the region (overrides panel titles)
32552 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
32553 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
32554 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
32555 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
32556 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
32557 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
32558 * the space available, similar to FireFox 1.5 tabs (defaults to false)
32559 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
32560 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
32561 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
32563 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
32564 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
32565 * @cfg {Boolean} disableTabTips True to disable tab tooltips
32566 * @cfg {Number} width For East/West panels
32567 * @cfg {Number} height For North/South panels
32568 * @cfg {Boolean} split To show the splitter
32569 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
32571 * @cfg {string} cls Extra CSS classes to add to region
32573 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
32574 * @cfg {string} region the region that it inhabits..
32577 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
32578 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
32580 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
32581 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
32582 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
32584 Roo.bootstrap.layout.Region = function(config)
32586 this.applyConfig(config);
32588 var mgr = config.mgr;
32589 var pos = config.region;
32590 config.skipConfig = true;
32591 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
32594 this.onRender(mgr.el);
32597 this.visible = true;
32598 this.collapsed = false;
32599 this.unrendered_panels = [];
32602 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
32604 position: '', // set by wrapper (eg. north/south etc..)
32605 unrendered_panels : null, // unrendered panels.
32606 createBody : function(){
32607 /** This region's body element
32608 * @type Roo.Element */
32609 this.bodyEl = this.el.createChild({
32611 cls: "roo-layout-panel-body tab-content" // bootstrap added...
32615 onRender: function(ctr, pos)
32617 var dh = Roo.DomHelper;
32618 /** This region's container element
32619 * @type Roo.Element */
32620 this.el = dh.append(ctr.dom, {
32622 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
32624 /** This region's title element
32625 * @type Roo.Element */
32627 this.titleEl = dh.append(this.el.dom,
32630 unselectable: "on",
32631 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
32633 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
32634 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
32637 this.titleEl.enableDisplayMode();
32638 /** This region's title text element
32639 * @type HTMLElement */
32640 this.titleTextEl = this.titleEl.dom.firstChild;
32641 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
32643 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
32644 this.closeBtn.enableDisplayMode();
32645 this.closeBtn.on("click", this.closeClicked, this);
32646 this.closeBtn.hide();
32648 this.createBody(this.config);
32649 if(this.config.hideWhenEmpty){
32651 this.on("paneladded", this.validateVisibility, this);
32652 this.on("panelremoved", this.validateVisibility, this);
32654 if(this.autoScroll){
32655 this.bodyEl.setStyle("overflow", "auto");
32657 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
32659 //if(c.titlebar !== false){
32660 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
32661 this.titleEl.hide();
32663 this.titleEl.show();
32664 if(this.config.title){
32665 this.titleTextEl.innerHTML = this.config.title;
32669 if(this.config.collapsed){
32670 this.collapse(true);
32672 if(this.config.hidden){
32676 if (this.unrendered_panels && this.unrendered_panels.length) {
32677 for (var i =0;i< this.unrendered_panels.length; i++) {
32678 this.add(this.unrendered_panels[i]);
32680 this.unrendered_panels = null;
32686 applyConfig : function(c)
32689 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
32690 var dh = Roo.DomHelper;
32691 if(c.titlebar !== false){
32692 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
32693 this.collapseBtn.on("click", this.collapse, this);
32694 this.collapseBtn.enableDisplayMode();
32696 if(c.showPin === true || this.showPin){
32697 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
32698 this.stickBtn.enableDisplayMode();
32699 this.stickBtn.on("click", this.expand, this);
32700 this.stickBtn.hide();
32705 /** This region's collapsed element
32706 * @type Roo.Element */
32709 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
32710 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
32713 if(c.floatable !== false){
32714 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
32715 this.collapsedEl.on("click", this.collapseClick, this);
32718 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
32719 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
32720 id: "message", unselectable: "on", style:{"float":"left"}});
32721 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
32723 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
32724 this.expandBtn.on("click", this.expand, this);
32728 if(this.collapseBtn){
32729 this.collapseBtn.setVisible(c.collapsible == true);
32732 this.cmargins = c.cmargins || this.cmargins ||
32733 (this.position == "west" || this.position == "east" ?
32734 {top: 0, left: 2, right:2, bottom: 0} :
32735 {top: 2, left: 0, right:0, bottom: 2});
32737 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
32740 this.bottomTabs = c.tabPosition != "top";
32742 this.autoScroll = c.autoScroll || false;
32747 this.duration = c.duration || .30;
32748 this.slideDuration = c.slideDuration || .45;
32753 * Returns true if this region is currently visible.
32754 * @return {Boolean}
32756 isVisible : function(){
32757 return this.visible;
32761 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
32762 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
32764 //setCollapsedTitle : function(title){
32765 // title = title || " ";
32766 // if(this.collapsedTitleTextEl){
32767 // this.collapsedTitleTextEl.innerHTML = title;
32771 getBox : function(){
32773 // if(!this.collapsed){
32774 b = this.el.getBox(false, true);
32776 // b = this.collapsedEl.getBox(false, true);
32781 getMargins : function(){
32782 return this.margins;
32783 //return this.collapsed ? this.cmargins : this.margins;
32786 highlight : function(){
32787 this.el.addClass("x-layout-panel-dragover");
32790 unhighlight : function(){
32791 this.el.removeClass("x-layout-panel-dragover");
32794 updateBox : function(box)
32796 if (!this.bodyEl) {
32797 return; // not rendered yet..
32801 if(!this.collapsed){
32802 this.el.dom.style.left = box.x + "px";
32803 this.el.dom.style.top = box.y + "px";
32804 this.updateBody(box.width, box.height);
32806 this.collapsedEl.dom.style.left = box.x + "px";
32807 this.collapsedEl.dom.style.top = box.y + "px";
32808 this.collapsedEl.setSize(box.width, box.height);
32811 this.tabs.autoSizeTabs();
32815 updateBody : function(w, h)
32818 this.el.setWidth(w);
32819 w -= this.el.getBorderWidth("rl");
32820 if(this.config.adjustments){
32821 w += this.config.adjustments[0];
32825 this.el.setHeight(h);
32826 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
32827 h -= this.el.getBorderWidth("tb");
32828 if(this.config.adjustments){
32829 h += this.config.adjustments[1];
32831 this.bodyEl.setHeight(h);
32833 h = this.tabs.syncHeight(h);
32836 if(this.panelSize){
32837 w = w !== null ? w : this.panelSize.width;
32838 h = h !== null ? h : this.panelSize.height;
32840 if(this.activePanel){
32841 var el = this.activePanel.getEl();
32842 w = w !== null ? w : el.getWidth();
32843 h = h !== null ? h : el.getHeight();
32844 this.panelSize = {width: w, height: h};
32845 this.activePanel.setSize(w, h);
32847 if(Roo.isIE && this.tabs){
32848 this.tabs.el.repaint();
32853 * Returns the container element for this region.
32854 * @return {Roo.Element}
32856 getEl : function(){
32861 * Hides this region.
32864 //if(!this.collapsed){
32865 this.el.dom.style.left = "-2000px";
32868 // this.collapsedEl.dom.style.left = "-2000px";
32869 // this.collapsedEl.hide();
32871 this.visible = false;
32872 this.fireEvent("visibilitychange", this, false);
32876 * Shows this region if it was previously hidden.
32879 //if(!this.collapsed){
32882 // this.collapsedEl.show();
32884 this.visible = true;
32885 this.fireEvent("visibilitychange", this, true);
32888 closeClicked : function(){
32889 if(this.activePanel){
32890 this.remove(this.activePanel);
32894 collapseClick : function(e){
32896 e.stopPropagation();
32899 e.stopPropagation();
32905 * Collapses this region.
32906 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
32909 collapse : function(skipAnim, skipCheck = false){
32910 if(this.collapsed) {
32914 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
32916 this.collapsed = true;
32918 this.split.el.hide();
32920 if(this.config.animate && skipAnim !== true){
32921 this.fireEvent("invalidated", this);
32922 this.animateCollapse();
32924 this.el.setLocation(-20000,-20000);
32926 this.collapsedEl.show();
32927 this.fireEvent("collapsed", this);
32928 this.fireEvent("invalidated", this);
32934 animateCollapse : function(){
32939 * Expands this region if it was previously collapsed.
32940 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
32941 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
32944 expand : function(e, skipAnim){
32946 e.stopPropagation();
32948 if(!this.collapsed || this.el.hasActiveFx()) {
32952 this.afterSlideIn();
32955 this.collapsed = false;
32956 if(this.config.animate && skipAnim !== true){
32957 this.animateExpand();
32961 this.split.el.show();
32963 this.collapsedEl.setLocation(-2000,-2000);
32964 this.collapsedEl.hide();
32965 this.fireEvent("invalidated", this);
32966 this.fireEvent("expanded", this);
32970 animateExpand : function(){
32974 initTabs : function()
32976 this.bodyEl.setStyle("overflow", "hidden");
32977 var ts = new Roo.bootstrap.panel.Tabs({
32978 el: this.bodyEl.dom,
32979 tabPosition: this.bottomTabs ? 'bottom' : 'top',
32980 disableTooltips: this.config.disableTabTips,
32981 toolbar : this.config.toolbar
32984 if(this.config.hideTabs){
32985 ts.stripWrap.setDisplayed(false);
32988 ts.resizeTabs = this.config.resizeTabs === true;
32989 ts.minTabWidth = this.config.minTabWidth || 40;
32990 ts.maxTabWidth = this.config.maxTabWidth || 250;
32991 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
32992 ts.monitorResize = false;
32993 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
32994 ts.bodyEl.addClass('roo-layout-tabs-body');
32995 this.panels.each(this.initPanelAsTab, this);
32998 initPanelAsTab : function(panel){
32999 var ti = this.tabs.addTab(
33003 this.config.closeOnTab && panel.isClosable()
33005 if(panel.tabTip !== undefined){
33006 ti.setTooltip(panel.tabTip);
33008 ti.on("activate", function(){
33009 this.setActivePanel(panel);
33012 if(this.config.closeOnTab){
33013 ti.on("beforeclose", function(t, e){
33015 this.remove(panel);
33021 updatePanelTitle : function(panel, title)
33023 if(this.activePanel == panel){
33024 this.updateTitle(title);
33027 var ti = this.tabs.getTab(panel.getEl().id);
33029 if(panel.tabTip !== undefined){
33030 ti.setTooltip(panel.tabTip);
33035 updateTitle : function(title){
33036 if(this.titleTextEl && !this.config.title){
33037 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
33041 setActivePanel : function(panel)
33043 panel = this.getPanel(panel);
33044 if(this.activePanel && this.activePanel != panel){
33045 this.activePanel.setActiveState(false);
33047 this.activePanel = panel;
33048 panel.setActiveState(true);
33049 if(this.panelSize){
33050 panel.setSize(this.panelSize.width, this.panelSize.height);
33053 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
33055 this.updateTitle(panel.getTitle());
33057 this.fireEvent("invalidated", this);
33059 this.fireEvent("panelactivated", this, panel);
33063 * Shows the specified panel.
33064 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
33065 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
33067 showPanel : function(panel)
33069 panel = this.getPanel(panel);
33072 var tab = this.tabs.getTab(panel.getEl().id);
33073 if(tab.isHidden()){
33074 this.tabs.unhideTab(tab.id);
33078 this.setActivePanel(panel);
33085 * Get the active panel for this region.
33086 * @return {Roo.ContentPanel} The active panel or null
33088 getActivePanel : function(){
33089 return this.activePanel;
33092 validateVisibility : function(){
33093 if(this.panels.getCount() < 1){
33094 this.updateTitle(" ");
33095 this.closeBtn.hide();
33098 if(!this.isVisible()){
33105 * Adds the passed ContentPanel(s) to this region.
33106 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
33107 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
33109 add : function(panel)
33111 if(arguments.length > 1){
33112 for(var i = 0, len = arguments.length; i < len; i++) {
33113 this.add(arguments[i]);
33118 // if we have not been rendered yet, then we can not really do much of this..
33119 if (!this.bodyEl) {
33120 this.unrendered_panels.push(panel);
33127 if(this.hasPanel(panel)){
33128 this.showPanel(panel);
33131 panel.setRegion(this);
33132 this.panels.add(panel);
33133 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
33134 // sinle panel - no tab...?? would it not be better to render it with the tabs,
33135 // and hide them... ???
33136 this.bodyEl.dom.appendChild(panel.getEl().dom);
33137 if(panel.background !== true){
33138 this.setActivePanel(panel);
33140 this.fireEvent("paneladded", this, panel);
33147 this.initPanelAsTab(panel);
33151 if(panel.background !== true){
33152 this.tabs.activate(panel.getEl().id);
33154 this.fireEvent("paneladded", this, panel);
33159 * Hides the tab for the specified panel.
33160 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
33162 hidePanel : function(panel){
33163 if(this.tabs && (panel = this.getPanel(panel))){
33164 this.tabs.hideTab(panel.getEl().id);
33169 * Unhides the tab for a previously hidden panel.
33170 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
33172 unhidePanel : function(panel){
33173 if(this.tabs && (panel = this.getPanel(panel))){
33174 this.tabs.unhideTab(panel.getEl().id);
33178 clearPanels : function(){
33179 while(this.panels.getCount() > 0){
33180 this.remove(this.panels.first());
33185 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
33186 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
33187 * @param {Boolean} preservePanel Overrides the config preservePanel option
33188 * @return {Roo.ContentPanel} The panel that was removed
33190 remove : function(panel, preservePanel)
33192 panel = this.getPanel(panel);
33197 this.fireEvent("beforeremove", this, panel, e);
33198 if(e.cancel === true){
33201 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
33202 var panelId = panel.getId();
33203 this.panels.removeKey(panelId);
33205 document.body.appendChild(panel.getEl().dom);
33208 this.tabs.removeTab(panel.getEl().id);
33209 }else if (!preservePanel){
33210 this.bodyEl.dom.removeChild(panel.getEl().dom);
33212 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
33213 var p = this.panels.first();
33214 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
33215 tempEl.appendChild(p.getEl().dom);
33216 this.bodyEl.update("");
33217 this.bodyEl.dom.appendChild(p.getEl().dom);
33219 this.updateTitle(p.getTitle());
33221 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
33222 this.setActivePanel(p);
33224 panel.setRegion(null);
33225 if(this.activePanel == panel){
33226 this.activePanel = null;
33228 if(this.config.autoDestroy !== false && preservePanel !== true){
33229 try{panel.destroy();}catch(e){}
33231 this.fireEvent("panelremoved", this, panel);
33236 * Returns the TabPanel component used by this region
33237 * @return {Roo.TabPanel}
33239 getTabs : function(){
33243 createTool : function(parentEl, className){
33244 var btn = Roo.DomHelper.append(parentEl, {
33246 cls: "x-layout-tools-button",
33249 cls: "roo-layout-tools-button-inner " + className,
33253 btn.addClassOnOver("roo-layout-tools-button-over");
33258 * Ext JS Library 1.1.1
33259 * Copyright(c) 2006-2007, Ext JS, LLC.
33261 * Originally Released Under LGPL - original licence link has changed is not relivant.
33264 * <script type="text/javascript">
33270 * @class Roo.SplitLayoutRegion
33271 * @extends Roo.LayoutRegion
33272 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
33274 Roo.bootstrap.layout.Split = function(config){
33275 this.cursor = config.cursor;
33276 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
33279 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
33281 splitTip : "Drag to resize.",
33282 collapsibleSplitTip : "Drag to resize. Double click to hide.",
33283 useSplitTips : false,
33285 applyConfig : function(config){
33286 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
33289 onRender : function(ctr,pos) {
33291 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
33292 if(!this.config.split){
33297 var splitEl = Roo.DomHelper.append(ctr.dom, {
33299 id: this.el.id + "-split",
33300 cls: "roo-layout-split roo-layout-split-"+this.position,
33303 /** The SplitBar for this region
33304 * @type Roo.SplitBar */
33305 // does not exist yet...
33306 Roo.log([this.position, this.orientation]);
33308 this.split = new Roo.bootstrap.SplitBar({
33309 dragElement : splitEl,
33310 resizingElement: this.el,
33311 orientation : this.orientation
33314 this.split.on("moved", this.onSplitMove, this);
33315 this.split.useShim = this.config.useShim === true;
33316 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
33317 if(this.useSplitTips){
33318 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
33320 //if(config.collapsible){
33321 // this.split.el.on("dblclick", this.collapse, this);
33324 if(typeof this.config.minSize != "undefined"){
33325 this.split.minSize = this.config.minSize;
33327 if(typeof this.config.maxSize != "undefined"){
33328 this.split.maxSize = this.config.maxSize;
33330 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
33331 this.hideSplitter();
33336 getHMaxSize : function(){
33337 var cmax = this.config.maxSize || 10000;
33338 var center = this.mgr.getRegion("center");
33339 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
33342 getVMaxSize : function(){
33343 var cmax = this.config.maxSize || 10000;
33344 var center = this.mgr.getRegion("center");
33345 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
33348 onSplitMove : function(split, newSize){
33349 this.fireEvent("resized", this, newSize);
33353 * Returns the {@link Roo.SplitBar} for this region.
33354 * @return {Roo.SplitBar}
33356 getSplitBar : function(){
33361 this.hideSplitter();
33362 Roo.bootstrap.layout.Split.superclass.hide.call(this);
33365 hideSplitter : function(){
33367 this.split.el.setLocation(-2000,-2000);
33368 this.split.el.hide();
33374 this.split.el.show();
33376 Roo.bootstrap.layout.Split.superclass.show.call(this);
33379 beforeSlide: function(){
33380 if(Roo.isGecko){// firefox overflow auto bug workaround
33381 this.bodyEl.clip();
33383 this.tabs.bodyEl.clip();
33385 if(this.activePanel){
33386 this.activePanel.getEl().clip();
33388 if(this.activePanel.beforeSlide){
33389 this.activePanel.beforeSlide();
33395 afterSlide : function(){
33396 if(Roo.isGecko){// firefox overflow auto bug workaround
33397 this.bodyEl.unclip();
33399 this.tabs.bodyEl.unclip();
33401 if(this.activePanel){
33402 this.activePanel.getEl().unclip();
33403 if(this.activePanel.afterSlide){
33404 this.activePanel.afterSlide();
33410 initAutoHide : function(){
33411 if(this.autoHide !== false){
33412 if(!this.autoHideHd){
33413 var st = new Roo.util.DelayedTask(this.slideIn, this);
33414 this.autoHideHd = {
33415 "mouseout": function(e){
33416 if(!e.within(this.el, true)){
33420 "mouseover" : function(e){
33426 this.el.on(this.autoHideHd);
33430 clearAutoHide : function(){
33431 if(this.autoHide !== false){
33432 this.el.un("mouseout", this.autoHideHd.mouseout);
33433 this.el.un("mouseover", this.autoHideHd.mouseover);
33437 clearMonitor : function(){
33438 Roo.get(document).un("click", this.slideInIf, this);
33441 // these names are backwards but not changed for compat
33442 slideOut : function(){
33443 if(this.isSlid || this.el.hasActiveFx()){
33446 this.isSlid = true;
33447 if(this.collapseBtn){
33448 this.collapseBtn.hide();
33450 this.closeBtnState = this.closeBtn.getStyle('display');
33451 this.closeBtn.hide();
33453 this.stickBtn.show();
33456 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
33457 this.beforeSlide();
33458 this.el.setStyle("z-index", 10001);
33459 this.el.slideIn(this.getSlideAnchor(), {
33460 callback: function(){
33462 this.initAutoHide();
33463 Roo.get(document).on("click", this.slideInIf, this);
33464 this.fireEvent("slideshow", this);
33471 afterSlideIn : function(){
33472 this.clearAutoHide();
33473 this.isSlid = false;
33474 this.clearMonitor();
33475 this.el.setStyle("z-index", "");
33476 if(this.collapseBtn){
33477 this.collapseBtn.show();
33479 this.closeBtn.setStyle('display', this.closeBtnState);
33481 this.stickBtn.hide();
33483 this.fireEvent("slidehide", this);
33486 slideIn : function(cb){
33487 if(!this.isSlid || this.el.hasActiveFx()){
33491 this.isSlid = false;
33492 this.beforeSlide();
33493 this.el.slideOut(this.getSlideAnchor(), {
33494 callback: function(){
33495 this.el.setLeftTop(-10000, -10000);
33497 this.afterSlideIn();
33505 slideInIf : function(e){
33506 if(!e.within(this.el)){
33511 animateCollapse : function(){
33512 this.beforeSlide();
33513 this.el.setStyle("z-index", 20000);
33514 var anchor = this.getSlideAnchor();
33515 this.el.slideOut(anchor, {
33516 callback : function(){
33517 this.el.setStyle("z-index", "");
33518 this.collapsedEl.slideIn(anchor, {duration:.3});
33520 this.el.setLocation(-10000,-10000);
33522 this.fireEvent("collapsed", this);
33529 animateExpand : function(){
33530 this.beforeSlide();
33531 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
33532 this.el.setStyle("z-index", 20000);
33533 this.collapsedEl.hide({
33536 this.el.slideIn(this.getSlideAnchor(), {
33537 callback : function(){
33538 this.el.setStyle("z-index", "");
33541 this.split.el.show();
33543 this.fireEvent("invalidated", this);
33544 this.fireEvent("expanded", this);
33572 getAnchor : function(){
33573 return this.anchors[this.position];
33576 getCollapseAnchor : function(){
33577 return this.canchors[this.position];
33580 getSlideAnchor : function(){
33581 return this.sanchors[this.position];
33584 getAlignAdj : function(){
33585 var cm = this.cmargins;
33586 switch(this.position){
33602 getExpandAdj : function(){
33603 var c = this.collapsedEl, cm = this.cmargins;
33604 switch(this.position){
33606 return [-(cm.right+c.getWidth()+cm.left), 0];
33609 return [cm.right+c.getWidth()+cm.left, 0];
33612 return [0, -(cm.top+cm.bottom+c.getHeight())];
33615 return [0, cm.top+cm.bottom+c.getHeight()];
33621 * Ext JS Library 1.1.1
33622 * Copyright(c) 2006-2007, Ext JS, LLC.
33624 * Originally Released Under LGPL - original licence link has changed is not relivant.
33627 * <script type="text/javascript">
33630 * These classes are private internal classes
33632 Roo.bootstrap.layout.Center = function(config){
33633 config.region = "center";
33634 Roo.bootstrap.layout.Region.call(this, config);
33635 this.visible = true;
33636 this.minWidth = config.minWidth || 20;
33637 this.minHeight = config.minHeight || 20;
33640 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
33642 // center panel can't be hidden
33646 // center panel can't be hidden
33649 getMinWidth: function(){
33650 return this.minWidth;
33653 getMinHeight: function(){
33654 return this.minHeight;
33667 Roo.bootstrap.layout.North = function(config)
33669 config.region = 'north';
33670 config.cursor = 'n-resize';
33672 Roo.bootstrap.layout.Split.call(this, config);
33676 this.split.placement = Roo.bootstrap.SplitBar.TOP;
33677 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
33678 this.split.el.addClass("roo-layout-split-v");
33680 var size = config.initialSize || config.height;
33681 if(typeof size != "undefined"){
33682 this.el.setHeight(size);
33685 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
33687 orientation: Roo.bootstrap.SplitBar.VERTICAL,
33691 getBox : function(){
33692 if(this.collapsed){
33693 return this.collapsedEl.getBox();
33695 var box = this.el.getBox();
33697 box.height += this.split.el.getHeight();
33702 updateBox : function(box){
33703 if(this.split && !this.collapsed){
33704 box.height -= this.split.el.getHeight();
33705 this.split.el.setLeft(box.x);
33706 this.split.el.setTop(box.y+box.height);
33707 this.split.el.setWidth(box.width);
33709 if(this.collapsed){
33710 this.updateBody(box.width, null);
33712 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
33720 Roo.bootstrap.layout.South = function(config){
33721 config.region = 'south';
33722 config.cursor = 's-resize';
33723 Roo.bootstrap.layout.Split.call(this, config);
33725 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
33726 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
33727 this.split.el.addClass("roo-layout-split-v");
33729 var size = config.initialSize || config.height;
33730 if(typeof size != "undefined"){
33731 this.el.setHeight(size);
33735 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
33736 orientation: Roo.bootstrap.SplitBar.VERTICAL,
33737 getBox : function(){
33738 if(this.collapsed){
33739 return this.collapsedEl.getBox();
33741 var box = this.el.getBox();
33743 var sh = this.split.el.getHeight();
33750 updateBox : function(box){
33751 if(this.split && !this.collapsed){
33752 var sh = this.split.el.getHeight();
33755 this.split.el.setLeft(box.x);
33756 this.split.el.setTop(box.y-sh);
33757 this.split.el.setWidth(box.width);
33759 if(this.collapsed){
33760 this.updateBody(box.width, null);
33762 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
33766 Roo.bootstrap.layout.East = function(config){
33767 config.region = "east";
33768 config.cursor = "e-resize";
33769 Roo.bootstrap.layout.Split.call(this, config);
33771 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
33772 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
33773 this.split.el.addClass("roo-layout-split-h");
33775 var size = config.initialSize || config.width;
33776 if(typeof size != "undefined"){
33777 this.el.setWidth(size);
33780 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
33781 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
33782 getBox : function(){
33783 if(this.collapsed){
33784 return this.collapsedEl.getBox();
33786 var box = this.el.getBox();
33788 var sw = this.split.el.getWidth();
33795 updateBox : function(box){
33796 if(this.split && !this.collapsed){
33797 var sw = this.split.el.getWidth();
33799 this.split.el.setLeft(box.x);
33800 this.split.el.setTop(box.y);
33801 this.split.el.setHeight(box.height);
33804 if(this.collapsed){
33805 this.updateBody(null, box.height);
33807 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
33811 Roo.bootstrap.layout.West = function(config){
33812 config.region = "west";
33813 config.cursor = "w-resize";
33815 Roo.bootstrap.layout.Split.call(this, config);
33817 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
33818 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
33819 this.split.el.addClass("roo-layout-split-h");
33823 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
33824 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
33826 onRender: function(ctr, pos)
33828 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
33829 var size = this.config.initialSize || this.config.width;
33830 if(typeof size != "undefined"){
33831 this.el.setWidth(size);
33835 getBox : function(){
33836 if(this.collapsed){
33837 return this.collapsedEl.getBox();
33839 var box = this.el.getBox();
33841 box.width += this.split.el.getWidth();
33846 updateBox : function(box){
33847 if(this.split && !this.collapsed){
33848 var sw = this.split.el.getWidth();
33850 this.split.el.setLeft(box.x+box.width);
33851 this.split.el.setTop(box.y);
33852 this.split.el.setHeight(box.height);
33854 if(this.collapsed){
33855 this.updateBody(null, box.height);
33857 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
33860 Roo.namespace("Roo.bootstrap.panel");/*
33862 * Ext JS Library 1.1.1
33863 * Copyright(c) 2006-2007, Ext JS, LLC.
33865 * Originally Released Under LGPL - original licence link has changed is not relivant.
33868 * <script type="text/javascript">
33871 * @class Roo.ContentPanel
33872 * @extends Roo.util.Observable
33873 * A basic ContentPanel element.
33874 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
33875 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
33876 * @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
33877 * @cfg {Boolean} closable True if the panel can be closed/removed
33878 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
33879 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
33880 * @cfg {Toolbar} toolbar A toolbar for this panel
33881 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
33882 * @cfg {String} title The title for this panel
33883 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
33884 * @cfg {String} url Calls {@link #setUrl} with this value
33885 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
33886 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
33887 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
33888 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
33891 * Create a new ContentPanel.
33892 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
33893 * @param {String/Object} config A string to set only the title or a config object
33894 * @param {String} content (optional) Set the HTML content for this panel
33895 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
33897 Roo.bootstrap.panel.Content = function( config){
33899 var el = config.el;
33900 var content = config.content;
33902 if(config.autoCreate){ // xtype is available if this is called from factory
33905 this.el = Roo.get(el);
33906 if(!this.el && config && config.autoCreate){
33907 if(typeof config.autoCreate == "object"){
33908 if(!config.autoCreate.id){
33909 config.autoCreate.id = config.id||el;
33911 this.el = Roo.DomHelper.append(document.body,
33912 config.autoCreate, true);
33914 var elcfg = { tag: "div",
33915 cls: "roo-layout-inactive-content",
33919 elcfg.html = config.html;
33923 this.el = Roo.DomHelper.append(document.body, elcfg , true);
33926 this.closable = false;
33927 this.loaded = false;
33928 this.active = false;
33931 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
33933 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
33935 this.wrapEl = this.el.wrap();
33937 if (config.toolbar.items) {
33938 ti = config.toolbar.items ;
33939 delete config.toolbar.items ;
33943 this.toolbar.render(this.wrapEl, 'before');
33944 for(var i =0;i < ti.length;i++) {
33945 // Roo.log(['add child', items[i]]);
33946 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
33948 this.toolbar.items = nitems;
33949 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
33950 delete config.toolbar;
33954 // xtype created footer. - not sure if will work as we normally have to render first..
33955 if (this.footer && !this.footer.el && this.footer.xtype) {
33956 if (!this.wrapEl) {
33957 this.wrapEl = this.el.wrap();
33960 this.footer.container = this.wrapEl.createChild();
33962 this.footer = Roo.factory(this.footer, Roo);
33967 if(typeof config == "string"){
33968 this.title = config;
33970 Roo.apply(this, config);
33974 this.resizeEl = Roo.get(this.resizeEl, true);
33976 this.resizeEl = this.el;
33978 // handle view.xtype
33986 * Fires when this panel is activated.
33987 * @param {Roo.ContentPanel} this
33991 * @event deactivate
33992 * Fires when this panel is activated.
33993 * @param {Roo.ContentPanel} this
33995 "deactivate" : true,
33999 * Fires when this panel is resized if fitToFrame is true.
34000 * @param {Roo.ContentPanel} this
34001 * @param {Number} width The width after any component adjustments
34002 * @param {Number} height The height after any component adjustments
34008 * Fires when this tab is created
34009 * @param {Roo.ContentPanel} this
34020 if(this.autoScroll){
34021 this.resizeEl.setStyle("overflow", "auto");
34023 // fix randome scrolling
34024 //this.el.on('scroll', function() {
34025 // Roo.log('fix random scolling');
34026 // this.scrollTo('top',0);
34029 content = content || this.content;
34031 this.setContent(content);
34033 if(config && config.url){
34034 this.setUrl(this.url, this.params, this.loadOnce);
34039 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
34041 if (this.view && typeof(this.view.xtype) != 'undefined') {
34042 this.view.el = this.el.appendChild(document.createElement("div"));
34043 this.view = Roo.factory(this.view);
34044 this.view.render && this.view.render(false, '');
34048 this.fireEvent('render', this);
34051 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
34053 setRegion : function(region){
34054 this.region = region;
34056 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
34058 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
34063 * Returns the toolbar for this Panel if one was configured.
34064 * @return {Roo.Toolbar}
34066 getToolbar : function(){
34067 return this.toolbar;
34070 setActiveState : function(active){
34071 this.active = active;
34073 this.fireEvent("deactivate", this);
34075 this.fireEvent("activate", this);
34079 * Updates this panel's element
34080 * @param {String} content The new content
34081 * @param {Boolean} loadScripts (optional) true to look for and process scripts
34083 setContent : function(content, loadScripts){
34084 this.el.update(content, loadScripts);
34087 ignoreResize : function(w, h){
34088 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
34091 this.lastSize = {width: w, height: h};
34096 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
34097 * @return {Roo.UpdateManager} The UpdateManager
34099 getUpdateManager : function(){
34100 return this.el.getUpdateManager();
34103 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
34104 * @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:
34107 url: "your-url.php",
34108 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
34109 callback: yourFunction,
34110 scope: yourObject, //(optional scope)
34113 text: "Loading...",
34118 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
34119 * 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.
34120 * @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}
34121 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
34122 * @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.
34123 * @return {Roo.ContentPanel} this
34126 var um = this.el.getUpdateManager();
34127 um.update.apply(um, arguments);
34133 * 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.
34134 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
34135 * @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)
34136 * @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)
34137 * @return {Roo.UpdateManager} The UpdateManager
34139 setUrl : function(url, params, loadOnce){
34140 if(this.refreshDelegate){
34141 this.removeListener("activate", this.refreshDelegate);
34143 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
34144 this.on("activate", this.refreshDelegate);
34145 return this.el.getUpdateManager();
34148 _handleRefresh : function(url, params, loadOnce){
34149 if(!loadOnce || !this.loaded){
34150 var updater = this.el.getUpdateManager();
34151 updater.update(url, params, this._setLoaded.createDelegate(this));
34155 _setLoaded : function(){
34156 this.loaded = true;
34160 * Returns this panel's id
34163 getId : function(){
34168 * Returns this panel's element - used by regiosn to add.
34169 * @return {Roo.Element}
34171 getEl : function(){
34172 return this.wrapEl || this.el;
34177 adjustForComponents : function(width, height)
34179 //Roo.log('adjustForComponents ');
34180 if(this.resizeEl != this.el){
34181 width -= this.el.getFrameWidth('lr');
34182 height -= this.el.getFrameWidth('tb');
34185 var te = this.toolbar.getEl();
34186 height -= te.getHeight();
34187 te.setWidth(width);
34190 var te = this.footer.getEl();
34191 Roo.log("footer:" + te.getHeight());
34193 height -= te.getHeight();
34194 te.setWidth(width);
34198 if(this.adjustments){
34199 width += this.adjustments[0];
34200 height += this.adjustments[1];
34202 return {"width": width, "height": height};
34205 setSize : function(width, height){
34206 if(this.fitToFrame && !this.ignoreResize(width, height)){
34207 if(this.fitContainer && this.resizeEl != this.el){
34208 this.el.setSize(width, height);
34210 var size = this.adjustForComponents(width, height);
34211 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
34212 this.fireEvent('resize', this, size.width, size.height);
34217 * Returns this panel's title
34220 getTitle : function(){
34225 * Set this panel's title
34226 * @param {String} title
34228 setTitle : function(title){
34229 this.title = title;
34231 this.region.updatePanelTitle(this, title);
34236 * Returns true is this panel was configured to be closable
34237 * @return {Boolean}
34239 isClosable : function(){
34240 return this.closable;
34243 beforeSlide : function(){
34245 this.resizeEl.clip();
34248 afterSlide : function(){
34250 this.resizeEl.unclip();
34254 * Force a content refresh from the URL specified in the {@link #setUrl} method.
34255 * Will fail silently if the {@link #setUrl} method has not been called.
34256 * This does not activate the panel, just updates its content.
34258 refresh : function(){
34259 if(this.refreshDelegate){
34260 this.loaded = false;
34261 this.refreshDelegate();
34266 * Destroys this panel
34268 destroy : function(){
34269 this.el.removeAllListeners();
34270 var tempEl = document.createElement("span");
34271 tempEl.appendChild(this.el.dom);
34272 tempEl.innerHTML = "";
34278 * form - if the content panel contains a form - this is a reference to it.
34279 * @type {Roo.form.Form}
34283 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
34284 * This contains a reference to it.
34290 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
34300 * @param {Object} cfg Xtype definition of item to add.
34304 getChildContainer: function () {
34305 return this.getEl();
34310 var ret = new Roo.factory(cfg);
34315 if (cfg.xtype.match(/^Form$/)) {
34318 //if (this.footer) {
34319 // el = this.footer.container.insertSibling(false, 'before');
34321 el = this.el.createChild();
34324 this.form = new Roo.form.Form(cfg);
34327 if ( this.form.allItems.length) {
34328 this.form.render(el.dom);
34332 // should only have one of theses..
34333 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
34334 // views.. should not be just added - used named prop 'view''
34336 cfg.el = this.el.appendChild(document.createElement("div"));
34339 var ret = new Roo.factory(cfg);
34341 ret.render && ret.render(false, ''); // render blank..
34351 * @class Roo.bootstrap.panel.Grid
34352 * @extends Roo.bootstrap.panel.Content
34354 * Create a new GridPanel.
34355 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
34356 * @param {Object} config A the config object
34362 Roo.bootstrap.panel.Grid = function(config)
34366 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
34367 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
34369 config.el = this.wrapper;
34370 //this.el = this.wrapper;
34372 if (config.container) {
34373 // ctor'ed from a Border/panel.grid
34376 this.wrapper.setStyle("overflow", "hidden");
34377 this.wrapper.addClass('roo-grid-container');
34382 if(config.toolbar){
34383 var tool_el = this.wrapper.createChild();
34384 this.toolbar = Roo.factory(config.toolbar);
34386 if (config.toolbar.items) {
34387 ti = config.toolbar.items ;
34388 delete config.toolbar.items ;
34392 this.toolbar.render(tool_el);
34393 for(var i =0;i < ti.length;i++) {
34394 // Roo.log(['add child', items[i]]);
34395 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
34397 this.toolbar.items = nitems;
34399 delete config.toolbar;
34402 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
34403 config.grid.scrollBody = true;;
34404 config.grid.monitorWindowResize = false; // turn off autosizing
34405 config.grid.autoHeight = false;
34406 config.grid.autoWidth = false;
34408 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
34410 if (config.background) {
34411 // render grid on panel activation (if panel background)
34412 this.on('activate', function(gp) {
34413 if (!gp.grid.rendered) {
34414 gp.grid.render(el);
34415 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
34421 this.grid.render(this.wrapper);
34422 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
34425 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
34426 // ??? needed ??? config.el = this.wrapper;
34431 // xtype created footer. - not sure if will work as we normally have to render first..
34432 if (this.footer && !this.footer.el && this.footer.xtype) {
34434 var ctr = this.grid.getView().getFooterPanel(true);
34435 this.footer.dataSource = this.grid.dataSource;
34436 this.footer = Roo.factory(this.footer, Roo);
34437 this.footer.render(ctr);
34447 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
34448 getId : function(){
34449 return this.grid.id;
34453 * Returns the grid for this panel
34454 * @return {Roo.bootstrap.Table}
34456 getGrid : function(){
34460 setSize : function(width, height){
34461 if(!this.ignoreResize(width, height)){
34462 var grid = this.grid;
34463 var size = this.adjustForComponents(width, height);
34464 var gridel = grid.getGridEl();
34465 gridel.setSize(size.width, size.height);
34467 var thd = grid.getGridEl().select('thead',true).first();
34468 var tbd = grid.getGridEl().select('tbody', true).first();
34470 tbd.setSize(width, height - thd.getHeight());
34479 beforeSlide : function(){
34480 this.grid.getView().scroller.clip();
34483 afterSlide : function(){
34484 this.grid.getView().scroller.unclip();
34487 destroy : function(){
34488 this.grid.destroy();
34490 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
34495 * @class Roo.bootstrap.panel.Nest
34496 * @extends Roo.bootstrap.panel.Content
34498 * Create a new Panel, that can contain a layout.Border.
34501 * @param {Roo.BorderLayout} layout The layout for this panel
34502 * @param {String/Object} config A string to set only the title or a config object
34504 Roo.bootstrap.panel.Nest = function(config)
34506 // construct with only one argument..
34507 /* FIXME - implement nicer consturctors
34508 if (layout.layout) {
34510 layout = config.layout;
34511 delete config.layout;
34513 if (layout.xtype && !layout.getEl) {
34514 // then layout needs constructing..
34515 layout = Roo.factory(layout, Roo);
34519 config.el = config.layout.getEl();
34521 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
34523 config.layout.monitorWindowResize = false; // turn off autosizing
34524 this.layout = config.layout;
34525 this.layout.getEl().addClass("roo-layout-nested-layout");
34532 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
34534 setSize : function(width, height){
34535 if(!this.ignoreResize(width, height)){
34536 var size = this.adjustForComponents(width, height);
34537 var el = this.layout.getEl();
34538 el.setSize(size.width, size.height);
34539 var touch = el.dom.offsetWidth;
34540 this.layout.layout();
34541 // ie requires a double layout on the first pass
34542 if(Roo.isIE && !this.initialized){
34543 this.initialized = true;
34544 this.layout.layout();
34549 // activate all subpanels if not currently active..
34551 setActiveState : function(active){
34552 this.active = active;
34554 this.fireEvent("deactivate", this);
34558 this.fireEvent("activate", this);
34559 // not sure if this should happen before or after..
34560 if (!this.layout) {
34561 return; // should not happen..
34564 for (var r in this.layout.regions) {
34565 reg = this.layout.getRegion(r);
34566 if (reg.getActivePanel()) {
34567 //reg.showPanel(reg.getActivePanel()); // force it to activate..
34568 reg.setActivePanel(reg.getActivePanel());
34571 if (!reg.panels.length) {
34574 reg.showPanel(reg.getPanel(0));
34583 * Returns the nested BorderLayout for this panel
34584 * @return {Roo.BorderLayout}
34586 getLayout : function(){
34587 return this.layout;
34591 * Adds a xtype elements to the layout of the nested panel
34595 xtype : 'ContentPanel',
34602 xtype : 'NestedLayoutPanel',
34608 items : [ ... list of content panels or nested layout panels.. ]
34612 * @param {Object} cfg Xtype definition of item to add.
34614 addxtype : function(cfg) {
34615 return this.layout.addxtype(cfg);
34620 * Ext JS Library 1.1.1
34621 * Copyright(c) 2006-2007, Ext JS, LLC.
34623 * Originally Released Under LGPL - original licence link has changed is not relivant.
34626 * <script type="text/javascript">
34629 * @class Roo.TabPanel
34630 * @extends Roo.util.Observable
34631 * A lightweight tab container.
34635 // basic tabs 1, built from existing content
34636 var tabs = new Roo.TabPanel("tabs1");
34637 tabs.addTab("script", "View Script");
34638 tabs.addTab("markup", "View Markup");
34639 tabs.activate("script");
34641 // more advanced tabs, built from javascript
34642 var jtabs = new Roo.TabPanel("jtabs");
34643 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
34645 // set up the UpdateManager
34646 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
34647 var updater = tab2.getUpdateManager();
34648 updater.setDefaultUrl("ajax1.htm");
34649 tab2.on('activate', updater.refresh, updater, true);
34651 // Use setUrl for Ajax loading
34652 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
34653 tab3.setUrl("ajax2.htm", null, true);
34656 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
34659 jtabs.activate("jtabs-1");
34662 * Create a new TabPanel.
34663 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
34664 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
34666 Roo.bootstrap.panel.Tabs = function(config){
34668 * The container element for this TabPanel.
34669 * @type Roo.Element
34671 this.el = Roo.get(config.el);
34674 if(typeof config == "boolean"){
34675 this.tabPosition = config ? "bottom" : "top";
34677 Roo.apply(this, config);
34681 if(this.tabPosition == "bottom"){
34682 this.bodyEl = Roo.get(this.createBody(this.el.dom));
34683 this.el.addClass("roo-tabs-bottom");
34685 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
34686 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
34687 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
34689 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
34691 if(this.tabPosition != "bottom"){
34692 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
34693 * @type Roo.Element
34695 this.bodyEl = Roo.get(this.createBody(this.el.dom));
34696 this.el.addClass("roo-tabs-top");
34700 this.bodyEl.setStyle("position", "relative");
34702 this.active = null;
34703 this.activateDelegate = this.activate.createDelegate(this);
34708 * Fires when the active tab changes
34709 * @param {Roo.TabPanel} this
34710 * @param {Roo.TabPanelItem} activePanel The new active tab
34714 * @event beforetabchange
34715 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
34716 * @param {Roo.TabPanel} this
34717 * @param {Object} e Set cancel to true on this object to cancel the tab change
34718 * @param {Roo.TabPanelItem} tab The tab being changed to
34720 "beforetabchange" : true
34723 Roo.EventManager.onWindowResize(this.onResize, this);
34724 this.cpad = this.el.getPadding("lr");
34725 this.hiddenCount = 0;
34728 // toolbar on the tabbar support...
34729 if (this.toolbar) {
34730 alert("no toolbar support yet");
34731 this.toolbar = false;
34733 var tcfg = this.toolbar;
34734 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
34735 this.toolbar = new Roo.Toolbar(tcfg);
34736 if (Roo.isSafari) {
34737 var tbl = tcfg.container.child('table', true);
34738 tbl.setAttribute('width', '100%');
34746 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
34749 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
34751 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
34753 tabPosition : "top",
34755 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
34757 currentTabWidth : 0,
34759 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
34763 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
34767 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
34769 preferredTabWidth : 175,
34771 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
34773 resizeTabs : false,
34775 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
34777 monitorResize : true,
34779 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
34784 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
34785 * @param {String} id The id of the div to use <b>or create</b>
34786 * @param {String} text The text for the tab
34787 * @param {String} content (optional) Content to put in the TabPanelItem body
34788 * @param {Boolean} closable (optional) True to create a close icon on the tab
34789 * @return {Roo.TabPanelItem} The created TabPanelItem
34791 addTab : function(id, text, content, closable)
34793 var item = new Roo.bootstrap.panel.TabItem({
34797 closable : closable
34799 this.addTabItem(item);
34801 item.setContent(content);
34807 * Returns the {@link Roo.TabPanelItem} with the specified id/index
34808 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
34809 * @return {Roo.TabPanelItem}
34811 getTab : function(id){
34812 return this.items[id];
34816 * Hides the {@link Roo.TabPanelItem} with the specified id/index
34817 * @param {String/Number} id The id or index of the TabPanelItem to hide.
34819 hideTab : function(id){
34820 var t = this.items[id];
34823 this.hiddenCount++;
34824 this.autoSizeTabs();
34829 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
34830 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
34832 unhideTab : function(id){
34833 var t = this.items[id];
34835 t.setHidden(false);
34836 this.hiddenCount--;
34837 this.autoSizeTabs();
34842 * Adds an existing {@link Roo.TabPanelItem}.
34843 * @param {Roo.TabPanelItem} item The TabPanelItem to add
34845 addTabItem : function(item){
34846 this.items[item.id] = item;
34847 this.items.push(item);
34848 // if(this.resizeTabs){
34849 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
34850 // this.autoSizeTabs();
34852 // item.autoSize();
34857 * Removes a {@link Roo.TabPanelItem}.
34858 * @param {String/Number} id The id or index of the TabPanelItem to remove.
34860 removeTab : function(id){
34861 var items = this.items;
34862 var tab = items[id];
34863 if(!tab) { return; }
34864 var index = items.indexOf(tab);
34865 if(this.active == tab && items.length > 1){
34866 var newTab = this.getNextAvailable(index);
34871 this.stripEl.dom.removeChild(tab.pnode.dom);
34872 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
34873 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
34875 items.splice(index, 1);
34876 delete this.items[tab.id];
34877 tab.fireEvent("close", tab);
34878 tab.purgeListeners();
34879 this.autoSizeTabs();
34882 getNextAvailable : function(start){
34883 var items = this.items;
34885 // look for a next tab that will slide over to
34886 // replace the one being removed
34887 while(index < items.length){
34888 var item = items[++index];
34889 if(item && !item.isHidden()){
34893 // if one isn't found select the previous tab (on the left)
34896 var item = items[--index];
34897 if(item && !item.isHidden()){
34905 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
34906 * @param {String/Number} id The id or index of the TabPanelItem to disable.
34908 disableTab : function(id){
34909 var tab = this.items[id];
34910 if(tab && this.active != tab){
34916 * Enables a {@link Roo.TabPanelItem} that is disabled.
34917 * @param {String/Number} id The id or index of the TabPanelItem to enable.
34919 enableTab : function(id){
34920 var tab = this.items[id];
34925 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
34926 * @param {String/Number} id The id or index of the TabPanelItem to activate.
34927 * @return {Roo.TabPanelItem} The TabPanelItem.
34929 activate : function(id){
34930 var tab = this.items[id];
34934 if(tab == this.active || tab.disabled){
34938 this.fireEvent("beforetabchange", this, e, tab);
34939 if(e.cancel !== true && !tab.disabled){
34941 this.active.hide();
34943 this.active = this.items[id];
34944 this.active.show();
34945 this.fireEvent("tabchange", this, this.active);
34951 * Gets the active {@link Roo.TabPanelItem}.
34952 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
34954 getActiveTab : function(){
34955 return this.active;
34959 * Updates the tab body element to fit the height of the container element
34960 * for overflow scrolling
34961 * @param {Number} targetHeight (optional) Override the starting height from the elements height
34963 syncHeight : function(targetHeight){
34964 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
34965 var bm = this.bodyEl.getMargins();
34966 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
34967 this.bodyEl.setHeight(newHeight);
34971 onResize : function(){
34972 if(this.monitorResize){
34973 this.autoSizeTabs();
34978 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
34980 beginUpdate : function(){
34981 this.updating = true;
34985 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
34987 endUpdate : function(){
34988 this.updating = false;
34989 this.autoSizeTabs();
34993 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
34995 autoSizeTabs : function(){
34996 var count = this.items.length;
34997 var vcount = count - this.hiddenCount;
34998 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
35001 var w = Math.max(this.el.getWidth() - this.cpad, 10);
35002 var availWidth = Math.floor(w / vcount);
35003 var b = this.stripBody;
35004 if(b.getWidth() > w){
35005 var tabs = this.items;
35006 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
35007 if(availWidth < this.minTabWidth){
35008 /*if(!this.sleft){ // incomplete scrolling code
35009 this.createScrollButtons();
35012 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
35015 if(this.currentTabWidth < this.preferredTabWidth){
35016 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
35022 * Returns the number of tabs in this TabPanel.
35025 getCount : function(){
35026 return this.items.length;
35030 * Resizes all the tabs to the passed width
35031 * @param {Number} The new width
35033 setTabWidth : function(width){
35034 this.currentTabWidth = width;
35035 for(var i = 0, len = this.items.length; i < len; i++) {
35036 if(!this.items[i].isHidden()) {
35037 this.items[i].setWidth(width);
35043 * Destroys this TabPanel
35044 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
35046 destroy : function(removeEl){
35047 Roo.EventManager.removeResizeListener(this.onResize, this);
35048 for(var i = 0, len = this.items.length; i < len; i++){
35049 this.items[i].purgeListeners();
35051 if(removeEl === true){
35052 this.el.update("");
35057 createStrip : function(container)
35059 var strip = document.createElement("nav");
35060 strip.className = "navbar navbar-default"; //"x-tabs-wrap";
35061 container.appendChild(strip);
35065 createStripList : function(strip)
35067 // div wrapper for retard IE
35068 // returns the "tr" element.
35069 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
35070 //'<div class="x-tabs-strip-wrap">'+
35071 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
35072 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
35073 return strip.firstChild; //.firstChild.firstChild.firstChild;
35075 createBody : function(container)
35077 var body = document.createElement("div");
35078 Roo.id(body, "tab-body");
35079 //Roo.fly(body).addClass("x-tabs-body");
35080 Roo.fly(body).addClass("tab-content");
35081 container.appendChild(body);
35084 createItemBody :function(bodyEl, id){
35085 var body = Roo.getDom(id);
35087 body = document.createElement("div");
35090 //Roo.fly(body).addClass("x-tabs-item-body");
35091 Roo.fly(body).addClass("tab-pane");
35092 bodyEl.insertBefore(body, bodyEl.firstChild);
35096 createStripElements : function(stripEl, text, closable)
35098 var td = document.createElement("li"); // was td..
35101 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
35104 stripEl.appendChild(td);
35106 td.className = "x-tabs-closable";
35107 if(!this.closeTpl){
35108 this.closeTpl = new Roo.Template(
35109 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
35110 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
35111 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
35114 var el = this.closeTpl.overwrite(td, {"text": text});
35115 var close = el.getElementsByTagName("div")[0];
35116 var inner = el.getElementsByTagName("em")[0];
35117 return {"el": el, "close": close, "inner": inner};
35120 // not sure what this is..
35122 //this.tabTpl = new Roo.Template(
35123 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
35124 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
35126 this.tabTpl = new Roo.Template(
35128 '<span unselectable="on"' +
35129 (this.disableTooltips ? '' : ' title="{text}"') +
35130 ' >{text}</span></span></a>'
35134 var el = this.tabTpl.overwrite(td, {"text": text});
35135 var inner = el.getElementsByTagName("span")[0];
35136 return {"el": el, "inner": inner};
35144 * @class Roo.TabPanelItem
35145 * @extends Roo.util.Observable
35146 * Represents an individual item (tab plus body) in a TabPanel.
35147 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
35148 * @param {String} id The id of this TabPanelItem
35149 * @param {String} text The text for the tab of this TabPanelItem
35150 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
35152 Roo.bootstrap.panel.TabItem = function(config){
35154 * The {@link Roo.TabPanel} this TabPanelItem belongs to
35155 * @type Roo.TabPanel
35157 this.tabPanel = config.panel;
35159 * The id for this TabPanelItem
35162 this.id = config.id;
35164 this.disabled = false;
35166 this.text = config.text;
35168 this.loaded = false;
35169 this.closable = config.closable;
35172 * The body element for this TabPanelItem.
35173 * @type Roo.Element
35175 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
35176 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
35177 this.bodyEl.setStyle("display", "block");
35178 this.bodyEl.setStyle("zoom", "1");
35179 //this.hideAction();
35181 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable);
35183 this.el = Roo.get(els.el);
35184 this.inner = Roo.get(els.inner, true);
35185 this.textEl = Roo.get(this.el.dom.firstChild, true);
35186 this.pnode = Roo.get(els.el.parentNode, true);
35187 this.el.on("mousedown", this.onTabMouseDown, this);
35188 this.el.on("click", this.onTabClick, this);
35190 if(config.closable){
35191 var c = Roo.get(els.close, true);
35192 c.dom.title = this.closeText;
35193 c.addClassOnOver("close-over");
35194 c.on("click", this.closeClick, this);
35200 * Fires when this tab becomes the active tab.
35201 * @param {Roo.TabPanel} tabPanel The parent TabPanel
35202 * @param {Roo.TabPanelItem} this
35206 * @event beforeclose
35207 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
35208 * @param {Roo.TabPanelItem} this
35209 * @param {Object} e Set cancel to true on this object to cancel the close.
35211 "beforeclose": true,
35214 * Fires when this tab is closed.
35215 * @param {Roo.TabPanelItem} this
35219 * @event deactivate
35220 * Fires when this tab is no longer the active tab.
35221 * @param {Roo.TabPanel} tabPanel The parent TabPanel
35222 * @param {Roo.TabPanelItem} this
35224 "deactivate" : true
35226 this.hidden = false;
35228 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
35231 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
35233 purgeListeners : function(){
35234 Roo.util.Observable.prototype.purgeListeners.call(this);
35235 this.el.removeAllListeners();
35238 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
35241 this.pnode.addClass("active");
35244 this.tabPanel.stripWrap.repaint();
35246 this.fireEvent("activate", this.tabPanel, this);
35250 * Returns true if this tab is the active tab.
35251 * @return {Boolean}
35253 isActive : function(){
35254 return this.tabPanel.getActiveTab() == this;
35258 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
35261 this.pnode.removeClass("active");
35263 this.fireEvent("deactivate", this.tabPanel, this);
35266 hideAction : function(){
35267 this.bodyEl.hide();
35268 this.bodyEl.setStyle("position", "absolute");
35269 this.bodyEl.setLeft("-20000px");
35270 this.bodyEl.setTop("-20000px");
35273 showAction : function(){
35274 this.bodyEl.setStyle("position", "relative");
35275 this.bodyEl.setTop("");
35276 this.bodyEl.setLeft("");
35277 this.bodyEl.show();
35281 * Set the tooltip for the tab.
35282 * @param {String} tooltip The tab's tooltip
35284 setTooltip : function(text){
35285 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
35286 this.textEl.dom.qtip = text;
35287 this.textEl.dom.removeAttribute('title');
35289 this.textEl.dom.title = text;
35293 onTabClick : function(e){
35294 e.preventDefault();
35295 this.tabPanel.activate(this.id);
35298 onTabMouseDown : function(e){
35299 e.preventDefault();
35300 this.tabPanel.activate(this.id);
35303 getWidth : function(){
35304 return this.inner.getWidth();
35307 setWidth : function(width){
35308 var iwidth = width - this.pnode.getPadding("lr");
35309 this.inner.setWidth(iwidth);
35310 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
35311 this.pnode.setWidth(width);
35315 * Show or hide the tab
35316 * @param {Boolean} hidden True to hide or false to show.
35318 setHidden : function(hidden){
35319 this.hidden = hidden;
35320 this.pnode.setStyle("display", hidden ? "none" : "");
35324 * Returns true if this tab is "hidden"
35325 * @return {Boolean}
35327 isHidden : function(){
35328 return this.hidden;
35332 * Returns the text for this tab
35335 getText : function(){
35339 autoSize : function(){
35340 //this.el.beginMeasure();
35341 this.textEl.setWidth(1);
35343 * #2804 [new] Tabs in Roojs
35344 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
35346 //this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
35347 //this.el.endMeasure();
35351 * Sets the text for the tab (Note: this also sets the tooltip text)
35352 * @param {String} text The tab's text and tooltip
35354 setText : function(text){
35356 this.textEl.update(text);
35357 this.setTooltip(text);
35358 //if(!this.tabPanel.resizeTabs){
35359 // this.autoSize();
35363 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
35365 activate : function(){
35366 this.tabPanel.activate(this.id);
35370 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
35372 disable : function(){
35373 if(this.tabPanel.active != this){
35374 this.disabled = true;
35375 this.pnode.addClass("disabled");
35380 * Enables this TabPanelItem if it was previously disabled.
35382 enable : function(){
35383 this.disabled = false;
35384 this.pnode.removeClass("disabled");
35388 * Sets the content for this TabPanelItem.
35389 * @param {String} content The content
35390 * @param {Boolean} loadScripts true to look for and load scripts
35392 setContent : function(content, loadScripts){
35393 this.bodyEl.update(content, loadScripts);
35397 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
35398 * @return {Roo.UpdateManager} The UpdateManager
35400 getUpdateManager : function(){
35401 return this.bodyEl.getUpdateManager();
35405 * Set a URL to be used to load the content for this TabPanelItem.
35406 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
35407 * @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)
35408 * @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)
35409 * @return {Roo.UpdateManager} The UpdateManager
35411 setUrl : function(url, params, loadOnce){
35412 if(this.refreshDelegate){
35413 this.un('activate', this.refreshDelegate);
35415 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
35416 this.on("activate", this.refreshDelegate);
35417 return this.bodyEl.getUpdateManager();
35421 _handleRefresh : function(url, params, loadOnce){
35422 if(!loadOnce || !this.loaded){
35423 var updater = this.bodyEl.getUpdateManager();
35424 updater.update(url, params, this._setLoaded.createDelegate(this));
35429 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
35430 * Will fail silently if the setUrl method has not been called.
35431 * This does not activate the panel, just updates its content.
35433 refresh : function(){
35434 if(this.refreshDelegate){
35435 this.loaded = false;
35436 this.refreshDelegate();
35441 _setLoaded : function(){
35442 this.loaded = true;
35446 closeClick : function(e){
35449 this.fireEvent("beforeclose", this, o);
35450 if(o.cancel !== true){
35451 this.tabPanel.removeTab(this.id);
35455 * The text displayed in the tooltip for the close icon.
35458 closeText : "Close this tab"