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){
395 config = config || {};
397 Roo.bootstrap.Body.superclass.constructor.call(this, config);
398 this.el = Roo.get(config.el ? config.el : document.body );
399 if (this.cls && this.cls.length) {
400 Roo.get(document.body).addClass(this.cls);
404 Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component, {
406 is_body : true,// just to make sure it's constructed?
411 onRender : function(ct, position)
413 /* Roo.log("Roo.bootstrap.Body - onRender");
414 if (this.cls && this.cls.length) {
415 Roo.get(document.body).addClass(this.cls);
434 * @class Roo.bootstrap.ButtonGroup
435 * @extends Roo.bootstrap.Component
436 * Bootstrap ButtonGroup class
437 * @cfg {String} size lg | sm | xs (default empty normal)
438 * @cfg {String} align vertical | justified (default none)
439 * @cfg {String} direction up | down (default down)
440 * @cfg {Boolean} toolbar false | true
441 * @cfg {Boolean} btn true | false
446 * @param {Object} config The config object
449 Roo.bootstrap.ButtonGroup = function(config){
450 Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config);
453 Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component, {
461 getAutoCreate : function(){
467 cfg.html = this.html || cfg.html;
478 if (['vertical','justified'].indexOf(this.align)!==-1) {
479 cfg.cls = 'btn-group-' + this.align;
481 if (this.align == 'justified') {
482 console.log(this.items);
486 if (['lg','sm','xs'].indexOf(this.size)!==-1) {
487 cfg.cls += ' btn-group-' + this.size;
490 if (this.direction == 'up') {
491 cfg.cls += ' dropup' ;
507 * @class Roo.bootstrap.Button
508 * @extends Roo.bootstrap.Component
509 * Bootstrap Button class
510 * @cfg {String} html The button content
511 * @cfg {String} weight (default | primary | success | info | warning | danger | link ) default
512 * @cfg {String} size ( lg | sm | xs)
513 * @cfg {String} tag ( a | input | submit)
514 * @cfg {String} href empty or href
515 * @cfg {Boolean} disabled default false;
516 * @cfg {Boolean} isClose default false;
517 * @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)
518 * @cfg {String} badge text for badge
519 * @cfg {String} theme default
520 * @cfg {Boolean} inverse
521 * @cfg {Boolean} toggle
522 * @cfg {String} ontext text for on toggle state
523 * @cfg {String} offtext text for off toggle state
524 * @cfg {Boolean} defaulton
525 * @cfg {Boolean} preventDefault default true
526 * @cfg {Boolean} removeClass remove the standard class..
527 * @cfg {String} target target for a href. (_self|_blank|_parent|_top| other)
530 * Create a new button
531 * @param {Object} config The config object
535 Roo.bootstrap.Button = function(config){
536 Roo.bootstrap.Button.superclass.constructor.call(this, config);
537 this.weightClass = ["btn-default",
549 * When a butotn is pressed
550 * @param {Roo.bootstrap.Button} this
551 * @param {Roo.EventObject} e
556 * After the button has been toggles
557 * @param {Roo.EventObject} e
558 * @param {boolean} pressed (also available as button.pressed)
564 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
582 preventDefault: true,
591 getAutoCreate : function(){
599 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
600 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
605 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
607 if (this.toggle == true) {
610 cls: 'slider-frame roo-button',
615 'data-off-text':'OFF',
616 cls: 'slider-button',
622 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
623 cfg.cls += ' '+this.weight;
632 cfg["aria-hidden"] = true;
634 cfg.html = "×";
640 if (this.theme==='default') {
641 cfg.cls = 'btn roo-button';
643 //if (this.parentType != 'Navbar') {
644 this.weight = this.weight.length ? this.weight : 'default';
646 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
648 cfg.cls += ' btn-' + this.weight;
650 } else if (this.theme==='glow') {
653 cfg.cls = 'btn-glow roo-button';
655 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
657 cfg.cls += ' ' + this.weight;
663 this.cls += ' inverse';
668 cfg.cls += ' active';
672 cfg.disabled = 'disabled';
676 Roo.log('changing to ul' );
678 this.glyphicon = 'caret';
681 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
683 //gsRoo.log(this.parentType);
684 if (this.parentType === 'Navbar' && !this.parent().bar) {
685 Roo.log('changing to li?');
694 href : this.href || '#'
697 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
698 cfg.cls += ' dropdown';
705 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
707 if (this.glyphicon) {
708 cfg.html = ' ' + cfg.html;
713 cls: 'glyphicon glyphicon-' + this.glyphicon
723 // cfg.cls='btn roo-button';
727 var value = cfg.html;
732 cls: 'glyphicon glyphicon-' + this.glyphicon,
751 cfg.cls += ' dropdown';
752 cfg.html = typeof(cfg.html) != 'undefined' ? cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
755 if (cfg.tag !== 'a' && this.href !== '') {
756 throw "Tag must be a to set href.";
757 } else if (this.href.length > 0) {
758 cfg.href = this.href;
761 if(this.removeClass){
766 cfg.target = this.target;
771 initEvents: function() {
772 // Roo.log('init events?');
773 // Roo.log(this.el.dom);
776 if (typeof (this.menu) != 'undefined') {
777 this.menu.parentType = this.xtype;
778 this.menu.triggerEl = this.el;
779 this.addxtype(Roo.apply({}, this.menu));
783 if (this.el.hasClass('roo-button')) {
784 this.el.on('click', this.onClick, this);
786 this.el.select('.roo-button').on('click', this.onClick, this);
789 if(this.removeClass){
790 this.el.on('click', this.onClick, this);
793 this.el.enableDisplayMode();
796 onClick : function(e)
803 Roo.log('button on click ');
804 if(this.preventDefault){
807 if (this.pressed === true || this.pressed === false) {
808 this.pressed = !this.pressed;
809 this.el[this.pressed ? 'addClass' : 'removeClass']('active');
810 this.fireEvent('toggle', this, e, this.pressed);
814 this.fireEvent('click', this, e);
818 * Enables this button
822 this.disabled = false;
823 this.el.removeClass('disabled');
827 * Disable this button
831 this.disabled = true;
832 this.el.addClass('disabled');
835 * sets the active state on/off,
836 * @param {Boolean} state (optional) Force a particular state
838 setActive : function(v) {
840 this.el[v ? 'addClass' : 'removeClass']('active');
843 * toggles the current active state
845 toggleActive : function()
847 var active = this.el.hasClass('active');
848 this.setActive(!active);
852 setText : function(str)
854 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
858 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
869 setWeight : function(str)
871 this.el.removeClass(this.weightClass);
872 this.el.addClass('btn-' + str);
886 * @class Roo.bootstrap.Column
887 * @extends Roo.bootstrap.Component
888 * Bootstrap Column class
889 * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
890 * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
891 * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
892 * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
893 * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
894 * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
895 * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
896 * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
899 * @cfg {Boolean} hidden (true|false) hide the element
900 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
901 * @cfg {String} fa (ban|check|...) font awesome icon
902 * @cfg {Number} fasize (1|2|....) font awsome size
904 * @cfg {String} icon (info-sign|check|...) glyphicon name
906 * @cfg {String} html content of column.
909 * Create a new Column
910 * @param {Object} config The config object
913 Roo.bootstrap.Column = function(config){
914 Roo.bootstrap.Column.superclass.constructor.call(this, config);
917 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, {
935 getAutoCreate : function(){
936 var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
944 ['xs','sm','md','lg'].map(function(size){
945 //Roo.log( size + ':' + settings[size]);
947 if (settings[size+'off'] !== false) {
948 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
951 if (settings[size] === false) {
955 if (!settings[size]) { // 0 = hidden
956 cfg.cls += ' hidden-' + size;
959 cfg.cls += ' col-' + size + '-' + settings[size];
964 cfg.cls += ' hidden';
967 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
968 cfg.cls +=' alert alert-' + this.alert;
972 if (this.html.length) {
973 cfg.html = this.html;
977 if (this.fasize > 1) {
978 fasize = ' fa-' + this.fasize + 'x';
980 cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
985 cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + (cfg.html || '');
1004 * @class Roo.bootstrap.Container
1005 * @extends Roo.bootstrap.Component
1006 * Bootstrap Container class
1007 * @cfg {Boolean} jumbotron is it a jumbotron element
1008 * @cfg {String} html content of element
1009 * @cfg {String} well (lg|sm|md) a well, large, small or medium.
1010 * @cfg {String} panel (primary|success|info|warning|danger) render as panel - type - primary/success.....
1011 * @cfg {String} header content of header (for panel)
1012 * @cfg {String} footer content of footer (for panel)
1013 * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
1014 * @cfg {String} tag (header|aside|section) type of HTML tag.
1015 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1016 * @cfg {String} fa font awesome icon
1017 * @cfg {String} icon (info-sign|check|...) glyphicon name
1018 * @cfg {Boolean} hidden (true|false) hide the element
1019 * @cfg {Boolean} expandable (true|false) default false
1020 * @cfg {Boolean} expanded (true|false) default true
1021 * @cfg {String} rheader contet on the right of header
1022 * @cfg {Boolean} clickable (true|false) default false
1026 * Create a new Container
1027 * @param {Object} config The config object
1030 Roo.bootstrap.Container = function(config){
1031 Roo.bootstrap.Container.superclass.constructor.call(this, config);
1037 * After the panel has been expand
1039 * @param {Roo.bootstrap.Container} this
1044 * After the panel has been collapsed
1046 * @param {Roo.bootstrap.Container} this
1051 * When a element is chick
1052 * @param {Roo.bootstrap.Container} this
1053 * @param {Roo.EventObject} e
1059 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, {
1077 getChildContainer : function() {
1083 if (this.panel.length) {
1084 return this.el.select('.panel-body',true).first();
1091 getAutoCreate : function(){
1094 tag : this.tag || 'div',
1098 if (this.jumbotron) {
1099 cfg.cls = 'jumbotron';
1104 // - this is applied by the parent..
1106 // cfg.cls = this.cls + '';
1109 if (this.sticky.length) {
1111 var bd = Roo.get(document.body);
1112 if (!bd.hasClass('bootstrap-sticky')) {
1113 bd.addClass('bootstrap-sticky');
1114 Roo.select('html',true).setStyle('height', '100%');
1117 cfg.cls += 'bootstrap-sticky-' + this.sticky;
1121 if (this.well.length) {
1122 switch (this.well) {
1125 cfg.cls +=' well well-' +this.well;
1134 cfg.cls += ' hidden';
1138 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1139 cfg.cls +=' alert alert-' + this.alert;
1144 if (this.panel.length) {
1145 cfg.cls += ' panel panel-' + this.panel;
1147 if (this.header.length) {
1151 if(this.expandable){
1153 cfg.cls = cfg.cls + ' expandable';
1157 cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus')
1165 cls : 'panel-title',
1166 html : (this.expandable ? ' ' : '') + this.header
1170 cls: 'panel-header-right',
1176 cls : 'panel-heading',
1177 style : this.expandable ? 'cursor: pointer' : '',
1185 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1190 if (this.footer.length) {
1192 cls : 'panel-footer',
1201 body.html = this.html || cfg.html;
1202 // prefix with the icons..
1204 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1207 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1212 if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1213 cfg.cls = 'container';
1219 initEvents: function()
1221 if(this.expandable){
1222 var headerEl = this.headerEl();
1225 headerEl.on('click', this.onToggleClick, this);
1230 this.el.on('click', this.onClick, this);
1235 onToggleClick : function()
1237 var headerEl = this.headerEl();
1253 if(this.fireEvent('expand', this)) {
1255 this.expanded = true;
1257 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1259 this.el.select('.panel-body',true).first().removeClass('hide');
1261 var toggleEl = this.toggleEl();
1267 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1272 collapse : function()
1274 if(this.fireEvent('collapse', this)) {
1276 this.expanded = false;
1278 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1279 this.el.select('.panel-body',true).first().addClass('hide');
1281 var toggleEl = this.toggleEl();
1287 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1291 toggleEl : function()
1293 if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1297 return this.el.select('.panel-heading .fa',true).first();
1300 headerEl : function()
1302 if(!this.el || !this.panel.length || !this.header.length){
1306 return this.el.select('.panel-heading',true).first()
1311 if(!this.el || !this.panel.length){
1315 return this.el.select('.panel-body',true).first()
1318 titleEl : function()
1320 if(!this.el || !this.panel.length || !this.header.length){
1324 return this.el.select('.panel-title',true).first();
1327 setTitle : function(v)
1329 var titleEl = this.titleEl();
1335 titleEl.dom.innerHTML = v;
1338 getTitle : function()
1341 var titleEl = this.titleEl();
1347 return titleEl.dom.innerHTML;
1350 setRightTitle : function(v)
1352 var t = this.el.select('.panel-header-right',true).first();
1358 t.dom.innerHTML = v;
1361 onClick : function(e)
1365 this.fireEvent('click', this, e);
1379 * @class Roo.bootstrap.Img
1380 * @extends Roo.bootstrap.Component
1381 * Bootstrap Img class
1382 * @cfg {Boolean} imgResponsive false | true
1383 * @cfg {String} border rounded | circle | thumbnail
1384 * @cfg {String} src image source
1385 * @cfg {String} alt image alternative text
1386 * @cfg {String} href a tag href
1387 * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
1388 * @cfg {String} xsUrl xs image source
1389 * @cfg {String} smUrl sm image source
1390 * @cfg {String} mdUrl md image source
1391 * @cfg {String} lgUrl lg image source
1394 * Create a new Input
1395 * @param {Object} config The config object
1398 Roo.bootstrap.Img = function(config){
1399 Roo.bootstrap.Img.superclass.constructor.call(this, config);
1405 * The img click event for the img.
1406 * @param {Roo.EventObject} e
1412 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
1414 imgResponsive: true,
1424 getAutoCreate : function()
1426 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1427 return this.createSingleImg();
1432 cls: 'roo-image-responsive-group',
1437 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
1439 if(!_this[size + 'Url']){
1445 cls: (_this.imgResponsive) ? 'img-responsive' : '',
1446 html: _this.html || cfg.html,
1447 src: _this[size + 'Url']
1450 img.cls += ' roo-image-responsive-' + size;
1452 var s = ['xs', 'sm', 'md', 'lg'];
1454 s.splice(s.indexOf(size), 1);
1456 Roo.each(s, function(ss){
1457 img.cls += ' hidden-' + ss;
1460 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
1461 cfg.cls += ' img-' + _this.border;
1465 cfg.alt = _this.alt;
1478 a.target = _this.target;
1482 cfg.cn.push((_this.href) ? a : img);
1489 createSingleImg : function()
1493 cls: (this.imgResponsive) ? 'img-responsive' : '',
1495 src : 'about:blank' // just incase src get's set to undefined?!?
1498 cfg.html = this.html || cfg.html;
1500 cfg.src = this.src || cfg.src;
1502 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
1503 cfg.cls += ' img-' + this.border;
1520 a.target = this.target;
1525 return (this.href) ? a : cfg;
1528 initEvents: function()
1531 this.el.on('click', this.onClick, this);
1536 onClick : function(e)
1538 Roo.log('img onclick');
1539 this.fireEvent('click', this, e);
1542 * Sets the url of the image - used to update it
1543 * @param {String} url the url of the image
1546 setSrc : function(url)
1550 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1551 this.el.dom.src = url;
1555 this.el.select('img', true).first().dom.src = url;
1571 * @class Roo.bootstrap.Link
1572 * @extends Roo.bootstrap.Component
1573 * Bootstrap Link Class
1574 * @cfg {String} alt image alternative text
1575 * @cfg {String} href a tag href
1576 * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
1577 * @cfg {String} html the content of the link.
1578 * @cfg {String} anchor name for the anchor link
1579 * @cfg {String} fa - favicon
1581 * @cfg {Boolean} preventDefault (true | false) default false
1585 * Create a new Input
1586 * @param {Object} config The config object
1589 Roo.bootstrap.Link = function(config){
1590 Roo.bootstrap.Link.superclass.constructor.call(this, config);
1596 * The img click event for the img.
1597 * @param {Roo.EventObject} e
1603 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component, {
1607 preventDefault: false,
1613 getAutoCreate : function()
1615 var html = this.html || '';
1617 if (this.fa !== false) {
1618 html = '<i class="fa fa-' + this.fa + '"></i>';
1623 // anchor's do not require html/href...
1624 if (this.anchor === false) {
1626 cfg.href = this.href || '#';
1628 cfg.name = this.anchor;
1629 if (this.html !== false || this.fa !== false) {
1632 if (this.href !== false) {
1633 cfg.href = this.href;
1637 if(this.alt !== false){
1642 if(this.target !== false) {
1643 cfg.target = this.target;
1649 initEvents: function() {
1651 if(!this.href || this.preventDefault){
1652 this.el.on('click', this.onClick, this);
1656 onClick : function(e)
1658 if(this.preventDefault){
1661 //Roo.log('img onclick');
1662 this.fireEvent('click', this, e);
1675 * @class Roo.bootstrap.Header
1676 * @extends Roo.bootstrap.Component
1677 * Bootstrap Header class
1678 * @cfg {String} html content of header
1679 * @cfg {Number} level (1|2|3|4|5|6) default 1
1682 * Create a new Header
1683 * @param {Object} config The config object
1687 Roo.bootstrap.Header = function(config){
1688 Roo.bootstrap.Header.superclass.constructor.call(this, config);
1691 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, {
1699 getAutoCreate : function(){
1704 tag: 'h' + (1 *this.level),
1705 html: this.html || ''
1717 * Ext JS Library 1.1.1
1718 * Copyright(c) 2006-2007, Ext JS, LLC.
1720 * Originally Released Under LGPL - original licence link has changed is not relivant.
1723 * <script type="text/javascript">
1727 * @class Roo.bootstrap.MenuMgr
1728 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
1731 Roo.bootstrap.MenuMgr = function(){
1732 var menus, active, groups = {}, attached = false, lastShow = new Date();
1734 // private - called when first menu is created
1737 active = new Roo.util.MixedCollection();
1738 Roo.get(document).addKeyListener(27, function(){
1739 if(active.length > 0){
1747 if(active && active.length > 0){
1748 var c = active.clone();
1758 if(active.length < 1){
1759 Roo.get(document).un("mouseup", onMouseDown);
1767 var last = active.last();
1768 lastShow = new Date();
1771 Roo.get(document).on("mouseup", onMouseDown);
1776 //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
1777 m.parentMenu.activeChild = m;
1778 }else if(last && last.isVisible()){
1779 //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
1784 function onBeforeHide(m){
1786 m.activeChild.hide();
1788 if(m.autoHideTimer){
1789 clearTimeout(m.autoHideTimer);
1790 delete m.autoHideTimer;
1795 function onBeforeShow(m){
1796 var pm = m.parentMenu;
1797 if(!pm && !m.allowOtherMenus){
1799 }else if(pm && pm.activeChild && active != m){
1800 pm.activeChild.hide();
1804 // private this should really trigger on mouseup..
1805 function onMouseDown(e){
1806 Roo.log("on Mouse Up");
1808 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
1809 Roo.log("MenuManager hideAll");
1818 function onBeforeCheck(mi, state){
1820 var g = groups[mi.group];
1821 for(var i = 0, l = g.length; i < l; i++){
1823 g[i].setChecked(false);
1832 * Hides all menus that are currently visible
1834 hideAll : function(){
1839 register : function(menu){
1843 menus[menu.id] = menu;
1844 menu.on("beforehide", onBeforeHide);
1845 menu.on("hide", onHide);
1846 menu.on("beforeshow", onBeforeShow);
1847 menu.on("show", onShow);
1849 if(g && menu.events["checkchange"]){
1853 groups[g].push(menu);
1854 menu.on("checkchange", onCheck);
1859 * Returns a {@link Roo.menu.Menu} object
1860 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
1861 * be used to generate and return a new Menu instance.
1863 get : function(menu){
1864 if(typeof menu == "string"){ // menu id
1866 }else if(menu.events){ // menu instance
1869 /*else if(typeof menu.length == 'number'){ // array of menu items?
1870 return new Roo.bootstrap.Menu({items:menu});
1871 }else{ // otherwise, must be a config
1872 return new Roo.bootstrap.Menu(menu);
1879 unregister : function(menu){
1880 delete menus[menu.id];
1881 menu.un("beforehide", onBeforeHide);
1882 menu.un("hide", onHide);
1883 menu.un("beforeshow", onBeforeShow);
1884 menu.un("show", onShow);
1886 if(g && menu.events["checkchange"]){
1887 groups[g].remove(menu);
1888 menu.un("checkchange", onCheck);
1893 registerCheckable : function(menuItem){
1894 var g = menuItem.group;
1899 groups[g].push(menuItem);
1900 menuItem.on("beforecheckchange", onBeforeCheck);
1905 unregisterCheckable : function(menuItem){
1906 var g = menuItem.group;
1908 groups[g].remove(menuItem);
1909 menuItem.un("beforecheckchange", onBeforeCheck);
1921 * @class Roo.bootstrap.Menu
1922 * @extends Roo.bootstrap.Component
1923 * Bootstrap Menu class - container for MenuItems
1924 * @cfg {String} type (dropdown|treeview|submenu) type of menu
1925 * @cfg {bool} hidden if the menu should be hidden when rendered.
1926 * @cfg {bool} stopEvent (true|false) Stop event after trigger press (default true)
1927 * @cfg {bool} isLink (true|false) the menu has link disable auto expand and collaspe (default false)
1931 * @param {Object} config The config object
1935 Roo.bootstrap.Menu = function(config){
1936 Roo.bootstrap.Menu.superclass.constructor.call(this, config);
1937 if (this.registerMenu && this.type != 'treeview') {
1938 Roo.bootstrap.MenuMgr.register(this);
1943 * Fires before this menu is displayed
1944 * @param {Roo.menu.Menu} this
1949 * Fires before this menu is hidden
1950 * @param {Roo.menu.Menu} this
1955 * Fires after this menu is displayed
1956 * @param {Roo.menu.Menu} this
1961 * Fires after this menu is hidden
1962 * @param {Roo.menu.Menu} this
1967 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
1968 * @param {Roo.menu.Menu} this
1969 * @param {Roo.menu.Item} menuItem The menu item that was clicked
1970 * @param {Roo.EventObject} e
1975 * Fires when the mouse is hovering over this menu
1976 * @param {Roo.menu.Menu} this
1977 * @param {Roo.EventObject} e
1978 * @param {Roo.menu.Item} menuItem The menu item that was clicked
1983 * Fires when the mouse exits this menu
1984 * @param {Roo.menu.Menu} this
1985 * @param {Roo.EventObject} e
1986 * @param {Roo.menu.Item} menuItem The menu item that was clicked
1991 * Fires when a menu item contained in this menu is clicked
1992 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
1993 * @param {Roo.EventObject} e
1997 this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
2000 Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component, {
2004 triggerEl : false, // is this set by component builder? -- it should really be fetched from parent()???
2007 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
2009 registerMenu : true,
2011 menuItems :false, // stores the menu items..
2021 getChildContainer : function() {
2025 getAutoCreate : function(){
2027 //if (['right'].indexOf(this.align)!==-1) {
2028 // cfg.cn[1].cls += ' pull-right'
2034 cls : 'dropdown-menu' ,
2035 style : 'z-index:1000'
2039 if (this.type === 'submenu') {
2040 cfg.cls = 'submenu active';
2042 if (this.type === 'treeview') {
2043 cfg.cls = 'treeview-menu';
2048 initEvents : function() {
2050 // Roo.log("ADD event");
2051 // Roo.log(this.triggerEl.dom);
2053 this.triggerEl.on('click', this.onTriggerClick, this);
2055 this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
2057 this.triggerEl.addClass('dropdown-toggle');
2060 this.el.on('touchstart' , this.onTouch, this);
2062 this.el.on('click' , this.onClick, this);
2064 this.el.on("mouseover", this.onMouseOver, this);
2065 this.el.on("mouseout", this.onMouseOut, this);
2069 findTargetItem : function(e)
2071 var t = e.getTarget(".dropdown-menu-item", this.el, true);
2075 //Roo.log(t); Roo.log(t.id);
2077 //Roo.log(this.menuitems);
2078 return this.menuitems.get(t.id);
2080 //return this.items.get(t.menuItemId);
2086 onTouch : function(e)
2088 Roo.log("menu.onTouch");
2089 //e.stopEvent(); this make the user popdown broken
2093 onClick : function(e)
2095 Roo.log("menu.onClick");
2097 var t = this.findTargetItem(e);
2098 if(!t || t.isContainer){
2103 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
2104 if(t == this.activeItem && t.shouldDeactivate(e)){
2105 this.activeItem.deactivate();
2106 delete this.activeItem;
2110 this.setActiveItem(t, true);
2118 Roo.log('pass click event');
2122 this.fireEvent("click", this, t, e);
2126 if(!t.href.length || t.href == '#'){
2127 (function() { _this.hide(); }).defer(100);
2132 onMouseOver : function(e){
2133 var t = this.findTargetItem(e);
2136 // if(t.canActivate && !t.disabled){
2137 // this.setActiveItem(t, true);
2141 this.fireEvent("mouseover", this, e, t);
2143 isVisible : function(){
2144 return !this.hidden;
2146 onMouseOut : function(e){
2147 var t = this.findTargetItem(e);
2150 // if(t == this.activeItem && t.shouldDeactivate(e)){
2151 // this.activeItem.deactivate();
2152 // delete this.activeItem;
2155 this.fireEvent("mouseout", this, e, t);
2160 * Displays this menu relative to another element
2161 * @param {String/HTMLElement/Roo.Element} element The element to align to
2162 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
2163 * the element (defaults to this.defaultAlign)
2164 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2166 show : function(el, pos, parentMenu){
2167 this.parentMenu = parentMenu;
2171 this.fireEvent("beforeshow", this);
2172 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
2175 * Displays this menu at a specific xy position
2176 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
2177 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2179 showAt : function(xy, parentMenu, /* private: */_e){
2180 this.parentMenu = parentMenu;
2185 this.fireEvent("beforeshow", this);
2186 //xy = this.el.adjustForConstraints(xy);
2190 this.hideMenuItems();
2191 this.hidden = false;
2192 this.triggerEl.addClass('open');
2194 if(this.el.getWidth() + xy[0] > Roo.lib.Dom.getViewWidth()){
2195 xy[0] = xy[0] - this.el.getWidth() + this.triggerEl.getWidth();
2198 if(this.el.getStyle('top') != 'auto' && this.el.getStyle('top').slice(-1) != "%"){
2203 this.fireEvent("show", this);
2209 this.doFocus.defer(50, this);
2213 doFocus : function(){
2215 this.focusEl.focus();
2220 * Hides this menu and optionally all parent menus
2221 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
2223 hide : function(deep)
2226 this.hideMenuItems();
2227 if(this.el && this.isVisible()){
2228 this.fireEvent("beforehide", this);
2229 if(this.activeItem){
2230 this.activeItem.deactivate();
2231 this.activeItem = null;
2233 this.triggerEl.removeClass('open');;
2235 this.fireEvent("hide", this);
2237 if(deep === true && this.parentMenu){
2238 this.parentMenu.hide(true);
2242 onTriggerClick : function(e)
2244 Roo.log('trigger click');
2246 var target = e.getTarget();
2248 Roo.log(target.nodeName.toLowerCase());
2250 if(target.nodeName.toLowerCase() === 'i'){
2256 onTriggerPress : function(e)
2258 Roo.log('trigger press');
2259 //Roo.log(e.getTarget());
2260 // Roo.log(this.triggerEl.dom);
2262 // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
2263 var pel = Roo.get(e.getTarget());
2264 if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
2265 Roo.log('is treeview or dropdown?');
2269 if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
2273 if (this.isVisible()) {
2278 this.show(this.triggerEl, false, false);
2281 if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
2288 hideMenuItems : function()
2290 Roo.log("hide Menu Items");
2294 //$(backdrop).remove()
2295 this.el.select('.open',true).each(function(aa) {
2297 aa.removeClass('open');
2298 //var parent = getParent($(this))
2299 //var relatedTarget = { relatedTarget: this }
2301 //$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
2302 //if (e.isDefaultPrevented()) return
2303 //$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
2306 addxtypeChild : function (tree, cntr) {
2307 var comp= Roo.bootstrap.Menu.superclass.addxtypeChild.call(this, tree, cntr);
2309 this.menuitems.add(comp);
2330 * @class Roo.bootstrap.MenuItem
2331 * @extends Roo.bootstrap.Component
2332 * Bootstrap MenuItem class
2333 * @cfg {String} html the menu label
2334 * @cfg {String} href the link
2335 * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
2336 * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
2337 * @cfg {Boolean} active used on sidebars to highlight active itesm
2338 * @cfg {String} fa favicon to show on left of menu item.
2339 * @cfg {Roo.bootsrap.Menu} menu the child menu.
2343 * Create a new MenuItem
2344 * @param {Object} config The config object
2348 Roo.bootstrap.MenuItem = function(config){
2349 Roo.bootstrap.MenuItem.superclass.constructor.call(this, config);
2354 * The raw click event for the entire grid.
2355 * @param {Roo.bootstrap.MenuItem} this
2356 * @param {Roo.EventObject} e
2362 Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component, {
2366 preventDefault: false,
2367 isContainer : false,
2371 getAutoCreate : function(){
2373 if(this.isContainer){
2376 cls: 'dropdown-menu-item'
2390 if (this.fa !== false) {
2393 cls : 'fa fa-' + this.fa
2402 cls: 'dropdown-menu-item',
2405 if (this.parent().type == 'treeview') {
2406 cfg.cls = 'treeview-menu';
2409 cfg.cls += ' active';
2414 anc.href = this.href || cfg.cn[0].href ;
2415 ctag.html = this.html || cfg.cn[0].html ;
2419 initEvents: function()
2421 if (this.parent().type == 'treeview') {
2422 this.el.select('a').on('click', this.onClick, this);
2426 this.menu.parentType = this.xtype;
2427 this.menu.triggerEl = this.el;
2428 this.menu = this.addxtype(Roo.apply({}, this.menu));
2432 onClick : function(e)
2434 Roo.log('item on click ');
2436 if(this.preventDefault){
2439 //this.parent().hideMenuItems();
2441 this.fireEvent('click', this, e);
2460 * @class Roo.bootstrap.MenuSeparator
2461 * @extends Roo.bootstrap.Component
2462 * Bootstrap MenuSeparator class
2465 * Create a new MenuItem
2466 * @param {Object} config The config object
2470 Roo.bootstrap.MenuSeparator = function(config){
2471 Roo.bootstrap.MenuSeparator.superclass.constructor.call(this, config);
2474 Roo.extend(Roo.bootstrap.MenuSeparator, Roo.bootstrap.Component, {
2476 getAutoCreate : function(){
2495 * @class Roo.bootstrap.Modal
2496 * @extends Roo.bootstrap.Component
2497 * Bootstrap Modal class
2498 * @cfg {String} title Title of dialog
2499 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
2500 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
2501 * @cfg {Boolean} specificTitle default false
2502 * @cfg {Array} buttons Array of buttons or standard button set..
2503 * @cfg {String} buttonPosition (left|right|center) default right
2504 * @cfg {Boolean} animate default true
2505 * @cfg {Boolean} allow_close default true
2506 * @cfg {Boolean} fitwindow default false
2507 * @cfg {String} size (sm|lg) default empty
2511 * Create a new Modal Dialog
2512 * @param {Object} config The config object
2515 Roo.bootstrap.Modal = function(config){
2516 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
2521 * The raw btnclick event for the button
2522 * @param {Roo.EventObject} e
2527 * Fire when dialog resize
2528 * @param {Roo.bootstrap.Modal} this
2529 * @param {Roo.EventObject} e
2533 this.buttons = this.buttons || [];
2536 this.tmpl = Roo.factory(this.tmpl);
2541 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
2543 title : 'test dialog',
2553 specificTitle: false,
2555 buttonPosition: 'right',
2574 onRender : function(ct, position)
2576 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
2579 var cfg = Roo.apply({}, this.getAutoCreate());
2582 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
2584 //if (!cfg.name.length) {
2588 cfg.cls += ' ' + this.cls;
2591 cfg.style = this.style;
2593 this.el = Roo.get(document.body).createChild(cfg, position);
2595 //var type = this.el.dom.type;
2598 if(this.tabIndex !== undefined){
2599 this.el.dom.setAttribute('tabIndex', this.tabIndex);
2602 this.dialogEl = this.el.select('.modal-dialog',true).first();
2603 this.bodyEl = this.el.select('.modal-body',true).first();
2604 this.closeEl = this.el.select('.modal-header .close', true).first();
2605 this.headerEl = this.el.select('.modal-header',true).first();
2606 this.titleEl = this.el.select('.modal-title',true).first();
2607 this.footerEl = this.el.select('.modal-footer',true).first();
2609 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2610 this.maskEl.enableDisplayMode("block");
2612 //this.el.addClass("x-dlg-modal");
2614 if (this.buttons.length) {
2615 Roo.each(this.buttons, function(bb) {
2616 var b = Roo.apply({}, bb);
2617 b.xns = b.xns || Roo.bootstrap;
2618 b.xtype = b.xtype || 'Button';
2619 if (typeof(b.listeners) == 'undefined') {
2620 b.listeners = { click : this.onButtonClick.createDelegate(this) };
2623 var btn = Roo.factory(b);
2625 btn.render(this.el.select('.modal-footer div').first());
2629 // render the children.
2632 if(typeof(this.items) != 'undefined'){
2633 var items = this.items;
2636 for(var i =0;i < items.length;i++) {
2637 nitems.push(this.addxtype(Roo.apply({}, items[i])));
2641 this.items = nitems;
2643 // where are these used - they used to be body/close/footer
2647 //this.el.addClass([this.fieldClass, this.cls]);
2651 getAutoCreate : function(){
2656 html : this.html || ''
2661 cls : 'modal-title',
2665 if(this.specificTitle){
2671 if (this.allow_close) {
2683 if(this.size.length){
2684 size = 'modal-' + this.size;
2689 style : 'display: none',
2692 cls: "modal-dialog " + size,
2695 cls : "modal-content",
2698 cls : 'modal-header',
2703 cls : 'modal-footer',
2707 cls: 'btn-' + this.buttonPosition
2724 modal.cls += ' fade';
2730 getChildContainer : function() {
2735 getButtonContainer : function() {
2736 return this.el.select('.modal-footer div',true).first();
2739 initEvents : function()
2741 if (this.allow_close) {
2742 this.closeEl.on('click', this.hide, this);
2744 Roo.EventManager.onWindowResize(this.resize, this, true);
2751 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2752 if (this.fitwindow) {
2753 var w = this.width || Roo.lib.Dom.getViewportWidth(true) - 30;
2754 var h = this.height || Roo.lib.Dom.getViewportHeight(true) - 60;
2759 setSize : function(w,h)
2769 if (!this.rendered) {
2773 this.el.setStyle('display', 'block');
2775 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
2778 this.el.addClass('in');
2781 this.el.addClass('in');
2785 // not sure how we can show data in here..
2787 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
2790 Roo.get(document.body).addClass("x-body-masked");
2792 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2793 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2798 this.fireEvent('show', this);
2800 // set zindex here - otherwise it appears to be ignored...
2801 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2804 this.items.forEach( function(e) {
2805 e.layout ? e.layout() : false;
2813 if(this.fireEvent("beforehide", this) !== false){
2815 Roo.get(document.body).removeClass("x-body-masked");
2816 this.el.removeClass('in');
2817 this.el.select('.modal-dialog', true).first().setStyle('transform','');
2819 if(this.animate){ // why
2821 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
2823 this.el.setStyle('display', 'none');
2825 this.fireEvent('hide', this);
2829 addButton : function(str, cb)
2833 var b = Roo.apply({}, { html : str } );
2834 b.xns = b.xns || Roo.bootstrap;
2835 b.xtype = b.xtype || 'Button';
2836 if (typeof(b.listeners) == 'undefined') {
2837 b.listeners = { click : cb.createDelegate(this) };
2840 var btn = Roo.factory(b);
2842 btn.render(this.el.select('.modal-footer div').first());
2848 setDefaultButton : function(btn)
2850 //this.el.select('.modal-footer').()
2854 resizeTo: function(w,h)
2858 this.dialogEl.setWidth(w);
2859 if (this.diff === false) {
2860 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
2863 this.bodyEl.setHeight(h-this.diff);
2865 this.fireEvent('resize', this);
2868 setContentSize : function(w, h)
2872 onButtonClick: function(btn,e)
2875 this.fireEvent('btnclick', btn.name, e);
2878 * Set the title of the Dialog
2879 * @param {String} str new Title
2881 setTitle: function(str) {
2882 this.titleEl.dom.innerHTML = str;
2885 * Set the body of the Dialog
2886 * @param {String} str new Title
2888 setBody: function(str) {
2889 this.bodyEl.dom.innerHTML = str;
2892 * Set the body of the Dialog using the template
2893 * @param {Obj} data - apply this data to the template and replace the body contents.
2895 applyBody: function(obj)
2898 Roo.log("Error - using apply Body without a template");
2901 this.tmpl.overwrite(this.bodyEl, obj);
2907 Roo.apply(Roo.bootstrap.Modal, {
2909 * Button config that displays a single OK button
2918 * Button config that displays Yes and No buttons
2934 * Button config that displays OK and Cancel buttons
2949 * Button config that displays Yes, No and Cancel buttons
2973 * messagebox - can be used as a replace
2977 * @class Roo.MessageBox
2978 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
2982 Roo.Msg.alert('Status', 'Changes saved successfully.');
2984 // Prompt for user data:
2985 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
2987 // process text value...
2991 // Show a dialog using config options:
2993 title:'Save Changes?',
2994 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
2995 buttons: Roo.Msg.YESNOCANCEL,
3002 Roo.bootstrap.MessageBox = function(){
3003 var dlg, opt, mask, waitTimer;
3004 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
3005 var buttons, activeTextEl, bwidth;
3009 var handleButton = function(button){
3011 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
3015 var handleHide = function(){
3017 dlg.el.removeClass(opt.cls);
3020 // Roo.TaskMgr.stop(waitTimer);
3021 // waitTimer = null;
3026 var updateButtons = function(b){
3029 buttons["ok"].hide();
3030 buttons["cancel"].hide();
3031 buttons["yes"].hide();
3032 buttons["no"].hide();
3033 //dlg.footer.dom.style.display = 'none';
3036 dlg.footerEl.dom.style.display = '';
3037 for(var k in buttons){
3038 if(typeof buttons[k] != "function"){
3041 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
3042 width += buttons[k].el.getWidth()+15;
3052 var handleEsc = function(d, k, e){
3053 if(opt && opt.closable !== false){
3063 * Returns a reference to the underlying {@link Roo.BasicDialog} element
3064 * @return {Roo.BasicDialog} The BasicDialog element
3066 getDialog : function(){
3068 dlg = new Roo.bootstrap.Modal( {
3071 //constraintoviewport:false,
3073 //collapsible : false,
3078 //buttonAlign:"center",
3079 closeClick : function(){
3080 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
3083 handleButton("cancel");
3088 dlg.on("hide", handleHide);
3090 //dlg.addKeyListener(27, handleEsc);
3092 this.buttons = buttons;
3093 var bt = this.buttonText;
3094 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
3095 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
3096 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
3097 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
3099 bodyEl = dlg.bodyEl.createChild({
3101 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
3102 '<textarea class="roo-mb-textarea"></textarea>' +
3103 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
3105 msgEl = bodyEl.dom.firstChild;
3106 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
3107 textboxEl.enableDisplayMode();
3108 textboxEl.addKeyListener([10,13], function(){
3109 if(dlg.isVisible() && opt && opt.buttons){
3112 }else if(opt.buttons.yes){
3113 handleButton("yes");
3117 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
3118 textareaEl.enableDisplayMode();
3119 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
3120 progressEl.enableDisplayMode();
3122 // This is supposed to be the progessElement.. but I think it's controlling the height of everything..
3123 //var pf = progressEl.dom.firstChild;
3125 //pp = Roo.get(pf.firstChild);
3126 //pp.setHeight(pf.offsetHeight);
3134 * Updates the message box body text
3135 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
3136 * the XHTML-compliant non-breaking space character '&#160;')
3137 * @return {Roo.MessageBox} This message box
3139 updateText : function(text)
3141 if(!dlg.isVisible() && !opt.width){
3142 dlg.dialogEl.setWidth(this.maxWidth);
3143 // dlg.resizeTo(this.maxWidth, 100); // forcing the height breaks long alerts()
3145 msgEl.innerHTML = text || ' ';
3147 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
3148 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
3150 Math.min(opt.width || cw , this.maxWidth),
3151 Math.max(opt.minWidth || this.minWidth, bwidth)
3154 activeTextEl.setWidth(w);
3156 if(dlg.isVisible()){
3157 dlg.fixedcenter = false;
3159 // to big, make it scroll. = But as usual stupid IE does not support
3162 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
3163 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
3164 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
3166 bodyEl.dom.style.height = '';
3167 bodyEl.dom.style.overflowY = '';
3170 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
3172 bodyEl.dom.style.overflowX = '';
3175 dlg.setContentSize(w, bodyEl.getHeight());
3176 if(dlg.isVisible()){
3177 dlg.fixedcenter = true;
3183 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
3184 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
3185 * @param {Number} value Any number between 0 and 1 (e.g., .5)
3186 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
3187 * @return {Roo.MessageBox} This message box
3189 updateProgress : function(value, text){
3191 this.updateText(text);
3193 if (pp) { // weird bug on my firefox - for some reason this is not defined
3194 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
3200 * Returns true if the message box is currently displayed
3201 * @return {Boolean} True if the message box is visible, else false
3203 isVisible : function(){
3204 return dlg && dlg.isVisible();
3208 * Hides the message box if it is displayed
3211 if(this.isVisible()){
3217 * Displays a new message box, or reinitializes an existing message box, based on the config options
3218 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
3219 * The following config object properties are supported:
3221 Property Type Description
3222 ---------- --------------- ------------------------------------------------------------------------------------
3223 animEl String/Element An id or Element from which the message box should animate as it opens and
3224 closes (defaults to undefined)
3225 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
3226 cancel:'Bar'}), or false to not show any buttons (defaults to false)
3227 closable Boolean False to hide the top-right close button (defaults to true). Note that
3228 progress and wait dialogs will ignore this property and always hide the
3229 close button as they can only be closed programmatically.
3230 cls String A custom CSS class to apply to the message box element
3231 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
3232 displayed (defaults to 75)
3233 fn Function A callback function to execute after closing the dialog. The arguments to the
3234 function will be btn (the name of the button that was clicked, if applicable,
3235 e.g. "ok"), and text (the value of the active text field, if applicable).
3236 Progress and wait dialogs will ignore this option since they do not respond to
3237 user actions and can only be closed programmatically, so any required function
3238 should be called by the same code after it closes the dialog.
3239 icon String A CSS class that provides a background image to be used as an icon for
3240 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
3241 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
3242 minWidth Number The minimum width in pixels of the message box (defaults to 100)
3243 modal Boolean False to allow user interaction with the page while the message box is
3244 displayed (defaults to true)
3245 msg String A string that will replace the existing message box body text (defaults
3246 to the XHTML-compliant non-breaking space character ' ')
3247 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
3248 progress Boolean True to display a progress bar (defaults to false)
3249 progressText String The text to display inside the progress bar if progress = true (defaults to '')
3250 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
3251 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
3252 title String The title text
3253 value String The string value to set into the active textbox element if displayed
3254 wait Boolean True to display a progress bar (defaults to false)
3255 width Number The width of the dialog in pixels
3262 msg: 'Please enter your address:',
3264 buttons: Roo.MessageBox.OKCANCEL,
3267 animEl: 'addAddressBtn'
3270 * @param {Object} config Configuration options
3271 * @return {Roo.MessageBox} This message box
3273 show : function(options)
3276 // this causes nightmares if you show one dialog after another
3277 // especially on callbacks..
3279 if(this.isVisible()){
3282 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
3283 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
3284 Roo.log("New Dialog Message:" + options.msg )
3285 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
3286 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
3289 var d = this.getDialog();
3291 d.setTitle(opt.title || " ");
3292 d.closeEl.setDisplayed(opt.closable !== false);
3293 activeTextEl = textboxEl;
3294 opt.prompt = opt.prompt || (opt.multiline ? true : false);
3299 textareaEl.setHeight(typeof opt.multiline == "number" ?
3300 opt.multiline : this.defaultTextHeight);
3301 activeTextEl = textareaEl;
3310 progressEl.setDisplayed(opt.progress === true);
3311 this.updateProgress(0);
3312 activeTextEl.dom.value = opt.value || "";
3314 dlg.setDefaultButton(activeTextEl);
3316 var bs = opt.buttons;
3320 }else if(bs && bs.yes){
3321 db = buttons["yes"];
3323 dlg.setDefaultButton(db);
3325 bwidth = updateButtons(opt.buttons);
3326 this.updateText(opt.msg);
3328 d.el.addClass(opt.cls);
3330 d.proxyDrag = opt.proxyDrag === true;
3331 d.modal = opt.modal !== false;
3332 d.mask = opt.modal !== false ? mask : false;
3334 // force it to the end of the z-index stack so it gets a cursor in FF
3335 document.body.appendChild(dlg.el.dom);
3336 d.animateTarget = null;
3337 d.show(options.animEl);
3343 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
3344 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
3345 * and closing the message box when the process is complete.
3346 * @param {String} title The title bar text
3347 * @param {String} msg The message box body text
3348 * @return {Roo.MessageBox} This message box
3350 progress : function(title, msg){
3357 minWidth: this.minProgressWidth,
3364 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
3365 * If a callback function is passed it will be called after the user clicks the button, and the
3366 * id of the button that was clicked will be passed as the only parameter to the callback
3367 * (could also be the top-right close button).
3368 * @param {String} title The title bar text
3369 * @param {String} msg The message box body text
3370 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3371 * @param {Object} scope (optional) The scope of the callback function
3372 * @return {Roo.MessageBox} This message box
3374 alert : function(title, msg, fn, scope)
3389 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
3390 * interaction while waiting for a long-running process to complete that does not have defined intervals.
3391 * You are responsible for closing the message box when the process is complete.
3392 * @param {String} msg The message box body text
3393 * @param {String} title (optional) The title bar text
3394 * @return {Roo.MessageBox} This message box
3396 wait : function(msg, title){
3407 waitTimer = Roo.TaskMgr.start({
3409 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
3417 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
3418 * If a callback function is passed it will be called after the user clicks either button, and the id of the
3419 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
3420 * @param {String} title The title bar text
3421 * @param {String} msg The message box body text
3422 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3423 * @param {Object} scope (optional) The scope of the callback function
3424 * @return {Roo.MessageBox} This message box
3426 confirm : function(title, msg, fn, scope){
3430 buttons: this.YESNO,
3439 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
3440 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
3441 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
3442 * (could also be the top-right close button) and the text that was entered will be passed as the two
3443 * parameters to the callback.
3444 * @param {String} title The title bar text
3445 * @param {String} msg The message box body text
3446 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3447 * @param {Object} scope (optional) The scope of the callback function
3448 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
3449 * property, or the height in pixels to create the textbox (defaults to false / single-line)
3450 * @return {Roo.MessageBox} This message box
3452 prompt : function(title, msg, fn, scope, multiline){
3456 buttons: this.OKCANCEL,
3461 multiline: multiline,
3468 * Button config that displays a single OK button
3473 * Button config that displays Yes and No buttons
3476 YESNO : {yes:true, no:true},
3478 * Button config that displays OK and Cancel buttons
3481 OKCANCEL : {ok:true, cancel:true},
3483 * Button config that displays Yes, No and Cancel buttons
3486 YESNOCANCEL : {yes:true, no:true, cancel:true},
3489 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
3492 defaultTextHeight : 75,
3494 * The maximum width in pixels of the message box (defaults to 600)
3499 * The minimum width in pixels of the message box (defaults to 100)
3504 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
3505 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
3508 minProgressWidth : 250,
3510 * An object containing the default button text strings that can be overriden for localized language support.
3511 * Supported properties are: ok, cancel, yes and no.
3512 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
3525 * Shorthand for {@link Roo.MessageBox}
3527 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
3528 Roo.Msg = Roo.Msg || Roo.MessageBox;
3537 * @class Roo.bootstrap.Navbar
3538 * @extends Roo.bootstrap.Component
3539 * Bootstrap Navbar class
3542 * Create a new Navbar
3543 * @param {Object} config The config object
3547 Roo.bootstrap.Navbar = function(config){
3548 Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
3552 * @event beforetoggle
3553 * Fire before toggle the menu
3554 * @param {Roo.EventObject} e
3556 "beforetoggle" : true
3560 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component, {
3569 getAutoCreate : function(){
3572 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
3576 initEvents :function ()
3578 //Roo.log(this.el.select('.navbar-toggle',true));
3579 this.el.select('.navbar-toggle',true).on('click', function() {
3580 if(this.fireEvent('beforetoggle', this) !== false){
3581 this.el.select('.navbar-collapse',true).toggleClass('in');
3591 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
3593 var size = this.el.getSize();
3594 this.maskEl.setSize(size.width, size.height);
3595 this.maskEl.enableDisplayMode("block");
3604 getChildContainer : function()
3606 if (this.el.select('.collapse').getCount()) {
3607 return this.el.select('.collapse',true).first();
3640 * @class Roo.bootstrap.NavSimplebar
3641 * @extends Roo.bootstrap.Navbar
3642 * Bootstrap Sidebar class
3644 * @cfg {Boolean} inverse is inverted color
3646 * @cfg {String} type (nav | pills | tabs)
3647 * @cfg {Boolean} arrangement stacked | justified
3648 * @cfg {String} align (left | right) alignment
3650 * @cfg {Boolean} main (true|false) main nav bar? default false
3651 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
3653 * @cfg {String} tag (header|footer|nav|div) default is nav
3659 * Create a new Sidebar
3660 * @param {Object} config The config object
3664 Roo.bootstrap.NavSimplebar = function(config){
3665 Roo.bootstrap.NavSimplebar.superclass.constructor.call(this, config);
3668 Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar, {
3684 getAutoCreate : function(){
3688 tag : this.tag || 'div',
3701 this.type = this.type || 'nav';
3702 if (['tabs','pills'].indexOf(this.type)!==-1) {
3703 cfg.cn[0].cls += ' nav-' + this.type
3707 if (this.type!=='nav') {
3708 Roo.log('nav type must be nav/tabs/pills')
3710 cfg.cn[0].cls += ' navbar-nav'
3716 if (['stacked','justified'].indexOf(this.arrangement)!==-1) {
3717 cfg.cn[0].cls += ' nav-' + this.arrangement;
3721 if (this.align === 'right') {
3722 cfg.cn[0].cls += ' navbar-right';
3726 cfg.cls += ' navbar-inverse';
3753 * @class Roo.bootstrap.NavHeaderbar
3754 * @extends Roo.bootstrap.NavSimplebar
3755 * Bootstrap Sidebar class
3757 * @cfg {String} brand what is brand
3758 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
3759 * @cfg {String} brand_href href of the brand
3760 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
3761 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
3762 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
3763 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
3766 * Create a new Sidebar
3767 * @param {Object} config The config object
3771 Roo.bootstrap.NavHeaderbar = function(config){
3772 Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
3776 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar, {
3783 desktopCenter : false,
3786 getAutoCreate : function(){
3789 tag: this.nav || 'nav',
3796 if (this.desktopCenter) {
3797 cn.push({cls : 'container', cn : []});
3804 cls: 'navbar-header',
3809 cls: 'navbar-toggle',
3810 'data-toggle': 'collapse',
3815 html: 'Toggle navigation'
3837 cls: 'collapse navbar-collapse',
3841 cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
3843 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
3844 cfg.cls += ' navbar-' + this.position;
3846 // tag can override this..
3848 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
3851 if (this.brand !== '') {
3854 href: this.brand_href ? this.brand_href : '#',
3855 cls: 'navbar-brand',
3863 cfg.cls += ' main-nav';
3871 getHeaderChildContainer : function()
3873 if (this.srButton && this.el.select('.navbar-header').getCount()) {
3874 return this.el.select('.navbar-header',true).first();
3877 return this.getChildContainer();
3881 initEvents : function()
3883 Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
3885 if (this.autohide) {
3890 Roo.get(document).on('scroll',function(e) {
3891 var ns = Roo.get(document).getScroll().top;
3892 var os = prevScroll;
3896 ft.removeClass('slideDown');
3897 ft.addClass('slideUp');
3900 ft.removeClass('slideUp');
3901 ft.addClass('slideDown');
3922 * @class Roo.bootstrap.NavSidebar
3923 * @extends Roo.bootstrap.Navbar
3924 * Bootstrap Sidebar class
3927 * Create a new Sidebar
3928 * @param {Object} config The config object
3932 Roo.bootstrap.NavSidebar = function(config){
3933 Roo.bootstrap.NavSidebar.superclass.constructor.call(this, config);
3936 Roo.extend(Roo.bootstrap.NavSidebar, Roo.bootstrap.Navbar, {
3938 sidebar : true, // used by Navbar Item and NavbarGroup at present...
3940 getAutoCreate : function(){
3945 cls: 'sidebar sidebar-nav'
3967 * @class Roo.bootstrap.NavGroup
3968 * @extends Roo.bootstrap.Component
3969 * Bootstrap NavGroup class
3970 * @cfg {String} align (left|right)
3971 * @cfg {Boolean} inverse
3972 * @cfg {String} type (nav|pills|tab) default nav
3973 * @cfg {String} navId - reference Id for navbar.
3977 * Create a new nav group
3978 * @param {Object} config The config object
3981 Roo.bootstrap.NavGroup = function(config){
3982 Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
3985 Roo.bootstrap.NavGroup.register(this);
3989 * Fires when the active item changes
3990 * @param {Roo.bootstrap.NavGroup} this
3991 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
3992 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
3999 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
4010 getAutoCreate : function()
4012 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
4019 if (['tabs','pills'].indexOf(this.type)!==-1) {
4020 cfg.cls += ' nav-' + this.type
4022 if (this.type!=='nav') {
4023 Roo.log('nav type must be nav/tabs/pills')
4025 cfg.cls += ' navbar-nav'
4028 if (this.parent().sidebar) {
4031 cls: 'dashboard-menu sidebar-menu'
4037 if (this.form === true) {
4043 if (this.align === 'right') {
4044 cfg.cls += ' navbar-right';
4046 cfg.cls += ' navbar-left';
4050 if (this.align === 'right') {
4051 cfg.cls += ' navbar-right';
4055 cfg.cls += ' navbar-inverse';
4063 * sets the active Navigation item
4064 * @param {Roo.bootstrap.NavItem} the new current navitem
4066 setActiveItem : function(item)
4069 Roo.each(this.navItems, function(v){
4074 v.setActive(false, true);
4081 item.setActive(true, true);
4082 this.fireEvent('changed', this, item, prev);
4087 * gets the active Navigation item
4088 * @return {Roo.bootstrap.NavItem} the current navitem
4090 getActive : function()
4094 Roo.each(this.navItems, function(v){
4105 indexOfNav : function()
4109 Roo.each(this.navItems, function(v,i){
4120 * adds a Navigation item
4121 * @param {Roo.bootstrap.NavItem} the navitem to add
4123 addItem : function(cfg)
4125 var cn = new Roo.bootstrap.NavItem(cfg);
4127 cn.parentId = this.id;
4128 cn.onRender(this.el, null);
4132 * register a Navigation item
4133 * @param {Roo.bootstrap.NavItem} the navitem to add
4135 register : function(item)
4137 this.navItems.push( item);
4138 item.navId = this.navId;
4143 * clear all the Navigation item
4146 clearAll : function()
4149 this.el.dom.innerHTML = '';
4152 getNavItem: function(tabId)
4155 Roo.each(this.navItems, function(e) {
4156 if (e.tabId == tabId) {
4166 setActiveNext : function()
4168 var i = this.indexOfNav(this.getActive());
4169 if (i > this.navItems.length) {
4172 this.setActiveItem(this.navItems[i+1]);
4174 setActivePrev : function()
4176 var i = this.indexOfNav(this.getActive());
4180 this.setActiveItem(this.navItems[i-1]);
4182 clearWasActive : function(except) {
4183 Roo.each(this.navItems, function(e) {
4184 if (e.tabId != except.tabId && e.was_active) {
4185 e.was_active = false;
4192 getWasActive : function ()
4195 Roo.each(this.navItems, function(e) {
4210 Roo.apply(Roo.bootstrap.NavGroup, {
4214 * register a Navigation Group
4215 * @param {Roo.bootstrap.NavGroup} the navgroup to add
4217 register : function(navgrp)
4219 this.groups[navgrp.navId] = navgrp;
4223 * fetch a Navigation Group based on the navigation ID
4224 * @param {string} the navgroup to add
4225 * @returns {Roo.bootstrap.NavGroup} the navgroup
4227 get: function(navId) {
4228 if (typeof(this.groups[navId]) == 'undefined') {
4230 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
4232 return this.groups[navId] ;
4247 * @class Roo.bootstrap.NavItem
4248 * @extends Roo.bootstrap.Component
4249 * Bootstrap Navbar.NavItem class
4250 * @cfg {String} href link to
4251 * @cfg {String} html content of button
4252 * @cfg {String} badge text inside badge
4253 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
4254 * @cfg {String} glyphicon name of glyphicon
4255 * @cfg {String} icon name of font awesome icon
4256 * @cfg {Boolean} active Is item active
4257 * @cfg {Boolean} disabled Is item disabled
4259 * @cfg {Boolean} preventDefault (true | false) default false
4260 * @cfg {String} tabId the tab that this item activates.
4261 * @cfg {String} tagtype (a|span) render as a href or span?
4262 * @cfg {Boolean} animateRef (true|false) link to element default false
4265 * Create a new Navbar Item
4266 * @param {Object} config The config object
4268 Roo.bootstrap.NavItem = function(config){
4269 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
4274 * The raw click event for the entire grid.
4275 * @param {Roo.EventObject} e
4280 * Fires when the active item active state changes
4281 * @param {Roo.bootstrap.NavItem} this
4282 * @param {boolean} state the new state
4288 * Fires when scroll to element
4289 * @param {Roo.bootstrap.NavItem} this
4290 * @param {Object} options
4291 * @param {Roo.EventObject} e
4299 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
4307 preventDefault : false,
4314 getAutoCreate : function(){
4323 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
4325 if (this.disabled) {
4326 cfg.cls += ' disabled';
4329 if (this.href || this.html || this.glyphicon || this.icon) {
4333 href : this.href || "#",
4334 html: this.html || ''
4339 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
4342 if(this.glyphicon) {
4343 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
4348 cfg.cn[0].html += " <span class='caret'></span>";
4352 if (this.badge !== '') {
4354 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
4362 initEvents: function()
4364 if (typeof (this.menu) != 'undefined') {
4365 this.menu.parentType = this.xtype;
4366 this.menu.triggerEl = this.el;
4367 this.menu = this.addxtype(Roo.apply({}, this.menu));
4370 this.el.select('a',true).on('click', this.onClick, this);
4372 if(this.tagtype == 'span'){
4373 this.el.select('span',true).on('click', this.onClick, this);
4376 // at this point parent should be available..
4377 this.parent().register(this);
4380 onClick : function(e)
4382 if (e.getTarget('.dropdown-menu-item')) {
4383 // did you click on a menu itemm.... - then don't trigger onclick..
4388 this.preventDefault ||
4391 Roo.log("NavItem - prevent Default?");
4395 if (this.disabled) {
4399 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4400 if (tg && tg.transition) {
4401 Roo.log("waiting for the transitionend");
4407 //Roo.log("fire event clicked");
4408 if(this.fireEvent('click', this, e) === false){
4412 if(this.tagtype == 'span'){
4416 //Roo.log(this.href);
4417 var ael = this.el.select('a',true).first();
4420 if(ael && this.animateRef && this.href.indexOf('#') > -1){
4421 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
4422 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
4423 return; // ignore... - it's a 'hash' to another page.
4425 Roo.log("NavItem - prevent Default?");
4427 this.scrollToElement(e);
4431 var p = this.parent();
4433 if (['tabs','pills'].indexOf(p.type)!==-1) {
4434 if (typeof(p.setActiveItem) !== 'undefined') {
4435 p.setActiveItem(this);
4439 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
4440 if (p.parentType == 'NavHeaderbar' && !this.menu) {
4441 // remove the collapsed menu expand...
4442 p.parent().el.select('.navbar-collapse',true).removeClass('in');
4446 isActive: function () {
4449 setActive : function(state, fire, is_was_active)
4451 if (this.active && !state && this.navId) {
4452 this.was_active = true;
4453 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4455 nv.clearWasActive(this);
4459 this.active = state;
4462 this.el.removeClass('active');
4463 } else if (!this.el.hasClass('active')) {
4464 this.el.addClass('active');
4467 this.fireEvent('changed', this, state);
4470 // show a panel if it's registered and related..
4472 if (!this.navId || !this.tabId || !state || is_was_active) {
4476 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4480 var pan = tg.getPanelByName(this.tabId);
4484 // if we can not flip to new panel - go back to old nav highlight..
4485 if (false == tg.showPanel(pan)) {
4486 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4488 var onav = nv.getWasActive();
4490 onav.setActive(true, false, true);
4499 // this should not be here...
4500 setDisabled : function(state)
4502 this.disabled = state;
4504 this.el.removeClass('disabled');
4505 } else if (!this.el.hasClass('disabled')) {
4506 this.el.addClass('disabled');
4512 * Fetch the element to display the tooltip on.
4513 * @return {Roo.Element} defaults to this.el
4515 tooltipEl : function()
4517 return this.el.select('' + this.tagtype + '', true).first();
4520 scrollToElement : function(e)
4522 var c = document.body;
4525 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
4527 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
4528 c = document.documentElement;
4531 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
4537 var o = target.calcOffsetsTo(c);
4544 this.fireEvent('scrollto', this, options, e);
4546 Roo.get(c).scrollTo('top', options.value, true);
4559 * <span> icon </span>
4560 * <span> text </span>
4561 * <span>badge </span>
4565 * @class Roo.bootstrap.NavSidebarItem
4566 * @extends Roo.bootstrap.NavItem
4567 * Bootstrap Navbar.NavSidebarItem class
4568 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
4569 * {bool} open is the menu open
4571 * Create a new Navbar Button
4572 * @param {Object} config The config object
4574 Roo.bootstrap.NavSidebarItem = function(config){
4575 Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
4580 * The raw click event for the entire grid.
4581 * @param {Roo.EventObject} e
4586 * Fires when the active item active state changes
4587 * @param {Roo.bootstrap.NavSidebarItem} this
4588 * @param {boolean} state the new state
4596 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem, {
4598 badgeWeight : 'default',
4602 getAutoCreate : function(){
4607 href : this.href || '#',
4619 html : this.html || ''
4624 cfg.cls += ' active';
4627 if (this.disabled) {
4628 cfg.cls += ' disabled';
4631 cfg.cls += ' open x-open';
4634 if (this.glyphicon || this.icon) {
4635 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
4636 a.cn.push({ tag : 'i', cls : c }) ;
4641 if (this.badge !== '') {
4643 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
4647 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
4648 a.cls += 'dropdown-toggle treeview' ;
4656 initEvents : function()
4658 if (typeof (this.menu) != 'undefined') {
4659 this.menu.parentType = this.xtype;
4660 this.menu.triggerEl = this.el;
4661 this.menu = this.addxtype(Roo.apply({}, this.menu));
4664 this.el.on('click', this.onClick, this);
4667 if(this.badge !== ''){
4669 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
4674 onClick : function(e)
4681 if(this.preventDefault){
4685 this.fireEvent('click', this);
4688 disable : function()
4690 this.setDisabled(true);
4695 this.setDisabled(false);
4698 setDisabled : function(state)
4700 if(this.disabled == state){
4704 this.disabled = state;
4707 this.el.addClass('disabled');
4711 this.el.removeClass('disabled');
4716 setActive : function(state)
4718 if(this.active == state){
4722 this.active = state;
4725 this.el.addClass('active');
4729 this.el.removeClass('active');
4734 isActive: function ()
4739 setBadge : function(str)
4745 this.badgeEl.dom.innerHTML = str;
4762 * @class Roo.bootstrap.Row
4763 * @extends Roo.bootstrap.Component
4764 * Bootstrap Row class (contains columns...)
4768 * @param {Object} config The config object
4771 Roo.bootstrap.Row = function(config){
4772 Roo.bootstrap.Row.superclass.constructor.call(this, config);
4775 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
4777 getAutoCreate : function(){
4796 * @class Roo.bootstrap.Element
4797 * @extends Roo.bootstrap.Component
4798 * Bootstrap Element class
4799 * @cfg {String} html contents of the element
4800 * @cfg {String} tag tag of the element
4801 * @cfg {String} cls class of the element
4802 * @cfg {Boolean} preventDefault (true|false) default false
4803 * @cfg {Boolean} clickable (true|false) default false
4806 * Create a new Element
4807 * @param {Object} config The config object
4810 Roo.bootstrap.Element = function(config){
4811 Roo.bootstrap.Element.superclass.constructor.call(this, config);
4817 * When a element is chick
4818 * @param {Roo.bootstrap.Element} this
4819 * @param {Roo.EventObject} e
4825 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
4830 preventDefault: false,
4833 getAutoCreate : function(){
4844 initEvents: function()
4846 Roo.bootstrap.Element.superclass.initEvents.call(this);
4849 this.el.on('click', this.onClick, this);
4854 onClick : function(e)
4856 if(this.preventDefault){
4860 this.fireEvent('click', this, e);
4863 getValue : function()
4865 return this.el.dom.innerHTML;
4868 setValue : function(value)
4870 this.el.dom.innerHTML = value;
4885 * @class Roo.bootstrap.Pagination
4886 * @extends Roo.bootstrap.Component
4887 * Bootstrap Pagination class
4888 * @cfg {String} size xs | sm | md | lg
4889 * @cfg {Boolean} inverse false | true
4892 * Create a new Pagination
4893 * @param {Object} config The config object
4896 Roo.bootstrap.Pagination = function(config){
4897 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
4900 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
4906 getAutoCreate : function(){
4912 cfg.cls += ' inverse';
4918 cfg.cls += " " + this.cls;
4936 * @class Roo.bootstrap.PaginationItem
4937 * @extends Roo.bootstrap.Component
4938 * Bootstrap PaginationItem class
4939 * @cfg {String} html text
4940 * @cfg {String} href the link
4941 * @cfg {Boolean} preventDefault (true | false) default true
4942 * @cfg {Boolean} active (true | false) default false
4943 * @cfg {Boolean} disabled default false
4947 * Create a new PaginationItem
4948 * @param {Object} config The config object
4952 Roo.bootstrap.PaginationItem = function(config){
4953 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
4958 * The raw click event for the entire grid.
4959 * @param {Roo.EventObject} e
4965 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
4969 preventDefault: true,
4974 getAutoCreate : function(){
4980 href : this.href ? this.href : '#',
4981 html : this.html ? this.html : ''
4991 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
4995 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
5001 initEvents: function() {
5003 this.el.on('click', this.onClick, this);
5006 onClick : function(e)
5008 Roo.log('PaginationItem on click ');
5009 if(this.preventDefault){
5017 this.fireEvent('click', this, e);
5033 * @class Roo.bootstrap.Slider
5034 * @extends Roo.bootstrap.Component
5035 * Bootstrap Slider class
5038 * Create a new Slider
5039 * @param {Object} config The config object
5042 Roo.bootstrap.Slider = function(config){
5043 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
5046 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
5048 getAutoCreate : function(){
5052 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
5056 cls: 'ui-slider-handle ui-state-default ui-corner-all'
5068 * Ext JS Library 1.1.1
5069 * Copyright(c) 2006-2007, Ext JS, LLC.
5071 * Originally Released Under LGPL - original licence link has changed is not relivant.
5074 * <script type="text/javascript">
5079 * @class Roo.grid.ColumnModel
5080 * @extends Roo.util.Observable
5081 * This is the default implementation of a ColumnModel used by the Grid. It defines
5082 * the columns in the grid.
5085 var colModel = new Roo.grid.ColumnModel([
5086 {header: "Ticker", width: 60, sortable: true, locked: true},
5087 {header: "Company Name", width: 150, sortable: true},
5088 {header: "Market Cap.", width: 100, sortable: true},
5089 {header: "$ Sales", width: 100, sortable: true, renderer: money},
5090 {header: "Employees", width: 100, sortable: true, resizable: false}
5095 * The config options listed for this class are options which may appear in each
5096 * individual column definition.
5097 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
5099 * @param {Object} config An Array of column config objects. See this class's
5100 * config objects for details.
5102 Roo.grid.ColumnModel = function(config){
5104 * The config passed into the constructor
5106 this.config = config;
5109 // if no id, create one
5110 // if the column does not have a dataIndex mapping,
5111 // map it to the order it is in the config
5112 for(var i = 0, len = config.length; i < len; i++){
5114 if(typeof c.dataIndex == "undefined"){
5117 if(typeof c.renderer == "string"){
5118 c.renderer = Roo.util.Format[c.renderer];
5120 if(typeof c.id == "undefined"){
5123 if(c.editor && c.editor.xtype){
5124 c.editor = Roo.factory(c.editor, Roo.grid);
5126 if(c.editor && c.editor.isFormField){
5127 c.editor = new Roo.grid.GridEditor(c.editor);
5129 this.lookup[c.id] = c;
5133 * The width of columns which have no width specified (defaults to 100)
5136 this.defaultWidth = 100;
5139 * Default sortable of columns which have no sortable specified (defaults to false)
5142 this.defaultSortable = false;
5146 * @event widthchange
5147 * Fires when the width of a column changes.
5148 * @param {ColumnModel} this
5149 * @param {Number} columnIndex The column index
5150 * @param {Number} newWidth The new width
5152 "widthchange": true,
5154 * @event headerchange
5155 * Fires when the text of a header changes.
5156 * @param {ColumnModel} this
5157 * @param {Number} columnIndex The column index
5158 * @param {Number} newText The new header text
5160 "headerchange": true,
5162 * @event hiddenchange
5163 * Fires when a column is hidden or "unhidden".
5164 * @param {ColumnModel} this
5165 * @param {Number} columnIndex The column index
5166 * @param {Boolean} hidden true if hidden, false otherwise
5168 "hiddenchange": true,
5170 * @event columnmoved
5171 * Fires when a column is moved.
5172 * @param {ColumnModel} this
5173 * @param {Number} oldIndex
5174 * @param {Number} newIndex
5176 "columnmoved" : true,
5178 * @event columlockchange
5179 * Fires when a column's locked state is changed
5180 * @param {ColumnModel} this
5181 * @param {Number} colIndex
5182 * @param {Boolean} locked true if locked
5184 "columnlockchange" : true
5186 Roo.grid.ColumnModel.superclass.constructor.call(this);
5188 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
5190 * @cfg {String} header The header text to display in the Grid view.
5193 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
5194 * {@link Roo.data.Record} definition from which to draw the column's value. If not
5195 * specified, the column's index is used as an index into the Record's data Array.
5198 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
5199 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
5202 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
5203 * Defaults to the value of the {@link #defaultSortable} property.
5204 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
5207 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
5210 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
5213 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
5216 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
5219 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
5220 * given the cell's data value. See {@link #setRenderer}. If not specified, the
5221 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
5222 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
5225 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
5228 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
5231 * @cfg {String} cursor (Optional)
5234 * @cfg {String} tooltip (Optional)
5237 * @cfg {Number} xs (Optional)
5240 * @cfg {Number} sm (Optional)
5243 * @cfg {Number} md (Optional)
5246 * @cfg {Number} lg (Optional)
5249 * Returns the id of the column at the specified index.
5250 * @param {Number} index The column index
5251 * @return {String} the id
5253 getColumnId : function(index){
5254 return this.config[index].id;
5258 * Returns the column for a specified id.
5259 * @param {String} id The column id
5260 * @return {Object} the column
5262 getColumnById : function(id){
5263 return this.lookup[id];
5268 * Returns the column for a specified dataIndex.
5269 * @param {String} dataIndex The column dataIndex
5270 * @return {Object|Boolean} the column or false if not found
5272 getColumnByDataIndex: function(dataIndex){
5273 var index = this.findColumnIndex(dataIndex);
5274 return index > -1 ? this.config[index] : false;
5278 * Returns the index for a specified column id.
5279 * @param {String} id The column id
5280 * @return {Number} the index, or -1 if not found
5282 getIndexById : function(id){
5283 for(var i = 0, len = this.config.length; i < len; i++){
5284 if(this.config[i].id == id){
5292 * Returns the index for a specified column dataIndex.
5293 * @param {String} dataIndex The column dataIndex
5294 * @return {Number} the index, or -1 if not found
5297 findColumnIndex : function(dataIndex){
5298 for(var i = 0, len = this.config.length; i < len; i++){
5299 if(this.config[i].dataIndex == dataIndex){
5307 moveColumn : function(oldIndex, newIndex){
5308 var c = this.config[oldIndex];
5309 this.config.splice(oldIndex, 1);
5310 this.config.splice(newIndex, 0, c);
5311 this.dataMap = null;
5312 this.fireEvent("columnmoved", this, oldIndex, newIndex);
5315 isLocked : function(colIndex){
5316 return this.config[colIndex].locked === true;
5319 setLocked : function(colIndex, value, suppressEvent){
5320 if(this.isLocked(colIndex) == value){
5323 this.config[colIndex].locked = value;
5325 this.fireEvent("columnlockchange", this, colIndex, value);
5329 getTotalLockedWidth : function(){
5331 for(var i = 0; i < this.config.length; i++){
5332 if(this.isLocked(i) && !this.isHidden(i)){
5333 this.totalWidth += this.getColumnWidth(i);
5339 getLockedCount : function(){
5340 for(var i = 0, len = this.config.length; i < len; i++){
5341 if(!this.isLocked(i)){
5346 return this.config.length;
5350 * Returns the number of columns.
5353 getColumnCount : function(visibleOnly){
5354 if(visibleOnly === true){
5356 for(var i = 0, len = this.config.length; i < len; i++){
5357 if(!this.isHidden(i)){
5363 return this.config.length;
5367 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
5368 * @param {Function} fn
5369 * @param {Object} scope (optional)
5370 * @return {Array} result
5372 getColumnsBy : function(fn, scope){
5374 for(var i = 0, len = this.config.length; i < len; i++){
5375 var c = this.config[i];
5376 if(fn.call(scope||this, c, i) === true){
5384 * Returns true if the specified column is sortable.
5385 * @param {Number} col The column index
5388 isSortable : function(col){
5389 if(typeof this.config[col].sortable == "undefined"){
5390 return this.defaultSortable;
5392 return this.config[col].sortable;
5396 * Returns the rendering (formatting) function defined for the column.
5397 * @param {Number} col The column index.
5398 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5400 getRenderer : function(col){
5401 if(!this.config[col].renderer){
5402 return Roo.grid.ColumnModel.defaultRenderer;
5404 return this.config[col].renderer;
5408 * Sets the rendering (formatting) function for a column.
5409 * @param {Number} col The column index
5410 * @param {Function} fn The function to use to process the cell's raw data
5411 * to return HTML markup for the grid view. The render function is called with
5412 * the following parameters:<ul>
5413 * <li>Data value.</li>
5414 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
5415 * <li>css A CSS style string to apply to the table cell.</li>
5416 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
5417 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
5418 * <li>Row index</li>
5419 * <li>Column index</li>
5420 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
5422 setRenderer : function(col, fn){
5423 this.config[col].renderer = fn;
5427 * Returns the width for the specified column.
5428 * @param {Number} col The column index
5431 getColumnWidth : function(col){
5432 return this.config[col].width * 1 || this.defaultWidth;
5436 * Sets the width for a column.
5437 * @param {Number} col The column index
5438 * @param {Number} width The new width
5440 setColumnWidth : function(col, width, suppressEvent){
5441 this.config[col].width = width;
5442 this.totalWidth = null;
5444 this.fireEvent("widthchange", this, col, width);
5449 * Returns the total width of all columns.
5450 * @param {Boolean} includeHidden True to include hidden column widths
5453 getTotalWidth : function(includeHidden){
5454 if(!this.totalWidth){
5455 this.totalWidth = 0;
5456 for(var i = 0, len = this.config.length; i < len; i++){
5457 if(includeHidden || !this.isHidden(i)){
5458 this.totalWidth += this.getColumnWidth(i);
5462 return this.totalWidth;
5466 * Returns the header for the specified column.
5467 * @param {Number} col The column index
5470 getColumnHeader : function(col){
5471 return this.config[col].header;
5475 * Sets the header for a column.
5476 * @param {Number} col The column index
5477 * @param {String} header The new header
5479 setColumnHeader : function(col, header){
5480 this.config[col].header = header;
5481 this.fireEvent("headerchange", this, col, header);
5485 * Returns the tooltip for the specified column.
5486 * @param {Number} col The column index
5489 getColumnTooltip : function(col){
5490 return this.config[col].tooltip;
5493 * Sets the tooltip for a column.
5494 * @param {Number} col The column index
5495 * @param {String} tooltip The new tooltip
5497 setColumnTooltip : function(col, tooltip){
5498 this.config[col].tooltip = tooltip;
5502 * Returns the dataIndex for the specified column.
5503 * @param {Number} col The column index
5506 getDataIndex : function(col){
5507 return this.config[col].dataIndex;
5511 * Sets the dataIndex for a column.
5512 * @param {Number} col The column index
5513 * @param {Number} dataIndex The new dataIndex
5515 setDataIndex : function(col, dataIndex){
5516 this.config[col].dataIndex = dataIndex;
5522 * Returns true if the cell is editable.
5523 * @param {Number} colIndex The column index
5524 * @param {Number} rowIndex The row index - this is nto actually used..?
5527 isCellEditable : function(colIndex, rowIndex){
5528 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
5532 * Returns the editor defined for the cell/column.
5533 * return false or null to disable editing.
5534 * @param {Number} colIndex The column index
5535 * @param {Number} rowIndex The row index
5538 getCellEditor : function(colIndex, rowIndex){
5539 return this.config[colIndex].editor;
5543 * Sets if a column is editable.
5544 * @param {Number} col The column index
5545 * @param {Boolean} editable True if the column is editable
5547 setEditable : function(col, editable){
5548 this.config[col].editable = editable;
5553 * Returns true if the column is hidden.
5554 * @param {Number} colIndex The column index
5557 isHidden : function(colIndex){
5558 return this.config[colIndex].hidden;
5563 * Returns true if the column width cannot be changed
5565 isFixed : function(colIndex){
5566 return this.config[colIndex].fixed;
5570 * Returns true if the column can be resized
5573 isResizable : function(colIndex){
5574 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5577 * Sets if a column is hidden.
5578 * @param {Number} colIndex The column index
5579 * @param {Boolean} hidden True if the column is hidden
5581 setHidden : function(colIndex, hidden){
5582 this.config[colIndex].hidden = hidden;
5583 this.totalWidth = null;
5584 this.fireEvent("hiddenchange", this, colIndex, hidden);
5588 * Sets the editor for a column.
5589 * @param {Number} col The column index
5590 * @param {Object} editor The editor object
5592 setEditor : function(col, editor){
5593 this.config[col].editor = editor;
5597 Roo.grid.ColumnModel.defaultRenderer = function(value)
5599 if(typeof value == "object") {
5602 if(typeof value == "string" && value.length < 1){
5606 return String.format("{0}", value);
5609 // Alias for backwards compatibility
5610 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
5613 * Ext JS Library 1.1.1
5614 * Copyright(c) 2006-2007, Ext JS, LLC.
5616 * Originally Released Under LGPL - original licence link has changed is not relivant.
5619 * <script type="text/javascript">
5623 * @class Roo.LoadMask
5624 * A simple utility class for generically masking elements while loading data. If the element being masked has
5625 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
5626 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
5627 * element's UpdateManager load indicator and will be destroyed after the initial load.
5629 * Create a new LoadMask
5630 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
5631 * @param {Object} config The config object
5633 Roo.LoadMask = function(el, config){
5634 this.el = Roo.get(el);
5635 Roo.apply(this, config);
5637 this.store.on('beforeload', this.onBeforeLoad, this);
5638 this.store.on('load', this.onLoad, this);
5639 this.store.on('loadexception', this.onLoadException, this);
5640 this.removeMask = false;
5642 var um = this.el.getUpdateManager();
5643 um.showLoadIndicator = false; // disable the default indicator
5644 um.on('beforeupdate', this.onBeforeLoad, this);
5645 um.on('update', this.onLoad, this);
5646 um.on('failure', this.onLoad, this);
5647 this.removeMask = true;
5651 Roo.LoadMask.prototype = {
5653 * @cfg {Boolean} removeMask
5654 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
5655 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
5659 * The text to display in a centered loading message box (defaults to 'Loading...')
5663 * @cfg {String} msgCls
5664 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
5666 msgCls : 'x-mask-loading',
5669 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
5675 * Disables the mask to prevent it from being displayed
5677 disable : function(){
5678 this.disabled = true;
5682 * Enables the mask so that it can be displayed
5684 enable : function(){
5685 this.disabled = false;
5688 onLoadException : function()
5692 if (typeof(arguments[3]) != 'undefined') {
5693 Roo.MessageBox.alert("Error loading",arguments[3]);
5697 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
5698 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
5705 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5710 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5714 onBeforeLoad : function(){
5716 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
5721 destroy : function(){
5723 this.store.un('beforeload', this.onBeforeLoad, this);
5724 this.store.un('load', this.onLoad, this);
5725 this.store.un('loadexception', this.onLoadException, this);
5727 var um = this.el.getUpdateManager();
5728 um.un('beforeupdate', this.onBeforeLoad, this);
5729 um.un('update', this.onLoad, this);
5730 um.un('failure', this.onLoad, this);
5741 * @class Roo.bootstrap.Table
5742 * @extends Roo.bootstrap.Component
5743 * Bootstrap Table class
5744 * @cfg {String} cls table class
5745 * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
5746 * @cfg {String} bgcolor Specifies the background color for a table
5747 * @cfg {Number} border Specifies whether the table cells should have borders or not
5748 * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
5749 * @cfg {Number} cellspacing Specifies the space between cells
5750 * @cfg {String} frame Specifies which parts of the outside borders that should be visible
5751 * @cfg {String} rules Specifies which parts of the inside borders that should be visible
5752 * @cfg {String} sortable Specifies that the table should be sortable
5753 * @cfg {String} summary Specifies a summary of the content of a table
5754 * @cfg {Number} width Specifies the width of a table
5755 * @cfg {String} layout table layout (auto | fixed | initial | inherit)
5757 * @cfg {boolean} striped Should the rows be alternative striped
5758 * @cfg {boolean} bordered Add borders to the table
5759 * @cfg {boolean} hover Add hover highlighting
5760 * @cfg {boolean} condensed Format condensed
5761 * @cfg {boolean} responsive Format condensed
5762 * @cfg {Boolean} loadMask (true|false) default false
5763 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
5764 * @cfg {Boolean} headerShow (true|false) generate thead, default true
5765 * @cfg {Boolean} rowSelection (true|false) default false
5766 * @cfg {Boolean} cellSelection (true|false) default false
5767 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
5768 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
5769 * @cfg {Boolean} lazyLoad auto load data while scrolling to the end (default false)
5773 * Create a new Table
5774 * @param {Object} config The config object
5777 Roo.bootstrap.Table = function(config){
5778 Roo.bootstrap.Table.superclass.constructor.call(this, config);
5783 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
5784 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
5785 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
5786 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
5788 this.sm = this.sm || {xtype: 'RowSelectionModel'};
5790 this.sm.grid = this;
5791 this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
5792 this.sm = this.selModel;
5793 this.sm.xmodule = this.xmodule || false;
5796 if (this.cm && typeof(this.cm.config) == 'undefined') {
5797 this.colModel = new Roo.grid.ColumnModel(this.cm);
5798 this.cm = this.colModel;
5799 this.cm.xmodule = this.xmodule || false;
5802 this.store= Roo.factory(this.store, Roo.data);
5803 this.ds = this.store;
5804 this.ds.xmodule = this.xmodule || false;
5807 if (this.footer && this.store) {
5808 this.footer.dataSource = this.ds;
5809 this.footer = Roo.factory(this.footer);
5816 * Fires when a cell is clicked
5817 * @param {Roo.bootstrap.Table} this
5818 * @param {Roo.Element} el
5819 * @param {Number} rowIndex
5820 * @param {Number} columnIndex
5821 * @param {Roo.EventObject} e
5825 * @event celldblclick
5826 * Fires when a cell is double clicked
5827 * @param {Roo.bootstrap.Table} this
5828 * @param {Roo.Element} el
5829 * @param {Number} rowIndex
5830 * @param {Number} columnIndex
5831 * @param {Roo.EventObject} e
5833 "celldblclick" : true,
5836 * Fires when a row is clicked
5837 * @param {Roo.bootstrap.Table} this
5838 * @param {Roo.Element} el
5839 * @param {Number} rowIndex
5840 * @param {Roo.EventObject} e
5844 * @event rowdblclick
5845 * Fires when a row is double clicked
5846 * @param {Roo.bootstrap.Table} this
5847 * @param {Roo.Element} el
5848 * @param {Number} rowIndex
5849 * @param {Roo.EventObject} e
5851 "rowdblclick" : true,
5854 * Fires when a mouseover occur
5855 * @param {Roo.bootstrap.Table} this
5856 * @param {Roo.Element} el
5857 * @param {Number} rowIndex
5858 * @param {Number} columnIndex
5859 * @param {Roo.EventObject} e
5864 * Fires when a mouseout occur
5865 * @param {Roo.bootstrap.Table} this
5866 * @param {Roo.Element} el
5867 * @param {Number} rowIndex
5868 * @param {Number} columnIndex
5869 * @param {Roo.EventObject} e
5874 * Fires when a row is rendered, so you can change add a style to it.
5875 * @param {Roo.bootstrap.Table} this
5876 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
5880 * @event rowsrendered
5881 * Fires when all the rows have been rendered
5882 * @param {Roo.bootstrap.Table} this
5884 'rowsrendered' : true,
5886 * @event contextmenu
5887 * The raw contextmenu event for the entire grid.
5888 * @param {Roo.EventObject} e
5890 "contextmenu" : true,
5892 * @event rowcontextmenu
5893 * Fires when a row is right clicked
5894 * @param {Roo.bootstrap.Table} this
5895 * @param {Number} rowIndex
5896 * @param {Roo.EventObject} e
5898 "rowcontextmenu" : true,
5900 * @event cellcontextmenu
5901 * Fires when a cell is right clicked
5902 * @param {Roo.bootstrap.Table} this
5903 * @param {Number} rowIndex
5904 * @param {Number} cellIndex
5905 * @param {Roo.EventObject} e
5907 "cellcontextmenu" : true,
5909 * @event headercontextmenu
5910 * Fires when a header is right clicked
5911 * @param {Roo.bootstrap.Table} this
5912 * @param {Number} columnIndex
5913 * @param {Roo.EventObject} e
5915 "headercontextmenu" : true
5919 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
5945 rowSelection : false,
5946 cellSelection : false,
5949 // Roo.Element - the tbody
5951 // Roo.Element - thead element
5954 container: false, // used by gridpanel...
5958 getAutoCreate : function()
5960 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
5967 if (this.scrollBody) {
5968 cfg.cls += ' table-body-fixed';
5971 cfg.cls += ' table-striped';
5975 cfg.cls += ' table-hover';
5977 if (this.bordered) {
5978 cfg.cls += ' table-bordered';
5980 if (this.condensed) {
5981 cfg.cls += ' table-condensed';
5983 if (this.responsive) {
5984 cfg.cls += ' table-responsive';
5988 cfg.cls+= ' ' +this.cls;
5991 // this lot should be simplifed...
5994 cfg.align=this.align;
5997 cfg.bgcolor=this.bgcolor;
6000 cfg.border=this.border;
6002 if (this.cellpadding) {
6003 cfg.cellpadding=this.cellpadding;
6005 if (this.cellspacing) {
6006 cfg.cellspacing=this.cellspacing;
6009 cfg.frame=this.frame;
6012 cfg.rules=this.rules;
6014 if (this.sortable) {
6015 cfg.sortable=this.sortable;
6018 cfg.summary=this.summary;
6021 cfg.width=this.width;
6024 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
6027 if(this.store || this.cm){
6028 if(this.headerShow){
6029 cfg.cn.push(this.renderHeader());
6032 cfg.cn.push(this.renderBody());
6034 if(this.footerShow){
6035 cfg.cn.push(this.renderFooter());
6037 // where does this come from?
6038 //cfg.cls+= ' TableGrid';
6041 return { cn : [ cfg ] };
6044 initEvents : function()
6046 if(!this.store || !this.cm){
6049 if (this.selModel) {
6050 this.selModel.initEvents();
6054 //Roo.log('initEvents with ds!!!!');
6056 this.mainBody = this.el.select('tbody', true).first();
6057 this.mainHead = this.el.select('thead', true).first();
6064 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6065 e.on('click', _this.sort, _this);
6068 this.mainBody.on("click", this.onClick, this);
6069 this.mainBody.on("dblclick", this.onDblClick, this);
6071 // why is this done????? = it breaks dialogs??
6072 //this.parent().el.setStyle('position', 'relative');
6076 this.footer.parentId = this.id;
6077 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
6080 this.el.select('tfoot tr td').first().addClass('hide');
6084 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
6086 this.store.on('load', this.onLoad, this);
6087 this.store.on('beforeload', this.onBeforeLoad, this);
6088 this.store.on('update', this.onUpdate, this);
6089 this.store.on('add', this.onAdd, this);
6090 this.store.on("clear", this.clear, this);
6092 this.el.on("contextmenu", this.onContextMenu, this);
6094 this.mainBody.on('scroll', this.onBodyScroll, this);
6099 onContextMenu : function(e, t)
6101 this.processEvent("contextmenu", e);
6104 processEvent : function(name, e)
6106 if (name != 'touchstart' ) {
6107 this.fireEvent(name, e);
6110 var t = e.getTarget();
6112 var cell = Roo.get(t);
6118 if(cell.findParent('tfoot', false, true)){
6122 if(cell.findParent('thead', false, true)){
6124 if(e.getTarget().nodeName.toLowerCase() != 'th'){
6125 cell = Roo.get(t).findParent('th', false, true);
6127 Roo.log("failed to find th in thead?");
6128 Roo.log(e.getTarget());
6133 var cellIndex = cell.dom.cellIndex;
6135 var ename = name == 'touchstart' ? 'click' : name;
6136 this.fireEvent("header" + ename, this, cellIndex, e);
6141 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6142 cell = Roo.get(t).findParent('td', false, true);
6144 Roo.log("failed to find th in tbody?");
6145 Roo.log(e.getTarget());
6150 var row = cell.findParent('tr', false, true);
6151 var cellIndex = cell.dom.cellIndex;
6152 var rowIndex = row.dom.rowIndex - 1;
6156 this.fireEvent("row" + name, this, rowIndex, e);
6160 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
6166 onMouseover : function(e, el)
6168 var cell = Roo.get(el);
6174 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6175 cell = cell.findParent('td', false, true);
6178 var row = cell.findParent('tr', false, true);
6179 var cellIndex = cell.dom.cellIndex;
6180 var rowIndex = row.dom.rowIndex - 1; // start from 0
6182 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
6186 onMouseout : function(e, el)
6188 var cell = Roo.get(el);
6194 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6195 cell = cell.findParent('td', false, true);
6198 var row = cell.findParent('tr', false, true);
6199 var cellIndex = cell.dom.cellIndex;
6200 var rowIndex = row.dom.rowIndex - 1; // start from 0
6202 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
6206 onClick : function(e, el)
6208 var cell = Roo.get(el);
6210 if(!cell || (!this.cellSelection && !this.rowSelection)){
6214 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6215 cell = cell.findParent('td', false, true);
6218 if(!cell || typeof(cell) == 'undefined'){
6222 var row = cell.findParent('tr', false, true);
6224 if(!row || typeof(row) == 'undefined'){
6228 var cellIndex = cell.dom.cellIndex;
6229 var rowIndex = this.getRowIndex(row);
6231 // why??? - should these not be based on SelectionModel?
6232 if(this.cellSelection){
6233 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
6236 if(this.rowSelection){
6237 this.fireEvent('rowclick', this, row, rowIndex, e);
6243 onDblClick : function(e,el)
6245 var cell = Roo.get(el);
6247 if(!cell || (!this.cellSelection && !this.rowSelection)){
6251 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6252 cell = cell.findParent('td', false, true);
6255 if(!cell || typeof(cell) == 'undefined'){
6259 var row = cell.findParent('tr', false, true);
6261 if(!row || typeof(row) == 'undefined'){
6265 var cellIndex = cell.dom.cellIndex;
6266 var rowIndex = this.getRowIndex(row);
6268 if(this.cellSelection){
6269 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
6272 if(this.rowSelection){
6273 this.fireEvent('rowdblclick', this, row, rowIndex, e);
6277 sort : function(e,el)
6279 var col = Roo.get(el);
6281 if(!col.hasClass('sortable')){
6285 var sort = col.attr('sort');
6288 if(col.select('i', true).first().hasClass('glyphicon-arrow-up')){
6292 this.store.sortInfo = {field : sort, direction : dir};
6295 Roo.log("calling footer first");
6296 this.footer.onClick('first');
6299 this.store.load({ params : { start : 0 } });
6303 renderHeader : function()
6311 this.totalWidth = 0;
6313 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6315 var config = cm.config[i];
6320 html: cm.getColumnHeader(i)
6325 if(typeof(config.sortable) != 'undefined' && config.sortable){
6327 c.html = '<i class="glyphicon"></i>' + c.html;
6330 if(typeof(config.lgHeader) != 'undefined'){
6331 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
6334 if(typeof(config.mdHeader) != 'undefined'){
6335 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
6338 if(typeof(config.smHeader) != 'undefined'){
6339 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
6342 if(typeof(config.xsHeader) != 'undefined'){
6343 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
6350 if(typeof(config.tooltip) != 'undefined'){
6351 c.tooltip = config.tooltip;
6354 if(typeof(config.colspan) != 'undefined'){
6355 c.colspan = config.colspan;
6358 if(typeof(config.hidden) != 'undefined' && config.hidden){
6359 c.style += ' display:none;';
6362 if(typeof(config.dataIndex) != 'undefined'){
6363 c.sort = config.dataIndex;
6368 if(typeof(config.align) != 'undefined' && config.align.length){
6369 c.style += ' text-align:' + config.align + ';';
6372 if(typeof(config.width) != 'undefined'){
6373 c.style += ' width:' + config.width + 'px;';
6374 this.totalWidth += config.width;
6376 this.totalWidth += 100; // assume minimum of 100 per column?
6379 if(typeof(config.cls) != 'undefined'){
6380 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
6383 ['xs','sm','md','lg'].map(function(size){
6385 if(typeof(config[size]) == 'undefined'){
6389 if (!config[size]) { // 0 = hidden
6390 c.cls += ' hidden-' + size;
6394 c.cls += ' col-' + size + '-' + config[size];
6404 renderBody : function()
6414 colspan : this.cm.getColumnCount()
6424 renderFooter : function()
6434 colspan : this.cm.getColumnCount()
6448 // Roo.log('ds onload');
6453 var ds = this.store;
6455 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6456 e.select('i', true).removeClass(['glyphicon-arrow-up', 'glyphicon-arrow-down']);
6457 if (_this.store.sortInfo) {
6459 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
6460 e.select('i', true).addClass(['glyphicon-arrow-up']);
6463 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
6464 e.select('i', true).addClass(['glyphicon-arrow-down']);
6469 var tbody = this.mainBody;
6471 if(ds.getCount() > 0){
6472 ds.data.each(function(d,rowIndex){
6473 var row = this.renderRow(cm, ds, rowIndex);
6475 tbody.createChild(row);
6479 if(row.cellObjects.length){
6480 Roo.each(row.cellObjects, function(r){
6481 _this.renderCellObject(r);
6488 Roo.each(this.el.select('tbody td', true).elements, function(e){
6489 e.on('mouseover', _this.onMouseover, _this);
6492 Roo.each(this.el.select('tbody td', true).elements, function(e){
6493 e.on('mouseout', _this.onMouseout, _this);
6495 this.fireEvent('rowsrendered', this);
6496 //if(this.loadMask){
6497 // this.maskEl.hide();
6504 onUpdate : function(ds,record)
6506 this.refreshRow(record);
6510 onRemove : function(ds, record, index, isUpdate){
6511 if(isUpdate !== true){
6512 this.fireEvent("beforerowremoved", this, index, record);
6514 var bt = this.mainBody.dom;
6516 var rows = this.el.select('tbody > tr', true).elements;
6518 if(typeof(rows[index]) != 'undefined'){
6519 bt.removeChild(rows[index].dom);
6522 // if(bt.rows[index]){
6523 // bt.removeChild(bt.rows[index]);
6526 if(isUpdate !== true){
6527 //this.stripeRows(index);
6528 //this.syncRowHeights(index, index);
6530 this.fireEvent("rowremoved", this, index, record);
6534 onAdd : function(ds, records, rowIndex)
6536 //Roo.log('on Add called');
6537 // - note this does not handle multiple adding very well..
6538 var bt = this.mainBody.dom;
6539 for (var i =0 ; i < records.length;i++) {
6540 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
6541 //Roo.log(records[i]);
6542 //Roo.log(this.store.getAt(rowIndex+i));
6543 this.insertRow(this.store, rowIndex + i, false);
6550 refreshRow : function(record){
6551 var ds = this.store, index;
6552 if(typeof record == 'number'){
6554 record = ds.getAt(index);
6556 index = ds.indexOf(record);
6558 this.insertRow(ds, index, true);
6560 this.onRemove(ds, record, index+1, true);
6562 //this.syncRowHeights(index, index);
6564 this.fireEvent("rowupdated", this, index, record);
6567 insertRow : function(dm, rowIndex, isUpdate){
6570 this.fireEvent("beforerowsinserted", this, rowIndex);
6572 //var s = this.getScrollState();
6573 var row = this.renderRow(this.cm, this.store, rowIndex);
6574 // insert before rowIndex..
6575 var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
6579 if(row.cellObjects.length){
6580 Roo.each(row.cellObjects, function(r){
6581 _this.renderCellObject(r);
6586 this.fireEvent("rowsinserted", this, rowIndex);
6587 //this.syncRowHeights(firstRow, lastRow);
6588 //this.stripeRows(firstRow);
6595 getRowDom : function(rowIndex)
6597 var rows = this.el.select('tbody > tr', true).elements;
6599 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
6602 // returns the object tree for a tr..
6605 renderRow : function(cm, ds, rowIndex)
6608 var d = ds.getAt(rowIndex);
6615 var cellObjects = [];
6617 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6618 var config = cm.config[i];
6620 var renderer = cm.getRenderer(i);
6624 if(typeof(renderer) !== 'undefined'){
6625 value = renderer(d.data[cm.getDataIndex(i)], false, d);
6627 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
6628 // and are rendered into the cells after the row is rendered - using the id for the element.
6630 if(typeof(value) === 'object'){
6640 rowIndex : rowIndex,
6645 this.fireEvent('rowclass', this, rowcfg);
6649 cls : rowcfg.rowClass,
6651 html: (typeof(value) === 'object') ? '' : value
6658 if(typeof(config.colspan) != 'undefined'){
6659 td.colspan = config.colspan;
6662 if(typeof(config.hidden) != 'undefined' && config.hidden){
6663 td.style += ' display:none;';
6666 if(typeof(config.align) != 'undefined' && config.align.length){
6667 td.style += ' text-align:' + config.align + ';';
6670 if(typeof(config.width) != 'undefined'){
6671 td.style += ' width:' + config.width + 'px;';
6674 if(typeof(config.cursor) != 'undefined'){
6675 td.style += ' cursor:' + config.cursor + ';';
6678 if(typeof(config.cls) != 'undefined'){
6679 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
6682 ['xs','sm','md','lg'].map(function(size){
6684 if(typeof(config[size]) == 'undefined'){
6688 if (!config[size]) { // 0 = hidden
6689 td.cls += ' hidden-' + size;
6693 td.cls += ' col-' + size + '-' + config[size];
6701 row.cellObjects = cellObjects;
6709 onBeforeLoad : function()
6711 //Roo.log('ds onBeforeLoad');
6715 //if(this.loadMask){
6716 // this.maskEl.show();
6724 this.el.select('tbody', true).first().dom.innerHTML = '';
6727 * Show or hide a row.
6728 * @param {Number} rowIndex to show or hide
6729 * @param {Boolean} state hide
6731 setRowVisibility : function(rowIndex, state)
6733 var bt = this.mainBody.dom;
6735 var rows = this.el.select('tbody > tr', true).elements;
6737 if(typeof(rows[rowIndex]) == 'undefined'){
6740 rows[rowIndex].dom.style.display = state ? '' : 'none';
6744 getSelectionModel : function(){
6746 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
6748 return this.selModel;
6751 * Render the Roo.bootstrap object from renderder
6753 renderCellObject : function(r)
6757 var t = r.cfg.render(r.container);
6760 Roo.each(r.cfg.cn, function(c){
6762 container: t.getChildContainer(),
6765 _this.renderCellObject(child);
6770 getRowIndex : function(row)
6774 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
6785 * Returns the grid's underlying element = used by panel.Grid
6786 * @return {Element} The element
6788 getGridEl : function(){
6792 * Forces a resize - used by panel.Grid
6793 * @return {Element} The element
6795 autoSize : function()
6797 //var ctr = Roo.get(this.container.dom.parentElement);
6798 var ctr = Roo.get(this.el.dom);
6800 var thd = this.getGridEl().select('thead',true).first();
6801 var tbd = this.getGridEl().select('tbody', true).first();
6802 var tfd = this.getGridEl().select('tfoot', true).first();
6804 var cw = ctr.getWidth();
6808 tbd.setSize(ctr.getWidth(),
6809 ctr.getHeight() - (thd.getHeight() + (tfd ? tfd.getHeight() : 0))
6811 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
6814 cw = Math.max(cw, this.totalWidth);
6815 this.getGridEl().select('tr',true).setWidth(cw);
6816 // resize 'expandable coloumn?
6818 return; // we doe not have a view in this design..
6821 onBodyScroll: function()
6823 //Roo.log("body scrolled');" + this.mainBody.dom.scrollLeft);
6824 this.mainHead.setStyle({
6825 'position' : 'relative',
6826 'left': (-1* this.mainBody.dom.scrollLeft) + 'px'
6831 var scrollHeight = this.mainBody.dom.scrollHeight;
6833 var scrollTop = Math.ceil(this.mainBody.getScroll().top);
6835 var height = this.mainBody.getHeight();
6837 if(scrollHeight - height == scrollTop) {
6839 var total = this.ds.getTotalCount();
6841 if(this.footer.cursor + this.footer.pageSize < total){
6843 this.footer.ds.load({
6845 start : this.footer.cursor + this.footer.pageSize,
6846 limit : this.footer.pageSize
6867 * @class Roo.bootstrap.TableCell
6868 * @extends Roo.bootstrap.Component
6869 * Bootstrap TableCell class
6870 * @cfg {String} html cell contain text
6871 * @cfg {String} cls cell class
6872 * @cfg {String} tag cell tag (td|th) default td
6873 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
6874 * @cfg {String} align Aligns the content in a cell
6875 * @cfg {String} axis Categorizes cells
6876 * @cfg {String} bgcolor Specifies the background color of a cell
6877 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
6878 * @cfg {Number} colspan Specifies the number of columns a cell should span
6879 * @cfg {String} headers Specifies one or more header cells a cell is related to
6880 * @cfg {Number} height Sets the height of a cell
6881 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
6882 * @cfg {Number} rowspan Sets the number of rows a cell should span
6883 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
6884 * @cfg {String} valign Vertical aligns the content in a cell
6885 * @cfg {Number} width Specifies the width of a cell
6888 * Create a new TableCell
6889 * @param {Object} config The config object
6892 Roo.bootstrap.TableCell = function(config){
6893 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
6896 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
6916 getAutoCreate : function(){
6917 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
6937 cfg.align=this.align
6943 cfg.bgcolor=this.bgcolor
6946 cfg.charoff=this.charoff
6949 cfg.colspan=this.colspan
6952 cfg.headers=this.headers
6955 cfg.height=this.height
6958 cfg.nowrap=this.nowrap
6961 cfg.rowspan=this.rowspan
6964 cfg.scope=this.scope
6967 cfg.valign=this.valign
6970 cfg.width=this.width
6989 * @class Roo.bootstrap.TableRow
6990 * @extends Roo.bootstrap.Component
6991 * Bootstrap TableRow class
6992 * @cfg {String} cls row class
6993 * @cfg {String} align Aligns the content in a table row
6994 * @cfg {String} bgcolor Specifies a background color for a table row
6995 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
6996 * @cfg {String} valign Vertical aligns the content in a table row
6999 * Create a new TableRow
7000 * @param {Object} config The config object
7003 Roo.bootstrap.TableRow = function(config){
7004 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
7007 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
7015 getAutoCreate : function(){
7016 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
7026 cfg.align = this.align;
7029 cfg.bgcolor = this.bgcolor;
7032 cfg.charoff = this.charoff;
7035 cfg.valign = this.valign;
7053 * @class Roo.bootstrap.TableBody
7054 * @extends Roo.bootstrap.Component
7055 * Bootstrap TableBody class
7056 * @cfg {String} cls element class
7057 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
7058 * @cfg {String} align Aligns the content inside the element
7059 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
7060 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
7063 * Create a new TableBody
7064 * @param {Object} config The config object
7067 Roo.bootstrap.TableBody = function(config){
7068 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
7071 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
7079 getAutoCreate : function(){
7080 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
7094 cfg.align = this.align;
7097 cfg.charoff = this.charoff;
7100 cfg.valign = this.valign;
7107 // initEvents : function()
7114 // this.store = Roo.factory(this.store, Roo.data);
7115 // this.store.on('load', this.onLoad, this);
7117 // this.store.load();
7121 // onLoad: function ()
7123 // this.fireEvent('load', this);
7133 * Ext JS Library 1.1.1
7134 * Copyright(c) 2006-2007, Ext JS, LLC.
7136 * Originally Released Under LGPL - original licence link has changed is not relivant.
7139 * <script type="text/javascript">
7142 // as we use this in bootstrap.
7143 Roo.namespace('Roo.form');
7145 * @class Roo.form.Action
7146 * Internal Class used to handle form actions
7148 * @param {Roo.form.BasicForm} el The form element or its id
7149 * @param {Object} config Configuration options
7154 // define the action interface
7155 Roo.form.Action = function(form, options){
7157 this.options = options || {};
7160 * Client Validation Failed
7163 Roo.form.Action.CLIENT_INVALID = 'client';
7165 * Server Validation Failed
7168 Roo.form.Action.SERVER_INVALID = 'server';
7170 * Connect to Server Failed
7173 Roo.form.Action.CONNECT_FAILURE = 'connect';
7175 * Reading Data from Server Failed
7178 Roo.form.Action.LOAD_FAILURE = 'load';
7180 Roo.form.Action.prototype = {
7182 failureType : undefined,
7183 response : undefined,
7187 run : function(options){
7192 success : function(response){
7197 handleResponse : function(response){
7201 // default connection failure
7202 failure : function(response){
7204 this.response = response;
7205 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7206 this.form.afterAction(this, false);
7209 processResponse : function(response){
7210 this.response = response;
7211 if(!response.responseText){
7214 this.result = this.handleResponse(response);
7218 // utility functions used internally
7219 getUrl : function(appendParams){
7220 var url = this.options.url || this.form.url || this.form.el.dom.action;
7222 var p = this.getParams();
7224 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
7230 getMethod : function(){
7231 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
7234 getParams : function(){
7235 var bp = this.form.baseParams;
7236 var p = this.options.params;
7238 if(typeof p == "object"){
7239 p = Roo.urlEncode(Roo.applyIf(p, bp));
7240 }else if(typeof p == 'string' && bp){
7241 p += '&' + Roo.urlEncode(bp);
7244 p = Roo.urlEncode(bp);
7249 createCallback : function(){
7251 success: this.success,
7252 failure: this.failure,
7254 timeout: (this.form.timeout*1000),
7255 upload: this.form.fileUpload ? this.success : undefined
7260 Roo.form.Action.Submit = function(form, options){
7261 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
7264 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
7267 haveProgress : false,
7268 uploadComplete : false,
7270 // uploadProgress indicator.
7271 uploadProgress : function()
7273 if (!this.form.progressUrl) {
7277 if (!this.haveProgress) {
7278 Roo.MessageBox.progress("Uploading", "Uploading");
7280 if (this.uploadComplete) {
7281 Roo.MessageBox.hide();
7285 this.haveProgress = true;
7287 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
7289 var c = new Roo.data.Connection();
7291 url : this.form.progressUrl,
7296 success : function(req){
7297 //console.log(data);
7301 rdata = Roo.decode(req.responseText)
7303 Roo.log("Invalid data from server..");
7307 if (!rdata || !rdata.success) {
7309 Roo.MessageBox.alert(Roo.encode(rdata));
7312 var data = rdata.data;
7314 if (this.uploadComplete) {
7315 Roo.MessageBox.hide();
7320 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
7321 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
7324 this.uploadProgress.defer(2000,this);
7327 failure: function(data) {
7328 Roo.log('progress url failed ');
7339 // run get Values on the form, so it syncs any secondary forms.
7340 this.form.getValues();
7342 var o = this.options;
7343 var method = this.getMethod();
7344 var isPost = method == 'POST';
7345 if(o.clientValidation === false || this.form.isValid()){
7347 if (this.form.progressUrl) {
7348 this.form.findField('UPLOAD_IDENTIFIER').setValue(
7349 (new Date() * 1) + '' + Math.random());
7354 Roo.Ajax.request(Roo.apply(this.createCallback(), {
7355 form:this.form.el.dom,
7356 url:this.getUrl(!isPost),
7358 params:isPost ? this.getParams() : null,
7359 isUpload: this.form.fileUpload
7362 this.uploadProgress();
7364 }else if (o.clientValidation !== false){ // client validation failed
7365 this.failureType = Roo.form.Action.CLIENT_INVALID;
7366 this.form.afterAction(this, false);
7370 success : function(response)
7372 this.uploadComplete= true;
7373 if (this.haveProgress) {
7374 Roo.MessageBox.hide();
7378 var result = this.processResponse(response);
7379 if(result === true || result.success){
7380 this.form.afterAction(this, true);
7384 this.form.markInvalid(result.errors);
7385 this.failureType = Roo.form.Action.SERVER_INVALID;
7387 this.form.afterAction(this, false);
7389 failure : function(response)
7391 this.uploadComplete= true;
7392 if (this.haveProgress) {
7393 Roo.MessageBox.hide();
7396 this.response = response;
7397 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7398 this.form.afterAction(this, false);
7401 handleResponse : function(response){
7402 if(this.form.errorReader){
7403 var rs = this.form.errorReader.read(response);
7406 for(var i = 0, len = rs.records.length; i < len; i++) {
7407 var r = rs.records[i];
7411 if(errors.length < 1){
7415 success : rs.success,
7421 ret = Roo.decode(response.responseText);
7425 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
7435 Roo.form.Action.Load = function(form, options){
7436 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
7437 this.reader = this.form.reader;
7440 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
7445 Roo.Ajax.request(Roo.apply(
7446 this.createCallback(), {
7447 method:this.getMethod(),
7448 url:this.getUrl(false),
7449 params:this.getParams()
7453 success : function(response){
7455 var result = this.processResponse(response);
7456 if(result === true || !result.success || !result.data){
7457 this.failureType = Roo.form.Action.LOAD_FAILURE;
7458 this.form.afterAction(this, false);
7461 this.form.clearInvalid();
7462 this.form.setValues(result.data);
7463 this.form.afterAction(this, true);
7466 handleResponse : function(response){
7467 if(this.form.reader){
7468 var rs = this.form.reader.read(response);
7469 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
7471 success : rs.success,
7475 return Roo.decode(response.responseText);
7479 Roo.form.Action.ACTION_TYPES = {
7480 'load' : Roo.form.Action.Load,
7481 'submit' : Roo.form.Action.Submit
7490 * @class Roo.bootstrap.Form
7491 * @extends Roo.bootstrap.Component
7492 * Bootstrap Form class
7493 * @cfg {String} method GET | POST (default POST)
7494 * @cfg {String} labelAlign top | left (default top)
7495 * @cfg {String} align left | right - for navbars
7496 * @cfg {Boolean} loadMask load mask when submit (default true)
7501 * @param {Object} config The config object
7505 Roo.bootstrap.Form = function(config){
7506 Roo.bootstrap.Form.superclass.constructor.call(this, config);
7508 Roo.bootstrap.Form.popover.apply();
7512 * @event clientvalidation
7513 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
7514 * @param {Form} this
7515 * @param {Boolean} valid true if the form has passed client-side validation
7517 clientvalidation: true,
7519 * @event beforeaction
7520 * Fires before any action is performed. Return false to cancel the action.
7521 * @param {Form} this
7522 * @param {Action} action The action to be performed
7526 * @event actionfailed
7527 * Fires when an action fails.
7528 * @param {Form} this
7529 * @param {Action} action The action that failed
7531 actionfailed : true,
7533 * @event actioncomplete
7534 * Fires when an action is completed.
7535 * @param {Form} this
7536 * @param {Action} action The action that completed
7538 actioncomplete : true
7543 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component, {
7546 * @cfg {String} method
7547 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
7552 * The URL to use for form actions if one isn't supplied in the action options.
7555 * @cfg {Boolean} fileUpload
7556 * Set to true if this form is a file upload.
7560 * @cfg {Object} baseParams
7561 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
7565 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
7569 * @cfg {Sting} align (left|right) for navbar forms
7574 activeAction : null,
7577 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
7578 * element by passing it or its id or mask the form itself by passing in true.
7581 waitMsgTarget : false,
7586 * @cfg {Boolean} errorMask (true|false) default false
7590 getAutoCreate : function(){
7594 method : this.method || 'POST',
7595 id : this.id || Roo.id(),
7598 if (this.parent().xtype.match(/^Nav/)) {
7599 cfg.cls = 'navbar-form navbar-' + this.align;
7603 if (this.labelAlign == 'left' ) {
7604 cfg.cls += ' form-horizontal';
7610 initEvents : function()
7612 this.el.on('submit', this.onSubmit, this);
7613 // this was added as random key presses on the form where triggering form submit.
7614 this.el.on('keypress', function(e) {
7615 if (e.getCharCode() != 13) {
7618 // we might need to allow it for textareas.. and some other items.
7619 // check e.getTarget().
7621 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
7625 Roo.log("keypress blocked");
7633 onSubmit : function(e){
7638 * Returns true if client-side validation on the form is successful.
7641 isValid : function(){
7642 var items = this.getItems();
7646 items.each(function(f){
7653 if(!target && f.el.isVisible(true)){
7659 if(this.errorMask && !valid){
7660 Roo.bootstrap.Form.popover.mask(this, target);
7667 * Returns true if any fields in this form have changed since their original load.
7670 isDirty : function(){
7672 var items = this.getItems();
7673 items.each(function(f){
7683 * Performs a predefined action (submit or load) or custom actions you define on this form.
7684 * @param {String} actionName The name of the action type
7685 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
7686 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
7687 * accept other config options):
7689 Property Type Description
7690 ---------------- --------------- ----------------------------------------------------------------------------------
7691 url String The url for the action (defaults to the form's url)
7692 method String The form method to use (defaults to the form's method, or POST if not defined)
7693 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
7694 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
7695 validate the form on the client (defaults to false)
7697 * @return {BasicForm} this
7699 doAction : function(action, options){
7700 if(typeof action == 'string'){
7701 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
7703 if(this.fireEvent('beforeaction', this, action) !== false){
7704 this.beforeAction(action);
7705 action.run.defer(100, action);
7711 beforeAction : function(action){
7712 var o = action.options;
7715 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7717 // not really supported yet.. ??
7719 //if(this.waitMsgTarget === true){
7720 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7721 //}else if(this.waitMsgTarget){
7722 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
7723 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
7725 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
7731 afterAction : function(action, success){
7732 this.activeAction = null;
7733 var o = action.options;
7735 //if(this.waitMsgTarget === true){
7737 //}else if(this.waitMsgTarget){
7738 // this.waitMsgTarget.unmask();
7740 // Roo.MessageBox.updateProgress(1);
7741 // Roo.MessageBox.hide();
7748 Roo.callback(o.success, o.scope, [this, action]);
7749 this.fireEvent('actioncomplete', this, action);
7753 // failure condition..
7754 // we have a scenario where updates need confirming.
7755 // eg. if a locking scenario exists..
7756 // we look for { errors : { needs_confirm : true }} in the response.
7758 (typeof(action.result) != 'undefined') &&
7759 (typeof(action.result.errors) != 'undefined') &&
7760 (typeof(action.result.errors.needs_confirm) != 'undefined')
7763 Roo.log("not supported yet");
7766 Roo.MessageBox.confirm(
7767 "Change requires confirmation",
7768 action.result.errorMsg,
7773 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
7783 Roo.callback(o.failure, o.scope, [this, action]);
7784 // show an error message if no failed handler is set..
7785 if (!this.hasListener('actionfailed')) {
7786 Roo.log("need to add dialog support");
7788 Roo.MessageBox.alert("Error",
7789 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
7790 action.result.errorMsg :
7791 "Saving Failed, please check your entries or try again"
7796 this.fireEvent('actionfailed', this, action);
7801 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
7802 * @param {String} id The value to search for
7805 findField : function(id){
7806 var items = this.getItems();
7807 var field = items.get(id);
7809 items.each(function(f){
7810 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
7817 return field || null;
7820 * Mark fields in this form invalid in bulk.
7821 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
7822 * @return {BasicForm} this
7824 markInvalid : function(errors){
7825 if(errors instanceof Array){
7826 for(var i = 0, len = errors.length; i < len; i++){
7827 var fieldError = errors[i];
7828 var f = this.findField(fieldError.id);
7830 f.markInvalid(fieldError.msg);
7836 if(typeof errors[id] != 'function' && (field = this.findField(id))){
7837 field.markInvalid(errors[id]);
7841 //Roo.each(this.childForms || [], function (f) {
7842 // f.markInvalid(errors);
7849 * Set values for fields in this form in bulk.
7850 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
7851 * @return {BasicForm} this
7853 setValues : function(values){
7854 if(values instanceof Array){ // array of objects
7855 for(var i = 0, len = values.length; i < len; i++){
7857 var f = this.findField(v.id);
7859 f.setValue(v.value);
7860 if(this.trackResetOnLoad){
7861 f.originalValue = f.getValue();
7865 }else{ // object hash
7868 if(typeof values[id] != 'function' && (field = this.findField(id))){
7870 if (field.setFromData &&
7872 field.displayField &&
7873 // combos' with local stores can
7874 // be queried via setValue()
7875 // to set their value..
7876 (field.store && !field.store.isLocal)
7880 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
7881 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
7882 field.setFromData(sd);
7885 field.setValue(values[id]);
7889 if(this.trackResetOnLoad){
7890 field.originalValue = field.getValue();
7896 //Roo.each(this.childForms || [], function (f) {
7897 // f.setValues(values);
7904 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
7905 * they are returned as an array.
7906 * @param {Boolean} asString
7909 getValues : function(asString){
7910 //if (this.childForms) {
7911 // copy values from the child forms
7912 // Roo.each(this.childForms, function (f) {
7913 // this.setValues(f.getValues());
7919 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
7920 if(asString === true){
7923 return Roo.urlDecode(fs);
7927 * Returns the fields in this form as an object with key/value pairs.
7928 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
7931 getFieldValues : function(with_hidden)
7933 var items = this.getItems();
7935 items.each(function(f){
7939 var v = f.getValue();
7940 if (f.inputType =='radio') {
7941 if (typeof(ret[f.getName()]) == 'undefined') {
7942 ret[f.getName()] = ''; // empty..
7945 if (!f.el.dom.checked) {
7953 // not sure if this supported any more..
7954 if ((typeof(v) == 'object') && f.getRawValue) {
7955 v = f.getRawValue() ; // dates..
7957 // combo boxes where name != hiddenName...
7958 if (f.name !== false && f.name != '' && f.name != f.getName()) {
7959 ret[f.name] = f.getRawValue();
7961 ret[f.getName()] = v;
7968 * Clears all invalid messages in this form.
7969 * @return {BasicForm} this
7971 clearInvalid : function(){
7972 var items = this.getItems();
7974 items.each(function(f){
7985 * @return {BasicForm} this
7988 var items = this.getItems();
7989 items.each(function(f){
7993 Roo.each(this.childForms || [], function (f) {
8000 getItems : function()
8002 var r=new Roo.util.MixedCollection(false, function(o){
8003 return o.id || (o.id = Roo.id());
8005 var iter = function(el) {
8012 Roo.each(el.items,function(e) {
8029 Roo.apply(Roo.bootstrap.Form, {
8056 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
8057 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
8058 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
8059 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
8062 this.maskEl.top.enableDisplayMode("block");
8063 this.maskEl.left.enableDisplayMode("block");
8064 this.maskEl.bottom.enableDisplayMode("block");
8065 this.maskEl.right.enableDisplayMode("block");
8067 this.toolTip = new Roo.bootstrap.Tooltip({
8068 cls : 'roo-form-error-popover',
8070 'left' : ['r-l', [-2,0], 'right'],
8071 'right' : ['l-r', [2,0], 'left'],
8072 'bottom' : ['tl-bl', [0,2], 'top'],
8073 'top' : [ 'bl-tl', [0,-2], 'bottom']
8077 this.toolTip.render(Roo.get(document.body));
8079 this.toolTip.el.enableDisplayMode("block");
8081 Roo.get(document.body).on('click', function(){
8085 this.isApplied = true
8088 mask : function(form, target)
8092 this.target = target;
8094 if(!this.form.errorMask || !target.el){
8098 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
8100 var ot = this.target.el.calcOffsetsTo(scrollable);
8102 var scrollTo = ot[1] - 100;
8104 var maxScroll = Roo.lib.Dom.getDocumentHeight() - Roo.lib.Dom.getViewportHeight();
8106 scrollTo = Math.min(scrollTo, maxScroll);
8108 scrollable.scrollTo('top', scrollTo);
8110 var box = this.target.el.getBox();
8112 var zIndex = Roo.bootstrap.Modal.zIndex++;
8114 this.maskEl.top.setStyle('position', 'fixed');
8115 this.maskEl.top.setStyle('z-index', zIndex);
8116 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
8117 this.maskEl.top.setXY([0, 0]);
8118 this.maskEl.top.show();
8120 this.maskEl.left.setStyle('position', 'fixed');
8121 this.maskEl.left.setStyle('z-index', zIndex);
8122 this.maskEl.left.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
8123 this.maskEl.left.setXY([box.right + this.padding, box.y - this.padding]);
8124 this.maskEl.left.show();
8126 this.maskEl.bottom.setStyle('position', 'fixed');
8127 this.maskEl.bottom.setStyle('z-index', zIndex);
8128 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
8129 this.maskEl.bottom.setXY([0, box.bottom + this.padding]);
8130 this.maskEl.bottom.show();
8132 this.maskEl.right.setStyle('position', 'fixed');
8133 this.maskEl.right.setStyle('z-index', zIndex);
8134 this.maskEl.right.setSize(box.x - this.padding, box.height + this.padding * 2);
8135 this.maskEl.right.setXY([0, box.y - this.padding]);
8136 this.maskEl.right.show();
8139 this.toolTip.bindEl = this.target.el;
8141 this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
8143 var tip = this.target.blankText;
8145 if(this.target.getValue() !== '' && this.target.regexText.length){
8146 tip = this.target.regexText;
8149 this.toolTip.show(tip);
8151 this.intervalID = window.setInterval(function() {
8152 Roo.bootstrap.Form.popover.unmask();
8155 window.onwheel = function(){ return false;};
8157 (function(){ this.isMasked = true; }).defer(500, this);
8165 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
8169 this.maskEl.top.setStyle('position', 'absolute');
8170 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
8171 this.maskEl.top.hide();
8173 this.maskEl.left.setStyle('position', 'absolute');
8174 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
8175 this.maskEl.left.hide();
8177 this.maskEl.bottom.setStyle('position', 'absolute');
8178 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
8179 this.maskEl.bottom.hide();
8181 this.maskEl.right.setStyle('position', 'absolute');
8182 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
8183 this.maskEl.right.hide();
8185 this.toolTip.hide();
8187 this.toolTip.el.hide();
8189 window.onwheel = function(){ return true;};
8191 if(this.intervalID){
8192 window.clearInterval(this.intervalID);
8193 this.intervalID = false;
8196 this.isMasked = false;
8206 * Ext JS Library 1.1.1
8207 * Copyright(c) 2006-2007, Ext JS, LLC.
8209 * Originally Released Under LGPL - original licence link has changed is not relivant.
8212 * <script type="text/javascript">
8215 * @class Roo.form.VTypes
8216 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
8219 Roo.form.VTypes = function(){
8220 // closure these in so they are only created once.
8221 var alpha = /^[a-zA-Z_]+$/;
8222 var alphanum = /^[a-zA-Z0-9_]+$/;
8223 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
8224 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
8226 // All these messages and functions are configurable
8229 * The function used to validate email addresses
8230 * @param {String} value The email address
8232 'email' : function(v){
8233 return email.test(v);
8236 * The error text to display when the email validation function returns false
8239 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
8241 * The keystroke filter mask to be applied on email input
8244 'emailMask' : /[a-z0-9_\.\-@]/i,
8247 * The function used to validate URLs
8248 * @param {String} value The URL
8250 'url' : function(v){
8254 * The error text to display when the url validation function returns false
8257 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
8260 * The function used to validate alpha values
8261 * @param {String} value The value
8263 'alpha' : function(v){
8264 return alpha.test(v);
8267 * The error text to display when the alpha validation function returns false
8270 'alphaText' : 'This field should only contain letters and _',
8272 * The keystroke filter mask to be applied on alpha input
8275 'alphaMask' : /[a-z_]/i,
8278 * The function used to validate alphanumeric values
8279 * @param {String} value The value
8281 'alphanum' : function(v){
8282 return alphanum.test(v);
8285 * The error text to display when the alphanumeric validation function returns false
8288 'alphanumText' : 'This field should only contain letters, numbers and _',
8290 * The keystroke filter mask to be applied on alphanumeric input
8293 'alphanumMask' : /[a-z0-9_]/i
8303 * @class Roo.bootstrap.Input
8304 * @extends Roo.bootstrap.Component
8305 * Bootstrap Input class
8306 * @cfg {Boolean} disabled is it disabled
8307 * @cfg {String} inputType button | checkbox | email | file | hidden | image | number | password | radio | range | reset | search | submit | text
8308 * @cfg {String} name name of the input
8309 * @cfg {string} fieldLabel - the label associated
8310 * @cfg {string} placeholder - placeholder to put in text.
8311 * @cfg {string} before - input group add on before
8312 * @cfg {string} after - input group add on after
8313 * @cfg {string} size - (lg|sm) or leave empty..
8314 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
8315 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
8316 * @cfg {Number} md colspan out of 12 for computer-sized screens
8317 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
8318 * @cfg {string} value default value of the input
8319 * @cfg {Number} labelWidth set the width of label
8320 * @cfg {Number} labellg set the width of label (1-12)
8321 * @cfg {Number} labelmd set the width of label (1-12)
8322 * @cfg {Number} labelsm set the width of label (1-12)
8323 * @cfg {Number} labelxs set the width of label (1-12)
8324 * @cfg {String} labelAlign (top|left)
8325 * @cfg {Boolean} readOnly Specifies that the field should be read-only
8326 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
8327 * @cfg {String} indicatorpos (left|right) default left
8329 * @cfg {String} align (left|center|right) Default left
8330 * @cfg {Boolean} forceFeedback (true|false) Default false
8336 * Create a new Input
8337 * @param {Object} config The config object
8340 Roo.bootstrap.Input = function(config){
8342 Roo.bootstrap.Input.superclass.constructor.call(this, config);
8347 * Fires when this field receives input focus.
8348 * @param {Roo.form.Field} this
8353 * Fires when this field loses input focus.
8354 * @param {Roo.form.Field} this
8359 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
8360 * {@link Roo.EventObject#getKey} to determine which key was pressed.
8361 * @param {Roo.form.Field} this
8362 * @param {Roo.EventObject} e The event object
8367 * Fires just before the field blurs if the field value has changed.
8368 * @param {Roo.form.Field} this
8369 * @param {Mixed} newValue The new value
8370 * @param {Mixed} oldValue The original value
8375 * Fires after the field has been marked as invalid.
8376 * @param {Roo.form.Field} this
8377 * @param {String} msg The validation message
8382 * Fires after the field has been validated with no errors.
8383 * @param {Roo.form.Field} this
8388 * Fires after the key up
8389 * @param {Roo.form.Field} this
8390 * @param {Roo.EventObject} e The event Object
8396 Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component, {
8398 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
8399 automatic validation (defaults to "keyup").
8401 validationEvent : "keyup",
8403 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
8405 validateOnBlur : true,
8407 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
8409 validationDelay : 250,
8411 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
8413 focusClass : "x-form-focus", // not needed???
8417 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
8419 invalidClass : "has-warning",
8422 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
8424 validClass : "has-success",
8427 * @cfg {Boolean} hasFeedback (true|false) default true
8432 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8434 invalidFeedbackClass : "glyphicon-warning-sign",
8437 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8439 validFeedbackClass : "glyphicon-ok",
8442 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
8444 selectOnFocus : false,
8447 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
8451 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
8456 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
8458 disableKeyFilter : false,
8461 * @cfg {Boolean} disabled True to disable the field (defaults to false).
8465 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
8469 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
8471 blankText : "Please complete this mandatory field",
8474 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
8478 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
8480 maxLength : Number.MAX_VALUE,
8482 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
8484 minLengthText : "The minimum length for this field is {0}",
8486 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
8488 maxLengthText : "The maximum length for this field is {0}",
8492 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
8493 * If available, this function will be called only after the basic validators all return true, and will be passed the
8494 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
8498 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
8499 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
8500 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
8504 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
8508 autocomplete: false,
8527 formatedValue : false,
8528 forceFeedback : false,
8530 indicatorpos : 'left',
8537 parentLabelAlign : function()
8540 while (parent.parent()) {
8541 parent = parent.parent();
8542 if (typeof(parent.labelAlign) !='undefined') {
8543 return parent.labelAlign;
8550 getAutoCreate : function()
8552 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8558 if(this.inputType != 'hidden'){
8559 cfg.cls = 'form-group' //input-group
8565 type : this.inputType,
8567 cls : 'form-control',
8568 placeholder : this.placeholder || '',
8569 autocomplete : this.autocomplete || 'new-password'
8573 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
8576 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
8577 input.maxLength = this.maxLength;
8580 if (this.disabled) {
8581 input.disabled=true;
8584 if (this.readOnly) {
8585 input.readonly=true;
8589 input.name = this.name;
8593 input.cls += ' input-' + this.size;
8597 ['xs','sm','md','lg'].map(function(size){
8598 if (settings[size]) {
8599 cfg.cls += ' col-' + size + '-' + settings[size];
8603 var inputblock = input;
8607 cls: 'glyphicon form-control-feedback'
8610 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8613 cls : 'has-feedback',
8621 if (this.before || this.after) {
8624 cls : 'input-group',
8628 if (this.before && typeof(this.before) == 'string') {
8630 inputblock.cn.push({
8632 cls : 'roo-input-before input-group-addon',
8636 if (this.before && typeof(this.before) == 'object') {
8637 this.before = Roo.factory(this.before);
8639 inputblock.cn.push({
8641 cls : 'roo-input-before input-group-' +
8642 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8646 inputblock.cn.push(input);
8648 if (this.after && typeof(this.after) == 'string') {
8649 inputblock.cn.push({
8651 cls : 'roo-input-after input-group-addon',
8655 if (this.after && typeof(this.after) == 'object') {
8656 this.after = Roo.factory(this.after);
8658 inputblock.cn.push({
8660 cls : 'roo-input-after input-group-' +
8661 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8665 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8666 inputblock.cls += ' has-feedback';
8667 inputblock.cn.push(feedback);
8671 if (align ==='left' && this.fieldLabel.length) {
8673 cfg.cls += ' roo-form-group-label-left';
8678 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
8679 tooltip : 'This field is required'
8684 cls : 'control-label',
8685 html : this.fieldLabel
8696 var labelCfg = cfg.cn[1];
8697 var contentCfg = cfg.cn[2];
8699 if(this.indicatorpos == 'right'){
8704 cls : 'control-label',
8705 html : this.fieldLabel
8710 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
8711 tooltip : 'This field is required'
8722 labelCfg = cfg.cn[0];
8723 contentCfg = cfg.cn[2];
8727 if(this.labelWidth > 12){
8728 labelCfg.style = "width: " + this.labelWidth + 'px';
8731 if(this.labelWidth < 13 && this.labelmd == 0){
8732 this.labelmd = this.labelWidth;
8735 if(this.labellg > 0){
8736 labelCfg.cls += ' col-lg-' + this.labellg;
8737 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
8740 if(this.labelmd > 0){
8741 labelCfg.cls += ' col-md-' + this.labelmd;
8742 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
8745 if(this.labelsm > 0){
8746 labelCfg.cls += ' col-sm-' + this.labelsm;
8747 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
8750 if(this.labelxs > 0){
8751 labelCfg.cls += ' col-xs-' + this.labelxs;
8752 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
8756 } else if ( this.fieldLabel.length) {
8761 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
8762 tooltip : 'This field is required'
8766 //cls : 'input-group-addon',
8767 html : this.fieldLabel
8775 if(this.indicatorpos == 'right'){
8780 //cls : 'input-group-addon',
8781 html : this.fieldLabel
8786 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
8787 tooltip : 'This field is required'
8807 if (this.parentType === 'Navbar' && this.parent().bar) {
8808 cfg.cls += ' navbar-form';
8811 if (this.parentType === 'NavGroup') {
8812 cfg.cls += ' navbar-form';
8820 * return the real input element.
8822 inputEl: function ()
8824 return this.el.select('input.form-control',true).first();
8827 tooltipEl : function()
8829 return this.inputEl();
8832 indicatorEl : function()
8834 var indicator = this.el.select('i.roo-required-indicator',true).first();
8844 setDisabled : function(v)
8846 var i = this.inputEl().dom;
8848 i.removeAttribute('disabled');
8852 i.setAttribute('disabled','true');
8854 initEvents : function()
8857 this.inputEl().on("keydown" , this.fireKey, this);
8858 this.inputEl().on("focus", this.onFocus, this);
8859 this.inputEl().on("blur", this.onBlur, this);
8861 this.inputEl().relayEvent('keyup', this);
8863 this.indicator = this.indicatorEl();
8866 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
8867 this.indicator.hide();
8870 // reference to original value for reset
8871 this.originalValue = this.getValue();
8872 //Roo.form.TextField.superclass.initEvents.call(this);
8873 if(this.validationEvent == 'keyup'){
8874 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
8875 this.inputEl().on('keyup', this.filterValidation, this);
8877 else if(this.validationEvent !== false){
8878 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
8881 if(this.selectOnFocus){
8882 this.on("focus", this.preFocus, this);
8885 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
8886 this.inputEl().on("keypress", this.filterKeys, this);
8888 this.inputEl().relayEvent('keypress', this);
8891 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
8892 this.el.on("click", this.autoSize, this);
8895 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
8896 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
8899 if (typeof(this.before) == 'object') {
8900 this.before.render(this.el.select('.roo-input-before',true).first());
8902 if (typeof(this.after) == 'object') {
8903 this.after.render(this.el.select('.roo-input-after',true).first());
8908 filterValidation : function(e){
8909 if(!e.isNavKeyPress()){
8910 this.validationTask.delay(this.validationDelay);
8914 * Validates the field value
8915 * @return {Boolean} True if the value is valid, else false
8917 validate : function(){
8918 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
8919 if(this.disabled || this.validateValue(this.getRawValue())){
8930 * Validates a value according to the field's validation rules and marks the field as invalid
8931 * if the validation fails
8932 * @param {Mixed} value The value to validate
8933 * @return {Boolean} True if the value is valid, else false
8935 validateValue : function(value){
8936 if(value.length < 1) { // if it's blank
8937 if(this.allowBlank){
8943 if(value.length < this.minLength){
8946 if(value.length > this.maxLength){
8950 var vt = Roo.form.VTypes;
8951 if(!vt[this.vtype](value, this)){
8955 if(typeof this.validator == "function"){
8956 var msg = this.validator(value);
8962 if(this.regex && !this.regex.test(value)){
8972 fireKey : function(e){
8973 //Roo.log('field ' + e.getKey());
8974 if(e.isNavKeyPress()){
8975 this.fireEvent("specialkey", this, e);
8978 focus : function (selectText){
8980 this.inputEl().focus();
8981 if(selectText === true){
8982 this.inputEl().dom.select();
8988 onFocus : function(){
8989 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
8990 // this.el.addClass(this.focusClass);
8993 this.hasFocus = true;
8994 this.startValue = this.getValue();
8995 this.fireEvent("focus", this);
8999 beforeBlur : Roo.emptyFn,
9003 onBlur : function(){
9005 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9006 //this.el.removeClass(this.focusClass);
9008 this.hasFocus = false;
9009 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
9012 var v = this.getValue();
9013 if(String(v) !== String(this.startValue)){
9014 this.fireEvent('change', this, v, this.startValue);
9016 this.fireEvent("blur", this);
9020 * Resets the current field value to the originally loaded value and clears any validation messages
9023 this.setValue(this.originalValue);
9027 * Returns the name of the field
9028 * @return {Mixed} name The name field
9030 getName: function(){
9034 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
9035 * @return {Mixed} value The field value
9037 getValue : function(){
9039 var v = this.inputEl().getValue();
9044 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
9045 * @return {Mixed} value The field value
9047 getRawValue : function(){
9048 var v = this.inputEl().getValue();
9054 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
9055 * @param {Mixed} value The value to set
9057 setRawValue : function(v){
9058 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9061 selectText : function(start, end){
9062 var v = this.getRawValue();
9064 start = start === undefined ? 0 : start;
9065 end = end === undefined ? v.length : end;
9066 var d = this.inputEl().dom;
9067 if(d.setSelectionRange){
9068 d.setSelectionRange(start, end);
9069 }else if(d.createTextRange){
9070 var range = d.createTextRange();
9071 range.moveStart("character", start);
9072 range.moveEnd("character", v.length-end);
9079 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
9080 * @param {Mixed} value The value to set
9082 setValue : function(v){
9085 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9091 processValue : function(value){
9092 if(this.stripCharsRe){
9093 var newValue = value.replace(this.stripCharsRe, '');
9094 if(newValue !== value){
9095 this.setRawValue(newValue);
9102 preFocus : function(){
9104 if(this.selectOnFocus){
9105 this.inputEl().dom.select();
9108 filterKeys : function(e){
9110 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
9113 var c = e.getCharCode(), cc = String.fromCharCode(c);
9114 if(Roo.isIE && (e.isSpecialKey() || !cc)){
9117 if(!this.maskRe.test(cc)){
9122 * Clear any invalid styles/messages for this field
9124 clearInvalid : function(){
9126 if(!this.el || this.preventMark){ // not rendered
9131 this.el.removeClass(this.invalidClass);
9133 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9135 var feedback = this.el.select('.form-control-feedback', true).first();
9138 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9143 this.fireEvent('valid', this);
9147 * Mark this field as valid
9149 markValid : function()
9151 if(!this.el || this.preventMark){ // not rendered...
9155 this.el.removeClass([this.invalidClass, this.validClass]);
9157 var feedback = this.el.select('.form-control-feedback', true).first();
9160 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9167 if(this.allowBlank && !this.getRawValue().length){
9172 this.indicator.hide();
9175 this.el.addClass(this.validClass);
9177 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9179 var feedback = this.el.select('.form-control-feedback', true).first();
9182 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9183 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9188 this.fireEvent('valid', this);
9192 * Mark this field as invalid
9193 * @param {String} msg The validation message
9195 markInvalid : function(msg)
9197 if(!this.el || this.preventMark){ // not rendered
9201 this.el.removeClass([this.invalidClass, this.validClass]);
9203 var feedback = this.el.select('.form-control-feedback', true).first();
9206 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9213 if(this.allowBlank && !this.getRawValue().length){
9218 this.indicator.show();
9221 this.el.addClass(this.invalidClass);
9223 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9225 var feedback = this.el.select('.form-control-feedback', true).first();
9228 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9230 if(this.getValue().length || this.forceFeedback){
9231 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9238 this.fireEvent('invalid', this, msg);
9241 SafariOnKeyDown : function(event)
9243 // this is a workaround for a password hang bug on chrome/ webkit.
9244 if (this.inputEl().dom.type != 'password') {
9248 var isSelectAll = false;
9250 if(this.inputEl().dom.selectionEnd > 0){
9251 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
9253 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
9254 event.preventDefault();
9259 if(isSelectAll && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
9261 event.preventDefault();
9262 // this is very hacky as keydown always get's upper case.
9264 var cc = String.fromCharCode(event.getCharCode());
9265 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
9269 adjustWidth : function(tag, w){
9270 tag = tag.toLowerCase();
9271 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
9272 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
9276 if(tag == 'textarea'){
9279 }else if(Roo.isOpera){
9283 if(tag == 'textarea'){
9302 * @class Roo.bootstrap.TextArea
9303 * @extends Roo.bootstrap.Input
9304 * Bootstrap TextArea class
9305 * @cfg {Number} cols Specifies the visible width of a text area
9306 * @cfg {Number} rows Specifies the visible number of lines in a text area
9307 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
9308 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
9309 * @cfg {string} html text
9312 * Create a new TextArea
9313 * @param {Object} config The config object
9316 Roo.bootstrap.TextArea = function(config){
9317 Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
9321 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input, {
9331 getAutoCreate : function(){
9333 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
9344 value : this.value || '',
9345 html: this.html || '',
9346 cls : 'form-control',
9347 placeholder : this.placeholder || ''
9351 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
9352 input.maxLength = this.maxLength;
9356 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
9360 input.cols = this.cols;
9363 if (this.readOnly) {
9364 input.readonly = true;
9368 input.name = this.name;
9372 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
9376 ['xs','sm','md','lg'].map(function(size){
9377 if (settings[size]) {
9378 cfg.cls += ' col-' + size + '-' + settings[size];
9382 var inputblock = input;
9384 if(this.hasFeedback && !this.allowBlank){
9388 cls: 'glyphicon form-control-feedback'
9392 cls : 'has-feedback',
9401 if (this.before || this.after) {
9404 cls : 'input-group',
9408 inputblock.cn.push({
9410 cls : 'input-group-addon',
9415 inputblock.cn.push(input);
9417 if(this.hasFeedback && !this.allowBlank){
9418 inputblock.cls += ' has-feedback';
9419 inputblock.cn.push(feedback);
9423 inputblock.cn.push({
9425 cls : 'input-group-addon',
9432 if (align ==='left' && this.fieldLabel.length) {
9437 cls : 'control-label',
9438 html : this.fieldLabel
9449 if(this.labelWidth > 12){
9450 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
9453 if(this.labelWidth < 13 && this.labelmd == 0){
9454 this.labelmd = this.labelWidth;
9457 if(this.labellg > 0){
9458 cfg.cn[0].cls += ' col-lg-' + this.labellg;
9459 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
9462 if(this.labelmd > 0){
9463 cfg.cn[0].cls += ' col-md-' + this.labelmd;
9464 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
9467 if(this.labelsm > 0){
9468 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
9469 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
9472 if(this.labelxs > 0){
9473 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
9474 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
9477 } else if ( this.fieldLabel.length) {
9482 //cls : 'input-group-addon',
9483 html : this.fieldLabel
9501 if (this.disabled) {
9502 input.disabled=true;
9509 * return the real textarea element.
9511 inputEl: function ()
9513 return this.el.select('textarea.form-control',true).first();
9517 * Clear any invalid styles/messages for this field
9519 clearInvalid : function()
9522 if(!this.el || this.preventMark){ // not rendered
9526 var label = this.el.select('label', true).first();
9527 var icon = this.el.select('i.fa-star', true).first();
9533 this.el.removeClass(this.invalidClass);
9535 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9537 var feedback = this.el.select('.form-control-feedback', true).first();
9540 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9545 this.fireEvent('valid', this);
9549 * Mark this field as valid
9551 markValid : function()
9553 if(!this.el || this.preventMark){ // not rendered
9557 this.el.removeClass([this.invalidClass, this.validClass]);
9559 var feedback = this.el.select('.form-control-feedback', true).first();
9562 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9565 if(this.disabled || this.allowBlank){
9569 var label = this.el.select('label', true).first();
9570 var icon = this.el.select('i.fa-star', true).first();
9576 this.el.addClass(this.validClass);
9578 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9580 var feedback = this.el.select('.form-control-feedback', true).first();
9583 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9584 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9589 this.fireEvent('valid', this);
9593 * Mark this field as invalid
9594 * @param {String} msg The validation message
9596 markInvalid : function(msg)
9598 if(!this.el || this.preventMark){ // not rendered
9602 this.el.removeClass([this.invalidClass, this.validClass]);
9604 var feedback = this.el.select('.form-control-feedback', true).first();
9607 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9610 if(this.disabled || this.allowBlank){
9614 var label = this.el.select('label', true).first();
9615 var icon = this.el.select('i.fa-star', true).first();
9617 if(!this.getValue().length && label && !icon){
9618 this.el.createChild({
9620 cls : 'text-danger fa fa-lg fa-star',
9621 tooltip : 'This field is required',
9622 style : 'margin-right:5px;'
9626 this.el.addClass(this.invalidClass);
9628 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9630 var feedback = this.el.select('.form-control-feedback', true).first();
9633 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9635 if(this.getValue().length || this.forceFeedback){
9636 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9643 this.fireEvent('invalid', this, msg);
9651 * trigger field - base class for combo..
9656 * @class Roo.bootstrap.TriggerField
9657 * @extends Roo.bootstrap.Input
9658 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
9659 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
9660 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
9661 * for which you can provide a custom implementation. For example:
9663 var trigger = new Roo.bootstrap.TriggerField();
9664 trigger.onTriggerClick = myTriggerFn;
9665 trigger.applyTo('my-field');
9668 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
9669 * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
9670 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
9671 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
9672 * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
9675 * Create a new TriggerField.
9676 * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
9677 * to the base TextField)
9679 Roo.bootstrap.TriggerField = function(config){
9680 this.mimicing = false;
9681 Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
9684 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input, {
9686 * @cfg {String} triggerClass A CSS class to apply to the trigger
9689 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
9694 * @cfg {Boolean} removable (true|false) special filter default false
9698 /** @cfg {Boolean} grow @hide */
9699 /** @cfg {Number} growMin @hide */
9700 /** @cfg {Number} growMax @hide */
9706 autoSize: Roo.emptyFn,
9713 actionMode : 'wrap',
9718 getAutoCreate : function(){
9720 var align = this.labelAlign || this.parentLabelAlign();
9725 cls: 'form-group' //input-group
9732 type : this.inputType,
9733 cls : 'form-control',
9734 autocomplete: 'new-password',
9735 placeholder : this.placeholder || ''
9739 input.name = this.name;
9742 input.cls += ' input-' + this.size;
9745 if (this.disabled) {
9746 input.disabled=true;
9749 var inputblock = input;
9751 if(this.hasFeedback && !this.allowBlank){
9755 cls: 'glyphicon form-control-feedback'
9758 if(this.removable && !this.editable && !this.tickable){
9760 cls : 'has-feedback',
9766 cls : 'roo-combo-removable-btn close'
9773 cls : 'has-feedback',
9782 if(this.removable && !this.editable && !this.tickable){
9784 cls : 'roo-removable',
9790 cls : 'roo-combo-removable-btn close'
9797 if (this.before || this.after) {
9800 cls : 'input-group',
9804 inputblock.cn.push({
9806 cls : 'input-group-addon',
9811 inputblock.cn.push(input);
9813 if(this.hasFeedback && !this.allowBlank){
9814 inputblock.cls += ' has-feedback';
9815 inputblock.cn.push(feedback);
9819 inputblock.cn.push({
9821 cls : 'input-group-addon',
9834 cls: 'form-hidden-field'
9848 cls: 'form-hidden-field'
9852 cls: 'roo-select2-choices',
9856 cls: 'roo-select2-search-field',
9869 cls: 'roo-select2-container input-group',
9874 // cls: 'typeahead typeahead-long dropdown-menu',
9875 // style: 'display:none'
9880 if(!this.multiple && this.showToggleBtn){
9886 if (this.caret != false) {
9889 cls: 'fa fa-' + this.caret
9896 cls : 'input-group-addon btn dropdown-toggle',
9901 cls: 'combobox-clear',
9915 combobox.cls += ' roo-select2-container-multi';
9918 if (align ==='left' && this.fieldLabel.length) {
9920 cfg.cls += ' roo-form-group-label-left';
9925 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9926 tooltip : 'This field is required'
9931 cls : 'control-label',
9932 html : this.fieldLabel
9944 var labelCfg = cfg.cn[1];
9945 var contentCfg = cfg.cn[2];
9947 if(this.indicatorpos == 'right'){
9952 cls : 'control-label',
9956 html : this.fieldLabel
9960 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9961 tooltip : 'This field is required'
9974 labelCfg = cfg.cn[0];
9975 contentCfg = cfg.cn[1];
9978 if(this.labelWidth > 12){
9979 labelCfg.style = "width: " + this.labelWidth + 'px';
9982 if(this.labelWidth < 13 && this.labelmd == 0){
9983 this.labelmd = this.labelWidth;
9986 if(this.labellg > 0){
9987 labelCfg.cls += ' col-lg-' + this.labellg;
9988 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
9991 if(this.labelmd > 0){
9992 labelCfg.cls += ' col-md-' + this.labelmd;
9993 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
9996 if(this.labelsm > 0){
9997 labelCfg.cls += ' col-sm-' + this.labelsm;
9998 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
10001 if(this.labelxs > 0){
10002 labelCfg.cls += ' col-xs-' + this.labelxs;
10003 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
10006 } else if ( this.fieldLabel.length) {
10007 // Roo.log(" label");
10011 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10012 tooltip : 'This field is required'
10016 //cls : 'input-group-addon',
10017 html : this.fieldLabel
10025 if(this.indicatorpos == 'right'){
10033 html : this.fieldLabel
10037 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10038 tooltip : 'This field is required'
10051 // Roo.log(" no label && no align");
10058 ['xs','sm','md','lg'].map(function(size){
10059 if (settings[size]) {
10060 cfg.cls += ' col-' + size + '-' + settings[size];
10071 onResize : function(w, h){
10072 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
10073 // if(typeof w == 'number'){
10074 // var x = w - this.trigger.getWidth();
10075 // this.inputEl().setWidth(this.adjustWidth('input', x));
10076 // this.trigger.setStyle('left', x+'px');
10081 adjustSize : Roo.BoxComponent.prototype.adjustSize,
10084 getResizeEl : function(){
10085 return this.inputEl();
10089 getPositionEl : function(){
10090 return this.inputEl();
10094 alignErrorIcon : function(){
10095 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
10099 initEvents : function(){
10103 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
10104 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
10105 if(!this.multiple && this.showToggleBtn){
10106 this.trigger = this.el.select('span.dropdown-toggle',true).first();
10107 if(this.hideTrigger){
10108 this.trigger.setDisplayed(false);
10110 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
10114 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
10117 if(this.removable && !this.editable && !this.tickable){
10118 var close = this.closeTriggerEl();
10121 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
10122 close.on('click', this.removeBtnClick, this, close);
10126 //this.trigger.addClassOnOver('x-form-trigger-over');
10127 //this.trigger.addClassOnClick('x-form-trigger-click');
10130 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
10134 closeTriggerEl : function()
10136 var close = this.el.select('.roo-combo-removable-btn', true).first();
10137 return close ? close : false;
10140 removeBtnClick : function(e, h, el)
10142 e.preventDefault();
10144 if(this.fireEvent("remove", this) !== false){
10146 this.fireEvent("afterremove", this)
10150 createList : function()
10152 this.list = Roo.get(document.body).createChild({
10154 cls: 'typeahead typeahead-long dropdown-menu',
10155 style: 'display:none'
10158 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
10163 initTrigger : function(){
10168 onDestroy : function(){
10170 this.trigger.removeAllListeners();
10171 // this.trigger.remove();
10174 // this.wrap.remove();
10176 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
10180 onFocus : function(){
10181 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
10183 if(!this.mimicing){
10184 this.wrap.addClass('x-trigger-wrap-focus');
10185 this.mimicing = true;
10186 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
10187 if(this.monitorTab){
10188 this.el.on("keydown", this.checkTab, this);
10195 checkTab : function(e){
10196 if(e.getKey() == e.TAB){
10197 this.triggerBlur();
10202 onBlur : function(){
10207 mimicBlur : function(e, t){
10209 if(!this.wrap.contains(t) && this.validateBlur()){
10210 this.triggerBlur();
10216 triggerBlur : function(){
10217 this.mimicing = false;
10218 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
10219 if(this.monitorTab){
10220 this.el.un("keydown", this.checkTab, this);
10222 //this.wrap.removeClass('x-trigger-wrap-focus');
10223 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
10227 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
10228 validateBlur : function(e, t){
10233 onDisable : function(){
10234 this.inputEl().dom.disabled = true;
10235 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
10237 // this.wrap.addClass('x-item-disabled');
10242 onEnable : function(){
10243 this.inputEl().dom.disabled = false;
10244 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
10246 // this.el.removeClass('x-item-disabled');
10251 onShow : function(){
10252 var ae = this.getActionEl();
10255 ae.dom.style.display = '';
10256 ae.dom.style.visibility = 'visible';
10262 onHide : function(){
10263 var ae = this.getActionEl();
10264 ae.dom.style.display = 'none';
10268 * The function that should handle the trigger's click event. This method does nothing by default until overridden
10269 * by an implementing function.
10271 * @param {EventObject} e
10273 onTriggerClick : Roo.emptyFn
10277 * Ext JS Library 1.1.1
10278 * Copyright(c) 2006-2007, Ext JS, LLC.
10280 * Originally Released Under LGPL - original licence link has changed is not relivant.
10283 * <script type="text/javascript">
10288 * @class Roo.data.SortTypes
10290 * Defines the default sorting (casting?) comparison functions used when sorting data.
10292 Roo.data.SortTypes = {
10294 * Default sort that does nothing
10295 * @param {Mixed} s The value being converted
10296 * @return {Mixed} The comparison value
10298 none : function(s){
10303 * The regular expression used to strip tags
10307 stripTagsRE : /<\/?[^>]+>/gi,
10310 * Strips all HTML tags to sort on text only
10311 * @param {Mixed} s The value being converted
10312 * @return {String} The comparison value
10314 asText : function(s){
10315 return String(s).replace(this.stripTagsRE, "");
10319 * Strips all HTML tags to sort on text only - Case insensitive
10320 * @param {Mixed} s The value being converted
10321 * @return {String} The comparison value
10323 asUCText : function(s){
10324 return String(s).toUpperCase().replace(this.stripTagsRE, "");
10328 * Case insensitive string
10329 * @param {Mixed} s The value being converted
10330 * @return {String} The comparison value
10332 asUCString : function(s) {
10333 return String(s).toUpperCase();
10338 * @param {Mixed} s The value being converted
10339 * @return {Number} The comparison value
10341 asDate : function(s) {
10345 if(s instanceof Date){
10346 return s.getTime();
10348 return Date.parse(String(s));
10353 * @param {Mixed} s The value being converted
10354 * @return {Float} The comparison value
10356 asFloat : function(s) {
10357 var val = parseFloat(String(s).replace(/,/g, ""));
10366 * @param {Mixed} s The value being converted
10367 * @return {Number} The comparison value
10369 asInt : function(s) {
10370 var val = parseInt(String(s).replace(/,/g, ""));
10378 * Ext JS Library 1.1.1
10379 * Copyright(c) 2006-2007, Ext JS, LLC.
10381 * Originally Released Under LGPL - original licence link has changed is not relivant.
10384 * <script type="text/javascript">
10388 * @class Roo.data.Record
10389 * Instances of this class encapsulate both record <em>definition</em> information, and record
10390 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
10391 * to access Records cached in an {@link Roo.data.Store} object.<br>
10393 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
10394 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
10397 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
10399 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
10400 * {@link #create}. The parameters are the same.
10401 * @param {Array} data An associative Array of data values keyed by the field name.
10402 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
10403 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
10404 * not specified an integer id is generated.
10406 Roo.data.Record = function(data, id){
10407 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
10412 * Generate a constructor for a specific record layout.
10413 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
10414 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
10415 * Each field definition object may contain the following properties: <ul>
10416 * <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,
10417 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
10418 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
10419 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
10420 * is being used, then this is a string containing the javascript expression to reference the data relative to
10421 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
10422 * to the data item relative to the record element. If the mapping expression is the same as the field name,
10423 * this may be omitted.</p></li>
10424 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
10425 * <ul><li>auto (Default, implies no conversion)</li>
10430 * <li>date</li></ul></p></li>
10431 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
10432 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
10433 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
10434 * by the Reader into an object that will be stored in the Record. It is passed the
10435 * following parameters:<ul>
10436 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
10438 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
10440 * <br>usage:<br><pre><code>
10441 var TopicRecord = Roo.data.Record.create(
10442 {name: 'title', mapping: 'topic_title'},
10443 {name: 'author', mapping: 'username'},
10444 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
10445 {name: 'lastPost', mapping: 'post_time', type: 'date'},
10446 {name: 'lastPoster', mapping: 'user2'},
10447 {name: 'excerpt', mapping: 'post_text'}
10450 var myNewRecord = new TopicRecord({
10451 title: 'Do my job please',
10454 lastPost: new Date(),
10455 lastPoster: 'Animal',
10456 excerpt: 'No way dude!'
10458 myStore.add(myNewRecord);
10463 Roo.data.Record.create = function(o){
10464 var f = function(){
10465 f.superclass.constructor.apply(this, arguments);
10467 Roo.extend(f, Roo.data.Record);
10468 var p = f.prototype;
10469 p.fields = new Roo.util.MixedCollection(false, function(field){
10472 for(var i = 0, len = o.length; i < len; i++){
10473 p.fields.add(new Roo.data.Field(o[i]));
10475 f.getField = function(name){
10476 return p.fields.get(name);
10481 Roo.data.Record.AUTO_ID = 1000;
10482 Roo.data.Record.EDIT = 'edit';
10483 Roo.data.Record.REJECT = 'reject';
10484 Roo.data.Record.COMMIT = 'commit';
10486 Roo.data.Record.prototype = {
10488 * Readonly flag - true if this record has been modified.
10497 join : function(store){
10498 this.store = store;
10502 * Set the named field to the specified value.
10503 * @param {String} name The name of the field to set.
10504 * @param {Object} value The value to set the field to.
10506 set : function(name, value){
10507 if(this.data[name] == value){
10511 if(!this.modified){
10512 this.modified = {};
10514 if(typeof this.modified[name] == 'undefined'){
10515 this.modified[name] = this.data[name];
10517 this.data[name] = value;
10518 if(!this.editing && this.store){
10519 this.store.afterEdit(this);
10524 * Get the value of the named field.
10525 * @param {String} name The name of the field to get the value of.
10526 * @return {Object} The value of the field.
10528 get : function(name){
10529 return this.data[name];
10533 beginEdit : function(){
10534 this.editing = true;
10535 this.modified = {};
10539 cancelEdit : function(){
10540 this.editing = false;
10541 delete this.modified;
10545 endEdit : function(){
10546 this.editing = false;
10547 if(this.dirty && this.store){
10548 this.store.afterEdit(this);
10553 * Usually called by the {@link Roo.data.Store} which owns the Record.
10554 * Rejects all changes made to the Record since either creation, or the last commit operation.
10555 * Modified fields are reverted to their original values.
10557 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10558 * of reject operations.
10560 reject : function(){
10561 var m = this.modified;
10563 if(typeof m[n] != "function"){
10564 this.data[n] = m[n];
10567 this.dirty = false;
10568 delete this.modified;
10569 this.editing = false;
10571 this.store.afterReject(this);
10576 * Usually called by the {@link Roo.data.Store} which owns the Record.
10577 * Commits all changes made to the Record since either creation, or the last commit operation.
10579 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10580 * of commit operations.
10582 commit : function(){
10583 this.dirty = false;
10584 delete this.modified;
10585 this.editing = false;
10587 this.store.afterCommit(this);
10592 hasError : function(){
10593 return this.error != null;
10597 clearError : function(){
10602 * Creates a copy of this record.
10603 * @param {String} id (optional) A new record id if you don't want to use this record's id
10606 copy : function(newId) {
10607 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
10611 * Ext JS Library 1.1.1
10612 * Copyright(c) 2006-2007, Ext JS, LLC.
10614 * Originally Released Under LGPL - original licence link has changed is not relivant.
10617 * <script type="text/javascript">
10623 * @class Roo.data.Store
10624 * @extends Roo.util.Observable
10625 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
10626 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
10628 * 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
10629 * has no knowledge of the format of the data returned by the Proxy.<br>
10631 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
10632 * instances from the data object. These records are cached and made available through accessor functions.
10634 * Creates a new Store.
10635 * @param {Object} config A config object containing the objects needed for the Store to access data,
10636 * and read the data into Records.
10638 Roo.data.Store = function(config){
10639 this.data = new Roo.util.MixedCollection(false);
10640 this.data.getKey = function(o){
10643 this.baseParams = {};
10645 this.paramNames = {
10650 "multisort" : "_multisort"
10653 if(config && config.data){
10654 this.inlineData = config.data;
10655 delete config.data;
10658 Roo.apply(this, config);
10660 if(this.reader){ // reader passed
10661 this.reader = Roo.factory(this.reader, Roo.data);
10662 this.reader.xmodule = this.xmodule || false;
10663 if(!this.recordType){
10664 this.recordType = this.reader.recordType;
10666 if(this.reader.onMetaChange){
10667 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
10671 if(this.recordType){
10672 this.fields = this.recordType.prototype.fields;
10674 this.modified = [];
10678 * @event datachanged
10679 * Fires when the data cache has changed, and a widget which is using this Store
10680 * as a Record cache should refresh its view.
10681 * @param {Store} this
10683 datachanged : true,
10685 * @event metachange
10686 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
10687 * @param {Store} this
10688 * @param {Object} meta The JSON metadata
10693 * Fires when Records have been added to the Store
10694 * @param {Store} this
10695 * @param {Roo.data.Record[]} records The array of Records added
10696 * @param {Number} index The index at which the record(s) were added
10701 * Fires when a Record has been removed from the Store
10702 * @param {Store} this
10703 * @param {Roo.data.Record} record The Record that was removed
10704 * @param {Number} index The index at which the record was removed
10709 * Fires when a Record has been updated
10710 * @param {Store} this
10711 * @param {Roo.data.Record} record The Record that was updated
10712 * @param {String} operation The update operation being performed. Value may be one of:
10714 Roo.data.Record.EDIT
10715 Roo.data.Record.REJECT
10716 Roo.data.Record.COMMIT
10722 * Fires when the data cache has been cleared.
10723 * @param {Store} this
10727 * @event beforeload
10728 * Fires before a request is made for a new data object. If the beforeload handler returns false
10729 * the load action will be canceled.
10730 * @param {Store} this
10731 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10735 * @event beforeloadadd
10736 * Fires after a new set of Records has been loaded.
10737 * @param {Store} this
10738 * @param {Roo.data.Record[]} records The Records that were loaded
10739 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10741 beforeloadadd : true,
10744 * Fires after a new set of Records has been loaded, before they are added to the store.
10745 * @param {Store} this
10746 * @param {Roo.data.Record[]} records The Records that were loaded
10747 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10748 * @params {Object} return from reader
10752 * @event loadexception
10753 * Fires if an exception occurs in the Proxy during loading.
10754 * Called with the signature of the Proxy's "loadexception" event.
10755 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
10758 * @param {Object} return from JsonData.reader() - success, totalRecords, records
10759 * @param {Object} load options
10760 * @param {Object} jsonData from your request (normally this contains the Exception)
10762 loadexception : true
10766 this.proxy = Roo.factory(this.proxy, Roo.data);
10767 this.proxy.xmodule = this.xmodule || false;
10768 this.relayEvents(this.proxy, ["loadexception"]);
10770 this.sortToggle = {};
10771 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
10773 Roo.data.Store.superclass.constructor.call(this);
10775 if(this.inlineData){
10776 this.loadData(this.inlineData);
10777 delete this.inlineData;
10781 Roo.extend(Roo.data.Store, Roo.util.Observable, {
10783 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
10784 * without a remote query - used by combo/forms at present.
10788 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
10791 * @cfg {Array} data Inline data to be loaded when the store is initialized.
10794 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
10795 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
10798 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
10799 * on any HTTP request
10802 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
10805 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
10809 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
10810 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
10812 remoteSort : false,
10815 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
10816 * loaded or when a record is removed. (defaults to false).
10818 pruneModifiedRecords : false,
10821 lastOptions : null,
10824 * Add Records to the Store and fires the add event.
10825 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
10827 add : function(records){
10828 records = [].concat(records);
10829 for(var i = 0, len = records.length; i < len; i++){
10830 records[i].join(this);
10832 var index = this.data.length;
10833 this.data.addAll(records);
10834 this.fireEvent("add", this, records, index);
10838 * Remove a Record from the Store and fires the remove event.
10839 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
10841 remove : function(record){
10842 var index = this.data.indexOf(record);
10843 this.data.removeAt(index);
10844 if(this.pruneModifiedRecords){
10845 this.modified.remove(record);
10847 this.fireEvent("remove", this, record, index);
10851 * Remove all Records from the Store and fires the clear event.
10853 removeAll : function(){
10855 if(this.pruneModifiedRecords){
10856 this.modified = [];
10858 this.fireEvent("clear", this);
10862 * Inserts Records to the Store at the given index and fires the add event.
10863 * @param {Number} index The start index at which to insert the passed Records.
10864 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
10866 insert : function(index, records){
10867 records = [].concat(records);
10868 for(var i = 0, len = records.length; i < len; i++){
10869 this.data.insert(index, records[i]);
10870 records[i].join(this);
10872 this.fireEvent("add", this, records, index);
10876 * Get the index within the cache of the passed Record.
10877 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
10878 * @return {Number} The index of the passed Record. Returns -1 if not found.
10880 indexOf : function(record){
10881 return this.data.indexOf(record);
10885 * Get the index within the cache of the Record with the passed id.
10886 * @param {String} id The id of the Record to find.
10887 * @return {Number} The index of the Record. Returns -1 if not found.
10889 indexOfId : function(id){
10890 return this.data.indexOfKey(id);
10894 * Get the Record with the specified id.
10895 * @param {String} id The id of the Record to find.
10896 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
10898 getById : function(id){
10899 return this.data.key(id);
10903 * Get the Record at the specified index.
10904 * @param {Number} index The index of the Record to find.
10905 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
10907 getAt : function(index){
10908 return this.data.itemAt(index);
10912 * Returns a range of Records between specified indices.
10913 * @param {Number} startIndex (optional) The starting index (defaults to 0)
10914 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
10915 * @return {Roo.data.Record[]} An array of Records
10917 getRange : function(start, end){
10918 return this.data.getRange(start, end);
10922 storeOptions : function(o){
10923 o = Roo.apply({}, o);
10926 this.lastOptions = o;
10930 * Loads the Record cache from the configured Proxy using the configured Reader.
10932 * If using remote paging, then the first load call must specify the <em>start</em>
10933 * and <em>limit</em> properties in the options.params property to establish the initial
10934 * position within the dataset, and the number of Records to cache on each read from the Proxy.
10936 * <strong>It is important to note that for remote data sources, loading is asynchronous,
10937 * and this call will return before the new data has been loaded. Perform any post-processing
10938 * in a callback function, or in a "load" event handler.</strong>
10940 * @param {Object} options An object containing properties which control loading options:<ul>
10941 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
10942 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
10943 * passed the following arguments:<ul>
10944 * <li>r : Roo.data.Record[]</li>
10945 * <li>options: Options object from the load call</li>
10946 * <li>success: Boolean success indicator</li></ul></li>
10947 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
10948 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
10951 load : function(options){
10952 options = options || {};
10953 if(this.fireEvent("beforeload", this, options) !== false){
10954 this.storeOptions(options);
10955 var p = Roo.apply(options.params || {}, this.baseParams);
10956 // if meta was not loaded from remote source.. try requesting it.
10957 if (!this.reader.metaFromRemote) {
10958 p._requestMeta = 1;
10960 if(this.sortInfo && this.remoteSort){
10961 var pn = this.paramNames;
10962 p[pn["sort"]] = this.sortInfo.field;
10963 p[pn["dir"]] = this.sortInfo.direction;
10965 if (this.multiSort) {
10966 var pn = this.paramNames;
10967 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
10970 this.proxy.load(p, this.reader, this.loadRecords, this, options);
10975 * Reloads the Record cache from the configured Proxy using the configured Reader and
10976 * the options from the last load operation performed.
10977 * @param {Object} options (optional) An object containing properties which may override the options
10978 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
10979 * the most recently used options are reused).
10981 reload : function(options){
10982 this.load(Roo.applyIf(options||{}, this.lastOptions));
10986 // Called as a callback by the Reader during a load operation.
10987 loadRecords : function(o, options, success){
10988 if(!o || success === false){
10989 if(success !== false){
10990 this.fireEvent("load", this, [], options, o);
10992 if(options.callback){
10993 options.callback.call(options.scope || this, [], options, false);
10997 // if data returned failure - throw an exception.
10998 if (o.success === false) {
10999 // show a message if no listener is registered.
11000 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
11001 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
11003 // loadmask wil be hooked into this..
11004 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
11007 var r = o.records, t = o.totalRecords || r.length;
11009 this.fireEvent("beforeloadadd", this, r, options, o);
11011 if(!options || options.add !== true){
11012 if(this.pruneModifiedRecords){
11013 this.modified = [];
11015 for(var i = 0, len = r.length; i < len; i++){
11019 this.data = this.snapshot;
11020 delete this.snapshot;
11023 this.data.addAll(r);
11024 this.totalLength = t;
11026 this.fireEvent("datachanged", this);
11028 this.totalLength = Math.max(t, this.data.length+r.length);
11032 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
11034 var e = new Roo.data.Record({});
11036 e.set(this.parent.displayField, this.parent.emptyTitle);
11037 e.set(this.parent.valueField, '');
11042 this.fireEvent("load", this, r, options, o);
11043 if(options.callback){
11044 options.callback.call(options.scope || this, r, options, true);
11050 * Loads data from a passed data block. A Reader which understands the format of the data
11051 * must have been configured in the constructor.
11052 * @param {Object} data The data block from which to read the Records. The format of the data expected
11053 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
11054 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
11056 loadData : function(o, append){
11057 var r = this.reader.readRecords(o);
11058 this.loadRecords(r, {add: append}, true);
11062 * Gets the number of cached records.
11064 * <em>If using paging, this may not be the total size of the dataset. If the data object
11065 * used by the Reader contains the dataset size, then the getTotalCount() function returns
11066 * the data set size</em>
11068 getCount : function(){
11069 return this.data.length || 0;
11073 * Gets the total number of records in the dataset as returned by the server.
11075 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
11076 * the dataset size</em>
11078 getTotalCount : function(){
11079 return this.totalLength || 0;
11083 * Returns the sort state of the Store as an object with two properties:
11085 field {String} The name of the field by which the Records are sorted
11086 direction {String} The sort order, "ASC" or "DESC"
11089 getSortState : function(){
11090 return this.sortInfo;
11094 applySort : function(){
11095 if(this.sortInfo && !this.remoteSort){
11096 var s = this.sortInfo, f = s.field;
11097 var st = this.fields.get(f).sortType;
11098 var fn = function(r1, r2){
11099 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
11100 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
11102 this.data.sort(s.direction, fn);
11103 if(this.snapshot && this.snapshot != this.data){
11104 this.snapshot.sort(s.direction, fn);
11110 * Sets the default sort column and order to be used by the next load operation.
11111 * @param {String} fieldName The name of the field to sort by.
11112 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11114 setDefaultSort : function(field, dir){
11115 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
11119 * Sort the Records.
11120 * If remote sorting is used, the sort is performed on the server, and the cache is
11121 * reloaded. If local sorting is used, the cache is sorted internally.
11122 * @param {String} fieldName The name of the field to sort by.
11123 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11125 sort : function(fieldName, dir){
11126 var f = this.fields.get(fieldName);
11128 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
11130 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
11131 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
11136 this.sortToggle[f.name] = dir;
11137 this.sortInfo = {field: f.name, direction: dir};
11138 if(!this.remoteSort){
11140 this.fireEvent("datachanged", this);
11142 this.load(this.lastOptions);
11147 * Calls the specified function for each of the Records in the cache.
11148 * @param {Function} fn The function to call. The Record is passed as the first parameter.
11149 * Returning <em>false</em> aborts and exits the iteration.
11150 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
11152 each : function(fn, scope){
11153 this.data.each(fn, scope);
11157 * Gets all records modified since the last commit. Modified records are persisted across load operations
11158 * (e.g., during paging).
11159 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
11161 getModifiedRecords : function(){
11162 return this.modified;
11166 createFilterFn : function(property, value, anyMatch){
11167 if(!value.exec){ // not a regex
11168 value = String(value);
11169 if(value.length == 0){
11172 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
11174 return function(r){
11175 return value.test(r.data[property]);
11180 * Sums the value of <i>property</i> for each record between start and end and returns the result.
11181 * @param {String} property A field on your records
11182 * @param {Number} start The record index to start at (defaults to 0)
11183 * @param {Number} end The last record index to include (defaults to length - 1)
11184 * @return {Number} The sum
11186 sum : function(property, start, end){
11187 var rs = this.data.items, v = 0;
11188 start = start || 0;
11189 end = (end || end === 0) ? end : rs.length-1;
11191 for(var i = start; i <= end; i++){
11192 v += (rs[i].data[property] || 0);
11198 * Filter the records by a specified property.
11199 * @param {String} field A field on your records
11200 * @param {String/RegExp} value Either a string that the field
11201 * should start with or a RegExp to test against the field
11202 * @param {Boolean} anyMatch True to match any part not just the beginning
11204 filter : function(property, value, anyMatch){
11205 var fn = this.createFilterFn(property, value, anyMatch);
11206 return fn ? this.filterBy(fn) : this.clearFilter();
11210 * Filter by a function. The specified function will be called with each
11211 * record in this data source. If the function returns true the record is included,
11212 * otherwise it is filtered.
11213 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11214 * @param {Object} scope (optional) The scope of the function (defaults to this)
11216 filterBy : function(fn, scope){
11217 this.snapshot = this.snapshot || this.data;
11218 this.data = this.queryBy(fn, scope||this);
11219 this.fireEvent("datachanged", this);
11223 * Query the records by a specified property.
11224 * @param {String} field A field on your records
11225 * @param {String/RegExp} value Either a string that the field
11226 * should start with or a RegExp to test against the field
11227 * @param {Boolean} anyMatch True to match any part not just the beginning
11228 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11230 query : function(property, value, anyMatch){
11231 var fn = this.createFilterFn(property, value, anyMatch);
11232 return fn ? this.queryBy(fn) : this.data.clone();
11236 * Query by a function. The specified function will be called with each
11237 * record in this data source. If the function returns true the record is included
11239 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11240 * @param {Object} scope (optional) The scope of the function (defaults to this)
11241 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11243 queryBy : function(fn, scope){
11244 var data = this.snapshot || this.data;
11245 return data.filterBy(fn, scope||this);
11249 * Collects unique values for a particular dataIndex from this store.
11250 * @param {String} dataIndex The property to collect
11251 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
11252 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
11253 * @return {Array} An array of the unique values
11255 collect : function(dataIndex, allowNull, bypassFilter){
11256 var d = (bypassFilter === true && this.snapshot) ?
11257 this.snapshot.items : this.data.items;
11258 var v, sv, r = [], l = {};
11259 for(var i = 0, len = d.length; i < len; i++){
11260 v = d[i].data[dataIndex];
11262 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
11271 * Revert to a view of the Record cache with no filtering applied.
11272 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
11274 clearFilter : function(suppressEvent){
11275 if(this.snapshot && this.snapshot != this.data){
11276 this.data = this.snapshot;
11277 delete this.snapshot;
11278 if(suppressEvent !== true){
11279 this.fireEvent("datachanged", this);
11285 afterEdit : function(record){
11286 if(this.modified.indexOf(record) == -1){
11287 this.modified.push(record);
11289 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
11293 afterReject : function(record){
11294 this.modified.remove(record);
11295 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
11299 afterCommit : function(record){
11300 this.modified.remove(record);
11301 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
11305 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
11306 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
11308 commitChanges : function(){
11309 var m = this.modified.slice(0);
11310 this.modified = [];
11311 for(var i = 0, len = m.length; i < len; i++){
11317 * Cancel outstanding changes on all changed records.
11319 rejectChanges : function(){
11320 var m = this.modified.slice(0);
11321 this.modified = [];
11322 for(var i = 0, len = m.length; i < len; i++){
11327 onMetaChange : function(meta, rtype, o){
11328 this.recordType = rtype;
11329 this.fields = rtype.prototype.fields;
11330 delete this.snapshot;
11331 this.sortInfo = meta.sortInfo || this.sortInfo;
11332 this.modified = [];
11333 this.fireEvent('metachange', this, this.reader.meta);
11336 moveIndex : function(data, type)
11338 var index = this.indexOf(data);
11340 var newIndex = index + type;
11344 this.insert(newIndex, data);
11349 * Ext JS Library 1.1.1
11350 * Copyright(c) 2006-2007, Ext JS, LLC.
11352 * Originally Released Under LGPL - original licence link has changed is not relivant.
11355 * <script type="text/javascript">
11359 * @class Roo.data.SimpleStore
11360 * @extends Roo.data.Store
11361 * Small helper class to make creating Stores from Array data easier.
11362 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
11363 * @cfg {Array} fields An array of field definition objects, or field name strings.
11364 * @cfg {Array} data The multi-dimensional array of data
11366 * @param {Object} config
11368 Roo.data.SimpleStore = function(config){
11369 Roo.data.SimpleStore.superclass.constructor.call(this, {
11371 reader: new Roo.data.ArrayReader({
11374 Roo.data.Record.create(config.fields)
11376 proxy : new Roo.data.MemoryProxy(config.data)
11380 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
11382 * Ext JS Library 1.1.1
11383 * Copyright(c) 2006-2007, Ext JS, LLC.
11385 * Originally Released Under LGPL - original licence link has changed is not relivant.
11388 * <script type="text/javascript">
11393 * @extends Roo.data.Store
11394 * @class Roo.data.JsonStore
11395 * Small helper class to make creating Stores for JSON data easier. <br/>
11397 var store = new Roo.data.JsonStore({
11398 url: 'get-images.php',
11400 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
11403 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
11404 * JsonReader and HttpProxy (unless inline data is provided).</b>
11405 * @cfg {Array} fields An array of field definition objects, or field name strings.
11407 * @param {Object} config
11409 Roo.data.JsonStore = function(c){
11410 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
11411 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
11412 reader: new Roo.data.JsonReader(c, c.fields)
11415 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
11417 * Ext JS Library 1.1.1
11418 * Copyright(c) 2006-2007, Ext JS, LLC.
11420 * Originally Released Under LGPL - original licence link has changed is not relivant.
11423 * <script type="text/javascript">
11427 Roo.data.Field = function(config){
11428 if(typeof config == "string"){
11429 config = {name: config};
11431 Roo.apply(this, config);
11434 this.type = "auto";
11437 var st = Roo.data.SortTypes;
11438 // named sortTypes are supported, here we look them up
11439 if(typeof this.sortType == "string"){
11440 this.sortType = st[this.sortType];
11443 // set default sortType for strings and dates
11444 if(!this.sortType){
11447 this.sortType = st.asUCString;
11450 this.sortType = st.asDate;
11453 this.sortType = st.none;
11458 var stripRe = /[\$,%]/g;
11460 // prebuilt conversion function for this field, instead of
11461 // switching every time we're reading a value
11463 var cv, dateFormat = this.dateFormat;
11468 cv = function(v){ return v; };
11471 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
11475 return v !== undefined && v !== null && v !== '' ?
11476 parseInt(String(v).replace(stripRe, ""), 10) : '';
11481 return v !== undefined && v !== null && v !== '' ?
11482 parseFloat(String(v).replace(stripRe, ""), 10) : '';
11487 cv = function(v){ return v === true || v === "true" || v == 1; };
11494 if(v instanceof Date){
11498 if(dateFormat == "timestamp"){
11499 return new Date(v*1000);
11501 return Date.parseDate(v, dateFormat);
11503 var parsed = Date.parse(v);
11504 return parsed ? new Date(parsed) : null;
11513 Roo.data.Field.prototype = {
11521 * Ext JS Library 1.1.1
11522 * Copyright(c) 2006-2007, Ext JS, LLC.
11524 * Originally Released Under LGPL - original licence link has changed is not relivant.
11527 * <script type="text/javascript">
11530 // Base class for reading structured data from a data source. This class is intended to be
11531 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
11534 * @class Roo.data.DataReader
11535 * Base class for reading structured data from a data source. This class is intended to be
11536 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
11539 Roo.data.DataReader = function(meta, recordType){
11543 this.recordType = recordType instanceof Array ?
11544 Roo.data.Record.create(recordType) : recordType;
11547 Roo.data.DataReader.prototype = {
11549 * Create an empty record
11550 * @param {Object} data (optional) - overlay some values
11551 * @return {Roo.data.Record} record created.
11553 newRow : function(d) {
11555 this.recordType.prototype.fields.each(function(c) {
11557 case 'int' : da[c.name] = 0; break;
11558 case 'date' : da[c.name] = new Date(); break;
11559 case 'float' : da[c.name] = 0.0; break;
11560 case 'boolean' : da[c.name] = false; break;
11561 default : da[c.name] = ""; break;
11565 return new this.recordType(Roo.apply(da, d));
11570 * Ext JS Library 1.1.1
11571 * Copyright(c) 2006-2007, Ext JS, LLC.
11573 * Originally Released Under LGPL - original licence link has changed is not relivant.
11576 * <script type="text/javascript">
11580 * @class Roo.data.DataProxy
11581 * @extends Roo.data.Observable
11582 * This class is an abstract base class for implementations which provide retrieval of
11583 * unformatted data objects.<br>
11585 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
11586 * (of the appropriate type which knows how to parse the data object) to provide a block of
11587 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
11589 * Custom implementations must implement the load method as described in
11590 * {@link Roo.data.HttpProxy#load}.
11592 Roo.data.DataProxy = function(){
11595 * @event beforeload
11596 * Fires before a network request is made to retrieve a data object.
11597 * @param {Object} This DataProxy object.
11598 * @param {Object} params The params parameter to the load function.
11603 * Fires before the load method's callback is called.
11604 * @param {Object} This DataProxy object.
11605 * @param {Object} o The data object.
11606 * @param {Object} arg The callback argument object passed to the load function.
11610 * @event loadexception
11611 * Fires if an Exception occurs during data retrieval.
11612 * @param {Object} This DataProxy object.
11613 * @param {Object} o The data object.
11614 * @param {Object} arg The callback argument object passed to the load function.
11615 * @param {Object} e The Exception.
11617 loadexception : true
11619 Roo.data.DataProxy.superclass.constructor.call(this);
11622 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
11625 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
11629 * Ext JS Library 1.1.1
11630 * Copyright(c) 2006-2007, Ext JS, LLC.
11632 * Originally Released Under LGPL - original licence link has changed is not relivant.
11635 * <script type="text/javascript">
11638 * @class Roo.data.MemoryProxy
11639 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
11640 * to the Reader when its load method is called.
11642 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
11644 Roo.data.MemoryProxy = function(data){
11648 Roo.data.MemoryProxy.superclass.constructor.call(this);
11652 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
11655 * Load data from the requested source (in this case an in-memory
11656 * data object passed to the constructor), read the data object into
11657 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
11658 * process that block using the passed callback.
11659 * @param {Object} params This parameter is not used by the MemoryProxy class.
11660 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11661 * object into a block of Roo.data.Records.
11662 * @param {Function} callback The function into which to pass the block of Roo.data.records.
11663 * The function must be passed <ul>
11664 * <li>The Record block object</li>
11665 * <li>The "arg" argument from the load function</li>
11666 * <li>A boolean success indicator</li>
11668 * @param {Object} scope The scope in which to call the callback
11669 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11671 load : function(params, reader, callback, scope, arg){
11672 params = params || {};
11675 result = reader.readRecords(this.data);
11677 this.fireEvent("loadexception", this, arg, null, e);
11678 callback.call(scope, null, arg, false);
11681 callback.call(scope, result, arg, true);
11685 update : function(params, records){
11690 * Ext JS Library 1.1.1
11691 * Copyright(c) 2006-2007, Ext JS, LLC.
11693 * Originally Released Under LGPL - original licence link has changed is not relivant.
11696 * <script type="text/javascript">
11699 * @class Roo.data.HttpProxy
11700 * @extends Roo.data.DataProxy
11701 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
11702 * configured to reference a certain URL.<br><br>
11704 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
11705 * from which the running page was served.<br><br>
11707 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
11709 * Be aware that to enable the browser to parse an XML document, the server must set
11710 * the Content-Type header in the HTTP response to "text/xml".
11712 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
11713 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
11714 * will be used to make the request.
11716 Roo.data.HttpProxy = function(conn){
11717 Roo.data.HttpProxy.superclass.constructor.call(this);
11718 // is conn a conn config or a real conn?
11720 this.useAjax = !conn || !conn.events;
11724 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
11725 // thse are take from connection...
11728 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
11731 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
11732 * extra parameters to each request made by this object. (defaults to undefined)
11735 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
11736 * to each request made by this object. (defaults to undefined)
11739 * @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)
11742 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11745 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
11751 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11755 * Return the {@link Roo.data.Connection} object being used by this Proxy.
11756 * @return {Connection} The Connection object. This object may be used to subscribe to events on
11757 * a finer-grained basis than the DataProxy events.
11759 getConnection : function(){
11760 return this.useAjax ? Roo.Ajax : this.conn;
11764 * Load data from the configured {@link Roo.data.Connection}, read the data object into
11765 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
11766 * process that block using the passed callback.
11767 * @param {Object} params An object containing properties which are to be used as HTTP parameters
11768 * for the request to the remote server.
11769 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11770 * object into a block of Roo.data.Records.
11771 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
11772 * The function must be passed <ul>
11773 * <li>The Record block object</li>
11774 * <li>The "arg" argument from the load function</li>
11775 * <li>A boolean success indicator</li>
11777 * @param {Object} scope The scope in which to call the callback
11778 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11780 load : function(params, reader, callback, scope, arg){
11781 if(this.fireEvent("beforeload", this, params) !== false){
11783 params : params || {},
11785 callback : callback,
11790 callback : this.loadResponse,
11794 Roo.applyIf(o, this.conn);
11795 if(this.activeRequest){
11796 Roo.Ajax.abort(this.activeRequest);
11798 this.activeRequest = Roo.Ajax.request(o);
11800 this.conn.request(o);
11803 callback.call(scope||this, null, arg, false);
11808 loadResponse : function(o, success, response){
11809 delete this.activeRequest;
11811 this.fireEvent("loadexception", this, o, response);
11812 o.request.callback.call(o.request.scope, null, o.request.arg, false);
11817 result = o.reader.read(response);
11819 this.fireEvent("loadexception", this, o, response, e);
11820 o.request.callback.call(o.request.scope, null, o.request.arg, false);
11824 this.fireEvent("load", this, o, o.request.arg);
11825 o.request.callback.call(o.request.scope, result, o.request.arg, true);
11829 update : function(dataSet){
11834 updateResponse : function(dataSet){
11839 * Ext JS Library 1.1.1
11840 * Copyright(c) 2006-2007, Ext JS, LLC.
11842 * Originally Released Under LGPL - original licence link has changed is not relivant.
11845 * <script type="text/javascript">
11849 * @class Roo.data.ScriptTagProxy
11850 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
11851 * other than the originating domain of the running page.<br><br>
11853 * <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
11854 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
11856 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
11857 * source code that is used as the source inside a <script> tag.<br><br>
11859 * In order for the browser to process the returned data, the server must wrap the data object
11860 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
11861 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
11862 * depending on whether the callback name was passed:
11865 boolean scriptTag = false;
11866 String cb = request.getParameter("callback");
11869 response.setContentType("text/javascript");
11871 response.setContentType("application/x-json");
11873 Writer out = response.getWriter();
11875 out.write(cb + "(");
11877 out.print(dataBlock.toJsonString());
11884 * @param {Object} config A configuration object.
11886 Roo.data.ScriptTagProxy = function(config){
11887 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
11888 Roo.apply(this, config);
11889 this.head = document.getElementsByTagName("head")[0];
11892 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
11894 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
11896 * @cfg {String} url The URL from which to request the data object.
11899 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
11903 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
11904 * the server the name of the callback function set up by the load call to process the returned data object.
11905 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
11906 * javascript output which calls this named function passing the data object as its only parameter.
11908 callbackParam : "callback",
11910 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
11911 * name to the request.
11916 * Load data from the configured URL, read the data object into
11917 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
11918 * process that block using the passed callback.
11919 * @param {Object} params An object containing properties which are to be used as HTTP parameters
11920 * for the request to the remote server.
11921 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11922 * object into a block of Roo.data.Records.
11923 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
11924 * The function must be passed <ul>
11925 * <li>The Record block object</li>
11926 * <li>The "arg" argument from the load function</li>
11927 * <li>A boolean success indicator</li>
11929 * @param {Object} scope The scope in which to call the callback
11930 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11932 load : function(params, reader, callback, scope, arg){
11933 if(this.fireEvent("beforeload", this, params) !== false){
11935 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
11937 var url = this.url;
11938 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
11940 url += "&_dc=" + (new Date().getTime());
11942 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
11945 cb : "stcCallback"+transId,
11946 scriptId : "stcScript"+transId,
11950 callback : callback,
11956 window[trans.cb] = function(o){
11957 conn.handleResponse(o, trans);
11960 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
11962 if(this.autoAbort !== false){
11966 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
11968 var script = document.createElement("script");
11969 script.setAttribute("src", url);
11970 script.setAttribute("type", "text/javascript");
11971 script.setAttribute("id", trans.scriptId);
11972 this.head.appendChild(script);
11974 this.trans = trans;
11976 callback.call(scope||this, null, arg, false);
11981 isLoading : function(){
11982 return this.trans ? true : false;
11986 * Abort the current server request.
11988 abort : function(){
11989 if(this.isLoading()){
11990 this.destroyTrans(this.trans);
11995 destroyTrans : function(trans, isLoaded){
11996 this.head.removeChild(document.getElementById(trans.scriptId));
11997 clearTimeout(trans.timeoutId);
11999 window[trans.cb] = undefined;
12001 delete window[trans.cb];
12004 // if hasn't been loaded, wait for load to remove it to prevent script error
12005 window[trans.cb] = function(){
12006 window[trans.cb] = undefined;
12008 delete window[trans.cb];
12015 handleResponse : function(o, trans){
12016 this.trans = false;
12017 this.destroyTrans(trans, true);
12020 result = trans.reader.readRecords(o);
12022 this.fireEvent("loadexception", this, o, trans.arg, e);
12023 trans.callback.call(trans.scope||window, null, trans.arg, false);
12026 this.fireEvent("load", this, o, trans.arg);
12027 trans.callback.call(trans.scope||window, result, trans.arg, true);
12031 handleFailure : function(trans){
12032 this.trans = false;
12033 this.destroyTrans(trans, false);
12034 this.fireEvent("loadexception", this, null, trans.arg);
12035 trans.callback.call(trans.scope||window, null, trans.arg, false);
12039 * Ext JS Library 1.1.1
12040 * Copyright(c) 2006-2007, Ext JS, LLC.
12042 * Originally Released Under LGPL - original licence link has changed is not relivant.
12045 * <script type="text/javascript">
12049 * @class Roo.data.JsonReader
12050 * @extends Roo.data.DataReader
12051 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
12052 * based on mappings in a provided Roo.data.Record constructor.
12054 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
12055 * in the reply previously.
12060 var RecordDef = Roo.data.Record.create([
12061 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
12062 {name: 'occupation'} // This field will use "occupation" as the mapping.
12064 var myReader = new Roo.data.JsonReader({
12065 totalProperty: "results", // The property which contains the total dataset size (optional)
12066 root: "rows", // The property which contains an Array of row objects
12067 id: "id" // The property within each row object that provides an ID for the record (optional)
12071 * This would consume a JSON file like this:
12073 { 'results': 2, 'rows': [
12074 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
12075 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
12078 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
12079 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
12080 * paged from the remote server.
12081 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
12082 * @cfg {String} root name of the property which contains the Array of row objects.
12083 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
12084 * @cfg {Array} fields Array of field definition objects
12086 * Create a new JsonReader
12087 * @param {Object} meta Metadata configuration options
12088 * @param {Object} recordType Either an Array of field definition objects,
12089 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
12091 Roo.data.JsonReader = function(meta, recordType){
12094 // set some defaults:
12095 Roo.applyIf(meta, {
12096 totalProperty: 'total',
12097 successProperty : 'success',
12102 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
12104 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
12107 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
12108 * Used by Store query builder to append _requestMeta to params.
12111 metaFromRemote : false,
12113 * This method is only used by a DataProxy which has retrieved data from a remote server.
12114 * @param {Object} response The XHR object which contains the JSON data in its responseText.
12115 * @return {Object} data A data block which is used by an Roo.data.Store object as
12116 * a cache of Roo.data.Records.
12118 read : function(response){
12119 var json = response.responseText;
12121 var o = /* eval:var:o */ eval("("+json+")");
12123 throw {message: "JsonReader.read: Json object not found"};
12129 this.metaFromRemote = true;
12130 this.meta = o.metaData;
12131 this.recordType = Roo.data.Record.create(o.metaData.fields);
12132 this.onMetaChange(this.meta, this.recordType, o);
12134 return this.readRecords(o);
12137 // private function a store will implement
12138 onMetaChange : function(meta, recordType, o){
12145 simpleAccess: function(obj, subsc) {
12152 getJsonAccessor: function(){
12154 return function(expr) {
12156 return(re.test(expr))
12157 ? new Function("obj", "return obj." + expr)
12162 return Roo.emptyFn;
12167 * Create a data block containing Roo.data.Records from an XML document.
12168 * @param {Object} o An object which contains an Array of row objects in the property specified
12169 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
12170 * which contains the total size of the dataset.
12171 * @return {Object} data A data block which is used by an Roo.data.Store object as
12172 * a cache of Roo.data.Records.
12174 readRecords : function(o){
12176 * After any data loads, the raw JSON data is available for further custom processing.
12180 var s = this.meta, Record = this.recordType,
12181 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
12183 // Generate extraction functions for the totalProperty, the root, the id, and for each field
12185 if(s.totalProperty) {
12186 this.getTotal = this.getJsonAccessor(s.totalProperty);
12188 if(s.successProperty) {
12189 this.getSuccess = this.getJsonAccessor(s.successProperty);
12191 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
12193 var g = this.getJsonAccessor(s.id);
12194 this.getId = function(rec) {
12196 return (r === undefined || r === "") ? null : r;
12199 this.getId = function(){return null;};
12202 for(var jj = 0; jj < fl; jj++){
12204 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
12205 this.ef[jj] = this.getJsonAccessor(map);
12209 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
12210 if(s.totalProperty){
12211 var vt = parseInt(this.getTotal(o), 10);
12216 if(s.successProperty){
12217 var vs = this.getSuccess(o);
12218 if(vs === false || vs === 'false'){
12223 for(var i = 0; i < c; i++){
12226 var id = this.getId(n);
12227 for(var j = 0; j < fl; j++){
12229 var v = this.ef[j](n);
12231 Roo.log('missing convert for ' + f.name);
12235 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
12237 var record = new Record(values, id);
12239 records[i] = record;
12245 totalRecords : totalRecords
12250 * Ext JS Library 1.1.1
12251 * Copyright(c) 2006-2007, Ext JS, LLC.
12253 * Originally Released Under LGPL - original licence link has changed is not relivant.
12256 * <script type="text/javascript">
12260 * @class Roo.data.ArrayReader
12261 * @extends Roo.data.DataReader
12262 * Data reader class to create an Array of Roo.data.Record objects from an Array.
12263 * Each element of that Array represents a row of data fields. The
12264 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
12265 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
12269 var RecordDef = Roo.data.Record.create([
12270 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
12271 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
12273 var myReader = new Roo.data.ArrayReader({
12274 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
12278 * This would consume an Array like this:
12280 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
12282 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
12284 * Create a new JsonReader
12285 * @param {Object} meta Metadata configuration options.
12286 * @param {Object} recordType Either an Array of field definition objects
12287 * as specified to {@link Roo.data.Record#create},
12288 * or an {@link Roo.data.Record} object
12289 * created using {@link Roo.data.Record#create}.
12291 Roo.data.ArrayReader = function(meta, recordType){
12292 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
12295 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
12297 * Create a data block containing Roo.data.Records from an XML document.
12298 * @param {Object} o An Array of row objects which represents the dataset.
12299 * @return {Object} data A data block which is used by an Roo.data.Store object as
12300 * a cache of Roo.data.Records.
12302 readRecords : function(o){
12303 var sid = this.meta ? this.meta.id : null;
12304 var recordType = this.recordType, fields = recordType.prototype.fields;
12307 for(var i = 0; i < root.length; i++){
12310 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
12311 for(var j = 0, jlen = fields.length; j < jlen; j++){
12312 var f = fields.items[j];
12313 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
12314 var v = n[k] !== undefined ? n[k] : f.defaultValue;
12316 values[f.name] = v;
12318 var record = new recordType(values, id);
12320 records[records.length] = record;
12324 totalRecords : records.length
12333 * @class Roo.bootstrap.ComboBox
12334 * @extends Roo.bootstrap.TriggerField
12335 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
12336 * @cfg {Boolean} append (true|false) default false
12337 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12338 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
12339 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
12340 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
12341 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
12342 * @cfg {Boolean} animate default true
12343 * @cfg {Boolean} emptyResultText only for touch device
12344 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
12345 * @cfg {String} emptyTitle default ''
12347 * Create a new ComboBox.
12348 * @param {Object} config Configuration options
12350 Roo.bootstrap.ComboBox = function(config){
12351 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
12355 * Fires when the dropdown list is expanded
12356 * @param {Roo.bootstrap.ComboBox} combo This combo box
12361 * Fires when the dropdown list is collapsed
12362 * @param {Roo.bootstrap.ComboBox} combo This combo box
12366 * @event beforeselect
12367 * Fires before a list item is selected. Return false to cancel the selection.
12368 * @param {Roo.bootstrap.ComboBox} combo This combo box
12369 * @param {Roo.data.Record} record The data record returned from the underlying store
12370 * @param {Number} index The index of the selected item in the dropdown list
12372 'beforeselect' : true,
12375 * Fires when a list item is selected
12376 * @param {Roo.bootstrap.ComboBox} combo This combo box
12377 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
12378 * @param {Number} index The index of the selected item in the dropdown list
12382 * @event beforequery
12383 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
12384 * The event object passed has these properties:
12385 * @param {Roo.bootstrap.ComboBox} combo This combo box
12386 * @param {String} query The query
12387 * @param {Boolean} forceAll true to force "all" query
12388 * @param {Boolean} cancel true to cancel the query
12389 * @param {Object} e The query event object
12391 'beforequery': true,
12394 * Fires when the 'add' icon is pressed (add a listener to enable add button)
12395 * @param {Roo.bootstrap.ComboBox} combo This combo box
12400 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
12401 * @param {Roo.bootstrap.ComboBox} combo This combo box
12402 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
12407 * Fires when the remove value from the combobox array
12408 * @param {Roo.bootstrap.ComboBox} combo This combo box
12412 * @event afterremove
12413 * Fires when the remove value from the combobox array
12414 * @param {Roo.bootstrap.ComboBox} combo This combo box
12416 'afterremove' : true,
12418 * @event specialfilter
12419 * Fires when specialfilter
12420 * @param {Roo.bootstrap.ComboBox} combo This combo box
12422 'specialfilter' : true,
12425 * Fires when tick the element
12426 * @param {Roo.bootstrap.ComboBox} combo This combo box
12430 * @event touchviewdisplay
12431 * Fires when touch view require special display (default is using displayField)
12432 * @param {Roo.bootstrap.ComboBox} combo This combo box
12433 * @param {Object} cfg set html .
12435 'touchviewdisplay' : true
12440 this.tickItems = [];
12442 this.selectedIndex = -1;
12443 if(this.mode == 'local'){
12444 if(config.queryDelay === undefined){
12445 this.queryDelay = 10;
12447 if(config.minChars === undefined){
12453 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
12456 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
12457 * rendering into an Roo.Editor, defaults to false)
12460 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
12461 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
12464 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
12467 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
12468 * the dropdown list (defaults to undefined, with no header element)
12472 * @cfg {String/Roo.Template} tpl The template to use to render the output
12476 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
12478 listWidth: undefined,
12480 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
12481 * mode = 'remote' or 'text' if mode = 'local')
12483 displayField: undefined,
12486 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
12487 * mode = 'remote' or 'value' if mode = 'local').
12488 * Note: use of a valueField requires the user make a selection
12489 * in order for a value to be mapped.
12491 valueField: undefined,
12493 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
12498 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
12499 * field's data value (defaults to the underlying DOM element's name)
12501 hiddenName: undefined,
12503 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
12507 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
12509 selectedClass: 'active',
12512 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
12516 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
12517 * anchor positions (defaults to 'tl-bl')
12519 listAlign: 'tl-bl?',
12521 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
12525 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
12526 * query specified by the allQuery config option (defaults to 'query')
12528 triggerAction: 'query',
12530 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
12531 * (defaults to 4, does not apply if editable = false)
12535 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
12536 * delay (typeAheadDelay) if it matches a known value (defaults to false)
12540 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
12541 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
12545 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
12546 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
12550 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
12551 * when editable = true (defaults to false)
12553 selectOnFocus:false,
12555 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
12557 queryParam: 'query',
12559 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
12560 * when mode = 'remote' (defaults to 'Loading...')
12562 loadingText: 'Loading...',
12564 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
12568 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
12572 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
12573 * traditional select (defaults to true)
12577 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
12581 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
12585 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
12586 * listWidth has a higher value)
12590 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
12591 * allow the user to set arbitrary text into the field (defaults to false)
12593 forceSelection:false,
12595 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
12596 * if typeAhead = true (defaults to 250)
12598 typeAheadDelay : 250,
12600 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
12601 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
12603 valueNotFoundText : undefined,
12605 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
12607 blockFocus : false,
12610 * @cfg {Boolean} disableClear Disable showing of clear button.
12612 disableClear : false,
12614 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
12616 alwaysQuery : false,
12619 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
12624 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
12626 invalidClass : "has-warning",
12629 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
12631 validClass : "has-success",
12634 * @cfg {Boolean} specialFilter (true|false) special filter default false
12636 specialFilter : false,
12639 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
12641 mobileTouchView : true,
12644 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
12646 useNativeIOS : false,
12648 ios_options : false,
12660 btnPosition : 'right',
12661 triggerList : true,
12662 showToggleBtn : true,
12664 emptyResultText: 'Empty',
12665 triggerText : 'Select',
12668 // element that contains real text value.. (when hidden is used..)
12670 getAutoCreate : function()
12675 * Render classic select for iso
12678 if(Roo.isIOS && this.useNativeIOS){
12679 cfg = this.getAutoCreateNativeIOS();
12687 if(Roo.isTouch && this.mobileTouchView){
12688 cfg = this.getAutoCreateTouchView();
12695 if(!this.tickable){
12696 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
12697 if(this.name == 'info_year_invest_id_display_name'){
12698 Roo.log('cfg.................................................');
12705 * ComboBox with tickable selections
12708 var align = this.labelAlign || this.parentLabelAlign();
12711 cls : 'form-group roo-combobox-tickable' //input-group
12714 var btn_text_select = '';
12715 var btn_text_done = '';
12716 var btn_text_cancel = '';
12718 if (this.btn_text_show) {
12719 btn_text_select = 'Select';
12720 btn_text_done = 'Done';
12721 btn_text_cancel = 'Cancel';
12726 cls : 'tickable-buttons',
12731 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
12732 //html : this.triggerText
12733 html: btn_text_select
12739 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
12741 html: btn_text_done
12747 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
12749 html: btn_text_cancel
12755 buttons.cn.unshift({
12757 cls: 'roo-select2-search-field-input'
12763 Roo.each(buttons.cn, function(c){
12765 c.cls += ' btn-' + _this.size;
12768 if (_this.disabled) {
12779 cls: 'form-hidden-field'
12783 cls: 'roo-select2-choices',
12787 cls: 'roo-select2-search-field',
12798 cls: 'roo-select2-container input-group roo-select2-container-multi',
12803 // cls: 'typeahead typeahead-long dropdown-menu',
12804 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
12809 if(this.hasFeedback && !this.allowBlank){
12813 cls: 'glyphicon form-control-feedback'
12816 combobox.cn.push(feedback);
12820 if (align ==='left' && this.fieldLabel.length) {
12822 cfg.cls += ' roo-form-group-label-left';
12827 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
12828 tooltip : 'This field is required'
12833 cls : 'control-label',
12834 html : this.fieldLabel
12846 var labelCfg = cfg.cn[1];
12847 var contentCfg = cfg.cn[2];
12850 if(this.indicatorpos == 'right'){
12856 cls : 'control-label',
12860 html : this.fieldLabel
12864 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
12865 tooltip : 'This field is required'
12880 labelCfg = cfg.cn[0];
12881 contentCfg = cfg.cn[1];
12885 if(this.labelWidth > 12){
12886 labelCfg.style = "width: " + this.labelWidth + 'px';
12889 if(this.labelWidth < 13 && this.labelmd == 0){
12890 this.labelmd = this.labelWidth;
12893 if(this.labellg > 0){
12894 labelCfg.cls += ' col-lg-' + this.labellg;
12895 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
12898 if(this.labelmd > 0){
12899 labelCfg.cls += ' col-md-' + this.labelmd;
12900 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
12903 if(this.labelsm > 0){
12904 labelCfg.cls += ' col-sm-' + this.labelsm;
12905 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
12908 if(this.labelxs > 0){
12909 labelCfg.cls += ' col-xs-' + this.labelxs;
12910 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
12914 } else if ( this.fieldLabel.length) {
12915 // Roo.log(" label");
12919 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
12920 tooltip : 'This field is required'
12924 //cls : 'input-group-addon',
12925 html : this.fieldLabel
12933 if(this.indicatorpos == 'right'){
12938 //cls : 'input-group-addon',
12942 html : this.fieldLabel
12946 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
12947 tooltip : 'This field is required'
12962 // Roo.log(" no label && no align");
12969 ['xs','sm','md','lg'].map(function(size){
12970 if (settings[size]) {
12971 cfg.cls += ' col-' + size + '-' + settings[size];
12979 _initEventsCalled : false,
12982 initEvents: function()
12984 if (this._initEventsCalled) { // as we call render... prevent looping...
12987 this._initEventsCalled = true;
12990 throw "can not find store for combo";
12993 this.store = Roo.factory(this.store, Roo.data);
12994 this.store.parent = this;
12996 // if we are building from html. then this element is so complex, that we can not really
12997 // use the rendered HTML.
12998 // so we have to trash and replace the previous code.
12999 if (Roo.XComponent.build_from_html) {
13001 // remove this element....
13002 var e = this.el.dom, k=0;
13003 while (e ) { e = e.previousSibling; ++k;}
13008 this.rendered = false;
13010 this.render(this.parent().getChildContainer(true), k);
13016 if(Roo.isIOS && this.useNativeIOS){
13017 this.initIOSView();
13025 if(Roo.isTouch && this.mobileTouchView){
13026 this.initTouchView();
13031 this.initTickableEvents();
13035 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
13037 if(this.hiddenName){
13039 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13041 this.hiddenField.dom.value =
13042 this.hiddenValue !== undefined ? this.hiddenValue :
13043 this.value !== undefined ? this.value : '';
13045 // prevent input submission
13046 this.el.dom.removeAttribute('name');
13047 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13052 // this.el.dom.setAttribute('autocomplete', 'off');
13055 var cls = 'x-combo-list';
13057 //this.list = new Roo.Layer({
13058 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
13064 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13065 _this.list.setWidth(lw);
13068 this.list.on('mouseover', this.onViewOver, this);
13069 this.list.on('mousemove', this.onViewMove, this);
13071 this.list.on('scroll', this.onViewScroll, this);
13074 this.list.swallowEvent('mousewheel');
13075 this.assetHeight = 0;
13078 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
13079 this.assetHeight += this.header.getHeight();
13082 this.innerList = this.list.createChild({cls:cls+'-inner'});
13083 this.innerList.on('mouseover', this.onViewOver, this);
13084 this.innerList.on('mousemove', this.onViewMove, this);
13085 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13087 if(this.allowBlank && !this.pageSize && !this.disableClear){
13088 this.footer = this.list.createChild({cls:cls+'-ft'});
13089 this.pageTb = new Roo.Toolbar(this.footer);
13093 this.footer = this.list.createChild({cls:cls+'-ft'});
13094 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
13095 {pageSize: this.pageSize});
13099 if (this.pageTb && this.allowBlank && !this.disableClear) {
13101 this.pageTb.add(new Roo.Toolbar.Fill(), {
13102 cls: 'x-btn-icon x-btn-clear',
13104 handler: function()
13107 _this.clearValue();
13108 _this.onSelect(false, -1);
13113 this.assetHeight += this.footer.getHeight();
13118 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
13121 this.view = new Roo.View(this.list, this.tpl, {
13122 singleSelect:true, store: this.store, selectedClass: this.selectedClass
13124 //this.view.wrapEl.setDisplayed(false);
13125 this.view.on('click', this.onViewClick, this);
13128 this.store.on('beforeload', this.onBeforeLoad, this);
13129 this.store.on('load', this.onLoad, this);
13130 this.store.on('loadexception', this.onLoadException, this);
13132 if(this.resizable){
13133 this.resizer = new Roo.Resizable(this.list, {
13134 pinned:true, handles:'se'
13136 this.resizer.on('resize', function(r, w, h){
13137 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
13138 this.listWidth = w;
13139 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
13140 this.restrictHeight();
13142 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
13145 if(!this.editable){
13146 this.editable = true;
13147 this.setEditable(false);
13152 if (typeof(this.events.add.listeners) != 'undefined') {
13154 this.addicon = this.wrap.createChild(
13155 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
13157 this.addicon.on('click', function(e) {
13158 this.fireEvent('add', this);
13161 if (typeof(this.events.edit.listeners) != 'undefined') {
13163 this.editicon = this.wrap.createChild(
13164 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
13165 if (this.addicon) {
13166 this.editicon.setStyle('margin-left', '40px');
13168 this.editicon.on('click', function(e) {
13170 // we fire even if inothing is selected..
13171 this.fireEvent('edit', this, this.lastData );
13177 this.keyNav = new Roo.KeyNav(this.inputEl(), {
13178 "up" : function(e){
13179 this.inKeyMode = true;
13183 "down" : function(e){
13184 if(!this.isExpanded()){
13185 this.onTriggerClick();
13187 this.inKeyMode = true;
13192 "enter" : function(e){
13193 // this.onViewClick();
13197 if(this.fireEvent("specialkey", this, e)){
13198 this.onViewClick(false);
13204 "esc" : function(e){
13208 "tab" : function(e){
13211 if(this.fireEvent("specialkey", this, e)){
13212 this.onViewClick(false);
13220 doRelay : function(foo, bar, hname){
13221 if(hname == 'down' || this.scope.isExpanded()){
13222 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13231 this.queryDelay = Math.max(this.queryDelay || 10,
13232 this.mode == 'local' ? 10 : 250);
13235 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13237 if(this.typeAhead){
13238 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13240 if(this.editable !== false){
13241 this.inputEl().on("keyup", this.onKeyUp, this);
13243 if(this.forceSelection){
13244 this.inputEl().on('blur', this.doForce, this);
13248 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13249 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13253 initTickableEvents: function()
13257 if(this.hiddenName){
13259 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13261 this.hiddenField.dom.value =
13262 this.hiddenValue !== undefined ? this.hiddenValue :
13263 this.value !== undefined ? this.value : '';
13265 // prevent input submission
13266 this.el.dom.removeAttribute('name');
13267 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13272 // this.list = this.el.select('ul.dropdown-menu',true).first();
13274 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13275 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13276 if(this.triggerList){
13277 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
13280 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
13281 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
13283 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
13284 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
13286 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
13287 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
13289 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
13290 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
13291 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
13294 this.cancelBtn.hide();
13299 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13300 _this.list.setWidth(lw);
13303 this.list.on('mouseover', this.onViewOver, this);
13304 this.list.on('mousemove', this.onViewMove, this);
13306 this.list.on('scroll', this.onViewScroll, this);
13309 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></div></li>';
13312 this.view = new Roo.View(this.list, this.tpl, {
13313 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
13316 //this.view.wrapEl.setDisplayed(false);
13317 this.view.on('click', this.onViewClick, this);
13321 this.store.on('beforeload', this.onBeforeLoad, this);
13322 this.store.on('load', this.onLoad, this);
13323 this.store.on('loadexception', this.onLoadException, this);
13326 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
13327 "up" : function(e){
13328 this.inKeyMode = true;
13332 "down" : function(e){
13333 this.inKeyMode = true;
13337 "enter" : function(e){
13338 if(this.fireEvent("specialkey", this, e)){
13339 this.onViewClick(false);
13345 "esc" : function(e){
13346 this.onTickableFooterButtonClick(e, false, false);
13349 "tab" : function(e){
13350 this.fireEvent("specialkey", this, e);
13352 this.onTickableFooterButtonClick(e, false, false);
13359 doRelay : function(e, fn, key){
13360 if(this.scope.isExpanded()){
13361 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13370 this.queryDelay = Math.max(this.queryDelay || 10,
13371 this.mode == 'local' ? 10 : 250);
13374 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13376 if(this.typeAhead){
13377 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13380 if(this.editable !== false){
13381 this.tickableInputEl().on("keyup", this.onKeyUp, this);
13384 this.indicator = this.indicatorEl();
13386 if(this.indicator){
13387 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
13388 this.indicator.hide();
13393 onDestroy : function(){
13395 this.view.setStore(null);
13396 this.view.el.removeAllListeners();
13397 this.view.el.remove();
13398 this.view.purgeListeners();
13401 this.list.dom.innerHTML = '';
13405 this.store.un('beforeload', this.onBeforeLoad, this);
13406 this.store.un('load', this.onLoad, this);
13407 this.store.un('loadexception', this.onLoadException, this);
13409 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
13413 fireKey : function(e){
13414 if(e.isNavKeyPress() && !this.list.isVisible()){
13415 this.fireEvent("specialkey", this, e);
13420 onResize: function(w, h){
13421 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
13423 // if(typeof w != 'number'){
13424 // // we do not handle it!?!?
13427 // var tw = this.trigger.getWidth();
13428 // // tw += this.addicon ? this.addicon.getWidth() : 0;
13429 // // tw += this.editicon ? this.editicon.getWidth() : 0;
13431 // this.inputEl().setWidth( this.adjustWidth('input', x));
13433 // //this.trigger.setStyle('left', x+'px');
13435 // if(this.list && this.listWidth === undefined){
13436 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
13437 // this.list.setWidth(lw);
13438 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13446 * Allow or prevent the user from directly editing the field text. If false is passed,
13447 * the user will only be able to select from the items defined in the dropdown list. This method
13448 * is the runtime equivalent of setting the 'editable' config option at config time.
13449 * @param {Boolean} value True to allow the user to directly edit the field text
13451 setEditable : function(value){
13452 if(value == this.editable){
13455 this.editable = value;
13457 this.inputEl().dom.setAttribute('readOnly', true);
13458 this.inputEl().on('mousedown', this.onTriggerClick, this);
13459 this.inputEl().addClass('x-combo-noedit');
13461 this.inputEl().dom.setAttribute('readOnly', false);
13462 this.inputEl().un('mousedown', this.onTriggerClick, this);
13463 this.inputEl().removeClass('x-combo-noedit');
13469 onBeforeLoad : function(combo,opts){
13470 if(!this.hasFocus){
13474 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
13476 this.restrictHeight();
13477 this.selectedIndex = -1;
13481 onLoad : function(){
13483 this.hasQuery = false;
13485 if(!this.hasFocus){
13489 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13490 this.loading.hide();
13493 if(this.store.getCount() > 0){
13496 this.restrictHeight();
13497 if(this.lastQuery == this.allQuery){
13498 if(this.editable && !this.tickable){
13499 this.inputEl().dom.select();
13503 !this.selectByValue(this.value, true) &&
13506 !this.store.lastOptions ||
13507 typeof(this.store.lastOptions.add) == 'undefined' ||
13508 this.store.lastOptions.add != true
13511 this.select(0, true);
13514 if(this.autoFocus){
13517 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
13518 this.taTask.delay(this.typeAheadDelay);
13522 this.onEmptyResults();
13528 onLoadException : function()
13530 this.hasQuery = false;
13532 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13533 this.loading.hide();
13536 if(this.tickable && this.editable){
13541 // only causes errors at present
13542 //Roo.log(this.store.reader.jsonData);
13543 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
13545 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
13551 onTypeAhead : function(){
13552 if(this.store.getCount() > 0){
13553 var r = this.store.getAt(0);
13554 var newValue = r.data[this.displayField];
13555 var len = newValue.length;
13556 var selStart = this.getRawValue().length;
13558 if(selStart != len){
13559 this.setRawValue(newValue);
13560 this.selectText(selStart, newValue.length);
13566 onSelect : function(record, index){
13568 if(this.fireEvent('beforeselect', this, record, index) !== false){
13570 this.setFromData(index > -1 ? record.data : false);
13573 this.fireEvent('select', this, record, index);
13578 * Returns the currently selected field value or empty string if no value is set.
13579 * @return {String} value The selected value
13581 getValue : function()
13583 if(Roo.isIOS && this.useNativeIOS){
13584 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
13588 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
13591 if(this.valueField){
13592 return typeof this.value != 'undefined' ? this.value : '';
13594 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
13598 getRawValue : function()
13600 if(Roo.isIOS && this.useNativeIOS){
13601 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
13604 var v = this.inputEl().getValue();
13610 * Clears any text/value currently set in the field
13612 clearValue : function(){
13614 if(this.hiddenField){
13615 this.hiddenField.dom.value = '';
13618 this.setRawValue('');
13619 this.lastSelectionText = '';
13620 this.lastData = false;
13622 var close = this.closeTriggerEl();
13633 * Sets the specified value into the field. If the value finds a match, the corresponding record text
13634 * will be displayed in the field. If the value does not match the data value of an existing item,
13635 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
13636 * Otherwise the field will be blank (although the value will still be set).
13637 * @param {String} value The value to match
13639 setValue : function(v)
13641 if(Roo.isIOS && this.useNativeIOS){
13642 this.setIOSValue(v);
13652 if(this.valueField){
13653 var r = this.findRecord(this.valueField, v);
13655 text = r.data[this.displayField];
13656 }else if(this.valueNotFoundText !== undefined){
13657 text = this.valueNotFoundText;
13660 this.lastSelectionText = text;
13661 if(this.hiddenField){
13662 this.hiddenField.dom.value = v;
13664 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
13667 var close = this.closeTriggerEl();
13670 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
13676 * @property {Object} the last set data for the element
13681 * Sets the value of the field based on a object which is related to the record format for the store.
13682 * @param {Object} value the value to set as. or false on reset?
13684 setFromData : function(o){
13691 var dv = ''; // display value
13692 var vv = ''; // value value..
13694 if (this.displayField) {
13695 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
13697 // this is an error condition!!!
13698 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
13701 if(this.valueField){
13702 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
13705 var close = this.closeTriggerEl();
13708 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
13711 if(this.hiddenField){
13712 this.hiddenField.dom.value = vv;
13714 this.lastSelectionText = dv;
13715 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
13719 // no hidden field.. - we store the value in 'value', but still display
13720 // display field!!!!
13721 this.lastSelectionText = dv;
13722 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
13729 reset : function(){
13730 // overridden so that last data is reset..
13737 this.setValue(this.originalValue);
13738 //this.clearInvalid();
13739 this.lastData = false;
13741 this.view.clearSelections();
13747 findRecord : function(prop, value){
13749 if(this.store.getCount() > 0){
13750 this.store.each(function(r){
13751 if(r.data[prop] == value){
13761 getName: function()
13763 // returns hidden if it's set..
13764 if (!this.rendered) {return ''};
13765 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
13769 onViewMove : function(e, t){
13770 this.inKeyMode = false;
13774 onViewOver : function(e, t){
13775 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
13778 var item = this.view.findItemFromChild(t);
13781 var index = this.view.indexOf(item);
13782 this.select(index, false);
13787 onViewClick : function(view, doFocus, el, e)
13789 var index = this.view.getSelectedIndexes()[0];
13791 var r = this.store.getAt(index);
13795 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
13802 Roo.each(this.tickItems, function(v,k){
13804 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
13806 _this.tickItems.splice(k, 1);
13808 if(typeof(e) == 'undefined' && view == false){
13809 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
13821 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
13822 this.tickItems.push(r.data);
13825 if(typeof(e) == 'undefined' && view == false){
13826 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
13833 this.onSelect(r, index);
13835 if(doFocus !== false && !this.blockFocus){
13836 this.inputEl().focus();
13841 restrictHeight : function(){
13842 //this.innerList.dom.style.height = '';
13843 //var inner = this.innerList.dom;
13844 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
13845 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
13846 //this.list.beginUpdate();
13847 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
13848 this.list.alignTo(this.inputEl(), this.listAlign);
13849 this.list.alignTo(this.inputEl(), this.listAlign);
13850 //this.list.endUpdate();
13854 onEmptyResults : function(){
13856 if(this.tickable && this.editable){
13857 this.restrictHeight();
13865 * Returns true if the dropdown list is expanded, else false.
13867 isExpanded : function(){
13868 return this.list.isVisible();
13872 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
13873 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
13874 * @param {String} value The data value of the item to select
13875 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
13876 * selected item if it is not currently in view (defaults to true)
13877 * @return {Boolean} True if the value matched an item in the list, else false
13879 selectByValue : function(v, scrollIntoView){
13880 if(v !== undefined && v !== null){
13881 var r = this.findRecord(this.valueField || this.displayField, v);
13883 this.select(this.store.indexOf(r), scrollIntoView);
13891 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
13892 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
13893 * @param {Number} index The zero-based index of the list item to select
13894 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
13895 * selected item if it is not currently in view (defaults to true)
13897 select : function(index, scrollIntoView){
13898 this.selectedIndex = index;
13899 this.view.select(index);
13900 if(scrollIntoView !== false){
13901 var el = this.view.getNode(index);
13903 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
13906 this.list.scrollChildIntoView(el, false);
13912 selectNext : function(){
13913 var ct = this.store.getCount();
13915 if(this.selectedIndex == -1){
13917 }else if(this.selectedIndex < ct-1){
13918 this.select(this.selectedIndex+1);
13924 selectPrev : function(){
13925 var ct = this.store.getCount();
13927 if(this.selectedIndex == -1){
13929 }else if(this.selectedIndex != 0){
13930 this.select(this.selectedIndex-1);
13936 onKeyUp : function(e){
13937 if(this.editable !== false && !e.isSpecialKey()){
13938 this.lastKey = e.getKey();
13939 this.dqTask.delay(this.queryDelay);
13944 validateBlur : function(){
13945 return !this.list || !this.list.isVisible();
13949 initQuery : function(){
13951 var v = this.getRawValue();
13953 if(this.tickable && this.editable){
13954 v = this.tickableInputEl().getValue();
13961 doForce : function(){
13962 if(this.inputEl().dom.value.length > 0){
13963 this.inputEl().dom.value =
13964 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
13970 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
13971 * query allowing the query action to be canceled if needed.
13972 * @param {String} query The SQL query to execute
13973 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
13974 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
13975 * saved in the current store (defaults to false)
13977 doQuery : function(q, forceAll){
13979 if(q === undefined || q === null){
13984 forceAll: forceAll,
13988 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
13993 forceAll = qe.forceAll;
13994 if(forceAll === true || (q.length >= this.minChars)){
13996 this.hasQuery = true;
13998 if(this.lastQuery != q || this.alwaysQuery){
13999 this.lastQuery = q;
14000 if(this.mode == 'local'){
14001 this.selectedIndex = -1;
14003 this.store.clearFilter();
14006 if(this.specialFilter){
14007 this.fireEvent('specialfilter', this);
14012 this.store.filter(this.displayField, q);
14015 this.store.fireEvent("datachanged", this.store);
14022 this.store.baseParams[this.queryParam] = q;
14024 var options = {params : this.getParams(q)};
14027 options.add = true;
14028 options.params.start = this.page * this.pageSize;
14031 this.store.load(options);
14034 * this code will make the page width larger, at the beginning, the list not align correctly,
14035 * we should expand the list on onLoad
14036 * so command out it
14041 this.selectedIndex = -1;
14046 this.loadNext = false;
14050 getParams : function(q){
14052 //p[this.queryParam] = q;
14056 p.limit = this.pageSize;
14062 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
14064 collapse : function(){
14065 if(!this.isExpanded()){
14071 this.hasFocus = false;
14075 this.cancelBtn.hide();
14076 this.trigger.show();
14079 this.tickableInputEl().dom.value = '';
14080 this.tickableInputEl().blur();
14085 Roo.get(document).un('mousedown', this.collapseIf, this);
14086 Roo.get(document).un('mousewheel', this.collapseIf, this);
14087 if (!this.editable) {
14088 Roo.get(document).un('keydown', this.listKeyPress, this);
14090 this.fireEvent('collapse', this);
14096 collapseIf : function(e){
14097 var in_combo = e.within(this.el);
14098 var in_list = e.within(this.list);
14099 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
14101 if (in_combo || in_list || is_list) {
14102 //e.stopPropagation();
14107 this.onTickableFooterButtonClick(e, false, false);
14115 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
14117 expand : function(){
14119 if(this.isExpanded() || !this.hasFocus){
14123 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
14124 this.list.setWidth(lw);
14130 this.restrictHeight();
14134 this.tickItems = Roo.apply([], this.item);
14137 this.cancelBtn.show();
14138 this.trigger.hide();
14141 this.tickableInputEl().focus();
14146 Roo.get(document).on('mousedown', this.collapseIf, this);
14147 Roo.get(document).on('mousewheel', this.collapseIf, this);
14148 if (!this.editable) {
14149 Roo.get(document).on('keydown', this.listKeyPress, this);
14152 this.fireEvent('expand', this);
14156 // Implements the default empty TriggerField.onTriggerClick function
14157 onTriggerClick : function(e)
14159 Roo.log('trigger click');
14161 if(this.disabled || !this.triggerList){
14166 this.loadNext = false;
14168 if(this.isExpanded()){
14170 if (!this.blockFocus) {
14171 this.inputEl().focus();
14175 this.hasFocus = true;
14176 if(this.triggerAction == 'all') {
14177 this.doQuery(this.allQuery, true);
14179 this.doQuery(this.getRawValue());
14181 if (!this.blockFocus) {
14182 this.inputEl().focus();
14187 onTickableTriggerClick : function(e)
14194 this.loadNext = false;
14195 this.hasFocus = true;
14197 if(this.triggerAction == 'all') {
14198 this.doQuery(this.allQuery, true);
14200 this.doQuery(this.getRawValue());
14204 onSearchFieldClick : function(e)
14206 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
14207 this.onTickableFooterButtonClick(e, false, false);
14211 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
14216 this.loadNext = false;
14217 this.hasFocus = true;
14219 if(this.triggerAction == 'all') {
14220 this.doQuery(this.allQuery, true);
14222 this.doQuery(this.getRawValue());
14226 listKeyPress : function(e)
14228 //Roo.log('listkeypress');
14229 // scroll to first matching element based on key pres..
14230 if (e.isSpecialKey()) {
14233 var k = String.fromCharCode(e.getKey()).toUpperCase();
14236 var csel = this.view.getSelectedNodes();
14237 var cselitem = false;
14239 var ix = this.view.indexOf(csel[0]);
14240 cselitem = this.store.getAt(ix);
14241 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
14247 this.store.each(function(v) {
14249 // start at existing selection.
14250 if (cselitem.id == v.id) {
14256 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
14257 match = this.store.indexOf(v);
14263 if (match === false) {
14264 return true; // no more action?
14267 this.view.select(match);
14268 var sn = Roo.get(this.view.getSelectedNodes()[0]);
14269 sn.scrollIntoView(sn.dom.parentNode, false);
14272 onViewScroll : function(e, t){
14274 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){
14278 this.hasQuery = true;
14280 this.loading = this.list.select('.loading', true).first();
14282 if(this.loading === null){
14283 this.list.createChild({
14285 cls: 'loading roo-select2-more-results roo-select2-active',
14286 html: 'Loading more results...'
14289 this.loading = this.list.select('.loading', true).first();
14291 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
14293 this.loading.hide();
14296 this.loading.show();
14301 this.loadNext = true;
14303 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
14308 addItem : function(o)
14310 var dv = ''; // display value
14312 if (this.displayField) {
14313 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14315 // this is an error condition!!!
14316 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14323 var choice = this.choices.createChild({
14325 cls: 'roo-select2-search-choice',
14334 cls: 'roo-select2-search-choice-close fa fa-times',
14339 }, this.searchField);
14341 var close = choice.select('a.roo-select2-search-choice-close', true).first();
14343 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
14351 this.inputEl().dom.value = '';
14356 onRemoveItem : function(e, _self, o)
14358 e.preventDefault();
14360 this.lastItem = Roo.apply([], this.item);
14362 var index = this.item.indexOf(o.data) * 1;
14365 Roo.log('not this item?!');
14369 this.item.splice(index, 1);
14374 this.fireEvent('remove', this, e);
14380 syncValue : function()
14382 if(!this.item.length){
14389 Roo.each(this.item, function(i){
14390 if(_this.valueField){
14391 value.push(i[_this.valueField]);
14398 this.value = value.join(',');
14400 if(this.hiddenField){
14401 this.hiddenField.dom.value = this.value;
14404 this.store.fireEvent("datachanged", this.store);
14409 clearItem : function()
14411 if(!this.multiple){
14417 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
14425 if(this.tickable && !Roo.isTouch){
14426 this.view.refresh();
14430 inputEl: function ()
14432 if(Roo.isIOS && this.useNativeIOS){
14433 return this.el.select('select.roo-ios-select', true).first();
14436 if(Roo.isTouch && this.mobileTouchView){
14437 return this.el.select('input.form-control',true).first();
14441 return this.searchField;
14444 return this.el.select('input.form-control',true).first();
14447 onTickableFooterButtonClick : function(e, btn, el)
14449 e.preventDefault();
14451 this.lastItem = Roo.apply([], this.item);
14453 if(btn && btn.name == 'cancel'){
14454 this.tickItems = Roo.apply([], this.item);
14463 Roo.each(this.tickItems, function(o){
14471 validate : function()
14473 var v = this.getRawValue();
14476 v = this.getValue();
14479 if(this.disabled || this.allowBlank || v.length){
14484 this.markInvalid();
14488 tickableInputEl : function()
14490 if(!this.tickable || !this.editable){
14491 return this.inputEl();
14494 return this.inputEl().select('.roo-select2-search-field-input', true).first();
14498 getAutoCreateTouchView : function()
14503 cls: 'form-group' //input-group
14509 type : this.inputType,
14510 cls : 'form-control x-combo-noedit',
14511 autocomplete: 'new-password',
14512 placeholder : this.placeholder || '',
14517 input.name = this.name;
14521 input.cls += ' input-' + this.size;
14524 if (this.disabled) {
14525 input.disabled = true;
14536 inputblock.cls += ' input-group';
14538 inputblock.cn.unshift({
14540 cls : 'input-group-addon',
14545 if(this.removable && !this.multiple){
14546 inputblock.cls += ' roo-removable';
14548 inputblock.cn.push({
14551 cls : 'roo-combo-removable-btn close'
14555 if(this.hasFeedback && !this.allowBlank){
14557 inputblock.cls += ' has-feedback';
14559 inputblock.cn.push({
14561 cls: 'glyphicon form-control-feedback'
14568 inputblock.cls += (this.before) ? '' : ' input-group';
14570 inputblock.cn.push({
14572 cls : 'input-group-addon',
14583 cls: 'form-hidden-field'
14597 cls: 'form-hidden-field'
14601 cls: 'roo-select2-choices',
14605 cls: 'roo-select2-search-field',
14618 cls: 'roo-select2-container input-group roo-touchview-combobox ',
14624 if(!this.multiple && this.showToggleBtn){
14631 if (this.caret != false) {
14634 cls: 'fa fa-' + this.caret
14641 cls : 'input-group-addon btn dropdown-toggle',
14646 cls: 'combobox-clear',
14660 combobox.cls += ' roo-select2-container-multi';
14663 var align = this.labelAlign || this.parentLabelAlign();
14665 if (align ==='left' && this.fieldLabel.length) {
14670 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
14671 tooltip : 'This field is required'
14675 cls : 'control-label',
14676 html : this.fieldLabel
14687 var labelCfg = cfg.cn[1];
14688 var contentCfg = cfg.cn[2];
14691 if(this.indicatorpos == 'right'){
14695 cls : 'control-label',
14696 html : this.fieldLabel,
14700 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
14701 tooltip : 'This field is required'
14714 labelCfg = cfg.cn[0];
14715 contentCfg = cfg.cn[2];
14717 if(this.labelWidth > 12){
14718 labelCfg.style = "width: " + this.labelWidth + 'px';
14721 if(this.labelWidth < 13 && this.labelmd == 0){
14722 this.labelmd = this.labelWidth;
14725 if(this.labellg > 0){
14726 labelCfg.cls += ' col-lg-' + this.labellg;
14727 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
14730 if(this.labelmd > 0){
14731 labelCfg.cls += ' col-md-' + this.labelmd;
14732 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
14735 if(this.labelsm > 0){
14736 labelCfg.cls += ' col-sm-' + this.labelsm;
14737 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
14740 if(this.labelxs > 0){
14741 labelCfg.cls += ' col-xs-' + this.labelxs;
14742 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
14746 } else if ( this.fieldLabel.length) {
14750 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
14751 tooltip : 'This field is required'
14755 cls : 'control-label',
14756 html : this.fieldLabel
14767 if(this.indicatorpos == 'right'){
14771 cls : 'control-label',
14772 html : this.fieldLabel,
14776 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
14777 tooltip : 'This field is required'
14794 var settings = this;
14796 ['xs','sm','md','lg'].map(function(size){
14797 if (settings[size]) {
14798 cfg.cls += ' col-' + size + '-' + settings[size];
14805 initTouchView : function()
14807 this.renderTouchView();
14809 this.touchViewEl.on('scroll', function(){
14810 this.el.dom.scrollTop = 0;
14813 this.originalValue = this.getValue();
14815 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
14817 this.inputEl().on("click", this.showTouchView, this);
14818 if (this.triggerEl) {
14819 this.triggerEl.on("click", this.showTouchView, this);
14823 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
14824 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
14826 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
14828 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
14829 this.store.on('load', this.onTouchViewLoad, this);
14830 this.store.on('loadexception', this.onTouchViewLoadException, this);
14832 if(this.hiddenName){
14834 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
14836 this.hiddenField.dom.value =
14837 this.hiddenValue !== undefined ? this.hiddenValue :
14838 this.value !== undefined ? this.value : '';
14840 this.el.dom.removeAttribute('name');
14841 this.hiddenField.dom.setAttribute('name', this.hiddenName);
14845 this.choices = this.el.select('ul.roo-select2-choices', true).first();
14846 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
14849 if(this.removable && !this.multiple){
14850 var close = this.closeTriggerEl();
14852 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
14853 close.on('click', this.removeBtnClick, this, close);
14857 * fix the bug in Safari iOS8
14859 this.inputEl().on("focus", function(e){
14860 document.activeElement.blur();
14868 renderTouchView : function()
14870 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
14871 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14873 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
14874 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14876 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
14877 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14878 this.touchViewBodyEl.setStyle('overflow', 'auto');
14880 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
14881 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14883 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
14884 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14888 showTouchView : function()
14894 this.touchViewHeaderEl.hide();
14896 if(this.modalTitle.length){
14897 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
14898 this.touchViewHeaderEl.show();
14901 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
14902 this.touchViewEl.show();
14904 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
14905 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
14906 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
14908 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
14910 if(this.modalTitle.length){
14911 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
14914 this.touchViewBodyEl.setHeight(bodyHeight);
14918 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
14920 this.touchViewEl.addClass('in');
14923 this.doTouchViewQuery();
14927 hideTouchView : function()
14929 this.touchViewEl.removeClass('in');
14933 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
14935 this.touchViewEl.setStyle('display', 'none');
14940 setTouchViewValue : function()
14947 Roo.each(this.tickItems, function(o){
14952 this.hideTouchView();
14955 doTouchViewQuery : function()
14964 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
14968 if(!this.alwaysQuery || this.mode == 'local'){
14969 this.onTouchViewLoad();
14976 onTouchViewBeforeLoad : function(combo,opts)
14982 onTouchViewLoad : function()
14984 if(this.store.getCount() < 1){
14985 this.onTouchViewEmptyResults();
14989 this.clearTouchView();
14991 var rawValue = this.getRawValue();
14993 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
14995 this.tickItems = [];
14997 this.store.data.each(function(d, rowIndex){
14998 var row = this.touchViewListGroup.createChild(template);
15000 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
15001 row.addClass(d.data.cls);
15004 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15007 html : d.data[this.displayField]
15010 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
15011 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
15014 row.removeClass('selected');
15015 if(!this.multiple && this.valueField &&
15016 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
15019 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15020 row.addClass('selected');
15023 if(this.multiple && this.valueField &&
15024 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
15028 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15029 this.tickItems.push(d.data);
15032 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
15036 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
15038 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15040 if(this.modalTitle.length){
15041 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15044 var listHeight = this.touchViewListGroup.getHeight();
15048 if(firstChecked && listHeight > bodyHeight){
15049 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
15054 onTouchViewLoadException : function()
15056 this.hideTouchView();
15059 onTouchViewEmptyResults : function()
15061 this.clearTouchView();
15063 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
15065 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
15069 clearTouchView : function()
15071 this.touchViewListGroup.dom.innerHTML = '';
15074 onTouchViewClick : function(e, el, o)
15076 e.preventDefault();
15079 var rowIndex = o.rowIndex;
15081 var r = this.store.getAt(rowIndex);
15083 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
15085 if(!this.multiple){
15086 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
15087 c.dom.removeAttribute('checked');
15090 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15092 this.setFromData(r.data);
15094 var close = this.closeTriggerEl();
15100 this.hideTouchView();
15102 this.fireEvent('select', this, r, rowIndex);
15107 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
15108 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
15109 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
15113 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15114 this.addItem(r.data);
15115 this.tickItems.push(r.data);
15119 getAutoCreateNativeIOS : function()
15122 cls: 'form-group' //input-group,
15127 cls : 'roo-ios-select'
15131 combobox.name = this.name;
15134 if (this.disabled) {
15135 combobox.disabled = true;
15138 var settings = this;
15140 ['xs','sm','md','lg'].map(function(size){
15141 if (settings[size]) {
15142 cfg.cls += ' col-' + size + '-' + settings[size];
15152 initIOSView : function()
15154 this.store.on('load', this.onIOSViewLoad, this);
15159 onIOSViewLoad : function()
15161 if(this.store.getCount() < 1){
15165 this.clearIOSView();
15167 if(this.allowBlank) {
15169 var default_text = '-- SELECT --';
15171 var opt = this.inputEl().createChild({
15174 html : default_text
15178 o[this.valueField] = 0;
15179 o[this.displayField] = default_text;
15181 this.ios_options.push({
15188 this.store.data.each(function(d, rowIndex){
15192 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15193 html = d.data[this.displayField];
15198 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
15199 value = d.data[this.valueField];
15208 if(this.value == d.data[this.valueField]){
15209 option['selected'] = true;
15212 var opt = this.inputEl().createChild(option);
15214 this.ios_options.push({
15221 this.inputEl().on('change', function(){
15222 this.fireEvent('select', this);
15227 clearIOSView: function()
15229 this.inputEl().dom.innerHTML = '';
15231 this.ios_options = [];
15234 setIOSValue: function(v)
15238 if(!this.ios_options){
15242 Roo.each(this.ios_options, function(opts){
15244 opts.el.dom.removeAttribute('selected');
15246 if(opts.data[this.valueField] != v){
15250 opts.el.dom.setAttribute('selected', true);
15256 * @cfg {Boolean} grow
15260 * @cfg {Number} growMin
15264 * @cfg {Number} growMax
15273 Roo.apply(Roo.bootstrap.ComboBox, {
15277 cls: 'modal-header',
15299 cls: 'list-group-item',
15303 cls: 'roo-combobox-list-group-item-value'
15307 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
15321 listItemCheckbox : {
15323 cls: 'list-group-item',
15327 cls: 'roo-combobox-list-group-item-value'
15331 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
15347 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
15352 cls: 'modal-footer',
15360 cls: 'col-xs-6 text-left',
15363 cls: 'btn btn-danger roo-touch-view-cancel',
15369 cls: 'col-xs-6 text-right',
15372 cls: 'btn btn-success roo-touch-view-ok',
15383 Roo.apply(Roo.bootstrap.ComboBox, {
15385 touchViewTemplate : {
15387 cls: 'modal fade roo-combobox-touch-view',
15391 cls: 'modal-dialog',
15392 style : 'position:fixed', // we have to fix position....
15396 cls: 'modal-content',
15398 Roo.bootstrap.ComboBox.header,
15399 Roo.bootstrap.ComboBox.body,
15400 Roo.bootstrap.ComboBox.footer
15409 * Ext JS Library 1.1.1
15410 * Copyright(c) 2006-2007, Ext JS, LLC.
15412 * Originally Released Under LGPL - original licence link has changed is not relivant.
15415 * <script type="text/javascript">
15420 * @extends Roo.util.Observable
15421 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
15422 * This class also supports single and multi selection modes. <br>
15423 * Create a data model bound view:
15425 var store = new Roo.data.Store(...);
15427 var view = new Roo.View({
15429 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
15431 singleSelect: true,
15432 selectedClass: "ydataview-selected",
15436 // listen for node click?
15437 view.on("click", function(vw, index, node, e){
15438 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
15442 dataModel.load("foobar.xml");
15444 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
15446 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
15447 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
15449 * Note: old style constructor is still suported (container, template, config)
15452 * Create a new View
15453 * @param {Object} config The config object
15456 Roo.View = function(config, depreciated_tpl, depreciated_config){
15458 this.parent = false;
15460 if (typeof(depreciated_tpl) == 'undefined') {
15461 // new way.. - universal constructor.
15462 Roo.apply(this, config);
15463 this.el = Roo.get(this.el);
15466 this.el = Roo.get(config);
15467 this.tpl = depreciated_tpl;
15468 Roo.apply(this, depreciated_config);
15470 this.wrapEl = this.el.wrap().wrap();
15471 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
15474 if(typeof(this.tpl) == "string"){
15475 this.tpl = new Roo.Template(this.tpl);
15477 // support xtype ctors..
15478 this.tpl = new Roo.factory(this.tpl, Roo);
15482 this.tpl.compile();
15487 * @event beforeclick
15488 * Fires before a click is processed. Returns false to cancel the default action.
15489 * @param {Roo.View} this
15490 * @param {Number} index The index of the target node
15491 * @param {HTMLElement} node The target node
15492 * @param {Roo.EventObject} e The raw event object
15494 "beforeclick" : true,
15497 * Fires when a template node is clicked.
15498 * @param {Roo.View} this
15499 * @param {Number} index The index of the target node
15500 * @param {HTMLElement} node The target node
15501 * @param {Roo.EventObject} e The raw event object
15506 * Fires when a template node is double clicked.
15507 * @param {Roo.View} this
15508 * @param {Number} index The index of the target node
15509 * @param {HTMLElement} node The target node
15510 * @param {Roo.EventObject} e The raw event object
15514 * @event contextmenu
15515 * Fires when a template node is right clicked.
15516 * @param {Roo.View} this
15517 * @param {Number} index The index of the target node
15518 * @param {HTMLElement} node The target node
15519 * @param {Roo.EventObject} e The raw event object
15521 "contextmenu" : true,
15523 * @event selectionchange
15524 * Fires when the selected nodes change.
15525 * @param {Roo.View} this
15526 * @param {Array} selections Array of the selected nodes
15528 "selectionchange" : true,
15531 * @event beforeselect
15532 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
15533 * @param {Roo.View} this
15534 * @param {HTMLElement} node The node to be selected
15535 * @param {Array} selections Array of currently selected nodes
15537 "beforeselect" : true,
15539 * @event preparedata
15540 * Fires on every row to render, to allow you to change the data.
15541 * @param {Roo.View} this
15542 * @param {Object} data to be rendered (change this)
15544 "preparedata" : true
15552 "click": this.onClick,
15553 "dblclick": this.onDblClick,
15554 "contextmenu": this.onContextMenu,
15558 this.selections = [];
15560 this.cmp = new Roo.CompositeElementLite([]);
15562 this.store = Roo.factory(this.store, Roo.data);
15563 this.setStore(this.store, true);
15566 if ( this.footer && this.footer.xtype) {
15568 var fctr = this.wrapEl.appendChild(document.createElement("div"));
15570 this.footer.dataSource = this.store;
15571 this.footer.container = fctr;
15572 this.footer = Roo.factory(this.footer, Roo);
15573 fctr.insertFirst(this.el);
15575 // this is a bit insane - as the paging toolbar seems to detach the el..
15576 // dom.parentNode.parentNode.parentNode
15577 // they get detached?
15581 Roo.View.superclass.constructor.call(this);
15586 Roo.extend(Roo.View, Roo.util.Observable, {
15589 * @cfg {Roo.data.Store} store Data store to load data from.
15594 * @cfg {String|Roo.Element} el The container element.
15599 * @cfg {String|Roo.Template} tpl The template used by this View
15603 * @cfg {String} dataName the named area of the template to use as the data area
15604 * Works with domtemplates roo-name="name"
15608 * @cfg {String} selectedClass The css class to add to selected nodes
15610 selectedClass : "x-view-selected",
15612 * @cfg {String} emptyText The empty text to show when nothing is loaded.
15617 * @cfg {String} text to display on mask (default Loading)
15621 * @cfg {Boolean} multiSelect Allow multiple selection
15623 multiSelect : false,
15625 * @cfg {Boolean} singleSelect Allow single selection
15627 singleSelect: false,
15630 * @cfg {Boolean} toggleSelect - selecting
15632 toggleSelect : false,
15635 * @cfg {Boolean} tickable - selecting
15640 * Returns the element this view is bound to.
15641 * @return {Roo.Element}
15643 getEl : function(){
15644 return this.wrapEl;
15650 * Refreshes the view. - called by datachanged on the store. - do not call directly.
15652 refresh : function(){
15653 //Roo.log('refresh');
15656 // if we are using something like 'domtemplate', then
15657 // the what gets used is:
15658 // t.applySubtemplate(NAME, data, wrapping data..)
15659 // the outer template then get' applied with
15660 // the store 'extra data'
15661 // and the body get's added to the
15662 // roo-name="data" node?
15663 // <span class='roo-tpl-{name}'></span> ?????
15667 this.clearSelections();
15668 this.el.update("");
15670 var records = this.store.getRange();
15671 if(records.length < 1) {
15673 // is this valid?? = should it render a template??
15675 this.el.update(this.emptyText);
15679 if (this.dataName) {
15680 this.el.update(t.apply(this.store.meta)); //????
15681 el = this.el.child('.roo-tpl-' + this.dataName);
15684 for(var i = 0, len = records.length; i < len; i++){
15685 var data = this.prepareData(records[i].data, i, records[i]);
15686 this.fireEvent("preparedata", this, data, i, records[i]);
15688 var d = Roo.apply({}, data);
15691 Roo.apply(d, {'roo-id' : Roo.id()});
15695 Roo.each(this.parent.item, function(item){
15696 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
15699 Roo.apply(d, {'roo-data-checked' : 'checked'});
15703 html[html.length] = Roo.util.Format.trim(
15705 t.applySubtemplate(this.dataName, d, this.store.meta) :
15712 el.update(html.join(""));
15713 this.nodes = el.dom.childNodes;
15714 this.updateIndexes(0);
15719 * Function to override to reformat the data that is sent to
15720 * the template for each node.
15721 * DEPRICATED - use the preparedata event handler.
15722 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
15723 * a JSON object for an UpdateManager bound view).
15725 prepareData : function(data, index, record)
15727 this.fireEvent("preparedata", this, data, index, record);
15731 onUpdate : function(ds, record){
15732 // Roo.log('on update');
15733 this.clearSelections();
15734 var index = this.store.indexOf(record);
15735 var n = this.nodes[index];
15736 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
15737 n.parentNode.removeChild(n);
15738 this.updateIndexes(index, index);
15744 onAdd : function(ds, records, index)
15746 //Roo.log(['on Add', ds, records, index] );
15747 this.clearSelections();
15748 if(this.nodes.length == 0){
15752 var n = this.nodes[index];
15753 for(var i = 0, len = records.length; i < len; i++){
15754 var d = this.prepareData(records[i].data, i, records[i]);
15756 this.tpl.insertBefore(n, d);
15759 this.tpl.append(this.el, d);
15762 this.updateIndexes(index);
15765 onRemove : function(ds, record, index){
15766 // Roo.log('onRemove');
15767 this.clearSelections();
15768 var el = this.dataName ?
15769 this.el.child('.roo-tpl-' + this.dataName) :
15772 el.dom.removeChild(this.nodes[index]);
15773 this.updateIndexes(index);
15777 * Refresh an individual node.
15778 * @param {Number} index
15780 refreshNode : function(index){
15781 this.onUpdate(this.store, this.store.getAt(index));
15784 updateIndexes : function(startIndex, endIndex){
15785 var ns = this.nodes;
15786 startIndex = startIndex || 0;
15787 endIndex = endIndex || ns.length - 1;
15788 for(var i = startIndex; i <= endIndex; i++){
15789 ns[i].nodeIndex = i;
15794 * Changes the data store this view uses and refresh the view.
15795 * @param {Store} store
15797 setStore : function(store, initial){
15798 if(!initial && this.store){
15799 this.store.un("datachanged", this.refresh);
15800 this.store.un("add", this.onAdd);
15801 this.store.un("remove", this.onRemove);
15802 this.store.un("update", this.onUpdate);
15803 this.store.un("clear", this.refresh);
15804 this.store.un("beforeload", this.onBeforeLoad);
15805 this.store.un("load", this.onLoad);
15806 this.store.un("loadexception", this.onLoad);
15810 store.on("datachanged", this.refresh, this);
15811 store.on("add", this.onAdd, this);
15812 store.on("remove", this.onRemove, this);
15813 store.on("update", this.onUpdate, this);
15814 store.on("clear", this.refresh, this);
15815 store.on("beforeload", this.onBeforeLoad, this);
15816 store.on("load", this.onLoad, this);
15817 store.on("loadexception", this.onLoad, this);
15825 * onbeforeLoad - masks the loading area.
15828 onBeforeLoad : function(store,opts)
15830 //Roo.log('onBeforeLoad');
15832 this.el.update("");
15834 this.el.mask(this.mask ? this.mask : "Loading" );
15836 onLoad : function ()
15843 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
15844 * @param {HTMLElement} node
15845 * @return {HTMLElement} The template node
15847 findItemFromChild : function(node){
15848 var el = this.dataName ?
15849 this.el.child('.roo-tpl-' + this.dataName,true) :
15852 if(!node || node.parentNode == el){
15855 var p = node.parentNode;
15856 while(p && p != el){
15857 if(p.parentNode == el){
15866 onClick : function(e){
15867 var item = this.findItemFromChild(e.getTarget());
15869 var index = this.indexOf(item);
15870 if(this.onItemClick(item, index, e) !== false){
15871 this.fireEvent("click", this, index, item, e);
15874 this.clearSelections();
15879 onContextMenu : function(e){
15880 var item = this.findItemFromChild(e.getTarget());
15882 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
15887 onDblClick : function(e){
15888 var item = this.findItemFromChild(e.getTarget());
15890 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
15894 onItemClick : function(item, index, e)
15896 if(this.fireEvent("beforeclick", this, index, item, e) === false){
15899 if (this.toggleSelect) {
15900 var m = this.isSelected(item) ? 'unselect' : 'select';
15903 _t[m](item, true, false);
15906 if(this.multiSelect || this.singleSelect){
15907 if(this.multiSelect && e.shiftKey && this.lastSelection){
15908 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
15910 this.select(item, this.multiSelect && e.ctrlKey);
15911 this.lastSelection = item;
15914 if(!this.tickable){
15915 e.preventDefault();
15923 * Get the number of selected nodes.
15926 getSelectionCount : function(){
15927 return this.selections.length;
15931 * Get the currently selected nodes.
15932 * @return {Array} An array of HTMLElements
15934 getSelectedNodes : function(){
15935 return this.selections;
15939 * Get the indexes of the selected nodes.
15942 getSelectedIndexes : function(){
15943 var indexes = [], s = this.selections;
15944 for(var i = 0, len = s.length; i < len; i++){
15945 indexes.push(s[i].nodeIndex);
15951 * Clear all selections
15952 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
15954 clearSelections : function(suppressEvent){
15955 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
15956 this.cmp.elements = this.selections;
15957 this.cmp.removeClass(this.selectedClass);
15958 this.selections = [];
15959 if(!suppressEvent){
15960 this.fireEvent("selectionchange", this, this.selections);
15966 * Returns true if the passed node is selected
15967 * @param {HTMLElement/Number} node The node or node index
15968 * @return {Boolean}
15970 isSelected : function(node){
15971 var s = this.selections;
15975 node = this.getNode(node);
15976 return s.indexOf(node) !== -1;
15981 * @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
15982 * @param {Boolean} keepExisting (optional) true to keep existing selections
15983 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
15985 select : function(nodeInfo, keepExisting, suppressEvent){
15986 if(nodeInfo instanceof Array){
15988 this.clearSelections(true);
15990 for(var i = 0, len = nodeInfo.length; i < len; i++){
15991 this.select(nodeInfo[i], true, true);
15995 var node = this.getNode(nodeInfo);
15996 if(!node || this.isSelected(node)){
15997 return; // already selected.
16000 this.clearSelections(true);
16003 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
16004 Roo.fly(node).addClass(this.selectedClass);
16005 this.selections.push(node);
16006 if(!suppressEvent){
16007 this.fireEvent("selectionchange", this, this.selections);
16015 * @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
16016 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
16017 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16019 unselect : function(nodeInfo, keepExisting, suppressEvent)
16021 if(nodeInfo instanceof Array){
16022 Roo.each(this.selections, function(s) {
16023 this.unselect(s, nodeInfo);
16027 var node = this.getNode(nodeInfo);
16028 if(!node || !this.isSelected(node)){
16029 //Roo.log("not selected");
16030 return; // not selected.
16034 Roo.each(this.selections, function(s) {
16036 Roo.fly(node).removeClass(this.selectedClass);
16043 this.selections= ns;
16044 this.fireEvent("selectionchange", this, this.selections);
16048 * Gets a template node.
16049 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16050 * @return {HTMLElement} The node or null if it wasn't found
16052 getNode : function(nodeInfo){
16053 if(typeof nodeInfo == "string"){
16054 return document.getElementById(nodeInfo);
16055 }else if(typeof nodeInfo == "number"){
16056 return this.nodes[nodeInfo];
16062 * Gets a range template nodes.
16063 * @param {Number} startIndex
16064 * @param {Number} endIndex
16065 * @return {Array} An array of nodes
16067 getNodes : function(start, end){
16068 var ns = this.nodes;
16069 start = start || 0;
16070 end = typeof end == "undefined" ? ns.length - 1 : end;
16073 for(var i = start; i <= end; i++){
16077 for(var i = start; i >= end; i--){
16085 * Finds the index of the passed node
16086 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16087 * @return {Number} The index of the node or -1
16089 indexOf : function(node){
16090 node = this.getNode(node);
16091 if(typeof node.nodeIndex == "number"){
16092 return node.nodeIndex;
16094 var ns = this.nodes;
16095 for(var i = 0, len = ns.length; i < len; i++){
16106 * based on jquery fullcalendar
16110 Roo.bootstrap = Roo.bootstrap || {};
16112 * @class Roo.bootstrap.Calendar
16113 * @extends Roo.bootstrap.Component
16114 * Bootstrap Calendar class
16115 * @cfg {Boolean} loadMask (true|false) default false
16116 * @cfg {Object} header generate the user specific header of the calendar, default false
16119 * Create a new Container
16120 * @param {Object} config The config object
16125 Roo.bootstrap.Calendar = function(config){
16126 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
16130 * Fires when a date is selected
16131 * @param {DatePicker} this
16132 * @param {Date} date The selected date
16136 * @event monthchange
16137 * Fires when the displayed month changes
16138 * @param {DatePicker} this
16139 * @param {Date} date The selected month
16141 'monthchange': true,
16143 * @event evententer
16144 * Fires when mouse over an event
16145 * @param {Calendar} this
16146 * @param {event} Event
16148 'evententer': true,
16150 * @event eventleave
16151 * Fires when the mouse leaves an
16152 * @param {Calendar} this
16155 'eventleave': true,
16157 * @event eventclick
16158 * Fires when the mouse click an
16159 * @param {Calendar} this
16168 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
16171 * @cfg {Number} startDay
16172 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
16180 getAutoCreate : function(){
16183 var fc_button = function(name, corner, style, content ) {
16184 return Roo.apply({},{
16186 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
16188 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
16191 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
16202 style : 'width:100%',
16209 cls : 'fc-header-left',
16211 fc_button('prev', 'left', 'arrow', '‹' ),
16212 fc_button('next', 'right', 'arrow', '›' ),
16213 { tag: 'span', cls: 'fc-header-space' },
16214 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
16222 cls : 'fc-header-center',
16226 cls: 'fc-header-title',
16229 html : 'month / year'
16237 cls : 'fc-header-right',
16239 /* fc_button('month', 'left', '', 'month' ),
16240 fc_button('week', '', '', 'week' ),
16241 fc_button('day', 'right', '', 'day' )
16253 header = this.header;
16256 var cal_heads = function() {
16258 // fixme - handle this.
16260 for (var i =0; i < Date.dayNames.length; i++) {
16261 var d = Date.dayNames[i];
16264 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
16265 html : d.substring(0,3)
16269 ret[0].cls += ' fc-first';
16270 ret[6].cls += ' fc-last';
16273 var cal_cell = function(n) {
16276 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
16281 cls: 'fc-day-number',
16285 cls: 'fc-day-content',
16289 style: 'position: relative;' // height: 17px;
16301 var cal_rows = function() {
16304 for (var r = 0; r < 6; r++) {
16311 for (var i =0; i < Date.dayNames.length; i++) {
16312 var d = Date.dayNames[i];
16313 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
16316 row.cn[0].cls+=' fc-first';
16317 row.cn[0].cn[0].style = 'min-height:90px';
16318 row.cn[6].cls+=' fc-last';
16322 ret[0].cls += ' fc-first';
16323 ret[4].cls += ' fc-prev-last';
16324 ret[5].cls += ' fc-last';
16331 cls: 'fc-border-separate',
16332 style : 'width:100%',
16340 cls : 'fc-first fc-last',
16358 cls : 'fc-content',
16359 style : "position: relative;",
16362 cls : 'fc-view fc-view-month fc-grid',
16363 style : 'position: relative',
16364 unselectable : 'on',
16367 cls : 'fc-event-container',
16368 style : 'position:absolute;z-index:8;top:0;left:0;'
16386 initEvents : function()
16389 throw "can not find store for calendar";
16395 style: "text-align:center",
16399 style: "background-color:white;width:50%;margin:250 auto",
16403 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
16414 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
16416 var size = this.el.select('.fc-content', true).first().getSize();
16417 this.maskEl.setSize(size.width, size.height);
16418 this.maskEl.enableDisplayMode("block");
16419 if(!this.loadMask){
16420 this.maskEl.hide();
16423 this.store = Roo.factory(this.store, Roo.data);
16424 this.store.on('load', this.onLoad, this);
16425 this.store.on('beforeload', this.onBeforeLoad, this);
16429 this.cells = this.el.select('.fc-day',true);
16430 //Roo.log(this.cells);
16431 this.textNodes = this.el.query('.fc-day-number');
16432 this.cells.addClassOnOver('fc-state-hover');
16434 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
16435 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
16436 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
16437 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
16439 this.on('monthchange', this.onMonthChange, this);
16441 this.update(new Date().clearTime());
16444 resize : function() {
16445 var sz = this.el.getSize();
16447 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
16448 this.el.select('.fc-day-content div',true).setHeight(34);
16453 showPrevMonth : function(e){
16454 this.update(this.activeDate.add("mo", -1));
16456 showToday : function(e){
16457 this.update(new Date().clearTime());
16460 showNextMonth : function(e){
16461 this.update(this.activeDate.add("mo", 1));
16465 showPrevYear : function(){
16466 this.update(this.activeDate.add("y", -1));
16470 showNextYear : function(){
16471 this.update(this.activeDate.add("y", 1));
16476 update : function(date)
16478 var vd = this.activeDate;
16479 this.activeDate = date;
16480 // if(vd && this.el){
16481 // var t = date.getTime();
16482 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
16483 // Roo.log('using add remove');
16485 // this.fireEvent('monthchange', this, date);
16487 // this.cells.removeClass("fc-state-highlight");
16488 // this.cells.each(function(c){
16489 // if(c.dateValue == t){
16490 // c.addClass("fc-state-highlight");
16491 // setTimeout(function(){
16492 // try{c.dom.firstChild.focus();}catch(e){}
16502 var days = date.getDaysInMonth();
16504 var firstOfMonth = date.getFirstDateOfMonth();
16505 var startingPos = firstOfMonth.getDay()-this.startDay;
16507 if(startingPos < this.startDay){
16511 var pm = date.add(Date.MONTH, -1);
16512 var prevStart = pm.getDaysInMonth()-startingPos;
16514 this.cells = this.el.select('.fc-day',true);
16515 this.textNodes = this.el.query('.fc-day-number');
16516 this.cells.addClassOnOver('fc-state-hover');
16518 var cells = this.cells.elements;
16519 var textEls = this.textNodes;
16521 Roo.each(cells, function(cell){
16522 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
16525 days += startingPos;
16527 // convert everything to numbers so it's fast
16528 var day = 86400000;
16529 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
16532 //Roo.log(prevStart);
16534 var today = new Date().clearTime().getTime();
16535 var sel = date.clearTime().getTime();
16536 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
16537 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
16538 var ddMatch = this.disabledDatesRE;
16539 var ddText = this.disabledDatesText;
16540 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
16541 var ddaysText = this.disabledDaysText;
16542 var format = this.format;
16544 var setCellClass = function(cal, cell){
16548 //Roo.log('set Cell Class');
16550 var t = d.getTime();
16554 cell.dateValue = t;
16556 cell.className += " fc-today";
16557 cell.className += " fc-state-highlight";
16558 cell.title = cal.todayText;
16561 // disable highlight in other month..
16562 //cell.className += " fc-state-highlight";
16567 cell.className = " fc-state-disabled";
16568 cell.title = cal.minText;
16572 cell.className = " fc-state-disabled";
16573 cell.title = cal.maxText;
16577 if(ddays.indexOf(d.getDay()) != -1){
16578 cell.title = ddaysText;
16579 cell.className = " fc-state-disabled";
16582 if(ddMatch && format){
16583 var fvalue = d.dateFormat(format);
16584 if(ddMatch.test(fvalue)){
16585 cell.title = ddText.replace("%0", fvalue);
16586 cell.className = " fc-state-disabled";
16590 if (!cell.initialClassName) {
16591 cell.initialClassName = cell.dom.className;
16594 cell.dom.className = cell.initialClassName + ' ' + cell.className;
16599 for(; i < startingPos; i++) {
16600 textEls[i].innerHTML = (++prevStart);
16601 d.setDate(d.getDate()+1);
16603 cells[i].className = "fc-past fc-other-month";
16604 setCellClass(this, cells[i]);
16609 for(; i < days; i++){
16610 intDay = i - startingPos + 1;
16611 textEls[i].innerHTML = (intDay);
16612 d.setDate(d.getDate()+1);
16614 cells[i].className = ''; // "x-date-active";
16615 setCellClass(this, cells[i]);
16619 for(; i < 42; i++) {
16620 textEls[i].innerHTML = (++extraDays);
16621 d.setDate(d.getDate()+1);
16623 cells[i].className = "fc-future fc-other-month";
16624 setCellClass(this, cells[i]);
16627 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
16629 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
16631 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
16632 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
16634 if(totalRows != 6){
16635 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
16636 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
16639 this.fireEvent('monthchange', this, date);
16643 if(!this.internalRender){
16644 var main = this.el.dom.firstChild;
16645 var w = main.offsetWidth;
16646 this.el.setWidth(w + this.el.getBorderWidth("lr"));
16647 Roo.fly(main).setWidth(w);
16648 this.internalRender = true;
16649 // opera does not respect the auto grow header center column
16650 // then, after it gets a width opera refuses to recalculate
16651 // without a second pass
16652 if(Roo.isOpera && !this.secondPass){
16653 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
16654 this.secondPass = true;
16655 this.update.defer(10, this, [date]);
16662 findCell : function(dt) {
16663 dt = dt.clearTime().getTime();
16665 this.cells.each(function(c){
16666 //Roo.log("check " +c.dateValue + '?=' + dt);
16667 if(c.dateValue == dt){
16677 findCells : function(ev) {
16678 var s = ev.start.clone().clearTime().getTime();
16680 var e= ev.end.clone().clearTime().getTime();
16683 this.cells.each(function(c){
16684 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
16686 if(c.dateValue > e){
16689 if(c.dateValue < s){
16698 // findBestRow: function(cells)
16702 // for (var i =0 ; i < cells.length;i++) {
16703 // ret = Math.max(cells[i].rows || 0,ret);
16710 addItem : function(ev)
16712 // look for vertical location slot in
16713 var cells = this.findCells(ev);
16715 // ev.row = this.findBestRow(cells);
16717 // work out the location.
16721 for(var i =0; i < cells.length; i++) {
16723 cells[i].row = cells[0].row;
16726 cells[i].row = cells[i].row + 1;
16736 if (crow.start.getY() == cells[i].getY()) {
16738 crow.end = cells[i];
16755 cells[0].events.push(ev);
16757 this.calevents.push(ev);
16760 clearEvents: function() {
16762 if(!this.calevents){
16766 Roo.each(this.cells.elements, function(c){
16772 Roo.each(this.calevents, function(e) {
16773 Roo.each(e.els, function(el) {
16774 el.un('mouseenter' ,this.onEventEnter, this);
16775 el.un('mouseleave' ,this.onEventLeave, this);
16780 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
16786 renderEvents: function()
16790 this.cells.each(function(c) {
16799 if(c.row != c.events.length){
16800 r = 4 - (4 - (c.row - c.events.length));
16803 c.events = ev.slice(0, r);
16804 c.more = ev.slice(r);
16806 if(c.more.length && c.more.length == 1){
16807 c.events.push(c.more.pop());
16810 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
16814 this.cells.each(function(c) {
16816 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
16819 for (var e = 0; e < c.events.length; e++){
16820 var ev = c.events[e];
16821 var rows = ev.rows;
16823 for(var i = 0; i < rows.length; i++) {
16825 // how many rows should it span..
16828 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
16829 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
16831 unselectable : "on",
16834 cls: 'fc-event-inner',
16838 // cls: 'fc-event-time',
16839 // html : cells.length > 1 ? '' : ev.time
16843 cls: 'fc-event-title',
16844 html : String.format('{0}', ev.title)
16851 cls: 'ui-resizable-handle ui-resizable-e',
16852 html : '  '
16859 cfg.cls += ' fc-event-start';
16861 if ((i+1) == rows.length) {
16862 cfg.cls += ' fc-event-end';
16865 var ctr = _this.el.select('.fc-event-container',true).first();
16866 var cg = ctr.createChild(cfg);
16868 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
16869 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
16871 var r = (c.more.length) ? 1 : 0;
16872 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
16873 cg.setWidth(ebox.right - sbox.x -2);
16875 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
16876 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
16877 cg.on('click', _this.onEventClick, _this, ev);
16888 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
16889 style : 'position: absolute',
16890 unselectable : "on",
16893 cls: 'fc-event-inner',
16897 cls: 'fc-event-title',
16905 cls: 'ui-resizable-handle ui-resizable-e',
16906 html : '  '
16912 var ctr = _this.el.select('.fc-event-container',true).first();
16913 var cg = ctr.createChild(cfg);
16915 var sbox = c.select('.fc-day-content',true).first().getBox();
16916 var ebox = c.select('.fc-day-content',true).first().getBox();
16918 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
16919 cg.setWidth(ebox.right - sbox.x -2);
16921 cg.on('click', _this.onMoreEventClick, _this, c.more);
16931 onEventEnter: function (e, el,event,d) {
16932 this.fireEvent('evententer', this, el, event);
16935 onEventLeave: function (e, el,event,d) {
16936 this.fireEvent('eventleave', this, el, event);
16939 onEventClick: function (e, el,event,d) {
16940 this.fireEvent('eventclick', this, el, event);
16943 onMonthChange: function () {
16947 onMoreEventClick: function(e, el, more)
16951 this.calpopover.placement = 'right';
16952 this.calpopover.setTitle('More');
16954 this.calpopover.setContent('');
16956 var ctr = this.calpopover.el.select('.popover-content', true).first();
16958 Roo.each(more, function(m){
16960 cls : 'fc-event-hori fc-event-draggable',
16963 var cg = ctr.createChild(cfg);
16965 cg.on('click', _this.onEventClick, _this, m);
16968 this.calpopover.show(el);
16973 onLoad: function ()
16975 this.calevents = [];
16978 if(this.store.getCount() > 0){
16979 this.store.data.each(function(d){
16982 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
16983 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
16984 time : d.data.start_time,
16985 title : d.data.title,
16986 description : d.data.description,
16987 venue : d.data.venue
16992 this.renderEvents();
16994 if(this.calevents.length && this.loadMask){
16995 this.maskEl.hide();
16999 onBeforeLoad: function()
17001 this.clearEvents();
17003 this.maskEl.show();
17017 * @class Roo.bootstrap.Popover
17018 * @extends Roo.bootstrap.Component
17019 * Bootstrap Popover class
17020 * @cfg {String} html contents of the popover (or false to use children..)
17021 * @cfg {String} title of popover (or false to hide)
17022 * @cfg {String} placement how it is placed
17023 * @cfg {String} trigger click || hover (or false to trigger manually)
17024 * @cfg {String} over what (parent or false to trigger manually.)
17025 * @cfg {Number} delay - delay before showing
17028 * Create a new Popover
17029 * @param {Object} config The config object
17032 Roo.bootstrap.Popover = function(config){
17033 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
17039 * After the popover show
17041 * @param {Roo.bootstrap.Popover} this
17046 * After the popover hide
17048 * @param {Roo.bootstrap.Popover} this
17054 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
17056 title: 'Fill in a title',
17059 placement : 'right',
17060 trigger : 'hover', // hover
17066 can_build_overlaid : false,
17068 getChildContainer : function()
17070 return this.el.select('.popover-content',true).first();
17073 getAutoCreate : function(){
17076 cls : 'popover roo-dynamic',
17077 style: 'display:block',
17083 cls : 'popover-inner',
17087 cls: 'popover-title',
17091 cls : 'popover-content',
17102 setTitle: function(str)
17105 this.el.select('.popover-title',true).first().dom.innerHTML = str;
17107 setContent: function(str)
17110 this.el.select('.popover-content',true).first().dom.innerHTML = str;
17112 // as it get's added to the bottom of the page.
17113 onRender : function(ct, position)
17115 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
17117 var cfg = Roo.apply({}, this.getAutoCreate());
17121 cfg.cls += ' ' + this.cls;
17124 cfg.style = this.style;
17126 //Roo.log("adding to ");
17127 this.el = Roo.get(document.body).createChild(cfg, position);
17128 // Roo.log(this.el);
17133 initEvents : function()
17135 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
17136 this.el.enableDisplayMode('block');
17138 if (this.over === false) {
17141 if (this.triggers === false) {
17144 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17145 var triggers = this.trigger ? this.trigger.split(' ') : [];
17146 Roo.each(triggers, function(trigger) {
17148 if (trigger == 'click') {
17149 on_el.on('click', this.toggle, this);
17150 } else if (trigger != 'manual') {
17151 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
17152 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
17154 on_el.on(eventIn ,this.enter, this);
17155 on_el.on(eventOut, this.leave, this);
17166 toggle : function () {
17167 this.hoverState == 'in' ? this.leave() : this.enter();
17170 enter : function () {
17172 clearTimeout(this.timeout);
17174 this.hoverState = 'in';
17176 if (!this.delay || !this.delay.show) {
17181 this.timeout = setTimeout(function () {
17182 if (_t.hoverState == 'in') {
17185 }, this.delay.show)
17188 leave : function() {
17189 clearTimeout(this.timeout);
17191 this.hoverState = 'out';
17193 if (!this.delay || !this.delay.hide) {
17198 this.timeout = setTimeout(function () {
17199 if (_t.hoverState == 'out') {
17202 }, this.delay.hide)
17205 show : function (on_el)
17208 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17212 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
17213 if (this.html !== false) {
17214 this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
17216 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
17217 if (!this.title.length) {
17218 this.el.select('.popover-title',true).hide();
17221 var placement = typeof this.placement == 'function' ?
17222 this.placement.call(this, this.el, on_el) :
17225 var autoToken = /\s?auto?\s?/i;
17226 var autoPlace = autoToken.test(placement);
17228 placement = placement.replace(autoToken, '') || 'top';
17232 //this.el.setXY([0,0]);
17234 this.el.dom.style.display='block';
17235 this.el.addClass(placement);
17237 //this.el.appendTo(on_el);
17239 var p = this.getPosition();
17240 var box = this.el.getBox();
17245 var align = Roo.bootstrap.Popover.alignment[placement];
17246 this.el.alignTo(on_el, align[0],align[1]);
17247 //var arrow = this.el.select('.arrow',true).first();
17248 //arrow.set(align[2],
17250 this.el.addClass('in');
17253 if (this.el.hasClass('fade')) {
17257 this.hoverState = 'in';
17259 this.fireEvent('show', this);
17264 this.el.setXY([0,0]);
17265 this.el.removeClass('in');
17267 this.hoverState = null;
17269 this.fireEvent('hide', this);
17274 Roo.bootstrap.Popover.alignment = {
17275 'left' : ['r-l', [-10,0], 'right'],
17276 'right' : ['l-r', [10,0], 'left'],
17277 'bottom' : ['t-b', [0,10], 'top'],
17278 'top' : [ 'b-t', [0,-10], 'bottom']
17289 * @class Roo.bootstrap.Progress
17290 * @extends Roo.bootstrap.Component
17291 * Bootstrap Progress class
17292 * @cfg {Boolean} striped striped of the progress bar
17293 * @cfg {Boolean} active animated of the progress bar
17297 * Create a new Progress
17298 * @param {Object} config The config object
17301 Roo.bootstrap.Progress = function(config){
17302 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
17305 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
17310 getAutoCreate : function(){
17318 cfg.cls += ' progress-striped';
17322 cfg.cls += ' active';
17341 * @class Roo.bootstrap.ProgressBar
17342 * @extends Roo.bootstrap.Component
17343 * Bootstrap ProgressBar class
17344 * @cfg {Number} aria_valuenow aria-value now
17345 * @cfg {Number} aria_valuemin aria-value min
17346 * @cfg {Number} aria_valuemax aria-value max
17347 * @cfg {String} label label for the progress bar
17348 * @cfg {String} panel (success | info | warning | danger )
17349 * @cfg {String} role role of the progress bar
17350 * @cfg {String} sr_only text
17354 * Create a new ProgressBar
17355 * @param {Object} config The config object
17358 Roo.bootstrap.ProgressBar = function(config){
17359 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
17362 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
17366 aria_valuemax : 100,
17372 getAutoCreate : function()
17377 cls: 'progress-bar',
17378 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
17390 cfg.role = this.role;
17393 if(this.aria_valuenow){
17394 cfg['aria-valuenow'] = this.aria_valuenow;
17397 if(this.aria_valuemin){
17398 cfg['aria-valuemin'] = this.aria_valuemin;
17401 if(this.aria_valuemax){
17402 cfg['aria-valuemax'] = this.aria_valuemax;
17405 if(this.label && !this.sr_only){
17406 cfg.html = this.label;
17410 cfg.cls += ' progress-bar-' + this.panel;
17416 update : function(aria_valuenow)
17418 this.aria_valuenow = aria_valuenow;
17420 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
17435 * @class Roo.bootstrap.TabGroup
17436 * @extends Roo.bootstrap.Column
17437 * Bootstrap Column class
17438 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
17439 * @cfg {Boolean} carousel true to make the group behave like a carousel
17440 * @cfg {Boolean} bullets show bullets for the panels
17441 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
17442 * @cfg {Number} timer auto slide timer .. default 0 millisecond
17443 * @cfg {Boolean} showarrow (true|false) show arrow default true
17446 * Create a new TabGroup
17447 * @param {Object} config The config object
17450 Roo.bootstrap.TabGroup = function(config){
17451 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
17453 this.navId = Roo.id();
17456 Roo.bootstrap.TabGroup.register(this);
17460 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
17463 transition : false,
17468 slideOnTouch : false,
17471 getAutoCreate : function()
17473 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
17475 cfg.cls += ' tab-content';
17477 if (this.carousel) {
17478 cfg.cls += ' carousel slide';
17481 cls : 'carousel-inner',
17485 if(this.bullets && !Roo.isTouch){
17488 cls : 'carousel-bullets',
17492 if(this.bullets_cls){
17493 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
17500 cfg.cn[0].cn.push(bullets);
17503 if(this.showarrow){
17504 cfg.cn[0].cn.push({
17506 class : 'carousel-arrow',
17510 class : 'carousel-prev',
17514 class : 'fa fa-chevron-left'
17520 class : 'carousel-next',
17524 class : 'fa fa-chevron-right'
17537 initEvents: function()
17539 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
17540 // this.el.on("touchstart", this.onTouchStart, this);
17543 if(this.autoslide){
17546 this.slideFn = window.setInterval(function() {
17547 _this.showPanelNext();
17551 if(this.showarrow){
17552 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
17553 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
17559 // onTouchStart : function(e, el, o)
17561 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
17565 // this.showPanelNext();
17569 getChildContainer : function()
17571 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
17575 * register a Navigation item
17576 * @param {Roo.bootstrap.NavItem} the navitem to add
17578 register : function(item)
17580 this.tabs.push( item);
17581 item.navId = this.navId; // not really needed..
17586 getActivePanel : function()
17589 Roo.each(this.tabs, function(t) {
17599 getPanelByName : function(n)
17602 Roo.each(this.tabs, function(t) {
17603 if (t.tabId == n) {
17611 indexOfPanel : function(p)
17614 Roo.each(this.tabs, function(t,i) {
17615 if (t.tabId == p.tabId) {
17624 * show a specific panel
17625 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
17626 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
17628 showPanel : function (pan)
17630 if(this.transition || typeof(pan) == 'undefined'){
17631 Roo.log("waiting for the transitionend");
17635 if (typeof(pan) == 'number') {
17636 pan = this.tabs[pan];
17639 if (typeof(pan) == 'string') {
17640 pan = this.getPanelByName(pan);
17643 var cur = this.getActivePanel();
17646 Roo.log('pan or acitve pan is undefined');
17650 if (pan.tabId == this.getActivePanel().tabId) {
17654 if (false === cur.fireEvent('beforedeactivate')) {
17658 if(this.bullets > 0 && !Roo.isTouch){
17659 this.setActiveBullet(this.indexOfPanel(pan));
17662 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
17664 this.transition = true;
17665 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
17666 var lr = dir == 'next' ? 'left' : 'right';
17667 pan.el.addClass(dir); // or prev
17668 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
17669 cur.el.addClass(lr); // or right
17670 pan.el.addClass(lr);
17673 cur.el.on('transitionend', function() {
17674 Roo.log("trans end?");
17676 pan.el.removeClass([lr,dir]);
17677 pan.setActive(true);
17679 cur.el.removeClass([lr]);
17680 cur.setActive(false);
17682 _this.transition = false;
17684 }, this, { single: true } );
17689 cur.setActive(false);
17690 pan.setActive(true);
17695 showPanelNext : function()
17697 var i = this.indexOfPanel(this.getActivePanel());
17699 if (i >= this.tabs.length - 1 && !this.autoslide) {
17703 if (i >= this.tabs.length - 1 && this.autoslide) {
17707 this.showPanel(this.tabs[i+1]);
17710 showPanelPrev : function()
17712 var i = this.indexOfPanel(this.getActivePanel());
17714 if (i < 1 && !this.autoslide) {
17718 if (i < 1 && this.autoslide) {
17719 i = this.tabs.length;
17722 this.showPanel(this.tabs[i-1]);
17726 addBullet: function()
17728 if(!this.bullets || Roo.isTouch){
17731 var ctr = this.el.select('.carousel-bullets',true).first();
17732 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
17733 var bullet = ctr.createChild({
17734 cls : 'bullet bullet-' + i
17735 },ctr.dom.lastChild);
17740 bullet.on('click', (function(e, el, o, ii, t){
17742 e.preventDefault();
17744 this.showPanel(ii);
17746 if(this.autoslide && this.slideFn){
17747 clearInterval(this.slideFn);
17748 this.slideFn = window.setInterval(function() {
17749 _this.showPanelNext();
17753 }).createDelegate(this, [i, bullet], true));
17758 setActiveBullet : function(i)
17764 Roo.each(this.el.select('.bullet', true).elements, function(el){
17765 el.removeClass('selected');
17768 var bullet = this.el.select('.bullet-' + i, true).first();
17774 bullet.addClass('selected');
17785 Roo.apply(Roo.bootstrap.TabGroup, {
17789 * register a Navigation Group
17790 * @param {Roo.bootstrap.NavGroup} the navgroup to add
17792 register : function(navgrp)
17794 this.groups[navgrp.navId] = navgrp;
17798 * fetch a Navigation Group based on the navigation ID
17799 * if one does not exist , it will get created.
17800 * @param {string} the navgroup to add
17801 * @returns {Roo.bootstrap.NavGroup} the navgroup
17803 get: function(navId) {
17804 if (typeof(this.groups[navId]) == 'undefined') {
17805 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
17807 return this.groups[navId] ;
17822 * @class Roo.bootstrap.TabPanel
17823 * @extends Roo.bootstrap.Component
17824 * Bootstrap TabPanel class
17825 * @cfg {Boolean} active panel active
17826 * @cfg {String} html panel content
17827 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
17828 * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
17829 * @cfg {String} href click to link..
17833 * Create a new TabPanel
17834 * @param {Object} config The config object
17837 Roo.bootstrap.TabPanel = function(config){
17838 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
17842 * Fires when the active status changes
17843 * @param {Roo.bootstrap.TabPanel} this
17844 * @param {Boolean} state the new state
17849 * @event beforedeactivate
17850 * Fires before a tab is de-activated - can be used to do validation on a form.
17851 * @param {Roo.bootstrap.TabPanel} this
17852 * @return {Boolean} false if there is an error
17855 'beforedeactivate': true
17858 this.tabId = this.tabId || Roo.id();
17862 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
17870 getAutoCreate : function(){
17873 // item is needed for carousel - not sure if it has any effect otherwise
17874 cls: 'tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
17875 html: this.html || ''
17879 cfg.cls += ' active';
17883 cfg.tabId = this.tabId;
17890 initEvents: function()
17892 var p = this.parent();
17894 this.navId = this.navId || p.navId;
17896 if (typeof(this.navId) != 'undefined') {
17897 // not really needed.. but just in case.. parent should be a NavGroup.
17898 var tg = Roo.bootstrap.TabGroup.get(this.navId);
17902 var i = tg.tabs.length - 1;
17904 if(this.active && tg.bullets > 0 && i < tg.bullets){
17905 tg.setActiveBullet(i);
17909 this.el.on('click', this.onClick, this);
17912 this.el.on("touchstart", this.onTouchStart, this);
17913 this.el.on("touchmove", this.onTouchMove, this);
17914 this.el.on("touchend", this.onTouchEnd, this);
17919 onRender : function(ct, position)
17921 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
17924 setActive : function(state)
17926 Roo.log("panel - set active " + this.tabId + "=" + state);
17928 this.active = state;
17930 this.el.removeClass('active');
17932 } else if (!this.el.hasClass('active')) {
17933 this.el.addClass('active');
17936 this.fireEvent('changed', this, state);
17939 onClick : function(e)
17941 e.preventDefault();
17943 if(!this.href.length){
17947 window.location.href = this.href;
17956 onTouchStart : function(e)
17958 this.swiping = false;
17960 this.startX = e.browserEvent.touches[0].clientX;
17961 this.startY = e.browserEvent.touches[0].clientY;
17964 onTouchMove : function(e)
17966 this.swiping = true;
17968 this.endX = e.browserEvent.touches[0].clientX;
17969 this.endY = e.browserEvent.touches[0].clientY;
17972 onTouchEnd : function(e)
17979 var tabGroup = this.parent();
17981 if(this.endX > this.startX){ // swiping right
17982 tabGroup.showPanelPrev();
17986 if(this.startX > this.endX){ // swiping left
17987 tabGroup.showPanelNext();
18006 * @class Roo.bootstrap.DateField
18007 * @extends Roo.bootstrap.Input
18008 * Bootstrap DateField class
18009 * @cfg {Number} weekStart default 0
18010 * @cfg {String} viewMode default empty, (months|years)
18011 * @cfg {String} minViewMode default empty, (months|years)
18012 * @cfg {Number} startDate default -Infinity
18013 * @cfg {Number} endDate default Infinity
18014 * @cfg {Boolean} todayHighlight default false
18015 * @cfg {Boolean} todayBtn default false
18016 * @cfg {Boolean} calendarWeeks default false
18017 * @cfg {Object} daysOfWeekDisabled default empty
18018 * @cfg {Boolean} singleMode default false (true | false)
18020 * @cfg {Boolean} keyboardNavigation default true
18021 * @cfg {String} language default en
18024 * Create a new DateField
18025 * @param {Object} config The config object
18028 Roo.bootstrap.DateField = function(config){
18029 Roo.bootstrap.DateField.superclass.constructor.call(this, config);
18033 * Fires when this field show.
18034 * @param {Roo.bootstrap.DateField} this
18035 * @param {Mixed} date The date value
18040 * Fires when this field hide.
18041 * @param {Roo.bootstrap.DateField} this
18042 * @param {Mixed} date The date value
18047 * Fires when select a date.
18048 * @param {Roo.bootstrap.DateField} this
18049 * @param {Mixed} date The date value
18053 * @event beforeselect
18054 * Fires when before select a date.
18055 * @param {Roo.bootstrap.DateField} this
18056 * @param {Mixed} date The date value
18058 beforeselect : true
18062 Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, {
18065 * @cfg {String} format
18066 * The default date format string which can be overriden for localization support. The format must be
18067 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
18071 * @cfg {String} altFormats
18072 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
18073 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
18075 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
18083 todayHighlight : false,
18089 keyboardNavigation: true,
18091 calendarWeeks: false,
18093 startDate: -Infinity,
18097 daysOfWeekDisabled: [],
18101 singleMode : false,
18103 UTCDate: function()
18105 return new Date(Date.UTC.apply(Date, arguments));
18108 UTCToday: function()
18110 var today = new Date();
18111 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
18114 getDate: function() {
18115 var d = this.getUTCDate();
18116 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
18119 getUTCDate: function() {
18123 setDate: function(d) {
18124 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
18127 setUTCDate: function(d) {
18129 this.setValue(this.formatDate(this.date));
18132 onRender: function(ct, position)
18135 Roo.bootstrap.DateField.superclass.onRender.call(this, ct, position);
18137 this.language = this.language || 'en';
18138 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
18139 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
18141 this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
18142 this.format = this.format || 'm/d/y';
18143 this.isInline = false;
18144 this.isInput = true;
18145 this.component = this.el.select('.add-on', true).first() || false;
18146 this.component = (this.component && this.component.length === 0) ? false : this.component;
18147 this.hasInput = this.component && this.inputEl().length;
18149 if (typeof(this.minViewMode === 'string')) {
18150 switch (this.minViewMode) {
18152 this.minViewMode = 1;
18155 this.minViewMode = 2;
18158 this.minViewMode = 0;
18163 if (typeof(this.viewMode === 'string')) {
18164 switch (this.viewMode) {
18177 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.DateField.template);
18179 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.DateField.template);
18181 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18183 this.picker().on('mousedown', this.onMousedown, this);
18184 this.picker().on('click', this.onClick, this);
18186 this.picker().addClass('datepicker-dropdown');
18188 this.startViewMode = this.viewMode;
18190 if(this.singleMode){
18191 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
18192 v.setVisibilityMode(Roo.Element.DISPLAY);
18196 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
18197 v.setStyle('width', '189px');
18201 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
18202 if(!this.calendarWeeks){
18207 v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18208 v.attr('colspan', function(i, val){
18209 return parseInt(val) + 1;
18214 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
18216 this.setStartDate(this.startDate);
18217 this.setEndDate(this.endDate);
18219 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
18226 if(this.isInline) {
18231 picker : function()
18233 return this.pickerEl;
18234 // return this.el.select('.datepicker', true).first();
18237 fillDow: function()
18239 var dowCnt = this.weekStart;
18248 if(this.calendarWeeks){
18256 while (dowCnt < this.weekStart + 7) {
18260 html: Roo.bootstrap.DateField.dates[this.language].daysMin[(dowCnt++)%7]
18264 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
18267 fillMonths: function()
18270 var months = this.picker().select('>.datepicker-months td', true).first();
18272 months.dom.innerHTML = '';
18278 html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
18281 months.createChild(month);
18288 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;
18290 if (this.date < this.startDate) {
18291 this.viewDate = new Date(this.startDate);
18292 } else if (this.date > this.endDate) {
18293 this.viewDate = new Date(this.endDate);
18295 this.viewDate = new Date(this.date);
18303 var d = new Date(this.viewDate),
18304 year = d.getUTCFullYear(),
18305 month = d.getUTCMonth(),
18306 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
18307 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
18308 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
18309 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
18310 currentDate = this.date && this.date.valueOf(),
18311 today = this.UTCToday();
18313 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].months[month]+' '+year;
18315 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18317 // this.picker.select('>tfoot th.today').
18318 // .text(dates[this.language].today)
18319 // .toggle(this.todayBtn !== false);
18321 this.updateNavArrows();
18324 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
18326 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
18328 prevMonth.setUTCDate(day);
18330 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
18332 var nextMonth = new Date(prevMonth);
18334 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
18336 nextMonth = nextMonth.valueOf();
18338 var fillMonths = false;
18340 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
18342 while(prevMonth.valueOf() < nextMonth) {
18345 if (prevMonth.getUTCDay() === this.weekStart) {
18347 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
18355 if(this.calendarWeeks){
18356 // ISO 8601: First week contains first thursday.
18357 // ISO also states week starts on Monday, but we can be more abstract here.
18359 // Start of current week: based on weekstart/current date
18360 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
18361 // Thursday of this week
18362 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
18363 // First Thursday of year, year from thursday
18364 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
18365 // Calendar week: ms between thursdays, div ms per day, div 7 days
18366 calWeek = (th - yth) / 864e5 / 7 + 1;
18368 fillMonths.cn.push({
18376 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
18378 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
18381 if (this.todayHighlight &&
18382 prevMonth.getUTCFullYear() == today.getFullYear() &&
18383 prevMonth.getUTCMonth() == today.getMonth() &&
18384 prevMonth.getUTCDate() == today.getDate()) {
18385 clsName += ' today';
18388 if (currentDate && prevMonth.valueOf() === currentDate) {
18389 clsName += ' active';
18392 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
18393 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
18394 clsName += ' disabled';
18397 fillMonths.cn.push({
18399 cls: 'day ' + clsName,
18400 html: prevMonth.getDate()
18403 prevMonth.setDate(prevMonth.getDate()+1);
18406 var currentYear = this.date && this.date.getUTCFullYear();
18407 var currentMonth = this.date && this.date.getUTCMonth();
18409 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
18411 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
18412 v.removeClass('active');
18414 if(currentYear === year && k === currentMonth){
18415 v.addClass('active');
18418 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
18419 v.addClass('disabled');
18425 year = parseInt(year/10, 10) * 10;
18427 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
18429 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
18432 for (var i = -1; i < 11; i++) {
18433 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
18435 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
18443 showMode: function(dir)
18446 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
18449 Roo.each(this.picker().select('>div',true).elements, function(v){
18450 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18453 this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
18458 if(this.isInline) {
18462 this.picker().removeClass(['bottom', 'top']);
18464 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
18466 * place to the top of element!
18470 this.picker().addClass('top');
18471 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
18476 this.picker().addClass('bottom');
18478 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
18481 parseDate : function(value)
18483 if(!value || value instanceof Date){
18486 var v = Date.parseDate(value, this.format);
18487 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
18488 v = Date.parseDate(value, 'Y-m-d');
18490 if(!v && this.altFormats){
18491 if(!this.altFormatsArray){
18492 this.altFormatsArray = this.altFormats.split("|");
18494 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18495 v = Date.parseDate(value, this.altFormatsArray[i]);
18501 formatDate : function(date, fmt)
18503 return (!date || !(date instanceof Date)) ?
18504 date : date.dateFormat(fmt || this.format);
18507 onFocus : function()
18509 Roo.bootstrap.DateField.superclass.onFocus.call(this);
18513 onBlur : function()
18515 Roo.bootstrap.DateField.superclass.onBlur.call(this);
18517 var d = this.inputEl().getValue();
18526 this.picker().show();
18530 this.fireEvent('show', this, this.date);
18535 if(this.isInline) {
18538 this.picker().hide();
18539 this.viewMode = this.startViewMode;
18542 this.fireEvent('hide', this, this.date);
18546 onMousedown: function(e)
18548 e.stopPropagation();
18549 e.preventDefault();
18554 Roo.bootstrap.DateField.superclass.keyup.call(this);
18558 setValue: function(v)
18560 if(this.fireEvent('beforeselect', this, v) !== false){
18561 var d = new Date(this.parseDate(v) ).clearTime();
18563 if(isNaN(d.getTime())){
18564 this.date = this.viewDate = '';
18565 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
18569 v = this.formatDate(d);
18571 Roo.bootstrap.DateField.superclass.setValue.call(this, v);
18573 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
18577 this.fireEvent('select', this, this.date);
18581 getValue: function()
18583 return this.formatDate(this.date);
18586 fireKey: function(e)
18588 if (!this.picker().isVisible()){
18589 if (e.keyCode == 27) { // allow escape to hide and re-show picker
18595 var dateChanged = false,
18597 newDate, newViewDate;
18602 e.preventDefault();
18606 if (!this.keyboardNavigation) {
18609 dir = e.keyCode == 37 ? -1 : 1;
18612 newDate = this.moveYear(this.date, dir);
18613 newViewDate = this.moveYear(this.viewDate, dir);
18614 } else if (e.shiftKey){
18615 newDate = this.moveMonth(this.date, dir);
18616 newViewDate = this.moveMonth(this.viewDate, dir);
18618 newDate = new Date(this.date);
18619 newDate.setUTCDate(this.date.getUTCDate() + dir);
18620 newViewDate = new Date(this.viewDate);
18621 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
18623 if (this.dateWithinRange(newDate)){
18624 this.date = newDate;
18625 this.viewDate = newViewDate;
18626 this.setValue(this.formatDate(this.date));
18628 e.preventDefault();
18629 dateChanged = true;
18634 if (!this.keyboardNavigation) {
18637 dir = e.keyCode == 38 ? -1 : 1;
18639 newDate = this.moveYear(this.date, dir);
18640 newViewDate = this.moveYear(this.viewDate, dir);
18641 } else if (e.shiftKey){
18642 newDate = this.moveMonth(this.date, dir);
18643 newViewDate = this.moveMonth(this.viewDate, dir);
18645 newDate = new Date(this.date);
18646 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
18647 newViewDate = new Date(this.viewDate);
18648 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
18650 if (this.dateWithinRange(newDate)){
18651 this.date = newDate;
18652 this.viewDate = newViewDate;
18653 this.setValue(this.formatDate(this.date));
18655 e.preventDefault();
18656 dateChanged = true;
18660 this.setValue(this.formatDate(this.date));
18662 e.preventDefault();
18665 this.setValue(this.formatDate(this.date));
18679 onClick: function(e)
18681 e.stopPropagation();
18682 e.preventDefault();
18684 var target = e.getTarget();
18686 if(target.nodeName.toLowerCase() === 'i'){
18687 target = Roo.get(target).dom.parentNode;
18690 var nodeName = target.nodeName;
18691 var className = target.className;
18692 var html = target.innerHTML;
18693 //Roo.log(nodeName);
18695 switch(nodeName.toLowerCase()) {
18697 switch(className) {
18703 var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
18704 switch(this.viewMode){
18706 this.viewDate = this.moveMonth(this.viewDate, dir);
18710 this.viewDate = this.moveYear(this.viewDate, dir);
18716 var date = new Date();
18717 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
18719 this.setValue(this.formatDate(this.date));
18726 if (className.indexOf('disabled') < 0) {
18727 this.viewDate.setUTCDate(1);
18728 if (className.indexOf('month') > -1) {
18729 this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
18731 var year = parseInt(html, 10) || 0;
18732 this.viewDate.setUTCFullYear(year);
18736 if(this.singleMode){
18737 this.setValue(this.formatDate(this.viewDate));
18748 //Roo.log(className);
18749 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
18750 var day = parseInt(html, 10) || 1;
18751 var year = this.viewDate.getUTCFullYear(),
18752 month = this.viewDate.getUTCMonth();
18754 if (className.indexOf('old') > -1) {
18761 } else if (className.indexOf('new') > -1) {
18769 //Roo.log([year,month,day]);
18770 this.date = this.UTCDate(year, month, day,0,0,0,0);
18771 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
18773 //Roo.log(this.formatDate(this.date));
18774 this.setValue(this.formatDate(this.date));
18781 setStartDate: function(startDate)
18783 this.startDate = startDate || -Infinity;
18784 if (this.startDate !== -Infinity) {
18785 this.startDate = this.parseDate(this.startDate);
18788 this.updateNavArrows();
18791 setEndDate: function(endDate)
18793 this.endDate = endDate || Infinity;
18794 if (this.endDate !== Infinity) {
18795 this.endDate = this.parseDate(this.endDate);
18798 this.updateNavArrows();
18801 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
18803 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
18804 if (typeof(this.daysOfWeekDisabled) !== 'object') {
18805 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
18807 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
18808 return parseInt(d, 10);
18811 this.updateNavArrows();
18814 updateNavArrows: function()
18816 if(this.singleMode){
18820 var d = new Date(this.viewDate),
18821 year = d.getUTCFullYear(),
18822 month = d.getUTCMonth();
18824 Roo.each(this.picker().select('.prev', true).elements, function(v){
18826 switch (this.viewMode) {
18829 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
18835 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
18842 Roo.each(this.picker().select('.next', true).elements, function(v){
18844 switch (this.viewMode) {
18847 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
18853 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
18861 moveMonth: function(date, dir)
18866 var new_date = new Date(date.valueOf()),
18867 day = new_date.getUTCDate(),
18868 month = new_date.getUTCMonth(),
18869 mag = Math.abs(dir),
18871 dir = dir > 0 ? 1 : -1;
18874 // If going back one month, make sure month is not current month
18875 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
18877 return new_date.getUTCMonth() == month;
18879 // If going forward one month, make sure month is as expected
18880 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
18882 return new_date.getUTCMonth() != new_month;
18884 new_month = month + dir;
18885 new_date.setUTCMonth(new_month);
18886 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
18887 if (new_month < 0 || new_month > 11) {
18888 new_month = (new_month + 12) % 12;
18891 // For magnitudes >1, move one month at a time...
18892 for (var i=0; i<mag; i++) {
18893 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
18894 new_date = this.moveMonth(new_date, dir);
18896 // ...then reset the day, keeping it in the new month
18897 new_month = new_date.getUTCMonth();
18898 new_date.setUTCDate(day);
18900 return new_month != new_date.getUTCMonth();
18903 // Common date-resetting loop -- if date is beyond end of month, make it
18906 new_date.setUTCDate(--day);
18907 new_date.setUTCMonth(new_month);
18912 moveYear: function(date, dir)
18914 return this.moveMonth(date, dir*12);
18917 dateWithinRange: function(date)
18919 return date >= this.startDate && date <= this.endDate;
18925 this.picker().remove();
18928 validateValue : function(value)
18930 if(value.length < 1) {
18931 if(this.allowBlank){
18937 if(value.length < this.minLength){
18940 if(value.length > this.maxLength){
18944 var vt = Roo.form.VTypes;
18945 if(!vt[this.vtype](value, this)){
18949 if(typeof this.validator == "function"){
18950 var msg = this.validator(value);
18956 if(this.regex && !this.regex.test(value)){
18960 if(typeof(this.parseDate(value)) == 'undefined'){
18964 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
18968 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
18978 Roo.apply(Roo.bootstrap.DateField, {
18989 html: '<i class="fa fa-arrow-left"/>'
18999 html: '<i class="fa fa-arrow-right"/>'
19041 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
19042 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
19043 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
19044 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
19045 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
19058 navFnc: 'FullYear',
19063 navFnc: 'FullYear',
19068 Roo.apply(Roo.bootstrap.DateField, {
19072 cls: 'datepicker dropdown-menu roo-dynamic',
19076 cls: 'datepicker-days',
19080 cls: 'table-condensed',
19082 Roo.bootstrap.DateField.head,
19086 Roo.bootstrap.DateField.footer
19093 cls: 'datepicker-months',
19097 cls: 'table-condensed',
19099 Roo.bootstrap.DateField.head,
19100 Roo.bootstrap.DateField.content,
19101 Roo.bootstrap.DateField.footer
19108 cls: 'datepicker-years',
19112 cls: 'table-condensed',
19114 Roo.bootstrap.DateField.head,
19115 Roo.bootstrap.DateField.content,
19116 Roo.bootstrap.DateField.footer
19135 * @class Roo.bootstrap.TimeField
19136 * @extends Roo.bootstrap.Input
19137 * Bootstrap DateField class
19141 * Create a new TimeField
19142 * @param {Object} config The config object
19145 Roo.bootstrap.TimeField = function(config){
19146 Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
19150 * Fires when this field show.
19151 * @param {Roo.bootstrap.DateField} thisthis
19152 * @param {Mixed} date The date value
19157 * Fires when this field hide.
19158 * @param {Roo.bootstrap.DateField} this
19159 * @param {Mixed} date The date value
19164 * Fires when select a date.
19165 * @param {Roo.bootstrap.DateField} this
19166 * @param {Mixed} date The date value
19172 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
19175 * @cfg {String} format
19176 * The default time format string which can be overriden for localization support. The format must be
19177 * valid according to {@link Date#parseDate} (defaults to 'H:i').
19181 onRender: function(ct, position)
19184 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
19186 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
19188 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19190 this.pop = this.picker().select('>.datepicker-time',true).first();
19191 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19193 this.picker().on('mousedown', this.onMousedown, this);
19194 this.picker().on('click', this.onClick, this);
19196 this.picker().addClass('datepicker-dropdown');
19201 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
19202 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
19203 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
19204 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
19205 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
19206 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
19210 fireKey: function(e){
19211 if (!this.picker().isVisible()){
19212 if (e.keyCode == 27) { // allow escape to hide and re-show picker
19218 e.preventDefault();
19226 this.onTogglePeriod();
19229 this.onIncrementMinutes();
19232 this.onDecrementMinutes();
19241 onClick: function(e) {
19242 e.stopPropagation();
19243 e.preventDefault();
19246 picker : function()
19248 return this.el.select('.datepicker', true).first();
19251 fillTime: function()
19253 var time = this.pop.select('tbody', true).first();
19255 time.dom.innerHTML = '';
19270 cls: 'hours-up glyphicon glyphicon-chevron-up'
19290 cls: 'minutes-up glyphicon glyphicon-chevron-up'
19311 cls: 'timepicker-hour',
19326 cls: 'timepicker-minute',
19341 cls: 'btn btn-primary period',
19363 cls: 'hours-down glyphicon glyphicon-chevron-down'
19383 cls: 'minutes-down glyphicon glyphicon-chevron-down'
19401 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
19408 var hours = this.time.getHours();
19409 var minutes = this.time.getMinutes();
19422 hours = hours - 12;
19426 hours = '0' + hours;
19430 minutes = '0' + minutes;
19433 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
19434 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
19435 this.pop.select('button', true).first().dom.innerHTML = period;
19441 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
19443 var cls = ['bottom'];
19445 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
19452 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
19457 this.picker().addClass(cls.join('-'));
19461 Roo.each(cls, function(c){
19463 _this.picker().setTop(_this.inputEl().getHeight());
19467 _this.picker().setTop(0 - _this.picker().getHeight());
19472 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
19476 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
19483 onFocus : function()
19485 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
19489 onBlur : function()
19491 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
19497 this.picker().show();
19502 this.fireEvent('show', this, this.date);
19507 this.picker().hide();
19510 this.fireEvent('hide', this, this.date);
19513 setTime : function()
19516 this.setValue(this.time.format(this.format));
19518 this.fireEvent('select', this, this.date);
19523 onMousedown: function(e){
19524 e.stopPropagation();
19525 e.preventDefault();
19528 onIncrementHours: function()
19530 Roo.log('onIncrementHours');
19531 this.time = this.time.add(Date.HOUR, 1);
19536 onDecrementHours: function()
19538 Roo.log('onDecrementHours');
19539 this.time = this.time.add(Date.HOUR, -1);
19543 onIncrementMinutes: function()
19545 Roo.log('onIncrementMinutes');
19546 this.time = this.time.add(Date.MINUTE, 1);
19550 onDecrementMinutes: function()
19552 Roo.log('onDecrementMinutes');
19553 this.time = this.time.add(Date.MINUTE, -1);
19557 onTogglePeriod: function()
19559 Roo.log('onTogglePeriod');
19560 this.time = this.time.add(Date.HOUR, 12);
19567 Roo.apply(Roo.bootstrap.TimeField, {
19597 cls: 'btn btn-info ok',
19609 Roo.apply(Roo.bootstrap.TimeField, {
19613 cls: 'datepicker dropdown-menu',
19617 cls: 'datepicker-time',
19621 cls: 'table-condensed',
19623 Roo.bootstrap.TimeField.content,
19624 Roo.bootstrap.TimeField.footer
19643 * @class Roo.bootstrap.MonthField
19644 * @extends Roo.bootstrap.Input
19645 * Bootstrap MonthField class
19647 * @cfg {String} language default en
19650 * Create a new MonthField
19651 * @param {Object} config The config object
19654 Roo.bootstrap.MonthField = function(config){
19655 Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
19660 * Fires when this field show.
19661 * @param {Roo.bootstrap.MonthField} this
19662 * @param {Mixed} date The date value
19667 * Fires when this field hide.
19668 * @param {Roo.bootstrap.MonthField} this
19669 * @param {Mixed} date The date value
19674 * Fires when select a date.
19675 * @param {Roo.bootstrap.MonthField} this
19676 * @param {String} oldvalue The old value
19677 * @param {String} newvalue The new value
19683 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
19685 onRender: function(ct, position)
19688 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
19690 this.language = this.language || 'en';
19691 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
19692 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
19694 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
19695 this.isInline = false;
19696 this.isInput = true;
19697 this.component = this.el.select('.add-on', true).first() || false;
19698 this.component = (this.component && this.component.length === 0) ? false : this.component;
19699 this.hasInput = this.component && this.inputEL().length;
19701 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
19703 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19705 this.picker().on('mousedown', this.onMousedown, this);
19706 this.picker().on('click', this.onClick, this);
19708 this.picker().addClass('datepicker-dropdown');
19710 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
19711 v.setStyle('width', '189px');
19718 if(this.isInline) {
19724 setValue: function(v, suppressEvent)
19726 var o = this.getValue();
19728 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
19732 if(suppressEvent !== true){
19733 this.fireEvent('select', this, o, v);
19738 getValue: function()
19743 onClick: function(e)
19745 e.stopPropagation();
19746 e.preventDefault();
19748 var target = e.getTarget();
19750 if(target.nodeName.toLowerCase() === 'i'){
19751 target = Roo.get(target).dom.parentNode;
19754 var nodeName = target.nodeName;
19755 var className = target.className;
19756 var html = target.innerHTML;
19758 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
19762 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
19764 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
19770 picker : function()
19772 return this.pickerEl;
19775 fillMonths: function()
19778 var months = this.picker().select('>.datepicker-months td', true).first();
19780 months.dom.innerHTML = '';
19786 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
19789 months.createChild(month);
19798 if(typeof(this.vIndex) == 'undefined' && this.value.length){
19799 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
19802 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
19803 e.removeClass('active');
19805 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
19806 e.addClass('active');
19813 if(this.isInline) {
19817 this.picker().removeClass(['bottom', 'top']);
19819 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
19821 * place to the top of element!
19825 this.picker().addClass('top');
19826 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
19831 this.picker().addClass('bottom');
19833 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
19836 onFocus : function()
19838 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
19842 onBlur : function()
19844 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
19846 var d = this.inputEl().getValue();
19855 this.picker().show();
19856 this.picker().select('>.datepicker-months', true).first().show();
19860 this.fireEvent('show', this, this.date);
19865 if(this.isInline) {
19868 this.picker().hide();
19869 this.fireEvent('hide', this, this.date);
19873 onMousedown: function(e)
19875 e.stopPropagation();
19876 e.preventDefault();
19881 Roo.bootstrap.MonthField.superclass.keyup.call(this);
19885 fireKey: function(e)
19887 if (!this.picker().isVisible()){
19888 if (e.keyCode == 27) {// allow escape to hide and re-show picker
19899 e.preventDefault();
19903 dir = e.keyCode == 37 ? -1 : 1;
19905 this.vIndex = this.vIndex + dir;
19907 if(this.vIndex < 0){
19911 if(this.vIndex > 11){
19915 if(isNaN(this.vIndex)){
19919 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
19925 dir = e.keyCode == 38 ? -1 : 1;
19927 this.vIndex = this.vIndex + dir * 4;
19929 if(this.vIndex < 0){
19933 if(this.vIndex > 11){
19937 if(isNaN(this.vIndex)){
19941 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
19946 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
19947 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
19951 e.preventDefault();
19954 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
19955 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
19971 this.picker().remove();
19976 Roo.apply(Roo.bootstrap.MonthField, {
19995 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
19996 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
20001 Roo.apply(Roo.bootstrap.MonthField, {
20005 cls: 'datepicker dropdown-menu roo-dynamic',
20009 cls: 'datepicker-months',
20013 cls: 'table-condensed',
20015 Roo.bootstrap.DateField.content
20035 * @class Roo.bootstrap.CheckBox
20036 * @extends Roo.bootstrap.Input
20037 * Bootstrap CheckBox class
20039 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20040 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
20041 * @cfg {String} boxLabel The text that appears beside the checkbox
20042 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
20043 * @cfg {Boolean} checked initnal the element
20044 * @cfg {Boolean} inline inline the element (default false)
20045 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
20048 * Create a new CheckBox
20049 * @param {Object} config The config object
20052 Roo.bootstrap.CheckBox = function(config){
20053 Roo.bootstrap.CheckBox.superclass.constructor.call(this, config);
20058 * Fires when the element is checked or unchecked.
20059 * @param {Roo.bootstrap.CheckBox} this This input
20060 * @param {Boolean} checked The new checked value
20067 Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input, {
20069 inputType: 'checkbox',
20077 getAutoCreate : function()
20079 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
20085 cfg.cls = 'form-group ' + this.inputType; //input-group
20088 cfg.cls += ' ' + this.inputType + '-inline';
20094 type : this.inputType,
20095 value : this.inputValue,
20096 cls : 'roo-' + this.inputType, //'form-box',
20097 placeholder : this.placeholder || ''
20101 if(this.inputType != 'radio'){
20105 cls : 'roo-hidden-value',
20106 value : this.checked ? this.valueOff : this.inputValue
20111 if (this.weight) { // Validity check?
20112 cfg.cls += " " + this.inputType + "-" + this.weight;
20115 if (this.disabled) {
20116 input.disabled=true;
20120 input.checked = this.checked;
20127 input.name = this.name;
20129 if(this.inputType != 'radio'){
20130 hidden.name = this.name;
20131 input.name = '_hidden_' + this.name;
20136 input.cls += ' input-' + this.size;
20141 ['xs','sm','md','lg'].map(function(size){
20142 if (settings[size]) {
20143 cfg.cls += ' col-' + size + '-' + settings[size];
20147 var inputblock = input;
20149 if (this.before || this.after) {
20152 cls : 'input-group',
20157 inputblock.cn.push({
20159 cls : 'input-group-addon',
20164 inputblock.cn.push(input);
20166 if(this.inputType != 'radio'){
20167 inputblock.cn.push(hidden);
20171 inputblock.cn.push({
20173 cls : 'input-group-addon',
20180 if (align ==='left' && this.fieldLabel.length) {
20181 // Roo.log("left and has label");
20186 cls : 'control-label',
20187 html : this.fieldLabel
20198 if(this.labelWidth > 12){
20199 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
20202 if(this.labelWidth < 13 && this.labelmd == 0){
20203 this.labelmd = this.labelWidth;
20206 if(this.labellg > 0){
20207 cfg.cn[0].cls += ' col-lg-' + this.labellg;
20208 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
20211 if(this.labelmd > 0){
20212 cfg.cn[0].cls += ' col-md-' + this.labelmd;
20213 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
20216 if(this.labelsm > 0){
20217 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
20218 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
20221 if(this.labelxs > 0){
20222 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
20223 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
20226 } else if ( this.fieldLabel.length) {
20227 // Roo.log(" label");
20231 tag: this.boxLabel ? 'span' : 'label',
20233 cls: 'control-label box-input-label',
20234 //cls : 'input-group-addon',
20235 html : this.fieldLabel
20245 // Roo.log(" no label && no align");
20246 cfg.cn = [ inputblock ] ;
20252 var boxLabelCfg = {
20254 //'for': id, // box label is handled by onclick - so no for...
20256 html: this.boxLabel
20260 boxLabelCfg.tooltip = this.tooltip;
20263 cfg.cn.push(boxLabelCfg);
20266 if(this.inputType != 'radio'){
20267 cfg.cn.push(hidden);
20275 * return the real input element.
20277 inputEl: function ()
20279 return this.el.select('input.roo-' + this.inputType,true).first();
20281 hiddenEl: function ()
20283 return this.el.select('input.roo-hidden-value',true).first();
20286 labelEl: function()
20288 return this.el.select('label.control-label',true).first();
20290 /* depricated... */
20294 return this.labelEl();
20297 boxLabelEl: function()
20299 return this.el.select('label.box-label',true).first();
20302 initEvents : function()
20304 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
20306 this.inputEl().on('click', this.onClick, this);
20308 if (this.boxLabel) {
20309 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
20312 this.startValue = this.getValue();
20315 Roo.bootstrap.CheckBox.register(this);
20319 onClick : function()
20321 this.setChecked(!this.checked);
20324 setChecked : function(state,suppressEvent)
20326 this.startValue = this.getValue();
20328 if(this.inputType == 'radio'){
20330 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20331 e.dom.checked = false;
20334 this.inputEl().dom.checked = true;
20336 this.inputEl().dom.value = this.inputValue;
20338 if(suppressEvent !== true){
20339 this.fireEvent('check', this, true);
20347 this.checked = state;
20349 this.inputEl().dom.checked = state;
20352 this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
20354 if(suppressEvent !== true){
20355 this.fireEvent('check', this, state);
20361 getValue : function()
20363 if(this.inputType == 'radio'){
20364 return this.getGroupValue();
20367 return this.hiddenEl().dom.value;
20371 getGroupValue : function()
20373 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
20377 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
20380 setValue : function(v,suppressEvent)
20382 if(this.inputType == 'radio'){
20383 this.setGroupValue(v, suppressEvent);
20387 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
20392 setGroupValue : function(v, suppressEvent)
20394 this.startValue = this.getValue();
20396 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20397 e.dom.checked = false;
20399 if(e.dom.value == v){
20400 e.dom.checked = true;
20404 if(suppressEvent !== true){
20405 this.fireEvent('check', this, true);
20413 validate : function()
20417 (this.inputType == 'radio' && this.validateRadio()) ||
20418 (this.inputType == 'checkbox' && this.validateCheckbox())
20424 this.markInvalid();
20428 validateRadio : function()
20430 if(this.allowBlank){
20436 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20437 if(!e.dom.checked){
20449 validateCheckbox : function()
20452 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
20453 //return (this.getValue() == this.inputValue) ? true : false;
20456 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20464 for(var i in group){
20469 r = (group[i].getValue() == group[i].inputValue) ? true : false;
20476 * Mark this field as valid
20478 markValid : function()
20482 this.fireEvent('valid', this);
20484 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20487 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
20494 if(this.inputType == 'radio'){
20495 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20496 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
20497 e.findParent('.form-group', false, true).addClass(_this.validClass);
20504 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20505 this.el.findParent('.form-group', false, true).addClass(this.validClass);
20509 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20515 for(var i in group){
20516 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20517 group[i].el.findParent('.form-group', false, true).addClass(this.validClass);
20522 * Mark this field as invalid
20523 * @param {String} msg The validation message
20525 markInvalid : function(msg)
20527 if(this.allowBlank){
20533 this.fireEvent('invalid', this, msg);
20535 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20538 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
20542 label.markInvalid();
20545 if(this.inputType == 'radio'){
20546 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20547 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
20548 e.findParent('.form-group', false, true).addClass(_this.invalidClass);
20555 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20556 this.el.findParent('.form-group', false, true).addClass(this.invalidClass);
20560 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20566 for(var i in group){
20567 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20568 group[i].el.findParent('.form-group', false, true).addClass(this.invalidClass);
20573 clearInvalid : function()
20575 Roo.bootstrap.Input.prototype.clearInvalid.call(this);
20577 // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20579 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20582 label.iconEl.removeClass(label.validClass);
20583 label.iconEl.removeClass(label.invalidClass);
20587 disable : function()
20589 if(this.inputType != 'radio'){
20590 Roo.bootstrap.CheckBox.superclass.disable.call(this);
20597 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20598 _this.getActionEl().addClass(this.disabledClass);
20599 e.dom.disabled = true;
20603 this.disabled = true;
20604 this.fireEvent("disable", this);
20608 enable : function()
20610 if(this.inputType != 'radio'){
20611 Roo.bootstrap.CheckBox.superclass.enable.call(this);
20618 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20619 _this.getActionEl().removeClass(this.disabledClass);
20620 e.dom.disabled = false;
20624 this.disabled = false;
20625 this.fireEvent("enable", this);
20631 Roo.apply(Roo.bootstrap.CheckBox, {
20636 * register a CheckBox Group
20637 * @param {Roo.bootstrap.CheckBox} the CheckBox to add
20639 register : function(checkbox)
20641 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
20642 this.groups[checkbox.groupId] = {};
20645 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
20649 this.groups[checkbox.groupId][checkbox.name] = checkbox;
20653 * fetch a CheckBox Group based on the group ID
20654 * @param {string} the group ID
20655 * @returns {Roo.bootstrap.CheckBox} the CheckBox group
20657 get: function(groupId) {
20658 if (typeof(this.groups[groupId]) == 'undefined') {
20662 return this.groups[groupId] ;
20675 * @class Roo.bootstrap.Radio
20676 * @extends Roo.bootstrap.Component
20677 * Bootstrap Radio class
20678 * @cfg {String} boxLabel - the label associated
20679 * @cfg {String} value - the value of radio
20682 * Create a new Radio
20683 * @param {Object} config The config object
20685 Roo.bootstrap.Radio = function(config){
20686 Roo.bootstrap.Radio.superclass.constructor.call(this, config);
20690 Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.Component, {
20696 getAutoCreate : function()
20700 cls : 'form-group radio',
20705 html : this.boxLabel
20713 initEvents : function()
20715 this.parent().register(this);
20717 this.el.on('click', this.onClick, this);
20721 onClick : function()
20723 this.setChecked(true);
20726 setChecked : function(state, suppressEvent)
20728 this.parent().setValue(this.value, suppressEvent);
20743 * @class Roo.bootstrap.SecurePass
20744 * @extends Roo.bootstrap.Input
20745 * Bootstrap SecurePass class
20749 * Create a new SecurePass
20750 * @param {Object} config The config object
20753 Roo.bootstrap.SecurePass = function (config) {
20754 // these go here, so the translation tool can replace them..
20756 PwdEmpty: "Please type a password, and then retype it to confirm.",
20757 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
20758 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
20759 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
20760 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
20761 FNInPwd: "Your password can't contain your first name. Please type a different password.",
20762 LNInPwd: "Your password can't contain your last name. Please type a different password.",
20763 TooWeak: "Your password is Too Weak."
20765 this.meterLabel = "Password strength:";
20766 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
20767 this.meterClass = [
20768 "roo-password-meter-tooweak",
20769 "roo-password-meter-weak",
20770 "roo-password-meter-medium",
20771 "roo-password-meter-strong",
20772 "roo-password-meter-grey"
20777 Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
20780 Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
20782 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
20784 * PwdEmpty: "Please type a password, and then retype it to confirm.",
20785 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
20786 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
20787 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
20788 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
20789 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
20790 * LNInPwd: "Your password can't contain your last name. Please type a different password."
20800 * @cfg {String/Object} Label for the strength meter (defaults to
20801 * 'Password strength:')
20806 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
20807 * ['Weak', 'Medium', 'Strong'])
20810 pwdStrengths: false,
20823 initEvents: function ()
20825 Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
20827 if (this.el.is('input[type=password]') && Roo.isSafari) {
20828 this.el.on('keydown', this.SafariOnKeyDown, this);
20831 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
20834 onRender: function (ct, position)
20836 Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
20837 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
20838 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
20840 this.trigger.createChild({
20845 cls: 'roo-password-meter-grey col-xs-12',
20848 //width: this.meterWidth + 'px'
20852 cls: 'roo-password-meter-text'
20858 if (this.hideTrigger) {
20859 this.trigger.setDisplayed(false);
20861 this.setSize(this.width || '', this.height || '');
20864 onDestroy: function ()
20866 if (this.trigger) {
20867 this.trigger.removeAllListeners();
20868 this.trigger.remove();
20871 this.wrap.remove();
20873 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
20876 checkStrength: function ()
20878 var pwd = this.inputEl().getValue();
20879 if (pwd == this._lastPwd) {
20884 if (this.ClientSideStrongPassword(pwd)) {
20886 } else if (this.ClientSideMediumPassword(pwd)) {
20888 } else if (this.ClientSideWeakPassword(pwd)) {
20894 Roo.log('strength1: ' + strength);
20896 //var pm = this.trigger.child('div/div/div').dom;
20897 var pm = this.trigger.child('div/div');
20898 pm.removeClass(this.meterClass);
20899 pm.addClass(this.meterClass[strength]);
20902 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
20904 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
20906 this._lastPwd = pwd;
20910 Roo.bootstrap.SecurePass.superclass.reset.call(this);
20912 this._lastPwd = '';
20914 var pm = this.trigger.child('div/div');
20915 pm.removeClass(this.meterClass);
20916 pm.addClass('roo-password-meter-grey');
20919 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
20922 this.inputEl().dom.type='password';
20925 validateValue: function (value)
20928 if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
20931 if (value.length == 0) {
20932 if (this.allowBlank) {
20933 this.clearInvalid();
20937 this.markInvalid(this.errors.PwdEmpty);
20938 this.errorMsg = this.errors.PwdEmpty;
20946 if ('[\x21-\x7e]*'.match(value)) {
20947 this.markInvalid(this.errors.PwdBadChar);
20948 this.errorMsg = this.errors.PwdBadChar;
20951 if (value.length < 6) {
20952 this.markInvalid(this.errors.PwdShort);
20953 this.errorMsg = this.errors.PwdShort;
20956 if (value.length > 16) {
20957 this.markInvalid(this.errors.PwdLong);
20958 this.errorMsg = this.errors.PwdLong;
20962 if (this.ClientSideStrongPassword(value)) {
20964 } else if (this.ClientSideMediumPassword(value)) {
20966 } else if (this.ClientSideWeakPassword(value)) {
20973 if (strength < 2) {
20974 //this.markInvalid(this.errors.TooWeak);
20975 this.errorMsg = this.errors.TooWeak;
20980 console.log('strength2: ' + strength);
20982 //var pm = this.trigger.child('div/div/div').dom;
20984 var pm = this.trigger.child('div/div');
20985 pm.removeClass(this.meterClass);
20986 pm.addClass(this.meterClass[strength]);
20988 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
20990 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
20992 this.errorMsg = '';
20996 CharacterSetChecks: function (type)
20999 this.fResult = false;
21002 isctype: function (character, type)
21005 case this.kCapitalLetter:
21006 if (character >= 'A' && character <= 'Z') {
21011 case this.kSmallLetter:
21012 if (character >= 'a' && character <= 'z') {
21018 if (character >= '0' && character <= '9') {
21023 case this.kPunctuation:
21024 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
21035 IsLongEnough: function (pwd, size)
21037 return !(pwd == null || isNaN(size) || pwd.length < size);
21040 SpansEnoughCharacterSets: function (word, nb)
21042 if (!this.IsLongEnough(word, nb))
21047 var characterSetChecks = new Array(
21048 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
21049 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
21052 for (var index = 0; index < word.length; ++index) {
21053 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21054 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
21055 characterSetChecks[nCharSet].fResult = true;
21062 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21063 if (characterSetChecks[nCharSet].fResult) {
21068 if (nCharSets < nb) {
21074 ClientSideStrongPassword: function (pwd)
21076 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
21079 ClientSideMediumPassword: function (pwd)
21081 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
21084 ClientSideWeakPassword: function (pwd)
21086 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
21089 })//<script type="text/javascript">
21092 * Based Ext JS Library 1.1.1
21093 * Copyright(c) 2006-2007, Ext JS, LLC.
21099 * @class Roo.HtmlEditorCore
21100 * @extends Roo.Component
21101 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
21103 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
21106 Roo.HtmlEditorCore = function(config){
21109 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
21114 * @event initialize
21115 * Fires when the editor is fully initialized (including the iframe)
21116 * @param {Roo.HtmlEditorCore} this
21121 * Fires when the editor is first receives the focus. Any insertion must wait
21122 * until after this event.
21123 * @param {Roo.HtmlEditorCore} this
21127 * @event beforesync
21128 * Fires before the textarea is updated with content from the editor iframe. Return false
21129 * to cancel the sync.
21130 * @param {Roo.HtmlEditorCore} this
21131 * @param {String} html
21135 * @event beforepush
21136 * Fires before the iframe editor is updated with content from the textarea. Return false
21137 * to cancel the push.
21138 * @param {Roo.HtmlEditorCore} this
21139 * @param {String} html
21144 * Fires when the textarea is updated with content from the editor iframe.
21145 * @param {Roo.HtmlEditorCore} this
21146 * @param {String} html
21151 * Fires when the iframe editor is updated with content from the textarea.
21152 * @param {Roo.HtmlEditorCore} this
21153 * @param {String} html
21158 * @event editorevent
21159 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
21160 * @param {Roo.HtmlEditorCore} this
21166 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
21168 // defaults : white / black...
21169 this.applyBlacklists();
21176 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
21180 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
21186 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
21191 * @cfg {Number} height (in pixels)
21195 * @cfg {Number} width (in pixels)
21200 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
21203 stylesheets: false,
21208 // private properties
21209 validationEvent : false,
21211 initialized : false,
21213 sourceEditMode : false,
21214 onFocus : Roo.emptyFn,
21216 hideMode:'offsets',
21220 // blacklist + whitelisted elements..
21227 * Protected method that will not generally be called directly. It
21228 * is called when the editor initializes the iframe with HTML contents. Override this method if you
21229 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
21231 getDocMarkup : function(){
21235 // inherit styels from page...??
21236 if (this.stylesheets === false) {
21238 Roo.get(document.head).select('style').each(function(node) {
21239 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21242 Roo.get(document.head).select('link').each(function(node) {
21243 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21246 } else if (!this.stylesheets.length) {
21248 st = '<style type="text/css">' +
21249 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21255 st += '<style type="text/css">' +
21256 'IMG { cursor: pointer } ' +
21260 return '<html><head>' + st +
21261 //<style type="text/css">' +
21262 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21264 ' </head><body class="roo-htmleditor-body"></body></html>';
21268 onRender : function(ct, position)
21271 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
21272 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
21275 this.el.dom.style.border = '0 none';
21276 this.el.dom.setAttribute('tabIndex', -1);
21277 this.el.addClass('x-hidden hide');
21281 if(Roo.isIE){ // fix IE 1px bogus margin
21282 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
21286 this.frameId = Roo.id();
21290 var iframe = this.owner.wrap.createChild({
21292 cls: 'form-control', // bootstrap..
21294 name: this.frameId,
21295 frameBorder : 'no',
21296 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
21301 this.iframe = iframe.dom;
21303 this.assignDocWin();
21305 this.doc.designMode = 'on';
21308 this.doc.write(this.getDocMarkup());
21312 var task = { // must defer to wait for browser to be ready
21314 //console.log("run task?" + this.doc.readyState);
21315 this.assignDocWin();
21316 if(this.doc.body || this.doc.readyState == 'complete'){
21318 this.doc.designMode="on";
21322 Roo.TaskMgr.stop(task);
21323 this.initEditor.defer(10, this);
21330 Roo.TaskMgr.start(task);
21335 onResize : function(w, h)
21337 Roo.log('resize: ' +w + ',' + h );
21338 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
21342 if(typeof w == 'number'){
21344 this.iframe.style.width = w + 'px';
21346 if(typeof h == 'number'){
21348 this.iframe.style.height = h + 'px';
21350 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
21357 * Toggles the editor between standard and source edit mode.
21358 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21360 toggleSourceEdit : function(sourceEditMode){
21362 this.sourceEditMode = sourceEditMode === true;
21364 if(this.sourceEditMode){
21366 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
21369 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
21370 //this.iframe.className = '';
21373 //this.setSize(this.owner.wrap.getSize());
21374 //this.fireEvent('editmodechange', this, this.sourceEditMode);
21381 * Protected method that will not generally be called directly. If you need/want
21382 * custom HTML cleanup, this is the method you should override.
21383 * @param {String} html The HTML to be cleaned
21384 * return {String} The cleaned HTML
21386 cleanHtml : function(html){
21387 html = String(html);
21388 if(html.length > 5){
21389 if(Roo.isSafari){ // strip safari nonsense
21390 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
21393 if(html == ' '){
21400 * HTML Editor -> Textarea
21401 * Protected method that will not generally be called directly. Syncs the contents
21402 * of the editor iframe with the textarea.
21404 syncValue : function(){
21405 if(this.initialized){
21406 var bd = (this.doc.body || this.doc.documentElement);
21407 //this.cleanUpPaste(); -- this is done else where and causes havoc..
21408 var html = bd.innerHTML;
21410 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
21411 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
21413 html = '<div style="'+m[0]+'">' + html + '</div>';
21416 html = this.cleanHtml(html);
21417 // fix up the special chars.. normaly like back quotes in word...
21418 // however we do not want to do this with chinese..
21419 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
21420 var cc = b.charCodeAt();
21422 (cc >= 0x4E00 && cc < 0xA000 ) ||
21423 (cc >= 0x3400 && cc < 0x4E00 ) ||
21424 (cc >= 0xf900 && cc < 0xfb00 )
21430 if(this.owner.fireEvent('beforesync', this, html) !== false){
21431 this.el.dom.value = html;
21432 this.owner.fireEvent('sync', this, html);
21438 * Protected method that will not generally be called directly. Pushes the value of the textarea
21439 * into the iframe editor.
21441 pushValue : function(){
21442 if(this.initialized){
21443 var v = this.el.dom.value.trim();
21445 // if(v.length < 1){
21449 if(this.owner.fireEvent('beforepush', this, v) !== false){
21450 var d = (this.doc.body || this.doc.documentElement);
21452 this.cleanUpPaste();
21453 this.el.dom.value = d.innerHTML;
21454 this.owner.fireEvent('push', this, v);
21460 deferFocus : function(){
21461 this.focus.defer(10, this);
21465 focus : function(){
21466 if(this.win && !this.sourceEditMode){
21473 assignDocWin: function()
21475 var iframe = this.iframe;
21478 this.doc = iframe.contentWindow.document;
21479 this.win = iframe.contentWindow;
21481 // if (!Roo.get(this.frameId)) {
21484 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21485 // this.win = Roo.get(this.frameId).dom.contentWindow;
21487 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
21491 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21492 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
21497 initEditor : function(){
21498 //console.log("INIT EDITOR");
21499 this.assignDocWin();
21503 this.doc.designMode="on";
21505 this.doc.write(this.getDocMarkup());
21508 var dbody = (this.doc.body || this.doc.documentElement);
21509 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
21510 // this copies styles from the containing element into thsi one..
21511 // not sure why we need all of this..
21512 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
21514 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
21515 //ss['background-attachment'] = 'fixed'; // w3c
21516 dbody.bgProperties = 'fixed'; // ie
21517 //Roo.DomHelper.applyStyles(dbody, ss);
21518 Roo.EventManager.on(this.doc, {
21519 //'mousedown': this.onEditorEvent,
21520 'mouseup': this.onEditorEvent,
21521 'dblclick': this.onEditorEvent,
21522 'click': this.onEditorEvent,
21523 'keyup': this.onEditorEvent,
21528 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
21530 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
21531 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
21533 this.initialized = true;
21535 this.owner.fireEvent('initialize', this);
21540 onDestroy : function(){
21546 //for (var i =0; i < this.toolbars.length;i++) {
21547 // // fixme - ask toolbars for heights?
21548 // this.toolbars[i].onDestroy();
21551 //this.wrap.dom.innerHTML = '';
21552 //this.wrap.remove();
21557 onFirstFocus : function(){
21559 this.assignDocWin();
21562 this.activated = true;
21565 if(Roo.isGecko){ // prevent silly gecko errors
21567 var s = this.win.getSelection();
21568 if(!s.focusNode || s.focusNode.nodeType != 3){
21569 var r = s.getRangeAt(0);
21570 r.selectNodeContents((this.doc.body || this.doc.documentElement));
21575 this.execCmd('useCSS', true);
21576 this.execCmd('styleWithCSS', false);
21579 this.owner.fireEvent('activate', this);
21583 adjustFont: function(btn){
21584 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
21585 //if(Roo.isSafari){ // safari
21588 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
21589 if(Roo.isSafari){ // safari
21590 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
21591 v = (v < 10) ? 10 : v;
21592 v = (v > 48) ? 48 : v;
21593 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
21598 v = Math.max(1, v+adjust);
21600 this.execCmd('FontSize', v );
21603 onEditorEvent : function(e)
21605 this.owner.fireEvent('editorevent', this, e);
21606 // this.updateToolbar();
21607 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
21610 insertTag : function(tg)
21612 // could be a bit smarter... -> wrap the current selected tRoo..
21613 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
21615 range = this.createRange(this.getSelection());
21616 var wrappingNode = this.doc.createElement(tg.toLowerCase());
21617 wrappingNode.appendChild(range.extractContents());
21618 range.insertNode(wrappingNode);
21625 this.execCmd("formatblock", tg);
21629 insertText : function(txt)
21633 var range = this.createRange();
21634 range.deleteContents();
21635 //alert(Sender.getAttribute('label'));
21637 range.insertNode(this.doc.createTextNode(txt));
21643 * Executes a Midas editor command on the editor document and performs necessary focus and
21644 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
21645 * @param {String} cmd The Midas command
21646 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
21648 relayCmd : function(cmd, value){
21650 this.execCmd(cmd, value);
21651 this.owner.fireEvent('editorevent', this);
21652 //this.updateToolbar();
21653 this.owner.deferFocus();
21657 * Executes a Midas editor command directly on the editor document.
21658 * For visual commands, you should use {@link #relayCmd} instead.
21659 * <b>This should only be called after the editor is initialized.</b>
21660 * @param {String} cmd The Midas command
21661 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
21663 execCmd : function(cmd, value){
21664 this.doc.execCommand(cmd, false, value === undefined ? null : value);
21671 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
21673 * @param {String} text | dom node..
21675 insertAtCursor : function(text)
21678 if(!this.activated){
21684 var r = this.doc.selection.createRange();
21695 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
21699 // from jquery ui (MIT licenced)
21701 var win = this.win;
21703 if (win.getSelection && win.getSelection().getRangeAt) {
21704 range = win.getSelection().getRangeAt(0);
21705 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
21706 range.insertNode(node);
21707 } else if (win.document.selection && win.document.selection.createRange) {
21708 // no firefox support
21709 var txt = typeof(text) == 'string' ? text : text.outerHTML;
21710 win.document.selection.createRange().pasteHTML(txt);
21712 // no firefox support
21713 var txt = typeof(text) == 'string' ? text : text.outerHTML;
21714 this.execCmd('InsertHTML', txt);
21723 mozKeyPress : function(e){
21725 var c = e.getCharCode(), cmd;
21728 c = String.fromCharCode(c).toLowerCase();
21742 this.cleanUpPaste.defer(100, this);
21750 e.preventDefault();
21758 fixKeys : function(){ // load time branching for fastest keydown performance
21760 return function(e){
21761 var k = e.getKey(), r;
21764 r = this.doc.selection.createRange();
21767 r.pasteHTML('    ');
21774 r = this.doc.selection.createRange();
21776 var target = r.parentElement();
21777 if(!target || target.tagName.toLowerCase() != 'li'){
21779 r.pasteHTML('<br />');
21785 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21786 this.cleanUpPaste.defer(100, this);
21792 }else if(Roo.isOpera){
21793 return function(e){
21794 var k = e.getKey();
21798 this.execCmd('InsertHTML','    ');
21801 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21802 this.cleanUpPaste.defer(100, this);
21807 }else if(Roo.isSafari){
21808 return function(e){
21809 var k = e.getKey();
21813 this.execCmd('InsertText','\t');
21817 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21818 this.cleanUpPaste.defer(100, this);
21826 getAllAncestors: function()
21828 var p = this.getSelectedNode();
21831 a.push(p); // push blank onto stack..
21832 p = this.getParentElement();
21836 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
21840 a.push(this.doc.body);
21844 lastSelNode : false,
21847 getSelection : function()
21849 this.assignDocWin();
21850 return Roo.isIE ? this.doc.selection : this.win.getSelection();
21853 getSelectedNode: function()
21855 // this may only work on Gecko!!!
21857 // should we cache this!!!!
21862 var range = this.createRange(this.getSelection()).cloneRange();
21865 var parent = range.parentElement();
21867 var testRange = range.duplicate();
21868 testRange.moveToElementText(parent);
21869 if (testRange.inRange(range)) {
21872 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
21875 parent = parent.parentElement;
21880 // is ancestor a text element.
21881 var ac = range.commonAncestorContainer;
21882 if (ac.nodeType == 3) {
21883 ac = ac.parentNode;
21886 var ar = ac.childNodes;
21889 var other_nodes = [];
21890 var has_other_nodes = false;
21891 for (var i=0;i<ar.length;i++) {
21892 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
21895 // fullly contained node.
21897 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
21902 // probably selected..
21903 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
21904 other_nodes.push(ar[i]);
21908 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
21913 has_other_nodes = true;
21915 if (!nodes.length && other_nodes.length) {
21916 nodes= other_nodes;
21918 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
21924 createRange: function(sel)
21926 // this has strange effects when using with
21927 // top toolbar - not sure if it's a great idea.
21928 //this.editor.contentWindow.focus();
21929 if (typeof sel != "undefined") {
21931 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
21933 return this.doc.createRange();
21936 return this.doc.createRange();
21939 getParentElement: function()
21942 this.assignDocWin();
21943 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
21945 var range = this.createRange(sel);
21948 var p = range.commonAncestorContainer;
21949 while (p.nodeType == 3) { // text node
21960 * Range intersection.. the hard stuff...
21964 * [ -- selected range --- ]
21968 * if end is before start or hits it. fail.
21969 * if start is after end or hits it fail.
21971 * if either hits (but other is outside. - then it's not
21977 // @see http://www.thismuchiknow.co.uk/?p=64.
21978 rangeIntersectsNode : function(range, node)
21980 var nodeRange = node.ownerDocument.createRange();
21982 nodeRange.selectNode(node);
21984 nodeRange.selectNodeContents(node);
21987 var rangeStartRange = range.cloneRange();
21988 rangeStartRange.collapse(true);
21990 var rangeEndRange = range.cloneRange();
21991 rangeEndRange.collapse(false);
21993 var nodeStartRange = nodeRange.cloneRange();
21994 nodeStartRange.collapse(true);
21996 var nodeEndRange = nodeRange.cloneRange();
21997 nodeEndRange.collapse(false);
21999 return rangeStartRange.compareBoundaryPoints(
22000 Range.START_TO_START, nodeEndRange) == -1 &&
22001 rangeEndRange.compareBoundaryPoints(
22002 Range.START_TO_START, nodeStartRange) == 1;
22006 rangeCompareNode : function(range, node)
22008 var nodeRange = node.ownerDocument.createRange();
22010 nodeRange.selectNode(node);
22012 nodeRange.selectNodeContents(node);
22016 range.collapse(true);
22018 nodeRange.collapse(true);
22020 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
22021 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
22023 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
22025 var nodeIsBefore = ss == 1;
22026 var nodeIsAfter = ee == -1;
22028 if (nodeIsBefore && nodeIsAfter) {
22031 if (!nodeIsBefore && nodeIsAfter) {
22032 return 1; //right trailed.
22035 if (nodeIsBefore && !nodeIsAfter) {
22036 return 2; // left trailed.
22042 // private? - in a new class?
22043 cleanUpPaste : function()
22045 // cleans up the whole document..
22046 Roo.log('cleanuppaste');
22048 this.cleanUpChildren(this.doc.body);
22049 var clean = this.cleanWordChars(this.doc.body.innerHTML);
22050 if (clean != this.doc.body.innerHTML) {
22051 this.doc.body.innerHTML = clean;
22056 cleanWordChars : function(input) {// change the chars to hex code
22057 var he = Roo.HtmlEditorCore;
22059 var output = input;
22060 Roo.each(he.swapCodes, function(sw) {
22061 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
22063 output = output.replace(swapper, sw[1]);
22070 cleanUpChildren : function (n)
22072 if (!n.childNodes.length) {
22075 for (var i = n.childNodes.length-1; i > -1 ; i--) {
22076 this.cleanUpChild(n.childNodes[i]);
22083 cleanUpChild : function (node)
22086 //console.log(node);
22087 if (node.nodeName == "#text") {
22088 // clean up silly Windows -- stuff?
22091 if (node.nodeName == "#comment") {
22092 node.parentNode.removeChild(node);
22093 // clean up silly Windows -- stuff?
22096 var lcname = node.tagName.toLowerCase();
22097 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
22098 // whitelist of tags..
22100 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
22102 node.parentNode.removeChild(node);
22107 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
22109 // remove <a name=....> as rendering on yahoo mailer is borked with this.
22110 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
22112 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
22113 // remove_keep_children = true;
22116 if (remove_keep_children) {
22117 this.cleanUpChildren(node);
22118 // inserts everything just before this node...
22119 while (node.childNodes.length) {
22120 var cn = node.childNodes[0];
22121 node.removeChild(cn);
22122 node.parentNode.insertBefore(cn, node);
22124 node.parentNode.removeChild(node);
22128 if (!node.attributes || !node.attributes.length) {
22129 this.cleanUpChildren(node);
22133 function cleanAttr(n,v)
22136 if (v.match(/^\./) || v.match(/^\//)) {
22139 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/)) {
22142 if (v.match(/^#/)) {
22145 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
22146 node.removeAttribute(n);
22150 var cwhite = this.cwhite;
22151 var cblack = this.cblack;
22153 function cleanStyle(n,v)
22155 if (v.match(/expression/)) { //XSS?? should we even bother..
22156 node.removeAttribute(n);
22160 var parts = v.split(/;/);
22163 Roo.each(parts, function(p) {
22164 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
22168 var l = p.split(':').shift().replace(/\s+/g,'');
22169 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
22171 if ( cwhite.length && cblack.indexOf(l) > -1) {
22172 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22173 //node.removeAttribute(n);
22177 // only allow 'c whitelisted system attributes'
22178 if ( cwhite.length && cwhite.indexOf(l) < 0) {
22179 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22180 //node.removeAttribute(n);
22190 if (clean.length) {
22191 node.setAttribute(n, clean.join(';'));
22193 node.removeAttribute(n);
22199 for (var i = node.attributes.length-1; i > -1 ; i--) {
22200 var a = node.attributes[i];
22203 if (a.name.toLowerCase().substr(0,2)=='on') {
22204 node.removeAttribute(a.name);
22207 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
22208 node.removeAttribute(a.name);
22211 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
22212 cleanAttr(a.name,a.value); // fixme..
22215 if (a.name == 'style') {
22216 cleanStyle(a.name,a.value);
22219 /// clean up MS crap..
22220 // tecnically this should be a list of valid class'es..
22223 if (a.name == 'class') {
22224 if (a.value.match(/^Mso/)) {
22225 node.className = '';
22228 if (a.value.match(/^body$/)) {
22229 node.className = '';
22240 this.cleanUpChildren(node);
22246 * Clean up MS wordisms...
22248 cleanWord : function(node)
22253 this.cleanWord(this.doc.body);
22256 if (node.nodeName == "#text") {
22257 // clean up silly Windows -- stuff?
22260 if (node.nodeName == "#comment") {
22261 node.parentNode.removeChild(node);
22262 // clean up silly Windows -- stuff?
22266 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
22267 node.parentNode.removeChild(node);
22271 // remove - but keep children..
22272 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
22273 while (node.childNodes.length) {
22274 var cn = node.childNodes[0];
22275 node.removeChild(cn);
22276 node.parentNode.insertBefore(cn, node);
22278 node.parentNode.removeChild(node);
22279 this.iterateChildren(node, this.cleanWord);
22283 if (node.className.length) {
22285 var cn = node.className.split(/\W+/);
22287 Roo.each(cn, function(cls) {
22288 if (cls.match(/Mso[a-zA-Z]+/)) {
22293 node.className = cna.length ? cna.join(' ') : '';
22295 node.removeAttribute("class");
22299 if (node.hasAttribute("lang")) {
22300 node.removeAttribute("lang");
22303 if (node.hasAttribute("style")) {
22305 var styles = node.getAttribute("style").split(";");
22307 Roo.each(styles, function(s) {
22308 if (!s.match(/:/)) {
22311 var kv = s.split(":");
22312 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
22315 // what ever is left... we allow.
22318 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22319 if (!nstyle.length) {
22320 node.removeAttribute('style');
22323 this.iterateChildren(node, this.cleanWord);
22329 * iterateChildren of a Node, calling fn each time, using this as the scole..
22330 * @param {DomNode} node node to iterate children of.
22331 * @param {Function} fn method of this class to call on each item.
22333 iterateChildren : function(node, fn)
22335 if (!node.childNodes.length) {
22338 for (var i = node.childNodes.length-1; i > -1 ; i--) {
22339 fn.call(this, node.childNodes[i])
22345 * cleanTableWidths.
22347 * Quite often pasting from word etc.. results in tables with column and widths.
22348 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
22351 cleanTableWidths : function(node)
22356 this.cleanTableWidths(this.doc.body);
22361 if (node.nodeName == "#text" || node.nodeName == "#comment") {
22364 Roo.log(node.tagName);
22365 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
22366 this.iterateChildren(node, this.cleanTableWidths);
22369 if (node.hasAttribute('width')) {
22370 node.removeAttribute('width');
22374 if (node.hasAttribute("style")) {
22377 var styles = node.getAttribute("style").split(";");
22379 Roo.each(styles, function(s) {
22380 if (!s.match(/:/)) {
22383 var kv = s.split(":");
22384 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
22387 // what ever is left... we allow.
22390 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22391 if (!nstyle.length) {
22392 node.removeAttribute('style');
22396 this.iterateChildren(node, this.cleanTableWidths);
22404 domToHTML : function(currentElement, depth, nopadtext) {
22406 depth = depth || 0;
22407 nopadtext = nopadtext || false;
22409 if (!currentElement) {
22410 return this.domToHTML(this.doc.body);
22413 //Roo.log(currentElement);
22415 var allText = false;
22416 var nodeName = currentElement.nodeName;
22417 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
22419 if (nodeName == '#text') {
22421 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
22426 if (nodeName != 'BODY') {
22429 // Prints the node tagName, such as <A>, <IMG>, etc
22432 for(i = 0; i < currentElement.attributes.length;i++) {
22434 var aname = currentElement.attributes.item(i).name;
22435 if (!currentElement.attributes.item(i).value.length) {
22438 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
22441 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
22450 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
22453 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
22458 // Traverse the tree
22460 var currentElementChild = currentElement.childNodes.item(i);
22461 var allText = true;
22462 var innerHTML = '';
22464 while (currentElementChild) {
22465 // Formatting code (indent the tree so it looks nice on the screen)
22466 var nopad = nopadtext;
22467 if (lastnode == 'SPAN') {
22471 if (currentElementChild.nodeName == '#text') {
22472 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
22473 toadd = nopadtext ? toadd : toadd.trim();
22474 if (!nopad && toadd.length > 80) {
22475 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
22477 innerHTML += toadd;
22480 currentElementChild = currentElement.childNodes.item(i);
22486 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
22488 // Recursively traverse the tree structure of the child node
22489 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
22490 lastnode = currentElementChild.nodeName;
22492 currentElementChild=currentElement.childNodes.item(i);
22498 // The remaining code is mostly for formatting the tree
22499 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
22504 ret+= "</"+tagName+">";
22510 applyBlacklists : function()
22512 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
22513 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
22517 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
22518 if (b.indexOf(tag) > -1) {
22521 this.white.push(tag);
22525 Roo.each(w, function(tag) {
22526 if (b.indexOf(tag) > -1) {
22529 if (this.white.indexOf(tag) > -1) {
22532 this.white.push(tag);
22537 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
22538 if (w.indexOf(tag) > -1) {
22541 this.black.push(tag);
22545 Roo.each(b, function(tag) {
22546 if (w.indexOf(tag) > -1) {
22549 if (this.black.indexOf(tag) > -1) {
22552 this.black.push(tag);
22557 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
22558 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
22562 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
22563 if (b.indexOf(tag) > -1) {
22566 this.cwhite.push(tag);
22570 Roo.each(w, function(tag) {
22571 if (b.indexOf(tag) > -1) {
22574 if (this.cwhite.indexOf(tag) > -1) {
22577 this.cwhite.push(tag);
22582 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
22583 if (w.indexOf(tag) > -1) {
22586 this.cblack.push(tag);
22590 Roo.each(b, function(tag) {
22591 if (w.indexOf(tag) > -1) {
22594 if (this.cblack.indexOf(tag) > -1) {
22597 this.cblack.push(tag);
22602 setStylesheets : function(stylesheets)
22604 if(typeof(stylesheets) == 'string'){
22605 Roo.get(this.iframe.contentDocument.head).createChild({
22607 rel : 'stylesheet',
22616 Roo.each(stylesheets, function(s) {
22621 Roo.get(_this.iframe.contentDocument.head).createChild({
22623 rel : 'stylesheet',
22632 removeStylesheets : function()
22636 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
22641 // hide stuff that is not compatible
22655 * @event specialkey
22659 * @cfg {String} fieldClass @hide
22662 * @cfg {String} focusClass @hide
22665 * @cfg {String} autoCreate @hide
22668 * @cfg {String} inputType @hide
22671 * @cfg {String} invalidClass @hide
22674 * @cfg {String} invalidText @hide
22677 * @cfg {String} msgFx @hide
22680 * @cfg {String} validateOnBlur @hide
22684 Roo.HtmlEditorCore.white = [
22685 'area', 'br', 'img', 'input', 'hr', 'wbr',
22687 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
22688 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
22689 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
22690 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
22691 'table', 'ul', 'xmp',
22693 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
22696 'dir', 'menu', 'ol', 'ul', 'dl',
22702 Roo.HtmlEditorCore.black = [
22703 // 'embed', 'object', // enable - backend responsiblity to clean thiese
22705 'base', 'basefont', 'bgsound', 'blink', 'body',
22706 'frame', 'frameset', 'head', 'html', 'ilayer',
22707 'iframe', 'layer', 'link', 'meta', 'object',
22708 'script', 'style' ,'title', 'xml' // clean later..
22710 Roo.HtmlEditorCore.clean = [
22711 'script', 'style', 'title', 'xml'
22713 Roo.HtmlEditorCore.remove = [
22718 Roo.HtmlEditorCore.ablack = [
22722 Roo.HtmlEditorCore.aclean = [
22723 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
22727 Roo.HtmlEditorCore.pwhite= [
22728 'http', 'https', 'mailto'
22731 // white listed style attributes.
22732 Roo.HtmlEditorCore.cwhite= [
22733 // 'text-align', /// default is to allow most things..
22739 // black listed style attributes.
22740 Roo.HtmlEditorCore.cblack= [
22741 // 'font-size' -- this can be set by the project
22745 Roo.HtmlEditorCore.swapCodes =[
22764 * @class Roo.bootstrap.HtmlEditor
22765 * @extends Roo.bootstrap.TextArea
22766 * Bootstrap HtmlEditor class
22769 * Create a new HtmlEditor
22770 * @param {Object} config The config object
22773 Roo.bootstrap.HtmlEditor = function(config){
22774 Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
22775 if (!this.toolbars) {
22776 this.toolbars = [];
22779 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
22782 * @event initialize
22783 * Fires when the editor is fully initialized (including the iframe)
22784 * @param {HtmlEditor} this
22789 * Fires when the editor is first receives the focus. Any insertion must wait
22790 * until after this event.
22791 * @param {HtmlEditor} this
22795 * @event beforesync
22796 * Fires before the textarea is updated with content from the editor iframe. Return false
22797 * to cancel the sync.
22798 * @param {HtmlEditor} this
22799 * @param {String} html
22803 * @event beforepush
22804 * Fires before the iframe editor is updated with content from the textarea. Return false
22805 * to cancel the push.
22806 * @param {HtmlEditor} this
22807 * @param {String} html
22812 * Fires when the textarea is updated with content from the editor iframe.
22813 * @param {HtmlEditor} this
22814 * @param {String} html
22819 * Fires when the iframe editor is updated with content from the textarea.
22820 * @param {HtmlEditor} this
22821 * @param {String} html
22825 * @event editmodechange
22826 * Fires when the editor switches edit modes
22827 * @param {HtmlEditor} this
22828 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
22830 editmodechange: true,
22832 * @event editorevent
22833 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
22834 * @param {HtmlEditor} this
22838 * @event firstfocus
22839 * Fires when on first focus - needed by toolbars..
22840 * @param {HtmlEditor} this
22845 * Auto save the htmlEditor value as a file into Events
22846 * @param {HtmlEditor} this
22850 * @event savedpreview
22851 * preview the saved version of htmlEditor
22852 * @param {HtmlEditor} this
22859 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
22863 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
22868 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
22873 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
22878 * @cfg {Number} height (in pixels)
22882 * @cfg {Number} width (in pixels)
22887 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
22890 stylesheets: false,
22895 // private properties
22896 validationEvent : false,
22898 initialized : false,
22901 onFocus : Roo.emptyFn,
22903 hideMode:'offsets',
22905 tbContainer : false,
22907 toolbarContainer :function() {
22908 return this.wrap.select('.x-html-editor-tb',true).first();
22912 * Protected method that will not generally be called directly. It
22913 * is called when the editor creates its toolbar. Override this method if you need to
22914 * add custom toolbar buttons.
22915 * @param {HtmlEditor} editor
22917 createToolbar : function(){
22918 Roo.log('renewing');
22919 Roo.log("create toolbars");
22921 this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
22922 this.toolbars[0].render(this.toolbarContainer());
22926 // if (!editor.toolbars || !editor.toolbars.length) {
22927 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
22930 // for (var i =0 ; i < editor.toolbars.length;i++) {
22931 // editor.toolbars[i] = Roo.factory(
22932 // typeof(editor.toolbars[i]) == 'string' ?
22933 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
22934 // Roo.bootstrap.HtmlEditor);
22935 // editor.toolbars[i].init(editor);
22941 onRender : function(ct, position)
22943 // Roo.log("Call onRender: " + this.xtype);
22945 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
22947 this.wrap = this.inputEl().wrap({
22948 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
22951 this.editorcore.onRender(ct, position);
22953 if (this.resizable) {
22954 this.resizeEl = new Roo.Resizable(this.wrap, {
22958 minHeight : this.height,
22959 height: this.height,
22960 handles : this.resizable,
22963 resize : function(r, w, h) {
22964 _t.onResize(w,h); // -something
22970 this.createToolbar(this);
22973 if(!this.width && this.resizable){
22974 this.setSize(this.wrap.getSize());
22976 if (this.resizeEl) {
22977 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
22978 // should trigger onReize..
22984 onResize : function(w, h)
22986 Roo.log('resize: ' +w + ',' + h );
22987 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
22991 if(this.inputEl() ){
22992 if(typeof w == 'number'){
22993 var aw = w - this.wrap.getFrameWidth('lr');
22994 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
22997 if(typeof h == 'number'){
22998 var tbh = -11; // fixme it needs to tool bar size!
22999 for (var i =0; i < this.toolbars.length;i++) {
23000 // fixme - ask toolbars for heights?
23001 tbh += this.toolbars[i].el.getHeight();
23002 //if (this.toolbars[i].footer) {
23003 // tbh += this.toolbars[i].footer.el.getHeight();
23011 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23012 ah -= 5; // knock a few pixes off for look..
23013 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
23017 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
23018 this.editorcore.onResize(ew,eh);
23023 * Toggles the editor between standard and source edit mode.
23024 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23026 toggleSourceEdit : function(sourceEditMode)
23028 this.editorcore.toggleSourceEdit(sourceEditMode);
23030 if(this.editorcore.sourceEditMode){
23031 Roo.log('editor - showing textarea');
23034 // Roo.log(this.syncValue());
23036 this.inputEl().removeClass(['hide', 'x-hidden']);
23037 this.inputEl().dom.removeAttribute('tabIndex');
23038 this.inputEl().focus();
23040 Roo.log('editor - hiding textarea');
23042 // Roo.log(this.pushValue());
23045 this.inputEl().addClass(['hide', 'x-hidden']);
23046 this.inputEl().dom.setAttribute('tabIndex', -1);
23047 //this.deferFocus();
23050 if(this.resizable){
23051 this.setSize(this.wrap.getSize());
23054 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
23057 // private (for BoxComponent)
23058 adjustSize : Roo.BoxComponent.prototype.adjustSize,
23060 // private (for BoxComponent)
23061 getResizeEl : function(){
23065 // private (for BoxComponent)
23066 getPositionEl : function(){
23071 initEvents : function(){
23072 this.originalValue = this.getValue();
23076 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23079 // markInvalid : Roo.emptyFn,
23081 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23084 // clearInvalid : Roo.emptyFn,
23086 setValue : function(v){
23087 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
23088 this.editorcore.pushValue();
23093 deferFocus : function(){
23094 this.focus.defer(10, this);
23098 focus : function(){
23099 this.editorcore.focus();
23105 onDestroy : function(){
23111 for (var i =0; i < this.toolbars.length;i++) {
23112 // fixme - ask toolbars for heights?
23113 this.toolbars[i].onDestroy();
23116 this.wrap.dom.innerHTML = '';
23117 this.wrap.remove();
23122 onFirstFocus : function(){
23123 //Roo.log("onFirstFocus");
23124 this.editorcore.onFirstFocus();
23125 for (var i =0; i < this.toolbars.length;i++) {
23126 this.toolbars[i].onFirstFocus();
23132 syncValue : function()
23134 this.editorcore.syncValue();
23137 pushValue : function()
23139 this.editorcore.pushValue();
23143 // hide stuff that is not compatible
23157 * @event specialkey
23161 * @cfg {String} fieldClass @hide
23164 * @cfg {String} focusClass @hide
23167 * @cfg {String} autoCreate @hide
23170 * @cfg {String} inputType @hide
23173 * @cfg {String} invalidClass @hide
23176 * @cfg {String} invalidText @hide
23179 * @cfg {String} msgFx @hide
23182 * @cfg {String} validateOnBlur @hide
23191 Roo.namespace('Roo.bootstrap.htmleditor');
23193 * @class Roo.bootstrap.HtmlEditorToolbar1
23198 new Roo.bootstrap.HtmlEditor({
23201 new Roo.bootstrap.HtmlEditorToolbar1({
23202 disable : { fonts: 1 , format: 1, ..., ... , ...],
23208 * @cfg {Object} disable List of elements to disable..
23209 * @cfg {Array} btns List of additional buttons.
23213 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
23216 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
23219 Roo.apply(this, config);
23221 // default disabled, based on 'good practice'..
23222 this.disable = this.disable || {};
23223 Roo.applyIf(this.disable, {
23226 specialElements : true
23228 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
23230 this.editor = config.editor;
23231 this.editorcore = config.editor.editorcore;
23233 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
23235 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
23236 // dont call parent... till later.
23238 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.NavSimplebar, {
23243 editorcore : false,
23248 "h1","h2","h3","h4","h5","h6",
23250 "abbr", "acronym", "address", "cite", "samp", "var",
23254 onRender : function(ct, position)
23256 // Roo.log("Call onRender: " + this.xtype);
23258 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
23260 this.el.dom.style.marginBottom = '0';
23262 var editorcore = this.editorcore;
23263 var editor= this.editor;
23266 var btn = function(id,cmd , toggle, handler, html){
23268 var event = toggle ? 'toggle' : 'click';
23273 xns: Roo.bootstrap,
23276 enableToggle:toggle !== false,
23278 pressed : toggle ? false : null,
23281 a.listeners[toggle ? 'toggle' : 'click'] = function() {
23282 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
23288 // var cb_box = function...
23293 xns: Roo.bootstrap,
23294 glyphicon : 'font',
23298 xns: Roo.bootstrap,
23302 Roo.each(this.formats, function(f) {
23303 style.menu.items.push({
23305 xns: Roo.bootstrap,
23306 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
23311 editorcore.insertTag(this.tagname);
23318 children.push(style);
23320 btn('bold',false,true);
23321 btn('italic',false,true);
23322 btn('align-left', 'justifyleft',true);
23323 btn('align-center', 'justifycenter',true);
23324 btn('align-right' , 'justifyright',true);
23325 btn('link', false, false, function(btn) {
23326 //Roo.log("create link?");
23327 var url = prompt(this.createLinkText, this.defaultLinkValue);
23328 if(url && url != 'http:/'+'/'){
23329 this.editorcore.relayCmd('createlink', url);
23332 btn('list','insertunorderedlist',true);
23333 btn('pencil', false,true, function(btn){
23335 this.toggleSourceEdit(btn.pressed);
23338 if (this.editor.btns.length > 0) {
23339 for (var i = 0; i<this.editor.btns.length; i++) {
23340 children.push(this.editor.btns[i]);
23348 xns: Roo.bootstrap,
23353 xns: Roo.bootstrap,
23358 cog.menu.items.push({
23360 xns: Roo.bootstrap,
23361 html : Clean styles,
23366 editorcore.insertTag(this.tagname);
23375 this.xtype = 'NavSimplebar';
23377 for(var i=0;i< children.length;i++) {
23379 this.buttons.add(this.addxtypeChild(children[i]));
23383 editor.on('editorevent', this.updateToolbar, this);
23385 onBtnClick : function(id)
23387 this.editorcore.relayCmd(id);
23388 this.editorcore.focus();
23392 * Protected method that will not generally be called directly. It triggers
23393 * a toolbar update by reading the markup state of the current selection in the editor.
23395 updateToolbar: function(){
23397 if(!this.editorcore.activated){
23398 this.editor.onFirstFocus(); // is this neeed?
23402 var btns = this.buttons;
23403 var doc = this.editorcore.doc;
23404 btns.get('bold').setActive(doc.queryCommandState('bold'));
23405 btns.get('italic').setActive(doc.queryCommandState('italic'));
23406 //btns.get('underline').setActive(doc.queryCommandState('underline'));
23408 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
23409 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
23410 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
23412 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
23413 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
23416 var ans = this.editorcore.getAllAncestors();
23417 if (this.formatCombo) {
23420 var store = this.formatCombo.store;
23421 this.formatCombo.setValue("");
23422 for (var i =0; i < ans.length;i++) {
23423 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
23425 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
23433 // hides menus... - so this cant be on a menu...
23434 Roo.bootstrap.MenuMgr.hideAll();
23436 Roo.bootstrap.MenuMgr.hideAll();
23437 //this.editorsyncValue();
23439 onFirstFocus: function() {
23440 this.buttons.each(function(item){
23444 toggleSourceEdit : function(sourceEditMode){
23447 if(sourceEditMode){
23448 Roo.log("disabling buttons");
23449 this.buttons.each( function(item){
23450 if(item.cmd != 'pencil'){
23456 Roo.log("enabling buttons");
23457 if(this.editorcore.initialized){
23458 this.buttons.each( function(item){
23464 Roo.log("calling toggole on editor");
23465 // tell the editor that it's been pressed..
23466 this.editor.toggleSourceEdit(sourceEditMode);
23476 * @class Roo.bootstrap.Table.AbstractSelectionModel
23477 * @extends Roo.util.Observable
23478 * Abstract base class for grid SelectionModels. It provides the interface that should be
23479 * implemented by descendant classes. This class should not be directly instantiated.
23482 Roo.bootstrap.Table.AbstractSelectionModel = function(){
23483 this.locked = false;
23484 Roo.bootstrap.Table.AbstractSelectionModel.superclass.constructor.call(this);
23488 Roo.extend(Roo.bootstrap.Table.AbstractSelectionModel, Roo.util.Observable, {
23489 /** @ignore Called by the grid automatically. Do not call directly. */
23490 init : function(grid){
23496 * Locks the selections.
23499 this.locked = true;
23503 * Unlocks the selections.
23505 unlock : function(){
23506 this.locked = false;
23510 * Returns true if the selections are locked.
23511 * @return {Boolean}
23513 isLocked : function(){
23514 return this.locked;
23518 * @extends Roo.bootstrap.Table.AbstractSelectionModel
23519 * @class Roo.bootstrap.Table.RowSelectionModel
23520 * The default SelectionModel used by {@link Roo.bootstrap.Table}.
23521 * It supports multiple selections and keyboard selection/navigation.
23523 * @param {Object} config
23526 Roo.bootstrap.Table.RowSelectionModel = function(config){
23527 Roo.apply(this, config);
23528 this.selections = new Roo.util.MixedCollection(false, function(o){
23533 this.lastActive = false;
23537 * @event selectionchange
23538 * Fires when the selection changes
23539 * @param {SelectionModel} this
23541 "selectionchange" : true,
23543 * @event afterselectionchange
23544 * Fires after the selection changes (eg. by key press or clicking)
23545 * @param {SelectionModel} this
23547 "afterselectionchange" : true,
23549 * @event beforerowselect
23550 * Fires when a row is selected being selected, return false to cancel.
23551 * @param {SelectionModel} this
23552 * @param {Number} rowIndex The selected index
23553 * @param {Boolean} keepExisting False if other selections will be cleared
23555 "beforerowselect" : true,
23558 * Fires when a row is selected.
23559 * @param {SelectionModel} this
23560 * @param {Number} rowIndex The selected index
23561 * @param {Roo.data.Record} r The record
23563 "rowselect" : true,
23565 * @event rowdeselect
23566 * Fires when a row is deselected.
23567 * @param {SelectionModel} this
23568 * @param {Number} rowIndex The selected index
23570 "rowdeselect" : true
23572 Roo.bootstrap.Table.RowSelectionModel.superclass.constructor.call(this);
23573 this.locked = false;
23576 Roo.extend(Roo.bootstrap.Table.RowSelectionModel, Roo.bootstrap.Table.AbstractSelectionModel, {
23578 * @cfg {Boolean} singleSelect
23579 * True to allow selection of only one row at a time (defaults to false)
23581 singleSelect : false,
23584 initEvents : function()
23587 //if(!this.grid.enableDragDrop && !this.grid.enableDrag){
23588 // this.growclickrid.on("mousedown", this.handleMouseDown, this);
23589 //}else{ // allow click to work like normal
23590 // this.grid.on("rowclick", this.handleDragableRowClick, this);
23592 //this.grid.on("rowdblclick", this.handleMouseDBClick, this);
23593 this.grid.on("rowclick", this.handleMouseDown, this);
23595 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
23596 "up" : function(e){
23598 this.selectPrevious(e.shiftKey);
23599 }else if(this.last !== false && this.lastActive !== false){
23600 var last = this.last;
23601 this.selectRange(this.last, this.lastActive-1);
23602 this.grid.getView().focusRow(this.lastActive);
23603 if(last !== false){
23607 this.selectFirstRow();
23609 this.fireEvent("afterselectionchange", this);
23611 "down" : function(e){
23613 this.selectNext(e.shiftKey);
23614 }else if(this.last !== false && this.lastActive !== false){
23615 var last = this.last;
23616 this.selectRange(this.last, this.lastActive+1);
23617 this.grid.getView().focusRow(this.lastActive);
23618 if(last !== false){
23622 this.selectFirstRow();
23624 this.fireEvent("afterselectionchange", this);
23628 this.grid.store.on('load', function(){
23629 this.selections.clear();
23632 var view = this.grid.view;
23633 view.on("refresh", this.onRefresh, this);
23634 view.on("rowupdated", this.onRowUpdated, this);
23635 view.on("rowremoved", this.onRemove, this);
23640 onRefresh : function()
23642 var ds = this.grid.store, i, v = this.grid.view;
23643 var s = this.selections;
23644 s.each(function(r){
23645 if((i = ds.indexOfId(r.id)) != -1){
23654 onRemove : function(v, index, r){
23655 this.selections.remove(r);
23659 onRowUpdated : function(v, index, r){
23660 if(this.isSelected(r)){
23661 v.onRowSelect(index);
23667 * @param {Array} records The records to select
23668 * @param {Boolean} keepExisting (optional) True to keep existing selections
23670 selectRecords : function(records, keepExisting)
23673 this.clearSelections();
23675 var ds = this.grid.store;
23676 for(var i = 0, len = records.length; i < len; i++){
23677 this.selectRow(ds.indexOf(records[i]), true);
23682 * Gets the number of selected rows.
23685 getCount : function(){
23686 return this.selections.length;
23690 * Selects the first row in the grid.
23692 selectFirstRow : function(){
23697 * Select the last row.
23698 * @param {Boolean} keepExisting (optional) True to keep existing selections
23700 selectLastRow : function(keepExisting){
23701 //this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
23702 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
23706 * Selects the row immediately following the last selected row.
23707 * @param {Boolean} keepExisting (optional) True to keep existing selections
23709 selectNext : function(keepExisting)
23711 if(this.last !== false && (this.last+1) < this.grid.store.getCount()){
23712 this.selectRow(this.last+1, keepExisting);
23713 this.grid.getView().focusRow(this.last);
23718 * Selects the row that precedes the last selected row.
23719 * @param {Boolean} keepExisting (optional) True to keep existing selections
23721 selectPrevious : function(keepExisting){
23723 this.selectRow(this.last-1, keepExisting);
23724 this.grid.getView().focusRow(this.last);
23729 * Returns the selected records
23730 * @return {Array} Array of selected records
23732 getSelections : function(){
23733 return [].concat(this.selections.items);
23737 * Returns the first selected record.
23740 getSelected : function(){
23741 return this.selections.itemAt(0);
23746 * Clears all selections.
23748 clearSelections : function(fast)
23754 var ds = this.grid.store;
23755 var s = this.selections;
23756 s.each(function(r){
23757 this.deselectRow(ds.indexOfId(r.id));
23761 this.selections.clear();
23768 * Selects all rows.
23770 selectAll : function(){
23774 this.selections.clear();
23775 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
23776 this.selectRow(i, true);
23781 * Returns True if there is a selection.
23782 * @return {Boolean}
23784 hasSelection : function(){
23785 return this.selections.length > 0;
23789 * Returns True if the specified row is selected.
23790 * @param {Number/Record} record The record or index of the record to check
23791 * @return {Boolean}
23793 isSelected : function(index){
23794 var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
23795 return (r && this.selections.key(r.id) ? true : false);
23799 * Returns True if the specified record id is selected.
23800 * @param {String} id The id of record to check
23801 * @return {Boolean}
23803 isIdSelected : function(id){
23804 return (this.selections.key(id) ? true : false);
23809 handleMouseDBClick : function(e, t){
23813 handleMouseDown : function(e, t)
23815 var rowIndex = this.grid.headerShow ? t.dom.rowIndex - 1 : t.dom.rowIndex ; // first row is header???
23816 if(this.isLocked() || rowIndex < 0 ){
23819 if(e.shiftKey && this.last !== false){
23820 var last = this.last;
23821 this.selectRange(last, rowIndex, e.ctrlKey);
23822 this.last = last; // reset the last
23826 var isSelected = this.isSelected(rowIndex);
23827 //Roo.log("select row:" + rowIndex);
23829 this.deselectRow(rowIndex);
23831 this.selectRow(rowIndex, true);
23835 if(e.button !== 0 && isSelected){
23836 alert('rowIndex 2: ' + rowIndex);
23837 view.focusRow(rowIndex);
23838 }else if(e.ctrlKey && isSelected){
23839 this.deselectRow(rowIndex);
23840 }else if(!isSelected){
23841 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
23842 view.focusRow(rowIndex);
23846 this.fireEvent("afterselectionchange", this);
23849 handleDragableRowClick : function(grid, rowIndex, e)
23851 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
23852 this.selectRow(rowIndex, false);
23853 grid.view.focusRow(rowIndex);
23854 this.fireEvent("afterselectionchange", this);
23859 * Selects multiple rows.
23860 * @param {Array} rows Array of the indexes of the row to select
23861 * @param {Boolean} keepExisting (optional) True to keep existing selections
23863 selectRows : function(rows, keepExisting){
23865 this.clearSelections();
23867 for(var i = 0, len = rows.length; i < len; i++){
23868 this.selectRow(rows[i], true);
23873 * Selects a range of rows. All rows in between startRow and endRow are also selected.
23874 * @param {Number} startRow The index of the first row in the range
23875 * @param {Number} endRow The index of the last row in the range
23876 * @param {Boolean} keepExisting (optional) True to retain existing selections
23878 selectRange : function(startRow, endRow, keepExisting){
23883 this.clearSelections();
23885 if(startRow <= endRow){
23886 for(var i = startRow; i <= endRow; i++){
23887 this.selectRow(i, true);
23890 for(var i = startRow; i >= endRow; i--){
23891 this.selectRow(i, true);
23897 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
23898 * @param {Number} startRow The index of the first row in the range
23899 * @param {Number} endRow The index of the last row in the range
23901 deselectRange : function(startRow, endRow, preventViewNotify){
23905 for(var i = startRow; i <= endRow; i++){
23906 this.deselectRow(i, preventViewNotify);
23912 * @param {Number} row The index of the row to select
23913 * @param {Boolean} keepExisting (optional) True to keep existing selections
23915 selectRow : function(index, keepExisting, preventViewNotify)
23917 if(this.locked || (index < 0 || index > this.grid.store.getCount())) {
23920 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
23921 if(!keepExisting || this.singleSelect){
23922 this.clearSelections();
23925 var r = this.grid.store.getAt(index);
23926 //console.log('selectRow - record id :' + r.id);
23928 this.selections.add(r);
23929 this.last = this.lastActive = index;
23930 if(!preventViewNotify){
23931 var proxy = new Roo.Element(
23932 this.grid.getRowDom(index)
23934 proxy.addClass('bg-info info');
23936 this.fireEvent("rowselect", this, index, r);
23937 this.fireEvent("selectionchange", this);
23943 * @param {Number} row The index of the row to deselect
23945 deselectRow : function(index, preventViewNotify)
23950 if(this.last == index){
23953 if(this.lastActive == index){
23954 this.lastActive = false;
23957 var r = this.grid.store.getAt(index);
23962 this.selections.remove(r);
23963 //.console.log('deselectRow - record id :' + r.id);
23964 if(!preventViewNotify){
23966 var proxy = new Roo.Element(
23967 this.grid.getRowDom(index)
23969 proxy.removeClass('bg-info info');
23971 this.fireEvent("rowdeselect", this, index);
23972 this.fireEvent("selectionchange", this);
23976 restoreLast : function(){
23978 this.last = this._last;
23983 acceptsNav : function(row, col, cm){
23984 return !cm.isHidden(col) && cm.isCellEditable(col, row);
23988 onEditorKey : function(field, e){
23989 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
23994 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
23996 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
23998 }else if(k == e.ENTER && !e.ctrlKey){
24002 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
24004 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
24006 }else if(k == e.ESC){
24010 g.startEditing(newCell[0], newCell[1]);
24016 * Ext JS Library 1.1.1
24017 * Copyright(c) 2006-2007, Ext JS, LLC.
24019 * Originally Released Under LGPL - original licence link has changed is not relivant.
24022 * <script type="text/javascript">
24026 * @class Roo.bootstrap.PagingToolbar
24027 * @extends Roo.bootstrap.NavSimplebar
24028 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
24030 * Create a new PagingToolbar
24031 * @param {Object} config The config object
24032 * @param {Roo.data.Store} store
24034 Roo.bootstrap.PagingToolbar = function(config)
24036 // old args format still supported... - xtype is prefered..
24037 // created from xtype...
24039 this.ds = config.dataSource;
24041 if (config.store && !this.ds) {
24042 this.store= Roo.factory(config.store, Roo.data);
24043 this.ds = this.store;
24044 this.ds.xmodule = this.xmodule || false;
24047 this.toolbarItems = [];
24048 if (config.items) {
24049 this.toolbarItems = config.items;
24052 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
24057 this.bind(this.ds);
24060 this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
24064 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
24066 * @cfg {Roo.data.Store} dataSource
24067 * The underlying data store providing the paged data
24070 * @cfg {String/HTMLElement/Element} container
24071 * container The id or element that will contain the toolbar
24074 * @cfg {Boolean} displayInfo
24075 * True to display the displayMsg (defaults to false)
24078 * @cfg {Number} pageSize
24079 * The number of records to display per page (defaults to 20)
24083 * @cfg {String} displayMsg
24084 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
24086 displayMsg : 'Displaying {0} - {1} of {2}',
24088 * @cfg {String} emptyMsg
24089 * The message to display when no records are found (defaults to "No data to display")
24091 emptyMsg : 'No data to display',
24093 * Customizable piece of the default paging text (defaults to "Page")
24096 beforePageText : "Page",
24098 * Customizable piece of the default paging text (defaults to "of %0")
24101 afterPageText : "of {0}",
24103 * Customizable piece of the default paging text (defaults to "First Page")
24106 firstText : "First Page",
24108 * Customizable piece of the default paging text (defaults to "Previous Page")
24111 prevText : "Previous Page",
24113 * Customizable piece of the default paging text (defaults to "Next Page")
24116 nextText : "Next Page",
24118 * Customizable piece of the default paging text (defaults to "Last Page")
24121 lastText : "Last Page",
24123 * Customizable piece of the default paging text (defaults to "Refresh")
24126 refreshText : "Refresh",
24130 onRender : function(ct, position)
24132 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
24133 this.navgroup.parentId = this.id;
24134 this.navgroup.onRender(this.el, null);
24135 // add the buttons to the navgroup
24137 if(this.displayInfo){
24138 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
24139 this.displayEl = this.el.select('.x-paging-info', true).first();
24140 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
24141 // this.displayEl = navel.el.select('span',true).first();
24147 Roo.each(_this.buttons, function(e){ // this might need to use render????
24148 Roo.factory(e).onRender(_this.el, null);
24152 Roo.each(_this.toolbarItems, function(e) {
24153 _this.navgroup.addItem(e);
24157 this.first = this.navgroup.addItem({
24158 tooltip: this.firstText,
24160 icon : 'fa fa-backward',
24162 preventDefault: true,
24163 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
24166 this.prev = this.navgroup.addItem({
24167 tooltip: this.prevText,
24169 icon : 'fa fa-step-backward',
24171 preventDefault: true,
24172 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
24174 //this.addSeparator();
24177 var field = this.navgroup.addItem( {
24179 cls : 'x-paging-position',
24181 html : this.beforePageText +
24182 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
24183 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
24186 this.field = field.el.select('input', true).first();
24187 this.field.on("keydown", this.onPagingKeydown, this);
24188 this.field.on("focus", function(){this.dom.select();});
24191 this.afterTextEl = field.el.select('.x-paging-after',true).first();
24192 //this.field.setHeight(18);
24193 //this.addSeparator();
24194 this.next = this.navgroup.addItem({
24195 tooltip: this.nextText,
24197 html : ' <i class="fa fa-step-forward">',
24199 preventDefault: true,
24200 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
24202 this.last = this.navgroup.addItem({
24203 tooltip: this.lastText,
24204 icon : 'fa fa-forward',
24207 preventDefault: true,
24208 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
24210 //this.addSeparator();
24211 this.loading = this.navgroup.addItem({
24212 tooltip: this.refreshText,
24213 icon: 'fa fa-refresh',
24214 preventDefault: true,
24215 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
24221 updateInfo : function(){
24222 if(this.displayEl){
24223 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
24224 var msg = count == 0 ?
24228 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
24230 this.displayEl.update(msg);
24235 onLoad : function(ds, r, o)
24237 this.cursor = o.params ? o.params.start : 0;
24238 var d = this.getPageData(),
24243 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
24244 this.field.dom.value = ap;
24245 this.first.setDisabled(ap == 1);
24246 this.prev.setDisabled(ap == 1);
24247 this.next.setDisabled(ap == ps);
24248 this.last.setDisabled(ap == ps);
24249 this.loading.enable();
24254 getPageData : function(){
24255 var total = this.ds.getTotalCount();
24258 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
24259 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
24264 onLoadError : function(){
24265 this.loading.enable();
24269 onPagingKeydown : function(e){
24270 var k = e.getKey();
24271 var d = this.getPageData();
24273 var v = this.field.dom.value, pageNum;
24274 if(!v || isNaN(pageNum = parseInt(v, 10))){
24275 this.field.dom.value = d.activePage;
24278 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
24279 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24282 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))
24284 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
24285 this.field.dom.value = pageNum;
24286 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
24289 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
24291 var v = this.field.dom.value, pageNum;
24292 var increment = (e.shiftKey) ? 10 : 1;
24293 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
24296 if(!v || isNaN(pageNum = parseInt(v, 10))) {
24297 this.field.dom.value = d.activePage;
24300 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
24302 this.field.dom.value = parseInt(v, 10) + increment;
24303 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
24304 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24311 beforeLoad : function(){
24313 this.loading.disable();
24318 onClick : function(which){
24327 ds.load({params:{start: 0, limit: this.pageSize}});
24330 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
24333 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
24336 var total = ds.getTotalCount();
24337 var extra = total % this.pageSize;
24338 var lastStart = extra ? (total - extra) : total-this.pageSize;
24339 ds.load({params:{start: lastStart, limit: this.pageSize}});
24342 ds.load({params:{start: this.cursor, limit: this.pageSize}});
24348 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
24349 * @param {Roo.data.Store} store The data store to unbind
24351 unbind : function(ds){
24352 ds.un("beforeload", this.beforeLoad, this);
24353 ds.un("load", this.onLoad, this);
24354 ds.un("loadexception", this.onLoadError, this);
24355 ds.un("remove", this.updateInfo, this);
24356 ds.un("add", this.updateInfo, this);
24357 this.ds = undefined;
24361 * Binds the paging toolbar to the specified {@link Roo.data.Store}
24362 * @param {Roo.data.Store} store The data store to bind
24364 bind : function(ds){
24365 ds.on("beforeload", this.beforeLoad, this);
24366 ds.on("load", this.onLoad, this);
24367 ds.on("loadexception", this.onLoadError, this);
24368 ds.on("remove", this.updateInfo, this);
24369 ds.on("add", this.updateInfo, this);
24380 * @class Roo.bootstrap.MessageBar
24381 * @extends Roo.bootstrap.Component
24382 * Bootstrap MessageBar class
24383 * @cfg {String} html contents of the MessageBar
24384 * @cfg {String} weight (info | success | warning | danger) default info
24385 * @cfg {String} beforeClass insert the bar before the given class
24386 * @cfg {Boolean} closable (true | false) default false
24387 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
24390 * Create a new Element
24391 * @param {Object} config The config object
24394 Roo.bootstrap.MessageBar = function(config){
24395 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
24398 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
24404 beforeClass: 'bootstrap-sticky-wrap',
24406 getAutoCreate : function(){
24410 cls: 'alert alert-dismissable alert-' + this.weight,
24415 html: this.html || ''
24421 cfg.cls += ' alert-messages-fixed';
24435 onRender : function(ct, position)
24437 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
24440 var cfg = Roo.apply({}, this.getAutoCreate());
24444 cfg.cls += ' ' + this.cls;
24447 cfg.style = this.style;
24449 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
24451 this.el.setVisibilityMode(Roo.Element.DISPLAY);
24454 this.el.select('>button.close').on('click', this.hide, this);
24460 if (!this.rendered) {
24466 this.fireEvent('show', this);
24472 if (!this.rendered) {
24478 this.fireEvent('hide', this);
24481 update : function()
24483 // var e = this.el.dom.firstChild;
24485 // if(this.closable){
24486 // e = e.nextSibling;
24489 // e.data = this.html || '';
24491 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
24507 * @class Roo.bootstrap.Graph
24508 * @extends Roo.bootstrap.Component
24509 * Bootstrap Graph class
24513 @cfg {String} graphtype bar | vbar | pie
24514 @cfg {number} g_x coodinator | centre x (pie)
24515 @cfg {number} g_y coodinator | centre y (pie)
24516 @cfg {number} g_r radius (pie)
24517 @cfg {number} g_height height of the chart (respected by all elements in the set)
24518 @cfg {number} g_width width of the chart (respected by all elements in the set)
24519 @cfg {Object} title The title of the chart
24522 -opts (object) options for the chart
24524 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
24525 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
24527 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.
24528 o stacked (boolean) whether or not to tread values as in a stacked bar chart
24530 o stretch (boolean)
24532 -opts (object) options for the pie
24535 o startAngle (number)
24536 o endAngle (number)
24540 * Create a new Input
24541 * @param {Object} config The config object
24544 Roo.bootstrap.Graph = function(config){
24545 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
24551 * The img click event for the img.
24552 * @param {Roo.EventObject} e
24558 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
24569 //g_colors: this.colors,
24576 getAutoCreate : function(){
24587 onRender : function(ct,position){
24590 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
24592 if (typeof(Raphael) == 'undefined') {
24593 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
24597 this.raphael = Raphael(this.el.dom);
24599 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
24600 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
24601 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
24602 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
24604 r.text(160, 10, "Single Series Chart").attr(txtattr);
24605 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
24606 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
24607 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
24609 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
24610 r.barchart(330, 10, 300, 220, data1);
24611 r.barchart(10, 250, 300, 220, data2, {stacked: true});
24612 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
24615 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
24616 // r.barchart(30, 30, 560, 250, xdata, {
24617 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
24618 // axis : "0 0 1 1",
24619 // axisxlabels : xdata
24620 // //yvalues : cols,
24623 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
24625 // this.load(null,xdata,{
24626 // axis : "0 0 1 1",
24627 // axisxlabels : xdata
24632 load : function(graphtype,xdata,opts)
24634 this.raphael.clear();
24636 graphtype = this.graphtype;
24641 var r = this.raphael,
24642 fin = function () {
24643 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
24645 fout = function () {
24646 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
24648 pfin = function() {
24649 this.sector.stop();
24650 this.sector.scale(1.1, 1.1, this.cx, this.cy);
24653 this.label[0].stop();
24654 this.label[0].attr({ r: 7.5 });
24655 this.label[1].attr({ "font-weight": 800 });
24658 pfout = function() {
24659 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
24662 this.label[0].animate({ r: 5 }, 500, "bounce");
24663 this.label[1].attr({ "font-weight": 400 });
24669 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
24672 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
24675 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
24676 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
24678 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
24685 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
24690 setTitle: function(o)
24695 initEvents: function() {
24698 this.el.on('click', this.onClick, this);
24702 onClick : function(e)
24704 Roo.log('img onclick');
24705 this.fireEvent('click', this, e);
24717 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
24720 * @class Roo.bootstrap.dash.NumberBox
24721 * @extends Roo.bootstrap.Component
24722 * Bootstrap NumberBox class
24723 * @cfg {String} headline Box headline
24724 * @cfg {String} content Box content
24725 * @cfg {String} icon Box icon
24726 * @cfg {String} footer Footer text
24727 * @cfg {String} fhref Footer href
24730 * Create a new NumberBox
24731 * @param {Object} config The config object
24735 Roo.bootstrap.dash.NumberBox = function(config){
24736 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
24740 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
24749 getAutoCreate : function(){
24753 cls : 'small-box ',
24761 cls : 'roo-headline',
24762 html : this.headline
24766 cls : 'roo-content',
24767 html : this.content
24781 cls : 'ion ' + this.icon
24790 cls : 'small-box-footer',
24791 href : this.fhref || '#',
24795 cfg.cn.push(footer);
24802 onRender : function(ct,position){
24803 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
24810 setHeadline: function (value)
24812 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
24815 setFooter: function (value, href)
24817 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
24820 this.el.select('a.small-box-footer',true).first().attr('href', href);
24825 setContent: function (value)
24827 this.el.select('.roo-content',true).first().dom.innerHTML = value;
24830 initEvents: function()
24844 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
24847 * @class Roo.bootstrap.dash.TabBox
24848 * @extends Roo.bootstrap.Component
24849 * Bootstrap TabBox class
24850 * @cfg {String} title Title of the TabBox
24851 * @cfg {String} icon Icon of the TabBox
24852 * @cfg {Boolean} showtabs (true|false) show the tabs default true
24853 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
24856 * Create a new TabBox
24857 * @param {Object} config The config object
24861 Roo.bootstrap.dash.TabBox = function(config){
24862 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
24867 * When a pane is added
24868 * @param {Roo.bootstrap.dash.TabPane} pane
24872 * @event activatepane
24873 * When a pane is activated
24874 * @param {Roo.bootstrap.dash.TabPane} pane
24876 "activatepane" : true
24884 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
24889 tabScrollable : false,
24891 getChildContainer : function()
24893 return this.el.select('.tab-content', true).first();
24896 getAutoCreate : function(){
24900 cls: 'pull-left header',
24908 cls: 'fa ' + this.icon
24914 cls: 'nav nav-tabs pull-right',
24920 if(this.tabScrollable){
24927 cls: 'nav nav-tabs pull-right',
24938 cls: 'nav-tabs-custom',
24943 cls: 'tab-content no-padding',
24951 initEvents : function()
24953 //Roo.log('add add pane handler');
24954 this.on('addpane', this.onAddPane, this);
24957 * Updates the box title
24958 * @param {String} html to set the title to.
24960 setTitle : function(value)
24962 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
24964 onAddPane : function(pane)
24966 this.panes.push(pane);
24967 //Roo.log('addpane');
24969 // tabs are rendere left to right..
24970 if(!this.showtabs){
24974 var ctr = this.el.select('.nav-tabs', true).first();
24977 var existing = ctr.select('.nav-tab',true);
24978 var qty = existing.getCount();;
24981 var tab = ctr.createChild({
24983 cls : 'nav-tab' + (qty ? '' : ' active'),
24991 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
24994 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
24996 pane.el.addClass('active');
25001 onTabClick : function(ev,un,ob,pane)
25003 //Roo.log('tab - prev default');
25004 ev.preventDefault();
25007 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
25008 pane.tab.addClass('active');
25009 //Roo.log(pane.title);
25010 this.getChildContainer().select('.tab-pane',true).removeClass('active');
25011 // technically we should have a deactivate event.. but maybe add later.
25012 // and it should not de-activate the selected tab...
25013 this.fireEvent('activatepane', pane);
25014 pane.el.addClass('active');
25015 pane.fireEvent('activate');
25020 getActivePane : function()
25023 Roo.each(this.panes, function(p) {
25024 if(p.el.hasClass('active')){
25045 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25047 * @class Roo.bootstrap.TabPane
25048 * @extends Roo.bootstrap.Component
25049 * Bootstrap TabPane class
25050 * @cfg {Boolean} active (false | true) Default false
25051 * @cfg {String} title title of panel
25055 * Create a new TabPane
25056 * @param {Object} config The config object
25059 Roo.bootstrap.dash.TabPane = function(config){
25060 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
25066 * When a pane is activated
25067 * @param {Roo.bootstrap.dash.TabPane} pane
25074 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
25079 // the tabBox that this is attached to.
25082 getAutoCreate : function()
25090 cfg.cls += ' active';
25095 initEvents : function()
25097 //Roo.log('trigger add pane handler');
25098 this.parent().fireEvent('addpane', this)
25102 * Updates the tab title
25103 * @param {String} html to set the title to.
25105 setTitle: function(str)
25111 this.tab.select('a', true).first().dom.innerHTML = str;
25128 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25131 * @class Roo.bootstrap.menu.Menu
25132 * @extends Roo.bootstrap.Component
25133 * Bootstrap Menu class - container for Menu
25134 * @cfg {String} html Text of the menu
25135 * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
25136 * @cfg {String} icon Font awesome icon
25137 * @cfg {String} pos Menu align to (top | bottom) default bottom
25141 * Create a new Menu
25142 * @param {Object} config The config object
25146 Roo.bootstrap.menu.Menu = function(config){
25147 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
25151 * @event beforeshow
25152 * Fires before this menu is displayed
25153 * @param {Roo.bootstrap.menu.Menu} this
25157 * @event beforehide
25158 * Fires before this menu is hidden
25159 * @param {Roo.bootstrap.menu.Menu} this
25164 * Fires after this menu is displayed
25165 * @param {Roo.bootstrap.menu.Menu} this
25170 * Fires after this menu is hidden
25171 * @param {Roo.bootstrap.menu.Menu} this
25176 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
25177 * @param {Roo.bootstrap.menu.Menu} this
25178 * @param {Roo.EventObject} e
25185 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
25189 weight : 'default',
25194 getChildContainer : function() {
25195 if(this.isSubMenu){
25199 return this.el.select('ul.dropdown-menu', true).first();
25202 getAutoCreate : function()
25207 cls : 'roo-menu-text',
25215 cls : 'fa ' + this.icon
25226 cls : 'dropdown-button btn btn-' + this.weight,
25231 cls : 'dropdown-toggle btn btn-' + this.weight,
25241 cls : 'dropdown-menu'
25247 if(this.pos == 'top'){
25248 cfg.cls += ' dropup';
25251 if(this.isSubMenu){
25254 cls : 'dropdown-menu'
25261 onRender : function(ct, position)
25263 this.isSubMenu = ct.hasClass('dropdown-submenu');
25265 Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
25268 initEvents : function()
25270 if(this.isSubMenu){
25274 this.hidden = true;
25276 this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
25277 this.triggerEl.on('click', this.onTriggerPress, this);
25279 this.buttonEl = this.el.select('button.dropdown-button', true).first();
25280 this.buttonEl.on('click', this.onClick, this);
25286 if(this.isSubMenu){
25290 return this.el.select('ul.dropdown-menu', true).first();
25293 onClick : function(e)
25295 this.fireEvent("click", this, e);
25298 onTriggerPress : function(e)
25300 if (this.isVisible()) {
25307 isVisible : function(){
25308 return !this.hidden;
25313 this.fireEvent("beforeshow", this);
25315 this.hidden = false;
25316 this.el.addClass('open');
25318 Roo.get(document).on("mouseup", this.onMouseUp, this);
25320 this.fireEvent("show", this);
25327 this.fireEvent("beforehide", this);
25329 this.hidden = true;
25330 this.el.removeClass('open');
25332 Roo.get(document).un("mouseup", this.onMouseUp);
25334 this.fireEvent("hide", this);
25337 onMouseUp : function()
25351 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25354 * @class Roo.bootstrap.menu.Item
25355 * @extends Roo.bootstrap.Component
25356 * Bootstrap MenuItem class
25357 * @cfg {Boolean} submenu (true | false) default false
25358 * @cfg {String} html text of the item
25359 * @cfg {String} href the link
25360 * @cfg {Boolean} disable (true | false) default false
25361 * @cfg {Boolean} preventDefault (true | false) default true
25362 * @cfg {String} icon Font awesome icon
25363 * @cfg {String} pos Submenu align to (left | right) default right
25367 * Create a new Item
25368 * @param {Object} config The config object
25372 Roo.bootstrap.menu.Item = function(config){
25373 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
25377 * Fires when the mouse is hovering over this menu
25378 * @param {Roo.bootstrap.menu.Item} this
25379 * @param {Roo.EventObject} e
25384 * Fires when the mouse exits this menu
25385 * @param {Roo.bootstrap.menu.Item} this
25386 * @param {Roo.EventObject} e
25392 * The raw click event for the entire grid.
25393 * @param {Roo.EventObject} e
25399 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
25404 preventDefault: true,
25409 getAutoCreate : function()
25414 cls : 'roo-menu-item-text',
25422 cls : 'fa ' + this.icon
25431 href : this.href || '#',
25438 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
25442 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
25444 if(this.pos == 'left'){
25445 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
25452 initEvents : function()
25454 this.el.on('mouseover', this.onMouseOver, this);
25455 this.el.on('mouseout', this.onMouseOut, this);
25457 this.el.select('a', true).first().on('click', this.onClick, this);
25461 onClick : function(e)
25463 if(this.preventDefault){
25464 e.preventDefault();
25467 this.fireEvent("click", this, e);
25470 onMouseOver : function(e)
25472 if(this.submenu && this.pos == 'left'){
25473 this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
25476 this.fireEvent("mouseover", this, e);
25479 onMouseOut : function(e)
25481 this.fireEvent("mouseout", this, e);
25493 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25496 * @class Roo.bootstrap.menu.Separator
25497 * @extends Roo.bootstrap.Component
25498 * Bootstrap Separator class
25501 * Create a new Separator
25502 * @param {Object} config The config object
25506 Roo.bootstrap.menu.Separator = function(config){
25507 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
25510 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
25512 getAutoCreate : function(){
25533 * @class Roo.bootstrap.Tooltip
25534 * Bootstrap Tooltip class
25535 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
25536 * to determine which dom element triggers the tooltip.
25538 * It needs to add support for additional attributes like tooltip-position
25541 * Create a new Toolti
25542 * @param {Object} config The config object
25545 Roo.bootstrap.Tooltip = function(config){
25546 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
25548 this.alignment = Roo.bootstrap.Tooltip.alignment;
25550 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
25551 this.alignment = config.alignment;
25556 Roo.apply(Roo.bootstrap.Tooltip, {
25558 * @function init initialize tooltip monitoring.
25562 currentTip : false,
25563 currentRegion : false,
25569 Roo.get(document).on('mouseover', this.enter ,this);
25570 Roo.get(document).on('mouseout', this.leave, this);
25573 this.currentTip = new Roo.bootstrap.Tooltip();
25576 enter : function(ev)
25578 var dom = ev.getTarget();
25580 //Roo.log(['enter',dom]);
25581 var el = Roo.fly(dom);
25582 if (this.currentEl) {
25584 //Roo.log(this.currentEl);
25585 //Roo.log(this.currentEl.contains(dom));
25586 if (this.currentEl == el) {
25589 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
25595 if (this.currentTip.el) {
25596 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
25600 if(!el || el.dom == document){
25606 // you can not look for children, as if el is the body.. then everythign is the child..
25607 if (!el.attr('tooltip')) { //
25608 if (!el.select("[tooltip]").elements.length) {
25611 // is the mouse over this child...?
25612 bindEl = el.select("[tooltip]").first();
25613 var xy = ev.getXY();
25614 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
25615 //Roo.log("not in region.");
25618 //Roo.log("child element over..");
25621 this.currentEl = bindEl;
25622 this.currentTip.bind(bindEl);
25623 this.currentRegion = Roo.lib.Region.getRegion(dom);
25624 this.currentTip.enter();
25627 leave : function(ev)
25629 var dom = ev.getTarget();
25630 //Roo.log(['leave',dom]);
25631 if (!this.currentEl) {
25636 if (dom != this.currentEl.dom) {
25639 var xy = ev.getXY();
25640 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
25643 // only activate leave if mouse cursor is outside... bounding box..
25648 if (this.currentTip) {
25649 this.currentTip.leave();
25651 //Roo.log('clear currentEl');
25652 this.currentEl = false;
25657 'left' : ['r-l', [-2,0], 'right'],
25658 'right' : ['l-r', [2,0], 'left'],
25659 'bottom' : ['t-b', [0,2], 'top'],
25660 'top' : [ 'b-t', [0,-2], 'bottom']
25666 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
25671 delay : null, // can be { show : 300 , hide: 500}
25675 hoverState : null, //???
25677 placement : 'bottom',
25681 getAutoCreate : function(){
25688 cls : 'tooltip-arrow'
25691 cls : 'tooltip-inner'
25698 bind : function(el)
25704 enter : function () {
25706 if (this.timeout != null) {
25707 clearTimeout(this.timeout);
25710 this.hoverState = 'in';
25711 //Roo.log("enter - show");
25712 if (!this.delay || !this.delay.show) {
25717 this.timeout = setTimeout(function () {
25718 if (_t.hoverState == 'in') {
25721 }, this.delay.show);
25725 clearTimeout(this.timeout);
25727 this.hoverState = 'out';
25728 if (!this.delay || !this.delay.hide) {
25734 this.timeout = setTimeout(function () {
25735 //Roo.log("leave - timeout");
25737 if (_t.hoverState == 'out') {
25739 Roo.bootstrap.Tooltip.currentEl = false;
25744 show : function (msg)
25747 this.render(document.body);
25750 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
25752 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
25754 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
25756 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
25758 var placement = typeof this.placement == 'function' ?
25759 this.placement.call(this, this.el, on_el) :
25762 var autoToken = /\s?auto?\s?/i;
25763 var autoPlace = autoToken.test(placement);
25765 placement = placement.replace(autoToken, '') || 'top';
25769 //this.el.setXY([0,0]);
25771 //this.el.dom.style.display='block';
25773 //this.el.appendTo(on_el);
25775 var p = this.getPosition();
25776 var box = this.el.getBox();
25782 var align = this.alignment[placement];
25784 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
25786 if(placement == 'top' || placement == 'bottom'){
25788 placement = 'right';
25791 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
25792 placement = 'left';
25795 var scroll = Roo.select('body', true).first().getScroll();
25797 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
25803 this.el.alignTo(this.bindEl, align[0],align[1]);
25804 //var arrow = this.el.select('.arrow',true).first();
25805 //arrow.set(align[2],
25807 this.el.addClass(placement);
25809 this.el.addClass('in fade');
25811 this.hoverState = null;
25813 if (this.el.hasClass('fade')) {
25824 //this.el.setXY([0,0]);
25825 this.el.removeClass('in');
25841 * @class Roo.bootstrap.LocationPicker
25842 * @extends Roo.bootstrap.Component
25843 * Bootstrap LocationPicker class
25844 * @cfg {Number} latitude Position when init default 0
25845 * @cfg {Number} longitude Position when init default 0
25846 * @cfg {Number} zoom default 15
25847 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
25848 * @cfg {Boolean} mapTypeControl default false
25849 * @cfg {Boolean} disableDoubleClickZoom default false
25850 * @cfg {Boolean} scrollwheel default true
25851 * @cfg {Boolean} streetViewControl default false
25852 * @cfg {Number} radius default 0
25853 * @cfg {String} locationName
25854 * @cfg {Boolean} draggable default true
25855 * @cfg {Boolean} enableAutocomplete default false
25856 * @cfg {Boolean} enableReverseGeocode default true
25857 * @cfg {String} markerTitle
25860 * Create a new LocationPicker
25861 * @param {Object} config The config object
25865 Roo.bootstrap.LocationPicker = function(config){
25867 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
25872 * Fires when the picker initialized.
25873 * @param {Roo.bootstrap.LocationPicker} this
25874 * @param {Google Location} location
25878 * @event positionchanged
25879 * Fires when the picker position changed.
25880 * @param {Roo.bootstrap.LocationPicker} this
25881 * @param {Google Location} location
25883 positionchanged : true,
25886 * Fires when the map resize.
25887 * @param {Roo.bootstrap.LocationPicker} this
25892 * Fires when the map show.
25893 * @param {Roo.bootstrap.LocationPicker} this
25898 * Fires when the map hide.
25899 * @param {Roo.bootstrap.LocationPicker} this
25904 * Fires when click the map.
25905 * @param {Roo.bootstrap.LocationPicker} this
25906 * @param {Map event} e
25910 * @event mapRightClick
25911 * Fires when right click the map.
25912 * @param {Roo.bootstrap.LocationPicker} this
25913 * @param {Map event} e
25915 mapRightClick : true,
25917 * @event markerClick
25918 * Fires when click the marker.
25919 * @param {Roo.bootstrap.LocationPicker} this
25920 * @param {Map event} e
25922 markerClick : true,
25924 * @event markerRightClick
25925 * Fires when right click the marker.
25926 * @param {Roo.bootstrap.LocationPicker} this
25927 * @param {Map event} e
25929 markerRightClick : true,
25931 * @event OverlayViewDraw
25932 * Fires when OverlayView Draw
25933 * @param {Roo.bootstrap.LocationPicker} this
25935 OverlayViewDraw : true,
25937 * @event OverlayViewOnAdd
25938 * Fires when OverlayView Draw
25939 * @param {Roo.bootstrap.LocationPicker} this
25941 OverlayViewOnAdd : true,
25943 * @event OverlayViewOnRemove
25944 * Fires when OverlayView Draw
25945 * @param {Roo.bootstrap.LocationPicker} this
25947 OverlayViewOnRemove : true,
25949 * @event OverlayViewShow
25950 * Fires when OverlayView Draw
25951 * @param {Roo.bootstrap.LocationPicker} this
25952 * @param {Pixel} cpx
25954 OverlayViewShow : true,
25956 * @event OverlayViewHide
25957 * Fires when OverlayView Draw
25958 * @param {Roo.bootstrap.LocationPicker} this
25960 OverlayViewHide : true,
25962 * @event loadexception
25963 * Fires when load google lib failed.
25964 * @param {Roo.bootstrap.LocationPicker} this
25966 loadexception : true
25971 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
25973 gMapContext: false,
25979 mapTypeControl: false,
25980 disableDoubleClickZoom: false,
25982 streetViewControl: false,
25986 enableAutocomplete: false,
25987 enableReverseGeocode: true,
25990 getAutoCreate: function()
25995 cls: 'roo-location-picker'
26001 initEvents: function(ct, position)
26003 if(!this.el.getWidth() || this.isApplied()){
26007 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26012 initial: function()
26014 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
26015 this.fireEvent('loadexception', this);
26019 if(!this.mapTypeId){
26020 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
26023 this.gMapContext = this.GMapContext();
26025 this.initOverlayView();
26027 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
26031 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
26032 _this.setPosition(_this.gMapContext.marker.position);
26035 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
26036 _this.fireEvent('mapClick', this, event);
26040 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
26041 _this.fireEvent('mapRightClick', this, event);
26045 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
26046 _this.fireEvent('markerClick', this, event);
26050 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
26051 _this.fireEvent('markerRightClick', this, event);
26055 this.setPosition(this.gMapContext.location);
26057 this.fireEvent('initial', this, this.gMapContext.location);
26060 initOverlayView: function()
26064 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
26068 _this.fireEvent('OverlayViewDraw', _this);
26073 _this.fireEvent('OverlayViewOnAdd', _this);
26076 onRemove: function()
26078 _this.fireEvent('OverlayViewOnRemove', _this);
26081 show: function(cpx)
26083 _this.fireEvent('OverlayViewShow', _this, cpx);
26088 _this.fireEvent('OverlayViewHide', _this);
26094 fromLatLngToContainerPixel: function(event)
26096 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
26099 isApplied: function()
26101 return this.getGmapContext() == false ? false : true;
26104 getGmapContext: function()
26106 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
26109 GMapContext: function()
26111 var position = new google.maps.LatLng(this.latitude, this.longitude);
26113 var _map = new google.maps.Map(this.el.dom, {
26116 mapTypeId: this.mapTypeId,
26117 mapTypeControl: this.mapTypeControl,
26118 disableDoubleClickZoom: this.disableDoubleClickZoom,
26119 scrollwheel: this.scrollwheel,
26120 streetViewControl: this.streetViewControl,
26121 locationName: this.locationName,
26122 draggable: this.draggable,
26123 enableAutocomplete: this.enableAutocomplete,
26124 enableReverseGeocode: this.enableReverseGeocode
26127 var _marker = new google.maps.Marker({
26128 position: position,
26130 title: this.markerTitle,
26131 draggable: this.draggable
26138 location: position,
26139 radius: this.radius,
26140 locationName: this.locationName,
26141 addressComponents: {
26142 formatted_address: null,
26143 addressLine1: null,
26144 addressLine2: null,
26146 streetNumber: null,
26150 stateOrProvince: null
26153 domContainer: this.el.dom,
26154 geodecoder: new google.maps.Geocoder()
26158 drawCircle: function(center, radius, options)
26160 if (this.gMapContext.circle != null) {
26161 this.gMapContext.circle.setMap(null);
26165 options = Roo.apply({}, options, {
26166 strokeColor: "#0000FF",
26167 strokeOpacity: .35,
26169 fillColor: "#0000FF",
26173 options.map = this.gMapContext.map;
26174 options.radius = radius;
26175 options.center = center;
26176 this.gMapContext.circle = new google.maps.Circle(options);
26177 return this.gMapContext.circle;
26183 setPosition: function(location)
26185 this.gMapContext.location = location;
26186 this.gMapContext.marker.setPosition(location);
26187 this.gMapContext.map.panTo(location);
26188 this.drawCircle(location, this.gMapContext.radius, {});
26192 if (this.gMapContext.settings.enableReverseGeocode) {
26193 this.gMapContext.geodecoder.geocode({
26194 latLng: this.gMapContext.location
26195 }, function(results, status) {
26197 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
26198 _this.gMapContext.locationName = results[0].formatted_address;
26199 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
26201 _this.fireEvent('positionchanged', this, location);
26208 this.fireEvent('positionchanged', this, location);
26213 google.maps.event.trigger(this.gMapContext.map, "resize");
26215 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
26217 this.fireEvent('resize', this);
26220 setPositionByLatLng: function(latitude, longitude)
26222 this.setPosition(new google.maps.LatLng(latitude, longitude));
26225 getCurrentPosition: function()
26228 latitude: this.gMapContext.location.lat(),
26229 longitude: this.gMapContext.location.lng()
26233 getAddressName: function()
26235 return this.gMapContext.locationName;
26238 getAddressComponents: function()
26240 return this.gMapContext.addressComponents;
26243 address_component_from_google_geocode: function(address_components)
26247 for (var i = 0; i < address_components.length; i++) {
26248 var component = address_components[i];
26249 if (component.types.indexOf("postal_code") >= 0) {
26250 result.postalCode = component.short_name;
26251 } else if (component.types.indexOf("street_number") >= 0) {
26252 result.streetNumber = component.short_name;
26253 } else if (component.types.indexOf("route") >= 0) {
26254 result.streetName = component.short_name;
26255 } else if (component.types.indexOf("neighborhood") >= 0) {
26256 result.city = component.short_name;
26257 } else if (component.types.indexOf("locality") >= 0) {
26258 result.city = component.short_name;
26259 } else if (component.types.indexOf("sublocality") >= 0) {
26260 result.district = component.short_name;
26261 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
26262 result.stateOrProvince = component.short_name;
26263 } else if (component.types.indexOf("country") >= 0) {
26264 result.country = component.short_name;
26268 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
26269 result.addressLine2 = "";
26273 setZoomLevel: function(zoom)
26275 this.gMapContext.map.setZoom(zoom);
26288 this.fireEvent('show', this);
26299 this.fireEvent('hide', this);
26304 Roo.apply(Roo.bootstrap.LocationPicker, {
26306 OverlayView : function(map, options)
26308 options = options || {};
26322 * @class Roo.bootstrap.Alert
26323 * @extends Roo.bootstrap.Component
26324 * Bootstrap Alert class
26325 * @cfg {String} title The title of alert
26326 * @cfg {String} html The content of alert
26327 * @cfg {String} weight ( success | info | warning | danger )
26328 * @cfg {String} faicon font-awesomeicon
26331 * Create a new alert
26332 * @param {Object} config The config object
26336 Roo.bootstrap.Alert = function(config){
26337 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
26341 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
26348 getAutoCreate : function()
26357 cls : 'roo-alert-icon'
26362 cls : 'roo-alert-title',
26367 cls : 'roo-alert-text',
26374 cfg.cn[0].cls += ' fa ' + this.faicon;
26378 cfg.cls += ' alert-' + this.weight;
26384 initEvents: function()
26386 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26389 setTitle : function(str)
26391 this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
26394 setText : function(str)
26396 this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
26399 setWeight : function(weight)
26402 this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
26405 this.weight = weight;
26407 this.el.select('.alert',true).first().addClass('alert-' + this.weight);
26410 setIcon : function(icon)
26413 this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
26416 this.faicon = icon;
26418 this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
26439 * @class Roo.bootstrap.UploadCropbox
26440 * @extends Roo.bootstrap.Component
26441 * Bootstrap UploadCropbox class
26442 * @cfg {String} emptyText show when image has been loaded
26443 * @cfg {String} rotateNotify show when image too small to rotate
26444 * @cfg {Number} errorTimeout default 3000
26445 * @cfg {Number} minWidth default 300
26446 * @cfg {Number} minHeight default 300
26447 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
26448 * @cfg {Boolean} isDocument (true|false) default false
26449 * @cfg {String} url action url
26450 * @cfg {String} paramName default 'imageUpload'
26451 * @cfg {String} method default POST
26452 * @cfg {Boolean} loadMask (true|false) default true
26453 * @cfg {Boolean} loadingText default 'Loading...'
26456 * Create a new UploadCropbox
26457 * @param {Object} config The config object
26460 Roo.bootstrap.UploadCropbox = function(config){
26461 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
26465 * @event beforeselectfile
26466 * Fire before select file
26467 * @param {Roo.bootstrap.UploadCropbox} this
26469 "beforeselectfile" : true,
26472 * Fire after initEvent
26473 * @param {Roo.bootstrap.UploadCropbox} this
26478 * Fire after initEvent
26479 * @param {Roo.bootstrap.UploadCropbox} this
26480 * @param {String} data
26485 * Fire when preparing the file data
26486 * @param {Roo.bootstrap.UploadCropbox} this
26487 * @param {Object} file
26492 * Fire when get exception
26493 * @param {Roo.bootstrap.UploadCropbox} this
26494 * @param {XMLHttpRequest} xhr
26496 "exception" : true,
26498 * @event beforeloadcanvas
26499 * Fire before load the canvas
26500 * @param {Roo.bootstrap.UploadCropbox} this
26501 * @param {String} src
26503 "beforeloadcanvas" : true,
26506 * Fire when trash image
26507 * @param {Roo.bootstrap.UploadCropbox} this
26512 * Fire when download the image
26513 * @param {Roo.bootstrap.UploadCropbox} this
26517 * @event footerbuttonclick
26518 * Fire when footerbuttonclick
26519 * @param {Roo.bootstrap.UploadCropbox} this
26520 * @param {String} type
26522 "footerbuttonclick" : true,
26526 * @param {Roo.bootstrap.UploadCropbox} this
26531 * Fire when rotate the image
26532 * @param {Roo.bootstrap.UploadCropbox} this
26533 * @param {String} pos
26538 * Fire when inspect the file
26539 * @param {Roo.bootstrap.UploadCropbox} this
26540 * @param {Object} file
26545 * Fire when xhr upload the file
26546 * @param {Roo.bootstrap.UploadCropbox} this
26547 * @param {Object} data
26552 * Fire when arrange the file data
26553 * @param {Roo.bootstrap.UploadCropbox} this
26554 * @param {Object} formData
26559 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
26562 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
26564 emptyText : 'Click to upload image',
26565 rotateNotify : 'Image is too small to rotate',
26566 errorTimeout : 3000,
26580 cropType : 'image/jpeg',
26582 canvasLoaded : false,
26583 isDocument : false,
26585 paramName : 'imageUpload',
26587 loadingText : 'Loading...',
26590 getAutoCreate : function()
26594 cls : 'roo-upload-cropbox',
26598 cls : 'roo-upload-cropbox-selector',
26603 cls : 'roo-upload-cropbox-body',
26604 style : 'cursor:pointer',
26608 cls : 'roo-upload-cropbox-preview'
26612 cls : 'roo-upload-cropbox-thumb'
26616 cls : 'roo-upload-cropbox-empty-notify',
26617 html : this.emptyText
26621 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
26622 html : this.rotateNotify
26628 cls : 'roo-upload-cropbox-footer',
26631 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
26641 onRender : function(ct, position)
26643 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
26645 if (this.buttons.length) {
26647 Roo.each(this.buttons, function(bb) {
26649 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
26651 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
26657 this.maskEl = this.el;
26661 initEvents : function()
26663 this.urlAPI = (window.createObjectURL && window) ||
26664 (window.URL && URL.revokeObjectURL && URL) ||
26665 (window.webkitURL && webkitURL);
26667 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
26668 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26670 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
26671 this.selectorEl.hide();
26673 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
26674 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26676 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
26677 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26678 this.thumbEl.hide();
26680 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
26681 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26683 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
26684 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26685 this.errorEl.hide();
26687 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
26688 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26689 this.footerEl.hide();
26691 this.setThumbBoxSize();
26697 this.fireEvent('initial', this);
26704 window.addEventListener("resize", function() { _this.resize(); } );
26706 this.bodyEl.on('click', this.beforeSelectFile, this);
26709 this.bodyEl.on('touchstart', this.onTouchStart, this);
26710 this.bodyEl.on('touchmove', this.onTouchMove, this);
26711 this.bodyEl.on('touchend', this.onTouchEnd, this);
26715 this.bodyEl.on('mousedown', this.onMouseDown, this);
26716 this.bodyEl.on('mousemove', this.onMouseMove, this);
26717 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
26718 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
26719 Roo.get(document).on('mouseup', this.onMouseUp, this);
26722 this.selectorEl.on('change', this.onFileSelected, this);
26728 this.baseScale = 1;
26730 this.baseRotate = 1;
26731 this.dragable = false;
26732 this.pinching = false;
26735 this.cropData = false;
26736 this.notifyEl.dom.innerHTML = this.emptyText;
26738 this.selectorEl.dom.value = '';
26742 resize : function()
26744 if(this.fireEvent('resize', this) != false){
26745 this.setThumbBoxPosition();
26746 this.setCanvasPosition();
26750 onFooterButtonClick : function(e, el, o, type)
26753 case 'rotate-left' :
26754 this.onRotateLeft(e);
26756 case 'rotate-right' :
26757 this.onRotateRight(e);
26760 this.beforeSelectFile(e);
26775 this.fireEvent('footerbuttonclick', this, type);
26778 beforeSelectFile : function(e)
26780 e.preventDefault();
26782 if(this.fireEvent('beforeselectfile', this) != false){
26783 this.selectorEl.dom.click();
26787 onFileSelected : function(e)
26789 e.preventDefault();
26791 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
26795 var file = this.selectorEl.dom.files[0];
26797 if(this.fireEvent('inspect', this, file) != false){
26798 this.prepare(file);
26803 trash : function(e)
26805 this.fireEvent('trash', this);
26808 download : function(e)
26810 this.fireEvent('download', this);
26813 loadCanvas : function(src)
26815 if(this.fireEvent('beforeloadcanvas', this, src) != false){
26819 this.imageEl = document.createElement('img');
26823 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
26825 this.imageEl.src = src;
26829 onLoadCanvas : function()
26831 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
26832 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
26834 this.bodyEl.un('click', this.beforeSelectFile, this);
26836 this.notifyEl.hide();
26837 this.thumbEl.show();
26838 this.footerEl.show();
26840 this.baseRotateLevel();
26842 if(this.isDocument){
26843 this.setThumbBoxSize();
26846 this.setThumbBoxPosition();
26848 this.baseScaleLevel();
26854 this.canvasLoaded = true;
26857 this.maskEl.unmask();
26862 setCanvasPosition : function()
26864 if(!this.canvasEl){
26868 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
26869 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
26871 this.previewEl.setLeft(pw);
26872 this.previewEl.setTop(ph);
26876 onMouseDown : function(e)
26880 this.dragable = true;
26881 this.pinching = false;
26883 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
26884 this.dragable = false;
26888 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
26889 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
26893 onMouseMove : function(e)
26897 if(!this.canvasLoaded){
26901 if (!this.dragable){
26905 var minX = Math.ceil(this.thumbEl.getLeft(true));
26906 var minY = Math.ceil(this.thumbEl.getTop(true));
26908 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
26909 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
26911 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
26912 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
26914 x = x - this.mouseX;
26915 y = y - this.mouseY;
26917 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
26918 var bgY = Math.ceil(y + this.previewEl.getTop(true));
26920 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
26921 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
26923 this.previewEl.setLeft(bgX);
26924 this.previewEl.setTop(bgY);
26926 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
26927 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
26930 onMouseUp : function(e)
26934 this.dragable = false;
26937 onMouseWheel : function(e)
26941 this.startScale = this.scale;
26943 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
26945 if(!this.zoomable()){
26946 this.scale = this.startScale;
26955 zoomable : function()
26957 var minScale = this.thumbEl.getWidth() / this.minWidth;
26959 if(this.minWidth < this.minHeight){
26960 minScale = this.thumbEl.getHeight() / this.minHeight;
26963 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
26964 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
26968 (this.rotate == 0 || this.rotate == 180) &&
26970 width > this.imageEl.OriginWidth ||
26971 height > this.imageEl.OriginHeight ||
26972 (width < this.minWidth && height < this.minHeight)
26980 (this.rotate == 90 || this.rotate == 270) &&
26982 width > this.imageEl.OriginWidth ||
26983 height > this.imageEl.OriginHeight ||
26984 (width < this.minHeight && height < this.minWidth)
26991 !this.isDocument &&
26992 (this.rotate == 0 || this.rotate == 180) &&
26994 width < this.minWidth ||
26995 width > this.imageEl.OriginWidth ||
26996 height < this.minHeight ||
26997 height > this.imageEl.OriginHeight
27004 !this.isDocument &&
27005 (this.rotate == 90 || this.rotate == 270) &&
27007 width < this.minHeight ||
27008 width > this.imageEl.OriginWidth ||
27009 height < this.minWidth ||
27010 height > this.imageEl.OriginHeight
27020 onRotateLeft : function(e)
27022 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27024 var minScale = this.thumbEl.getWidth() / this.minWidth;
27026 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27027 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27029 this.startScale = this.scale;
27031 while (this.getScaleLevel() < minScale){
27033 this.scale = this.scale + 1;
27035 if(!this.zoomable()){
27040 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27041 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27046 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27053 this.scale = this.startScale;
27055 this.onRotateFail();
27060 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27062 if(this.isDocument){
27063 this.setThumbBoxSize();
27064 this.setThumbBoxPosition();
27065 this.setCanvasPosition();
27070 this.fireEvent('rotate', this, 'left');
27074 onRotateRight : function(e)
27076 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27078 var minScale = this.thumbEl.getWidth() / this.minWidth;
27080 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27081 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27083 this.startScale = this.scale;
27085 while (this.getScaleLevel() < minScale){
27087 this.scale = this.scale + 1;
27089 if(!this.zoomable()){
27094 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27095 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27100 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27107 this.scale = this.startScale;
27109 this.onRotateFail();
27114 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27116 if(this.isDocument){
27117 this.setThumbBoxSize();
27118 this.setThumbBoxPosition();
27119 this.setCanvasPosition();
27124 this.fireEvent('rotate', this, 'right');
27127 onRotateFail : function()
27129 this.errorEl.show(true);
27133 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
27138 this.previewEl.dom.innerHTML = '';
27140 var canvasEl = document.createElement("canvas");
27142 var contextEl = canvasEl.getContext("2d");
27144 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27145 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27146 var center = this.imageEl.OriginWidth / 2;
27148 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
27149 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27150 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27151 center = this.imageEl.OriginHeight / 2;
27154 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
27156 contextEl.translate(center, center);
27157 contextEl.rotate(this.rotate * Math.PI / 180);
27159 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27161 this.canvasEl = document.createElement("canvas");
27163 this.contextEl = this.canvasEl.getContext("2d");
27165 switch (this.rotate) {
27168 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27169 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27171 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27176 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27177 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27179 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27180 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);
27184 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27189 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27190 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27192 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27193 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);
27197 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);
27202 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27203 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27205 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27206 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27210 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);
27217 this.previewEl.appendChild(this.canvasEl);
27219 this.setCanvasPosition();
27224 if(!this.canvasLoaded){
27228 var imageCanvas = document.createElement("canvas");
27230 var imageContext = imageCanvas.getContext("2d");
27232 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27233 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27235 var center = imageCanvas.width / 2;
27237 imageContext.translate(center, center);
27239 imageContext.rotate(this.rotate * Math.PI / 180);
27241 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27243 var canvas = document.createElement("canvas");
27245 var context = canvas.getContext("2d");
27247 canvas.width = this.minWidth;
27248 canvas.height = this.minHeight;
27250 switch (this.rotate) {
27253 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27254 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27256 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27257 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27259 var targetWidth = this.minWidth - 2 * x;
27260 var targetHeight = this.minHeight - 2 * y;
27264 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27265 scale = targetWidth / width;
27268 if(x > 0 && y == 0){
27269 scale = targetHeight / height;
27272 if(x > 0 && y > 0){
27273 scale = targetWidth / width;
27275 if(width < height){
27276 scale = targetHeight / height;
27280 context.scale(scale, scale);
27282 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27283 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27285 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27286 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27288 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27293 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27294 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27296 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27297 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27299 var targetWidth = this.minWidth - 2 * x;
27300 var targetHeight = this.minHeight - 2 * y;
27304 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27305 scale = targetWidth / width;
27308 if(x > 0 && y == 0){
27309 scale = targetHeight / height;
27312 if(x > 0 && y > 0){
27313 scale = targetWidth / width;
27315 if(width < height){
27316 scale = targetHeight / height;
27320 context.scale(scale, scale);
27322 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27323 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27325 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27326 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27328 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27330 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27335 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27336 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27338 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27339 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27341 var targetWidth = this.minWidth - 2 * x;
27342 var targetHeight = this.minHeight - 2 * y;
27346 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27347 scale = targetWidth / width;
27350 if(x > 0 && y == 0){
27351 scale = targetHeight / height;
27354 if(x > 0 && y > 0){
27355 scale = targetWidth / width;
27357 if(width < height){
27358 scale = targetHeight / height;
27362 context.scale(scale, scale);
27364 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27365 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27367 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27368 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27370 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27371 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27373 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27378 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27379 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27381 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27382 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27384 var targetWidth = this.minWidth - 2 * x;
27385 var targetHeight = this.minHeight - 2 * y;
27389 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27390 scale = targetWidth / width;
27393 if(x > 0 && y == 0){
27394 scale = targetHeight / height;
27397 if(x > 0 && y > 0){
27398 scale = targetWidth / width;
27400 if(width < height){
27401 scale = targetHeight / height;
27405 context.scale(scale, scale);
27407 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27408 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27410 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27411 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27413 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27415 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27422 this.cropData = canvas.toDataURL(this.cropType);
27424 if(this.fireEvent('crop', this, this.cropData) !== false){
27425 this.process(this.file, this.cropData);
27432 setThumbBoxSize : function()
27436 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
27437 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
27438 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
27440 this.minWidth = width;
27441 this.minHeight = height;
27443 if(this.rotate == 90 || this.rotate == 270){
27444 this.minWidth = height;
27445 this.minHeight = width;
27450 width = Math.ceil(this.minWidth * height / this.minHeight);
27452 if(this.minWidth > this.minHeight){
27454 height = Math.ceil(this.minHeight * width / this.minWidth);
27457 this.thumbEl.setStyle({
27458 width : width + 'px',
27459 height : height + 'px'
27466 setThumbBoxPosition : function()
27468 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
27469 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
27471 this.thumbEl.setLeft(x);
27472 this.thumbEl.setTop(y);
27476 baseRotateLevel : function()
27478 this.baseRotate = 1;
27481 typeof(this.exif) != 'undefined' &&
27482 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
27483 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
27485 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
27488 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
27492 baseScaleLevel : function()
27496 if(this.isDocument){
27498 if(this.baseRotate == 6 || this.baseRotate == 8){
27500 height = this.thumbEl.getHeight();
27501 this.baseScale = height / this.imageEl.OriginWidth;
27503 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
27504 width = this.thumbEl.getWidth();
27505 this.baseScale = width / this.imageEl.OriginHeight;
27511 height = this.thumbEl.getHeight();
27512 this.baseScale = height / this.imageEl.OriginHeight;
27514 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
27515 width = this.thumbEl.getWidth();
27516 this.baseScale = width / this.imageEl.OriginWidth;
27522 if(this.baseRotate == 6 || this.baseRotate == 8){
27524 width = this.thumbEl.getHeight();
27525 this.baseScale = width / this.imageEl.OriginHeight;
27527 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
27528 height = this.thumbEl.getWidth();
27529 this.baseScale = height / this.imageEl.OriginHeight;
27532 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27533 height = this.thumbEl.getWidth();
27534 this.baseScale = height / this.imageEl.OriginHeight;
27536 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
27537 width = this.thumbEl.getHeight();
27538 this.baseScale = width / this.imageEl.OriginWidth;
27545 width = this.thumbEl.getWidth();
27546 this.baseScale = width / this.imageEl.OriginWidth;
27548 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
27549 height = this.thumbEl.getHeight();
27550 this.baseScale = height / this.imageEl.OriginHeight;
27553 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27555 height = this.thumbEl.getHeight();
27556 this.baseScale = height / this.imageEl.OriginHeight;
27558 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
27559 width = this.thumbEl.getWidth();
27560 this.baseScale = width / this.imageEl.OriginWidth;
27568 getScaleLevel : function()
27570 return this.baseScale * Math.pow(1.1, this.scale);
27573 onTouchStart : function(e)
27575 if(!this.canvasLoaded){
27576 this.beforeSelectFile(e);
27580 var touches = e.browserEvent.touches;
27586 if(touches.length == 1){
27587 this.onMouseDown(e);
27591 if(touches.length != 2){
27597 for(var i = 0, finger; finger = touches[i]; i++){
27598 coords.push(finger.pageX, finger.pageY);
27601 var x = Math.pow(coords[0] - coords[2], 2);
27602 var y = Math.pow(coords[1] - coords[3], 2);
27604 this.startDistance = Math.sqrt(x + y);
27606 this.startScale = this.scale;
27608 this.pinching = true;
27609 this.dragable = false;
27613 onTouchMove : function(e)
27615 if(!this.pinching && !this.dragable){
27619 var touches = e.browserEvent.touches;
27626 this.onMouseMove(e);
27632 for(var i = 0, finger; finger = touches[i]; i++){
27633 coords.push(finger.pageX, finger.pageY);
27636 var x = Math.pow(coords[0] - coords[2], 2);
27637 var y = Math.pow(coords[1] - coords[3], 2);
27639 this.endDistance = Math.sqrt(x + y);
27641 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
27643 if(!this.zoomable()){
27644 this.scale = this.startScale;
27652 onTouchEnd : function(e)
27654 this.pinching = false;
27655 this.dragable = false;
27659 process : function(file, crop)
27662 this.maskEl.mask(this.loadingText);
27665 this.xhr = new XMLHttpRequest();
27667 file.xhr = this.xhr;
27669 this.xhr.open(this.method, this.url, true);
27672 "Accept": "application/json",
27673 "Cache-Control": "no-cache",
27674 "X-Requested-With": "XMLHttpRequest"
27677 for (var headerName in headers) {
27678 var headerValue = headers[headerName];
27680 this.xhr.setRequestHeader(headerName, headerValue);
27686 this.xhr.onload = function()
27688 _this.xhrOnLoad(_this.xhr);
27691 this.xhr.onerror = function()
27693 _this.xhrOnError(_this.xhr);
27696 var formData = new FormData();
27698 formData.append('returnHTML', 'NO');
27701 formData.append('crop', crop);
27704 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
27705 formData.append(this.paramName, file, file.name);
27708 if(typeof(file.filename) != 'undefined'){
27709 formData.append('filename', file.filename);
27712 if(typeof(file.mimetype) != 'undefined'){
27713 formData.append('mimetype', file.mimetype);
27716 if(this.fireEvent('arrange', this, formData) != false){
27717 this.xhr.send(formData);
27721 xhrOnLoad : function(xhr)
27724 this.maskEl.unmask();
27727 if (xhr.readyState !== 4) {
27728 this.fireEvent('exception', this, xhr);
27732 var response = Roo.decode(xhr.responseText);
27734 if(!response.success){
27735 this.fireEvent('exception', this, xhr);
27739 var response = Roo.decode(xhr.responseText);
27741 this.fireEvent('upload', this, response);
27745 xhrOnError : function()
27748 this.maskEl.unmask();
27751 Roo.log('xhr on error');
27753 var response = Roo.decode(xhr.responseText);
27759 prepare : function(file)
27762 this.maskEl.mask(this.loadingText);
27768 if(typeof(file) === 'string'){
27769 this.loadCanvas(file);
27773 if(!file || !this.urlAPI){
27778 this.cropType = file.type;
27782 if(this.fireEvent('prepare', this, this.file) != false){
27784 var reader = new FileReader();
27786 reader.onload = function (e) {
27787 if (e.target.error) {
27788 Roo.log(e.target.error);
27792 var buffer = e.target.result,
27793 dataView = new DataView(buffer),
27795 maxOffset = dataView.byteLength - 4,
27799 if (dataView.getUint16(0) === 0xffd8) {
27800 while (offset < maxOffset) {
27801 markerBytes = dataView.getUint16(offset);
27803 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
27804 markerLength = dataView.getUint16(offset + 2) + 2;
27805 if (offset + markerLength > dataView.byteLength) {
27806 Roo.log('Invalid meta data: Invalid segment size.');
27810 if(markerBytes == 0xffe1){
27811 _this.parseExifData(
27818 offset += markerLength;
27828 var url = _this.urlAPI.createObjectURL(_this.file);
27830 _this.loadCanvas(url);
27835 reader.readAsArrayBuffer(this.file);
27841 parseExifData : function(dataView, offset, length)
27843 var tiffOffset = offset + 10,
27847 if (dataView.getUint32(offset + 4) !== 0x45786966) {
27848 // No Exif data, might be XMP data instead
27852 // Check for the ASCII code for "Exif" (0x45786966):
27853 if (dataView.getUint32(offset + 4) !== 0x45786966) {
27854 // No Exif data, might be XMP data instead
27857 if (tiffOffset + 8 > dataView.byteLength) {
27858 Roo.log('Invalid Exif data: Invalid segment size.');
27861 // Check for the two null bytes:
27862 if (dataView.getUint16(offset + 8) !== 0x0000) {
27863 Roo.log('Invalid Exif data: Missing byte alignment offset.');
27866 // Check the byte alignment:
27867 switch (dataView.getUint16(tiffOffset)) {
27869 littleEndian = true;
27872 littleEndian = false;
27875 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
27878 // Check for the TIFF tag marker (0x002A):
27879 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
27880 Roo.log('Invalid Exif data: Missing TIFF marker.');
27883 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
27884 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
27886 this.parseExifTags(
27889 tiffOffset + dirOffset,
27894 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
27899 if (dirOffset + 6 > dataView.byteLength) {
27900 Roo.log('Invalid Exif data: Invalid directory offset.');
27903 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
27904 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
27905 if (dirEndOffset + 4 > dataView.byteLength) {
27906 Roo.log('Invalid Exif data: Invalid directory size.');
27909 for (i = 0; i < tagsNumber; i += 1) {
27913 dirOffset + 2 + 12 * i, // tag offset
27917 // Return the offset to the next directory:
27918 return dataView.getUint32(dirEndOffset, littleEndian);
27921 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
27923 var tag = dataView.getUint16(offset, littleEndian);
27925 this.exif[tag] = this.getExifValue(
27929 dataView.getUint16(offset + 2, littleEndian), // tag type
27930 dataView.getUint32(offset + 4, littleEndian), // tag length
27935 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
27937 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
27946 Roo.log('Invalid Exif data: Invalid tag type.');
27950 tagSize = tagType.size * length;
27951 // Determine if the value is contained in the dataOffset bytes,
27952 // or if the value at the dataOffset is a pointer to the actual data:
27953 dataOffset = tagSize > 4 ?
27954 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
27955 if (dataOffset + tagSize > dataView.byteLength) {
27956 Roo.log('Invalid Exif data: Invalid data offset.');
27959 if (length === 1) {
27960 return tagType.getValue(dataView, dataOffset, littleEndian);
27963 for (i = 0; i < length; i += 1) {
27964 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
27967 if (tagType.ascii) {
27969 // Concatenate the chars:
27970 for (i = 0; i < values.length; i += 1) {
27972 // Ignore the terminating NULL byte(s):
27973 if (c === '\u0000') {
27985 Roo.apply(Roo.bootstrap.UploadCropbox, {
27987 'Orientation': 0x0112
27991 1: 0, //'top-left',
27993 3: 180, //'bottom-right',
27994 // 4: 'bottom-left',
27996 6: 90, //'right-top',
27997 // 7: 'right-bottom',
27998 8: 270 //'left-bottom'
28002 // byte, 8-bit unsigned int:
28004 getValue: function (dataView, dataOffset) {
28005 return dataView.getUint8(dataOffset);
28009 // ascii, 8-bit byte:
28011 getValue: function (dataView, dataOffset) {
28012 return String.fromCharCode(dataView.getUint8(dataOffset));
28017 // short, 16 bit int:
28019 getValue: function (dataView, dataOffset, littleEndian) {
28020 return dataView.getUint16(dataOffset, littleEndian);
28024 // long, 32 bit int:
28026 getValue: function (dataView, dataOffset, littleEndian) {
28027 return dataView.getUint32(dataOffset, littleEndian);
28031 // rational = two long values, first is numerator, second is denominator:
28033 getValue: function (dataView, dataOffset, littleEndian) {
28034 return dataView.getUint32(dataOffset, littleEndian) /
28035 dataView.getUint32(dataOffset + 4, littleEndian);
28039 // slong, 32 bit signed int:
28041 getValue: function (dataView, dataOffset, littleEndian) {
28042 return dataView.getInt32(dataOffset, littleEndian);
28046 // srational, two slongs, first is numerator, second is denominator:
28048 getValue: function (dataView, dataOffset, littleEndian) {
28049 return dataView.getInt32(dataOffset, littleEndian) /
28050 dataView.getInt32(dataOffset + 4, littleEndian);
28060 cls : 'btn-group roo-upload-cropbox-rotate-left',
28061 action : 'rotate-left',
28065 cls : 'btn btn-default',
28066 html : '<i class="fa fa-undo"></i>'
28072 cls : 'btn-group roo-upload-cropbox-picture',
28073 action : 'picture',
28077 cls : 'btn btn-default',
28078 html : '<i class="fa fa-picture-o"></i>'
28084 cls : 'btn-group roo-upload-cropbox-rotate-right',
28085 action : 'rotate-right',
28089 cls : 'btn btn-default',
28090 html : '<i class="fa fa-repeat"></i>'
28098 cls : 'btn-group roo-upload-cropbox-rotate-left',
28099 action : 'rotate-left',
28103 cls : 'btn btn-default',
28104 html : '<i class="fa fa-undo"></i>'
28110 cls : 'btn-group roo-upload-cropbox-download',
28111 action : 'download',
28115 cls : 'btn btn-default',
28116 html : '<i class="fa fa-download"></i>'
28122 cls : 'btn-group roo-upload-cropbox-crop',
28127 cls : 'btn btn-default',
28128 html : '<i class="fa fa-crop"></i>'
28134 cls : 'btn-group roo-upload-cropbox-trash',
28139 cls : 'btn btn-default',
28140 html : '<i class="fa fa-trash"></i>'
28146 cls : 'btn-group roo-upload-cropbox-rotate-right',
28147 action : 'rotate-right',
28151 cls : 'btn btn-default',
28152 html : '<i class="fa fa-repeat"></i>'
28160 cls : 'btn-group roo-upload-cropbox-rotate-left',
28161 action : 'rotate-left',
28165 cls : 'btn btn-default',
28166 html : '<i class="fa fa-undo"></i>'
28172 cls : 'btn-group roo-upload-cropbox-rotate-right',
28173 action : 'rotate-right',
28177 cls : 'btn btn-default',
28178 html : '<i class="fa fa-repeat"></i>'
28191 * @class Roo.bootstrap.DocumentManager
28192 * @extends Roo.bootstrap.Component
28193 * Bootstrap DocumentManager class
28194 * @cfg {String} paramName default 'imageUpload'
28195 * @cfg {String} toolTipName default 'filename'
28196 * @cfg {String} method default POST
28197 * @cfg {String} url action url
28198 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
28199 * @cfg {Boolean} multiple multiple upload default true
28200 * @cfg {Number} thumbSize default 300
28201 * @cfg {String} fieldLabel
28202 * @cfg {Number} labelWidth default 4
28203 * @cfg {String} labelAlign (left|top) default left
28204 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
28205 * @cfg {Number} labellg set the width of label (1-12)
28206 * @cfg {Number} labelmd set the width of label (1-12)
28207 * @cfg {Number} labelsm set the width of label (1-12)
28208 * @cfg {Number} labelxs set the width of label (1-12)
28211 * Create a new DocumentManager
28212 * @param {Object} config The config object
28215 Roo.bootstrap.DocumentManager = function(config){
28216 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
28219 this.delegates = [];
28224 * Fire when initial the DocumentManager
28225 * @param {Roo.bootstrap.DocumentManager} this
28230 * inspect selected file
28231 * @param {Roo.bootstrap.DocumentManager} this
28232 * @param {File} file
28237 * Fire when xhr load exception
28238 * @param {Roo.bootstrap.DocumentManager} this
28239 * @param {XMLHttpRequest} xhr
28241 "exception" : true,
28243 * @event afterupload
28244 * Fire when xhr load exception
28245 * @param {Roo.bootstrap.DocumentManager} this
28246 * @param {XMLHttpRequest} xhr
28248 "afterupload" : true,
28251 * prepare the form data
28252 * @param {Roo.bootstrap.DocumentManager} this
28253 * @param {Object} formData
28258 * Fire when remove the file
28259 * @param {Roo.bootstrap.DocumentManager} this
28260 * @param {Object} file
28265 * Fire after refresh the file
28266 * @param {Roo.bootstrap.DocumentManager} this
28271 * Fire after click the image
28272 * @param {Roo.bootstrap.DocumentManager} this
28273 * @param {Object} file
28278 * Fire when upload a image and editable set to true
28279 * @param {Roo.bootstrap.DocumentManager} this
28280 * @param {Object} file
28284 * @event beforeselectfile
28285 * Fire before select file
28286 * @param {Roo.bootstrap.DocumentManager} this
28288 "beforeselectfile" : true,
28291 * Fire before process file
28292 * @param {Roo.bootstrap.DocumentManager} this
28293 * @param {Object} file
28300 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
28309 paramName : 'imageUpload',
28310 toolTipName : 'filename',
28313 labelAlign : 'left',
28323 getAutoCreate : function()
28325 var managerWidget = {
28327 cls : 'roo-document-manager',
28331 cls : 'roo-document-manager-selector',
28336 cls : 'roo-document-manager-uploader',
28340 cls : 'roo-document-manager-upload-btn',
28341 html : '<i class="fa fa-plus"></i>'
28352 cls : 'column col-md-12',
28357 if(this.fieldLabel.length){
28362 cls : 'column col-md-12',
28363 html : this.fieldLabel
28367 cls : 'column col-md-12',
28372 if(this.labelAlign == 'left'){
28377 html : this.fieldLabel
28386 if(this.labelWidth > 12){
28387 content[0].style = "width: " + this.labelWidth + 'px';
28390 if(this.labelWidth < 13 && this.labelmd == 0){
28391 this.labelmd = this.labelWidth;
28394 if(this.labellg > 0){
28395 content[0].cls += ' col-lg-' + this.labellg;
28396 content[1].cls += ' col-lg-' + (12 - this.labellg);
28399 if(this.labelmd > 0){
28400 content[0].cls += ' col-md-' + this.labelmd;
28401 content[1].cls += ' col-md-' + (12 - this.labelmd);
28404 if(this.labelsm > 0){
28405 content[0].cls += ' col-sm-' + this.labelsm;
28406 content[1].cls += ' col-sm-' + (12 - this.labelsm);
28409 if(this.labelxs > 0){
28410 content[0].cls += ' col-xs-' + this.labelxs;
28411 content[1].cls += ' col-xs-' + (12 - this.labelxs);
28419 cls : 'row clearfix',
28427 initEvents : function()
28429 this.managerEl = this.el.select('.roo-document-manager', true).first();
28430 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28432 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
28433 this.selectorEl.hide();
28436 this.selectorEl.attr('multiple', 'multiple');
28439 this.selectorEl.on('change', this.onFileSelected, this);
28441 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
28442 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28444 this.uploader.on('click', this.onUploaderClick, this);
28446 this.renderProgressDialog();
28450 window.addEventListener("resize", function() { _this.refresh(); } );
28452 this.fireEvent('initial', this);
28455 renderProgressDialog : function()
28459 this.progressDialog = new Roo.bootstrap.Modal({
28460 cls : 'roo-document-manager-progress-dialog',
28461 allow_close : false,
28471 btnclick : function() {
28472 _this.uploadCancel();
28478 this.progressDialog.render(Roo.get(document.body));
28480 this.progress = new Roo.bootstrap.Progress({
28481 cls : 'roo-document-manager-progress',
28486 this.progress.render(this.progressDialog.getChildContainer());
28488 this.progressBar = new Roo.bootstrap.ProgressBar({
28489 cls : 'roo-document-manager-progress-bar',
28492 aria_valuemax : 12,
28496 this.progressBar.render(this.progress.getChildContainer());
28499 onUploaderClick : function(e)
28501 e.preventDefault();
28503 if(this.fireEvent('beforeselectfile', this) != false){
28504 this.selectorEl.dom.click();
28509 onFileSelected : function(e)
28511 e.preventDefault();
28513 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
28517 Roo.each(this.selectorEl.dom.files, function(file){
28518 if(this.fireEvent('inspect', this, file) != false){
28519 this.files.push(file);
28529 this.selectorEl.dom.value = '';
28531 if(!this.files.length){
28535 if(this.boxes > 0 && this.files.length > this.boxes){
28536 this.files = this.files.slice(0, this.boxes);
28539 this.uploader.show();
28541 if(this.boxes > 0 && this.files.length > this.boxes - 1){
28542 this.uploader.hide();
28551 Roo.each(this.files, function(file){
28553 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
28554 var f = this.renderPreview(file);
28559 if(file.type.indexOf('image') != -1){
28560 this.delegates.push(
28562 _this.process(file);
28563 }).createDelegate(this)
28571 _this.process(file);
28572 }).createDelegate(this)
28577 this.files = files;
28579 this.delegates = this.delegates.concat(docs);
28581 if(!this.delegates.length){
28586 this.progressBar.aria_valuemax = this.delegates.length;
28593 arrange : function()
28595 if(!this.delegates.length){
28596 this.progressDialog.hide();
28601 var delegate = this.delegates.shift();
28603 this.progressDialog.show();
28605 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
28607 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
28612 refresh : function()
28614 this.uploader.show();
28616 if(this.boxes > 0 && this.files.length > this.boxes - 1){
28617 this.uploader.hide();
28620 Roo.isTouch ? this.closable(false) : this.closable(true);
28622 this.fireEvent('refresh', this);
28625 onRemove : function(e, el, o)
28627 e.preventDefault();
28629 this.fireEvent('remove', this, o);
28633 remove : function(o)
28637 Roo.each(this.files, function(file){
28638 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
28647 this.files = files;
28654 Roo.each(this.files, function(file){
28659 file.target.remove();
28668 onClick : function(e, el, o)
28670 e.preventDefault();
28672 this.fireEvent('click', this, o);
28676 closable : function(closable)
28678 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
28680 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28692 xhrOnLoad : function(xhr)
28694 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
28698 if (xhr.readyState !== 4) {
28700 this.fireEvent('exception', this, xhr);
28704 var response = Roo.decode(xhr.responseText);
28706 if(!response.success){
28708 this.fireEvent('exception', this, xhr);
28712 var file = this.renderPreview(response.data);
28714 this.files.push(file);
28718 this.fireEvent('afterupload', this, xhr);
28722 xhrOnError : function(xhr)
28724 Roo.log('xhr on error');
28726 var response = Roo.decode(xhr.responseText);
28733 process : function(file)
28735 if(this.fireEvent('process', this, file) !== false){
28736 if(this.editable && file.type.indexOf('image') != -1){
28737 this.fireEvent('edit', this, file);
28741 this.uploadStart(file, false);
28748 uploadStart : function(file, crop)
28750 this.xhr = new XMLHttpRequest();
28752 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
28757 file.xhr = this.xhr;
28759 this.managerEl.createChild({
28761 cls : 'roo-document-manager-loading',
28765 tooltip : file.name,
28766 cls : 'roo-document-manager-thumb',
28767 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
28773 this.xhr.open(this.method, this.url, true);
28776 "Accept": "application/json",
28777 "Cache-Control": "no-cache",
28778 "X-Requested-With": "XMLHttpRequest"
28781 for (var headerName in headers) {
28782 var headerValue = headers[headerName];
28784 this.xhr.setRequestHeader(headerName, headerValue);
28790 this.xhr.onload = function()
28792 _this.xhrOnLoad(_this.xhr);
28795 this.xhr.onerror = function()
28797 _this.xhrOnError(_this.xhr);
28800 var formData = new FormData();
28802 formData.append('returnHTML', 'NO');
28805 formData.append('crop', crop);
28808 formData.append(this.paramName, file, file.name);
28815 if(this.fireEvent('prepare', this, formData, options) != false){
28817 if(options.manually){
28821 this.xhr.send(formData);
28825 this.uploadCancel();
28828 uploadCancel : function()
28834 this.delegates = [];
28836 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
28843 renderPreview : function(file)
28845 if(typeof(file.target) != 'undefined' && file.target){
28849 var previewEl = this.managerEl.createChild({
28851 cls : 'roo-document-manager-preview',
28855 tooltip : file[this.toolTipName],
28856 cls : 'roo-document-manager-thumb',
28857 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename + '">'
28862 html : '<i class="fa fa-times-circle"></i>'
28867 var close = previewEl.select('button.close', true).first();
28869 close.on('click', this.onRemove, this, file);
28871 file.target = previewEl;
28873 var image = previewEl.select('img', true).first();
28877 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
28879 image.on('click', this.onClick, this, file);
28885 onPreviewLoad : function(file, image)
28887 if(typeof(file.target) == 'undefined' || !file.target){
28891 var width = image.dom.naturalWidth || image.dom.width;
28892 var height = image.dom.naturalHeight || image.dom.height;
28894 if(width > height){
28895 file.target.addClass('wide');
28899 file.target.addClass('tall');
28904 uploadFromSource : function(file, crop)
28906 this.xhr = new XMLHttpRequest();
28908 this.managerEl.createChild({
28910 cls : 'roo-document-manager-loading',
28914 tooltip : file.name,
28915 cls : 'roo-document-manager-thumb',
28916 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
28922 this.xhr.open(this.method, this.url, true);
28925 "Accept": "application/json",
28926 "Cache-Control": "no-cache",
28927 "X-Requested-With": "XMLHttpRequest"
28930 for (var headerName in headers) {
28931 var headerValue = headers[headerName];
28933 this.xhr.setRequestHeader(headerName, headerValue);
28939 this.xhr.onload = function()
28941 _this.xhrOnLoad(_this.xhr);
28944 this.xhr.onerror = function()
28946 _this.xhrOnError(_this.xhr);
28949 var formData = new FormData();
28951 formData.append('returnHTML', 'NO');
28953 formData.append('crop', crop);
28955 if(typeof(file.filename) != 'undefined'){
28956 formData.append('filename', file.filename);
28959 if(typeof(file.mimetype) != 'undefined'){
28960 formData.append('mimetype', file.mimetype);
28965 if(this.fireEvent('prepare', this, formData) != false){
28966 this.xhr.send(formData);
28976 * @class Roo.bootstrap.DocumentViewer
28977 * @extends Roo.bootstrap.Component
28978 * Bootstrap DocumentViewer class
28979 * @cfg {Boolean} showDownload (true|false) show download button (default true)
28980 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
28983 * Create a new DocumentViewer
28984 * @param {Object} config The config object
28987 Roo.bootstrap.DocumentViewer = function(config){
28988 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
28993 * Fire after initEvent
28994 * @param {Roo.bootstrap.DocumentViewer} this
29000 * @param {Roo.bootstrap.DocumentViewer} this
29005 * Fire after download button
29006 * @param {Roo.bootstrap.DocumentViewer} this
29011 * Fire after trash button
29012 * @param {Roo.bootstrap.DocumentViewer} this
29019 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
29021 showDownload : true,
29025 getAutoCreate : function()
29029 cls : 'roo-document-viewer',
29033 cls : 'roo-document-viewer-body',
29037 cls : 'roo-document-viewer-thumb',
29041 cls : 'roo-document-viewer-image'
29049 cls : 'roo-document-viewer-footer',
29052 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
29056 cls : 'btn-group roo-document-viewer-download',
29060 cls : 'btn btn-default',
29061 html : '<i class="fa fa-download"></i>'
29067 cls : 'btn-group roo-document-viewer-trash',
29071 cls : 'btn btn-default',
29072 html : '<i class="fa fa-trash"></i>'
29085 initEvents : function()
29087 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
29088 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
29090 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
29091 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
29093 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
29094 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
29096 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
29097 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
29099 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
29100 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
29102 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
29103 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
29105 this.bodyEl.on('click', this.onClick, this);
29106 this.downloadBtn.on('click', this.onDownload, this);
29107 this.trashBtn.on('click', this.onTrash, this);
29109 this.downloadBtn.hide();
29110 this.trashBtn.hide();
29112 if(this.showDownload){
29113 this.downloadBtn.show();
29116 if(this.showTrash){
29117 this.trashBtn.show();
29120 if(!this.showDownload && !this.showTrash) {
29121 this.footerEl.hide();
29126 initial : function()
29128 this.fireEvent('initial', this);
29132 onClick : function(e)
29134 e.preventDefault();
29136 this.fireEvent('click', this);
29139 onDownload : function(e)
29141 e.preventDefault();
29143 this.fireEvent('download', this);
29146 onTrash : function(e)
29148 e.preventDefault();
29150 this.fireEvent('trash', this);
29162 * @class Roo.bootstrap.NavProgressBar
29163 * @extends Roo.bootstrap.Component
29164 * Bootstrap NavProgressBar class
29167 * Create a new nav progress bar
29168 * @param {Object} config The config object
29171 Roo.bootstrap.NavProgressBar = function(config){
29172 Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
29174 this.bullets = this.bullets || [];
29176 // Roo.bootstrap.NavProgressBar.register(this);
29180 * Fires when the active item changes
29181 * @param {Roo.bootstrap.NavProgressBar} this
29182 * @param {Roo.bootstrap.NavProgressItem} selected The item selected
29183 * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item
29190 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component, {
29195 getAutoCreate : function()
29197 var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
29201 cls : 'roo-navigation-bar-group',
29205 cls : 'roo-navigation-top-bar'
29209 cls : 'roo-navigation-bullets-bar',
29213 cls : 'roo-navigation-bar'
29220 cls : 'roo-navigation-bottom-bar'
29230 initEvents: function()
29235 onRender : function(ct, position)
29237 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
29239 if(this.bullets.length){
29240 Roo.each(this.bullets, function(b){
29249 addItem : function(cfg)
29251 var item = new Roo.bootstrap.NavProgressItem(cfg);
29253 item.parentId = this.id;
29254 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
29257 var top = new Roo.bootstrap.Element({
29259 cls : 'roo-navigation-bar-text'
29262 var bottom = new Roo.bootstrap.Element({
29264 cls : 'roo-navigation-bar-text'
29267 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
29268 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
29270 var topText = new Roo.bootstrap.Element({
29272 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
29275 var bottomText = new Roo.bootstrap.Element({
29277 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
29280 topText.onRender(top.el, null);
29281 bottomText.onRender(bottom.el, null);
29284 item.bottomEl = bottom;
29287 this.barItems.push(item);
29292 getActive : function()
29294 var active = false;
29296 Roo.each(this.barItems, function(v){
29298 if (!v.isActive()) {
29310 setActiveItem : function(item)
29314 Roo.each(this.barItems, function(v){
29315 if (v.rid == item.rid) {
29319 if (v.isActive()) {
29320 v.setActive(false);
29325 item.setActive(true);
29327 this.fireEvent('changed', this, item, prev);
29330 getBarItem: function(rid)
29334 Roo.each(this.barItems, function(e) {
29335 if (e.rid != rid) {
29346 indexOfItem : function(item)
29350 Roo.each(this.barItems, function(v, i){
29352 if (v.rid != item.rid) {
29363 setActiveNext : function()
29365 var i = this.indexOfItem(this.getActive());
29367 if (i > this.barItems.length) {
29371 this.setActiveItem(this.barItems[i+1]);
29374 setActivePrev : function()
29376 var i = this.indexOfItem(this.getActive());
29382 this.setActiveItem(this.barItems[i-1]);
29385 format : function()
29387 if(!this.barItems.length){
29391 var width = 100 / this.barItems.length;
29393 Roo.each(this.barItems, function(i){
29394 i.el.setStyle('width', width + '%');
29395 i.topEl.el.setStyle('width', width + '%');
29396 i.bottomEl.el.setStyle('width', width + '%');
29405 * Nav Progress Item
29410 * @class Roo.bootstrap.NavProgressItem
29411 * @extends Roo.bootstrap.Component
29412 * Bootstrap NavProgressItem class
29413 * @cfg {String} rid the reference id
29414 * @cfg {Boolean} active (true|false) Is item active default false
29415 * @cfg {Boolean} disabled (true|false) Is item active default false
29416 * @cfg {String} html
29417 * @cfg {String} position (top|bottom) text position default bottom
29418 * @cfg {String} icon show icon instead of number
29421 * Create a new NavProgressItem
29422 * @param {Object} config The config object
29424 Roo.bootstrap.NavProgressItem = function(config){
29425 Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
29430 * The raw click event for the entire grid.
29431 * @param {Roo.bootstrap.NavProgressItem} this
29432 * @param {Roo.EventObject} e
29439 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component, {
29445 position : 'bottom',
29448 getAutoCreate : function()
29450 var iconCls = 'roo-navigation-bar-item-icon';
29452 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
29456 cls: 'roo-navigation-bar-item',
29466 cfg.cls += ' active';
29469 cfg.cls += ' disabled';
29475 disable : function()
29477 this.setDisabled(true);
29480 enable : function()
29482 this.setDisabled(false);
29485 initEvents: function()
29487 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
29489 this.iconEl.on('click', this.onClick, this);
29492 onClick : function(e)
29494 e.preventDefault();
29500 if(this.fireEvent('click', this, e) === false){
29504 this.parent().setActiveItem(this);
29507 isActive: function ()
29509 return this.active;
29512 setActive : function(state)
29514 if(this.active == state){
29518 this.active = state;
29521 this.el.addClass('active');
29525 this.el.removeClass('active');
29530 setDisabled : function(state)
29532 if(this.disabled == state){
29536 this.disabled = state;
29539 this.el.addClass('disabled');
29543 this.el.removeClass('disabled');
29546 tooltipEl : function()
29548 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
29561 * @class Roo.bootstrap.FieldLabel
29562 * @extends Roo.bootstrap.Component
29563 * Bootstrap FieldLabel class
29564 * @cfg {String} html contents of the element
29565 * @cfg {String} tag tag of the element default label
29566 * @cfg {String} cls class of the element
29567 * @cfg {String} target label target
29568 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
29569 * @cfg {String} invalidClass default "text-danger fa fa-lg fa-exclamation-triangle"
29570 * @cfg {String} validClass default "text-success fa fa-lg fa-check"
29571 * @cfg {String} iconTooltip default "This field is required"
29574 * Create a new FieldLabel
29575 * @param {Object} config The config object
29578 Roo.bootstrap.FieldLabel = function(config){
29579 Roo.bootstrap.Element.superclass.constructor.call(this, config);
29584 * Fires after the field has been marked as invalid.
29585 * @param {Roo.form.FieldLabel} this
29586 * @param {String} msg The validation message
29591 * Fires after the field has been validated with no errors.
29592 * @param {Roo.form.FieldLabel} this
29598 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component, {
29605 invalidClass : 'text-danger fa fa-lg fa-exclamation-triangle',
29606 validClass : 'text-success fa fa-lg fa-check',
29607 iconTooltip : 'This field is required',
29609 getAutoCreate : function(){
29613 cls : 'roo-bootstrap-field-label ' + this.cls,
29619 tooltip : this.iconTooltip
29631 initEvents: function()
29633 Roo.bootstrap.Element.superclass.initEvents.call(this);
29635 this.iconEl = this.el.select('i', true).first();
29637 this.iconEl.setVisibilityMode(Roo.Element.DISPLAY).hide();
29639 Roo.bootstrap.FieldLabel.register(this);
29643 * Mark this field as valid
29645 markValid : function()
29647 this.iconEl.show();
29649 this.iconEl.removeClass(this.invalidClass);
29651 this.iconEl.addClass(this.validClass);
29653 this.fireEvent('valid', this);
29657 * Mark this field as invalid
29658 * @param {String} msg The validation message
29660 markInvalid : function(msg)
29662 this.iconEl.show();
29664 this.iconEl.removeClass(this.validClass);
29666 this.iconEl.addClass(this.invalidClass);
29668 this.fireEvent('invalid', this, msg);
29674 Roo.apply(Roo.bootstrap.FieldLabel, {
29679 * register a FieldLabel Group
29680 * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
29682 register : function(label)
29684 if(this.groups.hasOwnProperty(label.target)){
29688 this.groups[label.target] = label;
29692 * fetch a FieldLabel Group based on the target
29693 * @param {string} target
29694 * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
29696 get: function(target) {
29697 if (typeof(this.groups[target]) == 'undefined') {
29701 return this.groups[target] ;
29710 * page DateSplitField.
29716 * @class Roo.bootstrap.DateSplitField
29717 * @extends Roo.bootstrap.Component
29718 * Bootstrap DateSplitField class
29719 * @cfg {string} fieldLabel - the label associated
29720 * @cfg {Number} labelWidth set the width of label (0-12)
29721 * @cfg {String} labelAlign (top|left)
29722 * @cfg {Boolean} dayAllowBlank (true|false) default false
29723 * @cfg {Boolean} monthAllowBlank (true|false) default false
29724 * @cfg {Boolean} yearAllowBlank (true|false) default false
29725 * @cfg {string} dayPlaceholder
29726 * @cfg {string} monthPlaceholder
29727 * @cfg {string} yearPlaceholder
29728 * @cfg {string} dayFormat default 'd'
29729 * @cfg {string} monthFormat default 'm'
29730 * @cfg {string} yearFormat default 'Y'
29731 * @cfg {Number} labellg set the width of label (1-12)
29732 * @cfg {Number} labelmd set the width of label (1-12)
29733 * @cfg {Number} labelsm set the width of label (1-12)
29734 * @cfg {Number} labelxs set the width of label (1-12)
29738 * Create a new DateSplitField
29739 * @param {Object} config The config object
29742 Roo.bootstrap.DateSplitField = function(config){
29743 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
29749 * getting the data of years
29750 * @param {Roo.bootstrap.DateSplitField} this
29751 * @param {Object} years
29756 * getting the data of days
29757 * @param {Roo.bootstrap.DateSplitField} this
29758 * @param {Object} days
29763 * Fires after the field has been marked as invalid.
29764 * @param {Roo.form.Field} this
29765 * @param {String} msg The validation message
29770 * Fires after the field has been validated with no errors.
29771 * @param {Roo.form.Field} this
29777 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
29780 labelAlign : 'top',
29782 dayAllowBlank : false,
29783 monthAllowBlank : false,
29784 yearAllowBlank : false,
29785 dayPlaceholder : '',
29786 monthPlaceholder : '',
29787 yearPlaceholder : '',
29791 isFormField : true,
29797 getAutoCreate : function()
29801 cls : 'row roo-date-split-field-group',
29806 cls : 'form-hidden-field roo-date-split-field-group-value',
29812 var labelCls = 'col-md-12';
29813 var contentCls = 'col-md-4';
29815 if(this.fieldLabel){
29819 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
29823 html : this.fieldLabel
29828 if(this.labelAlign == 'left'){
29830 if(this.labelWidth > 12){
29831 label.style = "width: " + this.labelWidth + 'px';
29834 if(this.labelWidth < 13 && this.labelmd == 0){
29835 this.labelmd = this.labelWidth;
29838 if(this.labellg > 0){
29839 labelCls = ' col-lg-' + this.labellg;
29840 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
29843 if(this.labelmd > 0){
29844 labelCls = ' col-md-' + this.labelmd;
29845 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
29848 if(this.labelsm > 0){
29849 labelCls = ' col-sm-' + this.labelsm;
29850 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
29853 if(this.labelxs > 0){
29854 labelCls = ' col-xs-' + this.labelxs;
29855 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
29859 label.cls += ' ' + labelCls;
29861 cfg.cn.push(label);
29864 Roo.each(['day', 'month', 'year'], function(t){
29867 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
29874 inputEl: function ()
29876 return this.el.select('.roo-date-split-field-group-value', true).first();
29879 onRender : function(ct, position)
29883 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
29885 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
29887 this.dayField = new Roo.bootstrap.ComboBox({
29888 allowBlank : this.dayAllowBlank,
29889 alwaysQuery : true,
29890 displayField : 'value',
29893 forceSelection : true,
29895 placeholder : this.dayPlaceholder,
29896 selectOnFocus : true,
29897 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
29898 triggerAction : 'all',
29900 valueField : 'value',
29901 store : new Roo.data.SimpleStore({
29902 data : (function() {
29904 _this.fireEvent('days', _this, days);
29907 fields : [ 'value' ]
29910 select : function (_self, record, index)
29912 _this.setValue(_this.getValue());
29917 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
29919 this.monthField = new Roo.bootstrap.MonthField({
29920 after : '<i class=\"fa fa-calendar\"></i>',
29921 allowBlank : this.monthAllowBlank,
29922 placeholder : this.monthPlaceholder,
29925 render : function (_self)
29927 this.el.select('span.input-group-addon', true).first().on('click', function(e){
29928 e.preventDefault();
29932 select : function (_self, oldvalue, newvalue)
29934 _this.setValue(_this.getValue());
29939 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
29941 this.yearField = new Roo.bootstrap.ComboBox({
29942 allowBlank : this.yearAllowBlank,
29943 alwaysQuery : true,
29944 displayField : 'value',
29947 forceSelection : true,
29949 placeholder : this.yearPlaceholder,
29950 selectOnFocus : true,
29951 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
29952 triggerAction : 'all',
29954 valueField : 'value',
29955 store : new Roo.data.SimpleStore({
29956 data : (function() {
29958 _this.fireEvent('years', _this, years);
29961 fields : [ 'value' ]
29964 select : function (_self, record, index)
29966 _this.setValue(_this.getValue());
29971 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
29974 setValue : function(v, format)
29976 this.inputEl.dom.value = v;
29978 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
29980 var d = Date.parseDate(v, f);
29987 this.setDay(d.format(this.dayFormat));
29988 this.setMonth(d.format(this.monthFormat));
29989 this.setYear(d.format(this.yearFormat));
29996 setDay : function(v)
29998 this.dayField.setValue(v);
29999 this.inputEl.dom.value = this.getValue();
30004 setMonth : function(v)
30006 this.monthField.setValue(v, true);
30007 this.inputEl.dom.value = this.getValue();
30012 setYear : function(v)
30014 this.yearField.setValue(v);
30015 this.inputEl.dom.value = this.getValue();
30020 getDay : function()
30022 return this.dayField.getValue();
30025 getMonth : function()
30027 return this.monthField.getValue();
30030 getYear : function()
30032 return this.yearField.getValue();
30035 getValue : function()
30037 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
30039 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
30049 this.inputEl.dom.value = '';
30054 validate : function()
30056 var d = this.dayField.validate();
30057 var m = this.monthField.validate();
30058 var y = this.yearField.validate();
30063 (!this.dayAllowBlank && !d) ||
30064 (!this.monthAllowBlank && !m) ||
30065 (!this.yearAllowBlank && !y)
30070 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
30079 this.markInvalid();
30084 markValid : function()
30087 var label = this.el.select('label', true).first();
30088 var icon = this.el.select('i.fa-star', true).first();
30094 this.fireEvent('valid', this);
30098 * Mark this field as invalid
30099 * @param {String} msg The validation message
30101 markInvalid : function(msg)
30104 var label = this.el.select('label', true).first();
30105 var icon = this.el.select('i.fa-star', true).first();
30107 if(label && !icon){
30108 this.el.select('.roo-date-split-field-label', true).createChild({
30110 cls : 'text-danger fa fa-lg fa-star',
30111 tooltip : 'This field is required',
30112 style : 'margin-right:5px;'
30116 this.fireEvent('invalid', this, msg);
30119 clearInvalid : function()
30121 var label = this.el.select('label', true).first();
30122 var icon = this.el.select('i.fa-star', true).first();
30128 this.fireEvent('valid', this);
30131 getName: function()
30141 * http://masonry.desandro.com
30143 * The idea is to render all the bricks based on vertical width...
30145 * The original code extends 'outlayer' - we might need to use that....
30151 * @class Roo.bootstrap.LayoutMasonry
30152 * @extends Roo.bootstrap.Component
30153 * Bootstrap Layout Masonry class
30156 * Create a new Element
30157 * @param {Object} config The config object
30160 Roo.bootstrap.LayoutMasonry = function(config){
30162 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
30166 Roo.bootstrap.LayoutMasonry.register(this);
30172 * Fire after layout the items
30173 * @param {Roo.bootstrap.LayoutMasonry} this
30174 * @param {Roo.EventObject} e
30181 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
30184 * @cfg {Boolean} isLayoutInstant = no animation?
30186 isLayoutInstant : false, // needed?
30189 * @cfg {Number} boxWidth width of the columns
30194 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
30199 * @cfg {Number} padWidth padding below box..
30204 * @cfg {Number} gutter gutter width..
30209 * @cfg {Number} maxCols maximum number of columns
30215 * @cfg {Boolean} isAutoInitial defalut true
30217 isAutoInitial : true,
30222 * @cfg {Boolean} isHorizontal defalut false
30224 isHorizontal : false,
30226 currentSize : null,
30232 bricks: null, //CompositeElement
30236 _isLayoutInited : false,
30238 // isAlternative : false, // only use for vertical layout...
30241 * @cfg {Number} alternativePadWidth padding below box..
30243 alternativePadWidth : 50,
30245 selectedBrick : [],
30247 getAutoCreate : function(){
30249 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
30253 cls: 'blog-masonary-wrapper ' + this.cls,
30255 cls : 'mas-boxes masonary'
30262 getChildContainer: function( )
30264 if (this.boxesEl) {
30265 return this.boxesEl;
30268 this.boxesEl = this.el.select('.mas-boxes').first();
30270 return this.boxesEl;
30274 initEvents : function()
30278 if(this.isAutoInitial){
30279 Roo.log('hook children rendered');
30280 this.on('childrenrendered', function() {
30281 Roo.log('children rendered');
30287 initial : function()
30289 this.selectedBrick = [];
30291 this.currentSize = this.el.getBox(true);
30293 Roo.EventManager.onWindowResize(this.resize, this);
30295 if(!this.isAutoInitial){
30303 //this.layout.defer(500,this);
30307 resize : function()
30309 var cs = this.el.getBox(true);
30312 this.currentSize.width == cs.width &&
30313 this.currentSize.x == cs.x &&
30314 this.currentSize.height == cs.height &&
30315 this.currentSize.y == cs.y
30317 Roo.log("no change in with or X or Y");
30321 this.currentSize = cs;
30327 layout : function()
30329 this._resetLayout();
30331 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
30333 this.layoutItems( isInstant );
30335 this._isLayoutInited = true;
30337 this.fireEvent('layout', this);
30341 _resetLayout : function()
30343 if(this.isHorizontal){
30344 this.horizontalMeasureColumns();
30348 this.verticalMeasureColumns();
30352 verticalMeasureColumns : function()
30354 this.getContainerWidth();
30356 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30357 // this.colWidth = Math.floor(this.containerWidth * 0.8);
30361 var boxWidth = this.boxWidth + this.padWidth;
30363 if(this.containerWidth < this.boxWidth){
30364 boxWidth = this.containerWidth
30367 var containerWidth = this.containerWidth;
30369 var cols = Math.floor(containerWidth / boxWidth);
30371 this.cols = Math.max( cols, 1 );
30373 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
30375 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
30377 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
30379 this.colWidth = boxWidth + avail - this.padWidth;
30381 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
30382 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
30385 horizontalMeasureColumns : function()
30387 this.getContainerWidth();
30389 var boxWidth = this.boxWidth;
30391 if(this.containerWidth < boxWidth){
30392 boxWidth = this.containerWidth;
30395 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
30397 this.el.setHeight(boxWidth);
30401 getContainerWidth : function()
30403 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
30406 layoutItems : function( isInstant )
30408 Roo.log(this.bricks);
30410 var items = Roo.apply([], this.bricks);
30412 if(this.isHorizontal){
30413 this._horizontalLayoutItems( items , isInstant );
30417 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30418 // this._verticalAlternativeLayoutItems( items , isInstant );
30422 this._verticalLayoutItems( items , isInstant );
30426 _verticalLayoutItems : function ( items , isInstant)
30428 if ( !items || !items.length ) {
30433 ['xs', 'xs', 'xs', 'tall'],
30434 ['xs', 'xs', 'tall'],
30435 ['xs', 'xs', 'sm'],
30436 ['xs', 'xs', 'xs'],
30442 ['sm', 'xs', 'xs'],
30446 ['tall', 'xs', 'xs', 'xs'],
30447 ['tall', 'xs', 'xs'],
30459 Roo.each(items, function(item, k){
30461 switch (item.size) {
30462 // these layouts take up a full box,
30473 boxes.push([item]);
30496 var filterPattern = function(box, length)
30504 var pattern = box.slice(0, length);
30508 Roo.each(pattern, function(i){
30509 format.push(i.size);
30512 Roo.each(standard, function(s){
30514 if(String(s) != String(format)){
30523 if(!match && length == 1){
30528 filterPattern(box, length - 1);
30532 queue.push(pattern);
30534 box = box.slice(length, box.length);
30536 filterPattern(box, 4);
30542 Roo.each(boxes, function(box, k){
30548 if(box.length == 1){
30553 filterPattern(box, 4);
30557 this._processVerticalLayoutQueue( queue, isInstant );
30561 // _verticalAlternativeLayoutItems : function( items , isInstant )
30563 // if ( !items || !items.length ) {
30567 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
30571 _horizontalLayoutItems : function ( items , isInstant)
30573 if ( !items || !items.length || items.length < 3) {
30579 var eItems = items.slice(0, 3);
30581 items = items.slice(3, items.length);
30584 ['xs', 'xs', 'xs', 'wide'],
30585 ['xs', 'xs', 'wide'],
30586 ['xs', 'xs', 'sm'],
30587 ['xs', 'xs', 'xs'],
30593 ['sm', 'xs', 'xs'],
30597 ['wide', 'xs', 'xs', 'xs'],
30598 ['wide', 'xs', 'xs'],
30611 Roo.each(items, function(item, k){
30613 switch (item.size) {
30624 boxes.push([item]);
30648 var filterPattern = function(box, length)
30656 var pattern = box.slice(0, length);
30660 Roo.each(pattern, function(i){
30661 format.push(i.size);
30664 Roo.each(standard, function(s){
30666 if(String(s) != String(format)){
30675 if(!match && length == 1){
30680 filterPattern(box, length - 1);
30684 queue.push(pattern);
30686 box = box.slice(length, box.length);
30688 filterPattern(box, 4);
30694 Roo.each(boxes, function(box, k){
30700 if(box.length == 1){
30705 filterPattern(box, 4);
30712 var pos = this.el.getBox(true);
30716 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
30718 var hit_end = false;
30720 Roo.each(queue, function(box){
30724 Roo.each(box, function(b){
30726 b.el.setVisibilityMode(Roo.Element.DISPLAY);
30736 Roo.each(box, function(b){
30738 b.el.setVisibilityMode(Roo.Element.DISPLAY);
30741 mx = Math.max(mx, b.x);
30745 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
30749 Roo.each(box, function(b){
30751 b.el.setVisibilityMode(Roo.Element.DISPLAY);
30765 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
30768 /** Sets position of item in DOM
30769 * @param {Element} item
30770 * @param {Number} x - horizontal position
30771 * @param {Number} y - vertical position
30772 * @param {Boolean} isInstant - disables transitions
30774 _processVerticalLayoutQueue : function( queue, isInstant )
30776 var pos = this.el.getBox(true);
30781 for (var i = 0; i < this.cols; i++){
30785 Roo.each(queue, function(box, k){
30787 var col = k % this.cols;
30789 Roo.each(box, function(b,kk){
30791 b.el.position('absolute');
30793 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
30794 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
30796 if(b.size == 'md-left' || b.size == 'md-right'){
30797 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
30798 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
30801 b.el.setWidth(width);
30802 b.el.setHeight(height);
30804 b.el.select('iframe',true).setSize(width,height);
30808 for (var i = 0; i < this.cols; i++){
30810 if(maxY[i] < maxY[col]){
30815 col = Math.min(col, i);
30819 x = pos.x + col * (this.colWidth + this.padWidth);
30823 var positions = [];
30825 switch (box.length){
30827 positions = this.getVerticalOneBoxColPositions(x, y, box);
30830 positions = this.getVerticalTwoBoxColPositions(x, y, box);
30833 positions = this.getVerticalThreeBoxColPositions(x, y, box);
30836 positions = this.getVerticalFourBoxColPositions(x, y, box);
30842 Roo.each(box, function(b,kk){
30844 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
30846 var sz = b.el.getSize();
30848 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
30856 for (var i = 0; i < this.cols; i++){
30857 mY = Math.max(mY, maxY[i]);
30860 this.el.setHeight(mY - pos.y);
30864 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
30866 // var pos = this.el.getBox(true);
30869 // var maxX = pos.right;
30871 // var maxHeight = 0;
30873 // Roo.each(items, function(item, k){
30877 // item.el.position('absolute');
30879 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
30881 // item.el.setWidth(width);
30883 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
30885 // item.el.setHeight(height);
30888 // item.el.setXY([x, y], isInstant ? false : true);
30890 // item.el.setXY([maxX - width, y], isInstant ? false : true);
30893 // y = y + height + this.alternativePadWidth;
30895 // maxHeight = maxHeight + height + this.alternativePadWidth;
30899 // this.el.setHeight(maxHeight);
30903 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
30905 var pos = this.el.getBox(true);
30910 var maxX = pos.right;
30912 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
30914 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
30916 Roo.each(queue, function(box, k){
30918 Roo.each(box, function(b, kk){
30920 b.el.position('absolute');
30922 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
30923 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
30925 if(b.size == 'md-left' || b.size == 'md-right'){
30926 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
30927 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
30930 b.el.setWidth(width);
30931 b.el.setHeight(height);
30939 var positions = [];
30941 switch (box.length){
30943 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
30946 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
30949 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
30952 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
30958 Roo.each(box, function(b,kk){
30960 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
30962 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
30970 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
30972 Roo.each(eItems, function(b,k){
30974 b.size = (k == 0) ? 'sm' : 'xs';
30975 b.x = (k == 0) ? 2 : 1;
30976 b.y = (k == 0) ? 2 : 1;
30978 b.el.position('absolute');
30980 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
30982 b.el.setWidth(width);
30984 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
30986 b.el.setHeight(height);
30990 var positions = [];
30993 x : maxX - this.unitWidth * 2 - this.gutter,
30998 x : maxX - this.unitWidth,
30999 y : minY + (this.unitWidth + this.gutter) * 2
31003 x : maxX - this.unitWidth * 3 - this.gutter * 2,
31007 Roo.each(eItems, function(b,k){
31009 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
31015 getVerticalOneBoxColPositions : function(x, y, box)
31019 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
31021 if(box[0].size == 'md-left'){
31025 if(box[0].size == 'md-right'){
31030 x : x + (this.unitWidth + this.gutter) * rand,
31037 getVerticalTwoBoxColPositions : function(x, y, box)
31041 if(box[0].size == 'xs'){
31045 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
31049 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
31063 x : x + (this.unitWidth + this.gutter) * 2,
31064 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
31071 getVerticalThreeBoxColPositions : function(x, y, box)
31075 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31083 x : x + (this.unitWidth + this.gutter) * 1,
31088 x : x + (this.unitWidth + this.gutter) * 2,
31096 if(box[0].size == 'xs' && box[1].size == 'xs'){
31105 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
31109 x : x + (this.unitWidth + this.gutter) * 1,
31123 x : x + (this.unitWidth + this.gutter) * 2,
31128 x : x + (this.unitWidth + this.gutter) * 2,
31129 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
31136 getVerticalFourBoxColPositions : function(x, y, box)
31140 if(box[0].size == 'xs'){
31149 y : y + (this.unitHeight + this.gutter) * 1
31154 y : y + (this.unitHeight + this.gutter) * 2
31158 x : x + (this.unitWidth + this.gutter) * 1,
31172 x : x + (this.unitWidth + this.gutter) * 2,
31177 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
31178 y : y + (this.unitHeight + this.gutter) * 1
31182 x : x + (this.unitWidth + this.gutter) * 2,
31183 y : y + (this.unitWidth + this.gutter) * 2
31190 getHorizontalOneBoxColPositions : function(maxX, minY, box)
31194 if(box[0].size == 'md-left'){
31196 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31203 if(box[0].size == 'md-right'){
31205 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31206 y : minY + (this.unitWidth + this.gutter) * 1
31212 var rand = Math.floor(Math.random() * (4 - box[0].y));
31215 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31216 y : minY + (this.unitWidth + this.gutter) * rand
31223 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
31227 if(box[0].size == 'xs'){
31230 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31235 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31236 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
31244 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31249 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31250 y : minY + (this.unitWidth + this.gutter) * 2
31257 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
31261 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31264 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31269 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31270 y : minY + (this.unitWidth + this.gutter) * 1
31274 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31275 y : minY + (this.unitWidth + this.gutter) * 2
31282 if(box[0].size == 'xs' && box[1].size == 'xs'){
31285 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31290 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31295 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31296 y : minY + (this.unitWidth + this.gutter) * 1
31304 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31309 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31310 y : minY + (this.unitWidth + this.gutter) * 2
31314 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31315 y : minY + (this.unitWidth + this.gutter) * 2
31322 getHorizontalFourBoxColPositions : function(maxX, minY, box)
31326 if(box[0].size == 'xs'){
31329 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31334 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31339 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),
31344 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
31345 y : minY + (this.unitWidth + this.gutter) * 1
31353 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31358 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31359 y : minY + (this.unitWidth + this.gutter) * 2
31363 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31364 y : minY + (this.unitWidth + this.gutter) * 2
31368 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),
31369 y : minY + (this.unitWidth + this.gutter) * 2
31377 * remove a Masonry Brick
31378 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
31380 removeBrick : function(brick_id)
31386 for (var i = 0; i<this.bricks.length; i++) {
31387 if (this.bricks[i].id == brick_id) {
31388 this.bricks.splice(i,1);
31389 this.el.dom.removeChild(Roo.get(brick_id).dom);
31396 * adds a Masonry Brick
31397 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
31399 addBrick : function(cfg)
31401 var cn = new Roo.bootstrap.MasonryBrick(cfg);
31402 //this.register(cn);
31403 cn.parentId = this.id;
31404 cn.onRender(this.el, null);
31409 * register a Masonry Brick
31410 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
31413 register : function(brick)
31415 this.bricks.push(brick);
31416 brick.masonryId = this.id;
31420 * clear all the Masonry Brick
31422 clearAll : function()
31425 //this.getChildContainer().dom.innerHTML = "";
31426 this.el.dom.innerHTML = '';
31429 getSelected : function()
31431 if (!this.selectedBrick) {
31435 return this.selectedBrick;
31439 Roo.apply(Roo.bootstrap.LayoutMasonry, {
31443 * register a Masonry Layout
31444 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
31447 register : function(layout)
31449 this.groups[layout.id] = layout;
31452 * fetch a Masonry Layout based on the masonry layout ID
31453 * @param {string} the masonry layout to add
31454 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
31457 get: function(layout_id) {
31458 if (typeof(this.groups[layout_id]) == 'undefined') {
31461 return this.groups[layout_id] ;
31473 * http://masonry.desandro.com
31475 * The idea is to render all the bricks based on vertical width...
31477 * The original code extends 'outlayer' - we might need to use that....
31483 * @class Roo.bootstrap.LayoutMasonryAuto
31484 * @extends Roo.bootstrap.Component
31485 * Bootstrap Layout Masonry class
31488 * Create a new Element
31489 * @param {Object} config The config object
31492 Roo.bootstrap.LayoutMasonryAuto = function(config){
31493 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
31496 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
31499 * @cfg {Boolean} isFitWidth - resize the width..
31501 isFitWidth : false, // options..
31503 * @cfg {Boolean} isOriginLeft = left align?
31505 isOriginLeft : true,
31507 * @cfg {Boolean} isOriginTop = top align?
31509 isOriginTop : false,
31511 * @cfg {Boolean} isLayoutInstant = no animation?
31513 isLayoutInstant : false, // needed?
31515 * @cfg {Boolean} isResizingContainer = not sure if this is used..
31517 isResizingContainer : true,
31519 * @cfg {Number} columnWidth width of the columns
31525 * @cfg {Number} maxCols maximum number of columns
31530 * @cfg {Number} padHeight padding below box..
31536 * @cfg {Boolean} isAutoInitial defalut true
31539 isAutoInitial : true,
31545 initialColumnWidth : 0,
31546 currentSize : null,
31548 colYs : null, // array.
31555 bricks: null, //CompositeElement
31556 cols : 0, // array?
31557 // element : null, // wrapped now this.el
31558 _isLayoutInited : null,
31561 getAutoCreate : function(){
31565 cls: 'blog-masonary-wrapper ' + this.cls,
31567 cls : 'mas-boxes masonary'
31574 getChildContainer: function( )
31576 if (this.boxesEl) {
31577 return this.boxesEl;
31580 this.boxesEl = this.el.select('.mas-boxes').first();
31582 return this.boxesEl;
31586 initEvents : function()
31590 if(this.isAutoInitial){
31591 Roo.log('hook children rendered');
31592 this.on('childrenrendered', function() {
31593 Roo.log('children rendered');
31600 initial : function()
31602 this.reloadItems();
31604 this.currentSize = this.el.getBox(true);
31606 /// was window resize... - let's see if this works..
31607 Roo.EventManager.onWindowResize(this.resize, this);
31609 if(!this.isAutoInitial){
31614 this.layout.defer(500,this);
31617 reloadItems: function()
31619 this.bricks = this.el.select('.masonry-brick', true);
31621 this.bricks.each(function(b) {
31622 //Roo.log(b.getSize());
31623 if (!b.attr('originalwidth')) {
31624 b.attr('originalwidth', b.getSize().width);
31629 Roo.log(this.bricks.elements.length);
31632 resize : function()
31635 var cs = this.el.getBox(true);
31637 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
31638 Roo.log("no change in with or X");
31641 this.currentSize = cs;
31645 layout : function()
31648 this._resetLayout();
31649 //this._manageStamps();
31651 // don't animate first layout
31652 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
31653 this.layoutItems( isInstant );
31655 // flag for initalized
31656 this._isLayoutInited = true;
31659 layoutItems : function( isInstant )
31661 //var items = this._getItemsForLayout( this.items );
31662 // original code supports filtering layout items.. we just ignore it..
31664 this._layoutItems( this.bricks , isInstant );
31666 this._postLayout();
31668 _layoutItems : function ( items , isInstant)
31670 //this.fireEvent( 'layout', this, items );
31673 if ( !items || !items.elements.length ) {
31674 // no items, emit event with empty array
31679 items.each(function(item) {
31680 Roo.log("layout item");
31682 // get x/y object from method
31683 var position = this._getItemLayoutPosition( item );
31685 position.item = item;
31686 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
31687 queue.push( position );
31690 this._processLayoutQueue( queue );
31692 /** Sets position of item in DOM
31693 * @param {Element} item
31694 * @param {Number} x - horizontal position
31695 * @param {Number} y - vertical position
31696 * @param {Boolean} isInstant - disables transitions
31698 _processLayoutQueue : function( queue )
31700 for ( var i=0, len = queue.length; i < len; i++ ) {
31701 var obj = queue[i];
31702 obj.item.position('absolute');
31703 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
31709 * Any logic you want to do after each layout,
31710 * i.e. size the container
31712 _postLayout : function()
31714 this.resizeContainer();
31717 resizeContainer : function()
31719 if ( !this.isResizingContainer ) {
31722 var size = this._getContainerSize();
31724 this.el.setSize(size.width,size.height);
31725 this.boxesEl.setSize(size.width,size.height);
31731 _resetLayout : function()
31733 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
31734 this.colWidth = this.el.getWidth();
31735 //this.gutter = this.el.getWidth();
31737 this.measureColumns();
31743 this.colYs.push( 0 );
31749 measureColumns : function()
31751 this.getContainerWidth();
31752 // if columnWidth is 0, default to outerWidth of first item
31753 if ( !this.columnWidth ) {
31754 var firstItem = this.bricks.first();
31755 Roo.log(firstItem);
31756 this.columnWidth = this.containerWidth;
31757 if (firstItem && firstItem.attr('originalwidth') ) {
31758 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
31760 // columnWidth fall back to item of first element
31761 Roo.log("set column width?");
31762 this.initialColumnWidth = this.columnWidth ;
31764 // if first elem has no width, default to size of container
31769 if (this.initialColumnWidth) {
31770 this.columnWidth = this.initialColumnWidth;
31775 // column width is fixed at the top - however if container width get's smaller we should
31778 // this bit calcs how man columns..
31780 var columnWidth = this.columnWidth += this.gutter;
31782 // calculate columns
31783 var containerWidth = this.containerWidth + this.gutter;
31785 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
31786 // fix rounding errors, typically with gutters
31787 var excess = columnWidth - containerWidth % columnWidth;
31790 // if overshoot is less than a pixel, round up, otherwise floor it
31791 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
31792 cols = Math[ mathMethod ]( cols );
31793 this.cols = Math.max( cols, 1 );
31794 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
31796 // padding positioning..
31797 var totalColWidth = this.cols * this.columnWidth;
31798 var padavail = this.containerWidth - totalColWidth;
31799 // so for 2 columns - we need 3 'pads'
31801 var padNeeded = (1+this.cols) * this.padWidth;
31803 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
31805 this.columnWidth += padExtra
31806 //this.padWidth = Math.floor(padavail / ( this.cols));
31808 // adjust colum width so that padding is fixed??
31810 // we have 3 columns ... total = width * 3
31811 // we have X left over... that should be used by
31813 //if (this.expandC) {
31821 getContainerWidth : function()
31823 /* // container is parent if fit width
31824 var container = this.isFitWidth ? this.element.parentNode : this.element;
31825 // check that this.size and size are there
31826 // IE8 triggers resize on body size change, so they might not be
31828 var size = getSize( container ); //FIXME
31829 this.containerWidth = size && size.innerWidth; //FIXME
31832 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
31836 _getItemLayoutPosition : function( item ) // what is item?
31838 // we resize the item to our columnWidth..
31840 item.setWidth(this.columnWidth);
31841 item.autoBoxAdjust = false;
31843 var sz = item.getSize();
31845 // how many columns does this brick span
31846 var remainder = this.containerWidth % this.columnWidth;
31848 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
31849 // round if off by 1 pixel, otherwise use ceil
31850 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
31851 colSpan = Math.min( colSpan, this.cols );
31853 // normally this should be '1' as we dont' currently allow multi width columns..
31855 var colGroup = this._getColGroup( colSpan );
31856 // get the minimum Y value from the columns
31857 var minimumY = Math.min.apply( Math, colGroup );
31858 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
31860 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
31862 // position the brick
31864 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
31865 y: this.currentSize.y + minimumY + this.padHeight
31869 // apply setHeight to necessary columns
31870 var setHeight = minimumY + sz.height + this.padHeight;
31871 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
31873 var setSpan = this.cols + 1 - colGroup.length;
31874 for ( var i = 0; i < setSpan; i++ ) {
31875 this.colYs[ shortColIndex + i ] = setHeight ;
31882 * @param {Number} colSpan - number of columns the element spans
31883 * @returns {Array} colGroup
31885 _getColGroup : function( colSpan )
31887 if ( colSpan < 2 ) {
31888 // if brick spans only one column, use all the column Ys
31893 // how many different places could this brick fit horizontally
31894 var groupCount = this.cols + 1 - colSpan;
31895 // for each group potential horizontal position
31896 for ( var i = 0; i < groupCount; i++ ) {
31897 // make an array of colY values for that one group
31898 var groupColYs = this.colYs.slice( i, i + colSpan );
31899 // and get the max value of the array
31900 colGroup[i] = Math.max.apply( Math, groupColYs );
31905 _manageStamp : function( stamp )
31907 var stampSize = stamp.getSize();
31908 var offset = stamp.getBox();
31909 // get the columns that this stamp affects
31910 var firstX = this.isOriginLeft ? offset.x : offset.right;
31911 var lastX = firstX + stampSize.width;
31912 var firstCol = Math.floor( firstX / this.columnWidth );
31913 firstCol = Math.max( 0, firstCol );
31915 var lastCol = Math.floor( lastX / this.columnWidth );
31916 // lastCol should not go over if multiple of columnWidth #425
31917 lastCol -= lastX % this.columnWidth ? 0 : 1;
31918 lastCol = Math.min( this.cols - 1, lastCol );
31920 // set colYs to bottom of the stamp
31921 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
31924 for ( var i = firstCol; i <= lastCol; i++ ) {
31925 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
31930 _getContainerSize : function()
31932 this.maxY = Math.max.apply( Math, this.colYs );
31937 if ( this.isFitWidth ) {
31938 size.width = this._getContainerFitWidth();
31944 _getContainerFitWidth : function()
31946 var unusedCols = 0;
31947 // count unused columns
31950 if ( this.colYs[i] !== 0 ) {
31955 // fit container to columns that have been used
31956 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
31959 needsResizeLayout : function()
31961 var previousWidth = this.containerWidth;
31962 this.getContainerWidth();
31963 return previousWidth !== this.containerWidth;
31978 * @class Roo.bootstrap.MasonryBrick
31979 * @extends Roo.bootstrap.Component
31980 * Bootstrap MasonryBrick class
31983 * Create a new MasonryBrick
31984 * @param {Object} config The config object
31987 Roo.bootstrap.MasonryBrick = function(config){
31989 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
31991 Roo.bootstrap.MasonryBrick.register(this);
31997 * When a MasonryBrick is clcik
31998 * @param {Roo.bootstrap.MasonryBrick} this
31999 * @param {Roo.EventObject} e
32005 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
32008 * @cfg {String} title
32012 * @cfg {String} html
32016 * @cfg {String} bgimage
32020 * @cfg {String} videourl
32024 * @cfg {String} cls
32028 * @cfg {String} href
32032 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
32037 * @cfg {String} placetitle (center|bottom)
32042 * @cfg {Boolean} isFitContainer defalut true
32044 isFitContainer : true,
32047 * @cfg {Boolean} preventDefault defalut false
32049 preventDefault : false,
32052 * @cfg {Boolean} inverse defalut false
32054 maskInverse : false,
32056 getAutoCreate : function()
32058 if(!this.isFitContainer){
32059 return this.getSplitAutoCreate();
32062 var cls = 'masonry-brick masonry-brick-full';
32064 if(this.href.length){
32065 cls += ' masonry-brick-link';
32068 if(this.bgimage.length){
32069 cls += ' masonry-brick-image';
32072 if(this.maskInverse){
32073 cls += ' mask-inverse';
32076 if(!this.html.length && !this.maskInverse && !this.videourl.length){
32077 cls += ' enable-mask';
32081 cls += ' masonry-' + this.size + '-brick';
32084 if(this.placetitle.length){
32086 switch (this.placetitle) {
32088 cls += ' masonry-center-title';
32091 cls += ' masonry-bottom-title';
32098 if(!this.html.length && !this.bgimage.length){
32099 cls += ' masonry-center-title';
32102 if(!this.html.length && this.bgimage.length){
32103 cls += ' masonry-bottom-title';
32108 cls += ' ' + this.cls;
32112 tag: (this.href.length) ? 'a' : 'div',
32117 cls: 'masonry-brick-mask'
32121 cls: 'masonry-brick-paragraph',
32127 if(this.href.length){
32128 cfg.href = this.href;
32131 var cn = cfg.cn[1].cn;
32133 if(this.title.length){
32136 cls: 'masonry-brick-title',
32141 if(this.html.length){
32144 cls: 'masonry-brick-text',
32149 if (!this.title.length && !this.html.length) {
32150 cfg.cn[1].cls += ' hide';
32153 if(this.bgimage.length){
32156 cls: 'masonry-brick-image-view',
32161 if(this.videourl.length){
32162 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32163 // youtube support only?
32166 cls: 'masonry-brick-image-view',
32169 allowfullscreen : true
32177 getSplitAutoCreate : function()
32179 var cls = 'masonry-brick masonry-brick-split';
32181 if(this.href.length){
32182 cls += ' masonry-brick-link';
32185 if(this.bgimage.length){
32186 cls += ' masonry-brick-image';
32190 cls += ' masonry-' + this.size + '-brick';
32193 switch (this.placetitle) {
32195 cls += ' masonry-center-title';
32198 cls += ' masonry-bottom-title';
32201 if(!this.bgimage.length){
32202 cls += ' masonry-center-title';
32205 if(this.bgimage.length){
32206 cls += ' masonry-bottom-title';
32212 cls += ' ' + this.cls;
32216 tag: (this.href.length) ? 'a' : 'div',
32221 cls: 'masonry-brick-split-head',
32225 cls: 'masonry-brick-paragraph',
32232 cls: 'masonry-brick-split-body',
32238 if(this.href.length){
32239 cfg.href = this.href;
32242 if(this.title.length){
32243 cfg.cn[0].cn[0].cn.push({
32245 cls: 'masonry-brick-title',
32250 if(this.html.length){
32251 cfg.cn[1].cn.push({
32253 cls: 'masonry-brick-text',
32258 if(this.bgimage.length){
32259 cfg.cn[0].cn.push({
32261 cls: 'masonry-brick-image-view',
32266 if(this.videourl.length){
32267 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32268 // youtube support only?
32269 cfg.cn[0].cn.cn.push({
32271 cls: 'masonry-brick-image-view',
32274 allowfullscreen : true
32281 initEvents: function()
32283 switch (this.size) {
32316 this.el.on('touchstart', this.onTouchStart, this);
32317 this.el.on('touchmove', this.onTouchMove, this);
32318 this.el.on('touchend', this.onTouchEnd, this);
32319 this.el.on('contextmenu', this.onContextMenu, this);
32321 this.el.on('mouseenter' ,this.enter, this);
32322 this.el.on('mouseleave', this.leave, this);
32323 this.el.on('click', this.onClick, this);
32326 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
32327 this.parent().bricks.push(this);
32332 onClick: function(e, el)
32334 var time = this.endTimer - this.startTimer;
32335 // Roo.log(e.preventDefault());
32338 e.preventDefault();
32343 if(!this.preventDefault){
32347 e.preventDefault();
32349 if (this.activcClass != '') {
32350 this.selectBrick();
32353 this.fireEvent('click', this);
32356 enter: function(e, el)
32358 e.preventDefault();
32360 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32364 if(this.bgimage.length && this.html.length){
32365 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32369 leave: function(e, el)
32371 e.preventDefault();
32373 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32377 if(this.bgimage.length && this.html.length){
32378 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
32382 onTouchStart: function(e, el)
32384 // e.preventDefault();
32386 this.touchmoved = false;
32388 if(!this.isFitContainer){
32392 if(!this.bgimage.length || !this.html.length){
32396 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32398 this.timer = new Date().getTime();
32402 onTouchMove: function(e, el)
32404 this.touchmoved = true;
32407 onContextMenu : function(e,el)
32409 e.preventDefault();
32410 e.stopPropagation();
32414 onTouchEnd: function(e, el)
32416 // e.preventDefault();
32418 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
32425 if(!this.bgimage.length || !this.html.length){
32427 if(this.href.length){
32428 window.location.href = this.href;
32434 if(!this.isFitContainer){
32438 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
32440 window.location.href = this.href;
32443 //selection on single brick only
32444 selectBrick : function() {
32446 if (!this.parentId) {
32450 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
32451 var index = m.selectedBrick.indexOf(this.id);
32454 m.selectedBrick.splice(index,1);
32455 this.el.removeClass(this.activeClass);
32459 for(var i = 0; i < m.selectedBrick.length; i++) {
32460 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
32461 b.el.removeClass(b.activeClass);
32464 m.selectedBrick = [];
32466 m.selectedBrick.push(this.id);
32467 this.el.addClass(this.activeClass);
32473 Roo.apply(Roo.bootstrap.MasonryBrick, {
32476 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
32478 * register a Masonry Brick
32479 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32482 register : function(brick)
32484 //this.groups[brick.id] = brick;
32485 this.groups.add(brick.id, brick);
32488 * fetch a masonry brick based on the masonry brick ID
32489 * @param {string} the masonry brick to add
32490 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
32493 get: function(brick_id)
32495 // if (typeof(this.groups[brick_id]) == 'undefined') {
32498 // return this.groups[brick_id] ;
32500 if(this.groups.key(brick_id)) {
32501 return this.groups.key(brick_id);
32519 * @class Roo.bootstrap.Brick
32520 * @extends Roo.bootstrap.Component
32521 * Bootstrap Brick class
32524 * Create a new Brick
32525 * @param {Object} config The config object
32528 Roo.bootstrap.Brick = function(config){
32529 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
32535 * When a Brick is click
32536 * @param {Roo.bootstrap.Brick} this
32537 * @param {Roo.EventObject} e
32543 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
32546 * @cfg {String} title
32550 * @cfg {String} html
32554 * @cfg {String} bgimage
32558 * @cfg {String} cls
32562 * @cfg {String} href
32566 * @cfg {String} video
32570 * @cfg {Boolean} square
32574 getAutoCreate : function()
32576 var cls = 'roo-brick';
32578 if(this.href.length){
32579 cls += ' roo-brick-link';
32582 if(this.bgimage.length){
32583 cls += ' roo-brick-image';
32586 if(!this.html.length && !this.bgimage.length){
32587 cls += ' roo-brick-center-title';
32590 if(!this.html.length && this.bgimage.length){
32591 cls += ' roo-brick-bottom-title';
32595 cls += ' ' + this.cls;
32599 tag: (this.href.length) ? 'a' : 'div',
32604 cls: 'roo-brick-paragraph',
32610 if(this.href.length){
32611 cfg.href = this.href;
32614 var cn = cfg.cn[0].cn;
32616 if(this.title.length){
32619 cls: 'roo-brick-title',
32624 if(this.html.length){
32627 cls: 'roo-brick-text',
32634 if(this.bgimage.length){
32637 cls: 'roo-brick-image-view',
32645 initEvents: function()
32647 if(this.title.length || this.html.length){
32648 this.el.on('mouseenter' ,this.enter, this);
32649 this.el.on('mouseleave', this.leave, this);
32652 Roo.EventManager.onWindowResize(this.resize, this);
32654 if(this.bgimage.length){
32655 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
32656 this.imageEl.on('load', this.onImageLoad, this);
32663 onImageLoad : function()
32668 resize : function()
32670 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
32672 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
32674 if(this.bgimage.length){
32675 var image = this.el.select('.roo-brick-image-view', true).first();
32677 image.setWidth(paragraph.getWidth());
32680 image.setHeight(paragraph.getWidth());
32683 this.el.setHeight(image.getHeight());
32684 paragraph.setHeight(image.getHeight());
32690 enter: function(e, el)
32692 e.preventDefault();
32694 if(this.bgimage.length){
32695 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
32696 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
32700 leave: function(e, el)
32702 e.preventDefault();
32704 if(this.bgimage.length){
32705 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
32706 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
32722 * @class Roo.bootstrap.NumberField
32723 * @extends Roo.bootstrap.Input
32724 * Bootstrap NumberField class
32730 * Create a new NumberField
32731 * @param {Object} config The config object
32734 Roo.bootstrap.NumberField = function(config){
32735 Roo.bootstrap.NumberField.superclass.constructor.call(this, config);
32738 Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
32741 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
32743 allowDecimals : true,
32745 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
32747 decimalSeparator : ".",
32749 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
32751 decimalPrecision : 2,
32753 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
32755 allowNegative : true,
32757 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
32759 minValue : Number.NEGATIVE_INFINITY,
32761 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
32763 maxValue : Number.MAX_VALUE,
32765 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
32767 minText : "The minimum value for this field is {0}",
32769 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
32771 maxText : "The maximum value for this field is {0}",
32773 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
32774 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
32776 nanText : "{0} is not a valid number",
32778 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
32783 initEvents : function()
32785 Roo.bootstrap.NumberField.superclass.initEvents.call(this);
32787 var allowed = "0123456789";
32789 if(this.allowDecimals){
32790 allowed += this.decimalSeparator;
32793 if(this.allowNegative){
32797 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
32799 var keyPress = function(e){
32801 var k = e.getKey();
32803 var c = e.getCharCode();
32806 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
32807 allowed.indexOf(String.fromCharCode(c)) === -1
32813 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
32817 if(allowed.indexOf(String.fromCharCode(c)) === -1){
32822 this.el.on("keypress", keyPress, this);
32825 validateValue : function(value)
32828 if(!Roo.bootstrap.NumberField.superclass.validateValue.call(this, value)){
32832 var num = this.parseValue(value);
32835 this.markInvalid(String.format(this.nanText, value));
32839 if(num < this.minValue){
32840 this.markInvalid(String.format(this.minText, this.minValue));
32844 if(num > this.maxValue){
32845 this.markInvalid(String.format(this.maxText, this.maxValue));
32852 getValue : function()
32854 return this.fixPrecision(this.parseValue(Roo.bootstrap.NumberField.superclass.getValue.call(this)));
32857 parseValue : function(value)
32859 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
32860 return isNaN(value) ? '' : value;
32863 fixPrecision : function(value)
32865 var nan = isNaN(value);
32867 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
32868 return nan ? '' : value;
32870 return parseFloat(value).toFixed(this.decimalPrecision);
32873 setValue : function(v)
32875 v = this.fixPrecision(v);
32876 Roo.bootstrap.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
32879 decimalPrecisionFcn : function(v)
32881 return Math.floor(v);
32884 beforeBlur : function()
32890 var v = this.parseValue(this.getRawValue());
32905 * @class Roo.bootstrap.DocumentSlider
32906 * @extends Roo.bootstrap.Component
32907 * Bootstrap DocumentSlider class
32910 * Create a new DocumentViewer
32911 * @param {Object} config The config object
32914 Roo.bootstrap.DocumentSlider = function(config){
32915 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
32922 * Fire after initEvent
32923 * @param {Roo.bootstrap.DocumentSlider} this
32928 * Fire after update
32929 * @param {Roo.bootstrap.DocumentSlider} this
32935 * @param {Roo.bootstrap.DocumentSlider} this
32941 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
32947 getAutoCreate : function()
32951 cls : 'roo-document-slider',
32955 cls : 'roo-document-slider-header',
32959 cls : 'roo-document-slider-header-title'
32965 cls : 'roo-document-slider-body',
32969 cls : 'roo-document-slider-prev',
32973 cls : 'fa fa-chevron-left'
32979 cls : 'roo-document-slider-thumb',
32983 cls : 'roo-document-slider-image'
32989 cls : 'roo-document-slider-next',
32993 cls : 'fa fa-chevron-right'
33005 initEvents : function()
33007 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
33008 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
33010 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
33011 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
33013 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
33014 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
33016 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
33017 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
33019 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
33020 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
33022 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
33023 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33025 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
33026 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33028 this.thumbEl.on('click', this.onClick, this);
33030 this.prevIndicator.on('click', this.prev, this);
33032 this.nextIndicator.on('click', this.next, this);
33036 initial : function()
33038 if(this.files.length){
33039 this.indicator = 1;
33043 this.fireEvent('initial', this);
33046 update : function()
33048 this.imageEl.attr('src', this.files[this.indicator - 1]);
33050 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
33052 this.prevIndicator.show();
33054 if(this.indicator == 1){
33055 this.prevIndicator.hide();
33058 this.nextIndicator.show();
33060 if(this.indicator == this.files.length){
33061 this.nextIndicator.hide();
33064 this.thumbEl.scrollTo('top');
33066 this.fireEvent('update', this);
33069 onClick : function(e)
33071 e.preventDefault();
33073 this.fireEvent('click', this);
33078 e.preventDefault();
33080 this.indicator = Math.max(1, this.indicator - 1);
33087 e.preventDefault();
33089 this.indicator = Math.min(this.files.length, this.indicator + 1);
33103 * @class Roo.bootstrap.RadioSet
33104 * @extends Roo.bootstrap.Input
33105 * Bootstrap RadioSet class
33106 * @cfg {String} indicatorpos (left|right) default left
33107 * @cfg {Boolean} inline (true|false) inline the element (default true)
33108 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
33110 * Create a new RadioSet
33111 * @param {Object} config The config object
33114 Roo.bootstrap.RadioSet = function(config){
33116 Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
33120 Roo.bootstrap.RadioSet.register(this);
33125 * Fires when the element is checked or unchecked.
33126 * @param {Roo.bootstrap.RadioSet} this This radio
33127 * @param {Roo.bootstrap.Radio} item The checked item
33134 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input, {
33142 indicatorpos : 'left',
33144 getAutoCreate : function()
33148 cls : 'roo-radio-set-label',
33152 html : this.fieldLabel
33157 if(this.indicatorpos == 'left'){
33160 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
33161 tooltip : 'This field is required'
33166 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
33167 tooltip : 'This field is required'
33173 cls : 'roo-radio-set-items'
33176 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
33178 if (align === 'left' && this.fieldLabel.length) {
33181 cls : "roo-radio-set-right",
33187 if(this.labelWidth > 12){
33188 label.style = "width: " + this.labelWidth + 'px';
33191 if(this.labelWidth < 13 && this.labelmd == 0){
33192 this.labelmd = this.labelWidth;
33195 if(this.labellg > 0){
33196 label.cls += ' col-lg-' + this.labellg;
33197 items.cls += ' col-lg-' + (12 - this.labellg);
33200 if(this.labelmd > 0){
33201 label.cls += ' col-md-' + this.labelmd;
33202 items.cls += ' col-md-' + (12 - this.labelmd);
33205 if(this.labelsm > 0){
33206 label.cls += ' col-sm-' + this.labelsm;
33207 items.cls += ' col-sm-' + (12 - this.labelsm);
33210 if(this.labelxs > 0){
33211 label.cls += ' col-xs-' + this.labelxs;
33212 items.cls += ' col-xs-' + (12 - this.labelxs);
33218 cls : 'roo-radio-set',
33222 cls : 'roo-radio-set-input',
33225 value : this.value ? this.value : ''
33232 if(this.weight.length){
33233 cfg.cls += ' roo-radio-' + this.weight;
33237 cfg.cls += ' roo-radio-set-inline';
33244 initEvents : function()
33246 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
33247 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
33249 if(!this.fieldLabel.length){
33250 this.labelEl.hide();
33253 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
33254 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
33256 this.indicatorEl().setVisibilityMode(Roo.Element.DISPLAY);
33257 this.indicatorEl().hide();
33259 this.originalValue = this.getValue();
33263 inputEl: function ()
33265 return this.el.select('.roo-radio-set-input', true).first();
33268 getChildContainer : function()
33270 return this.itemsEl;
33273 register : function(item)
33275 this.radioes.push(item);
33279 validate : function()
33283 Roo.each(this.radioes, function(i){
33292 if(this.allowBlank) {
33296 if(this.disabled || valid){
33301 this.markInvalid();
33306 markValid : function()
33308 if(this.labelEl.isVisible(true)){
33309 this.indicatorEl().hide();
33312 this.el.removeClass([this.invalidClass, this.validClass]);
33313 this.el.addClass(this.validClass);
33315 this.fireEvent('valid', this);
33318 markInvalid : function(msg)
33320 if(this.allowBlank || this.disabled){
33324 if(this.labelEl.isVisible(true)){
33325 this.indicatorEl().show();
33328 this.el.removeClass([this.invalidClass, this.validClass]);
33329 this.el.addClass(this.invalidClass);
33331 this.fireEvent('invalid', this, msg);
33335 setValue : function(v, suppressEvent)
33339 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
33342 Roo.each(this.radioes, function(i){
33345 i.el.removeClass('checked');
33347 if(i.value === v || i.value.toString() === v.toString()){
33349 i.el.addClass('checked');
33351 if(suppressEvent !== true){
33352 this.fireEvent('check', this, i);
33361 clearInvalid : function(){
33363 if(!this.el || this.preventMark){
33367 this.el.removeClass([this.invalidClass]);
33369 this.fireEvent('valid', this);
33374 Roo.apply(Roo.bootstrap.RadioSet, {
33378 register : function(set)
33380 this.groups[set.name] = set;
33383 get: function(name)
33385 if (typeof(this.groups[name]) == 'undefined') {
33389 return this.groups[name] ;
33395 * Ext JS Library 1.1.1
33396 * Copyright(c) 2006-2007, Ext JS, LLC.
33398 * Originally Released Under LGPL - original licence link has changed is not relivant.
33401 * <script type="text/javascript">
33406 * @class Roo.bootstrap.SplitBar
33407 * @extends Roo.util.Observable
33408 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
33412 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
33413 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
33414 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
33415 split.minSize = 100;
33416 split.maxSize = 600;
33417 split.animate = true;
33418 split.on('moved', splitterMoved);
33421 * Create a new SplitBar
33422 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
33423 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
33424 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
33425 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
33426 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
33427 position of the SplitBar).
33429 Roo.bootstrap.SplitBar = function(cfg){
33434 // dragElement : elm
33435 // resizingElement: el,
33437 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
33438 // placement : Roo.bootstrap.SplitBar.LEFT ,
33439 // existingProxy ???
33442 this.el = Roo.get(cfg.dragElement, true);
33443 this.el.dom.unselectable = "on";
33445 this.resizingEl = Roo.get(cfg.resizingElement, true);
33449 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
33450 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
33453 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
33456 * The minimum size of the resizing element. (Defaults to 0)
33462 * The maximum size of the resizing element. (Defaults to 2000)
33465 this.maxSize = 2000;
33468 * Whether to animate the transition to the new size
33471 this.animate = false;
33474 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
33477 this.useShim = false;
33482 if(!cfg.existingProxy){
33484 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
33486 this.proxy = Roo.get(cfg.existingProxy).dom;
33489 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
33492 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
33495 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
33498 this.dragSpecs = {};
33501 * @private The adapter to use to positon and resize elements
33503 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
33504 this.adapter.init(this);
33506 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
33508 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
33509 this.el.addClass("roo-splitbar-h");
33512 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
33513 this.el.addClass("roo-splitbar-v");
33519 * Fires when the splitter is moved (alias for {@link #event-moved})
33520 * @param {Roo.bootstrap.SplitBar} this
33521 * @param {Number} newSize the new width or height
33526 * Fires when the splitter is moved
33527 * @param {Roo.bootstrap.SplitBar} this
33528 * @param {Number} newSize the new width or height
33532 * @event beforeresize
33533 * Fires before the splitter is dragged
33534 * @param {Roo.bootstrap.SplitBar} this
33536 "beforeresize" : true,
33538 "beforeapply" : true
33541 Roo.util.Observable.call(this);
33544 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
33545 onStartProxyDrag : function(x, y){
33546 this.fireEvent("beforeresize", this);
33548 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
33550 o.enableDisplayMode("block");
33551 // all splitbars share the same overlay
33552 Roo.bootstrap.SplitBar.prototype.overlay = o;
33554 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
33555 this.overlay.show();
33556 Roo.get(this.proxy).setDisplayed("block");
33557 var size = this.adapter.getElementSize(this);
33558 this.activeMinSize = this.getMinimumSize();;
33559 this.activeMaxSize = this.getMaximumSize();;
33560 var c1 = size - this.activeMinSize;
33561 var c2 = Math.max(this.activeMaxSize - size, 0);
33562 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
33563 this.dd.resetConstraints();
33564 this.dd.setXConstraint(
33565 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
33566 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
33568 this.dd.setYConstraint(0, 0);
33570 this.dd.resetConstraints();
33571 this.dd.setXConstraint(0, 0);
33572 this.dd.setYConstraint(
33573 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
33574 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
33577 this.dragSpecs.startSize = size;
33578 this.dragSpecs.startPoint = [x, y];
33579 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
33583 * @private Called after the drag operation by the DDProxy
33585 onEndProxyDrag : function(e){
33586 Roo.get(this.proxy).setDisplayed(false);
33587 var endPoint = Roo.lib.Event.getXY(e);
33589 this.overlay.hide();
33592 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
33593 newSize = this.dragSpecs.startSize +
33594 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
33595 endPoint[0] - this.dragSpecs.startPoint[0] :
33596 this.dragSpecs.startPoint[0] - endPoint[0]
33599 newSize = this.dragSpecs.startSize +
33600 (this.placement == Roo.bootstrap.SplitBar.TOP ?
33601 endPoint[1] - this.dragSpecs.startPoint[1] :
33602 this.dragSpecs.startPoint[1] - endPoint[1]
33605 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
33606 if(newSize != this.dragSpecs.startSize){
33607 if(this.fireEvent('beforeapply', this, newSize) !== false){
33608 this.adapter.setElementSize(this, newSize);
33609 this.fireEvent("moved", this, newSize);
33610 this.fireEvent("resize", this, newSize);
33616 * Get the adapter this SplitBar uses
33617 * @return The adapter object
33619 getAdapter : function(){
33620 return this.adapter;
33624 * Set the adapter this SplitBar uses
33625 * @param {Object} adapter A SplitBar adapter object
33627 setAdapter : function(adapter){
33628 this.adapter = adapter;
33629 this.adapter.init(this);
33633 * Gets the minimum size for the resizing element
33634 * @return {Number} The minimum size
33636 getMinimumSize : function(){
33637 return this.minSize;
33641 * Sets the minimum size for the resizing element
33642 * @param {Number} minSize The minimum size
33644 setMinimumSize : function(minSize){
33645 this.minSize = minSize;
33649 * Gets the maximum size for the resizing element
33650 * @return {Number} The maximum size
33652 getMaximumSize : function(){
33653 return this.maxSize;
33657 * Sets the maximum size for the resizing element
33658 * @param {Number} maxSize The maximum size
33660 setMaximumSize : function(maxSize){
33661 this.maxSize = maxSize;
33665 * Sets the initialize size for the resizing element
33666 * @param {Number} size The initial size
33668 setCurrentSize : function(size){
33669 var oldAnimate = this.animate;
33670 this.animate = false;
33671 this.adapter.setElementSize(this, size);
33672 this.animate = oldAnimate;
33676 * Destroy this splitbar.
33677 * @param {Boolean} removeEl True to remove the element
33679 destroy : function(removeEl){
33681 this.shim.remove();
33684 this.proxy.parentNode.removeChild(this.proxy);
33692 * @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.
33694 Roo.bootstrap.SplitBar.createProxy = function(dir){
33695 var proxy = new Roo.Element(document.createElement("div"));
33696 proxy.unselectable();
33697 var cls = 'roo-splitbar-proxy';
33698 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
33699 document.body.appendChild(proxy.dom);
33704 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
33705 * Default Adapter. It assumes the splitter and resizing element are not positioned
33706 * elements and only gets/sets the width of the element. Generally used for table based layouts.
33708 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
33711 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
33712 // do nothing for now
33713 init : function(s){
33717 * Called before drag operations to get the current size of the resizing element.
33718 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
33720 getElementSize : function(s){
33721 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
33722 return s.resizingEl.getWidth();
33724 return s.resizingEl.getHeight();
33729 * Called after drag operations to set the size of the resizing element.
33730 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
33731 * @param {Number} newSize The new size to set
33732 * @param {Function} onComplete A function to be invoked when resizing is complete
33734 setElementSize : function(s, newSize, onComplete){
33735 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
33737 s.resizingEl.setWidth(newSize);
33739 onComplete(s, newSize);
33742 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
33747 s.resizingEl.setHeight(newSize);
33749 onComplete(s, newSize);
33752 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
33759 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
33760 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
33761 * Adapter that moves the splitter element to align with the resized sizing element.
33762 * Used with an absolute positioned SplitBar.
33763 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
33764 * document.body, make sure you assign an id to the body element.
33766 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
33767 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
33768 this.container = Roo.get(container);
33771 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
33772 init : function(s){
33773 this.basic.init(s);
33776 getElementSize : function(s){
33777 return this.basic.getElementSize(s);
33780 setElementSize : function(s, newSize, onComplete){
33781 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
33784 moveSplitter : function(s){
33785 var yes = Roo.bootstrap.SplitBar;
33786 switch(s.placement){
33788 s.el.setX(s.resizingEl.getRight());
33791 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
33794 s.el.setY(s.resizingEl.getBottom());
33797 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
33804 * Orientation constant - Create a vertical SplitBar
33808 Roo.bootstrap.SplitBar.VERTICAL = 1;
33811 * Orientation constant - Create a horizontal SplitBar
33815 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
33818 * Placement constant - The resizing element is to the left of the splitter element
33822 Roo.bootstrap.SplitBar.LEFT = 1;
33825 * Placement constant - The resizing element is to the right of the splitter element
33829 Roo.bootstrap.SplitBar.RIGHT = 2;
33832 * Placement constant - The resizing element is positioned above the splitter element
33836 Roo.bootstrap.SplitBar.TOP = 3;
33839 * Placement constant - The resizing element is positioned under splitter element
33843 Roo.bootstrap.SplitBar.BOTTOM = 4;
33844 Roo.namespace("Roo.bootstrap.layout");/*
33846 * Ext JS Library 1.1.1
33847 * Copyright(c) 2006-2007, Ext JS, LLC.
33849 * Originally Released Under LGPL - original licence link has changed is not relivant.
33852 * <script type="text/javascript">
33856 * @class Roo.bootstrap.layout.Manager
33857 * @extends Roo.bootstrap.Component
33858 * Base class for layout managers.
33860 Roo.bootstrap.layout.Manager = function(config)
33862 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
33868 /** false to disable window resize monitoring @type Boolean */
33869 this.monitorWindowResize = true;
33874 * Fires when a layout is performed.
33875 * @param {Roo.LayoutManager} this
33879 * @event regionresized
33880 * Fires when the user resizes a region.
33881 * @param {Roo.LayoutRegion} region The resized region
33882 * @param {Number} newSize The new size (width for east/west, height for north/south)
33884 "regionresized" : true,
33886 * @event regioncollapsed
33887 * Fires when a region is collapsed.
33888 * @param {Roo.LayoutRegion} region The collapsed region
33890 "regioncollapsed" : true,
33892 * @event regionexpanded
33893 * Fires when a region is expanded.
33894 * @param {Roo.LayoutRegion} region The expanded region
33896 "regionexpanded" : true
33898 this.updating = false;
33901 this.el = Roo.get(config.el);
33907 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
33912 monitorWindowResize : true,
33918 onRender : function(ct, position)
33921 this.el = Roo.get(ct);
33924 //this.fireEvent('render',this);
33928 initEvents: function()
33932 // ie scrollbar fix
33933 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
33934 document.body.scroll = "no";
33935 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
33936 this.el.position('relative');
33938 this.id = this.el.id;
33939 this.el.addClass("roo-layout-container");
33940 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
33941 if(this.el.dom != document.body ) {
33942 this.el.on('resize', this.layout,this);
33943 this.el.on('show', this.layout,this);
33949 * Returns true if this layout is currently being updated
33950 * @return {Boolean}
33952 isUpdating : function(){
33953 return this.updating;
33957 * Suspend the LayoutManager from doing auto-layouts while
33958 * making multiple add or remove calls
33960 beginUpdate : function(){
33961 this.updating = true;
33965 * Restore auto-layouts and optionally disable the manager from performing a layout
33966 * @param {Boolean} noLayout true to disable a layout update
33968 endUpdate : function(noLayout){
33969 this.updating = false;
33975 layout: function(){
33979 onRegionResized : function(region, newSize){
33980 this.fireEvent("regionresized", region, newSize);
33984 onRegionCollapsed : function(region){
33985 this.fireEvent("regioncollapsed", region);
33988 onRegionExpanded : function(region){
33989 this.fireEvent("regionexpanded", region);
33993 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
33994 * performs box-model adjustments.
33995 * @return {Object} The size as an object {width: (the width), height: (the height)}
33997 getViewSize : function()
34000 if(this.el.dom != document.body){
34001 size = this.el.getSize();
34003 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
34005 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
34006 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
34011 * Returns the Element this layout is bound to.
34012 * @return {Roo.Element}
34014 getEl : function(){
34019 * Returns the specified region.
34020 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
34021 * @return {Roo.LayoutRegion}
34023 getRegion : function(target){
34024 return this.regions[target.toLowerCase()];
34027 onWindowResize : function(){
34028 if(this.monitorWindowResize){
34035 * Ext JS Library 1.1.1
34036 * Copyright(c) 2006-2007, Ext JS, LLC.
34038 * Originally Released Under LGPL - original licence link has changed is not relivant.
34041 * <script type="text/javascript">
34044 * @class Roo.bootstrap.layout.Border
34045 * @extends Roo.bootstrap.layout.Manager
34046 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
34047 * please see: examples/bootstrap/nested.html<br><br>
34049 <b>The container the layout is rendered into can be either the body element or any other element.
34050 If it is not the body element, the container needs to either be an absolute positioned element,
34051 or you will need to add "position:relative" to the css of the container. You will also need to specify
34052 the container size if it is not the body element.</b>
34055 * Create a new Border
34056 * @param {Object} config Configuration options
34058 Roo.bootstrap.layout.Border = function(config){
34059 config = config || {};
34060 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
34064 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34065 if(config[region]){
34066 config[region].region = region;
34067 this.addRegion(config[region]);
34073 Roo.bootstrap.layout.Border.regions = ["north","south","east","west","center"];
34075 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
34077 * Creates and adds a new region if it doesn't already exist.
34078 * @param {String} target The target region key (north, south, east, west or center).
34079 * @param {Object} config The regions config object
34080 * @return {BorderLayoutRegion} The new region
34082 addRegion : function(config)
34084 if(!this.regions[config.region]){
34085 var r = this.factory(config);
34086 this.bindRegion(r);
34088 return this.regions[config.region];
34092 bindRegion : function(r){
34093 this.regions[r.config.region] = r;
34095 r.on("visibilitychange", this.layout, this);
34096 r.on("paneladded", this.layout, this);
34097 r.on("panelremoved", this.layout, this);
34098 r.on("invalidated", this.layout, this);
34099 r.on("resized", this.onRegionResized, this);
34100 r.on("collapsed", this.onRegionCollapsed, this);
34101 r.on("expanded", this.onRegionExpanded, this);
34105 * Performs a layout update.
34107 layout : function()
34109 if(this.updating) {
34113 // render all the rebions if they have not been done alreayd?
34114 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34115 if(this.regions[region] && !this.regions[region].bodyEl){
34116 this.regions[region].onRender(this.el)
34120 var size = this.getViewSize();
34121 var w = size.width;
34122 var h = size.height;
34127 //var x = 0, y = 0;
34129 var rs = this.regions;
34130 var north = rs["north"];
34131 var south = rs["south"];
34132 var west = rs["west"];
34133 var east = rs["east"];
34134 var center = rs["center"];
34135 //if(this.hideOnLayout){ // not supported anymore
34136 //c.el.setStyle("display", "none");
34138 if(north && north.isVisible()){
34139 var b = north.getBox();
34140 var m = north.getMargins();
34141 b.width = w - (m.left+m.right);
34144 centerY = b.height + b.y + m.bottom;
34145 centerH -= centerY;
34146 north.updateBox(this.safeBox(b));
34148 if(south && south.isVisible()){
34149 var b = south.getBox();
34150 var m = south.getMargins();
34151 b.width = w - (m.left+m.right);
34153 var totalHeight = (b.height + m.top + m.bottom);
34154 b.y = h - totalHeight + m.top;
34155 centerH -= totalHeight;
34156 south.updateBox(this.safeBox(b));
34158 if(west && west.isVisible()){
34159 var b = west.getBox();
34160 var m = west.getMargins();
34161 b.height = centerH - (m.top+m.bottom);
34163 b.y = centerY + m.top;
34164 var totalWidth = (b.width + m.left + m.right);
34165 centerX += totalWidth;
34166 centerW -= totalWidth;
34167 west.updateBox(this.safeBox(b));
34169 if(east && east.isVisible()){
34170 var b = east.getBox();
34171 var m = east.getMargins();
34172 b.height = centerH - (m.top+m.bottom);
34173 var totalWidth = (b.width + m.left + m.right);
34174 b.x = w - totalWidth + m.left;
34175 b.y = centerY + m.top;
34176 centerW -= totalWidth;
34177 east.updateBox(this.safeBox(b));
34180 var m = center.getMargins();
34182 x: centerX + m.left,
34183 y: centerY + m.top,
34184 width: centerW - (m.left+m.right),
34185 height: centerH - (m.top+m.bottom)
34187 //if(this.hideOnLayout){
34188 //center.el.setStyle("display", "block");
34190 center.updateBox(this.safeBox(centerBox));
34193 this.fireEvent("layout", this);
34197 safeBox : function(box){
34198 box.width = Math.max(0, box.width);
34199 box.height = Math.max(0, box.height);
34204 * Adds a ContentPanel (or subclass) to this layout.
34205 * @param {String} target The target region key (north, south, east, west or center).
34206 * @param {Roo.ContentPanel} panel The panel to add
34207 * @return {Roo.ContentPanel} The added panel
34209 add : function(target, panel){
34211 target = target.toLowerCase();
34212 return this.regions[target].add(panel);
34216 * Remove a ContentPanel (or subclass) to this layout.
34217 * @param {String} target The target region key (north, south, east, west or center).
34218 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
34219 * @return {Roo.ContentPanel} The removed panel
34221 remove : function(target, panel){
34222 target = target.toLowerCase();
34223 return this.regions[target].remove(panel);
34227 * Searches all regions for a panel with the specified id
34228 * @param {String} panelId
34229 * @return {Roo.ContentPanel} The panel or null if it wasn't found
34231 findPanel : function(panelId){
34232 var rs = this.regions;
34233 for(var target in rs){
34234 if(typeof rs[target] != "function"){
34235 var p = rs[target].getPanel(panelId);
34245 * Searches all regions for a panel with the specified id and activates (shows) it.
34246 * @param {String/ContentPanel} panelId The panels id or the panel itself
34247 * @return {Roo.ContentPanel} The shown panel or null
34249 showPanel : function(panelId) {
34250 var rs = this.regions;
34251 for(var target in rs){
34252 var r = rs[target];
34253 if(typeof r != "function"){
34254 if(r.hasPanel(panelId)){
34255 return r.showPanel(panelId);
34263 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
34264 * @param {Roo.state.Provider} provider (optional) An alternate state provider
34267 restoreState : function(provider){
34269 provider = Roo.state.Manager;
34271 var sm = new Roo.LayoutStateManager();
34272 sm.init(this, provider);
34278 * Adds a xtype elements to the layout.
34282 xtype : 'ContentPanel',
34289 xtype : 'NestedLayoutPanel',
34295 items : [ ... list of content panels or nested layout panels.. ]
34299 * @param {Object} cfg Xtype definition of item to add.
34301 addxtype : function(cfg)
34303 // basically accepts a pannel...
34304 // can accept a layout region..!?!?
34305 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
34308 // theory? children can only be panels??
34310 //if (!cfg.xtype.match(/Panel$/)) {
34315 if (typeof(cfg.region) == 'undefined') {
34316 Roo.log("Failed to add Panel, region was not set");
34320 var region = cfg.region;
34326 xitems = cfg.items;
34333 case 'Content': // ContentPanel (el, cfg)
34334 case 'Scroll': // ContentPanel (el, cfg)
34336 cfg.autoCreate = true;
34337 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34339 // var el = this.el.createChild();
34340 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
34343 this.add(region, ret);
34347 case 'TreePanel': // our new panel!
34348 cfg.el = this.el.createChild();
34349 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
34350 this.add(region, ret);
34355 // create a new Layout (which is a Border Layout...
34357 var clayout = cfg.layout;
34358 clayout.el = this.el.createChild();
34359 clayout.items = clayout.items || [];
34363 // replace this exitems with the clayout ones..
34364 xitems = clayout.items;
34366 // force background off if it's in center...
34367 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
34368 cfg.background = false;
34370 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
34373 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34374 //console.log('adding nested layout panel ' + cfg.toSource());
34375 this.add(region, ret);
34376 nb = {}; /// find first...
34381 // needs grid and region
34383 //var el = this.getRegion(region).el.createChild();
34385 *var el = this.el.createChild();
34386 // create the grid first...
34387 cfg.grid.container = el;
34388 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
34391 if (region == 'center' && this.active ) {
34392 cfg.background = false;
34395 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34397 this.add(region, ret);
34399 if (cfg.background) {
34400 // render grid on panel activation (if panel background)
34401 ret.on('activate', function(gp) {
34402 if (!gp.grid.rendered) {
34403 // gp.grid.render(el);
34407 // cfg.grid.render(el);
34413 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
34414 // it was the old xcomponent building that caused this before.
34415 // espeically if border is the top element in the tree.
34425 if (typeof(Roo[cfg.xtype]) != 'undefined') {
34427 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
34428 this.add(region, ret);
34432 throw "Can not add '" + cfg.xtype + "' to Border";
34438 this.beginUpdate();
34442 Roo.each(xitems, function(i) {
34443 region = nb && i.region ? i.region : false;
34445 var add = ret.addxtype(i);
34448 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
34449 if (!i.background) {
34450 abn[region] = nb[region] ;
34457 // make the last non-background panel active..
34458 //if (nb) { Roo.log(abn); }
34461 for(var r in abn) {
34462 region = this.getRegion(r);
34464 // tried using nb[r], but it does not work..
34466 region.showPanel(abn[r]);
34477 factory : function(cfg)
34480 var validRegions = Roo.bootstrap.layout.Border.regions;
34482 var target = cfg.region;
34485 var r = Roo.bootstrap.layout;
34489 return new r.North(cfg);
34491 return new r.South(cfg);
34493 return new r.East(cfg);
34495 return new r.West(cfg);
34497 return new r.Center(cfg);
34499 throw 'Layout region "'+target+'" not supported.';
34506 * Ext JS Library 1.1.1
34507 * Copyright(c) 2006-2007, Ext JS, LLC.
34509 * Originally Released Under LGPL - original licence link has changed is not relivant.
34512 * <script type="text/javascript">
34516 * @class Roo.bootstrap.layout.Basic
34517 * @extends Roo.util.Observable
34518 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
34519 * and does not have a titlebar, tabs or any other features. All it does is size and position
34520 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
34521 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
34522 * @cfg {string} region the region that it inhabits..
34523 * @cfg {bool} skipConfig skip config?
34527 Roo.bootstrap.layout.Basic = function(config){
34529 this.mgr = config.mgr;
34531 this.position = config.region;
34533 var skipConfig = config.skipConfig;
34537 * @scope Roo.BasicLayoutRegion
34541 * @event beforeremove
34542 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
34543 * @param {Roo.LayoutRegion} this
34544 * @param {Roo.ContentPanel} panel The panel
34545 * @param {Object} e The cancel event object
34547 "beforeremove" : true,
34549 * @event invalidated
34550 * Fires when the layout for this region is changed.
34551 * @param {Roo.LayoutRegion} this
34553 "invalidated" : true,
34555 * @event visibilitychange
34556 * Fires when this region is shown or hidden
34557 * @param {Roo.LayoutRegion} this
34558 * @param {Boolean} visibility true or false
34560 "visibilitychange" : true,
34562 * @event paneladded
34563 * Fires when a panel is added.
34564 * @param {Roo.LayoutRegion} this
34565 * @param {Roo.ContentPanel} panel The panel
34567 "paneladded" : true,
34569 * @event panelremoved
34570 * Fires when a panel is removed.
34571 * @param {Roo.LayoutRegion} this
34572 * @param {Roo.ContentPanel} panel The panel
34574 "panelremoved" : true,
34576 * @event beforecollapse
34577 * Fires when this region before collapse.
34578 * @param {Roo.LayoutRegion} this
34580 "beforecollapse" : true,
34583 * Fires when this region is collapsed.
34584 * @param {Roo.LayoutRegion} this
34586 "collapsed" : true,
34589 * Fires when this region is expanded.
34590 * @param {Roo.LayoutRegion} this
34595 * Fires when this region is slid into view.
34596 * @param {Roo.LayoutRegion} this
34598 "slideshow" : true,
34601 * Fires when this region slides out of view.
34602 * @param {Roo.LayoutRegion} this
34604 "slidehide" : true,
34606 * @event panelactivated
34607 * Fires when a panel is activated.
34608 * @param {Roo.LayoutRegion} this
34609 * @param {Roo.ContentPanel} panel The activated panel
34611 "panelactivated" : true,
34614 * Fires when the user resizes this region.
34615 * @param {Roo.LayoutRegion} this
34616 * @param {Number} newSize The new size (width for east/west, height for north/south)
34620 /** A collection of panels in this region. @type Roo.util.MixedCollection */
34621 this.panels = new Roo.util.MixedCollection();
34622 this.panels.getKey = this.getPanelId.createDelegate(this);
34624 this.activePanel = null;
34625 // ensure listeners are added...
34627 if (config.listeners || config.events) {
34628 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
34629 listeners : config.listeners || {},
34630 events : config.events || {}
34634 if(skipConfig !== true){
34635 this.applyConfig(config);
34639 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
34641 getPanelId : function(p){
34645 applyConfig : function(config){
34646 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
34647 this.config = config;
34652 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
34653 * the width, for horizontal (north, south) the height.
34654 * @param {Number} newSize The new width or height
34656 resizeTo : function(newSize){
34657 var el = this.el ? this.el :
34658 (this.activePanel ? this.activePanel.getEl() : null);
34660 switch(this.position){
34663 el.setWidth(newSize);
34664 this.fireEvent("resized", this, newSize);
34668 el.setHeight(newSize);
34669 this.fireEvent("resized", this, newSize);
34675 getBox : function(){
34676 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
34679 getMargins : function(){
34680 return this.margins;
34683 updateBox : function(box){
34685 var el = this.activePanel.getEl();
34686 el.dom.style.left = box.x + "px";
34687 el.dom.style.top = box.y + "px";
34688 this.activePanel.setSize(box.width, box.height);
34692 * Returns the container element for this region.
34693 * @return {Roo.Element}
34695 getEl : function(){
34696 return this.activePanel;
34700 * Returns true if this region is currently visible.
34701 * @return {Boolean}
34703 isVisible : function(){
34704 return this.activePanel ? true : false;
34707 setActivePanel : function(panel){
34708 panel = this.getPanel(panel);
34709 if(this.activePanel && this.activePanel != panel){
34710 this.activePanel.setActiveState(false);
34711 this.activePanel.getEl().setLeftTop(-10000,-10000);
34713 this.activePanel = panel;
34714 panel.setActiveState(true);
34716 panel.setSize(this.box.width, this.box.height);
34718 this.fireEvent("panelactivated", this, panel);
34719 this.fireEvent("invalidated");
34723 * Show the specified panel.
34724 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
34725 * @return {Roo.ContentPanel} The shown panel or null
34727 showPanel : function(panel){
34728 panel = this.getPanel(panel);
34730 this.setActivePanel(panel);
34736 * Get the active panel for this region.
34737 * @return {Roo.ContentPanel} The active panel or null
34739 getActivePanel : function(){
34740 return this.activePanel;
34744 * Add the passed ContentPanel(s)
34745 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
34746 * @return {Roo.ContentPanel} The panel added (if only one was added)
34748 add : function(panel){
34749 if(arguments.length > 1){
34750 for(var i = 0, len = arguments.length; i < len; i++) {
34751 this.add(arguments[i]);
34755 if(this.hasPanel(panel)){
34756 this.showPanel(panel);
34759 var el = panel.getEl();
34760 if(el.dom.parentNode != this.mgr.el.dom){
34761 this.mgr.el.dom.appendChild(el.dom);
34763 if(panel.setRegion){
34764 panel.setRegion(this);
34766 this.panels.add(panel);
34767 el.setStyle("position", "absolute");
34768 if(!panel.background){
34769 this.setActivePanel(panel);
34770 if(this.config.initialSize && this.panels.getCount()==1){
34771 this.resizeTo(this.config.initialSize);
34774 this.fireEvent("paneladded", this, panel);
34779 * Returns true if the panel is in this region.
34780 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
34781 * @return {Boolean}
34783 hasPanel : function(panel){
34784 if(typeof panel == "object"){ // must be panel obj
34785 panel = panel.getId();
34787 return this.getPanel(panel) ? true : false;
34791 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
34792 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
34793 * @param {Boolean} preservePanel Overrides the config preservePanel option
34794 * @return {Roo.ContentPanel} The panel that was removed
34796 remove : function(panel, preservePanel){
34797 panel = this.getPanel(panel);
34802 this.fireEvent("beforeremove", this, panel, e);
34803 if(e.cancel === true){
34806 var panelId = panel.getId();
34807 this.panels.removeKey(panelId);
34812 * Returns the panel specified or null if it's not in this region.
34813 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
34814 * @return {Roo.ContentPanel}
34816 getPanel : function(id){
34817 if(typeof id == "object"){ // must be panel obj
34820 return this.panels.get(id);
34824 * Returns this regions position (north/south/east/west/center).
34827 getPosition: function(){
34828 return this.position;
34832 * Ext JS Library 1.1.1
34833 * Copyright(c) 2006-2007, Ext JS, LLC.
34835 * Originally Released Under LGPL - original licence link has changed is not relivant.
34838 * <script type="text/javascript">
34842 * @class Roo.bootstrap.layout.Region
34843 * @extends Roo.bootstrap.layout.Basic
34844 * This class represents a region in a layout manager.
34846 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
34847 * @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})
34848 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
34849 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
34850 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
34851 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
34852 * @cfg {String} title The title for the region (overrides panel titles)
34853 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
34854 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
34855 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
34856 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
34857 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
34858 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
34859 * the space available, similar to FireFox 1.5 tabs (defaults to false)
34860 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
34861 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
34862 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
34864 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
34865 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
34866 * @cfg {Boolean} disableTabTips True to disable tab tooltips
34867 * @cfg {Number} width For East/West panels
34868 * @cfg {Number} height For North/South panels
34869 * @cfg {Boolean} split To show the splitter
34870 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
34872 * @cfg {string} cls Extra CSS classes to add to region
34874 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
34875 * @cfg {string} region the region that it inhabits..
34878 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
34879 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
34881 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
34882 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
34883 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
34885 Roo.bootstrap.layout.Region = function(config)
34887 this.applyConfig(config);
34889 var mgr = config.mgr;
34890 var pos = config.region;
34891 config.skipConfig = true;
34892 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
34895 this.onRender(mgr.el);
34898 this.visible = true;
34899 this.collapsed = false;
34900 this.unrendered_panels = [];
34903 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
34905 position: '', // set by wrapper (eg. north/south etc..)
34906 unrendered_panels : null, // unrendered panels.
34907 createBody : function(){
34908 /** This region's body element
34909 * @type Roo.Element */
34910 this.bodyEl = this.el.createChild({
34912 cls: "roo-layout-panel-body tab-content" // bootstrap added...
34916 onRender: function(ctr, pos)
34918 var dh = Roo.DomHelper;
34919 /** This region's container element
34920 * @type Roo.Element */
34921 this.el = dh.append(ctr.dom, {
34923 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
34925 /** This region's title element
34926 * @type Roo.Element */
34928 this.titleEl = dh.append(this.el.dom,
34931 unselectable: "on",
34932 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
34934 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
34935 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
34938 this.titleEl.enableDisplayMode();
34939 /** This region's title text element
34940 * @type HTMLElement */
34941 this.titleTextEl = this.titleEl.dom.firstChild;
34942 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
34944 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
34945 this.closeBtn.enableDisplayMode();
34946 this.closeBtn.on("click", this.closeClicked, this);
34947 this.closeBtn.hide();
34949 this.createBody(this.config);
34950 if(this.config.hideWhenEmpty){
34952 this.on("paneladded", this.validateVisibility, this);
34953 this.on("panelremoved", this.validateVisibility, this);
34955 if(this.autoScroll){
34956 this.bodyEl.setStyle("overflow", "auto");
34958 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
34960 //if(c.titlebar !== false){
34961 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
34962 this.titleEl.hide();
34964 this.titleEl.show();
34965 if(this.config.title){
34966 this.titleTextEl.innerHTML = this.config.title;
34970 if(this.config.collapsed){
34971 this.collapse(true);
34973 if(this.config.hidden){
34977 if (this.unrendered_panels && this.unrendered_panels.length) {
34978 for (var i =0;i< this.unrendered_panels.length; i++) {
34979 this.add(this.unrendered_panels[i]);
34981 this.unrendered_panels = null;
34987 applyConfig : function(c)
34990 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
34991 var dh = Roo.DomHelper;
34992 if(c.titlebar !== false){
34993 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
34994 this.collapseBtn.on("click", this.collapse, this);
34995 this.collapseBtn.enableDisplayMode();
34997 if(c.showPin === true || this.showPin){
34998 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
34999 this.stickBtn.enableDisplayMode();
35000 this.stickBtn.on("click", this.expand, this);
35001 this.stickBtn.hide();
35006 /** This region's collapsed element
35007 * @type Roo.Element */
35010 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
35011 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
35014 if(c.floatable !== false){
35015 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
35016 this.collapsedEl.on("click", this.collapseClick, this);
35019 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
35020 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
35021 id: "message", unselectable: "on", style:{"float":"left"}});
35022 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
35024 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
35025 this.expandBtn.on("click", this.expand, this);
35029 if(this.collapseBtn){
35030 this.collapseBtn.setVisible(c.collapsible == true);
35033 this.cmargins = c.cmargins || this.cmargins ||
35034 (this.position == "west" || this.position == "east" ?
35035 {top: 0, left: 2, right:2, bottom: 0} :
35036 {top: 2, left: 0, right:0, bottom: 2});
35038 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35041 this.bottomTabs = c.tabPosition != "top";
35043 this.autoScroll = c.autoScroll || false;
35048 this.duration = c.duration || .30;
35049 this.slideDuration = c.slideDuration || .45;
35054 * Returns true if this region is currently visible.
35055 * @return {Boolean}
35057 isVisible : function(){
35058 return this.visible;
35062 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
35063 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
35065 //setCollapsedTitle : function(title){
35066 // title = title || " ";
35067 // if(this.collapsedTitleTextEl){
35068 // this.collapsedTitleTextEl.innerHTML = title;
35072 getBox : function(){
35074 // if(!this.collapsed){
35075 b = this.el.getBox(false, true);
35077 // b = this.collapsedEl.getBox(false, true);
35082 getMargins : function(){
35083 return this.margins;
35084 //return this.collapsed ? this.cmargins : this.margins;
35087 highlight : function(){
35088 this.el.addClass("x-layout-panel-dragover");
35091 unhighlight : function(){
35092 this.el.removeClass("x-layout-panel-dragover");
35095 updateBox : function(box)
35097 if (!this.bodyEl) {
35098 return; // not rendered yet..
35102 if(!this.collapsed){
35103 this.el.dom.style.left = box.x + "px";
35104 this.el.dom.style.top = box.y + "px";
35105 this.updateBody(box.width, box.height);
35107 this.collapsedEl.dom.style.left = box.x + "px";
35108 this.collapsedEl.dom.style.top = box.y + "px";
35109 this.collapsedEl.setSize(box.width, box.height);
35112 this.tabs.autoSizeTabs();
35116 updateBody : function(w, h)
35119 this.el.setWidth(w);
35120 w -= this.el.getBorderWidth("rl");
35121 if(this.config.adjustments){
35122 w += this.config.adjustments[0];
35125 if(h !== null && h > 0){
35126 this.el.setHeight(h);
35127 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
35128 h -= this.el.getBorderWidth("tb");
35129 if(this.config.adjustments){
35130 h += this.config.adjustments[1];
35132 this.bodyEl.setHeight(h);
35134 h = this.tabs.syncHeight(h);
35137 if(this.panelSize){
35138 w = w !== null ? w : this.panelSize.width;
35139 h = h !== null ? h : this.panelSize.height;
35141 if(this.activePanel){
35142 var el = this.activePanel.getEl();
35143 w = w !== null ? w : el.getWidth();
35144 h = h !== null ? h : el.getHeight();
35145 this.panelSize = {width: w, height: h};
35146 this.activePanel.setSize(w, h);
35148 if(Roo.isIE && this.tabs){
35149 this.tabs.el.repaint();
35154 * Returns the container element for this region.
35155 * @return {Roo.Element}
35157 getEl : function(){
35162 * Hides this region.
35165 //if(!this.collapsed){
35166 this.el.dom.style.left = "-2000px";
35169 // this.collapsedEl.dom.style.left = "-2000px";
35170 // this.collapsedEl.hide();
35172 this.visible = false;
35173 this.fireEvent("visibilitychange", this, false);
35177 * Shows this region if it was previously hidden.
35180 //if(!this.collapsed){
35183 // this.collapsedEl.show();
35185 this.visible = true;
35186 this.fireEvent("visibilitychange", this, true);
35189 closeClicked : function(){
35190 if(this.activePanel){
35191 this.remove(this.activePanel);
35195 collapseClick : function(e){
35197 e.stopPropagation();
35200 e.stopPropagation();
35206 * Collapses this region.
35207 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
35210 collapse : function(skipAnim, skipCheck = false){
35211 if(this.collapsed) {
35215 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
35217 this.collapsed = true;
35219 this.split.el.hide();
35221 if(this.config.animate && skipAnim !== true){
35222 this.fireEvent("invalidated", this);
35223 this.animateCollapse();
35225 this.el.setLocation(-20000,-20000);
35227 this.collapsedEl.show();
35228 this.fireEvent("collapsed", this);
35229 this.fireEvent("invalidated", this);
35235 animateCollapse : function(){
35240 * Expands this region if it was previously collapsed.
35241 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
35242 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
35245 expand : function(e, skipAnim){
35247 e.stopPropagation();
35249 if(!this.collapsed || this.el.hasActiveFx()) {
35253 this.afterSlideIn();
35256 this.collapsed = false;
35257 if(this.config.animate && skipAnim !== true){
35258 this.animateExpand();
35262 this.split.el.show();
35264 this.collapsedEl.setLocation(-2000,-2000);
35265 this.collapsedEl.hide();
35266 this.fireEvent("invalidated", this);
35267 this.fireEvent("expanded", this);
35271 animateExpand : function(){
35275 initTabs : function()
35277 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
35279 var ts = new Roo.bootstrap.panel.Tabs({
35280 el: this.bodyEl.dom,
35281 tabPosition: this.bottomTabs ? 'bottom' : 'top',
35282 disableTooltips: this.config.disableTabTips,
35283 toolbar : this.config.toolbar
35286 if(this.config.hideTabs){
35287 ts.stripWrap.setDisplayed(false);
35290 ts.resizeTabs = this.config.resizeTabs === true;
35291 ts.minTabWidth = this.config.minTabWidth || 40;
35292 ts.maxTabWidth = this.config.maxTabWidth || 250;
35293 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
35294 ts.monitorResize = false;
35295 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
35296 ts.bodyEl.addClass('roo-layout-tabs-body');
35297 this.panels.each(this.initPanelAsTab, this);
35300 initPanelAsTab : function(panel){
35301 var ti = this.tabs.addTab(
35305 this.config.closeOnTab && panel.isClosable(),
35308 if(panel.tabTip !== undefined){
35309 ti.setTooltip(panel.tabTip);
35311 ti.on("activate", function(){
35312 this.setActivePanel(panel);
35315 if(this.config.closeOnTab){
35316 ti.on("beforeclose", function(t, e){
35318 this.remove(panel);
35322 panel.tabItem = ti;
35327 updatePanelTitle : function(panel, title)
35329 if(this.activePanel == panel){
35330 this.updateTitle(title);
35333 var ti = this.tabs.getTab(panel.getEl().id);
35335 if(panel.tabTip !== undefined){
35336 ti.setTooltip(panel.tabTip);
35341 updateTitle : function(title){
35342 if(this.titleTextEl && !this.config.title){
35343 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
35347 setActivePanel : function(panel)
35349 panel = this.getPanel(panel);
35350 if(this.activePanel && this.activePanel != panel){
35351 this.activePanel.setActiveState(false);
35353 this.activePanel = panel;
35354 panel.setActiveState(true);
35355 if(this.panelSize){
35356 panel.setSize(this.panelSize.width, this.panelSize.height);
35359 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
35361 this.updateTitle(panel.getTitle());
35363 this.fireEvent("invalidated", this);
35365 this.fireEvent("panelactivated", this, panel);
35369 * Shows the specified panel.
35370 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
35371 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
35373 showPanel : function(panel)
35375 panel = this.getPanel(panel);
35378 var tab = this.tabs.getTab(panel.getEl().id);
35379 if(tab.isHidden()){
35380 this.tabs.unhideTab(tab.id);
35384 this.setActivePanel(panel);
35391 * Get the active panel for this region.
35392 * @return {Roo.ContentPanel} The active panel or null
35394 getActivePanel : function(){
35395 return this.activePanel;
35398 validateVisibility : function(){
35399 if(this.panels.getCount() < 1){
35400 this.updateTitle(" ");
35401 this.closeBtn.hide();
35404 if(!this.isVisible()){
35411 * Adds the passed ContentPanel(s) to this region.
35412 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
35413 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
35415 add : function(panel)
35417 if(arguments.length > 1){
35418 for(var i = 0, len = arguments.length; i < len; i++) {
35419 this.add(arguments[i]);
35424 // if we have not been rendered yet, then we can not really do much of this..
35425 if (!this.bodyEl) {
35426 this.unrendered_panels.push(panel);
35433 if(this.hasPanel(panel)){
35434 this.showPanel(panel);
35437 panel.setRegion(this);
35438 this.panels.add(panel);
35439 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
35440 // sinle panel - no tab...?? would it not be better to render it with the tabs,
35441 // and hide them... ???
35442 this.bodyEl.dom.appendChild(panel.getEl().dom);
35443 if(panel.background !== true){
35444 this.setActivePanel(panel);
35446 this.fireEvent("paneladded", this, panel);
35453 this.initPanelAsTab(panel);
35457 if(panel.background !== true){
35458 this.tabs.activate(panel.getEl().id);
35460 this.fireEvent("paneladded", this, panel);
35465 * Hides the tab for the specified panel.
35466 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
35468 hidePanel : function(panel){
35469 if(this.tabs && (panel = this.getPanel(panel))){
35470 this.tabs.hideTab(panel.getEl().id);
35475 * Unhides the tab for a previously hidden panel.
35476 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
35478 unhidePanel : function(panel){
35479 if(this.tabs && (panel = this.getPanel(panel))){
35480 this.tabs.unhideTab(panel.getEl().id);
35484 clearPanels : function(){
35485 while(this.panels.getCount() > 0){
35486 this.remove(this.panels.first());
35491 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
35492 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
35493 * @param {Boolean} preservePanel Overrides the config preservePanel option
35494 * @return {Roo.ContentPanel} The panel that was removed
35496 remove : function(panel, preservePanel)
35498 panel = this.getPanel(panel);
35503 this.fireEvent("beforeremove", this, panel, e);
35504 if(e.cancel === true){
35507 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
35508 var panelId = panel.getId();
35509 this.panels.removeKey(panelId);
35511 document.body.appendChild(panel.getEl().dom);
35514 this.tabs.removeTab(panel.getEl().id);
35515 }else if (!preservePanel){
35516 this.bodyEl.dom.removeChild(panel.getEl().dom);
35518 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
35519 var p = this.panels.first();
35520 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
35521 tempEl.appendChild(p.getEl().dom);
35522 this.bodyEl.update("");
35523 this.bodyEl.dom.appendChild(p.getEl().dom);
35525 this.updateTitle(p.getTitle());
35527 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
35528 this.setActivePanel(p);
35530 panel.setRegion(null);
35531 if(this.activePanel == panel){
35532 this.activePanel = null;
35534 if(this.config.autoDestroy !== false && preservePanel !== true){
35535 try{panel.destroy();}catch(e){}
35537 this.fireEvent("panelremoved", this, panel);
35542 * Returns the TabPanel component used by this region
35543 * @return {Roo.TabPanel}
35545 getTabs : function(){
35549 createTool : function(parentEl, className){
35550 var btn = Roo.DomHelper.append(parentEl, {
35552 cls: "x-layout-tools-button",
35555 cls: "roo-layout-tools-button-inner " + className,
35559 btn.addClassOnOver("roo-layout-tools-button-over");
35564 * Ext JS Library 1.1.1
35565 * Copyright(c) 2006-2007, Ext JS, LLC.
35567 * Originally Released Under LGPL - original licence link has changed is not relivant.
35570 * <script type="text/javascript">
35576 * @class Roo.SplitLayoutRegion
35577 * @extends Roo.LayoutRegion
35578 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
35580 Roo.bootstrap.layout.Split = function(config){
35581 this.cursor = config.cursor;
35582 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
35585 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
35587 splitTip : "Drag to resize.",
35588 collapsibleSplitTip : "Drag to resize. Double click to hide.",
35589 useSplitTips : false,
35591 applyConfig : function(config){
35592 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
35595 onRender : function(ctr,pos) {
35597 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
35598 if(!this.config.split){
35603 var splitEl = Roo.DomHelper.append(ctr.dom, {
35605 id: this.el.id + "-split",
35606 cls: "roo-layout-split roo-layout-split-"+this.position,
35609 /** The SplitBar for this region
35610 * @type Roo.SplitBar */
35611 // does not exist yet...
35612 Roo.log([this.position, this.orientation]);
35614 this.split = new Roo.bootstrap.SplitBar({
35615 dragElement : splitEl,
35616 resizingElement: this.el,
35617 orientation : this.orientation
35620 this.split.on("moved", this.onSplitMove, this);
35621 this.split.useShim = this.config.useShim === true;
35622 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
35623 if(this.useSplitTips){
35624 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
35626 //if(config.collapsible){
35627 // this.split.el.on("dblclick", this.collapse, this);
35630 if(typeof this.config.minSize != "undefined"){
35631 this.split.minSize = this.config.minSize;
35633 if(typeof this.config.maxSize != "undefined"){
35634 this.split.maxSize = this.config.maxSize;
35636 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
35637 this.hideSplitter();
35642 getHMaxSize : function(){
35643 var cmax = this.config.maxSize || 10000;
35644 var center = this.mgr.getRegion("center");
35645 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
35648 getVMaxSize : function(){
35649 var cmax = this.config.maxSize || 10000;
35650 var center = this.mgr.getRegion("center");
35651 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
35654 onSplitMove : function(split, newSize){
35655 this.fireEvent("resized", this, newSize);
35659 * Returns the {@link Roo.SplitBar} for this region.
35660 * @return {Roo.SplitBar}
35662 getSplitBar : function(){
35667 this.hideSplitter();
35668 Roo.bootstrap.layout.Split.superclass.hide.call(this);
35671 hideSplitter : function(){
35673 this.split.el.setLocation(-2000,-2000);
35674 this.split.el.hide();
35680 this.split.el.show();
35682 Roo.bootstrap.layout.Split.superclass.show.call(this);
35685 beforeSlide: function(){
35686 if(Roo.isGecko){// firefox overflow auto bug workaround
35687 this.bodyEl.clip();
35689 this.tabs.bodyEl.clip();
35691 if(this.activePanel){
35692 this.activePanel.getEl().clip();
35694 if(this.activePanel.beforeSlide){
35695 this.activePanel.beforeSlide();
35701 afterSlide : function(){
35702 if(Roo.isGecko){// firefox overflow auto bug workaround
35703 this.bodyEl.unclip();
35705 this.tabs.bodyEl.unclip();
35707 if(this.activePanel){
35708 this.activePanel.getEl().unclip();
35709 if(this.activePanel.afterSlide){
35710 this.activePanel.afterSlide();
35716 initAutoHide : function(){
35717 if(this.autoHide !== false){
35718 if(!this.autoHideHd){
35719 var st = new Roo.util.DelayedTask(this.slideIn, this);
35720 this.autoHideHd = {
35721 "mouseout": function(e){
35722 if(!e.within(this.el, true)){
35726 "mouseover" : function(e){
35732 this.el.on(this.autoHideHd);
35736 clearAutoHide : function(){
35737 if(this.autoHide !== false){
35738 this.el.un("mouseout", this.autoHideHd.mouseout);
35739 this.el.un("mouseover", this.autoHideHd.mouseover);
35743 clearMonitor : function(){
35744 Roo.get(document).un("click", this.slideInIf, this);
35747 // these names are backwards but not changed for compat
35748 slideOut : function(){
35749 if(this.isSlid || this.el.hasActiveFx()){
35752 this.isSlid = true;
35753 if(this.collapseBtn){
35754 this.collapseBtn.hide();
35756 this.closeBtnState = this.closeBtn.getStyle('display');
35757 this.closeBtn.hide();
35759 this.stickBtn.show();
35762 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
35763 this.beforeSlide();
35764 this.el.setStyle("z-index", 10001);
35765 this.el.slideIn(this.getSlideAnchor(), {
35766 callback: function(){
35768 this.initAutoHide();
35769 Roo.get(document).on("click", this.slideInIf, this);
35770 this.fireEvent("slideshow", this);
35777 afterSlideIn : function(){
35778 this.clearAutoHide();
35779 this.isSlid = false;
35780 this.clearMonitor();
35781 this.el.setStyle("z-index", "");
35782 if(this.collapseBtn){
35783 this.collapseBtn.show();
35785 this.closeBtn.setStyle('display', this.closeBtnState);
35787 this.stickBtn.hide();
35789 this.fireEvent("slidehide", this);
35792 slideIn : function(cb){
35793 if(!this.isSlid || this.el.hasActiveFx()){
35797 this.isSlid = false;
35798 this.beforeSlide();
35799 this.el.slideOut(this.getSlideAnchor(), {
35800 callback: function(){
35801 this.el.setLeftTop(-10000, -10000);
35803 this.afterSlideIn();
35811 slideInIf : function(e){
35812 if(!e.within(this.el)){
35817 animateCollapse : function(){
35818 this.beforeSlide();
35819 this.el.setStyle("z-index", 20000);
35820 var anchor = this.getSlideAnchor();
35821 this.el.slideOut(anchor, {
35822 callback : function(){
35823 this.el.setStyle("z-index", "");
35824 this.collapsedEl.slideIn(anchor, {duration:.3});
35826 this.el.setLocation(-10000,-10000);
35828 this.fireEvent("collapsed", this);
35835 animateExpand : function(){
35836 this.beforeSlide();
35837 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
35838 this.el.setStyle("z-index", 20000);
35839 this.collapsedEl.hide({
35842 this.el.slideIn(this.getSlideAnchor(), {
35843 callback : function(){
35844 this.el.setStyle("z-index", "");
35847 this.split.el.show();
35849 this.fireEvent("invalidated", this);
35850 this.fireEvent("expanded", this);
35878 getAnchor : function(){
35879 return this.anchors[this.position];
35882 getCollapseAnchor : function(){
35883 return this.canchors[this.position];
35886 getSlideAnchor : function(){
35887 return this.sanchors[this.position];
35890 getAlignAdj : function(){
35891 var cm = this.cmargins;
35892 switch(this.position){
35908 getExpandAdj : function(){
35909 var c = this.collapsedEl, cm = this.cmargins;
35910 switch(this.position){
35912 return [-(cm.right+c.getWidth()+cm.left), 0];
35915 return [cm.right+c.getWidth()+cm.left, 0];
35918 return [0, -(cm.top+cm.bottom+c.getHeight())];
35921 return [0, cm.top+cm.bottom+c.getHeight()];
35927 * Ext JS Library 1.1.1
35928 * Copyright(c) 2006-2007, Ext JS, LLC.
35930 * Originally Released Under LGPL - original licence link has changed is not relivant.
35933 * <script type="text/javascript">
35936 * These classes are private internal classes
35938 Roo.bootstrap.layout.Center = function(config){
35939 config.region = "center";
35940 Roo.bootstrap.layout.Region.call(this, config);
35941 this.visible = true;
35942 this.minWidth = config.minWidth || 20;
35943 this.minHeight = config.minHeight || 20;
35946 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
35948 // center panel can't be hidden
35952 // center panel can't be hidden
35955 getMinWidth: function(){
35956 return this.minWidth;
35959 getMinHeight: function(){
35960 return this.minHeight;
35973 Roo.bootstrap.layout.North = function(config)
35975 config.region = 'north';
35976 config.cursor = 'n-resize';
35978 Roo.bootstrap.layout.Split.call(this, config);
35982 this.split.placement = Roo.bootstrap.SplitBar.TOP;
35983 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
35984 this.split.el.addClass("roo-layout-split-v");
35986 var size = config.initialSize || config.height;
35987 if(typeof size != "undefined"){
35988 this.el.setHeight(size);
35991 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
35993 orientation: Roo.bootstrap.SplitBar.VERTICAL,
35997 getBox : function(){
35998 if(this.collapsed){
35999 return this.collapsedEl.getBox();
36001 var box = this.el.getBox();
36003 box.height += this.split.el.getHeight();
36008 updateBox : function(box){
36009 if(this.split && !this.collapsed){
36010 box.height -= this.split.el.getHeight();
36011 this.split.el.setLeft(box.x);
36012 this.split.el.setTop(box.y+box.height);
36013 this.split.el.setWidth(box.width);
36015 if(this.collapsed){
36016 this.updateBody(box.width, null);
36018 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36026 Roo.bootstrap.layout.South = function(config){
36027 config.region = 'south';
36028 config.cursor = 's-resize';
36029 Roo.bootstrap.layout.Split.call(this, config);
36031 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
36032 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36033 this.split.el.addClass("roo-layout-split-v");
36035 var size = config.initialSize || config.height;
36036 if(typeof size != "undefined"){
36037 this.el.setHeight(size);
36041 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
36042 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36043 getBox : function(){
36044 if(this.collapsed){
36045 return this.collapsedEl.getBox();
36047 var box = this.el.getBox();
36049 var sh = this.split.el.getHeight();
36056 updateBox : function(box){
36057 if(this.split && !this.collapsed){
36058 var sh = this.split.el.getHeight();
36061 this.split.el.setLeft(box.x);
36062 this.split.el.setTop(box.y-sh);
36063 this.split.el.setWidth(box.width);
36065 if(this.collapsed){
36066 this.updateBody(box.width, null);
36068 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36072 Roo.bootstrap.layout.East = function(config){
36073 config.region = "east";
36074 config.cursor = "e-resize";
36075 Roo.bootstrap.layout.Split.call(this, config);
36077 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
36078 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36079 this.split.el.addClass("roo-layout-split-h");
36081 var size = config.initialSize || config.width;
36082 if(typeof size != "undefined"){
36083 this.el.setWidth(size);
36086 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
36087 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36088 getBox : function(){
36089 if(this.collapsed){
36090 return this.collapsedEl.getBox();
36092 var box = this.el.getBox();
36094 var sw = this.split.el.getWidth();
36101 updateBox : function(box){
36102 if(this.split && !this.collapsed){
36103 var sw = this.split.el.getWidth();
36105 this.split.el.setLeft(box.x);
36106 this.split.el.setTop(box.y);
36107 this.split.el.setHeight(box.height);
36110 if(this.collapsed){
36111 this.updateBody(null, box.height);
36113 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36117 Roo.bootstrap.layout.West = function(config){
36118 config.region = "west";
36119 config.cursor = "w-resize";
36121 Roo.bootstrap.layout.Split.call(this, config);
36123 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
36124 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36125 this.split.el.addClass("roo-layout-split-h");
36129 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
36130 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36132 onRender: function(ctr, pos)
36134 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
36135 var size = this.config.initialSize || this.config.width;
36136 if(typeof size != "undefined"){
36137 this.el.setWidth(size);
36141 getBox : function(){
36142 if(this.collapsed){
36143 return this.collapsedEl.getBox();
36145 var box = this.el.getBox();
36147 box.width += this.split.el.getWidth();
36152 updateBox : function(box){
36153 if(this.split && !this.collapsed){
36154 var sw = this.split.el.getWidth();
36156 this.split.el.setLeft(box.x+box.width);
36157 this.split.el.setTop(box.y);
36158 this.split.el.setHeight(box.height);
36160 if(this.collapsed){
36161 this.updateBody(null, box.height);
36163 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36166 Roo.namespace("Roo.bootstrap.panel");/*
36168 * Ext JS Library 1.1.1
36169 * Copyright(c) 2006-2007, Ext JS, LLC.
36171 * Originally Released Under LGPL - original licence link has changed is not relivant.
36174 * <script type="text/javascript">
36177 * @class Roo.ContentPanel
36178 * @extends Roo.util.Observable
36179 * A basic ContentPanel element.
36180 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
36181 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
36182 * @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
36183 * @cfg {Boolean} closable True if the panel can be closed/removed
36184 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
36185 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
36186 * @cfg {Toolbar} toolbar A toolbar for this panel
36187 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
36188 * @cfg {String} title The title for this panel
36189 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
36190 * @cfg {String} url Calls {@link #setUrl} with this value
36191 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
36192 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
36193 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
36194 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
36195 * @cfg {Boolean} badges render the badges
36198 * Create a new ContentPanel.
36199 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
36200 * @param {String/Object} config A string to set only the title or a config object
36201 * @param {String} content (optional) Set the HTML content for this panel
36202 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
36204 Roo.bootstrap.panel.Content = function( config){
36206 this.tpl = config.tpl || false;
36208 var el = config.el;
36209 var content = config.content;
36211 if(config.autoCreate){ // xtype is available if this is called from factory
36214 this.el = Roo.get(el);
36215 if(!this.el && config && config.autoCreate){
36216 if(typeof config.autoCreate == "object"){
36217 if(!config.autoCreate.id){
36218 config.autoCreate.id = config.id||el;
36220 this.el = Roo.DomHelper.append(document.body,
36221 config.autoCreate, true);
36223 var elcfg = { tag: "div",
36224 cls: "roo-layout-inactive-content",
36228 elcfg.html = config.html;
36232 this.el = Roo.DomHelper.append(document.body, elcfg , true);
36235 this.closable = false;
36236 this.loaded = false;
36237 this.active = false;
36240 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
36242 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
36244 this.wrapEl = this.el; //this.el.wrap();
36246 if (config.toolbar.items) {
36247 ti = config.toolbar.items ;
36248 delete config.toolbar.items ;
36252 this.toolbar.render(this.wrapEl, 'before');
36253 for(var i =0;i < ti.length;i++) {
36254 // Roo.log(['add child', items[i]]);
36255 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
36257 this.toolbar.items = nitems;
36258 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
36259 delete config.toolbar;
36263 // xtype created footer. - not sure if will work as we normally have to render first..
36264 if (this.footer && !this.footer.el && this.footer.xtype) {
36265 if (!this.wrapEl) {
36266 this.wrapEl = this.el.wrap();
36269 this.footer.container = this.wrapEl.createChild();
36271 this.footer = Roo.factory(this.footer, Roo);
36276 if(typeof config == "string"){
36277 this.title = config;
36279 Roo.apply(this, config);
36283 this.resizeEl = Roo.get(this.resizeEl, true);
36285 this.resizeEl = this.el;
36287 // handle view.xtype
36295 * Fires when this panel is activated.
36296 * @param {Roo.ContentPanel} this
36300 * @event deactivate
36301 * Fires when this panel is activated.
36302 * @param {Roo.ContentPanel} this
36304 "deactivate" : true,
36308 * Fires when this panel is resized if fitToFrame is true.
36309 * @param {Roo.ContentPanel} this
36310 * @param {Number} width The width after any component adjustments
36311 * @param {Number} height The height after any component adjustments
36317 * Fires when this tab is created
36318 * @param {Roo.ContentPanel} this
36329 if(this.autoScroll){
36330 this.resizeEl.setStyle("overflow", "auto");
36332 // fix randome scrolling
36333 //this.el.on('scroll', function() {
36334 // Roo.log('fix random scolling');
36335 // this.scrollTo('top',0);
36338 content = content || this.content;
36340 this.setContent(content);
36342 if(config && config.url){
36343 this.setUrl(this.url, this.params, this.loadOnce);
36348 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
36350 if (this.view && typeof(this.view.xtype) != 'undefined') {
36351 this.view.el = this.el.appendChild(document.createElement("div"));
36352 this.view = Roo.factory(this.view);
36353 this.view.render && this.view.render(false, '');
36357 this.fireEvent('render', this);
36360 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
36364 setRegion : function(region){
36365 this.region = region;
36366 this.setActiveClass(region && !this.background);
36370 setActiveClass: function(state)
36373 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
36374 this.el.setStyle('position','relative');
36376 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
36377 this.el.setStyle('position', 'absolute');
36382 * Returns the toolbar for this Panel if one was configured.
36383 * @return {Roo.Toolbar}
36385 getToolbar : function(){
36386 return this.toolbar;
36389 setActiveState : function(active)
36391 this.active = active;
36392 this.setActiveClass(active);
36394 this.fireEvent("deactivate", this);
36396 this.fireEvent("activate", this);
36400 * Updates this panel's element
36401 * @param {String} content The new content
36402 * @param {Boolean} loadScripts (optional) true to look for and process scripts
36404 setContent : function(content, loadScripts){
36405 this.el.update(content, loadScripts);
36408 ignoreResize : function(w, h){
36409 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
36412 this.lastSize = {width: w, height: h};
36417 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
36418 * @return {Roo.UpdateManager} The UpdateManager
36420 getUpdateManager : function(){
36421 return this.el.getUpdateManager();
36424 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
36425 * @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:
36428 url: "your-url.php",
36429 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
36430 callback: yourFunction,
36431 scope: yourObject, //(optional scope)
36434 text: "Loading...",
36439 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
36440 * 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.
36441 * @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}
36442 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
36443 * @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.
36444 * @return {Roo.ContentPanel} this
36447 var um = this.el.getUpdateManager();
36448 um.update.apply(um, arguments);
36454 * 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.
36455 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
36456 * @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)
36457 * @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)
36458 * @return {Roo.UpdateManager} The UpdateManager
36460 setUrl : function(url, params, loadOnce){
36461 if(this.refreshDelegate){
36462 this.removeListener("activate", this.refreshDelegate);
36464 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
36465 this.on("activate", this.refreshDelegate);
36466 return this.el.getUpdateManager();
36469 _handleRefresh : function(url, params, loadOnce){
36470 if(!loadOnce || !this.loaded){
36471 var updater = this.el.getUpdateManager();
36472 updater.update(url, params, this._setLoaded.createDelegate(this));
36476 _setLoaded : function(){
36477 this.loaded = true;
36481 * Returns this panel's id
36484 getId : function(){
36489 * Returns this panel's element - used by regiosn to add.
36490 * @return {Roo.Element}
36492 getEl : function(){
36493 return this.wrapEl || this.el;
36498 adjustForComponents : function(width, height)
36500 //Roo.log('adjustForComponents ');
36501 if(this.resizeEl != this.el){
36502 width -= this.el.getFrameWidth('lr');
36503 height -= this.el.getFrameWidth('tb');
36506 var te = this.toolbar.getEl();
36507 te.setWidth(width);
36508 height -= te.getHeight();
36511 var te = this.footer.getEl();
36512 te.setWidth(width);
36513 height -= te.getHeight();
36517 if(this.adjustments){
36518 width += this.adjustments[0];
36519 height += this.adjustments[1];
36521 return {"width": width, "height": height};
36524 setSize : function(width, height){
36525 if(this.fitToFrame && !this.ignoreResize(width, height)){
36526 if(this.fitContainer && this.resizeEl != this.el){
36527 this.el.setSize(width, height);
36529 var size = this.adjustForComponents(width, height);
36530 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
36531 this.fireEvent('resize', this, size.width, size.height);
36536 * Returns this panel's title
36539 getTitle : function(){
36541 if (typeof(this.title) != 'object') {
36546 for (var k in this.title) {
36547 if (!this.title.hasOwnProperty(k)) {
36551 if (k.indexOf('-') >= 0) {
36552 var s = k.split('-');
36553 for (var i = 0; i<s.length; i++) {
36554 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
36557 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
36564 * Set this panel's title
36565 * @param {String} title
36567 setTitle : function(title){
36568 this.title = title;
36570 this.region.updatePanelTitle(this, title);
36575 * Returns true is this panel was configured to be closable
36576 * @return {Boolean}
36578 isClosable : function(){
36579 return this.closable;
36582 beforeSlide : function(){
36584 this.resizeEl.clip();
36587 afterSlide : function(){
36589 this.resizeEl.unclip();
36593 * Force a content refresh from the URL specified in the {@link #setUrl} method.
36594 * Will fail silently if the {@link #setUrl} method has not been called.
36595 * This does not activate the panel, just updates its content.
36597 refresh : function(){
36598 if(this.refreshDelegate){
36599 this.loaded = false;
36600 this.refreshDelegate();
36605 * Destroys this panel
36607 destroy : function(){
36608 this.el.removeAllListeners();
36609 var tempEl = document.createElement("span");
36610 tempEl.appendChild(this.el.dom);
36611 tempEl.innerHTML = "";
36617 * form - if the content panel contains a form - this is a reference to it.
36618 * @type {Roo.form.Form}
36622 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
36623 * This contains a reference to it.
36629 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
36639 * @param {Object} cfg Xtype definition of item to add.
36643 getChildContainer: function () {
36644 return this.getEl();
36649 var ret = new Roo.factory(cfg);
36654 if (cfg.xtype.match(/^Form$/)) {
36657 //if (this.footer) {
36658 // el = this.footer.container.insertSibling(false, 'before');
36660 el = this.el.createChild();
36663 this.form = new Roo.form.Form(cfg);
36666 if ( this.form.allItems.length) {
36667 this.form.render(el.dom);
36671 // should only have one of theses..
36672 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
36673 // views.. should not be just added - used named prop 'view''
36675 cfg.el = this.el.appendChild(document.createElement("div"));
36678 var ret = new Roo.factory(cfg);
36680 ret.render && ret.render(false, ''); // render blank..
36690 * @class Roo.bootstrap.panel.Grid
36691 * @extends Roo.bootstrap.panel.Content
36693 * Create a new GridPanel.
36694 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
36695 * @param {Object} config A the config object
36701 Roo.bootstrap.panel.Grid = function(config)
36705 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
36706 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
36708 config.el = this.wrapper;
36709 //this.el = this.wrapper;
36711 if (config.container) {
36712 // ctor'ed from a Border/panel.grid
36715 this.wrapper.setStyle("overflow", "hidden");
36716 this.wrapper.addClass('roo-grid-container');
36721 if(config.toolbar){
36722 var tool_el = this.wrapper.createChild();
36723 this.toolbar = Roo.factory(config.toolbar);
36725 if (config.toolbar.items) {
36726 ti = config.toolbar.items ;
36727 delete config.toolbar.items ;
36731 this.toolbar.render(tool_el);
36732 for(var i =0;i < ti.length;i++) {
36733 // Roo.log(['add child', items[i]]);
36734 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
36736 this.toolbar.items = nitems;
36738 delete config.toolbar;
36741 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
36742 config.grid.scrollBody = true;;
36743 config.grid.monitorWindowResize = false; // turn off autosizing
36744 config.grid.autoHeight = false;
36745 config.grid.autoWidth = false;
36747 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
36749 if (config.background) {
36750 // render grid on panel activation (if panel background)
36751 this.on('activate', function(gp) {
36752 if (!gp.grid.rendered) {
36753 gp.grid.render(this.wrapper);
36754 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
36759 this.grid.render(this.wrapper);
36760 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
36763 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
36764 // ??? needed ??? config.el = this.wrapper;
36769 // xtype created footer. - not sure if will work as we normally have to render first..
36770 if (this.footer && !this.footer.el && this.footer.xtype) {
36772 var ctr = this.grid.getView().getFooterPanel(true);
36773 this.footer.dataSource = this.grid.dataSource;
36774 this.footer = Roo.factory(this.footer, Roo);
36775 this.footer.render(ctr);
36785 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
36786 getId : function(){
36787 return this.grid.id;
36791 * Returns the grid for this panel
36792 * @return {Roo.bootstrap.Table}
36794 getGrid : function(){
36798 setSize : function(width, height){
36799 if(!this.ignoreResize(width, height)){
36800 var grid = this.grid;
36801 var size = this.adjustForComponents(width, height);
36802 var gridel = grid.getGridEl();
36803 gridel.setSize(size.width, size.height);
36805 var thd = grid.getGridEl().select('thead',true).first();
36806 var tbd = grid.getGridEl().select('tbody', true).first();
36808 tbd.setSize(width, height - thd.getHeight());
36817 beforeSlide : function(){
36818 this.grid.getView().scroller.clip();
36821 afterSlide : function(){
36822 this.grid.getView().scroller.unclip();
36825 destroy : function(){
36826 this.grid.destroy();
36828 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
36833 * @class Roo.bootstrap.panel.Nest
36834 * @extends Roo.bootstrap.panel.Content
36836 * Create a new Panel, that can contain a layout.Border.
36839 * @param {Roo.BorderLayout} layout The layout for this panel
36840 * @param {String/Object} config A string to set only the title or a config object
36842 Roo.bootstrap.panel.Nest = function(config)
36844 // construct with only one argument..
36845 /* FIXME - implement nicer consturctors
36846 if (layout.layout) {
36848 layout = config.layout;
36849 delete config.layout;
36851 if (layout.xtype && !layout.getEl) {
36852 // then layout needs constructing..
36853 layout = Roo.factory(layout, Roo);
36857 config.el = config.layout.getEl();
36859 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
36861 config.layout.monitorWindowResize = false; // turn off autosizing
36862 this.layout = config.layout;
36863 this.layout.getEl().addClass("roo-layout-nested-layout");
36870 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
36872 setSize : function(width, height){
36873 if(!this.ignoreResize(width, height)){
36874 var size = this.adjustForComponents(width, height);
36875 var el = this.layout.getEl();
36876 if (size.height < 1) {
36877 el.setWidth(size.width);
36879 el.setSize(size.width, size.height);
36881 var touch = el.dom.offsetWidth;
36882 this.layout.layout();
36883 // ie requires a double layout on the first pass
36884 if(Roo.isIE && !this.initialized){
36885 this.initialized = true;
36886 this.layout.layout();
36891 // activate all subpanels if not currently active..
36893 setActiveState : function(active){
36894 this.active = active;
36895 this.setActiveClass(active);
36898 this.fireEvent("deactivate", this);
36902 this.fireEvent("activate", this);
36903 // not sure if this should happen before or after..
36904 if (!this.layout) {
36905 return; // should not happen..
36908 for (var r in this.layout.regions) {
36909 reg = this.layout.getRegion(r);
36910 if (reg.getActivePanel()) {
36911 //reg.showPanel(reg.getActivePanel()); // force it to activate..
36912 reg.setActivePanel(reg.getActivePanel());
36915 if (!reg.panels.length) {
36918 reg.showPanel(reg.getPanel(0));
36927 * Returns the nested BorderLayout for this panel
36928 * @return {Roo.BorderLayout}
36930 getLayout : function(){
36931 return this.layout;
36935 * Adds a xtype elements to the layout of the nested panel
36939 xtype : 'ContentPanel',
36946 xtype : 'NestedLayoutPanel',
36952 items : [ ... list of content panels or nested layout panels.. ]
36956 * @param {Object} cfg Xtype definition of item to add.
36958 addxtype : function(cfg) {
36959 return this.layout.addxtype(cfg);
36964 * Ext JS Library 1.1.1
36965 * Copyright(c) 2006-2007, Ext JS, LLC.
36967 * Originally Released Under LGPL - original licence link has changed is not relivant.
36970 * <script type="text/javascript">
36973 * @class Roo.TabPanel
36974 * @extends Roo.util.Observable
36975 * A lightweight tab container.
36979 // basic tabs 1, built from existing content
36980 var tabs = new Roo.TabPanel("tabs1");
36981 tabs.addTab("script", "View Script");
36982 tabs.addTab("markup", "View Markup");
36983 tabs.activate("script");
36985 // more advanced tabs, built from javascript
36986 var jtabs = new Roo.TabPanel("jtabs");
36987 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
36989 // set up the UpdateManager
36990 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
36991 var updater = tab2.getUpdateManager();
36992 updater.setDefaultUrl("ajax1.htm");
36993 tab2.on('activate', updater.refresh, updater, true);
36995 // Use setUrl for Ajax loading
36996 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
36997 tab3.setUrl("ajax2.htm", null, true);
37000 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
37003 jtabs.activate("jtabs-1");
37006 * Create a new TabPanel.
37007 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
37008 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
37010 Roo.bootstrap.panel.Tabs = function(config){
37012 * The container element for this TabPanel.
37013 * @type Roo.Element
37015 this.el = Roo.get(config.el);
37018 if(typeof config == "boolean"){
37019 this.tabPosition = config ? "bottom" : "top";
37021 Roo.apply(this, config);
37025 if(this.tabPosition == "bottom"){
37026 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37027 this.el.addClass("roo-tabs-bottom");
37029 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
37030 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
37031 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
37033 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
37035 if(this.tabPosition != "bottom"){
37036 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
37037 * @type Roo.Element
37039 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37040 this.el.addClass("roo-tabs-top");
37044 this.bodyEl.setStyle("position", "relative");
37046 this.active = null;
37047 this.activateDelegate = this.activate.createDelegate(this);
37052 * Fires when the active tab changes
37053 * @param {Roo.TabPanel} this
37054 * @param {Roo.TabPanelItem} activePanel The new active tab
37058 * @event beforetabchange
37059 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
37060 * @param {Roo.TabPanel} this
37061 * @param {Object} e Set cancel to true on this object to cancel the tab change
37062 * @param {Roo.TabPanelItem} tab The tab being changed to
37064 "beforetabchange" : true
37067 Roo.EventManager.onWindowResize(this.onResize, this);
37068 this.cpad = this.el.getPadding("lr");
37069 this.hiddenCount = 0;
37072 // toolbar on the tabbar support...
37073 if (this.toolbar) {
37074 alert("no toolbar support yet");
37075 this.toolbar = false;
37077 var tcfg = this.toolbar;
37078 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
37079 this.toolbar = new Roo.Toolbar(tcfg);
37080 if (Roo.isSafari) {
37081 var tbl = tcfg.container.child('table', true);
37082 tbl.setAttribute('width', '100%');
37090 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
37093 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
37095 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
37097 tabPosition : "top",
37099 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
37101 currentTabWidth : 0,
37103 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
37107 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
37111 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
37113 preferredTabWidth : 175,
37115 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
37117 resizeTabs : false,
37119 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
37121 monitorResize : true,
37123 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
37128 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
37129 * @param {String} id The id of the div to use <b>or create</b>
37130 * @param {String} text The text for the tab
37131 * @param {String} content (optional) Content to put in the TabPanelItem body
37132 * @param {Boolean} closable (optional) True to create a close icon on the tab
37133 * @return {Roo.TabPanelItem} The created TabPanelItem
37135 addTab : function(id, text, content, closable, tpl)
37137 var item = new Roo.bootstrap.panel.TabItem({
37141 closable : closable,
37144 this.addTabItem(item);
37146 item.setContent(content);
37152 * Returns the {@link Roo.TabPanelItem} with the specified id/index
37153 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
37154 * @return {Roo.TabPanelItem}
37156 getTab : function(id){
37157 return this.items[id];
37161 * Hides the {@link Roo.TabPanelItem} with the specified id/index
37162 * @param {String/Number} id The id or index of the TabPanelItem to hide.
37164 hideTab : function(id){
37165 var t = this.items[id];
37168 this.hiddenCount++;
37169 this.autoSizeTabs();
37174 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
37175 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
37177 unhideTab : function(id){
37178 var t = this.items[id];
37180 t.setHidden(false);
37181 this.hiddenCount--;
37182 this.autoSizeTabs();
37187 * Adds an existing {@link Roo.TabPanelItem}.
37188 * @param {Roo.TabPanelItem} item The TabPanelItem to add
37190 addTabItem : function(item){
37191 this.items[item.id] = item;
37192 this.items.push(item);
37193 // if(this.resizeTabs){
37194 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
37195 // this.autoSizeTabs();
37197 // item.autoSize();
37202 * Removes a {@link Roo.TabPanelItem}.
37203 * @param {String/Number} id The id or index of the TabPanelItem to remove.
37205 removeTab : function(id){
37206 var items = this.items;
37207 var tab = items[id];
37208 if(!tab) { return; }
37209 var index = items.indexOf(tab);
37210 if(this.active == tab && items.length > 1){
37211 var newTab = this.getNextAvailable(index);
37216 this.stripEl.dom.removeChild(tab.pnode.dom);
37217 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
37218 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
37220 items.splice(index, 1);
37221 delete this.items[tab.id];
37222 tab.fireEvent("close", tab);
37223 tab.purgeListeners();
37224 this.autoSizeTabs();
37227 getNextAvailable : function(start){
37228 var items = this.items;
37230 // look for a next tab that will slide over to
37231 // replace the one being removed
37232 while(index < items.length){
37233 var item = items[++index];
37234 if(item && !item.isHidden()){
37238 // if one isn't found select the previous tab (on the left)
37241 var item = items[--index];
37242 if(item && !item.isHidden()){
37250 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
37251 * @param {String/Number} id The id or index of the TabPanelItem to disable.
37253 disableTab : function(id){
37254 var tab = this.items[id];
37255 if(tab && this.active != tab){
37261 * Enables a {@link Roo.TabPanelItem} that is disabled.
37262 * @param {String/Number} id The id or index of the TabPanelItem to enable.
37264 enableTab : function(id){
37265 var tab = this.items[id];
37270 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
37271 * @param {String/Number} id The id or index of the TabPanelItem to activate.
37272 * @return {Roo.TabPanelItem} The TabPanelItem.
37274 activate : function(id){
37275 var tab = this.items[id];
37279 if(tab == this.active || tab.disabled){
37283 this.fireEvent("beforetabchange", this, e, tab);
37284 if(e.cancel !== true && !tab.disabled){
37286 this.active.hide();
37288 this.active = this.items[id];
37289 this.active.show();
37290 this.fireEvent("tabchange", this, this.active);
37296 * Gets the active {@link Roo.TabPanelItem}.
37297 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
37299 getActiveTab : function(){
37300 return this.active;
37304 * Updates the tab body element to fit the height of the container element
37305 * for overflow scrolling
37306 * @param {Number} targetHeight (optional) Override the starting height from the elements height
37308 syncHeight : function(targetHeight){
37309 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
37310 var bm = this.bodyEl.getMargins();
37311 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
37312 this.bodyEl.setHeight(newHeight);
37316 onResize : function(){
37317 if(this.monitorResize){
37318 this.autoSizeTabs();
37323 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
37325 beginUpdate : function(){
37326 this.updating = true;
37330 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
37332 endUpdate : function(){
37333 this.updating = false;
37334 this.autoSizeTabs();
37338 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
37340 autoSizeTabs : function(){
37341 var count = this.items.length;
37342 var vcount = count - this.hiddenCount;
37343 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
37346 var w = Math.max(this.el.getWidth() - this.cpad, 10);
37347 var availWidth = Math.floor(w / vcount);
37348 var b = this.stripBody;
37349 if(b.getWidth() > w){
37350 var tabs = this.items;
37351 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
37352 if(availWidth < this.minTabWidth){
37353 /*if(!this.sleft){ // incomplete scrolling code
37354 this.createScrollButtons();
37357 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
37360 if(this.currentTabWidth < this.preferredTabWidth){
37361 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
37367 * Returns the number of tabs in this TabPanel.
37370 getCount : function(){
37371 return this.items.length;
37375 * Resizes all the tabs to the passed width
37376 * @param {Number} The new width
37378 setTabWidth : function(width){
37379 this.currentTabWidth = width;
37380 for(var i = 0, len = this.items.length; i < len; i++) {
37381 if(!this.items[i].isHidden()) {
37382 this.items[i].setWidth(width);
37388 * Destroys this TabPanel
37389 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
37391 destroy : function(removeEl){
37392 Roo.EventManager.removeResizeListener(this.onResize, this);
37393 for(var i = 0, len = this.items.length; i < len; i++){
37394 this.items[i].purgeListeners();
37396 if(removeEl === true){
37397 this.el.update("");
37402 createStrip : function(container)
37404 var strip = document.createElement("nav");
37405 strip.className = "navbar navbar-default"; //"x-tabs-wrap";
37406 container.appendChild(strip);
37410 createStripList : function(strip)
37412 // div wrapper for retard IE
37413 // returns the "tr" element.
37414 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
37415 //'<div class="x-tabs-strip-wrap">'+
37416 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
37417 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
37418 return strip.firstChild; //.firstChild.firstChild.firstChild;
37420 createBody : function(container)
37422 var body = document.createElement("div");
37423 Roo.id(body, "tab-body");
37424 //Roo.fly(body).addClass("x-tabs-body");
37425 Roo.fly(body).addClass("tab-content");
37426 container.appendChild(body);
37429 createItemBody :function(bodyEl, id){
37430 var body = Roo.getDom(id);
37432 body = document.createElement("div");
37435 //Roo.fly(body).addClass("x-tabs-item-body");
37436 Roo.fly(body).addClass("tab-pane");
37437 bodyEl.insertBefore(body, bodyEl.firstChild);
37441 createStripElements : function(stripEl, text, closable, tpl)
37443 var td = document.createElement("li"); // was td..
37446 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
37449 stripEl.appendChild(td);
37451 td.className = "x-tabs-closable";
37452 if(!this.closeTpl){
37453 this.closeTpl = new Roo.Template(
37454 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
37455 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
37456 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
37459 var el = this.closeTpl.overwrite(td, {"text": text});
37460 var close = el.getElementsByTagName("div")[0];
37461 var inner = el.getElementsByTagName("em")[0];
37462 return {"el": el, "close": close, "inner": inner};
37465 // not sure what this is..
37466 // if(!this.tabTpl){
37467 //this.tabTpl = new Roo.Template(
37468 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
37469 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
37471 // this.tabTpl = new Roo.Template(
37472 // '<a href="#">' +
37473 // '<span unselectable="on"' +
37474 // (this.disableTooltips ? '' : ' title="{text}"') +
37475 // ' >{text}</span></a>'
37481 var template = tpl || this.tabTpl || false;
37485 template = new Roo.Template(
37487 '<span unselectable="on"' +
37488 (this.disableTooltips ? '' : ' title="{text}"') +
37489 ' >{text}</span></a>'
37493 switch (typeof(template)) {
37497 template = new Roo.Template(template);
37503 var el = template.overwrite(td, {"text": text});
37505 var inner = el.getElementsByTagName("span")[0];
37507 return {"el": el, "inner": inner};
37515 * @class Roo.TabPanelItem
37516 * @extends Roo.util.Observable
37517 * Represents an individual item (tab plus body) in a TabPanel.
37518 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
37519 * @param {String} id The id of this TabPanelItem
37520 * @param {String} text The text for the tab of this TabPanelItem
37521 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
37523 Roo.bootstrap.panel.TabItem = function(config){
37525 * The {@link Roo.TabPanel} this TabPanelItem belongs to
37526 * @type Roo.TabPanel
37528 this.tabPanel = config.panel;
37530 * The id for this TabPanelItem
37533 this.id = config.id;
37535 this.disabled = false;
37537 this.text = config.text;
37539 this.loaded = false;
37540 this.closable = config.closable;
37543 * The body element for this TabPanelItem.
37544 * @type Roo.Element
37546 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
37547 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
37548 this.bodyEl.setStyle("display", "block");
37549 this.bodyEl.setStyle("zoom", "1");
37550 //this.hideAction();
37552 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
37554 this.el = Roo.get(els.el);
37555 this.inner = Roo.get(els.inner, true);
37556 this.textEl = Roo.get(this.el.dom.firstChild, true);
37557 this.pnode = Roo.get(els.el.parentNode, true);
37558 this.el.on("mousedown", this.onTabMouseDown, this);
37559 this.el.on("click", this.onTabClick, this);
37561 if(config.closable){
37562 var c = Roo.get(els.close, true);
37563 c.dom.title = this.closeText;
37564 c.addClassOnOver("close-over");
37565 c.on("click", this.closeClick, this);
37571 * Fires when this tab becomes the active tab.
37572 * @param {Roo.TabPanel} tabPanel The parent TabPanel
37573 * @param {Roo.TabPanelItem} this
37577 * @event beforeclose
37578 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
37579 * @param {Roo.TabPanelItem} this
37580 * @param {Object} e Set cancel to true on this object to cancel the close.
37582 "beforeclose": true,
37585 * Fires when this tab is closed.
37586 * @param {Roo.TabPanelItem} this
37590 * @event deactivate
37591 * Fires when this tab is no longer the active tab.
37592 * @param {Roo.TabPanel} tabPanel The parent TabPanel
37593 * @param {Roo.TabPanelItem} this
37595 "deactivate" : true
37597 this.hidden = false;
37599 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
37602 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
37604 purgeListeners : function(){
37605 Roo.util.Observable.prototype.purgeListeners.call(this);
37606 this.el.removeAllListeners();
37609 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
37612 this.pnode.addClass("active");
37615 this.tabPanel.stripWrap.repaint();
37617 this.fireEvent("activate", this.tabPanel, this);
37621 * Returns true if this tab is the active tab.
37622 * @return {Boolean}
37624 isActive : function(){
37625 return this.tabPanel.getActiveTab() == this;
37629 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
37632 this.pnode.removeClass("active");
37634 this.fireEvent("deactivate", this.tabPanel, this);
37637 hideAction : function(){
37638 this.bodyEl.hide();
37639 this.bodyEl.setStyle("position", "absolute");
37640 this.bodyEl.setLeft("-20000px");
37641 this.bodyEl.setTop("-20000px");
37644 showAction : function(){
37645 this.bodyEl.setStyle("position", "relative");
37646 this.bodyEl.setTop("");
37647 this.bodyEl.setLeft("");
37648 this.bodyEl.show();
37652 * Set the tooltip for the tab.
37653 * @param {String} tooltip The tab's tooltip
37655 setTooltip : function(text){
37656 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
37657 this.textEl.dom.qtip = text;
37658 this.textEl.dom.removeAttribute('title');
37660 this.textEl.dom.title = text;
37664 onTabClick : function(e){
37665 e.preventDefault();
37666 this.tabPanel.activate(this.id);
37669 onTabMouseDown : function(e){
37670 e.preventDefault();
37671 this.tabPanel.activate(this.id);
37674 getWidth : function(){
37675 return this.inner.getWidth();
37678 setWidth : function(width){
37679 var iwidth = width - this.pnode.getPadding("lr");
37680 this.inner.setWidth(iwidth);
37681 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
37682 this.pnode.setWidth(width);
37686 * Show or hide the tab
37687 * @param {Boolean} hidden True to hide or false to show.
37689 setHidden : function(hidden){
37690 this.hidden = hidden;
37691 this.pnode.setStyle("display", hidden ? "none" : "");
37695 * Returns true if this tab is "hidden"
37696 * @return {Boolean}
37698 isHidden : function(){
37699 return this.hidden;
37703 * Returns the text for this tab
37706 getText : function(){
37710 autoSize : function(){
37711 //this.el.beginMeasure();
37712 this.textEl.setWidth(1);
37714 * #2804 [new] Tabs in Roojs
37715 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
37717 //this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
37718 //this.el.endMeasure();
37722 * Sets the text for the tab (Note: this also sets the tooltip text)
37723 * @param {String} text The tab's text and tooltip
37725 setText : function(text){
37727 this.textEl.update(text);
37728 this.setTooltip(text);
37729 //if(!this.tabPanel.resizeTabs){
37730 // this.autoSize();
37734 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
37736 activate : function(){
37737 this.tabPanel.activate(this.id);
37741 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
37743 disable : function(){
37744 if(this.tabPanel.active != this){
37745 this.disabled = true;
37746 this.pnode.addClass("disabled");
37751 * Enables this TabPanelItem if it was previously disabled.
37753 enable : function(){
37754 this.disabled = false;
37755 this.pnode.removeClass("disabled");
37759 * Sets the content for this TabPanelItem.
37760 * @param {String} content The content
37761 * @param {Boolean} loadScripts true to look for and load scripts
37763 setContent : function(content, loadScripts){
37764 this.bodyEl.update(content, loadScripts);
37768 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
37769 * @return {Roo.UpdateManager} The UpdateManager
37771 getUpdateManager : function(){
37772 return this.bodyEl.getUpdateManager();
37776 * Set a URL to be used to load the content for this TabPanelItem.
37777 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
37778 * @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)
37779 * @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)
37780 * @return {Roo.UpdateManager} The UpdateManager
37782 setUrl : function(url, params, loadOnce){
37783 if(this.refreshDelegate){
37784 this.un('activate', this.refreshDelegate);
37786 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
37787 this.on("activate", this.refreshDelegate);
37788 return this.bodyEl.getUpdateManager();
37792 _handleRefresh : function(url, params, loadOnce){
37793 if(!loadOnce || !this.loaded){
37794 var updater = this.bodyEl.getUpdateManager();
37795 updater.update(url, params, this._setLoaded.createDelegate(this));
37800 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
37801 * Will fail silently if the setUrl method has not been called.
37802 * This does not activate the panel, just updates its content.
37804 refresh : function(){
37805 if(this.refreshDelegate){
37806 this.loaded = false;
37807 this.refreshDelegate();
37812 _setLoaded : function(){
37813 this.loaded = true;
37817 closeClick : function(e){
37820 this.fireEvent("beforeclose", this, o);
37821 if(o.cancel !== true){
37822 this.tabPanel.removeTab(this.id);
37826 * The text displayed in the tooltip for the close icon.
37829 closeText : "Close this tab"